Better handling of zero period values, still silencing if period <= 1 though

This commit is contained in:
Badvision 2024-08-27 23:46:42 -05:00
parent 14b0cfd967
commit dfc2cbae4e
2 changed files with 8 additions and 9 deletions

View File

@ -162,10 +162,10 @@ public class CardMockingboard extends Card {
if (e.getType().isRead()) { if (e.getType().isRead()) {
int val = controller.readRegister(register & 0x0f); int val = controller.readRegister(register & 0x0f);
e.setNewValue(val); e.setNewValue(val);
if (DEBUG) System.out.println("Chip " + chip + " Read "+Integer.toHexString(register & 0x0f)+" == "+val); // if (DEBUG) System.out.println("Chip " + chip + " Read "+Integer.toHexString(register & 0x0f)+" == "+val);
} else { } else {
controller.writeRegister(register & 0x0f, e.getNewValue()); controller.writeRegister(register & 0x0f, e.getNewValue());
if (DEBUG) System.out.println("Chip " + chip + " Write "+Integer.toHexString(register & 0x0f)+" == "+e.getNewValue()); // if (DEBUG) System.out.println("Chip " + chip + " Write "+Integer.toHexString(register & 0x0f)+" == "+e.getNewValue());
} }
// Any firmware access will reset the idle counter and wake up the card, this allows the timers to start running again // Any firmware access will reset the idle counter and wake up the card, this allows the timers to start running again
// Games such as "Skyfox" use the timer to detect if the card is present. // Games such as "Skyfox" use the timer to detect if the card is present.

View File

@ -51,7 +51,7 @@ public class TimedGenerator {
} }
public void setPeriod(int _period) { public void setPeriod(int _period) {
period = _period > 0 ? _period : 1; period = _period;
clocksPerPeriod = (period * stepsPerCycle()); clocksPerPeriod = (period * stepsPerCycle());
// set counter back... necessary? // set counter back... necessary?
// while (clocksPerPeriod > period) { // while (clocksPerPeriod > period) {
@ -60,13 +60,12 @@ public class TimedGenerator {
} }
protected int updateCounter() { protected int updateCounter() {
counter += cyclesPerSample; // Period == 0 means the generator is off
int numStateChanges = 0; if (period <= 1 || clocksPerPeriod <= 1) {
// Skyfox and Genius use a period value of 001 for silence instead of setting volume to 0.
if (period == 1) {
counter = 0;
return 0; return 0;
} }
counter += cyclesPerSample;
int numStateChanges = 0;
while (counter >= clocksPerPeriod) { while (counter >= clocksPerPeriod) {
counter -= clocksPerPeriod; counter -= clocksPerPeriod;
numStateChanges++; numStateChanges++;
@ -76,6 +75,6 @@ public class TimedGenerator {
public void reset() { public void reset() {
counter = 0; counter = 0;
period = 1; period = 0;
} }
} }