;master code
;loaded between level files
;A = current level

nolist

org #4000
write "bin/master_code.bin"

.master_code_entry
	or A
	ret z

	cp 9
	ret nc
	
	ld L,A
	ld H,0
	add HL,HL
	ld DE,master_table
	add HL,DE

	ld E,(HL)
	inc HL
	ld D,(HL)
	ex DE,HL
	
.master_loop
	ld E,(HL)
	inc HL
	ld D,(HL)
	inc HL
	
	ld A,(HL)	;if all 3 data are null so do not patch
	or D
	or E
	ret z
	
;else patch it !	
	ld A,(HL)
	inc HL
	ld (DE),A
	jr master_loop	;next !

.master_table
	dw 0
	dw master_l1
	dw master_l2
	dw master_l3
	dw master_l4
	dw master_l5
	dw master_l6
	dw master_l7
	dw master_l8
	
	
	
.master_l1
	incbin "L1.MST"
.master_l2
	incbin "L2.MST"
.master_l3
	incbin "L3.MST"
.master_l4
	incbin "L4.MST"
.master_l5
	incbin "L5.MST"
.master_l6
	incbin "L6.MST"
.master_l7
	incbin "L7.MST"
.master_l8
	incbin "L8.MST"



list
;/end