Skip to content

Commit

Permalink
[ADAPTER] Make MT (Home) button toggle output mode
Browse files Browse the repository at this point in the history
  • Loading branch information
darthcloud committed Aug 27, 2023
1 parent 20ac63a commit eea61f8
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 8 deletions.
25 changes: 24 additions & 1 deletion main/adapter/wired/dc.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "tools/util.h"
#include "adapter/config.h"
#include "adapter/wired/wired.h"
#include "system/manager.h"
#include "dc.h"

enum {
Expand Down Expand Up @@ -99,7 +100,7 @@ struct dc_kb_map {
};
} __packed;

static const uint32_t dc_mask[4] = {0x333FFFFF, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t dc_mask[4] = {0x337FFFFF, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t dc_desc[4] = {0x110000FF, 0x00000000, 0x00000000, 0x00000000};
static DRAM_ATTR const uint32_t dc_btns_mask[32] = {
0, 0, 0, 0,
Expand Down Expand Up @@ -163,6 +164,26 @@ static const uint8_t dc_kb_scancode[KBM_MAX] = {
0x00, 0x00, 0x00,
};

static void dc_ctrl_special_action(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
/* Output config mode toggle GamePad/GamePadAlt */
if (ctrl_data->map_mask[0] & generic_btns_mask[PAD_MT]) {
if (ctrl_data->btns[0].value & generic_btns_mask[PAD_MT]) {
if (!atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_set_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);
}
}
else {
if (atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_clear_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);

config.out_cfg[ctrl_data->index].dev_mode &= 0x01;
config.out_cfg[ctrl_data->index].dev_mode ^= 0x01;
sys_mgr_cmd(SYS_MGR_CMD_WIRED_RST);
}
}
}
}

void IRAM_ATTR dc_init_buffer(int32_t dev_mode, struct wired_data *wired_data) {
switch (dev_mode) {
case DEV_KB:
Expand Down Expand Up @@ -247,6 +268,8 @@ static void dc_ctrl_from_generic(struct wired_ctrl *ctrl_data, struct wired_data
}
}

dc_ctrl_special_action(ctrl_data, wired_data);

for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) {
if (ctrl_data->map_mask[0] & (axis_to_btn_mask(i) & dc_desc[0])) {
if (ctrl_data->axes[i].value > ctrl_data->axes[i].meta->size_max) {
Expand Down
29 changes: 28 additions & 1 deletion main/adapter/wired/genesis.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string.h>
#include "adapter/config.h"
#include "adapter/wired/wired.h"
#include "system/manager.h"
#include "zephyr/types.h"
#include "tools/util.h"
#include "genesis.h"
Expand Down Expand Up @@ -122,7 +123,7 @@ struct genesis_map {
uint16_t twh_buttons;
} __packed;

static const uint32_t genesis_mask[4] = {0x333F0F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t genesis_mask[4] = {0x337F0F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t genesis_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
static DRAM_ATTR const uint32_t genesis_btns_mask[2][3][32] = {
{
Expand Down Expand Up @@ -208,6 +209,26 @@ static DRAM_ATTR const uint32_t genesis_twh_btns_mask[32] = {
BIT(GENESIS_Z), BIT(GENESIS_Z), 0, 0,
};

static void genesis_ctrl_special_action(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
/* Output config mode toggle GamePad/GamePadAlt */
if (ctrl_data->map_mask[0] & generic_btns_mask[PAD_MT]) {
if (ctrl_data->btns[0].value & generic_btns_mask[PAD_MT]) {
if (!atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_set_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);
}
}
else {
if (atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_clear_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);

config.out_cfg[ctrl_data->index].dev_mode &= 0x01;
config.out_cfg[ctrl_data->index].dev_mode ^= 0x01;
sys_mgr_cmd(SYS_MGR_CMD_WIRED_RST);
}
}
}
}

static void sega_mouse_from_generic(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
struct sega_mouse_map map_tmp;
int32_t *raw_axes = (int32_t *)(wired_data->output + 28);
Expand Down Expand Up @@ -283,6 +304,8 @@ static void genesis_std_from_generic(struct wired_ctrl *ctrl_data, struct wired_
}
}

genesis_ctrl_special_action(ctrl_data, wired_data);

memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp));

#ifdef CONFIG_BLUERETRO_RAW_OUTPUT
Expand Down Expand Up @@ -312,6 +335,8 @@ static void genesis_twh_from_generic(struct wired_ctrl *ctrl_data, struct wired_
}
}

genesis_ctrl_special_action(ctrl_data, wired_data);

memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp));
}

Expand Down Expand Up @@ -340,6 +365,8 @@ static void genesis_ea_from_generic(struct wired_ctrl *ctrl_data, struct wired_d
}
}

genesis_ctrl_special_action(ctrl_data, wired_data);

memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp));
}

Expand Down
27 changes: 25 additions & 2 deletions main/adapter/wired/pce.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <string.h>
#include "adapter/config.h"
#include "adapter/wired/wired.h"
#include "system/manager.h"
#include "zephyr/types.h"
#include "tools/util.h"
#include "pce.h"
Expand Down Expand Up @@ -88,7 +89,7 @@ static const uint32_t pce_mouse_btns_mask[32] = {
P1_R_II_MASK, 0, 0, 0,
};

static const uint32_t pce_mask[4] = {0x00350F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t pce_mask[4] = {0x00750F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t pce_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
static DRAM_ATTR const uint32_t pce_btns_mask[][32] = {
/* URDL */
Expand Down Expand Up @@ -126,7 +127,7 @@ static DRAM_ATTR const uint32_t pce_btns_mask[][32] = {
},
};

static const uint32_t pce_6btns_mask[4] = {0x333F0F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t pce_6btns_mask[4] = {0x337F0F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t pce_6btns_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
static DRAM_ATTR const uint32_t pce_6btns_btns_mask[][32] = {
/* URDL */
Expand Down Expand Up @@ -164,6 +165,26 @@ static DRAM_ATTR const uint32_t pce_6btns_btns_mask[][32] = {
},
};

static void pce_ctrl_special_action(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
/* Output config mode toggle GamePad/GamePadAlt */
if (ctrl_data->map_mask[0] & generic_btns_mask[PAD_MT]) {
if (ctrl_data->btns[0].value & generic_btns_mask[PAD_MT]) {
if (!atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_set_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);
}
}
else {
if (atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_clear_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);

config.out_cfg[ctrl_data->index].dev_mode &= 0x01;
config.out_cfg[ctrl_data->index].dev_mode ^= 0x01;
sys_mgr_cmd(SYS_MGR_CMD_WIRED_RST);
}
}
}
}

static void pce_mouse_from_generic(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
struct pce_mouse_map map_tmp;
int32_t *raw_axes = (int32_t *)(wired_data->output);
Expand Down Expand Up @@ -225,6 +246,8 @@ static void pce_ctrl_from_generic(struct wired_ctrl *ctrl_data, struct wired_dat
}
}

pce_ctrl_special_action(ctrl_data, wired_data);

memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp));

#ifdef CONFIG_BLUERETRO_RAW_OUTPUT
Expand Down
29 changes: 27 additions & 2 deletions main/adapter/wired/real.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "tools/util.h"
#include "adapter/config.h"
#include "adapter/wired/wired.h"
#include "system/manager.h"
#include "real.h"

enum {
Expand Down Expand Up @@ -85,7 +86,7 @@ struct real_mouse_map {
int32_t raw_axes[2];
} __packed;

static const uint32_t real_mask[4] = {0x33370F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t real_mask[4] = {0x33770F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t real_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
static DRAM_ATTR const uint32_t real_btns_mask[32] = {
0, 0, 0, 0,
Expand All @@ -98,7 +99,7 @@ static DRAM_ATTR const uint32_t real_btns_mask[32] = {
BIT(REAL_R), BIT(REAL_R), 0, 0,
};

static const uint32_t real_fs_mask[4] = {0x333F0FCF, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t real_fs_mask[4] = {0x337F0FCF, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t real_fs_desc[4] = {0x000000CF, 0x00000000, 0x00000000, 0x00000000};
static DRAM_ATTR const uint32_t real_fs_btns_mask[32] = {
0, 0, 0, 0,
Expand All @@ -124,6 +125,26 @@ static const uint32_t real_mouse_btns_mask[32] = {
BIT(REAL_M_LEFT), 0, 0, 0,
};

static void real_ctrl_special_action(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
/* Output config mode toggle GamePad/GamePadAlt */
if (ctrl_data->map_mask[0] & generic_btns_mask[PAD_MT]) {
if (ctrl_data->btns[0].value & generic_btns_mask[PAD_MT]) {
if (!atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_set_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);
}
}
else {
if (atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_clear_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);

config.out_cfg[ctrl_data->index].dev_mode &= 0x01;
config.out_cfg[ctrl_data->index].dev_mode ^= 0x01;
sys_mgr_cmd(SYS_MGR_CMD_WIRED_RST);
}
}
}
}

void IRAM_ATTR real_init_buffer(int32_t dev_mode, struct wired_data *wired_data) {
switch (dev_mode) {
case DEV_MOUSE:
Expand Down Expand Up @@ -209,6 +230,8 @@ void real_ctrl_from_generic(struct wired_ctrl *ctrl_data, struct wired_data *wir
}
}

real_ctrl_special_action(ctrl_data, wired_data);

memcpy(wired_data->output, (void *)&map_tmp, sizeof(map_tmp));

#ifdef CONFIG_BLUERETRO_RAW_OUTPUT
Expand Down Expand Up @@ -238,6 +261,8 @@ void real_fs_from_generic(struct wired_ctrl *ctrl_data, struct wired_data *wired
}
}

real_ctrl_special_action(ctrl_data, wired_data);

for (uint32_t i = 0; i < 4; i++) {
if (ctrl_data->map_mask[0] & (axis_to_btn_mask(i) & real_fs_desc[0])) {
uint16_t tmp = ctrl_data->axes[i].meta->neutral;
Expand Down
27 changes: 25 additions & 2 deletions main/adapter/wired/saturn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "adapter/config.h"
#include "adapter/kb_monitor.h"
#include "adapter/wired/wired.h"
#include "system/manager.h"
#include "saturn.h"

enum {
Expand Down Expand Up @@ -84,9 +85,9 @@ struct sega_mouse_map {
int32_t raw_axes[2];
} __packed;

static const uint32_t saturn_mask[4] = {0x331F0F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t saturn_mask[4] = {0x335F0F00, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t saturn_desc[4] = {0x00000000, 0x00000000, 0x00000000, 0x00000000};
static const uint32_t saturn_3d_mask[4] = {0x331F0F0F, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t saturn_3d_mask[4] = {0x335F0F0F, 0x00000000, 0x00000000, BR_COMBO_MASK};
static const uint32_t saturn_3d_desc[4] = {0x1100000F, 0x00000000, 0x00000000, 0x00000000};
static DRAM_ATTR const uint32_t saturn_btns_mask[32] = {
0, 0, 0, 0,
Expand Down Expand Up @@ -151,6 +152,26 @@ static const uint8_t saturn_kb_scancode[KBM_MAX] = {
0x59, 0x17, 0x00,
};

static void saturn_ctrl_special_action(struct wired_ctrl *ctrl_data, struct wired_data *wired_data) {
/* Output config mode toggle GamePad/GamePadAlt */
if (ctrl_data->map_mask[0] & generic_btns_mask[PAD_MT]) {
if (ctrl_data->btns[0].value & generic_btns_mask[PAD_MT]) {
if (!atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_set_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);
}
}
else {
if (atomic_test_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE)) {
atomic_clear_bit(&wired_data->flags, WIRED_WAITING_FOR_RELEASE);

config.out_cfg[ctrl_data->index].dev_mode &= 0x01;
config.out_cfg[ctrl_data->index].dev_mode ^= 0x01;
sys_mgr_cmd(SYS_MGR_CMD_WIRED_RST);
}
}
}
}

void IRAM_ATTR saturn_init_buffer(int32_t dev_mode, struct wired_data *wired_data) {
switch (dev_mode) {
case DEV_KB:
Expand Down Expand Up @@ -244,6 +265,8 @@ void saturn_ctrl_from_generic(struct wired_ctrl *ctrl_data, struct wired_data *w
}
}

saturn_ctrl_special_action(ctrl_data, wired_data);

if (config.out_cfg[ctrl_data->index].dev_mode == DEV_PAD_ALT) {
for (uint32_t i = 0; i < ADAPTER_MAX_AXES; i++) {
if (i == 2 || i == 3) {
Expand Down

0 comments on commit eea61f8

Please sign in to comment.