actsave: Added basic actor saving mechanism
authorLukas Krickl <lukas@krickl.dev>
Sun, 3 Aug 2025 16:38:46 +0000 (18:38 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sun, 3 Aug 2025 16:38:46 +0000 (18:38 +0200)
This code simply stores a few select properties of all actors into a temporary table.

src/actsave.s
src/defs.s

index 5d9e6e7d55663a07d0c263193582951604bc62cf..b80a4456191b0e64420339f13e415aa8cf4e7741 100644 (file)
@@ -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
index d2ea1a689b71a79874d79b16e6a73f9cca7b5d8c..b5f8ae050245a9b1d6c0da6cf3667d608e2578cd 100644 (file)
        ; 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