fixed PC (#6)

Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#6
This commit was merged in pull request #6.
This commit is contained in:
darkress
2023-05-31 14:22:45 +02:00
parent 2cfc14ba78
commit 0b5d0c172a
4 changed files with 23 additions and 18 deletions

View File

@@ -17,8 +17,6 @@ public class Retlw extends CommandUtils implements Command
public void execute() public void execute()
{ {
Memory.workingRegister = literal; Memory.workingRegister = literal;
ProgramCounter.setPcFrom11BitLiteral(Stack.pop()); ProgramCounter.setPcFromStack(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
} }
} }

View File

@@ -8,8 +8,6 @@ public class Return extends CommandUtils implements Command
@Override @Override
public void execute() public void execute()
{ {
ProgramCounter.setPcFrom11BitLiteral(Stack.pop()); ProgramCounter.setPcFromStack(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
} }
} }

View File

@@ -59,6 +59,10 @@ public class Memory
} }
memory[address] = data; memory[address] = data;
memory[address + 128] = data; //Ensure data is written to both banks to simulate mapping 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) 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] = data; // else: Registers.Registers which are mapped
memory[address % 128 + 128] = data; //Ensure data is written to both banks to simulate mapping 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() private static int getRegisterBank()

View File

@@ -20,19 +20,20 @@ public class ProgramCounter
pc = (pch) + pcl; 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 public static void incPC() //is called after every instruction execution
{ {
int pcl = Memory.getPCL(); pc++;
int pclath = Memory.getPCLATH(); Memory.setPCL(pc & 0x00FF);
if(pcl == 0xFF)
{
pclath++;
pcl = 0;
} else {
pcl++;
}
Memory.setPCL(pcl);
Memory.setPCLATH(pclath);
pc = (pclath <<8) + pcl;
} }
} }