]> git.sur5r.net Git - cc65/blob - libsrc/apple2/joy/a2.stdjoy.s
Removed IRQ support from joystick drivers.
[cc65] / libsrc / apple2 / joy / a2.stdjoy.s
1 ;
2 ; Standard joystick driver for the Apple ][. May be used multiple times
3 ; when statically linked to the application.
4 ;
5 ; Ullrich von Bassewitz, 2003-05-02
6 ; Oliver Schmidt, 2008-02-25
7 ; Using the readjoy code from Stefan Haubenthal
8 ;
9
10         .include        "zeropage.inc"
11
12         .include        "joy-kernel.inc"
13         .include        "joy-error.inc"
14         .include        "apple2.inc"
15
16         .macpack        module
17
18 ; ------------------------------------------------------------------------
19
20 ; Constants
21
22 THRESHOLD =     20      ; Deviation from center triggering movement
23
24 ; ------------------------------------------------------------------------
25
26 ; ROM entry points
27
28 PREAD   :=      $FB1E   ; Read paddle in X, return AD conv. value in Y
29
30 ; ------------------------------------------------------------------------
31
32 ; Header. Includes jump table.
33
34         .ifdef  __APPLE2ENH__
35         module_header   _a2e_stdjoy_joy
36         .else
37         module_header   _a2_stdjoy_joy
38         .endif
39
40 ; Driver signature
41
42         .byte   $6A, $6F, $79   ; "joy"
43         .byte   JOY_API_VERSION ; Driver API version number
44
45 ; Library reference
46
47         .addr   $0000
48
49 ; Jump table
50
51         .addr   INSTALL
52         .addr   UNINSTALL
53         .addr   COUNT
54         .addr   READJOY
55
56 ; ------------------------------------------------------------------------
57
58         .code
59
60 ; INSTALL routine. Is called after the driver is loaded into memory. If
61 ; possible, check if the hardware is present and determine the amount of
62 ; memory available.
63 ; Must return an JOY_ERR_xx code in a/x.
64 INSTALL:
65         lda     #<JOY_ERR_OK
66         ldx     #>JOY_ERR_OK
67         ; Fall through
68
69 ; UNINSTALL routine. Is called before the driver is removed from memory.
70 ; Can do cleanup or whatever. Must not return anything.
71 UNINSTALL:
72         rts
73
74 ; COUNT: Return the total number of available joysticks in a/x.
75 COUNT:
76         lda     #$02            ; Number of joysticks we support
77         ldx     #$00
78         rts
79
80 ; READ: Read a particular joystick passed in A.
81 READJOY:
82         bit     $C082           ; Switch in ROM
83         and     #$01            ; Restrict joystick number
84
85         ; Read horizontal paddle
86         asl                     ; Joystick number -> paddle number
87         tax                     ; Set paddle number (0, 2)
88         jsr     PREAD           ; Read paddle value
89         lda     #$00            ; 0 0 0 0 0 0 0 0
90         cpy     #127 - THRESHOLD
91         ror                     ; !LEFT 0 0 0 0 0 0 0
92         cpy     #127 + THRESHOLD
93         ror                     ; RIGHT !LEFT 0 0 0 0 0 0
94
95         ; Read vertical paddle
96         pha
97         inx                     ; Set paddle number (1, 3)
98         jsr     PREAD           ; Read paddle value
99         pla
100         cpy     #127 - THRESHOLD
101         ror                     ; !UP RIGHT !LEFT 0 0 0 0 0
102         cpy     #127 + THRESHOLD
103         ror                     ; DOWN !UP RIGHT !LEFT 0 0 0 0
104
105         ; Read primary button
106         tay
107         lda     BUTN0-1,x       ; Check button (1, 3)
108         asl
109         tya
110         ror                     ; BTN DOWN !UP RIGHT !LEFT 0 0 0
111
112         ; Read secondary button
113         tay
114         inx
115         txa
116         and     #$03            ; IIgs has fourth button at TAPEIN
117         tax
118         lda     BUTN0-1,x       ; Check button (2, 0)
119         asl
120         tya
121         ror                     ; BTN2 BTN DOWN !UP RIGHT !LEFT 0 0
122
123         ; Finalize
124         eor     #%00010100      ; BTN2 BTN DOWN UP RIGHT LEFT 0 0
125         ldx     #$00
126         bit     $C080           ; Switch in LC bank 2 for R/O
127         rts