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