2003-05-02 09:03:47 +00:00
|
|
|
;
|
2008-03-16 09:37:22 +00:00
|
|
|
; Standard joystick driver for the Apple ][. May be used multiple times
|
|
|
|
; when statically linked to the application.
|
2003-05-02 09:03:47 +00:00
|
|
|
;
|
|
|
|
; Ullrich von Bassewitz, 2003-05-02
|
2008-03-16 09:37:22 +00:00
|
|
|
; Oliver Schmidt, 2008-02-25
|
2003-05-02 09:03:47 +00:00
|
|
|
; Using the readjoy code from Stefan Haubenthal
|
|
|
|
;
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "zeropage.inc"
|
2003-05-02 09:03:47 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.include "joy-kernel.inc"
|
2003-05-02 09:03:47 +00:00
|
|
|
.include "joy-error.inc"
|
|
|
|
.include "apple2.inc"
|
|
|
|
|
2014-06-04 21:50:18 +00:00
|
|
|
.macpack module
|
|
|
|
|
2003-05-02 09:03:47 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2003-05-02 09:03:47 +00:00
|
|
|
; Constants
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
THRESHOLD = 20 ; Deviation from center triggering movement
|
2003-05-02 09:03:47 +00:00
|
|
|
|
2004-06-03 15:05:41 +00:00
|
|
|
; ------------------------------------------------------------------------
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2004-06-03 15:05:41 +00:00
|
|
|
; ROM entry points
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y
|
2004-06-03 15:05:41 +00:00
|
|
|
|
2003-05-02 09:03:47 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Header. Includes jump table.
|
|
|
|
|
2014-06-04 21:50:18 +00:00
|
|
|
.ifdef __APPLE2ENH__
|
|
|
|
module_header _a2e_stdjoy_joy
|
|
|
|
.else
|
|
|
|
module_header _a2_stdjoy_joy
|
|
|
|
.endif
|
2003-05-02 09:03:47 +00:00
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.byte $6A, $6F, $79 ; "joy"
|
|
|
|
.byte JOY_API_VERSION ; Driver API version number
|
2003-05-02 09:03:47 +00:00
|
|
|
|
2013-05-31 22:36:08 +00:00
|
|
|
; Library reference
|
|
|
|
|
|
|
|
.addr $0000
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Jump table
|
2003-05-02 09:03:47 +00:00
|
|
|
|
2004-11-06 13:05:26 +00:00
|
|
|
.addr INSTALL
|
|
|
|
.addr UNINSTALL
|
|
|
|
.addr COUNT
|
|
|
|
.addr READJOY
|
2003-05-02 09:03:47 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
.code
|
2003-05-02 09:03:47 +00:00
|
|
|
|
|
|
|
; 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:
|
|
|
|
lda #<JOY_ERR_OK
|
|
|
|
ldx #>JOY_ERR_OK
|
2013-05-09 11:56:54 +00:00
|
|
|
; Fall through
|
2003-05-02 09:03:47 +00:00
|
|
|
|
|
|
|
; UNINSTALL routine. Is called before the driver is removed from memory.
|
|
|
|
; Can do cleanup or whatever. Must not return anything.
|
|
|
|
UNINSTALL:
|
|
|
|
rts
|
|
|
|
|
|
|
|
; COUNT: Return the total number of available joysticks in a/x.
|
|
|
|
COUNT:
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$02 ; Number of joysticks we support
|
2008-03-16 09:37:22 +00:00
|
|
|
ldx #$00
|
2003-05-02 09:03:47 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; READ: Read a particular joystick passed in A.
|
|
|
|
READJOY:
|
2013-05-09 11:56:54 +00:00
|
|
|
bit $C082 ; Switch in ROM
|
|
|
|
and #$01 ; Restrict joystick number
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Read horizontal paddle
|
|
|
|
asl ; Joystick number -> paddle number
|
|
|
|
tax ; Set paddle number (0, 2)
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr PREAD ; Read paddle value
|
2013-05-09 11:56:54 +00:00
|
|
|
lda #$00 ; 0 0 0 0 0 0 0 0
|
2008-03-16 09:37:22 +00:00
|
|
|
cpy #127 - THRESHOLD
|
2013-05-09 11:56:54 +00:00
|
|
|
ror ; !LEFT 0 0 0 0 0 0 0
|
2008-03-16 09:37:22 +00:00
|
|
|
cpy #127 + THRESHOLD
|
2013-05-09 11:56:54 +00:00
|
|
|
ror ; RIGHT !LEFT 0 0 0 0 0 0
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Read vertical paddle
|
2003-05-02 09:03:47 +00:00
|
|
|
pha
|
2013-05-09 11:56:54 +00:00
|
|
|
inx ; Set paddle number (1, 3)
|
2008-03-16 09:37:22 +00:00
|
|
|
jsr PREAD ; Read paddle value
|
2003-05-02 09:03:47 +00:00
|
|
|
pla
|
2008-03-16 09:37:22 +00:00
|
|
|
cpy #127 - THRESHOLD
|
2013-05-09 11:56:54 +00:00
|
|
|
ror ; !UP RIGHT !LEFT 0 0 0 0 0
|
2008-03-16 09:37:22 +00:00
|
|
|
cpy #127 + THRESHOLD
|
2013-05-09 11:56:54 +00:00
|
|
|
ror ; DOWN !UP RIGHT !LEFT 0 0 0 0
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Read primary button
|
|
|
|
tay
|
|
|
|
lda BUTN0-1,x ; Check button (1, 3)
|
2008-03-16 09:37:22 +00:00
|
|
|
asl
|
|
|
|
tya
|
2017-08-19 17:11:28 +00:00
|
|
|
ror ; BTN DOWN !UP RIGHT !LEFT 0 0 0
|
2013-05-09 11:56:54 +00:00
|
|
|
|
|
|
|
; Read secondary button
|
|
|
|
tay
|
|
|
|
inx
|
|
|
|
txa
|
|
|
|
and #$03 ; IIgs has fourth button at TAPEIN
|
|
|
|
tax
|
|
|
|
lda BUTN0-1,x ; Check button (2, 0)
|
2008-03-16 09:37:22 +00:00
|
|
|
asl
|
|
|
|
tya
|
2017-08-19 17:11:28 +00:00
|
|
|
ror ; BTN2 BTN DOWN !UP RIGHT !LEFT 0 0
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
; Finalize
|
2017-08-19 17:11:28 +00:00
|
|
|
eor #%00010100 ; BTN2 BTN DOWN UP RIGHT LEFT 0 0
|
2008-03-16 09:37:22 +00:00
|
|
|
ldx #$00
|
2013-05-09 11:56:54 +00:00
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
2003-05-02 09:03:47 +00:00
|
|
|
rts
|