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
|
|
|
|
;
|
|
|
|
|
|
|
|
.include "zeropage.inc"
|
|
|
|
|
|
|
|
.include "joy-kernel.inc"
|
|
|
|
.include "joy-error.inc"
|
|
|
|
.include "apple2.inc"
|
|
|
|
|
|
|
|
.macpack generic
|
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
2008-03-16 09:37:22 +00:00
|
|
|
|
2003-05-02 09:03:47 +00:00
|
|
|
; Constants
|
|
|
|
|
2008-03-16 09:37:22 +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
|
|
|
|
|
|
|
|
PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y
|
|
|
|
|
2003-05-02 09:03:47 +00:00
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
; Header. Includes jump table.
|
|
|
|
|
|
|
|
.segment "JUMPTABLE"
|
2003-05-02 09:03:47 +00:00
|
|
|
|
|
|
|
; Driver signature
|
|
|
|
|
2008-03-16 09:37:22 +00:00
|
|
|
.byte $6A, $6F, $79 ; "joy"
|
|
|
|
.byte JOY_API_VERSION ; Driver API version number
|
2003-05-02 09:03:47 +00:00
|
|
|
|
|
|
|
; Button state masks (8 values)
|
|
|
|
|
2003-05-02 11:53:21 +00:00
|
|
|
.byte $10
|
|
|
|
.byte $20
|
2008-03-16 09:37:22 +00:00
|
|
|
.byte $04
|
2003-05-02 11:53:21 +00:00
|
|
|
.byte $08
|
2008-03-16 09:37:22 +00:00
|
|
|
.byte $40
|
|
|
|
.byte $80
|
|
|
|
.byte $00 ; Future expansion
|
|
|
|
.byte $00 ; Future expansion
|
2003-05-02 09:03:47 +00:00
|
|
|
|
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
|
2008-03-16 09:37:22 +00:00
|
|
|
.addr 0 ; IRQ not used
|
2003-05-02 09:03:47 +00:00
|
|
|
|
|
|
|
; ------------------------------------------------------------------------
|
|
|
|
|
2008-03-16 09:37:22 +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
|
2008-03-16 09:37:22 +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:
|
2008-03-16 09:37:22 +00:00
|
|
|
lda #$02 ; Number of joysticks we support
|
|
|
|
ldx #$00
|
2003-05-02 09:03:47 +00:00
|
|
|
rts
|
|
|
|
|
|
|
|
; READ: Read a particular joystick passed in A.
|
|
|
|
READJOY:
|
2008-03-16 09:37:22 +00:00
|
|
|
bit $C082 ; Switch in ROM
|
|
|
|
and #$01 ; Restrict joystick number
|
|
|
|
|
|
|
|
; Read horizontal paddle
|
|
|
|
asl ; Joystick number -> paddle number
|
|
|
|
tax ; Set paddle number (0, 2)
|
|
|
|
jsr PREAD ; Read paddle value
|
|
|
|
lda #$00 ; 0 0 0 0 0 0 0 0
|
|
|
|
cpy #127 - THRESHOLD
|
|
|
|
ror ; !LEFT 0 0 0 0 0 0 0
|
|
|
|
cpy #127 + THRESHOLD
|
|
|
|
ror ; RIGHT !LEFT 0 0 0 0 0 0
|
|
|
|
|
|
|
|
; Read vertical paddle
|
2003-05-02 09:03:47 +00:00
|
|
|
pha
|
2008-03-16 09:37:22 +00:00
|
|
|
inx ; Set paddle number (1, 3)
|
|
|
|
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
|
|
|
|
ror ; !UP RIGHT !LEFT 0 0 0 0 0
|
|
|
|
cpy #127 + THRESHOLD
|
|
|
|
ror ; DOWN !UP RIGHT !LEFT 0 0 0 0
|
|
|
|
|
|
|
|
; Read primary button
|
|
|
|
tay
|
|
|
|
lda BUTN0-1,x ; Check button (1, 3)
|
|
|
|
asl
|
|
|
|
tya
|
|
|
|
ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
|
|
|
|
|
|
|
|
; Read secondary button
|
|
|
|
tay
|
|
|
|
inx
|
|
|
|
txa
|
|
|
|
and #$03 ; IIgs has fourth button at TAPEIN
|
|
|
|
tax
|
|
|
|
lda BUTN0-1,x ; Check button (2, 0)
|
|
|
|
asl
|
|
|
|
tya
|
|
|
|
ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
|
|
|
|
|
|
|
|
; Finalize
|
|
|
|
eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
|
|
|
|
ldx #$00
|
|
|
|
bit $C080 ; Switch in LC bank 2 for R/O
|
2003-05-02 09:03:47 +00:00
|
|
|
rts
|