From 73f0228d0251fd3cdb68e6bdc47f9fdfe30864be Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 8 Apr 2025 16:57:17 +0200 Subject: [PATCH] cells: refactored cell struct to save more memory --- src/cells.s | 28 +++++++++++++--------------- src/defs.s | 21 +++++++++++---------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/cells.s b/src/cells.s index 13c0bf5..8af5976 100644 --- a/src/cells.s +++ b/src/cells.s @@ -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 diff --git a/src/defs.s b/src/defs.s index e128a1d..a8e3efc 100644 --- a/src/defs.s +++ b/src/defs.s @@ -29,6 +29,16 @@ ; 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 @@ -55,15 +65,6 @@ ; 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 -- 2.30.2