WIDTH = 15
HEIGHT = 8
SIZE = WIDTH*HEIGHT
TILE = 0
CLOSED = SIZE
NODES = 2*SIZE
b_tilemap:
.db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
.db 1,0,0,0,0,0,0,1,0,0,0,0,1,0,1
.db 1,0,0,0,1,0,0,1,0,0,0,0,0,0,1
.db 1,0,0,0,0,0,0,0,0,0,1,0,0,0,1
.db 1,0,1,1,0,0,1,1,0,0,1,0,1,1,1
.db 1,0,0,1,1,0,0,1,0,0,1,0,1,3,1
.db 1,2,0,0,0,0,0,1,1,0,1,0,0,0,1
.db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
b_closed:
.fill SIZE,0
b_nodes:
.fill SIZE,0
end:
bcall(_ClrLCDFull)
di
ld hl,b_tilemap
;x + y
ld de,1+(6*WIDTH)
ld bc,13+(5*WIDTH)
add hl,de ;starting position in map
start:
ld de,CLOSED
add hl,de ;b_closed
ld (hl),1 ;starting position marked as ready to check
add hl,de ;b_nodes
ld (hl),0 ;first node starts off at 0
ld hl,b_closed
add hl,bc
ld (hl),$FF
ld bc,SIZE
ex af,af'
ld a,%00110011
ex af,af'
ld hl,b_closed
search_outer:
push hl
push bc
ex af,af'
push af
call disp_frame
pop af
ex af,af'
pop bc
pop hl
di
ld de,0
search_loop:
ld a,(hl)
dec a
jr nz,$+4
push hl
inc e
inc hl
dec bc
ld a,c
or b
jr nz,search_loop ;check if bc = 0, repeat if no
retrieve_tiles:
ld a,e
or a
jr z,+_
pop hl
push de
call expand_tile
pop de
dec e
jr nz,retrieve_tiles
_ ld hl,b_closed ;reset search values
ld bc,SIZE
ex af,af'
rrca ;rotate to next part of pattern
ex af,af'
jr search_outer
expand_tile:
;search_right
inc (hl) ;set to 2 = closed
inc hl
ld a,(hl)
inc a
cp 2
call c,check_tile
search_left:
dec hl
dec hl
ld a,(hl)
inc a
cp 2
call c,check_tile
search_down:
inc hl
ld de,WIDTH
add hl,de
ld a,(hl)
inc a
cp 2
call c,check_tile
search_up:
ld de,-WIDTH*2
add hl,de
ld a,(hl)
inc a
cp 2
ret nc
check_tile:
ld de,CLOSED
or a
sbc hl,de ;hl points to -b_tilemap-
ld a,(hl)
or a ;check if current tile = 0
add hl,de ;doesn't affect z, -b_closed-
jr nz,$+4
ld (hl),1 ;1 = expand during next iteration
cp 3
jr nz,$+4
ld (hl),'X'-'0'
add hl,de ;hl points to -b_node-
ex af,af'
ld b,a
and %1
ld (hl),a ;load the current pattern
ld a,b
ex af,af'
sbc hl,de ;restore hl
ret
disp_frame:
bcall(_HomeUp)
display_smc = $+1
ld hl,b_tilemap
ld bc,WIDTH*256+HEIGHT
d_loop:
push hl
ld de,-b_tilemap
add hl,de
ld de,-SIZE
add hl,de
jr c,$-1
or a
sbc hl,de
ld de,b_tilemap
add hl,de
ld a,(hl)
cp 1
pop hl
ld a,(hl)
jr nz,$+4
ld a,$E0-'0'
add a,'0'
bcall(_PutC)
inc hl
djnz d_loop
ld de,(curRow)
inc e
ld d,0
ld (curRow),de
ld b,WIDTH
dec c
jr nz,d_loop
_ call pause
ld a,b
dec a
ld de,SIZE
rra
rra
jr c,+_
ld hl,(display_smc)
sbc hl,de
ld (display_smc),hl
jr disp_frame
_ rra
ret c
ld hl,(display_smc)
add hl,de
ld (display_smc),hl
jr disp_frame
pause:
call release_keys
pause_loop:
xor a
call read_keys
inc a
jr z,pause_loop
ld b,a
release_keys:
xor a
call read_keys
inc a
jr nz,release_keys
ret
;direct input
read_keys:
out (1),a ;
push af ;short delay
pop af
in a,(1)
ret