|
@@ -0,0 +1,682 @@
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+package de.mcs.tools.sps.emulator.emulator.holtek;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import de.mcs.tools.sps.emulator.EmulatorInput;
|
|
|
+import de.mcs.tools.sps.emulator.EmulatorInternals;
|
|
|
+import de.mcs.tools.sps.emulator.EmulatorOutput;
|
|
|
+import de.mcs.tools.sps.emulator.SPSCommand;
|
|
|
+import de.mcs.tools.sps.emulator.SPSCommandData;
|
|
|
+import de.mcs.tools.sps.emulator.SPSCommandDataImpl;
|
|
|
+import de.mcs.tools.sps.emulator.SPSCommandImpl;
|
|
|
+import de.mcs.tools.sps.emulator.SPSEmulator;
|
|
|
+import de.mcs.tools.sps.emulator.emulator.AbstractEmulator;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author w.klaas
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class HoltekEmulator extends AbstractEmulator implements SPSEmulator {
|
|
|
+ private List<SPSCommand> commands = new ArrayList<>();
|
|
|
+ {
|
|
|
+ commands.add(SPS_NOP);
|
|
|
+ commands.add(SPS_PORT);
|
|
|
+ commands.add(SPS_WAIT);
|
|
|
+ commands.add(SPS_JUMP_DOWN);
|
|
|
+ commands.add(SPS_A_EQUALS);
|
|
|
+ commands.add(SPS_EQUALS_A);
|
|
|
+ commands.add(SPS_A_INPUT);
|
|
|
+ commands.add(SPS_A_CALCULATE);
|
|
|
+ commands.add(SPS_PAGE);
|
|
|
+ commands.add(SPS_JUMP);
|
|
|
+ commands.add(SPS_C_LOOP);
|
|
|
+ commands.add(SPS_D_LOOP);
|
|
|
+ commands.add(SPS_SKIP_IF);
|
|
|
+ commands.add(SPS_CALL);
|
|
|
+ commands.add(SPS_RETURN);
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_NOP = new SPSCommandImpl().setName("no operation").setMnemonic("NOP")
|
|
|
+ .setCommandByte((byte) 0x00);
|
|
|
+ static {
|
|
|
+ SPS_NOP.getCommandDatas().add(new SPSCommandDataNOP().setName("nop").setMnemonic("NOP")
|
|
|
+ .setCommandByte((byte) (SPS_NOP.getCommandByte())).setCommand(SPS_NOP));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_PORT = new SPSCommandImpl().setName("Port Output").setMnemonic("PORT")
|
|
|
+ .setCommandByte((byte) 0x10);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ SPS_PORT.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte data = getData();
|
|
|
+ HoltekEmulatorOutput emulatorOutput = (HoltekEmulatorOutput) output;
|
|
|
+ emulatorOutput.setOutput(data);
|
|
|
+ internals.incAddress(1);
|
|
|
+ return emulatorOutput;
|
|
|
+ }
|
|
|
+ }.setName("Port " + Integer.toString(i)).setMnemonic("PO" + Integer.toString(i))
|
|
|
+ .setCommandByte((byte) (SPS_PORT.getCommandByte() + i)).setCommand(SPS_PORT));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_WAIT = new SPSCommandImpl().setName("WAIT").setMnemonic("WAIT")
|
|
|
+ .setCommandByte((byte) 0x20);
|
|
|
+ static {
|
|
|
+ List<SPSCommandData> datas = SPS_WAIT.getCommandDatas();
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ datas.add(
|
|
|
+ new SPSCommandDataWait().setName(SPSCommandDataWait.getName(i)).setMnemonic(SPSCommandDataWait.getMnemonic(i))
|
|
|
+ .setCommandByte((byte) (SPS_WAIT.getCommandByte() + i)).setCommand(SPS_WAIT));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_JUMP_DOWN = new SPSCommandImpl().setName("jump back").setMnemonic("JMP-")
|
|
|
+ .setCommandByte((byte) 0x30);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ SPS_JUMP_DOWN.getCommandDatas()
|
|
|
+ .add(new SPSCommandDataJumpDown().setName("Jump -" + Integer.toString(i))
|
|
|
+ .setMnemonic("JN" + Integer.toString(i)).setCommandByte((byte) (SPS_JUMP_DOWN.getCommandByte() + i))
|
|
|
+ .setCommand(SPS_JUMP_DOWN));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_A_EQUALS = new SPSCommandImpl().setName("Set A").setMnemonic("A=")
|
|
|
+ .setCommandByte((byte) 0x40);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ SPS_A_EQUALS.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte data = getData();
|
|
|
+ internals.setRegister("A", data);
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A= " + Integer.toString(i)).setMnemonic(String.format("A%02d", i))
|
|
|
+ .setCommandByte((byte) (SPS_A_EQUALS.getCommandByte() + i)).setCommand(SPS_A_EQUALS));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_EQUALS_A = new SPSCommandImpl().setName("=A").setMnemonic("=A")
|
|
|
+ .setCommandByte((byte) 0x50);
|
|
|
+ static {
|
|
|
+ List<SPSCommandData> datas = SPS_EQUALS_A.getCommandDatas();
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("B", internals.getRegister("A"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("B=A").setMnemonic("BEA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x01))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("C", internals.getRegister("A"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("C=A").setMnemonic("CEA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x02))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("D", internals.getRegister("A"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("D=A").setMnemonic("DEA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x03))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ HoltekEmulatorOutput emulatorOutput = (HoltekEmulatorOutput) output;
|
|
|
+ emulatorOutput.setOutput(internals.getRegister("A"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("Output=A").setMnemonic("OEA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x04))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ HoltekEmulatorOutput emulatorOutput = (HoltekEmulatorOutput) output;
|
|
|
+ byte dataNew = internals.getRegister("A");
|
|
|
+ byte dataOld = emulatorOutput.getOutput();
|
|
|
+ byte data = (byte) ((dataOld & 0b00001110) + (dataNew & 0x01));
|
|
|
+ emulatorOutput.setOutput(data);
|
|
|
+ internals.incAddress(1);
|
|
|
+ return emulatorOutput;
|
|
|
+ }
|
|
|
+ }.setName("Output.1=A").setMnemonic("O1EA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x05))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ HoltekEmulatorOutput emulatorOutput = (HoltekEmulatorOutput) output;
|
|
|
+ byte dataNew = internals.getRegister("A");
|
|
|
+ byte dataOld = emulatorOutput.getOutput();
|
|
|
+ byte data = (byte) ((dataOld & 0b00001101) + ((dataNew & 0x01) << 1));
|
|
|
+ emulatorOutput.setOutput(data);
|
|
|
+ internals.incAddress(1);
|
|
|
+ return emulatorOutput;
|
|
|
+ }
|
|
|
+ }.setName("Output.2=A").setMnemonic("O2EA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x06))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ HoltekEmulatorOutput emulatorOutput = (HoltekEmulatorOutput) output;
|
|
|
+ byte dataNew = internals.getRegister("A");
|
|
|
+ byte dataOld = emulatorOutput.getOutput();
|
|
|
+ byte data = (byte) ((dataOld & 0b00001011) + ((dataNew & 0x01) << 2));
|
|
|
+ emulatorOutput.setOutput(data);
|
|
|
+ internals.incAddress(1);
|
|
|
+ return emulatorOutput;
|
|
|
+ }
|
|
|
+ }.setName("Output.3=A").setMnemonic("O3EA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x07))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ HoltekEmulatorOutput emulatorOutput = (HoltekEmulatorOutput) output;
|
|
|
+ byte dataNew = internals.getRegister("A");
|
|
|
+ byte dataOld = emulatorOutput.getOutput();
|
|
|
+ byte data = (byte) ((dataOld & 0b00000111) + ((dataNew & 0x01) << 3));
|
|
|
+ emulatorOutput.setOutput(data);
|
|
|
+ internals.incAddress(1);
|
|
|
+ return emulatorOutput;
|
|
|
+ }
|
|
|
+ }.setName("Output.4=A").setMnemonic("O4EA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x08))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ HoltekEmulatorOutput emulatorOutput = (HoltekEmulatorOutput) output;
|
|
|
+ emulatorOutput.setFeature("PWM", internals.getRegister("A"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return emulatorOutput;
|
|
|
+ }
|
|
|
+ }.setName("PWM=A").setMnemonic("PEA").setCommandByte((byte) (SPS_EQUALS_A.getCommandByte() + 0x09))
|
|
|
+ .setCommand(SPS_EQUALS_A));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_A_INPUT = new SPSCommandImpl().setName("A=(some input)").setMnemonic("AEI")
|
|
|
+ .setCommandByte((byte) 0x60);
|
|
|
+ static {
|
|
|
+ List<SPSCommandData> datas = SPS_A_INPUT.getCommandDatas();
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", internals.getRegister("B"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=B").setMnemonic("AEB").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x01))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", internals.getRegister("C"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=C").setMnemonic("AEC").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x02))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", internals.getRegister("D"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=D").setMnemonic("AED").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x03))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", input.getInput());
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=Input").setMnemonic("AEI").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x04))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ boolean value = (input.getInput() & 0x01) > 0;
|
|
|
+ internals.setRegister("A", (byte) (value ? 1 : 0));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=Input.1").setMnemonic("AEI1").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x05))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ boolean value = (input.getInput() & 0x02) > 0;
|
|
|
+ internals.setRegister("A", (byte) (value ? 1 : 0));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=Input.2").setMnemonic("AEI2").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x06))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ boolean value = (input.getInput() & 0x04) > 0;
|
|
|
+ internals.setRegister("A", (byte) (value ? 1 : 0));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=Input.3").setMnemonic("AEI3").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x07))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ boolean value = (input.getInput() & 0x08) > 0;
|
|
|
+ internals.setRegister("A", (byte) (value ? 1 : 0));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=Input.4").setMnemonic("AEI4").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x08))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", input.getFeature("AD1"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=AD.1").setMnemonic("AEA1").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x09))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", input.getFeature("AD2"));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=AD.2").setMnemonic("AEA2").setCommandByte((byte) (SPS_A_INPUT.getCommandByte() + 0x0A))
|
|
|
+ .setCommand(SPS_A_INPUT));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_A_CALCULATE = new SPSCommandImpl().setName("Calculate with A").setMnemonic("CALC")
|
|
|
+ .setCommandByte((byte) 0x70);
|
|
|
+ static {
|
|
|
+ List<SPSCommandData> datas = SPS_A_CALCULATE.getCommandDatas();
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") + 1));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A+1").setMnemonic("INCA").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x01))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") - 1));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A-1").setMnemonic("DECA").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x02))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") + internals.getRegister("B")));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A+B").setMnemonic("ADDB").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x03))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") - internals.getRegister("B")));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A-B").setMnemonic("SUBB").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x04))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") * internals.getRegister("B")));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A*B").setMnemonic("MULB").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x05))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") / internals.getRegister("B")));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A/B").setMnemonic("DIVB").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x06))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") & internals.getRegister("B")));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A AND B").setMnemonic("ANDB").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x07))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") | internals.getRegister("B")));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A OR B").setMnemonic("ORB").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x08))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") ^ internals.getRegister("B")));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=A XOR B").setMnemonic("XORB").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x09))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ datas.add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.setRegister("A", (byte) (internals.getRegister("A") ^ 0xFF));
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=NOT A").setMnemonic("NOTA").setCommandByte((byte) (SPS_A_CALCULATE.getCommandByte() + 0x0A))
|
|
|
+ .setCommand(SPS_A_CALCULATE));
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_PAGE = new SPSCommandImpl().setName("Page").setMnemonic("PG")
|
|
|
+ .setCommandByte((byte) 0x80);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ SPS_PAGE.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte data = getData();
|
|
|
+ if (data <= 0x07) {
|
|
|
+ internals.setRegister(HoltekEmulatorInternals.REGISTER_PAGE, data);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("Page " + Integer.toString(i)).setMnemonic("PG" + Integer.toString(i))
|
|
|
+ .setCommandByte((byte) (SPS_PAGE.getCommandByte() + i)).setCommand(SPS_PAGE));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_JUMP = new SPSCommandImpl().setName("Jump").setMnemonic("JMP")
|
|
|
+ .setCommandByte((byte) 0x90);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ SPS_JUMP.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ ((HoltekEmulatorInternals) internals).address = getData()
|
|
|
+ + (internals.getRegister(HoltekEmulatorInternals.REGISTER_PAGE) * 16);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("Jump " + Integer.toString(i)).setMnemonic("JMP" + Integer.toString(i))
|
|
|
+ .setCommandByte((byte) (SPS_JUMP.getCommandByte() + i)).setCommand(SPS_JUMP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_C_LOOP = new SPSCommandImpl().setName("C* Loop").setMnemonic("CLOP")
|
|
|
+ .setCommandByte((byte) 0xA0);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ SPS_C_LOOP.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte c = internals.getRegister(HoltekEmulatorInternals.REGISTER_C);
|
|
|
+ if (c > 0) {
|
|
|
+ c -= 1;
|
|
|
+ c = (byte) (c & 0x0F);
|
|
|
+ internals.setRegister(HoltekEmulatorInternals.REGISTER_C, c);
|
|
|
+ ((HoltekEmulatorInternals) internals).address = getData()
|
|
|
+ + (internals.getRegister(HoltekEmulatorInternals.REGISTER_PAGE) * 16);
|
|
|
+ } else {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("C* Loop " + Integer.toString(i)).setMnemonic("CLOP" + Integer.toString(i))
|
|
|
+ .setCommandByte((byte) (SPS_C_LOOP.getCommandByte() + i)).setCommand(SPS_C_LOOP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_D_LOOP = new SPSCommandImpl().setName("D* Loop").setMnemonic("DLOP")
|
|
|
+ .setCommandByte((byte) 0xB0);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ SPS_D_LOOP.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte d = internals.getRegister(HoltekEmulatorInternals.REGISTER_D);
|
|
|
+ if (d > 0) {
|
|
|
+ d -= 1;
|
|
|
+ d = (byte) (d & 0x0F);
|
|
|
+ internals.setRegister(HoltekEmulatorInternals.REGISTER_D, d);
|
|
|
+ ((HoltekEmulatorInternals) internals).address = getData()
|
|
|
+ + (internals.getRegister(HoltekEmulatorInternals.REGISTER_PAGE) * 16);
|
|
|
+ } else {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("D* Loop " + Integer.toString(i)).setMnemonic("DLOP" + Integer.toString(i))
|
|
|
+ .setCommandByte((byte) (SPS_D_LOOP.getCommandByte() + i)).setCommand(SPS_D_LOOP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_SKIP_IF = new SPSCommandImpl().setName("Skip if").setMnemonic("SKIP")
|
|
|
+ .setCommandByte((byte) 0xC0);
|
|
|
+ static {
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte a = internals.getRegister(HoltekEmulatorInternals.REGISTER_A);
|
|
|
+ byte b = internals.getRegister(HoltekEmulatorInternals.REGISTER_B);
|
|
|
+ if (a > b) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A>B").setMnemonic("AGRB").setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x01))
|
|
|
+ .setCommand(SPS_SKIP_IF));
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte a = internals.getRegister(HoltekEmulatorInternals.REGISTER_A);
|
|
|
+ byte b = internals.getRegister(HoltekEmulatorInternals.REGISTER_B);
|
|
|
+ if (a < b) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A<B").setMnemonic("ASMB").setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x02))
|
|
|
+ .setCommand(SPS_SKIP_IF));
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte a = internals.getRegister(HoltekEmulatorInternals.REGISTER_A);
|
|
|
+ byte b = internals.getRegister(HoltekEmulatorInternals.REGISTER_B);
|
|
|
+ if (a == b) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("A=B").setMnemonic("AEQB").setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x03))
|
|
|
+ .setCommand(SPS_SKIP_IF));
|
|
|
+
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte in = input.getInput();
|
|
|
+ byte data = (byte) (getData() - 0x04);
|
|
|
+ if ((in & (0x01 << data)) > 0) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName(String.format("In.%d=1", i + 1)).setMnemonic(String.format("IN%d1", i + 1))
|
|
|
+ .setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x04 + i)).setCommand(SPS_SKIP_IF));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ byte in = input.getInput();
|
|
|
+ byte data = (byte) (getData() - 0x08);
|
|
|
+ if ((in & (0x01 << data)) == 0) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName(String.format("In.%d=0", i + 1)).setMnemonic(String.format("IN%d0", i + 1))
|
|
|
+ .setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x08 + i)).setCommand(SPS_SKIP_IF));
|
|
|
+ }
|
|
|
+
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ if (!input.getFeatureAsBool(HoltekEmulatorInput.S1)) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("S1=0").setMnemonic("S10").setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x0C))
|
|
|
+ .setCommand(SPS_SKIP_IF));
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ if (!input.getFeatureAsBool(HoltekEmulatorInput.S2)) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("S2=0").setMnemonic("S20").setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x0D))
|
|
|
+ .setCommand(SPS_SKIP_IF));
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ if (input.getFeatureAsBool(HoltekEmulatorInput.S1)) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("S1=1").setMnemonic("S11").setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x0E))
|
|
|
+ .setCommand(SPS_SKIP_IF));
|
|
|
+ SPS_SKIP_IF.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ if (input.getFeatureAsBool(HoltekEmulatorInput.S2)) {
|
|
|
+ internals.incAddress(1);
|
|
|
+ }
|
|
|
+ internals.incAddress(1);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("S2=1").setMnemonic("S21").setCommandByte((byte) (SPS_SKIP_IF.getCommandByte() + 0x0F))
|
|
|
+ .setCommand(SPS_SKIP_IF));
|
|
|
+ };
|
|
|
+
|
|
|
+ private static SPSCommand SPS_CALL = new SPSCommandImpl().setName("Call").setMnemonic("CALL")
|
|
|
+ .setCommandByte((byte) 0xD0);
|
|
|
+ static {
|
|
|
+ for (int i = 0; i < 16; i++) {
|
|
|
+ SPS_CALL.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.pushRtrAddress();
|
|
|
+ ((HoltekEmulatorInternals) internals).address = getData()
|
|
|
+ + (internals.getRegister(HoltekEmulatorInternals.REGISTER_PAGE) * 16);
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("Call " + Integer.toString(i)).setMnemonic("CALL" + Integer.toString(i))
|
|
|
+ .setCommandByte((byte) (SPS_CALL.getCommandByte() + i)).setCommand(SPS_CALL));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static SPSCommand SPS_RETURN = new SPSCommandImpl().setName("return").setMnemonic("RET")
|
|
|
+ .setCommandByte((byte) 0xE0);
|
|
|
+ private static HoltekEmulator instance;
|
|
|
+ static {
|
|
|
+ SPS_RETURN.getCommandDatas().add(new SPSCommandDataImpl() {
|
|
|
+ @Override
|
|
|
+ public EmulatorOutput doWork(EmulatorInput input, EmulatorInternals internals, EmulatorOutput output) {
|
|
|
+ internals.popRtrAddress();
|
|
|
+ return output;
|
|
|
+ }
|
|
|
+ }.setName("Return").setMnemonic("RET").setCommandByte((byte) (SPS_RETURN.getCommandByte())).setCommand(SPS_RETURN));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SPSCommand> getCommands() {
|
|
|
+ return commands;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getProgramSize() {
|
|
|
+ return 128;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void reset() {
|
|
|
+ getEmulatorOutput().reset();
|
|
|
+ getEmulatorInternals().reset();
|
|
|
+ System.out.println("holtec emulator resettet");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void callNextCommand() {
|
|
|
+ byte command = programMemory[getEmulatorInternals().getAddress()];
|
|
|
+ SPSCommandData commandData = getCommandData(command);
|
|
|
+ runCommand(commandData);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected EmulatorInput createEmulatorInput() {
|
|
|
+ return new HoltekEmulatorInput();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected EmulatorOutput createEmulatorOutput() {
|
|
|
+ return new HoltekEmulatorOutput();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected EmulatorInternals createEmulatorInternals() {
|
|
|
+ return new HoltekEmulatorInternals();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|