;------------------------------------------------------------------------------ ; HasJoystick ; Checks whether computer has joystick connected ; ; in: none ; out: C set if joystick found ; C clear if no joystick found ; 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 ;------------------------------------------------------------------------------ ; Fastchip firmware 0.4b-compatibility fix by Frank M. (0.5b seems unaffected) ;------------------------------------------------------------------------------ HasJoystick lda $FBB3 cmp #$06 bne ++ lda $FBC0 cmp #$E0 beq + ; test for Fastchip on enhanced //e cmp #$EA beq + ; test for Fastchip on non-enhanced //e jmp ++ + ; FASTChip fc_lock = $C06A fc_enable = $C06B fc_config = $C06E fc_data = $C06F FC_UNLOCK = $6A ; write 4 times FC_LOCK = $A6 FC_SPKR = 2 ; speaker delay register FC_HIFI = 4 ; set to 'HIFI' FC_JOY = 3 ; joystick delay register FC_LONG = 2 ; set to 'LONG' lda #FC_UNLOCK sta fc_lock sta fc_lock sta fc_lock sta fc_lock sta fc_enable lda fc_enable ; 00 if no fastchip cmp #$80 ; 80 if Fastchip normal bne ++ ; A0 if Fastchip disabled lda #FC_JOY ; change Fastchip joystick delay setting to 'LONG' sta fc_config ; (improves joystick detection) lda #FC_LONG sta fc_data lda #FC_SPKR ; change Fastchip speaker delay setting to 'HIFI' sta fc_config ; (improves sound on most games) lda #FC_HIFI sta fc_data lda #FC_LOCK ; (settings revert on power cycle) sta fc_lock ++ lda #0 sta @joyX sta @joyY lda $C070 ; reset analog input timers @loop ldx #1 @1 lda $C064,x ; check timer input bpl @beat inc @joyX,x ; still high, increment counter @nextpdl dex bpl @1 lda $C064 ora $C065 bpl @yes ; both inputs low, we're done lda @joyX ora @joyY bpl @loop ; do it again @no clc +HIDE_NEXT_BYTE @yes sec rts @beat nop bpl @nextpdl ; kill time @joyX !byte 0 @joyY !byte 0