map: wip recursive flood map uncover marker
authorLukas Krickl <lukas@krickl.dev>
Thu, 15 Jan 2026 07:47:14 +0000 (08:47 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 15 Jan 2026 07:47:14 +0000 (08:47 +0100)
src/defs.s
src/map.s
src/player.s
src/tiles.s
src/wram.s

index df9709bdda2ec617697ed586cc97ff36b967c104..0e23edf50ab5fdb0c9a9e7132065f673aa9e5bfe 100644 (file)
 .de TT_DOOR, 1
        ; wall inside of a room
 .de TT_INNER_WALL, 1
+       ; this marks the end of a room
+       ; doors turn into this tile type
+.de TT_ROOM_END, 1
 
 
        ; tile flags0
index 0ee3ffc77ef0b879a892ead6a59ff2a61dd0d70a..3aebd163c550364579c3fa669afb0f7c3a0169dd 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -32,6 +32,8 @@ map_load:
        call lcd_on
        call vblank_wait
        call enableinterrupts
+       
+       call map_uncover_player
 
        call map_full_draw
        call update_render
@@ -281,7 +283,7 @@ map_set_visible_row:
                
                ; hl = tile
                ld a, [hl]
-               or a, TF0_VISIBLE | TF0_UNCOVERED
+               or a, TF0_VISIBLE 
                ld [hl], a
 
 @skip:
@@ -480,15 +482,16 @@ map_full_draw:
        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
@@ -498,28 +501,59 @@ _map_uncover_mark:
        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 
@@ -536,58 +570,9 @@ map_uncover_player:
        ; 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
index 17b98b9d26679d67b2f1053dc1f0f00e41246eaa..0bc8247f8593aac246039a07a47d6b3fc9106395 100644 (file)
@@ -189,13 +189,13 @@ player_collided:
        
        ret
 @open_door:
-       ld a, TT_FLOOR
+       ld a, TT_ROOM_END
        ld [de], a
 
        ld hl, t_flags0
        add hl, de 
        ; clear all flags
-       xor a, a
+       ld a, TF0_UNCOVERED
        ld [hl], a
        
        call map_full_draw
index 03be90f092b6608e38e6b81d5e35c24a502764f5..66a2d3b0fcd046d24c47609bb2124f8456167646 100644 (file)
@@ -17,12 +17,16 @@ tile_floor:
 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 
@@ -41,4 +45,6 @@ tile_gfx_table:
        .db 0x03
        ; inner wall
        .db 0x01
+       ; room end
+       .db 0x02
 
index 4cf50f2a6496ce1a6dded4a5f39e05ca26d20bec..efadecba86777b082ea520e4a7c1b9233f62b39b 100644 (file)
@@ -128,6 +128,8 @@ col_tile: .adv 2
 col_y: .adv 1
 col_x: .adv 1
 
+map_mark_flag: .adv 1
+
 #ifdef DEBUG_CANARY
 render_canary: .adv 4
 #endif