;*** LOADER V2 ***
;for compressed main

nolist
org #5000
write "bin/faceA/b_5000.bin"
;run entry_point

.entry_point
	di

	;xor A	;debug
	ld (current_drive),A

	call GFX_Cls

	ld HL,crtc_setting
	call GFX_SetCRTC

	ld HL,palette
	call GFX_SetPalette

	ld BC,#7F8C+1	;mode 1 + no ROM
	out (C),C

	ld DE,ee_logo
	ld HL,#C10E
	ld C,8
	call draw_logo


	ld HL,main
	ld DE,0
	call deexo

current_drive EQU $+1
	ld A,0

	rst 0	;run baby , run !

;draw logo HL = screen address - DE = pixies address - C = lines count
.draw_logo
	ld B,8	
.draw_logo_loop1
	push BC
	push HL
.draw_logo_loop2
	push BC
	push HL

	ld B,36

.draw_logo_loop3
	ld A,(DE)
	ld (HL),A
	inc HL
	inc DE
	djnz draw_logo_loop3

	pop HL
	ld A,8
	add H
	ld H,A

	pop BC
	djnz draw_logo_loop2

	pop HL
	ld BC,64
	add HL,BC
	pop BC
	dec C
	jr nz,draw_logo_loop1 
	
	ret

	
	
	
	



;include exomizer
read "deexo.asm"

.crtc_setting
	db #01,#20,#02,#2A,#06,#18,#07,32,5,0,#0C,#30,#0D,#00,#FF

.palette
	db #40,#54,#57,#4B
.ee_logo
	incbin "gfx/easteregg_logo.pm1"
.ee_sub
	incbin "gfx/easteregg_sub.pm1"

.GFX_SetPalette
	ld BC,#7F10
	ld A,(HL)
	out (C),C
	out (C),A
	ld C,0

repeat 4
	ld A,(HL)
	out (C),C
	out (C),A
	inc C
	inc HL
rend
	ret

;clear screen range from #C000 to #FFFF
GFX_Cls:
	ld HL,#C000
	xor A
	ld (HL),A
	ld E,L
	ld D,H
	inc DE
	ld BC,#3FFF
	ldir
	ret

;setup crtc
; HL = setup data (reg,data) ending with #FF
GFX_SetCRTC:

	ld B,#BC
	ld A,#FF
.CRTC_loop
	ld C,(HL)
	cp C
	ret z

	out (C),C
	inc B
	inc HL

	ld C,(HL)
	out (C),C
	dec B
	inc HL

	jr CRTC_loop

;main code
.main
	incbin "bin/main.raw"

list
;/EOF