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
; 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