Compare commits

..

2 Commits

Author SHA1 Message Date
Darkress
022dd499ce Renamed setPcForGotoCall function to setPcFrom11BitLiteral 2023-05-30 01:18:51 +02:00
Darkress
3eaf697306 implemented Call instruction 2023-05-30 01:06:12 +02:00
7 changed files with 25 additions and 67 deletions

View File

@@ -12,14 +12,13 @@ class Main
public static void main(String[] args) { public static void main(String[] args) {
ArrayList<Command> program = new ArrayList<>(); ArrayList<Command> program = new ArrayList<>();
Memory.workingRegister = 0xAA;
int input1 = 0x27FF; int input1 = 0x27FF;
program.add(CommandDecoder.decode(0x3011)); program.add(CommandDecoder.decode(input1));
program.add(CommandDecoder.decode(0x2003));
program.add(CommandDecoder.decode(0x3022)); Memory.setPCLATH(0xFF);
program.add(CommandDecoder.decode(0x0008)); program.get(0).execute();
while(true)
{ //ProgramCounter.incPC();
program.get(ProgramCounter.getPc()).execute();
}
} }
} }

View File

@@ -1,22 +0,0 @@
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());
}
}

View File

@@ -1,13 +0,0 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
import de.darkress.pic16f84sim.microcontroller.Stack;
public class Return extends CommandUtils implements Command
{
@Override
public void execute()
{
ProgramCounter.setPcFromStack(Stack.pop());
}
}

View File

@@ -110,7 +110,8 @@ public class CommandDecoder
case 0x3000: case 0x3000:
return new Movlw(input); return new Movlw(input);
case 0x3400: case 0x3400:
return new Retlw(input); //retlw();
break;
} }
if ((input | 0x0060) == 0x0060) if ((input | 0x0060) == 0x0060)
@@ -130,7 +131,8 @@ public class CommandDecoder
if (input == 0x0008) if (input == 0x0008)
{ {
return new Return(); //return();
//This is the function name. Do not mistake this for a normal return!
} }
if (input == 0x0063) if (input == 0x0063)

View File

@@ -59,10 +59,6 @@ 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)
@@ -79,10 +75,6 @@ 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,20 +20,19 @@ 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
{ {
pc++; int pcl = Memory.getPCL();
Memory.setPCL(pc & 0x00FF); int pclath = Memory.getPCLATH();
if(pcl == 0xFF)
{
pclath++;
pcl = 0;
} else {
pcl++;
}
Memory.setPCL(pcl);
Memory.setPCLATH(pclath);
pc = (pclath <<8) + pcl;
} }
} }

View File

@@ -14,8 +14,9 @@ public class Stack
public static int pop() public static int pop()
{ {
int tmp = stack[stackPointer];
pointPrevious(); pointPrevious();
return stack[stackPointer]; return tmp;
} }
public static int peek() public static int peek()