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
+ ld [tmp], a ; tmp = h
+ ld a, l
+ ld [tmp+1], a ; tmp=1 = l
+
+@copy_header:
; this routine copies a base room
; and fixes the header accordingly
; copy header
- push hl ; save original target
ld bc, room_size
call memcpy
+ ; save next target hl
+ ; as returned by memcpy
+ push hl
+@copy_tiles:
+ ; copy tiles:
+
+ ; read header into hl
+ ld a, [tmp]
+ ld h, a
+ ld a, [tmp+1]
+ ld l, a
+
+ ; hl = new header = room tiles ptr
- ; copy tiles
- pop hl ; get target back
; read target room tiles ptr
; into hl
ld a, [hl+]
+ ld e, a
+ ld a, [hl]
+ ld d, a
+
+ ; fix the tile pointer
+ pop bc ; bc = tile ptr target
+ push bc ; need to pop into hl in a bit :^)
+
+ dec hl ; hl = room header tile ptr
+ ld a, c
+ ld [hl+], a
+ ld a, b
+ ld [hl], a
+ pop hl ; get target back
ld bc, ROOM_TILES_SIZE
call memcpy
+@copy_flags:
; copy flags
ld bc, ROOM_FLAGS_SIZE
call memcpy
+@copy_actors:
; copy actors
ld bc, ACTOR_TABLE_SIZE
call memcpy
+@setup_exits:
; set exits
pop bc ; restore default exit value