From: Pascal de Bruijn Date: Sat, 22 Jul 2017 13:49:34 +0000 (+0200) Subject: joy: refactor generic joy_masks array indices and macros X-Git-Tag: V2.17~111^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F467%2Fhead;p=cc65 joy: refactor generic joy_masks array indices and macros --- diff --git a/include/cbm.h b/include/cbm.h index 226a09793..27e82f9f3 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -75,6 +75,13 @@ +/* Expanding upon joystick.h */ +#define JOY_FIRE_IDX 4 + +#define JOY_FIRE(v) ((v) & joy_masks[JOY_FIRE_IDX]) + + + /*****************************************************************************/ /* Variables */ /*****************************************************************************/ diff --git a/include/gamate.h b/include/gamate.h index 96c70c9bc..7355ede84 100644 --- a/include/gamate.h +++ b/include/gamate.h @@ -80,17 +80,6 @@ bit 3: */ -#define JOY_DATA 0x4400 - -#define JOY_DATA_UP 0x01 -#define JOY_DATA_DOWN 0x02 -#define JOY_DATA_LEFT 0x04 -#define JOY_DATA_RIGHT 0x08 -#define JOY_DATA_FIRE_A 0x10 -#define JOY_DATA_FIRE_B 0x20 -#define JOY_DATA_START 0x40 -#define JOY_DATA_SELECT 0x80 - /* LCD resolution 160x152 in 4 greys/greens @@ -181,13 +170,20 @@ /* 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]) + /* The addresses of the static drivers */ extern void gamate_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ -#define JOY_FIRE_B 5 -#define JOY_START 6 -#define JOY_SELECT 7 - void waitvsync (void); /* Wait for start of next frame */ diff --git a/include/joystick.h b/include/joystick.h index 710d9b5a6..f08dd432a 100644 --- a/include/joystick.h +++ b/include/joystick.h @@ -52,27 +52,31 @@ #define JOY_ERR_NO_DEVICE 4 /* Device (hardware) not found */ /* Argument for the joy_read function */ -#define JOY_1 0 -#define JOY_2 1 +#define JOY_1 0 +#define JOY_2 1 /* The following codes are *indices* into the joy_masks array */ -#define JOY_UP 0 -#define JOY_DOWN 1 -#define JOY_LEFT 2 -#define JOY_RIGHT 3 -#define JOY_FIRE 4 -#define JOY_FIRE2 5 /* Second fire button if available */ +#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 fire button if available */ +#define JOY_BTN_3_IDX 6 /* Third fire button if available */ +#define JOY_BTN_4_IDX 7 /* Fourth fire 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_BTN_UP(v) ((v) & joy_masks[JOY_UP]) -#define JOY_BTN_DOWN(v) ((v) & joy_masks[JOY_DOWN]) -#define JOY_BTN_LEFT(v) ((v) & joy_masks[JOY_LEFT]) -#define JOY_BTN_RIGHT(v) ((v) & joy_masks[JOY_RIGHT]) -#define JOY_BTN_FIRE(v) ((v) & joy_masks[JOY_FIRE]) -#define JOY_BTN_FIRE2(v) ((v) & joy_masks[JOY_FIRE2]) +#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]) /* The name of the standard joystick driver for a platform */ extern const char joy_stddrv[]; diff --git a/include/lynx.h b/include/lynx.h index 72f3d5bfd..c30ca6265 100644 --- a/include/lynx.h +++ b/include/lynx.h @@ -92,6 +92,15 @@ +/* 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 */ /*****************************************************************************/ diff --git a/include/nes.h b/include/nes.h index 3e139e00c..0b65cdbe4 100644 --- a/include/nes.h +++ b/include/nes.h @@ -91,15 +91,15 @@ #define DYN_DRV 0 /* Expanding upon joystick.h */ -#define JOY_A 4 -#define JOY_B 5 -#define JOY_SELECT 6 -#define JOY_START 7 - -#define JOY_BTN_A(v) ((v) & joy_masks[JOY_A]) -#define JOY_BTN_B(v) ((v) & joy_masks[JOY_B]) -#define JOY_BTN_SELECT(v) ((v) & joy_masks[JOY_SELECT]) -#define JOY_BTN_START(v) ((v) & joy_masks[JOY_START]) +#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 */ diff --git a/include/pce.h b/include/pce.h index ac6b2503f..12b596cf9 100644 --- a/include/pce.h +++ b/include/pce.h @@ -77,23 +77,19 @@ #define DYN_DRV 0 /* Expanding upon joystick.h */ -#define JOY_I 4 -#define JOY_II 5 -#define JOY_SELECT 6 -#define JOY_RUN 7 +#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_I]) -#define JOY_BTN_II(v) ((v) & joy_masks[JOY_II]) -#define JOY_BTN_SELECT(v) ((v) & joy_masks[JOY_SELECT]) -#define JOY_BTN_RUN(v) ((v) & joy_masks[JOY_RUN]) +#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]) /* The addresses of the static drivers */ extern void pce_stdjoy_joy[]; /* Referred to by joy_static_stddrv[] */ -#define JOY_FIRE_B 5 -#define JOY_SELECT 6 -#define JOY_RUN 7 - void waitvsync (void); /* Wait for start of the next frame */