actsave: Added setup for loading and storing actor restore data
authorLukas Krickl <lukas@krickl.dev>
Sat, 2 Aug 2025 16:18:23 +0000 (18:18 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 2 Aug 2025 16:18:23 +0000 (18:18 +0200)
src/actsave.s
src/map.s

index a236e9c321be5559f4444e31cc830bd3c5a4fea7..5d9e6e7d55663a07d0c263193582951604bc62cf 100644 (file)
@@ -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
index 57c61269185f98f2d1727960b15e1ec11db742e1..e2ec3ee60577569bac381f254d80ab80b6625101 100644 (file)
--- 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