Changed name of eeprom to PROGRAMMEMORY, ReadEepromFile to ReadProgramFile

This commit is contained in:
WickedJack99
2022-04-28 10:18:35 +02:00
parent 393b9d39c6
commit ae946c109a
20 changed files with 388 additions and 520 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,7 +1,7 @@
package Control;
import Model.MyModelData;
import Model.EepromLoader.ReadEepromFile;
import Model.EepromLoader.ReadProgramFile;
import Model.Microcontroller.PIC;
import View.GUIAbout;
import View.GUIHelp;
@@ -33,7 +33,7 @@ public class MyControlModel implements ActionListener {
ConcurrentLinkedQueue<Integer> qCommandsForModel;
ConcurrentLinkedQueue<MyModelData> qDataForModel;
ReadEepromFile oRef;
ReadProgramFile oRef;
int iTestFileLoaded = 0;
boolean[] abBreakpoints;
PIC oPIC;
@@ -82,7 +82,7 @@ public class MyControlModel implements ActionListener {
if (iResponse == JFileChooser.APPROVE_OPTION) {
oFile = new File(oFileChooser.getSelectedFile().getAbsolutePath());
//System.out.println(oFile);
oRef = new ReadEepromFile();
oRef = new ReadProgramFile();
oRef.setData(oFile);
oRef.setOPCode(oRef.getData());
oMyView.getGUITestFileTable().setData(oRef.getData());
@@ -193,7 +193,11 @@ public class MyControlModel implements ActionListener {
//WDT-Enabled Checkbox
if (e.getSource() == oWDTEnabled) {
//Enable/disable watchdog
System.out.println("Watchdog got set to " + oWDTEnabled.isSelected());//TODO
if (oWDTEnabled.isSelected()) {
oPIC.getRuntimer().enableWDT();
} else {
oPIC.getRuntimer().disableWDT();
}
}
//Quarzfrequency

View File

@@ -226,7 +226,7 @@ public class MyControlView {
}
}
public void showEEInterruptPrompt() { //TODO
public void showEEInterruptPrompt() {
if (oPIC.getRam().get_GIE() && oPIC.getRam().get_EEIE() && oPIC.getRam().get_EEIF()) {
Object[] options = {"Ok"};
JOptionPane.showOptionDialog(new JFrame(),asPromptDialogs[1][oMyView.getLanguage()], asPromptTitle[1][oMyView.getLanguage()], JOptionPane.YES_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[1]);

View File

@@ -1,158 +0,0 @@
package Model.BackendCommandProcessing;
import Model.Microcontroller.PIC;
public class InformationConnecter {
public String connectInformation (PIC oPic, int iActualLine, int iLastLine, int iSetBreakpoint, int iResetBreakpoint, long liRuntime, long liWatchdog) {
String sConnectedInformation = "";
for (int i = 0; i < 128; i++) {
sConnectedInformation.concat("FREG " + i + "," + oPic.getRam().get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(false, i) + "\n");
}
int j = 0;
for (int i = 128; i < 256; i++) {
sConnectedInformation.concat("FREG " + i + "," + oPic.getRam().get_Value_Of_Bank_RP0_Bit_Of_Element_At_Adress(true, j) + "\n");
j++;
}
sConnectedInformation.concat("SETLINE " + iActualLine + "\n");
if (iLastLine != iActualLine)
{
sConnectedInformation.concat("RESLINE " + iLastLine + "\n");
}
sConnectedInformation.concat("TIME " + (liRuntime / 100) + " µs\n");
sConnectedInformation.concat("WReg " + oPic.get_WRegister() + "\n");
sConnectedInformation.concat("PCL " + oPic.getRam().get_PCL() + "\n");
sConnectedInformation.concat("PCLATH " + oPic.getRam().get_PCLATH() + "\n");
sConnectedInformation.concat("PCINTERN " + oPic.getRam().get_Programcounter() + "\n");
sConnectedInformation.concat("STATUS " + oPic.getRam().get_STATUS() + "\n");
sConnectedInformation.concat("FSR " + oPic.getRam().get_FSR() + "\n");
sConnectedInformation.concat("OPTION " + 1 + "\n");
//Statusbits
int sC = oPic.getRam().get_Carryflag()? 1:0;
int sDC = oPic.getRam().get_Digitcarryflag()? 1:0;
int sZ = oPic.getRam().get_Zeroflag()? 1:0;
int sPD = oPic.getRam().get_PowerDownFlag()? 1:0;
int sTO = oPic.getRam().get_TimeOutFlag()? 1:0;
int sRP0 = oPic.getRam().get_RP0Bit()? 1:0;
int sRP1 = oPic.getRam().get_RP1Bit()? 1:0;
int sIRP = oPic.getRam().get_Interruptflag()? 1:0;
//Set Statusbits in frontend.
sConnectedInformation.concat("STATUSBIT " + 0 + ", " + sC + "\n");
sConnectedInformation.concat("STATUSBIT " + 1 + ", " + sDC + "\n");
sConnectedInformation.concat("STATUSBIT " + 2 + ", " + sZ + "\n");
sConnectedInformation.concat("STATUSBIT " + 3 + ", " + sPD + "\n");
sConnectedInformation.concat("STATUSBIT " + 4 + ", " + sTO + "\n");
sConnectedInformation.concat("STATUSBIT " + 5 + ", " + sRP0 + "\n");
sConnectedInformation.concat("STATUSBIT " + 6 + ", " + sRP1 + "\n");
sConnectedInformation.concat("STATUSBIT " + 7 + ", " + sIRP + "\n");
//Optionbits
int oPS0 = oPic.getRam().get_PS0()? 1:0;
int oPS1 = oPic.getRam().get_PS1()? 1:0;
int oPS2 = oPic.getRam().get_PS2()? 1:0;
int oPSA = oPic.getRam().get_PSA()? 1:0;
int oTSE = oPic.getRam().get_T0SE()? 1:0;
int oTCS = oPic.getRam().get_T0CS()? 1:0;
int oIEG = oPic.getRam().get_INTEDG()? 1:0;
int oRPU = oPic.getRam().get_RBPU()? 1:0;
//Set Optionbits in frontend.
sConnectedInformation.concat("OPTIONBIT " + 0 + ", " + oPS0 + "\n");
sConnectedInformation.concat("OPTIONBIT " + 1 + ", " + oPS1 + "\n");
sConnectedInformation.concat("OPTIONBIT " + 2 + ", " + oPS2 + "\n");
sConnectedInformation.concat("OPTIONBIT " + 3 + ", " + oPSA + "\n");
sConnectedInformation.concat("OPTIONBIT " + 4 + ", " + oTSE + "\n");
sConnectedInformation.concat("OPTIONBIT " + 5 + ", " + oTCS + "\n");
sConnectedInformation.concat("OPTIONBIT " + 6 + ", " + oIEG + "\n");
sConnectedInformation.concat("OPTIONBIT " + 7 + ", " + oRPU + "\n");
//Intconbits
int iRIF = oPic.getRam().get_RBIF()? 1:0;
int iIF = oPic.getRam().get_INTF()? 1:0;
int iTIF = oPic.getRam().get_T0IF()? 1:0;
int iRIE = oPic.getRam().get_RBIE()? 1:0;
int iIE = oPic.getRam().get_INTE()? 1:0;
int iTIE = oPic.getRam().get_T0IE()? 1:0;
int iEIE = oPic.getRam().get_EEIE()? 1:0;
int iGIE = oPic.getRam().get_GIE()? 1:0;
//Set Intconbits in frontend.
sConnectedInformation.concat("INTCONBIT " + 0 + ", " + iRIF + "\n");
sConnectedInformation.concat("INTCONBIT " + 1 + ", " + iIF + "\n");
sConnectedInformation.concat("INTCONBIT " + 2 + ", " + iTIF + "\n");
sConnectedInformation.concat("INTCONBIT " + 3 + ", " + iRIE + "\n");
sConnectedInformation.concat("INTCONBIT " + 4 + "," + iIE + "\n");
sConnectedInformation.concat("INTCONBIT " + 5 + ", " + iTIE + "\n");
sConnectedInformation.concat("INTCONBIT " + 6 + ", " + iEIE + "\n");
sConnectedInformation.concat("INTCONBIT " + 7 + ", " + iGIE + "\n");
//TRISA in frontend is set.
sConnectedInformation.concat("TRISA " + 0 + "," + ((oPic.getRam().get_TRISA() & 0b00000001) >> 0) + "\n"); //For better understanding
sConnectedInformation.concat("TRISA " + 1 + "," + ((oPic.getRam().get_TRISA() & 0b00000010) >> 1) + "\n");
sConnectedInformation.concat("TRISA " + 2 + "," + ((oPic.getRam().get_TRISA() & 0b00000100) >> 2) + "\n");
sConnectedInformation.concat("TRISA " + 3 + "," + ((oPic.getRam().get_TRISA() & 0b00001000) >> 3) + "\n");
sConnectedInformation.concat("TRISA " + 4 + "," + ((oPic.getRam().get_TRISA() & 0b00010000) >> 4) + "\n");
sConnectedInformation.concat("TRISA " + 5 + "," + ((oPic.getRam().get_TRISA() & 0b00100000) >> 5) + "\n");
sConnectedInformation.concat("TRISA " + 6 + "," + ((oPic.getRam().get_TRISA() & 0b01000000) >> 6) + "\n");
sConnectedInformation.concat("TRISA " + 7 + "," + ((oPic.getRam().get_TRISA() & 0b10000000) >> 7) + "\n");
//PORTA in frontend is set.
sConnectedInformation.concat("PORTA " + 0 + "," + ((oPic.getRam().get_PORTA() & 0b00001) >> 0) + "\n"); //For better understanding
sConnectedInformation.concat("PORTA " + 1 + "," + ((oPic.getRam().get_PORTA() & 0b00010) >> 1) + "\n");
sConnectedInformation.concat("PORTA " + 2 + "," + ((oPic.getRam().get_PORTA() & 0b00100) >> 2) + "\n");
sConnectedInformation.concat("PORTA " + 3 + "," + ((oPic.getRam().get_PORTA() & 0b01000) >> 3) + "\n");
sConnectedInformation.concat("PORTA " + 4 + "," + ((oPic.getRam().get_PORTA() & 0b10000) >> 4) + "\n");
//TRISB in frontend is set.
sConnectedInformation.concat("TRISB " + 0 + "," + ((oPic.getRam().get_TRISB() & 0b00000001) >> 0) + "\n"); //For better understanding
sConnectedInformation.concat("TRISB " + 1 + "," + ((oPic.getRam().get_TRISB() & 0b00000010) >> 1) + "\n");
sConnectedInformation.concat("TRISB " + 2 + "," + ((oPic.getRam().get_TRISB() & 0b00000100) >> 2) + "\n");
sConnectedInformation.concat("TRISB " + 3 + "," + ((oPic.getRam().get_TRISB() & 0b00001000) >> 3) + "\n");
sConnectedInformation.concat("TRISB " + 4 + "," + ((oPic.getRam().get_TRISB() & 0b00010000) >> 4) + "\n");
sConnectedInformation.concat("TRISB " + 5 + "," + ((oPic.getRam().get_TRISB() & 0b00100000) >> 5) + "\n");
sConnectedInformation.concat("TRISB " + 6 + "," + ((oPic.getRam().get_TRISB() & 0b01000000) >> 6) + "\n");
sConnectedInformation.concat("TRISB " + 7 + "," + ((oPic.getRam().get_TRISB() & 0b10000000) >> 7) + "\n");
//PORTB in frontend is set.
sConnectedInformation.concat("PORTB " + 0 + "," + ((oPic.getRam().get_PORTB() & 0b00000001) >> 0) + "\n"); //For better understandin
sConnectedInformation.concat("PORTB " + 1 + "," + ((oPic.getRam().get_PORTB() & 0b00000010) >> 1) + "\n");
sConnectedInformation.concat("PORTB " + 2 + "," + ((oPic.getRam().get_PORTB() & 0b00000100) >> 2) + "\n");
sConnectedInformation.concat("PORTB " + 3 + "," + ((oPic.getRam().get_PORTB() & 0b00001000) >> 3) + "\n");
sConnectedInformation.concat("PORTB " + 4 + "," + ((oPic.getRam().get_PORTB() & 0b00010000) >> 4) + "\n");
sConnectedInformation.concat("PORTB " + 5 + "," + ((oPic.getRam().get_PORTB() & 0b00100000) >> 5) + "\n");
sConnectedInformation.concat("PORTB " + 6 + "," + ((oPic.getRam().get_PORTB() & 0b01000000) >> 6) + "\n");
sConnectedInformation.concat("PORTB " + 7 + "," + ((oPic.getRam().get_PORTB() & 0b10000000) >> 7) + "\n");
//STACK in frontend is set.
sConnectedInformation.concat("STACK " + oPic.getStack().getSTACK()[0] + ","
+ oPic.getStack().getSTACK()[1] + ","
+ oPic.getStack().getSTACK()[2] + ","
+ oPic.getStack().getSTACK()[3] + ","
+ oPic.getStack().getSTACK()[4] + ","
+ oPic.getStack().getSTACK()[5] + ","
+ oPic.getStack().getSTACK()[6] + ","
+ oPic.getStack().getSTACK()[7] + "\n");
//TIMER0
sConnectedInformation.concat("TIMER0 " + oPic.getRam().get_TMR0() + "\n");
//Watchdog in frontend is set. (Doesn't work correctly since watchdog isn't implemented correctly) TODO
sConnectedInformation.concat("WATCHDOG " + liWatchdog + "\n");
sConnectedInformation.concat("PRESCALER " + 1 + ":" + oPic.getRam().get_TMR0_PrescalerRate() + "\n");
if (iSetBreakpoint > -1)
sConnectedInformation.concat("SETBREAK " + iSetBreakpoint + "\n");
if (iResetBreakpoint > -1)
sConnectedInformation.concat("RESBREAK " + iResetBreakpoint + "\n");
else if (iResetBreakpoint == -2) {
sConnectedInformation.concat("RESALLBREAK"); //TODO \n if new string concated
}
return sConnectedInformation;
}
}

View File

@@ -1,236 +1,236 @@
package Model.EepromLoader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import Model.Microcontroller.PIC;
public class ReadEepromFile {
ArrayList<String> dataLines;
ArrayList<String> oPCode;
/**
* Get OP-Code out of String-data-array.
* @param dataArray String-array where OP-Code is.
* @return String-array with only OP-Code.
*/
public void setOPCode(ArrayList<String> data) {
oPCode = new ArrayList<String>();
for (int i = 0; i < data.size(); i++) {
//If element in dataArray at position i is null or a space, this element is not added into the new oPCode-Array.
if (data.get(i) != null && data.get(i).charAt(0) != 32) {
oPCode.add(data.get(i));
}
}
}
public ArrayList<String> getOPCode() {
return oPCode;
}
/**
* Gets whole data of the file.
* @param file
* @throws IOException
*/
public void setData(File file) {
//Creates String-arraylist with whole data.
dataLines = new ArrayList<String>();
try {
FileReader fR = new FileReader(file);
BufferedReader br = new BufferedReader(fR);
String sLine;
while ((sLine = br.readLine()) != null) {
dataLines.add(sLine);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @return ArrayList<String> dataLines from current this object.
*/
public ArrayList<String> getData() {
return dataLines;
}
/**
* Turns hex-values of an overhanded String-array into an int-array with decimal-values.
* [0] = memoryCountIndex
* [1] = commandAsInt
* [2] = dataLineRepresentationIndex
* @param oPCode String-array
* @return int-array
*/
public int[][] getOPCodeArrayCommandAsInt(ArrayList<String> oPCode) {
int[][] aiReturnArray = new int[oPCode.size()][3];
for (int i = 0; i < oPCode.size(); i++) {
for (int k = 0; k < dataLines.size(); k++)
if (oPCode.get(i).equals(dataLines.get(k))) {
aiReturnArray[i][2] = k;
}
}
for (int indexRowOPCode = 0; indexRowOPCode < oPCode.size(); indexRowOPCode++) {
int indexOPCode = 0;
int commandAsInt = 0;
int memoryCount = 0;
//Stops if second space is reached. (After command is read.)
while (indexOPCode < 9) {
switch (indexOPCode) {
case 0: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 0, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 1: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 1, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 2: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 2, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 3: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 3, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 5: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 5, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
case 6: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 6, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
case 7: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 7, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
case 8: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 8, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
}
//Increase location which will be checked by one.
indexOPCode++;
}
aiReturnArray[indexRowOPCode][0] = memoryCount;
aiReturnArray[indexRowOPCode][1] = commandAsInt;
}
return aiReturnArray;
}
/**
* @param iCase Location of the actually checked character.
* @param iIndexRowOPCode Actual row of oPCode.
* @param iMemoryCount
* @param iCommandAsInt
* @return Int-Array with memoryCount [0] and commmandAsInt [1].
*/
public int[] getOPCodeArrayCommandAsIntSubFunction(ArrayList<String> oPCode, int iCase, int iIndexRowOPCode, int iIndexOPCode, int iMemoryCount, int iCommandAsInt) {
int[] aiCaseArray = {4096, 256, 16, 1, 0, 4096, 256, 16, 1};
int[] aiResultArray = new int[2];
int iMemoryCountReturn = iMemoryCount;
int iCommandAsIntReturn = iCommandAsInt;
switch (iCase) {
//0123 0 == 4096 1 == 256 2 == 16 3 == 1
//0(Ascii: 48) 1(49) ... 9(57) / A(Ascii: 65) B(66) ... F(70)
//Checks first four characters of one line of the simulation-file which are hex-represented-characters(0-F)
//These characters are converted into integer-representation to process further.
case 0: //Fallthrough is wanted
case 1: //Fallthrough is wanted
case 2: //Fallthrough is wanted
case 3: {
//0-9
if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 47 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 58) {
iMemoryCountReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 48) * aiCaseArray[iCase];
}
//A-F
else if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 64 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 71) {
iMemoryCountReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 55) * aiCaseArray[iCase];
}
//Else
else {
System.out.println("Expected value between 48 and 57 or 65 and 70 but was " + oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode));
}
}break;
//Checks 5th, 6th, 7th, 8th character of one line of the simulation-file which are hex-represented-characters(0-F)
//These characters are converted into integer-representation to process further.
case 5: //Fallthrough is wanted
case 6: //Fallthrough is wanted
case 7: //Fallthrough is wanted
case 8: {
//0-9
if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 47 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 58) {
iCommandAsIntReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 48) * aiCaseArray[iCase];
}
//A-F
else if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 64 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 71) {
iCommandAsIntReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 55) * aiCaseArray[iCase];
}
//Else
else {
System.out.println("Expected value between 48 and 57 or 65 and 70 but was " + oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode));
}
}break;
}
aiResultArray[0] = iMemoryCountReturn;
aiResultArray[1] = iCommandAsIntReturn;
return aiResultArray;
}
/**
* Reads file and writes instructions to EEPROM.
* @param files String-Array with paths of files.
* @param k index of file in String-Array "files".
* @param oPIC of the main-function.
*/
public void readFileAndWriteToEEPROM(PIC oPIC) {
if (oPCode.size() > 0) {
//Integer-array which will contain oPCode as int-values.
//Get an twodimensional array with int-values.
int[][] oPCodeAsInt = getOPCodeArrayCommandAsInt(oPCode);
//asCommands are written into EEPROM
for (int i = 0; i < oPCodeAsInt.length; i++) {
//The adress where the command will be written in the EEPROM
int memoryAdress = oPCodeAsInt[i][0];
//System.out.println(memoryAdress);
//Command that will be written into the EEPROM
int command = oPCodeAsInt[i][1];
//System.out.println(command);
int iIndex = oPCodeAsInt[i][2];
//asCommands are written into EEPROM
oPIC.getEeprom().setElementXToValueY(memoryAdress, command);
oPIC.getEeprom().setElementXToIndexY(memoryAdress, iIndex);
}
}
}
}
package Model.EepromLoader;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import Model.Microcontroller.PIC;
public class ReadProgramFile {
ArrayList<String> dataLines;
ArrayList<String> oPCode;
/**
* Get OP-Code out of String-data-array.
* @param dataArray String-array where OP-Code is.
* @return String-array with only OP-Code.
*/
public void setOPCode(ArrayList<String> data) {
oPCode = new ArrayList<String>();
for (int i = 0; i < data.size(); i++) {
//If element in dataArray at position i is null or a space, this element is not added into the new oPCode-Array.
if (data.get(i) != null && data.get(i).charAt(0) != 32) {
oPCode.add(data.get(i));
}
}
}
public ArrayList<String> getOPCode() {
return oPCode;
}
/**
* Gets whole data of the file.
* @param file
* @throws IOException
*/
public void setData(File file) {
//Creates String-arraylist with whole data.
dataLines = new ArrayList<String>();
try {
FileReader fR = new FileReader(file);
BufferedReader br = new BufferedReader(fR);
String sLine;
while ((sLine = br.readLine()) != null) {
dataLines.add(sLine);
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @return ArrayList<String> dataLines from current this object.
*/
public ArrayList<String> getData() {
return dataLines;
}
/**
* Turns hex-values of an overhanded String-array into an int-array with decimal-values.
* [0] = memoryCountIndex
* [1] = commandAsInt
* [2] = dataLineRepresentationIndex
* @param oPCode String-array
* @return int-array
*/
public int[][] getOPCodeArrayCommandAsInt(ArrayList<String> oPCode) {
int[][] aiReturnArray = new int[oPCode.size()][3];
for (int i = 0; i < oPCode.size(); i++) {
for (int k = 0; k < dataLines.size(); k++)
if (oPCode.get(i).equals(dataLines.get(k))) {
aiReturnArray[i][2] = k;
}
}
for (int indexRowOPCode = 0; indexRowOPCode < oPCode.size(); indexRowOPCode++) {
int indexOPCode = 0;
int commandAsInt = 0;
int memoryCount = 0;
//Stops if second space is reached. (After command is read.)
while (indexOPCode < 9) {
switch (indexOPCode) {
case 0: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 0, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 1: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 1, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 2: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 2, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 3: {
memoryCount = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 3, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[0]);
}break;
case 5: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 5, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
case 6: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 6, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
case 7: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 7, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
case 8: {
commandAsInt = (getOPCodeArrayCommandAsIntSubFunction(oPCode, 8, indexRowOPCode, indexOPCode, memoryCount, commandAsInt)[1]);
}break;
}
//Increase location which will be checked by one.
indexOPCode++;
}
aiReturnArray[indexRowOPCode][0] = memoryCount;
aiReturnArray[indexRowOPCode][1] = commandAsInt;
}
return aiReturnArray;
}
/**
* @param iCase Location of the actually checked character.
* @param iIndexRowOPCode Actual row of oPCode.
* @param iMemoryCount
* @param iCommandAsInt
* @return Int-Array with memoryCount [0] and commmandAsInt [1].
*/
public int[] getOPCodeArrayCommandAsIntSubFunction(ArrayList<String> oPCode, int iCase, int iIndexRowOPCode, int iIndexOPCode, int iMemoryCount, int iCommandAsInt) {
int[] aiCaseArray = {4096, 256, 16, 1, 0, 4096, 256, 16, 1};
int[] aiResultArray = new int[2];
int iMemoryCountReturn = iMemoryCount;
int iCommandAsIntReturn = iCommandAsInt;
switch (iCase) {
//0123 0 == 4096 1 == 256 2 == 16 3 == 1
//0(Ascii: 48) 1(49) ... 9(57) / A(Ascii: 65) B(66) ... F(70)
//Checks first four characters of one line of the simulation-file which are hex-represented-characters(0-F)
//These characters are converted into integer-representation to process further.
case 0: //Fallthrough is wanted
case 1: //Fallthrough is wanted
case 2: //Fallthrough is wanted
case 3: {
//0-9
if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 47 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 58) {
iMemoryCountReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 48) * aiCaseArray[iCase];
}
//A-F
else if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 64 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 71) {
iMemoryCountReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 55) * aiCaseArray[iCase];
}
//Else
else {
System.out.println("Expected value between 48 and 57 or 65 and 70 but was " + oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode));
}
}break;
//Checks 5th, 6th, 7th, 8th character of one line of the simulation-file which are hex-represented-characters(0-F)
//These characters are converted into integer-representation to process further.
case 5: //Fallthrough is wanted
case 6: //Fallthrough is wanted
case 7: //Fallthrough is wanted
case 8: {
//0-9
if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 47 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 58) {
iCommandAsIntReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 48) * aiCaseArray[iCase];
}
//A-F
else if (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) > 64 && oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) < 71) {
iCommandAsIntReturn += (oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode) - 55) * aiCaseArray[iCase];
}
//Else
else {
System.out.println("Expected value between 48 and 57 or 65 and 70 but was " + oPCode.get(iIndexRowOPCode).charAt(iIndexOPCode));
}
}break;
}
aiResultArray[0] = iMemoryCountReturn;
aiResultArray[1] = iCommandAsIntReturn;
return aiResultArray;
}
/**
* Reads file and writes instructions to EEPROM.
* @param files String-Array with paths of files.
* @param k index of file in String-Array "files".
* @param oPIC of the main-function.
*/
public void readFileAndWriteToEEPROM(PIC oPIC) {
if (oPCode.size() > 0) {
//Integer-array which will contain oPCode as int-values.
//Get an twodimensional array with int-values.
int[][] oPCodeAsInt = getOPCodeArrayCommandAsInt(oPCode);
//asCommands are written into EEPROM
for (int i = 0; i < oPCodeAsInt.length; i++) {
//The adress where the command will be written in the EEPROM
int memoryAdress = oPCodeAsInt[i][0];
//System.out.println(memoryAdress);
//Command that will be written into the EEPROM
int command = oPCodeAsInt[i][1];
//System.out.println(command);
int iIndex = oPCodeAsInt[i][2];
//asCommands are written into EEPROM
oPIC.getEeprom().setElementXToValueY(memoryAdress, command);
oPIC.getEeprom().setElementXToIndexY(memoryAdress, iIndex);
}
}
}
}

View File

@@ -23,7 +23,7 @@ public class ALU {
}
/**
*
* Adds or subtracts iValue1 and iWRegister according to bSubtractionBit.
* @param iValue1
* @param iWRegister
* @param bSubtractionBit
@@ -112,14 +112,26 @@ public class ALU {
return iOutcome;
}
/**
*
* @returns CarryFlag
*/
public boolean getCarryFlag() {
return bCarryFlag;
}
/**
*
* @returns DigitCarryFlag
*/
public boolean getDigitCarryFlag() {
return bDigitCarryFlag;
}
/**
*
* @returns ZeroFlag
*/
public boolean getZeroFlag() {
return bZeroFlag;
}

View File

@@ -13,7 +13,7 @@ public class PIC {
* Parts of PIC.
* Objects are written with a large starting letter.
*/
private EEPROM Eeprom;
private PROGRAMMEMORY Eeprom;
private RAM Ram;
private STACK Stack;
private int WRegister;
@@ -22,7 +22,7 @@ public class PIC {
public PIC() {
//Initialising objects of PIC.
Eeprom = new EEPROM();
Eeprom = new PROGRAMMEMORY();
Ram = new RAM();
Stack = new STACK();
Runtimer = new RUNTIMER(Ram);
@@ -75,7 +75,7 @@ public class PIC {
return Ram;
}
public synchronized EEPROM getEeprom() {
public synchronized PROGRAMMEMORY getEeprom() {
return Eeprom;
}
@@ -1156,8 +1156,9 @@ public class PIC {
* Section 14.8 for more details.
*/
public void SLEEP() {
//TODO pause running (no Thread.sleep()!!!)
//pause running (no Thread.sleep()!!!)
//Not implemented
//Increment programcounter and TMR0 if assigned to TMR0.
Ram.inkrement_Programcounter(1);
if (Ram.get_T0CS() == false) {

View File

@@ -1,113 +1,113 @@
package Model.Microcontroller;
/**
* @author Aaron Moser
* @date 23.06.2021
*/
/**
* Electrical Eraseable Programmable Read Only Memory of the PIC (Programmspeicher)
*/
public class EEPROM
{
private int[][] eeprom;
private int eepromLength = 1024;
private int[] aiProgramLines;
public EEPROM()
{
eeprom = new int[eepromLength][2];
}
public EEPROM(int iLength) {
eeprom = new int[iLength][2];
}
/**
* Returns array of program lines in data
* @return
*/
public int[] getProgramLines() {
return aiProgramLines;
}
/**
* Return element i of program lines in data
* @param i
* @return
*/
public int getProgramLine(int i) {
return aiProgramLines[i];
}
/**
* Sets program lines of data
* @param aiProgLines
*/
public void setProgramLines(int[] aiProgLines) {
aiProgramLines = aiProgLines;
}
/**
* Returns element of index element in eeprom-array.
* @param element index of array.
* @return element at index.
*/
public int getElement(int index) {
int returnValue = -1;
if (index >= 0 && index < 1024) {
returnValue = eeprom[index][0];
}
return returnValue;
}
/**
* Returns index of line at data lines
* @param iIndex
* @return
*/
public int getIndex(int iIndex) {
int returnValue = -1;
if (iIndex >= 0 && iIndex < 1024) {
returnValue = eeprom[iIndex][1];
}
return returnValue;
}
/**
* Returns length of EEPROM
*/
public int getLengthEEPROM() {
return eepromLength;
}
/**
* Set element to value.
* @param index of element.
* @param value of what the element is set to.
* @return true if set worked.
*/
public boolean setElementXToValueY(int index, int value) {
boolean bSetWorked = false;
if ((index >= 0) && (index < 1024)) {
eeprom[index][0] = value;
bSetWorked = true;
}
return bSetWorked;
}
/**
*
* @param iElement
* @param iIndex
* @return
*/
public boolean setElementXToIndexY(int iElement, int iIndex) {
boolean bSetWorked = false;
if ((iElement >= 0) && (iElement < 1024)) {
eeprom[iElement][1] = iIndex;
bSetWorked = true;
}
return bSetWorked;
}
}
package Model.Microcontroller;
/**
* @author Aaron Moser
* @date 23.06.2021
*/
/**
* Electrical Eraseable Programmable Read Only Memory of the PIC (Programmspeicher)
*/
public class PROGRAMMEMORY
{
private int[][] eeprom;
private int eepromLength = 1024;
private int[] aiProgramLines;
public PROGRAMMEMORY()
{
eeprom = new int[eepromLength][2];
}
public PROGRAMMEMORY(int iLength) {
eeprom = new int[iLength][2];
}
/**
* Returns array of program lines in data
* @return
*/
public int[] getProgramLines() {
return aiProgramLines;
}
/**
* Return element i of program lines in data
* @param i
* @return
*/
public int getProgramLine(int i) {
return aiProgramLines[i];
}
/**
* Sets program lines of data
* @param aiProgLines
*/
public void setProgramLines(int[] aiProgLines) {
aiProgramLines = aiProgLines;
}
/**
* Returns element of index element in eeprom-array.
* @param element index of array.
* @return element at index.
*/
public int getElement(int index) {
int returnValue = -1;
if (index >= 0 && index < 1024) {
returnValue = eeprom[index][0];
}
return returnValue;
}
/**
* Returns index of line at data lines
* @param iIndex
* @return
*/
public int getIndex(int iIndex) {
int returnValue = -1;
if (iIndex >= 0 && iIndex < 1024) {
returnValue = eeprom[iIndex][1];
}
return returnValue;
}
/**
* Returns length of EEPROM
*/
public int getLengthEEPROM() {
return eepromLength;
}
/**
* Set element to value.
* @param index of element.
* @param value of what the element is set to.
* @return true if set worked.
*/
public boolean setElementXToValueY(int index, int value) {
boolean bSetWorked = false;
if ((index >= 0) && (index < 1024)) {
eeprom[index][0] = value;
bSetWorked = true;
}
return bSetWorked;
}
/**
*
* @param iElement
* @param iIndex
* @return
*/
public boolean setElementXToIndexY(int iElement, int iIndex) {
boolean bSetWorked = false;
if ((iElement >= 0) && (iElement < 1024)) {
eeprom[iElement][1] = iIndex;
bSetWorked = true;
}
return bSetWorked;
}
}

View File

@@ -107,4 +107,12 @@ public class RUNTIMER {
}break;
}
}
public void enableWDT() {
WDTE = true;
}
public void disableWDT() {
WDTE = false;
}
}

View File

@@ -61,7 +61,8 @@ public class MyModel extends Thread {
}
//Check if interrupt was acknowledged
if (oPIC.interruptAcknowledged()) {
//TODO
//Execute ISR
oPIC.InterruptServiceRoutine();
} else {
//Check if breakpoints initialized
if (abBreakpoints != null) {

View File

@@ -11,14 +11,14 @@ import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import Model.EepromLoader.ReadEepromFile;
import Model.EepromLoader.ReadProgramFile;
public class GUIMenuBar extends JMenuBar {
MyView oMyView;
ArrayList<JCheckBox> oBreakpoints;
ReadEepromFile oRef;
ReadProgramFile oRef;
boolean[] bBreakpointSet;
ArrayList<JMenuItem> oMenuItems = new ArrayList<JMenuItem>();