;casual menu graphics

nolist

org #4000

debug_casual	EQU 0

IF debug_casual
	write direct -1,-1,#C5
ELSE
	write "bin/casual.c5"
ENDIF

.bank_start
	db #C5
	db 0

.draw_casual

	ld (current_address),HL

	add A
	ld E,A
	ld D,0
	ld HL,casual_table
	add HL,DE
	ld E,(HL)
	inc HL
	ld D,(HL)
	ex DE,HL

	;ld HL,casual1
	ld DE,casual_buffer
	call deexo

;image
	ld HL,60
	ld (line_width),HL

	ld BC,92+2
	call getnew_current_address
	ld HL,casual_buffer
	ld B,30
	ld C,8
	call draw_image
;border up
	ld HL,64
	ld (line_width),HL
	ld DE,(current_address)
	ld HL,casual_border_up
	ld B,32
	ld C,1
	call draw_image

;border down
	ld BC,644+184
	call getnew_current_address
	ld HL,casual_border_down
	ld B,32
	ld C,1
	call draw_image

;border left
	ld HL,2
	ld (line_width),HL

	ld BC,92
	call getnew_current_address
	ld HL,casual_border_left
	ld B,1
	ld C,8
	call draw_image

;border right
	ld BC,92+62
	call getnew_current_address
	ld HL,casual_border_right
	ld B,1
	ld C,8
	call draw_image
	
	;ld HL,60
	;ld (line_width),HL

	;pop DE
	;ld B,30
	;ld C,8
	;ld HL,casual_buffer
	;call draw_image

	ret
;BC = offset , return in DE , HL corrupted
.getnew_current_address
;border left + 1 y
	ld HL,(current_address)
	ld A,H
	and %11111000
	ld E,A
	ld A,H
	and %00000111
	ld H,A
	add HL,BC
	ld A,H
	and %00000111
	or E
	ld H,A
	ex DE,HL
	ret
.line_width		dw 60
.current_address	dw 0


;draw an image
; HL = image
; B = width (char)
; C = height (char)
; DE = screen address
.draw_image

.draw_image_loopY

	push BC
	push DE
	push HL

.draw_image_loopChar

	push HL
	push BC
	ld BC,(line_width)
;draw char
repeat 7
	ld A,(HL)
	ld (DE),A
	inc HL
	inc DE
	ld A,(HL)
	ld (DE),A
	dec HL
	dec DE
	ld A,8
	add D
	ld D,A
	add HL,BC
rend
	ld A,(HL)
	ld (DE),A
	inc HL
	inc DE
	ld A,(HL)
	ld (DE),A

;next char + cleanup line	
	ld A,D
	and %11000111
	ld D,A
	inc DE
	ld A,D
	and %11000111
	ld D,A

	pop BC
;next char in image
	pop HL
	inc HL
	inc HL

	djnz draw_image_loopChar

;skip 8 lines in image
	pop HL
	ld BC,(line_width)
repeat 8
	add HL,BC
rend
	pop DE

	ld BC,92
	ex DE,HL

	ld A,H
	and %00000111
	ld H,A

	add HL,BC

	ld A,H
	and %00000111
	or %11000000
	ld H,A

	ex DE,HL

	pop BC
	dec C
	jp nz,draw_image_loopY	

	ret

.draw_image_width
	dw 0
	

.casual_table
	dw casual1
	dw casual2
	dw casual3
	dw casual4
	dw casual5
	dw casual6
	dw casual7
	dw casual8

;unpacker
read "deexo.asm"

.casual_buffer
	ds 60*64,0

.casual1
	incbin "gfx/casual_5_1.raw"
.casual2
	incbin "gfx/casual_5_2.raw"
.casual3
	incbin "gfx/casual_5_3.raw"
.casual4
	incbin "gfx/casual_5_4.raw"
.casual5
	incbin "gfx/casual_5_5.raw"
.casual6
	incbin "gfx/casual_5_6.raw"
.casual7
	incbin "gfx/casual_5_7.raw"
.casual8
	incbin "gfx/casual_5_8.raw"	



.casual_border_left
	incbin "gfx/casual_left.pm1"
.casual_border_right
	incbin "gfx/casual_right.pm1"
.casual_border_up
	incbin "gfx/casual_up.pm1"
.casual_border_down
	incbin "gfx/casual_down.pm1"

list
;/EOF