Skip to content

Commit d3908c5

Browse files
authored
Merge pull request #718 from johnbaumann/main
Add SIO1 Server + cdrom adjustments to support Unirom/NotPSXSerial
2 parents 58133cd + 3c3e1ae commit d3908c5

File tree

15 files changed

+771
-62
lines changed

15 files changed

+771
-62
lines changed

src/core/cdrom.cc

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class CDRomImpl : public PCSX::CDRom {
6969
CdlReadToc = 30,
7070
};
7171

72+
static const size_t cdCmdEnumCount = magic_enum::enum_count<Commands>();
73+
7274
static const inline uint8_t Test04[] = {0};
7375
static const inline uint8_t Test05[] = {0};
7476
static const inline uint8_t Test20[] = {0x98, 0x06, 0x10, 0xC3};
@@ -915,6 +917,15 @@ class CDRomImpl : public PCSX::CDRom {
915917

916918
case CdlID + 0x100:
917919
SetResultSize(8);
920+
921+
if (!m_iso.isActive()) {
922+
m_result[0] = 0x08;
923+
m_result[1] = 0x40;
924+
memset((char *)&m_result[2], 0, 6);
925+
m_stat = DiskError;
926+
break;
927+
}
928+
918929
m_result[0] = m_statP;
919930
m_result[1] = 0;
920931
m_result[2] = 0;
@@ -1232,9 +1243,11 @@ class CDRomImpl : public PCSX::CDRom {
12321243
m_ctrl &= ~0x20;
12331244
}
12341245

1235-
if (m_OCUP) m_ctrl |= 0x40;
1236-
// else
1237-
// m_ctrl &= ~0x40;
1246+
if (m_OCUP) {
1247+
m_ctrl |= 0x40;
1248+
} else {
1249+
m_ctrl &= ~0x40;
1250+
}
12381251

12391252
m_ctrl |= 0x18;
12401253

@@ -1276,7 +1289,12 @@ class CDRomImpl : public PCSX::CDRom {
12761289
m_cmd = rt;
12771290
m_OCUP = 0;
12781291

1279-
CDROM_IO_LOG("CD1 write: %x (%s)", rt, magic_enum::enum_names<Commands>()[rt]);
1292+
if (rt > cdCmdEnumCount) {
1293+
CDROM_IO_LOG("CD1 write: %x (CdlUnknown)", rt);
1294+
} else {
1295+
CDROM_IO_LOG("CD1 write: %x (%s)", rt, magic_enum::enum_names<Commands>()[rt]);
1296+
}
1297+
12801298
if (m_paramC) {
12811299
CDROM_IO_LOG(" Param[%d] = {", m_paramC);
12821300
for (i = 0; i < m_paramC; i++) CDROM_IO_LOG(" %x,", m_param[i]);
@@ -1342,6 +1360,7 @@ class CDRomImpl : public PCSX::CDRom {
13421360
unsigned char ret;
13431361

13441362
if (m_read == 0) {
1363+
m_OCUP = 0;
13451364
ret = 0;
13461365
} else {
13471366
ret = m_transfer[m_transferIndex];
@@ -1658,8 +1677,13 @@ class CDRomImpl : public PCSX::CDRom {
16581677
m_param[0]);
16591678
break;
16601679
default:
1661-
PCSX::g_system->log(PCSX::LogClass::CDROM, "[CDROM]%s Command: %s\n", delayedString,
1662-
magic_enum::enum_names<Commands>()[command & 0xff]);
1680+
if ((command & 0xff) > cdCmdEnumCount) {
1681+
PCSX::g_system->log(PCSX::LogClass::CDROM, "[CDROM]%s Command: CdlUnknown(0x%02X)\n", delayedString,
1682+
command & 0xff);
1683+
} else {
1684+
PCSX::g_system->log(PCSX::LogClass::CDROM, "[CDROM]%s Command: %s\n", delayedString,
1685+
magic_enum::enum_names<Commands>()[command & 0xff]);
1686+
}
16631687
break;
16641688
}
16651689
}

src/core/logger.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ enum class LogClass : unsigned {
3232
MIPS, // only the things coming from MIPS code
3333
UI, // messages from the UI specifically
3434
SIO0, // pad and memory card information
35-
SIO1, // uart information
35+
SIO1, // uart/sio1 information
36+
SIO1SERVER, // uart/sio1 server information
3637
GTE, // gte information
3738
CDROM, // low level cdrom information
3839
CDROM_IO, // high level cdrom information (iso file access)

src/core/psxemulator.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include "core/pcsxlua.h"
3232
#include "core/ppf.h"
3333
#include "core/r3000a.h"
34+
#include "core/sio1.h"
35+
#include "core/sio1-server.h"
3436
#include "core/web-server.h"
3537
#include "gpu/soft/interface.h"
3638
#include "lua/luawrapper.h"
@@ -51,6 +53,8 @@ PCSX::Emulator::Emulator()
5153
m_gpu(new PCSX::SoftGPU::impl()),
5254
m_gdbServer(new PCSX::GdbServer()),
5355
m_webServer(new PCSX::WebServer()),
56+
m_sio1(new PCSX::SIO1()),
57+
m_sio1Server(new PCSX::SIO1Server()),
5458
m_debug(new PCSX::Debug()),
5559
m_hw(new PCSX::HW()),
5660
m_spu(new PCSX::SPU::impl()),
@@ -99,6 +103,7 @@ void PCSX::Emulator::EmuReset() {
99103
m_gpu->clearVRAM();
100104
m_pads->shutdown();
101105
m_pads->init();
106+
m_sio1->sio1Reset();
102107
}
103108

104109
void PCSX::Emulator::EmuShutdown() {

src/core/psxemulator.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ class SIO;
9393
class SPUInterface;
9494
class System;
9595
class WebServer;
96+
class SIO1;
97+
class SIO1Server;
9698

9799
class Emulator;
98100
extern Emulator* g_emulator;
@@ -145,11 +147,13 @@ class Emulator {
145147
typedef Setting<uint32_t, TYPESTRING("KernelCallC0_00_1f"), 0xffffffff> KernelCallC0_00_1f;
146148
typedef Setting<bool, TYPESTRING("PCdrv"), false> PCdrv;
147149
typedef SettingPath<TYPESTRING("PCdrvBase")> PCdrvBase;
150+
typedef Setting<bool, TYPESTRING("SIO1Server"), false> SIO1Server;
151+
typedef Setting<int, TYPESTRING("SIO1ServerPort"), 6699> SIO1ServerPort;
148152
typedef Settings<Debug, Trace, KernelLog, FirstChanceException, SkipISR, LoggingCDROM, GdbServer, GdbManifest,
149153
GdbLogSetting, GdbServerPort, GdbServerTrace, WebServer, WebServerPort, KernelCallA0_00_1f,
150154
KernelCallA0_20_3f, KernelCallA0_40_5f, KernelCallA0_60_7f, KernelCallA0_80_9f,
151155
KernelCallA0_a0_bf, KernelCallB0_00_1f, KernelCallB0_20_3f, KernelCallB0_40_5f,
152-
KernelCallC0_00_1f, PCdrv, PCdrvBase>
156+
KernelCallC0_00_1f, PCdrv, PCdrvBase, SIO1Server, SIO1ServerPort>
153157
type;
154158
};
155159
typedef SettingNested<TYPESTRING("Debug"), DebugSettings::type> SettingDebugSettings;
@@ -242,6 +246,8 @@ class Emulator {
242246
std::unique_ptr<Pads> m_pads;
243247
std::unique_ptr<R3000Acpu> m_psxCpu;
244248
std::unique_ptr<SIO> m_sio;
249+
std::unique_ptr<SIO1> m_sio1;
250+
std::unique_ptr<SIO1Server> m_sio1Server;
245251
std::unique_ptr<SPUInterface> m_spu;
246252
std::unique_ptr<WebServer> m_webServer;
247253

src/core/psxhw.cc

Lines changed: 87 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,27 @@ uint8_t PCSX::HW::psxHwRead8(uint32_t add) {
5454
case 0x1f801040:
5555
hard = PCSX::g_emulator->m_sio->sioRead8();
5656
break;
57-
#ifdef ENABLE_SIO1API
58-
case 0x1f801050:
59-
hard = SIO1_readData8();
57+
case 0x1f801050: // rx/tx data register
58+
hard = PCSX::g_emulator->m_sio1->readData8();
59+
SIO1_LOG("SIO1.DATA read8 %x; ret = %x\n", add & 0xf, hard);
60+
break;
61+
case 0x1f801054: // stat register
62+
hard = PCSX::g_emulator->m_sio1->readStat8();
63+
// Log command below is overly spammy
64+
//SIO1_LOG("SIO1.STAT read8 %x; ret = %x\n", add & 0xf, hard);
65+
break;
66+
case 0x1f801058: // mode register
67+
hard = PCSX::g_emulator->m_sio1->readMode8();
68+
SIO1_LOG("SIO1.MODE read8 %x; ret = %x\n", add & 0xf, hard);
69+
break;
70+
case 0x1f80105a: // control register
71+
hard = PCSX::g_emulator->m_sio1->readCtrl8();
72+
SIO1_LOG("SIO1.CTRL read8 %x; ret = %x\n", add & 0xf, hard);
73+
break;
74+
case 0x1f80105e: // baudrate register
75+
hard = PCSX::g_emulator->m_sio1->readBaud8();
76+
SIO1_LOG("SIO1.BAUD read8 %x; ret = %x\n", add & 0xf, hard);
6077
break;
61-
#endif
6278
case 0x1f801800:
6379
hard = PCSX::g_emulator->m_cdrom->read0();
6480
break;
@@ -127,35 +143,36 @@ uint16_t PCSX::HW::psxHwRead16(uint32_t add) {
127143
hard = PCSX::g_emulator->m_sio->readBaud16();
128144
SIO0_LOG("sio read16 %x; ret = %x\n", add & 0xf, hard);
129145
return hard;
130-
#ifdef ENABLE_SIO1API
131-
case 0x1f801050:
132-
hard = SIO1_readData16();
133-
SIO1_LOG("sio1 read16 %x; ret = %x\n", add & 0xf, hard);
146+
case 0x1f801050: // rx/tx data register
147+
hard = PCSX::g_emulator->m_sio1->readData16();
148+
SIO1_LOG("SIO1.DATA read16 %x; ret = %x\n", add & 0xf, hard);
134149
return hard;
135-
case 0x1f801054:
136-
hard = SIO1_readStat16();
137-
SIO1_LOG("sio1 read16 %x; ret = %x\n", add & 0xf, hard);
150+
case 0x1f801054: // stat register
151+
hard = PCSX::g_emulator->m_sio1->readStat16();
152+
// Log command below is overly spammy
153+
//SIO1_LOG("SIO1.STAT read16 %x; ret = %x\n", add & 0xf, hard);
138154
return hard;
139-
case 0x1f801058:
140-
hard = SIO1_readMode16();
141-
SIO1_LOG("sio1 read16 %x; ret = %x\n", add & 0xf, hard);
155+
case 0x1f801058: // mode register
156+
hard = PCSX::g_emulator->m_sio1->readMode16();
157+
SIO1_LOG("SIO1.MODE read16 %x; ret = %x\n", add & 0xf, hard);
142158
return hard;
143-
case 0x1f80105a:
144-
hard = SIO1_readCtrl16();
145-
SIO1_LOG("sio1 read16 %x; ret = %x\n", add & 0xf, hard);
159+
case 0x1f80105a: // control register
160+
hard = PCSX::g_emulator->m_sio1->readCtrl16();
161+
SIO1_LOG("SIO1.CTRL read16 %x; ret = %x\n", add & 0xf, hard);
146162
return hard;
147-
case 0x1f80105e:
148-
hard = SIO1_readBaud16();
149-
SIO1_LOG("sio1 read16 %x; ret = %x\n", add & 0xf, hard);
163+
case 0x1f80105e: // baudrate register
164+
hard = PCSX::g_emulator->m_sio1->readBaud16();
165+
SIO1_LOG("SIO1.BAUD read16 %x; ret = %x\n", add & 0xf, hard);
150166
return hard;
151-
#else
152167
/* Fixes Armored Core misdetecting the Link cable being detected.
153168
* We want to turn that thing off and force it to do local multiplayer instead.
154169
* Thanks Sony for the fix, they fixed it in their PS Classic fork.
155170
*/
171+
/* Stat's value set in SIO1/m_sio1, Armored Core local multiplayer is working.
156172
case 0x1f801054:
157173
return 0x80;
158-
#endif
174+
*/
175+
159176
case 0x1f801100:
160177
hard = PCSX::g_emulator->m_psxCounters->psxRcntRcount(0);
161178
PSXHW_LOG("T0 count read16: %x\n", hard);
@@ -228,12 +245,15 @@ uint32_t PCSX::HW::psxHwRead32(uint32_t add) {
228245
hard |= PCSX::g_emulator->m_sio->sioRead8() << 24;
229246
SIO0_LOG("sio read32 ;ret = %x\n", hard);
230247
return hard;
231-
#ifdef ENABLE_SIO1API
232-
case 0x1f801050:
233-
hard = SIO1_readData32();
234-
SIO1_LOG("sio1 read32 ;ret = %x\n", hard);
248+
case 0x1f801050: // rx/tx data register
249+
hard = PCSX::g_emulator->m_sio1->readData32();
250+
SIO1_LOG("SIO1.DATA read32 ;ret = %x\n", hard);
251+
return hard;
252+
case 0x1f801054: // stat register
253+
hard = PCSX::g_emulator->m_sio1->readStat32();
254+
// Log command below is overly spammy
255+
//SIO1_LOG("SIO1.STAT read32 ;ret = %x\n", hard);
235256
return hard;
236-
#endif
237257
case 0x1f801060:
238258
PSXHW_LOG("RAM size read %x\n", psxHu32(0x1060));
239259
return psxHu32(0x1060);
@@ -341,11 +361,26 @@ void PCSX::HW::psxHwWrite8(uint32_t add, uint8_t value) {
341361
case 0x1f801040:
342362
PCSX::g_emulator->m_sio->write8(value);
343363
break;
344-
#ifdef ENABLE_SIO1API
345-
case 0x1f801050:
346-
SIO1_writeData8(value);
364+
case 0x1f801050: // rx/tx data register
365+
PCSX::g_emulator->m_sio1->writeData8(value);
366+
SIO1_LOG("SIO1.DATA write8 %x; ret = %x\n", add & 0xf, value);
367+
break;
368+
case 0x1f801054: // stat register
369+
PCSX::g_emulator->m_sio1->writeStat8(value);
370+
SIO1_LOG("SIO1.STAT write8 %x; ret = %x\n", add & 0xf, value);
371+
break;
372+
case 0x1f801058: // mode register
373+
PCSX::g_emulator->m_sio1->writeMode8(value);
374+
SIO1_LOG("SIO1.MODE write8 %x; ret = %x\n", add & 0xf, value);
375+
break;
376+
case 0x1f80105a: // control register
377+
PCSX::g_emulator->m_sio1->writeCtrl8(value);
378+
SIO1_LOG("SIO1.CTRL write8 %x; ret = %x\n", add & 0xf, value);
379+
break;
380+
case 0x1f80105e: // baudrate register
381+
PCSX::g_emulator->m_sio1->writeBaud8(value);
382+
SIO1_LOG("SIO1.Baud write8 %x; ret = %x\n", add & 0xf, value);
347383
break;
348-
#endif
349384
case 0x1f801800:
350385
PCSX::g_emulator->m_cdrom->write0(value);
351386
break;
@@ -403,28 +438,26 @@ void PCSX::HW::psxHwWrite16(uint32_t add, uint16_t value) {
403438
PCSX::g_emulator->m_sio->writeBaud16(value);
404439
SIO0_LOG("sio write16 %x, %x\n", add & 0xf, value);
405440
return;
406-
#ifdef ENABLE_SIO1API
407-
case 0x1f801050:
408-
SIO1_writeData16(value);
409-
SIO1_LOG("sio1 write16 %x, %x\n", add & 0xf, value);
441+
case 0x1f801050: // rx/tx data register
442+
PCSX::g_emulator->m_sio1->writeData16(value);
443+
SIO1_LOG("SIO1.DATA write16 %x, %x\n", add & 0xf, value);
410444
return;
411-
case 0x1f801054:
412-
SIO1_writeStat16(value);
413-
SIO1_LOG("sio1 write16 %x, %x\n", add & 0xf, value);
445+
case 0x1f801054: // stat register
446+
PCSX::g_emulator->m_sio1->writeStat16(value);
447+
SIO1_LOG("SIO1.STAT write16 %x, %x\n", add & 0xf, value);
414448
return;
415-
case 0x1f801058:
416-
SIO1_writeMode16(value);
417-
SIO1_LOG("sio1 write16 %x, %x\n", add & 0xf, value);
449+
case 0x1f801058: // mode register
450+
PCSX::g_emulator->m_sio1->writeMode16(value);
451+
SIO1_LOG("SIO1.MODE write16 %x, %x\n", add & 0xf, value);
418452
return;
419-
case 0x1f80105a:
420-
SIO1_writeCtrl16(value);
421-
SIO1_LOG("sio1 write16 %x, %x\n", add & 0xf, value);
453+
case 0x1f80105a: // control register
454+
PCSX::g_emulator->m_sio1->writeCtrl16(value);
455+
SIO1_LOG("SIO1.CTRL write16 %x, %x\n", add & 0xf, value);
422456
return;
423-
case 0x1f80105e:
424-
SIO1_writeBaud16(value);
425-
SIO1_LOG("sio1 write16 %x, %x\n", add & 0xf, value);
457+
case 0x1f80105e: // baudrate register
458+
PCSX::g_emulator->m_sio1->writeBaud16(value);
459+
SIO1_LOG("SIO1.BAUD write16 %x, %x\n", add & 0xf, value);
426460
return;
427-
#endif
428461
case 0x1f801070:
429462
PSXHW_LOG("IREG 16bit write %x\n", value);
430463
if (PCSX::g_emulator->settings.get<PCSX::Emulator::SettingSpuIrq>())
@@ -533,12 +566,14 @@ void PCSX::HW::psxHwWrite32(uint32_t add, uint32_t value) {
533566
PCSX::g_emulator->m_sio->write8((unsigned char)((value & 0xff) >> 24));
534567
SIO0_LOG("sio write32 %x\n", value);
535568
return;
536-
#ifdef ENABLE_SIO1API
537569
case 0x1f801050:
538-
SIO1_writeData32(value);
539-
SIO1_LOG("sio1 write32 %x\n", value);
570+
PCSX::g_emulator->m_sio1->writeData32(value);
571+
SIO1_LOG("SIO1.DATA write32 %x\n", value);
572+
return;
573+
case 0x1f801054:
574+
PCSX::g_emulator->m_sio1->writeStat32(value);
575+
SIO1_LOG("SIO1.STAT write32 %x\n", value);
540576
return;
541-
#endif
542577
case 0x1f801060:
543578
PSXHW_LOG("RAM size write %x\n", value);
544579
psxHu32ref(add) = SWAP_LEu32(value);

src/core/psxhw.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "core/psxmem.h"
2525
#include "core/r3000a.h"
2626
#include "core/sio.h"
27+
#include "core/sio1.h"
2728

2829
#define HW_DMA0_MADR (psxHu32ref(0x1080)) // MDEC in DMA
2930
#define HW_DMA0_BCR (psxHu32ref(0x1084))

src/core/r3000a.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ void PCSX::R3000Acpu::psxBranchTest() {
328328
};
329329

330330
checkAndUpdate(PSXINT_SIO, []() { g_emulator->m_sio->interrupt(); });
331+
checkAndUpdate(PSXINT_SIO1, []() { g_emulator->m_sio1->interrupt(); });
331332
checkAndUpdate(PSXINT_CDR, []() { g_emulator->m_cdrom->interrupt(); });
332333
checkAndUpdate(PSXINT_CDREAD, []() { g_emulator->m_cdrom->readInterrupt(); });
333334
checkAndUpdate(PSXINT_GPUDMA, []() { GPU::gpuInterrupt(); });

src/core/r3000a.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ typedef union {
164164

165165
enum {
166166
PSXINT_SIO = 0,
167+
PSXINT_SIO1,
167168
PSXINT_CDR,
168169
PSXINT_CDREAD,
169170
PSXINT_GPUDMA,
@@ -308,7 +309,7 @@ class R3000Acpu {
308309
}
309310

310311
psxRegisters m_psxRegs;
311-
float m_interruptScales[14] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
312+
float m_interruptScales[15] = {1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f};
312313
bool m_shellStarted = false;
313314

314315
virtual void Reset() {

0 commit comments

Comments
 (0)