2019-09-27 07:38:51 +00:00
|
|
|
;
|
|
|
|
; Standard joystick driver for the CX16.
|
2019-12-25 15:56:32 +00:00
|
|
|
; May be installed multiple times when statically linked to an application.
|
2019-09-27 07:38:51 +00:00
|
|
|
;
|
2022-04-02 13:39:35 +00:00
|
|
|
; 2021-04-07, Greg King
|
2019-09-27 07:38:51 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
.include "joy-kernel.inc"
|
|
|
|
.include "joy-error.inc"
|
|
|
|
|
|
|
|
.include "cbm_kernal.inc"
|
|
|
|
.include "cx16.inc"
|
|
|
|
|
|
|
|
.macpack generic
|
|
|
|
.macpack module
|
|
|
|
|
2019-12-25 15:56:32 +00:00
|
|
|
.importzp tmp1
|
|
|
|
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Header. Includes jump table
|
|
|
|
|
2019-11-16 18:11:40 +00:00
|
|
|
module_header _cx16_std_joy
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
|
|
|
.byte $6A, $6F, $79 ; ASCII "joy"
|
|
|
|
.byte JOY_API_VERSION ; Driver API version number
|
|
|
|
|
|
|
|
; Library reference
|
|
|
|
|
|
|
|
.addr $0000
|
|
|
|
|
|
|
|
; Jump table.
|
|
|
|
|
|
|
|
.addr INSTALL
|
|
|
|
.addr UNINSTALL
|
|
|
|
.addr COUNT
|
|
|
|
.addr READ
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Constant
|
|
|
|
|
2022-04-02 13:39:35 +00:00
|
|
|
JOY_COUNT = $05 ; Number of joysticks we support
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
; Data.
|
|
|
|
|
|
|
|
|
|
|
|
.code
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2019-11-16 18:11:40 +00:00
|
|
|
; INSTALL routine -- is called after the driver is loaded into memory.
|
2022-04-02 13:39:35 +00:00
|
|
|
; If possible, check if the hardware is present.
|
2019-11-16 18:11:40 +00:00
|
|
|
; Must return a JOY_ERR_xx code in .XA .
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
INSTALL:
|
2023-02-26 19:03:41 +00:00
|
|
|
lda #JOY_ERR_OK
|
|
|
|
.assert JOY_ERR_OK = 0, error
|
|
|
|
tax
|
2019-09-27 07:38:51 +00:00
|
|
|
; rts ; Run into UNINSTALL instead
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2019-11-16 18:11:40 +00:00
|
|
|
; UNINSTALL routine -- is called before the driver is removed from memory.
|
|
|
|
; Can do clean-up or whatever. Shouldn't return anything.
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
UNINSTALL:
|
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2019-11-16 18:11:40 +00:00
|
|
|
; COUNT: Return the total number of possible joysticks, in .XA .
|
2019-09-27 07:38:51 +00:00
|
|
|
|
|
|
|
COUNT: lda #<JOY_COUNT
|
|
|
|
ldx #>JOY_COUNT
|
|
|
|
rts
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2019-11-16 18:11:40 +00:00
|
|
|
; READ: Read a particular joystick passed in .A .
|
2019-09-27 07:38:51 +00:00
|
|
|
|
2022-04-02 13:39:35 +00:00
|
|
|
READ: cmp #JOY_COUNT
|
|
|
|
blt :+
|
|
|
|
lda #$00
|
|
|
|
: jsr JOYSTICK_GET
|
2019-12-25 15:56:32 +00:00
|
|
|
sta tmp1
|
|
|
|
txa
|
|
|
|
bit #%00001110 ; Is it NES or SNES controller?
|
|
|
|
bze nes
|
2019-11-16 18:11:40 +00:00
|
|
|
|
2019-12-25 15:56:32 +00:00
|
|
|
asl tmp1 ; Get SNES's B button
|
2019-09-27 07:38:51 +00:00
|
|
|
ror a ; Put it next to the A button
|
2019-12-25 15:56:32 +00:00
|
|
|
asl tmp1 ; Drop SNES's Y button
|
2019-11-16 18:11:40 +00:00
|
|
|
asl a ; Get back the B button
|
2019-12-25 15:56:32 +00:00
|
|
|
ror tmp1
|
2019-09-27 07:38:51 +00:00
|
|
|
asl a ; Get SNES's A button
|
2019-12-25 15:56:32 +00:00
|
|
|
ror tmp1 ; Make byte look like NES pad
|
2019-11-16 18:11:40 +00:00
|
|
|
|
2019-12-25 15:56:32 +00:00
|
|
|
nes: lda tmp1 ; The controllers give zeroes for "pressed"
|
|
|
|
eor #%11111111 ; We want ones for "pressed"
|
2019-09-27 07:38:51 +00:00
|
|
|
rts
|