Compare commits
5 Commits
comfInstru
...
decfszInst
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89f4845df6 | ||
|
|
e18ec6d167 | ||
|
|
46515de5f1 | ||
|
|
49ab5876b8 | ||
|
|
1f8e3aff58 |
@@ -14,9 +14,12 @@ class Main
|
|||||||
ArrayList<Command> program = new ArrayList<>();
|
ArrayList<Command> program = new ArrayList<>();
|
||||||
int input1 = 0x27FF;
|
int input1 = 0x27FF;
|
||||||
program.add(CommandDecoder.decode(0x3011)); //Write 0x11 to W
|
program.add(CommandDecoder.decode(0x3011)); //Write 0x11 to W
|
||||||
Memory.setRegister(0x14, 0x14);
|
Memory.setRegister(0x14, 0x01);
|
||||||
program.add(CommandDecoder.decode(0x0594));
|
program.add(CommandDecoder.decode(0x0B94));
|
||||||
for(int i = 0; i < 2; i++)
|
program.add(CommandDecoder.decode(0x0B94));
|
||||||
|
program.add(CommandDecoder.decode(0x0B94));
|
||||||
|
program.add(CommandDecoder.decode(0x3F05));
|
||||||
|
for(int i = 0; i < program.size(); i++)
|
||||||
{
|
{
|
||||||
program.get(ProgramCounter.getPc()).execute();
|
program.get(ProgramCounter.getPc()).execute();
|
||||||
}
|
}
|
||||||
|
|||||||
27
de/darkress/pic16f84sim/commands/Comf.java
Normal file
27
de/darkress/pic16f84sim/commands/Comf.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
|
public class Comf extends FileRegisterCommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int address;
|
||||||
|
private final boolean destinationBit;
|
||||||
|
|
||||||
|
public Comf(int input)
|
||||||
|
{
|
||||||
|
address = input & 0x007F;
|
||||||
|
destinationBit = checkDestinationBit(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
int result = 255 - Memory.getRegister(address); // Get inverse of 8Bit value
|
||||||
|
|
||||||
|
checkZeroBit(result);
|
||||||
|
|
||||||
|
writeToDestination(destinationBit, address, result);
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
}
|
||||||
27
de/darkress/pic16f84sim/commands/Decf.java
Normal file
27
de/darkress/pic16f84sim/commands/Decf.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
|
public class Decf extends FileRegisterCommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int address;
|
||||||
|
private final boolean destinationBit;
|
||||||
|
|
||||||
|
public Decf(int input)
|
||||||
|
{
|
||||||
|
address = input & 0x007F;
|
||||||
|
destinationBit = checkDestinationBit(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
int result = Memory.getRegister(address) + 255; // Allow underflow
|
||||||
|
|
||||||
|
checkZeroBit(result);
|
||||||
|
|
||||||
|
writeToDestination(destinationBit, address, result % 256); // Catch underflow
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
}
|
||||||
33
de/darkress/pic16f84sim/commands/Decfsz.java
Normal file
33
de/darkress/pic16f84sim/commands/Decfsz.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
|
public class Decfsz extends FileRegisterCommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int address;
|
||||||
|
private final boolean destinationBit;
|
||||||
|
|
||||||
|
public Decfsz(int input)
|
||||||
|
{
|
||||||
|
address = input & 0x007F;
|
||||||
|
destinationBit = checkDestinationBit(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
int result = Memory.getRegister(address) + 255; // Allow underflow
|
||||||
|
|
||||||
|
checkZeroBit(result);
|
||||||
|
|
||||||
|
writeToDestination(destinationBit, address, result % 256); // Catch underflow
|
||||||
|
|
||||||
|
if((result % 256) == 0)
|
||||||
|
{
|
||||||
|
Nop nop = new Nop();
|
||||||
|
nop.execute();
|
||||||
|
}
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
de/darkress/pic16f84sim/commands/Nop.java
Normal file
14
de/darkress/pic16f84sim/commands/Nop.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
|
public class Nop extends LiteralCommandUtils implements Command
|
||||||
|
{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
// Do nothing, just increment the PC
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,14 +13,11 @@ public class CommandDecoder
|
|||||||
case 0x500:
|
case 0x500:
|
||||||
return new Andwf(input);
|
return new Andwf(input);
|
||||||
case 0x900:
|
case 0x900:
|
||||||
//comf();
|
return new Comf(input);
|
||||||
break;
|
|
||||||
case 0x300:
|
case 0x300:
|
||||||
//decf();
|
return new Decf(input);
|
||||||
break;
|
|
||||||
case 0xB00:
|
case 0xB00:
|
||||||
//decfsz();
|
return new Decfsz(input);
|
||||||
break;
|
|
||||||
case 0xA00:
|
case 0xA00:
|
||||||
//incf();
|
//incf();
|
||||||
break;
|
break;
|
||||||
@@ -113,7 +110,7 @@ public class CommandDecoder
|
|||||||
|
|
||||||
if ((input | 0x0060) == 0x0060)
|
if ((input | 0x0060) == 0x0060)
|
||||||
{
|
{
|
||||||
//nop();
|
return new Nop();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == 0x0064)
|
if (input == 0x0064)
|
||||||
|
|||||||
Reference in New Issue
Block a user