; rz (receive Zmodem) is a disassembly of CP/M 3 binaries by Wilfried Schmitten released in 1992.
; this file is an attempt to reconstruct the Z80 assembler source code which has been lost
; credit to Wilfried Schmitten for writing this program initially

;
; +-----------------------------------------------------------------+
; | This file is generated by The Interactive Disassembler (IDA) FW |
; | Copyright (c) 1997 by DataRescue sprl, <ida@datarescue.com>     |
; | Professional version of IDA is at http://www.idapro.com         |
; +-----------------------------------------------------------------+
;


; File Name			  C:\RZ.COM
; Format			  COM File
; Base Address:	0000h Range: 0100h - 1800h Loaded length: 1700h

; Processor:	    z80
; Target assembler: Table Driven Assembler (TASM) by Speech Technology Inc.

cpm		.equ	0000h
iobyte		.equ	0004h
bdos		.equ	0005h

C_READ		.equ	1
A_READ		.equ	3
A_WRITE		.equ	4
A_STATIN	.equ	7
A_STAT_OUT	.equ	8
C_WRITESTR	.equ	9
C_STAT		.equ	11
S_BDOSVER	.equ	12
DRV_SET		.equ	14
F_OPEN		.equ	15
F_CLOSE		.equ	16
F_SFIRST	.equ	17
F_DELETE	.equ	19
F_WRITE		.equ	21
F_MAKE		.equ	22
DRV_GET		.equ	25
F_DMAOFF	.equ	26
F_USERNUM	.equ	32
DRV_DPB		.equ	33
F_SIZE		.equ	35
F_MULTISEC	.EQU	44
S_SYSVAR	.equ	49

buf_len:	.equ	80h
rbuf_size	.equ	1000h

;----------------------------------------------------------------------------

		.org	100h

start:		ld	sp, nstack	; Setup local stack
		ld	c,S_BDOSVER	; Get CP/M version #
		call	bdos
		cp	30h		; Exit if less than
		jp	c,err_vern	; CP/M 3
		ld	de,str_welc
		ld	c,C_WRITESTR	; display version
		call	bdos		; welcome message
		call	sub_195
		ld	hl,(word_179E)	; zero first 20
		xor	a		; bytes of
		ld	b,20		; free memory
		call	fill_bhla
		ld	a,(buf_len)	; if there is nothing in
		or	a		; the command line buffer
		jr	z,skip_cl	; go wait for transfer

		ld	(hl),2
		ld	de,82h
		ex	de,hl
		ld	a,0FFh
		call	sub_172E
		jp	nz, err_exit
		ld	hl,(word_179E)
		inc	hl
		ld	a,(hl)
		or	a
		jp	z,skip_cl
		inc	hl
		ld	e,(hl)
		inc	hl
		ld	d,(hl)
		inc	hl
		ld	a,(de)
		cp	'-'
		jr	nz,loc_152
		call	sub_39A
		ld	e,(hl)
		inc	hl
		ld	d,(hl)
		ld	a,d
		or	e
		jr	z,skip_cl
loc_152:	ld	hl,file_fcb
		ex	de,hl
		call	sub_1492
		ld	hl,file_fcb
		xor	a
		or	(hl)
		jr	nz,loc_164
		ld	a,(byte_17A1)
		ld	(hl),a
loc_164:	ld	bc,0Dh
		add	hl,bc
		dec	de
		ldi
		ld	de,file_fcb
		call	sub_1B0
		call	clo_c
skip_cl:	ld	de,str_sxfr	; display start
		ld	c,C_WRITESTR	; tranfer message
		call	bdos
		call	sub_3EF
		call	sub_8D1
		call	sub_451
smod_b_186:	.equ	$+1
loc_185:	ld	bc,0
		ld	(word_17A2),bc
		ld	de,file_fcb
		call	sub_1B0
		jp	cpm


;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_195:	ld	a,(iobyte)
		ld	b,a
		rlca
		rlca
		rlca
		rlca
		and	0Fh
		ld	(byte_17A0),a
		ld	a,b
		and	0Fh
		inc	a
		ld	(byte_17A1),a
		ld	hl,(byte_17A0)
		ld	(smod_b_186),hl
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1B0:	ld	a,(de)
		push	af
		dec	de
		ld	a,(de)
		ld	e, a
		ld	c,F_USERNUM
		call	bdos		; get/set user number
		pop	af
		dec	a
		ld	e, a
		ld	c,DRV_SET
		jp	bdos		; Select disc

;----------------------------------------------------------------------------

err_vern:	ld	de,str_cpm3	; Display version
		ld	c,C_WRITESTR	; error and exit
		call	bdos

err_exit:	ld	de,str_info	; Display usage
		ld	c,C_WRITESTR	; and exit to
		call	bdos		; CP/M
		jp	cpm

;----------------------------------------------------------------------------

str_welc:	.text	"RZ for CP/M 3   V 1.04\r\n"
		.text	"(C) 92 wshbg\r\n\n$"
str_sxfr:	.text	"start your local X/Y/ZModem sending program\r\n\n$"
str_cpm3:	.text	"sorry, CP/M 3 Tool\r\n$"
str_info:	.text	"usage: rz [-?pbcrxyz] [du:fn]\r\n\n"
		.text	" options for ZModem:\r\n"
		.text	"            ?     this help\r\n"
		.text	"            p     protect File\r\n"
		.text	"            b     receive binary\r\n"
		.text	"            c     convert to local linefeed\r\n"
		.text	"            r     resume transmission\r\n"
		.text	"            x,y,z Protokoll\r\n"
		.text	"            du:fn defaults to XModem\r\n\n"
		.text	"these values override options from sender\r\n$"

;----------------------------------------------------------------------------
;		Search list of command line options

sub_39A:	push	hl
		push	de
loc_39C:	inc	de		; get next character
		ld	a,(de)		; to check
		or	a		
		jr	z,loc_3AE	; exit if not found
		ld	hl,stab_clo	; table to seach
		ld	bc,stab_clo_s	; no. of table entries
		cpir			; check match
		call	z,stab_jmp	; if yes get table entry and jump
		jr	loc_39C		; else continue search

loc_3AE:	pop	de
		pop	hl
		ret

stab_clo:	.text	"?PBCXYZR"
stab_clo_s:	.equ	$-stab_clo

		.dw	clo_help	; ?
		.dw	clo_p		; P
		.dw	clo_b		; B
		.dw	clo_c		; C
		.dw	clo_x		; X
		.dw	clo_y		; Y
		.dw	clo_z		; Z
		.dw	err_exit	; R

;----------------------------------------------------------------------------
;		Set flags and options from command line

clo_c:		ld	a,1
		jr	set_opt
clo_b:		ld	a,3
		jr	set_opt
clo_p:		ld	a,4
set_opt:	ld	(byte_8AF),a
		ret

clo_z:		ld	a,$ff
		ld	(flg_zmdm),a
		ret
clo_y:		ld	a,$ff
		ld	(flg_ymdm),a
		ret
clo_x:		ld	a,$ff
		ld	(flg_xmdm),a
		ret
clo_help:	ld	a,$ff
		ld	(flg_help),a
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_3EF:	xor	a
		ld	(byte_460),a
		ld	(byte_464),a
		ld	c,S_SYSVAR
		ld	de,byte_45F
		call	bdos		; Access the system variables
		ld	a,h
		cpl
		ld	h,a
		ld	a,l
		cpl
		ld	l, a
		ld	(word_46F),hl
		ld	c,S_SYSVAR
		ld	de,byte_463
		call	bdos		; Access the system variables
		ld	(word_46B),hl
		ld	de,(word_46F)
		ld	a,h
		and	d
		ld	h,a
		ld	a,l
		and	e
		ld	l, a
		ld	(word_465),hl
		ld	c,S_SYSVAR
		ld	de,byte_467
		call	bdos		; Access the system variables
		ld	(word_46D),hl
		ld	de,(word_46F)
		ld	a,h
		and	d
		ld	h,a
		ld	a,l
		and	e
		ld	l, a
		ld	(word_469),hl
loc_437:	ld	a,0FEh
		ld	(byte_464),a
		ld	de,byte_463
		ld	c,S_SYSVAR
		call	bdos		; Access the system variables
		ld	a,0FEh
		ld	(byte_468),a
		ld	de,byte_467
		ld	c,S_SYSVAR
		jp	bdos		; Access the System Control Block

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_451:	ld	hl,(word_46B)
		ld	(word_465),hl
		ld	hl,(word_46D)
		ld	(word_469),hl
		jr	loc_437

;----------------------------------------------------------------------------'

byte_45F:	.db	28h
byte_460:	.db	0
		.db	0
		.db	0
byte_463:	.db	24h
byte_464:	.db	0
word_465:	.dw	0
byte_467:	.db	22h
byte_468:	.db	0
word_469:	.dw	0
word_46B:	.dw	0
word_46D:	.dw	0
word_46F:	.dw	0

;----------------------------------------------------------------------------
;		Call BDOS and set status flag

bdos_s:		call	bdos
		or	a
		ret

;----------------------------------------------------------------------------
;		Search for 0 terminated string starting at HL

Search0:	push	af
loc_477:	push	bc
		xor	a
		ld	b,a
		ld	c,a
		cpir
		pop	bc
		djnz	loc_477
		pop	af
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_482:	ld	a,(byte_2D04)
		ld	de,text495h	; Update error string with errors
		call	sub_16E7
		ld	de,text493h
		ld	c,C_WRITESTR
		jp	bdos		; Output string

;----------------------------------------------------------------------------

text493h:	.text	"\r\n"
text495h:	.db	0,0,0
		.text	" error(s)\r\n$"

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_4A4:	ld	de,file_fcb
		ld	hl,byte_4F8
		ld	(hl),':'
		inc	hl
		xor	a
		ld	b,0Dh
		call	fill_bhla
		inc	de
		call	sub_16C4
		dec	de
		ld	a,(de)
		add	a,'A'-1
		ld	(byte_4F4),a
		dec	de
		ld	a,(de)
		ld	de,byte_4F5
		call	sub_16E7
		ld	a,'$'
		ld	(term_fn),a
		ld	de,text4F2h
		ld	c,C_WRITESTR
		call	bdos		; Output string
		ld	hl,(byte_2CD4)
		ld	a,h
		or	l
		ret	z
		ld	b,1
		call	Search0
		dec	hl
		ld	(hl),'$'
		ld	de,(byte_2CD4)
		ld	c,C_WRITESTR
		call	bdos		; Output string
		ld	de,newline
		ld	c,C_WRITESTR
		jp	bdos		; Output string

;----------------------------------------------------------------------------

text4F2h:	.text	"\r\n"
byte_4F4:	.db	0			
byte_4F5:	.db	0 ;
		.db	0 ;
		.db	0 ;
byte_4F8:	.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	0 ;
		.db	20h ;
term_fn:	.db	0			
newline:	.text	"\r\n$"

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_50B:	ld	hl,loc_2CAB
		ld	de,loc_51F
		call	loc_774
		ld	(hl),'$'
		ld	de,text51Eh
		ld	c,C_WRITESTR
		jp	bdos		; Output string

;----------------------------------------------------------------------------
text51Eh:
		.db  0Dh ;
loc_51F:	.db    0 ;
		.db    0 ;
		.db    0 ;
		.db    0 ;
		.db    0 ;
		.db    0 ;
		.db    0 ;
		.db    0 ;
		.db    0 ;
		.db    0 ;

disp_bsy:	ld	hl,str_busy
smod_52D:	.equ	$+1		; self modifying
		ld	a,0
		inc	a
		and	3
		ld	(smod_52D),a
		ld	e,a
		ld	d,0
		add	hl,de
		ld	a,(hl)
		ld	(str_sav),a
		ld	de,str_rev
		ld	c,C_WRITESTR
		jp	bdos

str_busy:	.db	7ch		; |
		.db	02fh		; /
		.db	2dh		; -
		.db	5ch 		; \
str_rev:	.db	20h		;
str_sav:	.db	7ch		; |
		.db	08h		; /b
		.db	08h		; /b
		.db	24h		; $

		ld	de,text569h
		jr	sub_555

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_552:	ld	de,text55Ah
sub_555:	ld	c,C_WRITESTR
		jp	bdos		; Output string

;----------------------------------------------------------------------------

text55Ah:	.text	"File skipped\r\n$"
text569h:	.text	"can't open any file\r\n$"

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_57F:	ld	hl,byte_586
		ld	(hl),a
		inc	hl
		ld	(hl),c
		ret

;----------------------------------------------------------------------------

byte_586:	.db	0
byte_587:	.db	0

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_588:	or	a		; is the receive
		ld	hl,(rbuf_bfree)	; buffer full?
		ld	de,rbuf_size
		sbc	hl,de
		jr	z,loc_5A9	
		ld	c,A_STATIN	; if it isn't see
		call	bdos		; if there is a character
		or	a		; available
		jr	z,loc_5A9
		ld	c,A_READ	; get the character
		call	bdos
		ld	c,a
		ld	hl,rbuf_bfree
		call	sub_61C
		jr	sub_588

;----------------------------------------------------------------------------

loc_5A9:	ld	hl,byte_587
		or	(hl)
		ret	nz
		ld	hl,(rbuf_bfree)
		ld	a,h
		or	l
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_5B4:	ld	a,(byte_587)
		or	a
		ld	hl,rbuf_bfree
		jp	z,loc_5F7
		push	af
		ld	hl,byte_587
		dec	(hl)
		dec	hl
		pop	af
		ld	a,(hl)
		ret

;----------------------------------------------------------------------------

loc_5C7:	LD	C,A_WRITE	; punch out
		LD	E,A
		JP	bdos

;----------------------------------------------------------------------------
;	Set I/O byte
;	E=I/O byte
;	S u b r	o u t i	n e

sub_5CD:	ld	c,A_STAT_OUT
		call	bdos		; BDOS function 8 (A_STATOUT) - Auxiliary Output status
		or	a
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e	; Receive a byte into the receive buffer?

sub_5D4:	push	bc
		ld	b,5Fh		; retries?
loc_5D7:	push	bc
		call	sub_588
		pop	bc
		jr	nz,loc_5E6
		call	delay
		djnz	loc_5D7
		call	sub_588
loc_5E6:	call	nz,sub_5B4
		pop	bc
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

delay:		push	bc
		ld	a,4
		ld	b,0
loc_5F0:	djnz	loc_5F0
		dec	a
		jr	nz,loc_5F0
		pop	bc
		ret

;----------------------------------------------------------------------------

loc_5F7:	ld	e,(hl)
		inc	hl
		ld	d,(hl)
		ld	a,d
		or	e
		ret	z
		dec	de
		ld	(hl),d
		dec	hl
		ld	(hl),e
		ld	de,4
		add	hl,de
		push	hl
		ld	e,(hl)
		inc	hl
		ld	d,(hl)
		inc	hl
		add	hl,de
		ex	(sp),hl
		inc	de
		ld	a,e
		and	0FFh
		ld	(hl),a
		inc	hl
		ld	a,d
		and	0Fh
		ld	(hl),a
		pop	hl
		ld	a,1
		or	a
		ld	a,(hl)
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_61C:	or	a
		push	hl
		ld	e,(hl)
		inc	hl
		ld	d,(hl)
		ld	hl,rbuf_size
		sbc	hl,de
		pop	hl
		ret	z
		inc	de
		ld	(hl),e
		inc	hl
		ld	(hl),d
		inc	hl
		push	hl
		ld	e,(hl)
		inc	hl
		ld	d,(hl)
		inc	hl
		inc	hl
		inc	hl
		add	hl,de
		ex	(sp),hl
		inc	de
		ld	a,e
		and	0FFh
		ld	(hl),a
		inc	hl
		ld	a,d
		and	0Fh
		ld	(hl),a
		pop	hl
		ld	(hl),c
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_643:	ld	hl,word_17A2
		ld	b,25h
		jr	loc_650

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_64A:	ld	b,3
		jr	loc_650

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_64E:	ld	b,6
loc_650:	xor	a
		jp	fill_bhla

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_654:	xor	a
		or	(hl)
		ret	z
		dec	(hl)
		inc	hl
		inc	hl
		ld	e,(hl)
		ld	d,0
		ld	a,e
		inc	a
		and	7Fh
		ld	(hl),a
		inc	hl
		adc	hl,de
		ld	a,(hl)
		ret	nc
		ccf
		ret

;----------------------------------------------------------------------------

sub_669:	LD	A,80H
		SUB	(HL)
		RET	Z
		INC	(HL)
		INC	HL
		LD	E,(HL)
		LD	D,0
		LD	A,E
		INC	A
		AND	7FH
		LD	(HL),A
		INC	HL
		INC	HL
		ADC	HL,DE
		LD	(HL),C
		RET	NC
		CCF
		RET

;----------------------------------------------------------------------------
;		Jump to table address entry

stab_jmp:	add	hl,bc
		sla	c
		add	hl,bc
		ld	c,(hl)
		inc	hl
		ld	h,(hl)
		ld	l, c
		jp	(hl)

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_688:	xor	a
		push	bc
		push	de
		push	hl
		ld	(hl),a
		ld	d,h
		ld	e,l
		inc	de
		jr	loc_697

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_692:	push	bc
		push	de
		push	hl
		ldi
loc_697:	ldi
		ldi
		ldi
		pop	hl
		pop	de
		pop	bc
		ret

;----------------------------------------------------------------------------

loc_6A1:	PUSH	HL
		POP	IX
		PUSH	DE
		POP	IY
		LD	A,(IX+3)
		XOR	(IY+3)
		JP	P,loc_6B6
		XOR	(IX+3)
loc_6B3:	RET	M
		CCF
		RET

loc_6B6:	XOR	(IX+3)
		JP	P,loc_6C2
		CALL	loc_6C2
		SCF
		JR	loc_6B3

loc_6C2:	PUSH	BC
		PUSH	DE
		PUSH	HL
		EX	DE,HL
		OR	A
		LD	B,4
loc_6C9:	LD	A,(DE)
		SBC	A,(HL)
		INC	DE
		INC	HL
		DJNZ	loc_6C9
		POP	HL
		POP	DE
		POP	BC
		RET

sub_6D3:	PUSH	BC
		PUSH	DE
		PUSH	HL
		LD	B,4
loc_6D8:	LD	A,(DE)
		XOR	(HL)
		JR	NZ,loc_6E0
		INC	DE
		INC	HL
		DJNZ	loc_6D8
loc_6E0:	POP	HL
		POP	DE
		POP	BC
		RET

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_6E4:	push	bc
		push	de
		push	hl
		or	a
		ex	af, af'
		ld	a,4
loc_6EB:	ex	af, af'
		ld	a,(de)
		adc	a,(hl)
		ld	(bc),a
		inc	bc
		inc	de
		inc	hl
		ex	af, af'
		dec	a
		jr	nz,loc_6EB
		pop	hl
		pop	de
		pop	bc
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_6FA:	push	bc
		push	de
		push	hl
		ex	de,hl
		or	a
		ex	af, af'
		ld	a,4
loc_702:	ex	af, af'
		ld	a,(de)
		sbc	a,(hl)
		ld	(bc),a
		inc	bc
		inc	hl
		inc	de
		ex	af, af'
		dec	a
		jr	nz,loc_702
		ex	af, af'
		pop	hl
		pop	de
		pop	bc
		ret

;----------------------------------------------------------------------------

loc_712:	PUSH	BC
		PUSH	HL
		LD	A,1
		ADD	A,(HL)
		LD	(HL),A
		JR	NC,loc_723
		LD	B,3
loc_71C:	INC	HL
		LD	A,0
		ADC	A,(HL)
		LD	(HL),A
		DJNZ	loc_71C
loc_723:	POP	HL
		POP	BC
		RET

;----------------------------------------------------------------------------

loc_726:	call	sub_688
sub_729:	push	bc
		push	hl
		ld	a,(hl)
		sub	1
		ld	(hl),a
		ld	b,3
loc_731:	inc	hl
		ld	a,(hl)
		sbc	a,0
		ld	(hl),a
		djnz	loc_731
		pop	hl
		pop	bc
		ret

;----------------------------------------------------------------------------

loc_73B:	PUSH	BC
		PUSH	DE
		PUSH	HL
		EX	DE,HL
		LD	A,004H
loc_741:	PUSH	AF
		LD	A,(DE)
		AND	(HL)
		LD	(BC),A
		INC	BC
		INC	DE
		INC	HL
		POP	AF
		DEC	A
		JR	NZ,loc_741
		POP	HL
		POP	DE
		POP	BC
		RET

;----------------------------------------------------------------------------

loc_750:	.db	0,	0CAh,	9Ah,	3Bh
		.db	0,	0E1h,	0F5h,	5
		.db	80h,	96h,	98h,	0
		.db	40h,	42h,	0Fh,	0
		.db	0A0h,	86h,	1,	0
		.db	10h,	27h,	0,	0
		.db	0E8h,	3,	0,	0
		.db	64h,	0,	0,	0
		.db	0Ah,	0,	0,	0

loc_774:	ld	(smod_w_7BF),de
		ld	de,byte_2891
		call	sub_692
		ld	c,+(loc_774-loc_750)/4
		ld	de,loc_750-4
		xor	a
		ld	(smod_b_7BA),a
loc_787:	ld	a,30h
		ld	(smod_b_7B4),a
		inc	de
		inc	de
		inc	de
		inc	de
		ld	b,0Ah
loc_792:	push	bc
		ld	hl,byte_2891
		ld	bc,loc_2895
		call	sub_6FA
		pop	bc
		jr	c,loc_7B3
		push	de
		ld	a,(smod_b_7B4)
		inc	a
		ld	(smod_b_7B4),a
		ld	de,byte_2891
		ld	hl,loc_2895
		call	sub_692
		pop	de
		djnz	loc_792
smod_b_7B4:	.EQU	$+1
loc_7B3:	LD	A,30H		; self modifying
		CP	30H
		JR	NZ,loc_7BE
smod_b_7BA:	.EQU	$+1
		LD	A,0
		OR	A
		JR	Z,loc_7CB
smod_w_7BF:	.EQU	$+1
loc_7BE:	LD	HL,0
		LD	(HL),A
		INC	HL
		LD	(smod_w_7BF),HL
		LD	A,30H
		LD	(smod_b_7BA),A
loc_7CB:	DEC	C
		JR	NZ,loc_787
		LD	A,(byte_2891)
		AND	0FH
		ADD	A,30H
		LD	HL,(smod_w_7BF)
		LD	(HL),A
		INC	HL
		LD	(HL),0
		RET

sub_7DD:	PUSH	AF
smod_b_7DF:	.EQU	$+1
		ADD	A,0
		LD	(smod_b_7DF),A
		POP	AF
		RET

loc_7E5:	.db	20h
		.db	83h
		.db	0B8h
		.db	0EDh

loc_7E9:	.db	0E3h
		.db	20h
		.db	0BBh
		.db	0DEh

sub_7ED:	PUSH	AF
smod_w_7F0:	.EQU	$+2
		LD	IY,loc_289D
		LD	IX,loc_2899
		XOR	(ix+0)
		LD	H,0
		LD	L,A
		ADD	HL,HL
		ADD	HL,HL
		LD	B,H
		LD	C,L
		ADD	IY,BC
		LD	A,(IY)
		XOR	(IX+1)
		LD	(ix+0),A
		LD	A,(IY+1)
		XOR	(IX+2)
		LD	(IX+1),A
		LD	A,(IY+2)
		XOR	(IX+3)
		LD	(IX+2),A
		LD	A,(IY+3)
		LD	(IX+3),A
		POP	AF
		RET

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_825:	push	de
		push	hl
		ld	hl,(smod_w_7F0)
		ld	bc,3FFh
		add	hl,bc
		push	hl
		pop	iy
		ld	ix, loc_7E5
		xor	a
loc_836:	push	af
		ld	hl,0FFFFh
		ld	de,0FFFFh
		xor	e
		ld	e, a
		ld	b,8
loc_841:	scf
		rr	h
		rr	l
		rr	d
		rr	e
		jr	nc,loc_860
		ld	a,e
		xor	(ix+0)
		ld	e, a
		ld	a,d
		xor	(ix+1)
		ld	d,a
		ld	a,l
		xor	(ix+2)
		ld	l, a
		ld	a,h
		xor	(ix+3)
		ld	h,a
loc_860:	djnz	loc_841
		ld	a,h
		cpl
		ld	(iy+0),	a
		dec	iy
		ld	a,l
		cpl
		ld	(iy+0),	a
		dec	iy
		ld	a,d
		cpl
		ld	(iy+0),	a
		dec	iy
		ld	a,e
		cpl
		ld	(iy+0),	a
		dec	iy
		pop	af
		inc	a
		jr	nz,loc_836
		pop	hl
		pop	de
		ret

;----------------------------------------------------------------------------

crc16:		PUSH	AF
crc_seed:	.equ	$+1
		LD	HL,0
		LD	DE,1021H	; crc16-ccitt polynomial
		XOR	H
		LD	H,A
		LD	B,8
loc_890:	ADD	HL,HL
		JR	NC,loc_899
		LD	A,H
		XOR	D
		LD	H,A
		LD	A,L
		XOR	E
		LD	L,A
loc_899:	DJNZ	loc_890
		LD	(crc_seed),HL
		POP	AF
		RET

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_8A0:	xor	a
		ld	h,a
		ld	l, a
		ld	(smod_b_7DF),a
		ld	(crc_seed),hl
		ld	hl,loc_2899
		jp	loc_726

;----------------------------------------------------------------------------

byte_8AF:	.db 	4
flg_zmdm:	.db 	0
flg_xmdm:	.db 	0
flg_ymdm:	.db 	0
flg_help:	.db 	0
word_8B4:	.dw 	0

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_8B6:	xor	a
		ld	c,a
		ld	b,8
		ld	a,h
loc_8BB:	rlca
		set	7,c
		jr	c,loc_8C4
		rr	c
		djnz	loc_8BB
loc_8C4:	ld	a,h
		and	c
		ld	h,a
		ld	l,0
		ld	(word_2CEB),hl
		dec	hl
		ld	(word_8B4),hl
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_8D1:	xor	a
		ld	hl,byte_2C9D
		ld	b,61h
		call	fill_bhla
		ld	hl,rbuf_bfree
		call	sub_64E
		call	sub_825
		ld	hl,(word_179E)
		ld	(word_2CE9),hl
		ld	de,(6)
		ex	de,hl
		or	a
		sbc	hl,de
		call	sub_8B6
		ld	a,(flg_zmdm)
		cp	0
		jr	z,loc_8FD
		ld	a,7
loc_8FD:	ld	(byte_2CA4),a
		ld	a,10h
		ld	(byte_2C9E),a
		ld	a,(byte_8AF)
		cp	3
		jr	c,loc_947
		ld	a,1
		ld	(smod_b_B0A),a
		call	loc_ACF
		jp	c,loc_954
		or	a
		jr	z,loc_92B
		cp	4
		jr	z,loc_924
		cp	0Fh
		jr	nz,loc_924
		jr	locret_953

loc_924:	call	sub_BB4
		jr	c,loc_954
		jr	locret_953

;----------------------------------------------------------------------------

loc_92B:	ld	a,3
		ld	(byte_8AF),a
		xor	a
		ld	(byte_2D04),a
		call	sub_11C1
		jr	c,loc_954
		call	sub_961
		jr	c,loc_954
		jr	z,locret_953	; ret z ?
		call	sub_11FA
		jr	c,loc_954
		jr	loc_92B

;----------------------------------------------------------------------------

loc_947:	call	sub_961
		jr	c,loc_954
		jr	z,locret_953	; ret z ?
		call	sub_11FA
		jr	c,loc_954
locret_953:	ret

;----------------------------------------------------------------------------

loc_954:	call	sub_DD9
		ld	a,(byte_2CA5)
		cp	0FFh
		call	z,sub_D0E
		jr	locret_953	; ret ?

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_961:	ld	a,(flg_xmdm)
		cpl
		ld	hl,flg_ymdm
		or	(hl)
		ld	(byte_2CA3),a
		ld	a,(byte_2CA4)
		or	a
		jr	z,loc_975
		ld	(byte_2CA1),a
loc_975:	ld	a,(flg_ymdm)
		cp	0FFh
		jr	z,loc_988
		ld	a,(byte_2CA2)
		cp	2
		jr	nz,loc_988
		ld	a,0
		ld	(byte_2CA3),a
loc_988:	ld	a,(byte_2CA2)
		cp	1
		jr	nz,loc_994
		ld	a,0FFh
		ld	(byte_2CA3),a
loc_994:	ld	a,(byte_2CA1)
		cp	7
		jr	z,loc_9AE
		ld	a,(byte_2CA1)
		cp	3
		jr	nz,loc_9AE
		ld	a,(byte_2CA3)
		cp	0FFh
		jr	nz,loc_9AE
		ld	a,7
		ld	(byte_2CA1),a
loc_9AE:	ld	a,(byte_8AF)
		cp	3
		jr	c,loc_9E3
		call	sub_643
		ld	hl,(word_2CE9)
		xor	a
		or	(hl)
		scf
		ret	z
		push	hl
		ld	b,1
		call	Search0
		dec	hl
		ld	(hl),20h
		pop	hl
		ld	de,loc_2CD0
		ld	a,7
		ld	(de),a
		ld	a,0FFh
		call	sub_172E
		ld	hl,(word_2CD2)
		ld	de,file_fcb
		call	sub_1492
		ld	hl,(byte_17A0)
		ld	(word_17A2),hl
loc_9E3:	call	sub_4A4
		ld	de,file_fcb
		call	sub_169E
		jr	nz,loc_A11
		ld	de,file_fcb
		ld	c,F_MAKE
		call	bdos_s
		ret	c
		ld	a,0FFh
		ld	(byte_2CA5),a
		ld	hl,byte_280E
		call	sub_64A
		ld	a,(byte_2CD1)
		cp	2
		jr	c,loc_A0D
sub_A09:	ld	de,(byte_2CD4)
loc_A0D:	ld	a,1
		or	a
		ret

;----------------------------------------------------------------------------

loc_A11:	call	sub_A09
		ld	a,(byte_8AF)
		cp	4
		jr	nz,loc_A24
		ld	a,(byte_2CA1)
		cp	7
		jr	nz,loc_A35
		jr	loc_A2E

;----------------------------------------------------------------------------

loc_A24:	ld	de,file_fcb
		ld	c,F_DELETE
		call	bdos_s
		jr	nc,loc_9E3
loc_A2E:	call	sub_552
		ld	a,5
		scf
		ret

;----------------------------------------------------------------------------

loc_A35:	ld	a,(byte_2CA1)
		cp	3
		jr	z,loc_A43
		ld	a,(flg_help)
		cp	0FFh
		jr	nz,loc_A24
loc_A43:	ld	de,loc_2811
		ld	c,F_DMAOFF
		call	bdos		; BDOS function 26 (F_DMAOFF) - Set DMA address
		ld	e, 1
		ld	c,F_MULTISEC
		call	bdos		; BDOS function 44 (F_MULTISEC) - Set number of records to read/write at once
		ld	de,file_fcb
		ld	c,F_OPEN
		call	bdos_s
		ret	c
		ld	a,0FFh
		ld	(byte_2CA5),a
		ld	hl,byte_280E
		call	sub_64A
		ld	de,file_fcb
		ld	c,F_SIZE
		call	bdos_s
		ret	c
		ld	hl,byte_17C7
		ld	(hl),0
		ld	hl,loc_17C4
		call	sub_729
		ld	de,loc_2CAB
		call	sub_692
		ex	de,hl
		ld	b,7
loc_A83:	push	hl
		sla	(hl)
		inc	hl
		rl	(hl)
		inc	hl
		rl	(hl)
		inc	hl
		rl	(hl)
		pop	hl
		djnz	loc_A83
		ld	de,file_fcb
		ld	c,DRV_DPB
		call	bdos_s
		ret	c
		ld	a,(byte_2CA1)
		cp	3
		jr	z,loc_AA6
		ld	a,9
		or	a
		ret

;----------------------------------------------------------------------------

loc_AA6:	ld	a,80h
		ld	(byte_280E),a
loc_AAB:	ld	hl,byte_280E
		call	sub_654
		jr	z,loc_AC6
		cp	1Ah
		jr	nz,loc_AAB
		ld	a,(byte_2810)
		dec	a
		ld	(byte_280F),a
		ld	hl,byte_280E
		ld	a,7Fh
		sub	(hl)
		jr	loc_AC8

;----------------------------------------------------------------------------

loc_AC6:	ld	a,80h
loc_AC8:	ld	(byte_280E),a
		ld	a,1
		or	a
		ret

;----------------------------------------------------------------------------

loc_ACF:	xor	a
		ld	(byte_2D04),a
		ld	a,4
		ld	hl,byte_8AF
		cp	(hl)
		ld	a,0
		ret	nz
		ld	hl,word_2CED
		ld	b,11h
		xor	a
		call	fill_bhla
		call	sub_FAA
		ld	a,(byte_2CA6)
		cp	0FFh
		ld	b,5
		jr	z,loc_AF3
		ld	b,0Ah

loc_AF3:	push	bc
		ld	ix,loc_2CE0
		ld	(ix+3),20h
		ld	(ix+2),0
		ld	hl,(word_2CEB)
		ld	(ix+0),l
		ld	(ix+1),h
smod_b_B0A:	.equ	$+1
		ld	a,1		; self modifying value
		CALL	sub_13BA
		LD	A,(smod_b_B0A)
		CP	5
		JR	NZ,0B1AH
		LD	A,1
		LD	(smod_b_B0A),A
loc_B1A:	CALL	sub_FD1
		LD	HL,loc_B96
		LD	BC,0AH
		CPIR
		JP	Z,stab_jmp
loc_B28:	LD	HL,byte_2D04
		INC	(HL)
		CALL	sub_482
loc_B2F:	POP	BC
		DJNZ	loc_AF3
		XOR	A
		RET

loc_B34:	POP	BC
       		LD	A,0FFH
       		SCF
       		RET

loc_B39:	POP	BC
		CALL	sub_D9B
		LD	A,0FH
		RET

loc_B40:	LD	HL,loc_2CE0
		CALL	sub_688
		JR	loc_B68


loc_B48:	LD	IX,loc_2CA7
		LD	A,(IX+3)
		AND	40H
		LD	(byte_2C9D),A
		CALL	loc_EC7
		CP	0EBH
		LD	A,6
		JR	NZ,loc_B6A
		LD	HL,(word_2CE9)
		LD	DE,loc_2CAF
		LD	BC,20H
		LDIR
loc_B68:	LD	A,3
loc_B6A:	PUSH	AF
		LD	HL,loc_2CE0
		CALL	sub_688
		POP	AF
		CALL	sub_13BA
		CALL	sub_FC9
		JP	loc_B28

loc_B7B:  	LD	HL,loc_2CA7
		LD	DE,loc_2C9F
		CALL	sub_692
		LD	A,1
		LD	(smod_b_B0A),A
		CALL	loc_EC7
		CP	0EBH
		LD	A,6
		JR	NZ,loc_B6A
		POP	BC
		LD	A,4
		RET

loc_B96:	.db	0
		.db	0Bh
		.db	0FEh
		.db	4
		.db	2
		.db	11h
		.db	12h
		.db	0Fh
		.db	8
		.db	10h

loc_BA0:	.dw	loc_B34
		.dw	loc_B39
		.dw	loc_B1A
		.dw	loc_B34
		.dw	loc_B40
		.dw	loc_B48
		.dw	loc_B7B
		.dw	loc_B28
		.dw	loc_B2F
		.dw	loc_B2F

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_BB4:	call	sub_BD3
		ret	c
		cp	0Bh
		jr	z,loc_BC2
		cp	5
		jr	z,loc_BC2
		or	a
		ret

;----------------------------------------------------------------------------

loc_BC2:	call	loc_ACF
		ret	c
		cp	4
		jr	z,sub_BB4
		cp	0Fh
		ld	a,0
		ret	z
		ld	a,0FFh
		scf
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_BD3:	call	sub_961
		jr	nc,loc_BDF
		ld	a,5
		ld	(smod_b_B0A),a
		or	a
		ret

loc_BDF:	cp	9
		jr	z,loc_BE9
		ld	hl,loc_2CAB
		call	sub_688
loc_BE9:	xor	a
		ld	(byte_2D04),a
		call	sub_FAA
loc_BF0:	call	sub_FC9
		call	sub_D30
		ld	hl,loc_2CAB
		ld	de,loc_2CE0
		call	sub_692
		ld	hl,rbuf_bfree
		call	sub_64E
		ld	a,9
		call	sub_13BA
loc_C0A:	call	sub_FD1
		ld	hl,stab_CE4
		ld	bc,7
		cpir
		jp	z,stab_jmp
		ld	a,0FFh
		scf
		ret

;----------------------------------------------------------------------------

loc_C1C:	LD	HL,byte_2D04
		INC	(HL)
		CALL	sub_482
		LD	HL,byte_2D04
		LD	A,0AH
		CP	(HL)
		JP	NZ,loc_BF0
		LD	A,0FFH
		SCF
		RET

loc_C30:	CALL	loc_EC7
		JP	loc_BF0

loc_C36:	LD	DE,loc_2CA7
		LD	HL,loc_2CAB
		CALL	sub_6D3
		JP	NZ,loc_BF0
		CALL	sub_D0E
		JR	Z,loc_C50
loc_C47:	LD	A,0CH
		LD	(smod_b_B0A),A
		LD	A,0FFH
		SCF
		RET

loc_C50:	CALL	sub_643
		LD	A,0BH
		OR	A
		RET

loc_C57:	LD	HL,byte_2D04
		INC	(HL)
		CALL	sub_482
		LD	HL,byte_2D04
		LD	A,0AH
		CP	(HL)
		JR	NZ,loc_C6A
		LD	A,0FFH
		SCF
		RET

loc_C6A:	LD	HL,loc_2CAF
		CALL	sub_DDC
		JP	loc_BF0

loc_C73:	LD	DE,loc_2CA7
		LD	HL,loc_2CAB
		CALL	sub_6D3
		JP	NZ,0C57H
loc_C7F:	CALL	disp_bsy
		CALL	loc_EC7
		LD	HL,stab_CF9
		LD	BC,7
		CPIR
		JP	Z,stab_jmp
		JP	loc_C1C

loc_C93:	LD	A,0FFH
		SCF
		RET

sub_C97:	XOR	A
		LD	(byte_2D04),A
		LD	DE,loc_2CF9
		LD	HL,loc_2CAB
		LD	BC,loc_2CAB
		CALL	sub_6E4
		JP	sub_FBA

loc_CAA:	CALL	sub_C97
		JP	loc_C0A

loc_CB0:	CALL	sub_C97
		JP	loc_C7F

loc_CB6:	CALL	sub_C97
		LD	HL,loc_2CAB
		LD	DE,loc_2CE0
		CALL	sub_692
		LD	A,3
		CALL	sub_13BA
		JP	loc_C7F

loc_CCA:	CALL	sub_C97
		CALL	sub_D30
		JP	C,loc_C47
		LD	HL,loc_2CAB
		LD	DE,loc_2CE0
		CALL	sub_692
		LD	A,3
		CALL	sub_13BA
		JP	loc_C0A

stab_CE4:	.db	6
       		.db	0FEh
       		.db	4
       		.db	0Bh
       		.db	0FFh
       		.db	0Ah
       		.db	0FCh

       		.dw	loc_C1C
       		.dw	loc_C73
       		.dw	loc_C57
       		.dw	loc_C36
       		.dw	loc_C30
       		.dw	loc_C1C
       		.dw	loc_C1C

stab_CF9:	.db	0EBh
       		.db	0EAh
       		.db	0E9h
       		.db	0E8h
       		.db	0FFh
       		.db	0FEh
       		.db	010h

		.dw	loc_C93
 		.dw	loc_C1C
		.dw	loc_C57
		.dw	loc_CAA
		.dw	loc_CB0
		.dw	loc_CB6
		.dw	loc_CCA

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_D0E:	call	sub_50B
		call	sub_D30
		ret	c
loc_D15:	ld	a,1Ah
		call	loc_D68
		ret	c
		ld	hl,byte_280E
		ld	a,1
		cp	(hl)
		jr	nz,loc_D15
		ld	a,0
		ld	(byte_2CA5),a
		ld	c,F_CLOSE
		ld	de,file_fcb
		jp	bdos_s

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_D30:	ld	bc,(word_2CF5)
		ld	a,b
		or	c
		ret	z
		ld	hl,(word_2CE9)
loc_D3A:	ld	a,(byte_2CA3)
		cp	0FFh
		jr	z,loc_D52
smod_b_D41:	.equ	$+1
loc_D41:	ld	a,0
		cp	0Dh
		jr	z,loc_D52
		ld	a,(hl)
		cp	0Ah
		jr	nz,loc_D52
		ld	a,0Dh
		call	loc_D68
		ret	c
loc_D52:	ld	a,(hl)
		ld	(smod_b_D41),a
		inc	hl
		dec	bc
		call	loc_D68
		ret	c
		ld	a,b
		or	c
		jr	nz,loc_D3A
		call	sub_50B
		call	sub_FAA
		xor	a
		ret

;----------------------------------------------------------------------------

loc_D68:	ld	(byte_D6F),a
		push	bc
		push	de
		push	hl
byte_D6F:	.equ	$+1
loc_D6E: 	LD	C,0
    		LD	HL,byte_280E
    		CALL	sub_669
    		JR	NZ,loc_0D97
    		LD	HL,byte_280E
    		CALL	sub_64A
    		LD	C,F_DMAOFF	; set dma
    		LD	DE,loc_2811
    		CALL	bdos
    		LD	C,F_MULTISEC
    		LD	E,1
    		CALL	bdos
    		LD	C,F_WRITE	; wr. seq.
    		LD	DE,file_fcb
    		CALL	bdos_s
    		JR	NC,loc_D6E
loc_0D97:	POP	HL
    		POP	DE
    		POP	BC
    		RET

sub_D9B:	LD	HL,loc_2CE0
    		CALL	sub_688
    		LD	B,4
loc_0DA3:	PUSH	BC
    		LD	A,8
    		CALL	sub_13BA
    		LD	B,64H
    		CALL	sub_DE7
    		JR	C,loc_DB8
    		CP	4FH
    		JR	Z,loc_DBC
    		CP	0FDH
    		JR	Z,loc_DBC
loc_DB8:	POP	BC
    		DJNZ	loc_0DA3
    		PUSH	BC
loc_DBC:	POP	BC
    		LD	B,1
    		CALL	sub_DE7
    		XOR	A
    		RET

stab_DC4:	.db  18h ;
		.db  18h ;
		.db  18h ;
		.db  18h ;
		.db  18h ;
		.db  18h ;
		.db  18h ;
		.db  18h ;
		.db  18h ;
		.db  18h ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    8 ;
		.db    0 ;

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_DD9:	ld	hl,stab_DC4
sub_DDC:	ld	a,(hl)
		inc	hl
		or	a
		ret	z
		push	hl
		call	loc_145C
		pop	hl
		jr	sub_DDC

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_DE7:	push	bc
		call	sub_16AA
		call	nz,sub_16A5
		cp	1Bh
		ld	a,18h
		ld	c,0Ah
		call	z,sub_57F
		pop	bc
loc_DF8:	call	sub_5D4
		jr	nz,loc_E03
		djnz	loc_DF8
		ld	a,0FEh
		scf
		ret

loc_E03:	or	a
		ret

;----------------------------------------------------------------------------
loc_E05:	LD	B,64H
		CALL	sub_DE7
		RET	C
		AND	7FH
		LD	HL,loc_E2A
		LD	BC,2
		CPIR
		JR	Z,loc_E05
		LD	BC,3
		CPIR
		RET	Z
		LD	B,A
		AND	60H
		JR	NZ,loc_E28
		LD	A,(byte_2C9D)
		OR	A
		JR	NZ,loc_E05
loc_E28:	LD	A,B
      		RET

loc_E2A:	.db	11h	; dc1
		.db	13h	; dc3
		.db	0dh	; cr
		.db	0ah	; lf
		.db	18h	; can

sub_E2F:	ld	b,64H
		CALL	sub_DE7
		RET	C
		LD	E,A
loc_E36:	AND	60H
		LD	A,E
		RET	NZ
		CP	18H
		JR	Z,loc_E50
		LD	HL,loc_EA2
		LD	BC,4
		CPIR
		JR	Z,sub_E2F
		LD	A,(byte_2C9D)
		OR	A
		JR	NZ,sub_E2F
		LD	A,E
		RET

loc_E50:	LD	B,64H
		CALL	sub_DE7
		RET	C
		CP	18H
		JR	NZ,loc_0E74
		LD	B,64h
		CALL	sub_DE7
		RET	C
		CP	18H
		JR	NZ,loc_0E74
		LD	B,64H
		CALL	sub_DE7
		RET	C
		CP	18H
		JR	NZ,loc_0E74
		LD	B,64H
		CALL	sub_DE7
		RET	C
loc_0E74:	LD	HL,loc_EA6
		LD	BC,0BH
		CPIR
		JP	Z,stab_jmp
		LD	L,A
		LD	A,(byte_2C9D)
		OR	A
		JR	Z,loc_E8B
		LD	A,L
		AND	60H
		JR	Z,loc_E50
loc_E8B:	LD	A,L
		AND	60H
		CP	40H
		JR	NZ,loc_E9C
		LD	A,L
		XOR	40H
		RET

loc_E96:	LD	A,7FH
		RET

loc_E99:	LD	A,0FFH
		RET

loc_E9C:	LD	A,0FFH
loc_E9E:	OR	80H
		SCF
		RET

loc_EA2:	.db  11h ;
		.db  91h ; ?
		.db  13h ;
		.db  93h ; ?
loc_EA6:	.db  11h ;
		.db  91h ; ?
		.db  13h ;
		.db  93h ; ?
		.db  18h ;
		.db  68h ; h
		.db  69h ; i
		.db  6Ah ; j
		.db  6Bh ; k
		.db  6Ch ; l
		.db  6Dh ; m

		.dw	loc_E99
		.dw	loc_E96
		.dw	loc_E9E
		.dw	loc_E9E
		.dw	loc_E9E
		.dw	loc_E9E
		.dw	loc_E9E
		.dw	loc_E50
		.dw	loc_E50
		.dw	loc_E50
		.dw	loc_E50

loc_EC7:	OR	A
 		LD	HL,(word_2CEB)
 		LD	DE,(word_2CEF)
 		SBC	HL,DE
 		JP	C,sub_F4E
 		CALL	sub_8A0
 		LD	HL,0
 		LD	(loc_2CF9),HL
loc_EDD:	CALL	sub_E2F
 		JP	C,loc_F38
 		CALL	sub_FA2
 		CALL	Z,sub_7ED
 		CALL	NZ,crc16
 		LD	HL,(word_2CEB)
 		LD	BC,(word_2CEF)
 		SBC	HL,BC
 		JP	Z,sub_F4E
 		INC	BC
 		LD	(word_2CEF),BC
 		LD	HL,(loc_2CF9)
 		INC	HL
 		LD	(loc_2CF9),HL
 		LD	HL,(word_2CED)
 		LD	(HL),A
 		INC	HL
 		LD	(word_2CED),HL
 		JR	loc_EDD

sub_F0E:	.db 0E8h ; è
		.db 0E9h ; é
		.db 0EAh ; ê
		.db 0EBh ; ë
		.db  98h ; ?
		.db 0FFh ; ÿ
		.db 0FEh ; þ

		.dw	sub_F52
		.dw	sub_F4E
		.dw	sub_F54
		.dw	sub_F58
		.dw	sub_F58
		.dw	sub_F58
		.dw	sub_F58

stab_F23:	.db 0E8h ; è
		.db 0E9h ; é
		.db 0EAh ; ê
		.db 0EBh ; ë
		.db  98h ; ?
		.db 0FFh ; ÿ
		.db 0FEh ; þ

		.dw	sub_F52
		.dw	sub_F4E
		.dw	sub_F54
		.dw	sub_F7C
		.dw	sub_F7C
		.dw	sub_F7C
		.dw	sub_F7C

loc_F38: 	LD	HL,stab_F23
		LD	BC,7
		CALL	sub_FA2
		JR	Z,loc_F49
		LD	HL,sub_F0E
		LD	BC,7
loc_F49:	CPIR
		JP	Z,stab_jmp
sub_F4E:	LD	A,0FFH
		SCF
		RET

sub_F52:	SCF
		RET

sub_F54:	LD	A,10H
		SCF
		RET

sub_F58:	LD	(byte_2CFD),A
		AND	7FH
		CALL	crc16
		LD	B,2
loc_F62:	PUSH	BC
		CALL	sub_E2F
		CALL	crc16
		POP	BC
		JP	C,loc_F38
		DJNZ	loc_F62
		LD	A,H
		OR	L
		JR	Z,loc_F77
loc_F73:	LD	A,0FFH
		SCF
		RET

loc_F77:	LD	A,(byte_2CFD)
		OR	A
		RET

sub_F7C:	LD	(byte_2CFD),A
  		AND	7FH
  		CALL	sub_7ED
  		LD	B,4
loc_F86: 	PUSH	BC
  		CALL	sub_E2F
  		CALL	sub_7ED
  		POP	BC
  		JP	C,loc_F38
  		DJNZ	loc_F86
  		LD	HL,loc_2899
  		LD	DE,loc_7E9
  		CALL	sub_6D3
  		JP	Z,loc_F77
  		JP	loc_F73

sub_FA2:  	LD	E,A
  		LD	A,(byte_2C9E)
  		CP	20H
  		LD	A,E
  		RET

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_FAA:	ld	hl,word_2CE9
		ld	de,word_2CED
		ldi
		ldi
		ld	hl,0
		ld	(word_2CEF),hl
sub_FBA:	ld	hl,word_2CED
		ld	de,loc_2CF3
loc_FC0:	ldi
		ldi
		ldi
		ldi
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_FC9:	ld	hl,loc_2CF3
		ld	de,word_2CED
		jr	loc_FC0

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_FD1:	xor	a
		ld	(byte_2D01),a
		ld	hl,400h
		ld	(word_2CFE),hl
loc_FDB:	ld	a,5
		ld	(byte_2D00),a
loc_FE0:	ld	b,64h
		call	sub_DE7
		jp	c,loc_108A
		ld	hl,stab_109E
		ld	bc,3
		cpir
		jp	z,stab_jmp
		jr	loc_1024

;----------------------------------------------------------------------------

		LD	HL,byte_2D00
		DEC	(HL)
		LD	A,10H
		JP	Z,loc_108A
		LD	B,0AH
		CALL	sub_DE7
		JR	C,loc_FE0
		LD	HL,stab_10A7
		LD	BC,2
		CPIR
		JP	Z,stab_jmp
		JR	loc_1024

		LD	HL,byte_2D00
		DEC	(HL)
		LD	A,10H
		JP	Z,loc_108A
		JR	loc_FE0

		LD	B,0AH
		CALL	sub_DE7
		JR	C,loc_1035
loc_1024:	ld	hl,(word_2CFE)
		dec	hl
		ld	(word_2CFE),hl
		ld	a,h
		or	l
		ld	a,0FCh
		jp	z,loc_108A
		jp	loc_FDB

;----------------------------------------------------------------------------

loc_1035:	LD	A,0FFH
		JP	loc_108A

		LD	A,5
		LD	(byte_2D00),A
		CALL	loc_E05
		JR	C,loc_108A
		LD	HL,stab_10AD
		LD	BC,2
		CPIR
		JP	Z,stab_jmp
		JR	loc_1024

		CALL	loc_E05
		JR	C,loc_108A
		LD	HL,stab_10B3
		LD	BC,4
		CPIR
		JP	Z,stab_jmp
		JR	loc_1024

		LD	A,10H
		LD	(byte_2C9E),A
		CALL	sub_113F
		JR	loc_107F

		LD	A,10H
		LD	(byte_2C9E),A
		CALL	sub_1100
		JR	loc_107F

		LD	A,20H
		LD	(byte_2C9E),A
		CALL	sub_10C5
loc_107F:	PUSH	AF
		LD	HL,loc_2CA7
		LD	DE,loc_2CE4
		CALL	sub_692
		POP	AF
loc_108A:	ld	hl,stab_10BF
		ld	bc,6
		cpir
		jr	nz,loc_109C
		cp	98h
		jr	nz,loc_109A
		ld	a,10h
loc_109A:	scf
		ret

loc_109C:	or	a
		ret

;----------------------------------------------------------------------------

stab_109E:	.db  18h ;
		.db 0AAh ; ª
		.db  2Ah ; *
		.db  3Ah ; :
		.db  10h ;
		.db  3Ah ; :
		.db  10h ;
		.db 0F5h ; õ
		.db  0Fh ;

stab_10A7: 	.db  6Bh ; k
		.db  18h ;
		.db  12h ;
		.db  10h ;
		.db  1Dh ;
		.db  10h ;

stab_10AD:	.db  2Ah ; *
		.db  18h ;
		.db  51h ; Q
		.db  10h ;
		.db  3Fh ; ?
		.db  10h ;

stab_10B3: 	.db  43h ; C
		.db  41h ; A
		.db  42h ; B
		.db  18h ;
		.db 0F5h ; õ
		.db  0Fh ;

		.db  63h ; c
		.db  10h ;
		.db  6Dh ; m
		.db  10h ;
		.db  77h ; w
		.db  10h ;

stab_10BF:	.db  98h ; ?
		.db    6 ;
		.db  10h ;
		.db 0FFh ; ÿ
		.db 0FEh ; þ
		.db 0FCh ; ü

sub_10C5: 	CALL	sub_8A0
  		CALL	sub_E2F
  		RET	C
  		LD	(byte_2D01),A
  		CALL	sub_7ED
  		LD	HL,loc_2CA7
  		LD	B,4
loc_10D7:  	PUSH	BC
  		PUSH	HL
  		CALL	sub_E2F
  		CALL	sub_7ED
  		POP	HL
  		POP	BC
  		LD	(HL),A
  		INC	HL
  		RET	C
  		DJNZ	loc_10D7
  		LD	B,4
loc_10E8:  	PUSH	BC
  		CALL	sub_E2F
  		CALL	sub_7ED
  		POP	BC
  		RET	C
  		DJNZ	loc_10E8
  		LD	HL,loc_2899
  		LD	DE,loc_7E9
  		CALL	sub_6D3
  		JR	Z,loc_1132
  		JR	loc_113B

sub_1100:	CALL	sub_8A0
  		CALL	sub_E2F
  		RET	C
  		LD	(byte_2D01),A
  		CALL	crc16
  		LD	HL,loc_2CA7
  		LD	B,4
loc_1112:	PUSH	BC
  		PUSH	HL
  		CALL	sub_E2F
  		CALL	crc16
  		POP	HL
  		POP	BC
  		LD	(HL),A
  		INC	HL
  		RET	C
  		DJNZ	loc_1112
  		LD	B,2
loc_1123:	PUSH	BC
  		CALL	sub_E2F
  		CALL	crc16
  		POP	BC
  		RET	C
  		DJNZ	loc_1123
  		LD	A,H
  		OR	L
  		JR	NZ,loc_113B
loc_1132: 	LD	A,0FFH
  		LD	(byte_2CA6),A
  		LD	A,(byte_2D01)
  		RET

loc_113B:	LD	A,0FFH
  		SCF
  		RET

sub_113F:	CALL	sub_8A0
  		CALL	sub_1194
  		RET	C
  		LD	(byte_2D01),A
  		CALL	crc16
  		LD	HL,loc_2CA7
  		LD	B,4
loc_1151:	PUSH	BC
  		PUSH	HL
  		CALL	sub_1194
  		JR	NC,loc_115B
  		POP	HL
  		POP	BC
  		RET

loc_115B:	CALL	crc16
  		POP	HL
  		POP	BC
  		LD	(HL),A
  		INC	HL
  		DJNZ	loc_1151
  		LD	B,2
loc_1166:	PUSH	BC
  		CALL	sub_1194
  		JR	NC,loc_116E
  		POP	BC
  		RET

loc_116E:	CALL	crc16
  		POP	BC
  		DJNZ	loc_1166
  		LD	A,H
  		OR	L
  		JR	NZ,loc_1190
  		LD	B,0AH
  		CALL	sub_DE7
  		CP	0DH
  		JR	NZ,loc_1186
  		LD	B,0AH
  		CALL	sub_DE7
loc_1186:	OR	A
  		LD	A,0FFH
  		LD	(byte_2CA6),A
  		LD	A,(byte_2D01)
  		RET

loc_1190:	LD	A,0FFH
  		SCF
  		RET

sub_1194:	CALL	loc_E05
  		RET	C
  		CALL	sub_11B3
  		JR	NZ,loc_11AF
  		RLCA
  		RLCA
  		RLCA
  		RLCA
  		LD	B,A
  		PUSH	BC
  		CALL	loc_E05
  		POP	BC
  		RET	C
  		CALL	sub_11B3
  		JR	NZ,loc_11AF
  		OR	B
  		RET

loc_11AF:	LD	A,0FFH
  		SCF
  		RET

sub_11B3:	LD	L,A
  		SUB	30H
  		CP	0AH
  		JR	C,loc_11BC
  		SUB	27H
loc_11BC:	LD	L,A
  		AND	0F0H
  		LD	A,L
  		RET

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_11C1:	ld	a,0FFh
		ld	(byte_2D02),a
		call	sub_FAA
		ld	a,(byte_2C9E)
		cp	10h
		ld	a,43h
		jr	z,loc_11D4
		ld	a,15h

loc_11D4:	call	loc_145C
		ld	b,64h
		call	sub_1289
		or	a
		jr	z,loc_11F3
		cp	0F6h
		jr	z,loc_11E7
		ld	a,0FFh
		scf
		ret
;----------------------------------------------------------------------------

loc_11E7:	ld	a,6
		call	loc_145C
		ld	b,0Ah
		call	sub_DE7
		jr	sub_11C1

;----------------------------------------------------------------------------

loc_11F3:	ld	a,6
		call	loc_145C
		xor	a
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_11FA:	ld	a,0FFh
		ld	(byte_2D02),a
		ld	(byte_2CA3),a
		xor	a
		ld	(byte_2D07),a
		call	sub_FAA
		ld	hl,loc_2CAB
		call	sub_688
		ld	a,(byte_2C9E)
		cp	10h
		ld	a,43h
		jr	z,loc_121A
		ld	a,15h
loc_121A:	call	loc_145C
loc_121D:	ld	a,(byte_2D07)
		or	a
		ld	b,82h
		jr	z,loc_1227
		ld	b,32h
loc_1227:	call	sub_1289
		jr	c,loc_125A
		push	af
		call	sub_50B
		pop	af
		ld	hl,byte_2D07
		cp	(hl)
		jr	z,loc_1250
		dec	a
		cp	(hl)
		jr	nz,loc_126D
		inc	(hl)
		ld	de,word_2CEF
		ld	hl,loc_2CAB
		ld	bc,loc_2CAB
		call	sub_6E4
		call	sub_FBA
		call	sub_D30
		jr	c,loc_1285

loc_1250:	call	sub_FC9
		ld	a,6
		call	loc_145C
		jr	loc_121D

loc_125A:	cp	0F6h
		jr	nz,loc_126D
		call	sub_D0E
		jr	c,loc_1285
		call	sub_643
		ld	a,6
		call	loc_145C
		xor	a
		ret

;----------------------------------------------------------------------------

loc_126D:	cp	0FFh
		jr	nz,loc_1285
		ld	a,(byte_2D02)
		cp	0FFh
		jr	nz,loc_1285
		ld	a,(byte_2C9E)
		or	a
		jr	z,loc_1285
		xor	a
		ld	(byte_2C9E),a
		jp	sub_11FA

loc_1285:	ld	a,0FFh
		scf
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1289:	ld	a,b
		ld	(byte_2D03),a
		xor	a
		ld	(byte_2D04),a
		ld	a,0
		ld	(byte_2D09),a
loc_1296:	ld	a,(byte_2D03)
		ld	b,a
		call	sub_DE7
		ld	(byte_2D08),a
		ld	hl,loc_12AE
		ld	bc,4
		cpir
		jp	z,stab_jmp
		jp	loc_137A

;----------------------------------------------------------------------------

loc_12AE:	.db    2 ;
		.db    1 ;
		.db    4 ;
		.db  18h ;

		.dw	loc_136A
		.dw	loc_135F
		.dw	loc_12BF
		.dw	loc_12BA

loc_12BA:	LD	HL,400H
		JR	loc_12C2

loc_12BF:	LD	HL,80H
loc_12C2:	LD	(word_2D05),HL
		ld	b,0ah
		call	sub_DE7
		ld	(smod_b_12D9),A
		jp	c,loc_137A
		ld	b,0ah
		call	sub_DE7
		jp	c,loc_137A
smod_b_12D9:	.equ	$+1
		add	a,0
 		cp	0ffh
		jp	nz,loc_137A
		call	sub_8A0
		ld	ix,(word_2CED)
loc_12E6:	LD	B,0AH
		PUSH	IX
		CALL	sub_DE7
		POP	IX
		LD	(byte_2D08),A
		JP	C,loc_137A
		LD	(IX),A
		INC	IX
		CALL	sub_7DD
		CALL	crc16
		LD	BC,(word_2CEF)
		INC	BC
		LD	(word_2CEF),BC
		LD	DE,(word_2D05)
		DEC	DE
		LD	(word_2D05),DE
		LD	A,D
		OR	E
		JR	NZ,loc_12E6
		LD	(word_2CED),IX
		LD	B,0AH
		CALL	sub_DE7
		LD	(byte_2D08),A
		JP	C,loc_137A
		LD	A,(byte_2C9E)
		CP	10H
		JR	NZ,loc_1352
		LD	A,(byte_2D08)
		CALL	crc16
		LD	B,0AH
		CALL	sub_DE7
		LD	(byte_2D08),A
		JP	C,loc_137A
		CALL	crc16
		LD	A,H
		OR	L
		JP	NZ,loc_137A
loc_1345:	XOR	A
		LD	(byte_2D04),A
		LD	A,0
		LD	(byte_2D02),A
		LD	A,(smod_b_12D9)
		RET

loc_1352:	ld	a,(byte_2D08)
		ld	l,a
		ld	a,(smod_b_7DF)
		sub	l
		jr	z,loc_1345
		jp	loc_137A

loc_135F:	ld	b,0ah
		call	sub_DE7
		ld	a,0f6h
		ret	c
		jp	loc_137A

loc_136A:	ld	a,0ffh
		ld	hl,byte_2D09
		cp	(hl)
		jr	nz,loc_1376
		ld	a,0ffh
		scf
		ret

loc_1376:	ld	(hl),a
		jp	loc_13A4

;----------------------------------------------------------------------------

loc_137A:	ld	a,0
		ld	(byte_2D09),a
loc_137F:	ld	b,0Ah
		call	sub_DE7
		jr	nc,loc_137F
		ld	a,(byte_2D02)
		cp	0FFh
		jr	nz,loc_139A
		ld	a,(byte_2C9E)
		cp	10h
		ld	a,43h
		jr	z,loc_13A1
		ld	a,15h
		jr	loc_13A1

loc_139A:	ld	a,28h
		ld	(byte_2D03),a
		ld	a,15h
loc_13A1:	call	loc_145C
loc_13A4:	call	sub_FC9
		ld	hl,byte_2D04
		inc	(hl)
		call	sub_482
		ld	a,(byte_2D04)
		cp	5
		jp	nz,loc_1296
		ld	a,0FFh
		scf
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_13BA:	ld	(byte_2CE8),a
		ld	hl,loc_1403
		call	sub_DDC
		call	sub_8A0
		ld	a,(byte_2CE8)
		call	crc16
		call	sub_1418
		ld	hl,loc_2CE0
		ld	b,4
loc_13D4:	push	bc
		ld	a,(hl)
		inc	hl
		push	hl
		call	crc16
		call	sub_1418
		pop	hl
		pop	bc
		djnz	loc_13D4
		ld	a,(crc_seed+1)
		call	sub_1418
		ld	a,(crc_seed)
		call	sub_1418
		ld	a,0Dh
		call	loc_145C
		ld	a,0Ah
		call	loc_145C
		ld	a,(byte_2CE8)
		cp	8
		ret	z
		ld	a,11h
		jp	loc_145C

;----------------------------------------------------------------------------

loc_1403:	.db	2Ah ; *
		.db	2Ah ; *
		.db	18h ;
		.db	42h ; B
		.db	0 ;

loc_1408:	.text	"0123456789abcdef"

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1418:	push	af
		ld	hl,loc_1408
		ld	b,0
		rra
		rra
		rra
		rra
		and	0Fh
		ld	c,a
		add	hl,bc
		ld	a,(hl)
		call	loc_145C
		pop	af
		ld	hl,loc_1408
		ld	b,0
		and	0Fh
		ld	c,a
		add	hl,bc
		ld	a,(hl)
		jp	loc_145C

;----------------------------------------------------------------------------

loc_1438:	LD	(smod_b_145B),A
      		LD	BC,+(loc_1480-stab_7B3)
      		LD	HL,stab_7B3
      		CPIR
      		JP	Z,stab_jmp
		AND	60H
      		JR	NZ,loc_145A
      		LD	A,(byte_2C9D)
      		OR	A
      		JR	Z,loc_145A
loc_1450:	LD	HL,smod_b_145B
      		SET	6,(HL)
      		LD	A,18H
      		CALL	loc_145C
smod_b_145B:	.equ	$+1
loc_145A:	LD	A,0
loc_145C:	LD	(smod_b_1468),A
loc_145F:	CALL	sub_588
		CALL	sub_5CD
		JR	Z,loc_145F
smod_b_1468:	.equ	$+1
		LD	A,0
      		JP	loc_5C7

loc_146C:	LD	A,(smod_b_1468)
		AND	7FH
		CP	40H
		JR	NZ,loc_145A
		JR	loc_1450

stab_7B3:	.db	18h
		.db	0Dh
		.db	8Dh
		.db	10h
		.db	90h
		.db	11h
		.db	91h
		.db	13h
		.db	93h

loc_1480:	.dw	loc_1450
		.dw	loc_1450
		.dw	loc_1450
		.dw	loc_1450
		.dw	loc_1450
		.dw	loc_1450
		.dw	loc_146C
		.dw	loc_146C
		.dw	loc_1450

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1492:	push	bc
		ld	(byte_2D0A),a
		call	sub_171E
		push	de
		call	sub_162C
		ld	(de),a
		pop	de
		push	de
		call	sub_14A7
		pop	de
		pop	bc
		jr	loc_151D

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_14A7:	xor	a
		ld	(de),a
		ld	(byte_2D0D),a
		ld	(byte_2D0C),a
		call	sub_1687
		ld	a,c
		ld	(byte_2D0E),a
		push	de
		ld	a,(hl)
		cp	3Ah
		jr	nz,loc_14BD
		inc	hl
loc_14BD:	ld	b,8
		call	sub_1522
		pop	de
		ld	a,(hl)
		ld	(byte_2D0B),a
		cp	3Ah
		jr	nz,loc_14FE
		inc	hl
		ld	a,(byte_2D0A)
		or	a
		jr	z,loc_14D7
		call	sub_154A
		jr	z,loc_14E5
loc_14D7:	call	sub_159D
		jr	z,loc_14E5
		ld	a,(byte_2D0A)
		or	a
		jr	nz,loc_14E5
		call	sub_154A
loc_14E5:	ld	a,(byte_2D0D)
		ld	(de),a
		push	de
		inc	de
		call	sub_1632
		pop	de
		xor	a
		ld	(byte_2D0C),a
		push	de
		ld	b,8
		call	sub_1522
		pop	de
		ld	a,(hl)
		ld	(byte_2D0B),a
loc_14FE:	ld	a,(byte_2D0B)
		ex	de,hl
		ld	bc,8
		add	hl,bc
		ex	de,hl
		ld	b,3
		cp	2Eh
		jr	nz,loc_1513
		inc	hl
		push	de
		call	sub_1522
		pop	de
loc_1513:	ex	de,hl
		ld	bc,5
		add	hl,bc
		ex	de,hl
		ld	a,(byte_2D0E)
		ld	(de),a
loc_151D:	ld	a,(byte_2D0C)
		or	a
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1522:	call	valid_fnc
		ret	z
		inc	de
		cp	2Ah
		jr	nz,loc_1533
		ld	a,3Fh
		ld	(de),a
		call	sub_1543
		jr	loc_153A
loc_1533:	ld	(de),a
		inc	hl
		cp	3Fh
		call	z,sub_1543
loc_153A:	djnz	sub_1522
loc_153C:	call	valid_fnc
		ret	z
		inc	hl
		jr	loc_153C

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1543:	push	hl
		ld	hl,byte_2D0C
		inc	(hl)
		pop	hl
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_154A:	push	hl
		push	de
		call	sub_1552
		pop	de
		pop	hl
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1552:	call	sub_164A
		jr	z,loc_15CA
		ex	de,hl
		inc	hl
		call	sub_1652
		ld	b,a
		inc	b
		ld	a,(hl)
		cp	41h
		jr	c,loc_1574
		sub	40h
		cp	b
		jr	nc,loc_15CA
		ld	(byte_2D0D),a
		inc	hl
		ld	a,(hl)
		cp	20h
		ret	z
		call	sub_1625
		ret	c
loc_1574:	push	hl
		ld	b,2
loc_1577:	ld	a,(hl)
		cp	20h
		jr	z,loc_1589
		call	sub_1625
		jr	c,loc_159A
		inc	hl
		djnz	loc_1577
		ld	a,(hl)
		cp	20h
		jr	nz,loc_159A
loc_1589:	pop	hl
		call	sub_165A
		ld	c,a
		inc	c
		call	sub_15FA
		cp	c
		jr	nc,loc_15CA
		ld	(byte_2D0E),a
		xor	a
		ret

loc_159A:	pop	hl
		jr	loc_15CA

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_159D:	push	hl
		push	de
		call	sub_15A5
		pop	de
		pop	hl
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_15A5:	call	sub_1662
		jr	z,loc_15CA
		ex	de,hl
		inc	hl
loc_15AC:	ld	a,(de)
		or	a
		jr	z,loc_15CA
		inc	de
		inc	de
		push	hl
		push	de
		ld	b,8
loc_15B6:	ld	a,(de)
		cp	(hl)
		jr	nz,loc_15BE
		inc	hl
		inc	de
		djnz	loc_15B6
loc_15BE:	pop	de
		pop	hl
		jr	z,loc_15CD
		ex	de,hl
		ld	bc,10h
		add	hl,bc
		ex	de,hl
		jr	loc_15AC

loc_15CA:	or	0FFh
		ret

loc_15CD:	dec	de
		ld	a,(de)
		ld	(byte_2D0E),a
		dec	de
		ld	a,(de)
		ld	(byte_2D0D),a
		xor	a
		ret

;----------------------------------------------------------------------------
;		Validate character at hl is a valid filename character

valid_fnc:	ld	a,(hl)
		cp	'!'		; below !
		jr	c,loc_15F8
		cp	'='
		ret	z
		cp	'_'
		ret	z
		cp	'.'
		ret	z
		cp	':'
		ret	z
		cp	','
		ret	z
		cp	'<'
		ret	z
		cp	'>'
		ret	z
		or	a		; null
		ret	z
		cp	3bh		; ';'
		ret

loc_15F8:	xor	a
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_15FA:	push	bc
		ld	bc,1100h		; ?
loc_15FE:	ld	a,(hl)			; duplicious ?
		call	valid_fnc
		jr	z,loc_161E
		inc	hl
		call	sub_1625
		jr	c,loc_1622
		ld	d,a
		ld	a,c
		rlca
		jr	c,loc_1622
		rlca
		jr	c,loc_1622
		add	a,c
		jr	c,loc_1622
		rlca
		jr	c,loc_1622
		add	a,d
		jr	c,loc_1622
		ld	c,a
		djnz	loc_15FE
loc_161E:	ld	a,c
		pop	bc
		or	a
		ret
;
loc_1622:	pop	bc
		scf
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1625:	sub	30h
		ret	c
		cp	0Ah
		ccf
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_162C:	xor	a
		ld	(de),a
		inc	de
		call	sub_1632
sub_1632:	ld	b,0Bh
		ld	a,20h
		call	sub_1645
		xor	a
		ld	(de),a
		inc	de
		call	sub_1687
		ld	a,c
		ld	(de),a
		inc	de
		ld	b,3
		xor	a
sub_1645:	ld	(de),a
		inc	de
		djnz	sub_1645
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_164A:	push	hl
		push	de
		ld	de,2Eh
		jp	loc_1669

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1652:	push	hl
		push	de
		ld	de,2Ch
		jp	loc_1669

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_165A:	push	hl
		push	de
		ld	de,2Dh
		jp	loc_1669
;
;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1662:	push	de
		ld	de,15h
		jp	loc_1676

;----------------------------------------------------------------------------

loc_1669:	ld	hl,(word_2D0F)
		ld	a,h
		or	l
		jr	z,loc_1671
		add	hl,de
loc_1671:	ld	a,(hl)
		pop	de
		pop	hl
		or	a
		ret

;----------------------------------------------------------------------------

loc_1676:	ld	hl,(word_2D0F)
		add	hl,de
		ld	e,(hl)
		inc	hl
		ld	d,(hl)
		inc	hl
		ld	a,(hl)
		ex	de,hl
		pop	de
		or	a
		ret

;----------------------------------------------------------------------------

loc_1683:	ld	(word_2D0F),hl
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1687:	push	af
		push	de
		push	hl
		ld	c,DRV_GET
		call	bdos_s2
		push	af
		ld	e, 0FFh
		ld	c,F_USERNUM
		call	bdos_s2
		ld	c,a
		pop	af
		ld	b,a
		pop	hl
		pop	de
		pop	af
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_169E:	ld	a,F_SFIRST
		call	bdos_cs3
		inc	a
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_16A5:	ld	a,C_READ
		jp	bdos_cs3

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_16AA:	ld	a,C_STAT
		jp	bdos_cs3

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

bdos_s2:	push	de
		push	bc
		call	bdos
		pop	bc
		pop	de
		or	a
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

bdos_cs3:	push	hl
		push	de
		push	bc
		ld	c,a
		call	bdos
		or	a
		pop	bc
		pop	de
		pop	hl
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_16C4:	push	bc
		push	hl
		push	de
		push	af
		ld	b,8
		call	sub_16DA
		ld	(hl),2Eh
		inc	hl
		ld	b,3
		call	sub_16DA
		pop	af
		pop	de
		pop	hl
		pop	bc
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_16DA:	ld	a,(de)
		and	7Fh
		cp	20h
		jr	z,loc_16E3
		ld	(hl),a
		inc	hl
loc_16E3:	inc	de
		djnz	sub_16DA
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_16E7:	push	bc
		ld	b,0
		jp	loc_16F0
sub_16ED:	PUSH	BC
		LD	B,0FFH
loc_16F0:	push	hl
		push	af
		ld	h,64h
		call	sub_1703
		ld	h,0Ah
		call	sub_1703
		call	sub_1717
		pop	af
		pop	hl
		pop	bc
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1703:	ld	l, 0FFh
loc_1705:	sub	h
		inc	l
		jr	nc,loc_1705
		add	a,h
		ld	h,a
		ld	a,l
		or	a
		jr	nz,sub_1717
		or	b
		ld	a,h
		ret	m
		ld	a,20h
		jr	z,loc_171A
		xor	a
sub_1717:	add	a,30h
		ld	b,a
loc_171A:	ld	(de),a
		inc	de
		ld	a,h
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_171E:	push	af
		push	hl
loc_1720:	ld	a,(hl)
		or	a
		jr	z,loc_172B
		call	sub_1793
		ld	(hl),a
		inc	hl
		jr	loc_1720
loc_172B:	pop	hl
		pop	af
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_172E:	push	bc
		push	de
		push	hl
		ld	c,a
		ex	de,hl
		ld	b,(hl)
		push	hl
		inc	hl
		inc	hl
loc_1737:	call	sub_176B
		or	a
		jr	z,loc_1760
		ld	(hl),e
		inc	hl
		ld	(hl),d
		inc	hl
		dec	b
		jr	z,loc_1755
		call	sub_1779
		or	a
		jr	z,loc_1760
		ld	a,c
		or	a
		jr	z,loc_1751
		xor	a
		ld	(de),a
		inc	de
loc_1751:	ld	a,b
		or	a
		jr	nz,loc_1737
loc_1755:	call	sub_1779
		call	sub_176B
		or	a
		jr	z,loc_1760
		or	0FFh
loc_1760:	pop	hl
		push	af
		ld	a,(hl)
		sub	b
		inc	hl
		ld	(hl),a
		pop	af
		pop	hl
		pop	de
		pop	bc
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_176B:	ld	a,(de)
		and	7Fh
		inc	de
		cp	20h
		jr	z,sub_176B
		cp	9
		jr	z,sub_176B
		dec	de
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1779:	ld	a,(de)
		and	7Fh
		ret	z
		cp	20h
		ret	z
		cp	9
		ret	z
		inc	de
		jr	sub_1779

;----------------------------------------------------------------------------
;		Fill b locations starting at hl with value a

fill_bhla:	push	hl
		call	fill_1
		pop	hl
		ret

;----------------------------------------------------------------------------
;		Fill b locations starting at hl with value a

fill_1:		push	bc
loc_178D:	ld	(hl),a
		inc	hl
		djnz	loc_178D
		pop	bc
		ret

;----------------------------------------------------------------------------
;		S u b r	o u t i	n e

sub_1793:	and	7Fh
		cp	61h
		ret	c
		cp	7Bh
		ret	nc
		and	5Fh
		ret

;----------------------------------------------------------------------------
word_179E:	.dw	loc_end
byte_17A0:	.db	0
byte_17A1:	.db	0
word_17A2:	.db	0
file_fcb:	.db	0
		.fill	$20,0		
loc_17C4:	.db	0
		.db	0
		.db	0
byte_17C7:	.db	0
		.fill	$1800-$,0
		.ds	8
nstack:
rbuf_bfree:	.ds	2
		.ds	rbuf_size+4
byte_280E:	.ds	1
byte_280F:	.ds	1
byte_2810:	.ds	1
loc_2811:	.ds	80h
byte_2891:	.ds	1
		.ds	3
loc_2895:	.ds	4
loc_2899:	.ds	4
loc_289D:	.ds	400h
byte_2C9D:	.ds	1
byte_2C9E:	.ds	1
loc_2C9F:	.ds	1
		.ds	1
byte_2CA1:	.ds	1
byte_2CA2:	.ds	1
byte_2CA3:	.ds	1
byte_2CA4:	.ds	1
byte_2CA5:	.ds	1
byte_2CA6:	.ds	1
loc_2CA7:	.ds	4
loc_2CAB:	.ds	4
loc_2CAF:	.ds	21h
loc_2CD0:	.ds	1
byte_2CD1:	.ds	1
word_2CD2:	.ds	2
byte_2CD4:	.ds	1
		.ds	0Bh
loc_2CE0:	.ds	4
loc_2CE4:	.ds	4
byte_2CE8:	.ds	1
word_2CE9:	.ds	2
word_2CEB:	.ds	2
word_2CED:	.ds	2
word_2CEF:	.ds	2
		.ds	2
loc_2CF3:	.ds	2
word_2CF5:	.ds	2
		.ds	2
loc_2CF9:	.ds	4
byte_2CFD:	.ds	1
word_2CFE:	.ds	2
byte_2D00:	.ds	1
byte_2D01:	.ds	1
byte_2D02:	.ds	1
byte_2D03:	.ds	1
byte_2D04:	.ds	1
word_2D05:	.ds	2
byte_2D07:	.ds	1
byte_2D08:	.ds	1
byte_2D09:	.ds	1
byte_2D0A:	.ds	1
byte_2D0B:	.ds	1
byte_2D0C:	.ds	1
byte_2D0D:	.ds	1
byte_2D0E:	.ds	1
word_2D0F:	.ds	2
loc_end		.equ	$
		.end	; start
