Working PC
This commit is contained in:
@ -3,25 +3,27 @@ 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 int [] dataRegister = new int[0xFF];
|
||||
|
||||
private static final int [] dataRegister = new int[0xFF];
|
||||
|
||||
public static void initDataRegister() {
|
||||
dataRegister[0x2] = 0b0;
|
||||
dataRegister[0x3] = 0b00011000;
|
||||
dataRegister[PCL] = 0b0;
|
||||
dataRegister[STATUS] = 0b00011000;
|
||||
dataRegister[0xA] = 0b0;
|
||||
dataRegister[0xB] = 0b0;
|
||||
|
||||
dataRegister[0x81] = 0b11111111;
|
||||
dataRegister[0x82] = 0b0;
|
||||
dataRegister[0x83] = 0b00011000;
|
||||
dataRegister[0x85] = 0b11111000;
|
||||
dataRegister[0x86] = 0b11111111;
|
||||
dataRegister[0x88] = 0b0;
|
||||
dataRegister[0x8A] = 0b0;
|
||||
dataRegister[0x8B] = 0b0;
|
||||
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));
|
||||
}
|
||||
|
||||
@ -29,8 +31,55 @@ public class DataRegister {
|
||||
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[address] >> bit) & 1;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user