diff --git a/bin/Control/MyControlModel.class b/bin/Control/MyControlModel.class index 8ab41f7..67e29b1 100644 Binary files a/bin/Control/MyControlModel.class and b/bin/Control/MyControlModel.class differ diff --git a/bin/Control/MyControlView.class b/bin/Control/MyControlView.class index 96c37ce..963c3ef 100644 Binary files a/bin/Control/MyControlView.class and b/bin/Control/MyControlView.class differ diff --git a/bin/Model/BackendCommandProcessing/InformationConnecter.class b/bin/Model/BackendCommandProcessing/InformationConnecter.class deleted file mode 100644 index 82cd500..0000000 Binary files a/bin/Model/BackendCommandProcessing/InformationConnecter.class and /dev/null differ diff --git a/bin/Model/EepromLoader/ReadEepromFile.class b/bin/Model/EepromLoader/ReadProgramFile.class similarity index 86% rename from bin/Model/EepromLoader/ReadEepromFile.class rename to bin/Model/EepromLoader/ReadProgramFile.class index 8444bf8..5391973 100644 Binary files a/bin/Model/EepromLoader/ReadEepromFile.class and b/bin/Model/EepromLoader/ReadProgramFile.class differ diff --git a/bin/Model/Microcontroller/ALU.class b/bin/Model/Microcontroller/ALU.class index f28782d..b65215d 100644 Binary files a/bin/Model/Microcontroller/ALU.class and b/bin/Model/Microcontroller/ALU.class differ diff --git a/bin/Model/Microcontroller/PIC.class b/bin/Model/Microcontroller/PIC.class index 9b66730..c63deae 100644 Binary files a/bin/Model/Microcontroller/PIC.class and b/bin/Model/Microcontroller/PIC.class differ diff --git a/bin/Model/Microcontroller/EEPROM.class b/bin/Model/Microcontroller/PROGRAMMEMORY.class similarity index 80% rename from bin/Model/Microcontroller/EEPROM.class rename to bin/Model/Microcontroller/PROGRAMMEMORY.class index 9ea4632..900c1b9 100644 Binary files a/bin/Model/Microcontroller/EEPROM.class and b/bin/Model/Microcontroller/PROGRAMMEMORY.class differ diff --git a/bin/Model/Microcontroller/RUNTIMER.class b/bin/Model/Microcontroller/RUNTIMER.class index 61997c0..6d5ea5d 100644 Binary files a/bin/Model/Microcontroller/RUNTIMER.class and b/bin/Model/Microcontroller/RUNTIMER.class differ diff --git a/bin/Model/MyModel.class b/bin/Model/MyModel.class index d75f753..c7b48fe 100644 Binary files a/bin/Model/MyModel.class and b/bin/Model/MyModel.class differ diff --git a/bin/View/GUIMenuBar.class b/bin/View/GUIMenuBar.class index febde23..e76feb3 100644 Binary files a/bin/View/GUIMenuBar.class and b/bin/View/GUIMenuBar.class differ diff --git a/src/Control/MyControlModel.java b/src/Control/MyControlModel.java index 4b1ecbc..e30eb8e 100644 --- a/src/Control/MyControlModel.java +++ b/src/Control/MyControlModel.java @@ -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 qCommandsForModel; ConcurrentLinkedQueue 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 diff --git a/src/Control/MyControlView.java b/src/Control/MyControlView.java index 5baf638..3915abf 100644 --- a/src/Control/MyControlView.java +++ b/src/Control/MyControlView.java @@ -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]); diff --git a/src/Model/BackendCommandProcessing/InformationConnecter.java b/src/Model/BackendCommandProcessing/InformationConnecter.java deleted file mode 100755 index 0c74a2d..0000000 --- a/src/Model/BackendCommandProcessing/InformationConnecter.java +++ /dev/null @@ -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; - } -} diff --git a/src/Model/EepromLoader/ReadEepromFile.java b/src/Model/EepromLoader/ReadProgramFile.java old mode 100755 new mode 100644 similarity index 97% rename from src/Model/EepromLoader/ReadEepromFile.java rename to src/Model/EepromLoader/ReadProgramFile.java index 43d21a4..87cbc10 --- a/src/Model/EepromLoader/ReadEepromFile.java +++ b/src/Model/EepromLoader/ReadProgramFile.java @@ -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 dataLines; - ArrayList 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 data) { - - oPCode = new ArrayList(); - - 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 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(); - - 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 dataLines from current this object. - */ - public ArrayList 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 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 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 dataLines; + ArrayList 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 data) { + + oPCode = new ArrayList(); + + 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 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(); + + 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 dataLines from current this object. + */ + public ArrayList 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 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 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); + } + } + } +} diff --git a/src/Model/Microcontroller/ALU.java b/src/Model/Microcontroller/ALU.java index d28e135..1557287 100644 --- a/src/Model/Microcontroller/ALU.java +++ b/src/Model/Microcontroller/ALU.java @@ -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; } diff --git a/src/Model/Microcontroller/PIC.java b/src/Model/Microcontroller/PIC.java index 78a6ced..941183c 100755 --- a/src/Model/Microcontroller/PIC.java +++ b/src/Model/Microcontroller/PIC.java @@ -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) { diff --git a/src/Model/Microcontroller/EEPROM.java b/src/Model/Microcontroller/PROGRAMMEMORY.java old mode 100755 new mode 100644 similarity index 92% rename from src/Model/Microcontroller/EEPROM.java rename to src/Model/Microcontroller/PROGRAMMEMORY.java index 2b64e8e..3bd9eca --- a/src/Model/Microcontroller/EEPROM.java +++ b/src/Model/Microcontroller/PROGRAMMEMORY.java @@ -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; + } +} diff --git a/src/Model/Microcontroller/RUNTIMER.java b/src/Model/Microcontroller/RUNTIMER.java index 524fefd..1009afb 100644 --- a/src/Model/Microcontroller/RUNTIMER.java +++ b/src/Model/Microcontroller/RUNTIMER.java @@ -107,4 +107,12 @@ public class RUNTIMER { }break; } } + + public void enableWDT() { + WDTE = true; + } + + public void disableWDT() { + WDTE = false; + } } \ No newline at end of file diff --git a/src/Model/MyModel.java b/src/Model/MyModel.java index 3d04820..67ad768 100644 --- a/src/Model/MyModel.java +++ b/src/Model/MyModel.java @@ -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) { diff --git a/src/View/GUIMenuBar.java b/src/View/GUIMenuBar.java index 152c1e2..b91c3e2 100644 --- a/src/View/GUIMenuBar.java +++ b/src/View/GUIMenuBar.java @@ -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 oBreakpoints; - ReadEepromFile oRef; + ReadProgramFile oRef; boolean[] bBreakpointSet; ArrayList oMenuItems = new ArrayList();