]> git.sur5r.net Git - cc65/blob - libsrc/c64/joy/c64-hitjoy.s
Removed IRQ support from joystick drivers.
[cc65] / libsrc / c64 / joy / c64-hitjoy.s
1 ;
2 ; DXS/HIT-4 Player joystick driver for the C64
3 ;
4 ; Groepaz/Hitmen, 2002-12-23
5 ; obviously based on Ullrichs driver :)
6 ;
7
8         .include "zeropage.inc"
9
10         .include "joy-kernel.inc"
11         .include "joy-error.inc"
12         .include "c64.inc"
13
14         .macpack generic
15         .macpack module
16
17
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
20
21         module_header   _c64_hitjoy_joy
22
23 ; Driver signature
24
25         .byte   $6A, $6F, $79   ; "joy"
26         .byte   JOY_API_VERSION ; Driver API version number
27
28 ; Library reference
29
30         .addr   $0000
31
32 ; Jump table.
33
34         .addr   INSTALL
35         .addr   UNINSTALL
36         .addr   COUNT
37         .addr   READ
38
39 ; ------------------------------------------------------------------------
40 ; Constants
41
42 JOY_COUNT       = 4             ; Number of joysticks we support
43
44 ; ------------------------------------------------------------------------
45 ; Data. Written in the IRQ, read by the READ routine
46
47 .bss
48
49 temp3:  .byte 0
50 temp4:  .byte 0
51
52 .code
53
54 ; ------------------------------------------------------------------------
55 ; INSTALL routine. Is called after the driver is loaded into memory. If
56 ; possible, check if the hardware is present and determine the amount of
57 ; memory available.
58 ; Must return an JOY_ERR_xx code in a/x.
59 ;
60
61 INSTALL:
62         lda     #<JOY_ERR_OK
63         ldx     #>JOY_ERR_OK
64
65 ;       rts             ; Run into UNINSTALL instead
66
67 ; ------------------------------------------------------------------------
68 ; UNINSTALL routine. Is called before the driver is removed from memory.
69 ; Can do cleanup or whatever. Must not return anything.
70 ;
71
72 UNINSTALL:
73         rts
74
75 ; ------------------------------------------------------------------------
76 ; IRQ entry point. Is called from the C layer as a subroutine in the
77 ; interrupt. The routine MUST return carry set if the interrupt has been
78 ; 'handled' - which means that the interrupt source is gone. Otherwise it
79 ; MUST return carry clear.
80
81 IRQ:    ; cia 2 setup
82
83         ldy     #$00            ; port b direction
84         sty     $dd03           ; => input
85
86         sty     $dd05           ; cia2 timer a highbyte
87         sty     $dc05           ; cia1 timer a highbyte
88         iny
89         sty     $dd04           ; cia2 timer a lowbyte
90         sty     $dc04           ; cia1 timer a lowbyte
91
92         lda     #%00010001
93         sta     $dd0e           ; control register a
94                                 ; timer: start
95                                 ;        continous
96                                 ;        forced load
97                                 ; serial port: input
98
99         ; cia 1 setup
100         lda     #%01010001
101         sta     $dc0e           ; control register a
102                                 ; timer: start
103                                 ;        continous
104                                 ;        forced load
105                                 ; serial port: output
106
107         ; read directions 3
108         lda     $dd01           ;read cia 2 port b
109         and     #$0f
110         sta     temp3
111
112         ; read button 3
113         lda     $dd02           ;cia 2 port a
114         and     #%11111011      ;data direction
115         sta     $dd02           ;=> bit 2 input
116
117         lda     $dd00           ;read cia 2 p.A
118         and     #%00000100      ;check bit 2
119         asl     a
120         asl     a
121         ora     temp3
122         sta     temp3
123
124         ; read directions 4
125         lda     $dd01           ;read cia 2 port b
126         lsr     a
127         lsr     a
128         lsr     a
129         lsr     a
130         sta     temp4
131
132         ; read button 4
133         ldx     #$ff            ;serial data register
134         stx     $dc0c           ;=> writing $ff causes
135                                 ;cia to output some
136                                 ;count signals at cnt1
137
138         ldx     $dd0c           ;read cia 2 serial in
139         beq     fire            ;button press if zero
140
141         lda     temp4
142         ora     #%00010000
143         sta     temp4
144
145 fire:
146         ; Default Value: $40/64 on PAL
147         ;                    $42/66 on NTSC
148         lda     #$41
149         sta     $dc05
150         ; Default Value: $25/37 on PAL
151         ;                    $95/149 on NTSC
152         lda     #0
153         sta     $dc04
154
155         ; We do never "handle" the interrupt, we use it just as a timer.
156         clc
157         rts
158
159 ; ------------------------------------------------------------------------
160 ; COUNT: Return the total number of available joysticks in a/x.
161 ;
162
163 COUNT:  lda     #<JOY_COUNT
164         ldx     #>JOY_COUNT
165         rts
166
167 ; ------------------------------------------------------------------------
168 ; READ: Read a particular joystick passed in A.
169 ;
170
171 READ:   tax            ; Joystick number into X
172         bne joy2
173
174 ; Read joystick 1
175
176 joy1:   lda #$7F
177         sei
178         sta CIA1_PRA
179         lda CIA1_PRB
180         cli
181         and #$1F
182         eor #$1F
183         rts
184
185 ; Read joystick 2
186
187 joy2:   dex
188         bne joy3
189
190         ; ldx   #0
191         lda     #$E0
192         ldy     #$FF
193         sei
194         sta     CIA1_DDRA
195         lda     CIA1_PRA
196         sty     CIA1_DDRA
197         cli
198         and     #$1F
199         eor     #$1F
200         rts
201
202         ; Read joystick 3
203
204 joy3:   dex
205         bne     joy4
206
207         lda     temp3
208         eor     #$1F
209         rts
210
211         ; Read joystick 4
212
213 joy4:   lda     temp4
214         eor     #$1F
215         ldx     #0
216         rts
217