ld bc, c_size
call memcpy
- call cursor_get_tile
- ld a, BUILDING_ROAD_NORTH_SOUTH
- call bg_update_queue_push
-
ldnull bc
ret
; de: cell ptr
; bc: screen ptr
cell_update:
+ push de
+ inc de
+ inc de
inc de ; de = flags
ld a, [de] ; a = head offset
and a, CF_HEAD
+ pop de
; if not head cell return
ret z
; save cell ptr
- dec de ; de is c_type
push de
-
- inc de
+
+ ; check timer
+ ld a, [de] ; a = timer
+ cp a, 0
+ jr z, @update REL ; if timer is 0 update
+ dec a ; otherwise timer--
+ ld [de], a
+ pop de
+ ret
+@update:
inc de ; de = c_st_routine
ld a, [de]
or a, c
ret z
- inc de
inc de
; de = c_st_routine
; updates the tiles
; by pushing tile updates
cell_road_init:
+ push bc
+ pop hl ; hl = ptr to tile
+ ld a, BUILDING_ROAD_NORTH_SOUTH
+ call bg_update_queue_push
+
ld bc, cell_road_update
ret
cell_template_road:
- c_def C_ROAD, CF_HEAD, cell_road_init
+ c_def 0, cell_road_init, CF_HEAD
; game state cell struct
; this holds all the information
; a cell on the map has
+ ; cells are a reduced version of states
+ ; without a default next value and additional flags
.se 0
- ; cell type/cell gfx
-.de c_type, 1
-.de c_flags, 1
- ; if c_st_rotuine
- ; is unsued (true for all non-head cells)
- ; this space can be used by the head cell
- ; to store data
+ ; cell delay timer only used for head cell
+ ; when it reaches 0 the next state is called
+.de c_time, 1
+ ; type/gfx or custom data for non-head cells
+.de c_type, 0
.de c_st_data, 0
; this is the same as st routine,
; but tiles do not have a timer or
; de: cell ptr
; bc: screen ptr
.de c_st_routine, 2
+.de c_flags, 1
+ ; if c_st_rotuine
+ ; is unsued (true for all non-head cells)
+ ; this space can be used by the head cell
+ ; to store data
.de c_size, 0
; cell type enum
#define CURSOR_MIN_Y 0
#define CURSOR_MAX_Y 0xB8
- ; state struct
+ ; state struct
+ ; states are intended to
+ ; be used as part of a larger
+ ; struct
+ ; e.g. player state
.se 0
; time until next state
.de st_time, 1
; defines a new cell template
; inputs:
- ; $1: c_type
- ; $3: c_flags
+ ; $1: c_time
; $2: c_st_routine
+ ; $3: c_flags
#macro c_def
.db $1
- .db $2
- dw $3
+ dw $2
+ .db $3
#endmacro
; loads NULL into a 16 bit register
ld a, SIM_UPDATE_MAX+1
push af
@loop:
-
- ; advance to next cell
- .rep i, c_size, 1, inc de
- inc bc
-
push de
push bc
call cell_update
pop bc
pop de
pop af
+
+ ; advance to next cell
+ .rep i, c_size, 1, inc de
+ inc bc
; loop counter--
dec a