cells: refactored cell struct to save more memory
authorLukas Krickl <lukas@krickl.dev>
Tue, 8 Apr 2025 14:57:17 +0000 (16:57 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 8 Apr 2025 14:57:17 +0000 (16:57 +0200)
src/cells.s
src/defs.s

index 13c0bf55384db4ebdf864a2716bfd3463c446b8c..8af5976a7226c32507191ccae452a9a42f10b91b 100644 (file)
@@ -4,31 +4,29 @@
   ; 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
index e128a1d1955dfc46ab947605f17a9570326a68f0..a8e3efc035576e0a2ceab442a42bd1842055cc7c 100644 (file)
   ; 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
@@ -40,7 +50,7 @@
 .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