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