Implemented way to hold values from the watch widget

This commit is contained in:
Brendan Robert 2015-08-21 18:37:19 -05:00
parent a069f57a30
commit 2d9ef8b30d
2 changed files with 51 additions and 25 deletions

View File

@ -40,33 +40,39 @@ public abstract class Cheats extends Device {
super(computer);
}
public void bypassCode(int address, int addressEnd) {
public RAMListener bypassCode(int address, int addressEnd) {
int noOperation = MOS65C02.COMMAND.NOP.ordinal();
addCheat(RAMEvent.TYPE.READ, (e) -> {e.setNewValue(noOperation);}, address, addressEnd);
return addCheat(RAMEvent.TYPE.READ, (e) -> e.setNewValue(noOperation), address, addressEnd);
}
public void forceValue(int value, int... address) {
addCheat(RAMEvent.TYPE.READ, (e) -> {e.setNewValue(value);}, address);
public RAMListener forceValue(int value, int... address) {
return addCheat(RAMEvent.TYPE.ANY, (e) -> e.setNewValue(value), address);
}
public void forceValue(int value, boolean auxFlag, int... address) {
addCheat(RAMEvent.TYPE.READ, auxFlag, (e) -> {e.setNewValue(value);}, address);
}
public void addCheat(RAMEvent.TYPE type, RAMEvent.RAMEventHandler handler, int... address) {
if (address.length == 1) {
listeners.add(computer.getMemory().observe(type, address[0], handler));
} else {
listeners.add(computer.getMemory().observe(type, address[0], address[1], handler));
}
public RAMListener forceValue(int value, boolean auxFlag, int... address) {
return addCheat(RAMEvent.TYPE.ANY, auxFlag, (e) -> e.setNewValue(value), address);
}
public void addCheat(RAMEvent.TYPE type, boolean auxFlag, RAMEvent.RAMEventHandler handler, int... address) {
public RAMListener addCheat(RAMEvent.TYPE type, RAMEvent.RAMEventHandler handler, int... address) {
RAMListener listener;
if (address.length == 1) {
listeners.add(computer.getMemory().observe(type, address[0], auxFlag, handler));
listener = computer.getMemory().observe(type, address[0], handler);
} else {
listeners.add(computer.getMemory().observe(type, address[0], address[1], auxFlag, handler));
listener = computer.getMemory().observe(type, address[0], address[1], handler);
}
listeners.add(listener);
return listener;
}
public RAMListener addCheat(RAMEvent.TYPE type, boolean auxFlag, RAMEvent.RAMEventHandler handler, int... address) {
RAMListener listener;
if (address.length == 1) {
listener = computer.getMemory().observe(type, address[0], auxFlag, handler);
} else {
listener = computer.getMemory().observe(type, address[0], address[1], auxFlag, handler);
}
listeners.add(listener);
return listener;
}
@Override
@ -93,7 +99,7 @@ public abstract class Cheats extends Device {
computer.getMemory().removeListener(l);
listeners.remove(l);
}
@Override
public void reconfigure() {
unregisterListeners();

View File

@ -298,8 +298,14 @@ public class MetacheatUI {
StackPane pane = new StackPane();
Tooltip memoryWatchTooltip = new Tooltip();
private void memoryViewClicked(MouseEvent e) {
if (cheatEngine != null) {
Watch currentWatch = (Watch) memoryWatchTooltip.getGraphic();
if (currentWatch != null) {
currentWatch.disconnect();
}
double x = e.getX();
double y = e.getY();
int col = (int) (x / MEMORY_BOX_TOTAL_SIZE);
@ -307,12 +313,7 @@ public class MetacheatUI {
int addr = cheatEngine.getStartAddress() + row * memoryViewColumns + col;
Watch watch = new Watch(addr);
memoryWatchTooltip.setStyle("-fx-background-color:NAVY");
memoryWatchTooltip.onHidingProperty().addListener((prop, oldVal, newVal) -> {
Watch currentWatch = (Watch) memoryWatchTooltip.getGraphic();
if (currentWatch != null) {
currentWatch.disconnect();
}
watch.disconnect();
memoryWatchTooltip.setGraphic(null);
});
@ -352,7 +353,7 @@ public class MetacheatUI {
if (animationTimer == null) {
animationTimer = new ScheduledThreadPoolExecutor(10);
}
if (animationFuture != null) {
animationFuture.cancel(false);
}
@ -440,6 +441,10 @@ public class MetacheatUI {
graph = new Canvas(GRAPH_WIDTH, GRAPH_HEIGHT);
getChildren().add(addrLabel);
getChildren().add(graph);
CheckBox hold = new CheckBox("Hold");
hold.selectedProperty().addListener((prop, oldVal, newVal) -> this.hold(newVal));
getChildren().add(hold);
}
public void redraw() {
@ -470,7 +475,22 @@ public class MetacheatUI {
g.strokeText(String.valueOf(val), GRAPH_WIDTH - 25, GRAPH_HEIGHT - 5);
}
RAMListener holdListener;
private void hold(boolean state) {
if (!state) {
cheatEngine.removeListener(holdListener);
holdListener = null;
} else {
int val = cheatEngine.getMemoryCell(address).value.get() & 0x0ff;
holdListener = cheatEngine.forceValue(val, address);
}
}
public void disconnect() {
if (holdListener != null) {
cheatEngine.removeListener(holdListener);
}
redraw.cancel(false);
}
}