From 5de36bbb70134f5ec9aabc072e13d709ad3c8b21 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 2 Aug 2025 18:18:23 +0200 Subject: [PATCH] actsave: Added setup for loading and storing actor restore data --- src/actsave.s | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/map.s | 8 ++++++++ 2 files changed, 57 insertions(+) diff --git a/src/actsave.s b/src/actsave.s index a236e9c..5d9e6e7 100644 --- a/src/actsave.s +++ b/src/actsave.s @@ -7,12 +7,61 @@ act_save_init: call memset ret + ; loads current start of save game slot + ; based on the current map seed index + ; returns: + ; bc: act save game slot +act_sg_load_current_slot: + ld a, [map_header] + ld l, a + ld a, [map_header+1] + ld h, a + ld de, map_seed_index + add hl, de + ld a, [hl] ; a = seed index + + ld hl, act_sg + ; no need to loop if a is 0 + cp a, 0 + ret z + ld de, act_sg_size * UNITS_MAX + + ; add sg size for every index offset +@loop: + add hl, de + dec a + jr z, @loop REL + + push hl + pop bc ; we want return value in bc + + ret + ; stores actor save game ; based on the current map's seed offset + ; skipped if [map_header] is NULL act_sg_store: + ; check if map header is NULL + ld a, [map_header] + ld b, a + ld a, [map_header+1] + or a, b + ret z + + call act_sg_load_current_slot + + ret + + ; stores data from a single actor into + ; the save slot + ; inputs: + ; bc: act save game slot + ; hl: actor +act_sg_store_single: ret ; restores actor save game based on ; current map's seed offset act_sg_restore: + call act_sg_load_current_slot ret diff --git a/src/map.s b/src/map.s index 57c6126..e2ec3ee 100644 --- a/src/map.s +++ b/src/map.s @@ -21,6 +21,10 @@ map_init_floor: ; TODO: do not touch lcd or interrupts if ; they were not enabled! map_load: + push hl + call act_sg_store + pop hl + ; backup the map header ld a, l ld [map_header], a @@ -62,6 +66,10 @@ map_load: call map_call_gen pop hl + push hl + call act_sg_restore + pop hl + call map_draw_all ; restore lcd and interrupts -- 2.30.2