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.
35 module_header _a2e_stdjoy_joy
37 module_header _a2_stdjoy_joy
42 .byte $6A, $6F, $79 ; "joy"
43 .byte JOY_API_VERSION ; Driver API version number
49 ; Button state masks (8 values)
57 .byte $00 ; Future expansion
58 .byte $00 ; Future expansion
66 .addr 0 ; IRQ not used
68 ; ------------------------------------------------------------------------
72 ; INSTALL routine. Is called after the driver is loaded into memory. If
73 ; possible, check if the hardware is present and determine the amount of
75 ; Must return an JOY_ERR_xx code in a/x.
81 ; UNINSTALL routine. Is called before the driver is removed from memory.
82 ; Can do cleanup or whatever. Must not return anything.
86 ; COUNT: Return the total number of available joysticks in a/x.
88 lda #$02 ; Number of joysticks we support
92 ; READ: Read a particular joystick passed in A.
94 bit $C082 ; Switch in ROM
95 and #$01 ; Restrict joystick number
97 ; Read horizontal paddle
98 asl ; Joystick number -> paddle number
99 tax ; Set paddle number (0, 2)
100 jsr PREAD ; Read paddle value
101 lda #$00 ; 0 0 0 0 0 0 0 0
103 ror ; !LEFT 0 0 0 0 0 0 0
105 ror ; RIGHT !LEFT 0 0 0 0 0 0
107 ; Read vertical paddle
109 inx ; Set paddle number (1, 3)
110 jsr PREAD ; Read paddle value
113 ror ; !UP RIGHT !LEFT 0 0 0 0 0
115 ror ; DOWN !UP RIGHT !LEFT 0 0 0 0
117 ; Read primary button
119 lda BUTN0-1,x ; Check button (1, 3)
122 ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
124 ; Read secondary button
128 and #$03 ; IIgs has fourth button at TAPEIN
130 lda BUTN0-1,x ; Check button (2, 0)
133 ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
136 eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
138 bit $C080 ; Switch in LC bank 2 for R/O