Initialize Component Management

This commit is contained in:
2025-03-25 18:44:16 +01:00
parent 52daa062df
commit 133ee646d1
28 changed files with 167 additions and 69 deletions

View File

@ -1,28 +1,14 @@
package fabrik.simulator.pic16f84; package fabrik.simulator.pic16f84;
import fabrik.simulator.pic16f84.interfaces.*; import fabrik.simulator.pic16f84.interfaces.*;
public class Commands implements CommandInterface { public class Commands extends PICComponent implements CommandInterface {
private int wRegister; private int wRegister;
private long totalExecutionTime; private long totalExecutionTime;
private final TimerInterface timer; public Commands(){
private final EEPROMInterface eeprom; super();
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) {
wRegister = 0; wRegister = 0;
totalExecutionTime = 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() { public int get_wRegister() {
@ -418,7 +404,6 @@ public class Commands implements CommandInterface {
dataRegister.setRegister(file, result); dataRegister.setRegister(file, result);
} }
dataRegister.determineZeroFlag(result); dataRegister.determineZeroFlag(result);
} }
public void INCFSZ(int file, int destination) { public void INCFSZ(int file, int destination) {
@ -571,4 +556,9 @@ public class Commands implements CommandInterface {
addExecutionTime(1); addExecutionTime(1);
} }
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -599,6 +599,10 @@ public class Controller_Frontend implements FrontendControllerInterface {
wdtCheck.setText("Watchdog-Timer: " + watchdogTimer.get() + "µs"); wdtCheck.setText("Watchdog-Timer: " + watchdogTimer.get() + "µs");
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -20,8 +20,9 @@ public class CreateWindow extends Application {
@Override @Override
public void start(Stage primaryStage) throws IOException { 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")); FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
Parent code = codewindow.load(); Parent code = codewindow.load();
@ -43,7 +44,7 @@ public class CreateWindow extends Application {
public static void refreshTable() { public static void refreshTable() {
grid.getChildren().remove(table); grid.getChildren().remove(table);
table= Table.refresh(); //table= Table.refresh();
grid.add(table, 1, 1); grid.add(table, 1, 1);
} }
} }

View File

@ -6,7 +6,7 @@ import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
import java.util.Arrays; import java.util.Arrays;
public class DataRegister implements DataRegisterInterface { public class DataRegister extends PICComponent implements DataRegisterInterface {
private final int INDF = 0x0; private final int INDF = 0x0;
private final int PCL = 0x2; private final int PCL = 0x2;
private final int STATUS = 0x3; private final int STATUS = 0x3;
@ -35,17 +35,17 @@ public class DataRegister implements DataRegisterInterface {
private final int [] eepromRegisters = {EEDATA, EEADR, EECON1, EECON2}; private final int [] eepromRegisters = {EEDATA, EEADR, EECON1, EECON2};
public final int [] ioRegisters = {PORTA, PORTB, TRISA, TRISB}; 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) { public DataRegister () {
this.eeprom = eeprom; super();
this.preScaler = preScaler;
this.ioPorts = ioPorts;
initOrReset();
} }
@Override
public void initialize(PICComponents picComponents) {
super.initialize(picComponents);
System.out.println("DataRegister.\n");
initOrReset();
}
private void initOrReset () { private void initOrReset () {
dataRegister[PCL] = 0b0; dataRegister[PCL] = 0b0;
@ -62,7 +62,7 @@ public class DataRegister implements DataRegisterInterface {
carryFlag = 0; carryFlag = 0;
zeroFlag = 0; zeroFlag = 0;
digitCarryFlag = 0; digitCarryFlag = 0;
ioPorts.resetTRIS(); super.ioPorts.resetTRIS();
System.out.println(Arrays.toString(dataRegister)); System.out.println(Arrays.toString(dataRegister));
} }
@ -350,7 +350,6 @@ public class DataRegister implements DataRegisterInterface {
public int getDirectRegister(int address) { public int getDirectRegister(int address) {
return dataRegister[address]; return dataRegister[address];
} }
} }

View File

@ -173,4 +173,9 @@ public class EEPROM implements EEPROMInterface {
content |= 0b10; content |= 0b10;
dataRegister.setDirectRegister(EECON1, content); dataRegister.setDirectRegister(EECON1, content);
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -143,4 +143,9 @@ public class EmptyRegister implements DataRegisterInterface {
public int getSTATUS() { public int getSTATUS() {
return 0; return 0;
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -11,7 +11,7 @@ import javafx.scene.shape.Circle;
import java.io.IOException; import java.io.IOException;
public class IOPorts implements IOPortInterface { public class IOPorts extends PICComponent implements IOPortInterface {
private final int A = 0; private final int A = 0;
private final int B = 1; private final int B = 1;
private final int PORTA = 5; private final int PORTA = 5;
@ -32,26 +32,10 @@ public class IOPorts implements IOPortInterface {
private int RB6 = 0x40; private int RB6 = 0x40;
private int RB7 = 0x80; private int RB7 = 0x80;
public IOPorts(){
private final DataRegisterInterface dataRegister; super();
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 void setBit (int address, int bit){ public void setBit (int address, int bit){
if (address < 7) { if (address < 7) {
dataLatch[address - PORTA] |= (1 << bit); dataLatch[address - PORTA] |= (1 << bit);
@ -238,7 +222,13 @@ public class IOPorts implements IOPortInterface {
refreshPorts(); refreshPorts();
} }
public void resetTRIS (){ public void resetTRIS (){ // Only Backend
trisLatch = new int[] {0xFF, 0xFF}; trisLatch = new int[] {0xFF, 0xFF};
} }
@Override
public void initialize(PICComponents picComponents) {
super.initialize(picComponents);
System.out.println("IOPorts.\n");
}
} }

View File

@ -4,8 +4,9 @@ import eu.hansolo.tilesfx.Command;
import fabrik.simulator.pic16f84.interfaces.CommandInterface; import fabrik.simulator.pic16f84.interfaces.CommandInterface;
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface; import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface; 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 INTCON = 0xB;
private final int T0IF = 0x2; private final int T0IF = 0x2;
private final int ISR = 0x4; private final int ISR = 0x4;
@ -70,4 +71,8 @@ public class Interrupts {
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View 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 ");
}
}

View 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);
}
}
}

View File

@ -2,14 +2,15 @@ package fabrik.simulator.pic16f84;
import fabrik.simulator.pic16f84.interfaces.*; import fabrik.simulator.pic16f84.interfaces.*;
public class PreScaler { public class PreScaler extends PICComponent implements PICComponentInterface {
private final int PSA = 0x3; private final int PSA = 0x3;
private final int OPTION = 0x81; private final int OPTION = 0x81;
private final DataRegisterInterface dataRegister;
private final TimerInterface timer; private final TimerInterface timer;
private int scaler; private int scaler;
public PreScaler (DataRegisterInterface dataRegister, TimerInterface timer) { public PreScaler (DataRegisterInterface dataRegister, TimerInterface timer) {
super();
scaler = 0b111; scaler = 0b111;
this.dataRegister = dataRegister; this.dataRegister = dataRegister;
this.timer = timer; this.timer = timer;
@ -48,4 +49,9 @@ public class PreScaler {
timer.increment(manual); timer.increment(manual);
} }
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -46,4 +46,9 @@ public class ProgramStack implements ProgramStackInterface {
public List<Integer> getStack() { public List<Integer> getStack() {
return returnStack; return returnStack;
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -74,4 +74,9 @@ public class Timer implements TimerInterface {
dataRegister.setDirectRegister(1, timer); dataRegister.setDirectRegister(1, timer);
} }
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -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();
}
}

View File

@ -66,4 +66,9 @@ public class WatchdogTimer implements WatchdogTimerInterface {
public long get (){ public long get (){
return realtimer; return realtimer;
} }
@Override
public void initialize(PICComponents picComponents) {
}
} }

View File

@ -1,6 +1,6 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface CommandInterface { public interface CommandInterface extends PICComponentInterface {
void CALL(int isr); void CALL(int isr);
double getTotalExecutionTime(); double getTotalExecutionTime();

View File

@ -1,6 +1,6 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface DataRegisterInterface { public interface DataRegisterInterface extends PICComponentInterface {
void clearBit(int f, int b); void clearBit(int f, int b);
void setBit(int f, int b); void setBit(int f, int b);

View File

@ -1,6 +1,6 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface EEPROMInterface { public interface EEPROMInterface extends PICComponentInterface {
void registerTime(boolean b); void registerTime(boolean b);
void parse(int i, int content, int i1); void parse(int i, int content, int i1);

View File

@ -1,6 +1,6 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface FrontendControllerInterface { public interface FrontendControllerInterface extends PICComponentInterface {
double getExecutionTimeMultiplier(); double getExecutionTimeMultiplier();
void sleep(); void sleep();

View File

@ -5,7 +5,7 @@ import javafx.scene.shape.Circle;
import java.io.IOException; import java.io.IOException;
public interface IOPortInterface { public interface IOPortInterface extends PICComponentInterface {
void resetTRIS(); void resetTRIS();
void setRegister(int i, int content); void setRegister(int i, int content);

View File

@ -1,6 +1,6 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface InterruptInterface { public interface InterruptInterface extends PICComponentInterface {
void triggerRBInterrupt(int oldValue, int value); void triggerRBInterrupt(int oldValue, int value);
void triggerRB0Interrupt(int oldValue, int value); void triggerRB0Interrupt(int oldValue, int value);

View File

@ -0,0 +1,7 @@
package fabrik.simulator.pic16f84.interfaces;
import fabrik.simulator.pic16f84.PICComponents;
public interface PICComponentInterface {
void initialize(PICComponents picComponents);
}

View File

@ -2,7 +2,7 @@ package fabrik.simulator.pic16f84.interfaces;
import java.util.List; import java.util.List;
public interface ProgramStackInterface { public interface ProgramStackInterface extends PICComponentInterface {
int pop(); int pop();
void push(int i); void push(int i);

View File

@ -1,5 +1,5 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface TableInterface { public interface TableInterface extends PICComponentInterface {
void refresh(); void refresh();
} }

View File

@ -1,7 +1,7 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface TimerInterface { public interface TimerInterface extends PICComponentInterface {
public void cycles(int i); void cycles(int i);
void incrementFromPin(int directRegister); void incrementFromPin(int directRegister);

View File

@ -2,6 +2,6 @@ package fabrik.simulator.pic16f84.interfaces;
import fabrik.simulator.pic16f84.ToggleButtonGroupExt; import fabrik.simulator.pic16f84.ToggleButtonGroupExt;
public interface ToggleButtonInterface { public interface ToggleButtonInterface extends PICComponentInterface {
ToggleButtonGroupExt get(); ToggleButtonGroupExt get();
} }

View File

@ -1,6 +1,6 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface WatchdogTimerInterface { public interface WatchdogTimerInterface extends PICComponentInterface {
void reset(); void reset();
void testAndTrigger(); void testAndTrigger();

View File

@ -1,5 +1,5 @@
package fabrik.simulator.pic16f84.interfaces; package fabrik.simulator.pic16f84.interfaces;
public interface WindowManagement { public interface WindowManagement extends PICComponentInterface {
void refreshTable(); void refreshTable();
} }