This is done by writing the flags and tiles when linking.
Also added a memcpy that will skip copying if the value is not zero.
.db 1 , 64 , 72 , 0
.db 1 , 48 , 56 , 0
base_room_bg:
-.db 0x60, 0x62, 0x62, 0x64, 0x40, 0x40, 0x66, 0x62, 0x62, 0x68, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x46, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x48, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe2, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x6c, 0x4a, 0x4a, 0x42, 0x40, 0x40, 0x44, 0x4a, 0x4a, 0x6e
+.db 0x60, 0x62, 0x62, 0x64, 0x62, 0x62, 0x66, 0x62, 0x62, 0x68, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x46, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe0, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x48, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe2, 0x4c, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x6a, 0x6c, 0x4a, 0x4a, 0x42, 0x4a, 0x4a, 0x44, 0x4a, 0x4a, 0x6e
base_room_flags:
-.db 0x1, 0x1, 0x1, 0x1, 0x2, 0x2, 0x1, 0x1, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0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, 0x1, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1
#define TWALLD1 0x4A
#define TWALLL1 0x4C
+#define TEXIT1 0x4E
+
; count of all pointers in base room table
#define BASE_ROOM_TABLE_LEN ((base_room_table_end - base_room_table) / 2)
; hl: source roomb header
; de: target roomb header
map_gen_link_room_to:
+ call map_gen_fix_room_door
+
; skip hl and de to the exit table location
ld bc, roomb_size - ROOM_EXIT_TABLE_SIZE
add hl, bc ; hl = source exit table
ret
+ ; fixes a room's wall by placing a door in the desired position
+ ; and flagging the wall as a door instead
+ ; inputs:
+ ; a: direction
+ ; hl: source roomb header
+ ; registers are preserved
+map_gen_fix_room_door:
+ push hl
+ push af
+ push de
+
+ ld bc, room_size
+ add hl, bc ; hl = tile map
+
+ ; need different logic based on direction
+ cp a, NORTH
+ jr nz, @not_north REL
+
+ ld d, 0
+ ld e, 0x04
+ add hl, de ; go to door tile
+
+ ld a, TEXIT1
+ ld [hl+], a
+ ld [hl], a
+
+ dec hl ; hl is back to tile
+ ; now set flags
+
+ ld de, ROOM_TILES_SIZE
+ add hl, de ; hl = flags area
+
+ ld a, RF_DOOR
+ ld [hl+], a
+ ld [hl], a
+
+ jp @done
+@not_north:
+
+ cp a, SOUTH
+ jr nz, @not_south REL
+
+ ld de, ROOM_TILES_SIZE - 6
+ add hl, de ; go to door tile
+
+ ld a, TEXIT1
+ ld [hl+], a
+ ld [hl], a
+
+ dec hl ; hl is back to tile
+ ; now set flags
+
+ ld de, ROOM_TILES_SIZE
+ add hl, de ; hl = flags area
+
+ ld a, RF_DOOR
+ ld [hl+], a
+ ld [hl], a
+
+ jp @done
+@not_south:
+
+ cp a, EAST
+ jr nz, @not_east REL
+
+ ; TODO
+
+ jp @done
+@not_east:
+
+ cp a, WEST
+ jr nz, @not_west REL
+
+ ; TODO
+
+ ; no need to jp @done here
+@not_west:
+
+@done:
+ pop de
+ pop af
+ pop hl
+ ret
+
; copies a base room
; sets all exits to 0000 (null ptr)
pop hl ; get target back
ld bc, ROOM_TILES_SIZE
- call memcpy
+ call memcpyz
push hl ; save hl again just like before
@copy_flags:
; copy flags
ld bc, ROOM_FLAGS_SIZE
- call memcpy
+ call memcpyz
push hl ; save hl again
@copy_actors:
ret
+ ; same as memcpy
+ ; but only performs a write
+ ; if the value is currently 0
+memcpyz:
+@loop:
+ ; skip check
+ ld a, [hl]
+ cp a, 0
+ jr nz, @skip REL
+
+ ld a, [de]
+ ld [hl], a
+@skip:
+ inc hl
+ inc de
+ dec bc
+ ld a, b
+ or a, c
+ jp nz, @loop
+
+ ret
+
; sets a memory location to a specific value
; inputs:
; hl: destination
.chr 00000000
.chr 00000000
; tile 177
-.chr 00000000
-.chr 00100000
-.chr 00000100
-.chr 00010000
-.chr 00000000
-.chr 00100000
-.chr 00000100
-.chr 10000000
+.chr 11111111
+.chr 11111111
+.chr 11111111
+.chr 11111111
+.chr 11111111
+.chr 11111111
+.chr 11111111
+.chr 11111111
; tile 178
.chr 33333333
.chr 33333333
.chr 31122123
.chr 32122113
; tile 206
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
; tile 207
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
; tile 208
.chr 30222222
.chr 30222222
.chr 32122123
.chr 32122113
; tile 222
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
; tile 223
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
-.chr 00000000
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
+.chr 22222222
; tile 224
.chr 33333333
.chr 33322222