Skip to content

Commit

Permalink
Issue #22: Minor progress hooking up state manager; still doesn't wor…
Browse files Browse the repository at this point in the history
…k and crashes the emulator when triggered. :/
  • Loading branch information
badvision committed Feb 23, 2016
1 parent 3f11562 commit 6515c90
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/main/java/jace/Emulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class Emulator {
* @param args
*/
public Emulator(List<String> args) {
instance = this;
computer = new Apple2e();
Configuration.buildTree();
Configuration.loadSettings();
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/jace/core/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
* Generic abstraction of a 560x192 video output device which renders 40 columns
* per scanline. This also triggers VBL and updates the physical screen.
* Subclasses are used to manage actual rendering via ScreenWriter
* implementations.
* Created on November 10, 2006, 4:29 PM
* implementations. Created on November 10, 2006, 4:29 PM
*
* @author Brendan Robert (BLuRry) [email protected]
* @author Brendan Robert (BLuRry) [email protected]
*/
@Stateful
public abstract class Video extends Device {
Expand Down Expand Up @@ -90,6 +89,7 @@ public abstract class Video extends Device {

/**
* Creates a new instance of Video
*
* @param computer
*/
public Video(Computer computer) {
Expand All @@ -99,21 +99,21 @@ public Video(Computer computer) {
visible = new WritableImage(560, 192);
vPeriod = 0;
hPeriod = 0;
forceRefresh();
_forceRefresh();
}

public void setWidth(int w) {
width = w;
}

public int getWidth() {
return width;
}

public void setHeight(int h) {
height = h;
}

public int getHeight() {
return height;
}
Expand All @@ -136,6 +136,7 @@ public void setCurrentWriter(VideoWriter currentWriter) {
visible.getPixelWriter().setPixels(0, 0, 560, 192, video.getPixelReader(), 0, 0);
}
};

public void redraw() {
screenDirty = false;
javafx.application.Platform.runLater(redrawScreen);
Expand Down Expand Up @@ -209,8 +210,8 @@ public void tick() {
abstract public void configureVideoMode();

protected static int byteDoubler(byte b) {
int num =
// Skip hi-bit because it's not used in display
int num
= // Skip hi-bit because it's not used in display
// ((b&0x080)<<7) |
((b & 0x040) << 6)
| ((b & 0x020) << 5)
Expand Down Expand Up @@ -271,18 +272,22 @@ private void setFloatingBus(byte floatingBus) {
}

@InvokableAction(name = "Refresh screen",
category = "display",
description = "Marks screen contents as changed, forcing full screen redraw",
alternatives = "redraw",
defaultKeyMapping = {"ctrl+shift+r"})
category = "display",
description = "Marks screen contents as changed, forcing full screen redraw",
alternatives = "redraw",
defaultKeyMapping = {"ctrl+shift+r"})
public static final void forceRefresh() {
if (Emulator.computer != null && Emulator.computer.video != null) {
Emulator.computer.video.lineDirty = true;
Emulator.computer.video.screenDirty = true;
Emulator.computer.video.forceRedrawRowCount = APPLE_SCREEN_LINES + 1;
Emulator.computer.video._forceRefresh();
}
}

private void _forceRefresh() {
lineDirty = true;
screenDirty = true;
forceRedrawRowCount = APPLE_SCREEN_LINES + 1;
}

@Override
public String getShortName() {
return "vid";
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/jace/state/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
import javafx.scene.image.Image;

Expand Down Expand Up @@ -78,7 +79,7 @@ public void addState(State newState) {
}

public void apply() {
Set<ObjectGraphNode> applied = new HashSet<>();
Set<ObjectGraphNode> applied = new LinkedHashSet<>();
State current = this;
while (current != null) {
for (StateValue val : current.values()) {
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/jace/state/StateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
import jace.Emulator;
import jace.apple2e.SoftSwitches;
import jace.config.ConfigurableField;
import jace.config.InvokableAction;
import jace.config.Reconfigurable;
import jace.core.Computer;
import jace.core.PagedMemory;
import jace.core.Video;
import java.awt.image.BufferedImage;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -37,6 +40,7 @@
import java.util.logging.Logger;
import javafx.scene.image.Image;
import javafx.scene.image.WritableImage;
import javafx.scene.input.KeyCode;

/**
*
Expand Down Expand Up @@ -64,12 +68,13 @@ public static StateManager getInstance(Computer computer) {
private ObjectGraphNode<BufferedImage> imageGraphNode;

Computer computer;

private StateManager(Computer computer) {
this.computer = computer;
}

private void buildStateMap() {
allStateVariables = new HashSet<>();
allStateVariables = new LinkedHashSet<>();
objectLookup = new WeakHashMap<>();
ObjectGraphNode emulator = new ObjectGraphNode(Emulator.instance);
emulator.name = "Emulator";
Expand Down Expand Up @@ -295,7 +300,7 @@ public void invalidate() {

public void captureState() {
// If the state graph is invalidated it means we have to abandon all
// previously captured states. This helps ensure that rewinding will
// previously captured states. This helps ensure that rewinding will
// not result in an unintended or invalid state.
if (!isValid) {
alphaState = null;
Expand Down Expand Up @@ -402,6 +407,17 @@ public void notifyVBLActive() {
captureState();
}

@InvokableAction(
name = "Rewind",
alternatives = "Timewarp",
description = "Go back 1 second",
defaultKeyMapping = {"ctrl+shift+Open Bracket"}
)
public static void beKindRewind() {
StateManager manager = getInstance(Emulator.computer);
new Thread(()->manager.rewind(60 / manager.captureFrequency)).start();
}

public void rewind(int numStates) {
boolean resume = computer.pause();
State state = alphaState.tail;
Expand All @@ -412,7 +428,7 @@ public void rewind(int numStates) {
state.apply();
alphaState.tail = state;
state.nextState = null;
computer.getVideo().forceRefresh();
Video.forceRefresh();
System.gc();
if (resume) {
computer.resume();
Expand Down

0 comments on commit 6515c90

Please sign in to comment.