This queue can store up to 32 update requests for tiles.
build_road:
call cursor_get_cell
+
+ call cursor_get_tile
+ ld a, UI_TILE_ROAD
+ call bg_update_queue_push
+
ldnull bc
ret
#define TILE_SIZE 8
#define MAP_W 32
+.def int MAP_W_DEF = MAP_W
#define MAP_H 24
#define MAP_SIZE (MAP_W * MAP_H)
.de BT_WAREHOUSE, 1
.de BT_FARM, 1
.de BT_LUMBER, 1
+
+#define BGE_MAX 32
+
+ ; bg update entry
+.se 0
+.de bge_tile_ptr, 2
+.de bge_new_tile, 1
+.de bge_size, 0
.db 0
#endmacro
+ ; generic version of cursor get
+ ; math
+ ; inputs:
+ ; $1: stating address
+ ; $1: row size in bytes
+ ; $2: col size in bytes
+#macro cursor_get_at_generic
+ ; find the cell the cursor has selected
+ ld hl, $1
+
+ ; move y rows down
+ ld de, $2
+ ld a, [cursor_y]
+ div8 a
+ cp a, 0
+ jr z, @not_y_loop REL
+@y_loop:
+ add hl, de
+ dec a
+ cp a, 0
+ jr nz, @y_loop REL
+@not_y_loop:
+
+ ; move x cells
+ ld de, $3
+ ld a, [cursor_x]
+ div8 a
+ cp a, 0
+ jr z, @not_x_loop REL
+@x_loop:
+ add hl, de
+ dec a
+ cp a, 0
+ jr nz, @x_loop REL
+@not_x_loop:
+#endmacro
; returns:
; hl: cell ptr
cursor_get_cell:
- ; find the cell the cursor has selected
- ld hl, state_cells
+ cursor_get_at_generic state_cells, MAP_W_DEF * c_size, c_size
- ; move y rows down
- ld de, MAP_W * c_size
- ld a, [cursor_y]
- div8 a
- cp a, 0
- jr z, @not_y_loop REL
-@y_loop:
- add hl, de
- dec a
- cp a, 0
- jr nz, @y_loop REL
-@not_y_loop:
-
- ; move x cells
- ld de, c_size
- ld a, [cursor_x]
- div8 a
- cp a, 0
- jr z, @not_x_loop REL
-@x_loop:
- add hl, de
- dec a
- cp a, 0
- jr nz, @x_loop REL
-@not_x_loop:
+ ret
+
+ ; gets the current tile in SCRN0
+ ; based on cursor's location
+ ; cursor_y/x
+ ; retunrs:
+ ; hl: tile position
+cursor_get_tile:
+ cursor_get_at_generic SCRN0, MAP_W_DEF, 1
ret
st_build_warehouse:
st_def 0x00, build_warehouse, st_null
st_build_road:
- st_def 0x00, build_road, st_null
+ st_def 0x00, build_road, st_build_road
st_build_farm:
st_def 0x00, build_farm, st_null
st_build_lumber:
call st_update
; call player_update
- call sim_update
+ ; call sim_update
ldnull bc
ret
; hl: ptr to tile
; a: tile data
bg_update_queue_push:
+ push hl
+ pop bc ; move hl to bc
+ push af
+ ld hl, bg_update_queue
+ ld a, [bg_update_index]
+ ld d, 0
+ ld e, a
+ add hl, de ; hl = update queue + current offset
+
+ inc a ; offset += bgu_size
+ inc a
+ inc a
+ ld [bg_update_index], a
+
+ ; store ptr
+ ld a, c
+ ld [hl+], a
+ ld a, b
+ ld [hl+], a
+
+ ; store new tile
+ pop af
+ ld [hl], a
+
ret
call poll_inputs
call scroll_write
+ call bg_update_queue_process
; cycle bg tiles for animations
ld a, [frame_count]
; they get updated once a frame
actor_player: .adv act_size
+bg_update_index: .adv 2
+bg_update_queue: .adv bge_size * BGE_MAX
+
; game state
; this region holds the entire game state
; everything thats needed for a savme game should be