map: wip rendering ahead and doors
authorLukas Krickl <lukas@krickl.dev>
Tue, 16 Dec 2025 16:08:49 +0000 (17:08 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 16 Dec 2025 16:08:49 +0000 (17:08 +0100)
src/map.s
src/player.s
src/wram.s

index 7d615fa509469558ba9a5130044574276bfd0f0f..49fde97302891ee875bb21cf02bd7fc851cee37a 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -259,6 +259,150 @@ map_get_tile:
        ld hl, tile_null
        ret
        
+       ; gets south facing props 
+       ; inputs:
+       ;               hl: current tile
+       ;                $1: forward direction
+       ;                $2: left direction
+       ;                $3: right direction
+       ; returns:
+       ;               d/e: left/right door state
+       ;     a: forward door state
+#macro map_full_draw_door_state
+.beginscope
+       ld d, 0
+       ld e, 0
+
+       inc hl ; flags
+       ld a, [hl]
+       and a, $2
+       jp z, @no_left
+               ld d, 1 
+@no_left:
+
+       ld a, [hl]
+       and a, $3
+       jp z, @no_right
+               ld e, 1
+@no_right:
+
+       ld a, [hl]
+       and a, $1
+       jp z, @no_forward
+               ld a, 1
+@no_forward:
+
+       dec hl ; back to tile
+.endscope
+#endmacro
+       
+       ; writes door state
+       ; inputs:
+       ;               de: left/right state
+       ;                a: forward state
+       ;               $1: offset from tmp_map_forward (e.g. +2 to write to far left/right door)
+       ;               $2: forward value to set
+       ;               $3: instruction to run if forward is 1 (e.g. ret, nop)
+#macro map_full_draw_write_door_state
+.beginscope
+       push af
+
+       ; write left door
+       ld a, d
+       ld [tmp_map_forward+$1], a
+
+       ; write right door
+       ld a, e
+       ld [tmp_map_forward+1+$1], a
+       
+       ; check if forward is available
+       pop af
+       cp a, 0
+       jr z, @no_forward REL
+               ld a, $2
+               ld [tmp_map_forward], a
+               jp @done
+@no_forward:
+       $3
+@done:
+.endscope
+#endmacro
+
+
+       ; counts the tiles the player can move forward
+       ;       inputs:
+       ;               player facing direction y/x
+       ; retunrs:
+       ;               tmp_map_forward: 0/1 can move forward or not
+       ;               tmp_map_forward: 2 more than 1 tile can be moved forward
+       ;         tmp_map_near_left_door: 0/1 door present or not
+       ;               tmp_map_near_right_door: 0/1 door present or not
+       ;   tmp_map_far_left_door: 0/1 door present or not
+       ;       tmp_map_far_right_door 0/1 door present or not
+map_full_draw_count_forward_attributes:
+       xor a, a
+       ld [tmp_map_forward], a
+       ld [tmp_map_near_left_door], a
+       ld [tmp_map_near_right_door], a
+       ld [tmp_map_far_left_door], a
+       ld [tmp_map_far_right_door], a
+
+       ld a, [player+act_pos_y]
+       ld b, a
+       ld a, [player+act_pos_x]
+       ld c, a ; bc = y/x
+       push bc
+       call map_get_tile
+       pop bc ; bc = y/x
+       ; hl = tile
+
+       ld a, [player+act_dir]
+       and a, ACT_DIR_MASK
+
+
+       ; which routine to run to find values?
+       cp a, SOUTH
+       jp z, @south
+       cp a, WEST
+       jp z, @west
+       cp a, EAST
+       jp z, @east
+
+
+@north:
+       map_full_draw_door_state TF_NE, TF_WE, TF_EE
+       map_full_draw_write_door_state 1, 1, ret
+
+       dec b ; move one tile back
+       map_full_draw_door_state TF_NE, TF_WE, TF_EE
+       map_full_draw_write_door_state 3, 2, ret
+       ret
+@south:
+       map_full_draw_door_state TF_SE, TF_EE, TF_WE
+       map_full_draw_write_door_state 1, 1, ret
+       
+       inc b ; move one tile forward
+       map_full_draw_door_state TF_SE, TF_EE, TF_WE
+       map_full_draw_write_door_state 3, 2, ret
+       ret
+@east:
+       map_full_draw_door_state TF_EE, TF_NE, TF_SE
+       map_full_draw_write_door_state 1, 1, ret
+
+       inc c ; move one tile east
+       map_full_draw_door_state TF_EE, TF_NE, TF_SE
+       map_full_draw_write_door_state 3, 2, ret
+       ret
+@west:
+       map_full_draw_door_state TF_WE, TF_SE, TF_NE
+       map_full_draw_write_door_state 1, 1, ret
+
+       dec c ; move one tile west
+       map_full_draw_door_state TF_WE, TF_SE, TF_NE
+       map_full_draw_write_door_state 3, 2, ret
+       ret
+
+       
        ; draws a full map copy into the current map view buffer
        ; bsed on the current location the player is facing
        ; the map render buffer is then written to the screen
@@ -272,12 +416,28 @@ map_get_tile:
        ;               render_buffer: new map data to be drawn
        ; transferts to redraw state
 map_full_draw:
-       ; draw template for now
+       call map_full_draw_count_forward_attributes
+
+       ld a, [tmp_map_forward]
+       cp a, 0
+       jp z, @short_wall
+
+@far_wall:
+       ; draw far wall template
        ld de, far_wall
        ld hl, render_buffer
        ld bc, RENDER_BUF_TILES
        call memcpy
+       
+       jp @done
+@short_wall:
+       ; draw short wall template
+       ld de, near_wall
+       ld hl, render_buffer
+       ld bc, RENDER_BUF_TILES
+       call memcpy 
 
+@done:
        ; 4) go to render state
        call update_render
        ret
index ec430a9a72a7de15954dd8b18db2e16783b74c34..e5c378589043673a6c60015d68e0bd2275c55da6 100644 (file)
@@ -52,6 +52,7 @@ player_handle_move:
                and a, ~ACT_DIR_MASK & 0xFF
                or a, b
                ld [player+act_dir], a
+               call map_full_draw
 @not_left:
 
        ld b, DIRRIGHT
@@ -69,6 +70,7 @@ player_handle_move:
                and a, ~ACT_DIR_MASK & 0xFF
                or a, b
                ld [player+act_dir], a
+               call map_full_draw
 @not_right:
 
        ld b, DIRUP
index 04239764dab0e370b844cfba70f3a6554ddef79a..6f39dfa04dac6b4da2486fdf7821bf00d8b23a3d 100644 (file)
@@ -123,3 +123,9 @@ update_tile_vram: .adv 2
 update_tile_ptr: .adv 2
 
 render_buffer: .adv RENDER_BUF_TILES
+
+tmp_map_forward: .adv 1
+tmp_map_near_left_door: .adv 1
+tmp_map_near_right_door: .adv 1
+tmp_map_far_left_door: .adv 1
+tmp_map_far_right_door: .adv 1