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
39 ; Button state masks (8 values)
47 .byte $00 ; Future expansion
48 .byte $00 ; Future expansion
56 .addr 0 ; IRQ not used
58 ; ------------------------------------------------------------------------
62 ; INSTALL routine. Is called after the driver is loaded into memory. If
63 ; possible, check if the hardware is present and determine the amount of
65 ; Must return an JOY_ERR_xx code in a/x.
71 ; UNINSTALL routine. Is called before the driver is removed from memory.
72 ; Can do cleanup or whatever. Must not return anything.
76 ; COUNT: Return the total number of available joysticks in a/x.
78 lda #$02 ; Number of joysticks we support
82 ; READ: Read a particular joystick passed in A.
84 bit $C082 ; Switch in ROM
85 and #$01 ; Restrict joystick number
87 ; Read horizontal paddle
88 asl ; Joystick number -> paddle number
89 tax ; Set paddle number (0, 2)
90 jsr PREAD ; Read paddle value
91 lda #$00 ; 0 0 0 0 0 0 0 0
93 ror ; !LEFT 0 0 0 0 0 0 0
95 ror ; RIGHT !LEFT 0 0 0 0 0 0
97 ; Read vertical paddle
99 inx ; Set paddle number (1, 3)
100 jsr PREAD ; Read paddle value
103 ror ; !UP RIGHT !LEFT 0 0 0 0 0
105 ror ; DOWN !UP RIGHT !LEFT 0 0 0 0
107 ; Read primary button
109 lda BUTN0-1,x ; Check button (1, 3)
112 ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
114 ; Read secondary button
118 and #$03 ; IIgs has fourth button at TAPEIN
120 lda BUTN0-1,x ; Check button (2, 0)
123 ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
126 eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
128 bit $C080 ; Switch in LC bank 2 for R/O