diff --git a/de/darkress/pic16f84sim/commands/Retlw.java b/de/darkress/pic16f84sim/commands/Retlw.java index dba9c94..0e73aeb 100644 --- a/de/darkress/pic16f84sim/commands/Retlw.java +++ b/de/darkress/pic16f84sim/commands/Retlw.java @@ -17,8 +17,6 @@ public class Retlw extends CommandUtils implements Command public void execute() { Memory.workingRegister = literal; - ProgramCounter.setPcFrom11BitLiteral(Stack.pop()); - //TODO: This may need some rework since it does not really load all 13 Bit into the PC. Only 8 Bit are - // effectively set + ProgramCounter.setPcFromStack(Stack.pop()); } } diff --git a/de/darkress/pic16f84sim/commands/Return.java b/de/darkress/pic16f84sim/commands/Return.java index 8f7f630..9426725 100644 --- a/de/darkress/pic16f84sim/commands/Return.java +++ b/de/darkress/pic16f84sim/commands/Return.java @@ -8,8 +8,6 @@ public class Return extends CommandUtils implements Command @Override public void execute() { - ProgramCounter.setPcFrom11BitLiteral(Stack.pop()); - //TODO: This may need some rework since it does not really load all 13 Bit into the PC. Only 8 Bit are - // effectively set + ProgramCounter.setPcFromStack(Stack.pop()); } } diff --git a/de/darkress/pic16f84sim/microcontroller/Memory.java b/de/darkress/pic16f84sim/microcontroller/Memory.java index fdf8a6d..d701a15 100644 --- a/de/darkress/pic16f84sim/microcontroller/Memory.java +++ b/de/darkress/pic16f84sim/microcontroller/Memory.java @@ -59,6 +59,10 @@ public class Memory } memory[address] = data; memory[address + 128] = data; //Ensure data is written to both banks to simulate mapping + if(address == 0x2) //Check if PCL is destination + { + ProgramCounter.loadPc(); + } } private static int getDataFromIndirectAddress(int address) @@ -75,6 +79,10 @@ public class Memory } memory[address % 128] = data; // else: Registers.Registers which are mapped memory[address % 128 + 128] = data; //Ensure data is written to both banks to simulate mapping + if(address == 0x2) //Check if PCL is destination + { + ProgramCounter.loadPc(); + } } private static int getRegisterBank() diff --git a/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java b/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java index f9bccb9..0b2a156 100644 --- a/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java +++ b/de/darkress/pic16f84sim/microcontroller/ProgramCounter.java @@ -20,19 +20,20 @@ public class ProgramCounter pc = (pch) + pcl; } + public static void setPcFromStack(int stack) + { + pc = stack; + Memory.setPCL(pc & 0x00FF); + } + + public static void loadPc() + { + pc = (Memory.getPCLATH() <<8) + Memory.getPCL(); + } + public static void incPC() //is called after every instruction execution { - int pcl = Memory.getPCL(); - int pclath = Memory.getPCLATH(); - if(pcl == 0xFF) - { - pclath++; - pcl = 0; - } else { - pcl++; - } - Memory.setPCL(pcl); - Memory.setPCLATH(pclath); - pc = (pclath <<8) + pcl; + pc++; + Memory.setPCL(pc & 0x00FF); } }