h16731
s 00111/00000/00000
d D 1.1 83/03/17 14:38:09 tes 1 0
c date and time created 83/03/17 14:38:09 by tes
e
u
4
U
t
T
I 1
GSX_Code	CSeg	Byte	Public

; PSize	   Check a program's size.  Usually a driver via Gdos Open Workstation.

;	Call PSize(FcbPtr,HeaderPtr)	{Far PL/M invocation}

;	Dword Ptr FcbPtr points to Fcb of program to load.  PSize opens it.
;	Dword Ptr HeaderPtr points to BuffStrucSize area for .CMD header.

; Upon return, Bx contains size in paragraphs of program, if valid.  Al and
; flags contain error indicators:
;	0	No errors
;	4	File specified in Fcb not found
;	5	Unexpected Eof on file (previous driver not crashed)
;	6	Syntax error (absolute bucket) in file
NoErrors	Equ	0
Fnf		Equ	4
UnexpectedEof	Equ	5
Syntax		Equ	6

; All buckets required by the program (G-Min only) are summed and the size is
; returned.

		Public	PSize

		Extrn	FOpen		:Near
		Extrn	FGetRec		:Near

; Buffer structure offsets

	Include	BStruct.A86

OldDs		Equ	Ss:(Word Ptr 6)[Bp]
OldCx		Equ	Ss:(Word Ptr 4)[Bp]
OldSi		Equ	Ss:(Word Ptr 2)[Bp]
OldBp		Equ	Ss:(Word Ptr 0)[Bp]
ReturnAddress	Equ	Ss:(Dword Ptr (OldDs+2))[Bp]
HeaderPtr	Equ	Ss:(Dword Ptr (ReturnAddress+4))[Bp]
FcbPtr		Equ	Ss:(Dword Ptr (HeaderPtr+4))[Bp]

GForm	Equ	Ds:(Byte Ptr (BSBuffer))[Si]
GLength	Equ	Ds:(Word Ptr (BSBuffer+1))[Si]
ABase	Equ	Ds:(Word Ptr (BSBuffer+3))[Si]
GMin	Equ	Ds:(Word Ptr (BSBuffer+5))[Si]
GMax	Equ	Ds:(Word Ptr (BSBuffer+7))[Si]
GDLen	Equ	9

	Eject

PSize:	Push	Ds			; Preserve caller's registers
	Push	Cx
	Push	Si
	Push	Bp			;  & Bp
	Mov	Bp,Sp			; Point into stack

	Lds	Si,FcbPtr		; Ds:Si <- pointer to Fcb
	Push	Ds			; FOpen needs Fcb pointer
	Push	Si

	Push	Ds			; FGetRec also needs Fcb pointer
	Push	Si

	Lds	Si,HeaderPtr		; FOpen needs ptr to buffer structure
	Push	Ds
	Push	Si

	Mov	Al,Fnf			; Assume file not found

	Call	FOpen			; Open the file
	Jc	SizeQuit		; Jump if file not found

	Push	Ds			; FGetRec needs ptr to buffer structure
	Push	Si

	Mov	Al,UnexpectedEof	; Assume unexpected Eof error

	Call	FGetRec			; Read header record into header struct
	Jc	SizeQuit		; Jump if unexpected Eof

	Xor	Bx,Bx			; Start with zero size
	Mov	Cx,8			; Scan 8 buckets
	Mov	Al,Syntax		; Assume syntax error

SizeLoop:
	Test	GForm,00fh		; Bucket present?
	Jz	NextBucket		; Jump if nope

	Test	ABase,0ffffh		; Absolute bucket?
	Jnz	SizeQuit		; Jump if yes

	Add	Bx,GMin			; Include this bucket

NextBucket:
	Add	Si,GDLen		; Point to next bucket
	Loop	SizeLoop		;  & loop until all buckets looked at

	Mov	Al,NoErrors		; No errors found

SizeQuit:
	Mov	Sp,Bp			; Restore caller's
	Pop	Bp			;  stack frame
	Pop	Si			;  & registers
	Pop	Cx
	Pop	Ds

	Or	Al,Al			; Set flags

	Retf	8			;  & return to caller

	End
FOpen
E 1
