home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
PASCAL
/
PASTUT34
/
SYSDOS.TXT
< prev
next >
Wrap
Text File
|
1993-02-18
|
6KB
|
141 lines
THE SYSTEM AND DOS UNITS.
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
The Microsoft Disk Operating System (MS-DOS) is a group of programs that
controls the running and operation of the computer. It provides an
interface between the operator and the computer. Most of the MS-DOS
functions are actually executed from low-level language code using the
interrupt 21H with preset values in the AX register (see the notes on
Registers for further details). Directory and file manipulation is
fundamentally achieved in this way, as is date and time manipulation.
Whilst it is possible to use interrupt 21H via the procedure MSDOS
which is available in the DOS unit, most of the DOS functions are
to be found as procedures and functions in either the System unit or
the DOS unit, so avoiding the relative complexity of interrupt calls.
The System Unit.
════════════════
This unit implements low-level, run-time routines for file I/O, string
handling, arithmetic functions, dynamic memory management, etc.
It is the one exception to declaration in the Uses clause, as it is
always automatically included.
File I/O procedures include Reset, which opens an existing file.
File I/O functions include IOResult, which returns an integer value of 0
if the operation has been successful or non-zero if not.
String procedures include Str, which converts a numeric value to its
string representation.
String functions include Length, which returns the dynamic length of a
string.
The I/O procedures also include directory manipulation as follows:
ChDir Changes the current directory.
GetDir Returns the current directory of a specified drive.
MkDir Creates a subdirectory.
RmDir Removes an empty subdirectory.
All these procedure and functions are documented in the Library Reference,
which should be consulted to find the parameters required and in the case
of functions, the return type.
The IOResult function should be used to check the result of these operations.
The program DOSOPS.PAS contains examples of the use of the directory calls:
GetDir(0,dir); {I/O procedures from System unit - p131 Prog. Guide }
.... {The first parameter is the drive and 0 = current. }
.... {The second parameter is the current directory name.}
ChDir('\'); {The directory is changed to that of the parameter. }
GetDir(0,dir2);
....
ChDir(dir); {Change back to the original directory given by dir }
GetDir(0,dir3); {dir, dir2, dir3 are all string-type variables. }
Whilst the above program has switched to the root directory, the procedure
EXEC from the DOS unit is used to list selected files (see below).
The DOS Unit.
═════════════
The DOS unit contains over 30 procedures and functions for date and time
manipulation, interrupt support, file and process handling.
The DOS unit must be declared in the uses clause before it is used.
The function DosExitCode returns the exit code of a subprocess, with
0 indicating normal successful termination
1 if terminated by Ctrl-C
2 if due to a device error
3 if terminated by the Keep procedure, used by Terminate and Stay
Resident (TSR) programs.
The date and time procedures include GetDate, SetDate, GetTime and
SetTime, which are equivalent to the DOS interrupt 21H with the AH
register preset to hexadecimal values of 2A, 2B, 2C and 2D respectively.
The interrupt support procedures include Intr, which executes a specific
software interrupt as shown in the example INTRDEMO.PAS for the BIOS
function for checking the display mode.
....
Regs.AX := $0F00; { Sets AH = 0F for Get Display Mode function }
Intr($10,Regs); { Interrupt 10 for ROM BIOS Video Services }
.... { The $ sign indicates a hexadecimal value }
{ Regs of type Registers is a predeclared }
{ record of all the registers. }
This Intr procedure can also be used for DOS functions (interrupt 21H),
although special provision is made by the procedure MsDos for executing
a DOS function call.
The process-handling procedures include Exec, which executes a specified
program with a specified command line. This means that the parent program
can load another program, called the child, from a storage device and then
execute it. When the child program is concluded , the parent program
regains control and continues with its next statement.
The Exec procedure require two parameters:
1. The path, which of course includes the name of the program to be run.
2. The Command Line, including any parameters, switches and filenames
The Exec procedure is equivalent to the interrupt 21H with the AH register
preset to 4B and this function destroys the contents of all registers
except the Code Segment (CS) and the Instruction Pointer (IP). Thus the
parent program must push the contents of the registers onto the Stack
before calling the child program and then retrieved them afterwards.
The procedure SwapVectors is provided for this purpose, as shown below
in the extract from the program DOSOPS.PAS:
....
SwapVectors; {Process-handling procedure from DOS unit - p146 }
Exec('COMMAND.COM','/C DIR *.SYS'); {Also from DOS unit - p146}
If DosError <> 0 Then {see below}
Begin
Writeln('Error loading child program');
writeln('Dos error #', DosError);
End;
SwapVectors;
....
Note that the /C used in the command line string above is a special
requirement of COMMAND.COM, but not of other applications.
Errors are reported in DosError, with DosError = 8 indicating that there
is insufficient memory to load the child program.
Further details of the BIOS and DOS functions can be found in the
references:
1. 'Advanced MS-DOS' by Ray Duncan. Microsoft Press.
2. 'DOS and BIOS Functions' Que Quick Reference Series. Que Corporation.
SYSDOS.TXT
19.1.93