This is simply done by following door pointers when a direction with
an existing door is picked.
; if not done link to next room
pop de ; de = previous room ptr
- push de ; save it again
; for now just pick a direction
call map_gen_pick_direction
+ push de ; save it again
push hl
call map_gen_link_rooms
add a, e ; this must be 0
pop de ; get de back before jumping :^)
cp a, 0
- jr nz, @again REL
+ jr z, @good_pick REL
+
+ ; if it was not a good pick we
+ ; move the room ptr from [hl] to de
+ dec hl ; hl = exit ptr
+ ld a, [hl+]
+ ld e, a
+ ld a, [hl]
+ ld d, a
+ ; fix value on the stack
+ pop bc
+ push de
+
+ jr @again REL
+@good_pick:
; get original result
ld a, [tmp]