More minor bugfixes (vbl wait might be what causes hang on startup!)

This commit is contained in:
Brendan Robert 2024-03-14 00:06:54 -05:00
parent 4031aecfc7
commit d73ebd5765
8 changed files with 39 additions and 29 deletions

View File

@ -8,14 +8,12 @@ import java.util.logging.Logger;
import jace.apple2e.MOS65C02; import jace.apple2e.MOS65C02;
import jace.apple2e.RAM128k; import jace.apple2e.RAM128k;
import jace.apple2e.VideoNTSC; import jace.apple2e.VideoNTSC;
import jace.cheat.Cheats.Cheat;
import jace.config.Configuration; import jace.config.Configuration;
import jace.core.Computer; import jace.core.Computer;
import jace.core.RAMEvent; import jace.core.RAMEvent;
import jace.core.RAMListener; import jace.core.RAMListener;
import jace.core.Utility; import jace.core.Utility;
import jace.hardware.Cards; import jace.hardware.Cards;
import jace.hardware.VideoImpls;
import jace.lawless.LawlessComputer; import jace.lawless.LawlessComputer;
import jace.lawless.LawlessImageTool; import jace.lawless.LawlessImageTool;
import jace.ui.MetacheatUI; import jace.ui.MetacheatUI;
@ -126,6 +124,16 @@ public class LawlessLegends extends Application {
return cheatController; return cheatController;
} }
public void closeMetacheat() {
if (cheatStage != null) {
cheatStage.close();
}
if (cheatController != null) {
cheatController.detach();
cheatController = null;
}
}
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
@ -150,6 +158,7 @@ public class LawlessLegends extends Application {
romStarted.set(false); romStarted.set(false);
c.coldStart(); c.coldStart();
try { try {
// Logger.getLogger(getClass().getName()).log(Level.WARNING, "Watchdog: waiting " + watchdogDelay + "ms for boot to start.");
Thread.sleep(watchdogDelay); Thread.sleep(watchdogDelay);
watchdogDelay = 500; watchdogDelay = 500;
if (!romStarted.get() || !c.isRunning() || c.getCpu().getProgramCounter() == MOS65C02.FASTBOOT || c.getCpu().getProgramCounter() == 0) { if (!romStarted.get() || !c.isRunning() || c.getCpu().getProgramCounter() == MOS65C02.FASTBOOT || c.getCpu().getProgramCounter() == 0) {
@ -185,16 +194,13 @@ public class LawlessLegends extends Application {
c.joy2enabled = false; c.joy2enabled = false;
c.enableStateManager = false; c.enableStateManager = false;
c.ramCard.setValue(RAM128k.RamCards.CardRamworks); c.ramCard.setValue(RAM128k.RamCards.CardRamworks);
c.videoRenderer.setValue(VideoImpls.Lawless);
if (c.PRODUCTION_MODE) { if (c.PRODUCTION_MODE) {
c.card7.setValue(Cards.MassStorage); c.card7.setValue(Cards.MassStorage);
c.card6.setValue(Cards.DiskIIDrive); c.card6.setValue(Cards.DiskIIDrive);
c.card5.setValue(Cards.RamFactor); c.card5.setValue(Cards.RamFactor);
c.card4.setValue(null); c.card4.setValue(null);
c.card2.setValue(null); c.card2.setValue(null);
c.getMemory().writeWord(0x03f0, 0x0c700, false, false);
} }
c.cheatEngine.setValue(Cheat.LawlessHacks);
Configuration.buildTree(); Configuration.buildTree();
c.reconfigure(); c.reconfigure();
VideoNTSC.setVideoMode(VideoNTSC.VideoMode.TextFriendly, false); VideoNTSC.setVideoMode(VideoNTSC.VideoMode.TextFriendly, false);

View File

@ -83,7 +83,7 @@ public class Apple2e extends Computer {
@ConfigurableField(name = "Helpful hints", shortName = "hints") @ConfigurableField(name = "Helpful hints", shortName = "hints")
public boolean enableHints = true; public boolean enableHints = true;
@ConfigurableField(name = "Renderer", shortName = "video", description = "Video rendering implementation") @ConfigurableField(name = "Renderer", shortName = "video", description = "Video rendering implementation")
public DeviceSelection<VideoImpls> videoRenderer = new DeviceSelection<>(VideoImpls.class, VideoImpls.Lawless, false); public DeviceSelection<VideoImpls> videoRenderer = new DeviceSelection<>(VideoImpls.class, PRODUCTION_MODE ? VideoImpls.Lawless : VideoImpls.NTSC, false);
@ConfigurableField(name = "Aux Ram", shortName = "ram", description = "Aux ram card") @ConfigurableField(name = "Aux Ram", shortName = "ram", description = "Aux ram card")
public DeviceSelection<RAM128k.RamCards> ramCard = new DeviceSelection<>(RAM128k.RamCards.class, RAM128k.RamCards.CardRamworks, false); public DeviceSelection<RAM128k.RamCards> ramCard = new DeviceSelection<>(RAM128k.RamCards.class, RAM128k.RamCards.CardRamworks, false);
@ConfigurableField(name = "Joystick 1 Enabled", shortName = "joy1", description = "If unchecked, then there is no joystick support.", enablesDevice = true) @ConfigurableField(name = "Joystick 1 Enabled", shortName = "joy1", description = "If unchecked, then there is no joystick support.", enablesDevice = true)
@ -324,19 +324,15 @@ public class Apple2e extends Computer {
activeCheatEngine = null; activeCheatEngine = null;
} }
} else { } else {
boolean startCheats = true; if (activeCheatEngine != null && !cheatEngine.getValue().isInstance(activeCheatEngine)) {
if (activeCheatEngine != null) { activeCheatEngine.detach();
if (cheatEngine.getValue().isInstance(activeCheatEngine)) { activeCheatEngine.suspend();
startCheats = false; activeCheatEngine = null;
newDeviceSet.add(activeCheatEngine);
} else {
activeCheatEngine.detach();
activeCheatEngine.suspend();
activeCheatEngine = null;
}
} }
if (startCheats && cheatEngine.getValue() != null) { if (activeCheatEngine == null && cheatEngine.getValue() != null) {
activeCheatEngine = cheatEngine.getValue().create(); activeCheatEngine = cheatEngine.getValue().create();
}
if (activeCheatEngine != null) {
newDeviceSet.add(activeCheatEngine); newDeviceSet.add(activeCheatEngine);
} }
} }

View File

@ -63,7 +63,10 @@ public abstract class Cheats extends Device {
@Override @Override
public boolean isInstance(Cheats cheat) { public boolean isInstance(Cheats cheat) {
return clazz.isInstance(cheat); if (cheat == null) {
return false;
}
return clazz == cheat.getClass();
} }
} }

View File

@ -158,7 +158,7 @@ public class MetaCheat extends Cheats {
@Override @Override
public void detach() { public void detach() {
super.detach(); super.detach();
ui.detach(); LawlessLegends.getApplication().closeMetacheat();
} }
@Override @Override

View File

@ -396,9 +396,9 @@ public class Utility {
String osName = System.getProperty("os.name").toLowerCase(); String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) { if (osName.contains("windows")) {
return OS.Windows; return OS.Windows;
} else if (osName.contains("Linux")) { } else if (osName.contains("linux")) {
return OS.Linux; return OS.Linux;
} else if (osName.contains("Mac")) { } else if (osName.contains("mac")) {
return OS.Mac; return OS.Mac;
} else { } else {
System.out.println("Unknown %s".formatted(osName)); System.out.println("Unknown %s".formatted(osName));

View File

@ -38,8 +38,6 @@ public class LawlessComputer extends Apple2e {
if (PRODUCTION_MODE) { if (PRODUCTION_MODE) {
this.cheatEngine.setValue(Cheats.Cheat.LawlessHacks); this.cheatEngine.setValue(Cheats.Cheat.LawlessHacks);
} }
// this.activeCheatEngine = new LawlessHacks(this);
// this.activeCheatEngine.attach();
blankTextPage1(); blankTextPage1();
reconfigure(); reconfigure();
} }
@ -161,7 +159,7 @@ public class LawlessComputer extends Apple2e {
} }
public void waitForVBL(int count) throws InterruptedException { public void waitForVBL(int count) throws InterruptedException {
if (getVideo() == null || !getVideo().isRunning()) { if (getVideo() == null || !getVideo().isRunning() || !getMotherboard().isRunning()) {
return; return;
} }
Semaphore s = new Semaphore(0); Semaphore s = new Semaphore(0);

View File

@ -47,9 +47,7 @@ public class LawlessHacks extends Cheats {
// Observe graphics changes // Observe graphics changes
addCheat("Lawless Text Speedup", RAMEvent.TYPE.EXECUTE, this::fastText, 0x0ee00, 0x0ee00 + 0x0f00); addCheat("Lawless Text Speedup", RAMEvent.TYPE.EXECUTE, this::fastText, 0x0ee00, 0x0ee00 + 0x0f00);
addCheat("Lawless Text Enhancement", RAMEvent.TYPE.WRITE, this::enhanceText, 0x02000, 0x03fff); addCheat("Lawless Text Enhancement", RAMEvent.TYPE.WRITE, this::enhanceText, 0x02000, 0x03fff);
addCheat("Lawless Legends Music Commands", RAMEvent.TYPE.WRITE, (e) -> { addCheat("Lawless Legends Music Commands", RAMEvent.TYPE.WRITE, (e) -> playSound(e.getNewValue()), SFX_TRIGGER);
playSound(e.getNewValue());
}, SFX_TRIGGER);
} }
@Override @Override
@ -61,6 +59,13 @@ public class LawlessHacks extends Cheats {
public void tick() { public void tick() {
} }
@Override
public void detach() {
super.detach();
stopMusic();
Emulator.withComputer((c->c.getMotherboard().cancelSpeedRequest(this)));
}
// Speed up text rendering // Speed up text rendering
private void fastText(RAMEvent e) { private void fastText(RAMEvent e) {
if (e.isMainMemory() && e.getOldValue() != 0x060) { if (e.isMainMemory() && e.getOldValue() != 0x060) {

View File

@ -527,8 +527,10 @@ public class MetacheatUI {
searchValueField.textProperty().unbind(); searchValueField.textProperty().unbind();
searchChangeByField.textProperty().unbind(); searchChangeByField.textProperty().unbind();
memoryWatchTooltip.hide(); memoryWatchTooltip.hide();
animationTimer.shutdown(); if (animationTimer != null) {
animationTimer = null; animationTimer.shutdown();
animationTimer = null;
}
cheatEngine = null; cheatEngine = null;
} }