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
.de exit_goto_x, 1
; pointer to new map struct
.de exit_to, 2
+.de exit_size, 0
; special text commands
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
; 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, b
#endmacro
; TODO: if demo_inputs is set read from inputs instead of polling
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
; 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
ld bc, st_unit_delay_to_active
push bc
@notup:
-
- input_held BTNDOWN
+
+ ld b, BTNDOWN
+ input_held
jr z, @notdown REL
push de
ld bc, st_unit_delay_to_active
push bc
@notdown:
-
- input_held BTNLEFT
+
+ ld b, BTNLEFT
+ input_held
jr z, @notleft REL
push de
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