From 531137ae67b573bb90b28b9b15374bc2733461b9 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 31 Dec 2024 08:07:02 +0100 Subject: [PATCH] map: maps now set the correct tile ptr for a newly generate map --- src/map.s | 41 ++++++++++++++++++++++++++++++++++++++--- src/video.s | 2 +- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/map.s b/src/map.s index c709a9f..d7779f1 100644 --- a/src/map.s +++ b/src/map.s @@ -542,32 +542,67 @@ map_gen_next: 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 diff --git a/src/video.s b/src/video.s index 4d8e4e3..75f1ed4 100644 --- a/src/video.s +++ b/src/video.s @@ -101,7 +101,7 @@ video_init: call map_generate ; initial test map - ld de, base_room_header + ld de, map0 call room_load_from ; set up bgp -- 2.30.2