1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-10 23:29:05 +00:00

Merge pull request #397 from groessler/something_to_pull

fix creativision joystick driver
This commit is contained in:
Oliver Schmidt 2017-03-08 13:38:24 +01:00 committed by GitHub
commit 98e51d10d1
2 changed files with 184 additions and 108 deletions

View File

@ -36,6 +36,24 @@ ZP_JOY1_DIR = $13
ZP_JOY0_BUTTONS = $16 ZP_JOY0_BUTTONS = $16
ZP_JOY1_BUTTONS = $17 ZP_JOY1_BUTTONS = $17
;** Joystick direction values (ZP_JOY0_DIR/ZP_JOY1_DIR)
JOY_N = $49
JOY_NNE = $48
JOY_NE = $47
JOY_ENE = $46
JOY_E = $45
JOY_ESE = $44
JOY_SE = $43
JOY_SSE = $42
JOY_S = $41
JOY_SSW = $40
JOY_SW = $4F
JOY_WSW = $4E
JOY_W = $4D
JOY_WNW = $4C
JOY_NW = $4B
JOY_NNW = $4A
;** BIOS ;** BIOS
BIOS_IRQ1_ADDR = $FF3F BIOS_IRQ1_ADDR = $FF3F
BIOS_IRQ2_ADDR = $FF52 BIOS_IRQ2_ADDR = $FF52

View File

@ -1,60 +1,69 @@
; ;
; Standard joystick driver for the Creativision. ; Standard joystick driver for the Creativision.
; ;
; Christian Groessler, 2017-02-06 ; Christian Groessler, 2017-03-08
; ;
.include "zeropage.inc" .include "zeropage.inc"
.include "joy-kernel.inc" .include "joy-kernel.inc"
.include "joy-error.inc" .include "joy-error.inc"
.include "creativision.inc" .include "creativision.inc"
.macpack module .macpack module
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Header. Includes jump table ; Header. Includes jump table
module_header _creativisionstd_joy module_header _creativisionstd_joy
; Driver signature ; Driver signature
.byte $6A, $6F, $79 ; "joy" .byte $6A, $6F, $79 ; "joy"
.byte JOY_API_VERSION ; Driver API version number .byte JOY_API_VERSION ; Driver API version number
; Library reference ; Library reference
.addr $0000 .addr $0000
; Button state masks (8 values) ; Symbolic names for joystick masks (similar names like the defines in joystick.h, but not related to them)
.byte $10 ; JOY_UP JOY_UP = $10
.byte $04 ; JOY_DOWN JOY_DOWN = $04
.byte $20 ; JOY_LEFT JOY_LEFT = $20
.byte $08 ; JOY_RIGHT JOY_RIGHT = $08
.byte $01 ; JOY_FIRE (button #1) JOY_FIRE = $01
.byte $02 ; JOY_FIRE2 (button #2) JOY_FIRE2 = $02
.byte $00 ; Future expansion
.byte $00 ; Future expansion ; Joystick state masks (8 values)
.byte JOY_UP
.byte JOY_DOWN
.byte JOY_LEFT
.byte JOY_RIGHT
.byte JOY_FIRE
.byte JOY_FIRE2
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table. ; Jump table.
.addr INSTALL .addr INSTALL
.addr UNINSTALL .addr UNINSTALL
.addr COUNT .addr COUNT
.addr READJOY .addr READJOY
.addr 0 ; IRQ entry not used .addr 0 ; IRQ entry not used
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Constants ; Constants
JOY_COUNT = 2 ; Number of joysticks we support JOY_COUNT = 2 ; Number of joysticks we support
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; Code ; Code
.code .code
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If ; INSTALL routine. Is called after the driver is loaded into memory. If
@ -63,131 +72,180 @@ JOY_COUNT = 2 ; Number of joysticks we support
; Must return an JOY_ERR_xx code in a/x. ; Must return an JOY_ERR_xx code in a/x.
; ;
INSTALL: INSTALL: lda #JOY_ERR_OK
lda #JOY_ERR_OK ldx #0
ldx #0 ; rts ; Fall through
; rts ; Fall through
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory. ; UNINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything. ; Can do cleanup or whatever. Must not return anything.
; ;
UNINSTALL: UNINSTALL: rts
rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; COUNT: Return the total number of available joysticks in a/x. ; COUNT: Return the total number of available joysticks in a/x.
; ;
COUNT: COUNT: lda #<JOY_COUNT
lda #<JOY_COUNT ldx #>JOY_COUNT
ldx #>JOY_COUNT rts
rts
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in A. ; READ: Read a particular joystick passed in A.
; ;
READJOY: READJOY: and #1 ; fix joystick number
and #1 ; fix joystick number bne READJOY_1 ; read right joystick
bne READJOY_1 ; read right joystick
; Read left joystick ; Read left joystick
ldx ZP_JOY0_DIR ldx ZP_JOY0_DIR
lda ZP_JOY0_BUTTONS lda ZP_JOY0_BUTTONS
jmp convert ; convert joystick state to sane cc65 values jmp convert ; convert joystick state to cc65 values
; Read right joystick ; Read right joystick
READJOY_1: READJOY_1: ldx ZP_JOY1_DIR
lda ZP_JOY1_BUTTONS
ldx ZP_JOY1_DIR lsr a
lda ZP_JOY1_BUTTONS lsr a
lsr a ;jmp convert ; convert joystick state to cc65 values
lsr a ; fall thru...
;jmp convert ; convert joystick state to sane cc65 values
; fall thru...
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; convert: make runtime lib compatible values ; convert: make runtime lib compatible values
; A - buttons ; inputs:
; X - direction ; A - buttons
; X - direction
; ;
convert: convert:
ldy #0
sty retval ; initialize return value
; ------ ; ------
; buttons: ; buttons:
; Port values are for the left hand joystick (right hand joystick ; Port values are for the left hand joystick (right hand joystick
; values were shifted to the right to be identical). ; values were shifted to the right to be identical).
; Why are there two bits indicating a pressed trigger? ; Why are there two bits indicating a pressed trigger?
; According to the "Second book of programs for the Dick Smith Wizard" ; According to the "Second book of programs for the Dick Smith Wizard"
; (pg. 88ff), the left hand fire button gives the value of ; (pg. 88ff), the left hand fire button gives the value of
; %00010001 and the right hand button gives %00100010 ; %00010001 and the right hand button gives %00100010
; Why two bits? Am I missing something? Can there be cases that just ; Why two bits? Can there be cases that just one of those bits is set?
; one of those bits is set? ; Until these questions have been answered, we only use the lower two
; We just test if any of those two bits is not zero... ; bits and ignore the upper ones...
tay and #%00000011 ; button status came in in A, strip high bits
and #%00010001 sta retval ; initialize 'retval' with button status
beq cnv_1
inc retval ; left button pressed
cnv_1: tya
and #%00100010
beq cnv_2
lda #$02
ora retval
sta retval ; right button pressed
; ------ ; ------
; direction: ; direction:
cnv_2: txa ; CV has a 16-direction joystick
; tested with https://sourceforge.net/projects/creativisionemulator ;
; $49 - %01001001 - up ; port values: (compass points)
; $41 - %01000001 - down ; N - $49 - %01001001
; $4D - %01001101 - left ; NNE - $48 - %01001000
; $45 - %01000101 - right ; NE - $47 - %01000111
; ; ENE - $46 - %01000110
; are these correct? "Second book of programs for the Dick Smith Wizard" pg. 85 says something different ; E - $45 - %01000101
; ignored for now... ; ESE - $44 - %01000100
; $85 - %10000101 - up + right ; SE - $43 - %01000011
; $8D - %10001101 - down + left ; SSE - $42 - %01000010
; $89 - %10001001 - up + left ; S - $41 - %01000001
; $85 - %10000101 - down + right (emulator bug?) ; SSW - $40 - %01000000
; SW - $4F - %01001111
; WSW - $4E - %01001110
; W - $4D - %01001101
; WNW - $4C - %01001100
; NW - $4B - %01001011
; NNW - $4A - %01001010
; center - $00 - %00000000
;
; mapping to cc65 definitions (4-direction joystick with 8 possible directions thru combinations)
; N, E, S, W -> JOY_UP, JOY_RIGHT, JOY_DOWN, JOY_LEFT
; NE, SE, SW, NW -> (JOY_UP | JOY_RIGHT), (JOY_DOWN | JOY_RIGHT), (JOY_DOWN | JOY_LEFT), (JOY_UP | JOY_LEFT)
; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW:
; toggle between straight and diagonal direction for every call, e.g.
; NNE:
; call to READJOY: return JOY_UP | JOY_RIGHT
; call to READJOY: return JOY_UP
; call to READJOY: return JOY_UP | JOY_RIGHT
; call to READJOY: return JOY_UP
; call to READJOY: return JOY_UP | JOY_RIGHT
; etc...
bit testbit ; bit #0 set? txa ; move direction status into A
beq done ; no, no direction beq done ; center position (no bits are set), nothing to do
and #%00001100 ; mask out other bits and #$0F ; get rid of the "$40" bit
lsr a bit bit0 ; is it a "three letter" direction (NNE, ENE, etc.)?
lsr a beq special ; yes (bit #0 is zero)
tax
lda #%00000100 ; init bitmask
loop: dex
bmi done2
asl a
bne loop
done2: ora retval lsr a ; create index into table
rts tax
lda dirtable,x
done: ora retval ; include "button" bits
ldx #0
rts
done: lda retval ; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW
rts
special: lsr a
tax
lda toggler ; toggle the toggler
eor #$01
sta toggler
bne spec_1 ; toggler is 1, use spectable_1 entry
lda spectable_0,x ; toggler is 0, use spectable_0 entry
bne done ; jump always
spec_1: lda spectable_1,x
bne done ; jump always
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; ;
.data .rodata
testbit:.byte $01
; a mapping table of "port values" to "cc65 values"
; port value had been shifted one bit to the right (range 0..7)
dirtable: .byte JOY_DOWN ; S
.byte JOY_DOWN | JOY_RIGHT ; SE
.byte JOY_RIGHT ; E
.byte JOY_UP | JOY_RIGHT ; NE
.byte JOY_UP ; N
.byte JOY_UP | JOY_LEFT ; NW
.byte JOY_LEFT ; W
.byte JOY_DOWN | JOY_LEFT ; SW
; two "special" mapping tables for three-letter directions (NNE, etc.)
spectable_0: .byte JOY_DOWN ; SSW
.byte JOY_DOWN ; SSE
.byte JOY_RIGHT ; ESE
.byte JOY_RIGHT ; ENE
.byte JOY_RIGHT ; NNE
.byte JOY_UP ; NNW
.byte JOY_LEFT ; WNW
.byte JOY_LEFT ; WSW
spectable_1: .byte JOY_DOWN | JOY_LEFT ; SSW
.byte JOY_DOWN | JOY_RIGHT ; SSE
.byte JOY_DOWN | JOY_RIGHT ; ESE
.byte JOY_UP | JOY_RIGHT ; ENE
.byte JOY_UP | JOY_RIGHT ; NNE
.byte JOY_UP | JOY_LEFT ; NNW
.byte JOY_UP | JOY_LEFT ; WNW
.byte JOY_DOWN | JOY_LEFT ; WSW
; ------------------------------------------------------------------------ ; ------------------------------------------------------------------------
; ;
.bss bit0: .byte $01
retval: .res 0
; ------------------------------------------------------------------------
;
.bss
toggler: .res 1
retval: .res 1
.end