Working PC

This commit is contained in:
2024-04-21 13:10:02 +02:00
parent c2f5c3a81a
commit 7be45ed266
3 changed files with 404 additions and 97 deletions

View File

@ -1,8 +1,10 @@
package fabrik.simulator.pic16f84;
public class Commands {
public static void execute(){
;
private static int wRegister = 0;
public static int get_wRegister() {
return wRegister;
}
public static void decode(int instruction){
@ -12,79 +14,20 @@ public class Commands {
int bitaddr = 0x380;
int destinationbit = 0x80;
int d = (instruction & destinationbit) >> 7;
int f = instruction & fileregaddr;
int k = instruction & constant;
int b = (instruction & bitaddr) >> 7;
int j = instruction & jumpaddr;
switch (instruction & 0x3800){
case 0b10000000000000:
System.out.println("CALL");
System.out.println("CALL: " + j);
CALL (j);
return;
case 0b10100000000000:
System.out.println("GOTO");
return;
default:
break;
}
switch (instruction & 0x3F00){
case 0b00011100000000:
System.out.println("ADDWF");
return;
case 0b00010100000000:
System.out.println("ANDWF");
return;
case 0b00100100000000:
System.out.println("COMF");
return;
case 0b00001100000000:
System.out.println("DECF");
return;
case 0b00101100000000:
System.out.println("DECFSZ");
return;
case 0b00101000000000:
System.out.println("INCF");
return;
case 0b00111100000000:
System.out.println("INCFSZ");
return;
case 0b00010000000000:
System.out.println("IORWF");
return;
case 0b00100000000000:
System.out.println("MOVF");
return;
case 0b00110100000000:
System.out.println("RLF");
return;
case 0b00001000000000:
System.out.println("SUBWF");
return;
case 0b00111000000000:
System.out.println("SWAPF");
return;
case 0b00011000000000:
System.out.println("XORWF");
return;
case 0b11100100000000:
System.out.println("ANDLW");
return;
case 0b11101000000000:
System.out.println("XORLW");
return;
case 0b11100000000000:
System.out.println("IORLW");
return;
default:
break;
}
switch (instruction & 0x3F80){
case 0b00000110000000:
System.out.println("CLRF");
return;
case 0b00000100000000:
System.out.println("CLRW");
return;
case 0b00000010000000:
System.out.println("MOVWF");
System.out.println("GOTO: " + j);
GOTO (j);
return;
default:
break;
@ -92,22 +35,28 @@ public class Commands {
switch (instruction & 0x3C00){
case 0b01000000000000:
System.out.println("BCF");
System.out.println("BCF: " + f + " " + b);
DataRegister.clearBit(f, b);
return;
case 0b01010000000000:
System.out.println("BSF");
System.out.println("BSF: " + f + " " + b);
DataRegister.clearBit(f, b);
return;
case 0b01100000000000:
System.out.println("BTFSC");
System.out.println("BTFSC: " + f + " " + b);
BTFSC(f, b);
return;
case 0b01110000000000:
System.out.println("BTFSS");
System.out.println("BTFSS: " + f + " " + b);
BTFSS(f, b);
return;
case 0b11000000000000:
System.out.println("MOVLW");
System.out.println("MOVLW: " + k);
MOVLW (k);
return;
case 0b11010000000000:
System.out.println("RETLW");
System.out.println("RETLW: " + k);
RETLW (k);
return;
default:
break;
@ -115,10 +64,98 @@ public class Commands {
switch (instruction & 0x3E00){
case 0b11111000000000:
System.out.println("ADDLW");
System.out.println("ADDLW: " + k);
ADDLW (k);
return;
case 0b11110000000000:
System.out.println("SUBLW");
System.out.println("SUBLW: " + k);
SUBLW (k);
return;
default:
break;
}
switch (instruction & 0x3F00){
case 0b00011100000000:
System.out.println("ADDWF: " + f + " " + d);
ADDWF (f, d);
return;
case 0b00010100000000:
System.out.println("ANDWF: " + f + " " + d);
ANDWF (f, d);
return;
case 0b00100100000000:
System.out.println("COMF: " + f + " " + d);
COMF (f, d);
return;
case 0b00001100000000:
System.out.println("DECF: " + f + " " + d);
DECF (f, d);
return;
case 0b00101100000000:
System.out.println("DECFSZ: " + f + " " + d);
DECFSZ (f, d);
return;
case 0b00101000000000:
System.out.println("INCF: " + f + " " + d);
INCF (f, d);
return;
case 0b00111100000000:
System.out.println("INCFSZ: " + f + " " + d);
INCFSZ (f, d);
return;
case 0b00010000000000:
System.out.println("IORWF: " + f + " " + d);
IORWF (f, d);
return;
case 0b00100000000000:
System.out.println("MOVF: " + f + " " + d);
MOVF (f, d);
return;
case 0b00110100000000:
System.out.println("RLF: " + f + " " + d);
RLF (f, d);
return;
case 0b00001000000000:
System.out.println("SUBWF: " + f + " " + d);
SUBWF (f, d);
return;
case 0b00111000000000:
System.out.println("SWAPF: " + f + " " + d);
SWAPF (f, d);
return;
case 0b00011000000000:
System.out.println("XORWF: " + f + " " + d);
XORWF (f, d);
return;
case 0b11100100000000:
System.out.println("ANDLW: " + k);
ANDLW (k);
return;
case 0b11101000000000:
System.out.println("XORLW: " + k);
XORLW (k);
return;
case 0b11100000000000:
System.out.println("IORLW: " + k);
IORLW (k);
return;
default:
break;
}
switch (instruction & 0x3F80){
case 0b00000110000000:
System.out.println("CLRF: " + f);
CLRF (f);
return;
case 0b00000100000000:
System.out.println("CLRW");
CLRW ();
return;
case 0b00000010000000:
System.out.println("MOVWF: " + f);
MOVWF (f);
return;
default:
break;
@ -127,15 +164,19 @@ public class Commands {
switch (instruction){
case 0b01100100:
System.out.println("CLRWDT");
//TODO
return;
case 0b1001:
System.out.println("RETFIE");
//TODO
return;
case 0b1000:
System.out.println("RETURN");
//TODO
return;
case 0b01100011:
System.out.println("SLEEP");
//TODO
return;
default:
break;
@ -147,5 +188,215 @@ public class Commands {
else{
System.out.println("Nicht gefunden!");
}
}
public static void GOTO(int jump) {
DataRegister.setPC(jump-1);
}
public static void CALL(int jump) {
//TODO
}
public static void MOVWF(int file) {
DataRegister.setRegister(file, wRegister);
}
public static void CLRW() {
wRegister = 0;
//TODO: Zeroflag
}
public static void CLRF(int file) {
DataRegister.setRegister(file, 0);
//TODO: Zeroflag
}
public static void IORLW(int literal) {
wRegister |= literal;
//TODO: Zeroflag
}
public static void XORLW(int literal) {
wRegister ^= literal;
//TODO: Zeroflag
}
public static void ANDLW(int literal) {
wRegister &= literal;
//TODO: Zeroflag
}
public static void XORWF(int file, int destination) {
int result = wRegister ^ DataRegister.getRegister(file);
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
//TODO: Zeroflag
}
public static void SWAPF(int file, int destination) {
int content = DataRegister.getRegister(file);
int result = (content & 0x0F) << 4 | (content & 0xF0) >> 4;
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
}
public static void SUBWF(int file, int destination) {
int result = (DataRegister.getRegister(file) - wRegister) & 0xFF;
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
// TODO Zeroflag, Carry, DigitCarry
}
public static void RLF(int file, int destination) {
// TODO
}
public static void MOVF(int file, int destination) {
int content = DataRegister.getRegister(file);
if (destination == 0){
wRegister = content;
}
else {
DataRegister.setRegister(file, content);
}
// TODO: Zeroflag
}
public static void IORWF(int file, int destination) {
int result = wRegister | DataRegister.getRegister(file);
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
// TODO: Zeroflag
}
public static void INCFSZ(int file, int destination) {
int result = (DataRegister.getRegister(file) + 1) & 0xFF;
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
if (result == 0) {
DataRegister.increasePC();
}
}
public static void INCF(int file, int destination) {
int result = (DataRegister.getRegister(file) + 1) & 0xFF;
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
//TODO: Zeroflag
}
public static void DECFSZ(int file, int destination) {
int result = (DataRegister.getRegister(file) -1) & 0xFF;
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
if (result == 0){
DataRegister.increasePC();
}
}
public static void DECF(int file, int destination) {
int result = (DataRegister.getRegister(file) -1) & 0xFF;
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
// TODO: Zeroflag
}
private static void COMF(int file, int destination) {
int result = (~ DataRegister.getRegister(file)) & 0xFF;
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
// TODO: Zeroflag
}
public static void ANDWF(int file, int destination) {
int result = wRegister & DataRegister.getRegister(file);
if (destination == 0){
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
// TODO: Zeroflag, Carry, DigitCarry
}
public static void ADDWF(int file, int destination) {
int result = wRegister + DataRegister.getRegister(file);
if (destination == 0) {
wRegister = result;
}
else {
DataRegister.setRegister(file, result);
}
// TODO: Zeroflag, Carry, DigitCarry
}
public static void SUBLW(int literal) {
wRegister = literal - wRegister;
// TODO: Zeroflag, Carry, DigitCarry
}
public static void ADDLW(int literal) {
wRegister += literal;
// TODO: Zeroflag, Carry, DigitCarry
}
public static void RETLW(int literal) {
wRegister = literal;
//TODO: PC vom Stack holen und laden
}
public static void MOVLW(int literal) {
wRegister = literal;
}
public static void BTFSC(int address, int bit) {
if (DataRegister.getBit(address, bit) == 0){
DataRegister.increasePC();
}
}
public static void BTFSS(int address, int bit) {
if (DataRegister.getBit(address, bit) == 1){
DataRegister.increasePC();
}
}
}