Skip to content

Commit 001deee

Browse files
authored
Merge pull request #156 from grumpycoders/revert-155-spu-cleanup
Revert "Async SPU register writes."
2 parents aaf3c6c + 62e7209 commit 001deee

File tree

9 files changed

+20
-1635
lines changed

9 files changed

+20
-1635
lines changed

src/core/spu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ class SPUInterface {
6464
virtual bool configure() = 0;
6565
virtual void save(SaveStates::SPU &) = 0;
6666
virtual void load(const SaveStates::SPU &) = 0;
67-
virtual ~SPUInterface() {}
6867

6968
bool m_showDebug = false;
7069
bool m_showCfg = false;
7170

71+
7272
protected:
7373
void scheduleInterrupt();
7474
};

src/spu/dma.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void PCSX::SPU::impl::readDMAMem(uint16_t* pusPSXMem, int iSize) {
4040
if (spuAddr > 0x7ffff) spuAddr = 0; // wrap
4141
}
4242

43-
iSpuAsyncWait.store(0);
43+
iSpuAsyncWait = 0;
4444
}
4545

4646
////////////////////////////////////////////////////////////////////////
@@ -64,7 +64,7 @@ void PCSX::SPU::impl::writeDMAMem(uint16_t* pusPSXMem, int iSize) {
6464
if (spuAddr > 0x7ffff) spuAddr = 0; // wrap
6565
}
6666

67-
iSpuAsyncWait.store(0);
67+
iSpuAsyncWait = 0;
6868
}
6969

7070
////////////////////////////////////////////////////////////////////////

src/spu/interface.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
#include <stdint.h>
2424

2525
#include "json.hpp"
26-
#include "readerwriterqueue.h"
2726

2827
#include "core/decode_xa.h"
29-
#include "core/spu.h"
3028
#include "core/sstate.h"
29+
#include "core/spu.h"
3130
#include "main/settings.h"
3231
#include "spu/adsr.h"
3332
#include "spu/sdlsound.h"
@@ -75,12 +74,6 @@ class impl : public SPUInterface {
7574
}
7675

7776
private:
78-
struct RegisterWrite {
79-
uint32_t registerIndex;
80-
uint16_t value;
81-
};
82-
moodycamel::ReaderWriterQueue<RegisterWrite> m_registersWritesQueue;
83-
void writeRegisterAtomic(uint32_t, uint16_t);
8477
// sound buffer sizes
8578
// 400 ms complete sound buffer
8679
static const size_t SOUNDSIZE = 70560;
@@ -186,7 +179,7 @@ class impl : public SPUInterface {
186179
int lastch = -1; // last channel processed on spu irq in timer mode
187180
int lastns = 0; // last ns pos
188181
int iSecureStart = 0; // secure start counter
189-
std::atomic<int> iSpuAsyncWait;
182+
int iSpuAsyncWait = 0;
190183

191184
// REVERB info and timing vars...
192185

src/spu/registers.cc

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@
6868
////////////////////////////////////////////////////////////////////////
6969

7070
void PCSX::SPU::impl::writeRegister(uint32_t reg, uint16_t val) {
71-
RegisterWrite write;
72-
73-
write.registerIndex = reg;
74-
write.value = val;
75-
76-
m_registersWritesQueue.enqueue(write);
77-
}
78-
79-
void PCSX::SPU::impl::writeRegisterAtomic(uint32_t reg, uint16_t val) {
8071
const uint32_t r = reg & 0xfff;
8172

8273
regArea[(r - 0xc00) >> 1] = val;
@@ -199,7 +190,8 @@ void PCSX::SPU::impl::writeRegisterAtomic(uint32_t reg, uint16_t val) {
199190
//------------------------------------------------//
200191
}
201192

202-
iSpuAsyncWait.store(0);
193+
iSpuAsyncWait = 0;
194+
203195
return;
204196
}
205197

@@ -430,7 +422,7 @@ void PCSX::SPU::impl::writeRegisterAtomic(uint32_t reg, uint16_t val) {
430422
break;
431423
}
432424

433-
iSpuAsyncWait.store(0);
425+
iSpuAsyncWait = 0;
434426
}
435427

436428
////////////////////////////////////////////////////////////////////////
@@ -440,7 +432,7 @@ void PCSX::SPU::impl::writeRegisterAtomic(uint32_t reg, uint16_t val) {
440432
uint16_t PCSX::SPU::impl::readRegister(uint32_t reg) {
441433
const uint32_t r = reg & 0xfff;
442434

443-
iSpuAsyncWait.store(0);
435+
iSpuAsyncWait = 0;
444436

445437
if (r >= 0x0c00 && r < 0x0d80) {
446438
switch (r & 0x0f) {
@@ -563,7 +555,7 @@ void PCSX::SPU::impl::NoiseOn(int start, int end, uint16_t val) // NOISE ON PSX
563555

564556
for (ch = start; ch < end; ch++, val >>= 1) // loop channels
565557
{
566-
s_chan[ch].data.get<Chan::Noise>().value = !!(val & 1); // -> noise on/off
558+
s_chan[ch].data.get<Chan::Noise>().value = !!(val & 1); // -> noise on/off
567559
}
568560
}
569561

@@ -637,8 +629,8 @@ void PCSX::SPU::impl::SetPitch(int ch, uint16_t val) // SET PITCH
637629

638630
s_chan[ch].data.get<Chan::RawPitch>().value = NP;
639631

640-
NP = (44100L * NP) / 4096L; // calc frequency
641-
if (NP < 1) NP = 1; // some security
632+
NP = (44100L * NP) / 4096L; // calc frequency
633+
if (NP < 1) NP = 1; // some security
642634
s_chan[ch].data.get<Chan::ActFreq>().value = NP; // store frequency
643635
}
644636

@@ -652,6 +644,6 @@ void PCSX::SPU::impl::ReverbOn(int start, int end, uint16_t val) // REVERB ON P
652644

653645
for (ch = start; ch < end; ch++, val >>= 1) // loop channels
654646
{
655-
s_chan[ch].data.get<Chan::Reverb>().value = !!(val & 1); // -> reverb on/off
647+
s_chan[ch].data.get<Chan::Reverb>().value = !!(val & 1);// -> reverb on/off
656648
}
657649
}

src/spu/spu.cc

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,6 @@ void PCSX::SPU::impl::MainThread() {
435435

436436
while (!bEndThread) // until we are shutting down
437437
{
438-
{
439-
bool hasWrites;
440-
do {
441-
RegisterWrite write;
442-
hasWrites = m_registersWritesQueue.try_dequeue(write);
443-
if (hasWrites) {
444-
writeRegisterAtomic(write.registerIndex, write.value);
445-
}
446-
} while (hasWrites);
447-
}
448438
//--------------------------------------------------//
449439
// ok, at the beginning we are looking if there is
450440
// enuff free place in the dsound/oss buffer to
@@ -457,8 +447,8 @@ void PCSX::SPU::impl::MainThread() {
457447
{ // (at least one bit 0 ... MAXCHANNEL is set?)
458448
iSecureStart++; // -> set iSecure
459449
if (iSecureStart > 5)
460-
iSecureStart = 0; // (if it is set 5 times - that means on 5 tries a new samples has been
461-
// started - in a row, we will reset it, to give the sound update a chance)
450+
iSecureStart = 0; // (if it is set 5 times - that means on 5 tries a new samples has been started -
451+
// in a row, we will reset it, to give the sound update a chance)
462452
} else
463453
iSecureStart = 0; // 0: no new channel should start
464454

@@ -574,7 +564,7 @@ void PCSX::SPU::impl::MainThread() {
574564

575565
if (settings.get<SPUIRQWait>()) // -> option: wait after irq for main emu
576566
{
577-
iSpuAsyncWait.store(1);
567+
iSpuAsyncWait = 1;
578568
bIRQReturn = 1;
579569
}
580570
}
@@ -610,7 +600,7 @@ void PCSX::SPU::impl::MainThread() {
610600
bIRQReturn = 0;
611601
Uint32 dwWatchTime = SDL_GetTicks() + 2500;
612602

613-
while (iSpuAsyncWait.load() && !bEndThread && SDL_GetTicks() < dwWatchTime) SDL_Delay(1);
603+
while (iSpuAsyncWait && !bEndThread && SDL_GetTicks() < dwWatchTime) SDL_Delay(1);
614604
}
615605

616606
////////////////////////////////////////////
@@ -781,10 +771,10 @@ void PCSX::SPU::impl::MainThread() {
781771
////////////////////////////////////////////////////////////////////////
782772

783773
void PCSX::SPU::impl::async(uint32_t cycle) {
784-
if (iSpuAsyncWait.load()) {
774+
if (iSpuAsyncWait) {
785775
iSpuAsyncWait++;
786-
if (iSpuAsyncWait.load() <= 64) return;
787-
iSpuAsyncWait.store(0);
776+
if (iSpuAsyncWait <= 64) return;
777+
iSpuAsyncWait = 0;
788778
}
789779
}
790780

0 commit comments

Comments
 (0)