Dependency inversions
This commit is contained in:
@ -1,42 +1,51 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
import fabrik.simulator.pic16f84.interfaces.*;
|
||||
|
||||
public class PreScaler {
|
||||
private static final int PSA = 0x3;
|
||||
private static final int OPTION = 0x81;
|
||||
private final int PSA = 0x3;
|
||||
private final int OPTION = 0x81;
|
||||
private final DataRegisterInterface dataRegister;
|
||||
private final TimerInterface timer;
|
||||
private int scaler;
|
||||
|
||||
private static int scaler = 0b111;
|
||||
public PreScaler (DataRegisterInterface dataRegister, TimerInterface timer) {
|
||||
scaler = 0b111;
|
||||
this.dataRegister = dataRegister;
|
||||
this.timer = timer;
|
||||
}
|
||||
|
||||
public static boolean isPrescalerOnTimer (){
|
||||
return DataRegister.getDirectBit(OPTION, PSA) == 0;
|
||||
public boolean isPrescalerOnTimer (){
|
||||
return dataRegister.getDirectBit(OPTION, PSA) == 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static int getScaler() {
|
||||
public int getScaler() {
|
||||
return scaler;
|
||||
}
|
||||
|
||||
public static int getFactor () {
|
||||
int scale = DataRegister.getDirectRegister(OPTION) & 0b111;
|
||||
public int getFactor () {
|
||||
int scale = dataRegister.getDirectRegister(OPTION) & 0b111;
|
||||
int timer = isPrescalerOnTimer() ? 1 : 0;
|
||||
return (int) Math.pow (2, scale+timer);
|
||||
}
|
||||
|
||||
public static void reset (){
|
||||
DataRegister.setDirectBit(OPTION, 0, 0);
|
||||
DataRegister.setDirectBit(OPTION, 1, 0);
|
||||
DataRegister.setDirectBit(OPTION, 2, 0);
|
||||
public void reset (){
|
||||
dataRegister.setDirectBit(OPTION, 0, 0);
|
||||
dataRegister.setDirectBit(OPTION, 1, 0);
|
||||
dataRegister.setDirectBit(OPTION, 2, 0);
|
||||
}
|
||||
|
||||
public static void resetFromRegister() {
|
||||
public void resetFromRegister() {
|
||||
scaler = getFactor();
|
||||
}
|
||||
|
||||
public static void decrement(boolean manual) {
|
||||
public void decrement(boolean manual) {
|
||||
scaler--;
|
||||
if (scaler == 0) {
|
||||
scaler = getFactor();
|
||||
Timer.increment(manual);
|
||||
timer.increment(manual);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user