Skip to content

Commit

Permalink
Removed joy_masks array.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oliverschmidt committed Aug 19, 2017
1 parent f5e9b40 commit 7f52a77
Show file tree
Hide file tree
Showing 44 changed files with 221 additions and 353 deletions.
1 change: 0 additions & 1 deletion asminc/joy-kernel.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions include/apple2.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ][ */
Expand Down
9 changes: 8 additions & 1 deletion include/atari.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -346,4 +353,4 @@ struct __iocb {
#define IOCB_FORMAT 0xFE /* format */

/* End of atari.h */
#endif /* #ifndef _ATARI_H */
#endif
9 changes: 8 additions & 1 deletion include/atari5200.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
9 changes: 9 additions & 0 deletions include/atmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions include/c128.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions include/c64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions include/cbm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down
11 changes: 11 additions & 0 deletions include/cbm264.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions include/cbm510.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions include/creativision.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions include/em/em-kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
29 changes: 19 additions & 10 deletions include/gamate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[] */
Expand Down
6 changes: 6 additions & 0 deletions include/geos.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 8 additions & 21 deletions include/joystick.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
7 changes: 1 addition & 6 deletions include/joystick/joy-kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -85,6 +83,3 @@ void joy_clear_ptr (void);

/* End of joy-kernel.h */
#endif



21 changes: 13 additions & 8 deletions include/lynx.h
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down
31 changes: 20 additions & 11 deletions include/nes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand Down
31 changes: 20 additions & 11 deletions include/pce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[] */
Expand Down

0 comments on commit 7f52a77

Please sign in to comment.