]> git.sur5r.net Git - cc65/blob - libsrc/c64/joy/c64-hitjoy.s
Removed (pretty inconsistently used) tab chars from source code base.
[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
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. The routine MUST return carry set if the interrupt has been
84 ; 'handled' - which means that the interrupt source is gone. Otherwise it
85 ; MUST return carry clear.
86
87 IRQ:    ; cia 2 setup
88
89         ldy     #$00            ; port b direction
90         sty     $dd03           ; => input
91
92         sty     $dd05           ; cia2 timer a highbyte
93         sty     $dc05           ; cia1 timer a highbyte
94         iny
95         sty     $dd04           ; cia2 timer a lowbyte
96         sty     $dc04           ; cia1 timer a lowbyte
97
98         lda     #%00010001
99         sta     $dd0e           ; control register a
100                                 ; timer: start
101                                 ;        continous
102                                 ;        forced load
103                                 ; serial port: input
104
105         ; cia 1 setup
106         lda     #%01010001
107         sta     $dc0e           ; control register a
108                                 ; timer: start
109                                 ;        continous
110                                 ;        forced load
111                                 ; serial port: output
112
113         ; read directions 3
114         lda     $dd01           ;read cia 2 port b
115         and     #$0f
116         sta     temp3
117
118         ; read button 3
119         lda     $dd02           ;cia 2 port a
120         and     #%11111011      ;data direction
121         sta     $dd02           ;=> bit 2 input
122
123         lda     $dd00           ;read cia 2 p.A
124         and     #%00000100      ;check bit 2
125         asl     a
126         asl     a
127         ora     temp3
128         sta     temp3
129
130         ; read directions 4
131         lda     $dd01           ;read cia 2 port b
132         lsr     a
133         lsr     a
134         lsr     a
135         lsr     a
136         sta     temp4
137
138         ; read button 4
139         ldx     #$ff            ;serial data register
140         stx     $dc0c           ;=> writing $ff causes
141                                 ;cia to output some
142                                 ;count signals at cnt1
143
144         ldx     $dd0c           ;read cia 2 serial in
145         beq     fire            ;button press if zero
146
147         lda     temp4
148         ora     #%00010000
149         sta     temp4
150
151 fire:
152         ; Default Value: $40/64 on PAL
153         ;                    $42/66 on NTSC
154         lda     #$41
155         sta     $dc05
156         ; Default Value: $25/37 on PAL
157         ;                    $95/149 on NTSC
158         lda     #0
159         sta     $dc04
160
161         ; We do never "handle" the interrupt, we use it just as a timer.
162         clc
163         rts
164
165 ; ------------------------------------------------------------------------
166 ; COUNT: Return the total number of available joysticks in a/x.
167 ;
168
169 COUNT:  lda     #<JOY_COUNT
170         ldx     #>JOY_COUNT
171         rts
172
173 ; ------------------------------------------------------------------------
174 ; READ: Read a particular joystick passed in A.
175 ;
176
177 READ:   tax            ; Joystick number into X
178         bne joy2
179
180 ; Read joystick 1
181
182 joy1:   lda #$7F
183         sei
184         sta CIA1_PRA
185         lda CIA1_PRB
186         cli
187         and #$1F
188         eor #$1F
189         rts
190
191 ; Read joystick 2
192
193 joy2:   dex
194         bne joy3
195
196         ; ldx   #0
197         lda     #$E0
198         ldy     #$FF
199         sei
200         sta     CIA1_DDRA
201         lda     CIA1_PRA
202         sty     CIA1_DDRA
203         cli
204         and     #$1F
205         eor     #$1F
206         rts
207
208         ; Read joystick 3
209
210 joy3:   dex
211         bne     joy4
212
213         lda     temp3
214         eor     #$1F
215         rts
216
217         ; Read joystick 4
218
219 joy4:   lda     temp4
220         eor     #$1F
221         ldx     #0
222         rts
223