From 7f52a770d9c6a43dde67689032bb3a4848eb6b30 Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Sat, 19 Aug 2017 19:11:28 +0200 Subject: [PATCH] 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 --- asminc/joy-kernel.inc | 1 - include/apple2.h | 8 +++++ include/atari.h | 9 +++++- include/atari5200.h | 9 +++++- include/atmos.h | 9 ++++++ include/c128.h | 7 +++++ include/c64.h | 7 +++++ include/cbm.h | 6 ++-- include/cbm264.h | 11 +++++++ include/cbm510.h | 7 +++++ include/creativision.h | 8 +++++ include/em/em-kernel.h | 1 + include/gamate.h | 29 +++++++++++------ include/geos.h | 6 ++++ include/joystick.h | 29 +++++------------ include/joystick/joy-kernel.h | 7 +---- include/lynx.h | 21 ++++++++----- include/nes.h | 31 ++++++++++++------- include/pce.h | 31 ++++++++++++------- include/pet.h | 7 +++++ include/vic20.h | 9 ++++++ libsrc/apple2/joy/a2.stdjoy.s | 17 ++-------- libsrc/atari/joy/atrstd.s | 11 ------- libsrc/atari5200/joy/atr5200std.s | 13 +------- libsrc/atmos/joy/atmos-pase.s | 11 ------- libsrc/c128/joy/c128-ptvjoy.s | 11 ------- libsrc/c128/joy/c128-stdjoy.s | 11 ------- libsrc/c64/joy/c64-hitjoy.s | 11 ------- libsrc/c64/joy/c64-ptvjoy.s | 11 ------- libsrc/c64/joy/c64-stdjoy.s | 11 ------- libsrc/cbm510/joy/cbm510-std.s | 21 +++---------- libsrc/creativision/joy/creativision-stdjoy.s | 29 +++++------------ libsrc/gamate/joy/gamate-stdjoy.s | 11 ------- libsrc/geos-cbm/joy/geos-stdjoy.s | 11 ------- libsrc/joystick/joy-kernel.s | 22 +++---------- libsrc/lynx/joy/lynx-stdjoy.s | 12 ------- libsrc/nes/joy/nes-stdjoy.s | 11 ------- libsrc/pce/joy/pce-stdjoy.s | 11 ------- libsrc/pet/joy/pet-ptvjoy.s | 11 ------- libsrc/pet/joy/pet-stdjoy.s | 11 ------- libsrc/plus4/joy/plus4-stdjoy.s | 13 +------- libsrc/vic20/joy/vic20-ptvjoy.s | 12 ------- testcode/lib/joy-test.c | 22 ++++++------- testcode/lib/pce/conio.c | 17 +++++----- 44 files changed, 221 insertions(+), 353 deletions(-) diff --git a/asminc/joy-kernel.inc b/asminc/joy-kernel.inc index 4fe5572cf..ba969da1d 100644 --- a/asminc/joy-kernel.inc +++ b/asminc/joy-kernel.inc @@ -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 diff --git a/include/apple2.h b/include/apple2.h index e73023693..421b5db6c 100644 --- a/include/apple2.h +++ b/include/apple2.h @@ -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 ][ */ diff --git a/include/atari.h b/include/atari.h index fa99fca20..ca4b2ef26 100644 --- a/include/atari.h +++ b/include/atari.h @@ -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 diff --git a/include/atari5200.h b/include/atari5200.h index 4bd5bc0fd..12c2bb349 100644 --- a/include/atari5200.h +++ b/include/atari5200.h @@ -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 diff --git a/include/atmos.h b/include/atmos.h index 72388c974..c642f9e2a 100644 --- a/include/atmos.h +++ b/include/atmos.h @@ -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 diff --git a/include/c128.h b/include/c128.h index 565fbc9ce..356140d41 100644 --- a/include/c128.h +++ b/include/c128.h @@ -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 diff --git a/include/c64.h b/include/c64.h index adf3840b9..eb10600d6 100644 --- a/include/c64.h +++ b/include/c64.h @@ -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) diff --git a/include/cbm.h b/include/cbm.h index 27e82f9f3..129b0295b 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -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) diff --git a/include/cbm264.h b/include/cbm264.h index ff7468d30..46fa64050 100644 --- a/include/cbm264.h +++ b/include/cbm264.h @@ -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) diff --git a/include/cbm510.h b/include/cbm510.h index 25ea07540..3d6ccd209 100644 --- a/include/cbm510.h +++ b/include/cbm510.h @@ -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) diff --git a/include/creativision.h b/include/creativision.h index 5cc99b7af..a97109029 100644 --- a/include/creativision.h +++ b/include/creativision.h @@ -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 diff --git a/include/em/em-kernel.h b/include/em/em-kernel.h index e5df80321..a1ce9a253 100644 --- a/include/em/em-kernel.h +++ b/include/em/em-kernel.h @@ -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 */ diff --git a/include/gamate.h b/include/gamate.h index 7355ede84..0af21623d 100644 --- a/include/gamate.h +++ b/include/gamate.h @@ -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 - -#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[] */ diff --git a/include/geos.h b/include/geos.h index 65b85cd59..ae356d679 100644 --- a/include/geos.h +++ b/include/geos.h @@ -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 diff --git a/include/joystick.h b/include/joystick.h index 27c4af81a..26f339fe4 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -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[]; diff --git a/include/joystick/joy-kernel.h b/include/joystick/joy-kernel.h index bb571de3d..cec2633ab 100644 --- a/include/joystick/joy-kernel.h +++ b/include/joystick/joy-kernel.h @@ -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 - - - diff --git a/include/lynx.h b/include/lynx.h index c30ca6265..3629f322e 100644 --- a/include/lynx.h +++ b/include/lynx.h @@ -87,17 +87,22 @@ #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 diff --git a/include/nes.h b/include/nes.h index 0b65cdbe4..217a90779 100644 --- a/include/nes.h +++ b/include/nes.h @@ -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 */ diff --git a/include/pce.h b/include/pce.h index 12b596cf9..7744d0148 100644 --- a/include/pce.h +++ b/include/pce.h @@ -73,19 +73,28 @@ #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[] */ diff --git a/include/pet.h b/include/pet.h index 720e40a78..e9659d524 100644 --- a/include/pet.h +++ b/include/pet.h @@ -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) diff --git a/include/vic20.h b/include/vic20.h index c675de6d2..c6ad9632d 100644 --- a/include/vic20.h +++ b/include/vic20.h @@ -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) diff --git a/libsrc/apple2/joy/a2.stdjoy.s b/libsrc/apple2/joy/a2.stdjoy.s index e4097e043..ed2083255 100644 --- a/libsrc/apple2/joy/a2.stdjoy.s +++ b/libsrc/apple2/joy/a2.stdjoy.s @@ -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 diff --git a/libsrc/atari/joy/atrstd.s b/libsrc/atari/joy/atrstd.s index fc7aa55f4..0c8799e21 100644 --- a/libsrc/atari/joy/atrstd.s +++ b/libsrc/atari/joy/atrstd.s @@ -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 diff --git a/libsrc/atari5200/joy/atr5200std.s b/libsrc/atari5200/joy/atr5200std.s index 3483cc11a..0b8b93b63 100644 --- a/libsrc/atari5200/joy/atr5200std.s +++ b/libsrc/atari5200/joy/atr5200std.s @@ -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 diff --git a/libsrc/atmos/joy/atmos-pase.s b/libsrc/atmos/joy/atmos-pase.s index 26d7c74d8..637571c04 100644 --- a/libsrc/atmos/joy/atmos-pase.s +++ b/libsrc/atmos/joy/atmos-pase.s @@ -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 diff --git a/libsrc/c128/joy/c128-ptvjoy.s b/libsrc/c128/joy/c128-ptvjoy.s index 6f65ce5eb..c9ae39a47 100644 --- a/libsrc/c128/joy/c128-ptvjoy.s +++ b/libsrc/c128/joy/c128-ptvjoy.s @@ -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 diff --git a/libsrc/c128/joy/c128-stdjoy.s b/libsrc/c128/joy/c128-stdjoy.s index a2caead1a..943361da5 100644 --- a/libsrc/c128/joy/c128-stdjoy.s +++ b/libsrc/c128/joy/c128-stdjoy.s @@ -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 diff --git a/libsrc/c64/joy/c64-hitjoy.s b/libsrc/c64/joy/c64-hitjoy.s index a798100a7..10c936399 100644 --- a/libsrc/c64/joy/c64-hitjoy.s +++ b/libsrc/c64/joy/c64-hitjoy.s @@ -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 diff --git a/libsrc/c64/joy/c64-ptvjoy.s b/libsrc/c64/joy/c64-ptvjoy.s index 31850488c..e916d887a 100644 --- a/libsrc/c64/joy/c64-ptvjoy.s +++ b/libsrc/c64/joy/c64-ptvjoy.s @@ -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 diff --git a/libsrc/c64/joy/c64-stdjoy.s b/libsrc/c64/joy/c64-stdjoy.s index 2932c77fd..930ad6227 100644 --- a/libsrc/c64/joy/c64-stdjoy.s +++ b/libsrc/c64/joy/c64-stdjoy.s @@ -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 diff --git a/libsrc/cbm510/joy/cbm510-std.s b/libsrc/cbm510/joy/cbm510-std.s index 7133f9379..0c2efc12d 100644 --- a/libsrc/cbm510/joy/cbm510-std.s +++ b/libsrc/cbm510/joy/cbm510-std.s @@ -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 diff --git a/libsrc/creativision/joy/creativision-stdjoy.s b/libsrc/creativision/joy/creativision-stdjoy.s index 3f167464a..9a5afc42b 100644 --- a/libsrc/creativision/joy/creativision-stdjoy.s +++ b/libsrc/creativision/joy/creativision-stdjoy.s @@ -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 diff --git a/libsrc/gamate/joy/gamate-stdjoy.s b/libsrc/gamate/joy/gamate-stdjoy.s index 8b18bae7a..d10eb6f41 100644 --- a/libsrc/gamate/joy/gamate-stdjoy.s +++ b/libsrc/gamate/joy/gamate-stdjoy.s @@ -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 diff --git a/libsrc/geos-cbm/joy/geos-stdjoy.s b/libsrc/geos-cbm/joy/geos-stdjoy.s index 6afe46092..2787cb594 100644 --- a/libsrc/geos-cbm/joy/geos-stdjoy.s +++ b/libsrc/geos-cbm/joy/geos-stdjoy.s @@ -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 diff --git a/libsrc/joystick/joy-kernel.s b/libsrc/joystick/joy-kernel.s index 2b1dcf884..0746709e9 100644 --- a/libsrc/joystick/joy-kernel.s +++ b/libsrc/joystick/joy-kernel.s @@ -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 diff --git a/libsrc/lynx/joy/lynx-stdjoy.s b/libsrc/lynx/joy/lynx-stdjoy.s index 114647072..2e91cc43b 100644 --- a/libsrc/lynx/joy/lynx-stdjoy.s +++ b/libsrc/lynx/joy/lynx-stdjoy.s @@ -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 diff --git a/libsrc/nes/joy/nes-stdjoy.s b/libsrc/nes/joy/nes-stdjoy.s index b5e653c16..3032e9330 100644 --- a/libsrc/nes/joy/nes-stdjoy.s +++ b/libsrc/nes/joy/nes-stdjoy.s @@ -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 diff --git a/libsrc/pce/joy/pce-stdjoy.s b/libsrc/pce/joy/pce-stdjoy.s index 746929dd2..ab25134dd 100644 --- a/libsrc/pce/joy/pce-stdjoy.s +++ b/libsrc/pce/joy/pce-stdjoy.s @@ -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 diff --git a/libsrc/pet/joy/pet-ptvjoy.s b/libsrc/pet/joy/pet-ptvjoy.s index 229055fcb..3bb368355 100644 --- a/libsrc/pet/joy/pet-ptvjoy.s +++ b/libsrc/pet/joy/pet-ptvjoy.s @@ -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 diff --git a/libsrc/pet/joy/pet-stdjoy.s b/libsrc/pet/joy/pet-stdjoy.s index 5847c2b09..29c6de627 100644 --- a/libsrc/pet/joy/pet-stdjoy.s +++ b/libsrc/pet/joy/pet-stdjoy.s @@ -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 diff --git a/libsrc/plus4/joy/plus4-stdjoy.s b/libsrc/plus4/joy/plus4-stdjoy.s index 4a5132887..d998b2699 100644 --- a/libsrc/plus4/joy/plus4-stdjoy.s +++ b/libsrc/plus4/joy/plus4-stdjoy.s @@ -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 diff --git a/libsrc/vic20/joy/vic20-ptvjoy.s b/libsrc/vic20/joy/vic20-ptvjoy.s index cdd4c274f..07c979443 100644 --- a/libsrc/vic20/joy/vic20-ptvjoy.s +++ b/libsrc/vic20/joy/vic20-ptvjoy.s @@ -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 - diff --git a/testcode/lib/joy-test.c b/testcode/lib/joy-test.c index fc751ebdc..fdd83bb4e 100644 --- a/testcode/lib/joy-test.c +++ b/testcode/lib/joy-test.c @@ -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 } } diff --git a/testcode/lib/pce/conio.c b/testcode/lib/pce/conio.c index 00ae3c157..ed3f86240 100644 --- a/testcode/lib/pce/conio.c +++ b/testcode/lib/pce/conio.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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); -- 2.39.5