Remove Nashorn usage, fix configuration swap for video/memory so it works correctly.

This commit is contained in:
Brendan Robert 2024-03-09 10:49:34 -06:00
parent 264f317c90
commit f0b87d07ec
6 changed files with 18 additions and 46 deletions

View File

@ -200,7 +200,12 @@ public class Apple2e extends Computer {
}
return getDesiredMemoryConfiguration().isInstance((RAM128k) getMemory());
}
private boolean isVideoConfigurationCorrect() {
VideoImpls videoSelection = videoRenderer.getValue();
return videoSelection != null && videoSelection.isInstance(getVideo());
}
@Override
protected RAM createMemory() {
return getDesiredMemoryConfiguration().create();
@ -291,7 +296,7 @@ public class Apple2e extends Computer {
clock = null;
}
if (videoRenderer.getValue() != null && !videoRenderer.getValue().isInstance(getVideo())) {
if (!isVideoConfigurationCorrect()) {
boolean resumeVideo = false;
if (getVideo() != null) {
resumeVideo = getVideo().suspend();

View File

@ -71,7 +71,7 @@ abstract public class RAM128k extends RAM {
@Override
public boolean isInstance(RAM128k card) {
return card != null && clazz.isInstance(card);
return card != null && clazz.equals(card.getClass());
}
}

View File

@ -1,7 +1,5 @@
package jace.cheat;
import javax.script.ScriptException;
import jace.core.RAMEvent;
import jace.core.RAMListener;
import javafx.beans.property.BooleanProperty;
@ -25,20 +23,20 @@ public class DynamicCheat extends RAMListener {
String cheatName;
Callback<RAMEvent, Integer> expressionCallback;
public DynamicCheat(String cheatName, int address, String expr) {
public DynamicCheat(String cheatName, int address, int holdValue) {
super(cheatName, RAMEvent.TYPE.ANY, RAMEvent.SCOPE.ADDRESS, RAMEvent.VALUE.ANY);
id = (int) (Math.random() * 10000000);
addr = new SimpleIntegerProperty(address);
expression = new SimpleStringProperty(expr);
expression = new SimpleStringProperty(String.valueOf(holdValue));
isHold = true;
active = new SimpleBooleanProperty(false);
name = new SimpleStringProperty("Untitled");
expression.addListener((param, oldValue, newValue) -> {
expressionCallback = parseExpression(newValue);
});
expressionCallback = parseExpression(expr);
expressionCallback = (RAMEvent e) -> holdValue;
doConfig();
}
boolean isHold = false;
@Override
protected void doConfig() {
if (addr != null) {
@ -75,29 +73,6 @@ public class DynamicCheat extends RAMListener {
return expression;
}
private Callback<RAMEvent, Integer> parseExpression(String expr) {
String functionName = "processCheat" + id;
String functionBody = "function " + functionName + "(old,val){" + (expr.contains("return") ? expr : "return " + expr) + "}";
try {
MetaCheat.NASHORN_ENGINE.eval(functionBody);
return (RAMEvent e) -> {
try {
Object result = MetaCheat.NASHORN_INVOCABLE.invokeFunction(functionName, e.getOldValue(), e.getNewValue());
if (result instanceof Number) {
return ((Number) result).intValue();
} else {
System.err.println("Not able to handle non-numeric return value: " + result.getClass());
return null;
}
} catch (ScriptException | NoSuchMethodException ex) {
return null;
}
};
} catch (ScriptException ex) {
return null;
}
}
public static String escape(String in) {
return in.replaceAll(";", "~~").replaceAll("\n","\\n");
}
@ -120,7 +95,7 @@ public class DynamicCheat extends RAMListener {
Integer addr = Integer.parseInt(parts[2].substring(1), 16);
String expr = unescape(parts[3]);
DynamicCheat out = new DynamicCheat(cheatName, addr, expr);
DynamicCheat out = new DynamicCheat(cheatName, addr, Integer.parseInt(expr));
out.name.set(name);
return out;
}

View File

@ -11,10 +11,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import jace.Emulator;
import jace.LawlessLegends;
import jace.core.CPU;
@ -33,10 +29,6 @@ import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class MetaCheat extends Cheats {
static final ScriptEngine NASHORN_ENGINE = new ScriptEngineManager().getEngineByName("nashorn");
static Invocable NASHORN_INVOCABLE = (Invocable) NASHORN_ENGINE;
public enum SearchType {
VALUE, TEXT, CHANGE
}

View File

@ -35,6 +35,6 @@ public enum VideoImpls implements DeviceEnum<Video> {
@Override
public boolean isInstance(Video video) {
return clazz.isInstance(video);
return video != null && clazz.equals(video.getClass());
}
}

View File

@ -157,7 +157,7 @@ public class MetacheatUI {
@FXML
void addCheat(ActionEvent event) {
cheatEngine.addCheat(new DynamicCheat(event.toString(), 0, "?"));
cheatEngine.addCheat(new DynamicCheat(event.toString(), 0, 0));
}
@FXML
@ -562,7 +562,7 @@ public class MetacheatUI {
}
private void addCheat(String name, int addr, int val) {
cheatEngine.addCheat(new DynamicCheat(name, addr, String.valueOf(val)));
cheatEngine.addCheat(new DynamicCheat(name, addr, val));
}
int currentlyInspecting = 0;