diff --git a/src/core/input.c b/src/core/input.c index ef2a6b3f2..7354926f1 100644 --- a/src/core/input.c +++ b/src/core/input.c @@ -113,8 +113,8 @@ void input_init(BYTE set_cursor) { SET_DECODE_EVENT(a, NULL); SET_ADD_EVENT(a, NULL); - port[a].permit.up_or_down = 0x00; - port[a].permit.left_or_right = 0x00; + memset(&permit.left_or_right[a], 0x00, sizeof(_permit_axes_standard_controller)); + memset(&permit.up_or_down[a], 0x00, sizeof(_permit_axes_standard_controller)); // NSF if (nsf.enabled) { @@ -318,3 +318,5 @@ INLINE static void input_init_generic_keyboard(void) { nes_keyboard.enabled = FALSE; memset(&generic_keyboard, 0x00, sizeof(generic_keyboard)); } + + diff --git a/src/core/input.h b/src/core/input.h index 132ac79e4..a263a298b 100644 --- a/src/core/input.h +++ b/src/core/input.h @@ -106,10 +106,7 @@ typedef struct _port { BYTE raw[INPUT_DECODE_COUNTS]; BYTE treated[8]; } data; - struct permit_updown_leftright { - BYTE up_or_down; - BYTE left_or_right; - } permit; + // turbo buttons _turbo_button turbo[2]; } _port; diff --git a/src/core/input/four_score.c b/src/core/input/four_score.c index 1c9c57fed..1503ae470 100644 --- a/src/core/input/four_score.c +++ b/src/core/input/four_score.c @@ -20,6 +20,7 @@ #include "vs_system.h" #include "nes.h" #include "info.h" +#include "input/standard_controller.h" struct _four_score { BYTE signature; @@ -46,9 +47,11 @@ BYTE input_rd_reg_four_score(BYTE nidx, BYTE openbus, BYTE nport) { BYTE value = 0; if (nes[nidx].c.input.fsindex[nport] < 8) { + input_updown_leftright_standard_controller(index, nport); value = !!port[nport].data.treated[index]; nes[nidx].c.input.fsindex[nport]++; } else if (nes[nidx].c.input.fsindex[nport] < 16) { + input_updown_leftright_standard_controller(index, nport + 2); value = !!port[nport + 2].data.treated[index]; nes[nidx].c.input.fsindex[nport]++; } else if (nes[nidx].c.input.fsindex[nport] < 24) { @@ -75,9 +78,11 @@ BYTE input_rd_reg_four_score_vs(BYTE nidx, BYTE openbus, BYTE nport) { np ^= 0x01; } if (nes[nidx].c.input.fsindex[nport] < 8) { + input_updown_leftright_standard_controller(index, np); value = protection ? PRESSED : !!port[np].data.treated[index]; nes[nidx].c.input.fsindex[nport]++; } else if (nes[nidx].c.input.fsindex[nport] < 16) { + input_updown_leftright_standard_controller(index, np + 2); value = protection ? PRESSED : !!port[np + 2].data.treated[index]; nes[nidx].c.input.fsindex[nport]++; } else if (nes[nidx].c.input.fsindex[nport] < 24) { diff --git a/src/core/input/standard_controller.c b/src/core/input/standard_controller.c index 054bc1e53..e7cdc9bbc 100644 --- a/src/core/input/standard_controller.c +++ b/src/core/input/standard_controller.c @@ -27,12 +27,15 @@ INLINE static void input_turbo_buttons_standard_controller(_port *prt); +_permit_updown_leftright_standard_controller permit; + void input_wr_standard_controller(BYTE nidx, const BYTE *value, BYTE nport) { if ((nes[nidx].c.input.r4016 & 0x01) || ((*value) & 0x01)) { nes[nidx].c.input.pindex[nport] = 0; } } void input_rd_standard_controller(BYTE nidx, BYTE *value, BYTE nport, BYTE shift) { + input_updown_leftright_standard_controller(nes[nidx].c.input.pindex[nport], nport); (*value) = !!port[nport].data.treated[nes[nidx].c.input.pindex[nport]] << shift; // Se $4016 e' a 1 leggo solo lo stato del primo pulsante // del controller. Quando verra' scritto 0 nel $4016 @@ -71,19 +74,15 @@ BYTE input_decode_event_standard_controller(BYTE mode, BYTE autorepeat, DBWORD e return (EXIT_OK); } else if (event == prt->input[type][UP]) { input_data_set_standard_controller(axes.up, mode, prt); - input_updown_leftright_standard_controller(UP, axes.up, axes.down, prt); return (EXIT_OK); } else if (event == prt->input[type][DOWN]) { input_data_set_standard_controller(axes.down, mode, prt); - input_updown_leftright_standard_controller(DOWN, axes.down, axes.up, prt); return (EXIT_OK); } else if (event == prt->input[type][LEFT]) { input_data_set_standard_controller(axes.left, mode, prt); - input_updown_leftright_standard_controller(LEFT, axes.left, axes.right, prt); return (EXIT_OK); } else if (event == prt->input[type][RIGHT]) { input_data_set_standard_controller(axes.right, mode, prt); - input_updown_leftright_standard_controller(RIGHT, axes.right, axes.left, prt); return (EXIT_OK); } else if (event == prt->input[type][TRB_A]) { prt->turbo[TURBOA].mode = mode; @@ -114,6 +113,7 @@ void input_rd_standard_controller_vs(BYTE nidx, BYTE *value, BYTE nport, BYTE sh } else if (info.mapper.expansion == EXP_VS_1P_R4017) { np ^= 0x01; } + input_updown_leftright_standard_controller(index, nport); (*value) = (protection ? PRESSED : !!port[nport].data.treated[index]) << shift; // Se $4016 e' a 1 leggo solo lo stato del primo pulsante // del controller. Quando verra' scritto 0 nel $4016 @@ -166,29 +166,64 @@ void input_rotate_standard_controller(_input_lfud_standard_controller *lfud) { } } } -void input_updown_leftright_standard_controller(BYTE index, BYTE src, BYTE opposite, _port *prt) { - BYTE *axis = NULL; +void input_updown_leftright_standard_controller(BYTE index, BYTE nport) { + _permit_axes_standard_controller *pa = NULL; + static BYTE delay = 5; + BYTE value[2] = { 0 }; + BYTE axis[2] = { 0 }; if (cfg->input.permit_updown_leftright) { return; } if ((index == LEFT) || (index == RIGHT)) { - axis = &prt->permit.left_or_right; + axis[0] = LEFT; + axis[1] = RIGHT; + pa = &permit.left_or_right[nport]; } else if ((index == UP) || (index == DOWN)) { - axis = &prt->permit.up_or_down; + axis[0] = UP; + axis[1] = DOWN; + pa = &permit.up_or_down[nport]; } else { return; } - if ((*axis) == FALSE) { - (*axis) = prt->data.raw[src] ? src : opposite; - } else if (((*axis) == src) && (prt->data.raw[src] == RELEASED)) { - (*axis) = prt->data.raw[opposite] ? opposite : FALSE; - prt->data.treated[opposite] = prt->data.raw[opposite]; + value[0] = port[nport].data.raw[axis[0]]; + value[1] = port[nport].data.raw[axis[1]]; + if (!pa->delay) { + if (pa->axis != FALSE) { + if (((pa->axis == axis[0]) && !port[nport].data.raw[axis[0]]) || + ((pa->axis == axis[1]) && !port[nport].data.raw[axis[1]])) { + pa->delay = delay; + } + } else { + if (!(port[nport].data.raw[axis[0]] | port[nport].data.raw[axis[1]])) { + pa->axis = FALSE; + } else if (port[nport].data.raw[axis[0]] & port[nport].data.raw[axis[1]]) { + if (pa->axis == FALSE) { + pa->axis = axis[0]; + } + } else if (port[nport].data.raw[axis[0]]) { + pa->axis = axis[0]; + } else if (port[nport].data.raw[axis[1]]) { + pa->axis = axis[1]; + } else { + pa->axis = FALSE; + } + } + } else { + pa->delay--; + if (!pa->delay) { + pa->axis = FALSE; + } + } + if (pa->axis == axis[0]) { + value[1] = RELEASED; + } else if (pa->axis == axis[1]) { + value[0] = RELEASED; } - if ((*axis) == src) { - prt->data.treated[opposite] = RELEASED; - } else if ((*axis) == opposite) { - prt->data.treated[src] = RELEASED; + if (index == axis[0]) { + port[nport].data.treated[axis[0]] = value[0]; + } else { + port[nport].data.treated[axis[1]] = value[1]; } } diff --git a/src/core/input/standard_controller.h b/src/core/input/standard_controller.h index eebdafceb..8b8ac27bb 100644 --- a/src/core/input/standard_controller.h +++ b/src/core/input/standard_controller.h @@ -27,6 +27,16 @@ typedef struct _input_lfud_standard_controller { BYTE up; BYTE down; } _input_lfud_standard_controller; +typedef struct _permit_axes_standard_controller { + BYTE axis; + BYTE delay; +} _permit_axes_standard_controller; +typedef struct _permit_updown_leftright_standard_controller { + _permit_axes_standard_controller up_or_down[PORT_MAX]; + _permit_axes_standard_controller left_or_right[PORT_MAX]; +} _permit_updown_leftright_standard_controller; + +extern _permit_updown_leftright_standard_controller permit; #if defined (__cplusplus) #define EXTERNC extern "C" @@ -44,7 +54,7 @@ EXTERNC void input_rd_standard_controller_vs(BYTE nidx, BYTE *value, BYTE nport, EXTERNC void input_data_set_standard_controller(BYTE index, BYTE value, _port *prt); EXTERNC void input_rotate_standard_controller(_input_lfud_standard_controller *lfud); -EXTERNC void input_updown_leftright_standard_controller(BYTE index, BYTE src, BYTE opposite, _port *prt); +EXTERNC void input_updown_leftright_standard_controller(BYTE index, BYTE nport); #undef EXTERNC