Initialize Component Management
This commit is contained in:
@ -1,28 +1,14 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class Commands implements CommandInterface {
|
||||
public class Commands extends PICComponent implements CommandInterface {
|
||||
private int wRegister;
|
||||
private long totalExecutionTime;
|
||||
|
||||
private final TimerInterface timer;
|
||||
private final EEPROMInterface eeprom;
|
||||
private final WatchdogTimerInterface watchdogTimer;
|
||||
private final ProgramStackInterface programStack;
|
||||
private final DataRegisterInterface dataRegister;
|
||||
private final FrontendControllerInterface frontendController;
|
||||
|
||||
|
||||
public Commands(TimerInterface timer, EEPROMInterface eeprom, WatchdogTimerInterface watchdogTimer,
|
||||
ProgramStackInterface programStack, DataRegisterInterface dataRegister, FrontendControllerInterface frontendController) {
|
||||
public Commands(){
|
||||
super();
|
||||
wRegister = 0;
|
||||
totalExecutionTime = 0;
|
||||
this.timer = timer;
|
||||
this.eeprom = eeprom;
|
||||
this.watchdogTimer = watchdogTimer;
|
||||
this.programStack = programStack;
|
||||
this.dataRegister = dataRegister;
|
||||
this.frontendController = frontendController;
|
||||
}
|
||||
|
||||
public int get_wRegister() {
|
||||
@ -418,7 +404,6 @@ public class Commands implements CommandInterface {
|
||||
dataRegister.setRegister(file, result);
|
||||
}
|
||||
dataRegister.determineZeroFlag(result);
|
||||
|
||||
}
|
||||
|
||||
public void INCFSZ(int file, int destination) {
|
||||
@ -571,4 +556,9 @@ public class Commands implements CommandInterface {
|
||||
addExecutionTime(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -599,6 +599,10 @@ public class Controller_Frontend implements FrontendControllerInterface {
|
||||
wdtCheck.setText("Watchdog-Timer: " + watchdogTimer.get() + "µs");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -20,8 +20,9 @@ public class CreateWindow extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
DataRegister.initDataRegister();
|
||||
table = Table.refresh();
|
||||
|
||||
//DataRegister.initDataRegister();
|
||||
//table = Table.refresh();
|
||||
FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
|
||||
Parent code = codewindow.load();
|
||||
|
||||
@ -43,7 +44,7 @@ public class CreateWindow extends Application {
|
||||
|
||||
public static void refreshTable() {
|
||||
grid.getChildren().remove(table);
|
||||
table= Table.refresh();
|
||||
//table= Table.refresh();
|
||||
grid.add(table, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DataRegister implements DataRegisterInterface {
|
||||
public class DataRegister extends PICComponent implements DataRegisterInterface {
|
||||
private final int INDF = 0x0;
|
||||
private final int PCL = 0x2;
|
||||
private final int STATUS = 0x3;
|
||||
@ -35,17 +35,17 @@ public class DataRegister implements DataRegisterInterface {
|
||||
private final int [] eepromRegisters = {EEDATA, EEADR, EECON1, EECON2};
|
||||
public final int [] ioRegisters = {PORTA, PORTB, TRISA, TRISB};
|
||||
|
||||
private final EEPROMInterface eeprom;
|
||||
private final PreScaler preScaler;
|
||||
private final IOPortInterface ioPorts;
|
||||
|
||||
public DataRegister (EEPROMInterface eeprom, PreScaler preScaler, IOPortInterface ioPorts) {
|
||||
this.eeprom = eeprom;
|
||||
this.preScaler = preScaler;
|
||||
this.ioPorts = ioPorts;
|
||||
initOrReset();
|
||||
public DataRegister () {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
System.out.println("DataRegister.\n");
|
||||
initOrReset();
|
||||
}
|
||||
|
||||
private void initOrReset () {
|
||||
dataRegister[PCL] = 0b0;
|
||||
@ -62,7 +62,7 @@ public class DataRegister implements DataRegisterInterface {
|
||||
carryFlag = 0;
|
||||
zeroFlag = 0;
|
||||
digitCarryFlag = 0;
|
||||
ioPorts.resetTRIS();
|
||||
super.ioPorts.resetTRIS();
|
||||
System.out.println(Arrays.toString(dataRegister));
|
||||
}
|
||||
|
||||
@ -350,7 +350,6 @@ public class DataRegister implements DataRegisterInterface {
|
||||
public int getDirectRegister(int address) {
|
||||
return dataRegister[address];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -173,4 +173,9 @@ public class EEPROM implements EEPROMInterface {
|
||||
content |= 0b10;
|
||||
dataRegister.setDirectRegister(EECON1, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,4 +143,9 @@ public class EmptyRegister implements DataRegisterInterface {
|
||||
public int getSTATUS() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import javafx.scene.shape.Circle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IOPorts implements IOPortInterface {
|
||||
public class IOPorts extends PICComponent implements IOPortInterface {
|
||||
private final int A = 0;
|
||||
private final int B = 1;
|
||||
private final int PORTA = 5;
|
||||
@ -32,26 +32,10 @@ public class IOPorts implements IOPortInterface {
|
||||
private int RB6 = 0x40;
|
||||
private int RB7 = 0x80;
|
||||
|
||||
|
||||
private final DataRegisterInterface dataRegister;
|
||||
private final TimerInterface timer;
|
||||
private final InterruptInterface interrupts;
|
||||
private final TableInterface table;
|
||||
private final WindowManagement createWindow;
|
||||
private final FrontendControllerInterface frontendController;
|
||||
|
||||
public IOPorts (DataRegisterInterface dataRegister, FrontendControllerInterface frontendController, TimerInterface timer,
|
||||
InterruptInterface interrupts, TableInterface table, WindowManagement createWindow){
|
||||
|
||||
this.dataRegister = dataRegister;
|
||||
this.timer = timer;
|
||||
this.frontendController = frontendController;
|
||||
this.interrupts = interrupts;
|
||||
this.createWindow = createWindow;
|
||||
this.table = table;
|
||||
public IOPorts(){
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
public void setBit (int address, int bit){
|
||||
if (address < 7) {
|
||||
dataLatch[address - PORTA] |= (1 << bit);
|
||||
@ -238,7 +222,13 @@ public class IOPorts implements IOPortInterface {
|
||||
refreshPorts();
|
||||
}
|
||||
|
||||
public void resetTRIS (){
|
||||
public void resetTRIS (){ // Only Backend
|
||||
trisLatch = new int[] {0xFF, 0xFF};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
super.initialize(picComponents);
|
||||
System.out.println("IOPorts.\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,8 +4,9 @@ import eu.hansolo.tilesfx.Command;
|
||||
import fabrik.simulator.pic16f84.interfaces.CommandInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.InterruptInterface;
|
||||
|
||||
public class Interrupts {
|
||||
public class Interrupts implements InterruptInterface {
|
||||
private final int INTCON = 0xB;
|
||||
private final int T0IF = 0x2;
|
||||
private final int ISR = 0x4;
|
||||
@ -70,4 +71,8 @@ public class Interrupts {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
24
src/main/java/fabrik/simulator/pic16f84/PICComponent.java
Normal file
24
src/main/java/fabrik/simulator/pic16f84/PICComponent.java
Normal file
@ -0,0 +1,24 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public abstract class PICComponent {
|
||||
DataRegisterInterface dataRegister;
|
||||
EEPROMInterface eeprom;
|
||||
PreScaler preScaler;
|
||||
IOPortInterface ioPorts;
|
||||
TimerInterface timer;
|
||||
InterruptInterface interrupts;
|
||||
TableInterface table;
|
||||
WindowManagement createWindow;
|
||||
FrontendControllerInterface frontendController;
|
||||
WatchdogTimerInterface watchdogTimer;
|
||||
ProgramStackInterface programStack;
|
||||
|
||||
void initialize(PICComponents picComponents) {
|
||||
dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
|
||||
eeprom = (EEPROMInterface) picComponents.getComponent(EEPROMInterface.class);
|
||||
ioPorts = (IOPortInterface) picComponents.getComponent(IOPortInterface.class);
|
||||
System.out.print("Initializing PIC Component ");
|
||||
}
|
||||
}
|
||||
29
src/main/java/fabrik/simulator/pic16f84/PICComponents.java
Normal file
29
src/main/java/fabrik/simulator/pic16f84/PICComponents.java
Normal file
@ -0,0 +1,29 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PICComponents {
|
||||
private final HashMap<Class<? extends PICComponentInterface>, PICComponentInterface> componentCatalogue;
|
||||
|
||||
public PICComponents() {
|
||||
super();
|
||||
this.componentCatalogue = new HashMap<>();
|
||||
}
|
||||
|
||||
public void registerComponent (Class<? extends PICComponentInterface> componentClass, PICComponentInterface component) {
|
||||
this.componentCatalogue.put(componentClass, component);
|
||||
}
|
||||
|
||||
public PICComponentInterface getComponent(Class<? extends PICComponentInterface> componentClass) {
|
||||
return this.componentCatalogue.get(componentClass);
|
||||
}
|
||||
|
||||
public void initAll() {
|
||||
for (PICComponentInterface component : componentCatalogue.values()) {
|
||||
component.initialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,14 +2,15 @@ package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class PreScaler {
|
||||
public class PreScaler extends PICComponent implements PICComponentInterface {
|
||||
|
||||
private final int PSA = 0x3;
|
||||
private final int OPTION = 0x81;
|
||||
private final DataRegisterInterface dataRegister;
|
||||
private final TimerInterface timer;
|
||||
private int scaler;
|
||||
|
||||
public PreScaler (DataRegisterInterface dataRegister, TimerInterface timer) {
|
||||
super();
|
||||
scaler = 0b111;
|
||||
this.dataRegister = dataRegister;
|
||||
this.timer = timer;
|
||||
@ -48,4 +49,9 @@ public class PreScaler {
|
||||
timer.increment(manual);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,4 +46,9 @@ public class ProgramStack implements ProgramStackInterface {
|
||||
public List<Integer> getStack() {
|
||||
return returnStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,4 +74,9 @@ public class Timer implements TimerInterface {
|
||||
dataRegister.setDirectRegister(1, timer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
|
||||
|
||||
public class TryComponentManagement {
|
||||
public static void main(String[] args) {
|
||||
DataRegisterInterface dataRegister = new DataRegister();
|
||||
IOPortInterface ioPorts = new IOPorts();
|
||||
|
||||
PICComponents picComponents = new PICComponents(); // Subjekt
|
||||
|
||||
picComponents.registerComponent(DataRegisterInterface.class, dataRegister);
|
||||
picComponents.registerComponent(IOPortInterface.class, ioPorts);
|
||||
|
||||
picComponents.initAll();
|
||||
}
|
||||
}
|
||||
@ -66,4 +66,9 @@ public class WatchdogTimer implements WatchdogTimerInterface {
|
||||
public long get (){
|
||||
return realtimer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponents picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface CommandInterface {
|
||||
public interface CommandInterface extends PICComponentInterface {
|
||||
void CALL(int isr);
|
||||
|
||||
double getTotalExecutionTime();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface DataRegisterInterface {
|
||||
public interface DataRegisterInterface extends PICComponentInterface {
|
||||
void clearBit(int f, int b);
|
||||
|
||||
void setBit(int f, int b);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface EEPROMInterface {
|
||||
public interface EEPROMInterface extends PICComponentInterface {
|
||||
void registerTime(boolean b);
|
||||
|
||||
void parse(int i, int content, int i1);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface FrontendControllerInterface {
|
||||
public interface FrontendControllerInterface extends PICComponentInterface {
|
||||
double getExecutionTimeMultiplier();
|
||||
|
||||
void sleep();
|
||||
|
||||
@ -5,7 +5,7 @@ import javafx.scene.shape.Circle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IOPortInterface {
|
||||
public interface IOPortInterface extends PICComponentInterface {
|
||||
void resetTRIS();
|
||||
|
||||
void setRegister(int i, int content);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface InterruptInterface {
|
||||
public interface InterruptInterface extends PICComponentInterface {
|
||||
void triggerRBInterrupt(int oldValue, int value);
|
||||
|
||||
void triggerRB0Interrupt(int oldValue, int value);
|
||||
|
||||
@ -0,0 +1,7 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.PICComponents;
|
||||
|
||||
public interface PICComponentInterface {
|
||||
void initialize(PICComponents picComponents);
|
||||
}
|
||||
@ -2,7 +2,7 @@ package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProgramStackInterface {
|
||||
public interface ProgramStackInterface extends PICComponentInterface {
|
||||
int pop();
|
||||
|
||||
void push(int i);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface TableInterface {
|
||||
public interface TableInterface extends PICComponentInterface {
|
||||
void refresh();
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface TimerInterface {
|
||||
public void cycles(int i);
|
||||
public interface TimerInterface extends PICComponentInterface {
|
||||
void cycles(int i);
|
||||
|
||||
void incrementFromPin(int directRegister);
|
||||
|
||||
|
||||
@ -2,6 +2,6 @@ package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.ToggleButtonGroupExt;
|
||||
|
||||
public interface ToggleButtonInterface {
|
||||
public interface ToggleButtonInterface extends PICComponentInterface {
|
||||
ToggleButtonGroupExt get();
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface WatchdogTimerInterface {
|
||||
public interface WatchdogTimerInterface extends PICComponentInterface {
|
||||
void reset();
|
||||
|
||||
void testAndTrigger();
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface WindowManagement {
|
||||
public interface WindowManagement extends PICComponentInterface {
|
||||
void refreshTable();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user