2003-09-28 21:41:15 +00:00
|
|
|
;
|
|
|
|
; PTV-4 Player joystick driver for the C128
|
2003-12-16 22:38:12 +00:00
|
|
|
;
|
2003-09-28 21:41:15 +00:00
|
|
|
; Ullrich von Bassewitz, 2003-09-28, using the C64 driver from
|
|
|
|
; Groepaz/Hitmen, 2002-12-23, which is
|
|
|
|
; obviously based on Ullrichs driver :)
|
|
|
|
;
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
|
|
|
.include "joy-kernel.inc"
|
|
|
|
.include "joy-error.inc"
|
|
|
|
.include "c128.inc"
|
|
|
|
|
|
|
|
.macpack generic
|
2014-06-04 21:50:18 +00:00
|
|
|
.macpack module
|
|
|
|
|
2003-09-28 21:41:15 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
2014-06-04 21:50:18 +00:00
|
|
|
module_header _c128_ptvjoy_joy
|
2003-09-28 21:41:15 +00:00
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
2003-12-16 22:38:12 +00:00
|
|
|
.byte $6A, $6F, $79 ; "joy"
|
|
|
|
.byte JOY_API_VERSION ; Driver API version number
|
2003-09-28 21:41:15 +00:00
|
|
|
|
2013-05-31 22:36:08 +00:00
|
|
|
; Library reference
|
|
|
|
|
|
|
|
.addr $0000
|
|
|
|
|
2003-09-28 21:41:15 +00:00
|
|
|
; Jump table.
|
|
|
|
|
2004-11-06 13:12:57 +00:00
|
|
|
.addr INSTALL
|
|
|
|
.addr UNINSTALL
|
|
|
|
.addr COUNT
|
|
|
|
.addr READ
|
2003-09-28 21:41:15 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Constants
|
|
|
|
|
|
|
|
JOY_COUNT = 4 ; Number of joysticks we support
|
|
|
|
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; INSTALL routine. Is called after the driver is loaded into memory. If
|
|
|
|
; possible, check if the hardware is present and determine the amount of
|
|
|
|
; memory available.
|
|
|
|
; Must return an JOY_ERR_xx code in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
INSTALL:
|
2023-02-26 19:03:41 +00:00
|
|
|
lda #JOY_ERR_OK
|
|
|
|
.assert JOY_ERR_OK = 0, error
|
|
|
|
tax
|
2013-05-09 11:56:54 +00:00
|
|
|
; rts ; Run into UNINSTALL instead
|
2003-09-28 21:41:15 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2003-12-16 22:38:12 +00:00
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory.
|
2003-09-28 21:41:15 +00:00
|
|
|
; Can do cleanup or whatever. Must not return anything.
|
|
|
|
;
|
|
|
|
|
2003-12-16 22:38:12 +00:00
|
|
|
UNINSTALL:
|
2003-09-28 21:41:15 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; COUNT: Return the total number of available joysticks in a/x.
|
|
|
|
;
|
|
|
|
|
|
|
|
COUNT:
|
|
|
|
lda #<JOY_COUNT
|
|
|
|
ldx #>JOY_COUNT
|
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; READ: Read a particular joystick passed in A.
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
READ: tax ; Joystick number into X
|
2003-09-28 21:41:15 +00:00
|
|
|
bne joy2
|
|
|
|
|
|
|
|
; Read joystick 1
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
joy1: lda #$7F
|
2003-09-28 21:41:15 +00:00
|
|
|
sei
|
2013-05-09 11:56:54 +00:00
|
|
|
sta CIA1_PRA
|
|
|
|
lda CIA1_PRB
|
2003-09-28 21:41:15 +00:00
|
|
|
cli
|
2013-05-09 11:56:54 +00:00
|
|
|
and #$1F
|
|
|
|
eor #$1F
|
2003-09-28 21:41:15 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Read joystick 2
|
|
|
|
|
|
|
|
joy2: dex
|
|
|
|
bne joy3
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$E0
|
|
|
|
ldy #$FF
|
2003-09-28 21:41:15 +00:00
|
|
|
sei
|
2013-05-09 11:56:54 +00:00
|
|
|
sta CIA1_DDRA
|
|
|
|
lda CIA1_PRA
|
|
|
|
sty CIA1_DDRA
|
2003-09-28 21:41:15 +00:00
|
|
|
cli
|
2013-05-09 11:56:54 +00:00
|
|
|
and #$1F
|
|
|
|
eor #$1F
|
2003-09-28 21:41:15 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Read joystick 3
|
|
|
|
|
2010-02-04 21:02:00 +00:00
|
|
|
joy3:
|
2003-09-28 21:41:15 +00:00
|
|
|
lda #%10000000 ; cia 2 port B Data-Direction
|
|
|
|
sta CIA2_DDRB ; bit 7: out bit 6-0: in
|
|
|
|
|
2010-02-04 21:02:00 +00:00
|
|
|
dex
|
|
|
|
bne joy4
|
|
|
|
|
2003-09-28 21:41:15 +00:00
|
|
|
lda #$80 ; cia 2 port B read/write
|
|
|
|
sta CIA2_PRB ; (output one at PB7)
|
|
|
|
|
|
|
|
lda CIA2_PRB ; cia 2 port B read/write
|
|
|
|
and #$1f ; get bit 4-0 (PB4-PB0)
|
2010-02-04 21:02:00 +00:00
|
|
|
eor #$1f
|
2003-09-28 21:41:15 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; Read joystick 4
|
|
|
|
|
2010-02-04 21:02:00 +00:00
|
|
|
joy4:
|
2003-09-28 21:41:15 +00:00
|
|
|
lda #$00 ; cia 2 port B read/write
|
|
|
|
sta CIA2_PRB ; (output zero at PB7)
|
|
|
|
|
|
|
|
lda CIA2_PRB ; cia 2 port B read/write
|
|
|
|
and #$0f ; get bit 3-0 (PB3-PB0)
|
|
|
|
sta tmp1 ; joy 4 directions
|
|
|
|
|
|
|
|
lda CIA2_PRB ; cia 2 port B read/write
|
|
|
|
and #%00100000 ; get bit 5 (PB5)
|
|
|
|
lsr
|
|
|
|
ora tmp1
|
2010-02-04 21:02:00 +00:00
|
|
|
eor #$1f
|
2003-09-28 21:41:15 +00:00
|
|
|
|
|
|
|
ldx #0
|
|
|
|
rts
|