2018-08-27 19:39:08 +00:00
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
; HasJoystick
|
|
|
|
; Checks whether computer has joystick connected
|
|
|
|
;
|
|
|
|
; in: none
|
2018-08-29 19:27:30 +00:00
|
|
|
; out: C set if joystick found
|
|
|
|
; C clear if no joystick found
|
2018-08-27 19:39:08 +00:00
|
|
|
; other flags clobbered
|
|
|
|
; A,X clobbered
|
|
|
|
; Y preserved
|
|
|
|
;
|
|
|
|
; adapted from "Prince of Persia" by Jordan Mechner
|
|
|
|
; (c) 1989 Broderbund Software
|
|
|
|
; https://github.com/jmechner/Prince-of-Persia-Apple-II/blob/master/01%20POP%20Source/Source/GRAFIX.S#L1225
|
|
|
|
;------------------------------------------------------------------------------
|
|
|
|
HasJoystick
|
|
|
|
lda #0
|
2018-08-29 19:27:30 +00:00
|
|
|
sta @joyX
|
|
|
|
sta @joyY
|
2018-08-27 19:39:08 +00:00
|
|
|
lda $C070 ; reset analog input timers
|
|
|
|
@loop ldx #1
|
|
|
|
@1 lda $C064,x ; check timer input
|
|
|
|
bpl @beat
|
2018-08-29 19:27:30 +00:00
|
|
|
inc @joyX,x ; still high, increment counter
|
2018-08-27 19:39:08 +00:00
|
|
|
@nextpdl dex
|
|
|
|
bpl @1
|
|
|
|
lda $C064
|
|
|
|
ora $C065
|
2018-08-29 19:27:30 +00:00
|
|
|
bpl @yes ; both inputs low, we're done
|
|
|
|
lda @joyX
|
|
|
|
ora @joyY
|
2018-08-27 19:39:08 +00:00
|
|
|
bpl @loop ; do it again
|
2018-08-29 19:27:30 +00:00
|
|
|
@no clc
|
2018-08-27 19:39:08 +00:00
|
|
|
+HIDE_NEXT_BYTE
|
2018-08-29 19:27:30 +00:00
|
|
|
@yes sec
|
2018-08-27 19:39:08 +00:00
|
|
|
rts
|
|
|
|
@beat nop
|
|
|
|
bpl @nextpdl ; kill time
|
2018-08-29 19:27:30 +00:00
|
|
|
@joyX !byte 0
|
|
|
|
@joyY !byte 0
|