From 290dc0d6d00e19c5a661b541e84e90ac3db367a3 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 26 Jul 2025 07:22:33 +0200 Subject: [PATCH] mapgen: wip room patter drawing --- src/defs.s | 3 ++- src/mapgen.s | 49 ++++++++++++++++++++++++++++++++++++++++++++++ src/roompatterns.s | 7 +++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/defs.s b/src/defs.s index 0f1c3f7..bff715d 100644 --- a/src/defs.s +++ b/src/defs.s @@ -75,7 +75,8 @@ ; the upper nibble is ; an index into the current map's ; exit table -.de CF_EXIT, 1 +.de CF_EXIT, 2 +.de CF_DOOR, 4 ; cells struct .se 0 diff --git a/src/mapgen.s b/src/mapgen.s index 54aace5..9420e41 100644 --- a/src/mapgen.s +++ b/src/mapgen.s @@ -77,4 +77,53 @@ mapgen_up_left_room: ; hl: origin inside of map struct ; bc: room pattern header pointer mapgen_draw_room_pattern: + ld a, [bc] ; read room pattern size + and a, 0x0F ; number of tiles per row + ; e = tile per row counter + ld e, a + + ld a, [bc] + and a, 0xF0 ; number of rows + swap a + ld d, a ; d = number of rows + + inc bc ; move past header + ; bc = first room pattern entry +@y_loop: + call mapgen_draw_room_pattern_row + dec d + jr nz, @y_loop REL + + ret + + ; draws a single map pattern row + ; writes tile flags + ; inputs: + ; hl: map ptr + ; bc: room pattern + ; e: tiles per row counter + ; preserves: + ; de + ; returns: + ; hl: incremented by number of tiles * c_size + ; bc: incremented by number of tiles +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 + + pop de + pop hl + + ; tiles-- + dec e + jr nz, @x_loop REL + + pop de ret diff --git a/src/roompatterns.s b/src/roompatterns.s index 69c9876..dcfb369 100644 --- a/src/roompatterns.s +++ b/src/roompatterns.s @@ -73,6 +73,13 @@ room_pattern_tile_translation: ; translation table for flags room_pattern_floor1_flags_translation: + ; walls + .db CF_COLLISION, CF_COLLISION, CF_COLLISION + .db CF_COLLISION, CF_COLLISION, CF_COLLISION + .db CF_COLLISION, CF_COLLISION + .db 0x00 ; floor + ; doors + .db CF_DOOR, CF_DOOR, CF_DOOR, CF_DOOR ; table of 6 by 6 room patterns room_pattern_6by6: -- 2.30.2