From: Lukas Krickl Date: Tue, 16 Dec 2025 16:08:49 +0000 (+0100) Subject: map: wip rendering ahead and doors X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=9f352e4bfd1b2e3b9f1ce899c6b0f4a8005bc8aa;p=gbrg%2F.git map: wip rendering ahead and doors --- diff --git a/src/map.s b/src/map.s index 7d615fa..49fde97 100644 --- 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 diff --git a/src/player.s b/src/player.s index ec430a9..e5c3785 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 0423976..6f39dfa 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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