mapgen: Fixed map seed
authorLukas Krickl <lukas@krickl.dev>
Thu, 19 Feb 2026 05:03:22 +0000 (06:03 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 19 Feb 2026 05:03:22 +0000 (06:03 +0100)
Map seeds were not set correctly and restoring was also broken.

src/mapgen.s

index 3aaab421424bb75c7b334e6bccc44ae35829509a..6bebab633caecc8fdfa9998dfc10a21c27a9e92b 100644 (file)
@@ -10,11 +10,12 @@ mapgen_init_seeds:
        ; numbers into rng
        ld b, MAPGEN_FLOORS_MAX * 2
 @loop:
+               push hl
                call rand
+               pop hl
                ld [hl+], a
                dec b
-               jr z, @loop REL
-       
+               jr nz, @loop REL
        call mbc1_ram_disable
        ret
 
@@ -38,6 +39,7 @@ map_generate:
        ld [mapgen_game_seed+1], a
 
        ; load the seed
+       call mbc1_ram_enable
        call save_file_select
        ld d, 0
        ld a, [mapgen_floor]
@@ -46,7 +48,8 @@ map_generate:
        ld a, [hl+]
        ld [srand], a
        ld a, [hl]
-       ld [srand], a
+       ld [srand+1], a
+       call mbc1_ram_disable
 
        ; 2) set up map header
 
@@ -82,10 +85,11 @@ map_generate:
 
        ; cleanup) finally
        ; restore game seed from rng
-       ld [mapgen_game_seed], a
+       ld a, [mapgen_game_seed]
        ld [srand], a
-       ld [mapgen_game_seed+1], a
+       ld a, [mapgen_game_seed+1]
        ld [srand+1], a
+       BREAK
        ret
 
        ; makes a room at a sector offset