2 ; Standard joystick driver for the Creativision.
4 ; Christian Groessler, 2017-02-06
7 .include "zeropage.inc"
9 .include "joy-kernel.inc"
10 .include "joy-error.inc"
11 .include "creativision.inc"
16 ; ------------------------------------------------------------------------
17 ; Header. Includes jump table
19 module_header _creativisionstd_joy
23 .byte $6A, $6F, $79 ; "joy"
24 .byte JOY_API_VERSION ; Driver API version number
30 ; Button state masks (8 values)
36 .byte $01 ; JOY_FIRE (button #1)
37 .byte $02 ; JOY_FIRE2 (button #2)
38 .byte $00 ; Future expansion
39 .byte $00 ; Future expansion
47 .addr 0 ; IRQ entry not used
49 ; ------------------------------------------------------------------------
52 JOY_COUNT = 2 ; Number of joysticks we support
54 ; ------------------------------------------------------------------------
59 ; ------------------------------------------------------------------------
60 ; INSTALL routine. Is called after the driver is loaded into memory. If
61 ; possible, check if the hardware is present and determine the amount of
63 ; Must return an JOY_ERR_xx code in a/x.
71 ; ------------------------------------------------------------------------
72 ; UNINSTALL routine. Is called before the driver is removed from memory.
73 ; Can do cleanup or whatever. Must not return anything.
80 ; ------------------------------------------------------------------------
81 ; COUNT: Return the total number of available joysticks in a/x.
89 ; ------------------------------------------------------------------------
90 ; READ: Read a particular joystick passed in A.
94 and #1 ; fix joystick number
95 bne READJOY_1 ; read right joystick
101 jmp convert ; convert joystick state to sane cc65 values
103 ; Read right joystick
111 ;jmp convert ; convert joystick state to sane cc65 values
114 ; ------------------------------------------------------------------------
115 ; convert: make runtime lib compatible values
122 sty retval ; initialize return value
126 ; Port values are for the left hand joystick (right hand joystick
127 ; values were shifted to the right to be identical).
128 ; Why are there two bits indicating a pressed trigger?
129 ; According to the "Second book of programs for the Dick Smith Wizard"
130 ; (pg. 88ff), the left hand fire button gives the value of
131 ; %00010001 and the right hand button gives %00100010
132 ; Why two bits? Am I missing something? Can there be cases that just
133 ; one of those bits is set?
134 ; We just test if any of those two bits is not zero...
140 inc retval ; left button pressed
148 sta retval ; right button pressed
153 ; tested with https://sourceforge.net/projects/creativisionemulator
154 ; $49 - %01001001 - up
155 ; $41 - %01000001 - down
156 ; $4D - %01001101 - left
157 ; $45 - %01000101 - right
159 ; are these correct? "Second book of programs for the Dick Smith Wizard" pg. 85 says something different
161 ; $85 - %10000101 - up + right
162 ; $8D - %10001101 - down + left
163 ; $89 - %10001001 - up + left
164 ; $85 - %10000101 - down + right (emulator bug?)
166 bit testbit ; bit #0 set?
167 beq done ; no, no direction
169 and #%00001100 ; mask out other bits
171 lda #%00000100 ; init bitmask
183 ; ------------------------------------------------------------------------
188 ; ------------------------------------------------------------------------