Compare commits
3 Commits
returnInst
...
fixPC
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0d30b4db8 | ||
|
|
2cfc14ba78 | ||
|
|
eed0b2e3eb |
22
de/darkress/pic16f84sim/commands/Retlw.java
Normal file
22
de/darkress/pic16f84sim/commands/Retlw.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Stack;
|
||||||
|
|
||||||
|
public class Retlw extends CommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int literal;
|
||||||
|
|
||||||
|
public Retlw(int input)
|
||||||
|
{
|
||||||
|
literal = input & 0x00FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
Memory.workingRegister = literal;
|
||||||
|
ProgramCounter.setPcFromStack(Stack.pop());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,6 +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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,8 +110,7 @@ public class CommandDecoder
|
|||||||
case 0x3000:
|
case 0x3000:
|
||||||
return new Movlw(input);
|
return new Movlw(input);
|
||||||
case 0x3400:
|
case 0x3400:
|
||||||
//retlw();
|
return new Retlw(input);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((input | 0x0060) == 0x0060)
|
if ((input | 0x0060) == 0x0060)
|
||||||
|
|||||||
@@ -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()
|
||||||
|
|||||||
@@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user