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