Browse Source

web emulator adding the emulator interface and first implementing class

Wilfried Klaas 6 years ago
parent
commit
443b357a44

+ 7 - 0
src/main/java/de/mcs/tools/sps/SPSAssembler.java

@@ -207,6 +207,13 @@ public class SPSAssembler {
       SPSOutputter annotation = outClass.getAnnotation(SPSOutputter.class);
       if (annotation.name().equalsIgnoreCase(outputFormat)) {
         outputter = (Outputter) outClass.newInstance();
+        outputter = (Outputter) outClass.newInstance();
+        outputter = (Outputter) outClass.newInstance();
+        outputter = (Outputter) outClass.newInstance();
+        outputter = (Outputter) outClass.newInstance();
+        outputter = (Outputter) outClass.newInstance();
+        outputter = (Outputter) outClass.newInstance();
+        outputter = (Outputter) outClass.newInstance();
       }
     }
 

+ 114 - 0
src/main/java/de/mcs/tools/sps/emulator/AbstractEmulator.java

@@ -0,0 +1,114 @@
+/**
+ * MCS Media Computer Software
+ * Copyright 2019 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: AbstractEmulator.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 31.01.2019 wklaa_000
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.sps.emulator;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import de.mcs.tools.sps.SPSAssembler;
+import de.mcs.tools.sps.emulator.model.WebSessionModel;
+import de.mcs.tools.sps.emulator.model.WorkingModel;
+import de.mcs.tools.sps.emulator.model.WorkingModel.WORKINGSTATE;
+import de.mcs.tools.sps.mnemonic.Mnemonic;
+
+/**
+ * @author wklaa_000
+ *
+ */
+public abstract class AbstractEmulator implements Emulator {
+
+  private WebSessionModel model;
+
+  public AbstractEmulator(WebSessionModel model) {
+    this.model = model;
+  }
+
+  /**
+   * @return the model
+   */
+  public WebSessionModel getModel() {
+    return model;
+  }
+
+  /**
+   * starting the emulatiing process. Resetting all registers, addresses,
+   * stacks, outputs...
+   * 
+   * @return return true, if everything is ok.
+   */
+  @Override
+  public boolean start() {
+    WorkingModel work = model.getWork();
+    work.setAddress((short) 0);
+    work.setRaddress((short) 0);
+    work.setPage((byte) 0);
+    work.setRegisterA((byte) 0);
+    work.setRegisterB((byte) 0);
+    work.setRegisterC((byte) 0);
+    work.setRegisterD((byte) 0);
+    work.setRegisterE((byte) 0);
+    work.setRegisterF((byte) 0);
+    work.setStack(new ArrayList<>());
+    work.setWorkingstate(WORKINGSTATE.EMULATE);
+
+    model.getProgram().setActualLine(0);
+
+    model.getOutput().setOutput1(false);
+    model.getOutput().setOutput2(false);
+    model.getOutput().setOutput3(false);
+    model.getOutput().setOutput4(false);
+    model.getOutput().setPwm1((byte) 0);
+    model.getOutput().setPwm2((byte) 0);
+    model.getOutput().setServo1((byte) 0);
+    model.getOutput().setServo2((byte) 0);
+    model.getOutput().setTone((byte) 0);
+
+    return true;
+  }
+
+  /**
+   * processing the next command from the program
+   * 
+   * @return return true, if everything is ok.
+   */
+  @Override
+  public boolean next() {
+    // TODO Auto-generated method stub
+    return false;
+  }
+
+  @Override
+  public boolean stop() {
+    model.getWork().setWorkingstate(WORKINGSTATE.NN);
+    return true;
+  }
+
+  @Override
+  public boolean compile() {
+    SPSAssembler spsAssembler = new SPSAssembler();
+    spsAssembler.doWork(source);
+
+    List<Mnemonic> mnemonics = spsAssembler.getMnemonics();
+    return false;
+  }
+
+}

+ 16 - 4
src/main/java/de/mcs/tools/sps/emulator/emulator/package-info.java → src/main/java/de/mcs/tools/sps/emulator/Emulator.java

@@ -1,10 +1,10 @@
 /**
  * MCS Media Computer Software
- * Copyright 2018 by Wilfried Klaas
+ * Copyright 2019 by Wilfried Klaas
  * Project: SPSEmulator
- * File: package-info.java
+ * File: Emulator.java
  * EMail: W.Klaas@gmx.de
- * Created: 25.11.2018 wklaa_000
+ * Created: 31.01.2019 wklaa_000
  * 
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -19,8 +19,20 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>
  */
+package de.mcs.tools.sps.emulator;
+
 /**
  * @author wklaa_000
  *
  */
-package de.mcs.tools.sps.emulator.emulator;
+public interface Emulator {
+
+  boolean start();
+
+  boolean next();
+
+  boolean stop();
+
+  boolean compile();
+
+}

+ 47 - 0
src/main/java/de/mcs/tools/sps/emulator/EmulatorFactory.java

@@ -0,0 +1,47 @@
+/**
+ * MCS Media Computer Software
+ * Copyright 2019 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: EmulatorFactory.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 31.01.2019 wklaa_000
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.sps.emulator;
+
+import de.mcs.tools.sps.emulator.holtek.HoltekEmulator;
+import de.mcs.tools.sps.emulator.model.Hardware;
+import de.mcs.tools.sps.emulator.model.WebSessionModel;
+
+/**
+ * @author wklaa_000
+ *
+ */
+public class EmulatorFactory {
+
+  public static Emulator getEmulator(WebSessionModel model) {
+    Emulator emulator = null;
+    Hardware hardware = model.getProgram().getHardware();
+    switch (hardware) {
+    case HOLTEK:
+      emulator = new HoltekEmulator(model);
+      break;
+    default:
+      break;
+    }
+    return emulator;
+  }
+
+}

+ 38 - 0
src/main/java/de/mcs/tools/sps/emulator/holtek/HoltekEmulator.java

@@ -0,0 +1,38 @@
+/**
+ * MCS Media Computer Software
+ * Copyright 2019 by Wilfried Klaas
+ * Project: SPSEmulator
+ * File: HoltekEmulator.java
+ * EMail: W.Klaas@gmx.de
+ * Created: 31.01.2019 wklaa_000
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>
+ */
+package de.mcs.tools.sps.emulator.holtek;
+
+import de.mcs.tools.sps.emulator.AbstractEmulator;
+import de.mcs.tools.sps.emulator.Emulator;
+import de.mcs.tools.sps.emulator.model.WebSessionModel;
+
+/**
+ * @author wklaa_000
+ *
+ */
+public class HoltekEmulator extends AbstractEmulator implements Emulator {
+
+  public HoltekEmulator(WebSessionModel model) {
+    super(model);
+  }
+
+}

+ 2 - 1
src/main/java/de/mcs/tools/sps/emulator/model/CommandModel.java

@@ -7,7 +7,7 @@ import java.util.Set;
 public class CommandModel {
 
   public enum COMMAND {
-    START, STOP, NEXT, RESET, NN
+    START, STOP, NEXT, RESET, COMPILE, NN
   };
 
   private Set<COMMAND> availableCommands;
@@ -46,6 +46,7 @@ public class CommandModel {
     case RESET:
     case NN:
       getAvailableCommands().add(COMMAND.START);
+      getAvailableCommands().add(COMMAND.COMPILE);
       break;
     default:
       break;

+ 22 - 0
src/main/java/de/mcs/tools/sps/emulator/resources/EmulatorResource.java

@@ -6,6 +6,8 @@ import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 
+import de.mcs.tools.sps.emulator.Emulator;
+import de.mcs.tools.sps.emulator.EmulatorFactory;
 import de.mcs.tools.sps.emulator.model.CommandModel.COMMAND;
 import de.mcs.tools.sps.emulator.model.WebSessionModel;
 import de.mcs.tools.sps.emulator.model.WorkingModel.WORKINGSTATE;
@@ -22,6 +24,26 @@ public class EmulatorResource {
   @POST
   public WebSessionModel getSession(WebSessionModel model) {
     model = checkModel(model);
+    Emulator emulator = EmulatorFactory.getEmulator(model);
+    COMMAND actualCommand = model.getCommand().getActualCommand();
+    switch (actualCommand) {
+    case NN:
+      break;
+    case START:
+      emulator.start();
+      break;
+    case NEXT:
+      emulator.next();
+      break;
+    case STOP:
+      emulator.stop();
+      break;
+    case COMPILE:
+      emulator.compile();
+      break;
+    default:
+      break;
+    }
     return model;
   }