Skip to content

Commit

Permalink
fc: restore per-device co-threads
Browse files Browse the repository at this point in the history
(Reverts 265ba00)
  • Loading branch information
LukeUsher committed Apr 11, 2024
1 parent 66ecd2e commit 5104b34
Show file tree
Hide file tree
Showing 28 changed files with 48 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ares/fc/apu/apu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ auto APU::main() -> void {

stream->frame(sclamp<16>(output) / 32768.0);

tick();
}

auto APU::tick() -> void {
Thread::step(rate());
Thread::synchronize(cpu);
}
Expand All @@ -73,6 +77,8 @@ auto APU::setIRQ() -> void {
}

auto APU::power(bool reset) -> void {
Thread::create(system.frequency(), {&APU::main, this});

pulse1.power(reset);
pulse2.power(reset);
triangle.power(reset);
Expand Down
3 changes: 2 additions & 1 deletion ares/fc/apu/apu.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
struct APU: Thread {
struct APU : Thread {
Node::Object node;
Node::Audio::Stream stream;

Expand All @@ -9,6 +9,7 @@ struct APU: Thread {
auto unload() -> void;

auto main() -> void;
auto tick() -> void;
auto setIRQ() -> void;

auto power(bool reset) -> void;
Expand Down
1 change: 1 addition & 0 deletions ares/fc/apu/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
auto APU::serialize(serializer& s) -> void {
Thread::serialize(s);
s(pulse1);
s(pulse2);
s(triangle);
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/bandai-fcg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct BandaiFCG : Interface {
irqEnable = false;
}
}
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/bandai-lz93d50.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct BandaiLZ93D50 : Interface {
irqEnable = false;
}
}
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
10 changes: 10 additions & 0 deletions ares/fc/cartridge/board/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,16 @@ auto Interface::create(string board) -> Interface* {
return p;
}

auto Interface::main() -> void {
cartridge.step(cartridge.rate() * 4095);
tick();
}

auto Interface::tick() -> void {
cartridge.step(cartridge.rate());
cartridge.synchronize(cpu);
}

auto Interface::load(Memory::Readable<n8>& memory, string name) -> bool {
if(auto fp = pak->read(name)) {
memory.allocate(fp->size(), 0xff);
Expand Down
3 changes: 2 additions & 1 deletion ares/fc/cartridge/board/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct Interface {
virtual auto save() -> void {}
virtual auto unload() -> void {}

virtual auto main() -> void {}
virtual auto main() -> void;
virtual auto tick() -> void;

virtual auto readPRG(n32 address, n8 data) -> n8 { return data; }
virtual auto writePRG(n32 address, n8 data) -> void {}
Expand Down
2 changes: 2 additions & 0 deletions ares/fc/cartridge/board/hvc-exrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ struct HVC_ExROM : Interface { //MMC5
stream->frame(sclamp<16>(-output) / 32768.0);

cpu.irqLine((irqLine & irqEnable) || (pcm.irqLine & pcm.irqEnable) || timerLine);

tick();
}

auto scanline() -> void {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/hvc-fmr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct HVC_FMR : Interface {

auto main() -> void override {
fds.main();
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/hvc-hkrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct HVC_HKROM : Interface { //MMC6
auto main() -> void override {
if(irqDelay) irqDelay--;
cpu.irqLine(irqLine);
tick();
}

auto irqTest(n32 address) -> void {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/hvc-sxrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct HVC_SxROM : Interface { //MMC1

auto main() -> void override {
if(writeDelay) writeDelay--;
tick();
}

auto addressProgramROM(n32 address) -> n32 {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/hvc-txrom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ struct HVC_TxROM : Interface { //MMC3
auto main() -> void override {
if(irqDelay) irqDelay--;
cpu.irqLine(irqLine);
tick();
}

auto irqTest(n16 address) -> void {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/irem-h3001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct IremH3001 : Interface {
if(irqCounter && --irqCounter == 0) irqLine = 1;
}
cpu.irqLine(irqLine);
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/jaleco-jf23.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct JalecoJF23 : Interface {
}
}
cpu.irqLine(irqLine);
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/konami-vrc3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct KonamiVRC3 : Interface {
}
}
cpu.irqLine(irqLine);
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/konami-vrc4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct KonamiVRC4 : Interface {
}
}
cpu.irqLine(irqLine);
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/konami-vrc5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct KonamiVRC5 : Interface {
cpu.irqLine(1);
}
}
tick();
}

//converts JIS X 0208 codepoint to CIRAM tile# + QTRAM bank#
Expand Down
2 changes: 2 additions & 0 deletions ares/fc/cartridge/board/konami-vrc6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ struct KonamiVRC6 : Interface {
sawtooth.clock();
f64 output = (pulse1.output + pulse2.output + sawtooth.output) / 61.0 * 0.5;
stream->frame(-output);

tick();
}

auto addressPRG(n32 address) const -> n32 {
Expand Down
2 changes: 2 additions & 0 deletions ares/fc/cartridge/board/konami-vrc7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ struct KonamiVRC7 : Interface {
if(!disableFM) sample = ym2413.clock();
stream->frame(sample);
}

tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
2 changes: 2 additions & 0 deletions ares/fc/cartridge/board/namco-163.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ struct Namco163 : Interface {
double output = clockSound();
stream->frame(output / 255.0 * 0.5);
}

tick();
}

auto clockSound() -> double {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/sunsoft-3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct Sunsoft3 : Interface {
irqEnable = 0;
cpu.irqLine(1);
}
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/sunsoft-4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct Sunsoft4 : Interface {

auto main() -> void override {
if(optionTimer) optionTimer--;
tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
2 changes: 2 additions & 0 deletions ares/fc/cartridge/board/sunsoft-5b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct Sunsoft5B : Interface {
output += volume[channels[2]];
stream->frame(sclamp<16>(output * 1.5 * 32768.0) / 32768.0);
}

tick();
}

auto readPRG(n32 address, n8 data) -> n8 override {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/board/taito-tc0690.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct TaitoTC0690 : Interface {
if(irqDelay) irqDelay--;
if(irqLineDelay && --irqLineDelay == 0) irqLine = 1;
cpu.irqLine(irqLine);
tick();
}

auto irqTest(n16 address) -> void {
Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/cartridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ auto Cartridge::save() -> void {
}

auto Cartridge::power() -> void {
Thread::create(system.frequency(), {&Cartridge::main, this});
board->power();
}

Expand Down
1 change: 1 addition & 0 deletions ares/fc/cartridge/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
auto Cartridge::serialize(serializer& s) -> void {
Thread::serialize(s);
if(board) s(*board);
}
1 change: 0 additions & 1 deletion ares/fc/cpu/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ auto CPU::main() -> void {

auto CPU::step(u32 clocks) -> void {
assert(clocks == rate());
cartridge.main();
Thread::step(clocks);
Thread::synchronize();
}
Expand Down
2 changes: 1 addition & 1 deletion ares/fc/system/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const string SerializerVersion = "v139";
static const string SerializerVersion = "v140";

auto System::serialize(bool synchronize) -> serializer {
if(synchronize) scheduler.enter(Scheduler::Mode::Synchronize);
Expand Down

0 comments on commit 5104b34

Please sign in to comment.