You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
6.0 KiB

;; ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
;; █▄░▄█░▄▄▀█▀▄▄▀█░██░█▄░▄██
;; ██░██░██░█░▀▀░█░██░██░███
;; █▀░▀█▄██▄█░█████▄▄▄██▄███
;; ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
;; Handles the player inputs
2 years ago
; Read the current input state
; <- b: current keystates
; <- c: changed keys since last read
2 years ago
read_input:
di
; read right, left, up and down
ld a, %00100000
ld [INPUT_REGISTER], a
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
and a, $0f
swap a
ld b, a
; read a, b, select and start
ld a, %00010000
ld [INPUT_REGISTER], a
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
ld a, [INPUT_REGISTER]
and a, $0f
or a, b
cpl
ld b, a
; check for changed keystates
ld a, [input_state]
xor a, b
and a, b
ld c, a
ld a, b
ld [input_state], a
reti
; React to input within the menu
; -> c: the changed keystate
2 years ago
handle_input_menu:
2 years ago
.check_movement:
2 years ago
ld a, c
2 years ago
and a, INPUT_UP | INPUT_DOWN
jp z, .check_confirm
ld a, [sub_state]
2 years ago
; flip the corresponding bits
xor a, STATE_MENU_START + STATE_MENU_HELP
2 years ago
ld [sub_state], a
2 years ago
and a, STATE_MENU_START
2 years ago
jp z, .switch_to_help
2 years ago
.switch_to_start
call show_message_menu_start
jp .check_confirm
2 years ago
.switch_to_help
call show_message_menu_help
jp .check_confirm
.check_confirm
ld a, c
and a, INPUT_START | INPUT_A
jp z, .return
ld a, [sub_state]
and a, STATE_MENU_START
jp z, .help_selected
.start_selected
2 years ago
call init_state_game
2 years ago
jp .return
.help_selected
2 years ago
call init_state_help
2 years ago
jp .return
.return
2 years ago
ret
; React to input within the help screen
; -> c: the changed keystate
2 years ago
handle_input_help:
ld a, c
and a, INPUT_START
jp z, .return
call init_state_game
.return
ret
; React to input within the main game
; -> c: the changed keystate
; <- [selected_letter_x]
; <- [selected_letter_y]
2 years ago
handle_input_game:
ld a, [selected_letter_x]
ld d, a
ld a, [selected_letter_y]
ld e, a
.check_start:
ld a, c
and a, INPUT_START
jp z, .check_select
call init_state_game
.check_select:
ld a, c
and a, INPUT_SELECT
jp z, .check_right
call check_guess
.check_right:
ld a, c
and a, INPUT_RIGHT
jp z, .check_left
ld a, d
cp a, $08
jp z, .overflow_right
2 years ago
inc d
jp .check_left
.overflow_right:
ld d, 0
2 years ago
.check_left:
ld a, c
and a, INPUT_LEFT
jp z, .check_up
ld a, d
cp a, 0
jp z, .overflow_left
2 years ago
dec d
jp .check_up
.overflow_left:
ld d, 8
2 years ago
.check_up:
ld a, c
and a, INPUT_UP
jp z, .check_down
ld a, e
cp a, 0
jp z, .overflow_up
2 years ago
dec e
jp .check_down
.overflow_up:
ld e, 2
2 years ago
.check_down:
ld a, c
and a, INPUT_DOWN
jp z, .check_a
ld a, e
cp a, $02
jp z, .overflow_down
2 years ago
inc e
jp .check_a
.overflow_down:
ld e, 0
2 years ago
.check_a:
ld a, c
and a, INPUT_A
jp z, .check_b
call select_letter
.check_b:
ld a, c
and a, INPUT_B
jp z, .update_pos
call delete_letter
.update_pos
ld a, d
ld [selected_letter_x], a
ld a, e
ld [selected_letter_y], a
ret
; React to input after a game round,
; no matter if won or lost
; -> c: the changed keystate
2 years ago
handle_input_after:
ld a, c
and a, INPUT_START
jp z, .nothing
call init_state_game
call clear_message
.nothing
ret
; Select a character and add it to the current guess
2 years ago
; -> d: x position of the cursor
; -> e: y position of the cursor
; <- [current_guess]
; <- [current_char]
; <- [guesses]
2 years ago
select_letter:
push hl
push af
push bc
push de
; get the selected letter index
ld a, e
ld b, 9
call multiply_ab
add a, d
inc a
2 years ago
ld c, a
; check if it's enter
ld a, c
cp a, 27
2 years ago
jp nz, .normal_letter
call check_guess
jp .return
.normal_letter:
ld hl, guesses
ld a, [current_guess]
ld b, 5
call multiply_ab
ld b, a
ld a, [current_char]
cp a, 5
jp z, .return
add a, b
ld d, 0
ld e, a
add hl, de
ld [hl], c
ld a, [current_char]
inc a
ld [current_char], a
.return:
pop de
pop bc
pop af
pop hl
ret
; Delete the last entered letter
; <- [current_guess]
; <- [current_char]
; <- [guesses]
2 years ago
delete_letter:
push hl
push af
push bc
push de
ld hl, guesses
ld a, [current_guess]
ld b, 5
call multiply_ab
ld b, a
ld a, [current_char]
ld c, a
cp a, 0
jp z, .return
add a, b
dec a
ld d, 0
ld e, a
add hl, de
ld [hl], NULL
ld a, c
dec a
ld [current_char], a
.return:
pop de
pop bc
pop af
pop hl
ret
2 years ago
; Update the object data for the alphabet cursor
; -> [selected_letter_x]
; -> [selected_letter_y]
; <- [obj_selected_letter]
2 years ago
update_cursor_objects:
ld hl, obj_selected_letter
; vertical position
ld a, [selected_letter_y]
ld b, $08
call multiply_ab
2 years ago
add a, $80
2 years ago
ld [hl+], a
; horizontal position
ld a, [selected_letter_x]
ld b, $10
call multiply_ab
add a, $14
ld [hl+], a
; tile index
ld a, [selected_letter_x]
ld c, a
ld a, [selected_letter_y]
ld b, $09
call multiply_ab
add a, c
inc a
; char 27 doesn't exist, it's the enter sign
cp a, 27
jp nz, .not_enter
ld a, TILE_ENTER
.not_enter:
ld [hl+], a
; attributes
ld a, OBJ_ATTR_PALETTE1
ld [hl+], a
ret
2 years ago