mapgen: wip room patter drawing
authorLukas Krickl <lukas@krickl.dev>
Sat, 26 Jul 2025 05:22:33 +0000 (07:22 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 26 Jul 2025 05:22:33 +0000 (07:22 +0200)
src/defs.s
src/mapgen.s
src/roompatterns.s

index 0f1c3f7f132cb95fff852de715af624e36e60c1c..bff715d2aa6587cbbb846fce0a06584913f34a75 100644 (file)
@@ -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
index 54aace596ec7af0eb12ba0b713e5b415f3968aa6..9420e419042d1e5e161ffa067276b1440b959cfc 100644 (file)
@@ -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
index 69c9876eb321b420970befeca216f33a3cfbb91b..dcfb3699e51e1e659fccf3a47017cb0a761cc870 100644 (file)
@@ -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: