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
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
#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 ][ */
#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);
#define IOCB_FORMAT 0xFE /* format */
/* End of atari.h */
-#endif /* #ifndef _ATARI_H */
+#endif
#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
#define ANTIC (*(struct __antic*)0xD400)
/* End of atari5200.h */
-#endif /* #ifndef _ATARI5200_H */
+#endif
+/* 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
#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
#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)
-/* 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)
#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)
#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)
#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
/* 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 */
/* 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
-
-#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])
+/* 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_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[] */
#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
#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[];
/* 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 */
/* End of joy-kernel.h */
#endif
-
-
-
#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE
#define TGI_COLOR_WHITE COLOR_WHITE
-/* No support for dynamically loadable drivers */
-#define DYN_DRV 0
-
+/* 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
-/* Expanding upon joystick.h */
-#define JOY_BTN_A_IDX 4
-#define JOY_BTN_B_IDX 5
+#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK)
+#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK)
-#define JOY_BTN_A(v) ((v) & joy_masks[JOY_BTN_A_IDX])
-#define JOY_BTN_B(v) ((v) & joy_masks[JOY_BTN_B_IDX])
+/* No support for dynamically loadable drivers */
+#define DYN_DRV 0
#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
/* 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 */
#define TV_PAL 1
#define TV_OTHER 2
-/* No support for dynamically loadable drivers */
-#define DYN_DRV 0
+/* 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
-/* 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_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)
-#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])
+/* No support for dynamically loadable drivers */
+#define DYN_DRV 0
/* The addresses of the static drivers */
extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */
#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)
+/* 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)
.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
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
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
.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
.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
lda #0 ; Initialize return value
cmp TRIG0,y
bne @notrg
- lda #$10 ; JOY_FIRE
+ lda #$10 ; JOY_BTN
; Read joystick
.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
.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
.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
.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
.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
.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
.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
lda (cia2),y ; Read joystick inputs
sta tmp1
-; Get the fire bits
+; Get the push button bits
ldy #CIA::PRA
lda (cia2),y
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
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
.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
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
; 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
.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
.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
.bss
_joy_drv: .res 2 ; Pointer to driver
-_joy_masks: .res .sizeof(JOY_HDR::MASKS)
-
; Jump table for the driver functions.
.data
joy_vectors:
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
.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
.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
.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
.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
.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
.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
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
.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
ldx #0
rts
-
#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
}
}
+#include <pce.h>
#include <conio.h>
#include <time.h>
#include <joystick.h>
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);