; 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