From f644d929fc11832c39409a585080569e22a6b8c4 Mon Sep 17 00:00:00 2001 From: Darkress <30271678+DarkressX@users.noreply.github.com> Date: Fri, 16 Jun 2023 20:03:16 +0200 Subject: [PATCH] Added increase Timer --- .../pic16f84sim/microcontroller/Timer.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/de/darkress/pic16f84sim/microcontroller/Timer.java b/de/darkress/pic16f84sim/microcontroller/Timer.java index e115609..f92e975 100644 --- a/de/darkress/pic16f84sim/microcontroller/Timer.java +++ b/de/darkress/pic16f84sim/microcontroller/Timer.java @@ -2,11 +2,13 @@ package de.darkress.pic16f84sim.microcontroller; public class Timer { - private boolean getPrescalerAsssignment() { + private static int cyclesToTimerIncrease = getPrescalerFactor(); + + private static boolean getPrescalerAsssignment() { return (Memory.getOption() & 0x08) == 0x08; } - private int getPrescalerFactor() { + private static int getPrescalerFactor() { final int MULTIPLIER = 2; int prescalerPower = Memory.getOption() & 0x07; int prescaler = (int)Math.pow(2, prescalerPower); @@ -16,4 +18,24 @@ public class Timer } return prescaler; } + + private static void increaseTimerRegister() + { + int timerRegister = Memory.getRegister(0x01); + timerRegister = (timerRegister + 1) % 256; + if(timerRegister == 0) //check for timer Overflow --> interrupt + { + System.out.println("Timer Overflow"); + } + Memory.setRegister(0x01, timerRegister); + } + + public static void addToTimer(int increase) + { + cyclesToTimerIncrease -= increase; // TODO: Rethink everything + if(cyclesToTimerIncrease == 0) + { + cyclesToTimerIncrease = getPrescalerFactor(); + } + } }