2 ; DXS/HIT-4 Player joystick driver for the C64
4 ; Groepaz/Hitmen, 2002-12-23
5 ; obviously based on Ullrichs driver :)
8 .include "zeropage.inc"
10 .include "joy-kernel.inc"
11 .include "joy-error.inc"
18 ; ------------------------------------------------------------------------
19 ; Header. Includes jump table
21 module_header _c64_hitjoy_joy
25 .byte $6A, $6F, $79 ; "joy"
26 .byte JOY_API_VERSION ; Driver API version number
32 ; Button state masks (8 values)
39 .byte $00 ; JOY_FIRE2 unavailable
40 .byte $00 ; Future expansion
41 .byte $00 ; Future expansion
51 ; ------------------------------------------------------------------------
54 JOY_COUNT = 4 ; Number of joysticks we support
56 ; ------------------------------------------------------------------------
57 ; Data. Written in the IRQ, read by the READ routine
66 ; ------------------------------------------------------------------------
67 ; INSTALL routine. Is called after the driver is loaded into memory. If
68 ; possible, check if the hardware is present and determine the amount of
70 ; Must return an JOY_ERR_xx code in a/x.
77 ; rts ; Run into UNINSTALL instead
79 ; ------------------------------------------------------------------------
80 ; UNINSTALL routine. Is called before the driver is removed from memory.
81 ; Can do cleanup or whatever. Must not return anything.
87 ; ------------------------------------------------------------------------
88 ; IRQ entry point. Is called from the C layer as a subroutine in the
89 ; interrupt. The routine MUST return carry set if the interrupt has been
90 ; 'handled' - which means that the interrupt source is gone. Otherwise it
91 ; MUST return carry clear.
95 ldy #$00 ; port b direction
98 sty $dd05 ; cia2 timer a highbyte
99 sty $dc05 ; cia1 timer a highbyte
101 sty $dd04 ; cia2 timer a lowbyte
102 sty $dc04 ; cia1 timer a lowbyte
105 sta $dd0e ; control register a
113 sta $dc0e ; control register a
117 ; serial port: output
120 lda $dd01 ;read cia 2 port b
125 lda $dd02 ;cia 2 port a
126 and #%11111011 ;data direction
127 sta $dd02 ;=> bit 2 input
129 lda $dd00 ;read cia 2 p.A
130 and #%00000100 ;check bit 2
137 lda $dd01 ;read cia 2 port b
145 ldx #$ff ;serial data register
146 stx $dc0c ;=> writing $ff causes
148 ;count signals at cnt1
150 ldx $dd0c ;read cia 2 serial in
151 beq fire ;button press if zero
158 ; Default Value: $40/64 on PAL
162 ; Default Value: $25/37 on PAL
167 ; We do never "handle" the interrupt, we use it just as a timer.
171 ; ------------------------------------------------------------------------
172 ; COUNT: Return the total number of available joysticks in a/x.
175 COUNT: lda #<JOY_COUNT
179 ; ------------------------------------------------------------------------
180 ; READ: Read a particular joystick passed in A.
183 READ: tax ; Joystick number into X