ld a, [hl]
ld d, a
pop hl ; hl = room dst
-
- ; set default exit ptr to 0000
- ; to indicate it is empty
- xor a, a
- ld b, a
- ld c, a
; now we copy
push hl ; save original ptr for now
ld [mapgen_depth], a
ret
- ; copies a base room
+ ; copies a base room
+ ; sets all exits to 0000 (null ptr)
; inputs:
; de: base room
; hl: target
- ; bc: default exit room ptr
map_gen_copy_base_room:
- push bc
-
; save original hl in tmp
; this can then be used as a ptr to the struct
ld a, h
pop bc ; bc = tile ptr target
push bc ; need to pop into hl in a bit :^)
+ ; set tiles ptr
dec hl ; hl = room header tile ptr
ld a, c
ld [hl+], a
pop hl ; get target back
ld bc, ROOM_TILES_SIZE
call memcpy
+ push hl ; save hl again just like before
@copy_flags:
+
+ ; hl = header
+ ld a, [tmp]
+ ld h, a
+ ld a, [tmp+1]
+ ld l, a
+
+ ld bc, room_flags
+ add hl, bc ; hl = flags ptr
+
+ ; read src flags into de
+ ld a, [hl+]
+ ld e, a
+ ld a, [hl]
+ ld d, a
+
+ ; fix flags ptr
+ pop bc ; bc = flags ptr target
+ push bc ; push again to get the value into hl later
+
+ ; set flags ptr
+ dec hl ; hl = room flag ptr
+ ld a, c
+ ld [hl+], a
+ ld a, b
+ ld [hl], a
+
+ pop hl ; get target back
+
; copy flags
ld bc, ROOM_FLAGS_SIZE
call memcpy
+ push hl ; save hl again
@copy_actors:
+ ; hl = header
+ ld a, [tmp]
+ ld h, a
+ ld a, [tmp+1]
+ ld l, a
+
+ ld bc, room_actor_table
+ add hl, bc ; hl = flags ptr
+
+ ; read src actors into de
+ ld a, [hl+]
+ ld e, a
+ ld a, [hl]
+ ld d, a
+
+ ; fix flags ptr
+ pop bc ; bc = actors ptr target
+ push bc ; push again to get the value into hl later
+
+ ; set actor ptr
+ dec hl ; hl = room actor ptr
+ ld a, c
+ ld [hl+], a
+ ld a, b
+ ld [hl], a
+
+ pop hl ; get target back
+
; copy actors
ld bc, ACTOR_TABLE_SIZE
call memcpy
+ push hl ; save again for later
@setup_exits:
- ; set exits
- pop bc ; restore default exit value
+ ; fix exit table
+ ; hl = header
+ ld a, [tmp]
+ ld h, a
+ ld a, [tmp+1]
+ ld l, a
+
+ ld bc, room_exit_table
+ add hl, bc ; hl = flags ptr
+
+ pop bc ; bc = exit table location
+ push bc ; push again we need value back in hl soon :^)
+
+ ; set exit table ptr
+ ld a, c
+ ld [hl+], a
+ ld a, b
+ ld [hl], a
+
+ pop hl ; hl = exit table location
+ ; set exits to NULL
+ xor a, a
+.rep ci, 2 * ROOM_EXITS_MAX, 1, ld a, [hl+]
ret