	title	BDOSALL
	subttl	RSX reporting all BDOS functions
	.z80

; Program : BDOSALL.MAC

; RSX module for report of all BDOS functions
;
; Program by	Werner Cirsovius
;		Hohe Weide 44
;		D-2000 Hamburg 20

;		Tel.:049/040/4223247

;		Version 1.0, December 1988

; ===== Constants =====

warm	equ	0000h

conin	equ	1
conout	equ	2
print	equ	9
consta	equ	11

ctrlC	equ	'C'-'@'
lf	equ	0ah
cr	equ	0dh
eot	equ	'$'

; ===== RSX starts here =====

; ===== RSX header starts =====

	db	0,0,0,0,0,0	; Six byte serial number
	jp	start		; Jump to RSX program
bdos:	jp	$-$		; Jump to next RSX
	dw	0		; Address of previous RSX
	db	0ffh		; Remove flag (0 keep permanent)
	db	0		; Non bank only flag
	db	'BDOSREP '	; Any eight character name
	db	0		; Loader flag
	dw	0		; Spare (reserved)

; ===== RSX header ends =====

start:
	ex	(sp),hl		; Get callers PC
	ld	(calpc),hl	; .. save it
	ex	(sp),hl
	ld	(calsp),sp	; Save stack
	ld	sp,mystak	; Get local stack
	push	bc		; Push all
	push	de
	push	hl
	push	af
	ld	a,c		; Get BDOS code
	ld	hl,bdost1
	ld	bc,bdosl1
	cpir			; Find code
	jr	z,do.rep
	ld	de,ill.cod
	call	string		; Tell ILLEGAL
	jr	do.test
do.rep:
	call	report		; Report it
do.test:
	call	break		; Test abort
	pop	af
	pop	hl
	pop	de
	pop	bc
	ld	sp,(calsp)
	jr	bdos		; Perform user call
	;
break:	; Test user BREAK requested, abort if verified
	;
	ld	c,consta
	call	bdos		; Get state of console
	or	a		; Any character there ?
	ret	z		; .. no
	ld	c,conin
	call	bdos		; Get it
	cp	ctrlC		; Test Ctrl-C
	ret	nz		; .. no
	ld	de,brkmes
	call	string		; Tell user break found
	ld	c,conin
	call	bdos		; Verify it
	push	af
	call	type3
	pop	af
	and	05fh
	cp	'Y'
	ret	nz
	ld	de,dobrk
	call	string		; Tell aborting
	jp	warm		; Exit program
	;
string:	; Output string pointed to by reg DE
	;
	push	bc
	push	hl
	ld	c,print
	call	bdos		; Print it
	pop	hl
	pop	bc
	ret
	;
hexout:	; Print hex byte from accu
	;
	push	af
	rra			; Get hi part
	rra
	rra
	rra
	call	hxnibl
	pop	psw		; .. and lo part
hxnibl:
	and	0fh		; Extract lo
	add	a,'0'		; Set ASCII
	cp	'9'+1		; Test hex
	jr	c,consot
	add	a,7
consot:
	push	bc
	push	de
	push	hl
	ld	e,a
	ld	c,conout
	call	bdos		; Print character
	pop	hl
	pop	de
	pop	bc
	ret
	;
report:	; Perform the main report
	;
	inc	bc		; Fix index
	ld	hl,bdosl1
	or	a
	sbc	hl,bc		; .. make normal
	push	de		; Save FCB
	push	hl		; .. and index
	ld	de,bdospc
	call	string		; Tell PC
	ld	a,(calpc+1)
	call	hexout
	ld	a,(calpc)
	call	hexout
	ld	de,bdosfn
	call	string		; Tell function
	pop	hl
	add	hl,hl		; Adjust index
	add	hl,hl
	ld	bc,bdost2
	add	hl,bc		; Get table index
	ld	e,(hl)		; Get string
	inc	hl
	ld	d,(hl)
	inc	hl
	ld	c,(hl)		; .. and execution address
	inc	hl
	ld	b,(hl)
	push	bc
	call	string		; Tell kinda function
	pop	hl		; Get routine
	pop	de		; .. and FCB
	jp	(hl)		; RUN
	;
type1:	; Execute function with two file names (RENAME)
	;
	call	file		; Tell file
	call	fcbout		; Tell the name
	ld	hl,16
	add	hl,de
	push	hl		; Save 2nd file name
	ld	de,renmes
	call	string		; Tell renamed
	pop	de
	jr	dotyp2
	;
type2:	; Execute function with one file name
	;
	call	file		; Tell file
dotyp2:
	call	fcbout
	;
type3:	; Execute function without name
	;
	ld	de,crlf
	call	string		; Close line
	ret
	;
file:	; Tell file prefix
	;
	push	de
	ld	de,filmes
	call	string
	pop	de
	ret
	;
fcbout:	; Tell file name from FCB pointed to by reg DE
	;
	push	de
	ld	hl,'  '		; Set default
	ld	a,(de)		; Test default drive
	or	a
	jr	z,deffcb	; Yes, skip
	add	a,'@'		; Make real
	ld	h,a
	ld	l,':'
deffcb:
	ld	a,h
	call	consot		; Print drive
	ld	a,l
	call	consot		; .. and delimiter
	inc	de
	ld	b,8
	call	filnam		; Print file name
	ld	a,'.'
	call	consot		; Print delimiter
	ld	b,3
	call	filnam
	pop	de
	ret
	;
filnam:	; Print portion from FCB
	;
	ld	a,(de)
	and	07fh
	call	consot		; Print name/extension
	inc	de
	djnz	filnam
	ret

; ===== Data fields =====

bdost1:	db	0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
	db	18,19,20,21,22,23,24,25,26,27,28,29,30,31,33
	db	34,35,36,37,38,39,40,44,45,46,47,48,49,50,59
	db	60,98,99,100,101,102,103,104,105,106,107,108
	db	109,110,111,112,152
bdosl1	equ	$-bdost1

bdost2:	dw	bdos0,type3,bdos1,type3,bdos2,type3
	dw	bdos3,type3,bdos4,type3,bdos5,type3
	dw	bdos6,type3,bdos7,type3,bdos8,type3
	dw	bdos9,type3,bdos10,type3,bdos11,type3
	dw	bdos12,type3,bdos12,type3,bdos13,type3
	dw	bdos14,type3,bdos15,type2,bdos16,type2
	dw	bdos17,type2,bdos18,type3,bdos19,type2
	dw	bdos20,type2,bdos21,type2,bdos22,type2
	dw	bdos23,type1,bdos24,type3,bdos25,type3
	dw	bdos26,type3,bdos27,type3,bdos28,type3
	dw	bdos29,type3,bdos30,type3,bdos31,type3
	dw	bdos33,type2,bdos34,type2,bdos35,type3
	dw	bdos36,type3,bdos37,type3,bdos38,type3
	dw	bdos39,type3,bdos40,type3,bdos44,type3
	dw	bdos45,type3,bdos46,type3,bdos47,type3
	dw	bdos48,type3,bdos49,type3,bdos50,type3
	dw	bdos59,type3,bdos60,type3,bdos98,type3
	dw	bdos99,type3,bdos100,type3,bdos101,type3
	dw	bdos102,type3,bdos103,type3,bdos104,type3
	dw	bdos105,type3,bdos106,type3,bdos107,type3
	dw	bdos108,type3,bdos109,type3,bdos110,type3
	dw	bdos111,type3,bdos112,type3,bdos152,type3
bdos0:	db	'System reset',eot		;
bdos1:	db	'Console input',eot		;
bdos2:	db	'Console output',eot		;
bdos3:	db	'Auxiliary input',eot		;
bdos4:	db	'Auxiliary output',eot		;
bdos5:	db	'List output',eot		;
bdos6:	db	'Direct console I/O',eot	;
bdos7:	db	'Auxiliary input status',eot	;
bdos8:	db	'Auxiliary output status',eot	;
bdos9:	db	'List output string',eot	;
bdos10:	db	'Console buffer input',eot	;
bdos11:	db	'Console input status',eot	;
bdos12:	db	'Return version number',eot	;
bdos13:	db	'Reset disk status',eot		;
bdos14:	db	'Select disk',eot		;
bdos15:	db	'Open file       ',eot
bdos16:	db	'Close file      ',eot
bdos17:	db	'Search file     ',eot
bdos18:	db	'Search next',eot
bdos19:	db	'Delete file     ',eot
bdos20:	db	'Read sequential ',eot
bdos21:	db	'Write sequential',eot
bdos22:	db	'Make file       ',eot
bdos23:	db	'Rename file     ',eot
bdos24:	db	'Return login vector',0		;
bdos25:	db	'Return current disk',0		;
bdos26:	db	'Set DMA transfer address',0	;
bdos27:	db	'Get allocation vector',eot
bdos28:	db	'Write protect disk',eot	;
bdos29:	db	'Get R/O vector',eot		;
bdos30:	db	'Set FCB file attributes',eot	;
bdos31:	db	'Get DPH',eot
bdos32:	db	'Set/Get user number'		;
bdos33:	db	'Read random     ',eot
bdos34:	db	'Write random    ',eot
bdos35:	db	'Compute file size',eot		; --->> alles neu
bdos36:	db	'Set random record',eot
bdos37:	db	'Reset drive',eot
bdos38:	db	'Access drive',eot
bdos39:	db	'Free drive',eot
bdos40:	db	'Write random with zero fill',eot
bdos44:	db	'Multi-sector count',eot
bdos45:	db	'Set BDOS error code',eot
bdos46:	db	'Get disk free space',eot
bdos47:	db	'Chain to program',eot
bdos48:	db	'Flush buffers',eot
bdos49:	db	'Get/Set System control block',eot
bdos50:	db	'Direct BIOS call',eot
bdos59:	db	'Load overlay',eot
bdos60:	db	'Direct RSX call',eot
bdos98:	db	'Free temporary datablocks',eot
bdos99:	db	'Truncate file FCB',eot
bdos100:db	'Set directory label',eot
bdos101:db	'Return directory label',eot
bdos102:db	'Read file data stamp and password mode',eot
bdos103:db	'Write file password XFCB',eot
bdos104:db	'Set date and time',eot
bdos105:db	'Get date and time',eot
bdos106:db	'Set default password',eot
bdos107:db	'Return serial number',eot
bdos108:db	'Get/Set program return code',eot
bdos109:db	'Set/Get console mode',eot
bdos110:db	'Get/Set output delimiter',eot
bdos111:db	'Output string to console device',eot
bdos112:db	'Output string to list device',eot
bdos152:db	'Parse filename',eot

ill.cod:db	'*** Illegal BDOS code ***',cr,lf,eot
brkmes:	db	'Control C detected, BREAK [Y/N] ',eot
dobrk:	db	'++ User Break, ABORT ++'
crlf:	db	cr,lf,eot
bdospc:	db	'BDOS call at #',eot
bdosfn:	db	', ',eot
filmes:	db	', file : ',eot
renmes:	db	' -> ',eot

calpc:	ds	2		; Callers PC
calsp:	ds	2		; Callers stack
	ds	64		; Local stack
mystak:	end

