exits: Added map exit loader logic
authorLukas Krickl <lukas@krickl.dev>
Sat, 5 Jul 2025 04:32:35 +0000 (06:32 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 5 Jul 2025 04:32:35 +0000 (06:32 +0200)
Player position adjustments are still missing

maps/default_map.s
src/defs.s
src/exittables.s
src/input.s
src/player.s
src/unit.s

index e086cb6c1bf68ae9e53717ddfa8326ee8c001440..7016845ae6b398da457d9bc10ea2bec4025a2c61 100644 (file)
@@ -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
index 488a59dc80c067cf0c75c80b6b95d03baee69084..28ed01af8fd5204f2fbf1fcf6da2d55a2ea34048 100644 (file)
 .de exit_goto_x, 1
   ; pointer to new map struct
 .de exit_to, 2
+.de exit_size, 0
 
 ; special text commands
 
index fbea4454a9a6ad1420fbfeb3367e7e84af0a99fc..9dd931461ea228a1ecff4e44ed8b284343677729 100644 (file)
@@ -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 
index 763051dd73773e1a84ed495e43ef7d124299ffae..6018b3188445c3d30a791f4de4510bc32f47695e 100644 (file)
@@ -1,6 +1,6 @@
   ; checks if button was just pressed
   ; inputs: 
-  ;   $1 BUTTON
+  ;   b: BUTTON
   ; returns:
   ;   a: button state
 #macro input_just
   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, 
 #endmacro
   
   ; TODO: if demo_inputs is set read from inputs instead of polling 
index ad5b3c31a25d300f32a67c5f67b0cb57b1d27741..839766f05b3cc499f3457ee20ecc61d5e5f33cdf 100644 (file)
@@ -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
 
 
index 735f40b7ac7eb727dcc56ec5e73f2a918c71031b..c74ddd035eb7375a92bd0b7a24182d0189fdd414 100644 (file)
@@ -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