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"
16 ; ------------------------------------------------------------------------
20 THRESHOLD = 20 ; Deviation from center triggering movement
22 ; ------------------------------------------------------------------------
26 PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y
28 ; ------------------------------------------------------------------------
30 ; Header. Includes jump table.
36 .byte $6A, $6F, $79 ; "joy"
37 .byte JOY_API_VERSION ; Driver API version number
43 ; Button state masks (8 values)
51 .byte $00 ; Future expansion
52 .byte $00 ; Future expansion
60 .addr 0 ; IRQ not used
62 ; ------------------------------------------------------------------------
66 ; INSTALL routine. Is called after the driver is loaded into memory. If
67 ; possible, check if the hardware is present and determine the amount of
69 ; Must return an JOY_ERR_xx code in a/x.
75 ; UNINSTALL routine. Is called before the driver is removed from memory.
76 ; Can do cleanup or whatever. Must not return anything.
80 ; COUNT: Return the total number of available joysticks in a/x.
82 lda #$02 ; Number of joysticks we support
86 ; READ: Read a particular joystick passed in A.
88 bit $C082 ; Switch in ROM
89 and #$01 ; Restrict joystick number
91 ; Read horizontal paddle
92 asl ; Joystick number -> paddle number
93 tax ; Set paddle number (0, 2)
94 jsr PREAD ; Read paddle value
95 lda #$00 ; 0 0 0 0 0 0 0 0
97 ror ; !LEFT 0 0 0 0 0 0 0
99 ror ; RIGHT !LEFT 0 0 0 0 0 0
101 ; Read vertical paddle
103 inx ; Set paddle number (1, 3)
104 jsr PREAD ; Read paddle value
107 ror ; !UP RIGHT !LEFT 0 0 0 0 0
109 ror ; DOWN !UP RIGHT !LEFT 0 0 0 0
111 ; Read primary button
113 lda BUTN0-1,x ; Check button (1, 3)
116 ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
118 ; Read secondary button
122 and #$03 ; IIgs has fourth button at TAPEIN
124 lda BUTN0-1,x ; Check button (2, 0)
127 ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
130 eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
132 bit $C080 ; Switch in LC bank 2 for R/O