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 0x0, 0x0, 0x0
.db 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3, 0x3, 0x3, 0x2, 0x3, 0x3, 0x0, 0x0, 0x3, 0x1, 0x3, 0x0, 0x0
call lcd_on
call vblank_wait
call enableinterrupts
-
- call map_uncover
call map_full_draw
call update_render
; hl = tile
ld a, [hl]
- ; TODO: do not set uncovered flag here
- ; once room uncovering is implemented
- or a, TF0_VISIBLE | TF0_UNCOVERED
+ or a, TF0_VISIBLE
ld [hl], a
@skip:
; 4) go to render state
call update_render
ret
+
+ ; marks a single tile
+ ; inputs:
+ ; b/c: y/x
+ ; returns:
+ ; a: 1 -> is wall
+ ; a: 0 -> is not wall
+_map_uncover_mark:
+ push bc
+ call map_get_tile
+ pop bc
+
+ ld a, [hl+] ; check type
+ ; hl = flags
+ cp a, TT_INNER_WALL
+ jr z, @mark REL
+
+ cp a, TT_DOOR
+ jr z, @mark_but_exit REL
+
+ ld a, [hl]
+ and a, TF0_WALL
+ jr z, @mark REL
+
+ ; wall
+ ld a, 1
+ ret
+@mark:
+ ld a, [hl]
+ or a, TF0_UNCOVERED
+ ld [hl], a
+
+ ; not wall
+ ld a, 0
+ ret
+@mark_but_exit:
+ ld a, [hl]
+ or a, TF0_UNCOVERED
+ ld [hl], a
+
+ ; wall
+ ld a, 1
+ ret
+
+ ; same as map uncover
+ ; but starts at player position
+map_uncover_player:
+ ld a, [player+act_pos_y]
+ ld b, a
+ ld a, [player+act_pos_x]
+ ld c, a
+ ; b/c = player y/x
; uncovers tiles starting at player position
; and moving in all non-uncovered tiles until walls are hit
+ ; 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!
+
ret
; nop map rotuine