From: Lukas Krickl Date: Sat, 5 Jul 2025 04:32:35 +0000 (+0200) Subject: exits: Added map exit loader logic X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=aeb86ba2f06c7af75f099b2f7df9264df53efcae;p=gbrg%2F.git exits: Added map exit loader logic Player position adjustments are still missing --- diff --git a/maps/default_map.s b/maps/default_map.s index e086cb6..7016845 100644 --- a/maps/default_map.s +++ b/maps/default_map.s @@ -29,6 +29,6 @@ default_map_bg: default_map_tile_flags: .db 0x27, 0x0, 0x4, 0x1, 0x48, 0x0, 0x4, 0x1 -.db 0x8, 0x0, 0x1, 0x3, 0xf, 0x0, 0x1, 0x3 +.db 0x8, 0x0, 0x1, 0x2, 0xf, 0x0, 0x1, 0x2 .db 0x70, 0x0 .db 0x00 ; termiante data diff --git a/src/defs.s b/src/defs.s index 488a59d..28ed01a 100644 --- a/src/defs.s +++ b/src/defs.s @@ -309,6 +309,7 @@ .de exit_goto_x, 1 ; pointer to new map struct .de exit_to, 2 +.de exit_size, 0 ; special text commands diff --git a/src/exittables.s b/src/exittables.s index fbea445..9dd9314 100644 --- a/src/exittables.s +++ b/src/exittables.s @@ -1,3 +1,3 @@ default_map_exit_table: -exit_def 0, 0, 0, 0, default_map_header +exit_def 0, BTNRIGHT, 0, 0, default_map_header exit_def 0, 0, 0, 0, default_map_header diff --git a/src/input.s b/src/input.s index 763051d..6018b31 100644 --- a/src/input.s +++ b/src/input.s @@ -1,6 +1,6 @@ ; checks if button was just pressed ; inputs: - ; $1 BUTTON + ; b: BUTTON ; returns: ; a: button state #macro input_just @@ -11,17 +11,17 @@ ld c, a ; c = current xor prev ld a, [curr_inputs] and a, c ; give precdence to current inputs - and a, $1 + and a, b #endmacro ; checks for a button press ; inputs: - ; $1 BUTTON + ; b: BUTTON ; returns: ; a: button state #macro input_held ld a, [curr_inputs] - and a, $1 + and a, b #endmacro ; TODO: if demo_inputs is set read from inputs instead of polling diff --git a/src/player.s b/src/player.s index ad5b3c3..839766f 100644 --- a/src/player.s +++ b/src/player.s @@ -55,9 +55,70 @@ unit_check_exit_hit: call map_get_tile ; a = flags + ld b, a ; b = flags for later use and a, CF_EXIT ret z ; if not we bail + ; now it's time to look up + ; the exit + + ; de = exit ptr + ld de, map_exit_table + ld a, [de] + ld l, a + inc de + ld a, [de] + ld h, a + + ; hl = first entry in exit table + ld a, b ; a = flags + and a, 0xF0 ; we only care about the upper nibble + swap a ; a = exit table offset + cp a, 0 ; do not do this if a == 0 + jr z, @done_calculate_ptr REL + + ; add exit size to de a times + ld de, exit_size +@calculate_ptr: + add hl, de + dec a + jr z, @calculate_ptr REL +@done_calculate_ptr: + + ; hl == the exit table entry + ; check if input is required + + inc hl ; hl = required input + ld a, [hl] + dec hl ; hl = exit flags + + cp a, 0 + jr z, @skip_input_check REL + ; if inputs is not 0 we check button state + ld b, a ; b = button mask + input_just + ret z ; if not input bail +@skip_input_check: + + ; now we can load the map + + ; load map ptr + push hl + ld de, exit_to + add hl, de ; hl = map ptr + + ld a, [hl+] + ld c, a + ld a, [hl] + ld h, a + ld a, c + ld l, a ; hl = map header ptr + call map_load + + pop hl + ; TODO + ; finally adjust player position + ret diff --git a/src/unit.s b/src/unit.s index 735f40b..c74ddd0 100644 --- a/src/unit.s +++ b/src/unit.s @@ -270,8 +270,9 @@ unit_handle_inputs: ; push next state to the stack for now ld bc, NULL push bc - - input_held BTNUP + + ld b, BTNUP + input_held jr z, @notup REL push de @@ -284,8 +285,9 @@ unit_handle_inputs: ld bc, st_unit_delay_to_active push bc @notup: - - input_held BTNDOWN + + ld b, BTNDOWN + input_held jr z, @notdown REL push de @@ -298,8 +300,9 @@ unit_handle_inputs: ld bc, st_unit_delay_to_active push bc @notdown: - - input_held BTNLEFT + + ld b, BTNLEFT + input_held jr z, @notleft REL push de @@ -312,8 +315,9 @@ unit_handle_inputs: ld bc, st_unit_delay_to_active push bc @notleft: - - input_held BTNRIGHT + + ld b, BTNRIGHT + input_held jr z, @notright REL call unit_try_move_right