Sotos wrote:GR, I took an assembly course... it was the most boring and practically useless programming course I ever took. It just serves to explain some principles to students... very little purpose beyond that in our times except from some niche situations
Sotos, I have established a long time ago that you're one of the biggest idiots using a computer that should take it right back to the shop!
Here are a few assembly functions and procedures I pulled out of my many libraries for your perusal… so enjoy yourself staring at things beyond your comprehension!
NB: These routines (in fact my entire library collection) will be entering public domain soon anyway so I don't mind giving them away here.
{---------------------------------------------------------}
FUNCTION DriveValid(Drive:Char):Boolean; Assembler;
ASM
Mov AH,$19 { Save the current drive in BL }
Int $21
Mov BL,AL
Mov DL,Drive { Select the given drive }
Sub DL,'A'
Mov AH,$0E
Int $21
Mov AH,$19 { Retrieve what DOS thinks is current }
Int $21
Mov CX,0 { Assume false }
Cmp AL,DL { Is the current drive the given drive? }
Jne @1
Mov CX,1 { It is, so the drive is valid }
Mov DL,BL { Restore the old drive }
Mov AH,$0E
Int $21
@1: Xchg AX,CX { Put the return value into AX }
END;
{---------------------------------------------------------}
PROCEDURE GetDriveStats(Drv:Char; VAR Size,Used,Free:LongInt);
VAR Sectors,F_Clust,Bytes,T_Clust:Word;
BEGIN
ASM
Mov AH,$36
Mov DL,Drv
Sub DL,64
Int $21
Cmp AX,$FFFF {Invalid drive}
Jne @1
Xor AX,AX
Xor BX,BX
Xor CX,CX
Xor DX,DX
@1:
Mov Sectors,AX {Sectors per Cluster}
Mov F_Clust,BX {Free Clusters}
Mov Bytes,CX {Bytes per Sector}
Mov T_Clust,DX {Total Clusters}
END;
Size:=LongInt(Sectors)*LongInt(Bytes)*T_Clust;
Free:=LongInt(Sectors)*LongInt(F_Clust)*Bytes;
Used:=Size-Free;
END;
{---------------------------------------------------------}
FUNCTION GetDiskInfo(Drive:Char; VAR Buffer:DiskInfo):Word; Assembler;
ASM
Mov AX,$6900
Mov BL,Drive
Sub BL,64
Push DS
Lds DX,Buffer
Int $21
Pop DS
Jc @Bad
Xor AX,AX
@Bad:
END;
{---------------------------------------------------------}
FUNCTION SetDiskInfo(Drive:Char; VAR Buffer:DiskInfo):Word; Assembler;
ASM
Mov AX,$6901
Mov BL,Drive
Sub BL,64
Push DS
Lds DX,Buffer
Int $21
Pop DS
Jc @Bad
Xor AX,AX
@Bad:
END;
{---------------------------------------------------------}
FUNCTION IsCDRomDrive(Drive:Char):Boolean; Assembler;
ASM
Mov AX,$150B
Mov CX,Word(Drive)
Sub CX,$0041
Int $2F
END;
{---------------------------------------------------------}
FUNCTION IsDriveRemote(Drive:Char):Boolean; Assembler;
ASM
Mov AX,$4409
Mov BL,Drive
Sub BL,$40
Int $21
Xor AX,AX
Jc @1
And DH,$10
Jz @1
Inc AX
@1:
END;
{---------------------------------------------------------}
FUNCTION EnableDrive(Drv:Char):Boolean; Assembler;
ASM {DOS 5+ - Sets the "valid" bit in drive's CDS}
Mov AX,$5F07
Mov DL,Drv
Sub DL,$41
Int $21
Xor AL,AL
Jc @1
Mov AL,1
@1:
END;
{---------------------------------------------------------}
FUNCTION DisableDrive(Drv:Char):Boolean; Assembler;
ASM {DOS 5+ - Clears the "valid" bit in drive's CDS}
Mov AX,$5F08
Mov DL,Drv
Sub DL,$41
Int $21
Xor AL,AL
Jc @1
Mov AL,1
@1:
END;
{---------------------------------------------------------}
FUNCTION FileOpen(S:String):Boolean; Assembler;
ASM
Push DS
Mov AH,$3D
Xor AL,AL
Lds DX,S
Inc DX
Int $21
Mov BX,AX
Xor AL,AL
Jnc @1
Cmp BX,$05
Jz @2
Jmp @1
@2:
Mov AL,$01
@1:
Pop DS
END;
{---------------------------------------------------------}
FUNCTION FileLock(Lock:Byte; Handle:Word; Pos,Len:Longint):Word; Assembler;
ASM
Mov AH,$5C
Mov AL,Lock {0=Lock 1=Unlock}
Mov BX,Handle
Les DX,Pos
Mov CX,ES
Les DI,Len
Mov SI,ES
Int $21
Jb @1
Xor AX,AX
@1: {0=Ok}
END;
{---------------------------------------------------------}
FUNCTION GetMachineName:Str16;
VAR Data:Array[0..15] Of Byte; Bad:Boolean; S:Str16; N:Byte;
BEGIN
FillChar(Data,SizeOf(Data),0);
ASM
Mov Bad,1
Mov AX,$5E00
Mov DX,Offset Data
Mov DS,DX
Mov DX,Seg Data
Int $21 {CL returns NetBIOS number}
Jc @1
Mov Bad,0
@1:
END;
IF Bad THEN GetMachineName:='Error' ELSE
BEGIN
Move(Data[0],S[1],16); S[0]:=#16;
GetMachineName:=S;
END;
END;
{---------------------------------------------------------}
PROCEDURE SetMachineName(Number:Byte; Name:Str16);
VAR Data:Array[0..15] Of Byte;
BEGIN
FillChar(Data,SizeOf(Data),0);
Move(Name[1],Data[0],Length(Name));
ASM
Mov AX,$5E01
Mov CH,$01
Mov CL,Number
Mov DX,Offset Data
Mov DS,DX
Mov DX,Seg Data
Int $21
END;
END;
{---------------------------------------------------------}
PROCEDURE KillMachineName(Number:Byte); Assembler;
ASM
Mov AX,$5E01
Xor CH,CH
Mov CL,Number
Int $21
END;
{---------------------------------------------------------}
PROCEDURE GetNetResources(VAR Names,Blocks,Sessions:Word); Assembler;
ASM
Mov AX,$0500
Int $2A
Les DI,Names
Mov Word Ptr ES:[DI],BX
Les DI,Blocks
Mov Word Ptr ES:[DI],CX
Les DI,Sessions
Mov Word Ptr ES:[DI],DX
END;
Let me know if you want to see more!