call lcd_on
call vblank_wait
call enableinterrupts
+
+ call map_uncover_player
call map_full_draw
call update_render
; hl = tile
ld a, [hl]
- or a, TF0_VISIBLE | TF0_UNCOVERED
+ or a, TF0_VISIBLE
ld [hl], a
@skip:
ret
; marks a single tile
+ ; recursively calls mark until walls are hit
+ ; returns when a wall is hit, or a tile has already been marked, or TT_ROOM_END tile is seen
; inputs:
; b/c: y/x
- ; returns:
- ; a: 1 -> is wall
- ; a: 0 -> is not wall
-_map_uncover_mark:
+ ; map_mark_flag: flag to set/check for
+ ; preserves:
+ ; bc
+_map_mark:
push bc
call map_get_tile
- pop bc
ld a, [hl+] ; check type
; hl = flags
cp a, TT_DOOR
jr z, @mark_but_exit REL
+ cp a, TT_WALL
+ jr z, @mark_but_exit REL
+
+ cp a, TT_ROOM_END
+ jr z, @mark_but_exit REL
+
ld a, [hl]
and a, TF0_WALL
- jr z, @mark REL
-
- ; wall
- ld a, 1
- ret
+ jr nz, @mark_but_exit REL
@mark:
- ld a, [hl]
- or a, TF0_UNCOVERED
+ ld a, [map_mark_flag]
+ ; is the flag already set
+ ld b, [hl]
+ and a, b
+ jr nz, @exit REL ; bail if alrady set
+
+ ld b, [hl]
+ ld a, [map_mark_flag]
+ or a, b
+
ld [hl], a
-
- ; not wall
- ld a, 0
+
+@mark_adjacent:
+ pop bc
+ push bc
+ dec b ; tile up
+ call _map_mark
+
+ pop bc
+ push bc
+ inc b ; tile down
+ call _map_mark
+
+ pop bc
+ push bc
+ dec c ; tile left
+ call _map_mark
+
+ pop bc
+ push bc
+ inc c ; tile right
+ call _map_mark
+
+@exit:
+ pop bc
ret
@mark_but_exit:
- ld a, [hl]
- or a, TF0_UNCOVERED
+ ld b, [hl]
+ ld a, [map_mark_flag]
+ or a, b
ld [hl], a
- ; wall
- ld a, 1
+ pop bc
ret
; same as map uncover
; inputs:
; b/c: y/x coordinate to start at
map_uncover:
-
- ; 1) go up until we hit a wall that is not an internal wall type
-@find_top:
- push bc
- call map_get_tile
- ld a, [hl+] ; get type
-
- cp a, TT_INNER_WALL
- jr z, @next_find_top REL
-
- cp a, TT_DOOR
- jr z, @next_find_top REL
-
- ; hl = flags0
- ld a, [hl]
- and a, TF0_WALL
- jr nz, @done_find_top REL
-@next_find_top:
- pop bc
- dec b ; y--
- jr @find_top REL
-@done_find_top:
- pop bc
- inc b ; go one down again to get the last non-wall tile
-
- ; now bc == top y / x
-@mark_all:
- push bc
-@mark_left:
- ; now go as far left as possible (until wall is hit)
- call _map_uncover_mark
- dec c ; x--
- cp a, 0
- jr z, @mark_left REL
- pop bc
-
- ; then as far right as possible (until wall is hit)
- push bc
-@mark_right:
- ; now go as far left as possible (until wall is hit)
- call _map_uncover_mark
- inc c ; x++
- cp a, 0
- jr z, @mark_right REL
- pop bc
-
- ; then y++
- inc b
- call _map_uncover_mark
- cp a, 0 ; is it a wall?
- jr z, @mark_all REL ; again!
-
+ ld a, TF0_UNCOVERED
+ ld [map_mark_flag], a
+ call _map_mark
ret
; nop map rotuine
tile_door:
tiledef TT_DOOR, TF0_WALL, 0, 0
+tile_room_end:
+ tiledef TT_FLOOR, 0, 0, 1
+
; table of map tiles -> actual tile defs
tile_table:
dw tile_wall
dw tile_floor
dw tile_door
dw tile_inner_wall
+ dw tile_room_end
; map of tile type to gfx
; this is the base tile
.db 0x03
; inner wall
.db 0x01
+ ; room end
+ .db 0x02