Dependency inversions
This commit is contained in:
@ -1,48 +1,63 @@
|
||||
package fabrik.simulator.pic16f84;
|
||||
|
||||
public class Interrupts {
|
||||
private static final int INTCON = 0xB;
|
||||
private static final int T0IF = 0x2;
|
||||
private static final int ISR = 0x4;
|
||||
private static final int GIE = 0x7;
|
||||
private static final int T0IE = 0x5;
|
||||
private static final int RBIE = 0x3;
|
||||
private static final int RBIF = 0x0;
|
||||
private static final int INTEDG = 0x6;
|
||||
private static final int OPTION = 0x81;
|
||||
private static final int INTE = 0x4;
|
||||
private static final int INTF = 0x1;
|
||||
import eu.hansolo.tilesfx.Command;
|
||||
import fabrik.simulator.pic16f84.interfaces.CommandInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface;
|
||||
|
||||
public static void triggerTMR0(boolean manual) {
|
||||
triggerInterrupt(T0IF, T0IE);
|
||||
if (manual)
|
||||
DataRegister.increasePC();
|
||||
public class Interrupts {
|
||||
private final int INTCON = 0xB;
|
||||
private final int T0IF = 0x2;
|
||||
private final int ISR = 0x4;
|
||||
private final int GIE = 0x7;
|
||||
private final int T0IE = 0x5;
|
||||
private final int RBIE = 0x3;
|
||||
private final int RBIF = 0x0;
|
||||
private final int INTEDG = 0x6;
|
||||
private final int OPTION = 0x81;
|
||||
private final int INTE = 0x4;
|
||||
private final int INTF = 0x1;
|
||||
|
||||
private final DataRegisterInterface dataRegister;
|
||||
private final CommandInterface commands;
|
||||
private final FrontendControllerInterface frontendController;
|
||||
|
||||
public Interrupts (DataRegisterInterface dataRegister, CommandInterface commands, FrontendControllerInterface frontendController) {
|
||||
this.dataRegister = dataRegister;
|
||||
this.commands = commands;
|
||||
this.frontendController = frontendController;
|
||||
}
|
||||
|
||||
private static void triggerInterrupt(int flag, int enableFlag) {
|
||||
DataRegister.setBit(INTCON, flag);
|
||||
enableFlag = DataRegister.getDirectBit(INTCON, enableFlag);
|
||||
int globalFlag = DataRegister.getDirectBit(INTCON, GIE);
|
||||
public void triggerTMR0(boolean manual) {
|
||||
triggerInterrupt(T0IF, T0IE);
|
||||
if (manual)
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
|
||||
private void triggerInterrupt(int flag, int enableFlag) {
|
||||
dataRegister.setBit(INTCON, flag);
|
||||
enableFlag = dataRegister.getDirectBit(INTCON, enableFlag);
|
||||
int globalFlag = dataRegister.getDirectBit(INTCON, GIE);
|
||||
if (enableFlag == 1) {
|
||||
Controller_Frontend.wakeUpFromSleep();
|
||||
frontendController.wakeUpFromSleep();
|
||||
if (globalFlag == 1) {
|
||||
DataRegister.clearBit(INTCON, GIE);
|
||||
Commands.CALL(ISR);
|
||||
dataRegister.clearBit(INTCON, GIE);
|
||||
commands.CALL(ISR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void triggerRBInterrupt(int oldValue, int newValue) {
|
||||
public void triggerRBInterrupt(int oldValue, int newValue) {
|
||||
if (newValue != oldValue){
|
||||
triggerInterrupt(RBIF, RBIE);
|
||||
DataRegister.increasePC();
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
}
|
||||
|
||||
public static void triggerRB0Interrupt(int oldValue, int newValue){
|
||||
public void triggerRB0Interrupt(int oldValue, int newValue){
|
||||
if (newValue != oldValue){
|
||||
int intedg = DataRegister.getDirectBit(OPTION, INTEDG);
|
||||
int intedg = dataRegister.getDirectBit(OPTION, INTEDG);
|
||||
if (intedg == 1) {
|
||||
if (oldValue == 0 && newValue == 1)
|
||||
triggerInterrupt(INTF, INTE);
|
||||
@ -50,7 +65,7 @@ public class Interrupts {
|
||||
if (oldValue == 1 && newValue == 0)
|
||||
triggerInterrupt(INTF, INTE);
|
||||
}
|
||||
DataRegister.increasePC();
|
||||
dataRegister.increasePC();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user