	;
	; Quadrillion
	; Coded by Csabo of LOD, 2004.
	;
	ORG $4000-2
	DW $4000
	
	;DB $0B,$10,0,0,$9E,"4109",0,0,0
	
lptr2	= $B0		; second pointers for saved lum/col map
cptr2	= $B2
lptr	= $B4		; generic lum/col map pointers
cptr	= $B6
bptr	= $B8		; generic bitmap pointer
ctemp	= $BA
ctemp2	= $BB
block_ptr	= $BC
block_col	= $BE
block_col2	= $BF

cur_x	= $80	; 0-3: position within one char
cur_y	= $81	; 0-3: position within one char
x_offs	= $82	; 0/1: if 1, then on right side of big block
y_offs	= $83	; 0/1: if 1, then lower part of big block
cur_dir	= $84	; 0 = up, 1=down
cur_lr	= $85	; 0 = straight, 1=right, $FF=left
cur_col	= $86	; current color
cur_pos	= $88	; current position on screen (pointer)
cur_pos2= $8A	; temp
chk_pos	= $8C	; check position: always points to whole block
chk_pos2= $8E

text_dest	= $E0	; 16 bit
message_ptr	= $E2	; 16 bit
letter_tmp	= $0A
letter_tmp2	= $0B

lives		= $F3
level		= $F4
levels_cleared	= $F5
last_level	= $F6
blocks		= $F7

current_block	= $F8	; for level drawing
current_count	= $F9	; number of blocks to put
current_row	= $FA	; number of blocks drawn in current row
kb_delay	= $FB

temp_color	= $7800
temp_lum	= $7900
sprite_temp	= $7A00
score		= $7B00
score_curr	= $7C00
score_high	= $7D00
message_temp	= $7E00

mlen = 18

get_ROM_byte = $0473
set_ptr = $9DCA		; set 3B/3C (X,Y)

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

speed = 7

current_note	= $A0
notelen		= $A1
step		= $A2
step2		= $A3
basecnt		= $A4
baselen		= $A5
baseptrcnt	= $A6
baseptr		= $A7
music_flag	= $AA
;
ptr		= $3B

	;
	; init screen
	;
	DEC $75     		; flag graphic mode
	LDA #$47
	STA $85			; set color 2 to yellow
	LDA #$67
	STA $86			; set color 3 to yellow
	LDA #$A0
	STA $FF15
	STA $FF19
	JSR $C5DF		; GRAPHIC 3: turn on graphics
	JSR $C567		; SCNCLR: clear screen
	;
	SEI
	;
	DEC $047B
	LDA #$60
	STA $0484		; place RTS into routine
	;
	LDA #$00
	LDY #$05
is_00	STA score_high,y	; init high score
	DEY
	BPL is_00
	;
	LDA #$01
	STA last_level
	;
new_game
	LDA #$00
	STA lives
	STA music_flag
	STA level
	STA levels_cleared
	;
	LDY #$05
is_01	STA score,y		; init score
	STA score_curr,y
	DEY
	BPL is_01
	;
	; --- create "status bar"
	;
	LDX #$80
	LDY #$28
	STX text_dest
	STY text_dest+1
	;
	LDX #$00
ws_02	LDA text_data,x		; read next byte
	BNE ws_01		; non-zero?
	;
	LDA text_dest		; $00 means next "line"
	CLC
	ADC #$D0
	STA text_dest
	LDA text_dest+1
	ADC #$04
	STA text_dest+1
	BNE ws_03
	;
ws_01	JSR write_letter
	;
ws_03	INX
	CPX #text_data_end - text_data
	BNE ws_02
	;
	; ---
	;
	LDA #$B8
	STA text_dest
	LDA #$24
	STA text_dest+1
	;
	JSR write_title
	;
	; ---
	;
	JSR write_score		; write zeros
	JSR inc_level		; level 1 + write
	;
	;
	JSR draw_level_back
	;
	; ---
	;
	JSR clear_large
	;
	LDX #$98
	LDY #$2B
	STX text_dest
	STY text_dest+1
	;
	JSR write_title
	;
	LDX #$B0
	LDY #$2C
	LDA #text_author & 255
	JSR write_message_pos
	;
	; ---
	;
	LDX #$30
	LDY #$2F
	LDA #text_start_level & 255
	JSR write_message_pos
	;
	JSR write_high_score
	;
	; --- music init
	LDA #$03
	STA $FF10
	;
	LDX #$FF
	STX baseptrcnt
	INX
	STX step
	STX step2
	STX ptr
	STX basecnt
	STX reverse+1 
	INX
	STX notelen
	STX baselen
	LDA #$80
	STA ptr+1
	;
	LDA #$04
	STA current_note
	;
	JMP ml_02
	;
	; ---
	;
menu_loop
	DEC current_row
	BNE menu_loop1
	;
next_bline
	JSR next_block_line
	;
	LDA bptr+1
	CMP #$28
	BNE ml_03
	;
	LDX #$0A
ml_04	JSR inc_lptr_40
	JSR inc_bptr_140
	DEX
	BNE ml_04
	;
ml_03	LDA bptr+1
	CMP #$3C
	BEQ ml_02
	BNE ml_01
	;
ml_02	JSR init_block_pos
	;
ml_01	LDA #14
	STA current_row
	;
menu_loop1
	LDA #$7F
	JSR query_keyboard
	CMP #$FF
	BEQ ml_06
	;
	JMP menu_cont
	;
ml_06	LDA $FF1D
	CMP #$40
	BCS ml_06b
	;
	LDX #$01
	STX music_flag
	;
ml_06b	CMP #$CC
	BCC menu_loop1
	;
	LDA music_flag
	BEQ menu_loop1
	;
	DEC music_flag
	;
	; --------
	;
	LDX notelen
	DEX
	BNE ml_23
	;
	LDA #$BF		; check cursor right
	JSR query_keyboard
	TAY
	AND #$08
	BNE ml_20
	;
	LDA level
	CMP last_level
	BCS ml_20
	;
	JSR inc_level
	;
	JMP ml_23
	;
ml_20	TYA			; check cursor left
	AND #$01
	BNE ml_23
	;
	SED
	LDA level
	SEC
	SBC #$01
	CLD
	BEQ ml_23
	STA level
	;
	JSR write_level
	;
ml_23	; - write level into box
	;	
	LDX #$B0
	STX text_dest
	LDX #$2F
	STX text_dest+1
	;
	LDA level
	JSR write_two_digits
	;
	; -----------------------------
	; MUSIC
	;
	LDA notelen
	ORA #$30
	STA $FF11
	;
	DEC baselen
	BNE ch2
	;
	; ---
	;
	LDY basecnt
	BNE b1
	;
rest1	LDX baseptrcnt
	INX
	CPX #12
	BNE b2
	LDX #$00
b2	STX baseptrcnt	
	LDA base_lo,x
	STA baseptr
	;LDA base_hi,x
	LDA #base_c >> 8	; all patterns must be on same page
	STA baseptr+1
	;
b1	LDX #speed	
	LDA (baseptr),y
	BPL nowrap
	LDY #$00
	BEQ rest1
	;
nowrap	CMP #$0B
	BCC not_chord
	LDX #$01
not_chord	
	STX baselen
	;
	TAX
	LDA freq2lo,X
	STA $FF0E
	LDA freq2hi,X
	ORA #$C8
	STA $FF12
	;
	INY
	STY basecnt
	;
	; ---------
	;
ch2	DEC notelen
	BNE music_end
	;
	LDA #speed
	STA notelen
	;
	INC step
	LDA step
	CMP #$02
	BNE ex1
	;
	LDA step2
	AND #$03
	EOR #$03
	BNE quiet ;ex1
	;
	;JMP quiet
	;
ex1	CMP #$03
	BNE now1
	LDA #$00
	STA step
	;
	INC step2
	;
now1    ;
	JSR get_ROM_byte
	;
	AND #$0F
reverse	EOR #$00
	TAY
	LDA add,y
	CMP #$80
	BEQ quiet
	;
	CLC
	ADC current_note
	BPL not_neg
	;
	LDX #$00
	BEQ do_rev
not_neg
	CMP #$12
	BCC not_above
	;
	LDX #$12
	;
do_rev	LDA reverse+1
	EOR #$0F
	STA reverse+1
	;
	TXA
not_above
	STA current_note
	TAY
	LDA freq,y
	DB $2C
quiet	LDA #$FE

set_freq
	STA $FF0F
	;
music_end
	;
	LDA block_col		; random color
	ADC $FF00
	AND #$0F
	JSR change_block_col
	;
	LDX #$00
	;LDA $FF00
	;AND #$03
	;TAX
	JSR draw_new_block	; draw top/bottom blocks
	;
	JMP menu_loop
	;
	; ---
	;
menu_cont
	;JSR wait_space
	;
	LDA #$00
	STA $FF11		; sound off
	;
	LDA #$02		; 2 (+1 when level starts)
	STA lives
	BNE new_level_noinc	; always jump
	;
	; ###############################################################
	;
new_level
	JSR inc_level
	;
new_level_noinc
	LDA lives
	CMP #$06
	BEQ dont_add_lives
	INC lives
dont_add_lives
	;
	; -------------
	;
level_restart
	JSR draw_level_back
	;
	; --- ------------------------------------------------
	; DRAW LEVEL
	;
	LDA #$48		; default ball start pos (if not specified by level)
	STA cur_pos
	LDA #$26
	STA cur_pos+1
	;
	JSR init_block_pos
	;
	LDA #$00
	STA blocks	; reset number of blocks per level
	STA current_row
	;
	LDA #$11
	STA block_col2	; default color (if not specified by level)
	;
	LDX level
	LDY level_ptr_hi-1,x
	LDA level_ptr_lo-1,x
	TAX
	;
	;LDY #$B2
	;LDX #$0D
	;
	JSR set_ptr	; set 3B/3C
	;
data_loop
	JSR get_ROM_byte	; get one byte
	TAX			; save it for later
	BEQ level_done
	;
	CMP #$07 		; 07 = ball start position
	BNE not_start_pos
	;
	LDA bptr		; copy current position
	STA cur_pos
	LDA bptr+1
	STA cur_pos+1
	;
	BNE data_loop		; always jump
not_start_pos
	;
	AND #$07
	STA current_block
	;
	LDA block_col2		; restore color that may have been changed by a single piece
	STA block_col
	;
	TXA
	LSR a			; upper 5 bits = repetition
	LSR a
	LSR a
	STA current_count
	BNE not_col_change
	;
	LDA current_block
	JSR change_block_col
	STA block_col2		; set permanent color
	BNE data_loop		; always jump
	;
not_col_change
	CMP #$10
	BCC block_loop
	;
	LDA current_count	; single piece
	JSR change_block_col
	;
	LDA #$01
	STA current_count
	;
block_loop
	LDX current_block
	BNE dont_count_block
	;
	SED
	LDA blocks
	CLC
	ADC #$01
	STA blocks
	CLD
	;
dont_count_block
	CPX #$07
	BEQ skip_draw
	;
	LDA bptr+1		; safety check...
	CMP #$3C		; make sure we stop at bottom of screen.
	BEQ level_done
	;
	JSR draw_new_block
	JMP d1
	;
skip_draw
	JSR skip_block
	;
d1	INC current_row
	LDA current_row
	CMP #14
	BNE not_row_end
	;
	; ---
	LDA #$00
	STA current_row
	;
	JSR next_block_line
	;
not_row_end
	;
	DEC current_count
	BNE block_loop
	;
	JMP data_loop
	;
level_done
	; ----------------
	JSR get_ROM_byte	; read one more byte: color
	;
	STA cur_col
	ORA #$70
	STA $FF16
	;
	; ----------------
	;
	LDX #$78
	STX text_dest
	LDX #$3C
	STX text_dest+1
	;
	LDA level
	ASL a
	ASL a
	STA $3B
	LDA #$00
	STA $3C
	;
	ASL $3B
	ROL $3C
	ASL $3B
	ROL $3C
	;
	LDA $3B
	CLC
	ADC #(level_names - 17) & 255
	STA $3B
	LDA $3C
	ADC #(level_names - 17) >> 8
	STA $3C
	;
	JSR write_level_name
	;
	INC text_dest+1		; add $140 ($40 already added)
	;
	JSR write_level_name
	;

;	LDA #$22
;	STA block_col
;	;
;	LDX #$00
;	LDY #$80
;	JSR $9DCA	; set $3B/$3C
;	;
;	LDA #$00
;	STA blocks	; reset number of blocks per level
;	;
;	LDX #10
;l_db1	TXA
;	PHA
;	LDX #13
;l_db	TXA
;	PHA
;	;
;	JSR get_ROM_byte
;	LSR a
;	AND #$03
;	BEQ x3
;	STA block_col
;	ASL a
;	ASL a
;	ASL a
;	ASL a
;	ORA block_col
;	STA block_col
;	;
;	JSR skip_block
;	JMP x4
;	;
;x3	JSR get_ROM_byte
;	AND #$03
;	TAX
;	BNE dont_count_block
;	;
;	SED
;	LDA blocks
;	CLC
;	ADC #$01
;	STA blocks
;	CLD
;	;
;dont_count_block
;	JSR draw_new_block
;	;
;x4	PLA
;	TAX
;	DEX
;	BPL l_db
;	;
;	;LDA block_col
;	;CLC
;	;ADC #$11
;	;STA block_col
;	;
;	LDA #40+12		; next line of blocks
;	JSR inc_lptr
;	;
;	LDA #$A0
;	JSR inc_bptr
;	INC bptr+1
;	;
;	PLA
;	TAX
;	DEX
;	BPL l_db1
	;
	; ---
	;
	JSR write_blocks
	;
	; ---
	;
	LDX #$01		; down
	STX cur_dir
	DEX
	STX cur_x
	STX cur_y
	STX y_offs
	STX x_offs
	STX cur_lr		; clear left/right movement
	;
	JSR clear_middle
	;
	LDA #text_press_space & 255
	LDX #text_press_space >> 8
	JSR do_pause
	;
	JSR save_background	; pre-save
	;
	; ##################################################################
	; game loop
	;
game_loop	
	LDA $FF16
	EOR #$10
	STA $FF16
	;
	LDA $FF11		; decrease volume in every frame
	AND #$0F		; unless it's zero already
	BEQ no_sound_dec
	DEC $FF11		; decrease by 2
	DEC $FF11
no_sound_dec
	;
	;DEC $FF19		; debug
	;
sync2	LDA $FF1D
	CMP #$BB
	BCS sync2
	;
sync0	LDA #$BB		; SYNC to BB: two lines above lower edge
	CMP $FF1D
	BCC sync1
	;
	INC $FF0F		; adjust freq lower byte for "punchier" sound effect
	;
	LDA #$BF		; query keyboard
	JSR query_keyboard
	TAY			; save for later
	AND #$10
	BNE check_lr
	;
	JMP died		; ESC PRESSED
	;
check_lr
	LDA cur_x		; only allow left/right control when
	ORA cur_y
	BNE sync0		; fully inside character
	;
	TYA
	AND #$01		; CHECK CURSOR LEFT
	BNE check_right_key
	;
kleft	LDA #$FF		; mark LEFT
ksetdir	STA cur_lr
	JMP sync0
	;
check_right_key
	TYA
	AND #$08		; CHECK CURSOR RIGHT
	BNE check_pause
	;
kright	LDA #$01
	BNE ksetdir		; mark RIGHT; always jump
	;
check_pause
	LDA #$7F		; query "P" key
	JSR query_keyboard
	TAY
	AND #$10
	BNE check_joy
	;
	JMP pause
	;
check_joy
	TYA
	;AND #$20		; C=
	AND #$A4		; C= + CTRL + Run/Stop
	BNE cj_01
	;
	JMP skip_level
	;
cj_01	LDA #$F9		; allow both ports
	JSR query_joystick	; query joy
	TAY
	AND #$04		; left?
	BEQ kleft
	TYA
	AND #$08		; right?
	BEQ kright
	;
	; alternative keys
	;
	LDA #$FD
	JSR query_keyboard
	AND #$7C		; whole bunch of keys, except joy up/down+fire
	CMP #$7C
	BNE kleft
	;
	LDA #$FB
	JSR query_keyboard
	AND #$BC
	CMP #$BC
	BNE kright
	BEQ sync0	
	;
sync1
	;INC $FF19		; debug
	;
	; - update score if needed
	;
	JSR check_score
	;
	; - restore old background
	;
	LDY #$0F
rs_01	LDA sprite_temp,y
	STA (cur_pos),y
	DEY
	BPL rs_01
	;
	JSR cur_pos2_down
	;
	LDY #$0F
rs_02	LDA sprite_temp + $10,y
	STA (cur_pos2),y
	DEY
	BPL rs_02
	;
	; - move ball ######################################################
	; ##################################################################
	;
	JSR move_up_down
	;
	; ---
	;
	LDA cur_pos		; copy current position to check position
	STA chk_pos
	LDA cur_pos+1
	STA chk_pos+1
	;
	LDA cur_lr		; determine left or right or straight
	BMI check_left
	BNE check_right
	JMP go_straight
	;
check_left			; PLAYER INTENDS TO MOVE LEFT
	LDA cur_x		; check only when starting to change columns
	BNE go_left
	;
	JSR sub_chk_pos_8	; check position on the left
	;
	JSR check_small_collision
	BCS swr_1
	;
	; -------------
	LDA x_offs		; if offset=1, we can always go left
	BNE go_left
	;
	;			; otherwise left one more char
	JSR sub_chk_pos_8	; (which means we are checking 2 chars over)
	;
	LDA cur_dir
	BNE cl_d1
	;
	LDA y_offs
	BEQ no_yadd_1
	;
	JSR add_chk_pos_140
	JMP no_yadd_1
	;
cl_d1	LDA y_offs
	BEQ no_yadd_1
	;
	JSR sub_chk_pos_140	; up one line
	;
no_yadd_1
	;
	LDA chk_pos		; disk dest position: 2 chars left
	SEC
	SBC #$10
	STA chk_pos2
	LDA chk_pos+1
	SBC #$00
	STA chk_pos2+1
	;
	JSR check_collision
	BCC no_switch_right
	;
swr_1	JMP switch_right
	;
no_switch_right
	LDA y_offs
	BEQ go_left
	;
	LDA cur_dir
	BNE cl_d2
	;
	JSR sub_chk_pos_280	; check diagonally LEFT/ABOVE
	;
	JMP cl_d3
	;
cl_d2	JSR add_chk_pos_280	; check diagonally LEFT/BELOW - two lines down
	;
cl_d3	JSR check_collision_diag
	BCS switch_right_diag	; DIAGONAL hit
	;
	BCC go_left
	;
switch_left_diag
	JSR switch_up_down
	;	
switch_left
	LDA #$FF		; SWITCH direction
	STA cur_lr
	;
go_left	LDX cur_x		; MOVE LEFT is possible, do it
	DEX
	BPL mv_01
	;
	LDA cur_pos		; * MOVE LEFT
	SEC
	SBC #$08
	STA cur_pos
	BCS mv_02
	DEC cur_pos+1
mv_02	;
	LDA x_offs		; switch x offset
	EOR #$01
	STA x_offs
	;
	LDX #$03
mv_01	STX cur_x		; x will be checked
	;
	JMP check_lr_end
	;
	; --- move right -------------
	;
check_right
	LDA cur_x		; check only when starting to change columns
	BNE go_right
	;
	JSR add_chk_pos_8	; check position on the right
	;
	JSR check_small_collision
	BCS switch_left
	;
	; ----------
	LDA x_offs		; if x_offs=0 we can always go right
	BEQ go_right
	;			; x position is already set (one to the right)
	;
	LDA y_offs
	BEQ no_yadd_2
	;
	LDA cur_dir
	BNE cr_d1
	;
	JSR add_chk_pos_140	; position that needs to be checked it BELOW
	JMP no_yadd_2
	;
cr_d1	JSR sub_chk_pos_140
	;
no_yadd_2
	;
	LDA chk_pos		; disk dest pos: 2 chars right
	CLC
	ADC #$10
	STA chk_pos2
	LDA chk_pos+1
	ADC #$00
	STA chk_pos2+1
	;
	JSR check_collision
	BCS switch_left
	;
	; --------------------- ; no side hit, check diagonal
	;
	LDA y_offs
	BEQ go_right
	;
	LDA cur_dir
	BNE cr_d2
	;
	JSR sub_chk_pos_280	; CHECK diagonally UP/RIGHT
	;
	JMP cr_d3
	;
cr_d2	JSR add_chk_pos_280	; check diagonally DOWN/RIGHT - two lines down
	;
cr_d3	JSR check_collision_diag
	BCS switch_left_diag	; DIAGONAL hit
	;
	BCC go_right
	;
switch_right_diag
	JSR switch_up_down
	;
switch_right
	LDA #$01		; CHANGE direction
	STA cur_lr
	;
go_right
	LDX cur_x		; move right is possible
	INX
	CPX #$04
	BNE mv_10
	;
	LDA cur_pos		; * MOVE RIGHT
	CLC
	ADC #$08
	STA cur_pos
	BCC mv_11
	INC cur_pos+1
mv_11	;
	LDA x_offs		; switch x offset
	EOR #$01
	STA x_offs
	;
	LDX #$00
mv_10	STX cur_x
	;
check_lr_end
	CPX #$00		; is x=0? (arrived to next character?)
	BNE go_straight
	;
	STX cur_lr		; yes, stop horizontal movement
	;
go_straight
	;
	; ##################################################################
	;
	LDA cur_pos
	STA chk_pos
	LDA cur_pos+1
	STA chk_pos+1
	;
	LDA cur_dir
	BNE down
	;
	; - up
	;
	LDA cur_y
	BNE no_upper_check
	;
	; --- ! check above
	;
	JSR sub_chk_pos_140
	;
	JSR check_small_collision
	BCS ud_reverse
	;
	; -------------
	LDA y_offs
	BNE no_upper_check
	;
	JSR sub_chk_pos_140		; up one more
	;
	LDA x_offs
	BEQ no_xadd
	;
	JSR sub_chk_pos_8
	;
no_xadd
	;
	LDA chk_pos
	SEC
	SBC #$80
	STA chk_pos2
	LDA chk_pos+1
	SBC #$02
	STA chk_pos2+1
	;
	JSR check_collision
	;
	BCC no_upper_check
	;
ud_reverse
	LDA cur_dir			; reverse direction
	EOR #$01
	STA cur_dir
	;
no_upper_check
	JMP no_down_check
	;
	; ----------------------
	;
down	LDA cur_y
	BNE no_down_check
	;
	JSR add_chk_pos_140	; check down one line
	;
	JSR check_small_collision
	BCS ud_reverse_2
	;
	;-----------------
	LDA y_offs
	BEQ no_down_check
	;
	LDA x_offs
	BEQ no_xadd_2
	;
	JSR sub_chk_pos_8
	;
no_xadd_2
	;
	LDA chk_pos		; disk dest pos: 2 lines down
	CLC
	ADC #$80
	STA chk_pos2
	LDA chk_pos+1
	ADC #$02
	STA chk_pos2+1
	;
	JSR check_collision
	;
	BCC no_down_check
	;
ud_reverse_2
	LDA cur_dir			; reverse direction
	EOR #$01
	STA cur_dir
	;
no_down_check
	;
	; - save new background ------------------------------------------
	;
	JSR save_background
	;
	; - draw sprite
	;
	LDX cur_x
	LDA cur_y		; add 8,6,4,2 to sprite pos to shift it up
	EOR #$03
	ASL a
	CLC
	ADC #$02
	ADC sprite_ptrs_lo,x	; look up sprite mask according to x position
	STA chk_pos		; (each one is x shifted)
	LDA sprite_ptrs_hi,x
	ADC #$00
	STA chk_pos+1
	;
	LDA cur_y		; y stop value
	ASL a
	STA dr_02+1
	ORA #$08
	STA dr_04+1
	;
	SEC
	SBC #$01
	STA dr_07+1
	SEC
	SBC #$08
	STA dr_05+1
	;
	LDY #$07
dr_01	LDA (chk_pos),y		; top/left corner
	ORA (cur_pos),y
	STA (cur_pos),y
	DEY
dr_02	CPY #$00
	BPL dr_01
	;
	LDY #$0F		; top/right corner
dr_03	LDA (chk_pos),y
	ORA (cur_pos),y
	STA (cur_pos),y
	DEY
dr_04	CPY #$00
	BPL dr_03
	;
	JSR cur_pos2_down	; down one line
	;
	JSR add_chk_pos_8	; inc sprite pos
	;
dr_05	LDY #$07
	BMI dr_09
dr_06	LDA (chk_pos),y		; bottom/left
	ORA (cur_pos2),y
	STA (cur_pos2),y
	DEY
	BPL dr_06
	;
dr_07	LDY #$0F
dr_08	LDA (chk_pos),y		; bottom/right
	ORA (cur_pos2),y
	STA (cur_pos2),y
	DEY
	CPY #$07
	BNE dr_08
dr_09	;
	LDA blocks
	BEQ next_level
	;
	JMP game_loop
	
	;
	; *** NEXT LEVEL ***
	;
skip_level
	DEC lives		; so that they don't gain a life when skipping levels
	;
next_level
	INC levels_cleared
	;
	JSR clear_middle
	;
	LDA #text_level_cleared & 255
	JSR write_message
	;
	LDA #$20
	JSR do_noise
	;
	LDA level		; is there a next level?
	CMP #$20
	BEQ game_over
	;
	JMP new_level		; yes, go to new one
	
	;
	; *** player dies
	;
died	DEC lives		; decrease number
	JSR write_lives		; and erase lost one
	;
	; play some noise + pause
	;
	LDA #$40
	JSR do_noise
	;
	; --- decrease lives
	;
	LDA lives
	BEQ game_over
	;
	JMP level_restart
	
game_over
	LDA level
	CMP last_level
	BCC go_0
	STA last_level		; store last reached level
	;
	; check for new high score
	;
go_0	LDX #$05
chs_01	LDA score_high,x
	CMP score,x
	BCC new_high_score
	DEX
	BPL chs_01
	BMI go_2
	;
new_high_score
	LDX #$05
chs_02	LDA score,x		; it's a new high score, copy it
	STA score_high,x
	DEX
	BPL chs_02
	;
	JSR clear_large		; larger box
	;
	LDX #$70
	LDY #$30
	LDA #text_congrats & 255	; congrats message
	JSR write_message_pos
	;
	JSR write_high_score		; display actual high score
	;
	JMP go_2a
	;
	; --- all levels cleared
	;
go_2	LDA levels_cleared
	CMP #20				; decimal 20!
	BNE go_3
	;
	JSR clear_large
	;
go_2a	LDA levels_cleared
	CMP #20				; decimal 20!
	BNE go_3
	;       
	LDX #$70
	LDY #$2B
	LDA #text_all_levels_cleared & 255	; special message
	JSR write_message_pos
	;
go_3	JSR clear_middle		; display standard game over message
	;
	LDA #text_game_over & 255
	JSR write_message
	;	
	JSR wait_space
	JMP new_game
	
	;
	; --- pauses the game, waits for space keypress
	;
pause
	JSR clear_middle
	;
	LDA #text_paused & 255
	JSR do_pause
	;
	JMP sync0

do_pause
	LDY #$00		; volume off
	STY $FF11
	JSR write_message
	;
	JSR wait_space
	;
	JSR restore_middle
	;
	RTS
	
	;
	; pauses the program until space is pressed
	;
wait_space
	JSR wait_release
	;
wsp_1	JSR check_score
	;
	LDA #$7F
	JSR query_keyboard
	CMP #$FF
	BEQ wsp_1
	;
wait_release
	LDA #$7F		; wait until released
	JSR query_keyboard
	CMP #$FF
	BNE wait_release
	;
	RTS
	
query_keyboard
	STA $FD30
query_joystick
	STA $FF08
	LDA $FF08
	RTS
	
	;
	; displays a message in the middle of the screen
	; expected: A: LO pointer to message
	;
write_message_pos           
	STX text_dest
	STY text_dest+1
	;
write_message
	STA message_ptr
	;
	LDA #text_author >> 8	; high byte is always the same
	STA message_ptr+1
	;
	LDA #mlen
write_message_3
	STA message_len+1
	;
	LDA #$47
	STA put_shade+1
	;
	LDY #$00
wm_01	TYA
	PHA
	LDA (message_ptr),y
	JSR write_letter
	PLA
	TAY
	LDA #$11		; gray
	JSR put_color
	;
message_len
	CPY #mlen
	BNE wm_01
	;
	RTS
	
clear_large
	LDY #$28-1
	LDA #$2A
	LDX #$07
	JSR clear_generic
	;
	LDA #$30
	STA chk_pos
	LDA #$2A
	STA chk_pos+1
	;
	JSR calc_lum_col_chk
	;
	LDX #$07		; fill color
c_2	LDY #mlen
c_1	LDA #$35
	STA (lptr),y
	TXA
	EOR #$07
	JSR change_block_col
	STA (cptr),y
	DEY
	BPL c_1
	;
	JSR inc_lptr_40
	;
	DEX
	BPL c_2
	;
	JSR reset_message_pos
	;
	RTS
	
restore_middle
	LDX #mlen
rm_01	LDA message_temp,X
	STA $19BE,X
	LDA message_temp+$20,X
	STA $1DBE,X
	DEX
	BPL rm_01
	;
	LDA #$6C
	BNE cm_11		; always jump
	;
clear_middle
	LDX #mlen
cm_10	LDA $19BE,X
	STA message_temp,X
	LDA $1DBE,X
	STA message_temp+$20,X
	DEX
	BPL cm_10
	;
	LDA #$2C
cm_11	LDY #$A8-1
	;
	LDX #$02		; number of lines to clear-1
	;
	; at this entry point:  X = lines
	;			Y = lo
	;			A = hi
	;
clear_generic
	STY chk_pos
	STY bptr
	;	
	STA chk_pos+1
	EOR #$40
	STA bptr+1
	;
cm_03	LDY #(mlen+2)*8
cm_02	LDA (chk_pos),y
	STA (bptr),y	
	LDA #$00
	STA (chk_pos),y
	DEY
	BNE cm_02
	;
	JSR add_chk_pos_140
	JSR inc_bptr_140
	;
	DEX
	BPL cm_03
	;
	; ---
	;
reset_message_pos
	LDA #$F0
	STA text_dest
	LDA #$2D
	STA text_dest+1
	;
	LDA #$BE
	STA lptr
	STA cptr
	LDA #$19
	STA lptr+1
	ORA #$04
	STA cptr+1
	;
	RTS
	
;sync	LDA $FF1D
;	CMP #$C3
;	BNE sync
;	RTS
	
	;
	; ##################################################################
	;
switch_up_down
	LDA cur_dir		; switch the flag first
	EOR #$01
	STA cur_dir
	;
	JSR move_up_down	; step back (to compensate)
	;			; then step one in the right direction
	;
move_up_down	
	LDA cur_dir
	BNE mv_down
	;
	; - up
	;
	LDX cur_y
	DEX
	BPL mv_03
	;
	LDA cur_pos		; * UP one char
	SEC
	SBC #$40
	STA cur_pos
	LDA cur_pos+1
	SBC #$01
	STA cur_pos+1
	;
	LDA y_offs		; switch y offset
	EOR #$01
	STA y_offs
	;
	LDX #$03
	;
mv_03	STX cur_y
	RTS
	;
	; ----------------------
	;
mv_down	LDX cur_y
	INX
	CPX #$04
	BNE mv_04
	;
	LDA cur_pos		; * DOWN one line
	CLC
	ADC #$40
	STA cur_pos
	LDA cur_pos+1
	ADC #$01
	STA cur_pos+1
	;
	LDA y_offs		; switch y offset
	EOR #$01
	STA y_offs
	;
	LDX #$00
mv_04	STX cur_y
	;
	RTS
	
	;
	; ##################################################################
	;
sub_chk_pos_280
	JSR sub_chk_pos_140
sub_chk_pos_140
	DEC chk_pos+1		; up one line
	LDA #$40
	DB $2C
sub_chk_pos_8
	LDA #$08		; left one char
sub_chk_pos
	STA sub_val+1
	;
	LDA chk_pos
	SEC
sub_val	SBC #$00
	STA chk_pos
	BCS scp_1
	DEC chk_pos+1
scp_1	;
	RTS

add_chk_pos_280
	JSR add_chk_pos_140	
add_chk_pos_140
	INC chk_pos+1		; down one line
	LDA #$40
	DB $2C
add_chk_pos_8
	LDA #$08		; right one char
add_chk_pos
	CLC
	ADC chk_pos
	STA chk_pos
	BCC acp_1
	INC chk_pos+1
acp_1	;
	RTS
	
	;
	; *** returns a pseudo-random number
	;	
random	
	LDA $FF00
	ADC $FF1E
	EOR $FF00
	SBC $FF1D
	;
	RTS
	
draw_level_back
	LDX #$00		; generate randomised temporary color table
	LDY #$00
	;
cs_2a	JSR random		; random number
	AND #$F0
	BEQ cs_2a
	;
	STA ctemp2
	;
cs_20	CPX #$00		; every time and half time
	BNE cs_21
	;
cs_2b	JSR random		; generate new color
	AND #$0F
	BEQ cs_2b
	;
	STA ctemp
	;
cs_21	LDA ctemp		; put two colors together
	ORA ctemp2
	STA temp_color,y
	;
	CPX #$00
	BNE cs_26
	;
cs_25	ASL a			; copy new color to upper half
	ASL a
	ASL a
	ASL a
	STA ctemp2
	;
cs_26	LDA background_lum,x	; luminance table repeats
	STA temp_lum,y
	;
	INX			; wrap X at lum table end
	CPX #background_lum_end - background_lum
	BNE cs_22
	LDX #$00
	;
cs_22	INY
	BPL cs_20
	;
	; --- write lives
	;
	JSR write_lives
	;
	; ---------
	;
	LDX #$10
il_01	LDA #$00		; init bitmap and lum pointers
	STA bptr-$10,x
	TXA
	ASL A			; tricky: each pointer is $0400 + previous
	STA bptr-$10+1,x
	DEX
	DEX
	BPL il_01
	;
	; ---
	;
	LDA #$46
	STA put_shade+1
	;
	JSR draw_top_bot_border	; top
	;
	; ---
	;
	LDA #28
	STA ctemp
	;
d_01	JSR draw_smallblock	; left side
	;
	LDX #28-1		; middle bitmap
cs_02	LDY #$07		; loop from 7-0
cs_01	LDA background_pattern,y	; with pattern repeating every 8 bytes
	STA (bptr),y
	DEY
	BPL cs_01
	;
	JSR inc_bptr_8		; increase bitmap pointer by 8 bytes
	;
	DEX
	BPL cs_02
	;
	LDY #28-1
	LDX ctemp
cs_10	LDA temp_color,x	; draw background colors
	STA (cptr),y
	STA (cptr2),y		; and save them too...
	LDA temp_lum,x
	STA (lptr),y
	STA (lptr2),y
	DEX
	DEY
	BPL cs_10
	;
	INC ctemp
	LDA #28
	JSR inc_lptr
	;
	JSR draw_smallblock	; right side
	JSR skip_10
	;
	LDA bptr+1
	CMP #$3C
	BNE d_01
	;
	; ---
	;
	;JSR draw_top_bot_border	; bottom
	
draw_top_bot_border
	LDX #30-1
d_sb_01	JSR draw_smallblock	; draw top border
	DEX
	BPL d_sb_01
	;
skip_10
	LDA #10*8
	JSR inc_bptr
	LDA #10
	DB $2C
	
inc_lptr_40
	LDA #$28
inc_lptr
	CLC
	ADC lptr
	STA lptr
	STA cptr
	STA lptr2
	STA cptr2
	BCC noi2
	INC lptr+1
	INC cptr+1
	INC lptr2+1
	INC cptr2+1
noi2	RTS

inc_bptr_140
	INC bptr+1
	LDA #$40
	DB $2C
	
inc_bptr_8
	LDA #$08
inc_bptr
	CLC
	ADC bptr
	STA bptr
	BCC noi1
	INC bptr+1
noi1	RTS

next_block_line
	LDA #40+12		; next line of blocks
	JSR inc_lptr
	;
	LDA #$A0
	JSR inc_bptr
	INC bptr+1
	;
	RTS

init_block_pos
	LDA #$48
	STA bptr
	LDA #$21
	STA bptr+1
	;
	LDA #$29
	STA lptr
	STA cptr
	LDA #$18
	STA lptr+1
	ORA #$04
	STA cptr+1
	;
	RTS

	;
	; *** draws a small gray 1x1 block on screen
	;     position is given by bptr/lptr/cptr
	;
	;     then moves to next character position
	;	
draw_smallblock
	LDY #$07
sb_01	LDA small_block,y
	STA (bptr),y
	DEY
	BPL sb_01
	;
	INY			; Y=0
	LDA #$11		; gray
	JSR put_color
	;
	TYA			; Y=1, inc lum/col map by 1
	JSR inc_lptr
	;
	JMP inc_bptr_8		; inc bitmap by 8
	
	;
	; *** draws a block according to X
	;
draw_new_block
	LDA blocks_ptr_lo,x
	STA block_ptr
	LDA blocks_ptr_hi,x
	STA block_ptr+1
	;
	; *** draws a big 2x2 block on screen
	;     dest position specified by bptr
	;
draw_block
	LDY #$0F
db_01	LDA (block_ptr),y	; copy top of block
	STA (bptr),y
	DEY
	BPL db_01
	;
	INY			; place color codes
	JSR put_color3
	LDY #$28
	JSR put_color2
	;
	LDA #$30
	JSR inc_bptr
	INC bptr+1
	;
	LDY #$1F		; bottom of block
db_02	LDA (block_ptr),y
	STA (bptr),y
	DEY
	CPY #$0F
	BNE db_02
	;
	; -
	;
	LDA bptr
	SEC
	SBC #$20
	STA bptr
	LDA bptr+1
	SBC #$01
	STA bptr+1
	;
db_03	LDA #$02
	JMP inc_lptr
	
skip_block
	LDA #$10
	JSR inc_bptr
	JMP db_03

put_color3
	LDA block_col
	AND #$0F
	TAX
	LDA shades,x
	STA put_shade+1
	;
put_color2
	JSR put_color1
put_color1
	LDA block_col
put_color
	STA (cptr),y
put_shade
	LDA #$47		; shades, self-mod
	STA (lptr),y
	INY
	RTS
	
write_title
	LDX #$00
ws_04	LDA text_title,x
	JSR write_letter
	INX
	CPX #text_title_end - text_title
	BNE ws_04
	;
	DEC text_dest+1
	LDY #$B8+7
	LDA #$26
	STA (text_dest),y
	LDY #$E3
	LDA #$44
	STA (text_dest),y
	LDY #$E3+8
	STA (text_dest),y
	LDA #$04
	LDY #$E1
	STA (text_dest),y
	LDA #$40
	LDY #$E1+8
	STA (text_dest),y
	;
	RTS
	
write_level_name
	LDX #$07
ln_01	JSR get_ROM_byte
	JSR write_letter
	DEX
	BPL ln_01
	;
	RTS
	
	;
	; *** writes a number (converts to ascii)
	;
write_number
	CMP #$00
	BNE wn_1
	LDA #"O"-64		; change "0" to "O"
	DB $2C
wn_1	ORA #$30	
	;
	; *** writes one letter on screen
	;     letter is expected in "A"
	;     uses Y, leaves X
	;
write_letter
	CMP #$94		; "t"
	BNE wl_02
	;
	LDY #letter_t & 255
	LDA #letter_t >> 8
	BNE wl_05
	;
wl_02	CMP #$0D		; "M"
	BNE wl_04
	;
	LDY #letter_M & 255
	LDA #letter_M >> 8
wl_05	STY wl_01+1
	STA wl_01+2
	BNE wl_03
	;
wl_04	STA wl_01+1		; store letter
	;
	LDA #$D0 >> 3		; address is $D000 + letter * 8
	STA wl_01+2
	;
	ASL wl_01+1		; * 8 (16bit)
	ROL wl_01+2
	ASL wl_01+1
	ROL wl_01+2
	ASL wl_01+1
	ROL wl_01+2
	;
wl_03	LDY #$07		; copy!
wl_01	LDA $0A0A,y		; self-mod
	ASL a
	PHA
	AND #$AA
	STA letter_tmp
	PLA
	ASL a
	AND #$AA
	PHA
	EOR letter_tmp		; keep only half filled pixels
	STA letter_tmp2
	;
	PLA
	AND letter_tmp		; keep full pixels
	LSR a			; use other multicolor
	ORA letter_tmp2
	;
	STA (text_dest),y	; draw
	DEY
	BPL wl_01
	;
	LDA text_dest		; go to next character position
	CLC
	ADC #$08
	STA text_dest
	BCC wl_noi1
	INC text_dest+1
wl_noi1	;
	RTS
	
	;
	; checks for immediate collisiont (side of screen)
	; position in: chk_pos
	;
check_small_collision
	LDY #$04
	LDA (chk_pos),y		; check immediate next char...
	CMP #$68		; for small block (side of screen)
	BEQ its_smallblock
	;
	CLC			; way is clear!
	RTS
	;
its_smallblock
	LDA #$00
	JSR do_sound
	;
	SEC			; flag reverse direction
	RTS
	
	;
	; this is called when player presses left/right
	;
	; if there's a block there,
	; (remove block then)
	; direction is reversed.
	;
	; also called during up/down move.
	;
	; the first position to be checked is in cur_pos2
	; the second position is chk_pos
	;
check_collision_diag
	LDA #$00
	STA chk_pos2+1
	;
check_collision
	;
	JSR calc_lum_col_chk
	;
	LDY #$00		; pre-load block color
	LDA (cptr),y
	STA block_col
	;
	LDY #$03
	LDA (chk_pos),y		; check next big char
	;
	CMP #$65		; check "die" block
	BNE not_die
	;
	JMP died		; change this to cheat
	;
not_die	CMP #$66		; check "star" block
	BNE not_star
	;
	LDA block_col		; it's a star!
	STA cur_col
	AND #$0F
	ORA #$60
	STA $FF16
	;
	LDA #$02
	JSR do_sound
	;
	SEC
	RTS
	;
not_star
	CMP #$40
	BNE not_disk
	;
	LDA chk_pos2+1		; can we move it? (high byte = 0 means flag NOT to move)
	BEQ cant_remove
	;
	LDY #$03
	LDA (chk_pos2),y	; check if disk can move
	CMP #$56
	BNE cant_remove
	;
	LDA block_col		; check color
	CMP cur_col
	BNE cant_remove		; if color is not matching, can't move disk
	;
	; *** MOVE DISK
	;	
	JSR clear_block		; erase it from the old position
	;
	LDA chk_pos2		; new pos
	STA lptr
	STA bptr
	LDA chk_pos2+1
	STA lptr+1
	STA bptr+1
	;
	JSR calc_lum_col	; calc lum/col map pos
	;
	LDX #$03		; value for disk
	JSR draw_new_block	; and draw it
	;
	LDA #$01		; mid freq sound
	JMP block_sound		; it's a disk
	;
not_disk
	CMP #$6A		; check for block
	BNE not_block
	;
	LDA block_col
	CMP cur_col
	;
	BNE cant_remove		; cannot remove block, not the right color
	;
	JSR clear_block		; remove it!
	;
	SED
	LDA blocks
	SEC
	SBC #$01
	STA blocks		; decrease number of blocks
	CLD
	;
	JSR write_blocks	; update screen
	;
	LDX #$04		; tens
	LDA block_col
	AND #$0F
	JSR add_score
	;
	LDA #$03		; high freq sound
	DB $2C
cant_remove
	LDA #$00		; low freq sound
	;
block_sound
	JSR do_sound
	;
	SEC
	RTS
	;
not_block
	CMP #$68		; check for small blocks
	BEQ cant_remove
	;
	CLC			; way is clear!
	RTS
	
	; --------------------------------------
do_sound
	STA $FF10
	LDA #$28
	STA $FF11
	STA $FF0F
	;
	RTS
	
do_noise
	STA noise0+1
	;
	LDX #$00
noise2	TXA
	TAY
noise1	STY $FF0E
	TYA
	LSR a
	LSR a
	LSR a
	LSR a
	LSR a
noise0	ORA #$40
	STA $FF11
	STA $FF10
	;
	DEY
	BNE noise1
	;
	DEX
	BNE noise2
	;
	RTS
	
	;
	; *** increases scrore: X: digit to add, A: value to add
	;
add_score
	CLC
	ADC score,x
	STA score,x
	CMP #10
	BCC as_01
	SBC #10
	STA score,x
	DEX
	LDA #$01
	BNE add_score
	;
as_01	RTS

check_score
	LDX #$05
csc_01	LDA score_curr,x
	CMP score,x
	BCC needs_update
	DEX
	BPL csc_01
	RTS
	;
needs_update
	LDX #$05
csc_02	LDA score_curr,x
	CLC
	ADC #$01
	STA score_curr,x
	CMP #$0A
	BCC write_score
	SBC #$0A
	STA score_curr,x
	DEX
	BPL csc_02
	;	
write_score
	LDA #$C0
	STA text_dest
	LDA #$29
	STA text_dest+1
	;
	LDX #$00
as_02	LDA score_curr,x
	JSR write_number
	INX
	CPX #$06
	BNE as_02
	;
	RTS
	
write_high_score
	LDA #$B0
	STA text_dest
	LDA #$31
	STA text_dest+1
	;
	LDA #text_high & 255
	LDX #text_high >> 8
	STA message_ptr
	STX message_ptr+1
	;
	LDA #12
	JSR write_message_3
	;
	LDX #$00
as_03	LDA score_high,x
	JSR write_number
	INX
	CPX #$06
	BNE as_03
	;
	RTS

inc_level
	SED
	LDA level
	CLC
	ADC #$01
	STA level
	CLD
	;	
write_level
	LDX #$D0
	STX text_dest
	LDX #$38
	STX text_dest+1
	;
	JMP write_two_digits
	
write_blocks
	LDA #$D0
	STA text_dest
	LDA #$33
	STA text_dest+1
	;
	LDA blocks
	;
write_two_digits
	PHA
	LSR a
	LSR a
	LSR a
	LSR a
	JSR write_number
	PLA
	AND #$0F
	JSR write_number
	;
	RTS
	
write_lives
	LDA #$C0
	STA bptr
	LDA #$2E
	STA bptr+1
	;
	LDX lives
	BEQ erase_lives
	;
wli_02	LDY #$07
wli_01	LDA sprite_lives,y
	STA (bptr),y
	DEY
	BPL wli_01
	;
	JSR inc_bptr_8
	DEX
	BNE wli_02
	;
erase_lives
	LDA #$06
	SEC
	SBC lives
	ASL a
	ASL a
	ASL a
	TAY
	DEY
	LDA #$00
wli_03	STA (bptr),y
	DEY
	BPL wli_03
	;
	RTS
	
	;
	; ***
	;
change_block_col
	AND #$07
	BNE cbc_1
	LDA #$07		; avoid black...
cbc_1	STA block_col
	ASL a
	ASL a
	ASL a
	ASL a
	ORA block_col
	STA block_col
	RTS

	;
	; *** erases one 2x2 block from the screen
	;
clear_block	
	LDY #$0F
clb_01	LDA background_pattern,y	; clear bitmap top
	STA (chk_pos),y
	DEY
	BPL clb_01
	;
	JSR add_chk_pos_140		; down one line
	;
	LDY #$0F
clb_02	LDA background_pattern,y	; clear bitmap bottom
	STA (chk_pos),y
	DEY
	BPL clb_02
	;
	; ---
	;
	LDY #$00
	JSR copy_two_colors	; copy top two bytes
	LDY #$28		; and lower two bytes
copy_two_colors
	JSR copy_one_color
copy_one_color
	LDA (lptr2),y
	STA (lptr),y
	LDA (cptr2),y
	STA (cptr),y
	INY
	RTS
	
calc_lum_col_chk
	LDA chk_pos		; copy chk_pos lum/col address
	STA lptr
	LDA chk_pos+1
	STA lptr+1
	;
calc_lum_col
	LSR lptr+1		; calculate lum map pointer
	ROR lptr		; /8 (16 bit)
	LSR lptr+1
	ROR lptr
	LSR lptr+1
	ROR lptr
	;
	LDA lptr		; copy to other 3 pointers
	STA cptr
	STA lptr2
	STA cptr2
	;
	LDA lptr+1		; adjust high byte
	CLC
	ADC #$14		; add $14 instead of $18
	STA lptr+1		; $2000>>3=$400 already added
	EOR #$08
	STA lptr2+1
	EOR #$0C
	STA cptr+1
	EOR #$08
	STA cptr2+1
	;
	RTS
	
cur_pos2_down
	LDA cur_pos
	CLC
	ADC #$40
	STA cur_pos2
	LDA cur_pos+1
	ADC #$01
	STA cur_pos2+1
	RTS
	
	;
	; *** saves the background under the sprite
	;
save_background
	LDY #$0F
sv_01	LDA (cur_pos),y
	STA sprite_temp,y
	DEY
	BPL sv_01
	;
	JSR cur_pos2_down
	;
	LDY #$0F
sv_02	LDA (cur_pos2),y
	STA sprite_temp + $10,y
	DEY
	BPL sv_02
	;
	RTS
	
	;
	; ########################################################################################
	; data
	;
	
add
	;DB $FF,$FF,$80,$80,$80,$80,$80,$01
	DB $01,$00,$FF,$FF, $01,$80,$00,$80
	DB $00,$01,$80,$00, $01,$01,$FF,$FF

freq
	DB $02,$2A,$42,$4C, $56,$71,$81,$95
	DB $A1,$A6,$AB,$B9, $C0,$CB,$D0,$D3
	DB $D6,$DC,$E0

base_lo
	DB base_c & 255,base_c & 255,base_c & 255,base_c & 255
	DB base_f & 255,base_f & 255,base_c & 255,base_c & 255
	DB base_g & 255,base_f & 255,base_c & 255,base_g2 & 255
;base_hi
;	DB base_c >> 8,base_c >> 8,base_c >> 8,base_c >> 8
;	DB base_f >> 8,base_f >> 8,base_c >> 8,base_c >> 8
;	DB base_g >> 8,base_f >> 8,base_c >> 8,base_g2 >> 8

freq2lo	DB $FE,$07,$A9,$D9,$06,$31,$59,$C5,$E5,$04,$3B, $54,$83,$AD,$C0,$E3,$02,$1E
freq2hi	DB $03,$00,$00,$00,$01,$01,$01,$01,$01,$02,$02, $02,$02,$02,$02,$02,$03,$03
	;  0    1   2   3   4   5   6   7   8   9    A   B   C   D   E   F   10  11
	;       C   D#  E   F   F#  G   A#  B   C    D   D#  F   G   G#  A#   C    D
	;align 256
base_c
	DB 1	; C
	DB $00
	DB 5	; F#
	DB 6	; G
	DB $00
	DB 1	; C
	;
	DB $10		; chord: C3,G2,D#2
	DB $D
	DB $B
	DB $10
	DB $D
	DB $B
	DB $10
	;
	DB $00
	DB $9	; C1
	DB $7	; A#
	DB $00
	DB $6	; G
	DB $FF
	
base_f
	DB $4	; F
	DB $00
	DB $8	; B
	DB $9	; C1
	DB $00
	DB $4	; F
	;
	DB $10		; chord: C3,G#2,F2
	DB $E
	DB $C
	DB $10
	DB $E
	DB $C
	DB $10
	;
	DB $00
	DB $1	; C
	DB $2	; D#
	DB $00
	DB $3	; E
	DB $FF
	
base_g
	DB $6	; G
	DB $00
	DB $9	; C1
	DB $A	; D1
	DB $00
	DB $6	; G
	;
	DB $11		; chord: D3,A#2,G2
	DB $F
	DB $D
	DB $11
	DB $F
	DB $D
	DB $11
	;
	DB $00
	DB $6	; G
	DB $4	; F
	DB $00
	DB $6	; G
	DB $FF
	
base_g2
	DB $6	; G
	DB $00
	DB $6	; G
	DB $6	; G
	DB $00
	DB $6	; G
	;
	DB $6	; G
	DB $00
	DB $6	; G
	DB $6	; G
	DB $00
	DB $6	; G
	;
	DB $FF

; DB $07,$00,$40,$00,$76,$00,$A9,$00,$D9,$00,$06,$01,$31,$01,$59,$01
; DB $7F,$01,$A3,$01,$C5,$01,$E5,$01,$04,$02,$20,$02,$3B,$02,$54,$02
; DB $6C,$02,$83,$02,$98,$02,$AD,$02,$C0,$02,$D2,$02,$E3,$02,$F3,$02
; DB $02,$03,$10,$03,$1E,$03,$2A,$03,$36,$03,$42,$03,$4C,$03,$56,$03
; DB $60,$03,$69,$03,$71,$03,$79,$03,$81,$03,$88,$03,$8F,$03,$95,$03
; DB $9B,$03,$A1,$03,$A6,$03,$AB,$03,$B0,$03,$B4,$03,$B9,$03,$BD,$03
; DB $C0,$03,$C4,$03,$C7,$03,$CB,$03,$CE,$03,$D0,$03,$D3,$03,$D6,$03
; DB $D8,$03,$DA,$03,$DC,$03,$DE,$03,$E0,$03,$E2,$03,$E4,$03,$FE,$03
	
	cmap "A",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26
	cmap "a",$81,$82,$83,$84,$85,$86,$87,$88,$89,$8A,$8B,$8C,$8D,$8E,$8F,$90,$91,$92,$93,$94,$95,$96,$97,$98,$99,$9A
text_data
	DB "Score:",$00
	DB "Lives:",$00
	DB "Blocks",$00
	DB "Level:",$00
text_data_end

text_author
	DB "by Csabo/LOD  2OO4"
	
text_start_level
	DB "Starting level: O1"
	
text_high
	DB "High score: "

text_paused
	DB "   GAME  PAUSED   "
	
text_press_space
	DB "   PRESS  SPACE   "
	
text_level_cleared
	DB "  LEVEL  CLEARED  "

text_all_levels_cleared
	DB "ALL LEVELS CLEARED"
	
text_congrats
	DB " CONGRATULATIONS! "
	
text_game_over
	DB " G A M E  O V E R "

text_title
	DB "OuadrHHon"
text_title_end
	
level_names
	DB "Colored ","  Gem   "	; 1
	DB "Meet the","Blockers"	; 2
	DB " Candy  ","  Shop  "	; 3
	DB "Fill  or","  File  "
	DB "  BIG   ","  Wall  "	; 5
	DB "Storage ","Facility"	; 6
	DB " I made "," this ! "	; 7
	DB " Trade  ","  Mark  "
	DB " in da  "," house  "
	;
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	;
	DB "  Real  ","  Easy  "	; 10
	DB "  Four  ","  Turns "	; 11
	DB "   GO   "," Around "
	DB " Ghost  ","  Town  "
	DB "Rainbow "," Icicles"
	DB "  Wire  ","  Fence "	; 15
	DB "Shop Re-","visited "	; 16
	DB "Only one","  Green " 	; 17
	DB " Mine-  ","  Field "	; 18
	DB " Corner "," Bounce "	; 19
	;
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	DB "        ","        "
	;
	DB "Lando's "," Trap!  "	; 20
	

shades
	DB $00,$46,$37,$47,$47,$47,$37,$57
	
letter_t
	DB $18,$18,$7E,$18,$18,$18,$0E,$00
letter_M
	DB $6E,$7E,$7E,$6E,$66,$66,$66,$00
	
background_pattern
	DB $56,$55,$5A,$56,$6A,$5A,$AA,$6A	; 1 char twice, for clearing blocks
	DB $56,$55,$5A,$56,$6A,$5A,$AA,$6A
background_lum
	DB $00,$20,$32,$43,$54,$45,$34,$23,$02
background_lum_end

blocks_ptr_lo
	DB block & 255
	DB block_star & 255
	DB block_die & 255
	DB block_disk & 255
	DB small_block & 255
	DB small_block & 255
	DB small_block & 255
	
sprite_ptrs_lo
	DB sprite0 & 255
	DB sprite1 & 255
	DB sprite2 & 255
	DB sprite3 & 255

blocks_ptr_hi	
	DB block >> 8
	DB block_star >> 8
	DB block_die >> 8
	DB block_disk >> 8
	DB small_block >> 8
	DB small_block >> 8
	DB small_block >> 8
	
sprite_ptrs_hi
	DB sprite0 >> 8
	DB sprite1 >> 8
	DB sprite2 >> 8
	DB sprite3 >> 8
	
block	; 16*16
	DB $55,$6A,$6A,$6A,$6A,$6A,$6A,$6A
	DB $56,$A8,$A8,$A8,$A8,$A8,$A8,$A8

	DB $6A,$6A,$6A,$6A,$6A,$6A,$6A,$80
	DB $A8,$A8,$A8,$A8,$A8,$A8,$A8,$00
	
block_star	; 16*16
	DB $55,$6A,$6A,$66,$66,$65,$69,$55
	DB $56,$A8,$A8,$98,$98,$58,$68,$54

	DB $55,$69,$65,$66,$66,$6A,$6A,$80
	DB $54,$68,$58,$98,$98,$A8,$A8,$00
	
block_die	; 16*16
	DB $55,$6A,$69,$65,$65,$61,$61,$65
	DB $56,$A8,$68,$58,$58,$48,$48,$58

	DB $68,$69,$6A,$66,$65,$66,$6A,$80
	DB $28,$68,$A8,$98,$58,$98,$A8,$00
	
block_disk	; 16*16
	DB $55,$6A,$40,$40,$6A,$6A,$69,$69
	DB $56,$A8,$A8,$A8,$A8,$A8,$68,$28

	DB $68,$6A,$69,$69,$69,$68,$6A,$80
	DB $28,$A8,$68,$28,$28,$28,$A8,$00

small_block
	DB $56,$68,$68,$68,$68,$68,$68,$80
	DB $56,$68,$68,$68,$68,$68,$68,$80
	
	DB $56,$68,$68,$68,$68,$68,$68,$80
	DB $56,$68,$68,$68,$68,$68,$68,$80

sprite_lives
	DB $30,$FC,$FC,$FC,$FC,$FC,$30,$00	; smaller ball for "lives"
sprite0
	DB $00,$00,$00,$00,$00,$00,$00,$00
	DB $3C,$FF,$FF,$FF,$FF,$FF,$FF,$3C
	DB $00,$00,$00,$00,$00,$00,$00,$00
sprite1
	DB $00,$00,$00,$00,$00,$00,$00,$00
	DB $0F,$3F,$3F,$3F,$3F,$3F,$3F,$0F
	DB $00,$C0,$C0,$C0,$C0,$C0,$C0,$00
	DB $00,$00,$00,$00,$00,$00,$00,$00
sprite2
	DB $00,$00,$00,$00,$00,$00,$00,$00
	DB $03,$0F,$0F,$0F,$0F,$0F,$0F,$03
	DB $C0,$F0,$F0,$F0,$F0,$F0,$F0,$C0
	DB $00,$00,$00,$00,$00,$00,$00,$00
sprite3
	DB $00,$00,$00,$00,$00,$00,$00,$00
	DB $00,$03,$03,$03,$03,$03,$03,$00
	DB $F0,$FC,$FC,$FC,$FC,$FC,$FC,$F0
	DB $00,$00,$00,$00,$00,$00,$00,$00
	
level_ptr_lo
	DB (level01-1) & 255
	DB (level02-1) & 255
	DB (level03-1) & 255
	DB (level04-1) & 255
	DB (level05-1) & 255
	DB (level06-1) & 255
	DB (level07-1) & 255
	DB (level08-1) & 255
	DB (level09-1) & 255
	DB 0,0,0,0,0,0
	DB (level10-1) & 255
	DB (level11-1) & 255
	DB (level12-1) & 255
	DB (level13-1) & 255
	DB (level14-1) & 255
	DB (level15-1) & 255
	DB (level16-1) & 255
	DB (level17-1) & 255
	DB (level18-1) & 255
	DB (level19-1) & 255
	DB 0,0,0,0,0,0
	DB (level20-1) & 255
	
level_ptr_hi
	DB (level01-1) >> 8
	DB (level02-1) >> 8
	DB (level03-1) >> 8
	DB (level04-1) >> 8
	DB (level05-1) >> 8
	DB (level06-1) >> 8
	DB (level07-1) >> 8
	DB (level08-1) >> 8
	DB (level09-1) >> 8
	DB 0,0,0,0,0,0
	DB (level10-1) >> 8
	DB (level11-1) >> 8
	DB (level12-1) >> 8
	DB (level13-1) >> 8
	DB (level14-1) >> 8
	DB (level15-1) >> 8
	DB (level16-1) >> 8
	DB (level17-1) >> 8
	DB (level18-1) >> 8
	DB (level19-1) >> 8
	DB 0,0,0,0,0,0
	DB (level20-1) >> 8
;
; level data format: upper 5 bits: number of times to repeat
;                    lower 3 bits: block type:
;					0 : block
;					1 : star
;					2 : die
;					3 : disk
;				    4,5,6 : wall
;					7 : nothing
;
level20
	DB 10*8+7
	DB $80+03*8+0
	DB 2
	DB 02*8+0
	DB $80+03*8+1
	DB 01*8+7
	DB $80+05*8+1
	DB 06*8+0
	DB 01*8+3
	DB 01*8+7
	;
	DB $80+03*8+0
	DB 5
	DB 02*8+0
	DB $80+02*8+0
	DB 01*8+7
	DB 3
	DB 08*8+0
	DB 01*8+7
	DB 02*8+0
	DB $80+05*8+0
	DB 01*8+0
	DB 10*8+7
	DB 01*8+0
	DB 01*8+7
	DB $80+06*8+3
	DB 02*8+7
	DB $80+06*8+1
	DB 5
	DB 06*8+0
	DB 01*8+3
	DB 01*8+7
	DB $80+03*8+0
	DB 6
	DB 02*8+0
	DB 02*8+7
	;
	DB 3
	DB 08*8+0
	DB 01*8+7
	DB 02*8+0
	DB 01*8+2
	DB 11*8+7
	DB 02*8+0
	DB 03*8+7
	;
	DB $80+02*8+1
	DB 6
	DB 07*8+0
	DB 01*8+7
	DB 3
	DB 02*8+0
	DB 01*8+7
	DB 01*8+0
	DB 01*8+7
	DB 02*8+0
	DB 04*8+2
	DB 02*8+0
	DB 04*8+7
	DB 01*8+2
	DB 02*8+7
	DB 06*8+0
	DB 15*8+7
	DB 03*8+2
	DB 01*8+0
	DB 01*8+2
	;
	DB 0,$22
	
level19
	DB 2
	DB 06*8+2
	DB 02*8+7
	DB 5
	DB 06*8+2
	;
	DB 2
	DB 01*8+2
	DB $80+05*8+0
	DB $7
	DB 01*8+7
	DB 03*8+2
	DB 02*8+7
	DB 5
	DB 03*8+2
	DB 01*8+7
	DB $80+04*8+0
	DB 01*8+2
	;
	DB 2
	DB 01*8+2
	DB 04*8+7
	DB 01*8+2
	DB 02*8+7
	DB 5
	DB 01*8+2
	DB 04*8+7
	DB 01*8+2
	;
	DB 2
	DB 02*8+2
	DB 10*8+7
	DB 5
	DB 02*8+2
	;
	DB 14*8+7
	DB 14*8+7
	DB 14*8+7
	;
	DB 2
	DB 02*8+2
	DB 10*8+7
	DB 5
	DB 02*8+2
	;
	DB 2
	DB 01*8+2
	DB 04*8+7
	DB 01*8+2
	DB 02*8+7
	DB 5
	DB 01*8+2
	DB 04*8+7
	DB 01*8+2
	;
	DB 2
	DB 01*8+2
	DB $80+05*8+1
	DB 01*8+7
	DB 03*8+2
	DB 02*8+7
	DB 5
	DB 03*8+2
	DB 01*8+7
	DB $80+04*8+1
	DB 01*8+2
	;
	DB 2
	DB 06*8+2
	DB 02*8+7
	DB 5
	DB 06*8+2
	;
	DB 0,$22

level18
	DB 1
	DB 14*8+4
	DB 14*8+7
	DB 13*8+7
	DB $80+02*8+0
	DB 13*8+4
	DB 2
	DB 03*8+0
	DB $80+05*8+2
	DB 09*8+0
	DB $80+05*8+2
	DB 06*8+0
	DB $80+05*8+2
	DB 08*8+0
	DB 08*8+0
	DB $80+05*8+2
	DB 08*8+0
	DB $80+05*8+2
	DB 11*8+0
	DB 08*8+0
	DB $80+05*8+2
	DB 04*8+0
	DB $80+05*8+2
	DB 11*8+0
	DB 08*8+0
	DB $80+05*8+2
	DB 04*8+0
	DB $80+05*8+2
	DB 02*8+0
	;
	DB 0,$22
	
level17
	DB 1
	DB 06*8+4
	DB 01*8+7
	DB 4
	DB 02*8+0
	DB 02*8+7
	DB $80+06*8+0
	DB 01*8+7
	DB 01*8+2
	DB $80+01*8+4
	DB 01*8+2
	DB $80+01*8+4
	DB 01*8+2
	;
	DB $80+01*8+4
	DB 01*8+2
	DB 01*8+7
	DB 02*8+0
	DB 01*8+7
	DB 01*8+1
	DB $80+06*8+0
	DB 01*8+7
	DB $80+02*8+0
	;
	DB $80+01*8+4
	DB 06*8+7
	DB 02*8+0
	DB 01*8+7
	DB 01*8+2
	DB 6
	DB 03*8+0
	;
	DB $80+01*8+4
	DB 06*8+7
	DB 4
	DB 02*8+0
	DB 01*8+7
	DB 01*8+1
	DB 01*8+0
	DB 02*8+7
	;
	DB $80+01*8+4
	DB 06*8+7
	DB 02*8+0
	DB 01*8+7
	DB 01*8+2
	DB 01*8+0
	DB $80+02*8+1
	DB 01*8+7
	;
	DB $80+01*8+4
	DB 01*8+7
	DB 01*8+0
	DB 01*8+2
	DB 01*8+0
	DB 01*8+2
	DB 01*8+7
	DB 02*8+0
	DB 01*8+7
	DB 01*8+1
	DB 01*8+0
	DB $80+05*8+0
	;
	DB 7
	;
	DB 01*8+7
	DB $80+01*8+4
	DB 06*8+7
	DB 02*8+0
	DB 01*8+7
	DB 01*8+2
	DB 01*8+0
	DB $80+06*8+1
	DB 01*8+7
	;
	DB $80+01*8+4
	DB 06*8+7
	DB 4
	DB 02*8+0
	DB 01*8+7
	DB 01*8+1
	DB 01*8+0
	DB 02*8+7
	;
	DB $80+01*8+4
	DB 06*8+7
	DB 02*8+0
	DB 01*8+7
	DB 01*8+2
	DB 2
	DB 03*8+0
	;
	DB $80+01*8+4
	DB 4
	DB 01*8+2
	DB $80+01*8+4
	DB 01*8+2
	DB $80+01*8+4
	DB 01*8+2
	DB 01*8+7
	DB 02*8+0
	DB 01*8+7
	DB 01*8+1
	DB $80+02*8+0
	DB 01*8+7
	DB $80+06*8+0
	;
	DB 1
	DB 06*8+4
	DB 01*8+7
	DB 4
	DB 02*8+0
	DB 02*8+7
	DB $80+02*8+0
	DB 01*8+7
	DB 01*8+2
	;
	DB 0,$55

level16
	DB $80+07*8+1
	DB 01*8+7
	DB $80+05*8+0
	DB 01*8+7
	DB $80+03*8+0
	DB 01*8+7
	DB $80+06*8+0
	DB 01*8+7
	DB $80+04*8+0
	DB 01*8+7
	DB $80+02*8+0
	;
	DB 7
	;
	DB 03*8+7
	DB 1
	DB 01*8+4
	DB $80+07*8+0
	DB 01*8+4
	DB $80+05*8+3
	DB 01*8+4
	DB $80+03*8+3
	DB 01*8+4
	DB $80+06*8+3
	DB 01*8+4
	DB $80+04*8+3
	DB 01*8+4
	DB $80+02*8+3
	DB 01*8+4
	DB 01*8+7
	;
	DB 14*8+7
	DB 14*8+7
	;
	DB 01*8+7
	DB $80+05*8+0
	DB 01*8+7
	DB $80+03*8+0
	DB 01*8+7
	DB $80+06*8+0
	DB 01*8+7
	DB $80+04*8+0
	DB 01*8+7
	DB $80+02*8+0
	DB 04*8+7
	;
	DB 01*8+4
	DB $80+05*8+0
	DB 01*8+4
	DB $80+03*8+0
	DB 01*8+4
	DB $80+06*8+0
	DB 01*8+4
	DB $80+04*8+0
	DB 01*8+4
	DB $80+02*8+0
	DB 01*8+4
	DB 01*8+7
	DB 01*8+4
	DB 01*8+7
	;
	DB 01*8+4
	DB $80+05*8+0
	DB 01*8+4
	DB $80+03*8+0
	DB 01*8+4
	DB $80+06*8+0
	DB 01*8+4
	DB $80+04*8+0
	DB 01*8+4
	DB $80+02*8+0
	DB 01*8+4
	DB 01*8+7
	DB 01*8+4
	DB 01*8+7
	;
	DB 01*8+4
	DB $80+05*8+0
	DB 01*8+4
	DB $80+05*8+1
	DB 01*8+4
	DB $80+03*8+1
	DB 01*8+4
	DB $80+06*8+1
	DB 01*8+4
	DB $80+04*8+1
	DB 01*8+4
	DB $80+02*8+1
	DB 01*8+4
	DB 01*8+7
	;
	DB 13*8+4
	DB 01*8+7
	;
	DB $80+02*8+0
	DB $80+04*8+0
	DB $80+06*8+0
	DB $80+03*8+0
	DB $80+05*8+0
	DB $80+07*8+0
	DB 08*8+7
	;
	DB $80+02*8+0
	DB $80+04*8+0
	DB $80+06*8+0
	DB $80+03*8+0
	DB $80+05*8+0
	DB $80+07*8+0
	DB 08*8+7
	;
	DB 0,$11

level15
	DB $80+06*8+1
	DB 2
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 02*8+7
	;
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 02*8+7
	;
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 01*8+7
	DB 7
	DB 03*8+7
	;
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 02*8+7
	;
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 02*8+7
	;
	DB 1
	DB 13*8+4
	DB 01*8+7
	DB 3
	DB 13*8+2
	DB 6
	DB $80+02*8+0
	DB 13*8+0
	DB $80+02*8+0
	DB 13*8+0
	DB $80+02*8+0
	DB 13*8+0
	DB $80+02*8+0
	DB 13*8+0
	;
	DB 0,$22

level14
	DB 01*8+7
	DB $80+02*8+0
	DB 01*8+7
	DB $80+04*8+0
	DB 01*8+7
	DB $80+06*8+0
	DB 01*8+7
	DB $80+03*8+0
	DB 01*8+7
	DB $80+05*8+0
	DB 01*8+7
	DB $80+07*8+0
	DB 01*8+7
	DB $80+07*8+1
	;
	DB 01*8+7
	DB 7
	DB 12*8+7
	DB $80+05*8+1
	DB 13*8+7
	DB $80+03*8+1
	DB 13*8+7
	DB $80+06*8+1
	DB 13*8+7
	DB $80+04*8+1
	DB 13*8+7
	DB $80+02*8+1
	DB 13*8+7
	DB 1
	DB 02*8+2
	;
	DB $80+02*8+0
	DB 01*8+2
	DB $80+04*8+0
	DB 01*8+2
	DB $80+06*8+0
	DB 01*8+2
	DB $80+03*8+0
	DB 01*8+2
	DB $80+05*8+0
	DB 01*8+2
	DB $80+07*8+0
	DB 03*8+2
	;
	DB $80+02*8+0
	DB 01*8+2
	DB $80+04*8+0
	DB 01*8+2
	DB $80+06*8+0
	DB 01*8+2
	DB $80+03*8+0
	DB 01*8+2
	DB $80+05*8+0
	DB 01*8+2
	DB $80+07*8+0
	DB 03*8+2
	;
	DB $80+02*8+0
	DB 01*8+2
	DB $80+04*8+0
	DB 01*8+2
	DB $80+06*8+0
	DB 01*8+2
	DB $80+03*8+0
	DB 01*8+2
	DB $80+05*8+0
	DB 01*8+2
	DB $80+07*8+0
	DB 02*8+2
	DB 14*8+2
	;
	DB 0,$11
	
level13
	DB 7
	DB 6
	DB 03*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB $80+07*8+1
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB $80+07*8+0
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 03*8+7
	DB 01*8+3
	DB 01*8+7
	DB 01*8+3
	;
	DB 0,$66
	
level12
	DB 3
	DB 15*8+0
	DB 2
	DB 12*8+0
	DB 3
	DB 02*8+0
	DB $80+02*8+0
	DB 04*8+7
	DB $80+02*8+1
	DB $7			; ball
	DB 05*8+7
	DB $80+02*8+0
	DB 02*8+0
	DB $80+02*8+0
	DB 01*8+7
	;
	DB 6
	DB 03*8+2
	DB 02*8+7
	DB 03*8+2
	DB 01*8+7
	DB 3
	;
	DB $80+02*8+0
	DB 02*8+0
	DB $80+02*8+0
	DB 01*8+7
	;
	DB $80+06*8+2
	DB 04*8+7
	DB $80+06*8+2
	DB 01*8+7
	DB $80+06*8+2
	DB 01*8+7
	;
	DB $80+02*8+0
	DB 02*8+0
	DB $80+02*8+0
	DB 01*8+7
	;
	DB $80+06*8+2
	DB 01*8+7
	DB $80+06*8+2
	DB 02*8+7
	DB $80+06*8+2
	DB 01*8+7
	DB $80+06*8+2
	DB 01*8+7
	;
	DB $80+02*8+0
	DB 02*8+0
	DB $80+02*8+0
	DB 01*8+7
	;
	DB $80+06*8+2
	DB 01*8+7
	DB $80+06*8+2
	DB 02*8+7
	DB $80+06*8+2
	DB 01*8+7
	DB $80+06*8+2
	DB 01*8+7
	;
	DB $80+02*8+0
	DB 02*8+0
	DB $80+02*8+0
	DB 01*8+7
	;
	DB 6
	DB 03*8+2
	DB 02*8+7
	DB 03*8+2
	DB 01*8+7
	DB 3
	;
	DB $80+02*8+0
	DB 02*8+0
	DB $80+02*8+0
	DB 10*8+7
	;
	DB $80+02*8+0
	DB 02*8+0
	DB 2
	DB 05*8+0
	DB 01*8+7
	DB 06*8+0
	DB 3
	DB 15*8+0
	;
	DB 0,$33
	
level11
	DB 7
	;
	DB 14*8+7
	DB $80+01*8+4
	DB 6
	DB 12*8+3
	DB 02*8+7
	DB 14*8+7
	DB 14*8+7
	DB 13*8+0
	DB 01*8+7
	DB 4
	DB 13*8+2
	DB 01*8+7
	DB 1
	DB 12*8+4
	DB $80+05*8+1
	DB 14*8+7
	DB 2
	DB 01*8+1
	DB 12*8+3
	DB 01*8+7
	DB 5
	DB 01*8+0
	DB 13*8+7
	DB 02*8+0
	;
	DB 0,$66
	
level10
	DB 6
	DB 12*8+7
	DB 01*8+0
	DB $80+02*8+1
	DB 02*8+7
	DB 10*8+2
	DB 04*8+7
	DB 1
	DB 10*8+4
	DB 04*8+7
	DB 01*8+4
	DB 6
	DB 08*8+2
	DB 1
	DB 01*8+4
	DB 04*8+7
	DB 01*8+4
	DB 2
	DB 08*8+0
	DB $80+01*8+4
	DB 6
	DB 04*8+7
	DB 14*8+7
	DB 10*8+3
	DB 04*8+7
	DB 14*8+7
	DB 2
	DB 10*8+0
	DB 04*8+7
	DB 6
	DB 10*8+2
	DB 02*8+7
	DB $80+02*8+1
	DB 01*8+1
	DB 10*8+7
	DB $80+05*8+1
	DB $80+02*8+1
	;
	DB 0,$22
	
level09
	DB 01*8+7
	DB $7
	DB 05*8+7
	DB $80+05*8+3
	DB 12*8+7
	DB 2
	DB 03*8+0
	DB 10*8+7
	DB 05*8+0
	DB 08*8+7
	DB 07*8+0
	DB 07*8+7
	DB 6
	DB 01*8+1
	DB 01*8+2
	DB 03*8+0
	DB 01*8+2
	DB 01*8+1
	DB 07*8+7
	;
	DB 01*8+1
	DB 05*8+0
	DB 01*8+1
	DB 07*8+7
	;
	DB 01*8+1
	DB 05*8+0
	DB 01*8+1
	DB 07*8+7
	;
	DB 01*8+1
	DB 05*8+0
	DB 01*8+1
	DB 07*8+7
	;
	DB 01*8+1
	DB 05*8+0
	DB $80+02*8+1
	DB 07*8+7
	;
	DB 01*8+1
	DB 05*8+0
	DB 01*8+1
	DB 04*8+7
	;
	DB 1
	DB 01*8+2
	DB 01*8+4
	DB 09*8+2
	DB 01*8+4
	DB 01*8+2
	DB 01*8+4
	;
	DB 0,$55

level08
	DB 3
	DB 14*8+2
	DB 07*8+7
	DB 7
	DB 12*8+7
	DB 12*8+7
	DB 12*8+7
	DB 4
	DB 05*8+0
	DB 02*8+7
	DB $80+02*8+0
	DB 03*8+7
	DB $80+02*8+0
	DB 04*8+7
	DB 01*8+0
	DB 04*8+7
	DB 2
	DB 02*8+0
	DB 01*8+7
	DB 02*8+0
	DB 04*8+7
	DB $80+04*8+0
	DB 04*8+7
	DB 01*8+0
	DB 01*8+7
	DB $80+04*8+1
	DB 01*8+7
	DB 01*8+0
	;
	DB 04*8+7
	DB $80+04*8+0
	DB 04*8+7
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	;
	DB 04*8+7
	DB $80+04*8+0
	DB 04*8+7
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	;
	DB 04*8+7
	DB $80+04*8+0
	DB 04*8+7
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB 01*8+7
	;
	DB 1
	DB 14*8+4
	;
	DB 0,$22

level07
	DB 06*8+7
	DB $80+05*8+1
	DB $80+02*8+1
	DB 12*8+7
	DB $80+04*8+1
	DB $80+03*8+1
	DB 06*8+7
	;
	DB 14*8+7
	DB 14*8+7
	DB 14*8+7
	;
	DB 2
	DB 02*8+0
	DB 3
	DB 03*8+0
	DB 4
	DB 01*8+7
	DB 01*8+0
	DB 01*8+7
	DB 5
	DB 02*8+0
	DB 01*8+7
	DB 6
	DB 03*8+0
	;
	DB 2
	DB 01*8+0
	DB 01*8+7
	DB 3
	DB 01*8+0
	DB 02*8+7
	DB 4
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 5
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 6
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	;
	DB 2
	DB 01*8+0
	DB 01*8+7
	DB 3
	DB 03*8+0
	DB 4
	DB 03*8+0
	DB 5
	DB 02*8+0
	DB 01*8+7
	DB 6
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	;
	DB 2
	DB 01*8+0
	DB 01*8+7
	DB 3
	DB 02*8+7
	DB 01*8+0
	DB 4
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 5
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 6
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	;
	DB 2
	DB 02*8+2
	DB 3
	DB 03*8+2
	DB 4
	DB 01*8+2
	DB 01*8+7
	DB 01*8+2
	DB 5
	DB 02*8+2
	DB 01*8+7
	DB 6
	DB 03*8+2
	;
	DB 1
	DB 14*8+2
	;
	DB 0,$66

level06
	DB 1
	DB 03*8+4
	DB 6
	DB 03*8+0
	DB 1
	DB 02*8+4
	DB 4
	DB 03*8+0
	DB 1
	DB 04*8+4
	DB 01*8+7
	DB 6
	DB 04*8+0
	DB 1
	DB 02*8+4
	DB 4
	DB 04*8+0
	DB 01*8+7
	DB $80+01*8+4
	DB $80+06*8+1
	;
	DB 7
	;
	DB 01*8+7
	DB 1
	DB 10*8+4
	DB 01*8+7
	DB $80+04*8+1
	DB 01*8+4
	DB 01*8+7
	DB 3
	DB 04*8+0
	DB 1
	DB 02*8+4
	DB $80+07*8+0
	DB $80+07*8+0
	DB $80+07*8+0
	DB $80+07*8+0
	DB 01*8+7
	DB $80+01*8+4
	DB $80+03*8+1
	DB 01*8+7
	DB 10*8+4
	DB 01*8+7
	DB $80+07*8+1
	DB 01*8+4
	DB 01*8+7
	DB 2
	DB 04*8+0
	DB 1
	DB 02*8+4
	DB 5
	DB 04*8+0
	DB 01*8+7
	DB 1
	DB 02*8+4
	DB 01*8+7
	DB 10*8+4
	DB 01*8+7
	DB 02*8+4
	DB 12*8+7
	DB 05*8+4
	DB $80+02*8+1
	DB 01*8+4
	DB $80+02*8+0
	DB $80+05*8+0
	DB 01*8+4
	DB $80+05*8+1
	DB 04*8+4
	DB 3
	DB 14*8+2
	;
	DB 0,$55
	
level05
	DB 5
	DB 14*8+7
	DB 14*8+0
	DB 14*8+0
	DB 14*8+0
	DB 14*8+0
	DB 14*8+7
	DB 14*8+7
	DB 14*8+7
	DB 07*8+7
	DB $7		; ball
	DB 12*8+7
	DB 05*8+0
	DB 04*8+7
	DB 6
	DB 14*8+2
	DB 0,$55
	
level04
	DB 2
	DB 05*8+7
	DB 01*8+3
	DB 02*8+7
	DB 01*8+2
	DB 02*8+7
	DB 03*8+0
	DB 04*8+7
	DB $80+01*8+4
	DB 06*8+7
	DB 02*8+0
	DB $80+04*8+1
	DB 02*8+7
	DB 01*8+3
	DB 01*8+7
	DB $80+01*8+4
	DB $80+04*8+0
	DB 05*8+7
	DB 03*8+0
	DB 1
	DB 02*8+4
	DB 01*8+7
	DB 11*8+4
	DB 14*8+7
	;
	DB 4
	DB 03*8+0
	DB 01*8+7
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB $80+02*8+0
	DB $80+02*8+0
	DB 01*8+7
	;
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB 03*8+7
	;
	DB 03*8+0
	DB 01*8+7
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB $80+02*8+0
	DB $80+02*8+0
	DB 01*8+7
	;
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB 01*8+7
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB 03*8+7
	;
	DB 01*8+0
	DB 03*8+7
	DB 01*8+0
	DB 01*8+7
	DB 03*8+0
	DB 01*8+7
	DB 03*8+0
	;
	DB 0,$22
	
level03
	DB $80+07*8+1
	DB 01*8+7
	DB $80+05*8+0
	DB 01*8+7
	DB $80+03*8+0
	DB 01*8+7
	DB $80+06*8+0
	DB 01*8+7
	DB $80+04*8+0
	DB 01*8+7
	DB $80+02*8+0
	;
	DB 7
	;
	DB 03*8+7
	DB 1
	DB 01*8+4
	DB $80+07*8+0
	DB 01*8+4
	DB $80+05*8+3
	DB 01*8+4
	DB $80+03*8+3
	DB 01*8+4
	DB $80+06*8+3
	DB 01*8+4
	DB $80+04*8+3
	DB 01*8+4
	DB $80+02*8+3
	DB 01*8+4
	DB 01*8+7
	;
	DB 14*8+7
	;
	DB 01*8+7
	DB $80+05*8+0
	DB 01*8+7
	DB $80+03*8+0
	DB 01*8+7
	DB $80+06*8+0
	DB 01*8+7
	DB $80+04*8+0
	DB 01*8+7
	DB $80+02*8+0
	DB 04*8+7
	;
	DB 01*8+4
	DB $80+05*8+0
	DB 01*8+4
	DB $80+03*8+0
	DB 01*8+4
	DB $80+06*8+0
	DB 01*8+4
	DB $80+04*8+0
	DB 01*8+4
	DB $80+02*8+0
	DB 01*8+4
	DB 01*8+7
	DB 01*8+4
	DB 01*8+7
	;
	DB 01*8+4
	DB $80+05*8+0
	DB 01*8+4
	DB $80+03*8+0
	DB 01*8+4
	DB $80+06*8+0
	DB 01*8+4
	DB $80+04*8+0
	DB 01*8+4
	DB $80+02*8+0
	DB 01*8+4
	DB 01*8+7
	DB 01*8+4
	DB 01*8+7
	;
	DB 01*8+4
	DB $80+05*8+0
	DB 01*8+4
	DB $80+05*8+1
	DB 01*8+4
	DB $80+03*8+1
	DB 01*8+4
	DB $80+06*8+1
	DB 01*8+4
	DB $80+04*8+1
	DB 01*8+4
	DB $80+02*8+1
	DB 01*8+4
	DB 01*8+7
	;
	DB 13*8+4
	DB 01*8+7
	;
	DB 0,$11
	
level02
	DB 2
	DB 12*8+7
	DB 01*8+3
	DB 02*8+7
	DB $80+05*8+1
	DB 10*8+0
	DB 01*8+3
	DB 02*8+7
	DB 1
	DB 12*8+4
	;
	DB 5
	DB 13*8+7
	DB 01*8+3
	DB 02*8+7
	DB $80+06*8+1
	DB 10*8+0
	DB 01*8+3
	DB 02*8+7
	DB 1
	DB 12*8+4
	;
	;
	DB 14*8+7
	DB 02*8+7
	DB $80+02*8+1
	DB 6
	DB 11*8+0
	DB 02*8+7
	DB 1
	DB 04*8+4
	DB 3
	DB 04*8+2
	DB 1
	DB 04*8+4
	DB 02*8+7
	DB 3
	DB 04*8+2
	DB 1
	DB 04*8+4
	DB 3
	DB 04*8+2
	;
	DB 0,$77

level01
	DB 14*8+7
	DB 06*8+7
	DB 2
	DB 02*8+0
	DB 11*8+7
	DB 04*8+0
	DB 09*8+7
	DB 4
	DB 06*8+0
	DB 07*8+7
	DB 6
	DB 01*8+1
	DB 07*8+0
	DB 5
	DB 05*8+7
	DB 10*8+2
	DB 4
	DB 05*8+7
	DB 07*8+0
	DB 01*8+1
	DB 6
	DB 07*8+7
	DB 06*8+0
	DB 2
	DB 09*8+7
	DB 04*8+0
	DB 11*8+7
	DB 02*8+0
	;
	DB 0,$22
