From f75b5bca091d633052bf0d41cc1e40811f9fc174 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sun, 3 Aug 2025 18:38:46 +0200 Subject: [PATCH] actsave: Added basic actor saving mechanism This code simply stores a few select properties of all actors into a temporary table. --- src/actsave.s | 113 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/defs.s | 2 +- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/src/actsave.s b/src/actsave.s index 5d9e6e7..b80a445 100644 --- a/src/actsave.s +++ b/src/actsave.s @@ -23,7 +23,7 @@ act_sg_load_current_slot: ld hl, act_sg ; no need to loop if a is 0 cp a, 0 - ret z + jr z, @done REL ld de, act_sg_size * UNITS_MAX ; add sg size for every index offset @@ -31,7 +31,7 @@ act_sg_load_current_slot: add hl, de dec a jr z, @loop REL - +@done: push hl pop bc ; we want return value in bc @@ -47,9 +47,11 @@ act_sg_store: ld a, [map_header+1] or a, b ret z - call act_sg_load_current_slot + ld hl, p0_units +.rep i, UNITS_MAX, 1, call act_sg_store_single + ret ; stores data from a single actor into @@ -57,11 +59,116 @@ act_sg_store: ; inputs: ; bc: act save game slot ; hl: actor + ; returns: + ; hl: next actor + ; bc: next slot act_sg_store_single: + push hl + ; store flags + ld de, act_flags + add hl, de + ld a, [hl] + ld [bc], a + inc bc + pop hl + + push hl + + ; store y pos + ld de, act_pos_y + add hl, de + ld a, [hl+] + ld [bc], a + inc bc + + ; store x pos + ld a, [hl] + ld [bc], a + inc bc + + pop hl + + ; store p0 + push hl + ld de, act_p0 + add hl, de + ld a, [hl] + ld [bc], a + inc bc + pop hl + + ; advance to next actor + ld de, act_size + add hl, de + ret ; restores actor save game based on ; current map's seed offset act_sg_restore: call act_sg_load_current_slot + ; skip over player +.rep i, act_sg_size, 1, inc bc + ld hl, p0_units+act_size +.rep i, UNITS_MAX-1, 1, call act_sg_restore_single + ret + + ; restores a single entry of actor data + ; skips restore if pos y is 0xFF + ; inputs: + ; bc: act save game slot + ; hl: actor + ; returns: + ; hl: next actor + ; bc: next slot +act_sg_restore_single: + inc bc ; bc = position y + ld a, [bc] + dec bc + cp a, 0xFF + jp z, @skip ; skip if 0xFF + + push hl + ; load flags + ld de, act_flags + add hl, de + ld a, [bc] + ld [hl], a + inc bc + pop hl + + push hl + ; load positions + ld de, act_pos_y + add hl, de + ld a, [bc] + ld [hl+], a + inc bc + + ld a, [bc] + ld [hl], a + inc bc + + pop hl + + push hl + ; load p0 + ld de, act_p0 + add hl, de + + ld a, [bc] + ld [hl], a + inc bc + + pop hl + + ld de, act_size + add hl, de ; next actor + ret + +@skip: + ; move to next item and ret +.rep i, act_sg_size, 1, inc bc + ld de, act_size + add hl, de ret diff --git a/src/defs.s b/src/defs.s index d2ea1a6..b5f8ae0 100644 --- a/src/defs.s +++ b/src/defs.s @@ -233,9 +233,9 @@ ; if pos y and x is 0xFF ; it is not restored .se 0 +.de act_sg_flags, 1 .de act_sg_pos_y, 1 .de act_sg_pos_x, 1 -.de act_sg_flags, 1 .de act_sg_p0, 1 .de act_sg_size, 0 -- 2.30.2