forked from Apple-2-Tools/jace
Fixed goofy reboot logic that was causing the CPU to reset twice for no useful reason. Also added watchdog to application to ensure that CPU steps through FA62 boot routines and resets if not.
This commit is contained in:
parent
6995d610f3
commit
59afe5e72f
@ -73,7 +73,7 @@ public class Emulator {
|
||||
}
|
||||
Configuration.applySettings(settings);
|
||||
// EmulatorUILogic.registerDebugger();
|
||||
computer.coldStart();
|
||||
// computer.coldStart();
|
||||
}
|
||||
|
||||
public static void resizeVideo() {
|
||||
|
@ -5,13 +5,16 @@
|
||||
*/
|
||||
package jace;
|
||||
|
||||
import jace.core.RAMEvent;
|
||||
import jace.core.RAMListener;
|
||||
import jace.core.Utility;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
@ -25,6 +28,24 @@ public class JaceApplication extends Application {
|
||||
Stage primaryStage;
|
||||
JaceUIController controller;
|
||||
|
||||
static boolean romStarted = false;
|
||||
static RAMListener startListener = new RAMListener(RAMEvent.TYPE.EXECUTE, RAMEvent.SCOPE.ADDRESS, RAMEvent.VALUE.ANY) {
|
||||
@Override
|
||||
protected void doConfig() {
|
||||
setScopeStart(0x0FA62);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doEvent(RAMEvent e) {
|
||||
romStarted = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRelevant(RAMEvent e) {
|
||||
return super.isRelevant(e);
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
singleton = this;
|
||||
@ -50,7 +71,7 @@ public class JaceApplication extends Application {
|
||||
Thread.yield();
|
||||
}
|
||||
controller.connectComputer(Emulator.computer);
|
||||
Emulator.computer.warmStart();
|
||||
bootWatchdog();
|
||||
});
|
||||
primaryStage.setOnCloseRequest(event -> {
|
||||
Emulator.computer.deactivate();
|
||||
@ -70,4 +91,22 @@ public class JaceApplication extends Application {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the computer and make sure it runs through the expected rom routine for cold boot
|
||||
*/
|
||||
private void bootWatchdog() {
|
||||
Emulator.computer.getMemory().addListener(startListener);
|
||||
Emulator.computer.coldStart();
|
||||
try {
|
||||
Thread.sleep(250);
|
||||
if (!romStarted) {
|
||||
System.out.println("Boot not detected, performing a cold start");
|
||||
Emulator.computer.coldStart();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(JaceApplication.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
Emulator.computer.getMemory().removeListener(startListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -128,18 +128,16 @@ public class Apple2e extends Computer {
|
||||
public void coldStart() {
|
||||
pause();
|
||||
reinitMotherboard();
|
||||
reboot();
|
||||
//getMemory().dump();
|
||||
for (SoftSwitches s : SoftSwitches.values()) {
|
||||
s.getSwitch().reset();
|
||||
}
|
||||
getMemory().configureActiveMemory();
|
||||
getVideo().configureVideoMode();
|
||||
getCpu().reset();
|
||||
for (Optional<Card> c : getMemory().getAllCards()) {
|
||||
c.ifPresent(Card::reset);
|
||||
}
|
||||
|
||||
reboot();
|
||||
resume();
|
||||
/*
|
||||
getCpu().resume();
|
||||
|
@ -495,7 +495,7 @@ public class MOS65C02 extends CPU {
|
||||
}
|
||||
}
|
||||
|
||||
private static interface CommandProcessor {
|
||||
public static interface CommandProcessor {
|
||||
|
||||
public void processCommand(int address, int value, MODE addressMode, MOS65C02 cpu);
|
||||
}
|
||||
@ -1064,25 +1064,32 @@ public class MOS65C02 extends CPU {
|
||||
int wait = 0;
|
||||
int bytes = 2;
|
||||
int n = op & 0x0f;
|
||||
if (n == 2) {
|
||||
wait = 2;
|
||||
} else if (n == 3 || n == 7 || n == 0x0b || n == 0x0f) {
|
||||
wait = 1;
|
||||
bytes = 1;
|
||||
} else if (n == 4) {
|
||||
bytes = 2;
|
||||
if ((op & 0x0f0) == 0x040) {
|
||||
wait = 3;
|
||||
} else {
|
||||
wait = 4;
|
||||
}
|
||||
} else if (n == 0x0c) {
|
||||
bytes = 3;
|
||||
if ((op & 0x0f0) == 0x050) {
|
||||
wait = 8;
|
||||
} else {
|
||||
wait = 4;
|
||||
}
|
||||
switch (n) {
|
||||
case 2:
|
||||
wait = 2;
|
||||
break;
|
||||
case 3:
|
||||
case 7:
|
||||
case 0x0b:
|
||||
case 0x0f:
|
||||
wait = 1;
|
||||
bytes = 1;
|
||||
break;
|
||||
case 4:
|
||||
bytes = 2;
|
||||
if ((op & 0x0f0) == 0x040) {
|
||||
wait = 3;
|
||||
} else {
|
||||
wait = 4;
|
||||
} break;
|
||||
case 0x0c:
|
||||
bytes = 3;
|
||||
if ((op & 0x0f0) == 0x050) {
|
||||
wait = 8;
|
||||
} else {
|
||||
wait = 4;
|
||||
} break;
|
||||
default:
|
||||
}
|
||||
incrementProgramCounter(bytes);
|
||||
addWaitCycles(wait);
|
||||
@ -1212,7 +1219,6 @@ public class MOS65C02 extends CPU {
|
||||
// Cold/Warm boot procedure
|
||||
@Override
|
||||
public void reset() {
|
||||
boolean restart = computer.pause();
|
||||
pushWord(getProgramCounter());
|
||||
push(getStatus());
|
||||
// STACK = 0x0ff;
|
||||
@ -1227,9 +1233,6 @@ public class MOS65C02 extends CPU {
|
||||
int newPC = getMemory().readWord(RESET_VECTOR, TYPE.READ_DATA, true, false);
|
||||
System.out.println("Reset called, setting PC to (" + Integer.toString(RESET_VECTOR, 16) + ") = " + Integer.toString(newPC, 16));
|
||||
setProgramCounter(newPC);
|
||||
if (restart) {
|
||||
computer.resume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user