Removed joy_masks array.

So far the joy_masks array allowed several joystick drivers for a single target to each have different joy_read return values. However this meant that every call to joy_read implied an additional joy_masks lookup to post-process the return value.

Given that almost all targets only come with a single joystick driver this seems an inappropriate overhead. Therefore now the target header files contain constants matching the return value of the joy_read of the joystick driver(s) on that target.

If there indeed are several joystick drivers for a single target they must agree on a common return value for joy_read. In some cases this was alredy the case as there's a "natural" return value for joy_read. However a few joystick drivers need to be adjusted. This may cause some overhead inside the driver. But that is for sure smaller than the overhead introduced by the joy_masks lookup before.

!!! ToDo !!!

The following three joystick drivers become broken with this commit and need to be adjusted:
- atrmj8.s
- c64-numpad.s
- vic20-stdjoy.s
This commit is contained in:
Oliver Schmidt
2017-08-19 19:11:28 +02:00
parent f5e9b4012a
commit 7f52a770d9
44 changed files with 222 additions and 354 deletions

View File

@@ -46,17 +46,6 @@ PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y
.addr $0000
; Button state masks (8 values)
.byte $10
.byte $20
.byte $04
.byte $08
.byte $40
.byte $80
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table
.addr INSTALL
@@ -119,7 +108,7 @@ READJOY:
lda BUTN0-1,x ; Check button (1, 3)
asl
tya
ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
ror ; BTN DOWN !UP RIGHT !LEFT 0 0 0
; Read secondary button
tay
@@ -130,10 +119,10 @@ READJOY:
lda BUTN0-1,x ; Check button (2, 0)
asl
tya
ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
ror ; BTN2 BTN DOWN !UP RIGHT !LEFT 0 0
; Finalize
eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
eor #%00010100 ; BTN2 BTN DOWN UP RIGHT LEFT 0 0
ldx #$00
bit $C080 ; Switch in LC bank 2 for R/O
rts

View File

@@ -34,17 +34,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 not available
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -27,17 +27,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $20 ; JOY_FIRE2
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -99,7 +88,7 @@ READJOY:
lda #0 ; Initialize return value
cmp TRIG0,y
bne @notrg
lda #$10 ; JOY_FIRE
lda #$10 ; JOY_BTN
; Read joystick

View File

@@ -28,17 +28,6 @@
.addr $0000
; Button state masks (8 values)
.byte $10 ; JOY_UP
.byte $08 ; JOY_DOWN
.byte $01 ; JOY_LEFT
.byte $02 ; JOY_RIGHT
.byte $20 ; JOY_FIRE
.byte $00 ; Future expansion
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -105,7 +94,7 @@ READ: ldx #$0F ; Switch to the system bank
lda (cia2),y ; Read joystick inputs
sta tmp1
; Get the fire bits
; Get the push button bits
ldy #CIA::PRA
lda (cia2),y
@@ -115,12 +104,12 @@ READ: ldx #$0F ; Switch to the system bank
cpx #$00 ; Joystick 0?
bne @L1 ; Jump if no
; Joystick 1, fire is in bit 6, direction in bit 0-3
; Joystick 1, push button is in bit 6, direction in bit 0-3
asl a
jmp @L2
; Joystick 2, fire is in bit 7, direction in bit 5-7
; Joystick 2, push button is in bit 7, direction in bit 5-7
@L1: ldx #$00 ; High byte of return value
lsr tmp1
@@ -128,9 +117,9 @@ READ: ldx #$0F ; Switch to the system bank
lsr tmp1
lsr tmp1
; Mask the relavant bits, get the fire bit
; Mask the relavant bits, get the push button bit
@L2: asl a ; Fire bit into carry
@L2: asl a ; push button bit into carry
lda tmp1
and #$0F
bcc @L3

View File

@@ -27,26 +27,6 @@
.addr $0000
; Symbolic names for joystick masks (similar names like the defines in joystick.h, but not related to them)
JOY_UP = $10
JOY_DOWN = $04
JOY_LEFT = $20
JOY_RIGHT = $08
JOY_FIRE = $01
JOY_FIRE2 = $02
; 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.
.addr INSTALL
@@ -60,6 +40,13 @@ JOY_FIRE2 = $02
JOY_COUNT = 2 ; Number of joysticks we support
; Symbolic names for joystick masks (similar names like the defines in joystick.h, but not related to them)
JOY_UP = $10
JOY_DOWN = $04
JOY_LEFT = $20
JOY_RIGHT = $08
; ------------------------------------------------------------------------
; Code
@@ -129,7 +116,7 @@ convert:
; values were shifted to the right to be identical).
; Why are there two bits indicating a pressed trigger?
; 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 button gives the value of
; %00010001 and the right hand button gives %00100010
; Why two bits? Can there be cases that just one of those bits is set?
; Until these questions have been answered, we only use the lower two

View File

@@ -24,17 +24,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE_A
.byte $20 ; JOY_FIRE_B
.byte $80 ; JOY_SELECT
.byte $40 ; JOY_START
; Jump table.
.addr INSTALL

View File

@@ -28,17 +28,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; Future expansion
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.word INSTALL

View File

@@ -19,8 +19,6 @@
.bss
_joy_drv: .res 2 ; Pointer to driver
_joy_masks: .res .sizeof(JOY_HDR::MASKS)
; Jump table for the driver functions.
.data
joy_vectors:
@@ -65,38 +63,28 @@ _joy_install:
lda #>joy_libref
sta (ptr1),y
; Copy the mask array
ldy #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1
ldx #.sizeof(JOY_HDR::MASKS)-1
@L1: lda (ptr1),y
sta _joy_masks,x
dey
dex
bpl @L1
; Copy the jump vectors
ldy #JOY_HDR::JUMPTAB
ldx #0
@L2: inx ; Skip the JMP opcode
@L1: inx ; Skip the JMP opcode
jsr copy ; Copy one byte
jsr copy ; Copy one byte
cpy #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB))
bne @L2
bne @L1
jsr joy_install ; Call driver install routine
tay ; Test error code
bne @L3 ; Bail out if install had errors
bne @L2 ; Bail out if install had errors
; Install the IRQ vector if the driver needs it. A/X contains the error code
; from joy_install, so don't use it.
ldy joy_irq+2 ; Check high byte of IRQ vector
beq @L3 ; Jump if vector invalid
beq @L2 ; Jump if vector invalid
ldy #$4C ; JMP opcode
sty joy_irq ; Activate IRQ routine
@L3: rts
@L2: rts
; Driver signature invalid

View File

@@ -31,18 +31,6 @@
.addr $0000
; Button state masks (8 values)
joy_mask:
.byte $80 ; JOY_UP
.byte $40 ; JOY_DOWN
.byte $20 ; JOY_LEFT
.byte $10 ; JOY_RIGHT
.byte $01 ; JOY_FIRE
.byte $02 ; JOY_FIRE1
.byte $00 ;
.byte $00 ;
; Jump table.
.addr INSTALL

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $10 ; JOY_UP
.byte $20 ; JOY_DOWN
.byte $40 ; JOY_LEFT
.byte $80 ; JOY_RIGHT
.byte $01 ; JOY_FIRE (A)
.byte $02 ; JOY_FIRE2 (B)
.byte $04 ; (Select)
.byte $08 ; (Start)
; Jump table.
.addr INSTALL

View File

@@ -24,17 +24,6 @@
.addr $0000
; Button state masks (8 values)
.byte $10 ; JOY_UP
.byte $40 ; JOY_DOWN
.byte $80 ; JOY_LEFT
.byte $20 ; JOY_RIGHT
.byte $01 ; JOY_FIRE_A
.byte $02 ; JOY_FIRE_B
.byte $04 ; JOY_SELECT
.byte $08 ; JOY_RUN
; Jump table.
.addr INSTALL

View File

@@ -28,17 +28,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -27,17 +27,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -31,17 +31,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $80 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -107,7 +96,7 @@ READ: ldy #%11111011 ; Load index for joystick #1
cli
eor #%11111111
; The fire buttons are in bits 6 and 7. Both of them cannot be %1 together.
; The push buttons are in bits 6 and 7. Both of them cannot be %1 together.
; Therefore, bit 6 can be merged with bit 7.
clc

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -152,4 +141,3 @@ joy3: lda #$00 ; via port B read/write
ldx #0
rts