; 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
; 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: