push hl
call map_load_exit_table
pop hl
+
+ push hl
+ call map_call_gen
+ pop hl
call map_draw_all
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
; 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
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:
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
.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