dos33fsprogs/ootw/keyboard.s

418 lines
6.5 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
; L : charge gun
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
2019-08-17 19:27:17 +00:00
; if up: if crouching, stand up
; if standing, jump
; if walking, jump
; if running, run-jump
; if down: if standing, crouch
; if walking, crouch
; if if running, slide-crouch
2019-03-23 15:44:45 +00:00
handle_keypress:
lda PHYSICIST_STATE
bmi no_keypress ; ignore keypress if dying/action
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/A Pressed
;====================
2019-03-15 17:00:47 +00:00
;====================
left_pressed:
inc GUN_FIRE ; fire gun if charging
; 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
and #STATE_CROUCHING
bne 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
and #STATE_CROUCHING
bne 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/D Pressed
;===================
2019-03-15 17:00:47 +00:00
;===================
right_pressed:
inc GUN_FIRE ; fire if charging
2019-03-10 06:21:35 +00:00
; right==1
lda DIRECTION ; if facing left, turn to face right
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
and #STATE_CROUCHING
bne 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
and #STATE_CROUCHING
bne stand_right
;===========================
; 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:
;=============================
;=============================
; Up/W Pressed -- Jump, Get up
;=============================
;=============================
2019-03-15 17:00:47 +00:00
lda PHYSICIST_STATE ; shoot if charging
cmp #P_CROUCH_SHOOTING
beq up_no_fire
2019-08-14 19:38:36 +00:00
inc GUN_FIRE
up_no_fire:
2019-08-14 19:38:36 +00:00
2019-07-11 16:30:34 +00:00
lda ON_ELEVATOR
beq up_not_elevator
up_on_elevator:
lda #P_ELEVATING_UP
jmp change_state_clear_gait
2019-07-11 16:30:34 +00:00
up_not_elevator:
lda PHYSICIST_STATE
cmp #P_CROUCHING
beq stand_up
cmp #P_CROUCH_SHOOTING
beq stand_up_shoot
2019-08-17 19:27:17 +00:00
cmp #P_RUNNING
beq run_jump
up_jump:
2019-03-15 17:00:47 +00:00
lda #P_JUMPING
jmp change_state_clear_gait
2019-08-17 19:27:17 +00:00
run_jump:
lda #P_JUMPING|STATE_RUNNING
jmp change_state_clear_gait
stand_up:
lda #P_STANDING
jmp change_state_clear_gait
stand_up_shoot:
lda #P_SHOOTING
jmp change_state_clear_gait
2019-03-15 17:00:47 +00:00
;==========================
check_down:
cmp #'S'
beq down
cmp #$0A
bne check_gun
2019-03-15 17:00:47 +00:00
;==========================
;==========================
; Down/S Pressed -- Crouch
;==========================
;==========================
down:
2019-07-11 16:30:34 +00:00
lda PHYSICIST_STATE ; shoot if charging
cmp #P_SHOOTING
beq down_no_fire
inc GUN_FIRE
down_no_fire:
2019-07-11 16:30:34 +00:00
lda ON_ELEVATOR
beq down_not_elevator
down_on_elevator:
lda #P_ELEVATING_DOWN
jmp change_state_clear_gait
2019-07-11 16:30:34 +00:00
down_not_elevator:
lda PHYSICIST_STATE
cmp #P_SHOOTING
bne start_crouch
2019-08-17 19:27:17 +00:00
start_crouch_shoot:
and #STATE_RUNNING
ora #P_CROUCH_SHOOTING
jmp change_state_clear_gait
start_crouch:
2019-08-17 19:27:17 +00:00
and #STATE_RUNNING
ora #P_CROUCHING
jmp change_state_clear_gait
;==========================
check_gun:
cmp #'L'
bne check_space
2019-08-14 17:29:11 +00:00
;======================
; 'L' to charge gun
;======================
2019-08-14 19:38:36 +00:00
charge_gun:
lda HAVE_GUN ; only if have gun
beq done_keypress
2019-08-14 19:38:36 +00:00
lda GUN_STATE
beq not_already_firing
inc GUN_FIRE ; if charging, fire
jmp done_keypress
2019-08-14 19:38:36 +00:00
not_already_firing:
inc GUN_STATE
lda PHYSICIST_STATE
and #STATE_CROUCHING
2019-08-16 17:53:37 +00:00
beq crouch_charge
ldy #P_CROUCH_SHOOTING
bne crouch_charge_go ; bra
crouch_charge:
ldy #P_SHOOTING
crouch_charge_go:
sty PHYSICIST_STATE
2019-08-14 19:38:36 +00:00
jmp shoot
check_space:
cmp #' '
beq space
; cmp #$15 ; ascii 21=??
jmp unknown
2019-03-15 17:00:47 +00:00
;======================
; SPACE -- 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
2019-08-14 19:38:36 +00:00
; shoot pressed
inc GUN_FIRE ; if charging, shoot
2019-08-09 04:37:07 +00:00
shoot:
lda PHYSICIST_STATE ; if in stance, then shoot
2019-08-10 01:46:04 +00:00
cmp #P_SHOOTING
beq in_position
cmp #P_CROUCH_SHOOTING
2019-08-10 01:46:04 +00:00
bne no_stance
in_position:
2019-08-10 01:46:04 +00:00
lda #1
sta LASER_OUT
jmp done_keypress
2019-08-10 01:46:04 +00:00
no_stance:
and #STATE_CROUCHING
beq stand_stance
crouch_stance:
lda #P_CROUCH_SHOOTING
jmp change_state_clear_gait
stand_stance:
2019-08-09 04:37:07 +00:00
lda #P_SHOOTING
jmp change_state_clear_gait
2019-08-09 04:37:07 +00:00
kick:
; lda #STATE_CROUCHING
bit PHYSICIST_STATE ; crouching state in V now
; lda PHYSICIST_STATE
; cmp #P_CROUCHING
bvc kick_standing
lda #P_CROUCH_KICKING
jmp kick_final
kick_standing:
lda #P_KICKING
kick_final:
sta PHYSICIST_STATE
lda #15
sta GAIT
unknown:
done_keypress:
bit KEYRESET ; clear the keyboard strobe ; 4
rts ; 6
change_state_clear_gait:
sta PHYSICIST_STATE
lda #0
sta GAIT
jmp done_keypress