; 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]
; select a room
; and copy it to the current position
; linking back NULL on all exits initially
- push hl
; load base room ptr
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
ld [mapgen_depth], a
; pop saved registers
- pop de
pop hl
+ pop de
ret