sgdrvsim: display or network broadcast speedometer and tachometer
Display speedometer value, or network broadcast speedo and tacho on port 8002 (slave 2) if option is set
This commit is contained in:
parent
5542d6db21
commit
4d990947de
|
@ -16,6 +16,8 @@
|
|||
#include "naomi_m3comm.h"
|
||||
#include "serialize.h"
|
||||
#include "network/output.h"
|
||||
#include "hw/sh4/modules/modules.h"
|
||||
#include "rend/gui.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -776,3 +778,71 @@ void initMidiForceFeedback()
|
|||
{
|
||||
aica::setMidiReceiver(forceFeedbackMidiReceiver);
|
||||
}
|
||||
|
||||
struct DriveSimPipe : public SerialPipe
|
||||
{
|
||||
void write(u8 data) override
|
||||
{
|
||||
if (buffer.empty() && data != 2)
|
||||
return;
|
||||
if (buffer.size() == 7)
|
||||
{
|
||||
u8 checksum = 0;
|
||||
for (u8 b : buffer)
|
||||
checksum += b;
|
||||
if (checksum == data)
|
||||
{
|
||||
int newTacho = (buffer[2] - 1) * 100;
|
||||
if (newTacho != tacho)
|
||||
{
|
||||
tacho = newTacho;
|
||||
networkOutput.output("tachometer", tacho);
|
||||
}
|
||||
int newSpeed = buffer[3] - 1;
|
||||
if (newSpeed != speed)
|
||||
{
|
||||
speed = newSpeed;
|
||||
networkOutput.output("speedometer", speed);
|
||||
}
|
||||
if (!config::NetworkOutput)
|
||||
{
|
||||
char message[16];
|
||||
sprintf(message, "Speed: %3d", speed);
|
||||
gui_display_notification(message, 1000);
|
||||
}
|
||||
}
|
||||
buffer.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
buffer.push_back(data);
|
||||
}
|
||||
}
|
||||
|
||||
int available() override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
u8 read() override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
buffer.clear();
|
||||
tacho = -1;
|
||||
speed = -1;
|
||||
}
|
||||
private:
|
||||
std::vector<u8> buffer;
|
||||
int tacho = -1;
|
||||
int speed = -1;
|
||||
};
|
||||
|
||||
void initDriveSimSerialPipe()
|
||||
{
|
||||
static DriveSimPipe pipe;
|
||||
|
||||
pipe.reset();
|
||||
serial_setPipe(&pipe);
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ extern u32 reg_dimm_parameterh;
|
|||
extern u32 reg_dimm_status;
|
||||
|
||||
void initMidiForceFeedback();
|
||||
void initDriveSimSerialPipe();
|
||||
|
||||
u32 libExtDevice_ReadMem_A0_006(u32 addr, u32 size);
|
||||
void libExtDevice_WriteMem_A0_006(u32 addr, u32 data, u32 size);
|
||||
|
|
|
@ -631,6 +631,8 @@ void naomi_cart_LoadRom(const char* file, LoadProgress *progress)
|
|||
// Not a multiboard game but needs the same desktop environment
|
||||
if (gameId == "SAMPLE GAME MAX LONG NAME-") // Driving Simulator
|
||||
{
|
||||
initDriveSimSerialPipe();
|
||||
|
||||
config::NetworkEnable.override(true);
|
||||
config::ActAsServer.override(settings.naomi.drivingSimSlave == 0);
|
||||
config::NetworkServer.override("localhost:" + std::to_string(config::LocalPort));
|
||||
|
|
|
@ -27,7 +27,7 @@ class NetworkOutput
|
|||
public:
|
||||
void init()
|
||||
{
|
||||
if (!config::NetworkOutput || settings.naomi.slave || settings.naomi.drivingSimSlave != 0)
|
||||
if (!config::NetworkOutput || settings.naomi.slave || settings.naomi.drivingSimSlave == 1)
|
||||
return;
|
||||
server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
socklen_t saddr_len = sizeof(saddr);
|
||||
saddr.sin_family = AF_INET;
|
||||
saddr.sin_addr.s_addr = INADDR_ANY;
|
||||
saddr.sin_port = htons(8000);
|
||||
saddr.sin_port = htons(8000 + settings.naomi.drivingSimSlave);
|
||||
if (::bind(server, (sockaddr *)&saddr, saddr_len) < 0)
|
||||
{
|
||||
perror("bind");
|
||||
|
|
Loading…
Reference in New Issue