From: Lukas Krickl Date: Sat, 15 Feb 2025 05:49:04 +0000 (+0100) Subject: rand: srand is now stored in sram X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=refs%2Fremotes%2Forigin%2Fstate-machine-movement;p=gbrg%2F.git rand: srand is now stored in sram This makes it so srand is not always the same value on boot. --- diff --git a/src/rand.s b/src/rand.s index 97b6f6d..f0a22db 100644 --- a/src/rand.s +++ b/src/rand.s @@ -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 diff --git a/src/sram.s b/src/sram.s index f4e62ea..a67ffff 100644 --- a/src/sram.s +++ b/src/sram.s @@ -9,5 +9,5 @@ ; flag for init of sram sram_magic: .adv 1 - +sram_srand: .adv 1 save_game1: .adv save_game_size diff --git a/src/update.s b/src/update.s index ad43149..cdfbefb 100644 --- a/src/update.s +++ b/src/update.s @@ -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