Skip to content

Commit

Permalink
ym2612: fix timer behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
TascoDLX authored and LukeUsher committed Feb 17, 2025
1 parent a9f9fd9 commit e48b208
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
10 changes: 3 additions & 7 deletions ares/component/audio/ym2612/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,14 @@ auto YM2612::writeData(n8 data) -> void {
//timer B period
case 0x026: {
timerB.period.bit(0,7) = data.bit(0,7);
// Not sure if this is the right place for it, but...
// handle a specific use case to reset the subticks on timer B
if(!timerB.enable) timerB.divider = 0;
break;
}

//timer control
case 0x027: {
//reload period on 0->1 transition
if(!timerA.enable && data.bit(0)) timerA.counter = timerA.period;
if(!timerB.enable && data.bit(1)) {
timerB.counter = timerB.period;
timerB.divider = 0;
}

timerA.enable = data.bit(0);
timerB.enable = data.bit(1);
timerA.irq = data.bit(2);
Expand Down
2 changes: 2 additions & 0 deletions ares/component/audio/ym2612/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ auto YM2612::serialize(serializer& s) -> void {
s(envelope.divider);

s(timerA.enable);
s(timerA.enableLatch);
s(timerA.irq);
s(timerA.line);
s(timerA.period);
s(timerA.counter);

s(timerB.enable);
s(timerB.enableLatch);
s(timerB.irq);
s(timerB.line);
s(timerB.period);
Expand Down
21 changes: 10 additions & 11 deletions ares/component/audio/ym2612/timer.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
auto YM2612::TimerA::run() -> void {
if(!enable) return;
if(++counter) return;

counter = period;
line |= irq;
if(!++counter)
line |= irq & enableLatch;
if(enableLatch < enable || !counter)
counter = period;
enableLatch = enable;
}

auto YM2612::TimerB::run() -> void {
if(!enable) return;
if(++divider) return;
if(++counter) return;

counter = period;
line |= irq;
if(!++divider && !++counter)
line |= irq & enableLatch;
if(enableLatch < enable || !counter && !divider)
counter = period; // do not reset divider on reenable
enableLatch = enable;
}
2 changes: 2 additions & 0 deletions ares/component/audio/ym2612/ym2612.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct YM2612 {
auto run() -> void;

n1 enable = 0;
n1 enableLatch = 0;
n1 irq = 0;
n1 line = 0;
n10 period = 0;
Expand All @@ -56,6 +57,7 @@ struct YM2612 {
auto run() -> void;

n1 enable = 0;
n1 enableLatch = 0;
n1 irq = 0;
n1 line = 0;
n8 period = 0;
Expand Down
2 changes: 1 addition & 1 deletion ares/md/system/serialization.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
static const string SerializerVersion = "v142";
static const string SerializerVersion = "v142.1";

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

0 comments on commit e48b208

Please sign in to comment.