Compare commits

..

1 Commits

Author SHA1 Message Date
Darkress
2f8adb70c4 implemented Rlf Instruction 2023-06-06 01:09:16 +02:00
5 changed files with 13 additions and 94 deletions

View File

@@ -12,9 +12,9 @@ class Main
public static void main(String[] args) {
ArrayList<Command> program = new ArrayList<>();
Memory.workingRegister = 0x01;
Memory.setRegister(0x14, 0x01); //240 << 224
program.add(CommandDecoder.decode(0x0294));
Memory.clearCarryBit();
Memory.setRegister(0x14, 0B11110000); //240 << 224
program.add(CommandDecoder.decode(0x0D94));
for(int i = 0; i < program.size(); i++)
{
program.get(ProgramCounter.getPc()).execute();

View File

@@ -18,14 +18,15 @@ public class Rlf extends FileRegisterCommandUtils implements Command
public void execute()
{
int register = Memory.getRegister(address);
int newCarry = register >>7;
int oldCarry = Memory.getCarryBit();
register = ((register <<1) + oldCarry) & 0xFF;
int carry = Memory.getCarryBit();
int tmp = carry;
carry = register >>7;
register = ((register <<1) + tmp) & 0xFF;
if(newCarry == 1)
if(carry == 1)
{
Memory.setCarryBit();
} else if(newCarry == 0){
} else if(carry == 0){
Memory.clearCarryBit();
}

View File

@@ -1,35 +0,0 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Rrf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Rrf(int input)
{
address = input & 0x007F;
destinationBit = checkDestinationBit(input);
}
@Override
public void execute()
{
int register = Memory.getRegister(address);
int newCarry = register & 0x01;
int oldCarry = Memory.getCarryBit();
register = (oldCarry << 7) + (register >>1);
if(newCarry == 1)
{
Memory.setCarryBit();
} else if(newCarry == 0){
Memory.clearCarryBit();
}
writeToDestination(destinationBit, address, register);
ProgramCounter.incPC();
}
}

View File

@@ -1,49 +0,0 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Subwf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Subwf(int input)
{
address = input & 0x007F;
destinationBit = checkDestinationBit(input);
}
@Override
protected void checkCarryBit(int result)
{
if(result <= 255){
Memory.clearCarryBit();
} else{
Memory.setCarryBit();
}
}
@Override
protected void checkDigitCarryBit(int literal)
{
if(((literal & 0x0F) - (Memory.workingRegister & 0x0F)) < 0){
Memory.clearDigitCarryBit();
} else{
Memory.setDigitCarryBit();
}
}
@Override
public void execute()
{
int result = Memory.getRegister(address) - Memory.workingRegister + 256;
checkZeroBit(result);
checkCarryBit(result);
checkDigitCarryBit(Memory.getRegister(address));
writeToDestination(destinationBit, address, result % 256);
ProgramCounter.incPC();
}
}

View File

@@ -29,9 +29,11 @@ public class CommandDecoder
case 0xD00:
return new Rlf(input);
case 0xC00:
return new Rrf(input);
//rrf();
break;
case 0x200:
return new Subwf(input);
//subwf();
break;
case 0xE00:
//swapf();
break;