Somewhat working timer. Increases one instruction too early
This commit is contained in:
@@ -2,7 +2,17 @@ package de.darkress.pic16f84sim.microcontroller;
|
||||
|
||||
public class Timer
|
||||
{
|
||||
private static int cyclesToTimerIncrease = getPrescalerFactor();
|
||||
private static int cyclesToTimerIncrease = 1;
|
||||
|
||||
private static boolean timerEnabled()
|
||||
{
|
||||
return (Memory.getOption() & 0x20) != 0x20;
|
||||
}
|
||||
|
||||
public static void resetTimeToTimerIncrease()
|
||||
{
|
||||
cyclesToTimerIncrease = getPrescalerFactor();
|
||||
}
|
||||
|
||||
private static boolean getPrescalerAsssignment() {
|
||||
return (Memory.getOption() & 0x08) == 0x08;
|
||||
@@ -27,15 +37,20 @@ public class Timer
|
||||
{
|
||||
System.out.println("Timer Overflow");
|
||||
}
|
||||
Memory.setRegister(0x01, timerRegister);
|
||||
Memory.setTimer(timerRegister);
|
||||
}
|
||||
|
||||
public static void addToTimer(int increase)
|
||||
public static void increaseTimer()
|
||||
{
|
||||
cyclesToTimerIncrease -= increase; // TODO: Rethink everything
|
||||
if(!timerEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
cyclesToTimerIncrease--;
|
||||
if(cyclesToTimerIncrease == 0)
|
||||
{
|
||||
cyclesToTimerIncrease = getPrescalerFactor();
|
||||
resetTimeToTimerIncrease();
|
||||
increaseTimerRegister();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user