Dependency inversions
This commit is contained in:
@ -1,19 +1,35 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class Timer {
|
||||
private static final int TIMERREG = 0x1;
|
||||
private static final int T0SE = 0x4;
|
||||
private static final int T0CS = 0x5;
|
||||
private static final int OPTION = 0x81;
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.InterruptInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.TimerInterface;
|
||||
|
||||
private static int oldpin = 0;
|
||||
public class Timer implements TimerInterface {
|
||||
private final int TIMERREG = 0x1;
|
||||
private final int T0SE = 0x4;
|
||||
private final int T0CS = 0x5;
|
||||
private final int OPTION = 0x81;
|
||||
|
||||
private int oldpin = 0;
|
||||
|
||||
private final DataRegisterInterface dataRegister;
|
||||
private final InterruptInterface interrupts;
|
||||
private final PreScaler preScaler;
|
||||
private final FrontendControllerInterface frontendController;
|
||||
|
||||
public Timer (DataRegisterInterface dataRegister, InterruptInterface interrupts, PreScaler preScaler, FrontendControllerInterface frontendController){
|
||||
this.dataRegister = dataRegister;
|
||||
this.interrupts = interrupts;
|
||||
this.preScaler = preScaler;
|
||||
this.frontendController = frontendController;
|
||||
}
|
||||
|
||||
public static void cycles(int cycles){
|
||||
if (DataRegister.getDirectBit(OPTION, T0CS) == 0){
|
||||
if (PreScaler.isPrescalerOnTimer()){
|
||||
public void cycles(int cycles){
|
||||
if (dataRegister.getDirectBit(OPTION, T0CS) == 0){
|
||||
if (preScaler.isPrescalerOnTimer()){
|
||||
for (int i = 0; i < cycles; i++){
|
||||
PreScaler.decrement(false);
|
||||
preScaler.decrement(false);
|
||||
}
|
||||
} else {
|
||||
increment(false);
|
||||
@ -22,23 +38,23 @@ public class Timer {
|
||||
}
|
||||
|
||||
|
||||
public static void incrementFromPin (int register){
|
||||
if ((DataRegister.getDirectBit(OPTION, T0CS) == 1) && !Controller_Frontend.isSleeping()){
|
||||
public void incrementFromPin (int register){
|
||||
if ((dataRegister.getDirectBit(OPTION, T0CS) == 1) && !frontendController.isSleeping()){
|
||||
int newpin = (register >> 4) & 1;
|
||||
if (newpin != oldpin) {
|
||||
if (DataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
||||
if (dataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
||||
// Low to high
|
||||
if (newpin == 1 && oldpin == 0) {
|
||||
if (PreScaler.isPrescalerOnTimer())
|
||||
PreScaler.decrement(true);
|
||||
if (preScaler.isPrescalerOnTimer())
|
||||
preScaler.decrement(true);
|
||||
else
|
||||
increment(true);
|
||||
}
|
||||
} else {
|
||||
// High to low
|
||||
if (newpin == 0 && oldpin == 1) {
|
||||
if (PreScaler.isPrescalerOnTimer())
|
||||
PreScaler.decrement(true);
|
||||
if (preScaler.isPrescalerOnTimer())
|
||||
preScaler.decrement(true);
|
||||
else
|
||||
increment(true);
|
||||
}
|
||||
@ -48,14 +64,14 @@ public class Timer {
|
||||
}
|
||||
}
|
||||
|
||||
public static void increment(boolean manual) {
|
||||
int timer = DataRegister.getDirectRegister(TIMERREG);
|
||||
public void increment(boolean manual) {
|
||||
int timer = dataRegister.getDirectRegister(TIMERREG);
|
||||
timer++;
|
||||
if (timer > 0xFF){
|
||||
Interrupts.triggerTMR0(manual);
|
||||
DataRegister.setDirectRegister(TIMERREG, 0);
|
||||
interrupts.triggerTMR0(manual);
|
||||
dataRegister.setDirectRegister(TIMERREG, 0);
|
||||
} else {
|
||||
DataRegister.setDirectRegister(1, timer);
|
||||
dataRegister.setDirectRegister(1, timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user