This unit isn't portable at all (more portable stuf is moved to EFIO).
Types
Variables
Procedures
A lot of procedures in this unit have a parameter called Drv.
This parameter identifies a drive by a positive number:
Number | meaning |
---|---|
0 | current (default) drive |
1 | drive a: |
2 | drive b: even if you don't have a second floppy drive |
3 | drive c: |
4 | drive d: |
5 | drive e: |
6 | drive f: |
7 | drive g: |
8 | drive h: |
etc, | etc |
TYPE PagerType = (Res0, Reserved SW_NOPAGER, No paging system SW_DOSPAGER, Paging through Dos SW_IOSPAGER); Protected mode pager TSwapInfo = RECORD GetSwapData record FileName : String[255]; Location swapfile FileSize : COMP; Size swapfile Pager : PagerType; Pager type, see above END;This record is filled by GetSwapData and contains the location and size of the swapfile, and the operating mode of the swapper (none,dos,protected)
Notes
TYPE CMOSRec= PACKED RECORD (* Structure Cmos *) Sec, Hr:Min:Sec current time. May deviate from time reported by Windows or TIME command. Only synchronized on startup. AlSec, AlHr:AlMin:AlSec time of next alarm interrupt. Mosttimes nonsense data. Min, AlMin, Hr, AlHr, DayOfWeek, Day of week. Monday=1. Day, Day/Month/Year (only 2 digits of year, other two are in century) Month, Year, RTCA, Control registers of the Real Time Clock (RTC) RTCB, RTCC, RTCD, POSTStatus, Diagnostic status byte ShutDownStatus, Shutdown status byte DiskType, Floppy type (lo(x)=A: Hi(X)=B:) Res1, HDType, Hardddisk type (Lo(x)=HD1 Hi(X)=HD2) XT-only Res2, Equipment : BYTE; See sysinfo demo BaseMem, Basemem in kb XTDMem : WORD; Extended memory in kb (see alternate below) HD_C, modern harddisktypes (If Lo(CMOS.HDType)=15) HD_D : BYTE; modern harddisktypes (If Hi(CMOS.HDType)=15) Res3 : ARRAY[0..18] OF BYTE; Checksum, (Sum of bytes 16 to 45) AND 65535 XTDMem2 : WORD; Extended memory in kb (see alternate above) Century, First 2 digits of year Misc : BYTE; Bit 7 set = top 128k installed, bit 6 set = first user message? Res4 : ARRAY[0..11] OF BYTE; Res5 : ARRAY[0..63] OF BYTE; END;This record is filled by GetCMOS and contains the contents of the CMOS (the area where the BIOS keeps its data like harddisk time, amount of memory and the correct time
Explanation of some complex fields of above records:
TYPE UART = (uNoUART, uBadUART, u8250, u16450, u16550, u16550a); The UART type as returned by TestUart. The label names speak for themselves, except that NoUart can also be caused by the OS (e.g. Win95) blocking the detection
Declaration
VAR SubstExpand : BOOLEAN;
Description
If this boolean is TRUE, Truename,GetShortPathName and GetLongPathName will expand substed drive-letters to their original paths.
Declaration
FUNCTION GetSerial(Drv : LONGINT) : LONGINT;
Description
Returns the serial-number as longint for drive Drv. (0=current, 1=A, 2=B etc)
Note Only works for harddisks and floppies.
Example:
BEGIN Writeln(GetSerial(3)); {Prints serial number in decimal format for drive C} END.
Declaration
FUNCTION GetVolume(Drv : LONGINT) : String;
Description
Returns the volume-name for drive Drv. (0=current, 1=A, 2=B etc)
Obtained with FindFirst (most compatible, other methods don't work on CDROMs, Zip drives and networks)
Example:
BEGIN Writeln(GetVolume(3)); {Prints volume name of drive C} END.
Declaration
FUNCTION DriveType(Drv : LONGINT) : LONGINT;
Description
Tries to identify the type of drive Drv. (0=current, 1=A, 2=B etc)
ReturnValue | Drive type |
---|---|
0 | Drive physically isn't available, or it's removable, and no disk is loaded |
1 | Remote (network, Ramdrive) disk drive |
2 | Fixed (hard) disk drive |
3 | Removable (floppy) disk drive |
4 | Substed drive |
5 | Cdrom |
The procedure is quite efficient, and you can make your dos-based programs a lot more safe with it (no more invalid drive problems etc, or trying to mount cdroms without disks in it).
The procedure retrieves the number of floppy drives your system has (with NrFloppies), and if that is 1, it assumes drive b: doesn't exist. This avoids renaming A: to B: as most modern mainboards do
It also uses standard procedure DiskFree to check all drives. This way removable drives (floppy,ZIP,Cdrom) without media loaded are non-existant, and NOT mounted
The best way to detect the existance of drives is demonstrated in demo DFree, which I reduced to below skeleton.
Note :
VAR Drv : LONGINT; DrvT: LONGINT; BEGIN FOR Drv:=1 TO 26 DO BEGIN DrvT:=DriveType(Drv); {Get drivetype} IF DrvT<>0 THEN {Test if drive exists, and/or drive has media loaded} BEGIN Write(CHR(Drv+64),': '); Write(GetVolume(Drv):20,DiskFree(Drv):20,DiskSize(Drv):20); CASE DrvT OF 1 : Write('remote'); {Network or ramdrive} 2 : Write('fixed(harddisk)'); 3 : Write('removable'); {zipdrive or floppy} 4 : Write('substed'); 5 : Write('cdrom'); END; Writeln; END; END;
Declaration
FUNCTION NrFloppies:LONGINT
Description
Retrieves the number of floppies from the BIOS-data area.
Some mainboards(most of them 486er) always return two even if only one diskdrive exists!
Declaration
FUNCTION NrFixedDisks:LONGINT;
Description
Retrieves the number of fixed disks from the BIOS-data area.
Declaration
FUNCTION LastDrv:LONGINT;
Description
Returns highest valid logical drive
Declaration
PROCEDURE TrueName(VAR path : String);
Description
This procedure is similar to FExpand, but can also expands substituted drives to their real path.(Depending on SubstExpand)
This procedure uses a (formally) undocumented dos-function, and you'd better use FExpand, unless you want to avoid substed drives for some reason, or distinguish between HD's,substed drives and cdroms.
Though undocumented, the dos function is used very often, and Dos 7.x contains a LongFileName version of it. It's generally considered to be secure.
Declaration
PROCEDURE GetLongPathName (Short: String; VAR Long: String);
Description
This procedure is basically a Truename which tries to return only long file names. (expands 8.3 notation with tildes to lfn when possible)
Depending on SubstExpand substed drives are also expanded
See also
Declaration
PROCEDURE GetShortPathName (Long: String; VAR Short: String);
Description
This procedure is basically a Truename which only returns 8.3 (tilde-notation) filenames. This can be used to secure parameters which will be passed to non lfn-utils.
Depending on SubstExpandsubsted drives are also expanded
See also
Declaration
FUNCTION ClusterSize(Drv : LONGINT) : LONGINT;
Description
Returns the clustersize (allocation size on harddisk). This is the smallest chunk that can be allocated on disk. (so a 1 byte files occupies clustersize bytes)
This procedure also works for FAT32 (it has LFN support), and is also corrected for CDROMs (Clustersize cdrom AFAIK always=2048) Example
Writeln(Clustersize(3)); { Write clustersize of C:}
Declaration
FUNCTION NrDrives:LONGINT;
Description
SHOULD return the number of logical drives, but Win95 always returns 32 AFAIK.
Declaration
PROCEDURE GetSwapData(VAR Swp :TSwapInfo);
Description
Tries to locate the swapfile, and it's dimensions. If the call fails (No dos/win paging installed) the record is filled with CHR(0)
Declaration
Function WinVer:WORD;
Description
Returns the windows version in BCD format (minor=LO(WinVer), major=HI(WinVer))
For Win95 it returns $400 (=4.00)
This can also be used to distinguish between dos 7.x dosmode and Win95 GUI.
Declaration
PROCEDURE GenerateShortName(VAR Long: String; VAR Short: String);
Description
Just like GetShortPathName, this procedure changes a longfilename to a short one. However GenerateShortName doesn't generate a tilde notation, but tries to fit as much characters as possible in the 8.3 space.
E.g. "Very long name.txt" becomes "verylong.txt" while GetShortPathName would do it like this: "verylo~1.txt"
I don't use this procedure. I created it when trying to find something like GetShortPathName, and included it here, because it's ready.
See also
Declaration
PROCEDURE GetCMOS(VAR CMOS :CMOSRec);
Description
Copies the first 64 bytes of the CMOS to the above packed CMOSRecord
Before copying, GetCMOS tests bit 2 of the RTCB register if the date-time values of CMOS are coded as BCDs. If so, GetCMOS automatically performs a BCD2Binary conversion.
Example:
VAR CMOS : CMOSRec; BEGIN GetCMOS(CMOS); END.
Declaration
FUNCTION Installed(Tsr:WORD):WORD;
Description
Calls the multiplexer interrupt $2F (=47d).
IF Tsr<255 THEN
call $2F with AH=Tsr, AL=0
ELSE
call $2F with AX=Tsr BX=0;
The function returns:
Example
Uses EDos,EFIO; BEGIN WrHex(Installed(Windows)); {Writes 400 (4.00) if Windows '95 is running} END.
Declaration
FUNCTION TestUART(Port : LONGINT):UART;
Description
Tests if an UART (processor behind the com-port) exists on port "Port", IOW does the comport corresponding with this address exist?
. P.s. Windows sometimes blocks some ports. I can't detect COM1 under Windows. (The mouse is attached to it)
If I try to detect PS/2 ports under Windows, my soundcard hiks. Probably it doesn't decode the upper bits of the com-port adress :-)
Declaration
FUNCTION IsDevice(CONST Fnamex: String): BOOLEAN;
Description
Returns TRUE if named file is actually a device. (Like CON,NUL, etc). Can be used to detect a device as input/output on commandline, or to verify existance of a certain devicedriver.
example
BEGIN IF IsDevice('XMSXXXX0') THEN Writeln('Some XMS driver (e.g. Himem.sys) has been load') ELSE Writeln('No standard XMS driver loaded'); END.