Changed how breakpoints are handled, reworked programcounter, CALL and GOTO implemented

This commit is contained in:
Meruemon
2022-04-11 14:01:58 +02:00
parent ebeba35782
commit e80c875d44
18 changed files with 105 additions and 106 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

@@ -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);
}
}
}

View File

@@ -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++) {

View File

@@ -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<String> 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);
}
}
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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
}

View File

@@ -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;
}
}