Skip to content

Commit

Permalink
Fixed controller input display (#358).
Browse files Browse the repository at this point in the history
  • Loading branch information
punesemu committed Dec 22, 2023
1 parent f8e63ef commit 5249080
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 199 deletions.
3 changes: 2 additions & 1 deletion src/core/bck_states.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ void bck_states_op_input_port(BYTE id, BYTE mode, void *data, size_t *index, uin
bck_states_on_struct(mode, nes[nesidx].c.input.pindex, data, (*index), (*size_buff))
bck_states_on_struct(mode, nes[nesidx].c.input.fsindex, data, (*index), (*size_buff))
}
bck_states_on_struct(mode, port[id].data, data, (*index), (*size_buff))
bck_states_on_struct(mode, port[id].data.raw, data, (*index), (*size_buff))
bck_states_on_struct(mode, port[id].data.treated, data, (*index), (*size_buff))
bck_states_on_struct(mode, port[id].turbo, data, (*index), (*size_buff))
}
9 changes: 9 additions & 0 deletions src/core/emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,15 @@ void emu_save_header_info(void) {
BYTE emu_active_nidx(void) {
return (vs_system.special_mode.type == VS_DS_Normal ? cfg->vs_monitor : 0);
}
void emu_invert_bytes(BYTE *b0, BYTE *b1) {
BYTE tmp = (*b0);

(*b0) = (*b1);
(*b1) = tmp;
}
double emu_ms_to_cpu_cycles(double ms) {
return ((machine.cpu_hz * 0.001f) * ms);
}

INLINE static void emu_frame_started(void) {
info.lag_frame.next = TRUE;
Expand Down
2 changes: 2 additions & 0 deletions src/core/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ EXTERNC void emu_info_rom(void);
EXTERNC void emu_initial_ram(BYTE *ram, unsigned int length);
EXTERNC void emu_save_header_info(void);
EXTERNC BYTE emu_active_nidx(void);
EXTERNC void emu_invert_bytes(BYTE *b0, BYTE *b1);
EXTERNC double emu_ms_to_cpu_cycles(double ms);

#undef EXTERNC

Expand Down
70 changes: 6 additions & 64 deletions src/core/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ _port_funct port_funct[PORT_MAX];
_nes_keyboard nes_keyboard;
_generic_keyboard generic_keyboard;
_mic mic;
_ctrl_input_permit_updown_leftright cipu[PORT_MAX];
_ctrl_input_permit_updown_leftright cipl[PORT_MAX];

BYTE (*input_wr_reg)(BYTE nidx, BYTE value);
BYTE (*input_rd_reg[2])(BYTE nidx, BYTE openbus, BYTE nport);
Expand Down Expand Up @@ -115,8 +113,8 @@ void input_init(BYTE set_cursor) {
SET_DECODE_EVENT(a, NULL);
SET_ADD_EVENT(a, NULL);

memset(&cipu[a], 0x00, sizeof(_ctrl_input_permit_updown_leftright));
memset(&cipl[a], 0x00, sizeof(_ctrl_input_permit_updown_leftright));
port[a].permit.up_or_down = 0x00;
port[a].permit.left_or_right = 0x00;

// NSF
if (nsf.enabled) {
Expand Down Expand Up @@ -212,13 +210,13 @@ void input_init(BYTE set_cursor) {
state = PRESSED;
}

for (unsigned int b = 0; b < LENGTH(port[a].data); b++) {
for (unsigned int b = 0; b < LENGTH(port[a].data.raw); b++) {
if (b < 8) {
if (info.reset >= HARD) {
port[a].data[b] = RELEASED;
input_data_set_standard_controller(b, RELEASED, &port[a]);
}
} else {
port[a].data[b] = state;
input_data_set_standard_controller(b, state, &port[a]);
}
}
}
Expand Down Expand Up @@ -283,64 +281,8 @@ void input_init(BYTE set_cursor) {
}

void input_wr_disabled(UNUSED(BYTE nidx), UNUSED(const BYTE *value), UNUSED(BYTE nport)) {}
void input_rd_disabled(UNUSED(BYTE nidx), UNUSED(BYTE *value), UNUSED(BYTE nport), UNUSED(BYTE shift)) {}
void input_rd_disabled(UNUSED(BYTE nidx), UNUSED(BYTE *value), UNUSED(BYTE nport), UNUSED(BYTE shift)) {}

BYTE input_permit_updown_leftright(BYTE index, BYTE nport) {
_ctrl_input_permit_updown_leftright *cip = NULL;
static BYTE delay = 5;
BYTE value[2] = { 0 };
BYTE axe[2] = { 0 };

if (cfg->input.permit_updown_leftright) {
return (port[nport].data[index]);
}
if ((index == LEFT) || (index == RIGHT)) {
axe[0] = LEFT;
axe[1] = RIGHT;
cip = &cipl[nport];
} else if ((index == UP) || (index == DOWN)) {
axe[0] = UP;
axe[1] = DOWN;
cip = &cipu[nport];
} else {
return (port[nport].data[index]);
}
value[0] = port[nport].data[axe[0]];
value[1] = port[nport].data[axe[1]];
if (!cip->delay) {
if (cip->axe != FALSE) {
if (((cip->axe == axe[0]) && !port[nport].data[axe[0]]) ||
((cip->axe == axe[1]) && !port[nport].data[axe[1]])) {
cip->delay = delay;
}
} else {
if (!(port[nport].data[axe[0]] | port[nport].data[axe[1]])) {
cip->axe = FALSE;
} else if (port[nport].data[axe[0]] & port[nport].data[axe[1]]) {
if (cip->axe == FALSE) {
cip->axe = axe[0];
}
} else if (port[nport].data[axe[0]]) {
cip->axe = axe[0];
} else if (port[nport].data[axe[1]]) {
cip->axe = axe[1];
} else {
cip->axe = FALSE;
}
}
} else {
cip->delay--;
if (!cip->delay) {
cip->axe = FALSE;
}
}
if (cip->axe == axe[0]) {
value[1] = RELEASED;
} else if (cip->axe == axe[1]) {
value[0] = RELEASED;
}
return (index == axe[0] ? value[0] : value[1]);
}
BYTE input_draw_target(void) {
int i = 0;

Expand Down
16 changes: 8 additions & 8 deletions src/core/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ typedef struct _port {

// standard controller
BYTE type_pad;
BYTE data[INPUT_DECODE_COUNTS];
struct _port_data {
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;
Expand Down Expand Up @@ -138,19 +145,13 @@ typedef struct _nes_keyboard {
WORD totals;
BYTE matrix[NES_KEYBOARD_MAX_KEYS];
} _nes_keyboard;
typedef struct _ctrl_input_permit_updown_leftright {
BYTE axe;
int delay;
} _ctrl_input_permit_updown_leftright;

extern _port port[PORT_MAX];
extern _port_funct port_funct[PORT_MAX];
extern _arkanoid arkanoid[PORT_BASE];
extern _nes_keyboard nes_keyboard;
extern _generic_keyboard generic_keyboard;
extern _mic mic;
extern _ctrl_input_permit_updown_leftright cipu[PORT_MAX];
extern _ctrl_input_permit_updown_leftright cipl[PORT_MAX];

extern BYTE (*input_wr_reg)(BYTE nidx, BYTE value);
extern BYTE (*input_rd_reg[2])(BYTE nidx, BYTE openbus, BYTE nport);
Expand All @@ -166,7 +167,6 @@ EXTERNC void input_init(BYTE set_cursor);
EXTERNC void input_wr_disabled(BYTE nidx, const BYTE *value, BYTE nport);
EXTERNC void input_rd_disabled(BYTE nidx, BYTE *value, BYTE nport, BYTE shift);

EXTERNC BYTE input_permit_updown_leftright(BYTE index, BYTE nport);
EXTERNC BYTE input_draw_target();

#undef EXTERNC
Expand Down
8 changes: 4 additions & 4 deletions src/core/input/four_score.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ BYTE input_rd_reg_four_score(BYTE nidx, BYTE openbus, BYTE nport) {
BYTE value = 0;

if (nes[nidx].c.input.fsindex[nport] < 8) {
value = input_permit_updown_leftright(index, nport);
value = !!port[nport].data.treated[index];
nes[nidx].c.input.fsindex[nport]++;
} else if (nes[nidx].c.input.fsindex[nport] < 16) {
value = input_permit_updown_leftright(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) {
value = (four_score[nport].signature >> (23 - nes[nidx].c.input.fsindex[nport])) & 0x01;
Expand All @@ -75,10 +75,10 @@ BYTE input_rd_reg_four_score_vs(BYTE nidx, BYTE openbus, BYTE nport) {
np ^= 0x01;
}
if (nes[nidx].c.input.fsindex[nport] < 8) {
value = protection ? PRESSED : input_permit_updown_leftright(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) {
value = protection ? PRESSED : input_permit_updown_leftright(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) {
value = (four_score[np].signature >> (23 - nes[nidx].c.input.fsindex[nport])) & 0x01;
Expand Down
21 changes: 11 additions & 10 deletions src/core/input/nsf_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "input/nsf_controller.h"
#include "gui.h"
#include "nsf.h"
#include "input/standard_controller.h"

void input_add_event_nsf_controller(BYTE index) {
js_jdev_read_port(&jsp[index], &port[index]);
Expand All @@ -30,43 +31,43 @@ BYTE input_decode_event_nsf_controller(BYTE mode, BYTE autorepeat, DBWORD event,

if (event == prt->input[type][BUT_A]) {
if (!prt->turbo[TURBOA].active) {
prt->data[BUT_A] = mode;
input_data_set_standard_controller(BUT_A, mode, prt);
}
nsf.timers.button[BUT_A] = 0;
return (EXIT_OK);
} else if (event == prt->input[type][BUT_B]) {
if (!prt->turbo[TURBOB].active) {
prt->data[BUT_B] = mode;
input_data_set_standard_controller(BUT_B, mode, prt);
}
nsf.timers.button[BUT_B] = 0;
return (EXIT_OK);
} else if (event == prt->input[type][SELECT]) {
prt->data[SELECT] = mode;
input_data_set_standard_controller(SELECT, mode, prt);
nsf.timers.button[SELECT] = 0;
return (EXIT_OK);
} else if (event == prt->input[type][START]) {
prt->data[START] = mode;
input_data_set_standard_controller(START, mode, prt);
nsf.timers.button[START] = 0;
return (EXIT_OK);
} else if (event == prt->input[type][UP]) {
prt->data[UP] = mode;
input_data_set_standard_controller(UP, mode, prt);
nsf.timers.button[UP] = 0;
return (EXIT_OK);
} else if (event == prt->input[type][DOWN]) {
prt->data[DOWN] = mode;
input_data_set_standard_controller(DOWN, mode, prt);
nsf.timers.button[DOWN] = 0;
return (EXIT_OK);
} else if (event == prt->input[type][LEFT]) {
input_data_set_standard_controller(LEFT, mode, prt);
if (mode == PRESSED) {
prt->data[RIGHT] = RELEASED;
input_data_set_standard_controller(RIGHT, RELEASED, prt);
}
prt->data[LEFT] = mode;
nsf.timers.button[LEFT] = 0;
return (EXIT_OK);
} else if (event == prt->input[type][RIGHT]) {
prt->data[RIGHT] = mode;
input_data_set_standard_controller(RIGHT, mode, prt);
if (mode == PRESSED) {
prt->data[LEFT] = RELEASED;
input_data_set_standard_controller(LEFT, RELEASED, prt);
}
nsf.timers.button[RIGHT] = 0;
return (EXIT_OK);
Expand Down
13 changes: 8 additions & 5 deletions src/core/input/nsf_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <string.h>
#include "input/nsf_mouse.h"
#include "input/mouse.h"
#include "input/standard_controller.h"
#include "nsf.h"

struct _nsf_mouse {
Expand All @@ -43,11 +44,13 @@ void input_add_event_nsf_mouse(UNUSED(BYTE index)) {
}

if (nsf_mouse.pressed) {
port->data[LEFT] = RELEASED;
port->data[START] = RELEASED;
port->data[SELECT] = RELEASED;
port->data[BUT_A] = RELEASED;
port->data[RIGHT] = RELEASED;
_port *prt = &port[PORT1];

input_data_set_standard_controller(LEFT, RELEASED, prt);
input_data_set_standard_controller(START, RELEASED, prt);
input_data_set_standard_controller(SELECT, RELEASED, prt);
input_data_set_standard_controller(BUT_A, RELEASED, prt);
input_data_set_standard_controller(RIGHT, RELEASED, prt);
nsf_mouse.pressed = FALSE;
}
}
Loading

0 comments on commit 5249080

Please sign in to comment.