map: added rotuine to link two rooms to each other
authorLukas Krickl <lukas@krickl.dev>
Wed, 1 Jan 2025 10:25:20 +0000 (11:25 +0100)
committerLukas Krickl <lukas@krickl.dev>
Wed, 1 Jan 2025 10:25:20 +0000 (11:25 +0100)
src/map.s

index 75dcfdc70068239f7b6531b5aba9d4838c51e37f..288a2510bf9f6b11f3e11223350c7002e4e6ad28 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -593,11 +593,52 @@ map_gen_reverse_direction:
   ; link two rooms together
   ; by setting up the exit pointers 
   ; for a given direction
+  ; this assumes hl and de are romb structs 
   ; inputs:
   ;   a: direction
-  ;  hl: source room header
-  ;  de: target room header
+  ;  hl: source roomb header
+  ;  de: target roomb header
 map_gen_link_rooms:
+  ; call for intial direction
+  push hl
+  push de
+  push af
+  call map_gen_link_room_to
+
+  ; now reserve 
+  pop af 
+  ld hl, map_gen_reverse_direction 
+  ld d, 0
+  ld e, a
+  add hl, de ; de = reverse direction ptr
+  ld a, [hl] ; a = reverse direction
+  ; swap original hl and de ptrs
+  pop hl
+  pop de
+  ; call map_gen_link_room_to by simply falling through here
+
+  ; links a single room to another 
+  ; inputs:
+  ;   a: direction
+  ;  hl: source roomb header
+  ;  de: target roomb header 
+map_gen_link_room_to:
+  ; skip hl and de to the exit table location 
+  ld bc, roomb_size - ROOM_EXIT_TABLE_SIZE 
+  add hl, bc ; hl = source exit table 
+
+  add a, a ; a = a * 2
+  ; now add direction 
+  ld b, 0
+  ld c, a
+  add hl, bc ; hl = exit ptr
+
+  ; store ptr in correct location
+  ld a, e
+  ld [hl+], a
+  ld a, d
+  ld [hl], a
+
   ret