Dependency inversions
This commit is contained in:
@ -1,37 +1,50 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
|
|
||||||
public class Commands {
|
public class Commands implements CommandInterface {
|
||||||
private static int wRegister = 0;
|
private int wRegister;
|
||||||
|
private long totalExecutionTime;
|
||||||
|
|
||||||
static long totalExecutionTime = 0;
|
private final TimerInterface timer;
|
||||||
|
private final EEPROMInterface eeprom;
|
||||||
|
private final WatchdogTimerInterface watchdogTimer;
|
||||||
|
private final ProgramStackInterface programStack;
|
||||||
|
private final DataRegisterInterface dataRegister;
|
||||||
|
private final FrontendControllerInterface frontendController;
|
||||||
|
|
||||||
|
|
||||||
|
public Commands(TimerInterface timer, EEPROMInterface eeprom, WatchdogTimerInterface watchdogTimer,
|
||||||
|
ProgramStackInterface programStack, DataRegisterInterface dataRegister, FrontendControllerInterface frontendController) {
|
||||||
|
wRegister = 0;
|
||||||
|
totalExecutionTime = 0;
|
||||||
|
this.timer = timer;
|
||||||
|
this.eeprom = eeprom;
|
||||||
|
this.watchdogTimer = watchdogTimer;
|
||||||
|
this.programStack = programStack;
|
||||||
|
this.dataRegister = dataRegister;
|
||||||
|
this.frontendController = frontendController;
|
||||||
|
}
|
||||||
|
|
||||||
public static int get_wRegister() {
|
public int get_wRegister() {
|
||||||
return wRegister;
|
return wRegister;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addExecutionTime(int i) {
|
public void addExecutionTime(int i) {
|
||||||
totalExecutionTime += i;
|
totalExecutionTime += i;
|
||||||
Timer.cycles(i);
|
timer.cycles(i);
|
||||||
EEPROM.registerTime(false);
|
eeprom.registerTime(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getTotalExecutionTime() {
|
public double getTotalExecutionTime() {
|
||||||
return (long) (totalExecutionTime * Controller_Frontend.getExecutionTimeMultiplier());
|
return (totalExecutionTime * frontendController.getExecutionTimeMultiplier());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetTotalExecutionTime() {
|
public void resetTotalExecutionTime() {
|
||||||
totalExecutionTime = 0;
|
totalExecutionTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void decode(int instruction){
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void decode(int instruction){
|
|
||||||
final int jumpaddr = 0x7FF;
|
final int jumpaddr = 0x7FF;
|
||||||
final int fileregaddr = 0x7F;
|
final int fileregaddr = 0x7F;
|
||||||
final int constant = 0xFF;
|
final int constant = 0xFF;
|
||||||
@ -62,12 +75,12 @@ public class Commands {
|
|||||||
switch (instruction & 0x3C00){
|
switch (instruction & 0x3C00){
|
||||||
case 0b01000000000000:
|
case 0b01000000000000:
|
||||||
System.out.println("BCF: " + f + " " + b);
|
System.out.println("BCF: " + f + " " + b);
|
||||||
DataRegister.clearBit(f, b);
|
dataRegister.clearBit(f, b);
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
return;
|
return;
|
||||||
case 0b01010000000000:
|
case 0b01010000000000:
|
||||||
System.out.println("BSF: " + f + " " + b);
|
System.out.println("BSF: " + f + " " + b);
|
||||||
DataRegister.setBit(f, b);
|
dataRegister.setBit(f, b);
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
return;
|
return;
|
||||||
case 0b01100000000000:
|
case 0b01100000000000:
|
||||||
@ -223,7 +236,7 @@ public class Commands {
|
|||||||
switch (instruction){
|
switch (instruction){
|
||||||
case 0b01100100:
|
case 0b01100100:
|
||||||
System.out.println("CLRWDT");
|
System.out.println("CLRWDT");
|
||||||
WatchdogTimer.reset();
|
watchdogTimer.reset();
|
||||||
return;
|
return;
|
||||||
case 0b1001:
|
case 0b1001:
|
||||||
System.out.println("RETFIE");
|
System.out.println("RETFIE");
|
||||||
@ -232,7 +245,7 @@ public class Commands {
|
|||||||
return;
|
return;
|
||||||
case 0b1000:
|
case 0b1000:
|
||||||
System.out.println("RETURN");
|
System.out.println("RETURN");
|
||||||
DataRegister.setPC(ProgramStack.pop());
|
dataRegister.setPC(programStack.pop());
|
||||||
return;
|
return;
|
||||||
case 0b01100011:
|
case 0b01100011:
|
||||||
System.out.println("SLEEP");
|
System.out.println("SLEEP");
|
||||||
@ -253,308 +266,308 @@ public class Commands {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SLEEP() {
|
public void SLEEP() {
|
||||||
Controller_Frontend.sleep ();
|
frontendController.sleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RETFIE() {
|
public void RETFIE() {
|
||||||
DataRegister.setBit(DataRegister.getINTCON(), 7); // GIE wieder setzen
|
dataRegister.setBit(dataRegister.getINTCON(), 7); // GIE wieder setzen
|
||||||
DataRegister.setPC(ProgramStack.pop());
|
dataRegister.setPC(programStack.pop());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void NOP () {
|
public void NOP () {
|
||||||
System.out.println("NOP");
|
System.out.println("NOP");
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void GOTO(int jump) {
|
public void GOTO(int jump) {
|
||||||
DataRegister.setPC(jump-1);
|
dataRegister.setPC(jump-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CALL(int jump) {
|
public void CALL(int jump) {
|
||||||
ProgramStack.push(DataRegister.getPC()+1);
|
programStack.push(dataRegister.getPC()+1);
|
||||||
DataRegister.setPC(jump-1);
|
dataRegister.setPC(jump-1);
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MOVWF(int file) {
|
public void MOVWF(int file) {
|
||||||
DataRegister.setRegister(file, wRegister);
|
dataRegister.setRegister(file, wRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CLRW() {
|
public void CLRW() {
|
||||||
wRegister = 0;
|
wRegister = 0;
|
||||||
DataRegister.determineZeroFlag(wRegister);
|
dataRegister.determineZeroFlag(wRegister);
|
||||||
|
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CLRF(int file) {
|
public void CLRF(int file) {
|
||||||
DataRegister.setRegister(file, 0);
|
dataRegister.setRegister(file, 0);
|
||||||
DataRegister.determineZeroFlag(DataRegister.getRegister(file));
|
dataRegister.determineZeroFlag(dataRegister.getRegister(file));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IORLW(int literal) {
|
public void IORLW(int literal) {
|
||||||
wRegister |= literal;
|
wRegister |= literal;
|
||||||
DataRegister.determineZeroFlag(wRegister);
|
dataRegister.determineZeroFlag(wRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void XORLW(int literal) {
|
public void XORLW(int literal) {
|
||||||
wRegister ^= literal;
|
wRegister ^= literal;
|
||||||
DataRegister.determineZeroFlag(wRegister);
|
dataRegister.determineZeroFlag(wRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ANDLW(int literal) {
|
public void ANDLW(int literal) {
|
||||||
wRegister &= literal;
|
wRegister &= literal;
|
||||||
DataRegister.determineZeroFlag(wRegister);
|
dataRegister.determineZeroFlag(wRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void XORWF(int file, int destination) {
|
public void XORWF(int file, int destination) {
|
||||||
int result = wRegister ^ DataRegister.getRegister(file);
|
int result = wRegister ^ dataRegister.getRegister(file);
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SWAPF(int file, int destination) {
|
public void SWAPF(int file, int destination) {
|
||||||
int content = DataRegister.getRegister(file);
|
int content = dataRegister.getRegister(file);
|
||||||
int result = (content & 0x0F) << 4 | (content & 0xF0) >> 4;
|
int result = (content & 0x0F) << 4 | (content & 0xF0) >> 4;
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SUBWF(int file, int destination) {
|
public void SUBWF(int file, int destination) {
|
||||||
int result = (DataRegister.getRegister(file) - wRegister) ;
|
int result = (dataRegister.getRegister(file) - wRegister) ;
|
||||||
if (wRegister == 0 || result >= 0){
|
if (wRegister == 0 || result >= 0){
|
||||||
DataRegister.setCarryFlag(1);
|
dataRegister.setCarryFlag(1);
|
||||||
DataRegister.setDigitCarryFlag(1);
|
dataRegister.setDigitCarryFlag(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setCarryFlag(0);
|
dataRegister.setCarryFlag(0);
|
||||||
DataRegister.setDigitCarryFlag(0);
|
dataRegister.setDigitCarryFlag(0);
|
||||||
}
|
}
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result & 0xFF;
|
wRegister = result & 0xFF;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result & 0xFF);
|
dataRegister.setRegister(file, result & 0xFF);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RLF(int file, int destination) {
|
public void RLF(int file, int destination) {
|
||||||
int fcontent = DataRegister.getRegister(file);
|
int fcontent = dataRegister.getRegister(file);
|
||||||
int carry = DataRegister.getCarryFlag();
|
int carry = dataRegister.getCarryFlag();
|
||||||
int result = (fcontent << 1) | carry;
|
int result = (fcontent << 1) | carry;
|
||||||
DataRegister.determineCarryFlag(result);
|
dataRegister.determineCarryFlag(result);
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result & 0xFF;
|
wRegister = result & 0xFF;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result & 0xFF);
|
dataRegister.setRegister(file, result & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RRF(int file, int destination) {
|
public void RRF(int file, int destination) {
|
||||||
int fcontent = DataRegister.getRegister(file);
|
int fcontent = dataRegister.getRegister(file);
|
||||||
int carry = DataRegister.getCarryFlag() << 7;
|
int carry = dataRegister.getCarryFlag() << 7;
|
||||||
int contentlow = fcontent & 0b1;
|
int contentlow = fcontent & 0b1;
|
||||||
int result = (fcontent >> 1) | carry;
|
int result = (fcontent >> 1) | carry;
|
||||||
DataRegister.setCarryFlag(contentlow);
|
dataRegister.setCarryFlag(contentlow);
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result & 0xFF;
|
wRegister = result & 0xFF;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result & 0xFF);
|
dataRegister.setRegister(file, result & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MOVF(int file, int destination) {
|
public void MOVF(int file, int destination) {
|
||||||
int content = DataRegister.getRegister(file);
|
int content = dataRegister.getRegister(file);
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = content;
|
wRegister = content;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, content);
|
dataRegister.setRegister(file, content);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(content);
|
dataRegister.determineZeroFlag(content);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void IORWF(int file, int destination) {
|
public void IORWF(int file, int destination) {
|
||||||
int result = wRegister | DataRegister.getRegister(file);
|
int result = wRegister | dataRegister.getRegister(file);
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void INCFSZ(int file, int destination) {
|
public void INCFSZ(int file, int destination) {
|
||||||
int result = (DataRegister.getRegister(file) + 1) & 0xFF;
|
int result = (dataRegister.getRegister(file) + 1) & 0xFF;
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
DataRegister.increasePC();
|
dataRegister.increasePC();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void INCF(int file, int destination) {
|
public void INCF(int file, int destination) {
|
||||||
int result = (DataRegister.getRegister(file) + 1) & 0xFF;
|
int result = (dataRegister.getRegister(file) + 1) & 0xFF;
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DECFSZ(int file, int destination) {
|
public void DECFSZ(int file, int destination) {
|
||||||
int result = (DataRegister.getRegister(file) -1) & 0xFF;
|
int result = (dataRegister.getRegister(file) -1) & 0xFF;
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (result == 0){
|
if (result == 0){
|
||||||
DataRegister.increasePC();
|
dataRegister.increasePC();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void DECF(int file, int destination) {
|
public void DECF(int file, int destination) {
|
||||||
int result = (DataRegister.getRegister(file) -1) & 0xFF;
|
int result = (dataRegister.getRegister(file) -1) & 0xFF;
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void COMF(int file, int destination) {
|
private void COMF(int file, int destination) {
|
||||||
int result = (~ DataRegister.getRegister(file)) & 0xFF;
|
int result = (~ dataRegister.getRegister(file)) & 0xFF;
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result;
|
wRegister = result;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result);
|
dataRegister.setRegister(file, result);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ANDWF(int file, int destination) {
|
public void ANDWF(int file, int destination) {
|
||||||
int result = wRegister & DataRegister.getRegister(file);
|
int result = wRegister & dataRegister.getRegister(file);
|
||||||
if (destination == 0){
|
if (destination == 0){
|
||||||
wRegister = result & 0xFF;
|
wRegister = result & 0xFF;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result & 0xFF);
|
dataRegister.setRegister(file, result & 0xFF);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
DataRegister.determineCarryFlag(result);
|
dataRegister.determineCarryFlag(result);
|
||||||
DataRegister.determineDigitCarryFlag((wRegister&0b11101111) & (DataRegister.getRegister(file)&0b1111));
|
dataRegister.determineDigitCarryFlag((wRegister&0b11101111) & (dataRegister.getRegister(file)&0b1111));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ADDWF(int file, int destination) {
|
public void ADDWF(int file, int destination) {
|
||||||
int result = wRegister + DataRegister.getRegister(file);
|
int result = wRegister + dataRegister.getRegister(file);
|
||||||
if (wRegister == 0 || DataRegister.getRegister(file) == 0){
|
if (wRegister == 0 || dataRegister.getRegister(file) == 0){
|
||||||
DataRegister.setCarryFlag(0);
|
dataRegister.setCarryFlag(0);
|
||||||
DataRegister.setDigitCarryFlag(0);
|
dataRegister.setDigitCarryFlag(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.determineCarryFlag(result);
|
dataRegister.determineCarryFlag(result);
|
||||||
DataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (DataRegister.getRegister(file)&0b1111));
|
dataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (dataRegister.getRegister(file)&0b1111));
|
||||||
}
|
}
|
||||||
if (destination == 0) {
|
if (destination == 0) {
|
||||||
wRegister = result & 0xFF;
|
wRegister = result & 0xFF;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DataRegister.setRegister(file, result & 0xFF);
|
dataRegister.setRegister(file, result & 0xFF);
|
||||||
}
|
}
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SUBLW(int literal) {
|
public void SUBLW(int literal) {
|
||||||
int result = literal - wRegister;
|
int result = literal - wRegister;
|
||||||
if (wRegister == 0 || result >= 0){
|
if (wRegister == 0 || result >= 0){
|
||||||
DataRegister.setCarryFlag(1);
|
dataRegister.setCarryFlag(1);
|
||||||
DataRegister.setDigitCarryFlag(1);
|
dataRegister.setDigitCarryFlag(1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
DataRegister.setCarryFlag(0);
|
dataRegister.setCarryFlag(0);
|
||||||
DataRegister.setDigitCarryFlag(0);
|
dataRegister.setDigitCarryFlag(0);
|
||||||
}
|
}
|
||||||
wRegister = result & 0xFF;
|
wRegister = result & 0xFF;
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ADDLW(int literal) {
|
public void ADDLW(int literal) {
|
||||||
int result = wRegister + literal;
|
int result = wRegister + literal;
|
||||||
wRegister = result & 0xFF;
|
wRegister = result & 0xFF;
|
||||||
DataRegister.determineZeroFlag(result);
|
dataRegister.determineZeroFlag(result);
|
||||||
DataRegister.determineCarryFlag(result);
|
dataRegister.determineCarryFlag(result);
|
||||||
DataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (literal&0b1111));
|
dataRegister.determineDigitCarryFlag((wRegister&0b11101111) + (literal&0b1111));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RETLW(int literal) {
|
public void RETLW(int literal) {
|
||||||
wRegister = literal;
|
wRegister = literal;
|
||||||
DataRegister.setPC(ProgramStack.pop());
|
dataRegister.setPC(programStack.pop());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void MOVLW(int literal) {
|
public void MOVLW(int literal) {
|
||||||
wRegister = literal;
|
wRegister = literal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void BTFSC(int address, int bit) {
|
public void BTFSC(int address, int bit) {
|
||||||
if (DataRegister.getBit(address, bit) == 0){
|
if (dataRegister.getBit(address, bit) == 0){
|
||||||
DataRegister.increasePC();
|
dataRegister.increasePC();
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void BTFSS(int address, int bit) {
|
public void BTFSS(int address, int bit) {
|
||||||
if (DataRegister.getBit(address, bit) == 1){
|
if (dataRegister.getBit(address, bit) == 1){
|
||||||
DataRegister.increasePC();
|
dataRegister.increasePC();
|
||||||
addExecutionTime(1);
|
addExecutionTime(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package fabrik.simulator.pic16f84;
|
|||||||
|
|
||||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.WatchdogTimerInterface;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
@ -35,17 +37,17 @@ import java.util.Set;
|
|||||||
|
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
|
|
||||||
public class Controller_Frontend {
|
public class Controller_Frontend implements FrontendControllerInterface {
|
||||||
|
|
||||||
private int [] prog;
|
private int [] prog;
|
||||||
private int [][] read;
|
private int [][] read;
|
||||||
private int [] ind;
|
private int [] ind;
|
||||||
|
|
||||||
private static double executionTimeMultiplier = 1;
|
private double executionTimeMultiplier = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static double getExecutionTimeMultiplier(){
|
public double getExecutionTimeMultiplier(){
|
||||||
return executionTimeMultiplier;
|
return executionTimeMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,12 +55,6 @@ public class Controller_Frontend {
|
|||||||
|
|
||||||
private boolean continueExecutionAfterBreakpoint = false;
|
private boolean continueExecutionAfterBreakpoint = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private ComboBox<String> executionTimeComboBox;
|
private ComboBox<String> executionTimeComboBox;
|
||||||
|
|
||||||
@ -84,24 +80,46 @@ public class Controller_Frontend {
|
|||||||
@FXML
|
@FXML
|
||||||
private CheckBox wdtCheck;
|
private CheckBox wdtCheck;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static volatile boolean isAutoRunActive = false;
|
private static volatile boolean isAutoRunActive = false;
|
||||||
private static volatile boolean isSleeping = false;
|
private static volatile boolean isSleeping = false;
|
||||||
|
|
||||||
public static boolean isSleeping (){
|
private final CommandInterface commands;
|
||||||
|
private final WatchdogTimerInterface watchdogTimer;
|
||||||
|
private final ProgramStackInterface programStack;
|
||||||
|
private final WindowManagement createWindow;
|
||||||
|
private final TableInterface table;
|
||||||
|
private final DataRegisterInterface dataRegister;
|
||||||
|
private final IOPortInterface ioPorts;
|
||||||
|
private final ToggleButtonInterface toggleButtonExt;
|
||||||
|
private final ParseFile fileParser;
|
||||||
|
|
||||||
|
|
||||||
|
public Controller_Frontend(CommandInterface commands, WatchdogTimerInterface watchdogTimer,
|
||||||
|
ProgramStackInterface programStack, WindowManagement createWindow, TableInterface table,
|
||||||
|
DataRegisterInterface dataRegister, IOPortInterface ioPorts, ToggleButtonInterface toggleButtons,
|
||||||
|
ParseFile fileParser) {
|
||||||
|
this.commands = commands;
|
||||||
|
this.watchdogTimer = watchdogTimer;
|
||||||
|
this.programStack = programStack;
|
||||||
|
this.createWindow = createWindow;
|
||||||
|
this.table = table;
|
||||||
|
this.dataRegister = dataRegister;
|
||||||
|
this.ioPorts = ioPorts;
|
||||||
|
this.toggleButtonExt = toggleButtons;
|
||||||
|
this.fileParser = fileParser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isSleeping (){
|
||||||
return isSleeping;
|
return isSleeping;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stopRunFromBackend(String message){
|
public void stopRunFromBackend(String message){
|
||||||
isAutoRunActive = false;
|
isAutoRunActive = false;
|
||||||
if (isSleeping)
|
if (isSleeping)
|
||||||
wakeUpFromSleep();
|
wakeUpFromSleep();
|
||||||
else
|
else
|
||||||
DataRegister.resetPC();
|
dataRegister.resetPC();
|
||||||
Stage stoppedStage = new Stage();
|
Stage stoppedStage = new Stage();
|
||||||
stoppedStage.setTitle("Programm unterbrochen!");
|
stoppedStage.setTitle("Programm unterbrochen!");
|
||||||
VBox vbox = new VBox();
|
VBox vbox = new VBox();
|
||||||
@ -118,11 +136,11 @@ public class Controller_Frontend {
|
|||||||
stoppedStage.show();
|
stoppedStage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sleep() {
|
public void sleep() {
|
||||||
isSleeping = true;
|
isSleeping = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void wakeUpFromSleep() {
|
public void wakeUpFromSleep() {
|
||||||
isSleeping = false;
|
isSleeping = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +158,7 @@ public class Controller_Frontend {
|
|||||||
|
|
||||||
Thread autoRunThread = new Thread(() -> {
|
Thread autoRunThread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
while (DataRegister.getPC() < prog.length && isAutoRunActive){
|
while (dataRegister.getPC() < prog.length && isAutoRunActive){
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
try {
|
try {
|
||||||
@ -197,9 +215,9 @@ public class Controller_Frontend {
|
|||||||
int currentIndex;
|
int currentIndex;
|
||||||
// Aktuelle Zeile abrufen
|
// Aktuelle Zeile abrufen
|
||||||
if (!isSleeping)
|
if (!isSleeping)
|
||||||
currentIndex = ind[DataRegister.getPC()];
|
currentIndex = ind[dataRegister.getPC()];
|
||||||
else
|
else
|
||||||
currentIndex = ind[DataRegister.getPC()]-1;
|
currentIndex = ind[dataRegister.getPC()]-1;
|
||||||
|
|
||||||
// Überprüfung ob ein Breakpoint gesetzt ist testte
|
// Überprüfung ob ein Breakpoint gesetzt ist testte
|
||||||
|
|
||||||
@ -233,19 +251,19 @@ public class Controller_Frontend {
|
|||||||
markSelectedRow(currentIndex, selectedRowStyle);
|
markSelectedRow(currentIndex, selectedRowStyle);
|
||||||
|
|
||||||
if (!isSleeping) {
|
if (!isSleeping) {
|
||||||
Commands.decode(prog[DataRegister.getPC()]);
|
commands.decode(prog[dataRegister.getPC()]);
|
||||||
DataRegister.increasePC();
|
dataRegister.increasePC();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Commands.decode(0);
|
commands.decode(0);
|
||||||
}
|
}
|
||||||
WatchdogTimer.testAndTrigger();
|
watchdogTimer.testAndTrigger();
|
||||||
Table.refresh();
|
table.refresh();
|
||||||
CreateWindow.refreshTable();
|
createWindow.refreshTable();
|
||||||
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||||
updateStack();
|
updateStack();
|
||||||
updateWatchdog();
|
updateWatchdog();
|
||||||
long totalExecutionTime = Commands.getTotalExecutionTime();
|
double totalExecutionTime = commands.getTotalExecutionTime();
|
||||||
totalExecutionTimeLabel.setText("Total Execution Time: " + totalExecutionTime + "µs");
|
totalExecutionTimeLabel.setText("Total Execution Time: " + totalExecutionTime + "µs");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,26 +303,26 @@ public class Controller_Frontend {
|
|||||||
stopAutoRun(null);
|
stopAutoRun(null);
|
||||||
if(selectedFile != null){
|
if(selectedFile != null){
|
||||||
String fileAddress = selectedFile.getAbsolutePath();
|
String fileAddress = selectedFile.getAbsolutePath();
|
||||||
DataRegister.initDataRegister();
|
dataRegister.initDataRegister();
|
||||||
DataRegister.resetPC();
|
dataRegister.resetPC();
|
||||||
toggleLEDs(null);
|
toggleLEDs(null);
|
||||||
IOPorts.reset();
|
ioPorts.reset();
|
||||||
|
|
||||||
for (ToggleButtonGroup toggleButtonGroup : allPORTbuttons) {
|
for (ToggleButtonGroup toggleButtonGroup : allPORTbuttons) {
|
||||||
try {
|
try {
|
||||||
toggleButtonGroup.getToggles().get(0).setSelected(true);
|
toggleButtonGroup.getToggles().get(0).setSelected(true);
|
||||||
toggleButtonGroup.getToggles().get(1).setSelected(false);
|
toggleButtonGroup.getToggles().get(1).setSelected(false);
|
||||||
IOPorts.setPORTfromUI(toggleButtonGroup);
|
ioPorts.setPORTfromUI(toggleButtonGroup);
|
||||||
} catch (NullPointerException ignored) {}
|
} catch (NullPointerException ignored) {}
|
||||||
}
|
}
|
||||||
ProgramStack.reset();
|
programStack.reset();
|
||||||
wakeUpFromSleep();
|
wakeUpFromSleep();
|
||||||
breakpoints.clear();
|
breakpoints.clear();
|
||||||
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
ioPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
|
||||||
Commands.resetTotalExecutionTime();
|
commands.resetTotalExecutionTime();
|
||||||
WatchdogTimer.reset();
|
watchdogTimer.reset();
|
||||||
wdtCheck.setSelected(false);
|
wdtCheck.setSelected(false);
|
||||||
Table.refresh();
|
table.refresh();
|
||||||
read = ParseFile.parseDatei(fileAddress);
|
read = ParseFile.parseDatei(fileAddress);
|
||||||
prog = read [0];
|
prog = read [0];
|
||||||
ind = read[1];
|
ind = read[1];
|
||||||
@ -396,11 +414,11 @@ public class Controller_Frontend {
|
|||||||
@FXML
|
@FXML
|
||||||
public void toggleWatchdog(ActionEvent actionEvent) {
|
public void toggleWatchdog(ActionEvent actionEvent) {
|
||||||
if (wdtCheck.isSelected()){
|
if (wdtCheck.isSelected()){
|
||||||
WatchdogTimer.enable();
|
watchdogTimer.enable();
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
WatchdogTimer.disable();
|
watchdogTimer.disable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,15 +491,15 @@ public class Controller_Frontend {
|
|||||||
allPORTButtons[i].getToggles().get(0).setSelected(true);
|
allPORTButtons[i].getToggles().get(0).setSelected(true);
|
||||||
allTRISButtons[i].getToggles().get(1).setSelected(false);
|
allTRISButtons[i].getToggles().get(1).setSelected(false);
|
||||||
allPORTButtons[i].getToggles().get(1).setSelected(false);
|
allPORTButtons[i].getToggles().get(1).setSelected(false);
|
||||||
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allTRISButtons[i]);
|
toggleButtonExt.get().addAlwaysOneSelectedSupport(allTRISButtons[i]);
|
||||||
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allPORTButtons[i]);
|
toggleButtonExt.get().addAlwaysOneSelectedSupport(allPORTButtons[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
ledCheckA.setSelected(false);
|
ledCheckA.setSelected(false);
|
||||||
ledCheckB.setSelected(false);
|
ledCheckB.setSelected(false);
|
||||||
setTRISbuttons(allTRISButtons);
|
setTRISbuttons(allTRISButtons);
|
||||||
setPORTbuttons(allPORTButtons);
|
setPORTbuttons(allPORTButtons);
|
||||||
IOPorts.setLEDs(allLEDsA, allLEDsB);
|
ioPorts.setLEDs(allLEDsA, allLEDsB);
|
||||||
|
|
||||||
lstContentListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
lstContentListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
|
||||||
|
|
||||||
@ -554,7 +572,7 @@ public class Controller_Frontend {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void toggleLEDs (ActionEvent actionEvent) {
|
public void toggleLEDs (ActionEvent actionEvent) {
|
||||||
IOPorts.setLEDs(new boolean[]{ledCheckA.isSelected(), ledCheckB.isSelected()});
|
ioPorts.setLEDs(new boolean[]{ledCheckA.isSelected(), ledCheckB.isSelected()});
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
@ -568,9 +586,9 @@ public class Controller_Frontend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateStack (){
|
private void updateStack (){
|
||||||
stackIndex.setText("Stack-Pointer: " + ProgramStack.getStackPointer());
|
stackIndex.setText("Stack-Pointer: " + programStack.getStackPointer());
|
||||||
ObservableList<String> observedList = FXCollections.observableArrayList();
|
ObservableList<String> observedList = FXCollections.observableArrayList();
|
||||||
List<Integer> stackList = ProgramStack.getStack();
|
List<Integer> stackList = programStack.getStack();
|
||||||
for (Integer integer : stackList) {
|
for (Integer integer : stackList) {
|
||||||
observedList.add("0x" + format(Integer.toHexString(integer).toUpperCase()));
|
observedList.add("0x" + format(Integer.toHexString(integer).toUpperCase()));
|
||||||
}
|
}
|
||||||
@ -578,7 +596,7 @@ public class Controller_Frontend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateWatchdog (){
|
private void updateWatchdog (){
|
||||||
wdtCheck.setText("Watchdog-Timer: " + WatchdogTimer.get() + "µs");
|
wdtCheck.setText("Watchdog-Timer: " + watchdogTimer.get() + "µs");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +0,0 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
|
||||||
|
|
||||||
public class DataEntry {
|
|
||||||
|
|
||||||
|
|
||||||
private final String address;
|
|
||||||
private final String value;
|
|
||||||
|
|
||||||
public DataEntry(String address, String value) {
|
|
||||||
this.address = address;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getValue(int columnIndex) {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,42 +1,57 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.EEPROMInterface;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class DataRegister {
|
public class DataRegister implements DataRegisterInterface {
|
||||||
private static final int INDF = 0x0;
|
private final int INDF = 0x0;
|
||||||
private static final int PCL = 0x2;
|
private final int PCL = 0x2;
|
||||||
private static final int STATUS = 0x3;
|
private final int STATUS = 0x3;
|
||||||
private static final int FSR = 0x4;
|
private final int FSR = 0x4;
|
||||||
private static final int PORTA = 0x5;
|
private final int PORTA = 0x5;
|
||||||
private static final int PORTB = 0x6;
|
private final int PORTB = 0x6;
|
||||||
private static final int PCLATH = 0xA;
|
private final int PCLATH = 0xA;
|
||||||
private static final int INTCON = 0xB;
|
private final int INTCON = 0xB;
|
||||||
|
|
||||||
private static final int EEDATA = 0x08;
|
private final int EEDATA = 0x08;
|
||||||
private static final int EEADR = 0x09;
|
private final int EEADR = 0x09;
|
||||||
private static final int EECON1 = 0x88;
|
private final int EECON1 = 0x88;
|
||||||
private static final int EECON2 = 0x89;
|
private final int EECON2 = 0x89;
|
||||||
|
|
||||||
private static final int TRISA = 0x85;
|
private final int TRISA = 0x85;
|
||||||
private static final int TRISB = 0x86;
|
private final int TRISB = 0x86;
|
||||||
|
|
||||||
private static final int C = 0x0;
|
private final int C = 0x0;
|
||||||
private static final int DC = 0x1;
|
private final int DC = 0x1;
|
||||||
private static final int Z = 0x2;
|
private final int Z = 0x2;
|
||||||
private static final int RP0 = 0x5;
|
private final int RP0 = 0x5;
|
||||||
|
|
||||||
|
|
||||||
private static final int [] dataRegister = new int[0xFF];
|
private final int [] dataRegister = new int[0xFF];
|
||||||
private static final int [] syncedRegisters = {INDF, PCL, STATUS, FSR, PCLATH, INTCON};
|
private final int [] syncedRegisters = {INDF, PCL, STATUS, FSR, PCLATH, INTCON};
|
||||||
private static final int [] eepromRegisters = {EEDATA, EEADR, EECON1, EECON2};
|
private final int [] eepromRegisters = {EEDATA, EEADR, EECON1, EECON2};
|
||||||
public static final int [] ioRegisters = {PORTA, PORTB, TRISA, TRISB};
|
public final int [] ioRegisters = {PORTA, PORTB, TRISA, TRISB};
|
||||||
|
|
||||||
public static void initDataRegister() {
|
private final EEPROMInterface eeprom;
|
||||||
|
private final PreScaler preScaler;
|
||||||
|
private final IOPortInterface ioPorts;
|
||||||
|
|
||||||
|
public DataRegister (EEPROMInterface eeprom, PreScaler preScaler, IOPortInterface ioPorts) {
|
||||||
|
this.eeprom = eeprom;
|
||||||
|
this.preScaler = preScaler;
|
||||||
|
this.ioPorts = ioPorts;
|
||||||
|
initOrReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initOrReset () {
|
||||||
dataRegister[PCL] = 0b0;
|
dataRegister[PCL] = 0b0;
|
||||||
dataRegister[STATUS] = 0b00011000;
|
dataRegister[STATUS] = 0b00011000;
|
||||||
dataRegister[PCLATH] = 0b0;
|
dataRegister[PCLATH] = 0b0;
|
||||||
dataRegister[INTCON] = 0b0;
|
dataRegister[INTCON] = 0b0;
|
||||||
|
|
||||||
dataRegister[0x81] = 0b11111111;
|
dataRegister[0x81] = 0b11111111;
|
||||||
dataRegister[0x80 + PCL] = dataRegister[PCL];
|
dataRegister[0x80 + PCL] = dataRegister[PCL];
|
||||||
dataRegister[0x80 + STATUS] = dataRegister[STATUS];
|
dataRegister[0x80 + STATUS] = dataRegister[STATUS];
|
||||||
@ -47,11 +62,15 @@ public class DataRegister {
|
|||||||
carryFlag = 0;
|
carryFlag = 0;
|
||||||
zeroFlag = 0;
|
zeroFlag = 0;
|
||||||
digitCarryFlag = 0;
|
digitCarryFlag = 0;
|
||||||
IOPorts.resetTRIS();
|
ioPorts.resetTRIS();
|
||||||
System.out.println(Arrays.toString(dataRegister));
|
System.out.println(Arrays.toString(dataRegister));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isSyncedRegister (int address){
|
public void initDataRegister() {
|
||||||
|
initOrReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSyncedRegister (int address){
|
||||||
for (int register : syncedRegisters){
|
for (int register : syncedRegisters){
|
||||||
if (address == register || address == 0x80 + register){
|
if (address == register || address == 0x80 + register){
|
||||||
return true;
|
return true;
|
||||||
@ -60,11 +79,11 @@ public class DataRegister {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] getDataRegister() {
|
public int[] getDataRegister() {
|
||||||
return dataRegister;
|
return dataRegister;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int determineIndirectAndChange (int address){
|
private int determineIndirectAndChange (int address){
|
||||||
if (address == INDF || address == 0x80 + INDF) {
|
if (address == INDF || address == 0x80 + INDF) {
|
||||||
return dataRegister[FSR];
|
return dataRegister[FSR];
|
||||||
}
|
}
|
||||||
@ -72,29 +91,29 @@ public class DataRegister {
|
|||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getFSR (){
|
public int getFSR (){
|
||||||
return dataRegister[FSR];
|
return dataRegister[FSR];
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int bank() {
|
private int bank() {
|
||||||
return ((dataRegister[STATUS] >> RP0) & 1) * 0x80;
|
return ((dataRegister[STATUS] >> RP0) & 1) * 0x80;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getRegister(int fileAddress){
|
public int getRegister(int fileAddress){
|
||||||
int address = determineIndirectAndChange (fileAddress);
|
int address = determineIndirectAndChange (fileAddress);
|
||||||
if (bank () + address == EECON2)
|
if (bank () + address == EECON2)
|
||||||
return 0;
|
return 0;
|
||||||
return dataRegister[bank() + address];
|
return dataRegister[bank() + address];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setRegister(int fileAddress, int content){
|
public void setRegister(int fileAddress, int content){
|
||||||
int address = determineIndirectAndChange (fileAddress);
|
int address = determineIndirectAndChange (fileAddress);
|
||||||
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
||||||
IOPorts.setRegister(bank() + address, content);
|
ioPorts.setRegister(bank() + address, content);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
||||||
EEPROM.parse(bank() + address, content, 0b11);
|
eeprom.parse(bank() + address, content, 0b11);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fileAddress == PCL || fileAddress == 0x80 + PCL){
|
if (fileAddress == PCL || fileAddress == 0x80 + PCL){
|
||||||
@ -110,28 +129,28 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
PreScaler.resetFromRegister();
|
preScaler.resetFromRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getBit(int fileAddress, int bit) {
|
public int getBit(int fileAddress, int bit) {
|
||||||
int address = determineIndirectAndChange (fileAddress);
|
int address = determineIndirectAndChange (fileAddress);
|
||||||
if (bank() + address == EECON2)
|
if (bank() + address == EECON2)
|
||||||
return 0;
|
return 0;
|
||||||
return (dataRegister[bank() + address] >> bit) & 1;
|
return (dataRegister[bank() + address] >> bit) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDirectBit(int address, int bit){
|
public int getDirectBit(int address, int bit){
|
||||||
return (dataRegister[address] >> bit) & 1;
|
return (dataRegister[address] >> bit) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearBit(int fileAddress, int bit) {
|
public void clearBit(int fileAddress, int bit) {
|
||||||
int address = determineIndirectAndChange (fileAddress);
|
int address = determineIndirectAndChange (fileAddress);
|
||||||
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
||||||
IOPorts.clearBit(bank() + address, bit);
|
ioPorts.clearBit(bank() + address, bit);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
||||||
EEPROM.parse(bank () + address, bit, 0b00);
|
eeprom.parse(bank () + address, bit, 0b00);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isSyncedRegister(address)) {
|
if (!isSyncedRegister(address)) {
|
||||||
@ -149,17 +168,17 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
PreScaler.resetFromRegister();
|
preScaler.resetFromRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBit(int fileAddress, int bit) {
|
public void setBit(int fileAddress, int bit) {
|
||||||
int address = determineIndirectAndChange (fileAddress);
|
int address = determineIndirectAndChange (fileAddress);
|
||||||
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
|
||||||
IOPorts.setBit(bank() + address, bit);
|
ioPorts.setBit(bank() + address, bit);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
if (Arrays.stream(eepromRegisters).anyMatch(i -> i == address)){
|
||||||
EEPROM.parse(bank () + address, bit, 0b10);
|
eeprom.parse(bank () + address, bit, 0b10);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!isSyncedRegister(address)) {
|
if (!isSyncedRegister(address)) {
|
||||||
@ -177,10 +196,10 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (address == 1)
|
if (address == 1)
|
||||||
PreScaler.resetFromRegister();
|
preScaler.resetFromRegister();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDirectBit (int fileAddress, int bit, int value){
|
public void setDirectBit (int fileAddress, int bit, int value){
|
||||||
if (getDirectBit(fileAddress, bit) == 0 && value == 1){
|
if (getDirectBit(fileAddress, bit) == 0 && value == 1){
|
||||||
dataRegister[fileAddress] += (int) Math.pow(2, bit);
|
dataRegister[fileAddress] += (int) Math.pow(2, bit);
|
||||||
} else if (getDirectBit(fileAddress, bit) == 1 && value == 0){
|
} else if (getDirectBit(fileAddress, bit) == 1 && value == 0){
|
||||||
@ -188,14 +207,14 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int programCounter = 0;
|
private int programCounter = 0;
|
||||||
|
|
||||||
private static void writeToPCL(){
|
private void writeToPCL(){
|
||||||
dataRegister[PCL] = programCounter & 0xFF;
|
dataRegister[PCL] = programCounter & 0xFF;
|
||||||
dataRegister[0x80 + PCL] = dataRegister[PCL];
|
dataRegister[0x80 + PCL] = dataRegister[PCL];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void increasePC (){
|
public void increasePC (){
|
||||||
if (programCounter != 0x3FF) {
|
if (programCounter != 0x3FF) {
|
||||||
programCounter++;
|
programCounter++;
|
||||||
}
|
}
|
||||||
@ -205,28 +224,28 @@ public class DataRegister {
|
|||||||
writeToPCL();
|
writeToPCL();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPC (int value){
|
public void setPC (int value){
|
||||||
programCounter = value + ((getRegister(PCLATH) & 0b11000) << 8);
|
programCounter = value + ((getRegister(PCLATH) & 0b11000) << 8);
|
||||||
writeToPCL();
|
writeToPCL();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetPC () {
|
public void resetPC () {
|
||||||
programCounter = 0;
|
programCounter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPC(){
|
public int getPC(){
|
||||||
return programCounter;
|
return programCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setFlags() {
|
private void setFlags() {
|
||||||
carryFlag = getDirectBit(STATUS, C);
|
carryFlag = getDirectBit(STATUS, C);
|
||||||
digitCarryFlag = getDirectBit(STATUS, DC);
|
digitCarryFlag = getDirectBit(STATUS, DC);
|
||||||
zeroFlag = getDirectBit(STATUS, Z);
|
zeroFlag = getDirectBit(STATUS, Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int zeroFlag = 0;
|
private int zeroFlag = 0;
|
||||||
|
|
||||||
public static void determineZeroFlag(int result){
|
public void determineZeroFlag(int result){
|
||||||
if (result == 0){
|
if (result == 0){
|
||||||
zeroFlag = 1;
|
zeroFlag = 1;
|
||||||
if (getBit(STATUS, Z) == 0){
|
if (getBit(STATUS, Z) == 0){
|
||||||
@ -243,13 +262,13 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getZeroFlag(){
|
public int getZeroFlag(){
|
||||||
return zeroFlag;
|
return zeroFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int carryFlag = 0;
|
private int carryFlag = 0;
|
||||||
|
|
||||||
public static void setCarryFlag(int value){
|
public void setCarryFlag(int value){
|
||||||
carryFlag = value;
|
carryFlag = value;
|
||||||
if (value == 1){
|
if (value == 1){
|
||||||
if (getBit(STATUS, C) == 0){
|
if (getBit(STATUS, C) == 0){
|
||||||
@ -265,7 +284,7 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void determineCarryFlag (int result){
|
public void determineCarryFlag (int result){
|
||||||
if (result > 0xFF){
|
if (result > 0xFF){
|
||||||
setCarryFlag(1);
|
setCarryFlag(1);
|
||||||
}
|
}
|
||||||
@ -274,13 +293,13 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCarryFlag (){
|
public int getCarryFlag (){
|
||||||
return carryFlag;
|
return carryFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int digitCarryFlag = 0;
|
private int digitCarryFlag = 0;
|
||||||
|
|
||||||
public static void setDigitCarryFlag(int value){
|
public void setDigitCarryFlag(int value){
|
||||||
digitCarryFlag = value;
|
digitCarryFlag = value;
|
||||||
if (value == 1){
|
if (value == 1){
|
||||||
if (getBit(STATUS, DC) == 0){
|
if (getBit(STATUS, DC) == 0){
|
||||||
@ -296,7 +315,7 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void determineDigitCarryFlag(int result){
|
public void determineDigitCarryFlag(int result){
|
||||||
if (result >> 4 == 1){
|
if (result >> 4 == 1){
|
||||||
setDigitCarryFlag(1);
|
setDigitCarryFlag(1);
|
||||||
}
|
}
|
||||||
@ -305,30 +324,30 @@ public class DataRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDigitCarryFlag(){
|
public int getDigitCarryFlag(){
|
||||||
return digitCarryFlag;
|
return digitCarryFlag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setDirectRegister(int fileAddress, int content) {
|
public void setDirectRegister(int fileAddress, int content) {
|
||||||
dataRegister[fileAddress] = content;
|
dataRegister[fileAddress] = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static int getPCL() {
|
public int getPCL() {
|
||||||
return PCL;
|
return PCL;
|
||||||
}
|
}
|
||||||
public static int getSTATUS() {
|
public int getSTATUS() {
|
||||||
return STATUS;
|
return STATUS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPCLATH() {
|
public int getPCLATH() {
|
||||||
return PCLATH;
|
return PCLATH;
|
||||||
}
|
}
|
||||||
public static int getINTCON() {
|
public int getINTCON() {
|
||||||
return INTCON;
|
return INTCON;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getDirectRegister(int address) {
|
public int getDirectRegister(int address) {
|
||||||
return dataRegister[address];
|
return dataRegister[address];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
|
||||||
|
import eu.hansolo.tilesfx.Command;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
@ -11,26 +12,34 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
import static fabrik.simulator.pic16f84.Commands.getTotalExecutionTime;
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
|
|
||||||
public class EEPROM {
|
public class EEPROM implements EEPROMInterface {
|
||||||
private static final int EEDATA = 0x08;
|
private final int EEDATA = 0x08;
|
||||||
private static final int EEADR = 0x09;
|
private final int EEADR = 0x09;
|
||||||
private static final int EECON1 = 0x88;
|
private final int EECON1 = 0x88;
|
||||||
private static final int EECON2 = 0x89;
|
private final int EECON2 = 0x89;
|
||||||
|
|
||||||
private static final int RD = 0x00;
|
private final int RD = 0x00;
|
||||||
private static final int WR = 0x01;
|
private final int WR = 0x01;
|
||||||
private static final int WRERR = 0x03;
|
private final int WRERR = 0x03;
|
||||||
private static final int EEIF = 0x04;
|
private final int EEIF = 0x04;
|
||||||
|
|
||||||
private static boolean readControl = false;
|
private boolean readControl = false;
|
||||||
private static boolean writeControl = false;
|
private boolean writeControl = false;
|
||||||
private static boolean [] eecon2stages = {false, false};
|
private boolean [] eecon2stages = {false, false};
|
||||||
|
|
||||||
private static long startTime;
|
private final DataRegisterInterface dataRegister;
|
||||||
|
private final CommandInterface commands;
|
||||||
|
|
||||||
public static long read (int address) {
|
private double startTime;
|
||||||
|
|
||||||
|
public EEPROM (DataRegisterInterface dataRegister, CommandInterface commands){
|
||||||
|
this.dataRegister = dataRegister;
|
||||||
|
this.commands = commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long read (int address) {
|
||||||
FileReader reader;
|
FileReader reader;
|
||||||
try {
|
try {
|
||||||
reader = new FileReader("eeprom.json");
|
reader = new FileReader("eeprom.json");
|
||||||
@ -47,19 +56,19 @@ public class EEPROM {
|
|||||||
Object requestedData = data.get(String.valueOf(address));
|
Object requestedData = data.get(String.valueOf(address));
|
||||||
try {
|
try {
|
||||||
readControl = false;
|
readControl = false;
|
||||||
DataRegister.setDirectBit(EECON1, RD, 0);
|
dataRegister.setDirectBit(EECON1, RD, 0);
|
||||||
return (long) requestedData;
|
return (long) requestedData;
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void write (int address, long data) {
|
public void write (int address, long data) {
|
||||||
FileReader reader;
|
FileReader reader;
|
||||||
try {
|
try {
|
||||||
reader = new FileReader("eeprom.json");
|
reader = new FileReader("eeprom.json");
|
||||||
} catch (FileNotFoundException ignored) {
|
} catch (FileNotFoundException ignored) {
|
||||||
DataRegister.setDirectBit(EECON1, WRERR, 1);
|
dataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONParser parser = new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
@ -67,32 +76,32 @@ public class EEPROM {
|
|||||||
try {
|
try {
|
||||||
eeprom = (JSONObject) parser.parse(reader);
|
eeprom = (JSONObject) parser.parse(reader);
|
||||||
} catch (ParseException | IOException ignored) {
|
} catch (ParseException | IOException ignored) {
|
||||||
DataRegister.setDirectBit(EECON1, WRERR, 1);
|
dataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
eeprom.put(String.valueOf(address), data);
|
eeprom.put(String.valueOf(address), data);
|
||||||
try {
|
try {
|
||||||
Files.write(Paths.get("eeprom.json"), eeprom.toJSONString().getBytes());
|
Files.write(Paths.get("eeprom.json"), eeprom.toJSONString().getBytes());
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
DataRegister.setDirectBit(EECON1, WRERR, 1);
|
dataRegister.setDirectBit(EECON1, WRERR, 1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
registerTime(true);
|
registerTime(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerTime(boolean reset) {
|
public void registerTime(boolean reset) {
|
||||||
if (reset)
|
if (reset)
|
||||||
startTime = getTotalExecutionTime();
|
startTime = commands.getTotalExecutionTime();
|
||||||
else if ((getTotalExecutionTime() >= (startTime + 1000)) && writeControl) {
|
else if ((commands.getTotalExecutionTime() >= (startTime + 1000)) && writeControl) {
|
||||||
eecon2stages = new boolean[]{false, false};
|
eecon2stages = new boolean[]{false, false};
|
||||||
DataRegister.setDirectBit(EECON1, EEIF, 1);
|
dataRegister.setDirectBit(EECON1, EEIF, 1);
|
||||||
DataRegister.setDirectBit(EECON1, WR, 0);
|
dataRegister.setDirectBit(EECON1, WR, 0);
|
||||||
writeControl = false;
|
writeControl = false;
|
||||||
startTime = 0;
|
startTime = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void parse(int address, int content, int opcode) {
|
public void parse(int address, int content, int opcode) {
|
||||||
//OPCODE: 0b1x = set
|
//OPCODE: 0b1x = set
|
||||||
//OPCODE: 0b0x = clear
|
//OPCODE: 0b0x = clear
|
||||||
//OPCODE: 0bx1 = byte
|
//OPCODE: 0bx1 = byte
|
||||||
@ -100,21 +109,21 @@ public class EEPROM {
|
|||||||
switch (opcode){
|
switch (opcode){
|
||||||
case 0b00: // CLEAR BIT
|
case 0b00: // CLEAR BIT
|
||||||
if(address == EECON1) {
|
if(address == EECON1) {
|
||||||
if (DataRegister.getDirectBit(address, content) == 1)
|
if (dataRegister.getDirectBit(address, content) == 1)
|
||||||
setEECON1((int) (DataRegister.getDirectRegister(EECON1) - Math.pow(2, content)));
|
setEECON1((int) (dataRegister.getDirectRegister(EECON1) - Math.pow(2, content)));
|
||||||
} else {
|
} else {
|
||||||
DataRegister.setDirectBit(address, content, 0);
|
dataRegister.setDirectBit(address, content, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0b10: // SET BIT
|
case 0b10: // SET BIT
|
||||||
if(address == EECON1) {
|
if(address == EECON1) {
|
||||||
if (DataRegister.getDirectBit(address, content) == 0)
|
if (dataRegister.getDirectBit(address, content) == 0)
|
||||||
setEECON1((int) (DataRegister.getDirectRegister(EECON1) + Math.pow(2, content)));
|
setEECON1((int) (dataRegister.getDirectRegister(EECON1) + Math.pow(2, content)));
|
||||||
} else {
|
} else {
|
||||||
if (address == EEADR && content >= 0b01000000)
|
if (address == EEADR && content >= 0b01000000)
|
||||||
DataRegister.setDirectBit(address, content, 0);
|
dataRegister.setDirectBit(address, content, 0);
|
||||||
else
|
else
|
||||||
DataRegister.setDirectBit(address, content, 1);
|
dataRegister.setDirectBit(address, content, 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0b11: // SET BYTE
|
case 0b11: // SET BYTE
|
||||||
@ -131,20 +140,20 @@ public class EEPROM {
|
|||||||
else
|
else
|
||||||
eecon2stages = new boolean[]{false, false};
|
eecon2stages = new boolean[]{false, false};
|
||||||
}
|
}
|
||||||
DataRegister.setDirectRegister(address, content);
|
dataRegister.setDirectRegister(address, content);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setEECON1(int content) {
|
private void setEECON1(int content) {
|
||||||
content &= 0b00011111;
|
content &= 0b00011111;
|
||||||
boolean writeEnabled = ((content & 0b100) >> 2) == 1;
|
boolean writeEnabled = ((content & 0b100) >> 2) == 1;
|
||||||
if ((content & 0b1) == 1) { // READ
|
if ((content & 0b1) == 1) { // READ
|
||||||
readControl = true;
|
readControl = true;
|
||||||
DataRegister.setDirectRegister(EECON1, content);
|
dataRegister.setDirectRegister(EECON1, content);
|
||||||
int data = (int) read(DataRegister.getDirectRegister(EEADR));
|
int data = (int) read(dataRegister.getDirectRegister(EEADR));
|
||||||
DataRegister.setDirectRegister(EEDATA, data);
|
dataRegister.setDirectRegister(EEDATA, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ((content & 0b1) == 0 && readControl) // RD kann nicht manuell gecleart werden
|
else if ((content & 0b1) == 0 && readControl) // RD kann nicht manuell gecleart werden
|
||||||
@ -152,8 +161,8 @@ public class EEPROM {
|
|||||||
if (((content & 0b10) >> 1) == 1) { // WRITE CONTROL
|
if (((content & 0b10) >> 1) == 1) { // WRITE CONTROL
|
||||||
if (writeEnabled && eecon2stages[0] && eecon2stages[1]) {
|
if (writeEnabled && eecon2stages[0] && eecon2stages[1]) {
|
||||||
writeControl = true;
|
writeControl = true;
|
||||||
DataRegister.setDirectRegister(EECON1, content);
|
dataRegister.setDirectRegister(EECON1, content);
|
||||||
write(DataRegister.getDirectRegister(EEADR), DataRegister.getDirectRegister(EEDATA));
|
write(dataRegister.getDirectRegister(EEADR), dataRegister.getDirectRegister(EEDATA));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -162,6 +171,6 @@ public class EEPROM {
|
|||||||
}
|
}
|
||||||
else if ((((content & 0b10) >> 1) == 0) && writeControl) // WR kann nicht manuell gecleart werden
|
else if ((((content & 0b10) >> 1) == 0) && writeControl) // WR kann nicht manuell gecleart werden
|
||||||
content |= 0b10;
|
content |= 0b10;
|
||||||
DataRegister.setDirectRegister(EECON1, content);
|
dataRegister.setDirectRegister(EECON1, content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
146
src/main/java/fabrik/simulator/pic16f84/EmptyRegister.java
Normal file
146
src/main/java/fabrik/simulator/pic16f84/EmptyRegister.java
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||||
|
|
||||||
|
public class EmptyRegister implements DataRegisterInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearBit(int f, int b) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setBit(int f, int b) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPC(int pop) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getINTCON() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPC() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRegister(int file, int wRegister) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void determineZeroFlag(int wRegister) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRegister(int file) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCarryFlag(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDigitCarryFlag(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCarryFlag() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void determineCarryFlag(int result) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void increasePC() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void determineDigitCarryFlag(int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getBit(int address, int bit) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDirectBit(int option, int psa) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDirectRegister(int option) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDirectBit(int option, int i, int i1) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setDirectRegister(int porta, int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetPC() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int[] getDataRegister() {
|
||||||
|
return new int[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getDigitCarryFlag() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getZeroFlag() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFSR() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initDataRegister() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPCL() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getPCLATH() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSTATUS() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,39 +1,58 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
import javafx.scene.control.ToggleButton;
|
import javafx.scene.control.ToggleButton;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
import javafx.scene.paint.RadialGradient;
|
import javafx.scene.paint.RadialGradient;
|
||||||
import javafx.scene.paint.Stop;
|
import javafx.scene.paint.Stop;
|
||||||
import javafx.scene.shape.Circle;
|
import javafx.scene.shape.Circle;
|
||||||
import javafx.stage.Stage;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class IOPorts {
|
public class IOPorts implements IOPortInterface {
|
||||||
private static final int A = 0;
|
private final int A = 0;
|
||||||
private static final int B = 1;
|
private final int B = 1;
|
||||||
private static final int PORTA = 5;
|
private final int PORTA = 5;
|
||||||
private static final int PORTB = 6;
|
private final int PORTB = 6;
|
||||||
private static final int TRISA = 0x85;
|
private final int TRISA = 0x85;
|
||||||
private static final int TRISB = 0x86;
|
private final int TRISB = 0x86;
|
||||||
|
|
||||||
private static int [] trisLatch = {0xFF, 0xFF};
|
private int [] trisLatch = {0xFF, 0xFF};
|
||||||
private static int [] dataLatch = new int[2];
|
private int [] dataLatch = new int[2];
|
||||||
private static boolean isLEDenabledA = false;
|
private boolean isLEDenabledA = false;
|
||||||
private static boolean isLEDenabledB = false;
|
private boolean isLEDenabledB = false;
|
||||||
private static Circle[] allLEDsA;
|
private Circle[] allLEDsA;
|
||||||
private static Circle[] allLEDsB;
|
private Circle[] allLEDsB;
|
||||||
|
|
||||||
|
|
||||||
private static int RB4 = 0x10;
|
private int RB4 = 0x10;
|
||||||
private static int RB5 = 0x20;
|
private int RB5 = 0x20;
|
||||||
private static int RB6 = 0x40;
|
private int RB6 = 0x40;
|
||||||
private static int RB7 = 0x80;
|
private int RB7 = 0x80;
|
||||||
|
|
||||||
|
|
||||||
public static void setBit (int address, int bit){
|
private final DataRegisterInterface dataRegister;
|
||||||
|
private final TimerInterface timer;
|
||||||
|
private final InterruptInterface interrupts;
|
||||||
|
private final TableInterface table;
|
||||||
|
private final WindowManagement createWindow;
|
||||||
|
private final FrontendControllerInterface frontendController;
|
||||||
|
|
||||||
|
public IOPorts (DataRegisterInterface dataRegister, FrontendControllerInterface frontendController, TimerInterface timer,
|
||||||
|
InterruptInterface interrupts, TableInterface table, WindowManagement createWindow){
|
||||||
|
|
||||||
|
this.dataRegister = dataRegister;
|
||||||
|
this.timer = timer;
|
||||||
|
this.frontendController = frontendController;
|
||||||
|
this.interrupts = interrupts;
|
||||||
|
this.createWindow = createWindow;
|
||||||
|
this.table = table;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setBit (int address, int bit){
|
||||||
if (address < 7) {
|
if (address < 7) {
|
||||||
dataLatch[address - PORTA] |= (1 << bit);
|
dataLatch[address - PORTA] |= (1 << bit);
|
||||||
}
|
}
|
||||||
@ -43,7 +62,7 @@ public class IOPorts {
|
|||||||
refreshPorts();
|
refreshPorts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void clearBit(int address, int bit) {
|
public void clearBit(int address, int bit) {
|
||||||
if (address < 7) {
|
if (address < 7) {
|
||||||
if (((dataLatch[address-PORTA] >> bit)&1) == 1){
|
if (((dataLatch[address-PORTA] >> bit)&1) == 1){
|
||||||
dataLatch[address-PORTA] -= (int) Math.pow(2, bit);
|
dataLatch[address-PORTA] -= (int) Math.pow(2, bit);
|
||||||
@ -57,7 +76,7 @@ public class IOPorts {
|
|||||||
refreshPorts();
|
refreshPorts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setRegister(int address, int content) {
|
public void setRegister(int address, int content) {
|
||||||
if (address < 7) {
|
if (address < 7) {
|
||||||
dataLatch[address - PORTA] = content;
|
dataLatch[address - PORTA] = content;
|
||||||
}
|
}
|
||||||
@ -67,24 +86,24 @@ public class IOPorts {
|
|||||||
refreshPorts();
|
refreshPorts();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void refreshPorts() {
|
private void refreshPorts() {
|
||||||
DataRegister.setDirectRegister(PORTA, ((~((~dataLatch[A])&0x1F | trisLatch[A])) | (trisLatch[A] & DataRegister.getDirectRegister(PORTA))) & 0xFF);
|
dataRegister.setDirectRegister(PORTA, ((~((~dataLatch[A])&0x1F | trisLatch[A])) | (trisLatch[A] & dataRegister.getDirectRegister(PORTA))) & 0xFF);
|
||||||
DataRegister.setDirectRegister(PORTB, ((~((~dataLatch[B])&0xFF | trisLatch[B])) | (trisLatch[B] & DataRegister.getDirectRegister(PORTB))) & 0xFF);
|
dataRegister.setDirectRegister(PORTB, ((~((~dataLatch[B])&0xFF | trisLatch[B])) | (trisLatch[B] & dataRegister.getDirectRegister(PORTB))) & 0xFF);
|
||||||
DataRegister.setDirectRegister(TRISA, trisLatch[A]);
|
dataRegister.setDirectRegister(TRISA, trisLatch[A]);
|
||||||
DataRegister.setDirectRegister(TRISB, trisLatch[B]);
|
dataRegister.setDirectRegister(TRISB, trisLatch[B]);
|
||||||
if (((trisLatch[A] >> 4) & 1 )== 1)
|
if (((trisLatch[A] >> 4) & 1 )== 1)
|
||||||
Timer.incrementFromPin(DataRegister.getDirectRegister(PORTA));
|
timer.incrementFromPin(dataRegister.getDirectRegister(PORTA));
|
||||||
ToggleButtonGroup[] buttons = Controller_Frontend.getPORTbuttons();
|
ToggleButtonGroup[] buttons = Controller_Frontend.getPORTbuttons();
|
||||||
for (int i = 0; i < buttons.length; i++){
|
for (int i = 0; i < buttons.length; i++){
|
||||||
int port = (i < 8) ? PORTA : PORTB;
|
int port = (i < 8) ? PORTA : PORTB;
|
||||||
int bit = i % 8;
|
int bit = i % 8;
|
||||||
boolean value = ((DataRegister.getDirectRegister(port) >> bit) & 1) == 1;
|
boolean value = ((dataRegister.getDirectRegister(port) >> bit) & 1) == 1;
|
||||||
buttons[i].getToggles().get(0).setSelected(!value);
|
buttons[i].getToggles().get(0).setSelected(!value);
|
||||||
buttons[i].getToggles().get(1).setSelected(value);
|
buttons[i].getToggles().get(1).setSelected(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshUI(ToggleButtonGroup[] buttonsTRIS, ToggleButtonGroup[] buttonsPORT) {
|
public void refreshUI(ToggleButtonGroup[] buttonsTRIS, ToggleButtonGroup[] buttonsPORT) {
|
||||||
for (int i = 0; i< buttonsTRIS.length; i++){
|
for (int i = 0; i< buttonsTRIS.length; i++){
|
||||||
int tris = (i < 8) ? trisLatch[A] : trisLatch[B];
|
int tris = (i < 8) ? trisLatch[A] : trisLatch[B];
|
||||||
boolean val = isInput(tris, i%8);
|
boolean val = isInput(tris, i%8);
|
||||||
@ -95,18 +114,18 @@ public class IOPorts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void updateLEDs(boolean updateAll, int index, boolean val) {
|
private void updateLEDs(boolean updateAll, int index, boolean val) {
|
||||||
if (updateAll) {
|
if (updateAll) {
|
||||||
if (index < 8) {
|
if (index < 8) {
|
||||||
if (isLEDenabledA && !val) {
|
if (isLEDenabledA && !val) {
|
||||||
if (DataRegister.getDirectBit(PORTA, index) == 1)
|
if (dataRegister.getDirectBit(PORTA, index) == 1)
|
||||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||||
else
|
else
|
||||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (isLEDenabledB && !val) {
|
if (isLEDenabledB && !val) {
|
||||||
if (DataRegister.getDirectBit(PORTB, index - 8) == 1)
|
if (dataRegister.getDirectBit(PORTB, index - 8) == 1)
|
||||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
||||||
else
|
else
|
||||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||||
@ -115,23 +134,23 @@ public class IOPorts {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (index < 8)
|
if (index < 8)
|
||||||
if (val || DataRegister.getDirectBit(PORTA, index) == 0)
|
if (val || dataRegister.getDirectBit(PORTA, index) == 0)
|
||||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||||
else
|
else
|
||||||
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
allLEDsA[index].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
||||||
else
|
else
|
||||||
if (val || DataRegister.getDirectBit(PORTB, index - 8) == 0)
|
if (val || dataRegister.getDirectBit(PORTB, index - 8) == 0)
|
||||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.BLACK), new Stop(1, Color.DARKGRAY)));
|
||||||
else
|
else
|
||||||
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
allLEDsB[index - 8].setFill(new RadialGradient(0, 0, 0.5, 0.5, 0.7, true, null, new Stop(0, Color.RED), new Stop(1, Color.DARKGRAY)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isInput(int i, int bit) {
|
private boolean isInput(int i, int bit) {
|
||||||
return (i >> bit & 1) == 1;
|
return (i >> bit & 1) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setTRISfromUI(ToggleButtonGroup parent) throws IOException {
|
public void setTRISfromUI(ToggleButtonGroup parent) throws IOException {
|
||||||
int [] params = getToggleParams(parent);
|
int [] params = getToggleParams(parent);
|
||||||
int tris = params[0];
|
int tris = params[0];
|
||||||
int bit = params[1];
|
int bit = params[1];
|
||||||
@ -150,23 +169,23 @@ public class IOPorts {
|
|||||||
refreshTable(parent);
|
refreshTable(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPORTfromUI(ToggleButtonGroup parent) throws IOException {
|
public void setPORTfromUI(ToggleButtonGroup parent) throws IOException {
|
||||||
int [] params = getToggleParams(parent);
|
int [] params = getToggleParams(parent);
|
||||||
int port = params[0];
|
int port = params[0];
|
||||||
int bit = params[1];
|
int bit = params[1];
|
||||||
int value = params [2];
|
int value = params [2];
|
||||||
value = (value == 1) ? 0 : 1;
|
value = (value == 1) ? 0 : 1;
|
||||||
int oldValue = DataRegister.getDirectBit(port, bit);
|
int oldValue = dataRegister.getDirectBit(port, bit);
|
||||||
DataRegister.setDirectBit(port, bit, value);
|
dataRegister.setDirectBit(port, bit, value);
|
||||||
refreshPorts();
|
refreshPorts();
|
||||||
refreshTable(parent);
|
refreshTable(parent);
|
||||||
if (port == PORTB && bit >= 4)
|
if (port == PORTB && bit >= 4)
|
||||||
Interrupts.triggerRBInterrupt(oldValue, value);
|
interrupts.triggerRBInterrupt(oldValue, value);
|
||||||
else if (port == PORTB && bit == 0)
|
else if (port == PORTB && bit == 0)
|
||||||
Interrupts.triggerRB0Interrupt(oldValue, value);
|
interrupts.triggerRB0Interrupt(oldValue, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLEDs (boolean[] leds) {
|
public void setLEDs (boolean[] leds) {
|
||||||
boolean isAnowDisabled = isLEDenabledA && !leds[0];
|
boolean isAnowDisabled = isLEDenabledA && !leds[0];
|
||||||
isLEDenabledA = leds[0];
|
isLEDenabledA = leds[0];
|
||||||
boolean isBnowDisabled = isLEDenabledB && !leds[1];
|
boolean isBnowDisabled = isLEDenabledB && !leds[1];
|
||||||
@ -183,17 +202,17 @@ public class IOPorts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLEDs (Circle[] a, Circle[] b){
|
public void setLEDs (Circle[] a, Circle[] b){
|
||||||
allLEDsA = a;
|
allLEDsA = a;
|
||||||
allLEDsB = b;
|
allLEDsB = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshTable(ToggleButtonGroup parent) {
|
public void refreshTable(ToggleButtonGroup parent) {
|
||||||
Table.refresh();
|
table.refresh();
|
||||||
CreateWindow.refreshTable();
|
createWindow.refreshTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] getToggleParams(ToggleButtonGroup parent) {
|
private int[] getToggleParams(ToggleButtonGroup parent) {
|
||||||
String group = parent.getId();
|
String group = parent.getId();
|
||||||
ObservableList<ToggleButton> toggles = parent.getToggles();
|
ObservableList<ToggleButton> toggles = parent.getToggles();
|
||||||
int fileAddress;
|
int fileAddress;
|
||||||
@ -213,13 +232,13 @@ public class IOPorts {
|
|||||||
return new int[]{fileAddress, bit, value};
|
return new int[]{fileAddress, bit, value};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reset() {
|
public void reset() {
|
||||||
trisLatch = new int[]{0xFF, 0xFF};
|
trisLatch = new int[]{0xFF, 0xFF};
|
||||||
dataLatch = new int[2];
|
dataLatch = new int[2];
|
||||||
refreshPorts();
|
refreshPorts();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetTRIS (){
|
public void resetTRIS (){
|
||||||
trisLatch = new int[] {0xFF, 0xFF};
|
trisLatch = new int[] {0xFF, 0xFF};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,48 +1,63 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
public class Interrupts {
|
import eu.hansolo.tilesfx.Command;
|
||||||
private static final int INTCON = 0xB;
|
import fabrik.simulator.pic16f84.interfaces.CommandInterface;
|
||||||
private static final int T0IF = 0x2;
|
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||||
private static final int ISR = 0x4;
|
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface;
|
||||||
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;
|
|
||||||
|
|
||||||
public static void triggerTMR0(boolean manual) {
|
public class Interrupts {
|
||||||
triggerInterrupt(T0IF, T0IE);
|
private final int INTCON = 0xB;
|
||||||
if (manual)
|
private final int T0IF = 0x2;
|
||||||
DataRegister.increasePC();
|
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) {
|
public void triggerTMR0(boolean manual) {
|
||||||
DataRegister.setBit(INTCON, flag);
|
triggerInterrupt(T0IF, T0IE);
|
||||||
enableFlag = DataRegister.getDirectBit(INTCON, enableFlag);
|
if (manual)
|
||||||
int globalFlag = DataRegister.getDirectBit(INTCON, GIE);
|
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) {
|
if (enableFlag == 1) {
|
||||||
Controller_Frontend.wakeUpFromSleep();
|
frontendController.wakeUpFromSleep();
|
||||||
if (globalFlag == 1) {
|
if (globalFlag == 1) {
|
||||||
DataRegister.clearBit(INTCON, GIE);
|
dataRegister.clearBit(INTCON, GIE);
|
||||||
Commands.CALL(ISR);
|
commands.CALL(ISR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void triggerRBInterrupt(int oldValue, int newValue) {
|
public void triggerRBInterrupt(int oldValue, int newValue) {
|
||||||
if (newValue != oldValue){
|
if (newValue != oldValue){
|
||||||
triggerInterrupt(RBIF, RBIE);
|
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){
|
if (newValue != oldValue){
|
||||||
int intedg = DataRegister.getDirectBit(OPTION, INTEDG);
|
int intedg = dataRegister.getDirectBit(OPTION, INTEDG);
|
||||||
if (intedg == 1) {
|
if (intedg == 1) {
|
||||||
if (oldValue == 0 && newValue == 1)
|
if (oldValue == 0 && newValue == 1)
|
||||||
triggerInterrupt(INTF, INTE);
|
triggerInterrupt(INTF, INTE);
|
||||||
@ -50,7 +65,7 @@ public class Interrupts {
|
|||||||
if (oldValue == 1 && newValue == 0)
|
if (oldValue == 1 && newValue == 0)
|
||||||
triggerInterrupt(INTF, INTE);
|
triggerInterrupt(INTF, INTE);
|
||||||
}
|
}
|
||||||
DataRegister.increasePC();
|
dataRegister.increasePC();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,42 +1,51 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
|
|
||||||
public class PreScaler {
|
public class PreScaler {
|
||||||
private static final int PSA = 0x3;
|
private final int PSA = 0x3;
|
||||||
private static final int OPTION = 0x81;
|
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 (){
|
public boolean isPrescalerOnTimer (){
|
||||||
return DataRegister.getDirectBit(OPTION, PSA) == 0;
|
return dataRegister.getDirectBit(OPTION, PSA) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static int getScaler() {
|
public int getScaler() {
|
||||||
return scaler;
|
return scaler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getFactor () {
|
public int getFactor () {
|
||||||
int scale = DataRegister.getDirectRegister(OPTION) & 0b111;
|
int scale = dataRegister.getDirectRegister(OPTION) & 0b111;
|
||||||
int timer = isPrescalerOnTimer() ? 1 : 0;
|
int timer = isPrescalerOnTimer() ? 1 : 0;
|
||||||
return (int) Math.pow (2, scale+timer);
|
return (int) Math.pow (2, scale+timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reset (){
|
public void reset (){
|
||||||
DataRegister.setDirectBit(OPTION, 0, 0);
|
dataRegister.setDirectBit(OPTION, 0, 0);
|
||||||
DataRegister.setDirectBit(OPTION, 1, 0);
|
dataRegister.setDirectBit(OPTION, 1, 0);
|
||||||
DataRegister.setDirectBit(OPTION, 2, 0);
|
dataRegister.setDirectBit(OPTION, 2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetFromRegister() {
|
public void resetFromRegister() {
|
||||||
scaler = getFactor();
|
scaler = getFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void decrement(boolean manual) {
|
public void decrement(boolean manual) {
|
||||||
scaler--;
|
scaler--;
|
||||||
if (scaler == 0) {
|
if (scaler == 0) {
|
||||||
scaler = getFactor();
|
scaler = getFactor();
|
||||||
Timer.increment(manual);
|
timer.increment(manual);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,15 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.ProgramStackInterface;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ProgramStack {
|
public class ProgramStack implements ProgramStackInterface {
|
||||||
private static List<Integer> returnStack = new ArrayList<>(8);
|
private List<Integer> returnStack = new ArrayList<>(8);
|
||||||
private static int stackIndex = 0;
|
private int stackIndex = 0;
|
||||||
|
|
||||||
private static void incIndex(){
|
private void incIndex(){
|
||||||
if (stackIndex == 7){
|
if (stackIndex == 7){
|
||||||
stackIndex = 0;
|
stackIndex = 0;
|
||||||
}
|
}
|
||||||
@ -16,7 +18,7 @@ public class ProgramStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void push(int value) {
|
public void push(int value) {
|
||||||
if ((returnStack.size() != 8 ) && (returnStack.size() <= stackIndex)){
|
if ((returnStack.size() != 8 ) && (returnStack.size() <= stackIndex)){
|
||||||
returnStack.add(value);
|
returnStack.add(value);
|
||||||
incIndex();
|
incIndex();
|
||||||
@ -27,21 +29,21 @@ public class ProgramStack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int pop() {
|
public int pop() {
|
||||||
stackIndex = (stackIndex > 0) ? --stackIndex : 7;
|
stackIndex = (stackIndex > 0) ? --stackIndex : 7;
|
||||||
return returnStack.get(stackIndex)-1;
|
return returnStack.get(stackIndex)-1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reset (){
|
public void reset (){
|
||||||
returnStack.clear();
|
returnStack.clear();
|
||||||
stackIndex = 0;
|
stackIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getStackPointer(){
|
public int getStackPointer(){
|
||||||
return stackIndex;
|
return stackIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Integer> getStack() {
|
public List<Integer> getStack() {
|
||||||
return returnStack;
|
return returnStack;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,12 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.CommandInterface;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.WindowManagement;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
|
||||||
import javafx.beans.property.SimpleStringProperty;
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
import javafx.geometry.Insets;
|
import javafx.geometry.Insets;
|
||||||
|
|
||||||
import javafx.scene.chart.PieChart;
|
|
||||||
import javafx.scene.control.Button;
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
@ -21,6 +24,22 @@ public class Table {
|
|||||||
//Hier wird die Tabelle aktualisiert
|
//Hier wird die Tabelle aktualisiert
|
||||||
//Tabelle aktualisieren
|
//Tabelle aktualisieren
|
||||||
|
|
||||||
|
private final WindowManagement createWindow;
|
||||||
|
private final DataRegisterInterface dataRegister;
|
||||||
|
private final CommandInterface command;
|
||||||
|
private final PreScaler preScaler;
|
||||||
|
private final IOPortInterface ioPorts;
|
||||||
|
|
||||||
|
|
||||||
|
public Table (DataRegisterInterface dataRegister, WindowManagement createWindow, CommandInterface command, PreScaler preScaler, IOPortInterface ioPorts){
|
||||||
|
|
||||||
|
this.dataRegister = dataRegister;
|
||||||
|
this.createWindow = createWindow;
|
||||||
|
this.command = command;
|
||||||
|
this.preScaler = preScaler;
|
||||||
|
this.ioPorts = ioPorts;
|
||||||
|
}
|
||||||
|
|
||||||
private static final int NUM_COLUMNS = 8; // Anzahl der Spalten
|
private static final int NUM_COLUMNS = 8; // Anzahl der Spalten
|
||||||
private static final double TABLE_WIDTH = 425; // Breite der TableView
|
private static final double TABLE_WIDTH = 425; // Breite der TableView
|
||||||
private static final double TABLE_HEIGHT = 600; // Höhe der TableView
|
private static final double TABLE_HEIGHT = 600; // Höhe der TableView
|
||||||
@ -42,7 +61,7 @@ public class Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static VBox refresh(){
|
public VBox refresh(){
|
||||||
// Erstelle eine Instanz der DataRegister-Klasse
|
// Erstelle eine Instanz der DataRegister-Klasse
|
||||||
|
|
||||||
|
|
||||||
@ -69,14 +88,14 @@ public class Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fülle die TableView mit Daten aus dem Array
|
// Fülle die TableView mit Daten aus dem Array
|
||||||
int numRows = (int) Math.ceil((double) DataRegister.getDataRegister().length / NUM_COLUMNS);
|
int numRows = (int) Math.ceil((double) dataRegister.getDataRegister().length / NUM_COLUMNS);
|
||||||
for (int row = 0; row < numRows; row++) {
|
for (int row = 0; row < numRows; row++) {
|
||||||
DataEntry[] rowData = new DataEntry[NUM_COLUMNS];
|
DataEntry[] rowData = new DataEntry[NUM_COLUMNS];
|
||||||
for (int col = 0; col < NUM_COLUMNS; col++) {
|
for (int col = 0; col < NUM_COLUMNS; col++) {
|
||||||
int index = row * NUM_COLUMNS + col;
|
int index = row * NUM_COLUMNS + col;
|
||||||
if (index < DataRegister.getDataRegister().length) {
|
if (index < dataRegister.getDataRegister().length) {
|
||||||
String address = "0x" + formatHex(Integer.toHexString(index).toUpperCase());
|
String address = "0x" + formatHex(Integer.toHexString(index).toUpperCase());
|
||||||
String value = "0x" + formatHex(Integer.toHexString(DataRegister.getDataRegister()[index]).toUpperCase());
|
String value = "0x" + formatHex(Integer.toHexString(dataRegister.getDataRegister()[index]).toUpperCase());
|
||||||
rowData[col] = new DataEntry(address, value);
|
rowData[col] = new DataEntry(address, value);
|
||||||
} else {
|
} else {
|
||||||
rowData[col] = new DataEntry("", "");
|
rowData[col] = new DataEntry("", "");
|
||||||
@ -89,17 +108,17 @@ public class Table {
|
|||||||
|
|
||||||
Label spacing = new Label(" ");
|
Label spacing = new Label(" ");
|
||||||
Label spacing2 = new Label(" ");
|
Label spacing2 = new Label(" ");
|
||||||
Label wRegisterLabel = new Label("W-Register: 0x" + formatHex(Integer.toHexString(Commands.get_wRegister()).toUpperCase()));
|
Label wRegisterLabel = new Label("W-Register: 0x" + formatHex(Integer.toHexString(command.get_wRegister()).toUpperCase()));
|
||||||
Label cLabel = new Label("Carry-Flag: " + DataRegister.getCarryFlag());
|
Label cLabel = new Label("Carry-Flag: " + dataRegister.getCarryFlag());
|
||||||
Label dcLabel = new Label("DigitCarry-Flag: " + DataRegister.getDigitCarryFlag());
|
Label dcLabel = new Label("DigitCarry-Flag: " + dataRegister.getDigitCarryFlag());
|
||||||
Label zLabel = new Label("Zero-Flag: " + DataRegister.getZeroFlag());
|
Label zLabel = new Label("Zero-Flag: " + dataRegister.getZeroFlag());
|
||||||
Label pcLabel = new Label("PC: 0x" + formatHex(Integer.toHexString(DataRegister.getPC()).toUpperCase()));
|
Label pcLabel = new Label("PC: 0x" + formatHex(Integer.toHexString(dataRegister.getPC()).toUpperCase()));
|
||||||
Label pclLabel = new Label("PCL: 0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getPCL())).toUpperCase()));
|
Label pclLabel = new Label("PCL: 0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getPCL())).toUpperCase()));
|
||||||
Label pclathLabel = new Label("PCLATH: 0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getPCLATH())).toUpperCase()));
|
Label pclathLabel = new Label("PCLATH: 0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getPCLATH())).toUpperCase()));
|
||||||
Label statusLabel = new Label("STATUS: 0b" + formatBin(Integer.toBinaryString(DataRegister.getRegister(DataRegister.getSTATUS())))+ " (0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getSTATUS())).toUpperCase()) + ")");
|
Label statusLabel = new Label("STATUS: 0b" + formatBin(Integer.toBinaryString(dataRegister.getRegister(dataRegister.getSTATUS())))+ " (0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getSTATUS())).toUpperCase()) + ")");
|
||||||
Label fsrLabel = new Label("FSR: 0x" + formatHex(Integer.toHexString(DataRegister.getFSR()).toUpperCase()));
|
Label fsrLabel = new Label("FSR: 0x" + formatHex(Integer.toHexString(dataRegister.getFSR()).toUpperCase()));
|
||||||
Label prescalerLabel = new Label("Prescaler: 0x" + formatHex(Integer.toHexString(PreScaler.getScaler())).toUpperCase());
|
Label prescalerLabel = new Label("Prescaler: 0x" + formatHex(Integer.toHexString(preScaler.getScaler())).toUpperCase());
|
||||||
Label intconLabel = new Label("INTCON: 0b" + formatBin(Integer.toBinaryString(DataRegister.getRegister(DataRegister.getINTCON()))) + " (0x" + formatHex(Integer.toHexString(DataRegister.getRegister(DataRegister.getINTCON())).toUpperCase()) + ")");
|
Label intconLabel = new Label("INTCON: 0b" + formatBin(Integer.toBinaryString(dataRegister.getRegister(dataRegister.getINTCON()))) + " (0x" + formatHex(Integer.toHexString(dataRegister.getRegister(dataRegister.getINTCON())).toUpperCase()) + ")");
|
||||||
wRegisterLabel.setStyle("-fx-font-weight: bold");
|
wRegisterLabel.setStyle("-fx-font-weight: bold");
|
||||||
pcLabel.setStyle("-fx-font-weight: bold");
|
pcLabel.setStyle("-fx-font-weight: bold");
|
||||||
statusLabel.setStyle("-fx-font-weight: bold");
|
statusLabel.setStyle("-fx-font-weight: bold");
|
||||||
@ -128,9 +147,9 @@ public class Table {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void triggerReset() {
|
private void triggerReset() {
|
||||||
DataRegister.initDataRegister();
|
dataRegister.initDataRegister();
|
||||||
IOPorts.refreshUI(Controller_Frontend.getTRISbuttons(), Controller_Frontend.getPORTbuttons());
|
ioPorts.refreshUI(Controller_Frontend.getTRISbuttons(), Controller_Frontend.getPORTbuttons());
|
||||||
CreateWindow.refreshTable();
|
CreateWindow.refreshTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +158,7 @@ public class Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hilfsklasse für die Datenanzeige in der TableView
|
// Hilfsklasse für die Datenanzeige in der TableView
|
||||||
public static class DataEntry {
|
public class DataEntry {
|
||||||
private final String address;
|
private final String address;
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,35 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
public class Timer {
|
import fabrik.simulator.pic16f84.interfaces.DataRegisterInterface;
|
||||||
private static final int TIMERREG = 0x1;
|
import fabrik.simulator.pic16f84.interfaces.FrontendControllerInterface;
|
||||||
private static final int T0SE = 0x4;
|
import fabrik.simulator.pic16f84.interfaces.InterruptInterface;
|
||||||
private static final int T0CS = 0x5;
|
import fabrik.simulator.pic16f84.interfaces.TimerInterface;
|
||||||
private static final int OPTION = 0x81;
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
public static void cycles(int cycles){
|
private final DataRegisterInterface dataRegister;
|
||||||
if (DataRegister.getDirectBit(OPTION, T0CS) == 0){
|
private final InterruptInterface interrupts;
|
||||||
if (PreScaler.isPrescalerOnTimer()){
|
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 void cycles(int cycles){
|
||||||
|
if (dataRegister.getDirectBit(OPTION, T0CS) == 0){
|
||||||
|
if (preScaler.isPrescalerOnTimer()){
|
||||||
for (int i = 0; i < cycles; i++){
|
for (int i = 0; i < cycles; i++){
|
||||||
PreScaler.decrement(false);
|
preScaler.decrement(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
increment(false);
|
increment(false);
|
||||||
@ -22,23 +38,23 @@ public class Timer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void incrementFromPin (int register){
|
public void incrementFromPin (int register){
|
||||||
if ((DataRegister.getDirectBit(OPTION, T0CS) == 1) && !Controller_Frontend.isSleeping()){
|
if ((dataRegister.getDirectBit(OPTION, T0CS) == 1) && !frontendController.isSleeping()){
|
||||||
int newpin = (register >> 4) & 1;
|
int newpin = (register >> 4) & 1;
|
||||||
if (newpin != oldpin) {
|
if (newpin != oldpin) {
|
||||||
if (DataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
if (dataRegister.getDirectBit(OPTION, T0SE) == 0) {
|
||||||
// Low to high
|
// Low to high
|
||||||
if (newpin == 1 && oldpin == 0) {
|
if (newpin == 1 && oldpin == 0) {
|
||||||
if (PreScaler.isPrescalerOnTimer())
|
if (preScaler.isPrescalerOnTimer())
|
||||||
PreScaler.decrement(true);
|
preScaler.decrement(true);
|
||||||
else
|
else
|
||||||
increment(true);
|
increment(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// High to low
|
// High to low
|
||||||
if (newpin == 0 && oldpin == 1) {
|
if (newpin == 0 && oldpin == 1) {
|
||||||
if (PreScaler.isPrescalerOnTimer())
|
if (preScaler.isPrescalerOnTimer())
|
||||||
PreScaler.decrement(true);
|
preScaler.decrement(true);
|
||||||
else
|
else
|
||||||
increment(true);
|
increment(true);
|
||||||
}
|
}
|
||||||
@ -48,14 +64,14 @@ public class Timer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void increment(boolean manual) {
|
public void increment(boolean manual) {
|
||||||
int timer = DataRegister.getDirectRegister(TIMERREG);
|
int timer = dataRegister.getDirectRegister(TIMERREG);
|
||||||
timer++;
|
timer++;
|
||||||
if (timer > 0xFF){
|
if (timer > 0xFF){
|
||||||
Interrupts.triggerTMR0(manual);
|
interrupts.triggerTMR0(manual);
|
||||||
DataRegister.setDirectRegister(TIMERREG, 0);
|
dataRegister.setDirectRegister(TIMERREG, 0);
|
||||||
} else {
|
} else {
|
||||||
DataRegister.setDirectRegister(1, timer);
|
dataRegister.setDirectRegister(1, timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||||
|
import fabrik.simulator.pic16f84.interfaces.IOPortInterface;
|
||||||
import javafx.collections.ListChangeListener;
|
import javafx.collections.ListChangeListener;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import javafx.scene.control.Toggle;
|
import javafx.scene.control.Toggle;
|
||||||
@ -10,14 +11,18 @@ import javafx.scene.input.MouseEvent;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class ToggleButtonGroupExt {
|
public class ToggleButtonGroupExt {
|
||||||
|
|
||||||
|
private IOPortInterface ioPorts;
|
||||||
|
|
||||||
private static ToggleButtonGroupExt me;
|
private static ToggleButtonGroupExt me;
|
||||||
|
|
||||||
private ToggleButtonGroupExt() {
|
public ToggleButtonGroupExt(IOPortInterface ioPorts) {
|
||||||
|
this.ioPorts = ioPorts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ToggleButtonGroupExt get() {
|
public static ToggleButtonGroupExt get(IOPortInterface ioPorts) {
|
||||||
if (me == null) {
|
if (me == null) {
|
||||||
me = new ToggleButtonGroupExt();
|
me = new ToggleButtonGroupExt(ioPorts);
|
||||||
}
|
}
|
||||||
return me;
|
return me;
|
||||||
}
|
}
|
||||||
@ -45,14 +50,14 @@ public class ToggleButtonGroupExt {
|
|||||||
ToggleButtonGroup parent = (ToggleButtonGroup) ((ToggleButton) mouseEvent.getSource()).getParent();
|
ToggleButtonGroup parent = (ToggleButtonGroup) ((ToggleButton) mouseEvent.getSource()).getParent();
|
||||||
if (parent.getId().contains("TRIS")) {
|
if (parent.getId().contains("TRIS")) {
|
||||||
try {
|
try {
|
||||||
IOPorts.setTRISfromUI(parent);
|
ioPorts.setTRISfromUI(parent);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
IOPorts.setPORTfromUI(parent);
|
ioPorts.setPORTfromUI(parent);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,49 +1,69 @@
|
|||||||
package fabrik.simulator.pic16f84;
|
package fabrik.simulator.pic16f84;
|
||||||
|
|
||||||
public class WatchdogTimer {
|
import fabrik.simulator.pic16f84.interfaces.*;
|
||||||
private static long watchdogTime;
|
|
||||||
private static long lastReset = 0;
|
public class WatchdogTimer implements WatchdogTimerInterface {
|
||||||
private static boolean enabled = false;
|
private long watchdogTime;
|
||||||
private static long rawtimer = 0;
|
private double lastReset = 0;
|
||||||
private static long realtimer = 0;
|
private boolean enabled = false;
|
||||||
|
private long rawtimer = 0;
|
||||||
|
private long realtimer = 0;
|
||||||
|
|
||||||
|
|
||||||
|
private final DataRegisterInterface dataRegister;
|
||||||
|
private final ProgramStackInterface programStack;
|
||||||
|
private final FrontendControllerInterface frontendController;
|
||||||
|
private final PreScaler preScaler;
|
||||||
|
private final CommandInterface command;
|
||||||
|
|
||||||
|
|
||||||
|
public WatchdogTimer( DataRegisterInterface dataRegister, ProgramStackInterface programStack, FrontendControllerInterface frontendController,PreScaler preScaler, CommandInterface command){
|
||||||
|
|
||||||
|
this.dataRegister = dataRegister;
|
||||||
|
this.programStack = programStack;
|
||||||
|
this.preScaler = preScaler;
|
||||||
|
this.command = command;
|
||||||
|
this.frontendController = frontendController;
|
||||||
|
|
||||||
private static long getTimeFromRegister() {
|
|
||||||
return (PreScaler.isPrescalerOnTimer()) ? 18L : PreScaler.getFactor() * 18L;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void testAndTrigger() {
|
private long getTimeFromRegister() {
|
||||||
|
return (preScaler.isPrescalerOnTimer()) ? 18L : preScaler.getFactor() * 18L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAndTrigger() {
|
||||||
watchdogTime = getTimeFromRegister() * 1000;
|
watchdogTime = getTimeFromRegister() * 1000;
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (realtimer >= (watchdogTime + lastReset - 1)) {
|
if (realtimer >= (watchdogTime + lastReset - 1)) {
|
||||||
DataRegister.clearBit(3, 4);
|
dataRegister.clearBit(3, 4);
|
||||||
lastReset = Commands.getTotalExecutionTime();
|
lastReset = command.getTotalExecutionTime();
|
||||||
Controller_Frontend.stopRunFromBackend("Watchdog Timer");
|
frontendController.stopRunFromBackend("Watchdog Timer");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rawtimer++;
|
rawtimer++;
|
||||||
realtimer = (long) (rawtimer * Controller_Frontend.getExecutionTimeMultiplier());
|
realtimer = (long) (rawtimer * frontendController.getExecutionTimeMultiplier());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reset (){
|
public void reset (){
|
||||||
lastReset = Commands.getTotalExecutionTime();
|
lastReset = command.getTotalExecutionTime();
|
||||||
rawtimer = 0;
|
rawtimer = 0;
|
||||||
realtimer = 0;
|
realtimer = 0;
|
||||||
PreScaler.reset();
|
preScaler.reset();
|
||||||
DataRegister.setBit(3, 3);
|
dataRegister.setBit(3, 3);
|
||||||
DataRegister.setBit(3, 4);
|
dataRegister.setBit(3, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void enable() {
|
public void enable() {
|
||||||
enabled = true;
|
enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disable() {
|
public void disable() {
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long get (){
|
public long get (){
|
||||||
return realtimer;
|
return realtimer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,13 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface CommandInterface {
|
||||||
|
void CALL(int isr);
|
||||||
|
|
||||||
|
double getTotalExecutionTime();
|
||||||
|
|
||||||
|
int get_wRegister();
|
||||||
|
|
||||||
|
void decode(int i);
|
||||||
|
|
||||||
|
void resetTotalExecutionTime();
|
||||||
|
}
|
||||||
@ -0,0 +1,59 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface DataRegisterInterface {
|
||||||
|
void clearBit(int f, int b);
|
||||||
|
|
||||||
|
void setBit(int f, int b);
|
||||||
|
|
||||||
|
void setPC(int pop);
|
||||||
|
|
||||||
|
int getINTCON();
|
||||||
|
|
||||||
|
int getPC();
|
||||||
|
|
||||||
|
void setRegister(int file, int wRegister);
|
||||||
|
|
||||||
|
void determineZeroFlag(int wRegister);
|
||||||
|
|
||||||
|
int getRegister(int file);
|
||||||
|
|
||||||
|
void setCarryFlag(int i);
|
||||||
|
|
||||||
|
void setDigitCarryFlag(int i);
|
||||||
|
|
||||||
|
int getCarryFlag();
|
||||||
|
|
||||||
|
void determineCarryFlag(int result);
|
||||||
|
|
||||||
|
void increasePC();
|
||||||
|
|
||||||
|
void determineDigitCarryFlag(int i);
|
||||||
|
|
||||||
|
int getBit(int address, int bit);
|
||||||
|
|
||||||
|
int getDirectBit(int option, int psa);
|
||||||
|
|
||||||
|
int getDirectRegister(int option);
|
||||||
|
|
||||||
|
void setDirectBit(int option, int i, int i1);
|
||||||
|
|
||||||
|
void setDirectRegister(int porta, int i);
|
||||||
|
|
||||||
|
void resetPC();
|
||||||
|
|
||||||
|
int[] getDataRegister();
|
||||||
|
|
||||||
|
int getDigitCarryFlag();
|
||||||
|
|
||||||
|
int getZeroFlag();
|
||||||
|
|
||||||
|
int getFSR();
|
||||||
|
|
||||||
|
void initDataRegister();
|
||||||
|
|
||||||
|
int getPCL();
|
||||||
|
|
||||||
|
int getPCLATH();
|
||||||
|
|
||||||
|
int getSTATUS();
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface EEPROMInterface {
|
||||||
|
void registerTime(boolean b);
|
||||||
|
|
||||||
|
void parse(int i, int content, int i1);
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface FrontendControllerInterface {
|
||||||
|
double getExecutionTimeMultiplier();
|
||||||
|
|
||||||
|
void sleep();
|
||||||
|
|
||||||
|
void wakeUpFromSleep();
|
||||||
|
|
||||||
|
boolean isSleeping();
|
||||||
|
|
||||||
|
void stopRunFromBackend(String watchdogTimer);
|
||||||
|
}
|
||||||
@ -0,0 +1,28 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
import com.gluonhq.charm.glisten.control.ToggleButtonGroup;
|
||||||
|
import javafx.scene.shape.Circle;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface IOPortInterface {
|
||||||
|
void resetTRIS();
|
||||||
|
|
||||||
|
void setRegister(int i, int content);
|
||||||
|
|
||||||
|
void clearBit(int i, int bit);
|
||||||
|
|
||||||
|
void setBit(int i, int bit);
|
||||||
|
|
||||||
|
void setPORTfromUI(ToggleButtonGroup parent) throws IOException;
|
||||||
|
|
||||||
|
void setTRISfromUI(ToggleButtonGroup parent) throws IOException;
|
||||||
|
|
||||||
|
void refreshUI(ToggleButtonGroup[] triSbuttons, ToggleButtonGroup[] porTbuttons);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void setLEDs(Circle[] allLEDsA, Circle[] allLEDsB);
|
||||||
|
|
||||||
|
void setLEDs(boolean[] booleans);
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface InterruptInterface {
|
||||||
|
void triggerRBInterrupt(int oldValue, int value);
|
||||||
|
|
||||||
|
void triggerRB0Interrupt(int oldValue, int value);
|
||||||
|
|
||||||
|
void triggerTMR0(boolean manual);
|
||||||
|
}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ProgramStackInterface {
|
||||||
|
int pop();
|
||||||
|
|
||||||
|
void push(int i);
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
int getStackPointer();
|
||||||
|
|
||||||
|
List<Integer> getStack();
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface TableInterface {
|
||||||
|
void refresh();
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface TimerInterface {
|
||||||
|
public void cycles(int i);
|
||||||
|
|
||||||
|
void incrementFromPin(int directRegister);
|
||||||
|
|
||||||
|
void increment(boolean manual);
|
||||||
|
}
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
import fabrik.simulator.pic16f84.ToggleButtonGroupExt;
|
||||||
|
|
||||||
|
public interface ToggleButtonInterface {
|
||||||
|
ToggleButtonGroupExt get();
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface WatchdogTimerInterface {
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
void testAndTrigger();
|
||||||
|
|
||||||
|
void enable();
|
||||||
|
|
||||||
|
void disable();
|
||||||
|
|
||||||
|
long get();
|
||||||
|
}
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
package fabrik.simulator.pic16f84.interfaces;
|
||||||
|
|
||||||
|
public interface WindowManagement {
|
||||||
|
void refreshTable();
|
||||||
|
}
|
||||||
@ -12,4 +12,6 @@ module fabrik.simulator.pic16f84 {
|
|||||||
|
|
||||||
opens fabrik.simulator.pic16f84 to javafx.fxml;
|
opens fabrik.simulator.pic16f84 to javafx.fxml;
|
||||||
exports fabrik.simulator.pic16f84;
|
exports fabrik.simulator.pic16f84;
|
||||||
|
exports fabrik.simulator.pic16f84.interfaces;
|
||||||
|
opens fabrik.simulator.pic16f84.interfaces to javafx.fxml;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user