map: maps now set the correct tile ptr for a newly generate map
authorLukas Krickl <lukas@krickl.dev>
Tue, 31 Dec 2024 07:07:02 +0000 (08:07 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 31 Dec 2024 07:07:02 +0000 (08:07 +0100)
src/map.s
src/video.s

index c709a9fe8397af45472f6a667f5193b9f94105a2..d7779f118260ca6e0f2ab823599db3ac1750da8f 100644 (file)
--- 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 
 
index 4d8e4e3cea90e169cbb3354bb7ddfbae21f46575..75f1ed43cbc4da47b27caf2ceb4d07dc0782ea1a 100644 (file)
@@ -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