From: Lukas Krickl Date: Tue, 17 Feb 2026 06:59:57 +0000 (+0100) Subject: mapgen: Room patterns are now randomly chosen. X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=7d19337cc4649f142657405d3161d24bb92031af;p=gbrg%2F.git mapgen: Room patterns are now randomly chosen. Added init code for mapgen seed. --- diff --git a/assets b/assets index dfacc03..49200b3 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit dfacc03a9d29342f17f2a688733c6124edc841a7 +Subproject commit 49200b3a091eca46b333f2d636e56f371d07fe52 diff --git a/makefile b/makefile index 8c778e4..ba4d6d2 100644 --- a/makefile +++ b/makefile @@ -23,4 +23,5 @@ tiles: maps: ./tools/tmx2map.py assets/maps/l1.tmx > maps/l1.inc ./tools/tmx2map.py assets/maps/f1r1.tmx > maps/f1r1.inc + ./tools/tmx2map.py assets/maps/f1r2.tmx > maps/f1r2.inc diff --git a/maps/f1r2.inc b/maps/f1r2.inc new file mode 100644 index 0000000..9cdf1a0 --- /dev/null +++ b/maps/f1r2.inc @@ -0,0 +1,7 @@ +; this map was generated by tmx2map.py + +.db 0x1, 0x0, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1 +.db 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2 +.db 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x2 +.db 0x0, 0x0, 0x0, 0x0 + diff --git a/src/mapgen.s b/src/mapgen.s index fb7cfc1..b771602 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -10,7 +10,7 @@ map_generate: ld bc, MAP_TILES call memset - ; 1) setup seed + ; 1) setup seed,,, ; store exiting seed in tmp game seed ld a, [srand] ld [mapgen_game_seed], a @@ -164,6 +164,22 @@ mapgen_make_rooms: ; hl: start position in tile map mapgen_make_room: ; TODO: pick a room pattern + push hl + + ld b, a + call rand + dec b + and a, b ; ensure we are in range + add a, a ; *2 for offset + + ld h, 0 + ld l, a + add hl, de + push hl + pop de ; de = correct room to draw + + pop hl + ; de = room pattern to draw ld a, [de] @@ -189,8 +205,11 @@ mapgen_make_room: f1r1: #include "f1r1.inc" +f1r2: +#include "f1r2.inc" + floor1_patterns: dw f1r1 -dw f1r1 +dw f1r2 floor1_patterns_end: diff --git a/src/mem.s b/src/mem.s index 21b9d2e..3249680 100644 --- a/src/mem.s +++ b/src/mem.s @@ -12,14 +12,15 @@ mem_init: ld bc, WRAMLEN/2 call memset + ; set up rand + call rand_init + call map_globals_init ; set up shadow IE ld a, IVBLANK | ILCD ld [shadow_ie], a - ; set up rand - call rand_init ; copy shadow oam dma function ld de, shadow_oam_to_oam diff --git a/src/rand.s b/src/rand.s index 8414b11..e9b057c 100644 --- a/src/rand.s +++ b/src/rand.s @@ -12,6 +12,13 @@ rand_init: or a, 1 ld [srand+1], a + ld a, [sram_mapgen_srand] + or a, 1 + ld [mapgen_seed], a + ld a, [sram_mapgen_srand+1] + or a, 1 + ld [mapgen_seed+1], a + call mbc1_ram_disable ret @@ -26,6 +33,12 @@ rand_save_srand: ld a, [srand+1] ld [sram_srand+1], a + ; save mapgen seed in sram + ld a, [mapgen_seed] + ld [sram_mapgen_srand], a + ld a, [mapgen_seed+1] + ld [sram_mapgen_srand], a + call mbc1_ram_disable ret @@ -36,6 +49,8 @@ rand_save_srand: ; a, hl, de ; returns: ; a: random value + ; uses: + ; hl, a rand: ; load seed ld a, [srand] diff --git a/src/sram.s b/src/sram.s index 27ee968..e6ffe55 100644 --- a/src/sram.s +++ b/src/sram.s @@ -10,3 +10,4 @@ ; flag for init of sram sram_magic: .adv 1 sram_srand: .adv 2 +sram_mapgen_srand: .adv 2