From: Lukas Krickl Date: Wed, 1 Jan 2025 10:25:20 +0000 (+0100) Subject: map: added rotuine to link two rooms to each other X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=bc014c54dc55127d10afe82e4aae16bbb29ab463;p=gbrg%2F.git map: added rotuine to link two rooms to each other --- diff --git a/src/map.s b/src/map.s index 75dcfdc..288a251 100644 --- 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