2 ; Standard joystick driver for the Apple ][. May be used multiple times
3 ; when statically linked to the application.
5 ; Ullrich von Bassewitz, 2003-05-02
6 ; Oliver Schmidt, 2008-02-25
7 ; Using the readjoy code from Stefan Haubenthal
10 .include "zeropage.inc"
12 .include "joy-kernel.inc"
13 .include "joy-error.inc"
18 ; ------------------------------------------------------------------------
22 THRESHOLD = 20 ; Deviation from center triggering movement
24 ; ------------------------------------------------------------------------
28 PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y
30 ; ------------------------------------------------------------------------
32 ; Header. Includes jump table.
38 .byte $6A, $6F, $79 ; "joy"
39 .byte JOY_API_VERSION ; Driver API version number
41 ; Button state masks (8 values)
49 .byte $00 ; Future expansion
50 .byte $00 ; Future expansion
58 .addr 0 ; IRQ not used
60 ; ------------------------------------------------------------------------
64 ; INSTALL routine. Is called after the driver is loaded into memory. If
65 ; possible, check if the hardware is present and determine the amount of
67 ; Must return an JOY_ERR_xx code in a/x.
73 ; UNINSTALL routine. Is called before the driver is removed from memory.
74 ; Can do cleanup or whatever. Must not return anything.
78 ; COUNT: Return the total number of available joysticks in a/x.
80 lda #$02 ; Number of joysticks we support
84 ; READ: Read a particular joystick passed in A.
86 bit $C082 ; Switch in ROM
87 and #$01 ; Restrict joystick number
89 ; Read horizontal paddle
90 asl ; Joystick number -> paddle number
91 tax ; Set paddle number (0, 2)
92 jsr PREAD ; Read paddle value
93 lda #$00 ; 0 0 0 0 0 0 0 0
95 ror ; !LEFT 0 0 0 0 0 0 0
97 ror ; RIGHT !LEFT 0 0 0 0 0 0
99 ; Read vertical paddle
101 inx ; Set paddle number (1, 3)
102 jsr PREAD ; Read paddle value
105 ror ; !UP RIGHT !LEFT 0 0 0 0 0
107 ror ; DOWN !UP RIGHT !LEFT 0 0 0 0
109 ; Read primary button
111 lda BUTN0-1,x ; Check button (1, 3)
114 ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
116 ; Read secondary button
120 and #$03 ; IIgs has fourth button at TAPEIN
122 lda BUTN0-1,x ; Check button (2, 0)
125 ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
128 eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
130 bit $C080 ; Switch in LC bank 2 for R/O