From ec41528cc20d9dccc34a53248f85be0a320463cc Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 26 Jul 2025 14:37:12 +0200 Subject: [PATCH] roomgen: wip room generation This is currently rather broken and corrupts the map :^) --- src/defs.s | 5 +++++ src/map.s | 48 ++++++++++++++++++++++++++++++++++++++++++++ src/mapgen.s | 50 ++++++++++++++++++++++++++++++++++++++++------ src/roompatterns.s | 2 +- 4 files changed, 98 insertions(+), 7 deletions(-) diff --git a/src/defs.s b/src/defs.s index bff715d..8d58554 100644 --- a/src/defs.s +++ b/src/defs.s @@ -222,6 +222,11 @@ #define MAP_NAME_LEN 8 + ; map flags1 +.se 1 + ; disables random generation +.de MAPF1_NO_RAND, 1 + ; map header struct .se 0 .de map_flags_1, 1 diff --git a/src/map.s b/src/map.s index ca1b648..cf9de48 100644 --- a/src/map.s +++ b/src/map.s @@ -41,6 +41,10 @@ map_load: push hl call map_load_exit_table pop hl + + push hl + call map_call_gen + pop hl call map_draw_all @@ -51,6 +55,50 @@ map_load: ret + ; calls mapgen unless disabled + ; for current map + ; loads the seed based on map offset + ; inputs: + ; hl: map_ptr +map_call_gen: + push hl + + ; check if rand is disabled + ld de, map_flags_1 + add hl, de + ld a, [hl] + and a, MAPF1_NO_RAND + + pop hl + ; bail if flag is set + ret nz + + ; load seed offset + push hl + + ld de, map_seed_index + add hl, de ; hl = seed index + ld a, [hl] + + ; * 2 because it is a 2-byte table + add a, a + ld d, 0 + ld e, a + ld hl, map_seeds + add hl, de + ; hl = seeds+offset + ld a, [hl+] ; a = seed LO + ld d, a + ld a, [hl] + ld e, a ; de = seed + + pop hl + + ld hl, map + call mapgen + + ret + ; draws map title to UI ; inputs: ; hl: map_ptr diff --git a/src/mapgen.s b/src/mapgen.s index 9420e41..c101245 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -70,6 +70,8 @@ mapgen: ; inputs: ; hl: [map] mapgen_up_left_room: + ld bc, room_pattern_6by6 + call mapgen_draw_room_pattern ret ; draws a room pattern to the map @@ -90,12 +92,37 @@ mapgen_draw_room_pattern: inc bc ; move past header ; bc = first room pattern entry @y_loop: + push hl call mapgen_draw_room_pattern_row + pop hl + + push bc + ld bc, MAP_W + add hl, bc ; next row + pop bc + dec d jr nz, @y_loop REL ret + ; reads a value from a table + ; inputs: + ; a: pattern value + ; $1: table name + ; preserves: hl and de +#macro mapgen_read_value_from_table + push hl + push de + ld hl, $1 + ld d, 0 + ld e, a + add hl, de ; hl = offset into table + ld a, [hl] + pop de + pop hl +#endmacro + ; draws a single map pattern row ; writes tile flags ; inputs: @@ -111,15 +138,26 @@ mapgen_draw_room_pattern_row: push de @x_loop: ld a, [bc] - inc bc ; next pattern ; read from tile and flag tables and write to map - push hl - push de - ld hl, room_pattern_tile_translation + + ; tile table first + mapgen_read_value_from_table room_pattern_tile_translation + + ; write to map + ld [hl+], a ; write tile - pop de - pop hl + ; read pattern again + ld a, [bc] + + ; now flags table + mapgen_read_value_from_table room_pattern_flags_translation + + ; write to flags + ld [hl+], a + + ; hl = next tile + inc bc ; next pattern ; tiles-- dec e diff --git a/src/roompatterns.s b/src/roompatterns.s index dcfb369..35e9b1b 100644 --- a/src/roompatterns.s +++ b/src/roompatterns.s @@ -72,7 +72,7 @@ room_pattern_tile_translation: .db 0x00, 0x00, 0x00, 0x00 ; translation table for flags -room_pattern_floor1_flags_translation: +room_pattern_flags_translation: ; walls .db CF_COLLISION, CF_COLLISION, CF_COLLISION .db CF_COLLISION, CF_COLLISION, CF_COLLISION -- 2.30.2