dos33fsprogs/ootw/keyboard.s

300 lines
4.3 KiB
ArmAsm
Raw Normal View History

;======================================
; handle keypress
;======================================
2019-03-23 15:44:45 +00:00
; A or <- : start moving left
; D or -> : start moving right
2019-07-11 16:30:34 +00:00
; W or up : jump or elevator/transporter up
; S or down : crouch or pickup or elevator/transporter down
2019-03-23 15:44:45 +00:00
; space : action
; escape : quit
; if left: if running right, walk right
; if walk right, stand right
; if stand right, stand left
; if stand left, walk left
; if walk left, run left
handle_keypress:
lda PHYSICIST_STATE
cmp #P_COLLAPSING ; ignore keypress if dying
beq no_keypress
cmp #P_JUMPING ; ignore keypress if jumping
beq no_keypress
2019-03-17 05:28:42 +00:00
cmp #P_SWINGING
beq no_keypress
cmp #P_FALLING_SIDEWAYS
2019-03-17 05:28:42 +00:00
beq no_keypress
2019-08-09 19:00:34 +00:00
cmp #P_FALLING_DOWN
beq no_keypress
cmp #P_IMPALED
beq no_keypress
lda KEYPRESS ; 4
bmi keypress ; 3
no_keypress:
2019-03-17 05:28:42 +00:00
bit KEYRESET ; clear
; avoid keeping old keys around
rts ; nothing pressed, return
keypress:
; -1
and #$7f ; clear high bit
;======================
; check escape
check_quit:
2019-03-15 17:00:47 +00:00
cmp #27 ; quit if ESCAPE pressed
bne check_left
2019-03-15 17:00:47 +00:00
;=====================
; QUIT
;=====================
quit:
lda #$ff ; could just dec
sta GAME_OVER
rts
;======================
; check left
check_left:
cmp #'A'
beq left_pressed
cmp #$8 ; left arrow
bne check_right
2019-03-15 17:00:47 +00:00
2019-03-15 17:00:47 +00:00
;====================
; Left Pressed
2019-03-15 17:00:47 +00:00
;====================
left_pressed:
; left==0
lda DIRECTION ; if facing right, turn to face left
bne left_going_right
left_going_left:
lda PHYSICIST_STATE
cmp #P_STANDING
beq walk_left
2019-08-09 04:37:07 +00:00
cmp #P_SHOOTING
beq walk_left
cmp #P_WALKING
beq run_left
2019-03-27 03:12:44 +00:00
cmp #P_CROUCHING
beq stand_left
;=============================
; already running, do nothing?
rts
left_going_right:
lda PHYSICIST_STATE
cmp #P_RUNNING
beq walk_right
cmp #P_WALKING
beq stand_right
cmp #P_STANDING
beq stand_left
2019-08-09 04:37:07 +00:00
cmp #P_SHOOTING
beq stand_left
2019-03-27 03:12:44 +00:00
cmp #P_CROUCHING
beq stand_left
;===========================
; otherwise?
rts
;========================
; check for right pressed
check_right:
cmp #'D'
beq right_pressed
cmp #$15
bne check_up
2019-03-15 17:00:47 +00:00
;===================
; Right Pressed
2019-03-15 17:00:47 +00:00
;===================
right_pressed:
2019-03-10 06:21:35 +00:00
; right==1
lda DIRECTION ; if facing right, turn to face left
beq right_going_left
2019-03-10 06:21:35 +00:00
right_going_right:
lda PHYSICIST_STATE
cmp #P_STANDING
beq walk_right
2019-08-09 04:37:07 +00:00
cmp #P_SHOOTING
beq walk_right
cmp #P_WALKING
beq run_right
2019-03-27 03:12:44 +00:00
cmp #P_CROUCHING
beq stand_right
;=============================
; already running, do nothing?
rts
right_going_left:
lda PHYSICIST_STATE
cmp #P_RUNNING
beq walk_left
cmp #P_WALKING
beq stand_left
cmp #P_STANDING
beq stand_right
2019-08-09 04:37:07 +00:00
cmp #P_SHOOTING
beq stand_right
2019-03-27 03:12:44 +00:00
cmp #P_CROUCHING
beq stand_left
;===========================
; otherwise?
rts
2019-03-10 06:21:35 +00:00
;=====================
; Left, direction=0
; Right, direction=1
stand_left:
lda #0 ; left
sta DIRECTION
sta GAIT
lda #P_STANDING
beq update_state
2019-03-15 17:00:47 +00:00
walk_left:
lda #P_WALKING
bne update_state
2019-03-15 17:00:47 +00:00
run_left:
lda #P_RUNNING
bne update_state
2019-03-15 17:00:47 +00:00
stand_right:
lda #0
sta GAIT
lda #1 ; just inc DIRECTION?
sta DIRECTION
lda #P_STANDING
beq update_state
2019-03-15 17:00:47 +00:00
walk_right:
lda #P_WALKING
bne update_state
2019-03-15 17:00:47 +00:00
run_right:
lda #P_RUNNING
bne update_state
update_state:
2019-03-15 17:00:47 +00:00
sta PHYSICIST_STATE
bit KEYRESET
rts
2019-03-15 17:00:47 +00:00
;=====================
; check up
2019-03-15 17:00:47 +00:00
check_up:
cmp #'W'
beq up
cmp #$0B
bne check_down
up:
;========================
2019-07-11 16:30:34 +00:00
; UP -- Jump
2019-03-15 17:00:47 +00:00
;========================
2019-07-11 16:30:34 +00:00
lda ON_ELEVATOR
beq up_not_elevator
up_on_elevator:
lda #P_ELEVATING_UP
sta PHYSICIST_STATE
lda #0
sta GAIT
jmp done_keypress
up_not_elevator:
2019-03-15 17:00:47 +00:00
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
;======================
2019-07-11 16:30:34 +00:00
; DOWN -- Crouch
2019-03-15 17:00:47 +00:00
;======================
down:
2019-07-11 16:30:34 +00:00
lda ON_ELEVATOR
beq down_not_elevator
down_on_elevator:
lda #P_ELEVATING_DOWN
sta PHYSICIST_STATE
lda #0
sta GAIT
jmp done_keypress
down_not_elevator:
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
;======================
2019-08-09 04:37:07 +00:00
; Kick or shoot
2019-03-15 17:00:47 +00:00
;======================
space:
2019-08-09 04:37:07 +00:00
lda HAVE_GUN
beq kick
shoot:
lda #P_SHOOTING
sta PHYSICIST_STATE
jmp done_keypress
kick:
lda #P_KICKING
sta PHYSICIST_STATE
lda #15
sta GAIT
unknown:
done_keypress:
bit KEYRESET ; clear the keyboard strobe ; 4
rts ; 6