TRIS/DATA-Latch

This commit is contained in:
2024-04-29 16:59:15 +02:00
parent b4f49dbb97
commit 3c406378b2
2 changed files with 94 additions and 1 deletions

View File

@ -7,6 +7,8 @@ public class DataRegister {
private static final int PCL = 0x2;
private static final int STATUS = 0x3;
private static final int FSR = 0x4;
private static final int PORTA = 0x5;
private static final int PORTB = 0x6;
private static final int PCLATH = 0xA;
private static final int INTCON = 0xB;
@ -21,6 +23,7 @@ public class DataRegister {
private static final int [] dataRegister = new int[0xFF];
private static final int [] syncedRegisters = {INDF, PCL, STATUS, FSR, PCLATH, INTCON};
public static final int [] ioRegisters = {PORTA, PORTB, TRISA, TRISB};
public static void initDataRegister() {
dataRegister[PCL] = 0b0;
@ -74,6 +77,10 @@ public class DataRegister {
public static void setRegister(int fileAddress, int content){
int address = determineIndirectAndChange (fileAddress);
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
IOPorts.setRegister(address, content);
return;
}
if (fileAddress == PCL || fileAddress == 0x80 + PCL){
programCounter = content + (dataRegister[PCLATH] << 8);
}
@ -90,12 +97,16 @@ public class DataRegister {
return (dataRegister[bank() + address] >> bit) & 1;
}
private static int getDirectBit(int address, int bit){
public static int getDirectBit(int address, int bit){
return (dataRegister[address] >> bit) & 1;
}
public static void clearBit(int fileAddress, int bit) {
int address = determineIndirectAndChange (fileAddress);
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
IOPorts.clearBit(address, bit);
return;
}
if (!isSyncedRegister(address)) {
if (getBit(address, bit) == 1) {
dataRegister[bank() + address] -= (int) Math.pow(2, bit);
@ -111,6 +122,10 @@ public class DataRegister {
public static void setBit(int fileAddress, int bit) {
int address = determineIndirectAndChange (fileAddress);
if (Arrays.stream(ioRegisters).anyMatch(i -> i == address)){
IOPorts.setBit(address, bit);
return;
}
if (!isSyncedRegister(address)) {
if (getBit(address, bit) == 0) {
dataRegister[bank() + address] += (int) Math.pow(2, bit);
@ -231,4 +246,28 @@ public class DataRegister {
return digitCarryFlag;
}
public static void setDirectRegister(int fileAddress, int content) {
dataRegister[fileAddress] = content;
}
public static int getPCL() {
return PCL;
}
public static int getSTATUS() {
return STATUS;
}
public static int getPCLATH() {
return PCLATH;
}
public static int getINTCON() {
return INTCON;
}
public static int getDirectRegister(int address) {
return dataRegister[address];
}
}