botscreen:		equ	192
rightscreen:		equ	176	
length_of_sprite_table:	equ	badtab-spritetab
length_of_variables:	equ	varstore-variables
numsprite:		equ	12;16
numstars:		equ	40
numbullets:		equ	(endbulltab-bullettab)/2
numkeys:		equ	7		;number of keys
AY_initiate:		equ	56064		;whatever Sountracker does to set up
play_AY:		equ	56070		;call every halt
barpos:			equ	20480+128+26+512
scorepos:		equ	16384+96+25	
lifetextpos:		equ	20480+27
itempos:		equ	18432+27
itemnumpos:		equ	itempos+66
levelpos:		equ	18432+96+26
offscreen:		equ	230		;byte that is out of range, for ON/OFF switch
bulletstrength:		equ	2		;sprite lives odd, bullet strengths even, to ensure we set the carry
blast1power:		equ	4
blast2power:		equ	8
blast3power:		equ	16
baddylife:		equ	1
playercolour:		equ	71
safeplace:		equ	0
tvpos:			equ	16384+25+224
easylevel:		equ	3
	;
org 37120
	jr start
starspeeds:	;must be within a word boundary
	db	0,0,0,0,0,0,0,0,0,0,1,1,1,1,3,7
	;
start:	call any_key	
	call creditscreen
	ld hl,(23672)
	ld (rnd+1),hl
	ld a,(23560)
	ld (rnd+4),a
	ld a,r
	ld (rnd+5),a
	call setupstartab	;only needs doing once
start0:	xor a
	out (254),a
	call introscreen
	call cls
	call print_panel
	call clear_sprite_table
	call setvariables
	call AY_initiate
	call set_interrupt
	call main_start
	ld a,(gameoverflag)
	or a
	call nz,gameoverscr
	ld a,(gamecompletedflag)
	or a
	call nz,gamecompletescreen
	jr start0
	;
tv_time:
	ld b,80
tv_lp:	push bc
	call big_tv
	pop bc
	djnz tv_lp
	ret
	;
big_tv:
	ld hl,0
	ld de,16384
	ld b,192
btlp:	xor a	
	push bc
	push de
	ld bc,23
	ldir
	ld a,(hl)
	and 248
	out (254),a
	pop de
	pop bc
	call nextlinedown
	ld a,h
	and 31
	ld h,a
	djnz btlp
	ld (big_tv+1),hl
	ret	
	;
cls:	ld hl,16384
	ld d,h
	ld e,1
	ld (hl),l
	ld bc,6143
	ldir
	ret
	;
cls_playarea:
	ld de,16384
	ld c,192
cplp0:	push de
	xor a
	ld b,24
cplp:	ld (de),a
	inc e
	djnz cplp
	pop de
	call nextlinedown
	dec c
	jr nz,cplp0
	ret
	;
paperfill:
	ld a,7
pf2:	ld hl,22528
	ld d,h
	ld e,1
	ld (hl),a
	ld bc,767
	ldir
	ret
	;
paperseg:
	ld (hl),a
	inc l
	jr nz,paperseg
	ret
	;
main_start:
	call display_levelinfo
	call zap
	call any_key
	call cls_playarea
	call draw_stars
	call display_sprites
	ld a,(level)
	or a
	call z,tvanimate
	call printcurrentitem
ment:	call printitems
	call printlives	
	ld a,127
	ld (inwincibleflag),a
main:	call bulletsound	
	call display_sprites
	call draw_stars
	call move_draw_bullets
	ld a,(blast1flag)
	or a
	call nz,move_draw_blast1
	ld a,(blast2flag)
	or a
	call nz,move_draw_blast2
	ld a,(blast3flag)
	or a
	call nz,move_draw_blast3
	call sprite_collisions
	call inwincibility
	call control_sprites
	call draw_blast_power
	call bulletcollisions
	call print_score
kjp:	call check_keys		;keys or kempston poked in here
	call checkscorebonus
	call extralifemessage
	call events
	ld hl,(loop_counter)
	inc hl
	ld (loop_counter),hl
	ld a,(items)
	cp '9'
	jr nc,nextlevel
lip:	ld a,(deadflag)
	or a
	jr z,main
dead:	xor a
	ld (deadflag),a
	call deadanim
	ld d,10
	call crlp0
	ld a,(lives)		;player dead
	dec a
	jr z,gameover
	ld (lives),a
	ld bc,10000
	call delay
	jp ment
	;
gameover:
	ld a,255
	ld (gameoverflag),a
	ret
	;
nextlevel:		;25 items collected
	ld a,'0'
	ld (items),a
	ld a,(level)
	inc a
	ld (level),a
	cp 8
	jp c,main_start
	ld a,255
	ld (gamecompletedflag),a
	ret
	;
deadanim:
	ld hl,(spritetab)	;oldscadd
	call dlspr		;delete sprite
	ld hl,(py)
	ld a,(px+1)
	ld l,a
	call xy2screen		;de at player screen pos
	xor a
dlp:	push af
	push de	
	halt
	halt
	ld hl,explodegraphic
	call getgraphic
	call dsp1
	call crashy
	pop de
	pop af
	inc a
	cp 9
	jr c,dlp
	ret
	;
crashy:
	ld bc,1500
clp:	call rnd
	and 248
	out (254),a
	dec bc
	ld a,b
	or c
	jr nz,clp
	ret
	;
delay2:
	ld bc,200
	jr delay
	;
delay1:
	ld bc,400
	jr delay
	;
delay0:
	ld bc,2000
delay:
	dec bc
	ld a,b
	or c
	jr nz,delay
	ret
	;
haltdelay0:
	ld b,20
haltdelay:
	halt
	djnz haltdelay
	ret
	;
loop_counter:	dw	0
	;
check_keys:
	ld a,(key0)
	ld hl,and0
	in a,(254)
	and (hl)
	call z,player_up
	ld a,(key1)
	in a,(254)
	ld hl,and1
	and (hl)
	call z,player_down
	ld a,(key3)
	in a,(254)
	ld hl,and3
	and (hl)
	call z,player_right
	ld a,(key2)
	in a,(254)
	ld hl,and2
	and (hl)
	call z,player_left
	ld a,(key4)
	in a,(254)
	ld hl,and4
	and (hl)
	push af
	call z,charge_blaster
	pop af
	call nz,fire
cpk:	ld a,(key5)
	in a,(254)
	ld hl,and5
	and (hl)
	call z,any_key
	ld a,(key6)
	in a,(254)
	ld hl,and6
	and (hl)
	call z,toggleAY
	ret
	;
check_kempston:
	ld a,31
	in a,(31)
	and 8
	call nz,player_up
	ld a,31
	in a,(31)
	and 4
	call nz,player_down
	ld a,31
	in a,(31)
	and 1
	call nz,player_right
	ld a,31
	in a,(31)
	and 2
	call nz,player_left
	ld a,31
	in a,(31)
	and 16
	push af
	call nz,charge_blaster
	pop af
	call z,fire
	jp cpk	;check pause key
	;
charge_blaster:
	ld a,(blastpower)
	cp 31	;31 ismax power
	jr z,decpower
	ret nc	;c means >31
	inc a
	ld (blastpower),a
	ret
	;
decpower:
	dec a
	ld (blastpower),a
	ret
	;
fire:	ld a,(blastpower)	;0-31
	or a
	ret z
	rra			;0-15
	rra			;0-7
	rra			;
	and 3			;0-3
	add a,a			;byte to word
	ld l,a
	xor a
	ld h,a
	ld (blastpower),a
	ld de,firetab
	add hl,de
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	jp (hl)
	;
firetab:
	dw	setbullet	;normal bullet
	dw	setblast1		;small pixel blast
	dw	setblast2
	dw	setblast3
	;
setbullet:
	ld ix,(bulltabseed)
	ld a,(ix+1)
	cp botscreen
	ret c		;if not you'll have to wait
	ld a,255
	ld (bulletsoundflag),a
	ld a,(px+1)
bdp:	add a,8
	and 248
	ld (ix+0),a	;bullet x
	ld a,(py+1)
	and 248
	ld (ix+1),a
	inc ix
	inc ix
	ld (bulltabseed),ix
	ld a,(bdp+1)
	xor 8
	ld (bdp+1),a
	ld a,(ix+0)
	cp 255
	ret nz
	ld hl,bullettab
	ld (bulltabseed),hl	
	ret
	;
bulletsound:
	ld a,(bulletsoundflag)
	or a
	jp z,delay1
	xor a
	ld b,a
	ld (bulletsoundflag),a
	ld bc,400
bslp:	ld a,c
	and 248
	out (254),a
	dec bc
	ld a,b
	or c
	jr nz,bslp
	ret
	;
blastsound:
	ld a,(AYbyte)
	rra
	ret nc
	ld a,b
	and 248
	out (254),a
	djnz blastsound
	ret
	;
zap:	;DKTRonics
	push de
	ld d, 127
	ld e, 63
	ld b, 191
l_7536: push bc
	ld a, 0;(23624)
	srl a
	srl a
	srl a
	set 4, a
	out (254), a
	ld b, d
l_7545: nop
	nop
	nop
	djnz l_7545
	res 4, a
	out (254), a
	ld b, e
l_754f: nop
	nop
	nop
	djnz l_754f
	nop
	nop
	dec e
	dec e
	pop bc
	djnz l_7536
	pop de
	ret
	;
move_draw_bullets:
	ld ix,bullettab
	ld c,0
	ld b,numbullets
mdblp:	ld h,(ix+1)	;y
	ld l,(ix+0)	;x
	ld a,h
	cp botscreen
	jr nc,bmiss
	push hl
	call getspritepos	;point DE at screen
	ex de,hl
	ld (hl),c		;delete old position
	inc h
	ld (hl),c
	inc h
	ld (hl),c
	inc h
	ld (hl),c
	pop hl			;get xy back
	ld a,h
	sub 8			;move bullet up
	ld (ix+1),a
	ld h,a
	call getspritepos
	push de
	call screen2att
	ld (hl),69
	pop hl
	ld a,60
	ld (hl),a
	inc h
	ld (hl),126
	inc h
	ld (hl),a
	inc h
	ld (hl),24	
bmiss:	inc ix
	inc ix			;next bullet
	djnz mdblp
	ret	
	;
setblast1:
	ld a,(blast1flag)	;currently blasting?
	or a
	ret nz
	cpl
	ld (blast1flag),a	;we certainly are now
	ld a,(px+1)
	ld (blast1_x),a
	ld a,(py+1)
	and 248
	ld (blast1_y),a
	ret
	;
setblast2:
	ld a,(blast2flag)	;currently blasting?
	or a
	ret nz
	cpl
	ld (blast2flag),a	;we certainly are now
	ld a,(px+1)
	ld (blast2_x),a
	ld a,(py+1)
	and 248
	ld (blast2_y),a
	ret
	;
setblast3:
	ld a,(blast3flag)	;currently blasting?
	or a
	ret nz
	cpl
	ld (blast3flag),a	;we certainly are now
	ld a,(px+1)
	call bigblastpos
	ld (blast3_x),a
	ld a,(py+1)
	and 248
	ld (blast3_y),a
	ret
	;
bigblastpos:
	cp 8
	ret c
	sub 8
	cp rightscreen-8
	ret c
	sub 8
	ret
	;
move_draw_blast1:		;only called when active
	ld b,8
	call blastsound
	ld hl,(blast1_x)	;h at ycor, l at xcor
	push hl
	call getspritepos	;point DE at screen
	ld b,3	
	xor a
db1lp:	ld (de),a		;delete old pos
	inc e
	ld (de),a
	inc d
	ld (de),a
	dec e
	ld (de),a
	inc d
	djnz db1lp
	pop hl	;get xyback
	ld a,h
	sub 8
	ld h,a
	ld (blast1_y),a
	cp botscreen
	jr nc,b1_off
	call getspritepos
	push de
	call screen2att
	ld a,69
	ld (hl),a
	inc l
	ld (hl),a
	pop de
	ld hl,blast1_graphic
	ld b,3
mb1lp:	ld a,(hl)
	ld (de),a
	inc hl
	inc e
	ld a,(hl)
	ld (de),a
	inc hl
	inc d
	ld a,(hl)
	ld (de),a
	inc hl
	dec e
	ld a,(hl)
	ld (de),a
	inc hl
	inc d
	djnz mb1lp
	ld hl,(blast1_x)	;h=y, l=x
	ld d,24
	ld e,31
	ld a,blast1power
	ld (bp+1),a
	call checkblast
	ret
	;
b1_off:
	xor a
	ld (blast1flag),a
	ret
	;
move_draw_blast2:		;only called when active
	ld b,16
	call blastsound
	ld hl,(blast2_x)	;h at ycor, l at xcor
	push hl
	call getspritepos	;point DE at screen
	ld b,4	
	xor a
db2lp:	ld (de),a		;delete old pos
	inc e
	ld (de),a
	inc d
	ld (de),a
	dec e
	ld (de),a
	inc d
	djnz db2lp
	pop hl	;get xyback
	ld a,h
	sub 8
	ld h,a
	ld (blast2_y),a
	cp botscreen
	jr nc,b2_off
	call getspritepos
	push de
	call screen2att
	ld a,69
	ld (hl),a
	inc l
	ld (hl),a
	pop de
	ld hl,blast2_graphic
	ld b,4
mb2lp:	ld a,(hl)
	ld (de),a
	inc hl
	inc e
	ld a,(hl)
	ld (de),a
	inc hl
	inc d
	ld a,(hl)
	ld (de),a
	inc hl
	dec e
	ld a,(hl)
	ld (de),a
	inc hl
	inc d
	djnz mb2lp
	ld hl,(blast2_x)	;h=y, l=x
	ld d,24
	ld e,31
	ld a,blast2power
	ld (bp+1),a
	call checkblast
	ret
	;
b2_off:
	xor a
	ld (blast2flag),a
	ret
	;
move_draw_blast3:		;only called when active
	ld b,64
	call blastsound
	ld hl,(blast3_x)	;h at ycor, l at xcor
	push hl
	call getspritepos	;point DE at screen
	ld b,4	
	xor a
db3lp:	ld (de),a
	inc e
	ld (de),a
	inc e
	ld (de),a
	inc e
	ld (de),a
	inc d
	ld (de),a
	dec e
	ld (de),a
	dec e
	ld (de),a
	dec e
	ld (de),a
	inc d
	djnz db3lp
	pop hl	;get xyback
	ld a,h
	sub 8
	ld h,a
	ld (blast3_y),a
	cp botscreen
	jr nc,b3_off
	call getspritepos
	push de
	call screen2att
	ld a,69
	ld c,71
	ld (hl),a
	inc l
	ld (hl),c
	inc l
	ld (hl),c
	inc l
	ld (hl),a
	pop de
	ld hl,blast3_graphic
	ld c,255
	ld a,8
mb3lp:	ld b,e
	ldi
	ldi
	ldi
	ldi
	ld e,b
	inc d
	dec a
	jr nz,mb3lp
	ld hl,(blast3_x)	;h=y, l=x
	ld d,24
	ld e,47
	ld a,blast3power
	ld (bp+1),a
	call checkblast
	ret
	;
b3_off:
	xor a
	ld (blast3flag),a
	ret
	;
blast1_graphic
db 15, 240
db 248,31
db 57, 156
db 12,48
db 17, 136
db 16,8
	;
blast2_graphic:
db 63, 252
db 254,127
db 255, 255
db 255, 255
db 239, 247
db 247,239
db 71, 226
db 196,35
	;
blast3_graphic:
db 63, 255, 255, 252
db 127, 255, 255, 254
db 255, 247, 223, 255
db 255, 253, 127, 255
db 244, 26, 176, 47
db 232, 5, 64, 23
db 80, 2, 128, 10
db 41, 1, 0, 148
	;	

blast1_x:	db	0
blast1_y:	db	0
	;
blast2_x:	db	0
blast2_y:	db	0
	;
blast3_x:	db	0
blast3_y:	db	0
	;
bullettab:	;normal small bullets
	db	0,200	;xy of bullet
	db	0,200
	db	0,200
	db	0,200
endbulltab:
	db	255,255
	;
bulletcollisions:
	ld iy,bullettab
	ld b,numbullets
bcilp:	push bc
	call checkbullet
	pop bc
	inc iy
	inc iy
	djnz bcilp
	ret
	;
checkbullet:
	ld h,(iy+1)
	ld l,(iy+0)
	ld a,h			;>botscreen means bullet off
	cp botscreen
	ret nc
	ld ix,badtab
	ld de,length_of_sprite_table
	ld b,numsprite-1	;number of baddies
bclp:	ld a,(ix+19)		;sprite active?
	or a			;0 means active
	jr z,bullmiss
	ld a,(ix+3)		;baddy ycor
	sub h			;bullet y
	add a,15
	cp 24
	jr nc,bullmiss
	ld a,(ix+5)		;baddy xcor
	sub l			;bullet x
	add a,15
	cp 24
	jr nc,bullmiss
	;collision here
	ld (iy+1),200		;switch bullet off
	call getspritepos	;point DE at bullet address
	xor a
	ld (de),a
	inc d
	ld (de),a
	inc d
	ld (de),a
	inc d
	ld (de),a		;delete bullet
	ld a,(ix+16)		;life
	sub bulletstrength
	ld (ix+16),a
	call c,spritedead	;when life overclocks we've killed the sprite
	ret			;RET as the bullet has collided and gets switched off
bullmiss:
	add ix,de		;next sprite
	djnz bclp
	ret
	;
spritedead:		;sprite has been shot enough times to kill
	ld h,(ix+18)
	ld l,(ix+17)	;dead routine e.g. explode
	ld (ix+9),h
	ld (ix+8),l	;into control routine
	ld (ix+14),0	;explosion counter
	ld h,(ix+21)
	ld l,(ix+20)	;score value, score 1,10,100
	jp (hl)
	;
checkblast:		;collision check for blast 1,2,3
	ld ix,badtab
	ld b,numsprite-1
cb1lp:	push bc	
	ld a,(ix+19)	;on off switch
	or a
	jr z,cb1m
	ld a,(ix+3)	;ycor
	cp botscreen
	jr nc,cb1m
	sub h
	add a,15
	cp d
	jr nc,cb1m
	ld a,(ix+5)
	cp rightscreen
	jr nc,cb1m
	sub l
	add a,15
	cp e		;
	jr nc,cb1m
	push de		;could replace with sub C from power, as long as that's all that's needed
	push hl
	ld a,(ix+16)		;life
bp:	sub 0			;blast power poked in here
	ld (ix+16),a
	call c,spritedead	;when life overclocks we've killed the sprite
	pop hl
	pop de
cb1m:	ld bc,length_of_sprite_table	
	add ix,bc
	pop bc
	djnz cb1lp
	ret
	;
player_right:
	ld hl,(px)	;xcor word
	ld de,(xd)	;x displacement
	add hl,de
	ld a,h
	cp rightscreen
	ret nc
	ld (px),hl
	ret
	;
player_left:
	ld hl,(px)	;xcor word
	ld de,(xd)	;x displacement
	xor a
	sbc hl,de
	ld a,h
	cp rightscreen
	ret nc
	ld (px),hl
	ret
	;
player_up:
	ld hl,(py)	;xcor word
	ld de,(yd)	;x displacement
	xor a
	sbc hl,de
	ld a,h
	cp 9
	ret c
	ld (py),hl
	ret
	;
player_down:
	ld hl,(py)	;xcor word
	ld de,(yd)	;x displacement
	add hl,de
	ld a,h
	cp botscreen-16
	ret nc
	ld (py),hl
	ret
	;
no_key:
	xor a
	in a,(254)
	cpl
	and 31
	jr nz,no_key
	ret
	;
any_key:
	call no_key
aklp:	xor a
	in a,(254)
	cpl
	and 31
	jr z,aklp
	ret
	;
	;
key0:	db	251	;default set as QAOP-Spc H
and0:	db	1
key1:	db	253
and1:	db	1
key2:	db	223
and2:	db	2
key3:	db	223
and3:	db	1
key4:	db	127
and4:	db	1
key5:	db	191
and5:	db	16
key6:	db	127
and6:	db	4
	;
sprite_collisions:		;ripped off from Jonathan Cauldwell's routine
	ld ix,badtab
	ld b,numsprite-1
sclp:	ld a,(py+1)
	sub (ix+3)	;baddy ycor
	add a,15
	cp 30
	jr nc,nocol
	ld a,(px+1)
	sub (ix+5)	;baddy xcor
	add a,15
	cp 30
	jr nc,nocol
	;collision if here reached
	call collisionroutine
nocol:	ld de,length_of_sprite_table
	add ix,de
	djnz sclp
	ret
	;
collisionroutine:
	ld h,(ix+23)
	ld l,(ix+22)
	jp (hl)
	;
killplayer:
	ld a,(inwincibleflag)
	or a
	ret nz
	ld a,255
	ld (deadflag),a
	ret
	;
inwincibility:
	ld hl,inwincibleflag
	ld a,(hl)
	or a
	jr z,normalcolour
	dec a
	ld (hl),a
	ld a,(spcol)
	xor 6
	ld (spcol),a
	ret
	;
normalcolour:
	ld a,playercolour
	ld (spcol),a
	ret
	;
itemless:		;decrease items by 1
	ld a,(level)
	cp easylevel
	jr c,iout		;easy levels 0,1,2
	ld hl,items
	dec (hl)
	ld a,(hl)
	cp '0'
	jr nc,iout
	ld (hl),'0'
iout:	call printitems
	call badnoise
	ret
	;
itemsplus1:
	ld hl,items
	inc (hl)
	ld a,(hl)
	cp '9'+1
	jr c,ipout
	ld (hl),'9'
ipout:	call printitems
	ret
	;
itemcollected:
	push hl
	push bc
	push ix
	call score100
	call spriteoff
	call itemsplus1
	call printitems
	call collectedsound
	pop ix
	pop bc
	pop hl
	ret
	;
control_sprites:
	ld ix,badtab
	ld b,numsprite-1	;exclude player
cslp:	push bc
	call contrspr
	pop bc
	ld de,length_of_sprite_table
	add ix,de
	djnz cslp
	ret
	;
contrspr:
	ld h,(ix+9)
	ld l,(ix+8)	;control routine
	jp (hl)
	;
explode:		;baddy killed, explode it
	ld a,(ix+19)
	or a		;check sprite active switch
	ret z
	inc (ix+14)	;animation counter
	ld a,(ix+14)
	cp 16
	jr nc,spriteoff
	rra	;0-7
	and 7
	or 64
	ld (ix+15),a
	and 6	;0,2,4,6
	ld l,a
	ld a,(ix+5)
	and 248
	or l
	ld (ix+5),a
	ld hl,explodegraphic
	ld (ix+7),h	;set
	ld (ix+6),l
	ld a,r
	and 248
	out (254),a
	ret
	;
spriteoff:
	call deletesprite
	ld a,offscreen
	ld (ix+3),a
	ld (ix+5),a
	ld (ix+19),0	;on off switch 0=off, <>=on
	ret
	;
t_downdiag:		;trilobite
	ld a,(ix+3)	;ycor
	cp 90
	jr c,downdiag
	cp 130
	jr c,t1
t2:	ld hl,2048
	jr tm
t1:	ld hl,1024
tm:	ld (ix+13),h
	ld (ix+12),l
	ld a,(ix+15)
	xor 2
	ld (ix+15),a
	jp downdiag
	;
rhinodowndiag:
	ld a,(ix+15)
	xor 4
	ld (ix+15),a
	jr downdiag
	;
orangedowndiag:
	ld a,(ix+15)
	xor 4		;toggle between yellow and red ink
	ld (ix+15),a
downdiag:		;move down and diagonally horizontal
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	add hl,de
	ld a,h
	cp botscreen
	jp nc,spriteoff
	ld (ix+3),h
	ld (ix+2),l
	ld a,(ix+14)	;direction byte
	rra
	jp c,sprite_right
	jp sprite_left
	;
justdown:		;move down and diagonally horizontal
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	add hl,de
	ld a,h
	cp botscreen
	jp nc,spriteoff
	ld (ix+3),h
	ld (ix+2),l
	ret
	;
cockdrop:
	ld a,(px+1)
	sub (ix+5)	;baddy xcor
	add a,96
	cp 96+16
	jp nc,chasedowndiag
	ld hl,1024
	ld (ix+11),h
	ld (ix+10),l	;yd
	ld a,(loop_counter)
	rra
	rra
	rra
	and 1
	ld (ix+14),a
	jp downdiag
	;
wobbledown:
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	add hl,de
	ld a,h
	cp botscreen
	jp nc,spriteoff
	ld (ix+3),h
	ld (ix+2),l
	ld a,(loop_counter)
	rlca
	rlca
	rlca
	and 1
	ld (ix+14),a
	jp downdiag
	;
wobbledown1:
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	add hl,de
	ld a,h
	cp botscreen
	jp nc,spriteoff
	ld (ix+3),h
	ld (ix+2),l
	ld a,(loop_counter)
	rlca
	rlca
	and 1
	ld (ix+14),a
	jp downdiag
	;
downdiagaccelerate:	;increases vertical speed as we get further down the screen
	call getspeed
	ld (ix+11),h
	ld (ix+10),l
	jp downdiag
	;
getspeed:
	ld a,(ix+1)	;high byte of screen address
	and 88		;we just want segments
	ld hl,32
	cp 64
	ret c
	ld hl,512
	cp 72
	ret c
	ld hl,1024
	ret
	;
vagup:
	ld a,(ix+15)
	xor 1
	ld (ix+15),a	;toggle magenta and red
chaseupdiag:		;move down and diagonally horizontal
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	xor a
	sbc hl,de
	ld a,h
	cp botscreen
	jp nc,spriteoff
	ld (ix+3),h
	ld (ix+2),l
	ld a,(px+1)
	cp (ix+5)	;baddy x
	jp c,sprite_left
	jp sprite_right
	;
dangerouseggdown:	;normal down to bottom, then turn into vag
	ld a,(ix+15)
	xor 3+64	;toggle green and white
	ld (ix+15),a
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	add hl,de
	ld a,h
	cp botscreen-16
	ld (ix+3),h
	ld (ix+2),l
	ret c
	push ix
	pop hl
	ld de,6
	add hl,de
	ex de,hl
	ld hl,vagldir
	ld bc,10
	ldir
	ret
	;
			;at bottom of screen, time to hatch
vagldir:	;data to ldir in place when egg hatches
	dw	vaggraphic
	dw	vagup
	dw	512
	dw	512
	db	0
	db	2
	;
chasedowndiag:		;move down and diagonally horizontal
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	add hl,de
	ld a,h
	cp botscreen
	jp nc,spriteoff
	ld (ix+3),h
	ld (ix+2),l
	ld a,(px+1)
	cp (ix+5)	;baddy x
	jp c,sprite_left
	jp sprite_right
	;
avoiddowndiag:		;down and run away from px
	ld d,(ix+11)
	ld e,(ix+10)	;ydisp
	ld h,(ix+3)
	ld l,(ix+2)	;ycor
	add hl,de
	ld a,h
	cp botscreen
	jp nc,spriteoff
	ld (ix+3),h
	ld (ix+2),l
	ld a,(px+1)
	cp (ix+5)	;baddy x
	jp nc,sprite_left
	jp sprite_right
	;
sprite_right:
	ld d,(ix+13)
	ld e,(ix+12)
	ld h,(ix+5)
	ld l,(ix+4)
	add hl,de
	ld a,h
	cp rightscreen
	jr nc,togglehoriz
	ld (ix+5),h
	ld (ix+4),l
	ret
	;
sprite_left:
	ld d,(ix+13)
	ld e,(ix+12)
	ld h,(ix+5)
	ld l,(ix+4)
	xor a		;clear carry
	sbc hl,de
	ld a,h
	cp rightscreen
	jr nc,togglehoriz
	ld (ix+5),h
	ld (ix+4),l
	ret
	;
togglehoriz:
	ld a,(ix+14)
	xor 1
	ld (ix+14),a
	ret	
	;
display_sprites:
	ld ix,spritetab
	ld b,numsprite
dslp0:	push bc
	call deletesprite
	call drawsprite
	call coloursprite
	ld de,length_of_sprite_table
	add ix,de
	pop bc
	djnz dslp0
	ret
	;
powerbars:		;graphic bytes for display, KEEP WITHIN PAGE
	db	000,000,000,000
	db	128,000,000,000
	db	192,000,000,000
	db	224,000,000,000
	db	240,000,000,000
	db	248,000,000,000
	db	252,000,000,000
	db	254,000,000,000
	db	255,000,000,000
	db	255,128,000,000
	db	255,192,000,000
	db	255,224,000,000
	db	255,240,000,000
	db	255,248,000,000
	db	255,252,000,000
	db	255,254,000,000
	db	255,255,000,000
	db	255,255,128,000
	db	255,255,192,000
	db	255,255,224,000
	db	255,255,240,000
	db	255,255,248,000
	db	255,255,252,000
	db	255,255,254,000
	db	255,255,255,000
	db	255,255,255,128
	db	255,255,255,192
	db	255,255,255,224
	db	255,255,255,240
	db	255,255,255,248
	db	255,255,255,252
	db	255,255,255,254
	db	255,255,255,255
	;
printlives:
	ld a,(lives)
	add a,'0'	;convert to ASCII '0-9'
	call get_char
	ld de,lifetextpos
	call print_char
	ret
	;
printitems:
	ld hl,items
	ld de,itemnumpos
	ld b,1
	jr psclp
	;
print_score:
	ld hl,score
	ld de,scorepos	;where we print the string
	ld b,6		;6 letters to print
psclp:	push bc
	push hl
	ld a,(hl)
	call get_char
	push de
	call print_char
	pop de
	inc e
	pop hl
	pop bc
	inc hl
	djnz psclp
	ret
	;
printcurrentitem:
	call ixitem
	ld de,itempos
prit:	push de
	call dsp1	;print on screen
	pop de
	call screen2att
	ld a,(ix+15)
	ld b,2
	call csent0
	ld b,1
	ld a,71
	call csent0
	ret
	;
ixitem:	call getitem
	push hl
	pop ix		;IX at current item data
	ld h,(ix+7)
	ld l,(ix+6)	;HL at graphic
	ret
	;
printlineofitems
	call ixitem
	ld de,20480+3
	ld b,9
pllp:	push bc
	push de
	push hl
	call prit
	pop hl
	pop de
	inc e
	inc e
	pop bc
	djnz pllp
	ret
	;
get_char:
	ld bc,font-256
gcent:	ld h,0		;entry point with different BC pointer
	ld l,a
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,bc
	ret
	;
get_block:		;entry point with different font
	ld h,0
	ld l,a
	ld b,h
	ld c,l
	add hl,hl
	add hl,hl
	add hl,hl	;x8
	add hl,bc	;x9
	ld bc,blocks
	add hl,bc
	ret
	;
print_char:
	ld b,8
pclp:	ld a,(hl)
	ld (de),a
	inc d
	inc hl
	djnz pclp
	ret
	
	;
draw_blast_power:
	ld a,(blastpower)	;0-31
	add a,a
	add a,a			;x4
	ld h,0
	ld l,a
	ld de,powerbars
	add hl,de
	ld de,barpos		;screen address
	ld a,3
dpblp:	push hl
	push de
	ldi
	ldi
	ldi
	ldi
	pop de
	pop hl
	inc d
	dec a
	jr nz,dpblp
	ret
	;
drawsprite:
	ld h,(ix+3)	;ycor
	ld l,(ix+5)	;xcor
	call getspritepos	;point DE at screen address
	ld (ix+1),d
	ld (ix+0),e	;address to delete next time
	ld a,(ix+5)	;xcor
	ld h,(ix+7)
	ld l,(ix+6)	;graphpoint
	call getgraphic
dsp1:	ld b,16		;16 lines to sprite
	ld c,255
drlp:	ld a,d
	cp 88		;88> is offscreen
	jr nc,drmiss
	ldi
	ldi
	ldi
	dec e
	dec e
	dec e
	inc d
	ld a,d
	and 7
	jp nz ,drmiss
	ld a,e
	add a,32
	ld e,a
	jr c,drmiss
	ld a,d
	sub 8
	ld d,a
drmiss:
	djnz drlp
	ret
	;
coloursprite:
	ld h,(ix+3)	;ycor
	ld l,(ix+5)	;xcor
	call getspriteatt
csent:	ld a,(ix+15)	;get colour
	ld b,3
csent0:	ld de,30
colp:	ld (hl),a
	inc l
	ld (hl),a
	inc l
	ld (hl),a
	add hl,de
	djnz colp
	ret
	;
deletesprite:
	ld h,(ix+1)
	ld l,(ix+0)	;oldscadd to delete
dlspr:	ld c,0		;delete with C
	ld b,16		;16 lines to delete
delp:	ld a,h
	cp 88		;88> is outside screen
	jr nc,dmiss
	ld (hl),c
	inc l
	ld (hl),c
	inc l
	ld (hl),c	;delete 3 cells
	dec l
	dec l
	inc h		;next linedown
	ld a,h
	and 7
	jp nz,dmiss
	ld a,l
	add a,32
	ld l,a
	jr c,dmiss
	ld a,h
	sub 8
	ld h,a
dmiss:	djnz delp
	ret
	;
score100:
	ld b,4
	ld hl,score+3
	jr scolp
	;
score10:
	ld b,5
	ld hl,score+4
	jr scolp
	;
score1:
	ld b,6
	ld hl,score+5
scolp:	inc (hl)
	ld a,(hl)
	cp '9'+1
	ret c
	ld (hl),'0'
	dec hl
	djnz scolp
	ret
	;
extralifemessage:
	ld a,(extralifeflag)
	or a
	ret z
	dec a
	ld (extralifeflag),a
	jr z,restore_lifeattrs
	ld h,0
	ld b,a		;shorter sound
	call pblp0
	ld hl,23033	;start of the 'lives' box on panel
	ld de,32-6
	ld c,2
exlp0:	ld b,6
exlp:	ld a,(hl)
	add a,8
	and 127
	ld (hl),a
	inc l
	djnz exlp
	add hl,de
	dec c
	jr nz,exlp0
	ret
	;
restore_lifeattrs:
	ld hl,lifeattrs
	ld de,23033
	ldi
	ldi
	ldi
	ldi
	ldi
	ldi
	ld de,23033+32
	ldi
	ldi
	ldi
	ldi
	ldi
	ldi
	ret
	;
lifeattrs:
	db	70,70,70,70,70,70
	db	71,71,71,71,71,71
	;
checkscorebonus:	;if we've added 1000 we gain a life
	ld a,(score+2)	;thousands column
	ld hl,oldscore
	cp (hl)
	ld (hl),a	;keep score to check next time
	jr nz,lifeplus
	ret
	;
lifeplus:
	ld a,(lives)
	cp 9
	ret nc
	inc a
	ld (lives),a
	call printlives
	ld a,24
	ld (extralifeflag),a
	ret
	;
variables:
lives:			db	9
level:			db	0
deadflag:		db	0
gameoverflag:		db	0
gamecompletedflag:	db	0
inwincibleflag:		db	0
extralifeflag:		db	0
bulletsoundflag:	db	0
shootflag:		db	0
blastpower:		db	0
bulltabseed:		dw	bullettab
badtabseed:		db	0
blast1flag:		db	0
blast2flag:		db	0
blast3flag:		db	0
eventcounter:		db	0
items:			db	'0'	;number of oranges, turkeys etc
	db	0,0	;necessary?
score:	db	'000000'
oldscore:	db	'0'
	;
varstore:
	db	9
	db	0
	db	0
	db	0
	db	0
	db	0
	db	0
	db	0
	db	0
	db	0
	dw	bullettab
	db	0
	db	0
	db	0
	db	0
	db	0
	db	'0'
	db	0,0
scstore:	db	'000000'	;score store
	db	'0'
endvarstore:
	;
spritetab:
	dw	0		;oldscadd		0,1
py:	db	0,0		;player y cor		2,3
px:	db	0,0		;player x cor		4,5
gp:	dw	shipgraphic	;graphic pointer	6,7
cr:	dw	downdiag	;control routine	8,9
yd:	dw	512		;ydisp			10,11
xd:	dw	512		;xdisp			12,13
cd:	db	0		;direction byte		14
spcol:	db	71		;sprite colour		15
	db	0		;sprite life (baddies)	16
	dw	dnth		;sprite dead routine	17,18
	db	0		;on/off switch (baddies)19
	dw	dnth		;score value		20,21
	dw	dnth		;collision effect	22,23
	;
badtab:
rept	numsprite-1
	dw	0
	db	0,0
	db	0,0
	dw	puddinggraphic
	dw	downdiag
	dw	256
	dw	256
	db	0
	db	7
	db	0
	dw	dnth
	db	0	;active switch
	dw	dnth
	dw	dnth
endrep
	;
events:
	ld de,(level)	;level in E
	ld d,0
	ld hl,levelwaitstab
	add hl,de
	ld a,(loop_counter)
	and (hl)
	ret nz
	ld a,(badtabseed)	;event ok
	cp numsprite-1
	jr nc,resetbtseed
	ld b,a	;0-14
	inc b	;1-15
	ld hl,badtab
	ld de,length_of_sprite_table
elp:	add hl,de
	djnz elp
	push hl
	pop ix
	ld a,(ix+19)
	or a
	jr nz,emiss
	;	okay insert a new sprite
	push hl
	call getbaddy
	pop de
	ld bc,length_of_sprite_table
	ldir
	ld a,(ix+10)
	or (ix+11)
	call z,setspeed
elp0:	call rnd
	cp rightscreen
	jr nc,elp0
	ld (ix+5),a	;xcor
emiss:	ld a,(badtabseed)
	inc a
	ld (badtabseed),a
	cp 15
	ret c
resetbtseed:
	xor a
	ld (badtabseed),a
	ret
	;
getbaddy:
	ld hl,eventcounter
	inc (hl)
	ld a,(hl)
	cp 8
	jr nc,getitem
	call rnd
	ld b,a
	ld a,(level)
	and 7
	ld e,a
	ld d,0
	ld hl,availablebaddytab
	add hl,de
	ld a,b
	and (hl)	;1,3,7,or15
	add a,a		;byte to word
	ld hl,getbaddytab
	ld b,0
	ld c,a
	add hl,bc
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	ret
	;
getitem:
	xor a
	ld (eventcounter),a	;reset eventcounter
	ld a,(level)
	and 7
	add a,a		;byte to word
	ld hl,getitemtab
	ld b,0
	ld c,a
	add hl,bc
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	ret
	;
getbaddytab:
	dw	asteroiddata
	dw	medusoidaliendata
	dw	tutankdata
	dw	rhinotankdata
	dw	hardasteroiddata
	dw	bouncyasteroiddata
	dw	rotatingthingdata
	dw	cockdata
	dw	beetlebonnetdata
	dw	fallingfishdata
	dw	dangerouseggdata
	dw	worryaliendata
	dw	bluevagdata
	dw	flapjellydata
	dw	trilobitedata
	dw	windmilldata
	;
getitemtab:
	dw	presentdata
	dw	puddingdata
	dw	socksdata
	dw	orangedata
	dw	baubledata
	dw	datedata
	dw	turkeydata
	dw	sproutdata
	;
levelwaitstab:
	db	31,31,31,31,15,15,07,03
	;
availablebaddytab:
	db	01,03,07,07,15,15,15,15
	;
setspeed:
	call rnd
	and 14
	ld hl,spritespeedtab
	ld d,0
	ld e,a
	add hl,de
	ld e,(hl)
	inc hl
	ld d,(hl)
	ld (ix+10),e
	ld (ix+11),d
	ret
	;
spritespeedtab:
	dw	64
	dw	128
	dw	256
	dw	256
	dw	512
	dw	512
	dw	512
	dw	1024
	;
emptydata
	dw	0
	db	0,230
	db	0,230
	dw	puddinggraphic
	dw	downdiag
	dw	256
	dw	256
	db	0
	db	7
	db	0
	dw	dnth
	db	0	;active switch
	dw	dnth
	dw	dnth	
	;
bluevagdata:
	dw	0
	db	0,0
	db	0,0
	dw	worrywartgraphic
	dw	chasedowndiag
	dw	256
	dw	128
	db	0
	db	65
	db	baddylife*4
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
worryaliendata:
	dw	0
	db	0,0
	db	0,0
	dw	worryaliengraphic
	dw	avoiddowndiag
	dw	256
	dw	128
	db	0
	db	5
	db	baddylife*2
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
medusoidaliendata:
	dw	0
	db	0,0
	db	0,0
	dw	medusoidaliengraphic
	dw	chasedowndiag
	dw	512
	dw	256
	db	0
	db	67
	db	baddylife*4
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
beetlebonnetdata:
	dw	0
	db	0,0
	db	0,0
	dw	beetlebonnetgraphic
	dw	chasedowndiag
	dw	512
	dw	512
	db	0
	db	70
	db	baddylife*2
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
dangerouseggdata:
	dw	0
	db	0,0
	db	0,0
	dw	dangerousegggraphic
	dw	dangerouseggdown
	dw	256
	dw	2
	db	0
	db	7
	db	baddylife*16
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
fallingfishdata:
	dw	0
	db	0,0
	db	0,0
	dw	fallingfishgraphic
	dw	wobbledown
	dw	256
	dw	512
	db	0
	db	69
	db	baddylife
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
rotatingthingdata:
	dw	0
	db	0,0
	db	0,0
	dw	rotatingthinggraphic
	dw	wobbledown1
	dw	256
	dw	256
	db	0
	db	69
	db	baddylife
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
cockdata:
	dw	0
	db	0,0
	db	0,0
	dw	cockgraphic
	dw	cockdrop
	dw	128
	dw	256
	db	0
	db	6
	db	baddylife
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
flapjellydata:
	dw	0
	db	0,0
	db	0,0
	dw	flapjellygraphic
	dw	downdiag
	dw	64
	dw	256
	db	0
	db	4
	db	baddylife*16
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
rhinotankdata:
	dw	0
	db	0,0
	db	0,0
	dw	rhinotankgraphic
	dw	rhinodowndiag
	dw	256
	dw	256
	db	0
	db	65
	db	baddylife
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
tutankdata:
	dw	0
	db	0,0
	db	0,0
	dw	tutankgraphic
	dw	rhinodowndiag
	dw	512
	dw	256
	db	0
	db	7
	db	baddylife
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
trilobitedata:
	dw	0
	db	0,0
	db	0,0
	dw	trilobitegraphic
	dw	t_downdiag
	dw	256
	dw	256
	db	0
	db	65
	db	baddylife
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
windmilldata:
	dw	0
	db	0,0
	db	0,0
	dw	windmillgraphic
	dw	downdiagaccelerate
	dw	32
	dw	256
	db	0
	db	71
	db	baddylife*4
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
asteroiddata:
	dw	0
	db	0,0
	db	0,0
	dw	asteroidgraphic
	dw	downdiag
	dw	0
	dw	32
	db	0
	db	7
	db	baddylife*4
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
hardasteroiddata:
	dw	0
	db	0,0
	db	0,0
	dw	hardasteroidgraphic
	dw	justdown
	dw	128
	dw	0
	db	0
	db	2
	db	baddylife*8
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
bouncyasteroiddata:
	dw	0
	db	0,0
	db	0,0
	dw	asteroidgraphic
	dw	downdiag
	dw	64
	dw	1024
	db	0
	db	7
	db	baddylife
	dw	explode
	db	255
	dw	score10
	dw	killplayer
	;
orangedata:
	dw	0
	db	0,0
	db	0,0
	dw	orangegraphic
	dw	orangedowndiag
	dw	256
	dw	512
	db	0
	db	70
	db	baddylife*4
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
turkeydata:
	dw	0
	db	0,0
	db	0,0
	dw	turkeygraphic
	dw	downdiag
	dw	512
	dw	512
	db	0
	db	6
	db	baddylife*2
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
puddingdata:
	dw	0
	db	0,0
	db	0,0
	dw	puddinggraphic
	dw	downdiag
	dw	256
	dw	256
	db	0
	db	66
	db	baddylife*8
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
datedata:
	dw	0
	db	0,0
	db	0,0
	dw	dategraphic
	dw	downdiag
	dw	256
	dw	512
	db	0
	db	2
	db	baddylife*2
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
sproutdata:
	dw	0
	db	0,0
	db	0,0
	dw	sproutgraphic
	dw	downdiag
	dw	512
	dw	512
	db	0
	db	68
	db	baddylife
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
socksdata:
	dw	0
	db	0,0
	db	0,0
	dw	socksgraphic
	dw	downdiag
	dw	256
	dw	256
	db	0
	db	70
	db	baddylife*4
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
baubledata:
	dw	0
	db	0,0
	db	0,0
	dw	baublegraphic
	dw	downdiag
	dw	256
	dw	512
	db	0
	db	70
	db	baddylife*2
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
presentdata:
	dw	0
	db	0,0
	db	0,0
	dw	presentgraphic
	dw	downdiag
	dw	256
	dw	256
	db	0
	db	68
	db	baddylife*16
	dw	explode
	db	255
	dw	itemless
	dw	itemcollected
	;
getgraphic:	;arrive A holding xcor, HL pointing at graphic start, leave HL pointing at graphic
	and 6	;same as divide by two then x2
	add a,a	;x4
	add a,a	;x8
	add a,a	;x16
	ld b,a
	add a,a	;x32
	add a,b	;x48
	ld c,a
	ld b,0
	add hl,bc
	ret
	;
safety:
	ld hl,safeplace
	ld de,safeplace	;safe offscreen place to draw in contended memory
	ret
	;
getspritepos:
	ld a,h
	cp botscreen
	jr nc,safety
	ld a,l
	cp rightscreen
	jr nc,safety
xy2screen:	;arrive with H=y 0-192, l=x 0-255, return with DE at corresponding screen
	ld a,h
	rra
	rra
	rra
	and 24
	or 64
	ld d,a
	ld a,h
	and 7
	or d
	ld d,a
	ld a,h
	rla
	rla
	and 224
	ld e,a
	ld a,l
	rra
	rra
	rra
	and 31
	or e
	ld e,a
	ret
	;
getspriteatt:
	ld a,h
	cp botscreen
	jr nc,safety
	ld a,l
	cp rightscreen
	jr nc,safety
	call xy2screen
screen2att:		;convert DE at screen to HL at ATTRS
	ld a,d
	rra
	rra
	rra
	and 3
	or 88
	ld h,a
	ld l,e
	ret	
	;
nextlinedown:		;move DE one line down in display file
	inc d
	ld a,d
	and 7
	ret nz
	ld a,e
	add a,32
	ld e,a
	ret c
	ld a,d
	sub 8
	ld d,a
	ret
	;
draw_stars:
	ld ix,star_tab
	ld b,numstars
slp:	ld a,(loop_counter)
	and (ix+3)
	jr nz,smiss
	ld h,(ix+1)
	ld l,(ix+0)
	ld a,(ix+2)
	cpl
	ld d,a
	ld a,(hl)
	and d
	ld (hl),a
	inc h
	ld a,h
	and 7
	jr nz,smiss0
	ld a,l
	add a,32
	ld l,a
	jr c,smiss0
	ld a,h
	sub 8
	ld h,a
smiss0:	ld a,h	
	cp 88
	call nc,newstar
	ld (ix+1),h
	ld (ix+0),l
	ld a,(hl)
	or (ix+2)
	ld (hl),a
smiss:	inc ix
	inc ix
	inc ix
	inc ix
	djnz slp
	ret
	;
newstar:
	call rnd
	and 15
	ld hl,starspeeds
	add a,l
	ld l,a
	ld a,(hl)
	ld (ix+3),a
	call rnd
	and 7
	inc a
	ld d,a
	xor a
	scf
nslp:	rra
	dec d
	jr nz,nslp
	ld (ix+2),a
rstar:	call rnd
	and 31
	cp 23
	jr nc,rstar
	ld l,a
	ld h,64
	ret
	;
setvariables:
	ld hl,varstore
	ld de,variables
	ld bc,length_of_variables
	ldir
	ld l,0
	ld h,120
	ld (py),hl
	ld h,88
	ld (px),hl
	ret
	;
setupstartab:
	ld ix,star_tab
	ld b,numstars
sulp:	call newstar
	ld (ix+0),l
	call rnd
	and 80
	ld (ix+1),a
	inc ix
	inc ix
	inc ix
	inc ix
	djnz sulp
	ret
	;
set_interrupt:		;im2 that plays AY, vector table at 65024, routine at 65021 which JPs to proper routine
	di
	ld a,254
	ld i,a
	im 2
	ei
	ret
	;
toggleAY:
	ld a,(loop_counter)
	and 7
	ret nz
	ld hl,AYbyte
	inc (hl)
	ld a,(hl)
	rra
	jr c,AYoff
AYon:	di	
	ld hl,play_AY
	ld (intpok+1),hl
	ei
	ret
	;
ifAYon:
	ld a,(AYbyte)
	rra
	jr nc,AYon
	ret
	;
AYbyte:	db	0
	;
AYoff:	di	
	ld hl,delay2
	ld (intpok+1),hl
	ld c,253
	ld e,0
	ld a,8		;register #
aolp:	ld b,255
	out (c),a
	ld b,191
	out (c),e	;set to zero
	inc a
	cp 11		;repeat for register 8,9,10
	jr c,aolp
	ei
	ret
	;
clear_sprite_table:
	ld a,numsprite-1
	ld de,badtab
cstlp:	ld hl,emptydata
	ld bc,length_of_sprite_table
	ldir
	dec a
	jr nz,cstlp
	ret
	;
star_tab:
rept	numstars
	dw	0
	db	0,0	;bit to set, speed
endrep
	;
;PATRIK RAK's XOR SHIFT RND generator
rnd     ld  hl,0xA280   ; yw -> zt
        ld  de,0xC0DE   ; xz -> yw
        ld  (rnd+4),hl  ; x = y, z = w
        ld  a,l         ; w = w ^ ( w << 3 )
        add a,a
        add a,a
        add a,a
        xor l
        ld  l,a
        ld  a,d         ; t = x ^ (x << 1)
        add a,a
        xor d
        ld  h,a
        rra             ; t = t ^ (t >> 1) ^ w
        xor h
        xor l
        ld  h,e         ; y = z
        ld  l,a         ; w = t
        ld  (rnd+1),hl
	ret
	;
shipgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 32, 4, 0
db 2, 64, 0
db 39, 228, 0
db 36, 36, 0
db 100, 38, 0
db 206, 115, 0
db 175, 245, 0
db 103, 230, 0
db 237, 183, 0
db 204, 51, 0
db 165, 165, 0
db 108, 54, 0
db 229, 167, 0
db 68, 34, 0
db 39, 228, 0
db 1, 128, 0

; block at pixel position (0,16):

db 8, 1, 0
db 0, 144, 0
db 9, 249, 0
db 9, 9, 0
db 25, 9, 128
db 51, 156, 192
db 43, 253, 64
db 25, 249, 128
db 59, 109, 192
db 51, 12, 192
db 41, 105, 64
db 27, 13, 128
db 57, 105, 192
db 17, 8, 128
db 9, 249, 0
db 0, 96, 0

; block at pixel position (0,32):

db 2, 0, 64
db 0, 36, 0
db 2, 126, 64
db 2, 66, 64
db 6, 66, 96
db 12, 231, 48
db 10, 255, 80
db 6, 126, 96
db 14, 219, 112
db 12, 195, 48
db 10, 90, 80
db 6, 195, 96
db 14, 90, 112
db 4, 66, 32
db 2, 126, 64
db 0, 24, 0

; block at pixel position (0,48):

db 0, 128, 16
db 0, 9, 0
db 0, 159, 144
db 0, 144, 144
db 1, 144, 152
db 3, 57, 204
db 2, 191, 212
db 1, 159, 152
db 3, 182, 220
db 3, 48, 204
db 2, 150, 148
db 1, 176, 216
db 3, 150, 156
db 1, 16, 136
db 0, 159, 144
db 0, 6, 0
	;
puddinggraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

defb 8, 16, 0
 defb 28, 56, 0
 defb 14, 112, 0
 defb 1, 128, 0
 defb 14, 112, 0
 defb 48, 140, 0
 defb 64, 50, 0
 defb 64, 10, 0
 defb 128, 1, 0
 defb 192, 193, 0
 defb 217, 231, 0
 defb 255, 125, 0
 defb 223, 255, 0
 defb 123, 154, 0
 defb 63, 156, 0
 defb 15, 240, 0

; block at pixel position (0,16):

defb 2, 4, 0
 defb 7, 14, 0
 defb 3, 156, 0
 defb 0, 96, 0
 defb 3, 156, 0
 defb 12, 35, 0
 defb 16, 12, 128
 defb 16, 2, 128
 defb 32, 0, 64
 defb 48, 48, 64
 defb 54, 121, 192
 defb 63, 223, 64
 defb 55, 255, 192
 defb 30, 230, 128
 defb 15, 231, 0
 defb 3, 252, 0

; block at pixel position (0,32):

defb 0, 129, 0
 defb 1, 195, 128
 defb 0, 231, 0
 defb 0, 24, 0
 defb 0, 231, 0
 defb 3, 8, 192
 defb 4, 3, 32
 defb 4, 0, 160
 defb 8, 0, 16
 defb 12, 12, 16
 defb 13, 158, 112
 defb 15, 247, 208
 defb 13, 255, 240
 defb 7, 185, 160
 defb 3, 249, 192
 defb 0, 255, 0

; block at pixel position (0,48):

defb 0, 32, 64
 defb 0, 112, 224
 defb 0, 57, 192
 defb 0, 6, 0
 defb 0, 57, 192
 defb 0, 194, 48
 defb 1, 0, 200
 defb 1, 0, 40
 defb 2, 0, 4
 defb 3, 3, 4
 defb 3, 103, 156
 defb 3, 253, 244
 defb 3, 127, 252
 defb 1, 238, 104
 defb 0, 254, 112
 defb 0, 63, 192
	;
asteroidgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 7, 192, 0
db 31, 240, 0
db 127, 248, 0
db 111, 124, 0
db 91, 238, 0
db 219, 253, 0
db 231, 235, 0
db 255, 117, 0
db 255, 233, 0
db 255, 209, 0
db 118, 169, 0
db 125, 66, 0
db 118, 170, 0
db 61, 2, 0
db 30, 140, 0
db 7, 240, 0

; block at pixel position (0,16):

db 1, 240, 0
db 7, 252, 0
db 31, 254, 0
db 27, 223, 0
db 22, 251, 128
db 54, 255, 64
db 57, 250, 192
db 63, 221, 64
db 63, 250, 64
db 63, 244, 64
db 29, 170, 64
db 31, 80, 128
db 29, 170, 128
db 15, 64, 128
db 7, 163, 0
db 1, 252, 0

; block at pixel position (0,32):

db 0, 124, 0
db 1, 255, 0
db 7, 255, 128
db 6, 247, 192
db 5, 190, 224
db 13, 191, 208
db 14, 126, 176
db 15, 247, 80
db 15, 254, 144
db 15, 253, 16
db 7, 106, 144
db 7, 212, 32
db 7, 106, 160
db 3, 208, 32
db 1, 232, 192
db 0, 127, 0

; block at pixel position (0,48):

db 0, 31, 0
db 0, 127, 192
db 1, 255, 224
db 1, 189, 240
db 1, 111, 184
db 3, 111, 244
db 3, 159, 172
db 3, 253, 212
db 3, 255, 164
db 3, 255, 68
db 1, 218, 164
db 1, 245, 8
db 1, 218, 168
db 0, 244, 8
db 0, 122, 48
db 0, 31, 192
	;
worryaliengraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 9, 144, 0
db 22, 104, 0
db 46, 116, 0
db 90, 90, 0
db 218, 91, 0
db 109, 182, 0
db 179, 205, 0
db 93, 186, 0
db 174, 117, 0
db 95, 250, 0
db 184, 29, 0
db 112, 14, 0
db 119, 238, 0
db 62, 124, 0
db 31, 248, 0
db 7, 224, 0

; block at pixel position (0,16):

db 2, 100, 0
db 5, 154, 0
db 11, 157, 0
db 22, 150, 128
db 54, 150, 192
db 27, 109, 128
db 44, 243, 64
db 23, 110, 128
db 43, 157, 64
db 23, 254, 128
db 46, 7, 64
db 28, 3, 128
db 29, 251, 128
db 15, 159, 0
db 7, 254, 0
db 1, 248, 0

; block at pixel position (0,32):

db 0, 153, 0
db 1, 102, 128
db 2, 231, 64
db 4, 0, 32
db 13, 231, 176
db 6, 219, 96
db 11, 60, 208
db 5, 219, 160
db 10, 231, 80
db 5, 255, 160
db 11, 129, 208
db 7, 0, 224
db 7, 126, 224
db 3, 231, 192
db 1, 255, 128
db 0, 126, 0

; block at pixel position (0,48):

db 0, 38, 64
db 0, 89, 160
db 0, 185, 208
db 1, 0, 8
db 3, 121, 236
db 1, 182, 216
db 2, 207, 52
db 1, 118, 232
db 2, 185, 212
db 1, 127, 232
db 2, 224, 116
db 1, 192, 56
db 1, 223, 184
db 0, 249, 240
db 0, 127, 224
db 0, 31, 128
	;
medusoidaliengraphic:
;
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 32, 4, 0
db 65, 130, 0
db 64, 2, 0
db 137, 145, 0
db 145, 137, 0
db 170, 85, 0
db 243, 207, 0
db 232, 23, 0
db 243, 207, 0
db 123, 222, 0
db 124, 62, 0
db 59, 220, 0
db 55, 236, 0
db 183, 237, 0
db 87, 234, 0
db 139, 209, 0

; block at pixel position (0,16):

db 8, 1, 0
db 16, 96, 128
db 16, 0, 128
db 34, 100, 64
db 36, 98, 64
db 42, 149, 64
db 60, 243, 192
db 58, 5, 192
db 60, 243, 192
db 30, 247, 128
db 31, 15, 128
db 14, 247, 0
db 13, 251, 0
db 45, 251, 64
db 21, 250, 128
db 34, 244, 64

; block at pixel position (0,32):

db 4, 24, 32
db 4, 0, 32
db 8, 24, 16
db 8, 153, 16
db 9, 36, 144
db 10, 189, 80
db 15, 60, 240
db 14, 129, 112
db 15, 60, 240
db 7, 189, 224
db 7, 195, 224
db 3, 189, 192
db 11, 126, 208
db 7, 126, 224
db 9, 126, 144
db 0, 189, 0

; block at pixel position (0,48):

db 1, 6, 8
db 1, 0, 8
db 2, 6, 4
db 2, 38, 68
db 2, 73, 36
db 2, 175, 84
db 3, 207, 60
db 3, 160, 92
db 3, 207, 60
db 1, 239, 120
db 1, 240, 248
db 0, 239, 112
db 2, 223, 180
db 1, 223, 184
db 2, 95, 164
db 0, 47, 64
;
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):
beetlebonnetgraphic:
db 14, 112, 0
db 63, 252, 0
db 126, 126, 0
db 127, 254, 0
db 254, 127, 0
db 255, 255, 0
db 190, 125, 0
db 209, 139, 0
db 175, 245, 0
db 223, 251, 0
db 185, 157, 0
db 176, 13, 0
db 209, 139, 0
db 72, 18, 0
db 96, 6, 0
db 16, 8, 0

; block at pixel position (0,16):

db 3, 156, 0
db 15, 255, 0
db 31, 159, 128
db 31, 255, 128
db 63, 159, 192
db 63, 255, 192
db 47, 159, 64
db 52, 98, 192
db 43, 253, 64
db 55, 254, 192
db 46, 103, 64
db 44, 3, 64
db 52, 98, 192
db 18, 4, 128
db 24, 1, 128
db 4, 2, 0

; block at pixel position (0,32):

db 0, 231, 0
db 3, 255, 192
db 7, 255, 224
db 7, 231, 224
db 15, 219, 240
db 15, 231, 240
db 11, 219, 208
db 13, 60, 176
db 10, 255, 80
db 13, 255, 176
db 5, 195, 160
db 5, 153, 160
db 4, 129, 32
db 4, 66, 32
db 3, 0, 192
db 0, 129, 0

; block at pixel position (0,48):

db 0, 57, 192
db 0, 255, 240
db 1, 255, 248
db 1, 249, 248
db 3, 246, 252
db 3, 249, 252
db 2, 246, 244
db 3, 79, 44
db 2, 191, 212
db 3, 127, 236
db 1, 112, 232
db 1, 102, 104
db 1, 32, 72
db 1, 16, 136
db 0, 192, 48
db 0, 32, 64
	;
dangerousegggraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 3, 192, 0
db 15, 240, 0
db 31, 248, 0
db 63, 252, 0
db 62, 124, 0
db 124, 62, 0
db 127, 254, 0
db 254, 127, 0
db 254, 127, 0
db 251, 223, 0
db 241, 143, 0
db 243, 207, 0
db 127, 254, 0
db 127, 254, 0
db 31, 248, 0
db 7, 224, 0

; block at pixel position (0,16):

db 0, 240, 0
db 3, 252, 0
db 7, 254, 0
db 15, 255, 0
db 15, 159, 0
db 31, 15, 128
db 31, 255, 128
db 63, 159, 192
db 63, 159, 192
db 62, 247, 192
db 60, 99, 192
db 60, 243, 192
db 31, 255, 128
db 31, 255, 128
db 7, 254, 0
db 1, 248, 0

; block at pixel position (0,32):

db 0, 60, 0
db 0, 255, 0
db 1, 255, 128
db 3, 255, 192
db 3, 231, 192
db 7, 195, 224
db 7, 255, 224
db 15, 231, 240
db 15, 231, 240
db 15, 189, 240
db 15, 24, 240
db 15, 60, 240
db 7, 255, 224
db 7, 255, 224
db 1, 255, 128
db 0, 126, 0

; block at pixel position (0,48):

db 0, 15, 0
db 0, 63, 192
db 0, 127, 224
db 0, 255, 240
db 0, 249, 240
db 1, 240, 248
db 1, 255, 248
db 3, 249, 252
db 3, 249, 252
db 3, 239, 124
db 3, 198, 60
db 3, 207, 60
db 1, 255, 248
db 1, 255, 248
db 0, 127, 224
db 0, 31, 128
	;
flapjellygraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 129, 129, 0
db 128, 1, 0
db 193, 131, 0
db 240, 15, 0
db 249, 159, 0
db 250, 95, 0
db 253, 191, 0
db 254, 127, 0
db 253, 191, 0
db 126, 126, 0
db 125, 190, 0
db 126, 126, 0
db 61, 188, 0
db 58, 220, 0
db 11, 208, 0
db 5, 160, 0

; block at pixel position (0,16):

db 0, 96, 0
db 16, 0, 128
db 16, 96, 128
db 24, 1, 128
db 20, 98, 128
db 26, 149, 128
db 31, 111, 128
db 31, 159, 128
db 31, 111, 128
db 31, 159, 128
db 31, 111, 128
db 31, 159, 128
db 15, 111, 0
db 14, 183, 0
db 2, 244, 0
db 1, 104, 0

; block at pixel position (0,32):

db 0, 24, 0
db 0, 0, 0
db 0, 24, 0
db 2, 0, 64
db 3, 24, 192
db 2, 165, 64
db 3, 90, 192
db 2, 231, 64
db 3, 90, 192
db 3, 231, 192
db 3, 219, 192
db 1, 231, 128
db 1, 219, 128
db 1, 173, 128
db 0, 189, 0
db 0, 90, 0

; block at pixel position (0,48):

db 0, 6, 0
db 1, 0, 8
db 1, 6, 8
db 1, 128, 24
db 1, 70, 40
db 1, 169, 88
db 1, 246, 248
db 1, 249, 248
db 1, 246, 248
db 1, 249, 248
db 1, 246, 248
db 1, 249, 248
db 0, 246, 240
db 0, 235, 112
db 0, 47, 64
db 0, 22, 128
	;
worrywartgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

defb 122, 0, 0
defb 221, 192, 0
defb 182, 240, 0
defb 146, 248, 0
defb 146, 248, 0
defb 254, 252, 0
defb 125, 254, 0
defb 131, 255, 0
defb 255, 255, 0
defb 215, 255, 0
defb 255, 79, 0
defb 124, 15, 0
defb 124, 175, 0
defb 63, 254, 0
defb 31, 252, 0
defb 7, 240, 0

; block at pixel position (0,16):

defb 30, 128, 0
defb 63, 112, 0
defb 53, 188, 0
defb 44, 190, 0
defb 36, 191, 0
defb 39, 191, 0
defb 31, 127, 128
defb 32, 255, 128
defb 63, 255, 192
defb 53, 255, 192
defb 63, 215, 192
defb 31, 131, 192
defb 31, 43, 192
defb 15, 255, 128
defb 7, 255, 0
defb 1, 252, 0

; block at pixel position (0,32):

defb 7, 176, 0
defb 13, 222, 0
defb 11, 239, 128
defb 9, 111, 128
defb 9, 47, 192
defb 15, 47, 192
defb 7, 223, 224
defb 8, 63, 224
defb 15, 255, 240
defb 13, 127, 240
defb 15, 255, 240
defb 7, 229, 240
defb 7, 202, 240
defb 3, 255, 224
defb 1, 255, 192
defb 0, 127, 0

; block at pixel position (0,48):

defb 1, 232, 0
defb 3, 247, 0
defb 3, 91, 192
defb 2, 203, 224
defb 2, 75, 240
defb 2, 123, 240
defb 1, 247, 252
defb 2, 15, 252
defb 3, 255, 252
defb 3, 95, 252
defb 3, 253, 124
defb 1, 248, 60
defb 1, 242, 188
defb 0, 255, 248
defb 0, 127, 240
defb 0, 31, 192
	;
vaggraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 112, 14, 0
db 192, 3, 0
db 225, 135, 0
db 114, 78, 0
db 13, 176, 0
db 21, 168, 0
db 46, 116, 0
db 93, 186, 0
db 90, 90, 0
db 186, 93, 0
db 244, 47, 0
db 244, 47, 0
db 168, 21, 0
db 116, 46, 0
db 122, 94, 0
db 29, 184, 0

; block at pixel position (0,16):

db 28, 3, 128
db 48, 0, 192
db 56, 97, 192
db 28, 147, 128
db 3, 108, 0
db 5, 106, 0
db 11, 157, 0
db 23, 110, 128
db 22, 150, 128
db 46, 151, 64
db 61, 11, 192
db 61, 11, 192
db 42, 5, 64
db 29, 11, 128
db 30, 151, 128
db 7, 110, 0

; block at pixel position (0,32):

db 3, 129, 192
db 6, 0, 96
db 7, 0, 224
db 3, 153, 192
db 0, 231, 0
db 1, 90, 128
db 2, 219, 64
db 2, 231, 64
db 5, 219, 160
db 5, 165, 160
db 15, 165, 240
db 15, 165, 240
db 13, 66, 176
db 7, 165, 224
db 7, 219, 224
db 1, 231, 128

; block at pixel position (0,48):

db 0, 224, 112
db 1, 128, 24
db 1, 192, 56
db 0, 230, 112
db 0, 57, 192
db 0, 86, 160
db 0, 182, 208
db 0, 185, 208
db 1, 118, 232
db 1, 105, 104
db 3, 233, 124
db 3, 233, 124
db 3, 80, 172
db 1, 233, 120
db 1, 246, 248
db 0, 121, 224
	;
windmillgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 96, 6, 0
db 252, 63, 0
db 254, 127, 0
db 126, 126, 0
db 121, 158, 0
db 119, 238, 0
db 55, 236, 0
db 15, 240, 0
db 15, 240, 0
db 55, 236, 0
db 119, 238, 0
db 121, 158, 0
db 126, 126, 0
db 254, 127, 0
db 252, 63, 0
db 96, 6, 0

; block at pixel position (0,16):

db 0, 0, 0
db 12, 3, 0
db 31, 159, 128
db 31, 255, 128
db 15, 255, 0
db 15, 15, 0
db 14, 247, 0
db 6, 246, 0
db 6, 246, 0
db 14, 247, 0
db 15, 15, 0
db 15, 255, 0
db 31, 255, 128
db 31, 159, 128
db 12, 3, 0
db 0, 0, 0

; block at pixel position (0,32):

db 0, 0, 0
db 0, 0, 0
db 1, 129, 128
db 3, 255, 192
db 3, 255, 192
db 1, 255, 128
db 1, 231, 128
db 1, 219, 128
db 1, 219, 128
db 1, 231, 128
db 1, 255, 128
db 3, 255, 192
db 3, 255, 192
db 1, 129, 128
db 0, 0, 0
db 0, 0, 0

; block at pixel position (0,48):

db 0, 0, 0
db 0, 192, 48
db 1, 249, 248
db 1, 255, 248
db 0, 255, 240
db 0, 240, 240
db 0, 239, 112
db 0, 111, 96
db 0, 111, 96
db 0, 239, 112
db 0, 240, 240
db 0, 255, 240
db 1, 255, 248
db 1, 249, 248
db 0, 192, 48
db 0, 0, 0
	;
fallingfishgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 81, 138, 0
db 142, 113, 0
db 197, 163, 0
db 235, 215, 0
db 127, 254, 0
db 231, 231, 0
db 219, 219, 0
db 189, 189, 0
db 181, 173, 0
db 181, 173, 0
db 219, 219, 0
db 231, 231, 0
db 124, 62, 0
db 120, 30, 0
db 25, 152, 0
db 6, 96, 0

; block at pixel position (0,16):

db 20, 98, 128
db 35, 156, 64
db 49, 104, 192
db 58, 245, 192
db 31, 255, 128
db 57, 249, 192
db 54, 246, 192
db 47, 111, 64
db 45, 107, 64
db 45, 107, 64
db 54, 246, 192
db 57, 249, 192
db 31, 15, 128
db 30, 7, 128
db 6, 102, 0
db 1, 152, 0

; block at pixel position (0,32):

db 5, 24, 160
db 8, 231, 16
db 12, 90, 48
db 14, 189, 112
db 7, 255, 224
db 14, 126, 112
db 13, 189, 176
db 11, 219, 208
db 11, 90, 208
db 11, 90, 208
db 13, 189, 176
db 14, 126, 112
db 7, 195, 224
db 7, 129, 224
db 1, 153, 128
db 0, 102, 0

; block at pixel position (0,48):

db 1, 70, 40
db 2, 57, 196
db 3, 22, 140
db 3, 175, 92
db 1, 255, 248
db 3, 159, 156
db 3, 111, 108
db 2, 246, 244
db 2, 214, 180
db 2, 214, 180
db 3, 111, 108
db 3, 159, 156
db 1, 240, 248
db 1, 224, 120
db 0, 102, 96
db 0, 25, 128
	;
cockgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

defb 51, 204, 0
defb 109, 182, 0
defb 222, 123, 0
defb 186, 93, 0
defb 182, 109, 0
defb 178, 77, 0
defb 221, 187, 0
defb 227, 199, 0
defb 254, 127, 0
defb 228, 39, 0
defb 90, 90, 0
defb 45, 180, 0
defb 60, 60, 0
defb 40, 20, 0
defb 16, 8, 0
defb 8, 16, 0

; block at pixel position (0,16):

defb 12, 243, 0
defb 27, 109, 128
defb 55, 158, 192
defb 46, 151, 64
defb 45, 155, 64
defb 44, 147, 64
defb 55, 110, 192
defb 56, 241, 192
defb 63, 159, 192
defb 57, 9, 192
defb 22, 150, 128
defb 11, 109, 0
defb 15, 15, 0
defb 10, 5, 0
defb 4, 2, 0
defb 2, 4, 0

; block at pixel position (0,32):

defb 3, 60, 192
defb 6, 219, 96
defb 13, 231, 176
defb 11, 165, 208
defb 11, 102, 208
defb 11, 36, 208
defb 13, 219, 176
defb 14, 60, 112
defb 15, 231, 240
defb 14, 66, 112
defb 5, 165, 160
defb 2, 219, 64
defb 3, 195, 192
defb 2, 129, 64
defb 1, 0, 128
defb 0, 129, 0

; block at pixel position (0,48):

defb 0, 207, 48
defb 1, 182, 216
defb 3, 121, 236
defb 2, 233, 116
defb 2, 217, 180
defb 2, 201, 52
defb 3, 118, 236
defb 3, 143, 28
defb 3, 249, 252
defb 3, 144, 156
defb 1, 105, 104
defb 0, 182, 208
defb 0, 240, 240
defb 0, 160, 80
defb 0, 64, 32
defb 0, 32, 64
	;
rotatingthinggraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 61, 240, 0
db 126, 248, 0
db 255, 124, 0
db 231, 124, 0
db 231, 124, 0
db 255, 124, 0
db 126, 252, 0
db 189, 252, 0
db 195, 252, 0
db 255, 252, 0
db 255, 236, 0
db 127, 212, 0
db 127, 236, 0
db 15, 252, 0
db 0, 0, 0
db 0, 0, 0

; block at pixel position (0,16):

db 1, 239, 0
db 7, 223, 128
db 7, 191, 192
db 7, 185, 192
db 15, 185, 192
db 15, 191, 192
db 15, 223, 128
db 15, 239, 64
db 15, 240, 192
db 15, 255, 192
db 13, 255, 192
db 10, 255, 192
db 13, 255, 128
db 15, 255, 0
db 0, 0, 0
db 0, 0, 0

; block at pixel position (0,32):

db 0, 0, 0
db 0, 0, 0
db 3, 255, 0
db 3, 127, 224
db 2, 191, 224
db 3, 127, 240
db 3, 255, 240
db 3, 252, 48
db 3, 251, 208
db 3, 247, 224
db 3, 239, 240
db 3, 238, 112
db 3, 238, 112
db 3, 239, 240
db 1, 247, 224
db 0, 251, 192

; block at pixel position (0,48):

db 0, 0, 0
db 0, 0, 0
db 0, 255, 240
db 1, 255, 176
db 3, 255, 80
db 3, 255, 176
db 3, 255, 240
db 3, 15, 240
db 2, 247, 240
db 1, 251, 240
db 3, 253, 240
db 3, 157, 240
db 3, 157, 224
db 3, 253, 224
db 1, 251, 224
db 0, 247, 128
	;
hardasteroidgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 119, 246, 0
db 231, 167, 0
db 215, 87, 0
db 0, 0, 0
db 255, 127, 0
db 250, 122, 0
db 245, 117, 0
db 0, 0, 0
db 247, 247, 0
db 231, 167, 0
db 215, 87, 0
db 0, 0, 0
db 255, 127, 0
db 250, 117, 0
db 117, 106, 0
db 0, 0, 0

; block at pixel position (0,16):

db 29, 253, 128
db 57, 233, 192
db 53, 213, 192
db 0, 0, 0
db 63, 223, 192
db 62, 158, 128
db 61, 93, 64
db 0, 0, 0
db 61, 253, 192
db 57, 233, 192
db 53, 213, 192
db 0, 0, 0
db 63, 223, 192
db 62, 157, 64
db 29, 90, 128
db 0, 0, 0

; block at pixel position (0,32):

db 7, 127, 96
db 14, 122, 112
db 13, 117, 112
db 0, 0, 0
db 15, 247, 240
db 15, 167, 160
db 15, 87, 80
db 0, 0, 0
db 15, 127, 112
db 14, 122, 112
db 13, 117, 112
db 0, 0, 0
db 15, 247, 240
db 15, 167, 80
db 7, 86, 160
db 0, 0, 0

; block at pixel position (0,48):

db 1, 223, 216
db 3, 158, 156
db 3, 93, 92
db 0, 0, 0
db 3, 253, 252
db 3, 233, 232
db 3, 213, 212
db 0, 0, 0
db 3, 223, 220
db 3, 158, 156
db 3, 93, 92
db 0, 0, 0
db 3, 253, 252
db 3, 233, 212
db 1, 213, 168
db 0, 0, 0
	;
rhinotankgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 63, 252, 0
db 111, 254, 0
db 87, 246, 0
db 111, 234, 0
db 127, 246, 0
db 127, 254, 0
db 0, 0, 0
db 255, 255, 0
db 0, 0, 0
db 57, 156, 0
db 58, 92, 0
db 58, 92, 0
db 56, 28, 0
db 56, 28, 0
db 16, 8, 0
db 16, 8, 0

; block at pixel position (0,16):

db 15, 255, 0
db 27, 255, 128
db 21, 253, 128
db 27, 250, 128
db 31, 253, 128
db 31, 255, 128
db 0, 0, 0
db 63, 255, 192
db 0, 0, 0
db 14, 103, 0
db 14, 103, 0
db 14, 151, 0
db 14, 7, 0
db 14, 7, 0
db 4, 2, 0
db 4, 2, 0

; block at pixel position (0,32):

db 3, 255, 192
db 7, 255, 96
db 6, 254, 160
db 5, 127, 96
db 6, 255, 224
db 7, 255, 224
db 0, 0, 0
db 15, 255, 240
db 0, 0, 0
db 3, 153, 192
db 3, 153, 192
db 3, 153, 192
db 3, 129, 192
db 3, 129, 192
db 1, 0, 128
db 1, 0, 128

; block at pixel position (0,48):

db 0, 255, 240
db 1, 191, 248
db 1, 95, 216
db 1, 191, 168
db 1, 255, 216
db 1, 255, 168
db 0, 0, 0
db 3, 255, 252
db 0, 0, 0
db 0, 230, 112
db 0, 230, 112
db 0, 233, 112
db 0, 224, 112
db 0, 224, 112
db 0, 64, 32
db 0, 64, 32
tutankgraphic:
	;
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 121, 158, 0
db 3, 192, 0
db 251, 223, 0
db 3, 192, 0
db 251, 223, 0
db 3, 192, 0
db 251, 223, 0
db 3, 192, 0
db 123, 222, 0
db 3, 192, 0
db 59, 220, 0
db 3, 192, 0
db 27, 216, 0
db 3, 192, 0
db 11, 208, 0
db 1, 128, 0

; block at pixel position (0,16):

db 30, 103, 128
db 0, 240, 0
db 62, 247, 192
db 0, 240, 0
db 62, 247, 192
db 0, 240, 0
db 62, 247, 192
db 0, 240, 0
db 30, 247, 128
db 0, 240, 0
db 14, 247, 0
db 0, 240, 0
db 6, 246, 0
db 0, 240, 0
db 2, 244, 0
db 0, 96, 0

; block at pixel position (0,32):

db 7, 153, 224
db 0, 60, 0
db 15, 189, 240
db 0, 60, 0
db 15, 189, 240
db 0, 60, 0
db 15, 189, 240
db 0, 60, 0
db 7, 189, 224
db 0, 60, 0
db 3, 189, 192
db 0, 60, 0
db 1, 189, 128
db 0, 60, 0
db 0, 189, 0
db 0, 24, 0

; block at pixel position (0,48):

db 1, 230, 120
db 0, 15, 0
db 3, 239, 124
db 0, 15, 0
db 3, 239, 124
db 0, 15, 0
db 3, 239, 124
db 0, 15, 0
db 1, 239, 120
db 0, 15, 0
db 0, 239, 112
db 0, 15, 0
db 0, 111, 96
db 0, 15, 0
db 0, 47, 64
db 0, 6, 0
	;
trilobitegraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 1, 128, 0
db 27, 216, 0
db 123, 222, 0
db 0, 0, 0
db 251, 223, 0
db 0, 0, 0
db 251, 223, 0
db 248, 31, 0
db 3, 192, 0
db 248, 31, 0
db 3, 192, 0
db 248, 31, 0
db 251, 223, 0
db 119, 238, 0
db 119, 174, 0
db 27, 216, 0

; block at pixel position (0,16):

db 0, 96, 0
db 6, 246, 0
db 30, 247, 128
db 0, 0, 0
db 62, 247, 192
db 0, 0, 0
db 62, 247, 192
db 62, 7, 192
db 0, 240, 0
db 62, 7, 192
db 0, 240, 0
db 62, 7, 192
db 62, 247, 192
db 29, 251, 128
db 29, 235, 128
db 6, 246, 0

; block at pixel position (0,32):

db 0, 24, 0
db 1, 189, 128
db 7, 189, 224
db 0, 0, 0
db 15, 189, 240
db 0, 0, 0
db 15, 189, 240
db 15, 129, 240
db 0, 60, 0
db 15, 129, 240
db 0, 60, 0
db 15, 129, 240
db 15, 189, 240
db 7, 126, 224
db 7, 122, 224
db 1, 189, 128

; block at pixel position (0,48):

db 0, 6, 0
db 0, 111, 96
db 1, 239, 120
db 0, 0, 0
db 3, 239, 124
db 0, 0, 0
db 3, 239, 124
db 3, 224, 124
db 0, 15, 0
db 3, 224, 124
db 0, 15, 0
db 3, 224, 124
db 3, 239, 124
db 1, 223, 184
db 1, 222, 184
db 0, 111, 96
	;
explodegraphic: 
db 0, 0, 0
db 0, 0, 0
db 0, 238, 192
db 1, 225, 224
db 0, 158, 224
db 2, 127, 96
db 3, 190, 160
db 3, 189, 192
db 1, 125, 128
db 0, 126, 96
db 0, 159, 32
db 0, 232, 192
db 0, 245, 224
db 0, 110, 224
db 0, 12, 192
db 0, 0, 0

; block at pixel position (0,16):

db 0, 0, 0
db 3, 12, 0
db 7, 32, 24
db 0, 81, 204
db 0, 115, 76
db 4, 96, 192
db 14, 6, 192
db 12, 10, 0
db 12, 6, 0
db 0, 224, 204
db 0, 243, 204
db 0, 167, 64
db 28, 99, 156
db 22, 0, 56
db 14, 0, 48
db 0, 0, 0

; block at pixel position (0,32):

db 0, 0, 0
db 0, 128, 8
db 0, 25, 128
db 0, 195, 192
db 17, 233, 200
db 1, 192, 0
db 0, 1, 32
db 2, 64, 33
db 34, 0, 0
db 2, 146, 192
db 0, 64, 192
db 0, 113, 200
db 2, 112, 128
db 32, 2, 0
db 0, 0, 8
db 0, 0, 0

; block at pixel position (0,48):

db 64, 24, 0
db 6, 0, 72
db 14, 0, 6
db 16, 0, 6
db 0, 62, 1
db 128, 65, 0
db 0, 85, 0
db 0, 65, 4
db 0, 34, 0
db 8, 28, 0
db 132, 0, 0
db 0, 0, 0
db 96, 0, 32
db 208, 0, 2
db 96, 64, 4
db 4, 14, 0
	;
dategraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 0, 120, 0
db 3, 174, 0
db 15, 119, 0
db 52, 239, 0
db 91, 221, 0
db 86, 181, 0
db 213, 187, 0
db 237, 119, 0
db 179, 86, 0
db 207, 86, 0
db 250, 234, 0
db 157, 212, 0
db 141, 188, 0
db 78, 72, 0
db 57, 176, 0
db 15, 192, 0

; block at pixel position (0,16):

db 0, 30, 0
db 0, 235, 128
db 3, 221, 192
db 13, 59, 192
db 22, 247, 64
db 21, 173, 64
db 53, 110, 192
db 59, 93, 192
db 44, 213, 128
db 51, 213, 128
db 62, 186, 128
db 39, 117, 0
db 35, 111, 0
db 19, 146, 0
db 14, 108, 0
db 3, 240, 0

; block at pixel position (0,32):

db 0, 7, 128
db 0, 58, 224
db 0, 247, 112
db 3, 78, 240
db 5, 189, 208
db 5, 107, 80
db 13, 91, 176
db 14, 215, 112
db 11, 53, 96
db 12, 245, 96
db 15, 174, 160
db 9, 221, 64
db 8, 219, 192
db 4, 228, 128
db 3, 155, 0
db 0, 252, 0

; block at pixel position (0,48):

db 0, 1, 224
db 0, 14, 184
db 0, 61, 220
db 0, 211, 188
db 1, 111, 116
db 1, 90, 212
db 3, 86, 236
db 3, 181, 220
db 2, 205, 88
db 3, 61, 88
db 3, 235, 168
db 2, 119, 80
db 2, 54, 240
db 1, 57, 32
db 0, 230, 192
db 0, 63, 0
sproutgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 13, 180, 0
db 61, 118, 0
db 94, 238, 0
db 110, 223, 0
db 245, 188, 0
db 123, 187, 0
db 187, 181, 0
db 91, 182, 0
db 237, 175, 0
db 245, 222, 0
db 117, 220, 0
db 123, 218, 0
db 29, 52, 0
db 18, 204, 0
db 13, 112, 0
db 6, 192, 0

; block at pixel position (0,16):

db 3, 109, 0
db 15, 93, 128
db 23, 187, 128
db 27, 183, 192
db 61, 111, 0
db 30, 238, 192
db 46, 237, 64
db 22, 237, 128
db 59, 107, 192
db 61, 119, 128
db 29, 119, 0
db 30, 246, 128
db 7, 77, 0
db 4, 179, 0
db 3, 92, 0
db 1, 176, 0

; block at pixel position (0,32):

db 0, 219, 64
db 3, 215, 96
db 5, 238, 224
db 6, 237, 240
db 15, 91, 192
db 7, 187, 176
db 11, 187, 80
db 5, 187, 96
db 14, 218, 240
db 15, 93, 224
db 7, 93, 192
db 7, 189, 160
db 1, 211, 64
db 1, 44, 192
db 0, 215, 0
db 0, 108, 0

; block at pixel position (0,48):

db 0, 54, 208
db 0, 245, 216
db 1, 123, 184
db 1, 187, 124
db 3, 214, 240
db 1, 238, 236
db 2, 238, 212
db 1, 110, 216
db 3, 182, 188
db 3, 215, 120
db 1, 215, 112
db 1, 239, 104
db 0, 116, 208
db 0, 75, 48
db 0, 53, 192
db 0, 27, 0
presentgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 56, 28, 0
db 69, 162, 0
db 63, 252, 0
db 1, 128, 0
db 254, 127, 0
db 254, 127, 0
db 254, 125, 0
db 254, 122, 0
db 254, 117, 0
db 0, 0, 0
db 0, 0, 0
db 126, 126, 0
db 126, 126, 0
db 126, 116, 0
db 126, 122, 0
db 62, 116, 0

; block at pixel position (0,16):

db 14, 7, 0
db 17, 104, 128
db 15, 255, 0
db 0, 96, 0
db 63, 159, 192
db 63, 159, 192
db 63, 159, 64
db 63, 158, 128
db 63, 157, 64
db 0, 0, 0
db 0, 0, 0
db 31, 159, 128
db 31, 159, 128
db 31, 157, 0
db 31, 158, 128
db 15, 157, 0

; block at pixel position (0,32):

db 3, 129, 192
db 4, 90, 32
db 3, 255, 192
db 0, 24, 0
db 15, 231, 240
db 15, 231, 240
db 15, 231, 208
db 15, 231, 160
db 15, 231, 80
db 0, 0, 0
db 0, 0, 0
db 7, 231, 224
db 7, 231, 224
db 7, 231, 64
db 7, 231, 160
db 3, 231, 64

; block at pixel position (0,48):

db 0, 224, 112
db 1, 22, 136
db 0, 255, 240
db 0, 6, 0
db 3, 249, 252
db 3, 249, 252
db 3, 249, 244
db 3, 249, 232
db 3, 249, 212
db 0, 0, 0
db 0, 0, 0
db 1, 249, 248
db 1, 249, 248
db 1, 249, 208
db 1, 249, 232
db 0, 249, 208
baublegraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 3, 192, 0
db 4, 32, 0
db 3, 192, 0
db 0, 0, 0
db 7, 224, 0
db 0, 0, 0
db 31, 248, 0
db 127, 254, 0
db 87, 254, 0
db 255, 255, 0
db 215, 254, 0
db 215, 253, 0
db 255, 254, 0
db 255, 253, 0
db 127, 250, 0
db 63, 212, 0

; block at pixel position (0,16):

db 0, 240, 0
db 1, 8, 0
db 0, 240, 0
db 0, 0, 0
db 1, 248, 0
db 0, 0, 0
db 7, 254, 0
db 31, 255, 128
db 21, 255, 128
db 63, 255, 192
db 53, 255, 128
db 53, 255, 64
db 63, 255, 128
db 63, 255, 64
db 31, 254, 128
db 15, 245, 0

; block at pixel position (0,32):

db 0, 60, 0
db 0, 66, 0
db 0, 60, 0
db 0, 0, 0
db 0, 126, 0
db 0, 0, 0
db 1, 255, 128
db 7, 255, 224
db 5, 127, 224
db 15, 255, 240
db 13, 127, 224
db 13, 127, 208
db 15, 255, 224
db 15, 255, 208
db 7, 255, 160
db 3, 253, 64

; block at pixel position (0,48):

db 0, 15, 0
db 0, 16, 128
db 0, 15, 0
db 0, 0, 0
db 0, 31, 128
db 0, 0, 0
db 0, 127, 224
db 1, 255, 248
db 1, 95, 248
db 3, 255, 252
db 3, 95, 248
db 3, 95, 244
db 3, 255, 248
db 3, 255, 244
db 1, 255, 232
db 0, 255, 80
	;
socksgraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 15, 254, 0
db 31, 255, 0
db 15, 254, 0
db 0, 0, 0
db 3, 252, 0
db 3, 252, 0
db 3, 244, 0
db 3, 252, 0
db 3, 244, 0
db 7, 252, 0
db 31, 244, 0
db 127, 236, 0
db 255, 212, 0
db 255, 168, 0
db 255, 216, 0
db 127, 160, 0

; block at pixel position (0,16):

db 3, 255, 128
db 7, 255, 192
db 3, 255, 128
db 0, 0, 0
db 0, 255, 0
db 0, 255, 0
db 0, 253, 0
db 0, 255, 0
db 0, 253, 0
db 1, 255, 0
db 7, 253, 0
db 31, 251, 0
db 63, 245, 0
db 63, 234, 0
db 63, 246, 0
db 31, 232, 0

; block at pixel position (0,32):

db 0, 255, 224
db 1, 255, 240
db 0, 255, 224
db 0, 0, 0
db 0, 63, 192
db 0, 63, 192
db 0, 63, 64
db 0, 63, 192
db 0, 63, 64
db 0, 127, 192
db 1, 255, 64
db 7, 254, 192
db 15, 253, 64
db 15, 250, 128
db 15, 253, 128
db 7, 250, 0

; block at pixel position (0,48):

db 0, 63, 248
db 0, 127, 252
db 0, 63, 248
db 0, 0, 0
db 0, 15, 240
db 0, 15, 240
db 0, 15, 208
db 0, 15, 240
db 0, 15, 208
db 0, 31, 240
db 0, 127, 208
db 1, 255, 176
db 3, 255, 80
db 3, 254, 160
db 3, 255, 96
db 1, 254, 128
turkeygraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 96, 0, 0
db 224, 240, 0
db 209, 248, 0
db 59, 252, 0
db 29, 254, 0
db 14, 126, 0
db 55, 159, 0
db 123, 239, 0
db 251, 246, 0
db 249, 231, 0
db 253, 213, 0
db 253, 166, 0
db 126, 213, 0
db 126, 174, 0
db 63, 29, 0
db 15, 250, 0

; block at pixel position (0,16):

db 24, 0, 0
db 56, 60, 0
db 52, 126, 0
db 14, 255, 0
db 7, 127, 128
db 3, 159, 128
db 13, 231, 192
db 30, 251, 192
db 62, 253, 128
db 62, 121, 192
db 63, 117, 64
db 63, 105, 128
db 31, 181, 64
db 31, 171, 128
db 15, 199, 64
db 3, 254, 128

; block at pixel position (0,32):

db 6, 0, 0
db 14, 15, 0
db 13, 31, 128
db 3, 191, 192
db 1, 223, 224
db 0, 231, 224
db 3, 121, 240
db 7, 190, 240
db 15, 191, 96
db 15, 158, 112
db 15, 221, 80
db 15, 218, 96
db 7, 237, 80
db 7, 234, 224
db 3, 241, 208
db 0, 255, 160

; block at pixel position (0,48):

db 1, 128, 0
db 3, 131, 192
db 3, 71, 224
db 0, 239, 240
db 0, 119, 248
db 0, 57, 248
db 0, 222, 124
db 1, 239, 188
db 3, 239, 216
db 3, 231, 156
db 3, 247, 84
db 3, 246, 152
db 1, 251, 84
db 1, 250, 184
db 0, 252, 116
db 0, 63, 232
	;
orangegraphic:
; ASM data file from a ZX-Paintbrush picture with 24 x 64 pixels (= 3 x 8 characters)

; block based output of pixel data - each block contains 24 x 16 pixels

; block at pixel position (0,0):

db 3, 192, 0
db 14, 112, 0
db 28, 56, 0
db 62, 124, 0
db 127, 254, 0
db 127, 246, 0
db 255, 255, 0
db 255, 251, 0
db 255, 245, 0
db 255, 187, 0
db 127, 246, 0
db 127, 234, 0
db 63, 212, 0
db 31, 168, 0
db 15, 240, 0
db 3, 192, 0

; block at pixel position (0,16):

db 0, 240, 0
db 3, 156, 0
db 7, 14, 0
db 15, 159, 0
db 31, 255, 128
db 31, 253, 128
db 63, 255, 192
db 63, 254, 192
db 63, 253, 64
db 63, 238, 192
db 31, 253, 128
db 31, 250, 128
db 15, 245, 0
db 7, 234, 0
db 3, 252, 0
db 0, 240, 0

; block at pixel position (0,32):

db 0, 60, 0
db 0, 231, 0
db 1, 195, 128
db 3, 231, 192
db 7, 255, 224
db 7, 255, 96
db 15, 255, 240
db 15, 255, 176
db 15, 255, 80
db 15, 251, 176
db 7, 255, 96
db 7, 254, 160
db 3, 253, 64
db 1, 250, 128
db 0, 255, 0
db 0, 60, 0

; block at pixel position (0,48):

db 0, 15, 0
db 0, 57, 192
db 0, 112, 224
db 0, 249, 240
db 1, 255, 248
db 1, 255, 216
db 3, 255, 252
db 3, 255, 236
db 3, 255, 212
db 3, 254, 236
db 1, 255, 216
db 1, 255, 168
db 0, 255, 80
db 0, 126, 160
db 0, 63, 192
db 0, 15, 0
	;
font:	;custom font, designed in ZX-Paint on 16/10/15
db	0,0,0,0,0,0,0,0
db 60, 60, 60, 60, 60, 0, 60, 0
db 108, 108, 108, 72, 0, 0, 0, 0
db 100, 254, 100, 100, 100, 254, 100, 0
db 0, 6, 70, 56, 40, 40, 40, 0
db 226, 164, 232, 16, 46, 74, 142, 0
db 56, 116, 56, 124, 242, 244, 122, 0
db 28, 12, 12, 16, 0, 0, 0, 0
db 56, 48, 48, 48, 48, 48, 56, 0
db 28, 12, 12, 12, 12, 12, 28, 0
db 0, 84, 56, 124, 56, 84, 0, 0
db 0, 48, 48, 252, 252, 48, 48, 0
db 0, 0, 0, 0, 24, 24, 24, 48
db 0, 0, 0, 124, 124, 0, 0, 0
db 0, 0, 0, 0, 0, 48, 48, 0
db 0, 6, 12, 24, 48, 96, 192, 0
db 254, 230, 226, 226, 226, 242, 254, 0
db 60, 28, 28, 28, 28, 28, 62, 0
db 254, 14, 14, 254, 224, 224, 254, 0
db 254, 14, 62, 14, 14, 14, 254, 0
db 228, 228, 228, 228, 254, 4, 4, 0
db 254, 224, 254, 14, 14, 14, 254, 0
db 224, 224, 224, 254, 230, 230, 254, 0
db 254, 14, 14, 14, 14, 14, 14, 0
db 254, 226, 254, 226, 226, 226, 254, 0
db 254, 142, 142, 254, 14, 14, 14, 0
db 0, 24, 24, 0, 24, 24, 0, 0
db 0, 24, 24, 0, 24, 24, 48, 0
db 0, 12, 24, 48, 24, 12, 0, 0
db 0, 0, 60, 0, 0, 60, 0, 0
db 0, 48, 24, 12, 24, 48, 0, 0
db 254, 142, 14, 62, 56, 0, 56, 0
db 0, 78, 164, 228, 164, 164, 0, 0
db 254, 230, 230, 254, 230, 230, 230, 0
db 254, 226, 252, 226, 226, 226, 254, 0
db 254, 224, 224, 224, 224, 224, 254, 0
db 252, 226, 226, 226, 226, 226, 252, 0
db 254, 224, 248, 224, 224, 224, 254, 0
db 254, 224, 248, 224, 224, 224, 224, 0
db 254, 224, 224, 238, 230, 230, 254, 0
db 226, 226, 226, 254, 226, 226, 226, 0
db 60, 0, 60, 60, 60, 60, 126, 0
db 254, 14, 14, 142, 142, 142, 254, 0
db 230, 230, 230, 252, 230, 230, 230, 0
db 224, 224, 224, 224, 224, 224, 254, 0
db 254, 234, 234, 234, 226, 226, 226, 0
db 254, 226, 226, 226, 226, 226, 226, 0
db 254, 226, 226, 226, 226, 226, 254, 0
db 254, 226, 226, 254, 224, 224, 224, 0
db 254, 226, 226, 226, 226, 231, 255, 7
db 252, 230, 230, 252, 230, 230, 230, 0
db 254, 224, 224, 254, 14, 14, 254, 0
db 254, 56, 56, 56, 56, 56, 56, 0
db 226, 226, 226, 226, 226, 226, 254, 0
db 238, 238, 238, 238, 254, 124, 16, 0
db 198, 198, 214, 214, 214, 254, 108, 0
db 230, 230, 230, 24, 230, 230, 230, 0
db 226, 226, 226, 254, 56, 56, 56, 0
db 254, 14, 14, 254, 224, 224, 254, 0
;
db 32, 2, 39, 36, 100, 206, 175, 103	;player ship CHR$ 91
db 4, 64, 228, 36, 38, 115, 245, 230
db 237, 204, 165, 108, 229, 68, 39, 1
db 183, 51, 165, 54, 167, 34, 228, 128
	;
	db	28, 99, 68, 43, 23, 23, 111, 15	;snowman CHRS 120
	db	60, 192, 60, 255, 251, 158, 158, 254
	db	0, 0, 0, 0, 0, 248, 253, 210
		;
	db 15, 15, 7, 11, 7, 11, 12, 31
	db 255, 127, 245, 223, 254, 253, 3, 255
	db 0, 128, 128, 0, 0, 128, 192, 224
		;
	db 23, 11, 21, 43, 109, 118, 251, 188
	db 249, 249, 255, 255, 255, 191, 255, 0
	db 224, 224, 224, 232, 216, 222, 63, 255
		;
	db 95, 183, 95, 171, 222, 107, 53, 10
	db 255, 252, 252, 255, 255, 255, 255, 191
	db 255, 255, 255, 254, 254, 252, 248, 224
	;
	defb 28, 99, 68, 43, 23, 23, 111, 15
	defb 60, 192, 60, 255, 251, 158, 158, 254
	defb 0, 0, 0, 0, 0, 248, 253, 210
	;
db 0, 0, 14, 14, 0, 0, 0, 0	;robin CHRS 109
db 127, 241, 226, 224, 241, 255, 255, 255
db 128, 224, 240, 248, 252, 254, 222, 190
;
db 0, 0, 1, 1, 1, 0, 0, 0
db 1, 254, 254, 254, 254, 254, 254, 62
db 191, 186, 189, 186, 221, 234, 241, 254
;
db 0, 0, 0, 0, 0, 1, 7, 127
db 2, 2, 2, 11, 0, 255, 255, 255
db 16, 16, 16, 120, 0, 252, 234, 213
	;
db 127, 255, 255, 238, 241, 255, 255, 255	;robin blink
	;
defb 239, 140, 140, 143, 131, 131, 239, 0	;caps shift CHRS
defb 238, 137, 201, 137, 224, 15, 6, 6		;enter
defb 239, 137, 239, 40, 224, 15, 8, 15		;space
defb 238, 136, 136, 238, 34, 34, 238, 0		;symb shift
	;
db 0, 0, 0, 189, 126, 60, 66, 36		;jumping homunculous CHRS 123
db 0, 0, 60, 60, 255, 60, 36, 36
db 0, 60, 60, 126, 189, 36, 36, 0
db 60, 60, 126, 126, 36, 24, 0, 0
fend:
	;
sectordude:	;8x8 chars for tv image guy
db	0,0,0,0,0,0,0,0
;
db 0, 0, 0, 1, 1, 0, 0, 0
;
db 0, 0, 1, 1, 1, 3, 0, 0
;8x8 char
db 1, 2, 2, 2, 1, 3, 7, 7
;8x8 char
db 7, 8, 10, 5, 2, 7, 15, 15
;start of tile
db 7, 9, 24, 24, 31, 16, 48, 47
db 240, 200, 12, 12, 124, 132, 134, 122
db 32, 20, 9, 12, 7, 2, 126, 255
db 130, 20, 200, 24, 240, 32, 62, 255
;
db 0, 15, 51, 64, 192, 192, 220, 128
db 0, 240, 204, 2, 3, 3, 59, 1
;line 2
db 0, 0, 3, 2, 2, 1, 0, 0
db 188, 194, 195, 66, 188, 128, 193, 160
db 61, 67, 195, 66, 61, 1, 131, 5
db 0, 0, 128, 64, 64, 128, 0, 0
;
db 0, 0, 0, 0, 0, 0, 0, 3
db 208, 99, 48, 17, 14, 16, 240, 255
db 11, 198, 12, 136, 112, 8, 15, 255
db 0, 0, 0, 0, 0, 0, 0, 192
;third biggest
db 0, 0, 0, 0, 1, 1, 3, 3
db 0, 31, 119, 195, 0, 0, 0, 0
db 0, 252, 247, 225, 0, 0, 0, 0
db 0, 0, 0, 128, 64, 64, 96, 96
;
db 3, 3, 3, 2, 7, 5, 4, 4
db 60, 2, 124, 130, 1, 1, 130, 124
db 30, 32, 31, 32, 192, 192, 32, 31
db 96, 96, 96, 160, 112, 80, 144, 16
;
db 3, 1, 1, 1, 1, 0, 0, 0
db 0, 129, 64, 160, 67, 160, 81, 60
db 0, 192, 1, 2, 225, 2, 197, 158
db 96, 192, 64, 192, 64, 128, 0, 0
;
db 0, 0, 3, 15, 31, 63, 0, 0
db 19, 32, 242, 241, 252, 255, 0, 0
db 228, 2, 7, 7, 31, 255, 0, 0
db 0, 0, 224, 248, 252, 254, 0, 0
;biggest image
db 0, 0, 0, 0, 1, 7, 14, 12
db 0, 0, 0, 127, 143, 7, 0, 0
db 0, 0, 0, 254, 241, 224, 0, 0
db 0, 0, 0, 0, 128, 224, 112, 48
;
db 28, 24, 56, 56, 49, 115, 112, 115
db 0, 0, 0, 0, 240, 248, 4, 248
db 0, 0, 0, 0, 15, 31, 32, 31
db 56, 24, 28, 28, 140, 206, 14, 206
;
db 0, 0, 1, 1, 0, 1, 0, 0
db 52, 184, 120, 24, 144, 84, 147, 184
db 4, 2, 3, 2, 2, 4, 248, 0
db 32, 64, 192, 64, 64, 32, 31, 0
db 44, 29, 30, 24, 11, 42, 201, 29
db 0, 0, 128, 128, 0, 128, 0, 0
;
db 92, 30, 15, 15, 7, 6, 3, 1
db 3, 1, 64, 160, 71, 160, 65, 160
db 192, 128, 2, 5, 226, 5, 130, 5
db 58, 120, 240, 240, 224, 96, 192, 128
;
db 0, 0, 0, 0, 1, 3, 7, 7
db 0, 1, 1, 63, 255, 255, 255, 255
db 240, 15, 0, 130, 193, 224, 255, 255
db 15, 240, 0, 65, 131, 7, 255, 255
db 0, 128, 128, 252, 255, 255, 255, 255
db 0, 0, 0, 0, 128, 192, 224, 224
;extras
db 0, 0, 0, 128, 128, 0, 0, 0
db 0, 0, 128, 128, 128, 192, 0, 0
db 128, 64, 64, 64, 128, 192, 224, 224
db 224, 16, 80, 160, 64, 224, 240, 240
;open mouth
db 3, 1, 64, 160, 67, 167, 67, 160
db 192, 128, 2, 5, 194, 229, 194, 5
;
tvmap:
db	00,00,00,00,00,00
db	00,00,00,00,00,00
db	00,00,01,59,00,00
db	00,00,00,00,00,00
db	00,00,00,00,00,00
;
db	00,00,00,00,00,00
db	00,00,00,00,00,00
db	00,00,02,60,00,00
db	00,00,00,00,00,00
db	00,00,00,00,00,00
;
db	00,00,00,00,00,00
db	00,00,00,00,00,00
db	00,00,03,61,00,00
db	00,00,00,00,00,00
db	00,00,00,00,00,00
;
db	00,00,00,00,00,00
db	00,00,00,00,00,00
db	00,00,04,62,00,00
db	00,00,00,00,00,00
db	00,00,00,00,00,00
;
db	00,00,00,00,00,00
db	00,00,00,00,00,00
db	00,00,05,06,00,00
db	00,00,07,08,00,00
db	00,00,00,00,00,00
;
db	00,00,00,00,00,00
db	00,00,09,10,00,00
db	00,11,12,13,14,00
db	00,15,16,17,18,00
db	00,00,00,00,00,00
;
db	00,00,00,00,00,00
db	00,19,20,21,22,00
db	00,23,24,25,26,00
db	00,27,28,29,30,00
db	00,31,32,33,34,00
;
db	00,35,36,37,38,00
db	00,39,40,41,42,00
db	43,44,45,46,47,48
db	00,49,50,51,52,00
db	53,54,55,56,57,58
	;
speaktv:
db	00,35,36,37,38,00
db	00,39,40,41,42,00
db	43,44,45,46,47,48
db	00,49,63,64,52,00
db	53,54,55,56,57,58
	;
tvnoise:ld b,50
tvnalp:	push bc
	halt
	call dotvn
	pop bc
	djnz tvnalp
	ret
dotvn:	;do tv noise
	call rnd
	ld a,h
	and 31
	ld h,a
	ld de,tvpos
	ld a,5*8
tvnlp:	push af
	push de
	ld bc,6
	ldir
	ld a,(hl)
	and 248
	out (254),a
	pop de
	call nextlinedown
	pop af
	dec a
	jr nz,tvnlp
	ret
	;
tvanimate:
	call tvnoise
	xor a
tvlp1:	push af
	ld b,6
	call haltdelay
	call printtv
	pop af
	inc a
	cp 8
	jr c,tvlp1
	call haltdelay0
	ld a,8
	call printtv
	call AYoff
	call go
	call ifAYon
	ld a,7
tvlp2:	push af
	ld b,6
	call haltdelay
	call printtv
	pop af
	dec a
	cp 255
	jr nz,tvlp2
blacktv:
	ld de,tvpos
	call screen2att
	ld de,32-6
	xor a
	ld c,5
dtlp0:	ld b,6
dtlp:	ld (hl),a
	inc l
	djnz dtlp
	add hl,de
	dec c
	jr nz,dtlp0
	ret
printtv:		;arrive with A holding TV frame 0-7, prints corresponding TV frame
	ld h,0
	ld l,a
	add hl,hl	;x2
	ld d,h
	ld e,l
	add hl,hl
	add hl,hl
	add hl,hl
	add hl,hl	;x32
	xor a
	sbc hl,de
	ld de,tvmap
	add hl,de	;hl pointing at correct map
	push hl
	pop ix		;now IX is
	ld de,tvpos	;DE at screen
	ld c,5
tvlp0:	push bc
	ld b,6
	push de
tvlp:	push bc
	push de
	ld a,(ix+0)
	inc ix
	ld bc,sectordude
	call gcent	;point HL at graphic
	call print_char
	dec d
	call screen2att
	ld (hl),56
	pop de
	pop bc
	inc e
	djnz tvlp
	pop de
	call rowdown
	pop bc
	dec c
	jr nz,tvlp0
	ret
;
panelmap:
	db	00,00,01,02,02,03,00,00
	db	04,05,05,05,05,05,05,06
	db	07,00,08,09,10,11,00,12
	db	07,00,00,00,00,00,00,12
	db	13,14,14,14,14,14,14,15
	db	00,00,16,00,00,16,00,00
	db	04,05,05,05,05,05,05,06
	db	07,00,00,00,00,00,00,12
	db	07,00,00,00,00,00,00,12
	db	07,00,00,00,00,00,00,12
	db	07,00,00,00,00,00,00,12
	db	07,00,00,00,00,00,00,12
	db	13,14,14,14,14,14,14,15
	db	00,00,16,00,00,16,00,00
	db	04,05,05,05,05,05,05,06
	db	07,00,17,18,19,20,00,12
	db	07,00,00,00,00,00,00,12	
	db	13,14,14,14,14,14,14,15
	db	00,00,16,00,00,16,00,00
	db	04,05,05,05,05,05,05,06
	db	07,00,24,25,26,27,00,12
	db	13,14,14,14,14,14,14,15
	db	00,00,21,22,22,23,00,00
	db	00,00,00,00,00,00,00,00,255
	;
blocks:	
; ASM data file from a ZX-Paintbrush picture with 192 x 8 pixels (= 24 x 1 characters)
; and an attribute area of 24 bytes

; block based output of pixel data - each block contains 8 x 8 pixels

; blocks at pixel positionn (y=0):

db 0, 0, 0, 0, 0, 0, 0, 0
db 7
db 14, 30, 62, 60, 0, 60, 60, 0
db 71
db 238, 238, 238, 0, 0, 0, 0, 0
db 7
db 224, 240, 248, 120, 0, 120, 120, 0
db 7
db 7, 63, 127, 127, 127, 255, 255, 254
db 65
db 255, 255, 255, 255, 255, 255, 255, 0
db 65
db 224, 252, 254, 254, 254, 255, 255, 127
db 65
db 254, 254, 254, 254, 254, 254, 254, 254
db 65
db 0, 125, 97, 125, 29, 125, 0, 0
db 70
db 0, 247, 134, 134, 134, 247, 0, 0
db 70
db 0, 239, 105, 111, 105, 233, 0, 0
db 70
db 0, 190, 176, 60, 176, 190, 0, 0
db 70
db 127, 127, 127, 127, 127, 127, 127, 127
db 1
db 254, 255, 255, 127, 127, 127, 63, 7
db 1
db 0, 255, 255, 255, 255, 255, 255, 255
db 1
db 127, 255, 255, 254, 254, 254, 252, 224
db 1
db 0, 60, 0, 60, 60, 0, 60, 0
db 7
db 24, 24, 24, 24, 31, 0, 0, 0
db 70
db 118, 6, 118, 114, 113, 0, 0, 0
db 70
db 223, 216, 220, 152, 31, 0, 0, 0
db 70
db 124, 96, 124, 12, 124, 0, 0, 0
db 70
db 0, 60, 60, 0, 60, 62, 30, 14
db 7
db 0, 0, 0, 0, 0, 238, 238, 238
db 7
db 0, 120, 120, 0, 120, 248, 240, 224
db 7
	;
db 0, 0, 0, 0, 0, 0, 0, 0	;blaster colours
db 2
db 0, 0, 0, 0, 0, 0, 0, 0
db 66
db 0, 0, 0, 0, 0, 0, 0, 0
db 70
db 0, 0, 0, 0, 0, 0, 0, 0
db 71
	;
verybigstring:	
	ld a,(ix+0)
	inc ix
	or a
	ret z
	call get_char
	push de
	call very_bigchar
	pop de
	ld a,e
	add a,4
	ld e,a
	jr verybigstring
	;
very_bigchar:	;HL at graphic, DE at screen
	ld a,4
vblp1	push af
	ld b,(hl)
	inc hl
	ld c,(hl)
	inc hl
	push de
	ld a,4
vblp	push af
	push de
	xor a
	rl b
	jr nc,miss0
	or $F0
miss0	rl b
	jr nc,miss1
	or $0F
miss1	call half_char
	xor a
	rl c
	jr nc,miss2
	or $F0
miss2	rl c
	jr nc,miss3
	or $0F
miss3	call half_char
	pop de
	inc e
	pop af
	dec a
	jr nz,vblp
	pop de
	call rowdown
	pop af
	dec a
	jr nz,vblp1
	ret
	;
half_char:
	ld (de),a
	inc d
	ld (de),a
	inc d
	ld (de),a
	inc d
	ld (de),a
	call nextlinedown
	ret
	;
print_string:			;arrive with IX pointing at string,and DE at screen (unless string sets cords)
	ld a,(ix+0)
	inc ix
	or a			;strings end in zero
	ret z
	call do_byte
	jr print_string
	;
do_byte:
	cp 32
	jr c,control_code	;0-31 reserved for control codes
	call get_char		;>32 we print a char
	push de
	call print_char
	dec d
	call screen2att
	ld a,(fontcolour)
	ld (hl),a
	pop de
	inc e
	ret nz
	ld a,d
	add a,8
	ld d,a
	ret
	;
fontcolour:	db	70
font_disp:	db	0
	;
control_code:			;perform an action
	add a,a			;byte to word
	ld h,0
	ld l,a
	ld bc,print_jp_table
	add hl,bc
	ld a,(hl)
	inc hl
	ld h,(hl)
	ld l,a
	jp (hl)
	;
print_jp_table:
	dw	dnth
	dw	pratt		;print at 1,y,x
	dw	setfontcolour	;2,ATTR
	dw	setdisplacement	;3,disp
	dw	rowdowndisp	;4
	dw	zap	;5
	;
pratt:
	ld h,(ix+0)	;ycor
	ld l,(ix+1)	;xcor
	inc ix
	inc ix
	call xy2cell	;point DE at scadd
	ret
	;
setfontcolour:
	ld a,(ix+0)
	inc ix
	ld (fontcolour),a
	ret
	;
setdisplacement:
	ld a,(ix+0)
	ld (font_disp),a
	inc ix
	ret
	;
rowdowndisp:
	call rowdown
	ld hl,font_disp
	ld a,e
	and 224
	or (hl)
	ld e,a
	ret
	;
xy2cell:	;H=ycor 0-23 L = column 0-31,points DE at char aligned cell on screen, used in ASCII print routine
	ld a,h
	rrca
	rrca
	rrca
	and 224
	or l
	ld e,a
	ld a,h
	and 24
	or 64
	ld d,a
	ret
	;
beepnoise:
	ld b,0
	ld c,0
	ld a,24
bnlp	out (254),a
	inc c
	jr nz,bnlp
	xor 24
	djnz bnlp
	xor a
	out (254),a
	ret
	;
badnoise:
	ld b,8
	ld c,0
	ld a,26
bdnlp	out (254),a
	inc c
	jr nz,bdnlp
	xor 26
	djnz bdnlp
	xor a
	out (254),a
	ret
	;
collectedsound:
	ld h,0
	ld b,0
pblp0:	ld c,10
pblp:	ld a,h
	and 248
	out (254),a
	dec c
	jr nz,pblp
	inc h
	djnz pblp0
	ret
	;
print_panel:
	ld ix,panelmap
	ld de,16384+24
pplp:	ld a,(ix+0)
	cp 255
	ret z
	inc ix
	push de
	call get_block
	call print_char
	dec d
	ld c,(hl)
	call screen2att
	ld (hl),c
	pop de
	inc e
	call z,segdown
	ld a,e
	and 31
	jr nz,pplp
	ld a,e
	or 24
	ld e,a
	jr pplp
	;
rowdown:
	ld a,e
	add a,32
	ld e,a
	ret nc
segdown:
	ld a,d
	add a,8
	ld d,a
	ret
	;
creditscreen:
	call no_key
	xor a
	out (254),a
	call cls
	call paperfill
	ld ix,creditstring
	call print_string
credloop:
	ld b,4
	call haltdelay
	ld a,(crframe)
	inc a
	and 7
	ld (crframe),a		;0-7
	ld hl,crdisp
	ld d,0
	ld e,a
	add hl,de
	ld a,(hl)
	add a,124
	call get_char
	ld de,20480+96+14	;jumping man animation
	call very_bigchar
	ld a,(crframe)
	or a
	call z,plop
	xor a
	in a,(254)
	cpl
	and 31
	jr z,credloop
	ret
	;
crdisp:	db	0,1,2,3,3,2,1,0
	;
crframe:	db	7
	;
creditstring:
	db	2,96
	db	1,23,0
	db	'                                '
	db	2,70
	db	3,0
	db	1,4,0
	db	'BY DAVE HUGHES 2015.',4,4
	db	'A TANK OF THANK TO:',4,4
	db	'AY MUSIC- YERZMYEY',4
	db	'DIGISPEECH - BEEPFX',4
	db	'ZX-PAINTBRUSH',4
	db	'ZX-SPIN ASSEMBLER',4
	db	'PATRIK RAK - RND NUMBERS',4
	db	'THE SPECCY SCENE',4,4
	db	2,85+128
	db	'KEEP THE ATTRIBUTE FLASHING YO!',0
	;
introscreen:
	xor a
	out (254),a
	call cls
	call paperfill
	call print_panel
	call tv_time
	call cls_playarea
	ld a,68
	ld hl,22528
	call paperseg
	call print_panel
	ld ix,itstr0
	ld de,16384+1
	call verybigstring
	ld ix,itstr1
	ld de,16384+128
	call verybigstring
	ld ix,shstr1
	ld de,18432+64+7
	call verybigstring
	ld ix,shstr2
	ld de,18432+64+128+7
	call verybigstring
	ld ix,introstring
	call print_string
	xor a
	ld (introloopflag),a
	call chrimblast
	ld a,201
	ld (chrimblast),a
introloop:
	halt
	call introkeys
	ld hl,introcount
	inc (hl)
	ld a,(introloopflag)
	or a
	jr z,introloop
	call collectedsound
	ret
	;
introcount:
	db	0
	;
introkeys:
	ld a,247	;top keyrow
	in a,(254)
	ld b,a
	and 1
	jp z,refine_keys
	ld a,b
	and 2
	jp z,setcontrols
	ld a,b
	and 4
	ret nz
	cpl
	ld (introloopflag),a
	ret		;return and start game
	;
introloopflag:	db	0
	;
itstr0:	db	'CHRIM',0
itstr1:	db	'BLAST!',0
	;
shstr1:	db	91,92,0
shstr2:	db	93,94,0
	;
introstring:	db	2,70
		db	1,21,2,'1 - REFINE KEYS      '
		db	1,22,1,'2 - CONTROL: '
contpok:	db	'KEYBOARD'
		db	1,23,4,'3 - PLAY GAME',0
	;
keytxt:		db	'KEYBOARD'
kemstxt:	db	'KEMPSTON'
	;
refine_keys:
	call collectedsound
	call reset_lettermap
	ld ix,kdstr	;'UP'
	ld iy,key0
	ld b,numkeys
krlp:	push bc
	push ix	
	call no_key
	ld a,' '
	ld de,16384;20480+192+20;20480+64+30
	call get_char
	call print_char
	ld ix,keystring
	call print_string
	pop ix
	call print_string
	ld d,254
rrlp:	rlc d
	ld a,d
	in a,(254)
	cpl
	and 31
	jr z,rrlp
	push de
	push af
	call findletter
	ld a,(hl)
	ld (lkey+1),a
	and 127
	set 7,(hl)
	call get_char
	ld de,20480+160+22;20480+64+30
	call print_char
	pop af
	pop de	
	ld (iy+0),d
	inc iy
	ld (iy+0),a
	inc iy
	call lilplop
	pop bc
lkey:	ld a,0
	rla
	jr c,keyrepeated
	djnz krlp
	;call clseg
	ld ix,introstring
	call print_string
	ret
	;
keyrepeated:
	ld ix,krepstr
	call print_string
	call alarmplop
	call print_string
	call negplop
	jp refine_keys
	;
findletter:	;D holds port, A holds bit
	ld hl,lettermap-5
	ld bc,5
fllp0:	add hl,bc
	rrc d
	jr c,fllp0
fllp1:	rrca		;hl now pointing at correct row
	ret c
	inc hl
	jr fllp1
	;
reset_lettermap:	;unset any repeated keys from previous time
	ld hl,lettermap-1
rlp:	inc hl	
	res 7,(hl)	;unset any signed bits
	ld a,(hl)
	cp 'B'		;B is the last letter
	jr nz,rlp
	ret
	;
lettermap:
                db           120,'ZXCV'             ;120 is caps
                db           'ASDFG'
                db           'QWERT'
                db           '12345'
                db           '09876'
                db           'POIUY'
                db           121,'LKJH'               ;121 is ent
                db           122,123,'MNB'        ;122 spc, 123 ss	
	;
keystring:
	db	2,70
	db	1,21,2
	db	'PRESS KEY FOR ',0
kdstr:	db	'UP   ',0
	db	'DOWN ',0
	db	'LEFT ',0
	db	'RIGHT',0
	db	'FIRE ',0
	db	'PAUSE',0
	db	'MUSIC',0
	;
krepstr:
	db	2,70
	db	1,21,2
	db	'   '
	db	2,67+128
	db	'*KEY*REPEATED*'
	db	2,68,'     ',0
	db	2,66+128
	db	1,21,5
	db	'**TRY**AGAIN**'
	db	2,7,0
	;
;
lilplop:
	ld bc,32768
lplp:	ld a,r
	and 248
	out (254),a
	dec bc
	ld a,b
	or c
	jr nz,lplp
	ret
	;
plop:
	ld b,0
plp:	ld a,b
	and 248
	out (254),a
	djnz plp
	ret
	;
negplop:	;like lil plop but more negative sounding, and longer
	ld d,3
nplp1:	ld bc,0
nplp:	ld a,b
	and 16
	out (254),a
	dec bc
	ld a,b
	or c
	jr nz,nplp
	dec d
	jr nz,nplp1
	ret
	;
alarmplop:	;like lil plop but more negative sounding, and longer
	ld d,3
aplp1:	ld bc,0
aplp:	ld a,b
	or c
	and 16
	out (254),a
	dec bc
	ld a,b
	or c
	jr nz,aplp
	dec d
	jr nz,aplp1
	ret
	;
setcontrols:
	ld a,(introcount)
	and 7
	ret nz
	call collectedsound
	ld hl,controlbyte
	inc (hl)		;toggle bit 0
	ld a,(hl)
	rra
	jr c,setkempston
setkeys:
	ld hl,keytxt
	call movetxt		;place correct text
	ld hl,check_keys
	ld (kjp+1),hl
skc	ld ix,introstring
	call print_string
	ret
	;
setkempston:
	ld hl,kemstxt
	call movetxt
	ld hl,check_kempston
	ld (kjp+1),hl
	jr skc
	;
movetxt:
	ld de,contpok
	ld bc,8
	ldir	
	ret
	;
controlbyte:	db	0
	;	
display_levelinfo:
	call cls
	call paperfill
	call print_panel
	ld ix,levstr0
	ld de,16384+2
	call verybigstring
	ld a,(level)
	inc a
	add a,'0'
	call get_char
	ld de,16384+160+10
	call very_bigchar
	ld ix,levstr1	
	call print_string
	ld (scradd+1),de
	ld a,(level)
	ld b,a
	add a,a
	add a,a
	add a,a
	add a,b	;x9
	ld d,0
	ld e,a
	ld ix,levstrings
	add ix,de
scradd:	ld de,0
	call print_string
	call printlineofitems
	ld a,(level)
	cp easylevel
	ret c
	ld ix,warnstr
	call print_string
	ret
	;
levstr0:	db	'LEVEL',0
	;
levstr1:
		db	2,71,1,12,3
		db	'COLLECT 9 '
		db	0	
	;
levstrings:
	db	'PRESENTS',0
	db	'PUDDINGS',0
	db	'  SOCKS ',0
	db	'ORANGES ',0
	db	'BAUBLES ',0
	db	' DATES  ',0
	db	'TURKEYS ',0
	db	'SPROUTS!',0
	;
warnstr:
	db	2,2,1,22,5
	db	'SHOOT AN ITEM'
	db	1,23,5
	db	'LOSE AN ITEM!',0
	;
gameoverscr:
	call no_key
	ld a,2
	call pf2
	call print_panel
	ld ix,gstr
	ld de,16384+128+4
	call verybigstring
	ld ix,ovstr
	ld de,18432+64+4
	call verybigstring
	call AYoff
	call crash
	call ifAYon
	call any_key
	ret
	;
crash:
	ld hl,0
	ld d,1
crlp0:	ld c,d
crlp:	ld a,(hl)
	inc hl
	and 248
	out (254),a
	ld b,c
glp	djnz glp
	inc c
	jr nz,crlp
	inc d
	ld a,d
	cp 11
	jr c,crlp0
	ret
	;
gstr:	db	'XMAS',0
ovstr:	db	'OVER',0
	;
gamecompletescreen:
	call AYoff
	call AY_initiate
	call no_key
	call paperfill
	call print_panel
	call tv_time
	call cls
	ld a,68
	call pf2
	call print_panel
	ld ix,gcstr
	ld de,16384+128+4
	call verybigstring
	ld ix,cstr
	ld de,18432+64+2
	call verybigstring
	call zap
	ld b,250
	call haltdelay
	call cls_playarea
	ld b,2
	ld ix,gcstr2
gclp	push bc
	call print_string
	;inc ix
	call zap
	ld b,250
	call haltdelay
	call cls_playarea
	pop bc
	djnz gclp
	call cls
	ld a,71
	call pf2
	call snowdraw
	call print_panel
	;
gcloop:	halt
	halt
	call draw_stars
	ld ix,gcstr4
	call print_string
	ld ix,snowmanstring
	call print_string
	ld ix,robinstring
	call print_string
	call robinblink
	ld hl,robloopcount
	inc (hl)
	xor a
	in a,(254)
	cpl
	and 31
	jr z,gcloop
	ret
	;
robinblink:
	call rnd
	cp 40
	ret nc
	ld a,111
	ld (robpok),a
	ld a,(robloopcount)
	cp 10
	ret nc
	ld a,119
	ld (robpok),a
	ret
	;
robloopcount:	db	0
	;
gcstr:	db	'WELL',0
cstr:	db	'DONE!',0
	;
gcstr2:
	db	1,9,2
	db	3,2
	db	'  YOU HAVE DESTOYED',4
	db	'COUNTLESS ALIEN LIVES',4
	db	'  IN ORDER TO FILL',4
	db	'    YOUR HAMPER.',5,0
	;
gcstr3:
	db	1,9,5
	db	'NEVERMIND EH.',5,0
	;
gcstr4:
	db	1,9,5
	db	2,66,'SPE',2,70,'CCY ',2,68,'FORE',2,69,'VER!',0
	;
snowdraw:
	ld hl,23200
sdlp:	ld (hl),127
	inc l
	jr nz,sdlp
	ret
	;
snowmanstring:
	db	1,17,3
	db	3,3	;disp
	db	2,71,95,96,2,6,97,4
	db	2,71,98,99,100,4
	db	2,7,101,2,71,102,103,4
	db	2,7,104,2,71,105,106,0
	;
robinstring:
	db	3,18
	db	1,18,18
	db	2,7,110,2,10
robpok:	db	111,2,2,112,4
	db	2,66,113,114,2,2,115,4
	db	2,71,116,117,2,7,118,0
cend:
	org 51180

;BeepFX player by Shiru
;You are free to do whatever you want with this code



chrimblast:
	ld a,0
play_cb:
	ld hl,sfxData_cb	;address of sound effects data

	di
	push ix
	push iy

	ld b,0
	ld c,a
	add hl,bc
	add hl,bc
	ld e,(hl)
	inc hl
	ld d,(hl)
	push de
	pop ix			;put it into ix

	ld a,0;(23624)	;get border color from BASIC vars to keep it unchanged
	rra
	rra
	rra
	and 7
	ld (sfxRoutineToneBorder_cb  +1),a
	ld (sfxRoutineNoiseBorder_cb +1),a
	ld (sfxRoutineSampleBorder_cb+1),a


readData_cb:
	ld a,(ix+0)		;read block type
	ld c,(ix+1)		;read duration 1
	ld b,(ix+2)
	ld e,(ix+3)		;read duration 2
	ld d,(ix+4)
	push de
	pop iy

	dec a
	jr z,sfxRoutineTone_cb
	dec a
	jr z,sfxRoutineNoise_cb
	dec a
	jr z,sfxRoutineSample_cb
	pop iy
	pop ix
	ei
	ret

	

;play sample

sfxRoutineSample_cb:
	ex de,hl
sfxRS0_cb:
	ld e,8
	ld d,(hl)
	inc hl
sfxRS1_cb:
	ld a,(ix+5)
sfxRS2_cb:
	dec a
	jr nz,sfxRS2_cb
	rl d
	sbc a,a
	and 16
sfxRoutineSampleBorder_cb:
	or 0
	out (254),a
	dec e
	jr nz,sfxRS1_cb
	dec bc
	ld a,b
	or c
	jr nz,sfxRS0_cb

	ld c,6
	
nextData_cb:
	add ix,bc		;skip to the next block
	jr readData_cb



;generate tone with many parameters

sfxRoutineTone_cb:
	ld e,(ix+5)		;freq
	ld d,(ix+6)
	ld a,(ix+9)		;duty
	ld (sfxRoutineToneDuty_cb+1),a
	ld hl,0

sfxRT0_cb:
	push bc
	push iy
	pop bc
sfxRT1_cb:
	add hl,de
	ld a,h
sfxRoutineToneDuty_cb:
	cp 0
	sbc a,a
	and 16
sfxRoutineToneBorder_cb:
	or 0
	out (254),a

	dec bc
	ld a,b
	or c
	jr nz,sfxRT1_cb

	ld a,(sfxRoutineToneDuty_cb+1)	 ;duty change
	add a,(ix+10)
	ld (sfxRoutineToneDuty_cb+1),a

	ld c,(ix+7)		;slide
	ld b,(ix+8)
	ex de,hl
	add hl,bc
	ex de,hl

	pop bc
	dec bc
	ld a,b
	or c
	jr nz,sfxRT0_cb

	ld c,11
	jr nextData_cb



;generate noise with two parameters

sfxRoutineNoise_cb:
	ld e,(ix+5)		;pitch

	ld d,1
	ld h,d
	ld l,d
sfxRN0_cb:
	push bc
	push iy
	pop bc
sfxRN1_cb:
	ld a,(hl)
	and 16
sfxRoutineNoiseBorder_cb:
	or 0
	out (254),a
	dec d
	jr nz,sfxRN2_cb
	ld d,e
	inc hl
	ld a,h
	and 31
	ld h,a
sfxRN2_cb:
	dec bc
	ld a,b
	or c
	jr nz,sfxRN1_cb

	ld a,e
	add a,(ix+6)	;slide
	ld e,a

	pop bc
	dec bc
	ld a,b
	or c
	jr nz,sfxRN0_cb

	ld c,7
	jr nextData_cb


sfxData_cb:

SoundEffectsData_cb:
	defw SoundEffect0Data_cb

SoundEffect0Data_cb:
	defb 3 ;sample
	defw 2786
	defw Sample0Data_cb+0
	defb 6
	defb 0

Sample0Data_cb:
	defb 161,63,214,182,181,66,173,255,215,255,248,1,253,0,11,254
	defb 0,63,254,165,127,244,15,255,218,86,255,253,235,123,222,191
	defb 255,254,245,160,1,10,247,191,255,249,127,255,194,255,251,55
	defb 255,228,0,255,255,255,255,228,165,232,75,255,234,223,242,136
	defb 91,218,243,191,255,251,255,255,255,255,255,255,165,128,11,255
	defb 255,255,255,189,96,0,5,191,255,255,254,247,247,237,255,128
	defb 1,251,120,2,87,255,247,255,254,64,13,128,95,252,79,255
	defb 255,255,236,9,26,72,31,255,255,255,254,216,128,2,94,222
	defb 246,142,255,255,255,252,128,0,1,255,251,107,107,90,82,0
	defb 3,192,0,16,0,0,0,0,0,0,127,255,255,255,247,228
	defb 141,191,101,109,223,240,16,0,0,0,157,253,185,0,0,0
	defb 190,2,255,253,254,128,240,191,255,255,255,255,249,216,9,0
	defb 31,255,255,255,255,255,255,255,255,255,126,90,11,127,255,255
	defb 247,32,5,255,255,255,255,255,39,164,15,255,255,255,252,8
	defb 8,11,255,255,128,191,255,255,255,255,255,255,255,255,255,255
	defb 255,224,0,0,0,0,0,61,255,255,255,255,248,3,255,255
	defb 255,255,255,255,0,0,0,0,31,255,255,252,0,31,255,255
	defb 255,255,255,235,255,255,255,255,224,0,0,0,3,255,247,255
	defb 0,0,15,3,255,255,255,255,255,255,255,255,255,128,0,0
	defb 0,255,255,255,254,0,0,0,1,255,255,255,255,255,255,82
	defb 182,252,0,0,0,127,255,255,255,128,0,0,7,255,255,255
	defb 255,255,255,253,90,143,255,128,0,31,255,255,255,254,0,0
	defb 31,255,255,255,255,255,255,255,74,219,3,192,0,3,255,253
	defb 127,255,0,0,0,31,255,255,192,7,255,255,53,107,192,0
	defb 0,0,63,255,255,252,0,0,0,12,11,248,0,0,7,255
	defb 214,181,101,248,0,56,63,255,255,254,0,0,3,255,255,255
	defb 0,0,127,255,214,212,249,108,0,92,31,255,255,254,0,0
	defb 3,255,255,255,224,0,255,255,242,214,176,0,0,0,7,255
	defb 255,254,0,0,0,0,255,240,0,0,3,255,255,173,86,30
	defb 0,16,35,255,255,255,192,192,3,255,255,255,255,0,255,255
	defb 255,253,105,67,224,3,2,127,255,255,240,62,0,252,127,240
	defb 0,0,63,255,255,255,255,126,31,160,63,255,255,255,255,199
	defb 255,255,248,0,0,63,255,255,255,255,255,255,92,127,192,255
	defb 255,255,255,255,255,255,255,224,0,0,127,255,255,255,255,255
	defb 255,252,63,192,127,255,255,227,255,255,255,255,248,0,0,127
	defb 255,255,255,255,255,255,254,15,160,63,255,255,254,255,255,255
	defb 255,128,0,0,0,0,0,255,255,225,255,169,91,255,231,239
	defb 192,15,0,31,255,255,248,0,0,0,0,0,0,0,3,255
	defb 247,223,255,255,254,0,0,0,0,0,0,0,0,0,0,0
	defb 0,0,0,0,255,255,255,255,255,255,255,248,0,0,0,1
	defb 255,255,255,255,255,255,192,0,7,255,255,255,255,255,255,255
	defb 255,255,192,0,15,63,255,255,255,255,255,255,0,0,63,255
	defb 255,255,255,255,255,255,255,255,3,0,112,255,255,255,255,255
	defb 255,248,0,1,255,255,255,255,255,255,255,255,255,248,8,0
	defb 195,255,255,255,255,255,255,224,0,15,255,255,255,255,255,255
	defb 255,255,255,240,48,7,15,255,255,255,255,255,255,128,0,15
	defb 255,255,255,255,255,255,255,255,239,224,96,0,15,255,255,255
	defb 255,255,255,0,0,0,127,255,255,255,255,255,255,255,249,240
	defb 8,0,3,255,255,255,255,255,255,192,0,0,15,255,255,255
	defb 255,255,255,255,255,143,0,0,0,63,255,255,255,255,255,252
	defb 0,0,0,31,255,255,255,255,255,255,255,254,28,0,0,0
	defb 127,255,255,255,255,255,240,0,0,0,15,255,255,255,255,255
	defb 255,255,254,0,0,0,0,255,255,255,255,255,255,248,0,0
	defb 0,7,255,255,255,255,255,255,255,255,231,0,0,0,63,255
	defb 255,255,255,255,255,128,0,0,0,255,255,255,255,255,255,255
	defb 255,255,144,0,0,0,255,255,255,255,255,255,255,0,0,0
	defb 0,255,255,255,255,255,255,255,255,255,252,0,0,0,127,255
	defb 255,255,255,255,255,224,0,0,0,255,255,255,255,255,255,255
	defb 255,255,255,252,0,0,0,255,255,255,255,255,255,255,254,0
	defb 0,0,31,255,255,255,255,255,255,255,255,255,255,255,240,0
	defb 0,15,255,255,255,255,255,255,255,255,192,0,0,31,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,253,191,255,253,255,255,255,245,0,0,100,0,3
	defb 224,1,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,248,0,0,0,0
	defb 63,248,0,0,0,0,0,0,0,0,0,0,0,0,0,63
	defb 255,255,255,255,254,0,0,0,0,7,255,128,0,0,0,0
	defb 0,0,0,0,0,0,0,0,63,255,255,255,255,255,248,0
	defb 0,0,1,255,255,252,0,0,0,127,224,0,0,0,0,0
	defb 1,191,255,255,255,255,255,255,240,0,0,195,255,255,255,255
	defb 254,0,63,255,224,0,0,0,0,0,0,0,127,255,255,255
	defb 255,255,192,0,33,255,255,255,128,0,12,223,255,254,0,0
	defb 0,15,254,0,0,1,255,255,255,255,255,240,0,7,255,255
	defb 255,128,0,127,255,255,240,0,0,3,255,128,0,0,15,255
	defb 255,255,255,255,255,192,0,127,255,255,240,0,127,255,255,240
	defb 0,127,224,0,0,0,0,0,7,255,255,255,255,255,255,224
	defb 1,255,255,255,128,1,255,254,0,0,7,255,224,0,63,252
	defb 0,0,31,254,31,255,255,255,255,248,0,31,255,255,192,0
	defb 255,254,0,0,7,255,192,0,7,255,128,0,127,240,7,255
	defb 255,255,255,255,192,1,255,255,248,0,15,255,192,0,0,255
	defb 248,0,3,255,224,0,15,254,0,63,255,255,255,255,254,0
	defb 15,255,239,192,0,255,252,0,0,31,255,128,0,63,252,0
	defb 1,255,0,3,255,255,255,255,255,254,0,15,255,199,128,1
	defb 255,248,0,0,127,254,0,0,63,252,0,3,255,0,7,255
	defb 255,255,255,255,255,0,7,255,224,128,0,255,252,0,0,255
	defb 254,0,0,127,192,0,3,254,0,3,255,255,255,255,255,255
	defb 224,0,255,252,0,0,63,255,0,0,63,255,128,0,5,252
	defb 0,0,61,0,0,127,255,255,255,255,255,252,0,63,255,0
	defb 0,31,255,128,15,255,255,192,0,14,208,0,0,0,0,0
	defb 31,255,255,255,255,255,255,224,1,255,248,0,0,255,252,0
	defb 127,255,252,0,0,0,0,0,0,7,128,0,127,255,255,255
	defb 255,255,255,192,3,255,240,0,1,255,248,1,255,255,252,0
	defb 0,64,0,0,1,252,0,15,255,255,255,255,255,255,255,128
	defb 7,255,224,0,3,255,240,7,254,255,252,0,0,0,0,0
	defb 1,64,0,31,255,255,255,255,255,255,255,128,15,255,128,0
	defb 31,255,240,31,255,255,224,0,0,0,0,0,0,0,0,15
	defb 255,255,255,255,255,255,255,255,128,31,255,128,16,255,255,255
	defb 255,255,0,1,37,0,0,0,0,0,91,218,151,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,192
	defb 0,67,127,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0
	defb 0,3,255,255,0,1,255,240,3,255,255,255,255,255,255,255
	defb 255,255,253,255,255,255,255,255,7,191,255,255,255,255,255,255
	defb 255,128,0,0,0,3,255,255,255,243,224,0,0,0,0,0
	defb 127,255,255,255,255,248,0,0,1,255,255,255,255,255,160,125
	defb 255,255,224,15,255,255,255,255,255,255,255,255,255,144,255,255
	defb 255,255,255,255,252,163,255,255,255,255,255,128,0,0,247,255
	defb 255,255,255,255,255,240,16,0,0,0,7,127,255,255,255,240
	defb 95,246,253,63,255,255,255,255,255,236,32,37,0,0,0,0
	defb 0,0,152,24,0,0,0,0,0,0,0,0,0,0,0,79
	defb 255,255,181,235,0,0,0,0,0,0,0,0,0,2,16,138
	defb 72,0,0,0,75,239,241,194,75,255,240,9,123,217,123,88
	defb 0,64,0,0,0,0,0,134,32,0,0,2,18,151,0,0
	defb 0,0,2,83,210,80,192,0,0,52,132,0,0,32,3,41
	defb 107,115,1,165,253,140,61,247,173,38,41,99,8,75,8,97
	defb 44,49,164,149,12,52,183,176,37,16,16,0,34,72,2,25
	defb 182,189,109,45,131,6,136,16,148,181,138,185,109,9,66,247
	defb 189,101,37,173,104,82,210,18,65,4,160,0,164,180,164,160
	defb 90,87,239,223,236,178,209,164,148,146,90,73,21,158,181,134
	defb 146,129,108,223,118,148,190,251,111,255,255,127,239,251,247,109
	defb 173,179,255,255,255,123,123,223,45,123,127,237,173,255,255,254
	defb 251,255,123,123,79,75,79,251,79,109,36,145,229,127,255,246
	defb 222,255,185,33,99,10,82,127,247,255,255,223,254,208,161,0
	defb 18,127,255,255,255,255,255,255,255,255,255,239,255,254,219,254
	defb 220,181,255,254,255,255,255,172,72,0,18,150,180,155,123,213
	defb 47,255,109,36,32,9,18,125,255,255,255,255,255,127,215,255
	defb 251,255,219,207,9,9,0,0,0,4,182,132,149,44,203,18
	defb 49,32,32,18,144,70,148,179,150,183,178,219,174,220,132,102
	defb 165,164,164,144,90,214,41,45,45,90,82,16,133,73,37,45
	defb 103,91,73,74,149,89,174,149,45,78,239,255,255,127,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,249,127,255,255,127,251,255,239,223,255,189,255,111,123
	defb 90,246,255,173,239,123,251,95,237,237,109,45,183,255,254,255
	defb 255,255,235,255,223,255,255,255,255,255,255,255,255,255,255,237
	defb 173,239,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,246,255,255,255,255,255,156,191,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,254,0,0,39,155,255,255
	defb 255,192,0,2,127,255,255,255,255,255,228,7,255,32,0,47
	defb 255,255,255,255,255,255,255,252,0,0,0,0,0,0,0,0
	defb 0,0,0,0,0,2,255,255,255,255,255,255,192,0,0,0
	defb 0,0,0,127,255,255,255,248,0,31,255,255,240,0,0,0
	defb 0,15,248,31,255,255,255,128,0,0,0,0,0,0,0,0
	defb 3,255,255,255,255,255,192,0,0,0,0,0,0,0,0,0
	defb 0,1,255,255,255,192,0,0,63,255,255,255,255,255,255,255
	defb 255,255,254,0,0,0,24,0,127,255,255,255,255,255,255,255
	defb 255,252,0,0,127,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,248,0,0
	defb 0,0,0,3,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,240,0,0
	defb 7,255,255,255,255,255,248,0,127,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0
	defb 0,0,0,0,0,127,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
	defb 255,255
	;
go:
	org 54200

;BeepFX player by Shiru
;You are free to do whatever you want with this code



playBasic:
	ld a,0
play:
	ld hl,sfxData	;address of sound effects data

	di
	push ix
	push iy

	ld b,0
	ld c,a
	add hl,bc
	add hl,bc
	ld e,(hl)
	inc hl
	ld d,(hl)
	push de
	pop ix			;put it into ix

	ld a,0;(23624)	;get border color from BASIC vars to keep it unchanged
	rra
	rra
	rra
	and 7
	ld (sfxRoutineToneBorder  +1),a
	ld (sfxRoutineNoiseBorder +1),a
	ld (sfxRoutineSampleBorder+1),a


readData:
	ld a,(ix+0)		;read block type
	ld c,(ix+1)		;read duration 1
	ld b,(ix+2)
	ld e,(ix+3)		;read duration 2
	ld d,(ix+4)
	push de
	pop iy

	dec a
	jr z,sfxRoutineTone
	dec a
	jr z,sfxRoutineNoise
	dec a
	jr z,sfxRoutineSample
	pop iy
	pop ix
	ei
	ret

	

;play sample

sfxRoutineSample:
	ex de,hl
sfxRS0:
	ld e,8
	ld d,(hl)
	inc hl
sfxRS1:
	ld a,(ix+5)
sfxRS2:
	dec a
	jr nz,sfxRS2
	rl d
	sbc a,a
	and 16
sfxRoutineSampleBorder:
	or 0
	out (254),a
	dec e
	jr nz,sfxRS1
	dec bc
	ld a,b
	or c
	jr nz,sfxRS0

	ld c,6
	
nextData:
	add ix,bc		;skip to the next block
	jr readData



;generate tone with many parameters

sfxRoutineTone:
	ld e,(ix+5)		;freq
	ld d,(ix+6)
	ld a,(ix+9)		;duty
	ld (sfxRoutineToneDuty+1),a
	ld hl,0

sfxRT0:
	push bc
	push iy
	pop bc
sfxRT1:
	add hl,de
	ld a,h
sfxRoutineToneDuty:
	cp 0
	sbc a,a
	and 16
sfxRoutineToneBorder:
	or 0
	out (254),a

	dec bc
	ld a,b
	or c
	jr nz,sfxRT1

	ld a,(sfxRoutineToneDuty+1)	 ;duty change
	add a,(ix+10)
	ld (sfxRoutineToneDuty+1),a

	ld c,(ix+7)		;slide
	ld b,(ix+8)
	ex de,hl
	add hl,bc
	ex de,hl

	pop bc
	dec bc
	ld a,b
	or c
	jr nz,sfxRT0

	ld c,11
	jr nextData



;generate noise with two parameters

sfxRoutineNoise:
	ld e,(ix+5)		;pitch

	ld d,1
	ld h,d
	ld l,d
sfxRN0:
	push bc
	push iy
	pop bc
sfxRN1:
	ld a,(hl)
	and 16
sfxRoutineNoiseBorder:
	or 0
	out (254),a
	dec d
	jr nz,sfxRN2
	ld d,e
	inc hl
	ld a,h
	and 31
	ld h,a
sfxRN2:
	dec bc
	ld a,b
	or c
	jr nz,sfxRN1

	ld a,e
	add a,(ix+6)	;slide
	ld e,a

	pop bc
	dec bc
	ld a,b
	or c
	jr nz,sfxRN0

	ld c,7
	jr nextData


sfxData:

SoundEffectsData:
	defw SoundEffect0Data

SoundEffect0Data:
	defb 3 ;sample
	defw 1612
	defw Sample0Data+0
	defb 6
	defb 0

Sample0Data:
	defb 96,31,176,159,233,111,188,150,253,109,254,198,183,181,251,111
	defb 127,247,255,255,175,255,221,107,64,0,0,0,0,4,45,183
	defb 255,255,210,255,245,191,255,127,240,0,0,0,0,0,0,0
	defb 63,255,255,255,255,255,255,254,0,0,33,255,255,252,0,0
	defb 0,0,7,255,255,255,255,255,255,224,0,0,1,255,255,255
	defb 128,0,0,0,0,63,255,255,255,255,255,252,0,0,0,15
	defb 255,255,224,0,0,0,15,252,15,255,255,255,255,255,128,0
	defb 0,7,255,255,248,0,0,0,1,255,224,255,255,255,255,255
	defb 240,0,0,0,127,255,252,0,0,0,0,31,254,0,255,255
	defb 255,255,255,224,0,0,0,255,255,192,0,0,0,0,127,254
	defb 0,31,255,255,255,255,128,0,0,3,255,255,0,0,0,0
	defb 255,255,240,0,15,255,255,255,255,224,0,0,3,255,255,128
	defb 0,0,0,127,240,224,0,3,255,255,255,255,240,0,0,3
	defb 255,255,192,0,0,0,255,248,0,0,0,127,255,255,255,255
	defb 0,0,4,63,255,252,0,0,0,15,254,0,0,0,7,255
	defb 255,255,255,240,0,0,227,255,255,192,0,0,0,127,252,0
	defb 0,0,63,255,255,255,255,240,0,3,255,255,255,192,0,0
	defb 0,127,252,0,0,0,31,255,255,255,255,252,0,0,255,255
	defb 255,240,0,0,0,7,255,0,0,0,3,255,255,255,255,255
	defb 128,0,15,255,255,255,0,0,0,0,31,240,0,0,0,127
	defb 255,255,255,255,252,0,0,255,247,255,248,0,0,0,0,127
	defb 128,0,0,3,255,255,255,255,255,248,0,1,255,255,255,240
	defb 0,0,0,0,63,0,0,7,255,255,255,255,255,255,224,0
	defb 7,255,255,255,224,0,3,204,0,4,0,0,15,255,255,255
	defb 255,255,255,192,0,15,255,255,255,128,0,7,248,0,0,0
	defb 0,31,255,255,255,255,255,255,0,0,31,255,255,255,128,0
	defb 15,248,0,0,0,0,127,255,255,255,255,255,254,0,0,127
	defb 255,255,255,0,0,31,248,0,0,0,0,127,255,255,255,255
	defb 255,255,0,0,63,255,255,255,0,0,15,248,0,0,0,0
	defb 31,255,255,255,255,255,255,0,0,31,255,255,255,128,0,7
	defb 254,0,0,0,0,15,255,255,255,255,255,255,224,0,7,255
	defb 255,255,248,0,1,255,192,0,0,0,7,255,255,255,255,255
	defb 255,254,0,0,127,255,255,255,192,0,31,252,0,0,0,0
	defb 31,255,255,255,255,255,255,192,0,7,255,255,255,252,0,1
	defb 255,224,0,0,0,1,255,255,255,255,255,255,252,0,0,127
	defb 255,255,255,224,0,15,254,0,0,0,0,7,255,255,255,255
	defb 255,255,192,0,7,255,255,255,254,0,1,255,240,0,0,0
	defb 0,127,255,255,255,255,255,254,0,0,63,255,255,255,240,0
	defb 7,255,192,0,0,0,1,255,255,255,255,255,255,252,0,0
	defb 255,255,255,255,224,0,15,255,192,0,0,0,3,255,255,255
	defb 255,255,255,254,0,0,127,255,255,255,224,0,7,255,224,0
	defb 0,0,1,255,255,191,255,255,255,255,240,0,7,255,255,255
	defb 255,0,0,63,255,128,0,0,0,15,255,240,31,255,255,255
	defb 255,240,0,7,255,255,255,254,0,0,63,255,128,0,0,0
	defb 7,255,240,1,255,255,255,255,254,0,0,127,255,255,255,224
	defb 0,3,255,248,0,0,0,0,63,255,0,31,255,255,255,255
	defb 192,0,15,255,255,252,248,0,0,63,255,128,0,0,0,0
	defb 255,248,0,127,255,255,255,255,0,0,31,255,255,248,240,0
	defb 0,127,255,128,0,0,0,1,255,248,0,255,255,255,255,254
	defb 0,0,63,255,255,240,224,0,0,255,255,128,0,0,0,0
	defb 255,248,0,63,255,255,255,255,128,0,15,255,255,248,0,0
	defb 0,31,255,224,0,0,0,0,63,255,0,31,255,255,255,255
	defb 224,0,7,255,255,255,188,0,0,15,255,248,0,0,0,0
	defb 31,255,0,1,255,255,255,255,254,0,0,63,255,255,253,224
	defb 0,0,127,255,224,0,0,0,0,255,252,0,15,255,255,255
	defb 255,252,0,0,255,255,255,255,192,0,1,255,255,128,0,0
	defb 0,3,255,224,0,7,255,255,255,255,248,0,0,255,255,255
	defb 227,128,0,1,255,255,128,0,0,0,7,255,248,0,7,255
	defb 255,255,255,255,0,0,63,255,255,251,240,0,0,127,255,224
	defb 0,0,0,0,255,252,0,0,127,255,255,255,255,224,0,3
	defb 255,255,254,24,0,0,7,255,254,0,0,7,255,255,255,240
	defb 0,63,255,255,255,255,254,0,0,31,255,255,193,128,0,0
	defb 63,255,224,0,0,1,240,96,240,0,0,255,255,255,255,255
	defb 248,0,0,255,255,255,128,0,0,1,255,255,192,0,0,15
	defb 255,255,192,0,0,255,255,255,255,255,254,0,0,63,255,255
	defb 192,0,0,0,127,255,240,0,0,15,255,255,255,0,0,127
	defb 255,255,255,255,255,248,0,0,255,255,255,255,224,0,1,255
	defb 255,192,0,0,15,255,254,64,0,0,255,255,255,255,255,255
	defb 255,0,0,31,255,255,255,255,128,0,63,255,240,0,0,31
	defb 255,224,0,0,0,63,255,255,255,255,255,255,255,0,0,15
	defb 255,255,255,255,224,0,127,255,224,0,0,15,224,0,0,0
	defb 0,127,255,255,255,255,255,255,255,254,0,0,127,255,255,255
	defb 255,128,15,255,255,128,0,0,239,228,0,0,0,0,15,255
	defb 255,255,255,255,255,255,255,240,0,63,255,255,255,255,255,254
	defb 0,0,0,0,0,0,0,0,0,0,0,127,255,255,255,255
	defb 255,255,255,255,255,255,252,0,0,3,255,255,255,255,254,0
	defb 0,0,0,0,0,31,255,255,255,255,255,255,255,254,15,255
	defb 255,255,255,254,0,63,255,255,255,255,255,255,128,0,15,255
	defb 255,255,255,248,31,255,255,255,255,255,255,255,254,0,31,255
	defb 255,255,255,255,255,224,255,255,255,0,0,0,0,0,0,63
	defb 251,255,255,248,0,0,0,0,127,135,255,255,255,255,255,255
	defb 255,255,254,0,0,63,255,248,0,1,195,0,0,0,0,255
	defb 255,252,0,15,255,255,255,255,254,0,0,0,0,0,63,252
	defb 0,3,255,255,255,193,255,255,255,255,255,255,255,255,255,253
	defb 240,0,125,128,3,128,31,255,240,0,1,192,0,0,4,254
	defb 127,255,252,0,31,255,192,0,15,240,0,127,254,0,248,0
	defb 0,0,0,0,24,0,0,0,0,1,252,0,30,96,252,0
	defb 7,255,255,255,236,0,0,0,31,255,255,255,248,192,0,0
	defb 15,240,0,24,0,0,0,2,0,0,16,1,255,255,255,255
	defb 255,255,0,0,0,0,0,192,0,31,254,1,3,240,3,225
	defb 255,255,248,0,1,224,0,0,0,0,0,0,0,56,0,3
	defb 252,0,0,0,0,0,0,0,0,0,0,28,0,1,255,0
	defb 0,0,0,0,14,16,6,31,243,255,0,7,240,0,0,7
	defb 254,0,0,7,192,1,255,224,0,0,0,0,0,0,0,0
	defb 0,3,232,0,0,240,0,63,255,0,0,0,63,192,0,127
	defb 252,0,0,0,0,127,255,128,0,0,0,0,31,224,0,127
	defb 240,0,0,0,0,127,254,0,28,0,255,252,0,0,15,224
	defb 63,254,0,255,255,3,255,128,0,0,7,255,255,255,192,7
	defb 255,240,0,15,255,255,255,255,255,255,192,0,0,0,1,255
	defb 255,255,255,255,255,255,128,7,248,1,255,255,255,255,128,63
	defb 255,255,255,255,255,255,255,199,255,255,255,255
	;
org 56064
AY_code:	;8113 bytes of Sountracker music by Yerzmyey
incbin	'yerz_jupiter_bin'	
	;
	;844 bytes free here (64177 to 65021)
org 65021
	jp AY_interrupt
org 65024
rept	257
	db	253
endrep
AY_interrupt:	;plays Yerz's cool AY music every 50th of a second
	push af
	push bc
	push de	
	push hl
	ex af,af'
	exx
	push af
	push bc
	push de
	push hl
	push ix
	push iy
intpok:	call play_AY	;playAY gets poked in here
	pop iy
	pop ix
	pop hl
	pop de
	pop bc
	pop af
	exx
	ex af,af'
	pop hl
	pop de
	pop bc
	pop af
	ei
dnth:	ret
	;

codend
