; inputs:
; de: cell ptr
cell_update:
- ld hl, c_head_offset
- add hl, de ; hl = c_head_offset for current cell
- ld a, [hl] ; a = head offset
- cp a, 0
+ inc de ; de = flags
+ ld a, [de] ; a = head offset
+ and a, CF_HEAD
; if not head cell return
ret nz
- ; save cell ptr
+ ; save cell ptr
+ dec de ; de is c_type
push de
- ; otherwise call update routine
- ld hl, c_st_routine
- add hl, de ; hl = ptr to routine to call
-
- push hl
- pop bc ; bc = ptr to rotuine to call
- ld a, [bc]
+ inc de
+ inc de ; de = c_st_routine
+
+ ld a, [de]
ld l, a
- inc bc
- ld a, [bc]
+ inc de
+ ld a, [de]
ld h, a ; hl = update routine
; cell ptr has to be passed
; to call
- pop de
+ pop de ; de is cell ptr
+ push de ; save again
call call_hl
; restore cell ptr
; it is connected to a warehouse
; a warehouse is always connected
.de CF_CONNECTED, 1
+ ; if this flag is set, the cell in question is a head cell
+ ; head cells contain update code and can own many tiles
+ ; head cells are always in the top left corner of a multi cell
+ ; structure
+ ; so if a cell needs to look up its head
+ ; (e.g. when being selected for deletion)
+ ; it can walk the cell map up and left until a head is found
+.de CF_HEAD, 2
+ ; mark a cell as used
+.de CF_USED, 4
; cell types
.se 0
.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
; cell update
.de c_st_routine, 2
-.de c_flags, 1
- ; offset to head tile for thsi tile
- ; if offset is 0000 this is the head tile
- ; head tiles are tiles that manage the state of a
- ; multi-tile object
- ; the head offset consists of 2 4-bit integers
- ; HI: how many cells up to walk to get to head
- ; LO: how many cells left to walk to get to head
-.de c_head_offset, 1
.de c_size, 0
; cell type enum