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