]> git.sur5r.net Git - cc65/blob - libsrc/apple2/apple2-stdjoy.s
Documented the new mouse_setbox() and mouse_getbox functions.
[cc65] / libsrc / apple2 / apple2-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        generic
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         .segment        "JUMPTABLE"
35
36 ; Driver signature
37
38         .byte   $6A, $6F, $79   ; "joy"
39         .byte   JOY_API_VERSION ; Driver API version number
40
41 ; Button state masks (8 values)
42
43         .byte   $10
44         .byte   $20
45         .byte   $04
46         .byte   $08
47         .byte   $40
48         .byte   $80
49         .byte   $00             ; Future expansion
50         .byte   $00             ; Future expansion
51
52 ; Jump table
53
54         .addr   INSTALL
55         .addr   UNINSTALL
56         .addr   COUNT
57         .addr   READJOY
58         .addr   0               ; IRQ not used
59
60 ; ------------------------------------------------------------------------
61
62         .code
63
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
66 ; memory available.
67 ; Must return an JOY_ERR_xx code in a/x.
68 INSTALL:
69         lda     #<JOY_ERR_OK
70         ldx     #>JOY_ERR_OK
71         ; Fall through
72
73 ; UNINSTALL routine. Is called before the driver is removed from memory.
74 ; Can do cleanup or whatever. Must not return anything.
75 UNINSTALL:
76         rts
77
78 ; COUNT: Return the total number of available joysticks in a/x.
79 COUNT:
80         lda     #$02            ; Number of joysticks we support
81         ldx     #$00
82         rts
83
84 ; READ: Read a particular joystick passed in A.
85 READJOY:
86         bit     $C082           ; Switch in ROM
87         and     #$01            ; Restrict joystick number
88
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
94         cpy     #127 - THRESHOLD
95         ror                     ; !LEFT 0 0 0 0 0 0 0
96         cpy     #127 + THRESHOLD
97         ror                     ; RIGHT !LEFT 0 0 0 0 0 0
98
99         ; Read vertical paddle
100         pha
101         inx                     ; Set paddle number (1, 3)
102         jsr     PREAD           ; Read paddle value
103         pla
104         cpy     #127 - THRESHOLD
105         ror                     ; !UP RIGHT !LEFT 0 0 0 0 0
106         cpy     #127 + THRESHOLD
107         ror                     ; DOWN !UP RIGHT !LEFT 0 0 0 0
108
109         ; Read primary button
110         tay
111         lda     BUTN0-1,x       ; Check button (1, 3)
112         asl
113         tya
114         ror                     ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
115
116         ; Read secondary button
117         tay
118         inx
119         txa
120         and     #$03            ; IIgs has fourth button at TAPEIN
121         tax
122         lda     BUTN0-1,x       ; Check button (2, 0)
123         asl
124         tya
125         ror                     ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
126
127         ; Finalize
128         eor     #%00010100      ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
129         ldx     #$00
130         bit     $C080           ; Switch in LC bank 2 for R/O
131         rts