	title	Disk-Editor
	name	('SUPERZAP')

;; l198e:	l244d:

;; UNKNOWN: l06f6 l0792 l0a99		l07ea !!

FALSE	equ	0
TRUE	equ	NOT FALSE

OS	equ	0000h
BDOS	equ	0005h
TPATOP	equ	BDOS+1
DMA	equ	0080h

.vers	equ	12
.resdsk	equ	13
.open	equ	15
.close	equ	16
.srcfrs	equ	17
.srcnxt	equ	18
.curdsk	equ	25
.setdma	equ	26
.usrcod	equ	32
.rdrnd	equ	33
.wrrnd	equ	34
.filsiz	equ	35
.bios	equ	50

OSerr	equ	255

_get	equ	-1

.drv	equ	 1
.nam	equ	 8
.ext	equ	 3
_EX	equ	12
_RRN	equ	33
DIRlen	equ	32

reclng	equ	128

CPMv	equ	30h

MAXUSR	equ	15

null	equ	00h
bell	equ	07h
tab	equ	09h
lf	equ	0ah
cr	equ	0dh
esc	equ	1bh
DEL	equ	7fh

NIL	equ	0000h

PAGLEN	equ	 8
DSPLINE	equ	16
CLRLINE	equ	16
LASTCOL	equ	79

BITMASK	equ	00000011b
LOMASK	equ	00001111b
MSB	equ	10000000b
NOMSB	equ	01111111b
UPPMASK	equ	01011111b
TABMASK	equ	00000111b

_XY	macro	row,col
	db	row,col
	endm

l0000	equ	00h
l0001	equ	01h
l0003	equ	03h
l0006	equ	06h
l0008	equ	08h
l0010	equ	10h
l0011	equ	11h
l005c	equ	5ch
l0080	equ	80h
lffff	equ	0ffffh

;;	jp	l0201
;
	db	'Z3ENV'
l0108:
	db	4,esc,'H',esc,'E'
l010d:
	db	2,esc,'K'
l0110:
	db	2,esc,'p'
l0113:
	db	2,esc,'q'
l0116:
	db	2,esc,'r'
l0119:
	db	2,esc,'u'
l011c:
	db	0
l011d:
	db	0
l011e:
	db	2,esc,'e'
l0121:
	db	2,esc,'f'
l0124:
	db	2,esc,'Y'
l0127:
	db	1		; ROW/COL
l0128:
	db	' '		; Row offset
l0129:
	db	' '		; Column offset
l012a:
	db	1		; ASCII mode
l012b:
	db	lf,cr
	db	cr+MSB,cr
l012f:
	dw	l2ee5
l0131:
	_XY	0,33
	db	'SuperZap 5.1',null
l0140:
	dw	0		; Pointer to start of free data
l0142:
	db	0		; OS version
l0143:
	db	OSerr		; IOResult
l0144:
	db	0		; Console character
;
; Next eight bytes ????????????
;
l0145:
	db	0
l0146:
	dw	0		; Record number
l0148:
	db	0		; Record position
l0149:
	db	0
l014a:
	db	0
l014b:
	ds	3		; Display page
l014e:
	dw	0
l0150:
	dw	0		; Record number
l0152:
	db	0		; R/O bit (80H is R/O)
l0153:
	dw	0		; Temp pointer
l0155:
	dw	0		; File pointer
l0157:
	dw	0		; File pointer
l0159:
	dw	0		; File pointer
l015b:
	db	0		; File count
l015c:
	db	0		; Directory cursor
l015d:
	db	0		; Directory page position
l015e:
	db	0		; Directory index
l015f:
	db	0		; Callers disk
l0160:
	db	0		; Current disk
l0161:
	db	0,0,null	; Cursor coordinates
l0164:
	dw	NIL		; Message pointer (to be displayed)
l0166:
	dw	NIL		; Message pointer (to be cleared)
l0168:
	db	0		; Disk type
l0169:
	db	'???????????'
l0174:
	db	'DSK:'
ll0174	equ	$-l0174
;
l0178:
	dw	0		; Base page
l017a:
	dw	0		; Current page
l017c:
	dw	0		; Top page
l017e:
	db	FALSE		; Request panel
l017f:
	dw	0		; Address of disk buffer
l0181:
	db	0		; Clipboard action (0 is none)
l0182:
	dw	0		; Clipboard record
l0184:
	db	0		; Clipboard disk
l0185:
	ds	.nam+1+.ext	; Clipboard filename
	db	null
l0192:
	db	'Drive ',null
l0199:
	db	' Track ',null
l01a1:
	db	' Sector ',null
l01aa:
	db	'Empty',null
l01b0:
	ds	33		; Temp FCB
;
; BIOS vectors (On CP/M 2.x only these will be changed)
;
l01d1:
	call	l18e3		; Warm start
l01d4:
	call	l18e3		; Console state
l01d7:
	call	l18e3		; Console input
l01da:
	call	l18e3		; Console output
	call	l18e3		; Printer output
	call	l18e3		; Puncher output
	call	l18e3		; Reader input
l01e6:
	call	l18e3		; Home disk head
l01e9:
	call	l18e3		; Select drive
l01ec:
	call	l18e3		; Select track
l01ef:
	call	l18e3		; Select sector
l01f2:
	call	l18e3		; Set DMA address
l01f5:
	call	l18e3		; Read sector
l01f8:
	call	l18e3		; Write sector
	call	l18e3		; Printer status
l01fe:
	call	l18e3		; Sector tanslation
;
; Start of SUPERZAP
;
l0201:
	ld	hl,(TPATOP)	; Get top of memory
	ld	l,0
	ld	sp,hl		; For stack
	ld	c,.vers
	call	BDOS		; Get version number
	ld	a,CPMv-1	; Test version
	sub	l
	ld	a,h
	jr	nc,l0213
	inc	a
l0213:
	ld	(l0142),a	; Save version
	or	a
	jr	nz,l0224	; Skip CP/M PLUS
	ld	hl,(OS+1)	; Get vector
	ld	de,l01d1
	ld	bc,l0201-l01d1
	ldir			; Unpack CP/M 2.x BIOS vectors
l0224:
	ld	hl,l0169
	call	l1e84		; Set wildcard file name
	ld	hl,(l012f)	; Get start of heap
	ld	(l017f),hl	; Set for disk buffer
	ld	de,l0080
	add	hl,de		; Let some room
	ld	(l0140),hl	; Set start of free data
	xor	a
	ld	(l0181),a	; Clear clipboard action
	ld	hl,NIL
	ld	(l0164),hl	; Clear message pointers
	ld	(l0166),hl
	ld	c,.curdsk
	call	BDOS		; Get current disk
	ld	(l015f),a
	ld	(l0160),a
	ld	a,(l005c)	; Get disk
	or	a
	jr	z,l0259		; Skip if current one
	dec	a
	ld	(l0160),a	; Set current disk
l0259:
	ld	hl,l0080	; Point to command line
l025c:
	inc	hl
	ld	a,(hl)		; Get character from CCP
	or	a		; Test end
	jr	z,l027d		; Yeap
	cp	' '
	jr	z,l025c
	inc	hl
	ld	a,(hl)
	cp	':'		; Test drive delimiter
	jr	z,l026e		; Yeap
	dec	hl
	jr	l026f
l026e:
	inc	hl
l026f:
	ld	de,l0174
	ld	bc,ll0174
	call	l2365		; Find DSK:
	call	z,l257f		; Yeap, set type
	jr	z,l0295
l027d:
	call	l2579		; Set disk type
	ld	hl,l005c+.drv
	ld	a,(hl)		; Test file name given
	cp	' '
	jr	z,l0295		; Nope
	ld	b,.nam+.ext
l028a:
	ld	a,(hl)
	cp	'?'		; Test wildcard in name
	jr	z,l029f		; Yeap
	inc	hl
	djnz	l028a
	call	l257c		; Set disk type
l0295:
	ld	a,(l0160)	; Get current disk
	call	l219f		; Select it
	jr	z,l02a7		; Not valid
	jr	l02b3
l029f:
	ld	hl,l005c+.drv
	call	l1e84		; Unpack name and extension
	jr	l0295
l02a7:
	ld	a,(l015f)	; Get callers disk
	call	l219f		; Select it
	ld	hl,l02ca
	ld	(l0164),hl	; Set invalid drive
l02b3:
	ld	a,(l0168)	; Get type
	ld	hl,l02e8
	call	l251f		; Find type
	jr	nz,l02c6	; Nope
	ld	de,l02ed
	call	l2531		; Execute thru table
	jr	l02b3
l02c6:
	call	l263c		; Clear screen
	rst	0		; Leave SUPERZAP
;
l02ca:
	db	'** Invalid drive specified **',null
l02e8:
	db	4,'X','F','D','P'
l02ed:
	dw	l02f5		; X - End run
	dw	l02fa		; F - File display mode
	dw	l0b7d		; D - Directory mode
	dw	l186d		; P - Physical sector mode
;
; File type X - End run
;
l02f5:
	xor	a
	ld	(l0168),a	; Clear type
	ret
;
; File type F - File display mode
;
l02fa:
	ld	hl,(l03b0)
	ld	(l0161),hl	; Init cursor
	ld	a,TRUE
	ld	(l017e),a	; Set request panel
	ld	(l05ea),a	; Request SI display
	call	l1833		; Open file
	ld	a,(l186c)	; Get I/O flag
	or	a		; Test success
	jp	nz,l2579	; Nope
l0312:
	ld	a,(l017e)	; Get request panel
	or	a
	jr	z,l0348
	xor	a
	ld	(l017e),a	; Reset request panel
	call	l264d		; Print header
	ld	hl,l03d0
	call	l268a		; Print menu
	ld	hl,l03b2
	ld	a,(l0387)	; Test .COM
	or	a
	jr	z,l0331		; Nope
	ld	hl,l03c1
l0331:
	call	l2653		; Give offset/address message
	ld	hl,l0506
	call	l2653		; Tell clipboard
	call	l06f6		; Display S/P info
	ld	hl,l0516
	call	l268d		; Give header line
	ld	a,8
	call	l262b		; Clear row
l0348:
	call	l24e3		; Display error message
	ld	a,(l05ea)
	or	a		; Test SI dissplay required
	jr	z,l035e		; Nope
	call	l0792		; Display file sector info
	ld	hl,l0080
	call	l20af
	xor	a
	ld	(l05ea),a	; Reset request
l035e:
	ld	hl,l0388
	call	l2653		; Tell option to be selected
	call	l2595		; Read uppercase character
	ld	hl,l05c8
	call	l251f		; Find in table
	call	nz,l25a1	; Nope, ring the bell
	jr	nz,l035e
	ld	de,l05d4
	call	l2531		; Execute thru table
	ld	a,(l0168)	; Get disk type
	cp	'F'		; Teststill file display mode
	jr	z,l0312
	ld	de,l005c
	ld	c,.close
	jp	BDOS		; Close file
;
l0387:
	db	0		; .COM (00H is not)
l0388:
	_XY	9,31
	db	'Select option ==>',null
l039c:
	_XY	11,34
	db	'Enter Hex Sector:',null
l03b0:
	_XY	7,0
l03b2:
	_XY	11,55
	db	'File Offset ',null
l03c1:
	_XY	11,54
	db	'Load Address',null
l03d0:
	db	16
	db	2, 3,'Next sector',null
	db	2,33,'Top of file',null
	db	2,60,'Return to file List',null
	db	3, 3,'Previous sector',null
	db	3,33,'Bottom of file',null
	db	3,60,'Exit from SuperZap',null
	db	4, 3,'Select Sector',null
	db	4,33,'Find ASCII string',null
	db	5, 3,'Clipboard operations',null
	db	5,33,'Find Hex sequence',null
	db	5,60,'Edit sector',null
;
	db	11,3,'File Name',null
	db	11,16,'Access',null
l04ad::
	_XY	11,34
	db	'  Current Sector ',null
	db	12,0
l04c3:
	db	'd:'
l04c5:
	db	'filename.'
l04ce:
	db	'typ',null
;
	db	12,17,'R/'
l04d6:
	db	's ',null
;
	db	11
	db	2, 0,'N',null
	db	2,30,'T',null
	db	2,57,'L',null
	db	3, 0,'P',null
	db	3,30,'B',null
	db	3,57,'Z',null
	db	4, 0,'S',null
	db	4,30,'A',null
	db	5, 0,'C',null
	db	5,30,'H',null
	db	5,57,'E',null
l0506:
	_XY	6,3
	db	'Clipboard :- ',null
l0516:
	db	1
	_XY	14,0
	db	'Offset    0  1  2  3   4  5  6  7   8  9  A  B'
	db	'   C  D  E  F    -----ASCII------',null
l0569:
	_XY	8,0
	db	'Find:',null
l0571:
	_XY	8,6
	db	null
l0574:
	_XY	8,0
	db	'NOT FOUND ',null
l0581:
	_XY	8,0
	db	'INTERRUPTED ',null
l0590:
	db	'- HIT ANY KEY',bell,null
l059f:
	db	'- HIT <T> FOR TOP',null
l05b1:
	_XY	13,65
	db	'NEXT? (Y/N)',null
l05bf:
	_XY	12,41
	db	null
l05c2:
	_XY	12,57
	db	null
l05c5:
	_XY	12,41
	db	null
l05c8:
	db	11,'N','P','T','B','Z','L','E','S','C','A','H'
l05d4:
	dw	l05eb		; N - Next file sector
	dw	l0604		; P - Previous file sector
	dw	l0631		; T - Position to first file sector
	dw	l063c		; B - Position to last file sector
	dw	l2582		; Z - Exit from SuperZap
	dw	l2579		; L - Return to file List
	dw	l0618		; E - File sector change
	dw	l0650		; S - Set file sector number
	dw	l0693		; C - File scratchpad mode
	dw	l07ea		; A - Find ASCII string
	dw	l07e1		; H - Find Hex sequence
l05ea:
	db	0		; SI request flag
;
; Command N: Next file sector
;
l05eb:
	push	de
	ld	hl,(l0146)	; Get record number
	inc	hl		; Increment it
	ld	(l0146),hl
	call	l23ed		; Read random record
	push	af
	call	nz,l25a1	; Ring the bell on error
	jr	nz,l0601
	ld	a,TRUE
	ld	(l05ea),a	; Request SI display
l0601:
	pop	af
	pop	de
	ret
;
; Command P: Previous file sector
;
l0604:
	ld	hl,(l0146)	; Get record number
	ld	a,h
	or	l
	jp	z,l25a1		; Ring the bell if very first one
	dec	hl		; Decrement record number
	ld	(l0146),hl	; Set record number
	call	l23ed		; Read random record
	jp	nz,l25a1	; Ring the bell on error
	jr	l068d
;
; Command E: File sector change, edit sector
;
l0618:
	ld	a,(l0152)	; Test R/O
	or	a
	jp	nz,l25a1	; Ring the bell if so
	call	l1e9f		; Edit sector
	ld	a,(l1f62)	; Get write flag
	or	a		; Test write required
	push	af
	call	nz,l241a	; Write random record if so
	pop	af
	call	z,l23ed		; Read random record
	jp	l06d3
;
; Command T: Top of file, position to first file sector
;
l0631:
	ld	hl,0
	ld	(l0146),hl	; Clear record number
	call	l23ed		; Read random record
	jr	l068d
;
; Command B: Bottom of file, position to last file sector
;
l063c:
	ld	de,l005c
	ld	c,.filsiz
	call	BDOS		; Get size of file
	ld	hl,(l005c+_RRN)	; Fetch last record
	dec	hl		; Fix it
	ld	(l0146),hl	; Save it
	call	l23ed		; Read random record
	jr	l068d
;
; Command S: Select Sector, set file sector number
;
l0650:
	ld	hl,l0388
	call	l2666		; Delete message
	ld	hl,(l0146)	; Get record number
	ld	(l014e),hl
	ld	(l1419),hl
	ld	hl,l039c
	call	l2653		; Ask for hex sector
	ld	hl,0
	ld	(l1417),hl	; Init default
	ld	a,1
	ld	(l141b),a
	ld	hl,l05c5
	ld	(l1415),hl	; Set cursor positioning
l0676:
	call	l13b7		; Get hex value
	ld	hl,(l1417)	; Fetch result
	ld	(l0146),hl	; Set record number
	call	l23ed		; Read random record
	call	nz,l25a1	; Ring the bell on error
	jr	nz,l0676	; Try again on error
	ld	hl,l04ad
	call	l2653		; Tell current sector
l068d:
	ld	a,TRUE
	ld	(l05ea),a	; Request SI display
	ret
;
; Command C: Clipboard operations, file scratchpad mode
;
l0693:
	call	l264d		; Print header
	ld	hl,l1d56
	call	l268a		; Print menu
	ld	hl,l1dcd
	call	l2653		; Tell current
	ld	a,(l0160)	; Get current disk
	add	a,'A'
	call	l25e7		; Put to console
	ld	a,':'
	call	l25e7
	ld	hl,l04c5
	call	l265d		; Tell filename
	ld	hl,l01a1
	call	l265d		; Tell sector
	ld	hl,(l0146)	; Get record number
	call	l260d		; Put hex word to console
	ld	hl,l1ddd
	call	l2653		; Tell clipboard
	call	l209b
	call	l06e1		; Find clipboard command
	ld	de,l06da
	call	l2531		; Execute thru table
l06d3:
	ld	a,TRUE
	ld	(l017e),a	; Set request panel
	jr	l068d
;
l06da:
	dw	l06e0		; ESC - Return to sector display
	dw	l0769		;  C  - Load scratchpad (logical)
	dw	l0745		;  X  - Exchange current sector with clipboard
;
; Command ESC: Return to sector display
;
l06e0:
	ret
;
; Find clipboard command
;
l06e1:
	ld	hl,l0388
	call	l2653		; Tell option to be selected
	call	l2595		; Read uppercase character
	ld	hl,l1ded
	call	l251f		; Find in table
	ret	z		; Yeap
	call	l25a1		; Ring the bell if not
	jr	l06e1
;
; Display S/P info
;
l06f6:
	ld	a,(l0181)	; Get clipboard action
	or	a
	jr	z,l071e		; Not active
	dec	a
	jr	z,l0724
	ld	a,(l0184)	; Get clipboard disk
	add	a,'A'
	call	l25e7		; Put to console
	ld	a,':'
	call	l25e7
	ld	hl,l0185
	call	l265d		; Tell clipboard filename
l0712:
	ld	hl,l01a1
	call	l265d		; Tell sector
	ld	hl,(l0182)	; Get clipboard record
	jp	l260d		; Put hex word to console
l071e:
	ld	hl,l01aa
	jp	l265d		; Tell empty
l0724:
	ld	hl,l0192
	call	l265d		; Tell drive
	ld	a,(l0184)	; Get clipboard disk
	add	a,'A'
	call	l25e7		; Put to console
	ld	a,':'
	call	l25e7
	ld	hl,l0199
	call	l265d		; Tell track
	ld	hl,(l0185)
	call	l260d		; Put hex word to console
	jr	l0712
;
; Command X: Exchange current sector with clipboard
;
l0745::
	ld	a,(l0181)	; Get clipboard action
	or	a
	jp	z,l25a1		; Ring the bell if not active
	ld	a,(l0152)	; Test R/O
	or	a
	jp	nz,l25a1	; Ring the bell if so
	ld	bc,(l017f)	; Get address of disk buffer
	call	l23dd		; Save DMA pointer
	call	l241a		; Write random record
	ld	bc,DMA
	call	l23dd		; Save DMA pointer
	call	l0769		; Copy sector to clipboard
	jp	l23ed		; Read random record
;
; Command C: Copy current sector to clipboard
;
l0769:
	ld	hl,DMA
	ld	de,(l017f)	; Get address of disk buffer
	ld	bc,reclng
	ldir			; Unpack sector
	ld	a,(l0160)	; Get current disk
	ld	(l0184),a	; Save for clipboard disk
	ld	hl,l04c5
	ld	de,l0185
	ld	bc,.nam+1+.ext
	ldir			; Unpack filename
	ld	hl,(l0146)	; Get record number
	ld	(l0182),hl	; Save
	ld	a,2
	ld	(l0181),a	; Set clipboard action
	ret
;
; Display file sector info
;
l0792:
	ld	hl,l05bf
	call	l2653		; Set cursor
	ld	hl,(l0146)	; Get record number
	call	l260d		; Put hex word to console
	ld	hl,l05c2
	call	l2653		; Set cursor again
	ld	hl,(l0146)	; Get record number
	xor	a
	srl	h
	rr	l
	rra
	ld	(l014b+2),a
	ld	a,(l0387)	; Test .COM
	or	a
	jr	z,l07b7		; Nope
	inc	hl
l07b7:
	ld	(l014b),hl	; Set display page
	jp	l2152		; Print it
;
l07bd:
	ds	20
l07d1:
	dw	0
l07d3:
	dw	0
l07d5:
	dw	0
l07d7:
	dw	0
l07d9:
	db	0
l07da:
	db	0
l07db:
	db	0
l07dc:
	db	0
l07dd:
	db	0
l07de:
	db	2,'->'
;
; Command H: Find Hex sequence
;
l07e1::
	xor	a
	ld	(l2188),a	; Set hex
	call	l0a99
	jr	l07f2
;
; Command A: Find ASCII string
;
l07ea:
	ld	a,TRUE
	ld	(l2188),a	; Set ASCII
	call	l0a36
l07f2:
	ld	a,(l15d9)	; Get column
	or	a		; Test it
	jp	z,l06d3
l07f9:
	xor	a
	ld	(l07d9),a
	ld	hl,l0080
	ld	bc,l0080
	ld	(l07d3),bc
	ld	(l07d1),hl
	ld	(l07d7),bc
	ld	(l07d5),hl
l0811:
	push	de
	call	l01d4		; Get state of console
	pop	de
	or	a		; Test key pressed
	jr	z,l0842		; Nope
	call	l09a1
	call	l26c1		; Turn on revers video
	ld	hl,l0581
	call	l2653		; Tell interrupted
	ld	hl,l0590
	call	l265d		; Tell to press any key
	call	l26bb		; Turn off revers video
	call	l2588		; Get character from console
l0831:
	call	l2588		; Get character from console
	call	l0a12
	push	af
	ld	a,8
	call	l262b		; Clear row
	pop	af
	ld	(l05ea),a	; Request ??? SI display
	ret
l0842:
	ld	a,TRUE
	ld	(l07db),a
	ld	hl,(l07d1)
	ld	bc,(l07d3)
l084e:
	ld	a,(l15d9)	; Get column
	ld	(l07dc),a
	ld	de,l07bd
	ld	a,(de)
	cpir
	jp	pe,l0883
	jr	z,l089a
	call	l09ac
	jr	z,l07f9
l0864:
	call	l09a1
	call	l26c1		; Turn on revers video
	ld	hl,l0574
	call	l2653		; Tell not found
	ld	a,(l0168)	; Get disk type
	cp	'F'
	jp	z,l098b
	ld	hl,l0590
	call	l265d		; Tell to press any key
	call	l26bb		; Turn off revers video
	jr	l0831
l0883:
	ld	(l07d3),bc
	ld	(l07d1),hl
l088a:
	call	l0a2d
	jr	z,l08f5
	dec	c
	jp	m,l08a6
	cp	(hl)
	jp	nz,l0811
	inc	hl
	jr	l088a
l089a:
	ld	(l07d3),bc
	ld	(l07d1),hl
	call	l0a2d
	jr	z,l08f1
l08a6:
	ld	(l07da),a
	ld	a,c
	ld	(l07db),a
	ld	hl,(l07d1)
	ld	(l07d5),hl
	ld	bc,(l07d3)
	ld	(l07d7),bc
	ld	a,0ffh
	ld	(l07d9),a
	call	l09ac
	jr	nz,l0864
	ld	hl,l0080
	ld	bc,l0080
	ld	a,(l07da)
l08ce:
	cp	(hl)
	jr	nz,l08d9
	call	l0a2d
	jr	z,l08f5
	inc	hl
	jr	l08ce
l08d9:
	ld	a,(l07db)
	or	a
	jp	z,l07f9
	call	l09fb
	xor	a
	ld	(l07d9),a
	ld	hl,(l07d5)
	ld	bc,(l07d7)
	jp	l084e
l08f1:
	ld	a,c
	ld	(l07db),a
l08f5:
	ld	bc,(l07d3)
	ld	a,(l07db)
	or	a
	jr	nz,l090c
	ld	hl,l0080
	ld	(l07d1),hl
	ld	bc,l0080
	ld	(l07d3),bc
l090c:
	ld	a,(l07d9)
	or	a
	jr	z,l091d
	ld	bc,(l07d7)
	call	l09fb
	xor	a
	ld	(l07d9),a
l091d:
	push	bc
	call	l0a12
	pop	bc
	ld	hl,l0080
	or	a
	sbc	hl,bc
	ld	a,l
	or	a
	jr	nz,l092e
	ld	a,l0080
l092e:
	dec	a
	ld	(l0148),a	; Update record position
	call	l2172
	ld	hl,(l25d1)	; Get row/col
	dec	h		; Fix column
	dec	h
	ld	(l25d1),hl	; Save it
	call	l25b1		; Position cursor
	call	l26d1		; Turn on fat
	ld	hl,l07de
	call	l2679
	call	l26d6		; Turn off fat
	call	l26c1		; Turn on revers video
	ld	hl,l05b1
	call	l2653		; Ask for next
	call	l26bb		; Turn off revers video
	call	l2595		; Read uppercase character
	cp	'Y'
	push	af
	ld	hl,l05b1
	call	l2666		; Delete message
	call	l2172
	ld	hl,(l25d1)	; Get row/col
	dec	h		; Fix column
	dec	h
	ld	(l25d1),hl	; Save it
	call	l25b1		; Position cursor
	call	l25a6		; Print blank
	call	l25a6
	pop	af
	jr	nz,l099e
	ld	a,(l07db)
	or	a
	jp	nz,l0811
	call	l09ac
	jp	z,l0811
	jp	l0864
l098b:
	ld	hl,l059f
	call	l265d		; Tell key 'T' for top
	call	l26bb		; Turn off revers video
	call	l2595		; Read uppercase character
	cp	'T'
	jr	nz,l099e
	call	l0631
l099e:
	jp	l06d3
l09a1:
	ld	hl,l05b1
	call	l2666		; Delete message
	ld	a,8
	jp	l262b		; Clear row
l09ac:
	push	de
	ld	a,(l0168)	; Get disk type
	cp	'F'
	jr	z,l09e3
	ld	hl,(l193a)	; Get track
	ld	(l108f),hl
	call	l1c0c
	ld	hl,(l193a)	; Get track
	ld	de,(l193c)	; Get sector
	add	hl,de
	ld	a,l
	or	h
	jr	z,l09f1
	xor	a
l09ca:
	push	af
	call	l244d
	ld	hl,(l193a)	; Get track
	ld	de,(l108f)
	or	a
	sbc	hl,de
	jr	z,l09e0
	call	l1bdb
	call	l1ba4		; Tell track, sector, block and drive
l09e0:
	pop	af
	pop	de
	ret
l09e3:
	call	l05eb
	push	af
	ld	a,(l0146)	; Get record number
	and	7
	call	z,l0792		; Display file sector info
	jr	l09e0
l09f1:
	or	0ffh
	ld	hl,(l1930)	; Get number of reserved tracks
	ld	(l193a),hl	; Init track
	jr	l09ca
l09fb:
	push	bc
	push	de
	ld	a,(l0168)	; Get disk type
	cp	'F'
	push	af
	call	z,l0604
	pop	af
	jr	z,l0a0f
	call	l1c37
	call	l244d
l0a0f:
	pop	de
	pop	bc
	ret
;
;
;
l0a12:
	push	de
	ld	a,(l0168)	; Get disk type
	cp	'F'
	push	af
	call	z,l0792		; Display file sector info
	pop	af
	jr	z,l0a25
	call	l1bdb
	call	l1ba4		; Tell track, sector, block and drive
l0a25:
	ld	hl,l0080
	call	l20af
	pop	de
	ret
l0a2d:
	inc	de
	ld	a,(de)
	push	hl
	ld	hl,l07dc
	dec	(hl)
	pop	hl
	ret
;
;
;
l0a36:
	call	l0b5c
l0a39:
	call	l1828
	call	l2588		; Get character from console
	cp	cr
	ret	z
	cp	esc
	jr	z,l0a67
	ld	hl,l0a74
	call	l251f		; Find in table
	jr	z,l0a6c		; Yeap
	cp	tab
	jr	z,l0a59
	cp	' '
	call	c,l25a1		; Ring the bell
	jr	c,l0a39
l0a59:
	call	l0a7e
	ld	hl,l15d9	; Point to column
	ld	a,(l15de)
	inc	(hl)
	cp	(hl)
	ret	z
	jr	l0a39
l0a67:
	xor	a
	ld	(l15d9),a	; Clear column
	ret
l0a6c:
	ld	de,l0a78
	call	l2531		; Execute thru table
	jr	l0a39
;
l0a74:
	db	3,'A'-'@','F'-'@',DEL
;
l0a78:
	dw	l17ee		; ^A  - Cursor left
	dw	l17f8		; ^F  - Cursor right
	dw	l16c5		; DEL - Delete
;
;
;
l0a7e::
	push	af
	ld	hl,(l15dc)
	ld	a,(l15d9)	; Get column
	call	l253e		; HL:=HL+ACCU
	pop	af
	ld	(hl),a
	push	af
	ld	a,(l2188)	; Test hex/ASCII
	or	a
	jr	z,l0a95		; Hex
	pop	af
	jp	l25e7		; Put to console
l0a95:
	pop	af
	jp	l2618		; Put hex byte to console
;
;
;
l0a99:
	call	l0b5c
l0a9c:
	xor	a
	ld	(l07dd),a
	call	l0b40
	ld	hl,l010d
	call	l2679		; Erase to end of line
	call	l0b40
	call	l2595		; Read uppercase character
	ld	hl,l1f50
	call	l251f		; Find in table
	jr	z,l0aca		; Yeap
	ld	a,(l0144)	; Get console character
	cp	cr
	ret	z
	cp	esc
	jr	z,l0af9
	cp	'A'-'@'
	jr	z,l0afe
	call	l25a1		; Ring the bell
	jr	l0a9c
l0aca:
	ld	a,(l07dd)
	call	l0b53
	ld	(l07dd),a
	call	l0a7e
	ld	hl,l15d9	; Point to column
	inc	(hl)
l0ada:
	call	l2595		; Read uppercase character
	ld	hl,l1f50
	call	l251f		; Find in table
	jr	z,l0b0a		; Yeap
	ld	a,(l0144)	; Get console character
	cp	cr
	jr	z,l0b28
	cp	esc
	jr	z,l0af9
	cp	'A'-'@'
	jr	z,l0b2f
	call	l25a1		; Ring the bell
	jr	l0ada
l0af9:
	xor	a
	ld	(l15d9),a	; Clear column
	ret
l0afe:
	ld	a,(l15d9)	; Get column
	or	a		; Test it
	jr	z,l0a9c
	dec	a
	ld	(l15d9),a
	jr	l0a9c
l0b0a:
	ld	a,(l07dd)
	call	l0b53
	ld	(l07dd),a
	ld	hl,l15d9	; Point to column
	dec	(hl)
	call	l0b40
	call	l0a7e
	ld	hl,l15d9	; Point to column
	ld	a,(l15de)
	inc	(hl)
	cp	(hl)
	ret	z
	jr	l0b3d
l0b28:
	ld	hl,l15d9	; Point to column
	dec	(hl)
	ret	nz
	inc	(hl)
	ret
l0b2f:
	xor	a
	ld	hl,l07dd
	rrd
	ld	a,(hl)
	or	a
	jr	nz,l0ada
	ld	hl,l15d9	; Point to column
	dec	(hl)
l0b3d:
	jp	l0a9c
;
;
;
l0b40:
	push	af
	push	bc
	ld	hl,(l15da)	; Get base coordinates
	ld	a,(l15d9)	; Get column
	ld	b,a
	add	a,a		; * 2
	add	a,b		; * 3
	add	a,h
	ld	h,a		; Set column
	call	l25b7		; Position cursor
	pop	bc
	pop	af
	ret
;
;
;
l0b53:
	ex	de,hl
	ld	l,a
	ld	h,0
	call	l24dd		; HL:=16*HL+DE
	ld	a,l
	ret
;
;
;
l0b5c:
	xor	a
	ld	(l15d9),a	; Clear column
	ld	a,8
	call	l262b		; Clear row
	ld	hl,l0569
	call	l2653		; Tell find
	ld	hl,(l0571)	; Get cursor
	ld	(l15da),hl	; Set for coordinates
	ld	hl,l07bd
	ld	(l15dc),hl
	ld	a,14h
	ld	(l15de),a
	ret
;
; File type D - Directory mode
;
l0b7d:
	ld	hl,(l0d4f)
	ld	(l0161),hl	; Init cursor
	ld	a,TRUE
	ld	(l0d7f),a	; Set request list
l0b88:
	ld	a,(l0d7f)	; Get request list
	or	a		; Test list requested
	jr	z,l0bbf		; Nope
	call	l264d		; Print header
	ld	hl,l0be4
	call	l268a		; Print menu
	ld	hl,(l0d4d)	; Get coordinates
	call	l25b7		; Position cursor
	ld	e,_get
	ld	c,.usrcod
	call	BDOS		; Get current user
	ld	c,a
	sub	10		; Test 0..9
	jr	c,l0baf		; Yeap
	ld	c,a
	ld	a,'1'		; Mark 10..15
	call	l25e7		; Put to console
l0baf:
	ld	a,c
	call	l2621		; Put nibbles to console
	ld	a,')'
	call	l25e7		; Put to console
	call	l2230		; Give list
	xor	a
	ld	(l0d7f),a	; Reset request list
l0bbf:
	call	l24e3		; Display error message
	ld	a,(l015d)	; Get directory page position
	call	l0e12		; Position cursor
	call	l2595		; Read uppercase character
	ld	hl,l0d1f
	call	l251f		; Find in table
	call	nz,l25a1	; Nope, ring the bell
	jr	nz,l0bbf
	ld	de,l0d2f
	call	l2531		; Execute thru table
	ld	a,(l0168)	; Get disk type
	cp	'D'
	ret	nz
	jr	l0b88
;
; Directory mode panel and vector
;
l0be4:
	db	15
	db	2, 4,'Cursor left',null
	db	2,25,'Next directory page',null
	db	2,57,'Change Drive',null
	db	3, 4,'Cursor right',null
	db	3,25,'Previous directory page',null
	db	3,57,'Select track/Sector',null
	db	4, 4,'Cursor up',null
	db	4,25,'Set directory Mask',null
	db	4,57,'Edit file',null
	db	5, 4,'Cursor down',null
	db	5,25,'Change User number',null
	db	5,57,'Type file',null
	db	6, 4,'Next file',null
	db	6,25,'(current:',null
	db	6,57,'Exit from SuperZap',null
;
	db	14
	db	2, 0,'^A',null
	db	2,22,'N',null
	db	2,54,'D',null
	db	3, 0,'^F',null
	db	3,22,'P',null
	db	3,54,'S',null
	db	4, 0,'^_',null
	db	4,22,'M',null
	db	4,54,'E',null
	db	5, 0,'^^',null
	db	5,22,'U',null
	db	5,54,'T',null
	db	6, 0,'TAB',null
	db	6,54,'Z',null
l0d1f:
	db	15,'A'-'@','F'-'@','_'-'@','^'-'@',cr,'E'
	db	'Z','D','S','M','P','N','T','U','I'-'@'
l0d2f:
	dw	l0dbc		; ^A - Cursor left
	dw	l0daa		; ^F - Cursor right
	dw	l0dce		; ^_ - Cursor up
	dw	l0de1		; ^^ - Cursor down
	dw	l0df4		; ^M - Next file
	dw	l0e31		; E  - Edit file
	dw	l2582		; Z  - Exit from SuperZap
	dw	l14fd		; D  - Change Drive
	dw	l257f		; S  - Select track/Sector
	dw	l1553		; M  - Set directory Mask
	dw	l0d80		; P  - Previous directory page
	dw	l0d8b		; N  - Next directory page
	dw	l0e68		; T  - Type file
	dw	l149c		; U  - Change User number
	dw	l0daa		; ^I - Cursor right
l0d4d:
	_XY	6,36
l0d4f:
	_XY	10,0
l0d51:
	db	'** No records in file **',null
l0d6a:
	db	'** File not found **',null
l0d7f:
	db	FALSE		; Request list
;
; Command P: Previous directory page
;
l0d80:
	ld	a,(l015e)	; Get directory index
	or	a
	jp	z,l25a1		; Ring the bell if 1st page
	sub	DIRlen		; Subtract for previous
	jr	l0d97
;
; Command N: Next directory page
;
l0d8b:
	ld	a,(l015e)	; Get directory index
	add	a,DIRlen	; Add for next
	ld	hl,l015b	; Point to file count
	cp	(hl)		; Test in range
	jp	nc,l25a1	; Ring the bell if not
l0d97:
	ld	(l015e),a	; Set directory index
	xor	a
	ld	(l015d),a	; Clear directory page position
	call	l24e3		; Display message
	ld	hl,14*256+8
	call	l2387		; Clear 8 rows starting with row 14
	jp	l2230		; Give list
;
; Command ^F/TAB: Cursor right
;
l0daa:
	call	l0e0a		; Get disk values
l0dad:
	ld	a,(l015d)	; Get directory page position
	inc	a		; Get next
	and	DIRlen-1	; Truncate for max
	ld	(l015d),a
	ret	z		; End on start position
	add	a,b		; Add to index
	cp	(hl)		; Test against file count
	ret	c		; End if out of limit
	jr	l0dad
;
; Command ^A: Cursor left
;
l0dbc:
	call	l0e0a		; Get disk values
l0dbf:
	ld	a,(l015d)	; Get directory page position
	dec	a		; Get previous
	and	DIRlen-1	; Truncate for max
	ld	(l015d),a
	ret	z		; End on start position
	add	a,b		; Add to index
	cp	(hl)		; Test against file count
	ret	c		; End if out of limit
	jr	l0dbf
;
; Command ^_: Cursor up
;
l0dce:
	call	l0e0a		; Get disk values
l0dd1:
	ld	a,(l015d)	; Get directory page position
	sub	reclng/DIRlen	; Get previous file
	and	DIRlen-1	; Truncate for max
	ld	(l015d),a
	ret	z		; End on start position
	add	a,b		; Add to index
	cp	(hl)		; Test against file count
	ret	c		; End if out of limit
	jr	l0dd1
;
; Command ^^: Cursor down
;
l0de1:
	call	l0e0a		; Get disk values
l0de4:
	ld	a,(l015d)	; Get directory page position
	add	a,reclng/DIRlen	; Get next file
	and	DIRlen-1	; Truncate for max
	ld	(l015d),a
	ret	z		; End on start position
	add	a,b		; Add to index
	cp	(hl)		; Test against file count
	ret	c		; End if out of limit
	jr	l0de4
;
; Command CR: Next file
;
l0df4:
	call	l0e0a		; Get disk values
l0df7:
	ld	a,(l015d)	; Get directory page position
	add	a,reclng/DIRlen	; Get next file
	and	DIRlen-reclng/DIRlen
	ld	(l015d),a	; Truncate for max
	ret	z		; End on start position
	add	a,b		; Add to index
	ld	hl,l015b	; Point to file count		WHY????
	cp	(hl)		; Test against file count
	ret	c		; End if out of limit
	jr	l0df7
;
; Get disk values - Returns ^HL file count, reg B directory index
;
l0e0a:
	ld	hl,l015b	; Point to file count
	ld	a,(l015e)	; Get directory index
	ld	b,a
	ret
;
; Position cursor
;
l0e12:
	ld	(l0e30),a	; Save entry
	ld	hl,l211b
	rrca			; Divide by 4
	rrca
	and	LOMASK		; Get the bits
	call	l253e		; HL:=HL+ACCU
	ld	b,(hl)		; Fetch row
	ld	hl,l2144
	ld	a,(l0e30)	; Get back entry value
	and	BITMASK		; Get the bits
	call	l253e		; HL:=HL+ACCU
	ld	h,(hl)		; Get column
	ld	l,b		; Get row
	jp	l25b7		; Position cursor
;
l0e30:
	db	0
;
; Command E: Edit file
;
l0e31:
	call	l0e38		; Get file from list
	ret	z		; None there
	jp	l257c		; Set edit
;
; Get file from list - Z set if no file present
;
l0e38:
	ld	a,(l015b)	; Get file count
	or	a		; Test any file there
	jr	z,l0e5e		; Nope
	ld	a,(l015d)	; Get directory page position
	ld	b,a
	ld	a,(l015e)	; Get directory index
	add	a,b		; Build index
	ld	l,a
	ld	h,0
	ld	de,(l0140)	; Get start of free data
	call	l24dd		; HL:=16*HL+DE
	ld	de,l005c+.drv
	ld	bc,.nam+.ext
	ldir			; Unpack filename
	xor	a
	ld	(l005c+_EX),a	; Clear extent
	dec	a
	ret
l0e5e:
	call	l25a1		; Ring the bell
	ld	hl,l0d6a
	ld	(l0164),hl	; Set file not found
	ret
;
; Command T: Type file
;
l0e68:
	call	l0e38		; Get file from list
	ret	z		; None there
	call	l1833		; Open file
	ld	a,(l186c)	; Get I/O flag
	or	a		; Test success
	jr	nz,l0ef1	; Nope
	call	l264d		; Print header
	ld	hl,l0f33
	call	l268a		; Print menu
	ld	hl,l102a
	call	l2653		; Tell file
	ld	hl,l04c3
	call	l265d		; Tell drive and filename
	xor	a
	ld	(l0148),a	; Clear record position
	ld	(l014a),a
	ld	(l014b+1),a
	ld	(l1091),a
	inc	a
	ld	(l0149),a
	ld	(l014b),a	; Set next display page
	call	l11b7		; Get character
	ld	hl,(l0178)	; Get base page
	ld	(l017a),hl	; Set current page
	ld	(l017c),hl	; And top page, too
	ld	a,TRUE
	ld	(l1086),a	; Set no exit
	ld	(l1087),a	; Indicate page access
l0eb2:
	ld	a,(l1087)	; Get page access
	or	a
	jr	z,l0ed1		; No access
	xor	a
	ld	(l1087),a	; Indicate no page access
	ld	(l11b6),a
	call	l26e0		; Disable cursor
	call	l12cd		; Clear lines
	call	l0ef7
	call	l1106
	call	l0f1b
	call	l26db		; Enable cursor
l0ed1:
	ld	hl,l1034
	call	l2653		; Set cursor
	call	l2595		; Read uppercase character
	ld	hl,l106a
	call	l251f		; Find in table
	call	nz,l25a1	; Nope, ring the bell
	jr	nz,l0ed1
	ld	de,l1074
	call	l2531		; Execute thru table
	ld	a,(l1086)	; Get exit flag
	or	a
	jr	nz,l0eb2	; No exit
l0ef1:
	ld	a,TRUE
	ld	(l0d7f),a	; Indicate file type error
	ret
;
;
;
l0ef7:
	ld	hl,l1006
	call	l2653		; Tell page
	ld	hl,(l014b)	; Get display page
	call	l260d		; Put hex word to console
	ld	hl,l100e
	call	l2653		; Tell sectors
	ld	hl,(l0146)	; Get record number
	call	l260d		; Put hex word to console
	ld	hl,l101d
	call	l2653		; Tell lines
	ld	hl,(l0149)
	jp	l260d		; Put hex word to console
;
;
;
l0f1b:
	ld	hl,l1019
	call	l2653		; Give minus
	ld	hl,(l0146)	; Get record number
	call	l260d		; Put hex word to console
	ld	hl,l1026
	call	l2653		; Give minus
	ld	hl,(l108b)
	jp	l260d		; Put hex word to console
;
l0f33:
	db	10
	db	1, 3,'Next page',null
	db	1,29,'Forward paging',null
	db	1,56,'Select Sector',null
	db	2, 3,'Previous page',null
	db	2,29,'Backward paging',null
	db	2,56,'Return to file List',null
	db	3, 3,'Go to page No.',null
	db	3,29,'Top of file',null
	db	3,56,'Exit from SuperZap',null
;
	db	4,26,'Select option ==>',null
;
	db	9
	db	1, 0,'N',null
	db	1,26,'F',null
	db	1,53,'S',null
	db	2, 0,'P',null
	db	2,26,'B',null
	db	2,53,'L',null
	db	3, 0,'G',null
	db	3,26,'T',null
	db	3,53,'Z',null
l1006:
	_XY	6,0
	db	'Page ',null
l100e:
	_XY	6,26
	db	'Sectors ',null
l1019:
	_XY	6,38
	db	'-',null
l101d:
	_XY	6,59
	db	'Lines ',null
l1026:
	_XY	6,69
	db	'-',null
l102a:
	_XY	5,0
	db	'File:  ',null
l1034:
	_XY	4,43
	db	null
l1037:
	_XY	8,0
	db	null
l103a:
	_XY	6,38
	db	'     ',null
l1042:
	_XY	7,0
	db	'HIT ANY KEY to halt paging',null
l105f:
	db	10,'0123456789'
l106a:
	db	9,'N','L','P','T','Z','F','B','G','S'
l1074:
	dw	l1092		; N - Next page
	dw	l1101		; L - Return to file List
	dw	l10ae		; P - Previous page
	dw	l10ec		; T - Top of file
	dw	l10fe		; Z - Exit from SuperZap
	dw	l1230		; F -  Forward paging
	dw	l1272		; B - Backward paging
	dw	l12e9		; G - Go to page No.
	dw	l1374		; S - Select Sector
l1086:
	db	FALSE		; Exit flag (TRUE indicates no exit)
l1087:
	db	FALSE		; Page access (TRUE indicates access)
l1088:
	db	0
l1089:
	dw	0
l108b:
	dw	0
l108d:
	dw	0
l108f:
	dw	0
l1091:
	db	0
;
; Command N: Next page
;
l1092::
	ld	a,(l0143)	; Get I/O result
	or	a
	jp	nz,l25a1	; Ring the bell on error
l1099:
	call	l10a3		; Select next page
	ld	a,TRUE
	ld	(l1087),a	; Indicate page access
	inc	a
	ret
;
; Select next page
;
l10a3:
	ld	hl,(l017a)	; Get current page
	ld	de,PAGLEN
	add	hl,de		; Fix for next
	ld	(l017a),hl
	ret
;
; Command P: Previous page
;
l10ae::
	call	l10c4		; Test current page at base page
	jp	z,l25a1		; Ring the bell if so
l10b4:
	ex	de,hl
	ld	de,PAGLEN
	or	a
	sbc	hl,de		; Get previous page
	call	l1457		; Save it
	ld	a,TRUE
	ld	(l1087),a	; Indicate page access
	ret
;
; Test current page at base page - Z set if so
;
l10c4:
	ld	hl,(l0178)	; Get base page
	ld	de,(l017a)	; Get current page
	or	a
	sbc	hl,de
	ret
;
; Test current page at top page - NZ set on top page reached
;
l10cf:
	ld	hl,(l017a)	; Get current page
	ld	de,(l017c)	; And top page
	xor	a
	sbc	hl,de		; Test on top
	jr	z,l10ea
	ex	de,hl
	ld	de,PAGLEN
	or	a
	sbc	hl,de
	call	l1457		; Save it
	ld	a,TRUE
	ld	(l1087),a	; Indicate page access
l10ea:
	inc	a
	ret
;
; Command T: Top of file
;
l10ec::
	call	l10c4		; Test current page at base page
	jp	z,l25a1		; Ring the bell if so
l10f2:
	ld	hl,(l0178)	; Get base page
	call	l1457		; Save it
	ld	a,TRUE
	ld	(l1087),a	; Indicate page access
	ret
;
; Command Z: Exit from SuperZap
;
l10fe::
	call	l2582		; Simple setting
;
; Command L: Return to file List
;
l1101::
	xor	a
	ld	(l1086),a	; Simple setting
	ret
;
;
;
l1106:
	ld	hl,(l017c)	; Get top page
	ld	de,(l017a)	; And current page
	or	a
	sbc	hl,de
	jr	nz,l1122
	ld	hl,l0145
	ld	de,(l017c)	; Get top page
	ld	bc,l0008
	ldir
	ld	(l017c),de
l1122:
	ld	hl,l1037
	call	l2653		; Set cursor
	xor	a
	ld	(l1088),a
	ld	(l11b4),a	; Clear column
	ld	(l11b5),a
l1132:
	ld	a,(l1088)
	or	a
	jr	nz,l1155
	ld	a,(l0387)	; Test .COM
	or	a
	ld	a,(l0145)	; Get character
	jr	z,l115f		; Nope
	call	l11e5
	ld	a,(l0143)	; Get I/O result
	or	a
	jr	nz,l1155	; Error
	ld	a,(l1088)
l114d:
	or	a
	jr	nz,l1155	; Error
	call	l11b7		; Get character
	jr	l1132
l1155:
	ld	hl,(l014b)	; Get display page
	call	l12de		; Add 1
	ld	(l014b),hl
	ret
l115f:
	cp	tab		; Test tabulator
	jr	z,l1181
	cp	cr
	jr	z,l118f
	ld	hl,l012b	; Point to control table
	cp	(hl)		; Test any in list
	jr	z,l1199
	inc	hl
	cp	(hl)
	jr	z,l1199
	inc	hl
	cp	(hl)
	jr	z,l118f
	inc	hl
	cp	(hl)
	jr	z,l118f
l1179:
	call	l11e5
l117c:
	ld	a,(l0143)	; Get I/O result
	jr	l114d
;
; Found tab
;
l1181:
	ld	a,' '
	call	l11e5
	ld	a,(l11b4)	; Get column
	and	TABMASK
	jr	z,l117c
	jr	l1181
;
; Found control - carriage return
;
l118f:
	ld	a,(l0143)	; Get I/O result
	or	a
	jr	z,l119e		; No error
	ld	a,cr
	jr	l1179
;
; Found control - new line
;
l1199:
	call	l1202
	jr	l117c
l119e:
	ld	a,(l0148)	; Get record position
	ld	hl,l0080
	call	l253e		; HL:=HL+ACCU
	ld	a,(hl)		; Get character
	cp	lf		; Test line feed
	push	af
	call	l1202
	pop	af
	call	z,l11b7		; Get character
	jr	l117c
;
l11b4:
	db	0
l11b5:
	db	0
l11b6:
	db	0
;
; Get character ?????????????
;
l11b7:
	ld	a,(l0143)	; Get I/O result
	or	a
	jr	nz,l11e1	; Error
	ld	hl,l0148	; Point to record position
	ld	a,(hl)
	inc	(hl)
	ld	hl,l0080
	call	l253e		; HL:=HL+ACCU
	ld	a,(hl)		; Het character
	ld	(l0145),a	; Save it
	ld	a,(l0148)	; Get record position
	cp	reclng
	jr	nz,l11e1
	ld	hl,(l0146)	; Get record number
	inc	hl
	ld	(l0146),hl
	xor	a
	ld	(l0148),a	; Clear record position
	call	l23ed		; Read random record
l11e1:
	ld	a,(l0145)	; Get back character
	ret
;
;
;
l11e5:
	ld	b,a		; Save character
	ld	a,(l11b4)	; Get column
	cp	LASTCOL
	call	z,l1202
	ld	a,(l1088)
	or	a
	ret	nz
	ld	a,(l11b6)
	or	a
	jr	nz,l11fd
	ld	a,b
	call	l26a1		; Print character
l11fd:
	ld	hl,l11b4
	inc	(hl)		; Advance column
	ret
;
;
;
l1202:
	xor	a
	ld	(l11b4),a	; Clear column
	ld	hl,(l0149)
	ld	(l108b),hl
	call	l12de		; Add 1
	ld	(l0149),hl
	ld	hl,l11b5
	inc	(hl)
	ld	a,10h
	cp	(hl)
	jr	z,l122a
	ld	a,(l11b6)
	or	a
	ret	nz
	ld	a,cr
	call	l25e7		; Put new line to console
	ld	a,lf
	jp	l25e7
l122a:
	ld	a,0ffh
	ld	(l1088),a
	ret
;
; Command F: Forward paging
;
l1230::
	ld	a,(l0143)	; Get I/O result
	or	a
	jp	nz,l25a1	; Ring the bell on error
	call	l10a3		; Select next page
	call	l26e0		; Disable cursor
	call	l12b9
l1240:
	call	l12ae
	call	l0ef7
	call	l1106
	ld	a,(l0143)	; Get I/O result
	or	a
	jr	nz,l1257	; Error
	call	l1099		; Set next page
	call	l0f1b
	jr	l1240
l1257:
	call	l10cf		; Test current page at top page
	ld	a,0ffh
	ld	(l1091),a
l125f:
	xor	a
	ld	(l11b6),a
	dec	a
	ld	(l1086),a
	ld	(l1087),a	; Indicate page access
	ld	a,7
	call	l262b		; Clear row
	jp	l26db		; Enable cursor
;
; Command B: Backward paging
;
l1272::
	call	l10c4		; Test current page at base page
	jp	z,l25a1		; Ring the bell if so
	call	l26e0		; Disable cursor
	call	l12b9
l127e:
	call	l12ae
	call	l1106
	ld	hl,l1019
	call	l2653		; Give minus
	ld	hl,(l0146)	; Get record number
	call	l260d		; Put hex word to console
	ld	hl,l1026
	call	l2653		; Give minus
	ld	hl,(l0149)
	call	l260d		; Put hex word to console
	call	l10c4		; Test current page at base page
	jr	z,l12a9		; Yeap
	call	l10b4
	call	l0ef7
	jr	l127e
l12a9:
	call	l10f2
	jr	l125f
l12ae:
	call	l01d4		; Get state of console
	or	a		; Test key pressed
	ret	z		; Nope
	call	l2588		; Get character from console
	pop	af
	jr	l125f
l12b9:
	ld	a,0ffh
	ld	(l11b6),a
	call	l12cd		; Clear lines
	call	l26c1		; Turn on revers video
	ld	hl,l1042
	call	l2653		; Tell how to halt paging
	jp	l26bb		; Turn off revers video
;
; Clear 16 lines
;
l12cd:
	push	bc
	push	de
	ld	b,CLRLINE	; Get number of lines
	ld	a,(l1037)	; Get start row
	dec	a
l12d5:
	inc	a
	call	l262b		; Clear row
	djnz	l12d5
	pop	de
	pop	bc
	ret
;
; Add a 1 to BCD in reg HL
;
l12de:
	ld	a,1
;
; Add Accu to BCD in reg HL
;
l12e0:
	add	a,l		; Add it
	daa			; Fix for BCD
	ld	l,a
	ld	a,0
	adc	a,h		; Do not forget carry
	daa
	ld	h,a
	ret
;
; Command G: Go to page No.
;
l12e9::
	call	l130c
	ld	hl,(l014b)	; Get display page
	ld	a,l		; Test zero
	or	h
	jr	nz,l12f7	; Nope
	inc	a
	ld	(l014b),a	; Init page
l12f7:
	ld	hl,(l014b)	; Get display page
	ld	(l108d),hl
	ld	a,(l1091)
	or	a
	call	z,l1465
	ld	de,l0006
	call	l141c
	jr	l136e
;
;
;
l130c:
	ld	hl,(l0146)	; Get record number
	ld	(l0150),hl	; Set record number
	ld	hl,(l014b)	; Get display page
	ld	(l1089),hl
	ld	hl,0
	ld	(l014b),hl	; Clear display page
l131e:
	ld	hl,l1006
	call	l2653		; Tell page
	ld	hl,(l014b)	; Get display page
	call	l260d		; Put hex word to console
	call	l2595		; Read uppercase character
	ld	hl,l105f
	call	l251f		; Find in table
	jr	z,l1346		; Yeap
	cp	'A'-'@'		; Filter controls
	jr	z,l1356
	cp	esc
	jr	z,l1361
	cp	cr
	jr	z,l136e
	call	l25a1		; Ring the bell
	jr	l131e
l1346:
	ld	a,l
	ld	hl,(l014b)	; Get display page
	add	hl,hl		; * 2
	add	hl,hl		; * 4
	add	hl,hl		; * 8
	add	hl,hl		; *16
	call	l12e0		; Add Accu
	ld	(l014b),hl	; Set display page
	jr	l131e
;
; Ctrl-A: ????????????
;
; Shift right 4 bits:
;
;
; +----+----+----+----+        +----+----+----+----+
; | n3 | n2 | n1 | n0 |  ===>> | 00 | n3 | n2 | n1 |
; +----+----+----+----+        +----+----+----+----+
;
;
l1356:
	ld	hl,l014b+1
	xor	a
	rrd
	dec	hl
	rrd
	jr	l131e
;
; ESC: ????????????
;
l1361:
	ld	hl,(l0150)	; Get record number
	ld	(l0146),hl	; Set record number
	ld	hl,(l1089)
	dec	hl
	ld	(l014b),hl	; Set display page
;
; CR: ????????????
;
l136e:
	ld	a,TRUE
	ld	(l1087),a	; Indicate page access
	ret
;
; Command S: Select Sector
;
l1374::
	ld	hl,(l0146)	; Get record number
	ld	(l0150),hl	; Set record number
	ld	(l1419),hl
	ld	hl,0
	ld	(l1417),hl	; Init default
	ld	hl,l103a
	call	l2653		; Give blank line
	ld	hl,l100e
	ld	(l1415),hl	; Set sector message
	xor	a
	ld	(l141b),a
	call	l13b7		; Get hex value
	ld	hl,(l1417)	; Fetch result
	ld	a,l
	or	h
	jr	z,l139e
	dec	hl
l139e:
	ld	(l108d),hl
	ex	de,hl
	ld	hl,(l0150)	; Get record number
	ld	(l0146),hl	; Set record number
	ld	a,(l1091)
	or	a
	call	z,l1465
	ld	de,l0001
	call	l141c
	jr	l136e
;
; Input 16 bit hex number				??????????
;
l13b7:
	ld	a,(l141b)	; Get mode
	or	a
	jr	z,l13cb
	cp	1
	jr	z,l13f2
	cp	2
	jr	z,l13c8
	call	l1bdb
l13c8:
	call	l1ba4		; Tell track, sector, block and drive
l13cb:
	ld	hl,(l1415)	; Get cursor setting only or sector message
	call	l2653		; Print it
	ld	hl,(l1417)	; Get default
	call	l260d		; Put hex word to console
	call	l2595		; Read uppercase character
	ld	hl,l1f50
	call	l251f		; Find in table
	jr	z,l13f7		; Yeap
	cp	esc		; Test abort
	jr	z,l1403
	cp	'A'-'@'
	jr	z,l140a
	cp	cr
	ret	z
	call	l25a1		; Ring the bell
	jr	l13b7
l13f2:
	call	l0792		; Display file sector info
	jr	l13cb
l13f7:
	ex	de,hl
	ld	hl,(l1417)	; Get current value
	call	l24dd		; HL:=16*HL+DE
	ld	(l1417),hl	; Save
	jr	l13b7
l1403:
	ld	hl,(l1419)	; Get value
	ld	(l1417),hl	; Reset result
	ret
l140a:
	ld	hl,l1417+1	; Point to current
	xor	a
	rrd							;??????????????????????
	dec	hl
	rrd
	jr	l13b7
;
l1415:
	dw	0
l1417:
	dw	0
l1419:
	dw	0
l141b:
	db	0
l141c:
	push	de
	ld	hl,(l0178)	; Get base page
	add	hl,de
	ld	bc,l0008
l1424:
	ld	de,(l108d)
	push	hl
	call	l2537		; Get from table
	or	a
	sbc	hl,de
	jr	nc,l144f
	pop	hl
	pop	de
	push	de
	add	hl,bc
	push	hl
	or	a
	sbc	hl,de
	ld	de,l0006
	add	hl,de
	call	l2537		; Get from table
	ld	a,l
	or	h
	pop	hl
	jr	nz,l1424
	pop	de
	push	af
	call	l10cf		; Test current page at top page
	call	l25a1		; Ring the bell
	pop	af
	ret
l144f:
	pop	hl
	jr	z,l1454
	sbc	hl,bc
l1454:
	pop	de
	sbc	hl,de
l1457:
	ld	(l017a),hl	; Set current page
	ld	de,l0145
	ld	bc,l0008
	ldir
	jp	l23ed		; Read random record
l1465:
	call	l26e0		; Disable cursor
	call	l12cd		; Clear lines
	ld	a,0ffh
	ld	(l11b6),a
	call	l10cf		; Test current page at top page
l1473:
	call	l0ef7
	call	l1106
	call	l0f1b
	ld	a,(l0143)	; Get I/O result
	or	a
	call	z,l1099		; Set next page if no error
	jr	z,l1473
	ld	hl,(l017a)	; Get current page
	ld	de,l0008
	add	hl,de
	xor	a
	ld	b,e
l148e:
	ld	(hl),a
	inc	hl
	djnz	l148e
	ld	(l11b6),a
	dec	a
	ld	(l1091),a
	jp	l26db		; Enable cursor
;
; Command U: Change User number
;
l149c:
	ld	hl,l14d4
	call	l2666		; Delete message
	ld	a,TRUE
	ld	(l0d7f),a
	ld	hl,l14d4
	call	l2653		; Tell what to input
	call	l2595		; Read uppercase character
	cp	esc
	ret	z
	sub	'0'
	jp	c,l25a1		; Ring the bell
	cp	9+1
	jr	c,l14c3
	sub	'A'-10-'0'
	cp	MAXUSR+1
	jp	nc,l25a1	; Ring the bell
l14c3:
	ld	e,a
	ld	c,.usrcod
	call	BDOS		; Set user
	ld	a,(l0160)	; Get current disk
	call	l219f		; Select disk
	xor	a
	ld	(l015d),a	; Clear directory page position
	ret
;
l14d4:
	_XY	12,17
	db	'Enter hex user number or press ESC ==>',null
;
; Command D: Change Drive
;
l14fd:
	ld	a,TRUE
	ld	(l0d7f),a
l1502:
	ld	a,12
	call	l262b		; Clear row
	ld	hl,l152d
	call	l2653		; Tell what to be inputted
	call	l2595		; Read uppercase character
	cp	esc
	ret	z
	cp	'A'
	jr	c,l1528
	push	af
	call	l25e7		; Put to console
	pop	af
	sub	'A'
	call	l219f		; Select disk
	jr	z,l1528		; Invalid
	xor	a
	ld	(l015d),a	; Clear directory page position
	ret
l1528:
	call	l25a1		; Ring the bell
	jr	l1502
l152d:
	_XY	12,20
	db	'Enter drive letter or press ESC ==>',null
;
; Command M: Set directory Mask
;
l1553:
	call	l264d		; Print header
	ld	hl,l15ea
	call	l268a		; Print menu
	ld	a,TRUE
	ld	(l0d7f),a
	ld	hl,l01b0+.drv
	ld	de,l15df
	ld	bc,.nam+.ext
	ldir
	call	l16fa
	xor	a
	ld	(l15d7),a
	ld	(l15d8),a
	ld	(l15d9),a	; Clear column
	ld	(l2188),a	; Set hex
	ld	hl,(l169d)
	ld	(l15da),hl	; Set coordinates
	ld	hl,l15df
	ld	(l15dc),hl
	ld	a,8
	ld	(l15de),a
l158d:
	call	l1828
	call	l2595		; Read uppercase character
	cp	esc
	ret	z
	cp	cr
	jr	z,l15b3
	ld	hl,l16ac
	call	l251f		; Find in table
	jr	z,l15c1		; Yeap
	ld	hl,l15ce
	call	l251f		; Find in table
	jr	z,l15c9		; Yeap
	cp	' '
	jr	c,l15c9
	call	l1749
	jr	l158d
l15b3:
	ld	hl,l15df
	call	l1e84		; Unpack name and extension
	call	l22ac		; Build directory list
	xor	a
	ld	(l015d),a	; Clear directory page position
	ret
l15c1:
	ld	de,l16b5
	call	l2531		; Execute thru table
	jr	l158d
l15c9:
	call	l25a1		; Ring the bell
	jr	l158d
l15ce:
	db	8,',.:;<>[]'
l15d7:
	db	0
l15d8:
	db	0
l15d9:
	db	0		; Column
l15da:
	db	0,0		; Screen coordinates [Row, Column]
l15dc:
	db	0,0
l15de:
	db	0
l15df:
	db	0,0,0,0,0,0,0,0
l15e7:
	db	0,0,0
l15ea:
	db	10
	db	2, 4,'Cursor left',null
	db	2,29,'Insert on/off',null
	db	2,58,'Toggle name/type',null
	db	3, 4,'Cursor right',null
	db	3,29,'Delete character',null
	db	3,58,'Use current mask',null
;
	db	7,20,'File name ==>',null
	db	7,37,'<=',null
	db	9,20,'File type ==>',null
	db	9,32,'<=',null
;
	db	6
	db	2, 0,'^A',null
	db	2,25,'^V',null
	db	2,54,'TAB',null
	db	3, 0,'^F',null
	db	3,25,'DEL',null
	db	3,54,'ESC',null
l169d:
	_XY	7,28
	db	null
l16a0:
	_XY	9,28
	db	null
l16a3:
	_XY	5,29
	db	'Insert',null
l16ac:
	db	8,'A'-'@','F'-'@',DEL,'V'-'@','I'-'@',' ','.','*'
l16b5:
	dw	l17c9		; ^A
	dw	l176a		; ^F
	dw	l16c5		; DEL
	dw	l180f		; ^V
	dw	l1781		; TAB
	dw	l1724		; ' '
	dw	l171f		; '.'
	dw	l1728		; '*'
;
; Command DEL: Delete character
;
l16c5::
	ld	hl,(l15dc)
	ld	a,(l15d9)	; Get column
	ld	c,a
	call	l253e		; HL:=HL+ACCU
	ld	e,l
	ld	d,h
	inc	hl
	ld	a,(l15de)
	sub	c
	dec	a
	jr	z,l16de
	ld	c,a
	ld	b,0
	ldir
l16de:
	ld	a,' '
	ld	(de),a
	ld	a,(l2188)	; Test hex/ASCII
	or	a
	jr	z,l16fa		; Hex
	ld	hl,l0571
	call	l2653		; Set cursor
	ld	hl,l07bd
	ld	b,14h
l16f2:
	ld	a,(hl)
	call	l25e7		; Put to console
	inc	hl
	djnz	l16f2
	ret
l16fa:
	ld	hl,l169d
	call	l2653		; Set cursor
	ld	hl,l15df
	ld	b,8
l1705:
	ld	a,(hl)
	call	l25e7		; Put to console
	inc	hl
	djnz	l1705
	ld	hl,l16a0
	call	l2653		; Set cursor
	ld	hl,l15e7
	ld	b,3
l1717:
	ld	a,(hl)
	call	l25e7		; Put to console
	inc	hl
	djnz	l1717
	ret
;
; Character '.'
;
l171f::
	ld	a,(l15d8)
	or	a
	ret	nz
;
; Character ' '
;
l1724::
	ld	a,' '
	jr	l172a
;
; Character '*'
;
l1728::
	ld	a,'?'
l172a:
	ld	hl,(l15dc)
	ld	(l1748),a
	ld	a,(l15d9)	; Get column
	ld	b,a
	call	l253e		; HL:=HL+ACCU
	ld	a,(l15de)
	sub	b
	ld	b,a
	ld	a,(l1748)
l173f:
	ld	(hl),a
	inc	hl
	djnz	l173f
	call	l16fa
	jr	l1781
l1748:
	db	0
l1749:
	push	af
	ld	a,(l15d7)
	or	a
	jr	z,l1753
	call	l17ac
l1753:
	ld	hl,(l15dc)
	ld	a,(l15d9)	; Get column
	call	l253e		; HL:=HL+ACCU
	pop	af
	ld	(hl),a
	call	l25e7		; Put to console
	ld	a,(l15d7)
	or	a
	jr	z,l176a
	call	l16fa
;
; Command ^F: Cursor right
;
l176a:
	ld	hl,(l15dc)
	ld	a,(l15d9)	; Get column
	call	l253e		; HL:=HL+ACCU
	ld	a,(hl)
	cp	' '
	jr	z,l1781
	ld	hl,l15d9	; Point to column
	ld	a,(l15de)
	inc	(hl)
	cp	(hl)
	ret	nz
;
; Command TAB: Toggle name/type
;
l1781:
	xor	a
	ld	(l15d9),a	; Clear column
	ld	a,(l15d8)
	cpl
	ld	(l15d8),a
	or	a
	jr	nz,l17a2
	ld	hl,(l169d)
	ld	de,l15df
	ld	a,8
l1797:
	ld	(l15de),a
	ld	(l15dc),de
	ld	(l15da),hl	; Set coordinates
	ret
l17a2:
	ld	hl,(l16a0)
	ld	de,l15e7
	ld	a,3
	jr	l1797
l17ac:
	ld	hl,(l15dc)
	ld	a,(l15de)
	dec	a
	call	l253e		; HL:=HL+ACCU
	ld	e,l
	ld	d,h
	dec	hl
	ld	a,(l15d9)	; Get column
	ld	c,a
	ld	a,(l15de)
	sub	c
	dec	a
	ret	z
	ld	c,a
	ld	b,0
	lddr
	ret
;
; Command ^A: Cursor left
;
l17c9::
	ld	a,(l15d9)	; Get column
	or	a		; Test it
	jr	nz,l17eb
	call	l1781
	ld	hl,(l15dc)
	ld	a,(l15de)
	dec	a
	ld	b,a
	dec	a
	call	l253e		; HL:=HL+ACCU
	ld	a,' '
l17e0:
	cp	(hl)
	jr	nz,l17e6
	dec	hl
	djnz	l17e0
l17e6:
	ld	a,b
l17e7:
	ld	(l15d9),a	; Set column
	ret
l17eb:
	dec	a
	jr	l17e7
;
; ^A - Cursor left
;
l17ee::
	ld	a,(l15d9)	; Get column
	or	a		; Test it
	ret	z
	dec	a
	ld	(l15d9),a
	ret
;
; ^F - Cursor right
;
l17f8::
	ld	hl,l15de
	ld	a,(l15d9)	; Get column
	inc	a
	cp	(hl)
	ret	z
	ld	hl,(l15dc)
	ld	(l15d9),a
	dec	a
	call	l253e		; HL:=HL+ACCU
	ld	a,(hl)
	jp	l25e7		; Put to console
;
; Command ^V: Insert on/off
;
l180f::
	ld	a,(l15d7)
	cpl
	ld	(l15d7),a
	ld	hl,l16a3
	or	a
	jp	z,l2666		; Delete message
	push	hl
	call	l26c1		; Turn on revers video
	pop	hl
	call	l2653		; Tell insert
	jp	l26bb		; Turn off revers video
l1828:
	ld	hl,(l15da)	; Get base coordinates
	ld	a,(l15d9)	; Get column
	add	a,h		; Add to base
	ld	h,a		; Build column
	jp	l25b7		; Position cursor
;
; Open file
;
l1833:
	xor	a
	ld	(l186c),a	; Init auccess
	ld	de,l005c
	ld	c,.open
	call	BDOS		; Open file
	ld	hl,l0d6a
	inc	a
	jr	z,l1863
	ld	hl,0
	ld	(l0146),hl	; Clear record numbers
	ld	(l0150),hl
	ld	de,l005c+.drv
	call	l2396		; Unpack FCB to filename
	ld	a,(l005c)
	add	a,'A'-1		; Make ASCII drive
	ld	(l04c3),a
	call	l23ed		; Read random record
	ret	z
	ld	hl,l0d51
l1863:
	ld	(l0164),hl	; Set empty file or file not found
	ld	a,TRUE
	ld	(l186c),a	; Set no success
	ret
;
l186c:
	db	FALSE		; I/O flag
;
; File type P - Physical sector mode
;
l186d:
	ld	hl,(l1b09)
	ld	(l0161),hl	; Init cursor
	ld	a,TRUE
	ld	(l017e),a	; Set request panel
	ld	(l18e2),a
l187b:
	call	l2148		; Clear display page number
	ld	a,(l18e2)
	or	a
	jr	z,l189e
	xor	a
	ld	(l18e2),a
	ld	a,(l0160)	; Get current disk
	ld	c,a
	call	l01e9		; Select drive
	call	l01e6		; Home disk head
	ld	hl,0
	ld	(l193c),hl	; Clear sector
	ld	hl,(l1930)	; Get number of reserved tracks
	ld	(l193a),hl	; Init track
l189e:
	ld	a,(l017e)	; Get request panel
	or	a
	jr	z,l18ba
	xor	a
	ld	(l017e),a	; Reset request panel
	call	l264d		; Print header
	ld	hl,l198e
	call	l268a		; Print menu
	ld	hl,l1b0b
	call	l2653		; Tell clipboard
	call	l06f6		; Display S/P info
l18ba:
	call	l1b92
	call	l24e3		; Display error message
l18c0:
	ld	hl,l0388
	call	l2653		; Tell option to be selected
	call	l2595		; Read uppercase character
	ld	hl,l1b27
	call	l251f		; Find in table
	call	nz,l25a1	; Nope, ring the bell
	jr	nz,l18c0
	ld	de,l1b36
	call	l2531		; Execute thru table
	ld	a,(l0168)	; Get disk type
	cp	'P'
	ret	nz
	jr	l187b
l18e2:
	db	0
;
; Entry for CP/M PLUS BIOS call
;
l18e3:
	ld	(l190b+1),a	; Save registers
	ld	(l190b+2),bc
	ld	(l190b+4),de
	ld	(l190b+6),hl
	pop	hl		; Get caller address
	ld	de,l01d1-3
	xor	a
	sbc	hl,de		; Calculate offset
	ld	b,a
	ld	a,l
l18fa:
	sub	3		; Generate BIOS function
	jr	z,l1901
	inc	b		; Update dunction
	jr	l18fa
l1901:
	ld	a,b		; Get function
	ld	de,l190b
	ld	(de),a		; Save function
	ld	c,.bios
	jp	BDOS		; Do BIOS call
;
; BIOS parameter block
;
l190b:
	db	0		; BIOS function
	db	0		; Accu
	dw	0		; Register BC
	dw	0		; Register DE
	dw	0		; Register HL
;
; DPH - Disc Parameter Header
;
l1913:				; XLT - Address of sector translation table
	ds	10
l191d:				; DPB if CP/M 2
	ds	2
l191f:				; DPB if CP/M 3
	ds	4
;
; DPB - Disc Parameter Block
;
l1923:
	ds	2		; spt - Number of 128-byte records per track
	ds	1		; bsh - Block shift
l1926:
	ds	1		; blm - Block mask
	ds	1		; exm - Extent mask
l1928:
	ds	2		; dsm - (no. of blocks on the disc)-1
	ds	2		; drm - (no. of directory entries)-1
	ds	1		; al0 - Directory allocation bitmap, first byte
	ds	1		; al1 - Directory allocation bitmap, second byte
	ds	2		; cks - Checksum vector size
l1930:
	ds	2		; off - Offset, number of reserved tracks
l1932:
	ds	1		; psh - Physical sector shift
l1933:
	ds	1		; phm - Physical sector mask
;
l1934:
	dw	0
l1936:
	dw	0
l1938:
	dw	0
l193a:
	dw	0		; Track
l193c:
	dw	0		; Sector
l193e:
	dw	0		; Block
l1940:
	_XY	11,4
	db	'Enter Hex Track:',null
l1953:
	_XY	11,21
	db	'Enter Hex Sector:',null
l1967:
	_XY	11,40
	db	'Enter Hex Block:',null
l197a:
	_XY	11,61
	db	'  Enter Drive ID:',null
l198e:
	db	18
	db	2, 3,'Next sector',null
	db	2,33,'Select Track',null
	db	2,57,'Find ASCII string',null
	db	3, 3,'Previous sector',null
	db	3,33,'Select Sector',null
	db	3,57,'Find Hex sequence',null
	db	4, 3,'Next track',null
	db	4,33,'Select Block',null
	db	4,57,'Return to file List',null
	db	5, 3,'Previous track',null
	db	5,33,'Select Drive',null
	db	5,57,'Exit from SuperZap',null
	db	6, 3,'Clipboard operations',null
	db	7,57,'Edit sector',null
l1a82:
	_XY	11,4
	db	'  Current Track ',null
l1a95:
	_XY	11,21
	db	'  Current Sector ',null
l1aa9:
	_XY	11,40
	db	'  Current Block ',null
l1abc:
	_XY	11,61
	db	'Current Drive    ',null
;
	db	14
	db	2, 0,'N',null
	db	2,30,'T',null
	db	2,54,'A',null
	db	3, 0,'P',null
	db	3,30,'S',null
	db	3,54,'H',null
	db	4, 0,'I',null
	db	4,30,'B',null
	db	4,54,'L',null
	db	5, 0,'O',null
	db	5,30,'D',null
	db	5,54,'Z',null
	db	6, 0,'C',null
	db	7,54,'E',null
l1b09:
	_XY	9,54
l1b0b:
	_XY	7,3
	db	'Clipboard :- ',null
l1b1b:
	_XY	12,11
	db	null
l1b1e:
	_XY	12,28
	db	null
l1b21:
	_XY	12,47
	db	null
l1b24:
	_XY	12,67
	db	null
l1b27:
	db	14,'N','E','P','S','I','T','O','Z','L','B','D','C','A','H'
l1b36:
	dw	l1c0c		; N
	dw	l1e8d		; E
	dw	l1c37		; P
	dw	l1c49		; S
	dw	l1c21		; I
	dw	l1c92		; T
	dw	l1cdb		; O
	dw	l2582		; Z
	dw	l2573		; L
	dw	l1cea		; B
	dw	l1b52		; D
	dw	l1df8		; C
	dw	l07ea		; A
	dw	l07e1		; H
;
; Command D: Select Drive
;
l1b52::
	ld	hl,l197a
	call	l2653		; Tell enter drive id
l1b58:
	ld	hl,l1b24
	call	l2653		; Set cursor
	ld	a,(l0160)	; Get current disk
	add	a,'A'
	call	l25e7		; Put to console
	ld	a,1
	call	l25e7
	call	l2595		; Read uppercase character
	cp	esc
	jr	z,l1b87
	cp	'A'
	jr	c,l1b8d
	push	af
	call	l25e7		; Put to console
	pop	af
	sub	'A'
	call	l219f		; Select disk
	jr	z,l1b8d		; Invalid
	ld	a,0ffh
	ld	(l18e2),a
l1b87:
	ld	hl,l1abc
	jp	l2653		; Tell current drive
l1b8d:
	call	l25a1		; Ring the bell
	jr	l1b58
l1b92:
	call	l244d
	ld	hl,l0516
	call	l268d		; Give header line
	ld	hl,l0080
	call	l20af
	call	l1bdb
;
; Tell track, sector, block and drive
;
l1ba4:
	ld	hl,l1b1b
	call	l2653		; Set cursor
	ld	hl,(l193a)	; Get track
	call	l260d		; Put hex word to console
	ld	hl,l1b1e
	call	l2653		; Set cursor
	ld	hl,(l193c)	; Get sector
	call	l260d		; Put hex word to console
	ld	hl,l1b21
	call	l2653		; Set cursor
	ld	hl,(l193e)	; Get block
	call	l260d		; Put hex word to console
	ld	hl,l1b24
	call	l2653		; Set cursor
	ld	a,(l0160)	; Get current disk
	add	a,'A'
	call	l25e7		; Put to console
	ld	a,':'
	jp	l25e7
;
;
;
l1bdb:
	ld	de,(l193a)	; Get track
	ld	bc,(l1923)	; Get number of 128-byte records per track
	call	l2545		; HL=BC*DE
	ld	de,(l193c)	; Get sector
	add	hl,de
	ld	de,(l1938)
	or	a
	sbc	hl,de
	jr	c,l1c04
	ex	de,hl
	ld	bc,(l1936)
	call	l255a		; HL=BC/DE; DE=BC MOD DE
	ld	hl,(l1928)	; Get (no. of blocks on the disc)-1
	or	a
	sbc	hl,de
	jr	nc,l1c07
l1c04:
	ld	de,l0000
l1c07:
	ld	(l193e),de	; Set block
	ret
;
; Command N: Next sector
;
l1c0c:
	ld	hl,(l193c)	; Get sector
	inc	hl		; Advanve it
	ld	(l193c),hl
	ld	de,(l1923)	; Get number of 128-byte records per track
	or	a
	sbc	hl,de		; Test in range
	ret	c		; Yeap
	ld	hl,0
	ld	(l193c),hl	; Clear sector
;
; Command I: Next track
;
l1c21::
	ld	hl,(l193a)	; Get track
	inc	hl		; Advance to next
	ld	(l193a),hl
	ld	de,(l1934)
	or	a
	sbc	hl,de
	ret	c
	ld	hl,0
	ld	(l193a),hl	; Init track
	ret
;
; Command P: Previous sector
;
l1c37:
	ld	hl,(l193c)	; Get sector
	ld	a,h		; Test already zero
	or	l
	jr	nz,l1c44	; Nope
	call	l1cdb
	ld	hl,(l1923)	; Get number of 128-byte records per track
l1c44:
	dec	hl		; Get previous sector
	ld	(l193c),hl	; Set sector
	ret
;
; Command S: Select Sector
;
l1c49::
	ld	hl,l0388
	call	l2666		; Delete message
	ld	hl,(l193c)	; Get sector
	ld	(l1c90),hl
	ld	(l1419),hl
	ld	hl,l1953
	call	l2653		; Tell enter hex sector
	ld	hl,l1b1e
	ld	(l1415),hl
	ld	hl,l0000
	ld	(l1417),hl
	ld	a,3
	ld	(l141b),a
l1c6f:
	call	l13b7		; Get hex value
	ld	hl,(l1417)	; Fetch result
	ld	(l193c),hl	; Set sector
	ld	de,(l1923)	; Get number of 128-byte records per track
	or	a
	sbc	hl,de
	ld	hl,l1a95
	jp	c,l2653		; Tell current secor
	call	l25a1		; Ring the bell
	ld	hl,(l1419)
	ld	(l1417),hl
	jr	l1c6f
l1c90:
	dw	0
;
; Command T: Select Track
;
l1c92::
	ld	hl,l0388
	call	l2666		; Delete message
	ld	hl,(l193a)	; Get track
	ld	(l1cd9),hl
	ld	(l1419),hl
	ld	hl,l1940
	call	l2653		; Tell enter hex track
	ld	hl,l1b1b
	ld	(l1415),hl
	ld	hl,l0000
	ld	(l1417),hl
	ld	a,3
	ld	(l141b),a
l1cb8:
	call	l13b7		; Get hex value
	ld	hl,(l1417)	; Fetch result
	ld	(l193a),hl	; Set track
	ld	de,(l1934)
	or	a
	sbc	hl,de
	ld	hl,l1a82
	jp	c,l2653		; Tell current track
	call	l25a1		; Ring the bell
	ld	hl,(l1cd9)
	ld	(l1417),hl
	jr	l1cb8
l1cd9:
	dw	0
;
; Command O: Previous track
;
l1cdb:
	ld	hl,(l193a)	; Get track
	ld	a,h
	or	l
	jr	nz,l1ce5
	ld	hl,(l1934)
l1ce5:
	dec	hl
	ld	(l193a),hl	; Set track
	ret
;
; Command B: Select Block
;
l1cea::
	ld	hl,l0388
	call	l2666		; Delete message
	ld	hl,(l193e)	; Get block
	ld	(l1d54),hl
	ld	(l1419),hl
	ld	hl,l1967
	call	l2653		; Tell enter hex block
	ld	hl,l1b21
	ld	(l1415),hl
	ld	hl,l0000
	ld	(l1417),hl
	ld	a,2
	ld	(l141b),a
l1d10:
	call	l13b7		; Get hex value
	ld	hl,(l1417)	; Fetch result
	ld	(l193e),hl	; Save block
	ld	de,(l1928)	; Get (no. of blocks on the disc)-1
	ex	de,hl
	or	a
	sbc	hl,de
	jp	p,l1d2f
	call	l25a1		; Ring the bell
	ld	hl,(l1419)
	ld	(l1417),hl
	jr	l1d10
l1d2f:
	ld	de,(l193e)	; Get block
	ld	bc,(l1936)
	call	l2545		; HL=BC*DE
	ld	de,(l1938)
	add	hl,de
	ex	de,hl
	ld	bc,(l1923)	; Get number of 128-byte records per track
	call	l255a		; HL=BC/DE; DE=BC MOD DE
	ld	(l193a),de	; Set track
	ld	(l193c),hl	; And sector
	ld	hl,l1aa9
	jp	l2653		; Tell current block
l1d54:
	db	0,0
l1d56:
	db	3
	db	2,4,'Copy current sector to clipboard',null
	db	3,4,'Exchange current sector with clipboard',null
	db	4,4,'Return to sector display',null
;
	db	3
	db	2,1,'C',null
	db	3,1,'X',null
	db	4,0,'ESC',null
l1dcd:
	_XY	11,0
	db	'Current   :- ',null
l1ddd:
	_XY	12,0
	db	'Clipboard :- ',null
l1ded:
	db	3,esc,'C','X'
l1df1:
	dw	l1df7		; ESC
	dw	l1e60		; C
	dw	l1e46		; X
;
; Command ESC: Return to sector display
;
l1df7::
	ret
;
; Command C: Clipboard operations
;
l1df8::
	call	l264d		; Print header
	ld	hl,l1d56
	call	l268a		; Print menu
	ld	hl,l1dcd
	call	l2653		; Tell current
	ld	hl,l0192
	call	l265d		; Tell drive
	ld	a,(l0160)	; Get current disk
	add	a,'A'
	call	l25e7		; Put to console
	ld	a,':'
	call	l25e7
	ld	hl,l0199
	call	l265d		; Tell track
	ld	hl,(l193a)	; Get track
	call	l260d		; Put hex word to console
	ld	hl,l01a1
	call	l265d		; Tell sector
	ld	hl,(l193c)	; Get sector
	call	l260d		; Put hex word to console
	ld	hl,l1ddd
	call	l2653		; Tell clipboard
	call	l209b
	call	l06e1		; Find clipboard command
	ld	de,l1df1
	call	l2531		; Execute thru table
	jr	l1e99
;
; Command X: Exchange current sector with clipboard
;
l1e46::
	ld	a,(l0181)	; Get clipboard action
	or	a
	jp	z,l25a1		; Ring the bell if not active
	ld	bc,(l017f)	; Get address of disk buffer
	call	l23dd		; Save DMA pointer
	call	l23e4		; Set disk buffer thru BDOS
	call	l24b9		; Write sector to disk
	ld	bc,l0080
	call	l23dd		; Save DMA pointer
;
; Command C: Copy current sector to clipboard
;
l1e60::
	ld	hl,l0080
	ld	de,(l017f)	; Get address of disk buffer
	ld	bc,l0080
	ldir
	ld	a,1
	ld	(l0181),a	; Set clipboard action
	ld	a,(l0160)	; Get current disk
	ld	(l0184),a	; Save for clipboard disk
	ld	hl,(l193a)	; Get track
	ld	(l0185),hl
	ld	hl,(l193c)	; Get sector
	ld	(l0182),hl	; Set clipboard record
	ret
;
; Unpack name and extension from ^HL
;
l1e84:
	ld	de,l01b0+.drv
	ld	bc,.nam+.ext
	ldir
	ret
;
; Command E: Edit sector
;
l1e8d::
	call	l1e9f		; Edit sector
	ld	a,(l1f62)	; Get write flag
	or	a
	jr	z,l1e99
	call	l24b9		; Write sector to disk
l1e99:
	ld	a,TRUE
	ld	(l017e),a	; Set request panel
	ret
;
; Submenue: Edit sector
;
l1e9f:
	ld	hl,1*256+9
	call	l2387		; Clear 9 rows starting with row 1
	ld	hl,l1f63
	call	l268a		; Print menu
	xor	a
	ld	(l0148),a	; Clear record position
	ld	(l1f61),a
	ld	(l1f62),a	; Reset write flag
	ld	(l2188),a	; Set hex
	ld	(l2189),a
l1ebb:
	call	l2172
	call	l25b1		; Position cursor
	call	l2588		; Get character from console
	cp	' '
	jr	c,l1efa
	ld	a,(l2188)	; Test hex/ASCII
	or	a
	ld	a,(l0144)	; Get console character
	jr	z,l1f0f		; Hex
	cp	' '
	jr	c,l1f0a
	cp	80h
	jr	nc,l1f0a
	push	af
	push	af
	ld	hl,l0080
	ld	a,(l0148)	; Get record position
	call	l253e		; HL:=HL+ACCU
	pop	af
	ld	(hl),a
	call	l26a1		; Print character
	call	l25ae		; Position cursor
	pop	af
	call	l2618		; Put hex byte to console
l1ef0:
	call	l204e
l1ef3:
	ld	a,(l1f61)
	or	a
	ret	nz
	jr	l1ebb
l1efa:
	ld	hl,l201b
	call	l251f		; Find in table
	jr	nz,l1f0a	; Nope
	ld	de,l2024
	call	l2531		; Execute thru table
	jr	l1ef3
l1f0a:
	call	l25a1		; Ring the bell
	jr	l1ebb
l1f0f:
	call	l2598		; Get uppercase
	ld	(l0144),a	; Save console character
	ld	hl,l1f50
	call	l251f		; Find in table
	jr	nz,l1f0a	; Nope
	ld	c,l
	ld	a,(l0144)	; Get console character
	call	l26a1		; Print character
	ld	hl,l0080
	ld	a,(l0148)	; Get record position
	call	l253e		; HL:=HL+ACCU
	ld	b,(hl)
	ld	a,(l2189)
	or	a
	ld	a,0f0h
	jr	nz,l1f40
	ld	a,c
	rlca
	rlca
	rlca
	rlca
	and	0f0h
	ld	c,a
	ld	a,0fh
l1f40:
	and	b
	or	c
	ld	(hl),a
	push	af
	call	l218f		; Get ASCII column
	call	l25b1		; Position cursor
	pop	af
	call	l26a1		; Print character
	jr	l1ef0
l1f50:
	db	16,'0123456789ABCDEF'
l1f61:
	db	0
l1f62:
	db	0		; Get write flag
l1f63:
	db	8
	db	2, 4,'Cursor left',null
	db	2,44,'New line',null
	db	3, 4,'Cursor right',null
	db	3,44,'Toggle hex/ASCII field',null
	db	4, 4,'Cursor up',null
	db	4,44,'Write changes to disk',null
	db	5, 4,'Cursor down',null
	db	5,44,'Quit and cancel changes',null
;
	db	8
	db	2, 0,'^A',null
	db	2,40,'CR',null
	db	3, 0,'^F',null
	db	3,40,'TAB',null
	db	4, 0,'^_',null
	db	4,40,'^C',null
	db	5, 0,'^^',null
	db	5,40,'^H',null
l201b:
	db	8
	db	'A'-'@','I'-'@','^'-'@','_'-'@'
	db	'F'-'@',cr,'C'-'@','H'-'@'
l2024:
	dw	l2034		; ^A
	dw	l2063		; TAB
	dw	l2077		; ^^
	dw	l2070		; ^_
	dw	l204e		; ^F
	dw	l2082		; CR
	dw	l2090		; ^C
	dw	l2091		; ^H
;
; Command ^A: Cursor left
;
l2034::
	ld	a,(l2189)
	or	a
	jr	nz,l2043
	ld	a,(l0148)	; Get record position
	dec	a
	and	NoMSB
	ld	(l0148),a	; Update record position
l2043::
	ld	a,(l2188)	; Test hex/ASCII
	or	a
	ret	nz		; ASCII
	ld	a,(l2189)
	cpl
	jr	l206c
;
; Command ^F: Cursor right
;
l204e:
	ld	a,(l2188)	; Test hex/ASCII
	or	a
	ld	a,(l2189)
	jr	nz,l205b	; ASCII
	cpl
	ld	(l2189),a
l205b:
	or	a
	ret	nz
	ld	a,(l0148)	; Get record position
	inc	a
	jr	l207c
;
; Command TAB: Toggle hex/ASCII field
;
l2063::
	ld	a,(l2188)	; Test hex/ASCII
	cpl			; Toggle it
	ld	(l2188),a
	ld	a,0
l206c:
	ld	(l2189),a
	ret
;
; Command ^_: Cursor up
;
l2070::
	ld	a,(l0148)	; Get row
	sub	DSPLINE		; Fix for previous
	jr	l207c
;
; Command ^^: Cursor down
;
l2077::
	ld	a,(l0148)	; Get row
	add	a,DSPLINE	; Fix for next
l207c:
	and	NoMSB		; Strip off hi bit
l207e:
	ld	(l0148),a	; Set row
	ret
;
; Command CR: New line
;
l2082::
	ld	a,0
	ld	(l2189),a
	ld	a,(l0148)
	add	a,10h
	and	70h
	jr	l207e
;
; Command ^C: Write changes to disk
;
l2090::
	or	a		; Set NZ
;
; Command ^H: Quit and cancel changes
;
l2091::
	ld	a,TRUE
	ld	(l1f61),a	; Set end
	ret	z		; Only one
	ld	(l1f62),a	; Set cancel
	ret
;
;
;
l209b:
	call	l06f6		; Display S/P info
	ld	a,(l0181)	; Get clipboard action
	or	a
	ret	z		; Not active
	ld	hl,l0516
	call	l268d		; Give header line
	call	l2148		; Clear display page number
	ld	hl,(l017f)	; Get address of disk buffer
l20af:
	push	hl
	call	l26e0		; Disable cursor
	xor	a
	ld	(l0148),a
	pop	de
l20b8:
	push	de
	push	de
	xor	a
	ld	(l25d1+1),a	; Clear column
	call	l215e
	call	l25b1		; Position cursor
	call	l2152		; Print display page number
	ld	a,(l014b+2)
	add	a,10h
	ld	(l014b+2),a
	call	l25ae		; Position cursor
	pop	de
l20d3:
	ld	a,(de)
	inc	de
	call	l2618		; Put hex byte to console
	call	l25a6		; Print blank
	ld	hl,l0148
	inc	(hl)
	ld	a,3
	and	(hl)
	jr	nz,l20e7
	call	l25a6		; Print blank
l20e7:
	ld	a,0fh
	and	(hl)
	jr	nz,l20d3
	ld	a,(hl)
	sub	10h
	ld	(hl),a
	call	l218f		; Get ASCII column
	ld	hl,l25d1+1
	dec	(hl)		; Get previous column
	call	l25b1		; Position cursor
	ld	a,'|'
	call	l25e7		; Put to console
	pop	de
l2100:
	ld	a,(de)
	inc	de
	call	l26a1		; Print character
	ld	hl,l0148
	inc	(hl)
	ld	a,0fh
	and	(hl)
	jr	nz,l2100
	ld	a,'|'
	call	l25e7		; Put to console
	ld	a,(hl)
	and	7fh
	jp	z,l26db		; Enable cursor
	jr	l20b8
;
; Row table
;
l211b:
	db	14
l211c::
	db	15,16,17,18,19,20,21,22
;
; Hex column table
;
l2124:
	db	 9,12,15,18,22,25,28,31,35,38,41,44,48,51,54,57
;
; ASCII column table
;
l2134::
	db	63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78
l2144:
	db	0,20,40,60
;
; Clear display page number
;
l2148:
	ld	hl,l014b	; Get display page pointer
	xor	a
	ld	(hl),a		; Clear page
	inc	hl
	ld	(hl),a
	inc	hl
	ld	(hl),a
	ret
;
; Print display page number as hex
;
l2152:
	ld	hl,(l014b)	; Get display page
	call	l260d		; Put hex word to console
	ld	a,(l014b+2)
	jp	l2618		; Put hex byte to console
;
;
;
l215e:
	ld	hl,l211c
	ld	a,(l0148)
	rra
	rra
	rra
	rra
	and	0fh
	call	l253e		; Add to HL
	ld	a,(hl)
	ld	(l25d1),a	; Set column
	ret
;
;
;
l2172:
	call	l215e
	ld	a,(l2188)	; Test hex/ASCII
	or	a
	jr	nz,l218f	; Get ASCII column
	call	l218a		; Get hex column
	ld	a,(l2189)
	or	a
	ret	z
	ld	hl,l25d1+1
	inc	(hl)		; Advance column
	ret
;
l2188:
	db	0		; 0x00=hex, 0xFF=ASCII
l2189:
	db	0
;
; Calculate column and position cursor
;
; 1) Hex mode
;
l218a:
	ld	hl,l2124	; Get hex column table
	jr	l2192
;
; 2) ASCII mode
;
l218f:
	ld	hl,l2134
l2192:
	ld	a,(l0148)	; Get position
	and	LOMASK
	call	l253e		; HL:=HL+ACCU
	ld	a,(hl)		; Fetch corresponding column
	ld	(l25d1+1),a	; Set it
	ret
;
; Select disk - Z set says invalid
; Disk data (DPH and DPB) will be loaded
; Directory list will be generated
;
l219f:
	ld	(l222f),a	; Save disk
	ld	c,a
	call	l01e9		; Select drive
	ld	a,h
	or	l		; Test valid disk
	jr	z,l2226		; Nope
	ld	c,.resdsk
	call	BDOS		; Reset disk system
	ld	a,(l222f)	; Get requested disk
	ld	c,a
	call	l01e9		; Select drive
	push	hl		; Save DPH
	ld	hl,lffff
	ld	(l24d9),hl
	ld	(l24db),hl
	pop	hl		; Get back DPH
	ld	de,l1913
	ld	bc,l0010
	ldir			; Unpack it
	ld	hl,(l191d)	; Get address of the DPB
	ld	a,(l0142)	; Get OS version
	or	a
	jr	z,l21d5		; Not CP/M PLUS
	ld	hl,(l191f)	; Get address of the DPB
l21d5:
	ld	de,l1923	; Point to DPB
	ld	bc,l0011
	ldir			; Unpack DPB
	ld	de,(l1923)	; Get number of 128-byte records per track
	ld	bc,(l1930)	; Get number of reserved tracks
	call	l2545		; HL=BC*DE
	push	hl
	ld	(l1938),hl
	ld	a,(l1926)	; Get block mask
	ld	e,a
	ld	d,0
	inc	de
	ld	(l1936),de
	ld	bc,(l1928)	; Get (no. of blocks on the disc)-1
	call	l2545		; HL=BC*DE
	pop	de
	add	hl,de
	ld	de,(l1923)	; Get number of 128-byte records per track
	dec	de
	add	hl,de
	ex	de,hl
	ld	bc,(l1923)	; Get number of 128-byte records per track
	call	l255a		; HL=BC/DE; DE=BC MOD DE
	ld	(l1934),de
	ld	a,(l222f)
	ld	(l0160),a	; Set current disk
	inc	a
	ld	(l005c),a
	ld	(l01b0),a
	call	l22ac		; Build directory list
	ld	a,0ffh
	or	a		; Set success
	ret
l2226:
	ld	a,(l0160)	; Get current disk
	ld	c,a
	call	l01e9		; Select drive
	xor	a
	ret
;
l222f:
	db	0
;
; Give file list
;
l2230:
	ld	hl,l2298
	call	l2653		; Tell directory list
	ld	de,l01b0+.drv
	ld	a,(l0160)	; Get current disk
	add	a,'A'		; Make ASCII
	ld	(l04c3),a
	call	l2396		; Unpack FCB to filename
	ld	hl,l04c3
	call	l265d		; Tell drive and filename
	ld	de,(l0159)	; Get base file pointer
	ld	a,(l015e)	; Get directory index
	ld	l,a
	ld	h,0
	call	l24dd		; HL:=16*HL+DE
	ld	(l0155),hl	; Set file pointer
	xor	a
	ld	(l015c),a	; Clear directory cursor
l225e:
	ld	a,(l015e)	; Get directory index
	ld	b,a
	ld	a,(l015b)	; Get file count
	sub	b
	ld	hl,l015c
	cp	(hl)		; Test end reached
	ret	z		; Yeap
	ld	a,(hl)
	call	l0e12		; Position cursor
	ld	a,'>'
	call	l25e7		; Put to console
	call	l25a6		; Print blank
	ld	de,(l0155)	; Get file pointer
	call	l2396		; Unpack FCB to filename
	ld	hl,l04c5
	call	l265d		; Tell filename
	ld	hl,(l0155)	; Get file pointer
	ld	de,l0010
	add	hl,de		; Advance
	ld	(l0155),hl	; Set file pointer
	ld	hl,l015c
	inc	(hl)		; Advance position
	ld	a,' '
	cp	(hl)		; Test max reached
	ret	z
	jr	l225e
;
l2298:
	_XY	12,23
	db	'Directory List - ',null
;
; Build directory list
;
l22ac:
	xor	a
	ld	(l015b),a	; Clear file count
	ld	(l015d),a	; Clear directory page position
	ld	(l015e),a	; Clear directory index
	ld	hl,(l0140)	; Get start of free data
	ld	(l0155),hl	; Init pointers
	ld	(l0159),hl
	dec	hl
	ld	(l0157),hl
	ld	de,l01b0
	ld	c,.srcfrs
	call	BDOS		; Find file
	cp	OSerr		; Test any
	jr	z,l2308		; Nope
	ld	hl,l0080
	rrca			; * 32 [=2^5 same as shift right 3 bits]
	rrca
	rrca
	call	l253e		; HL:=HL+ACCU
	ld	(l0153),hl	; Save address
	call	l2310		; Unpack file
	ld	hl,(l0157)	; Get file pointer
	ld	de,l0010
	add	hl,de		; Point to next
	ld	(l0157),hl
l22e8:
	ld	de,l01b0
	ld	c,.srcnxt
	call	BDOS		; Find next file
	cp	OSerr		; Test more
	jr	z,l2308		; Nope
	ld	hl,l0080
	rrca
	rrca
	rrca
	call	l253e		; HL:=HL+ACCU
	ld	(l0153),hl	; Save address
	call	l2322		; Insert file
	call	l2310		; Unpack file
	jr	l22e8
l2308:
	ld	hl,(l0157)	; Get file pointer
	inc	hl		; Fix it
	ld	(l0178),hl	; Set base page
	ret
;
; Unpack file
;
l2310:
	ld	hl,(l0153)	; Get buffer address
	inc	hl
	ld	de,(l0155)	; Get destination
	ld	bc,l0010
	ldir			; Unpack it
	ld	hl,l015b
	inc	(hl)		; Advance file count
	ret
;
; Insert file			SUPPLEMENT COMMENT!!!!!!!!!!
;
l2322:
	ld	hl,(l0159)	; Get base file pointer
l2325:
	ld	de,(l0157)	; Get file pointer
	ex	de,hl
	or	a
	sbc	hl,de		; Test within list
	jp	m,l2345		; Nope
	push	de
	ld	hl,(l0153)	; Get buffer address
	inc	hl
	ld	bc,.nam+.ext
	call	l2365		; Find file
	pop	de
	jp	m,l2345		; ^HL<^DE
	ld	hl,l0010
	add	hl,de		; Advance to next
	jr	l2325
l2345:
	ld	(l0155),de	; Set file pointer
	ld	hl,(l0157)	; Get file pointer
	inc	hl
	or	a
	sbc	hl,de		; Get difference
	ld	c,l		; For number of bytes to be moved
	ld	b,h
	ld	hl,(l0157)	; Get file pointer
	push	hl
	ld	de,l0010
	add	hl,de		; Advance pointer
	ld	(l0157),hl
	pop	de
	ld	a,b		; Test within list
	or	c
	ret	z		; Nope, that's it
	ex	de,hl
	lddr			; Move for insertion
	ret
;
; Compare BC bytes ^HL:^DE - Z set says match, M set says ^HL < ^DE
;
l2365:
	xor	a
	ld	(l2386),a	; Set success as default
l2369:
	ld	a,b		; Test end of comparision
	or	c
	jr	z,l2381		; Yeap
	push	bc
	ld	a,(de)		; Get character
	and	NOMSB		; Less attribute
	ld	b,a
	ld	a,(hl)		; Get character
	and	NOMSB		; Less attribute
	sub	b		; Compare
	ld	(l2386),a	; Save result
	pop	bc
	jr	nz,l2381	; No match, abort
	inc	hl
	inc	de
	dec	bc
	jr	l2369
l2381:
	ld	a,(l2386)
	or	a
	ret
;
l2386:
	db	0
;
; Clear L rows starting with row in reg H
;
l2387:
	ld	b,l		; Unpack count
	ld	a,h		; Unpack row
l2389:
	call	l262b		; Clear row
	inc	a
	djnz	l2389
	ld	hl,NIL
	ld	(l0166),hl	; Clear message
	ret
;
; Unpack FCB to filename and get attributes of file
;
l2396:
	ld	hl,l04c5	; Get destination pointer
	ld	b,.nam		; Set length
l239b:
	ld	a,(de)		; Get from FCB
	and	NOMSB		; Less attribute
	ld	(hl),a		; Store
	inc	hl
	inc	de
	djnz	l239b
	ld	(hl),'.'	; Set extension delimiter
	inc	hl
	ld	a,(de)		; Get first extension character
	and	MSB		; Get attribute
	ld	(l0152),a	; It indicates R/O
	ld	b,.ext
l23ae:
	ld	a,(de)		; Get from FCB
	and	NOMSB		; Less attribute
	ld	(hl),a		; Store
	inc	hl
	inc	de
	djnz	l23ae
	ld	a,(l0152)	; Test R/O
	or	a
	ld	a,'W'
	jr	z,l23c0
	ld	a,'O'
l23c0:
	ld	(l04d6),a	; Indicate R/O or R/W
	xor	a
	ld	(l0387),a	; Set no .COM
	ld	hl,l23da
	ld	de,l04ce
	ld	bc,ll23da
	call	l2365		; Find .COM
	ret	nz		; Nope
	ld	a,TRUE
	ld	(l0387),a	; Set .COM
	ret
;
l23da:
	db	'COM'
ll23da	equ	$-l23da
;
; Save DMA pointer
;
l23dd:
	ld	(l23e2),bc	; Save current DMA pointer
	ret
;
l23e2:
	dw	l0080
;
; Set disk buffer thru BDOS
;
l23e4:
	ld	de,(l23e2)	; Get current DMA pointer
	ld	c,.setdma
	jp	BDOS		; Set disk buffer
;
; Read random record
;
l23ed:
	push	bc
	xor	a
	ld	(l005c+_RRN+2),a
	ld	hl,(l005c+_RRN)	; Get current record
	ld	(l0150),hl	; Save it
	ld	hl,(l0146)	; Get record number
	ld	(l005c+_RRN),hl
	call	l23e4		; Set disk buffer thru BDOS
	ld	de,l005c
	ld	c,.rdrnd
	call	BDOS		; Read record
	ld	(l0143),a	; Set I/O result
	or	a
	jr	z,l2418
	ld	hl,(l0150)	; Get record number
	ld	(l0146),hl	; Set record number
	ld	(l005c+_RRN),hl
l2418:
	pop	bc
	ret
;
; Write random record
;
l241a:
	call	l23e4		; Set disk buffer thru BDOS
	ld	de,l005c
	ld	c,.wrrnd
	jp	BDOS		; Write record
;
;
;
l2425:
	ld	a,(l0142)	; Get OS version
	or	a
	push	af
	jr	z,l2439		; Not CP/M PLUS
	ld	a,(l1932)	; Get physical sector shift
	inc	a
l2430:
	dec	a
	jr	z,l2439
	srl	b
	sra	c
	jr	l2430
l2439:
	pop	af
	ret
;
; Calculate DMA buffer address
;
l243b:
	ld	hl,(l193c)	; Get sector
	ld	a,(l1933)	; Get physical sector mask
	and	l		; Get mask for count
	ld	hl,l26e5	; Init base of DMA buffer
	ld	bc,l0080	; Set record size
l2448:
	ret	z
	add	hl,bc		; Calculate buffer address
	dec	a
	jr	l2448
;
;
;
l244d:
	call	l23e4		; Set disk buffer thru BDOS
	ld	bc,(l193a)	; Get track
	call	l01ec		; Select it
	ld	bc,(l193c)	; Get sector
	call	l2425
	push	bc
	jr	z,l2473		; Skip if not CP/M PLUS
	ld	hl,(l24d9)
	sbc	hl,bc
	jr	nz,l2473
	ld	bc,(l24db)
	ld	hl,(l193a)	; Get track
	sbc	hl,bc
	jr	z,l24ae
l2473:
	pop	bc
	ld	(l24d9),bc
	ld	hl,(l193a)	; Get track
	ld	(l24db),hl
	ld	de,(l1913)	; Get sector translation table address
	call	l01fe		; Translate it
	ld	c,l
	ld	b,h
	call	l01ef		; Select sector
	ld	a,(l0142)	; Get OS version
	or	a
	jr	z,l2496		; Not CP/M PLUS
	ld	bc,l26e5
	call	l01f2		; Set DMA address
l2496:
	call	l01f5		; Read sector
	push	af
	ld	a,(l0142)	; Get OS version
	or	a
	jr	z,l24ac		; Not CP/M PLUS
	call	l23e4		; Set disk buffer thru BDOS
	call	l243b		; Calculate DMA buffer address
	ld	de,(l23e2)	; Get current DMA pointer
	ldir
l24ac:
	pop	af
	ret
l24ae:
	pop	bc
	call	l243b		; Calculate DMA buffer address
	ld	de,(l23e2)	; Get current DMA pointer
	ldir
	ret
;
; Write sector to disk
;
l24b9:
	ld	a,(l0142)	; Get OS version
	or	a
	jr	z,l24ce		; Not CP/M PLUS
	call	l243b		; Calculate DMA buffer address
	ex	de,hl
	ld	hl,(l23e2)	; Get current DMA pointer
	ldir			; Unpack it
	ld	bc,l26e5
	call	l01f2		; Set DMA address
l24ce:
	ld	c,1		; Force immediate write
	call	l01f8		; Write sector
	push	af
	call	l23e4		; Set disk buffer thru BDOS
	pop	af
	ret
;
l24d9:
	dw	-1
l24db:
	dw	-1
;
; HL:=16*HL+DE
;
l24dd:
	add	hl,hl		; * 2
	add	hl,hl		; * 4
	add	hl,hl		; * 8
	add	hl,hl		; *16
	add	hl,de		; Add to ^DE
	ret
;
; Clear previous and print new message from pointers
;
l24e3:
	ld	hl,(l0166)	; Get pointer to message to be cleared
	ld	a,h
	or	l		; Test defined
	jr	z,l24fb		; Nope
	push	hl
	ld	hl,l0161
	call	l2653		; Set cursor
	pop	hl
	call	l2670		; Print blanks
	ld	hl,NIL
	ld	(l0166),hl
l24fb:
	ld	hl,(l0164)	; Get message
	ld	a,h
	or	l		; Test defined
	ret	z		; Nope
	ld	(l0166),hl	; Set for clearing
	push	hl
	ld	hl,l0161
	call	l2653		; Set cursor
	call	l26c1		; Turn on revers video
	pop	hl
	call	l265d		; Give message
	call	l26bb		; Turn off revers video
	call	l25a1		; Ring the bell
	ld	hl,NIL
	ld	(l0164),hl	; Clear message
	ret
;
; Find byte in Accu in table ^HL - table starts with length
; Z set says match
;
l251f:
	push	bc
	ld	c,(hl)		; Fetch length
	ld	b,0
	inc	hl
	push	bc
	cpir			; Find key
	pop	hl
	jr	nz,l252f	; Nope
	or	a
	sbc	hl,bc		; Position in table
	dec	hl
	cp	a
l252f:
	pop	bc
	ret
;
; Execute thru table ^DE indexed by reg HL
;
l2531:
	add	hl,hl		; Double index
	add	hl,de		; Position in table
	call	l2537		; Get execution address
	jp	(hl)		; Go
;
; HL:=^HL
;
l2537:
	push	af
	ld	a,(hl)		; Get it
	inc	hl
	ld	h,(hl)		; Into reg HL
	ld	l,a
	pop	af
	ret
;
; HL:=HL+ACCU
;
l253e:
	push	de
	ld	e,a		; Expand Accu
	ld	d,0
	add	hl,de		; Add it
	pop	de
	ret
;
; HL=BC*DE (BC unchanged)
;
l2545:
	ld	hl,0		; Init result
	ld	a,16		; Set counter
	or	a
l254b:
	ex	de,hl
	adc	hl,hl		; Now multiply
	ex	de,hl
	jr	nc,l2555
	add	hl,bc
	jr	nc,l2555
	inc	de
l2555:
	dec	a
	ret	z
	add	hl,hl
	jr	l254b
;
; HL=BC/DE; DE=BC MOD DE (BC unchanged)
;
l255a:
	ld	hl,0		; Init result
	ld	a,16		; Set counter
l255f:
	add	hl,hl		; Now divide
	ex	de,hl
	add	hl,hl
	ex	de,hl
	jr	nc,l2566
	inc	hl
l2566:
	or	a
	sbc	hl,bc
	inc	de
	jp	p,l256f
	add	hl,bc
	dec	de
l256f:
	dec	a
	ret	z
	jr	l255f
;
; Command L: Return to file List
;
l2573::
	ld	a,(l0160)	; Get current disk
	call	l219f		; Select it
;
; Command L: Return to file List
;
l2579:
	ld	a,'D'
	db	01h
l257c::
	ld	a,'F'
	db	01h
;
; Command S: Select track/Sector
;
l257f::
	ld	a,'P'
	db	01h
;
; Command Z: Exit from SuperZap
;
l2582::
	ld	a,'X'
	ld	(l0168),a	; Set disk type
	ret
;
; Get character from console
;
l2588:
	push	bc
	push	de
	push	hl
	call	l01d7		; Get character from console
	ld	(l0144),a	; Save it
	pop	hl
	pop	de
	pop	bc
	ret
;
; Read character from console, return as UPPER case
;
l2595:
	call	l2588		; Get character from console
;
; Convert character to UPPER case
;
l2598:
	cp	'a'		; Test range
	ret	c
	cp	'z'+1
	ret	nc
	and	UPPMASK		; Convert it
	ret
;
; Ring bell on console
;
l25a1:
	push	af
	ld	a,bell
	jr	l25a9
;
; Print blank on console
;
l25a6:
	push	af
	ld	a,' '
l25a9:
	call	l25e7		; Put to console
	pop	af
	ret
;
; Calculate column and position cursor
;
l25ae:
	call	l218a		; Get hex column
;
; Position cursor
;
l25b1:
	ld	hl,l25d1
	call	l2537		; Get from table
;
; Position cursor to row=reg L and column=reg H
;
l25b7:
	push	af
	push	hl
	ld	hl,l0124
	call	l2679		; Position cursor sequence
	pop	hl
	push	hl
	ld	a,(l0127)	; Get direction mode
	or	a
	push	af
	call	l25d3		; Build row/col position
	pop	af
	dec	a
	pop	hl
	call	l25d3		; Build row/col position
	pop	af
	ret
;
l25d1:
	db	0,0		; Temp row/col
;
; Output cursor position sequence
;
l25d3:
	jr	z,l25db		; Skip if column
	ld	a,(l0128)	; Get row offset
	add	a,l		; Add to row
	jr	l25df
l25db:
	ld	a,(l0129)	; Get column offset
	add	a,h		; Add to column
l25df:
	ld	e,a		; Save character
	ld	a,(l012a)	; Test binary
	or	a
	jr	z,l25f2		; Yeap, print as ASCII
	ld	a,e
;
; Put character in Accu to console thru BIOS
;
l25e7:
	push	bc
	push	de
	push	hl
l25ea:
	ld	c,a		; Get character
	call	l01da		; Put to console
	pop	hl
	pop	de
	pop	bc
	ret
;
; Put hex word in reg HL to console
;
l25f2:
	push	bc
	push	de
	push	hl
	ex	de,hl
	ld	de,-1		; Init quotient
	ld	bc,-10		; Init divisor
l25fc:
	add	hl,bc		; Divide word
	inc	de		; Update quotient
	jr	c,l25fc		; Loop
	sbc	hl,bc
	ex	de,hl
	ld	a,h		; Test zero quotient
	or	l
	call	nz,l25f2	; Nope, recursive call
	ld	a,'0'
	add	a,e		; Build ASCII digit
	jr	l25ea		; Put to console
;
; Put hex word in reg HL to console
;
l260d:
	push	af
	ld	a,h		; Get high byte
	call	l2618		; Put to console as hex
	ld	a,l
	call	l2618		; Then low byte
	pop	af
	ret
;
; Put hex byte in Accu to console
;
l2618:
	push	af
	rra
	rra
	rra
	rra
	call	l2621		; Put hi nibbles to console
	pop	af
;
; Put hex nibbles in Accu to console
;
l2621:
	and	LOMASK		; Get nibble
	add	a,90h		; Do the dirty trick
	daa
	adc	a,40h
	daa
	jr	l25e7		; Put to console
;
; Clear row - row in Accu
;
l262b:
	push	af
	push	hl
	ld	l,a		; Set row
	ld	h,0		; Init column
	call	l25b7		; Position cursor
	ld	hl,l010d
	call	l2679		; Erase to end of line
	pop	hl
	pop	af
	ret
;
; Clear screen
;
l263c:
	push	af
	push	hl
	ld	hl,l0108
	call	l2679		; Clear screen
	ld	hl,NIL
	ld	(l0166),hl	; Reset message pointer
	pop	hl
	pop	af
	ret
;
; Print header
;
l264d:
	call	l263c		; Clear screen
	ld	hl,l0131
;
; Print string ^HL on console - string starts with cursor position
;
l2653:
	push	hl
	call	l2537		; Get cursor position from ^HL
	call	l25b7		; Position cursor
	pop	hl
	inc	hl		; Skip cursor position
	inc	hl
;
; Print string ^HL on console
;
l265d:
	ld	a,(hl)		; Get character
	inc	hl
	or	a		; Test end
	ret	z
	call	l25e7		; Put to console
	jr	l265d
;
; Delete string ^HL on console - string starts with cursor position
;
l2666:
	push	hl
	call	l2537		; Get from table
	call	l25b7		; Position cursor
	pop	hl
	inc	hl
	inc	hl
l2670:
	ld	a,(hl)		; Get character
	inc	hl
	or	a		; Test end
	ret	z
	call	l25a6		; Print blank if not
	jr	l2670
;
; Put control string ^HL to console 
;
l2679:
	push	bc
	ld	b,(hl)		; Get length
	inc	b
l267c:
	inc	hl
	dec	b
	jp	z,l2688
	ld	a,(hl)		; Get character
	call	l25e7		; Put to console
	jp	l267c
l2688:
	pop	bc
	ret
;
; Print two lists of messages - second will be printed underline
;
l268a:
	call	l2697		; Print 1st list of messages
l268d:
	push	hl
	call	l26c7		; Turn on underline
	pop	hl
	call	l2697		; Print 2nd list of messages
	jr	l26cc		; Turn off underline
;
; Print list of messages
;
l2697:
	ld	b,(hl)		; Get number of items
	inc	hl
l2699:
	push	bc
	call	l2653		; Print them
	pop	bc
	djnz	l2699
	ret
;
; Print character - map if not printable
;
l26a1:
	or	a
	push	af
	push	af
	call	m,l26c1		; Turn on revers video if out of range
	pop	af
	and	NOMSB		;; ????
	cp	DEL+1		;; ????
	jp	nc,l26b4
	cp	' '
	jp	nc,l26b6
l26b4:
	ld	a,'.'		; Map unprintable
l26b6:
	call	l25e7		; Put to console
	pop	af
	ret	p		; Return if printable, else turn off reverse
;
; Video contol
;
l26bb:
	ld	hl,l0113
	jp	l2679		; Turn off revers video
l26c1:
	ld	hl,l0110
	jp	l2679		; Turn on revers video
l26c7:
	ld	hl,l0116
	jr	l2679		; Turn on underline
l26cc:
	ld	hl,l0119
	jr	l2679		; Turn off underline
l26d1:
	ld	hl,l011c
	jr	l2679		; Turn on fat
l26d6:
	ld	hl,l011d
	jr	l2679		; Turn off fat
l26db:
	ld	hl,l011e
	jr	l2679		; Enable cursor
l26e0:
	ld	hl,l0121
	jr	l2679		; Disable cursor
;
; DMA buffer starts here
;
l26e5:

l2ee5	equ	$+2048

	end	l0201

