This commit is contained in:
2024-04-26 20:21:39 +02:00
parent b4f49dbb97
commit 0ea1143934
6 changed files with 237 additions and 49 deletions

View File

@ -1,61 +1,65 @@
package fabrik.simulator.pic16f84;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.FileReader;
public class Controller_FileSelect {
private int [] prog;
@FXML
protected void selectFileLST(ActionEvent event) throws IOException {
private TextArea lstContentLabel;
@FXML
protected void selectFileLST(ActionEvent event){
File selectedFile = chooseLSTFile();
if(selectedFile != null){
displayLSTFileContent(selectedFile);
}
}
private File chooseLSTFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open LST File");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("LST-Dateien", "*.LST", "*.lst"),
new FileChooser.ExtensionFilter("Alle Dateien", "*.*"));
File selectedFile = fileChooser.showOpenDialog(new Stage());
new FileChooser.ExtensionFilter("LST Files", "*.lst"),
new FileChooser.ExtensionFilter("All Files", "*.*"));
return fileChooser.showOpenDialog(null);
}
if (selectedFile != null) {
prog = ParseFile.parseDatei(selectedFile.getAbsolutePath());
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
FXMLLoader fxmlLoader = new FXMLLoader(CreateWindow.class.getResource("MainBody.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1200, 800);
stage.setTitle("PIC16F84-Simulator Hauptseite");
stage.setScene(scene);
stage.show();
System.out.println("\n");
DataRegister.initDataRegister();
while (true) {
Scanner reader = new Scanner(System.in);
System.out.println("\nWeiter? ");
int n = reader.nextInt();
if (n != 0) {
Commands.decode(prog[DataRegister.getPC()]);
System.out.println("\nPC: " + DataRegister.getPC());
System.out.println("FSR: " + DataRegister.getFSR());
System.out.println("PCL: " + DataRegister.getRegister(0x2));
System.out.println("PCLATH: " + DataRegister.getRegister(0xA));
System.out.println("W: " + Commands.get_wRegister());
System.out.println("C: " + DataRegister.getCarryFlag());
System.out.println("DC: " + DataRegister.getDigitCarryFlag());
System.out.println("StackPointer: " + ProgramStack.getStackPointer());
System.out.println(ProgramStack.getStack());
System.out.printf(Arrays.toString(DataRegister.getDataRegister()));
DataRegister.increasePC();
}
@FXML
private void displayLSTFileContent(File selectedFile) {
try (BufferedReader reader = new BufferedReader(new FileReader(selectedFile))) {
StringBuilder content = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
}
lstContentLabel.setText(content.toString());
} catch (IOException e) {
e.printStackTrace();
}
}
public int[] getProg() {
return prog;
}
}

View File

@ -1,23 +1,109 @@
package fabrik.simulator.pic16f84;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.io.IOException;
public class CreateWindow extends Application {
private static final int NUM_COLUMNS = 8; // Anzahl der Spalten
@Override
public void start(Stage stage) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(CreateWindow.class.getResource("FileSelector.fxml"));
Scene scene = new Scene(fxmlLoader.load(), 1200, 800);
stage.setTitle("PIC16F84-Simulator Datei auswählen");
stage.setScene(scene);
stage.show();
public void start(Stage primaryStage) throws IOException {
// Erstelle eine Instanz der DataRegister-Klasse
DataRegister.initDataRegister();
// Erstelle eine TableView für die Datenanzeige
TableView<DataEntry[]> tableView = new TableView<>();
// Erstelle Spalten für die TableView
for (int i = 0; i < NUM_COLUMNS; i++) {
TableColumn<DataEntry[], String> column = new TableColumn<>("0" + (i + 1));
final int columnIndex = i;
column.setCellValueFactory(cellData -> {
if (cellData.getValue() != null && cellData.getValue().length > columnIndex) {
return new SimpleStringProperty(cellData.getValue()[columnIndex].getValue());
} else {
return new SimpleStringProperty("");
}
});
tableView.getColumns().add(column);
}
// Fülle die TableView mit Daten aus dem Array
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) {
String address = "0x" + Integer.toHexString(index).toUpperCase();
String value = "0x" + Integer.toHexString(DataRegister.getDataRegister()[index]).toUpperCase();
rowData[col] = new DataEntry(address, value);
} else {
rowData[col] = new DataEntry("", "");
}
}
tableView.getItems().add(rowData);
}
// Erstelle Labels für die Spezialregister
Label pclLabel = new Label("PCL: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getPCL())).toUpperCase());
Label statusLabel = new Label("STATUS: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getSTATUS())).toUpperCase());
Label fsrLabel = new Label("FSR: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getFSR())).toUpperCase());
Label pclathLabel = new Label("PCLATH: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getPCLATH())).toUpperCase());
Label intconLabel = new Label("INTCON: 0x" + Integer.toHexString(DataRegister.getRegister(DataRegister.getINTCON())).toUpperCase());
FXMLLoader fxmlLoader = new FXMLLoader(CreateWindow.class.getResource("frontend.fxml"));
Parent loadedRoot = fxmlLoader.load();
// Erstelle einen VBox, um die TableView und Labels anzuzeigen
VBox root = new VBox();
root.getChildren().addAll(tableView, pclLabel, statusLabel, fsrLabel, pclathLabel, intconLabel);
AnchorPane Parent = new AnchorPane();
Parent.getChildren().addAll(root, loadedRoot);
Scene scene = new Scene(Parent, 1600, 800);
primaryStage.setScene(scene);
primaryStage.setTitle("Simulator");
primaryStage.show();
}
public static void main(String[] args) {
launch();
launch(args);
}
// Hilfsklasse für die Datenanzeige in der TableView
public static 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() {
return value;
}
}
}

View File

@ -0,0 +1,22 @@
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;
}
}

View File

@ -231,4 +231,21 @@ public class DataRegister {
return digitCarryFlag;
}
public static int getPCL() {
return PCL;
}
public static int getSTATUS() {
return STATUS;
}
public static int getPCLATH() {
return PCLATH;
}
public static int getINTCON() {
return INTCON;
}
}

View File

@ -8,6 +8,7 @@
xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.Controller_FileSelect">
<VBox alignment="CENTER" prefHeight="500.0" prefWidth="500.0" AnchorPane.bottomAnchor="0.0"
AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Label text="Willkommen beim PIC-Simulator!" textAlignment="CENTER">
<padding>
<Insets bottom="10.0"/>

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<VBox prefHeight="1400.0" prefWidth="1440.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fabrik.simulator.pic16f84.Controller_FileSelect">
<children>
<MenuBar prefHeight="26.0" prefWidth="673.0" VBox.vgrow="NEVER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="New" />
<MenuItem mnemonicParsing="false" onAction="#selectFileLST" text="Open…" />
<Menu mnemonicParsing="false" text="Open Recent" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Close" />
<MenuItem mnemonicParsing="false" text="Save" />
<MenuItem mnemonicParsing="false" text="Save As...." />
<MenuItem mnemonicParsing="false" text="Revert" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Preferences…" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Quit" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Undo" />
<MenuItem mnemonicParsing="false" text="Redo" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Cut" />
<MenuItem mnemonicParsing="false" text="Copy" />
<MenuItem mnemonicParsing="false" text="Paste" />
<MenuItem mnemonicParsing="false" text="Delete" />
<SeparatorMenuItem mnemonicParsing="false" />
<MenuItem mnemonicParsing="false" text="Select All" />
<MenuItem mnemonicParsing="false" text="Unselect All" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About MyHelloApp" />
</items>
</Menu>
</menus>
</MenuBar>
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<children>
<TextArea fx:id="lstContentLabel" editable="false" layoutX="684.0" layoutY="27.0" wrapText="true" />
</children>
</AnchorPane>
</children>
</VBox>