map: room linking is now generic
authorLukas Krickl <lukas@krickl.dev>
Wed, 1 Jan 2025 11:14:10 +0000 (12:14 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 1 Jan 2025 11:14:10 +0000 (12:14 +0100)
src/map.s

index 288a2510bf9f6b11f3e11223350c7002e4e6ad28..20f004c5d7cead0c73c7930917ed71cc48ae0428 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -500,8 +500,8 @@ map_generate:
   ;    a: 0 == stop recursion
   ;    a: 1 == continue recurions
 map_gen_next:
-  push hl ; save current room
   push de ; save previous room
+  push hl ; save current room
 
   ; depth ++
   ld a, [mapgen_depth]
@@ -511,7 +511,6 @@ map_gen_next:
   ; select a room 
   ; and copy it to the current position
   ; linking back NULL on all exits initially 
-  push hl
 
   ; load base room ptr
 
@@ -524,43 +523,29 @@ map_gen_next:
   ld a, [hl]
   ld d, a
   pop hl ; hl = room dst
+  push hl
 
   ; now we copy
-  push hl ; save original ptr for now
   call map_gen_copy_base_room
   ; hl = next room 
+  pop de ; de = previous room ptr 
+  push de ; save it again 
+  ld a, SOUTH ; link south for now
   push hl
-  pop bc ; bc = next room ptr
-  pop hl
-
-  ; set up link to room 2 
-  ld de, room_exit_table 
-  add hl, de ; hl = exit table ptr 
-  ld a, [hl+]
-  ld e, a
-  ld a, [hl]
-  ld d, a 
-
-  ; de = NORTH exit
-
-  ; store bc in north exit 
-  ld a, c
-  ld [de], a
-  inc de
-  ld a, b
-  ld [de], a
+  call map_gen_link_rooms
 
-  push bc
-
-  ; load base room from table
   ld hl, base_room_table
-  ld de, 2
-  add hl, de ; hl = second room entry
+  ld b, 0
+  ld c, 2 ; add 2 to load next base room 
+  add hl, bc
+
   ld a, [hl+]
   ld e, a
   ld a, [hl]
   ld d, a
-  pop hl ; hl = next room ptr again
+  
+  pop hl
+
   call map_gen_copy_base_room
 
   ; TODO end test 
@@ -580,8 +565,8 @@ map_gen_next:
   ld [mapgen_depth], a
 
   ; pop saved registers 
-  pop de
   pop hl
+  pop de
 
   ret