; right
.db TF_SE
+ ; loads the marching vector
+ ; as well as player positin
+ ; inputs:
+ ; de: actor ptr
+ ; $1: vector to load
+ ; returns:
+ ; b/c: player y/x
+ ; d/e: chosen vector
+#macro map_load_march_vec
+ ld hl, act_pos_y
+ add hl, de
+ ld a, [hl+]
+ ld b, a
+ ld a, [hl]
+ ld c, a
+
+ ld a, [$1]
+ ld d, a
+ ld a, [$1+1]
+ ld e, a
+#endmacro
+
+
+ ; gets a tile based on a positon
+ ; and a marching vector
+ ; inputs:
+ ; b/c: y/x origin
+ ; d/e: marching vector
+ ; a: amount of steps to take
+ ; returns:
+ ; tile at b/c + a * d/e
+map_get_tile_march:
+@loop:
+ push af
+ ld a, b
+ add a, d
+ ld b, a ; add vec to b
+
+ ld a, c
+ add a, e
+ ld c, a ; add vec to c
+
+ pop af
+ dec a
+ jr nz, @loop REL
+ jp map_get_tile
+
+
; gets the direction vector
; for the current direction
; copies to common wram location
map_full_draw_ceiling:
ld hl, render_buffer
ld bc, RENDER_BUF_W * 5
- ld d, 0x11
+ ld d, 0x01
; set ceiling tile for 4 rows
jp memset
; draws floor tiles
map_full_draw_floor:
ld hl, render_buffer + RENDER_BUF_W * 5
- ld bc, RENDER_BUF_W * 9
- ld d, 0x27
+ ld bc, RENDER_BUF_W * 5
+ ld d, 0x02
jp memset
- ; gets a tile based on a positon
- ; and a marching vector
- ; inputs:
- ; b/c: y/x origin
- ; d/e: marching vector
- ; a: amount of steps to take
- ; returns:
- ; tile at b/c + a * d/e
-map_get_tile_march:
-@loop:
- push af
- ld a, b
- add a, d
- ld b, a ; add vec to b
-
- ld a, c
- add a, e
- ld c, a ; add vec to c
-
- pop af
- dec a
- jr nz, @loop REL
- jp map_get_tile
-
- ; loads the marching vector
- ; as well as player positin
- ; inputs:
- ; de: actor ptr
- ; $1: vector to load
- ; returns:
- ; b/c: player y/x
- ; d/e: chosen vector
-#macro map_load_march_vec
- ld hl, act_pos_y
- add hl, de
- ld a, [hl+]
- ld b, a
- ld a, [hl]
- ld c, a
-
- ld a, [$1]
- ld d, a
- ld a, [$1+1]
- ld e, a
-#endmacro
-
- ; loads the near tile ahead of player
- ; returns:
- ; hl: near tile
-#macro _map_full_draw_load_near_tile
- ; near is just the current tile, no need for march load
- ld a, [player+act_pos_y]
- ld b, a
- ld a, [player+act_pos_x]
- ld c, a
- call map_get_tile
-#endmacro
-
- ; loads the far tile ahead of player
- ; returns:
- ; hl: far tile
-#macro _map_full_draw_load_far_tile
- ld de, player
- map_load_march_vec dir_vector_forward
- ld a, 1
- call map_get_tile_march
- ; hl = tile ahead
-#endmacro
-
- ; draws the far center wall
- ; either draws a wall or an open space
- ; depending on the door state
-map_full_draw_far_center:
- _map_full_draw_load_far_tile
- ld de, t_flags0
- add hl, de
-
- ; load forward direction bit
- ld b, [hl]
- ld a, [dir_tf_forward]
- and a, b ; mask out forward door bit
-
- jr z, @no_door REL
-@door:
- ld hl, render_buffer + RENDER_BUF_W * 5 + 8
- ld de, far_center_door
- ld bc, RENDER_BUF_W - 4
- ld a, 3
- jp tiles_block_copy
-@no_door:
- ld hl, render_buffer + RENDER_BUF_W * 5 + 8
- ld de, far_center_wall
- ld bc, RENDER_BUF_W - 4
- ld a, 3
- jp tiles_block_copy
-
-
- ; draws a near wall or door
-map_full_draw_near_center:
- _map_full_draw_load_near_tile
- ; hl = tile
- ld de, t_flags0
- add hl, de
- ; get forward direction flag
- ld b, [hl]
- ld a, [dir_tf_forward]
- and a, b
-
- ret nz ; do nothing if there is an opening
-
-@no_door:
- ; draw near center wall left, right and center
- ld hl, render_buffer + RENDER_BUF_W * 4 + 4
- ld de, near_center_wall_left
- ld bc, RENDER_BUF_W - 4
- ld a, 5
- call tiles_block_copy
-
- ld hl, render_buffer + RENDER_BUF_W * 4 + 8
- ld de, near_center_wall_middle
- ld bc, RENDER_BUF_W - 4
- ld a, 5
- call tiles_block_copy
-
- ld hl, render_buffer + RENDER_BUF_W * 4 + 12
- ld de, near_center_wall_right
- ld bc, RENDER_BUF_W - 4
- ld a, 5
- call tiles_block_copy
-
- ret
-
- ; draws near left wall or door
-map_full_draw_near_left:
- _map_full_draw_load_near_tile
- ; hl = tile
- ld de, t_flags0
- add hl, de
-
- ; get forward direction flag
- ld b, [hl]
- ld a, [dir_tf_left]
- and a, b
-
- jr z, @no_door REL
-@door:
- ld hl, render_buffer + RENDER_BUF_W * 3
- ld de, near_left_door
- ld bc, RENDER_BUF_W - 4
- ld a, 7
- call tiles_block_copy
-
- ; draw a near left wall if needed
- jp map_full_draw_near_left_wall
-@no_door:
- ld hl, render_buffer + RENDER_BUF_W * 3
- ld de, near_left_wall
- ld bc, RENDER_BUF_W - 4
- ld a, 7
- jp tiles_block_copy
-
- ; draws a near left wall if
- ; the near left tile has a forward wall
- ; otherwise does nothing
-map_full_draw_near_left_wall:
- ; get left tile
- ld de, player
- map_load_march_vec dir_vector_left
- ld a, 1
- call map_get_tile_march
- ; hl = tile to the left
- ld de, t_flags0
- add hl, de
-
- ld b, [hl]
- ld a, [dir_tf_forward]
- and a, b
- ret nz ; bail if door
-
- ld hl, render_buffer + RENDER_BUF_W * 3
- ld de, near_center_left_wall
- ld bc, RENDER_BUF_W-4
- ld a, 6
- call tiles_block_copy
-
- ret
-
-
- ; draws near right wall or door
-map_full_draw_near_right:
- _map_full_draw_load_near_tile
- ; hl = tile
- ld de, t_flags0
- add hl, de
-
- ; get forward direction flag
- ld b, [hl]
- ld a, [dir_tf_right]
- and a, b
-
- jr z, @no_door REL
-@door:
- ld hl, render_buffer + RENDER_BUF_W * 3 + 16
- ld de, near_right_door
- ld bc, RENDER_BUF_W - 4
- ld a, 7
- call tiles_block_copy
-
- jp map_full_draw_near_right_wall
-@no_door:
- ld hl, render_buffer + RENDER_BUF_W * 3 + 16
- ld de, near_right_wall
- ld bc, RENDER_BUF_W - 4
- ld a, 7
- jp tiles_block_copy
-
-
- ; draws a near right wall if
- ; the near right tile has a forward wall
- ; otherwise does nothing
-map_full_draw_near_right_wall:
- ; get left tile
- ld de, player
- map_load_march_vec dir_vector_right
- ld a, 1
- call map_get_tile_march
- ; hl = tile to the left
- ld de, t_flags0
- add hl, de
-
- ld b, [hl]
- ld a, [dir_tf_forward]
- and a, b
- ret nz ; bail if door
-
- ld hl, render_buffer + RENDER_BUF_W * 3 + 16
- ld de, near_center_right_wall
- ld bc, RENDER_BUF_W-4
- ld a, 6
- call tiles_block_copy
-
- ret
-
-
- ; draws far left wall or door
-map_full_draw_far_left:
- _map_full_draw_load_far_tile
- ; hl = tile
- ld de, t_flags0
- add hl, de
-
- ; get forward direction flag
- ld b, [hl]
- ld a, [dir_tf_left]
- and a, b
-
- jr z, @no_door REL
-@door:
- ld hl, render_buffer + RENDER_BUF_W * 4 + 4
- ld de, far_left_door
- ld bc, RENDER_BUF_W - 4
- ld a, 5
- call tiles_block_copy
-
- jp map_full_draw_far_left_wall
-@no_door:
- ld hl, render_buffer + RENDER_BUF_W * 4 + 4
- ld de, far_left_wall
- ld bc, RENDER_BUF_W - 4
- ld a, 5
- jp tiles_block_copy
-
-
- ; draws a far left wall if
- ; the far left tile has a forward wall
- ; otherwise does nothing
-map_full_draw_far_left_wall:
- ; get left tile
- ld de, player
- map_load_march_vec dir_vector_left
- ; load the march vec, but or it with the forward vec
- ld a, [dir_vector_forward]
- or a, d
- ld d, a
- ld a, [dir_vector_forward+1]
- or a, e
- ld e, a ; d/e = forward + left vector
-
- ld a, 1
- call map_get_tile_march
- ; hl = tile to the left
- ld de, t_flags0
- add hl, de
-
- ld b, [hl]
- ld a, [dir_tf_forward]
- and a, b
- ret nz ; bail if door
-
- ld hl, render_buffer + RENDER_BUF_W * 4 + 4
- ld de, far_center_left_wall
- ld bc, RENDER_BUF_W-4
- ld a, 5
- call tiles_block_copy
-
- ret
-
-
- ; draws far right wall or door
-map_full_draw_far_right:
- _map_full_draw_load_far_tile
- ; hl = tile
- ld de, t_flags0
- add hl, de
-
- ; get forward direction flag
- ld b, [hl]
- ld a, [dir_tf_right]
- and a, b
-
- jr z, @no_door REL
-@door:
- ld hl, render_buffer + RENDER_BUF_W * 4 + 12
- ld de, far_right_door
- ld bc, RENDER_BUF_W - 4
- ld a, 5
- call tiles_block_copy
-
- jp map_full_draw_far_right_wall
-@no_door:
- ld hl, render_buffer + RENDER_BUF_W * 4 + 12
- ld de, far_right_wall
- ld bc, RENDER_BUF_W - 4
- ld a, 5
- jp tiles_block_copy
-
-
- ; draws a far right wall if
- ; the far right tile has a forward wall
- ; otherwise does nothing
-map_full_draw_far_right_wall:
- ; get right tile
- ld de, player
- map_load_march_vec dir_vector_right
- ; load the march vec, but or it with the forward vec
- ld a, [dir_vector_forward]
- or a, d
- ld d, a
- ld a, [dir_vector_forward+1]
- or a, e
- ld e, a ; d/e = forward + left vector
-
- ld a, 1
- call map_get_tile_march
- ; hl = tile to the left
- ld de, t_flags0
- add hl, de
-
- ld b, [hl]
- ld a, [dir_tf_forward]
- and a, b
- ret nz ; bail if door
-
- ld hl, render_buffer + RENDER_BUF_W * 4 + 12
- ld de, far_center_right_wall
- ld bc, RENDER_BUF_W-4
- ld a, 5
- call tiles_block_copy
-
- ret
; draws a full map copy into the current map view buffer
; 2) draw back to front
call map_full_draw_ceiling
call map_full_draw_floor
-
- ; either draw a wall or a door ahead
- call map_full_draw_far_center
- call map_full_draw_far_left
- call map_full_draw_far_right
-
- ; draw near wall or door
- call map_full_draw_near_center
- call map_full_draw_near_left
- call map_full_draw_near_right
@done: