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

@ -43,7 +43,6 @@
ID .byte 3 ; $6A, $6F, $79 ("joy")
VERSION .byte 1 ; Interface version
LIBREF .addr ; Library reference
MASKS .byte 8 ; Joystick state mask array
JUMPTAB .struct
INSTALL .addr ; INSTALL routine
UNINSTALL .addr ; UNINSTALL routine

View file

@ -91,6 +91,14 @@
#define CH_RTEE '+'
#define CH_CROSS '+'
/* Masks for joy_read */
#define JOY_UP_MASK 0x10
#define JOY_DOWN_MASK 0x20
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x40
#define JOY_BTN_2_MASK 0x80
/* Return codes for get_ostype */
#define APPLE_UNKNOWN 0x00
#define APPLE_II 0x10 /* Apple ][ */

View file

@ -149,6 +149,13 @@
#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE
#define TGI_COLOR_GRAY3 COLOR_GRAY3
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* color register functions */
extern void __fastcall__ _setcolor (unsigned char color_reg, unsigned char hue, unsigned char luminace);
extern void __fastcall__ _setcolor_low (unsigned char color_reg, unsigned char color_value);
@ -346,4 +353,4 @@ struct __iocb {
#define IOCB_FORMAT 0xFE /* format */
/* End of atari.h */
#endif /* #ifndef _ATARI_H */
#endif

View file

@ -87,6 +87,13 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */
#define COLOR_LIGHTBLUE _gtia_mkcolor(HUE_BLUE,6)
#define COLOR_GRAY3 _gtia_mkcolor(HUE_GREY,5)
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* get_tv return values */
#define AT_NTSC 0
#define AT_PAL 1
@ -104,4 +111,4 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */
#define ANTIC (*(struct __antic*)0xD400)
/* End of atari5200.h */
#endif /* #ifndef _ATARI5200_H */
#endif

View file

@ -113,6 +113,15 @@
/* Masks for joy_read */
#define JOY_UP_MASK 0x10
#define JOY_DOWN_MASK 0x08
#define JOY_LEFT_MASK 0x01
#define JOY_RIGHT_MASK 0x02
#define JOY_BTN_1_MASK 0x20
/* No support for dynamically loadable drivers */
#define DYN_DRV 0

View file

@ -91,6 +91,13 @@
#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE
#define TGI_COLOR_GRAY3 COLOR_GRAY3
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* Video mode defines */
#define VIDEOMODE_40x25 0x00
#define VIDEOMODE_80x25 0x80

View file

@ -99,6 +99,13 @@
#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE
#define TGI_COLOR_GRAY3 COLOR_GRAY3
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* Define hardware */
#include <_vic2.h>
#define VIC (*(struct __vic2*)0xD000)

View file

@ -75,10 +75,8 @@
/* Expanding upon joystick.h */
#define JOY_FIRE_IDX 4
#define JOY_FIRE(v) ((v) & joy_masks[JOY_FIRE_IDX])
#define JOY_FIRE_MASK JOY_BTN_1_MASK
#define JOY_FIRE(v) ((v) & JOY_FIRE_MASK)

View file

@ -112,6 +112,17 @@
#define COLOR_LIGHTBLUE (BCOLOR_LIGHTBLUE | CATTR_LUMA7)
#define COLOR_GRAY3 (BCOLOR_WHITE | CATTR_LUMA5)
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x80
/* Define hardware */
#include <_ted.h>
#define TED (*(struct __ted*)0xFF00)

View file

@ -92,6 +92,13 @@
#define COLOR_LIGHTBLUE 0x0E
#define COLOR_GRAY3 0x0F
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* Define hardware */
#include <_vic2.h>
#define VIC (*(struct __vic2*)0xD800)

View file

@ -40,6 +40,14 @@
#define CH_LLCORNER 37
#define CH_LRCORNER 38
/* Masks for joy_read */
#define JOY_UP_MASK 0x10
#define JOY_DOWN_MASK 0x04
#define JOY_LEFT_MASK 0x20
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x01
#define JOY_BTN_2_MASK 0x02
/* no support for dynamically loadable drivers */
#define DYN_DRV 0

View file

@ -52,6 +52,7 @@ typedef struct {
/* Driver header */
char id[3]; /* Contains 0x65, 0x6d, 0x64 ("emd") */
unsigned char version; /* Interface version */
void* /* Library reference */
/* Jump vectors. Note that these are not C callable */
void* install; /* INSTALL routine */

View file

@ -170,16 +170,25 @@
/* No support for dynamically loadable drivers */
#define DYN_DRV 0
/* Expanding upon joystick.h */
#define JOY_BTN_A_IDX 4
#define JOY_BTN_B_IDX 5
#define JOY_START_IDX 6
#define JOY_SELECT_IDX 7
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
#define JOY_BTN_2_MASK 0x20
#define JOY_BTN_3_MASK 0x40
#define JOY_BTN_4_MASK 0x80
#define JOY_BTN_A(v) ((v) & joy_masks[JOY_BTN_A_IDX])
#define JOY_BTN_B(v) ((v) & joy_masks[JOY_BTN_B_IDX])
#define JOY_START(v) ((v) & joy_masks[JOY_START_IDX])
#define JOY_SELECT(v) ((v) & joy_masks[JOY_SELECT_IDX])
#define JOY_BTN_A_MASK JOY_BTN_1_MASK
#define JOY_BTN_B_MASk JOY_BTN_2_MASK
#define JOY_START_MASK JOY_BTN_3_MASK
#define JOY_SELECT_MASK JOY_BTN_4_MASK
#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK)
#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK)
#define JOY_START(v) ((v) & JOY_START_MASK)
#define JOY_SELECT(v) ((v) & JOY_SELECT_MASK)
/* The addresses of the static drivers */
extern void gamate_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */

View file

@ -133,6 +133,12 @@
#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE
#define TGI_COLOR_GRAY3 COLOR_GRAY3
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* End of geos.h */
#endif

View file

@ -55,28 +55,15 @@
#define JOY_1 0
#define JOY_2 1
/* The following codes are *indices* into the joy_masks array */
#define JOY_UP_IDX 0
#define JOY_DOWN_IDX 1
#define JOY_LEFT_IDX 2
#define JOY_RIGHT_IDX 3
#define JOY_BTN_1_IDX 4 /* Universally available */
#define JOY_BTN_2_IDX 5 /* Second button if available */
#define JOY_BTN_3_IDX 6 /* Third button if available */
#define JOY_BTN_4_IDX 7 /* Fourth button if available */
/* Array of masks used to check the return value of joy_read for a state */
extern const unsigned char joy_masks[8];
/* Macros that evaluate the return code of joy_read */
#define JOY_UP(v) ((v) & joy_masks[JOY_UP_IDX])
#define JOY_DOWN(v) ((v) & joy_masks[JOY_DOWN_IDX])
#define JOY_LEFT(v) ((v) & joy_masks[JOY_LEFT_IDX])
#define JOY_RIGHT(v) ((v) & joy_masks[JOY_RIGHT_IDX])
#define JOY_BTN_1(v) ((v) & joy_masks[JOY_BTN_1_IDX])
#define JOY_BTN_2(v) ((v) & joy_masks[JOY_BTN_2_IDX])
#define JOY_BTN_3(v) ((v) & joy_masks[JOY_BTN_3_IDX])
#define JOY_BTN_4(v) ((v) & joy_masks[JOY_BTN_4_IDX])
#define JOY_UP(v) ((v) & JOY_UP_MASK)
#define JOY_DOWN(v) ((v) & JOY_DOWN_MASK)
#define JOY_LEFT(v) ((v) & JOY_LEFT_MASK)
#define JOY_RIGHT(v) ((v) & JOY_RIGHT_MASK)
#define JOY_BTN_1(v) ((v) & JOY_BTN_1_MASK) /* Universally available */
#define JOY_BTN_2(v) ((v) & JOY_BTN_2_MASK) /* Second button if available */
#define JOY_BTN_3(v) ((v) & JOY_BTN_3_MASK) /* Third button if available */
#define JOY_BTN_4(v) ((v) & JOY_BTN_4_MASK) /* Fourth button if available */
/* The name of the standard joystick driver for a platform */
extern const char joy_stddrv[];

View file

@ -52,9 +52,7 @@ typedef struct {
/* Driver header */
char id[3]; /* Contains 0x6a, 0x6f, 0x79 ("joy") */
unsigned char version; /* Interface version */
/* Bitmasks for the joystick states. See joystick.h for indices */
unsigned char masks[8];
void* /* Library reference */
/* Jump vectors. Note that these are not C callable */
void* install; /* INSTALL routine */
@ -85,6 +83,3 @@ void joy_clear_ptr (void);
/* End of joy-kernel.h */
#endif

View file

@ -87,20 +87,25 @@
#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE
#define TGI_COLOR_WHITE COLOR_WHITE
/* Masks for joy_read */
#define JOY_UP_MASK 0x80
#define JOY_DOWN_MASK 0x40
#define JOY_LEFT_MASK 0x20
#define JOY_RIGHT_MASK 0x10
#define JOY_BTN_1_MASK 0x01
#define JOY_BTN_2_MASK 0x02
#define JOY_BTN_A_MASK JOY_BTN_1_MASK
#define JOY_BTN_B_MASK JOY_BTN_2_MASK
#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK)
#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK)
/* No support for dynamically loadable drivers */
#define DYN_DRV 0
/* Expanding upon joystick.h */
#define JOY_BTN_A_IDX 4
#define JOY_BTN_B_IDX 5
#define JOY_BTN_A(v) ((v) & joy_masks[JOY_BTN_A_IDX])
#define JOY_BTN_B(v) ((v) & joy_masks[JOY_BTN_B_IDX])
/*****************************************************************************/
/* Variables */
/*****************************************************************************/

View file

@ -82,6 +82,26 @@
#define COLOR_LIGHTBLUE 0x0E
#define COLOR_GRAY3 0x0F
/* Masks for joy_read */
#define JOY_UP_MASK 0x10
#define JOY_DOWN_MASK 0x20
#define JOY_LEFT_MASK 0x40
#define JOY_RIGHT_MASK 0x80
#define JOY_BTN_1_MASK 0x01
#define JOY_BTN_2_MASK 0x02
#define JOY_BTN_3_MASK 0x04
#define JOY_BTN_4_MASK 0x08
#define JOY_BTN_A_MASK JOY_BTN_1_MASK
#define JOY_BTN_B_MASK JOY_BTN_2_MASK
#define JOY_SELECT_MASK JOY_BTN_3_MASK
#define JOY_START_MASK JOY_BTN_4_MASK
#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK)
#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK)
#define JOY_SELECT(v) ((v) & JOY_SELECT_MASK)
#define JOY_START(v) ((v) & JOY_START_MASK)
/* Return codes of get_tv */
#define TV_NTSC 0
#define TV_PAL 1
@ -90,17 +110,6 @@
/* No support for dynamically loadable drivers */
#define DYN_DRV 0
/* Expanding upon joystick.h */
#define JOY_BTN_A_IDX 4
#define JOY_BTN_B_IDX 5
#define JOY_SELECT_IDX 6
#define JOY_START_IDX 7
#define JOY_BTN_A(v) ((v) & joy_masks[JOY_BTN_A_IDX])
#define JOY_BTN_B(v) ((v) & joy_masks[JOY_BTN_B_IDX])
#define JOY_SELECT(v) ((v) & joy_masks[JOY_SELECT_IDX])
#define JOY_START(v) ((v) & joy_masks[JOY_START_IDX])
/* Define hardware */
/* Picture Processing Unit */

View file

@ -73,19 +73,28 @@
#define TV_PAL 1
#define TV_OTHER 2
/* Masks for joy_read */
#define JOY_UP_MASK 0x10
#define JOY_DOWN_MASK 0x40
#define JOY_LEFT_MASK 0x80
#define JOY_RIGHT_MASK 0x20
#define JOY_BTN_1_MASK 0x01
#define JOY_BTN_2_MASK 0x02
#define JOY_BTN_3_MASK 0x04
#define JOY_BTN_4_MASK 0x08
#define JOY_BTN_I_MASK JOY_BTN_1_MASK
#define JOY_BTN_II_MASK JOY_BTN_2_MASK
#define JOY_SELECT_MASK JOY_BTN_3_MASK
#define JOY_RUN_MASK JOY_BTN_4_MASK
#define JOY_BTN_I(v) ((v) & JOY_BTN_I_MASK)
#define JOY_BTN_II(v) ((v) & JOY_BTN_II_MASK)
#define JOY_SELECT(v) ((v) & JOY_SELECT_MASK)
#define JOY_RUN(v) ((v) & JOY_RUN_MASK)
/* No support for dynamically loadable drivers */
#define DYN_DRV 0
/* Expanding upon joystick.h */
#define JOY_BTN_I_IDX 4
#define JOY_BTN_II_IDX 5
#define JOY_SELECT_IDX 6
#define JOY_RUN_IDX 7
#define JOY_BTN_I(v) ((v) & joy_masks[JOY_BTN_I_IDX])
#define JOY_BTN_II(v) ((v) & joy_masks[JOY_BTN_II_IDX])
#define JOY_SELECT(v) ((v) & joy_masks[JOY_SELECT_IDX])
#define JOY_RUN(v) ((v) & joy_masks[JOY_RUN_IDX])
#define DYN_DRV 0
/* The addresses of the static drivers */
extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */

View file

@ -55,6 +55,13 @@
#define COLOR_BLACK 0x00
#define COLOR_WHITE 0x01
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* Define hardware */
#include <_pia.h>
#define PIA1 (*(struct __pia*)0xE810)

View file

@ -77,6 +77,15 @@
/* Masks for joy_read */
#define JOY_UP_MASK 0x01
#define JOY_DOWN_MASK 0x02
#define JOY_LEFT_MASK 0x04
#define JOY_RIGHT_MASK 0x08
#define JOY_BTN_1_MASK 0x10
/* Define hardware */
#include <_vic.h>
#define VIC (*(struct __vic*)0x9000)

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

View file

@ -58,21 +58,19 @@ int main (void)
#if defined(__ATARI5200__) || defined(__CREATIVISION__)
cprintf ("%1d:%-3s%-3s%-3s%-3s%-3s%-3s",
i,
(j & joy_masks[JOY_UP])? " U " : " ",
(j & joy_masks[JOY_DOWN])? " D " : " ",
(j & joy_masks[JOY_LEFT])? " L " : " ",
(j & joy_masks[JOY_RIGHT])? " R " : " ",
(j & joy_masks[JOY_FIRE])? " 1 " : " ",
(j & joy_masks[JOY_FIRE2])? " 2 " : " ");
JOY_UP(j)? " U " : " - ",
JOY_DOWN(j)? " D " : " - ",
JOY_LEFT(j)? " L " : " - ",
JOY_RIGHT(j)? " R " : " - ",
JOY_BTN_1(j)? " 1 " : " - ");
#else
cprintf ("%2d: %-6s%-6s%-6s%-6s%-6s%-6s",
i,
(j & joy_masks[JOY_UP])? " up " : " ---- ",
(j & joy_masks[JOY_DOWN])? " down " : " ---- ",
(j & joy_masks[JOY_LEFT])? " left " : " ---- ",
(j & joy_masks[JOY_RIGHT])? "right " : " ---- ",
(j & joy_masks[JOY_FIRE])? " fire " : " ---- ",
(j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ");
JOY_UP(j)? " up " : " ---- ",
JOY_DOWN(j)? " down " : " ---- ",
JOY_LEFT(j)? " left " : " ---- ",
JOY_RIGHT(j)? "right " : " ---- ",
JOY_BTN_1(j)? "button" : " ---- ");
#endif
}
}

View file

@ -1,3 +1,4 @@
#include <pce.h>
#include <conio.h>
#include <time.h>
#include <joystick.h>
@ -97,14 +98,14 @@ void main(void)
j = joy_read (i);
cprintf ("pad %d: %02x %-6s%-6s%-6s%-6s%-6s%-6s%-6s%-6s",
i, j,
(j & joy_masks[JOY_UP])? " up " : " ---- ",
(j & joy_masks[JOY_DOWN])? " down " : " ---- ",
(j & joy_masks[JOY_LEFT])? " left " : " ---- ",
(j & joy_masks[JOY_RIGHT])? "right " : " ---- ",
(j & joy_masks[JOY_FIRE])? " fire " : " ---- ",
(j & joy_masks[JOY_FIRE2])? "fire2 " : " ---- ",
(j & joy_masks[JOY_SELECT])? "select" : " ---- ",
(j & joy_masks[JOY_RUN])? " run " : " ---- ");
JOY_UP(j)? " up " : " ---- ",
JOY_DOWN(j)? " down " : " ---- ",
JOY_LEFT(j)? " left " : " ---- ",
JOY_RIGHT(j)? "right " : " ---- ",
JOY_BTN_I(j)? "btn I " : " ---- ",
JOY_BTN_II(j)? "btn II" : " ---- ",
JOY_SELECT(j)? "select" : " ---- ",
JOY_RUN(j)? " run " : " ---- ");
}
gotoxy(xsize - 10, 3);