$title(PCDOS Procedures Version 2.0)
		name	pcdos2_proc
;
dgroup		group	data
cgroup		group	code
;
diskinfo	struc
 nunits		dw	?
 totalunits	dw	?
 nbytes		dw	?
 nsectors	dw	?
diskinfo	ends
data		segment	public 'data'
save_bp		dw	?
save_ss		dw	?
save_sp		dw	?
data		ends
;
code		segment	public 'code'
		assume	cs:cgroup,ds:dgroup
;
; dtaptr = GetDta;
;
getdta		proc	near
		public	getdta
;
		mov	ah,2fh
		int	21h
		ret
getdta		endp
;
; dosversion = getversion;
;
getversion	proc	near
		public	getversion
;
		mov	ah,30h
		int	21h
		ret
getversion	endp
;
;
; call KeepProcess(exit_code,end_seg);
;
keepprocess	proc	near
		public	keepprocess
;
		push	bp
		mov	bp,sp
		mov	al,[bp+6]	; exit code
		mov	dx,[bp+4]	; end seg
		mov	ah,31h
		int	21h
		pop	bp
		ret	4
keepprocess	endp
;
;
; break_status = CtrlBreakCheck(Mode,Setting);
;
ctrlbreakcheck	proc	near
		public	ctrlbreakcheck
;
		push	bp
		mov	bp,sp
		mov	AL,[BP+6]	; mode
		mov	dl,[bp+4]	; setting
		mov	ah,33h
		int	21h
		pop	bp
		ret	4
ctrlbreakcheck	endp
;
;
; Vector = GetVector(VectorNum);
;
getvector	proc	near
		public	getvector
		push	bp
		mov	bp,sp
		mov	al,[bp+4]	; vector number
		mov	ah,35h
		int	21h
		pop	bp
		ret	2
getvector	endp
;
;
; Call GetDiskFreeSpace(drive,disk$infoP)
;
getdiskfreespace	proc	near
		public	getdiskfreespace
;
		push	bp
		mov	bp,sp
		mov	dl,[bp+12]	; drive
		mov	ah,36h
		int	21h
		mov	di,bx
		les	bx,dword ptr [bp+6]
		mov	es:[bx].nunits,di
		mov	es:[bx].totalunits,dx
		mov	es:[bx].nbytes,cx
		mov	es:[bx].nsectors,ax
		pop	bp
		ret	6
getdiskfreespace	endp
;
;
; status = mkdir(dir$p);
;
mkdir		proc	near
		public	mkdir
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+4]
		mov	ah,39h
		int	21h
		pop	ds
		pop	bp
		ret	4
mkdir		endp
;
;
; status = rmdir(dir$p);
;
rmdir		proc	near
		public	rmdir
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+4]
		mov	ah,3ah
		int	21h
		pop	ds
		pop	bp
		ret	4
rmdir		endp
;
;
; status = chdir(dir$p);
;
chdir		proc	near
		public	chdir
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+4]
		mov	ah,3bh
		int	21h
		pop	ds
		pop	bp
		ret	4
chdir		endp
;
;
; handle = creat(access,fil$p,status$p);
;
creat		proc	near
		public	creat
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+8]
		mov	cx,[bp+12]
		mov	ah,3ch
		int	21h
		pop	ds
		les	bx,dword ptr [bp+4]
		mov	cx,0
		jnc	creat_e
		mov	cx,ax
creat_e:	mov	es:[bx],cx
		pop	bp
		ret	10
creat		endp
;
;
;
; handle = openf(access,fil$p,status$p);
;
openf		proc	near
		public	openf
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+8]
		mov	al,[bp+12]
		mov	ah,3dh
		int	21h
		pop	ds
		les	bx,dword ptr [bp+4]
		mov	cx,0
		jnc	openf_e
		mov	cx,ax
openf_e:	mov	es:[bx],cx
		pop	bp
		ret	10
openf		endp
;
;
; call closef(handle,status$p);
;
closef		proc	near
		public	closef
		push	bp
		mov	bp,sp
		mov	bx,[bp+8]
		mov	ah,3eh
		int	21h
		les	bx,dword ptr [bp+4]
		mov	cx,0
		jnc	closef_e
		mov	cx,ax
closef_e:	mov	es:[bx],cx
		pop	bp
		ret	6
closef		endp
;
;
; actual = readf(handle,count,buffer$p,status$p);
;
readf		proc	near
		public	readf
		push	bp
		mov	bp,sp
		push	ds
		mov	bx,[bp+14]
		mov	cx,[bp+12]
		lds	dx,dword ptr [bp+8]
		mov	ah,3fh
		int	21h
		mov	cx,0
		jnc	readf_e
		mov	cx,ax
		mov	ax,0
readf_e:	les	bx,dword ptr [bp+4]
		mov	es:[bx],cx
		pop	ds
		pop	bp
		ret	12
readf		endp
;
;
;
; actual = writef(handle,count,buffer$p,status$p);
;
writef		proc	near
		public	writef
		push	bp
		mov	bp,sp
		push	ds
		mov	bx,[bp+14]
		mov	cx,[bp+12]
		lds	dx,dword ptr [bp+8]
		mov	ah,40h
		int	21h
		mov	cx,0
		jnc	writef_e
		mov	cx,ax
		mov	ax,0
writef_e:	les	bx,dword ptr [bp+4]
		mov	es:[bx],cx
		pop	ds
		pop	bp
		ret	12
writef		endp
;
; status = unlink(file$p);
;
unlink		proc	near
		public	unlink
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+4]
		mov	ah,41h
		int	21h
		jc	unl_ok
		mov	ax,0
unl_ok:		mov	ah,0
		pop	ds
		pop	bp
		ret	4
unlink		endp
;
;
; new$loc = lseek(handel,mode,foffset,status$p);
;
lseek		proc	near
		public	lseek
		push	bp
		mov	bp,sp
		mov	bx,[bp+14]
		mov	al,[bp+12]
		les	dx,dword ptr [bp+8]
		mov	cx,es
		mov	ah,42h
		int	21h
		mov	cx,0
		jnc	lseek_e
		mov	cx,ax
lseek_e:	les	bx,dword ptr [bp+4]
		mov	es:[bx],cx
		pop	bp
		ret	12
lseek		endp
;
;
; new$mode = chmod(funct,mode,file$p,status$p);
;
chmod		proc	near
		public	chmod
		push	bp
		mov	bp,sp
		mov	cx,[bp+12]
		mov	al,[bp+14]
		les	dx,dword ptr [bp+8]
		mov	ah,43h
		int	21h
		jc	chmod_e
		mov	ax,0
chmod_e:	les	bx,dword ptr [bp+4]
		mov	es:[bx],ax
		mov	ax,cx
		pop	bp
		ret	12
chmod		endp
;
;
; status = get$current$dir(drive,string$p);
;
getcurrentdir	proc	near
		public	getcurrentdir
		push	bp
		mov	bp,sp
		push	ds
		lds	si,dword ptr [bp+4]
		mov	dl,[bp+8]
		mov	ah,47h
		int	21h
		pop	ds
		pop	bp
		ret	6
getcurrentdir	endp
;
;
; memseg = allocatemem(size,status$p);
;
allocatemem	proc	near
		public	allocatemem
		push	bp
		mov	bp,sp
		mov	ax,[bp+8]
		mov	dx,0
		mov	cx,16
		div	cx
		cmp	dx,0
		jz	al_1
		inc	ax
al_1:		mov	bx,ax
		mov	ah,48h
		int	21h
		mov	cx,0
		jnc	al_e
		mov	cx,ax
		mov	ax,bx
al_e:		les	bx,dword ptr [bp+4]
		mov	es:[bx],cx
		pop	bp
		ret	6
allocatemem	endp
;
;
; status = freemem(memseg);
;
freemem		proc	near
		public	freemem
		push	bp
		mov	bp,sp
		mov	es,[bp+4]
		mov	ah,49h
		int	21h
		pop	bp
		ret	2
freemem		endp
;
;
; status = setblock(memseg,new$size,max$blk$p);
;
setblock	proc	near
		public	setblock
		push	bp
		mov	bp,sp
		mov	es,[bp+10]
		mov	bx,[bp+8]
		mov	ah,4ah
		int	21h
		jnc	setblock_e
		les	di,dword ptr [bp+4]
		mov	es:[di],bx
setblock_e:	pop	bp
		ret	8
setblock	endp
;
;
; status = loadf(file$p,lpb$p,mode);
;
loadf		proc	near
		public	loadf
		push	bp
		mov	bp,sp
		push	ds
		mov	al,[bp+4]
		or	al,al
		jz	save_l
		les	bx,dword ptr [bp+6]
		lds	dx,dword ptr [bp+10]
		mov	ah,4bh
		int	21h
		pop	ds
		pop	bp
		ret	10
save_l:		cli
		mov	save_bp,bp
		mov	save_sp,sp
		mov	save_ss,ss
		sti
		les	bx,dword ptr [bp+6]
		lds	dx,dword ptr [bp+10]
		mov	ah,4bh
		int	21h
loadreturn	label	far
		public	loadreturn
		mov	ax,data
		mov	ds,ax
		cli
		mov	bp,save_bp
		mov	sp,save_sp
		mov	ss,save_ss
		sti
		pop	ds
		pop	bp
		ret	10
loadf		endp
;
;
; call terminateprocess(exit_code,orig_data);
;
terminateprocess	proc	near
		public	terminateprocess
		push	bp
		mov	bp,sp
		mov	ax,[bp+4]
		mov	ds,ax
		mov	al,[bp+6]
		mov	ah,4ch
		int	21h
tp_e:		jmp	tp_e
terminateprocess	endp
;
; rcode = getreturncode;
;
getreturncode	proc	near
		public	getreturncode
		mov	ah,4dh
		int	21h
		ret
getreturncode	endp
;
; status = findfirst(attr,@fname,dta$ptr);
;
findfirst	proc	near
		public	findfirst
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+4]
		mov	ah,1ah
		int	21h
		lds	dx,dword ptr [bp+8]
		mov	cx,[bp+12]
		mov	ah,4eh
		int	21h
		pop	ds
		pop	bp
		ret	10
findfirst	endp
;
; status = findnext(dta$ptr);
;
findnext	proc	near
		public	findnext
		push	bp
		mov	bp,sp
		lds	dx,dword ptr [bp+4]
		mov	ah,1ah
		int	21h
		mov	ah,4fh
		int	21h
		pop	bp
		ret	4
findnext	endp
;
; status = renamef(old$f,new$f);
;
renamef		proc	near
		public	renamef
		push	bp
		mov	bp,sp
		push	ds
		lds	dx,dword ptr [bp+8]
		les	di,dword ptr [bp+4]
		mov	ah,56h
		int	21h
		jc	ren01
		mov	ax,0
ren01:		mov	ah,0
		pop	ds
		pop	bp
		ret	8
renamef		endp
;
;
; ftime = getftime(handle,funct,status$p);
;
getftime	proc	near
		public	getftime
		push	bp
		mov	bp,sp
		mov	bx,[bp+10]
		mov	al,[bp+8]
		mov	ah,57h
		int	21h
		jc	getftime_e
		mov	ax,0
getftime_e:	les	bx,dword ptr [bp+4]
		mov	es:[bx],ax
		mov	ax,cx
		pop	bp
		ret	8
getftime	endp
code		ends
		end
