dos33fsprogs/ootw/keyboard.s

231 lines
2.9 KiB
ArmAsm
Raw Normal View History

;======================================
; handle keypress
;======================================
handle_keypress:
lda PHYSICIST_STATE
cmp #P_COLLAPSING ; ignore keypress if dying
beq no_keypress
lda KEYPRESS ; 4
bmi keypress ; 3
no_keypress:
rts ; nothing pressed, return
keypress:
; -1
and #$7f ; clear high bit
check_quit:
2019-03-15 17:00:47 +00:00
cmp #27 ; quit if ESCAPE pressed
bne check_walk_left
;=====================
; QUIT
;=====================
quit:
lda #$ff ; could just dec
sta GAME_OVER
rts
2019-03-15 17:00:47 +00:00
check_walk_left:
cmp #'A'
2019-03-15 17:00:47 +00:00
beq walk_left
cmp #$8 ; left arrow
2019-03-15 17:00:47 +00:00
bne check_walk_right
2019-03-15 17:00:47 +00:00
;====================
; Walk left
;====================
walk_left:
lda #P_WALKING
sta PHYSICIST_STATE ; stand from crouching
lda DIRECTION ; if facing right, turn to face left
bne face_left
2019-03-10 06:21:35 +00:00
inc GAIT ; cycle through animation
lda GAIT
and #$7
cmp #$4
bne no_move_left
dec PHYSICIST_X ; walk left
2019-03-10 06:21:35 +00:00
no_move_left:
lda PHYSICIST_X
cmp LEFT_LIMIT
bpl just_fine_left
too_far_left:
inc PHYSICIST_X
lda #1
sta GAME_OVER
just_fine_left:
jmp done_keypress ; done
face_left:
lda #0
sta DIRECTION
sta GAIT
jmp done_keypress
2019-03-15 17:00:47 +00:00
check_walk_right:
cmp #'D'
2019-03-15 17:00:47 +00:00
beq walk_right
cmp #$15
2019-03-15 17:00:47 +00:00
bne check_run_left
;===================
; Walk Right
;===================
walk_right:
lda #P_WALKING
sta PHYSICIST_STATE
lda DIRECTION
beq face_right
2019-03-10 06:21:35 +00:00
inc GAIT
lda GAIT
and #$7
cmp #$4
bne no_move_right
inc PHYSICIST_X
2019-03-10 06:21:35 +00:00
no_move_right:
lda PHYSICIST_X
cmp RIGHT_LIMIT
bne just_fine_right
too_far_right:
dec PHYSICIST_X
lda #2
sta GAME_OVER
just_fine_right:
2019-03-10 06:21:35 +00:00
jmp done_keypress
face_right:
lda #0
sta GAIT
lda #1
sta DIRECTION
jmp done_keypress
2019-03-15 17:00:47 +00:00
check_run_left:
cmp #'Q'
bne check_run_right
;====================
; Run left
;====================
run_left:
lda #P_RUNNING
sta PHYSICIST_STATE ; stand from crouching
lda DIRECTION ; if facing right, turn to face left
bne face_left
inc GAIT ; cycle through animation
inc GAIT ; cycle through animation
dec PHYSICIST_X ; walk left
jmp no_move_left
check_run_right:
cmp #'E'
bne check_up
;===================
; Run Right
;===================
run_right:
lda #P_RUNNING
sta PHYSICIST_STATE
lda DIRECTION
beq face_right
inc GAIT
inc GAIT
inc PHYSICIST_X
jmp no_move_right
check_up:
cmp #'W'
beq up
cmp #$0B
bne check_down
up:
;========================
; Jump
;========================
lda #P_JUMPING
sta PHYSICIST_STATE
lda #0
sta GAIT
jmp done_keypress
check_down:
cmp #'S'
beq down
cmp #$0A
bne check_space
2019-03-15 17:00:47 +00:00
;======================
; Crouch
;======================
down:
lda #P_CROUCHING
sta PHYSICIST_STATE
lda #0
sta GAIT
jmp done_keypress
check_space:
cmp #' '
beq space
cmp #$15
bne unknown
2019-03-15 17:00:47 +00:00
;======================
; Kick
;======================
space:
lda #P_KICKING
sta PHYSICIST_STATE
lda #15
sta GAIT
unknown:
done_keypress:
bit KEYRESET ; clear the keyboard strobe ; 4
rts ; 6