home *** CD-ROM | disk | FTP | other *** search
- {@@@@@@@@@@@@@@@@@ copyright 1984 by Neil J. Rubenking @@@@@@@@@@@@@@@@@@@@@
-
- Standard TURBO procedures for input/output do not support subdirectories.
-
- XSeek repaired 1/9/85 to take care of problem with LARGE files
-
- These file handling procedures are based on the DOS 2.0 "file handle" access
- concept. They are named after their standard TURBO equivalents, but with
- an X in front. Note that these files are not "typed"--they are just files
- of bytes. The "SIZE" parameter determines how many bytes are read at once.
-
- NOTE that any program that INCLUDEs these Extended I/O routines MUST
- also include the type definitions in REGPACK.TYP and FILENAME.TYP,
- and ERRMESSG.LIB, to interpret any error messages.
-
-
- Xreset(VAR FileName : filename_type; VAR handle : integer; VAR error : byte);
- NOTE: for a simple reset of an already-open file, use XSeek.
- Xrewrite(VAR FileName : filename_type; VAR handle : integer; VAR error:byte);
- INPUT : a filename, including full path.
- EFFECT : XRESET opens an already-existing file
- XREWRITE opens a new file, or writes over an existing file
- OUTPUT : an integer FILE HANDLE or a byte ERROR.
-
-
- Xclose(handle : integer ; VAR error : byte);
- INPUT : integer FILE HANDLE
- EFFECT : flushes buffers and closes the file
- OUTPUT : error #6 if handle is wrong
-
- Xread(handle,size : integer ; VAR buffer ; VAR error : byte);
- Xwrite(handle,size : integer ; VAR buffer ; VAR error : byte);
- INPUT : integer FILE HANDLE
- integer SIZE of buffer variable. You can pass this using TURBO's
- builtin SIZEOF(x) function, where x is a variable OR a TYPE.
- EFFECT : reads into or writes from the buffer.
- OUTPUT : byte error message
-
- Xerase(VAR filename : filename_type ; VAR error : byte);
- INPUT : filename, including drive and full path
- EFFECT : erases the named filename
- OUTPUT : byte error message
-
- Xseek(handle, offset,size : integer ; starting_at : char;
- VAR position : integer ; VAR error : byte);
- INPUT : integer FILE HANDLE
- integer OFFSET--how far to seek forward, in # of records
- integer SIZE of each record
- character STARTING_AT: [B]eginning, [E]nd, or [C]urrent position
- EFFECT : moves the file pointer to a position OFFSET*SIZE bytes after
- the position defined by STARTING_AT.
- OUTPUT : integer POSITION--position of file pointer in # of records after
- the move.
- byte ERROR message.
- NOTES : OFFSET and POSITION both have the potential to be 32-bit
- quantities, but since TURBO doesn't handle even true 16-bit
- quantities easily, I didn't implement this possibility. It is
- probably safe to assume that if you want BIG access to BIG files,
- your record size will be such that you won't have more than
- 32,767 records.
- To APPEND to a file, XSEEK Starting_At the [E]nd for an OFFSET
- of 1, SIZE of 1. You'll need a dummy variable for the returned
- POSITION.}
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
-
- var
- registers : regpack;
-
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
- procedure Xreset(VAR FileName : filename_type;
- VAR handle:integer;
- VAR error : byte);
-
- begin { The filename has to be in the form }
- FileName[length(FileName)+1] := #0; { of an "ASCIIZ" (ASCII+zero) string, }
- with registers do { so we add a chr(0) to the end. This}
- begin { function is not interested in the }
- DS := seg(FileName); { LENGTH byte of the string,so we give}
- DX := ofs(FileName)+1; { OFFSET+1 as the starting address. }
- {We need $3D in AH (the high byte of AX) and 2}
- AX := $3D shl 8 + 2; {in AL to select "open for reading & writing".}
- {"SHL" is SHift Left--shifting a byte 8 binary}
- {digits left makes it the high byte of an in- }
- {teger value. }
- MSDOS(registers);
- if Flags and 1 = 1 then {<< if the "carry flag" (the low bit of FLAGS)}
- {is set to one, that means an error message is}
- {being passed in AX }
- error := AX and $00FF {<-- Since the messages are "byte-sized", we }
- {can safely mask off the high byte of AX. }
- else
- begin
- handle := AX;
- error := 0;
- end;
- end;
- end;
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
- procedure Xclose(handle : integer; VAR error : byte);
- begin
- with registers do
- begin
- BX := handle;
- AX := $3E shl 8;
- MSDOS(registers);
- if Flags and 1 = 1 then
- error := AX mod 256
- else error := 0;
- end;
- end;
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
- procedure Xwrite(handle, size : integer;
- VAR buffer ; {the type of the data in file}
- VAR error : byte);
-
- begin
- with registers do
- begin
- AX := $40 shl 8;
- BX := handle;
- CX := Size;
- DS := seg(buffer);
- DX := ofs(buffer);
- MSDOS(registers);
- if Flags and 1 = 1 then
- error := AX and $00FF
- else
- if AX <> Size then
- error := AX and $00FF
- else error := 0;
- end;
- end;
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
- procedure Xread(handle, size : integer;
- VAR buffer ; {the type of the data in file}
- VAR error : byte);
-
- begin
- with registers do
- begin
- AX := $3F shl 8;
- BX := handle;
- CX := Size;
- DS := seg(buffer);
- DX := ofs(buffer);
- MSDOS(registers);
- if Flags and 1 = 1 then
- error := AX and $00FF
- else
- if AX <> Size then
- error := 255
- else error := 0;
- end;
- end;
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
- procedure Xrewrite(VAR FileName : filename_type;
- VAR handle:integer;
- VAR error : byte);
- begin
- FileName[length(FileName)+1] := #0;
- with registers do
- begin
- DS := seg(FileName);
- DX := ofs(FileName)+1;
- CX := $20; {archive}
- AX := $3C shl 8;
- MSDOS(registers);
- if Flags and 1 = 1 then
- error := AX and $00FF
- else
- begin
- handle :=AX;
- error := 0;
- end;
- end;
- end;
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
- procedure Xerase(VAR FileName : filename_type;
- VAR error : byte);
- begin
- FileName[length(FileName)+1] := #0;
- with registers do
- begin
- DS := seg(FileName);
- DX := ofs(FileName)+1;
- AX := $41 shl 8;
- MSDOS(registers);
- if Flags and 1 = 1 then
- error := AX and $00FF
- else
- begin
- error := 0;
- end;
- end;
- end;
- {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
- procedure Xseek(handle, offset, size : integer ; starting_at : char;
- VAR position : integer ; VAR error : byte);
- const
- HexTenThou : real = 65536.;
- var
- method_value : byte;
- MSInt, LSInt, tempPos : real;
- begin
- case upCase(starting_at) of
- 'B': method_value := 0; {starting at beginning}
- 'E': method_value := 2; {starting at end}
- else method_value := 1; {default is starting at current pos}
- end; {case}
- with registers do
- begin
- AX := $42 shl 8 + method_value;
- BX := handle;
- CX := trunc(offset*size/HexTenThou);
- DX := trunc(offset*size - CX);
- MSDOS(registers);
- if Flags and 1 = 1 then
- error := AX
- else
- begin
- error := 0;
- { 1/9/85 Noted that must take care of the case of DX or AX
- being greater than HexTenThou/2 and thus seeming negative }
- if DX >= 0 then MSInt := DX
- else MSInt := HexTenThou + DX;
- if AX >= 0 then LSInt := AX
- else LSInt := HexTenThou + AX;
- tempPos := (HexTenThou*MSInt + LSInt) / size;
- if (tempPos >= -32768.0) and (tempPos <= 32767.0) then
- if tempPos < 0 then position := trunc(HexTenThou + tempPos)
- else position := trunc(tempPos)
- else error := $FF;
- end;
- end;
- end;