Compare commits

..

8 Commits

Author SHA1 Message Date
darkress
9a21d9256f implemented Clrf Instruction 2023-06-02 23:50:34 +02:00
darkress
ab9f378d34 implemented Clrw instruction (#15)
Co-authored-by: darkress <github@darkress.xyz>
Reviewed-on: darkress/pic16f84-sim#15
2023-06-02 23:29:15 +02:00
darkress
b23bf4c54b implemented Incfsz Instruction (#14)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#14
2023-05-31 22:30:29 +02:00
darkress
7eab465fff implement Incf Instruction (#13)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#13
2023-05-31 22:13:12 +02:00
darkress
c896b4f199 decfszInstruction (#12)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#12
2023-05-31 20:51:00 +02:00
darkress
46515de5f1 implemented Nop Instruction (#11)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#11
2023-05-31 20:24:57 +02:00
darkress
49ab5876b8 implemented decf Instruction (#10)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#10
2023-05-31 20:16:46 +02:00
darkress
1f8e3aff58 implemented comf Instruction (#9)
Co-authored-by: Darkress <30271678+DarkressX@users.noreply.github.com>
Reviewed-on: darkress/pic16f84-sim#9
2023-05-31 20:00:52 +02:00
9 changed files with 189 additions and 18 deletions

View File

@@ -12,11 +12,9 @@ class Main
public static void main(String[] args) {
ArrayList<Command> program = new ArrayList<>();
int input1 = 0x27FF;
program.add(CommandDecoder.decode(0x3011)); //Write 0x11 to W
Memory.setRegister(0x14, 0x14);
program.add(CommandDecoder.decode(0x0994));
for(int i = 0; i < 2; i++)
Memory.setRegister(0x14, 0xFF);
program.add(CommandDecoder.decode(0x0194));
for(int i = 0; i < program.size(); i++)
{
program.get(ProgramCounter.getPc()).execute();
}

View File

@@ -0,0 +1,27 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Clrf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Clrf(int input)
{
address = input & 0x007F;
destinationBit = true;
}
@Override
public void execute()
{
final int result = 0;
checkZeroBit(result);
writeToDestination(destinationBit, address, result);
ProgramCounter.incPC();
}
}

View File

@@ -0,0 +1,18 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Clrw extends FileRegisterCommandUtils implements Command
{
@Override
public void execute()
{
final int result = 0;
checkZeroBit(result);
Memory.workingRegister = result;
ProgramCounter.incPC();
}
}

View 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();
}
}

View 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();
}
}

View File

@@ -0,0 +1,27 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Incf extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Incf(int input)
{
address = input & 0x007F;
destinationBit = checkDestinationBit(input);
}
@Override
public void execute()
{
int result = Memory.getRegister(address) + 1; // Allow underflow
checkZeroBit(result);
writeToDestination(destinationBit, address, result % 256); // Catch underflow
ProgramCounter.incPC();
}
}

View File

@@ -0,0 +1,33 @@
package de.darkress.pic16f84sim.commands;
import de.darkress.pic16f84sim.microcontroller.Memory;
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
public class Incfsz extends FileRegisterCommandUtils implements Command
{
private final int address;
private final boolean destinationBit;
public Incfsz(int input)
{
address = input & 0x007F;
destinationBit = checkDestinationBit(input);
}
@Override
public void execute()
{
int result = Memory.getRegister(address) + 1;
checkZeroBit(result);
writeToDestination(destinationBit, address, result % 256);
if((result % 256) == 0)
{
Nop nop = new Nop();
nop.execute();
}
ProgramCounter.incPC();
}
}

View 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();
}
}

View File

@@ -15,17 +15,13 @@ public class CommandDecoder
case 0x900:
return new Comf(input);
case 0x300:
//decf();
break;
return new Decf(input);
case 0xB00:
//decfsz();
break;
return new Decfsz(input);
case 0xA00:
//incf();
break;
return new Incf(input);
case 0xF00:
//incfsz();
break;
return new Incfsz(input);
case 0x400:
//iorwf();
break;
@@ -58,11 +54,9 @@ public class CommandDecoder
switch(input & 0x3F80)
{
case 0x180:
//clrf();
break;
return new Clrf(input);
case 0x100:
//clrw();
break;
return new Clrw();
case 0x80:
//movwf();
break;
@@ -112,7 +106,7 @@ public class CommandDecoder
if ((input | 0x0060) == 0x0060)
{
//nop();
return new Nop();
}
if (input == 0x0064)