rand: srand is now stored in sram origin/state-machine-movement
authorLukas Krickl <lukas@krickl.dev>
Sat, 15 Feb 2025 05:49:04 +0000 (06:49 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sat, 15 Feb 2025 05:49:04 +0000 (06:49 +0100)
This makes it so srand is not always the same value on boot.

src/rand.s
src/sram.s
src/update.s

index 97b6f6d4e23cad67944d18abf1f90d77d79cecf9..f0a22db1b9637c0b715601636b41681ac5a675d7 100644 (file)
@@ -1,9 +1,22 @@
   ; inits the random seed 
 rand_init:
-  ld a, SRAND_INITIAL
+  call mbc1_ram_enable
+
+  ld a, [sram_srand] 
   ld [srand], a
+
+  call mbc1_ram_disable
   ret
 
+  ; saves srand in sram
+rand_save_srand:
+  call mbc1_ram_enable
+  
+  ld a, [srand]
+  ld [sram_srand], a
+
+  call mbc1_ram_disable
+  ret
 
   ; gets a pseudo-random number
   ; and advances to the next seed
index f4e62ead607fc377cb4c15545631aaf3f73267f4..a67ffff310135b69f0387ace05501c93e885a881 100644 (file)
@@ -9,5 +9,5 @@
 
   ; flag for init of sram
 sram_magic: .adv 1
-
+sram_srand: .adv 1
 save_game1: .adv save_game_size
index ad4314978bf18e3bf0c4c67b50b5f81a3b0443f8..cdfbefb5f958fb7ba588635f0ac3977b0031106f 100644 (file)
@@ -9,7 +9,8 @@ update_game_over:
 
 update_game:
   ; tick rng every frame
-  call rand 
+  call rand
+  call rand_save_srand
 
   ; update player
   ld hl, player