Somewhat working Timer0Interrupt

This commit is contained in:
Darkress
2023-06-18 19:13:37 +02:00
parent 101c6ec464
commit 60b288a762
7 changed files with 48 additions and 7 deletions

View File

@@ -11,7 +11,7 @@ class Main
{
public static void main(String[] args) {
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim11.LST");
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim8.LST");
Memory.initMemory();

View File

@@ -0,0 +1,18 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Cycles;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
import de.darkress.pic16f84sim.microcontroller.Stack;
public class Retfie extends LiteralCommandUtils implements Command
{
@Override
public void execute()
{
Cycles.incCycles();
Memory.setRegister(0x0B, Memory.getRegister(0x0B) | 0x80); //Set GIE
ProgramCounter.setPcFromStack(Stack.pop() + 1);
Cycles.incCycles(); // Simulate 2-Cycle Instruction
}
}

View File

@@ -102,7 +102,7 @@ public class CommandDecoder
if (input == 0x0009)
{
//retfie();
return new Retfie();
}
if (input == 0x0008)

View File

@@ -0,0 +1,14 @@
package de.darkress.pic16f84sim.microcontroller;
public class Interrupt
{
private static boolean globalInterruptEnabled() {
return (Memory.getRegister(0x0B) & 0x80) == 0x80;
}
public static boolean checkTimerInterruptConditions() {
boolean timerInterruptEnabled = (Memory.getRegister(0x0B) & 0x20) == 0x20;
//boolean timerOverflowInterruptFlag = (Memory.getRegister(0x0B) & 0x04) == 0x04;
return globalInterruptEnabled() && timerInterruptEnabled;
}
}

View File

@@ -37,8 +37,11 @@ public class ProgramCounter
Memory.setPCL(pc & 0x00FF);
}
public static void resetProgramCounter() {
pc = 0;
Memory.setPCL(0x0);
public static void setProgramCounter(int value) {
if(value <= 0xFF && value >= 0)
{
pc = value;
Memory.setPCL(pc);
}
}
}

View File

@@ -43,9 +43,15 @@ public class Timer
{
int timerRegister = Memory.getRegister(0x01);
timerRegister = (timerRegister + 1) % 256;
if(timerRegister == 0) //check for timer Overflow --> interrupt
if(timerRegister == 0 && !((Memory.getRegister(0x0B) & 0x04) == 0x04)) //check for timer Overflow --> interrupt
{
System.out.println("Timer Overflow");
Memory.setRegister(0x0B, Memory.getRegister(0x0B) | 0x04); //set T0IF
if(Interrupt.checkTimerInterruptConditions())
{
Stack.push(ProgramCounter.getPc());
ProgramCounter.setProgramCounter(0x04); // Interrupt Vector
}
}
Memory.setTimer(timerRegister);
}

View File

@@ -30,7 +30,7 @@ public class Watchdog
public static void resetProgram()
{
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x10); //Set !T0 in StatusReg
ProgramCounter.resetProgramCounter();
ProgramCounter.setProgramCounter(0);
watchdogTimer = 18000;
}