diff --git a/bin/Control/MyControlModel.class b/bin/Control/MyControlModel.class index 644cc85..174dd84 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 ca9be9c..f978d42 100644 Binary files a/bin/Control/MyControlView.class and b/bin/Control/MyControlView.class differ diff --git a/bin/Model/EepromLoader/ReadEepromFile.class b/bin/Model/EepromLoader/ReadEepromFile.class index 8a1fd98..2258db2 100644 Binary files a/bin/Model/EepromLoader/ReadEepromFile.class and b/bin/Model/EepromLoader/ReadEepromFile.class differ diff --git a/bin/Model/Microcontroller/Bitmask.class b/bin/Model/Microcontroller/Bitmask.class index 0096de6..2912924 100644 Binary files a/bin/Model/Microcontroller/Bitmask.class and b/bin/Model/Microcontroller/Bitmask.class differ diff --git a/bin/Model/Microcontroller/EEPROM.class b/bin/Model/Microcontroller/EEPROM.class index f50d03e..1a83fd9 100644 Binary files a/bin/Model/Microcontroller/EEPROM.class and b/bin/Model/Microcontroller/EEPROM.class differ diff --git a/bin/Model/Microcontroller/PIC.class b/bin/Model/Microcontroller/PIC.class index 71b082c..88b1956 100644 Binary files a/bin/Model/Microcontroller/PIC.class and b/bin/Model/Microcontroller/PIC.class differ diff --git a/bin/Model/Microcontroller/RAM.class b/bin/Model/Microcontroller/RAM.class index b484a8d..cfd5351 100644 Binary files a/bin/Model/Microcontroller/RAM.class and b/bin/Model/Microcontroller/RAM.class differ diff --git a/bin/Model/MyModel.class b/bin/Model/MyModel.class index b0c22cc..73e63a6 100644 Binary files a/bin/Model/MyModel.class and b/bin/Model/MyModel.class differ diff --git a/bin/View/MyViewData.class b/bin/View/MyViewData.class deleted file mode 100644 index 21eb421..0000000 Binary files a/bin/View/MyViewData.class and /dev/null differ diff --git a/src/Control/MyControlModel.java b/src/Control/MyControlModel.java index 53bd77f..2e39df7 100644 --- a/src/Control/MyControlModel.java +++ b/src/Control/MyControlModel.java @@ -88,6 +88,7 @@ public class MyControlModel implements ActionListener { oRef.readFileAndWriteToEEPROM(oPIC); oMyView.updateWindow(); iTestFileLoaded = 1; + resetProgramModel(); oMyModelData.setPIC(oPIC); oMyModelData.setBreakpoints(abBreakpoints); qDataForModel.add(oMyModelData); @@ -142,22 +143,26 @@ public class MyControlModel implements ActionListener { } } oPIC.getEeprom().setProgramLines(aiProgramLines); - abBreakpoints = new boolean[iOPCodeSize]; + abBreakpoints = new boolean[oPIC.getEeprom().getLengthEEPROM()]; } private void controlBreakpoints(ActionEvent e) { if (oRef != null) { int iOPCode = oRef.getOPCode().size(); if (iOPCode > 0) { + int [][] aiiOPCodeInformation = oRef.getOPCodeArrayCommandAsInt(oRef.getOPCode()); for (int i = 0; i < oBreakpoints.size(); i++) { if (e.getSource() == oBreakpoints.get(i)) { - for (int j = 0; j < iOPCode; j++) { - if (oRef.getOPCode().get(j).equals(oRef.getData().get(i))) { - abBreakpoints[j] = !abBreakpoints[j]; - oMyModelData.setBreakpoints(abBreakpoints); - qDataForModel.add(oMyModelData); + //i = index of breakpoint which got set / reset + for (int j = 0; j < aiiOPCodeInformation.length; j++) { + //aiiOPCodeInformation[j][0] index of eepromindex + //aiiOPCodeInformation[j][2] index of breakpoint + if (aiiOPCodeInformation[j][2] == i) { + abBreakpoints[aiiOPCodeInformation[j][0]] = !abBreakpoints[aiiOPCodeInformation[j][0]]; } } + oMyModelData.setBreakpoints(abBreakpoints); + qDataForModel.add(oMyModelData); } } } diff --git a/src/Control/MyControlView.java b/src/Control/MyControlView.java index e8371af..1e0ebe0 100644 --- a/src/Control/MyControlView.java +++ b/src/Control/MyControlView.java @@ -178,8 +178,14 @@ public class MyControlView { public void setTestFileTable() { if (oPIC.getEeprom().getProgramLines() != null) { if (oPIC.getRam().get_LastProgramcounter() > -1) { - oMyView.getGUITestFileTable().unmarkLine(oPIC.getEeprom().getProgramLine(oPIC.getRam().get_LastProgramcounter())); - oMyView.getGUITestFileTable().markLine(oPIC.getEeprom().getProgramLine(oPIC.getRam().get_Programcounter())); + + int iL = oPIC.getRam().get_LastProgramcounter(); + + int iProgC = oPIC.getRam().get_Programcounter(); + + oMyView.getGUITestFileTable().unmarkLine(oPIC.getEeprom().getIndex(iL)); + oMyView.getGUITestFileTable().markLine(oPIC.getEeprom().getIndex(iProgC)); + } else { int[] aiProgList = oPIC.getEeprom().getProgramLines(); for (int i = 0; i < aiProgList.length; i++) { diff --git a/src/Model/EepromLoader/ReadEepromFile.java b/src/Model/EepromLoader/ReadEepromFile.java index be24f67..43d21a4 100755 --- a/src/Model/EepromLoader/ReadEepromFile.java +++ b/src/Model/EepromLoader/ReadEepromFile.java @@ -67,11 +67,21 @@ public class ReadEepromFile { /** * 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()][2]; + 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; @@ -204,9 +214,6 @@ public class ReadEepromFile { //Get an twodimensional array with int-values. int[][] oPCodeAsInt = getOPCodeArrayCommandAsInt(oPCode); - //Set length of eeprom for programend. - oPIC.getEeprom().setLengthEEPROM(oPCodeAsInt.length); - //asCommands are written into EEPROM for (int i = 0; i < oPCodeAsInt.length; i++) { //The adress where the command will be written in the EEPROM @@ -217,8 +224,12 @@ public class ReadEepromFile { 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/Bitmask.java b/src/Model/Microcontroller/Bitmask.java index 52dd5ab..2e735ab 100755 --- a/src/Model/Microcontroller/Bitmask.java +++ b/src/Model/Microcontroller/Bitmask.java @@ -7,7 +7,7 @@ public class Bitmask { * @param oPIC */ public int bitMaskDecoderAndExecuteCommand(int iCommandAsIntToMask, PIC oPIC) { - System.out.println("Command " + Integer.toHexString(iCommandAsIntToMask)); + //System.out.println("Command " + Integer.toHexString(iCommandAsIntToMask)); //Return-value will be -1 if command can't be read. int iDecodedCommand = -1; diff --git a/src/Model/Microcontroller/EEPROM.java b/src/Model/Microcontroller/EEPROM.java index 3f82989..2b64e8e 100755 --- a/src/Model/Microcontroller/EEPROM.java +++ b/src/Model/Microcontroller/EEPROM.java @@ -9,14 +9,18 @@ package Model.Microcontroller; */ public class EEPROM { - private int[] eeprom; - private int eepromLength = 0; + private int[][] eeprom; + private int eepromLength = 1024; private int[] aiProgramLines; public EEPROM() { - eeprom = new int[1024]; + eeprom = new int[eepromLength][2]; + } + + public EEPROM(int iLength) { + eeprom = new int[iLength][2]; } /** @@ -49,23 +53,31 @@ public class EEPROM * @param element index of array. * @return element at index. */ - public int getElement(int index) - { + public int getElement(int index) { int returnValue = -1; - - if (index >= 0 && index <= 1024) - { - returnValue = eeprom[index]; + 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() - { + public int getLengthEEPROM() { return eepromLength; } @@ -75,25 +87,27 @@ public class EEPROM * @param value of what the element is set to. * @return true if set worked. */ - public boolean setElementXToValueY(int index, int value) - { - boolean setWorked = false; - - if ((index >= 0) && (index <= 1024)) - { - eeprom[index] = value; - setWorked = true; + public boolean setElementXToValueY(int index, int value) { + boolean bSetWorked = false; + if ((index >= 0) && (index < 1024)) { + eeprom[index][0] = value; + bSetWorked = true; } - - return setWorked; - } + return bSetWorked; + } /** - * Length of eeprom gets restricted. - * @param length is new length. + * + * @param iElement + * @param iIndex + * @return */ - public void setLengthEEPROM(int length) - { - eepromLength = length; - } + 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/PIC.java b/src/Model/Microcontroller/PIC.java index 4bdfc7e..483f8a6 100755 --- a/src/Model/Microcontroller/PIC.java +++ b/src/Model/Microcontroller/PIC.java @@ -479,21 +479,16 @@ public class PIC { public void CALL(int elevenK) { //Push next instruction on STACK. Stack.pushReturnAdressOnStack(Ram.get_Programcounter() + 1); - - //Get upper two bits of PCLATH and shift it by eight. - int shiftedPCLATH = (Ram.get_PCLATH() & 0b11000) << 8; - - //Create new address out of shifted PCLATH and elevenK. - int newPC = shiftedPCLATH | elevenK; //Set Programmcounter to new address. - Ram.set_Programcounter(newPC); - //Increment TMR0 if interbnal instruction cycle assigned to TMR0. + Ram.set_Programcounter(elevenK + ((Ram.get_PCLATH() & 0b11000) << 8)); + + //Increment TMR0 if internal instruction cycle assigned to TMR0. if (Ram.get_T0CS() == false) Ram.increment_TMR0(); //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. - Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + Ram.set_PCL(Ram.get_Programcounter() & 0b11111111); Runtimer.incrementRuntime(); } @@ -727,10 +722,10 @@ public class PIC { * GOTO is a two cycle instruction. */ public void GOTO(int elevenK) { - //elevenK OR ((PCLATH AND 0b11000) << 8) - int result = elevenK | ((Ram.get_PCLATH() & 0b11000) << 8); - Ram.set_Programcounter(result); + //Set Programmcounter to new address. + Ram.set_Programcounter(elevenK + ((Ram.get_PCLATH() & 0b11000) << 8)); + //Increment TMR0 if internal instruction cycle assigned to TMR0. if (Ram.get_T0CS() == false) Ram.increment_TMR0(); @@ -1004,7 +999,7 @@ public class PIC { Ram.increment_TMR0(); //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. - Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + Ram.set_PCL(Ram.get_Programcounter() & 0b11111111); Runtimer.incrementRuntime(); } @@ -1017,11 +1012,12 @@ public class PIC { public void NOP() { //Increment programcounter and TMR0 if assigned to TMR0. Ram.inkrement_Programcounter(1, 0); //Kind of call + if (Ram.get_T0CS() == false) Ram.increment_TMR0(); //Each Instruction has to split Programmcounter to PC and PCLATH because Ram can't see RAM. - Ram.set_PCL(Ram.get_Programcounter() & 0b0000011111111); + Ram.set_PCL(Ram.get_Programcounter() & 0b11111111); Runtimer.incrementRuntime(); } diff --git a/src/Model/Microcontroller/RAM.java b/src/Model/Microcontroller/RAM.java index b5dff93..6fc13e4 100755 --- a/src/Model/Microcontroller/RAM.java +++ b/src/Model/Microcontroller/RAM.java @@ -20,6 +20,8 @@ public class RAM { //Bank1 of the PIC-RAM private int[] bank1; + private int iProgramcounter = 0; + //Last programmcounter for function getLastLine in main. private int lastProgramcounter = -1; @@ -114,6 +116,7 @@ public class RAM { }break; case 2: { set_PCL(value); + set_Programcounter(value + (get_PCLATH() << 8)); }break; case 3: { set_STATUS(value); @@ -623,9 +626,8 @@ public class RAM { return (get_STATUS() & 0b10000000) == 128; } - //Bank0 PCL public synchronized int get_Programcounter() { - return (bank0[2]); + return iProgramcounter; } public synchronized int get_LastProgramcounter() { @@ -637,19 +639,10 @@ public class RAM { * @param value * @param kindOfCall 0 at normal instruction, 1 at Fetchzycle,... 2 at Jumpcommand, 3 at ... */ - public synchronized void inkrement_Programcounter(int value, int kindOfCall) { - if (bank0[2] >= 0 && bank0[2] <= 255) { - lastProgramcounter = bank0[2]; - bank0[2] += value; - } else { - if (kindOfCall == 0) { - //Nothing happens - } - - if (kindOfCall == 1) { - bank0[2] = 0; //Wrap-Around at fetchcycle - } - } + public synchronized void inkrement_Programcounter(int value, int kindOfCall) { + lastProgramcounter = get_Programcounter(); + iProgramcounter += value; + iProgramcounter &= 0x3FF; } /** @@ -657,12 +650,9 @@ public class RAM { * @param value to decrement PC by. */ public synchronized void dekrement_Programcounter(int value) { - if (bank0[2] > 0 && bank0[2] <= 255) { - lastProgramcounter = bank0[2]; - bank0[2] -= value; - } else { - throw new IndexOutOfBoundsException(); - } + lastProgramcounter = get_Programcounter(); + iProgramcounter -= value; + iProgramcounter &= 0x3FF; } /** @@ -670,18 +660,9 @@ public class RAM { * @param value to set PC to. * @returns true if set worked, else false if set didn't work. */ - public synchronized boolean set_Programcounter(int value) { - boolean setWorked = false; - - if (value >= 0 && value <= 255) { - lastProgramcounter = bank0[2]; - bank0[2] = value; - setWorked = true; - } else { - throw new IndexOutOfBoundsException(); - } - - return setWorked; + public synchronized void set_Programcounter(int value) { + lastProgramcounter = iProgramcounter; + iProgramcounter = value; } //Bank0 PORTA diff --git a/src/Model/MyModel.java b/src/Model/MyModel.java index 0ca3b1d..d155c80 100644 --- a/src/Model/MyModel.java +++ b/src/Model/MyModel.java @@ -39,7 +39,7 @@ public class MyModel extends Thread { } //Check if element at command-queue if (!qReceivedCommands.isEmpty()) { - /* -1 == ERROR, 0 == END, 1 == START, 2 == PAUSE, 3 == RESET*/ + /* -1 == ERROR, 0 == END, 1 == START, 2 == PAUSE, 3 == RESET 4 == STEP*/ iProgState = qReceivedCommands.poll(); switch (iProgState) { case (-1): { @@ -86,7 +86,9 @@ public class MyModel extends Thread { case (4): { if (abBreakpoints != null) { //Check if breakpoint is set - if (!abBreakpoints[oPIC.getRam().get_Programcounter()]) { + int iProgC = oPIC.getRam().get_Programcounter(); + iProgC &= abBreakpoints.length; + if (!abBreakpoints[iProgC]) { step(); qDataToView.add(oPIC); //TODO } diff --git a/src/View/MyViewData.java b/src/View/MyViewData.java deleted file mode 100644 index bbb0baa..0000000 --- a/src/View/MyViewData.java +++ /dev/null @@ -1,16 +0,0 @@ -package View; - -import Model.Microcontroller.PIC; - -public class MyViewData { - private PIC oPIC; - - public PIC getPIC() { - return oPIC; - } - - public void setPIC(PIC oPIC) { - this.oPIC = oPIC; - } - -}