h26004
s 00156/00000/00000
d D 1.1 83/03/17 14:37:15 tes 1 0
c date and time created 83/03/17 14:37:15 by tes
e
u
4
U
t
T
I 1
Bdos		Equ	224		; Int code for Bdos

GSX_Code	CSeg	Byte	Public

		Extrn	GSX_Bdos	:Near

; FOpen		Open a CP/M-86 file

;	Call FOpen(FcbPtr,BufferPtr)	{Near PL/M invocation}

;	Dword Ptr FcbPtr points to the Fcb of the file to be opened.
;	Dword Ptr BufferPtr points to the buffer structure to be used for
;	 reading the file.

; Open for reading the file pointed to by FcbPtr.  Initialize the buffer
; pointer.  Carry set upon return if file not found.

		Public	FOpen

	Include	BStruct.A86

OldDs		Equ	Ss:(Word Ptr 8)[Bp]
OldAx		Equ	Ss:(Word Ptr 6)[Bp]
OldBx		Equ	Ss:(Word Ptr 4)[Bp]
OldCx		Equ	Ss:(Word Ptr 2)[Bp]
OldBp		Equ	Ss:(Word Ptr 0)[Bp]
ReturnAddress	Equ	Ss:(Dword Ptr (OldDs+2))[Bp]
BufferPtr	Equ	Ss:(Dword Ptr (ReturnAddress+2))[Bp]
FcbPtr		Equ	Ss:(Dword Ptr (BufferPtr+4))[Bp]

FOpen:	Push	Ds			; Save caller's registers
	Push	Ax
	Push	Bx
	Push	Cx
	Push	Bp			;  & frame
	Mov	Bp,Sp			; Set up local frame

	Lds	Bx,FcbPtr		; Point to Fcb

	Mov	(Byte Ptr .12)[Bx],0	; Clear "ex" for extent 0

	Mov	Cl,00fh			; Bdos "Open File" opcode
	Call	FBdos			; Let Bdos open the file

	Mov	(Byte Ptr .32)[Bx],0	; Clear "cr" for sequential read

	Lds	Bx,BufferPtr		; Get pointer to buffer structure
	Mov	(Byte Ptr .BSBufferPtr)[Bx],BSBufferSize; Init buff structure
	Mov	(Byte Ptr .BSUpZ)[Bx],01ah

	Rol	Al,1			; High bit of Al to carry

	Pop	Bp			; Restore caller's registers
	Pop	Cx
	Pop	Bx
	Pop	Ax
	Pop	Ds
	Ret	8			;  & return to caller

	Eject

; FGetRec	Get the next record from a sequential file

;	Call FGetRec(FcbPtr,BufferPtr)	{Near PL/M invocation}

; Read next record from file described by Fcb.  Return carry set if EOF.

	Public	FGetRec

FGetRec:
	Push	Ds			; Save caller's registers
	Push	Ax
	Push	Bx
	Push	Cx
	Push	Bp			;  & frame
	Mov	Bp,Sp			; Set up local frame

	Mov	Bx,Word Ptr (BufferPtr+2); Get segbase of buffer
	Mov	Cl,033h			; Bdos "SetDMA Base" opcode
	Call	FBdos			; Tell Bdos our DMA buffer base

	Mov	Bx,Word Ptr BufferPtr	; Get offset of buffer structure
	Lea	Bx,BSBuffer[Bx]		; Get offset of buffer
	Mov	Cl,01ah			; Bdos "Set DMA Address" opcode
	Call	FBdos			; Tell Bdos our DMA offset

	Lds	Bx,FcbPtr		; Point to Fcb
	Mov	Cl,014h			; Bdos "Read Sequential" opcode
	Call	FBdos			; Get next record from file

	Shr	Al,1			; Carry <- EOF
	Sbb	Al,Al			; Al, Carry <- -1 if EOF

	Lds	Bx,BufferPtr		; Get base & offset of buffer structure
	Mov	Byte Ptr BSBufferPtr[Bx],Al; Unless EOF, pt to 1st byte of rec

	Pop	Bp			; Restore caller's registers
	Pop	Cx
	Pop	Bx
	Pop	Ax
	Pop	Ds
	Ret	8			;  & return to caller

	Eject

; FClose	Close a CP/M-86 file

;	Call	FClose(CFcbPtr)		{Far PL/M invocation}

;	Dword Ptr CFcbPtr points to the Fcb for the file to be closed.

; Close the file at Fcb.  Carry returned set if close error.

CFcbPtr		Equ	Ss:(Dword Ptr (ReturnAddress+4))[Bp]

		Public	FClose

FClose:	Push	Ds			; Save caller's registers
	Push	Ax
	Push	Bx
	Push	Cx
	Push	Bp			;  & frame
	Mov	Bp,Sp			; Set up local frame

	Lds	Bx,CFcbPtr		; Point to Fcb

	Mov	Cl,010h			; Bdos "Close File" opcode
	Call	FBdos			; Let Bdos close the file

	Rol	Al,1			; If 0ffh, set carry

	Pop	Bp			; Restore caller's registers
	Pop	Cx
	Pop	Bx
	Pop	Ax
	Pop	Ds
	Retf	4			;  & return to caller

; Invoke Bdos with Ds:Dx pointing at Ds:Bx.
; Preserve all registers except Cx & Ax.
FBdos:	Push	Bx			; Preserve registers crashed by CP/M-86
	Push	Dx
	Push	Ds
	Push	Es

	Xchg	Dx,Bx			; Point Ds:Dx at Buff or Fcb
	Push	Cs
	Call	GSX_Bdos		; Invoke file operation

        Pop     Es                      ; Restore caller's registers
        Pop     Ds
        Pop     Dx
        Pop     Bx
        Ret                             ; Return with whatever in Ax

	End
E 1
