Compare commits
33 Commits
main
...
advancedSE
| Author | SHA1 | Date | |
|---|---|---|---|
| e4bc5347f1 | |||
| a360c4d986 | |||
| 9d393deaa7 | |||
| cf1bddd231 | |||
| f28603843d | |||
| 47c2ca7d36 | |||
| 52d6352334 | |||
| 68d7f3c3d9 | |||
| ce8a77d049 | |||
| 4f219ad5d5 | |||
| d56c7a1439 | |||
| 0e70985ff3 | |||
| 735990b7cf | |||
| 48928f8587 | |||
| ef3b0fce5f | |||
| 3ae042e0bb | |||
| cf6bcd8498 | |||
| 85bc6e9eba | |||
| 06e9348016 | |||
| 03941fc302 | |||
| 087b132362 | |||
| 757e51f1db | |||
| db03c9d7bd | |||
| 0dd7494f5a | |||
| c38835fd7b | |||
| ac854ed4f1 | |||
| bafb8314f6 | |||
| 466ae211d9 | |||
| fec427794d | |||
| 4310011f0e | |||
| ca36cffd47 | |||
| 133ee646d1 | |||
| 52daa062df |
28
combined.qmd
Normal file
28
combined.qmd
Normal file
@ -0,0 +1,28 @@
|
||||
---
|
||||
title: "Programmentwurf Advanced SoftwareEngineering"
|
||||
subtitle: Für einen [PIC16f84-Simulator (Link)](https://git.paulmartin.cloud/paul/PIC-Simu/src/branch/advancedSE/)
|
||||
abstract: Alle für die Vorlesung durchgeführten Änderungen befinden sich im Branch [advancedSE](https://git.paulmartin.cloud/paul/PIC-Simu/src/branch/advancedSE/). Als ursprünglicher Stand kann der [main-Branch](https://git.paulmartin.cloud/paul/PIC-Simu/src/branch/main/) oder [dieser Commit](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/c8f23176d25701c2de0723cd52bf2faaee121fb0) gesehen werden.
|
||||
author:
|
||||
- Luca Müller
|
||||
- Paul Martin
|
||||
date: 05/31/2025
|
||||
date-format: "DD.MM.YYYY"
|
||||
lang: de
|
||||
format:
|
||||
pdf:
|
||||
toc: true
|
||||
number-sections: true
|
||||
colorlinks: true
|
||||
crossref:
|
||||
custom:
|
||||
- kind: float
|
||||
reference-prefix: UML-Diagramm
|
||||
key: uml
|
||||
latex-env: uml
|
||||
latex-list-of-description: UML-Diagramme
|
||||
---
|
||||
|
||||
\listof{uml}{Verzeichnis der UML-Diagramme}
|
||||
|
||||
{{< include paul.qmd >}}
|
||||
{{< include luca.qmd >}}
|
||||
511
luca.qmd
Normal file
511
luca.qmd
Normal file
@ -0,0 +1,511 @@
|
||||
---
|
||||
lang: de
|
||||
format:
|
||||
pdf:
|
||||
toc: true
|
||||
number-sections: true
|
||||
colorlinks: true
|
||||
crossref:
|
||||
custom:
|
||||
- kind: float
|
||||
reference-prefix: UML-Diagramm
|
||||
key: uml
|
||||
latex-env: uml
|
||||
latex-list-of-description: UML-Diagramme
|
||||
---
|
||||
|
||||
# Code Smell 1: Long Method
|
||||
|
||||
## Beschreibung des Problems
|
||||
|
||||
Das **Long Method** Anti-Pattern tritt auf, wenn eine einzelne Methode zu viele Zeilen Code enthält und multiple Verantwortlichkeiten übernimmt. Eine solche Methode verstößt gegen das **Single Responsibility Principle (SRP)** und führt zu verschiedenen Problemen:
|
||||
|
||||
- **Schwere Verständlichkeit**: Entwickler müssen viel Zeit aufwenden, um die gesamte Methode zu durchdringen
|
||||
- **Reduzierte Testbarkeit**: Verschiedene Logikbereiche können nicht isoliert getestet werden
|
||||
- **Mangelnde Wiederverwendbarkeit**: Teilfunktionalitäten sind nicht separat nutzbar
|
||||
- **Erhöhte Fehleranfälligkeit**: Bugs sind schwerer zu lokalisieren und zu beheben
|
||||
|
||||
## Praktisches Beispiel
|
||||
|
||||
Die folgende Methode `stopRunFromBackend()` zeigt ein typisches Long Method Problem:
|
||||
|
||||
### Vorher (Problematischer Code)
|
||||
|
||||
```java
|
||||
public static void stopRunFromBackend(String message){
|
||||
// Zustandsänderungen
|
||||
isAutoRunActive = false;
|
||||
if (isSleeping)
|
||||
wakeUpFromSleep();
|
||||
else
|
||||
DataRegister.resetPC();
|
||||
|
||||
// UI-Erstellung und -Konfiguration
|
||||
Stage stoppedStage = new Stage();
|
||||
stoppedStage.setTitle("Programm unterbrochen!");
|
||||
VBox vbox = new VBox();
|
||||
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||
vbox.getChildren().add(ueberlabel);
|
||||
vbox.getChildren().add(grundlabel);
|
||||
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||
Scene scene = new Scene(vbox, 300, 90);
|
||||
stoppedStage.setAlwaysOnTop(true);
|
||||
stoppedStage.setScene(scene);
|
||||
stoppedStage.show();
|
||||
}
|
||||
```
|
||||
|
||||
### Identifizierte Probleme
|
||||
|
||||
- **Vermischte Verantwortlichkeiten**: Die Methode kombiniert Geschäftslogik (Zustandsänderungen) mit UI-Code
|
||||
- **Schwere Testbarkeit**: UI-Code kann nicht isoliert von der Geschäftslogik getestet werden
|
||||
- **Code-Duplikation**: Wird die Dialog-Funktionalität anderswo benötigt, muss der gesamte UI-Code kopiert werden
|
||||
|
||||
## Lösung: Extract Method Refactoring
|
||||
|
||||
Die **Extract Method** Technik löst das Problem durch Aufspaltung der langen Methode in kleinere, fokussierte Methoden:
|
||||
|
||||
### Nachher (Refactorierter Code)
|
||||
|
||||
```java
|
||||
public static void stopRunFromBackend(String message){
|
||||
handleExecutionStop();
|
||||
showInterruptionDialog(message);
|
||||
}
|
||||
|
||||
private static void handleExecutionStop(){
|
||||
isAutoRunActive = false;
|
||||
if (isSleeping)
|
||||
wakeUpFromSleep();
|
||||
else
|
||||
DataRegister.resetPC();
|
||||
}
|
||||
|
||||
private static void showInterruptionDialog(String message){
|
||||
Stage stoppedStage = new Stage();
|
||||
stoppedStage.setTitle("Programm unterbrochen!");
|
||||
|
||||
VBox vbox = new VBox();
|
||||
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
|
||||
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
|
||||
vbox.getChildren().addAll(ueberlabel, grundlabel);
|
||||
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||
|
||||
Scene scene = new Scene(vbox, 300, 90);
|
||||
stoppedStage.setAlwaysOnTop(true);
|
||||
stoppedStage.setScene(scene);
|
||||
stoppedStage.show();
|
||||
}
|
||||
```
|
||||
|
||||
## Vorteile der Lösung
|
||||
|
||||
- **Klare Trennung der Verantwortlichkeiten**: Geschäftslogik und UI-Code sind getrennt
|
||||
- **Verbesserte Lesbarkeit**: Jede Methode hat einen klaren, fokussierten Zweck
|
||||
- **Erhöhte Wiederverwendbarkeit**: `showInterruptionDialog()` kann in anderen Kontexten genutzt werden
|
||||
- **Bessere Testbarkeit**: Geschäftslogik und UI können separat getestet werden
|
||||
|
||||
|
||||
# Code Smell 2: Large Class
|
||||
|
||||
## Beschreibung des Problems
|
||||
|
||||
Eine **Large Class** entsteht, wenn eine Klasse zu viele Verantwortlichkeiten übernimmt und dadurch überladen wird. Typische Kennzeichen sind:
|
||||
|
||||
- **Hohe Anzahl an Instanzvariablen**: Die Klasse verwaltet zu viele verschiedene Datentypen
|
||||
- **Viele Methoden**: Unterschiedliche Funktionsbereiche werden in einer Klasse gemischt
|
||||
- **Multiple Domänenaspekte**: Logik, Darstellung, Benutzerinteraktion und Statusverwaltung in einer Klasse
|
||||
|
||||
## Praktisches Beispiel
|
||||
|
||||
Die Klasse `Controller_Frontend` zeigt typische Large Class Probleme:
|
||||
|
||||
### Identifizierte Probleme
|
||||
|
||||
```java
|
||||
public class Controller_Frontend {
|
||||
// GUI-Elemente
|
||||
@FXML private Button startButton;
|
||||
@FXML private Button pauseButton;
|
||||
@FXML private Label statusLabel;
|
||||
|
||||
// Zustandsverwaltung (gehört nicht hierher!)
|
||||
private static boolean isAutoRunActive = false;
|
||||
private static boolean isSleeping = false;
|
||||
private static double executionTimeMultiplier = 1.0;
|
||||
|
||||
// GUI-Steuerung
|
||||
public void handleStart() { /* ... */ }
|
||||
public void handlePause() { /* ... */ }
|
||||
|
||||
// Zustandslogik (gehört nicht hierher!)
|
||||
public void sleep() { isSleeping = true; }
|
||||
public void wakeUpFromSleep() { isSleeping = false; }
|
||||
|
||||
// ... viele weitere Methoden
|
||||
}
|
||||
```
|
||||
|
||||
### Auswirkungen
|
||||
|
||||
- **Schwere Wartbarkeit**: Änderungen in einem Bereich können unbeabsichtigte Nebeneffekte verursachen
|
||||
- **Reduzierte Testbarkeit**: Verschiedene Aspekte können nicht isoliert getestet werden
|
||||
- **Unübersichtlichkeit**: Die Klasse wird schnell unhandlich und schwer verständlich
|
||||
- **Violierung des Single Responsibility Principle**: Eine Klasse sollte nur einen Grund zur Änderung haben
|
||||
|
||||
## Lösung: Extract Class Refactoring
|
||||
|
||||
Die Lösung besteht in der Auslagerung der Zustandsverwaltung in eine separate, spezialisierte Klasse:
|
||||
|
||||
### Neue ExecutionState Klasse
|
||||
|
||||
```java
|
||||
/**
|
||||
* Zentrale Verwaltung aller Ausführungszustände.
|
||||
* Diese Klasse kapselt alle zustandsbezogenen Operationen
|
||||
* und bietet eine saubere API für den Zugriff darauf.
|
||||
*/
|
||||
public class ExecutionState {
|
||||
private static boolean isAutoRunActive = false;
|
||||
private static boolean isSleeping = false;
|
||||
private static double executionTimeMultiplier = 1.0;
|
||||
|
||||
// AutoRun-Zustand
|
||||
public static boolean isAutoRunActive() {
|
||||
return isAutoRunActive;
|
||||
}
|
||||
|
||||
public static void setAutoRunActive(boolean active) {
|
||||
isAutoRunActive = active;
|
||||
}
|
||||
|
||||
// Sleep-Zustand
|
||||
public static boolean isSleeping() {
|
||||
return isSleeping;
|
||||
}
|
||||
|
||||
public static void sleep() {
|
||||
isSleeping = true;
|
||||
}
|
||||
|
||||
public static void wakeUp() {
|
||||
isSleeping = false;
|
||||
}
|
||||
|
||||
// Ausführungsgeschwindigkeit
|
||||
public static double getExecutionTimeMultiplier() {
|
||||
return executionTimeMultiplier;
|
||||
}
|
||||
|
||||
public static void setExecutionTimeMultiplier(double multiplier) {
|
||||
if (multiplier > 0) {
|
||||
executionTimeMultiplier = multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
// Hilfsmethoden
|
||||
public static void reset() {
|
||||
isAutoRunActive = false;
|
||||
isSleeping = false;
|
||||
executionTimeMultiplier = 1.0;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Refactorierte Controller Klasse
|
||||
|
||||
```java
|
||||
public class Controller_Frontend {
|
||||
// Nur noch GUI-Elemente
|
||||
@FXML private Button startButton;
|
||||
@FXML private Button pauseButton;
|
||||
@FXML private Label statusLabel;
|
||||
|
||||
// Verwendung der ExecutionState Klasse
|
||||
public void stopRunFromBackend(String message) {
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
|
||||
if (ExecutionState.isSleeping()) {
|
||||
ExecutionState.wakeUp();
|
||||
} else {
|
||||
DataRegister.resetPC();
|
||||
}
|
||||
|
||||
showInterruptionDialog(message);
|
||||
}
|
||||
|
||||
// Weitere GUI-Methoden...
|
||||
}
|
||||
```
|
||||
|
||||
## Vorteile der Lösung
|
||||
|
||||
- **Klare Verantwortlichkeiten**: Controller fokussiert sich auf GUI, ExecutionState auf Zustandsverwaltung
|
||||
- **Verbesserte Testbarkeit**: Zustandslogik kann isoliert getestet werden
|
||||
- **Erhöhte Wiederverwendbarkeit**: ExecutionState kann in anderen Klassen genutzt werden
|
||||
- **Bessere Wartbarkeit**: Änderungen an der Zustandslogik betreffen nur eine Klasse
|
||||
|
||||
|
||||
# Code Smell 3: Shotgun Surgery
|
||||
|
||||
## Beschreibung des Problems
|
||||
|
||||
**Shotgun Surgery** tritt auf, wenn eine kleine fachliche Änderung Modifikationen an vielen verschiedenen Stellen im Code erfordert. Dieses Anti-Pattern entsteht durch:
|
||||
|
||||
- **Zu starke Verteilung**: Zusammengehörige Funktionalität ist über viele Klassen und Methoden verstreut
|
||||
- **Mangelnde Kapselung**: Ähnliche Operationen sind nicht zentral gebündelt
|
||||
- **Duplizierte Logik**: Gleiche oder ähnliche Code-Fragmente existieren an mehreren Stellen
|
||||
|
||||
## Praktisches Beispiel
|
||||
|
||||
Die Schlafmodus-Funktionalität war ursprünglich über mehrere Bereiche verteilt:
|
||||
|
||||
### Vor dem Refactoring (Problematische Verteilung)
|
||||
|
||||
```java
|
||||
// In Controller_Frontend
|
||||
private boolean isSleeping = false;
|
||||
|
||||
public void enterSleepMode() {
|
||||
isSleeping = true;
|
||||
// Logging hier
|
||||
System.out.println("Entering sleep mode");
|
||||
}
|
||||
|
||||
// In ExecutionEngine
|
||||
private boolean sleepState = false;
|
||||
|
||||
public void pauseExecution() {
|
||||
sleepState = true;
|
||||
// Ähnliches Logging dort
|
||||
System.out.println("Execution paused - sleep mode");
|
||||
}
|
||||
|
||||
// In StatusManager
|
||||
public void checkSleepStatus() {
|
||||
if (someCondition) {
|
||||
// Wieder ähnlicher Code
|
||||
setSleeping(true);
|
||||
System.out.println("Sleep mode activated");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Identifizierte Probleme
|
||||
|
||||
- **Mehrfache Implementierung**: Sleep-Logik existiert in verschiedenen Varianten
|
||||
- **Inkonsistente Zustände**: Verschiedene Klassen können unterschiedliche Sleep-Zustände haben
|
||||
- **Hoher Änderungsaufwand**: Neue Sleep-Features müssen an mehreren Stellen implementiert werden
|
||||
- **Fehleranfälligkeit**: Beim Hinzufügen neuer Funktionen können leicht Stellen vergessen werden
|
||||
|
||||
## Lösung: Zentralisierung durch Extract Class
|
||||
|
||||
Die Lösung besteht in der Konsolidierung aller sleep-bezogenen Operationen in der `ExecutionState` Klasse:
|
||||
|
||||
### Zentralisierte Lösung
|
||||
|
||||
```java
|
||||
public class ExecutionState {
|
||||
private static boolean isSleeping = false;
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExecutionState.class);
|
||||
|
||||
/**
|
||||
* Aktiviert den Schlafmodus mit einheitlichem Logging und Zustandsmanagement
|
||||
*/
|
||||
public static void sleep() {
|
||||
if (!isSleeping) {
|
||||
isSleeping = true;
|
||||
logger.info("Sleep mode activated");
|
||||
notifyStateChange("SLEEP_ACTIVATED");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deaktiviert den Schlafmodus
|
||||
*/
|
||||
public static void wakeUp() {
|
||||
if (isSleeping) {
|
||||
isSleeping = false;
|
||||
logger.info("Waking up from sleep mode");
|
||||
notifyStateChange("SLEEP_DEACTIVATED");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Überprüft den aktuellen Schlafzustand
|
||||
*/
|
||||
public static boolean isSleeping() {
|
||||
return isSleeping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Erweiterte Sleep-Funktionalität mit Timeout
|
||||
*/
|
||||
public static void sleepWithTimeout(long milliseconds) {
|
||||
sleep();
|
||||
Timer timer = new Timer();
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
wakeUp();
|
||||
}
|
||||
}, milliseconds);
|
||||
}
|
||||
|
||||
private static void notifyStateChange(String event) {
|
||||
// Zentrale Benachrichtigung für alle interessierten Komponenten
|
||||
EventBus.getInstance().publish(new StateChangeEvent(event));
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Vereinfachte Nutzung in anderen Klassen
|
||||
|
||||
```java
|
||||
// In Controller_Frontend
|
||||
public void handleSleepButton() {
|
||||
ExecutionState.sleep();
|
||||
updateUI();
|
||||
}
|
||||
|
||||
// In ExecutionEngine
|
||||
public void pauseIfNeeded() {
|
||||
if (shouldPause()) {
|
||||
ExecutionState.sleep();
|
||||
}
|
||||
}
|
||||
|
||||
// In StatusManager
|
||||
public void checkAndActivateSleep() {
|
||||
if (criticalCondition()) {
|
||||
ExecutionState.sleepWithTimeout(5000); // 5 Sekunden Sleep
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Vorteile der Lösung
|
||||
|
||||
- **Einheitliche Implementierung**: Alle sleep-bezogenen Operationen verwenden dieselbe Logik
|
||||
- **Zentrale Wartung**: Änderungen müssen nur an einer Stelle vorgenommen werden
|
||||
- **Konsistente Zustände**: Nur eine Quelle der Wahrheit für den Sleep-Zustand
|
||||
- **Erweiterte Funktionalität**: Neue Features (wie Timeout) können zentral hinzugefügt werden
|
||||
- **Bessere Nachverfolgbarkeit**: Einheitliches Logging und Event-System
|
||||
|
||||
# Anwendung von Programmierprinzipien im Projekt
|
||||
|
||||
## Einleitung
|
||||
Im Rahmen der Refaktorisierung und Weiterentwicklung des Projekts wurde besonderer Fokus auf die Einhaltung zentraler Programmierprinzipien gelegt. Die folgenden Prinzipien wurden gezielt analysiert und angewendet:
|
||||
|
||||
## 1. SOLID-Prinzipien
|
||||
|
||||
### Single Responsibility Principle (SRP)
|
||||
Die Methode `stopRunFromBackend()` wurde in zwei unabhängige Methoden aufgeteilt:
|
||||
|
||||
```java
|
||||
public void stopRunFromBackend(String message) {
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
handleSleepOrReset();
|
||||
showStopDialog(message);
|
||||
}
|
||||
|
||||
private void handleSleepOrReset() {
|
||||
if (ExecutionState.isSleeping()) {
|
||||
ExecutionState.wakeUp();
|
||||
} else {
|
||||
dataRegister.resetPC();
|
||||
}
|
||||
}
|
||||
|
||||
private static void showStopDialog(String message) {
|
||||
// GUI-Erzeugung...
|
||||
}
|
||||
```
|
||||
|
||||
### Open/Closed Principle (OCP)
|
||||
Die Klasse `ExecutionState` kapselt erweiterbare Zustandslogik, ohne dass bestehende Methoden geändert werden müssen:
|
||||
|
||||
```java
|
||||
public class ExecutionState {
|
||||
private static boolean isAutoRunActive;
|
||||
private static boolean isSleeping;
|
||||
|
||||
public static boolean isSleeping() { return isSleeping; }
|
||||
public static void wakeUp() { isSleeping = false; }
|
||||
public static void setAutoRunActive(boolean value) {
|
||||
isAutoRunActive = value;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Liskov Substitution Principle (LSP)
|
||||
`Controller_Frontend` implementiert ein Interface, wodurch die Substituierbarkeit gemäß LSP gewährleistet ist:
|
||||
|
||||
```java
|
||||
public class Controller_Frontend extends PICComponent
|
||||
implements FrontendControllerInterface { }
|
||||
|
||||
public void resetPC() {
|
||||
programCounter = 0;
|
||||
}
|
||||
```
|
||||
|
||||
### Interface Segregation Principle (ISP)
|
||||
Spezialisierte Interfaces sorgen dafür, dass Klassen nur relevante Funktionen implementieren:
|
||||
|
||||
```java
|
||||
public interface TimerInterface {
|
||||
void start();
|
||||
void stop();
|
||||
int getCurrentTime();
|
||||
}
|
||||
```
|
||||
|
||||
### Dependency Inversion Principle (DIP)
|
||||
Zentrale Komponenten wie `PICComponentLocator` und Interfaces lösen die Abhängigkeit von konkreten Klassen:
|
||||
|
||||
```java
|
||||
private PICComponentLocator picComponents;
|
||||
```
|
||||
|
||||
## 2. GRASP-Prinzipien
|
||||
|
||||
### Low Coupling
|
||||
Die Kopplung im Projekt ist durch Verwendung zentraler Zugriffsklassen wie `PICComponentLocator` gering gehalten.
|
||||
|
||||
```java
|
||||
private PICComponentLocator picComponents;
|
||||
```
|
||||
|
||||
### High Cohesion
|
||||
Funktionen übernehmen jeweils thematisch zusammenhängende Aufgaben:
|
||||
|
||||
```java
|
||||
public static void showStopDialog(String message) {
|
||||
Stage stoppedStage = new Stage();
|
||||
VBox vbox = new VBox();
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
// GUI-Details ausgelassen
|
||||
stoppedStage.show();
|
||||
}
|
||||
```
|
||||
|
||||
## 3. DRY – Don’t Repeat Yourself
|
||||
Wiederverwendbare Logik zur Statuskontrolle wurde in `ExecutionState` gekapselt. GUI-Erzeugung findet zentral in `showStopDialog()` statt:
|
||||
|
||||
```java
|
||||
public class ExecutionState {
|
||||
private static boolean isSleeping;
|
||||
public static boolean isSleeping() { return isSleeping; }
|
||||
public static void wakeUp() { isSleeping = false; }
|
||||
}
|
||||
|
||||
private static void showStopDialog(String message) {
|
||||
// einmal zentral definierte GUI-Logik
|
||||
}
|
||||
317
paul.qmd
Normal file
317
paul.qmd
Normal file
@ -0,0 +1,317 @@
|
||||
---
|
||||
lang: de
|
||||
format:
|
||||
pdf:
|
||||
toc: true
|
||||
number-sections: true
|
||||
colorlinks: true
|
||||
crossref:
|
||||
custom:
|
||||
- kind: float
|
||||
reference-prefix: UML-Diagramm
|
||||
key: uml
|
||||
latex-env: uml
|
||||
latex-list-of-description: UML-Diagramme
|
||||
---
|
||||
|
||||
{{< pagebreak >}}
|
||||
|
||||
# Entwurfsmuster
|
||||
Zusätzlich zu den beiden im Folgenden dargestellten Entwursmustern benutzen wir einen [Service Locator](https://en.wikipedia.org/wiki/Service_locator_pattern), der zu den [Architectural Patterns](https://en.wikipedia.org/wiki/Architectural_pattern) zählt. Dieses Pattern nutzt ein `HashMap`, in der verschiedene Komponenten des Programms gespeichert werden, um das Komponenten-Management zu vereinfachen und explizite Abhängigkeiten der Komponenten untereinander zu vermeiden, die das Initialisieren der einzelnen Komponenten erschweren könnten.
|
||||
In unserem Projekt fungiert [`PICComponentLocator`](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/c38835fd7b47c662a344c9ab2c41e0527760bd61/src/main/java/fabrik/simulator/pic16f84/PICComponentLocator.java) als dieser Locator. Er besitzt einen `componentCatalogue` als Member, der eine `Map<Class<? extends PICComponentInterface>, PICComponentInterface>` ist. Das bedeutet, dass alle Klassen, die durch den Locator gemanaget werden sollen, das `PICComponentInterface` implementieren müssen.
|
||||
|
||||
Um nicht bei allen Zugriffen die `PICComponentLocator.getComponent()` ausführen zu müssen, wurde zusätzlich die `abstract` Klasse `PICComponent` [eingeführt]. Sie besitzt als Member alle implementierten Komponenten, also sollten neue Komponenten ebenfalls das Interface implementieren und als Member in `PICComponent` angelegt werden. Alle Komponenten können diese Klasse `extend`en und dadurch auch alle weiteren Komponenten als Member haben, dies ist auch in @uml-observer dargestellt [^1]. Durch die `initialize`-Funktion des `PICComponent` werden durch einen Aufruf der `PICComponentLocator.initAll()` alle Member vom Locator geholt.
|
||||
|
||||
## Marker-Entwurfsmuster
|
||||
[Marker-Patterns](https://en.wikipedia.org/wiki/Marker_interface_pattern) werden allgemein genutzt, um Klassen Metadaten zuzuordnen. In unserem Projekt stellen die `FrontendSpecific`-Interfaces Marker dar, die genutzt werden um zu kommunizieren, dass Klassen andere Klassen benötigen, die Frontend-spezifisch sind und somit besonders beachtet werden müssen. So können alle [`Interface`s](LINK ZU ORDNER) definiert werden ohne direkt von fremdem Code abhängig zu sein. Bei möglichen anderen Frontend-Implementierungen müssten entsprechend nur die passenden Klassen die jeweiligen Interfaces implementieren und nichts an den Interfaces ändern.
|
||||
Eingeführt wurden die `FrontendSpecific`s in [diesem Commit](https://git.paulmartin.cloud/paul/PIC-Simu/commit/06e934801645e32dea5415ccb4f38368a1667df6) ([hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/ef3b0fce5f9b6cce06494ff6ce59f5534064e7d2) verfollständigt). Es wurde zunächst ein `FrontendSpecificObject`-Interface angelegt, das alle Frontend-spezifischen Klassen beschreibt, die von Methoden anderer Klassen genutzt werden (sprich, die in den [`Interface`s](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/f28603843d7ef6cbf4666ab2b2ceda02ca411eb7/src/main/java/fabrik/simulator/pic16f84/interfaces) vorkommen). Es ist - entsprechend des Marker-Patterns - komplett leer [definiert](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/f28603843d7ef6cbf4666ab2b2ceda02ca411eb7/src/main/java/fabrik/simulator/pic16f84/frontendspecifics/FrontendSpecificObject.java):
|
||||
```java
|
||||
public interface FrontendSpecificObject {
|
||||
}
|
||||
```
|
||||
Zusätzlich gibt es für spezifische Frontend-Klassen auch `FrontendSpecific`-Interfaces, sodass nach wie vor nur bestimmte Klassen über- bzw. zurückgegeben werden können. Diese spezifischen Interfaces sind ebenfalls leer, nur nutzen sie `extends FrontendSpecificObject` um zu verdeutlichen, dass sie zu den allgemeinen `FrontendSpecificObject`s gehören. Hier beispielsweise [`FrontendSpecificCircle`](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/ef3b0fce5f9b6cce06494ff6ce59f5534064e7d2/src/main/java/fabrik/simulator/pic16f84/frontendspecifics/FrontendSpecificCircle.java):
|
||||
```java
|
||||
public interface FrontendSpecificCircle extends FrontendSpecificObject {
|
||||
}
|
||||
```
|
||||
Tatsächlich genutzt werden die `FrontendSpecific`-Interfaces von [Circle], [ToggleButtonGroup] und [Vbox]. Sie `extenden` ihr jeweiliges `JavaFX`-Pendant und `implementen` ihr jeweiliges `FrontendSpecific`-Interface. Darüber hinaus implementieren sie nur die nötigen (also im Code tatsächlich genutzten) Konstruktoren, die wiederum nur `super()` aufrufen, hier bspw. [`ToggleButtonGroup`]:
|
||||
```java
|
||||
public class ToggleButtonGroup extends
|
||||
com.gluonhq.charm.glisten.control.ToggleButtonGroup
|
||||
implements FrontendSpecificToggleButtonGroup {
|
||||
public ToggleButtonGroup(){
|
||||
super();
|
||||
}
|
||||
|
||||
public ToggleButtonGroup(ToggleButton... toggles) {
|
||||
super(toggles);
|
||||
}
|
||||
}
|
||||
```
|
||||
Alle für das Marker-Pattern eingeführten Klassen sind in @uml-marker erkennbar [^1]:
|
||||
|
||||
::: {#uml-marker}
|
||||
|
||||
```{mermaid}
|
||||
%%| fig-width: 6.5
|
||||
classDiagram
|
||||
direction TB
|
||||
class FrontendSpecificObject {
|
||||
<<Interface>>
|
||||
}
|
||||
class FrontendSpecificToggleButtonGroup {
|
||||
<<Interface>>
|
||||
}
|
||||
class ToggleButtonGroup {
|
||||
public ToggleButtonGroup()
|
||||
public ToggleButtonGroup(ToggleButton... toggles)
|
||||
}
|
||||
|
||||
class `com.gluonhq.charm.glisten.control.ToggleButtonGroup` {
|
||||
...
|
||||
....()
|
||||
}
|
||||
|
||||
FrontendSpecificObject <|-- FrontendSpecificToggleButtonGroup : << extends >>
|
||||
FrontendSpecificToggleButtonGroup <|-- ToggleButtonGroup : << implements >>
|
||||
`com.gluonhq.charm.glisten.control.ToggleButtonGroup` <|-- ToggleButtonGroup : << extends >>
|
||||
|
||||
class FrontendSpecificVBox{
|
||||
<<Interface>>
|
||||
}
|
||||
class VBox {
|
||||
public VBox()
|
||||
}
|
||||
|
||||
class `javafx.scene.layout.VBox` {
|
||||
...
|
||||
....()
|
||||
}
|
||||
|
||||
FrontendSpecificObject <|-- FrontendSpecificVBox : << extends >>
|
||||
FrontendSpecificVBox <|-- VBox : << implements >>
|
||||
`javafx.scene.layout.VBox` <|-- VBox : << extends >>
|
||||
|
||||
class FrontendSpecificCircle {
|
||||
<<Interface>>
|
||||
}
|
||||
class Circle {
|
||||
public Circle()
|
||||
}
|
||||
|
||||
class `javafx.scene.shape.Circle` {
|
||||
...
|
||||
....()
|
||||
}
|
||||
|
||||
|
||||
FrontendSpecificObject <|-- FrontendSpecificCircle : << extends >>
|
||||
FrontendSpecificCircle <|-- Circle : << implements >>
|
||||
`javafx.scene.shape.Circle` <|-- Circle : << extends >>
|
||||
|
||||
class PICComponentInterface{
|
||||
<<Interface>>
|
||||
+ initialize(PICComponentLocator picComponents)
|
||||
}
|
||||
|
||||
class WindowManagement{
|
||||
<<Interface>>
|
||||
refreshTable()$
|
||||
startFromMain(String[] args)$
|
||||
}
|
||||
|
||||
FrontendSpecificObject <|-- WindowManagement : << extends >>
|
||||
PICComponentInterface <|-- WindowManagement : << extends >>
|
||||
|
||||
```
|
||||
|
||||
Das genutzte Marker-Pattern und alle seine Verwendungen.
|
||||
:::
|
||||
## Beobachter- (/Observer-) Entwurfsmuster
|
||||
[Beobachter-Entwurfsmuster](https://en.wikipedia.org/wiki/Observer_pattern) werden genutzt, damit ein Subjekt mehrere Beobachter über eine Zustandsänderung informieren kann. In unserem Projekt passiert das bei einer Änderung der `totalExecutionTime`. Das Subjekt `ExecutionTimeSubject` führt hierbei ein `Set` an Beobachtern, die bei uns durch das Interface `ExecutionTimeObserver` repräsentiert werden, welches durch die `registerObserver`- und `unregisterObserver`-Funktionen verwaltet werden kann. Bei einer Zustandsänderung muss die `notifyObservers`-Funktion aufgerufen werden, welche für alle Observer die im Interface spezifizierte `executionTimeChanged`-Funktion aufruft. Die Implementierung wurde [hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/85bc6e9ebae4655ba3ad7ee360332010edc910dd) begonnen, [hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/cf6bcd8498cd2d03e85b0c5f6faaaed935d3a155) vereinfacht um das Threading des Frontends zu respektieren und [hier](https://git.paulmartin.cloud/paul/PIC-Simu/commit/52d63523341179c3c49e0ac31a60a8d7c11cdddc) in die letzten Tests eingefügt.
|
||||
In der aktuellen Umsetzung übernimmt die [`Commands`](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/ef3b0fce5f9b6cce06494ff6ce59f5534064e7d2/src/main/java/fabrik/simulator/pic16f84/Commands.java)-Klasse gleichzeitig die Rolle des `ExecutionTimeSubject`s und `CommandsInterface`s. Deshalb [wird in der `Main`-Klasse](https://git.paulmartin.cloud/paul/PIC-Simu/src/commit/85bc6e9ebae4655ba3ad7ee360332010edc910dd/src/main/java/fabrik/simulator/pic16f84/Main.java) das `Commands`-Objekt dem `ComponentLocator` sowohl für die `ExecutionTimeSubject.class` als auch für die `CommandInterface.class` hinzugefügt. `ExecutionTimeObserver` sind die Klassen, die vorher `commands.getTotalExecutionTime()` gepollt haben. Die Implementierung dieses Entwursmusters ist in @uml-observer erkennbar [^1]:
|
||||
|
||||
:::{#uml-observer}
|
||||
|
||||
```{mermaid}
|
||||
%%| fig-width: 6.5
|
||||
classDiagram
|
||||
direction TB
|
||||
class PICComponentInterface{
|
||||
<<Interface>>
|
||||
+ initialize(PICComponentLocator picComponents)
|
||||
}
|
||||
|
||||
|
||||
class CommandInterface {
|
||||
<<Interface>>
|
||||
+ CALL(int isr);
|
||||
|
||||
+ get_wRegister();
|
||||
|
||||
+ decode(int i);
|
||||
}
|
||||
|
||||
|
||||
class PICComponent{
|
||||
<<Abstract>>
|
||||
# DataRegisterInterface dataRegister
|
||||
...
|
||||
|
||||
+ initialize(PICComponentLocator locator)
|
||||
}
|
||||
|
||||
|
||||
class ExecutionTimeSubject{
|
||||
<<Abstract>>
|
||||
- Set~ExecutionTimeObserver~ observers
|
||||
|
||||
+ registerObserver(ExecutionTimeObserver observer)
|
||||
+ unregisterObserver(ExecutionTimeObserver observer)
|
||||
+ getTotalExecutionTime()
|
||||
+ addExecutionTime(int i)
|
||||
+ getExecutionTimeMultiplier()
|
||||
# notifyObservers()
|
||||
....()
|
||||
}
|
||||
|
||||
|
||||
class Commands{
|
||||
- wRegister
|
||||
- totalExecutionTime
|
||||
- executionTimeMultiplier
|
||||
....()
|
||||
}
|
||||
|
||||
class FrontendSpecificObject {
|
||||
<<Interface>>
|
||||
}
|
||||
|
||||
class FrontendControllerInterface{
|
||||
<<Interface>>
|
||||
+ getPORTbuttons() FrontendSpecificToggleButtonGroup[]
|
||||
+ getTRISbuttons() FrontendSpecificToggleButtonGroup[]
|
||||
+ stopRunFromBackend(String watchdogTimer)
|
||||
}
|
||||
|
||||
|
||||
class Controller_Frontend {
|
||||
...
|
||||
....()
|
||||
}
|
||||
|
||||
class TimerInterface {
|
||||
<<Interface>>
|
||||
+ cycles(int i)
|
||||
+ incrementFromPin(int directRegister)
|
||||
+ increment(boolean manual)
|
||||
}
|
||||
|
||||
class Timer {
|
||||
...
|
||||
....()
|
||||
}
|
||||
|
||||
|
||||
class EEPROMInterface {
|
||||
<<Interface>>
|
||||
registerTime(double executionTime, boolean b)
|
||||
parse(int i, int content, int i1)
|
||||
read(int address) long
|
||||
write(int address, long data)
|
||||
}
|
||||
|
||||
class EEPROM {
|
||||
...
|
||||
....()
|
||||
}
|
||||
|
||||
|
||||
class ExecutionTimeObserver {
|
||||
<<Interface>>
|
||||
+ executionTimeChanged()
|
||||
}
|
||||
|
||||
ExecutionTimeObserver <|-- Timer : << implements >>
|
||||
TimerInterface <|-- Timer : << implements >>
|
||||
PICComponent <|-- Timer : << extends >>
|
||||
PICComponentInterface <|-- TimerInterface : << extends >>
|
||||
PICComponentInterface <|-- EEPROMInterface : << extends >>
|
||||
ExecutionTimeObserver <|-- EEPROM : << implements >>
|
||||
EEPROMInterface <|-- EEPROM : << implements >>
|
||||
PICComponent <|-- EEPROM : << extends >>
|
||||
ExecutionTimeObserver <|-- Controller_Frontend : << implements >>
|
||||
PICComponent <|-- Controller_Frontend : << extends >>
|
||||
PICComponentInterface <|-- PICComponent : << implements >>
|
||||
PICComponentInterface <|-- FrontendControllerInterface : << extends >>
|
||||
FrontendControllerInterface <|-- Controller_Frontend : << implements >>
|
||||
FrontendSpecificObject <|-- FrontendControllerInterface : << extends >>
|
||||
CommandInterface <|-- Commands : << implements >>
|
||||
ExecutionTimeSubject <|-- Commands : << extends >>
|
||||
PICComponent <|-- ExecutionTimeSubject : << extends >>
|
||||
PICComponentInterface <|-- CommandInterface : << extends >>
|
||||
|
||||
```
|
||||
|
||||
Das genutzte Observer-Pattern und seine Verwendungen im (Nicht-Test-) Code.
|
||||
:::
|
||||
|
||||
[^1]: Für das Pattern unwichtige Funktionen und Variablen wurden ausgelassen
|
||||
|
||||
|
||||
# Clean Architecture
|
||||
|
||||
Die Clean Architecture ist darauf ausgelegt, Softwareprojekte langfristig betreibbar, flexibel und wartbar zu halten. Dazu wird das Projekt in **konzentrische Schichten** unterteilt, in denen die **Abhängigkeitsrichtung stets von außen nach innen** verläuft – die sogenannte *Dependency Rule*. Der Kern der Anwendung bleibt dabei vollständig unabhängig von technischen Details wie Benutzeroberflächen, Datenbanken oder Netzwerken.
|
||||
|
||||
In unserem Projekt haben wir diese Schichtarchitektur wie folgt umgesetzt:
|
||||
|
||||
## 1. Interface/Adapter-Schicht
|
||||
|
||||
Diese Schicht enthält alle Klassen, die als Schnittstelle zwischen der Anwendung und der Benutzeroberfläche dienen.
|
||||
Dazu zählen alle Klassen im Package, `fabrik.simulator.pic16f84.frontendspecifics` insbesondere:
|
||||
|
||||
- `Controller_Frontend`
|
||||
- `CreateWindow`
|
||||
- `IOPorts`
|
||||
- `ToggleButtonGroupExt`
|
||||
|
||||
Diese Klassen erben vom `FrontendSpecificObject` und sind spezifisch für die grafische Oberfläche. Sie implementieren die Schnittstellen der inneren Schichten und leiten Benutzerinteraktionen weiter.
|
||||
|
||||
## 2. Application Code
|
||||
|
||||
Die nächstinnere Schicht beinhaltet die anwendungsspezifische Logik – unsere *Use Cases*. Dazu zählen sämtliche Klassen im Package `fabrik.simulator.pic16f84`, **sofern sie nicht vom `FrontendSpecificObject` erben**. Diese Schicht ist weitgehend unabhängig von der GUI und bleibt stabil, selbst wenn sich die Darstellung oder Eingabeform ändert.
|
||||
Diese Klassen gehören zur Anwendungslogik:
|
||||
|
||||
- `Timer`
|
||||
- `PreScaler`
|
||||
- `WatchdogTimer`
|
||||
- `ProgrammStack`
|
||||
|
||||
## Main-Klasse als Plugin
|
||||
|
||||
Die `Main`-Klasse bildet den äußeren Rahmen (Plugin-Schicht) und initialisiert die gesamte Anwendung:
|
||||
|
||||
- Es werden alle Objekte erzeugt und dem `Locator` zugewiesen.
|
||||
- Das `WindowManagement` startet das Frontend.
|
||||
|
||||
Ein besonders interessanter Aspekt: Wenn man sämtliche Referenzen auf das Frontend (z. B. in Zeile 19, 20, 23) entfernt, lässt sich die App **trotzdem erfolgreich starten und nutzen**. Das zeigt, dass die Schichten entkoppelt sind – ein zentrales Ziel der Clean Architecture.
|
||||
|
||||
\newpage
|
||||
|
||||
## Visualisierung
|
||||
|
||||
```{mermaid}
|
||||
flowchart TB
|
||||
subgraph Interface/Adapter-Schicht
|
||||
A1[Controller_Frontend, CreateWindow, IOPorts, ToggleButtonGroupExt]
|
||||
end
|
||||
subgraph Application Code
|
||||
A2[Use Cases, WatchdogTimer, PreScaler, ProgrammStack, Timer]
|
||||
end
|
||||
subgraph Plugin-Schicht
|
||||
A3[Main.java]
|
||||
end
|
||||
|
||||
A3 --> A1
|
||||
A1 --> A2
|
||||
```
|
||||
25
pom.xml
25
pom.xml
@ -80,6 +80,13 @@
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>5.17.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -113,6 +120,24 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>properties</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@ -1,37 +1,39 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class Commands {
|
||||
private static int wRegister = 0;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
static long totalExecutionTime = 0;
|
||||
public class Commands extends ExecutionTimeSubject implements CommandInterface {
|
||||
private int wRegister;
|
||||
private long totalExecutionTime;
|
||||
private double executionTimeMultiplier = 1;
|
||||
|
||||
|
||||
|
||||
public static int get_wRegister() {
|
||||
return wRegister;
|
||||
}
|
||||
|
||||
public static void addExecutionTime(int i) {
|
||||
totalExecutionTime += i;
|
||||
Timer.cycles(i);
|
||||
EEPROM.registerTime(false);
|
||||
}
|
||||
|
||||
public static long getTotalExecutionTime() {
|
||||
return (long) (totalExecutionTime * Controller_Frontend.getExecutionTimeMultiplier());
|
||||
}
|
||||
|
||||
public static void resetTotalExecutionTime() {
|
||||
public Commands(){
|
||||
super();
|
||||
wRegister = 0;
|
||||
totalExecutionTime = 0;
|
||||
}
|
||||
|
||||
public int get_wRegister() {
|
||||
return wRegister;
|
||||
}
|
||||
|
||||
|
||||
public void addExecutionTime(int i) {
|
||||
totalExecutionTime += i;
|
||||
super.notifyObservers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTotalExecutionTime() {
|
||||
return (totalExecutionTime * getExecutionTimeMultiplier());
|
||||
}
|
||||
|
||||
public void resetTotalExecutionTime() {
|
||||
totalExecutionTime = 0;
|
||||
super.notifyObservers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void decode(int instruction){
|
||||
public void decode(int instruction){
|
||||
final int jumpaddr = 0x7FF;
|
||||
final int fileregaddr = 0x7F;
|
||||
final int constant = 0xFF;
|
||||
@ -62,12 +64,12 @@ public class Commands {
|
||||
switch (instruction & 0x3C00){
|
||||
case 0b01000000000000:
|
||||
System.out.println("BCF: " + f + " " + b);
|
||||
DataRegister.clearBit(f, b);
|
||||
dataRegister.clearBit(f, b);
|
||||
addExecutionTime(1);
|
||||
return;
|
||||
case 0b01010000000000:
|
||||
System.out.println("BSF: " + f + " " + b);
|
||||
DataRegister.setBit(f, b);
|
||||
dataRegister.setBit(f, b);
|
||||
addExecutionTime(1);
|
||||
return;
|
||||
case 0b01100000000000:
|
||||
@ -223,7 +225,7 @@ public class Commands {
|
||||
switch (instruction){
|
||||
case 0b01100100:
|
||||
System.out.println("CLRWDT");
|
||||
WatchdogTimer.reset();
|
||||
watchdogTimer.reset();
|
||||
return;
|
||||
case 0b1001:
|
||||
System.out.println("RETFIE");
|
||||
@ -232,7 +234,7 @@ public class Commands {
|
||||
return;
|
||||
case 0b1000:
|
||||
System.out.println("RETURN");
|
||||
DataRegister.setPC(ProgramStack.pop());
|
||||
dataRegister.setPC(programStack.pop());
|
||||
return;
|
||||
case 0b01100011:
|
||||
System.out.println("SLEEP");
|
||||
@ -249,313 +251,343 @@ public class Commands {
|
||||
else{
|
||||
System.out.println("Nicht gefunden!");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void SLEEP() {
|
||||
Controller_Frontend.sleep ();
|
||||
public void SLEEP() {
|
||||
ExecutionState.sleep();
|
||||
}
|
||||
|
||||
public static void RETFIE() {
|
||||
DataRegister.setBit(DataRegister.getINTCON(), 7); // GIE wieder setzen
|
||||
DataRegister.setPC(ProgramStack.pop());
|
||||
public void RETFIE() {
|
||||
dataRegister.setBit(dataRegister.getINTCON(), 7); // GIE wieder setzen
|
||||
dataRegister.setPC(programStack.pop());
|
||||
}
|
||||
|
||||
public static void NOP () {
|
||||
public void NOP () {
|
||||
System.out.println("NOP");
|
||||
addExecutionTime(1);
|
||||
}
|
||||
|
||||
public static void GOTO(int jump) {
|
||||
DataRegister.setPC(jump-1);
|
||||
public void GOTO(int jump) {
|
||||
dataRegister.setPC(jump-1);
|
||||
}
|
||||
|
||||
public static void CALL(int jump) {
|
||||
ProgramStack.push(DataRegister.getPC()+1);
|
||||
DataRegister.setPC(jump-1);
|
||||
public void CALL(int jump) {
|
||||
programStack.push(dataRegister.getPC()+1);
|
||||
dataRegister.setPC(jump-1);
|
||||
addExecutionTime(1);
|
||||
}
|
||||
|
||||
public static void MOVWF(int file) {
|
||||
DataRegister.setRegister(file, wRegister);
|
||||
public void MOVWF(int file) {
|
||||
dataRegister.setRegister(file, wRegister);
|
||||
}
|
||||
|
||||
public static void CLRW() {
|
||||
public void CLRW() {
|
||||
wRegister = 0;
|
||||
DataRegister.determineZeroFlag(wRegister);
|
||||
dataRegister.determineZeroFlag(wRegister);
|
||||
|
||||
addExecutionTime(1);
|
||||
|
||||
}
|
||||
|
||||
public static void CLRF(int file) {
|
||||
DataRegister.setRegister(file, 0);
|
||||
DataRegister.determineZeroFlag(DataRegister.getRegister(file));
|
||||
public void CLRF(int file) {
|
||||
dataRegister.setRegister(file, 0);
|
||||
dataRegister.determineZeroFlag(dataRegister.getRegister(file));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void IORLW(int literal) {
|
||||
public void IORLW(int literal) {
|
||||
wRegister |= literal;
|
||||
DataRegister.determineZeroFlag(wRegister);
|
||||
dataRegister.determineZeroFlag(wRegister);
|
||||
}
|
||||
|
||||
public static void XORLW(int literal) {
|
||||
public void XORLW(int literal) {
|
||||
wRegister ^= literal;
|
||||
DataRegister.determineZeroFlag(wRegister);
|
||||
dataRegister.determineZeroFlag(wRegister);
|
||||
}
|
||||
|
||||
public static void ANDLW(int literal) {
|
||||
public void ANDLW(int literal) {
|
||||
wRegister &= literal;
|
||||
DataRegister.determineZeroFlag(wRegister);
|
||||
dataRegister.determineZeroFlag(wRegister);
|
||||
}
|
||||
|
||||
public static void XORWF(int file, int destination) {
|
||||
int result = wRegister ^ DataRegister.getRegister(file);
|
||||
public void XORWF(int file, int destination) {
|
||||
int result = wRegister ^ dataRegister.getRegister(file);
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineZeroFlag(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void SWAPF(int file, int destination) {
|
||||
int content = DataRegister.getRegister(file);
|
||||
public void SWAPF(int file, int destination) {
|
||||
int content = dataRegister.getRegister(file);
|
||||
int result = (content & 0x0F) << 4 | (content & 0xF0) >> 4;
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void SUBWF(int file, int destination) {
|
||||
int result = (DataRegister.getRegister(file) - wRegister) ;
|
||||
public void SUBWF(int file, int destination) {
|
||||
int result = (dataRegister.getRegister(file) - wRegister) ;
|
||||
if (wRegister == 0 || result >= 0){
|
||||
DataRegister.setCarryFlag(1);
|
||||
DataRegister.setDigitCarryFlag(1);
|
||||
dataRegister.setCarryFlag(1);
|
||||
dataRegister.setDigitCarryFlag(1);
|
||||
}
|
||||
else {
|
||||
DataRegister.setCarryFlag(0);
|
||||
DataRegister.setDigitCarryFlag(0);
|
||||
dataRegister.setCarryFlag(0);
|
||||
dataRegister.setDigitCarryFlag(0);
|
||||
}
|
||||
if (destination == 0){
|
||||
wRegister = result & 0xFF;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result & 0xFF);
|
||||
dataRegister.setRegister(file, result & 0xFF);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineZeroFlag(result);
|
||||
addExecutionTime(1);
|
||||
}
|
||||
|
||||
public static void RLF(int file, int destination) {
|
||||
int fcontent = DataRegister.getRegister(file);
|
||||
int carry = DataRegister.getCarryFlag();
|
||||
public void RLF(int file, int destination) {
|
||||
int fcontent = dataRegister.getRegister(file);
|
||||
int carry = dataRegister.getCarryFlag();
|
||||
int result = (fcontent << 1) | carry;
|
||||
DataRegister.determineCarryFlag(result);
|
||||
dataRegister.determineCarryFlag(result);
|
||||
if (destination == 0){
|
||||
wRegister = result & 0xFF;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result & 0xFF);
|
||||
dataRegister.setRegister(file, result & 0xFF);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void RRF(int file, int destination) {
|
||||
int fcontent = DataRegister.getRegister(file);
|
||||
int carry = DataRegister.getCarryFlag() << 7;
|
||||
public void RRF(int file, int destination) {
|
||||
int fcontent = dataRegister.getRegister(file);
|
||||
int carry = dataRegister.getCarryFlag() << 7;
|
||||
int contentlow = fcontent & 0b1;
|
||||
int result = (fcontent >> 1) | carry;
|
||||
DataRegister.setCarryFlag(contentlow);
|
||||
dataRegister.setCarryFlag(contentlow);
|
||||
if (destination == 0){
|
||||
wRegister = result & 0xFF;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result & 0xFF);
|
||||
dataRegister.setRegister(file, result & 0xFF);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void MOVF(int file, int destination) {
|
||||
int content = DataRegister.getRegister(file);
|
||||
public void MOVF(int file, int destination) {
|
||||
int content = dataRegister.getRegister(file);
|
||||
if (destination == 0){
|
||||
wRegister = content;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, content);
|
||||
dataRegister.setRegister(file, content);
|
||||
}
|
||||
DataRegister.determineZeroFlag(content);
|
||||
dataRegister.determineZeroFlag(content);
|
||||
}
|
||||
|
||||
public static void IORWF(int file, int destination) {
|
||||
int result = wRegister | DataRegister.getRegister(file);
|
||||
public void IORWF(int file, int destination) {
|
||||
int result = wRegister | dataRegister.getRegister(file);
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
|
||||
dataRegister.determineZeroFlag(result);
|
||||
}
|
||||
|
||||
public static void INCFSZ(int file, int destination) {
|
||||
int result = (DataRegister.getRegister(file) + 1) & 0xFF;
|
||||
public void INCFSZ(int file, int destination) {
|
||||
int result = (dataRegister.getRegister(file) + 1) & 0xFF;
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
addExecutionTime(1);
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
|
||||
}
|
||||
if (result == 0) {
|
||||
DataRegister.increasePC();
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
}
|
||||
|
||||
public static void INCF(int file, int destination) {
|
||||
int result = (DataRegister.getRegister(file) + 1) & 0xFF;
|
||||
public void INCF(int file, int destination) {
|
||||
int result = (dataRegister.getRegister(file) + 1) & 0xFF;
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineZeroFlag(result);
|
||||
|
||||
}
|
||||
|
||||
public static void DECFSZ(int file, int destination) {
|
||||
int result = (DataRegister.getRegister(file) -1) & 0xFF;
|
||||
public void DECFSZ(int file, int destination) {
|
||||
int result = (dataRegister.getRegister(file) -1) & 0xFF;
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
addExecutionTime(1);
|
||||
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
|
||||
}
|
||||
if (result == 0){
|
||||
DataRegister.increasePC();
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
}
|
||||
|
||||
public static void DECF(int file, int destination) {
|
||||
int result = (DataRegister.getRegister(file) -1) & 0xFF;
|
||||
public void DECF(int file, int destination) {
|
||||
int result = (dataRegister.getRegister(file) -1) & 0xFF;
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineZeroFlag(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void COMF(int file, int destination) {
|
||||
int result = (~ DataRegister.getRegister(file)) & 0xFF;
|
||||
private void COMF(int file, int destination) {
|
||||
int result = (~ dataRegister.getRegister(file)) & 0xFF;
|
||||
if (destination == 0){
|
||||
wRegister = result;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result);
|
||||
dataRegister.setRegister(file, result);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineZeroFlag(result);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void ANDWF(int file, int destination) {
|
||||
int result = wRegister & DataRegister.getRegister(file);
|
||||
public void ANDWF(int file, int destination) {
|
||||
int result = wRegister & dataRegister.getRegister(file);
|
||||
if (destination == 0){
|
||||
wRegister = result & 0xFF;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result & 0xFF);
|
||||
dataRegister.setRegister(file, result & 0xFF);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
DataRegister.determineCarryFlag(result);
|
||||
DataRegister.determineDigitCarryFlag((wRegister&0b11101111) & (DataRegister.getRegister(file)&0b1111));
|
||||
dataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineCarryFlag(result);
|
||||
dataRegister.determineDigitCarryFlag((wRegister&0b11101111) & (dataRegister.getRegister(file)&0b1111));
|
||||
|
||||
}
|
||||
|
||||
public static void ADDWF(int file, int destination) {
|
||||
int result = wRegister + DataRegister.getRegister(file);
|
||||
if (wRegister == 0 || DataRegister.getRegister(file) == 0){
|
||||
DataRegister.setCarryFlag(0);
|
||||
DataRegister.setDigitCarryFlag(0);
|
||||
public void ADDWF(int file, int destination) {
|
||||
int result = wRegister + dataRegister.getRegister(file);
|
||||
if (wRegister == 0 || dataRegister.getRegister(file) == 0){
|
||||
dataRegister.setCarryFlag(0);
|
||||
dataRegister.setDigitCarryFlag(0);
|
||||
}
|
||||
else {
|
||||
DataRegister.determineCarryFlag(result);
|
||||
DataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (DataRegister.getRegister(file)&0b1111));
|
||||
dataRegister.determineCarryFlag(result);
|
||||
dataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (dataRegister.getRegister(file)&0b1111));
|
||||
}
|
||||
if (destination == 0) {
|
||||
wRegister = result & 0xFF;
|
||||
}
|
||||
else {
|
||||
DataRegister.setRegister(file, result & 0xFF);
|
||||
dataRegister.setRegister(file, result & 0xFF);
|
||||
}
|
||||
DataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineZeroFlag(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void SUBLW(int literal) {
|
||||
public void SUBLW(int literal) {
|
||||
int result = literal - wRegister;
|
||||
if (wRegister == 0 || result >= 0){
|
||||
DataRegister.setCarryFlag(1);
|
||||
DataRegister.setDigitCarryFlag(1);
|
||||
dataRegister.setCarryFlag(1);
|
||||
dataRegister.setDigitCarryFlag(1);
|
||||
}
|
||||
else {
|
||||
|
||||
DataRegister.setCarryFlag(0);
|
||||
DataRegister.setDigitCarryFlag(0);
|
||||
dataRegister.setCarryFlag(0);
|
||||
dataRegister.setDigitCarryFlag(0);
|
||||
}
|
||||
wRegister = result & 0xFF;
|
||||
DataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineZeroFlag(result);
|
||||
}
|
||||
|
||||
public static void ADDLW(int literal) {
|
||||
public void ADDLW(int literal) {
|
||||
int result = wRegister + literal;
|
||||
wRegister = result & 0xFF;
|
||||
DataRegister.determineZeroFlag(result);
|
||||
DataRegister.determineCarryFlag(result);
|
||||
DataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (literal&0b1111));
|
||||
dataRegister.determineZeroFlag(result);
|
||||
dataRegister.determineCarryFlag(result);
|
||||
dataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (literal&0b1111));
|
||||
}
|
||||
|
||||
public static void RETLW(int literal) {
|
||||
public void RETLW(int literal) {
|
||||
wRegister = literal;
|
||||
DataRegister.setPC(ProgramStack.pop());
|
||||
dataRegister.setPC(programStack.pop());
|
||||
}
|
||||
|
||||
public static void MOVLW(int literal) {
|
||||
public void MOVLW(int literal) {
|
||||
wRegister = literal;
|
||||
}
|
||||
|
||||
public static void BTFSC(int address, int bit) {
|
||||
if (DataRegister.getBit(address, bit) == 0){
|
||||
DataRegister.increasePC();
|
||||
public void BTFSC(int address, int bit) {
|
||||
if (dataRegister.getBit(address, bit) == 0){
|
||||
dataRegister.increasePC();
|
||||
addExecutionTime(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void BTFSS(int address, int bit) {
|
||||
if (DataRegister.getBit(address, bit) == 1){
|
||||
DataRegister.increasePC();
|
||||
public void BTFSS(int address, int bit) {
|
||||
if (dataRegister.getBit(address, bit) == 1){
|
||||
dataRegister.increasePC();
|
||||
addExecutionTime(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getExecutionTimeMultiplier(){
|
||||
return executionTimeMultiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExecutionTimeMultiplier(String option){
|
||||
switch (option) {
|
||||
case "8 MHZ":
|
||||
executionTimeMultiplier = 0.5;
|
||||
break;
|
||||
|
||||
case "4 MHZ":
|
||||
executionTimeMultiplier = 1;
|
||||
break;
|
||||
case "1 MHZ":
|
||||
executionTimeMultiplier = 4;
|
||||
break;
|
||||
case "500 HZ":
|
||||
executionTimeMultiplier = 8;
|
||||
break;
|
||||
|
||||
case "100 HZ":
|
||||
executionTimeMultiplier = 40;
|
||||
break;
|
||||
|
||||
case "32 HZ":
|
||||
executionTimeMultiplier = 125;
|
||||
break;
|
||||
}
|
||||
super.notifyObservers();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,11 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.Circle;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
@ -11,7 +15,6 @@ import javafx.fxml.FXML;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.stage.FileChooser;
|
||||
|
||||
import java.io.File;
|
||||
@ -35,30 +38,17 @@ import java.util.Set;
|
||||
|
||||
import static java.lang.Math.max;
|
||||
|
||||
public class Controller_Frontend {
|
||||
public class Controller_Frontend extends PICComponent implements FrontendControllerInterface, ExecutionTimeObserver {
|
||||
|
||||
private int [] prog;
|
||||
private int [][] read;
|
||||
private int [] ind;
|
||||
|
||||
private static double executionTimeMultiplier = 1;
|
||||
|
||||
|
||||
|
||||
public static double getExecutionTimeMultiplier(){
|
||||
return executionTimeMultiplier;
|
||||
}
|
||||
private PICComponentLocator picComponents;
|
||||
|
||||
private boolean isBreakpointReached = false;
|
||||
|
||||
private boolean continueExecutionAfterBreakpoint = false;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@FXML
|
||||
private ComboBox<String> executionTimeComboBox;
|
||||
|
||||
@ -86,61 +76,73 @@ public class Controller_Frontend {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static volatile boolean isAutoRunActive = false;
|
||||
private static volatile boolean isSleeping = false;
|
||||
|
||||
public static boolean isSleeping (){
|
||||
return isSleeping;
|
||||
public Controller_Frontend() {
|
||||
super();
|
||||
System.out.println(this);
|
||||
}
|
||||
|
||||
public static void stopRunFromBackend(String message){
|
||||
isAutoRunActive = false;
|
||||
if (isSleeping)
|
||||
wakeUpFromSleep();
|
||||
else
|
||||
DataRegister.resetPC();
|
||||
|
||||
|
||||
|
||||
|
||||
//Refactoring
|
||||
|
||||
public void stopRunFromBackend(String message) {
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
|
||||
handleSleepOrReset();
|
||||
showStopDialog(message);
|
||||
|
||||
}
|
||||
private void handleSleepOrReset() {
|
||||
if (ExecutionState.isSleeping()) {
|
||||
ExecutionState.wakeUp();
|
||||
} else {
|
||||
dataRegister.resetPC();
|
||||
}
|
||||
}
|
||||
|
||||
private static void showStopDialog(String message) {
|
||||
Stage stoppedStage = new Stage();
|
||||
stoppedStage.setTitle("Programm unterbrochen!");
|
||||
|
||||
VBox vbox = new VBox();
|
||||
vbox.setAlignment(javafx.geometry.Pos.CENTER);
|
||||
|
||||
Label grundlabel = new Label("Grund: " + message);
|
||||
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
|
||||
|
||||
Label ueberlabel = new Label("Programm unterbrochen!");
|
||||
vbox.getChildren().add(ueberlabel);
|
||||
vbox.getChildren().add(grundlabel);
|
||||
vbox.getChildren().addAll(ueberlabel, grundlabel);
|
||||
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
|
||||
|
||||
Scene scene = new Scene(vbox, 300, 90);
|
||||
stoppedStage.setAlwaysOnTop(true);
|
||||
stoppedStage.setScene(scene);
|
||||
stoppedStage.show();
|
||||
}
|
||||
|
||||
public static void sleep() {
|
||||
isSleeping = true;
|
||||
}
|
||||
|
||||
public static void wakeUpFromSleep() {
|
||||
isSleeping = false;
|
||||
}
|
||||
|
||||
//Refactoring Ende
|
||||
|
||||
|
||||
|
||||
@FXML
|
||||
private void stopAutoRun(ActionEvent event) {
|
||||
isAutoRunActive = false;
|
||||
ExecutionState.setAutoRunActive(false);
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
public void autoRunGUI(ActionEvent event) {
|
||||
if (!isAutoRunActive) {
|
||||
isAutoRunActive = true;
|
||||
if (!ExecutionState.isAutoRunActive()) {
|
||||
ExecutionState.setAutoRunActive(true) ;
|
||||
}
|
||||
|
||||
Thread autoRunThread = new Thread(() -> {
|
||||
try {
|
||||
while (DataRegister.getPC() < prog.length && isAutoRunActive){
|
||||
while (dataRegister.getPC() < prog.length && ExecutionState.isAutoRunActive()){
|
||||
|
||||
Platform.runLater(() -> {
|
||||
try {
|
||||
@ -160,31 +162,10 @@ public class Controller_Frontend {
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void updateExecutionTimeMultiplier() {
|
||||
String selectedOption = executionTimeComboBox.getValue();
|
||||
switch (selectedOption) {
|
||||
case "8 MHZ":
|
||||
executionTimeMultiplier = 0.5;
|
||||
break;
|
||||
|
||||
case "4 MHZ":
|
||||
executionTimeMultiplier = 1;
|
||||
break;
|
||||
case "1 MHZ":
|
||||
executionTimeMultiplier = 4;
|
||||
break;
|
||||
case "500 HZ":
|
||||
executionTimeMultiplier = 8;
|
||||
break;
|
||||
|
||||
case "100 HZ":
|
||||
executionTimeMultiplier = 40;
|
||||
break;
|
||||
|
||||
case "32 HZ":
|
||||
executionTimeMultiplier = 125;
|
||||
break;
|
||||
}
|
||||
executionTime.setExecutionTimeMultiplier(selectedOption);
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -196,10 +177,10 @@ public class Controller_Frontend {
|
||||
|
||||
int currentIndex;
|
||||
// Aktuelle Zeile abrufen
|
||||
if (!isSleeping)
|
||||
currentIndex = ind[DataRegister.getPC()];
|
||||
if (!ExecutionState.isSleeping())
|
||||
currentIndex = ind[dataRegister.getPC()];
|
||||
else
|
||||
currentIndex = ind[DataRegister.getPC()]-1;
|
||||
currentIndex = ind[dataRegister.getPC()]-1;
|
||||
|
||||
// Überprüfung ob ein Breakpoint gesetzt ist testte
|
||||
|
||||
@ -225,30 +206,29 @@ public class Controller_Frontend {
|
||||
lstContentListView.getSelectionModel().select(currentIndex);
|
||||
|
||||
String selectedRowStyle;
|
||||
if (!isSleeping)
|
||||
if (!ExecutionState.isSleeping())
|
||||
selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
|
||||
else
|
||||
selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
|
||||
|
||||
markSelectedRow(currentIndex, selectedRowStyle);
|
||||
|
||||
if (!isSleeping) {
|
||||
Commands.decode(prog[DataRegister.getPC()]);
|
||||
DataRegister.increasePC();
|
||||
if (!ExecutionState.isSleeping()) {
|
||||
commands.decode(prog[dataRegister.getPC()]);
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
else {
|
||||
Commands.decode(0);
|
||||
commands.decode(0);
|
||||
}
|
||||
WatchdogTimer.testAndTrigger();
|
||||
Table.refresh();
|
||||
watchdogTimer.testAndTrigger();
|
||||
table.refresh();
|
||||
CreateWindow.refreshTable();
|
||||
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||
updateStack();
|
||||
updateWatchdog();
|
||||
long totalExecutionTime = Commands.getTotalExecutionTime();
|
||||
totalExecutionTimeLabel.setText("Total Execution Time: " + totalExecutionTime + "µs");
|
||||
}
|
||||
|
||||
|
||||
private void markSelectedRow(int currentIndex, String selectedRowStyle) {
|
||||
lstContentListView.setCellFactory(column -> new ListCell<String>() {
|
||||
@Override
|
||||
@ -285,26 +265,28 @@ public class Controller_Frontend {
|
||||
stopAutoRun(null);
|
||||
if(selectedFile != null){
|
||||
String fileAddress = selectedFile.getAbsolutePath();
|
||||
DataRegister.initDataRegister();
|
||||
DataRegister.resetPC();
|
||||
System.out.println(dataRegister);
|
||||
if (null == dataRegister) dataRegister = (DataRegisterInterface) picComponents.getComponent(DataRegisterInterface.class);
|
||||
dataRegister.initDataRegister();
|
||||
dataRegister.resetPC();
|
||||
toggleLEDs(null);
|
||||
IOPorts.reset();
|
||||
ioPorts.reset();
|
||||
|
||||
for (ToggleButtonGroup toggleButtonGroup : allPORTbuttons) {
|
||||
try {
|
||||
toggleButtonGroup.getToggles().get(0).setSelected(true);
|
||||
toggleButtonGroup.getToggles().get(1).setSelected(false);
|
||||
IOPorts.setPORTfromUI(toggleButtonGroup);
|
||||
ioPorts.setPORTfromUI(toggleButtonGroup);
|
||||
} catch (NullPointerException ignored) {}
|
||||
}
|
||||
ProgramStack.reset();
|
||||
wakeUpFromSleep();
|
||||
programStack.reset();
|
||||
ExecutionState.wakeUp();
|
||||
breakpoints.clear();
|
||||
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||
Commands.resetTotalExecutionTime();
|
||||
WatchdogTimer.reset();
|
||||
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||
executionTime.resetTotalExecutionTime();
|
||||
watchdogTimer.reset();
|
||||
wdtCheck.setSelected(false);
|
||||
Table.refresh();
|
||||
table.refresh();
|
||||
read = ParseFile.parseDatei(fileAddress);
|
||||
prog = read [0];
|
||||
ind = read[1];
|
||||
@ -396,11 +378,11 @@ public class Controller_Frontend {
|
||||
@FXML
|
||||
public void toggleWatchdog(ActionEvent actionEvent) {
|
||||
if (wdtCheck.isSelected()){
|
||||
WatchdogTimer.enable();
|
||||
watchdogTimer.enable();
|
||||
|
||||
}
|
||||
else{
|
||||
WatchdogTimer.disable();
|
||||
watchdogTimer.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -473,15 +455,15 @@ public class Controller_Frontend {
|
||||
allPORTButtons[i].getToggles().get(0).setSelected(true);
|
||||
allTRISButtons[i].getToggles().get(1).setSelected(false);
|
||||
allPORTButtons[i].getToggles().get(1).setSelected(false);
|
||||
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allTRISButtons[i]);
|
||||
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allPORTButtons[i]);
|
||||
toggleButtonExt.addAlwaysOneSelectedSupport(allTRISButtons[i]);
|
||||
toggleButtonExt.addAlwaysOneSelectedSupport(allPORTButtons[i]);
|
||||
}
|
||||
|
||||
ledCheckA.setSelected(false);
|
||||
ledCheckB.setSelected(false);
|
||||
setTRISbuttons(allTRISButtons);
|
||||
setPORTbuttons(allPORTButtons);
|
||||
IOPorts.setLEDs(allLEDsA, allLEDsB);
|
||||
ioPorts.setLEDs(allLEDsA, allLEDsB);
|
||||
|
||||
lstContentListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||
|
||||
@ -496,27 +478,27 @@ public class Controller_Frontend {
|
||||
|
||||
|
||||
|
||||
private static void setTRISbuttons(ToggleButtonGroup[] allButtons) {
|
||||
private void setTRISbuttons(ToggleButtonGroup[] allButtons) {
|
||||
allTRISbuttons = allButtons;
|
||||
}
|
||||
|
||||
public static ToggleButtonGroup [] getTRISbuttons() {
|
||||
public FrontendSpecificToggleButtonGroup [] getTRISbuttons() {
|
||||
return allTRISbuttons;
|
||||
}
|
||||
|
||||
private static void setPORTbuttons(ToggleButtonGroup[] allButtons) {
|
||||
private void setPORTbuttons(ToggleButtonGroup[] allButtons) {
|
||||
allPORTbuttons = allButtons;
|
||||
}
|
||||
|
||||
public static ToggleButtonGroup [] getPORTbuttons() {
|
||||
public ToggleButtonGroup [] getPORTbuttons() {
|
||||
return allPORTbuttons;
|
||||
}
|
||||
|
||||
public static Circle[] getLEDsA() {
|
||||
public Circle[] getLEDsA() {
|
||||
return allLEDsA;
|
||||
}
|
||||
|
||||
public static Circle[] getLEDsB() {
|
||||
public Circle[] getLEDsB() {
|
||||
return allLEDsB;
|
||||
}
|
||||
|
||||
@ -554,7 +536,7 @@ public class Controller_Frontend {
|
||||
|
||||
@FXML
|
||||
public void toggleLEDs (ActionEvent actionEvent) {
|
||||
IOPorts.setLEDs(new boolean[]{ledCheckA.isSelected(), ledCheckB.isSelected()});
|
||||
ioPorts.setLEDs(new boolean[]{ledCheckA.isSelected(), ledCheckB.isSelected()});
|
||||
}
|
||||
|
||||
@FXML
|
||||
@ -568,9 +550,9 @@ public class Controller_Frontend {
|
||||
}
|
||||
|
||||
private void updateStack (){
|
||||
stackIndex.setText("Stack-Pointer: " + ProgramStack.getStackPointer());
|
||||
stackIndex.setText("Stack-Pointer: " + programStack.getStackPointer());
|
||||
ObservableList<String> observedList = FXCollections.observableArrayList();
|
||||
List<Integer> stackList = ProgramStack.getStack();
|
||||
List<Integer> stackList = programStack.getStack();
|
||||
for (Integer integer : stackList) {
|
||||
observedList.add("0x" + format(Integer.toHexString(integer).toUpperCase()));
|
||||
}
|
||||
@ -578,11 +560,20 @@ public class Controller_Frontend {
|
||||
}
|
||||
|
||||
private void updateWatchdog (){
|
||||
wdtCheck.setText("Watchdog-Timer: " + WatchdogTimer.get() + "µs");
|
||||
wdtCheck.setText("Watchdog-Timer: " + watchdogTimer.get() + "µs");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
executionTime.registerObserver(this);
|
||||
this.picComponents = locator;
|
||||
System.out.println("Frontend");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executionTimeChanged() {
|
||||
totalExecutionTimeLabel.setText("Total Execution Time: " + executionTime.getTotalExecutionTime() + "µs");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.VBox;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import javafx.application.Application;
|
||||
|
||||
import javafx.fxml.FXMLLoader;
|
||||
@ -7,25 +9,33 @@ import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CreateWindow extends Application {
|
||||
|
||||
private static VBox table;
|
||||
public class CreateWindow extends Application implements WindowManagement {
|
||||
private static PICComponentLocator picComponents; // Subjekt
|
||||
public static GridPane grid = new GridPane();
|
||||
private TableInterface table;
|
||||
private static VBox tableBox;
|
||||
|
||||
@Override
|
||||
public void start(Stage primaryStage) throws IOException {
|
||||
DataRegister.initDataRegister();
|
||||
table = Table.refresh();
|
||||
picComponents.registerComponent(ToggleButtonInterface.class, new ToggleButtonGroupExt());
|
||||
picComponents.registerComponent(IOPortInterface.class, new IOPorts());
|
||||
picComponents.registerComponent(TableInterface.class, new Table());
|
||||
picComponents.registerComponent(FrontendControllerInterface.class, new Controller_Frontend());
|
||||
picComponents.initAll();
|
||||
|
||||
table = picComponents.getComponent(TableInterface.class);
|
||||
|
||||
FXMLLoader codewindow = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
|
||||
codewindow.setController(picComponents.getComponent(FrontendControllerInterface.class));
|
||||
Parent code = codewindow.load();
|
||||
|
||||
grid.add(table, 1, 1);
|
||||
tableBox = (VBox) table.getTable();
|
||||
grid.add(tableBox, 1, 1);
|
||||
grid.add(code, 0, 1);
|
||||
|
||||
grid.relocate(0, 0);
|
||||
@ -37,16 +47,29 @@ public class CreateWindow extends Application {
|
||||
primaryStage.show();
|
||||
}
|
||||
|
||||
public void startFromMain(String[] args){
|
||||
launch(args);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch(args);
|
||||
}
|
||||
|
||||
public static void refreshTable() {
|
||||
grid.getChildren().remove(table);
|
||||
table= Table.refresh();
|
||||
grid.add(table, 1, 1);
|
||||
TableInterface table = picComponents.getComponent(TableInterface.class);
|
||||
grid.getChildren().remove(table.getTable());
|
||||
table.refresh();
|
||||
tableBox = (VBox) table.getTable();
|
||||
grid.add(tableBox, 1, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator picComponents) {
|
||||
CreateWindow.picComponents = picComponents;
|
||||
}
|
||||
|
||||
public CreateWindow (){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,22 +0,0 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class DataEntry {
|
||||
|
||||
|
||||
private final String address;
|
||||
private final String value;
|
||||
|
||||
public DataEntry(String address, String value) {
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getValue(int columnIndex) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,42 +1,55 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class DataRegister {
|
||||
private static final int INDF = 0x0;
|
||||
private static final int PCL = 0x2;
|
||||
private static final int STATUS = 0x3;
|
||||
private static final int FSR = 0x4;
|
||||
private static final int PORTA = 0x5;
|
||||
private static final int PORTB = 0x6;
|
||||
private static final int PCLATH = 0xA;
|
||||
private static final int INTCON = 0xB;
|
||||
public class DataRegister extends PICComponent implements DataRegisterInterface {
|
||||
private final int INDF = 0x0;
|
||||
private final int PCL = 0x2;
|
||||
private final int STATUS = 0x3;
|
||||
private final int FSR = 0x4;
|
||||
private final int PORTA = 0x5;
|
||||
private final int PORTB = 0x6;
|
||||
private final int PCLATH = 0xA;
|
||||
private final int INTCON = 0xB;
|
||||
|
||||
private static final int EEDATA = 0x08;
|
||||
private static final int EEADR = 0x09;
|
||||
private static final int EECON1 = 0x88;
|
||||
private static final int EECON2 = 0x89;
|
||||
private final int EEDATA = 0x08;
|
||||
private final int EEADR = 0x09;
|
||||
private final int EECON1 = 0x88;
|
||||
private final int EECON2 = 0x89;
|
||||
|
||||
private static final int TRISA = 0x85;
|
||||
private static final int TRISB = 0x86;
|
||||
private final int TRISA = 0x85;
|
||||
private final int TRISB = 0x86;
|
||||
|
||||
private static final int C = 0x0;
|
||||
private static final int DC = 0x1;
|
||||
private static final int Z = 0x2;
|
||||
private static final int RP0 = 0x5;
|
||||
private final int C = 0x0;
|
||||
private final int DC = 0x1;
|
||||
private final int Z = 0x2;
|
||||
private final int RP0 = 0x5;
|
||||
|
||||
|
||||
private static final int [] dataRegister = new int[0xFF];
|
||||
private static final int [] syncedRegisters = {INDF, PCL, STATUS, FSR, PCLATH, INTCON};
|
||||
private static final int [] eepromRegisters = {EEDATA, EEADR, EECON1, EECON2};
|
||||
public static final int [] ioRegisters = {PORTA, PORTB, TRISA, TRISB};
|
||||
private final int [] dataRegister = new int[0xFF];
|
||||
private final int [] syncedRegisters = {INDF, PCL, STATUS, FSR, PCLATH, INTCON};
|
||||
private final int [] eepromRegisters = {EEDATA, EEADR, EECON1, EECON2};
|
||||
public final int [] ioRegisters = {PORTA, PORTB, TRISA, TRISB};
|
||||
|
||||
public static void initDataRegister() {
|
||||
|
||||
public DataRegister () {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
System.out.println("DataRegister.\n");
|
||||
initOrReset();
|
||||
}
|
||||
|
||||
private void initOrReset () {
|
||||
dataRegister[PCL] = 0b0;
|
||||
dataRegister[STATUS] = 0b00011000;
|
||||
dataRegister[PCLATH] = 0b0;
|
||||
dataRegister[INTCON] = 0b0;
|
||||
|
||||
dataRegister[0x81] = 0b11111111;
|
||||
dataRegister[0x80 + PCL] = dataRegister[PCL];
|
||||
dataRegister[0x80 + STATUS] = dataRegister[STATUS];
|
||||
@ -47,11 +60,15 @@ public class DataRegister {
|
||||
carryFlag = 0;
|
||||
zeroFlag = 0;
|
||||
digitCarryFlag = 0;
|
||||
IOPorts.resetTRIS();
|
||||
if (null != ioPorts) ioPorts.resetTRIS();
|
||||
System.out.println(Arrays.toString(dataRegister));
|
||||
}
|
||||
|
||||
private static boolean isSyncedRegister (int address){
|
||||
public void initDataRegister() {
|
||||
initOrReset();
|
||||
}
|
||||
|
||||
private boolean isSyncedRegister (int address){
|
||||
for (int register : syncedRegisters){
|
||||
if (address == register || address == 0x80 + register){
|
||||
return true;
|
||||
@ -60,11 +77,11 @@ public class DataRegister {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static int[] getDataRegister() {
|
||||
public int[] getDataRegister() {
|
||||
return dataRegister;
|
||||
}
|
||||
|
||||
private static int determineIndirectAndChange (int address){
|
||||
private int determineIndirectAndChange (int address){
|
||||
if (address == INDF || address == 0x80 + INDF) {
|
||||
return dataRegister[FSR];
|
||||
}
|
||||
@ -72,29 +89,29 @@ public class DataRegister {
|
||||
return address;
|
||||
}
|
||||
|
||||
public static int getFSR (){
|
||||
public int getFSR (){
|
||||
return dataRegister[FSR];
|
||||
}
|
||||
|
||||
private static int bank() {
|
||||
private int bank() {
|
||||
return ((dataRegister[STATUS] >> RP0) & 1) * 0x80;
|
||||
}
|
||||
|
||||
public static int getRegister(int fileAddress){
|
||||
public int getRegister(int fileAddress){
|
||||
int address = determineIndirectAndChange (fileAddress);
|
||||
if (bank () + address == EECON2)
|
||||
return 0;
|
||||
return dataRegister[bank() + address];
|
||||
}
|
||||
|
||||
public static void setRegister(int fileAddress, int content){
|
||||
public void setRegister(int fileAddress, int content){
|
||||
int address = determineIndirectAndChange (fileAddress);
|
||||
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
||||
IOPorts.setRegister(bank() + address, content);
|
||||
ioPorts.setRegister(bank() + address, content);
|
||||
return;
|
||||
}
|
||||
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
||||
EEPROM.parse(bank() + address, content, 0b11);
|
||||
eeprom.parse(bank() + address, content, 0b11);
|
||||
return;
|
||||
}
|
||||
if (fileAddress == PCL || fileAddress == 0x80 + PCL){
|
||||
@ -110,28 +127,28 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
if (address == 1)
|
||||
PreScaler.resetFromRegister();
|
||||
preScaler.resetFromRegister();
|
||||
}
|
||||
|
||||
public static int getBit(int fileAddress, int bit) {
|
||||
public int getBit(int fileAddress, int bit) {
|
||||
int address = determineIndirectAndChange (fileAddress);
|
||||
if (bank() + address == EECON2)
|
||||
return 0;
|
||||
return (dataRegister[bank() + address] >> bit) & 1;
|
||||
}
|
||||
|
||||
public static int getDirectBit(int address, int bit){
|
||||
public int getDirectBit(int address, int bit){
|
||||
return (dataRegister[address] >> bit) & 1;
|
||||
}
|
||||
|
||||
public static void clearBit(int fileAddress, int bit) {
|
||||
public void clearBit(int fileAddress, int bit) {
|
||||
int address = determineIndirectAndChange (fileAddress);
|
||||
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
||||
IOPorts.clearBit(bank() + address, bit);
|
||||
ioPorts.clearBit(bank() + address, bit);
|
||||
return;
|
||||
}
|
||||
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
||||
EEPROM.parse(bank () + address, bit, 0b00);
|
||||
eeprom.parse(bank () + address, bit, 0b00);
|
||||
return;
|
||||
}
|
||||
if (!isSyncedRegister(address)) {
|
||||
@ -149,17 +166,17 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
if (address == 1)
|
||||
PreScaler.resetFromRegister();
|
||||
preScaler.resetFromRegister();
|
||||
}
|
||||
|
||||
public static void setBit(int fileAddress, int bit) {
|
||||
public void setBit(int fileAddress, int bit) {
|
||||
int address = determineIndirectAndChange (fileAddress);
|
||||
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
||||
IOPorts.setBit(bank() + address, bit);
|
||||
ioPorts.setBit(bank() + address, bit);
|
||||
return;
|
||||
}
|
||||
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
||||
EEPROM.parse(bank () + address, bit, 0b10);
|
||||
eeprom.parse(bank () + address, bit, 0b10);
|
||||
return;
|
||||
}
|
||||
if (!isSyncedRegister(address)) {
|
||||
@ -177,10 +194,10 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
if (address == 1)
|
||||
PreScaler.resetFromRegister();
|
||||
preScaler.resetFromRegister();
|
||||
}
|
||||
|
||||
public static void setDirectBit (int fileAddress, int bit, int value){
|
||||
public void setDirectBit (int fileAddress, int bit, int value){
|
||||
if (getDirectBit(fileAddress, bit) == 0 && value == 1){
|
||||
dataRegister[fileAddress] += (int) Math.pow(2, bit);
|
||||
} else if (getDirectBit(fileAddress, bit) == 1 && value == 0){
|
||||
@ -188,14 +205,14 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
|
||||
private static int programCounter = 0;
|
||||
private int programCounter = 0;
|
||||
|
||||
private static void writeToPCL(){
|
||||
private void writeToPCL(){
|
||||
dataRegister[PCL] = programCounter & 0xFF;
|
||||
dataRegister[0x80 + PCL] = dataRegister[PCL];
|
||||
}
|
||||
|
||||
public static void increasePC (){
|
||||
public void increasePC (){
|
||||
if (programCounter != 0x3FF) {
|
||||
programCounter++;
|
||||
}
|
||||
@ -205,28 +222,28 @@ public class DataRegister {
|
||||
writeToPCL();
|
||||
}
|
||||
|
||||
public static void setPC (int value){
|
||||
public void setPC (int value){
|
||||
programCounter = value + ((getRegister(PCLATH) & 0b11000) << 8);
|
||||
writeToPCL();
|
||||
}
|
||||
|
||||
public static void resetPC () {
|
||||
public void resetPC () {
|
||||
programCounter = 0;
|
||||
}
|
||||
|
||||
public static int getPC(){
|
||||
public int getPC(){
|
||||
return programCounter;
|
||||
}
|
||||
|
||||
private static void setFlags() {
|
||||
private void setFlags() {
|
||||
carryFlag = getDirectBit(STATUS, C);
|
||||
digitCarryFlag = getDirectBit(STATUS, DC);
|
||||
zeroFlag = getDirectBit(STATUS, Z);
|
||||
}
|
||||
|
||||
private static int zeroFlag = 0;
|
||||
private int zeroFlag = 0;
|
||||
|
||||
public static void determineZeroFlag(int result){
|
||||
public void determineZeroFlag(int result){
|
||||
if (result == 0){
|
||||
zeroFlag = 1;
|
||||
if (getBit(STATUS, Z) == 0){
|
||||
@ -243,13 +260,13 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getZeroFlag(){
|
||||
public int getZeroFlag(){
|
||||
return zeroFlag;
|
||||
}
|
||||
|
||||
private static int carryFlag = 0;
|
||||
private int carryFlag = 0;
|
||||
|
||||
public static void setCarryFlag(int value){
|
||||
public void setCarryFlag(int value){
|
||||
carryFlag = value;
|
||||
if (value == 1){
|
||||
if (getBit(STATUS, C) == 0){
|
||||
@ -265,7 +282,7 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
|
||||
public static void determineCarryFlag (int result){
|
||||
public void determineCarryFlag (int result){
|
||||
if (result > 0xFF){
|
||||
setCarryFlag(1);
|
||||
}
|
||||
@ -274,13 +291,13 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getCarryFlag (){
|
||||
public int getCarryFlag (){
|
||||
return carryFlag;
|
||||
}
|
||||
|
||||
private static int digitCarryFlag = 0;
|
||||
private int digitCarryFlag = 0;
|
||||
|
||||
public static void setDigitCarryFlag(int value){
|
||||
public void setDigitCarryFlag(int value){
|
||||
digitCarryFlag = value;
|
||||
if (value == 1){
|
||||
if (getBit(STATUS, DC) == 0){
|
||||
@ -296,7 +313,7 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
|
||||
public static void determineDigitCarryFlag(int result){
|
||||
public void determineDigitCarryFlag(int result){
|
||||
if (result >> 4 == 1){
|
||||
setDigitCarryFlag(1);
|
||||
}
|
||||
@ -305,33 +322,32 @@ public class DataRegister {
|
||||
}
|
||||
}
|
||||
|
||||
public static int getDigitCarryFlag(){
|
||||
public int getDigitCarryFlag(){
|
||||
return digitCarryFlag;
|
||||
}
|
||||
|
||||
public static void setDirectRegister(int fileAddress, int content) {
|
||||
public void setDirectRegister(int fileAddress, int content) {
|
||||
dataRegister[fileAddress] = content;
|
||||
}
|
||||
|
||||
|
||||
public static int getPCL() {
|
||||
public int getPCL() {
|
||||
return PCL;
|
||||
}
|
||||
public static int getSTATUS() {
|
||||
public int getSTATUS() {
|
||||
return STATUS;
|
||||
}
|
||||
|
||||
public static int getPCLATH() {
|
||||
public int getPCLATH() {
|
||||
return PCLATH;
|
||||
}
|
||||
public static int getINTCON() {
|
||||
public int getINTCON() {
|
||||
return INTCON;
|
||||
}
|
||||
|
||||
public static int getDirectRegister(int address) {
|
||||
public int getDirectRegister(int address) {
|
||||
return dataRegister[address];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -11,26 +11,31 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static fabrik.simulator.pic16f84.Commands.getTotalExecutionTime;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class EEPROM {
|
||||
private static final int EEDATA = 0x08;
|
||||
private static final int EEADR = 0x09;
|
||||
private static final int EECON1 = 0x88;
|
||||
private static final int EECON2 = 0x89;
|
||||
public class EEPROM extends PICComponent implements EEPROMInterface, ExecutionTimeObserver {
|
||||
private final int EEDATA = 0x08;
|
||||
private final int EEADR = 0x09;
|
||||
private final int EECON1 = 0x88;
|
||||
private final int EECON2 = 0x89;
|
||||
|
||||
private static final int RD = 0x00;
|
||||
private static final int WR = 0x01;
|
||||
private static final int WRERR = 0x03;
|
||||
private static final int EEIF = 0x04;
|
||||
private final int RD = 0x00;
|
||||
private final int WR = 0x01;
|
||||
private final int WRERR = 0x03;
|
||||
private final int EEIF = 0x04;
|
||||
|
||||
private static boolean readControl = false;
|
||||
private static boolean writeControl = false;
|
||||
private static boolean [] eecon2stages = {false, false};
|
||||
private boolean readControl = false;
|
||||
private boolean writeControl = false;
|
||||
private boolean [] eecon2stages = {false, false};
|
||||
|
||||
private static long startTime;
|
||||
|
||||
public static long read (int address) {
|
||||
private double startTime;
|
||||
|
||||
public EEPROM (){
|
||||
}
|
||||
|
||||
public long read (int address) {
|
||||
if (address < 0) return 0;
|
||||
FileReader reader;
|
||||
try {
|
||||
reader = new FileReader("eeprom.json");
|
||||
@ -47,19 +52,20 @@ public class EEPROM {
|
||||
Object requestedData = data.get(String.valueOf(address));
|
||||
try {
|
||||
readControl = false;
|
||||
DataRegister.setDirectBit(EECON1, RD, 0);
|
||||
dataRegister.setDirectBit(EECON1, RD, 0);
|
||||
return (long) requestedData;
|
||||
} catch (NullPointerException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void write (int address, long data) {
|
||||
public void write (int address, long data) {
|
||||
if (address < 0) return;
|
||||
FileReader reader;
|
||||
try {
|
||||
reader = new FileReader("eeprom.json");
|
||||
} catch (FileNotFoundException ignored) {
|
||||
DataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||
dataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||
return;
|
||||
}
|
||||
JSONParser parser = new JSONParser();
|
||||
@ -67,32 +73,32 @@ public class EEPROM {
|
||||
try {
|
||||
eeprom = (JSONObject) parser.parse(reader);
|
||||
} catch (ParseException | IOException ignored) {
|
||||
DataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||
dataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||
return;
|
||||
}
|
||||
eeprom.put(String.valueOf(address), data);
|
||||
try {
|
||||
Files.write(Paths.get("eeprom.json"), eeprom.toJSONString().getBytes());
|
||||
} catch (IOException ignored) {
|
||||
DataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||
dataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||
return;
|
||||
}
|
||||
registerTime(true);
|
||||
registerTime(executionTime.getTotalExecutionTime(), true);
|
||||
}
|
||||
|
||||
public static void registerTime(boolean reset) {
|
||||
public void registerTime(double executionTime, boolean reset) {
|
||||
if (reset)
|
||||
startTime = getTotalExecutionTime();
|
||||
else if ((getTotalExecutionTime() >= (startTime + 1000)) && writeControl) {
|
||||
startTime = executionTime;
|
||||
else if ((executionTime >= (startTime + 1000)) && writeControl) {
|
||||
eecon2stages = new boolean[]{false, false};
|
||||
DataRegister.setDirectBit(EECON1, EEIF, 1);
|
||||
DataRegister.setDirectBit(EECON1, WR, 0);
|
||||
dataRegister.setDirectBit(EECON1, EEIF, 1);
|
||||
dataRegister.setDirectBit(EECON1, WR, 0);
|
||||
writeControl = false;
|
||||
startTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static void parse(int address, int content, int opcode) {
|
||||
public void parse(int address, int content, int opcode) {
|
||||
//OPCODE: 0b1x = set
|
||||
//OPCODE: 0b0x = clear
|
||||
//OPCODE: 0bx1 = byte
|
||||
@ -100,21 +106,21 @@ public class EEPROM {
|
||||
switch (opcode){
|
||||
case 0b00: // CLEAR BIT
|
||||
if(address == EECON1) {
|
||||
if (DataRegister.getDirectBit(address, content) == 1)
|
||||
setEECON1((int) (DataRegister.getDirectRegister(EECON1) - Math.pow(2, content)));
|
||||
if (dataRegister.getDirectBit(address, content) == 1)
|
||||
setEECON1((int) (dataRegister.getDirectRegister(EECON1) - Math.pow(2, content)));
|
||||
} else {
|
||||
DataRegister.setDirectBit(address, content, 0);
|
||||
dataRegister.setDirectBit(address, content, 0);
|
||||
}
|
||||
break;
|
||||
case 0b10: // SET BIT
|
||||
if(address == EECON1) {
|
||||
if (DataRegister.getDirectBit(address, content) == 0)
|
||||
setEECON1((int) (DataRegister.getDirectRegister(EECON1) + Math.pow(2, content)));
|
||||
if (dataRegister.getDirectBit(address, content) == 0)
|
||||
setEECON1((int) (dataRegister.getDirectRegister(EECON1) + Math.pow(2, content)));
|
||||
} else {
|
||||
if (address == EEADR && content >= 0b01000000)
|
||||
DataRegister.setDirectBit(address, content, 0);
|
||||
dataRegister.setDirectBit(address, content, 0);
|
||||
else
|
||||
DataRegister.setDirectBit(address, content, 1);
|
||||
dataRegister.setDirectBit(address, content, 1);
|
||||
}
|
||||
break;
|
||||
case 0b11: // SET BYTE
|
||||
@ -131,20 +137,20 @@ public class EEPROM {
|
||||
else
|
||||
eecon2stages = new boolean[]{false, false};
|
||||
}
|
||||
DataRegister.setDirectRegister(address, content);
|
||||
dataRegister.setDirectRegister(address, content);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void setEECON1(int content) {
|
||||
private void setEECON1(int content) {
|
||||
content &= 0b00011111;
|
||||
boolean writeEnabled = ((content & 0b100) >> 2) == 1;
|
||||
if ((content & 0b1) == 1) { // READ
|
||||
readControl = true;
|
||||
DataRegister.setDirectRegister(EECON1, content);
|
||||
int data = (int) read(DataRegister.getDirectRegister(EEADR));
|
||||
DataRegister.setDirectRegister(EEDATA, data);
|
||||
dataRegister.setDirectRegister(EECON1, content);
|
||||
int data = (int) read(dataRegister.getDirectRegister(EEADR));
|
||||
dataRegister.setDirectRegister(EEDATA, data);
|
||||
return;
|
||||
}
|
||||
else if ((content & 0b1) == 0 && readControl) // RD kann nicht manuell gecleart werden
|
||||
@ -152,8 +158,8 @@ public class EEPROM {
|
||||
if (((content & 0b10) >> 1) == 1) { // WRITE CONTROL
|
||||
if (writeEnabled && eecon2stages[0] && eecon2stages[1]) {
|
||||
writeControl = true;
|
||||
DataRegister.setDirectRegister(EECON1, content);
|
||||
write(DataRegister.getDirectRegister(EEADR), DataRegister.getDirectRegister(EEDATA));
|
||||
dataRegister.setDirectRegister(EECON1, content);
|
||||
write(dataRegister.getDirectRegister(EEADR), dataRegister.getDirectRegister(EEDATA));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@ -162,6 +168,17 @@ public class EEPROM {
|
||||
}
|
||||
else if ((((content & 0b10) >> 1) == 0) && writeControl) // WR kann nicht manuell gecleart werden
|
||||
content |= 0b10;
|
||||
DataRegister.setDirectRegister(EECON1, content);
|
||||
dataRegister.setDirectRegister(EECON1, content);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
executionTime.registerObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executionTimeChanged() {
|
||||
registerTime(executionTime.getTotalExecutionTime(), false);
|
||||
}
|
||||
}
|
||||
|
||||
151
src/main/java/fabrik/simulator/pic16f84/EmptyRegister.java
Normal file
151
src/main/java/fabrik/simulator/pic16f84/EmptyRegister.java
Normal file
@ -0,0 +1,151 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
|
||||
public class EmptyRegister implements DataRegisterInterface {
|
||||
|
||||
@Override
|
||||
public void clearBit(int f, int b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBit(int f, int b) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPC(int pop) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getINTCON() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPC() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRegister(int file, int wRegister) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void determineZeroFlag(int wRegister) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRegister(int file) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCarryFlag(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDigitCarryFlag(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCarryFlag() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void determineCarryFlag(int result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void increasePC() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void determineDigitCarryFlag(int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBit(int address, int bit) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDirectBit(int option, int psa) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDirectRegister(int option) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectBit(int option, int i, int i1) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDirectRegister(int porta, int i) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPC() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getDataRegister() {
|
||||
return new int[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDigitCarryFlag() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getZeroFlag() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFSR() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initDataRegister() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPCL() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPCLATH() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSTATUS() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator picComponents) {
|
||||
|
||||
}
|
||||
}
|
||||
19
src/main/java/fabrik/simulator/pic16f84/ExecutionState.java
Normal file
19
src/main/java/fabrik/simulator/pic16f84/ExecutionState.java
Normal file
@ -0,0 +1,19 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class ExecutionState {
|
||||
|
||||
private static boolean isAutoRunActive = false;
|
||||
private static boolean isSleeping = false;
|
||||
private static double executionTimeMultiplier = 1;
|
||||
|
||||
public static boolean isAutoRunActive() { return isAutoRunActive; }
|
||||
public static void setAutoRunActive(boolean active) { isAutoRunActive = active; }
|
||||
|
||||
public static boolean isSleeping() { return isSleeping; }
|
||||
public static void sleep() { isSleeping = true; }
|
||||
public static void wakeUp() { isSleeping = false; }
|
||||
|
||||
public static double getExecutionTimeMultiplier() { return executionTimeMultiplier; }
|
||||
public static void setExecutionTimeMultiplier(double multiplier) { executionTimeMultiplier = multiplier; }
|
||||
}
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.ExecutionTimeObserver;
|
||||
|
||||
public abstract class ExecutionTimeSubject extends PICComponent{
|
||||
private Set<ExecutionTimeObserver> observers;
|
||||
|
||||
public ExecutionTimeSubject(){
|
||||
super();
|
||||
this.observers = new HashSet<>();
|
||||
}
|
||||
|
||||
|
||||
public void registerObserver(ExecutionTimeObserver observer){
|
||||
observers.add(observer);
|
||||
}
|
||||
|
||||
public void unregisterObserver(ExecutionTimeObserver observer){
|
||||
observers.remove(observer);
|
||||
}
|
||||
|
||||
protected void notifyObservers(){
|
||||
observers.forEach(o -> o.executionTimeChanged());
|
||||
}
|
||||
|
||||
public double getTotalExecutionTime(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void addExecutionTime(int i){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public double getExecutionTimeMultiplier(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void setExecutionTimeMultiplier(String option){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
public void resetTotalExecutionTime(){
|
||||
throw new UnsupportedOperationException("No class implements ExecutionTimeSubject correctly!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
@ -1,39 +1,44 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.Circle;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificCircle;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.scene.paint.Color;
|
||||
import javafx.scene.paint.RadialGradient;
|
||||
import javafx.scene.paint.Stop;
|
||||
import javafx.scene.shape.Circle;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class IOPorts {
|
||||
private static final int A = 0;
|
||||
private static final int B = 1;
|
||||
private static final int PORTA = 5;
|
||||
private static final int PORTB = 6;
|
||||
private static final int TRISA = 0x85;
|
||||
private static final int TRISB = 0x86;
|
||||
public class IOPorts extends PICComponent implements IOPortInterface {
|
||||
private final int A = 0;
|
||||
private final int B = 1;
|
||||
private final int PORTA = 5;
|
||||
private final int PORTB = 6;
|
||||
private final int TRISA = 0x85;
|
||||
private final int TRISB = 0x86;
|
||||
|
||||
private static int [] trisLatch = {0xFF, 0xFF};
|
||||
private static int [] dataLatch = new int[2];
|
||||
private static boolean isLEDenabledA = false;
|
||||
private static boolean isLEDenabledB = false;
|
||||
private static Circle[] allLEDsA;
|
||||
private static Circle[] allLEDsB;
|
||||
private int [] trisLatch = {0xFF, 0xFF};
|
||||
private int [] dataLatch = new int[2];
|
||||
private boolean isLEDenabledA = false;
|
||||
private boolean isLEDenabledB = false;
|
||||
private Circle[] allLEDsA;
|
||||
private Circle[] allLEDsB;
|
||||
|
||||
|
||||
private static int RB4 = 0x10;
|
||||
private static int RB5 = 0x20;
|
||||
private static int RB6 = 0x40;
|
||||
private static int RB7 = 0x80;
|
||||
private int RB4 = 0x10;
|
||||
private int RB5 = 0x20;
|
||||
private int RB6 = 0x40;
|
||||
private int RB7 = 0x80;
|
||||
|
||||
public IOPorts(){
|
||||
super();
|
||||
}
|
||||
|
||||
public static void setBit (int address, int bit){
|
||||
public void setBit (int address, int bit){
|
||||
if (address < 7) {
|
||||
dataLatch[address - PORTA] |= (1 << bit);
|
||||
}
|
||||
@ -43,7 +48,7 @@ public class IOPorts {
|
||||
refreshPorts();
|
||||
}
|
||||
|
||||
public static void clearBit(int address, int bit) {
|
||||
public void clearBit(int address, int bit) {
|
||||
if (address < 7) {
|
||||
if (((dataLatch[address-PORTA] >> bit)&1) == 1){
|
||||
dataLatch[address-PORTA] -= (int) Math.pow(2, bit);
|
||||
@ -57,7 +62,7 @@ public class IOPorts {
|
||||
refreshPorts();
|
||||
}
|
||||
|
||||
public static void setRegister(int address, int content) {
|
||||
public void setRegister(int address, int content) {
|
||||
if (address < 7) {
|
||||
dataLatch[address - PORTA] = content;
|
||||
}
|
||||
@ -67,24 +72,24 @@ public class IOPorts {
|
||||
refreshPorts();
|
||||
}
|
||||
|
||||
private static void refreshPorts() {
|
||||
DataRegister.setDirectRegister(PORTA, ((~((~dataLatch[A])&0x1F | trisLatch[A])) | (trisLatch[A] & DataRegister.getDirectRegister(PORTA))) & 0xFF);
|
||||
DataRegister.setDirectRegister(PORTB, ((~((~dataLatch[B])&0xFF | trisLatch[B])) | (trisLatch[B] & DataRegister.getDirectRegister(PORTB))) & 0xFF);
|
||||
DataRegister.setDirectRegister(TRISA, trisLatch[A]);
|
||||
DataRegister.setDirectRegister(TRISB, trisLatch[B]);
|
||||
private void refreshPorts() {
|
||||
dataRegister.setDirectRegister(PORTA, ((~((~dataLatch[A])&0x1F | trisLatch[A])) | (trisLatch[A] & dataRegister.getDirectRegister(PORTA))) & 0xFF);
|
||||
dataRegister.setDirectRegister(PORTB, ((~((~dataLatch[B])&0xFF | trisLatch[B])) | (trisLatch[B] & dataRegister.getDirectRegister(PORTB))) & 0xFF);
|
||||
dataRegister.setDirectRegister(TRISA, trisLatch[A]);
|
||||
dataRegister.setDirectRegister(TRISB, trisLatch[B]);
|
||||
if (((trisLatch[A] >> 4) & 1 )== 1)
|
||||
Timer.incrementFromPin(DataRegister.getDirectRegister(PORTA));
|
||||
ToggleButtonGroup[] buttons = Controller_Frontend.getPORTbuttons();
|
||||
timer.incrementFromPin(dataRegister.getDirectRegister(PORTA));
|
||||
ToggleButtonGroup[] buttons = (ToggleButtonGroup[]) frontendController.getPORTbuttons();
|
||||
for (int i = 0; i < buttons.length; i++){
|
||||
int port = (i < 8) ? PORTA : PORTB;
|
||||
int bit = i % 8;
|
||||
boolean value = ((DataRegister.getDirectRegister(port) >> bit) & 1) == 1;
|
||||
boolean value = ((dataRegister.getDirectRegister(port) >> bit) & 1) == 1;
|
||||
buttons[i].getToggles().get(0).setSelected(!value);
|
||||
buttons[i].getToggles().get(1).setSelected(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void refreshUI(ToggleButtonGroup[] buttonsTRIS, ToggleButtonGroup[] buttonsPORT) {
|
||||
public void refreshUI(ToggleButtonGroup[] buttonsTRIS, ToggleButtonGroup[] buttonsPORT) {
|
||||
for (int i = 0; i< buttonsTRIS.length; i++){
|
||||
int tris = (i < 8) ? trisLatch[A] : trisLatch[B];
|
||||
boolean val = isInput(tris, i%8);
|
||||
@ -95,18 +100,18 @@ public class IOPorts {
|
||||
}
|
||||
}
|
||||
|
||||
private static void updateLEDs(boolean updateAll, int index, boolean val) {
|
||||
private void updateLEDs(boolean updateAll, int index, boolean val) {
|
||||
if (updateAll) {
|
||||
if (index < 8) {
|
||||
if (isLEDenabledA && !val) {
|
||||
if (DataRegister.getDirectBit(PORTA, index) == 1)
|
||||
if (dataRegister.getDirectBit(PORTA, index) == 1)
|
||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||
else
|
||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||
}
|
||||
} else {
|
||||
if (isLEDenabledB && !val) {
|
||||
if (DataRegister.getDirectBit(PORTB, index - 8) == 1)
|
||||
if (dataRegister.getDirectBit(PORTB, index - 8) == 1)
|
||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
||||
else
|
||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||
@ -115,28 +120,28 @@ public class IOPorts {
|
||||
}
|
||||
else {
|
||||
if (index < 8)
|
||||
if (val || DataRegister.getDirectBit(PORTA, index) == 0)
|
||||
if (val || dataRegister.getDirectBit(PORTA, index) == 0)
|
||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||
else
|
||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
||||
else
|
||||
if (val || DataRegister.getDirectBit(PORTB, index - 8) == 0)
|
||||
if (val || dataRegister.getDirectBit(PORTB, index - 8) == 0)
|
||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||
else
|
||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isInput(int i, int bit) {
|
||||
private boolean isInput(int i, int bit) {
|
||||
return (i >> bit & 1) == 1;
|
||||
}
|
||||
|
||||
public static void setTRISfromUI(ToggleButtonGroup parent) throws IOException {
|
||||
public void setTRISfromUI(ToggleButtonGroup parent) throws IOException {
|
||||
int [] params = getToggleParams(parent);
|
||||
int tris = params[0];
|
||||
int bit = params[1];
|
||||
int value = params[2];
|
||||
ToggleButtonGroup [] buttonsPORT = Controller_Frontend.getPORTbuttons();
|
||||
ToggleButtonGroup [] buttonsPORT = (ToggleButtonGroup[]) frontendController.getPORTbuttons();
|
||||
if (value == 1){
|
||||
setBit(tris, bit);
|
||||
buttonsPORT[(tris-TRISA)*8 + bit].setDisable(false);
|
||||
@ -150,23 +155,23 @@ public class IOPorts {
|
||||
refreshTable(parent);
|
||||
}
|
||||
|
||||
public static void setPORTfromUI(ToggleButtonGroup parent) throws IOException {
|
||||
public void setPORTfromUI(ToggleButtonGroup parent) throws IOException {
|
||||
int [] params = getToggleParams(parent);
|
||||
int port = params[0];
|
||||
int bit = params[1];
|
||||
int value = params [2];
|
||||
value = (value == 1) ? 0 : 1;
|
||||
int oldValue = DataRegister.getDirectBit(port, bit);
|
||||
DataRegister.setDirectBit(port, bit, value);
|
||||
int oldValue = dataRegister.getDirectBit(port, bit);
|
||||
dataRegister.setDirectBit(port, bit, value);
|
||||
refreshPorts();
|
||||
refreshTable(parent);
|
||||
if (port == PORTB && bit >= 4)
|
||||
Interrupts.triggerRBInterrupt(oldValue, value);
|
||||
interrupts.triggerRBInterrupt(oldValue, value);
|
||||
else if (port == PORTB && bit == 0)
|
||||
Interrupts.triggerRB0Interrupt(oldValue, value);
|
||||
interrupts.triggerRB0Interrupt(oldValue, value);
|
||||
}
|
||||
|
||||
public static void setLEDs (boolean[] leds) {
|
||||
public void setLEDs (boolean[] leds) {
|
||||
boolean isAnowDisabled = isLEDenabledA && !leds[0];
|
||||
isLEDenabledA = leds[0];
|
||||
boolean isBnowDisabled = isLEDenabledB && !leds[1];
|
||||
@ -183,17 +188,17 @@ public class IOPorts {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setLEDs (Circle[] a, Circle[] b){
|
||||
allLEDsA = a;
|
||||
allLEDsB = b;
|
||||
public void setLEDs (FrontendSpecificCircle[] a, FrontendSpecificCircle[] b){
|
||||
allLEDsA = (Circle []) a;
|
||||
allLEDsB = (Circle []) b;
|
||||
}
|
||||
|
||||
public static void refreshTable(ToggleButtonGroup parent) {
|
||||
Table.refresh();
|
||||
public void refreshTable(ToggleButtonGroup parent) {
|
||||
table.refresh();
|
||||
CreateWindow.refreshTable();
|
||||
}
|
||||
|
||||
private static int[] getToggleParams(ToggleButtonGroup parent) {
|
||||
private int[] getToggleParams(ToggleButtonGroup parent) {
|
||||
String group = parent.getId();
|
||||
ObservableList<ToggleButton> toggles = parent.getToggles();
|
||||
int fileAddress;
|
||||
@ -213,13 +218,35 @@ public class IOPorts {
|
||||
return new int[]{fileAddress, bit, value};
|
||||
}
|
||||
|
||||
public static void reset() {
|
||||
public void reset() {
|
||||
trisLatch = new int[]{0xFF, 0xFF};
|
||||
dataLatch = new int[2];
|
||||
refreshPorts();
|
||||
}
|
||||
|
||||
public static void resetTRIS (){
|
||||
public void resetTRIS (){ // Only Backend
|
||||
trisLatch = new int[] {0xFF, 0xFF};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
System.out.println("IOPorts.\n");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPORTfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException {
|
||||
setPORTfromUI((ToggleButtonGroup) parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTRISfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException {
|
||||
setTRISfromUI((ToggleButtonGroup) parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshUI(FrontendSpecificToggleButtonGroup[] trisButtons,
|
||||
FrontendSpecificToggleButtonGroup[] portButtons) {
|
||||
refreshUI((ToggleButtonGroup[]) trisButtons, (ToggleButtonGroup[]) portButtons);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,48 +1,54 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class Interrupts {
|
||||
private static final int INTCON = 0xB;
|
||||
private static final int T0IF = 0x2;
|
||||
private static final int ISR = 0x4;
|
||||
private static final int GIE = 0x7;
|
||||
private static final int T0IE = 0x5;
|
||||
private static final int RBIE = 0x3;
|
||||
private static final int RBIF = 0x0;
|
||||
private static final int INTEDG = 0x6;
|
||||
private static final int OPTION = 0x81;
|
||||
private static final int INTE = 0x4;
|
||||
private static final int INTF = 0x1;
|
||||
import fabrik.simulator.pic16f84.interfaces.InterruptInterface;
|
||||
|
||||
public static void triggerTMR0(boolean manual) {
|
||||
triggerInterrupt(T0IF, T0IE);
|
||||
if (manual)
|
||||
DataRegister.increasePC();
|
||||
public class Interrupts extends PICComponent implements InterruptInterface {
|
||||
private final int INTCON = 0xB;
|
||||
private final int T0IF = 0x2;
|
||||
private final int ISR = 0x4;
|
||||
private final int GIE = 0x7;
|
||||
private final int T0IE = 0x5;
|
||||
private final int RBIE = 0x3;
|
||||
private final int RBIF = 0x0;
|
||||
private final int INTEDG = 0x6;
|
||||
private final int OPTION = 0x81;
|
||||
private final int INTE = 0x4;
|
||||
private final int INTF = 0x1;
|
||||
|
||||
|
||||
public Interrupts () {
|
||||
}
|
||||
|
||||
private static void triggerInterrupt(int flag, int enableFlag) {
|
||||
DataRegister.setBit(INTCON, flag);
|
||||
enableFlag = DataRegister.getDirectBit(INTCON, enableFlag);
|
||||
int globalFlag = DataRegister.getDirectBit(INTCON, GIE);
|
||||
public void triggerTMR0(boolean manual) {
|
||||
triggerInterrupt(T0IF, T0IE);
|
||||
if (manual)
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
|
||||
private void triggerInterrupt(int flag, int enableFlag) {
|
||||
dataRegister.setBit(INTCON, flag);
|
||||
enableFlag = dataRegister.getDirectBit(INTCON, enableFlag);
|
||||
int globalFlag = dataRegister.getDirectBit(INTCON, GIE);
|
||||
if (enableFlag == 1) {
|
||||
Controller_Frontend.wakeUpFromSleep();
|
||||
ExecutionState.wakeUp();
|
||||
if (globalFlag == 1) {
|
||||
DataRegister.clearBit(INTCON, GIE);
|
||||
Commands.CALL(ISR);
|
||||
dataRegister.clearBit(INTCON, GIE);
|
||||
commands.CALL(ISR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void triggerRBInterrupt(int oldValue, int newValue) {
|
||||
public void triggerRBInterrupt(int oldValue, int newValue) {
|
||||
if (newValue != oldValue){
|
||||
triggerInterrupt(RBIF, RBIE);
|
||||
DataRegister.increasePC();
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
}
|
||||
|
||||
public static void triggerRB0Interrupt(int oldValue, int newValue){
|
||||
public void triggerRB0Interrupt(int oldValue, int newValue){
|
||||
if (newValue != oldValue){
|
||||
int intedg = DataRegister.getDirectBit(OPTION, INTEDG);
|
||||
int intedg = dataRegister.getDirectBit(OPTION, INTEDG);
|
||||
if (intedg == 1) {
|
||||
if (oldValue == 0 && newValue == 1)
|
||||
triggerInterrupt(INTF, INTE);
|
||||
@ -50,9 +56,13 @@ public class Interrupts {
|
||||
if (oldValue == 1 && newValue == 0)
|
||||
triggerInterrupt(INTF, INTE);
|
||||
}
|
||||
DataRegister.increasePC();
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
25
src/main/java/fabrik/simulator/pic16f84/Main.java
Normal file
25
src/main/java/fabrik/simulator/pic16f84/Main.java
Normal file
@ -0,0 +1,25 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class Main {
|
||||
private static final PICComponentLocator picComponents = new PICComponentLocator(); // Subjekt
|
||||
|
||||
public static void main(String[] args) {
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, commands);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, new DataRegister());
|
||||
picComponents.registerComponent(EEPROMInterface.class, new EEPROM());
|
||||
picComponents.registerComponent(InterruptInterface.class, new Interrupts());
|
||||
picComponents.registerComponent(PreScalerInterface.class, new PreScaler());
|
||||
picComponents.registerComponent(ProgramStackInterface.class, new ProgramStack());
|
||||
picComponents.registerComponent(TimerInterface.class, new Timer());
|
||||
picComponents.registerComponent(WatchdogTimerInterface.class, new WatchdogTimer());
|
||||
CreateWindow window = new CreateWindow();
|
||||
picComponents.registerComponent(WindowManagement.class, window);
|
||||
picComponents.initAll();
|
||||
|
||||
window.startFromMain(new String[]{});
|
||||
}
|
||||
}
|
||||
35
src/main/java/fabrik/simulator/pic16f84/PICComponent.java
Normal file
35
src/main/java/fabrik/simulator/pic16f84/PICComponent.java
Normal file
@ -0,0 +1,35 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public abstract class PICComponent implements PICComponentInterface{
|
||||
protected DataRegisterInterface dataRegister;
|
||||
protected EEPROMInterface eeprom;
|
||||
protected PreScalerInterface preScaler;
|
||||
protected IOPortInterface ioPorts;
|
||||
protected TimerInterface timer;
|
||||
protected InterruptInterface interrupts;
|
||||
protected TableInterface table;
|
||||
protected FrontendControllerInterface frontendController;
|
||||
protected WatchdogTimerInterface watchdogTimer;
|
||||
protected ProgramStackInterface programStack;
|
||||
protected CommandInterface commands;
|
||||
protected ExecutionTimeSubject executionTime;
|
||||
protected ToggleButtonInterface toggleButtonExt;
|
||||
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
toggleButtonExt = locator.getComponent(ToggleButtonInterface.class);
|
||||
dataRegister = locator.getComponent(DataRegisterInterface.class);
|
||||
eeprom = locator.getComponent(EEPROMInterface.class);
|
||||
ioPorts = locator.getComponent(IOPortInterface.class);
|
||||
preScaler = locator.getComponent(PreScalerInterface.class);
|
||||
timer = locator.getComponent(TimerInterface.class);
|
||||
interrupts = locator.getComponent(InterruptInterface.class);
|
||||
frontendController = locator.getComponent(FrontendControllerInterface.class);
|
||||
watchdogTimer = locator.getComponent(WatchdogTimerInterface.class);
|
||||
programStack = locator.getComponent(ProgramStackInterface.class);
|
||||
commands = locator.getComponent(CommandInterface.class);
|
||||
table = locator.getComponent(TableInterface.class);
|
||||
executionTime = locator.getComponent(ExecutionTimeSubject.class);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PICComponentLocator {
|
||||
// https://en.wikipedia.org/wiki/Service_locator_pattern
|
||||
private final HashMap<Class<? extends PICComponentInterface>, PICComponentInterface> componentCatalogue;
|
||||
|
||||
public PICComponentLocator() {
|
||||
super();
|
||||
this.componentCatalogue = new HashMap<>();
|
||||
}
|
||||
|
||||
public void registerComponent (Class<? extends PICComponentInterface> componentClass, PICComponentInterface component) {
|
||||
this.componentCatalogue.put(componentClass, component);
|
||||
}
|
||||
|
||||
public <T extends PICComponentInterface> T getComponent(Class<T> componentClass) {
|
||||
T component = (T) this.componentCatalogue.get(componentClass);
|
||||
return component;
|
||||
}
|
||||
|
||||
public void initAll() {
|
||||
for (PICComponentInterface component : componentCatalogue.values()) component.initialize(this);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,42 +1,60 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class PreScaler {
|
||||
private static final int PSA = 0x3;
|
||||
private static final int OPTION = 0x81;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
private static int scaler = 0b111;
|
||||
public class PreScaler extends PICComponent implements PreScalerInterface {
|
||||
|
||||
public static boolean isPrescalerOnTimer (){
|
||||
return DataRegister.getDirectBit(OPTION, PSA) == 0;
|
||||
private final int PSA = 0x3;
|
||||
private final int OPTION = 0x81;
|
||||
private int scaler;
|
||||
|
||||
public PreScaler () {
|
||||
super();
|
||||
scaler = 0b111;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrescalerOnTimer(){
|
||||
return dataRegister.getDirectBit(OPTION, PSA) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int getScaler() {
|
||||
@Override
|
||||
public int getScaler() {
|
||||
return scaler;
|
||||
}
|
||||
|
||||
public static int getFactor () {
|
||||
int scale = DataRegister.getDirectRegister(OPTION) & 0b111;
|
||||
@Override
|
||||
public int getFactor() {
|
||||
int scale = dataRegister.getDirectRegister(OPTION) & 0b111;
|
||||
int timer = isPrescalerOnTimer() ? 1 : 0;
|
||||
return (int) Math.pow (2, scale+timer);
|
||||
}
|
||||
|
||||
public static void reset (){
|
||||
DataRegister.setDirectBit(OPTION, 0, 0);
|
||||
DataRegister.setDirectBit(OPTION, 1, 0);
|
||||
DataRegister.setDirectBit(OPTION, 2, 0);
|
||||
@Override
|
||||
public void reset(){
|
||||
dataRegister.setDirectBit(OPTION, 0, 0);
|
||||
dataRegister.setDirectBit(OPTION, 1, 0);
|
||||
dataRegister.setDirectBit(OPTION, 2, 0);
|
||||
}
|
||||
|
||||
public static void resetFromRegister() {
|
||||
@Override
|
||||
public void resetFromRegister() {
|
||||
scaler = getFactor();
|
||||
}
|
||||
|
||||
public static void decrement(boolean manual) {
|
||||
@Override
|
||||
public void decrement(boolean manual) {
|
||||
scaler--;
|
||||
if (scaler == 0) {
|
||||
scaler = getFactor();
|
||||
Timer.increment(manual);
|
||||
timer.increment(manual);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.ProgramStackInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ProgramStack {
|
||||
private static List<Integer> returnStack = new ArrayList<>(8);
|
||||
private static int stackIndex = 0;
|
||||
public class ProgramStack extends PICComponent implements ProgramStackInterface {
|
||||
private List<Integer> returnStack = new ArrayList<>(8);
|
||||
private int stackIndex = 0;
|
||||
|
||||
private static void incIndex(){
|
||||
private void incIndex(){
|
||||
if (stackIndex == 7){
|
||||
stackIndex = 0;
|
||||
}
|
||||
@ -16,7 +18,7 @@ public class ProgramStack {
|
||||
}
|
||||
}
|
||||
|
||||
public static void push(int value) {
|
||||
public void push(int value) {
|
||||
if ((returnStack.size() != 8 ) && (returnStack.size() <= stackIndex)){
|
||||
returnStack.add(value);
|
||||
incIndex();
|
||||
@ -27,21 +29,26 @@ public class ProgramStack {
|
||||
}
|
||||
}
|
||||
|
||||
public static int pop() {
|
||||
public int pop() {
|
||||
stackIndex = (stackIndex > 0) ? --stackIndex : 7;
|
||||
return returnStack.get(stackIndex)-1;
|
||||
}
|
||||
|
||||
public static void reset (){
|
||||
public void reset (){
|
||||
returnStack.clear();
|
||||
stackIndex = 0;
|
||||
}
|
||||
|
||||
public static int getStackPointer(){
|
||||
public int getStackPointer(){
|
||||
return stackIndex;
|
||||
}
|
||||
|
||||
public static List<Integer> getStack() {
|
||||
public List<Integer> getStack() {
|
||||
return returnStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,26 +1,22 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.VBox;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
import javafx.geometry.Insets;
|
||||
|
||||
import javafx.scene.chart.PieChart;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
|
||||
import static javafx.application.Application.launch;
|
||||
|
||||
public class Table {
|
||||
|
||||
|
||||
//Hier wird die Tabelle aktualisiert
|
||||
//Tabelle aktualisieren
|
||||
|
||||
public class Table extends PICComponent implements TableInterface {
|
||||
private VBox tableBox;
|
||||
private static final int NUM_COLUMNS = 8; // Anzahl der Spalten
|
||||
private static final double TABLE_WIDTH = 425; // Breite der TableView
|
||||
private static final double TABLE_HEIGHT = 600; // Höhe der TableView
|
||||
@ -41,19 +37,16 @@ public class Table {
|
||||
return s;
|
||||
}
|
||||
|
||||
public VBox getTable(){
|
||||
refresh();
|
||||
return tableBox;
|
||||
}
|
||||
|
||||
public static VBox refresh(){
|
||||
// Erstelle eine Instanz der DataRegister-Klasse
|
||||
|
||||
|
||||
public void refresh() {
|
||||
// Erstelle eine TableView für die Datenanzeige
|
||||
TableView<DataEntry[]> tableView = new TableView<>();
|
||||
tableView.setPrefWidth(TABLE_WIDTH);
|
||||
tableView.setPrefHeight(TABLE_HEIGHT);
|
||||
|
||||
|
||||
|
||||
|
||||
// Erstelle Spalten für die TableView
|
||||
for (int i = 0; i < NUM_COLUMNS; i++) {
|
||||
TableColumn<DataEntry[], String> column = new TableColumn<>("0" + (i));
|
||||
@ -67,16 +60,15 @@ public class Table {
|
||||
});
|
||||
tableView.getColumns().add(column);
|
||||
}
|
||||
|
||||
// Fülle die TableView mit Daten aus dem Array
|
||||
int numRows = (int) Math.ceil((double) DataRegister.getDataRegister().length / NUM_COLUMNS);
|
||||
int numRows = (int) Math.ceil((double) dataRegister.getDataRegister().length / NUM_COLUMNS);
|
||||
for (int row = 0; row < numRows; row++) {
|
||||
DataEntry[] rowData = new DataEntry[NUM_COLUMNS];
|
||||
for (int col = 0; col < NUM_COLUMNS; col++) {
|
||||
int index = row * NUM_COLUMNS + col;
|
||||
if (index < DataRegister.getDataRegister().length) {
|
||||
if (index < dataRegister.getDataRegister().length) {
|
||||
String address = "0x" + formatHex(Integer.toHexString(index).toUpperCase());
|
||||
String value = "0x" + formatHex(Integer.toHexString(DataRegister.getDataRegister()[index]).toUpperCase());
|
||||
String value = "0x" + formatHex(Integer.toHexString(dataRegister.getDataRegister()[index]).toUpperCase());
|
||||
rowData[col] = new DataEntry(address, value);
|
||||
} else {
|
||||
rowData[col] = new DataEntry("", "");
|
||||
@ -89,17 +81,17 @@ public class Table {
|
||||
|
||||
Label spacing = new Label(" ");
|
||||
Label spacing2 = new Label(" ");
|
||||
Label wRegisterLabel = new Label("W-Register: 0x" + formatHex(Integer.toHexString(Commands.get_wRegister()).toUpperCase()));
|
||||
Label cLabel = new Label("Carry-Flag: " + DataRegister.getCarryFlag());
|
||||
Label dcLabel = new Label("DigitCarry-Flag: " + DataRegister.getDigitCarryFlag());
|
||||
Label zLabel = new Label("Zero-Flag: " + DataRegister.getZeroFlag());
|
||||
Label pcLabel = new Label("PC: 0x" + formatHex(Integer.toHexString(DataRegister.getPC()).toUpperCase()));
|
||||
Label pclLabel = new Label("PCL: 0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getPCL())).toUpperCase()));
|
||||
Label pclathLabel = new Label("PCLATH: 0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getPCLATH())).toUpperCase()));
|
||||
Label statusLabel = new Label("STATUS: 0b" + formatBin(Integer.toBinaryString(DataRegister.getRegister(DataRegister.getSTATUS())))+ " (0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getSTATUS())).toUpperCase()) + ")");
|
||||
Label fsrLabel = new Label("FSR: 0x" + formatHex(Integer.toHexString(DataRegister.getFSR()).toUpperCase()));
|
||||
Label prescalerLabel = new Label("Prescaler: 0x" + formatHex(Integer.toHexString(PreScaler.getScaler())).toUpperCase());
|
||||
Label intconLabel = new Label("INTCON: 0b" + formatBin(Integer.toBinaryString(DataRegister.getRegister(DataRegister.getINTCON()))) + " (0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getINTCON())).toUpperCase()) + ")");
|
||||
Label wRegisterLabel = new Label("W-Register: 0x" + formatHex(Integer.toHexString(commands.get_wRegister()).toUpperCase()));
|
||||
Label cLabel = new Label("Carry-Flag: " + dataRegister.getCarryFlag());
|
||||
Label dcLabel = new Label("DigitCarry-Flag: " + dataRegister.getDigitCarryFlag());
|
||||
Label zLabel = new Label("Zero-Flag: " + dataRegister.getZeroFlag());
|
||||
Label pcLabel = new Label("PC: 0x" + formatHex(Integer.toHexString(dataRegister.getPC()).toUpperCase()));
|
||||
Label pclLabel = new Label("PCL: 0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getPCL())).toUpperCase()));
|
||||
Label pclathLabel = new Label("PCLATH: 0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getPCLATH())).toUpperCase()));
|
||||
Label statusLabel = new Label("STATUS: 0b" + formatBin(Integer.toBinaryString(dataRegister.getRegister(dataRegister.getSTATUS())))+ " (0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getSTATUS())).toUpperCase()) + ")");
|
||||
Label fsrLabel = new Label("FSR: 0x" + formatHex(Integer.toHexString(dataRegister.getFSR()).toUpperCase()));
|
||||
Label prescalerLabel = new Label("Prescaler: 0x" + formatHex(Integer.toHexString(preScaler.getScaler())).toUpperCase());
|
||||
Label intconLabel = new Label("INTCON: 0b" + formatBin(Integer.toBinaryString(dataRegister.getRegister(dataRegister.getINTCON()))) + " (0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getINTCON())).toUpperCase()) + ")");
|
||||
wRegisterLabel.setStyle("-fx-font-weight: bold");
|
||||
pcLabel.setStyle("-fx-font-weight: bold");
|
||||
statusLabel.setStyle("-fx-font-weight: bold");
|
||||
@ -123,14 +115,12 @@ public class Table {
|
||||
VBox table = new VBox();
|
||||
table.getChildren().addAll(tableView, labelsAndButton);
|
||||
VBox.setMargin(tableView, new Insets(0, 0, 0, 0));
|
||||
|
||||
return table;
|
||||
|
||||
tableBox = table;
|
||||
}
|
||||
|
||||
private static void triggerReset() {
|
||||
DataRegister.initDataRegister();
|
||||
IOPorts.refreshUI(Controller_Frontend.getTRISbuttons(), Controller_Frontend.getPORTbuttons());
|
||||
private void triggerReset() {
|
||||
dataRegister.initDataRegister();
|
||||
ioPorts.refreshUI(frontendController.getTRISbuttons(), frontendController.getPORTbuttons());
|
||||
CreateWindow.refreshTable();
|
||||
}
|
||||
|
||||
@ -157,5 +147,7 @@ public class Table {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void initialize(PICComponentLocator picComponents) {
|
||||
super.initialize(picComponents);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +1,24 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class Timer {
|
||||
private static final int TIMERREG = 0x1;
|
||||
private static final int T0SE = 0x4;
|
||||
private static final int T0CS = 0x5;
|
||||
private static final int OPTION = 0x81;
|
||||
import fabrik.simulator.pic16f84.interfaces.ExecutionTimeObserver;
|
||||
import fabrik.simulator.pic16f84.interfaces.TimerInterface;
|
||||
|
||||
private static int oldpin = 0;
|
||||
public class Timer extends PICComponent implements TimerInterface, ExecutionTimeObserver {
|
||||
private final int TIMERREG = 0x1;
|
||||
private final int T0SE = 0x4;
|
||||
private final int T0CS = 0x5;
|
||||
private final int OPTION = 0x81;
|
||||
|
||||
private int oldpin = 0;
|
||||
|
||||
public Timer (){
|
||||
}
|
||||
|
||||
public static void cycles(int cycles){
|
||||
if (DataRegister.getDirectBit(OPTION, T0CS) == 0){
|
||||
if (PreScaler.isPrescalerOnTimer()){
|
||||
public void cycles(int cycles){
|
||||
if (dataRegister.getDirectBit(OPTION, T0CS) == 0){
|
||||
if (preScaler.isPrescalerOnTimer()){
|
||||
for (int i = 0; i < cycles; i++){
|
||||
PreScaler.decrement(false);
|
||||
preScaler.decrement(false);
|
||||
}
|
||||
} else {
|
||||
increment(false);
|
||||
@ -22,23 +27,23 @@ public class Timer {
|
||||
}
|
||||
|
||||
|
||||
public static void incrementFromPin (int register){
|
||||
if ((DataRegister.getDirectBit(OPTION, T0CS) == 1) && !Controller_Frontend.isSleeping()){
|
||||
public void incrementFromPin (int register){
|
||||
if ((dataRegister.getDirectBit(OPTION, T0CS) == 1) && !ExecutionState.isSleeping()){
|
||||
int newpin = (register >> 4) & 1;
|
||||
if (newpin != oldpin) {
|
||||
if (DataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
||||
if (dataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
||||
// Low to high
|
||||
if (newpin == 1 && oldpin == 0) {
|
||||
if (PreScaler.isPrescalerOnTimer())
|
||||
PreScaler.decrement(true);
|
||||
if (preScaler.isPrescalerOnTimer())
|
||||
preScaler.decrement(true);
|
||||
else
|
||||
increment(true);
|
||||
}
|
||||
} else {
|
||||
// High to low
|
||||
if (newpin == 0 && oldpin == 1) {
|
||||
if (PreScaler.isPrescalerOnTimer())
|
||||
PreScaler.decrement(true);
|
||||
if (preScaler.isPrescalerOnTimer())
|
||||
preScaler.decrement(true);
|
||||
else
|
||||
increment(true);
|
||||
}
|
||||
@ -48,14 +53,25 @@ public class Timer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void increment(boolean manual) {
|
||||
int timer = DataRegister.getDirectRegister(TIMERREG);
|
||||
public void increment(boolean manual) {
|
||||
int timer = dataRegister.getDirectRegister(TIMERREG);
|
||||
timer++;
|
||||
if (timer > 0xFF){
|
||||
Interrupts.triggerTMR0(manual);
|
||||
DataRegister.setDirectRegister(TIMERREG, 0);
|
||||
interrupts.triggerTMR0(manual);
|
||||
dataRegister.setDirectRegister(TIMERREG, 0);
|
||||
} else {
|
||||
DataRegister.setDirectRegister(1, timer);
|
||||
dataRegister.setDirectRegister(1, timer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
executionTime.registerObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executionTimeChanged() {
|
||||
cycles((int) executionTime.getTotalExecutionTime());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
import fabrik.simulator.pic16f84.interfaces.ToggleButtonInterface;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.scene.control.Toggle;
|
||||
@ -9,17 +12,12 @@ import javafx.scene.input.MouseEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class ToggleButtonGroupExt {
|
||||
public class ToggleButtonGroupExt extends PICComponent implements ToggleButtonInterface, FrontendSpecificObject {
|
||||
|
||||
|
||||
private static ToggleButtonGroupExt me;
|
||||
|
||||
private ToggleButtonGroupExt() {
|
||||
}
|
||||
|
||||
public static ToggleButtonGroupExt get() {
|
||||
if (me == null) {
|
||||
me = new ToggleButtonGroupExt();
|
||||
}
|
||||
return me;
|
||||
public ToggleButtonGroupExt() {
|
||||
}
|
||||
|
||||
|
||||
@ -45,14 +43,14 @@ public class ToggleButtonGroupExt {
|
||||
ToggleButtonGroup parent = (ToggleButtonGroup) ((ToggleButton) mouseEvent.getSource()).getParent();
|
||||
if (parent.getId().contains("TRIS")) {
|
||||
try {
|
||||
IOPorts.setTRISfromUI(parent);
|
||||
ioPorts.setTRISfromUI(parent);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
IOPorts.setPORTfromUI(parent);
|
||||
ioPorts.setPORTfromUI(parent);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
@ -60,4 +58,10 @@ public class ToggleButtonGroupExt {
|
||||
mouseEvent.consume();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
System.out.println("ToggleButtonGroupExt");
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,49 +1,59 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class WatchdogTimer {
|
||||
private static long watchdogTime;
|
||||
private static long lastReset = 0;
|
||||
private static boolean enabled = false;
|
||||
private static long rawtimer = 0;
|
||||
private static long realtimer = 0;
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
private static long getTimeFromRegister() {
|
||||
return (PreScaler.isPrescalerOnTimer()) ? 18L : PreScaler.getFactor() * 18L;
|
||||
public class WatchdogTimer extends PICComponent implements WatchdogTimerInterface {
|
||||
private long watchdogTime;
|
||||
private double lastReset = 0;
|
||||
private boolean enabled = false;
|
||||
private long rawtimer = 0;
|
||||
private long realtimer = 0;
|
||||
|
||||
public WatchdogTimer(){
|
||||
}
|
||||
|
||||
private long getTimeFromRegister() {
|
||||
return (preScaler.isPrescalerOnTimer()) ? 18L : preScaler.getFactor() * 18L;
|
||||
}
|
||||
|
||||
public static void testAndTrigger() {
|
||||
public void testAndTrigger() {
|
||||
watchdogTime = getTimeFromRegister() * 1000;
|
||||
if (enabled) {
|
||||
if (realtimer >= (watchdogTime + lastReset - 1)) {
|
||||
DataRegister.clearBit(3, 4);
|
||||
lastReset = Commands.getTotalExecutionTime();
|
||||
Controller_Frontend.stopRunFromBackend("Watchdog Timer");
|
||||
dataRegister.clearBit(3, 4);
|
||||
lastReset = executionTime.getTotalExecutionTime();
|
||||
frontendController.stopRunFromBackend("Watchdog Timer");
|
||||
}
|
||||
else {
|
||||
rawtimer++;
|
||||
realtimer = (long) (rawtimer * Controller_Frontend.getExecutionTimeMultiplier());
|
||||
realtimer = (long) (rawtimer * executionTime.getExecutionTimeMultiplier());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void reset (){
|
||||
lastReset = Commands.getTotalExecutionTime();
|
||||
public void reset (){
|
||||
lastReset = executionTime.getTotalExecutionTime();
|
||||
rawtimer = 0;
|
||||
realtimer = 0;
|
||||
PreScaler.reset();
|
||||
DataRegister.setBit(3, 3);
|
||||
DataRegister.setBit(3, 4);
|
||||
preScaler.reset();
|
||||
dataRegister.setBit(3, 3);
|
||||
dataRegister.setBit(3, 4);
|
||||
}
|
||||
|
||||
public static void enable() {
|
||||
public void enable() {
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
public static void disable() {
|
||||
public void disable() {
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
public static long get (){
|
||||
public long get (){
|
||||
return realtimer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(PICComponentLocator locator) {
|
||||
super.initialize(locator);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
|
||||
public class Circle extends javafx.scene.shape.Circle implements FrontendSpecificCircle {
|
||||
public Circle () {
|
||||
super();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public interface FrontendSpecificCircle extends FrontendSpecificObject {
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public interface FrontendSpecificObject {
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public interface FrontendSpecificToggleButtonGroup extends FrontendSpecificObject{
|
||||
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public interface FrontendSpecificVBox extends FrontendSpecificObject {
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
import javafx.scene.control.ToggleButton;
|
||||
|
||||
public class ToggleButtonGroup extends com.gluonhq.charm.glisten.control.ToggleButtonGroup implements FrontendSpecificToggleButtonGroup {
|
||||
public ToggleButtonGroup(){
|
||||
super();
|
||||
}
|
||||
|
||||
public ToggleButtonGroup(ToggleButton... toggles) {
|
||||
super(toggles);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package fabrik.simulator.pic16f84.frontendspecifics;
|
||||
|
||||
public class VBox extends javafx.scene.layout.VBox implements FrontendSpecificVBox {
|
||||
public VBox(){
|
||||
super();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface CommandInterface extends PICComponentInterface {
|
||||
void CALL(int isr);
|
||||
|
||||
int get_wRegister();
|
||||
|
||||
void decode(int i);
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface DataRegisterInterface extends PICComponentInterface {
|
||||
void clearBit(int f, int b);
|
||||
|
||||
void setBit(int f, int b);
|
||||
|
||||
void setPC(int pop);
|
||||
|
||||
int getINTCON();
|
||||
|
||||
int getPC();
|
||||
|
||||
void setRegister(int file, int wRegister);
|
||||
|
||||
void determineZeroFlag(int wRegister);
|
||||
|
||||
int getRegister(int file);
|
||||
|
||||
void setCarryFlag(int i);
|
||||
|
||||
void setDigitCarryFlag(int i);
|
||||
|
||||
int getCarryFlag();
|
||||
|
||||
void determineCarryFlag(int result);
|
||||
|
||||
void increasePC();
|
||||
|
||||
void determineDigitCarryFlag(int i);
|
||||
|
||||
int getBit(int address, int bit);
|
||||
|
||||
int getDirectBit(int option, int psa);
|
||||
|
||||
int getDirectRegister(int option);
|
||||
|
||||
void setDirectBit(int option, int i, int i1);
|
||||
|
||||
void setDirectRegister(int porta, int i);
|
||||
|
||||
void resetPC();
|
||||
|
||||
int[] getDataRegister();
|
||||
|
||||
int getDigitCarryFlag();
|
||||
|
||||
int getZeroFlag();
|
||||
|
||||
int getFSR();
|
||||
|
||||
void initDataRegister();
|
||||
|
||||
int getPCL();
|
||||
|
||||
int getPCLATH();
|
||||
|
||||
int getSTATUS();
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface EEPROMInterface extends PICComponentInterface {
|
||||
void registerTime(double executionTime, boolean b);
|
||||
|
||||
void parse(int i, int content, int i1);
|
||||
|
||||
long read(int address);
|
||||
|
||||
void write (int address, long data);
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface ExecutionTimeObserver {
|
||||
void executionTimeChanged();
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
|
||||
public interface FrontendControllerInterface extends PICComponentInterface, FrontendSpecificObject {
|
||||
|
||||
FrontendSpecificToggleButtonGroup[] getPORTbuttons();
|
||||
|
||||
FrontendSpecificToggleButtonGroup[] getTRISbuttons();
|
||||
|
||||
void stopRunFromBackend(String watchdogTimer);
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificCircle;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificToggleButtonGroup;
|
||||
|
||||
public interface IOPortInterface extends PICComponentInterface, FrontendSpecificObject {
|
||||
void resetTRIS();
|
||||
|
||||
void setRegister(int i, int content);
|
||||
|
||||
void clearBit(int i, int bit);
|
||||
|
||||
void setBit(int i, int bit);
|
||||
|
||||
void setPORTfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException;
|
||||
|
||||
void setTRISfromUI(FrontendSpecificToggleButtonGroup parent) throws IOException;
|
||||
|
||||
void refreshUI(FrontendSpecificToggleButtonGroup[] trisButtons, FrontendSpecificToggleButtonGroup[] portButtons);
|
||||
|
||||
void reset();
|
||||
|
||||
void setLEDs(FrontendSpecificCircle[] allLEDsA, FrontendSpecificCircle[] allLEDsB);
|
||||
|
||||
void setLEDs(boolean[] booleans);
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface InterruptInterface extends PICComponentInterface {
|
||||
void triggerRBInterrupt(int oldValue, int value);
|
||||
|
||||
void triggerRB0Interrupt(int oldValue, int value);
|
||||
|
||||
void triggerTMR0(boolean manual);
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.PICComponentLocator;
|
||||
|
||||
public interface PICComponentInterface {
|
||||
void initialize(PICComponentLocator picComponents);
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface PreScalerInterface extends PICComponentInterface{
|
||||
boolean isPrescalerOnTimer();
|
||||
|
||||
int getScaler();
|
||||
|
||||
int getFactor();
|
||||
|
||||
void reset();
|
||||
|
||||
void resetFromRegister();
|
||||
|
||||
void decrement(boolean manual);
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ProgramStackInterface extends PICComponentInterface {
|
||||
int pop();
|
||||
|
||||
void push(int i);
|
||||
|
||||
void reset();
|
||||
|
||||
int getStackPointer();
|
||||
|
||||
List<Integer> getStack();
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificVBox;
|
||||
|
||||
public interface TableInterface extends PICComponentInterface {
|
||||
void refresh();
|
||||
|
||||
FrontendSpecificVBox getTable();
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface TimerInterface extends PICComponentInterface {
|
||||
void cycles(int i);
|
||||
|
||||
void incrementFromPin(int directRegister);
|
||||
|
||||
void increment(boolean manual);
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.ToggleButtonGroup;
|
||||
|
||||
public interface ToggleButtonInterface extends PICComponentInterface, FrontendSpecificObject {
|
||||
void addAlwaysOneSelectedSupport(ToggleButtonGroup allTRISButton);
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
public interface WatchdogTimerInterface extends PICComponentInterface {
|
||||
void reset();
|
||||
|
||||
void testAndTrigger();
|
||||
|
||||
void enable();
|
||||
|
||||
void disable();
|
||||
|
||||
long get();
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package fabrik.simulator.pic16f84.interfaces;
|
||||
|
||||
import fabrik.simulator.pic16f84.frontendspecifics.FrontendSpecificObject;
|
||||
|
||||
public interface WindowManagement extends PICComponentInterface, FrontendSpecificObject {
|
||||
static void refreshTable() {}
|
||||
|
||||
static void startFromMain(String[] args) {}
|
||||
}
|
||||
@ -11,5 +11,9 @@ module fabrik.simulator.pic16f84 {
|
||||
requires json.simple;
|
||||
|
||||
opens fabrik.simulator.pic16f84 to javafx.fxml;
|
||||
opens fabrik.simulator.pic16f84.frontendspecifics to javafx.fxml;
|
||||
exports fabrik.simulator.pic16f84;
|
||||
exports fabrik.simulator.pic16f84.interfaces;
|
||||
exports fabrik.simulator.pic16f84.frontendspecifics;
|
||||
opens fabrik.simulator.pic16f84.interfaces to javafx.fxml;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import fabrik.simulator.pic16f84.frontendspecifics.*?>
|
||||
<?import com.gluonhq.charm.glisten.control.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.collections.*?>
|
||||
@ -11,7 +12,7 @@
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
|
||||
<AnchorPane stylesheets="@styles.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.Controller_Frontend">
|
||||
<AnchorPane stylesheets="@styles.css" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1">
|
||||
|
||||
<children>
|
||||
<ListView fx:id="lstContentListView" layoutY="31.0" prefHeight="645.0" prefWidth="600.0">
|
||||
|
||||
88
src/test/java/fabrik/simulator/pic16f84/CommandsTests.java
Normal file
88
src/test/java/fabrik/simulator/pic16f84/CommandsTests.java
Normal file
@ -0,0 +1,88 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
class CommandsTests {
|
||||
PICComponentLocator picComponents;
|
||||
|
||||
public CommandsTests() {}
|
||||
|
||||
@BeforeEach
|
||||
void resetComponents() {
|
||||
picComponents = new PICComponentLocator();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Execution Time wird korrekt addiert")
|
||||
void executionTimeIsAddedCorrectly() {
|
||||
TimerInterface timerMock = mock(TimerInterface.class);
|
||||
picComponents.registerComponent(TimerInterface.class, timerMock);
|
||||
|
||||
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
|
||||
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
|
||||
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
commands.addExecutionTime(5);
|
||||
|
||||
|
||||
assertEquals(5, commands.getTotalExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Execution Time wird korrekt zurückgesetzt")
|
||||
void executionTimeResetWorks() {
|
||||
TimerInterface timerMock = mock(TimerInterface.class);
|
||||
picComponents.registerComponent(TimerInterface.class, timerMock);
|
||||
|
||||
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
|
||||
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
|
||||
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
commands.addExecutionTime(5);
|
||||
commands.resetTotalExecutionTime();
|
||||
|
||||
|
||||
assertEquals(0, commands.getTotalExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Execution Time Faktor wird berücksichtigt")
|
||||
void executionTimeMultiplierIsUsed() {
|
||||
TimerInterface timerMock = mock(TimerInterface.class);
|
||||
picComponents.registerComponent(TimerInterface.class, timerMock);
|
||||
|
||||
EEPROMInterface eepromMock = mock(EEPROMInterface.class);
|
||||
picComponents.registerComponent(EEPROMInterface.class, eepromMock);
|
||||
|
||||
Commands commands = new Commands();
|
||||
picComponents.registerComponent(CommandInterface.class, commands);
|
||||
picComponents.initAll();
|
||||
|
||||
commands.addExecutionTime(5);
|
||||
commands.setExecutionTimeMultiplier("100 HZ");
|
||||
|
||||
assertEquals(5 * 40, commands.getTotalExecutionTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Decode mit ungültigem Opcode wirft keine Exception")
|
||||
void decodeInvalidOpcodeDoesNotCrash() {
|
||||
CommandInterface commands = new Commands();
|
||||
|
||||
assertDoesNotThrow(() -> commands.decode(1));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
class DataRegisterTests {
|
||||
PICComponentLocator picComponents;
|
||||
|
||||
public DataRegisterTests() {}
|
||||
|
||||
@BeforeEach
|
||||
void resetComponents() {
|
||||
picComponents = new PICComponentLocator();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("DataRegister wird durch Components initialisiert und enthält dann die korrekten Startwerte")
|
||||
void registerGetsInitializedThroughComponents() {
|
||||
IOPortInterface mockIOPorts = mock(IOPortInterface.class);
|
||||
picComponents.registerComponent(IOPortInterface.class, mockIOPorts);
|
||||
|
||||
DataRegisterInterface dataRegister = new DataRegister();
|
||||
picComponents.registerComponent(DataRegisterInterface.class, dataRegister);
|
||||
|
||||
|
||||
picComponents.initAll();
|
||||
int [] expected = {0, 0, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 255, 0, 24, 0, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
int [] actual = dataRegister.getDataRegister();
|
||||
|
||||
assertEquals(expected.length, actual.length);
|
||||
for (int i = 0; i<expected.length; i++){
|
||||
assertEquals(expected[i], actual[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
144
src/test/java/fabrik/simulator/pic16f84/EEPROMTests.java
Normal file
144
src/test/java/fabrik/simulator/pic16f84/EEPROMTests.java
Normal file
@ -0,0 +1,144 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.CommandInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.EEPROMInterface;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
||||
class EEPROMTests {
|
||||
PICComponentLocator picComponents;
|
||||
String savedEEPROM;
|
||||
|
||||
public EEPROMTests() {}
|
||||
|
||||
@BeforeEach
|
||||
void resetComponentsAndReadEEPROM() throws IOException {
|
||||
picComponents = new PICComponentLocator();
|
||||
savedEEPROM = Files.readString(Path.of("eeprom.json"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void rewriteEEPROM() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write(savedEEPROM);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM read gibt gültigen Wert zurück")
|
||||
void eepromReadReturnsValidLong() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{\"0\": 255}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
long value = eeprom.read(0);
|
||||
|
||||
|
||||
assertEquals(255, value);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM write schreibt an die korrekte Adresse in eeprom.json")
|
||||
void eepromWritesCorrectly() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
eeprom.write(3, 123);
|
||||
|
||||
|
||||
assertEquals("{\"3\":123}", Files.readString(Path.of("eeprom.json")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM write schreibt nicht an negative Adressen")
|
||||
void eepromDoesntWriteNegative() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||
|
||||
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
eeprom.write(-1, 1);
|
||||
|
||||
|
||||
assertEquals("{}", Files.readString(Path.of("eeprom.json")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("EEPROM read mit negativem Wert liefert 0")
|
||||
void eepromReadWithNegativeAddress() throws IOException {
|
||||
FileWriter writer = new FileWriter("eeprom.json");
|
||||
writer.write("{\"-1\":5}");
|
||||
writer.close();
|
||||
|
||||
DataRegisterInterface mockDataRegister = Mockito.mock(DataRegisterInterface.class);
|
||||
picComponents.registerComponent(DataRegisterInterface.class, mockDataRegister);
|
||||
|
||||
CommandInterface mockCommands = mock(CommandInterface.class);
|
||||
picComponents.registerComponent(CommandInterface.class, mockCommands);
|
||||
|
||||
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||
|
||||
EEPROMInterface eeprom = new EEPROM();
|
||||
picComponents.registerComponent(EEPROMInterface.class, eeprom);
|
||||
picComponents.initAll();
|
||||
|
||||
|
||||
long result = eeprom.read(-1);
|
||||
|
||||
|
||||
assertEquals(0, result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class WatchDogTimerTests {
|
||||
private PICComponentLocator picComponents;
|
||||
|
||||
@BeforeEach
|
||||
void resetComponents() {
|
||||
picComponents = new PICComponentLocator();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("WatchDogTimer testet ob er triggern soll, triggert korrekt nicht")
|
||||
void watchDogIncrementWithoutTriggering() {
|
||||
PreScalerInterface mockPreScaler = mock(PreScalerInterface.class);
|
||||
when(
|
||||
mockPreScaler.isPrescalerOnTimer()
|
||||
).thenReturn(
|
||||
true
|
||||
);
|
||||
picComponents.registerComponent(PreScalerInterface.class, mockPreScaler);
|
||||
|
||||
|
||||
ExecutionTimeSubject mockExecutionTime = mock(ExecutionTimeSubject.class);
|
||||
when(
|
||||
mockExecutionTime.getExecutionTimeMultiplier()
|
||||
).thenReturn(
|
||||
1.0
|
||||
);
|
||||
picComponents.registerComponent(ExecutionTimeSubject.class, mockExecutionTime);
|
||||
|
||||
WatchdogTimerInterface watchDogTimer = new WatchdogTimer();
|
||||
picComponents.registerComponent(WatchdogTimerInterface.class, watchDogTimer);
|
||||
picComponents.initAll();
|
||||
|
||||
watchDogTimer.enable();
|
||||
watchDogTimer.testAndTrigger();
|
||||
|
||||
|
||||
assertEquals(1, watchDogTimer.get());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user