From: Lukas Krickl Date: Sat, 2 Aug 2025 16:18:23 +0000 (+0200) Subject: actsave: Added setup for loading and storing actor restore data X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=5de36bbb70134f5ec9aabc072e13d709ad3c8b21;p=gbrg%2F.git actsave: Added setup for loading and storing actor restore data --- 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