86 lines
2.3 KiB
Java
86 lines
2.3 KiB
Java
package fabrik.simulator.pic16f84;
|
|
|
|
import java.util.Arrays;
|
|
|
|
public class DataRegister {
|
|
public static final int STATUS = 0x3;
|
|
public static final int TRISA = 0x85;
|
|
public static final int TRISB = 0x86;
|
|
public static final int PCL = 0x2;
|
|
public static final int RP0 = 0x5;
|
|
|
|
private static final int [] dataRegister = new int[0xFF];
|
|
|
|
public static void initDataRegister() {
|
|
dataRegister[PCL] = 0b0;
|
|
dataRegister[STATUS] = 0b00011000;
|
|
dataRegister[0xA] = 0b0;
|
|
dataRegister[0xB] = 0b0;
|
|
|
|
dataRegister[0x81] = 0b11111111;
|
|
dataRegister[0x82] = dataRegister[PCL];
|
|
dataRegister[0x83] = dataRegister[STATUS];
|
|
dataRegister[TRISA] = 0b11111000;
|
|
dataRegister[TRISB] = 0b11111111;
|
|
dataRegister[0x8A] = dataRegister[0xA];
|
|
dataRegister[0x8B] = dataRegister[0xB];
|
|
System.out.println(Arrays.toString(dataRegister));
|
|
}
|
|
|
|
public static int[] getDataRegister() {
|
|
return dataRegister;
|
|
}
|
|
|
|
private static int bank() {
|
|
return ((dataRegister[STATUS] >> RP0) & 1) * 0x80;
|
|
}
|
|
|
|
public static int getRegister(int fileAddress){
|
|
return dataRegister[bank() + fileAddress];
|
|
}
|
|
|
|
public static void setRegister(int fileAddress, int content){
|
|
dataRegister[bank() + fileAddress] = content;
|
|
}
|
|
|
|
public static int getBit(int address, int bit) {
|
|
return (dataRegister[bank() + address] >> bit) & 1;
|
|
}
|
|
|
|
public static void clearBit(int address, int bit) {
|
|
dataRegister[bank() + address] -= (int) Math.pow(2, bit);
|
|
}
|
|
|
|
public static void setBit(int address, int bit) {
|
|
dataRegister[bank() + address] += (int) Math.pow(2, bit);
|
|
}
|
|
|
|
private static int programCounter = 0;
|
|
|
|
private static void writeToPCL(){
|
|
dataRegister[PCL] = programCounter;
|
|
dataRegister[0x82] = dataRegister[PCL];
|
|
}
|
|
|
|
public static void increasePC (){
|
|
programCounter = getRegister(PCL);
|
|
if (programCounter != 0x3FF) {
|
|
programCounter++;
|
|
}
|
|
else {
|
|
programCounter = 0;
|
|
}
|
|
writeToPCL();
|
|
}
|
|
|
|
public static void setPC (int value){
|
|
programCounter = value;
|
|
writeToPCL();
|
|
}
|
|
|
|
public static int getPC(){
|
|
return programCounter;
|
|
}
|
|
|
|
}
|