Speed adjusts down for portrait animation

This commit is contained in:
Brendan Robert 2024-04-06 11:59:29 -05:00
parent 25d5f293e8
commit b3ec0df929
4 changed files with 33 additions and 5 deletions

View File

@ -167,7 +167,6 @@ public class LawlessLegends extends Application {
resetEmulator();
configureEmulatorForGame();
bootWatchdog();
// Emulator.getComputer().getCpu().trace=true;
} else {
startListener.unregister();
}

View File

@ -123,5 +123,5 @@ public class Motherboard extends IndependentTimedDevice {
if (accelorationRequestors.remove(requester) && accelorationRequestors.isEmpty()) {
disableTempMaxSpeed();
}
}
}
}

View File

@ -124,6 +124,10 @@ public abstract class TimedDevice extends Device {
}
}
public final boolean isMaxSpeedEnabled() {
return maxspeed;
}
public final boolean isMaxSpeed() {
return forceMaxspeed || maxspeed;
}

View File

@ -19,7 +19,10 @@ import java.util.regex.Pattern;
import jace.Emulator;
import jace.apple2e.VideoDHGR;
import jace.cheat.Cheats;
import jace.core.Computer;
import jace.core.Motherboard;
import jace.core.RAMEvent;
import jace.core.TimedDevice;
import javafx.util.Duration;
/**
@ -117,9 +120,11 @@ public class LawlessHacks extends Cheats {
private Map<Integer, Integer> keyReadAddresses = new TreeMap<>();
long lastKeyStatus = 0;
long lastKnownSpeed = -1;
boolean isCurrentlyMaxSpeed = false;
private void adjustAnimationSpeed(RAMEvent e) {
int pc = Emulator.withComputer(c->c.getCpu().getProgramCounter(), 0);
if (DEBUG) {
int pc = Emulator.withComputer(c->c.getCpu().getProgramCounter(), 0);
keyReadAddresses.put(pc, keyReadAddresses.getOrDefault(pc, 0) + 1);
if ((System.currentTimeMillis() - lastKeyStatus) >= 10000) {
lastKeyStatus = System.currentTimeMillis();
@ -129,8 +134,28 @@ public class LawlessHacks extends Cheats {
});
}
}
// D5FE: Key-in routine used when animating portraits
}
Motherboard m = Emulator.withComputer(Computer::getMotherboard, null);
long currentSpeed = m.getSpeedInHz();
if (pc == 0x0D5FE) {
long slowerSpeed = (long) (TimedDevice.NTSC_1MHZ * 1.5);
// We are waiting for a key in portait mode, slow to 1.5x
if (currentSpeed > slowerSpeed || m.isMaxSpeedEnabled()) {
lastKnownSpeed = currentSpeed;
isCurrentlyMaxSpeed = m.isMaxSpeedEnabled();
m.setSpeedInHz(slowerSpeed);
m.setMaxSpeed(false);
m.cancelSpeedRequest(this);
}
} else {
// We're in some other mode, go back the default speed
if (currentSpeed < lastKnownSpeed || isCurrentlyMaxSpeed) {
m.setSpeedInHz(lastKnownSpeed);
m.setMaxSpeed(isCurrentlyMaxSpeed);
isCurrentlyMaxSpeed = false;
lastKnownSpeed = -1;
}
}
}
public static final String SCORE_NONE = "none";
public static final String SCORE_COMMON = "common";