	title	Fireworx Driver
	name	('FIREWORX')

; This is the machine part of a BASIC-program written
; by Richard Cox,
; published in 8000 Plus, December 1989

; Disassembled by W.Cirsovius

OS	equ	00000h		; BIOS entry
ROLLER	equ	0b600h		; Start of roller RAM

B1PORT	equ	0f1h		; Memory 04000H-07FFFH
B2PORT	equ	0f2h		; Memory 08000H-0BFFFH

SCRBANK	equ	082h
TPABANK	equ	086h

_ret	equ	0c9h
_ret.c	equ	0d8h

esc	equ	1bh

_COT	equ	 4		; BIOS console output
_USERF	equ	30		; BIOS user function

KT_GET	equ	00dah		; XBIOS function

_SHIFT	equ	21		; Key number for SHIFT key
_STOP	equ	66		; STOP key

	.phase	0e000h

l0006	equ	06h
;
; Jump vectors into version dependend BASIC interpreter
;
le258	equ	0e258h
le25b	equ	0e25bh
le25e	equ	0e25eh
le261	equ	0e261h
le264	equ	0e264h
le267	equ	0e267h

le000::
	call	le24f		; Do BASIC call ?????
	ld	a,_ret.c
	ld	(le057),a	; Change op code
	ld	hl,1
	ld	(le24d),hl	; Init value
	ld	c,'f'
	call	le033		; Disable cursor
	set	5,b		; Set bit
	call	le12a
	jr	le01d
le01a:
	call	le0df
le01d:
	call	le244
le020:
	push	bc
	call	le144
	pop	bc
	djnz	le020
	call	le04a		; Get key thru XBIOS call
	ld	a,c		; Get key number
	jr	nc,le01d	; No key pressed
	cp	_STOP		; Test STOP key
	jr	nz,le01a
le031:
	ld	c,'e'		; Enable cursor
;
; Print ESCape sequence
; ENTRY	Reg C holds definition character
;
le033:
	push	bc
	ld	c,esc
	call	le03d		; Output ESCape
	pop	bc
	jp	le03d		; Put sequence
;
; Console output thru BIOS
;
le03d:
	ld	de,3*(_COT-1)
	jr	le045
;
; Do user function call
;
le042:
	ld	de,3*(_USERF-1)
le045:
	ld	hl,(OS+1)	; Get BIOS vector
	add	hl,de		; Position jump
	jp	(hl)		; Execute BIOS function
;
; Get key thru XBIOS call
;
le04a:
	call	le042		; Get keyboard character
	dw	KT_GET
	jr	nc,le057	; No key pressed
	ld	a,c		; Get key number
	cp	_SHIFT		; No firework if so
	jr	z,le04a		; Wait for more
	scf			; Indicate key pressed
le057:
	ret			; Changed to RET (C)
	ld	hl,(le24d)
	dec	hl
	ld	(le24d),hl
	ld	a,h
	or	l
	ret	nz
	call	le0b3
	inc	hl
	call	le25e
	ld	b,0
	res	5,a
	cp	'N'
	jr	z,le089
	ld	b,0ffh
	cp	'S'
	jr	z,le089
	cp	'K'
	jr	z,le09a
	ld	c,'B'
	cp	'Q'
	scf
	ret	z
	call	le031
	ld	a,0c8h
	jp	le264
le089:
	push	bc
	call	le0a4
	pop	bc
	ld	c,e
	push	bc
	call	le0a1
	ld	(le24d),de
	pop	bc
	scf
	ret
le09a:
	ld	a,_ret
	ld	(le057),a	; Disable routine
	or	a
	ret
le0a1:
	call	le0b3
le0a4:
	ld	b,0ah
	call	le258
	call	le261
	ld	(iy+0),l
	ld	(iy+1),h
	ret
le0b3:
	ld	e,(iy+0)
	ld	d,(iy+1)
	ld	l,(ix+0)
	ld	h,(ix+1)
	add	hl,de
	jp	le25b
le0c3:
	db	13,00fh,030h,038h	; ZEILE		EOL
	db	 5,00fh,030h,0b8h	; WORD		WORD/CHAR
	db	 1,00fh,088h,058h	; FORM		RELAY
	db	78,00fh,088h,098h	; ENTER		ENTER
	db	 7,00fh,058h,078h	; BLOCK		[2]
	db	14,00fh,020h,078h	; Arrow up	[5]
	db	 0,07fh,020h,040h	; F3/F4
;
;
;
le0df:
	cp	47		; Test space bar
	jp	z,le12a		; Yeap, get next
	ld	hl,le0c3	; Point to key list
le0e7:
	ld	a,(hl)		; Get key number
	inc	hl
	or	a		; Test end of list
	jr	z,le0f4		; Yeap
	cp	c		; Test match
	jr	z,le0f4		; Yeap
	inc	hl		; Skip to next
	inc	hl
	inc	hl
	jr	le0e7
le0f4:
	ld	c,(hl)
	inc	hl
	ld	de,le24b
	call	le123
	inc	hl
	inc	de
le0fe::
	call	le123
	bit	5,b		; Test bit set
	push	af
	call	le244
	ld	c,b
	srl	c
	srl	c
	pop	af		; Get back bit state
	jr	nz,le111	; Was set
	srl	c
le111:
	ld	a,(hl)
	or	a
	jr	nz,le11d
	call	le1a2
	dec	c
	jr	z,le122
	jr	le120
le11d:
	call	le1b5
le120:
	djnz	le111
le122:
	ret
;
;
;
le123:
	call	le220
	and	c
	add	a,(hl)
	ld	(de),a
	ret
;
;
;
le12a:
	ld	de,l0006
	ld	c,e		; Get value
	bit	5,b		; Test bit
	jr	z,le134
	ld	c,-1		; Change value
le134:
	call	le244
le137:
	ld	a,(hl)
	or	a
	jr	z,le140
	ld	(hl),0
	dec	c
	jr	z,le143
le140:
	add	hl,de
	djnz	le137
le143:
	ret
;
;
;
le144:
	push	hl
	xor	a
	ld	(le24a),a	; Select clear bits
	call	le1bf		; Attache bit on screen
	pop	de
	call	le161
	jr	nc,le160
	call	le161
	jr	nc,le160
	ex	de,hl
	ld	a,-1
	ld	(le24a),a	; Select set bits
	call	le1ba
le160:
	ret
;
;
;
le161:
	ld	a,(de)
	or	a
	ret	z
	ld	h,d
	ld	l,e
	call	le171
	call	le184
	call	le184
	scf
	ret
;
;
;
le171:
	ld	a,(hl)
	or	a
	jp	m,le17d
	add	a,2
	ld	(hl),a
	ret	po
	ld	(hl),7fh
	ret
le17d:
	sub	2
	ld	(hl),a
	ret	po
	ld	(hl),1
	ret
;
;
;
le184:
	ld	a,(hl)
	inc	hl
	scf
	adc	a,a
	jr	c,le194
	add	a,(hl)
	ld	(hl),a
	inc	hl
	jr	nc,le1a0
	inc	(hl)
	jr	nz,le1a0
	jr	le19e
le194:
	ld	c,a
	ld	a,(hl)
	sub	c
	ld	(hl),a
	inc	hl
	jr	nc,le1a0
	dec	(hl)
	jr	nz,le1a0
le19e:
	xor	a
	ld	(de),a
le1a0:
	inc	hl
	ret
;
;
;
le1a2:
	ld	de,le24b
	call	le1a9
	inc	de
le1a9:
	call	le220
	ld	(hl),a
	inc	hl
	ld	(hl),0
	inc	hl
	ld	a,(de)
	ld	(hl),a
	inc	hl
	ret
;
;
;
le1b5:
	ld	de,l0006
	add	hl,de
	ret
;
;
;
le1ba:
	ld	a,(hl)
	or	a
	jp	z,le1b5
;
; Attache bit on screen
;
le1bf:
	inc	hl
	inc	hl
	ld	e,(hl)
	ld	d,0
	inc	hl
	inc	hl
	inc	hl
	ld	a,(hl)
	add	a,'4'
	ld	c,a
	ld	b,0
	rl	b
	sla	c
	rl	b
	inc	hl
	push	hl
	ex	de,hl
	add	hl,hl		; Double index
	ld	de,ROLLER
	add	hl,de		; Position in ROLLER RAM
	di
	ld	a,SCRBANK
	out	(B2PORT),a	; Select screen memory banks
	dec	a
	out	(B1PORT),a
	ld	e,(hl)		; Fetch address from ROLLER RAM
	inc	hl
	ld	d,(hl)
	ex	de,hl
	ld	a,l
	and	00000111b
	ld	e,a
	add	hl,hl
	ld	a,l
	and	11110000b
	or	e
	ld	l,a
	ld	e,c
	ld	a,c
	and	11111000b
	ld	c,a
	add	hl,bc
	ld	a,e
	and	00000111b	; Mask count
	ld	b,a
	ld	a,11000000b	; Init bits
	jr	z,le202		; Nothing to do
le1ff:
	rrca			; Shift bits into right place
	djnz	le1ff
le202:
	ld	b,a		; Save bits
	ld	a,(le24a)	; Get mode
	or	a		; Test it
	ld	a,b
	jr	nz,le20f	; Set bits
	cpl			; Build mask
	and	(hl)		; Clear bits
	ld	(hl),a
	jr	le211
le20f:
	or	(hl)		; Set bits
	ld	(hl),a
le211:
	ld	a,TPABANK
	out	(B2PORT),a	; Select TPA memory banks
	dec	a
	out	(B1PORT),a
	ei
	pop	hl
	ret
;
;
;
le21b:
	db	0
	db	10001001b
	db	11001011b
	db	11000111b
	db	00101101b
;
;
;
le220:
	push	hl
	ld	hl,le21b
	ld	a,(hl)
	inc	hl
	add	a,(hl)
	rrc	(hl)
	inc	hl
	add	a,(hl)
	rrc	(hl)
	rrc	(hl)
	rrc	(hl)
	jr	nc,le23f
	inc	hl
	add	a,(hl)
	rlc	(hl)
	rlc	(hl)
	rlc	(hl)
	inc	hl
	add	a,(hl)
	rlc	(hl)
le23f:
	ld	(le21b),a
	pop	hl
	ret
;
;
;
le244:
	ld	hl,le267
	ld	b,0b4h
	ret
;
;
;
le24a:
	db	0		; Bit mode (0 is clear)
le24b:
	db	00h,00h
le24d:
	dw	0
;
; Do BASIC call ?????
;
le24f:
	db	0ddh,21h	; LD IX,... following code depends on BASIC version
;
; BASIC version 1.29
;
	.comment	*
	ld	ix,7417h
	ld	iy,73aah
	ret
le258:
	jp	59cdh
le25b:
	jp	4597h
le25e:
	jp	4727h
le261:
	jp	62e7h
le264:
	jp	0eb3h
le267:
			*
;
; BASIC version 1.39
;
	.comment	*
	ld	ix,74a4h
	ld	iy,7337h
	ret
le258:
	jp	5a75h
le25b:
	jp	45deh
le25e:
	jp	4757h
le261:
	jp	6391h
le264:
	jp	0eb2h
le267:
			*

	.dephase

	end

