naomi: insert card button compatibility with ggpo

handle insert card button like standard naomi buttons so it can be used
with ggpo
load card data when it's inserted, not before
This commit is contained in:
Flyinghead 2023-05-06 20:54:45 +02:00
parent 220fd51b27
commit 1a5a2f64d4
9 changed files with 26 additions and 15 deletions

View File

@ -1498,7 +1498,7 @@ struct RFIDReaderWriter : maple_base
void OnSetup() override
{
loadCard();
memset(cardData, 0, sizeof(cardData));
}
std::string getCardPath() const {
@ -1576,6 +1576,7 @@ struct RFIDReaderWriter : maple_base
void insertCard() {
cardInserted = true;
loadCard();
}
u8 cardData[128];

View File

@ -6,6 +6,7 @@
#include "hw/sh4/sh4_mem.h"
#include "hw/sh4/sh4_sched.h"
#include "network/ggpo.h"
#include "hw/naomi/card_reader.h"
enum MaplePattern
{
@ -135,6 +136,18 @@ static void maple_DoDma()
#endif
ggpo::getInput(mapleInputState);
// TODO put this elsewhere and let the card readers handle being called multiple times
if (settings.platform.isNaomi())
{
static u32 last_kcode[std::size(mapleInputState)];
for (size_t i = 0; i < std::size(mapleInputState); i++)
{
if ((mapleInputState[i].kcode & DC_BTN_INSERT_CARD) == 0
&& (last_kcode[i] & DC_BTN_INSERT_CARD) != 0)
card_reader::insertCard(i);
last_kcode[i] = mapleInputState[i].kcode;
}
}
const bool swap_msb = (SB_MMSEL == 0);
u32 xfer_count = 0;

View File

@ -59,7 +59,7 @@ extern u32 awavelg_button_mapping[32];
const char *GetCurrentGameButtonName(DreamcastKey key)
{
if (NaomiGameInputs == nullptr || key == EMU_BTN_NONE || key > DC_BTN_RELOAD)
if (NaomiGameInputs == nullptr || key == EMU_BTN_NONE || key > DC_BTN_BITMAPPED_LAST)
return nullptr;
u32 pos = 0;
u32 val = (u32)key;

View File

@ -160,7 +160,7 @@ private:
};
std::vector<Socket> sockets;
bool dnsInProgress = false;
u32 serverIp = 0; //0x1e01a8c0 for testing only
u32 serverIp = 0; //0x0100007f for testing only
bool finalTuned = false;
u32 dimmBufferOffset = 0x0f000000;

View File

@ -36,6 +36,8 @@ enum DreamcastKey
DC_DPAD2_LEFT = 1 << 14,
DC_DPAD2_RIGHT = 1 << 15,
DC_BTN_RELOAD = 1 << 16, // Not a real button but handled like one
DC_BTN_INSERT_CARD = 1 << 17, // Not a real button but handled like one
DC_BTN_BITMAPPED_LAST = DC_BTN_INSERT_CARD,
// System buttons
EMU_BTN_NONE = 0,
@ -46,7 +48,6 @@ enum DreamcastKey
EMU_BTN_MENU,
EMU_BTN_FFORWARD,
EMU_BTN_ESCAPE,
EMU_BTN_INSERT_CARD,
EMU_BTN_LOADSTATE,
EMU_BTN_SAVESTATE,

View File

@ -23,7 +23,6 @@
#include "rend/gui.h"
#include "emulator.h"
#include "hw/maple/maple_devs.h"
#include "hw/naomi/card_reader.h"
#include "mouse.h"
#include <algorithm>
@ -58,7 +57,7 @@ bool GamepadDevice::handleButtonInput(int port, DreamcastKey key, bool pressed)
if (key == EMU_BTN_NONE)
return false;
if (key <= DC_BTN_RELOAD)
if (key <= DC_BTN_BITMAPPED_LAST)
{
if (port >= 0)
{
@ -88,10 +87,6 @@ bool GamepadDevice::handleButtonInput(int port, DreamcastKey key, bool pressed)
if (pressed && !gui_is_open())
settings.input.fastForwardMode = !settings.input.fastForwardMode && !settings.network.online && !settings.naomi.multiboard;
break;
case EMU_BTN_INSERT_CARD:
if (pressed && settings.platform.isNaomi())
card_reader::insertCard(maple_port());
break;
case EMU_BTN_LOADSTATE:
if (pressed)
gui_loadState();
@ -258,7 +253,7 @@ bool GamepadDevice::gamepad_axis_input(u32 code, int value)
else
*this_axis = v * axisDirection;
}
else if (key != EMU_BTN_NONE && key <= DC_BTN_RELOAD) // Map triggers to digital buttons
else if (key != EMU_BTN_NONE && key <= DC_BTN_BITMAPPED_LAST) // Map triggers to digital buttons
{
//printf("B-AXIS %d Mapped to %d -> %d\n", key, value, v);
// TODO hysteresis?

View File

@ -55,7 +55,7 @@ button_list[] =
{ DC_AXIS_LEFT, "compat", "btn_analog_left" },
{ DC_AXIS_RIGHT, "compat", "btn_analog_right" },
{ DC_BTN_RELOAD, "dreamcast", "reload" },
{ EMU_BTN_INSERT_CARD, "emulator", "insert_card" },
{ DC_BTN_INSERT_CARD, "emulator", "insert_card" },
{ EMU_BTN_LOADSTATE, "emulator", "btn_jump_state" },
{ EMU_BTN_SAVESTATE, "emulator", "btn_quick_save" },
};

View File

@ -94,8 +94,8 @@ using namespace std::chrono;
constexpr int MAX_PLAYERS = 2;
constexpr int SERVER_PORT = 19713;
constexpr u32 BTN_TRIGGER_LEFT = DC_BTN_RELOAD << 1;
constexpr u32 BTN_TRIGGER_RIGHT = DC_BTN_RELOAD << 2;
constexpr u32 BTN_TRIGGER_LEFT = DC_BTN_BITMAPPED_LAST << 1;
constexpr u32 BTN_TRIGGER_RIGHT = DC_BTN_BITMAPPED_LAST << 2;
#pragma pack(push, 1)
struct VerificationData
@ -169,6 +169,7 @@ struct Inputs
} u;
};
static_assert(sizeof(Inputs) == 10, "wrong Inputs size");
static_assert(BTN_TRIGGER_RIGHT < (1 << 20));
struct GameEvent
{

View File

@ -808,6 +808,7 @@ const Mapping arcadeButtons[] = {
{ DC_BTN_D, "Coin" },
{ DC_DPAD2_UP, "Service" },
{ DC_DPAD2_DOWN, "Test" },
{ DC_BTN_INSERT_CARD, "Insert Card" },
{ EMU_BTN_NONE, "Emulator" },
{ EMU_BTN_MENU, "Menu" },
@ -815,7 +816,6 @@ const Mapping arcadeButtons[] = {
{ EMU_BTN_FFORWARD, "Fast-forward" },
{ EMU_BTN_LOADSTATE, "Load State" },
{ EMU_BTN_SAVESTATE, "Save State" },
{ EMU_BTN_INSERT_CARD, "Insert Card" },
{ EMU_BTN_NONE, nullptr }
};