From 629c5d29dc1b9e364aaff1a917bdf96629101fd4 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 15 Feb 2025 06:49:04 +0100 Subject: [PATCH] rand: srand is now stored in sram This makes it so srand is not always the same value on boot. --- src/rand.s | 15 ++++++++++++++- src/sram.s | 2 +- src/update.s | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) 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 -- 2.30.2