Compare commits
4 Commits
clrwdtInst
...
CommandLin
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6772f448ba | ||
|
|
9319a14d88 | ||
|
|
9d7d1ce5b1 | ||
|
|
b408b10cd0 |
@@ -1,5 +1,6 @@
|
|||||||
package de.darkress.pic16f84sim;
|
package de.darkress.pic16f84sim;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.cli.Cli;
|
||||||
import de.darkress.pic16f84sim.commands.Command;
|
import de.darkress.pic16f84sim.commands.Command;
|
||||||
import de.darkress.pic16f84sim.decoder.CommandDecoder;
|
import de.darkress.pic16f84sim.decoder.CommandDecoder;
|
||||||
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
||||||
@@ -24,20 +25,10 @@ class Main
|
|||||||
System.out.println("Resetting device");
|
System.out.println("Resetting device");
|
||||||
Watchdog.resetProgram();
|
Watchdog.resetProgram();
|
||||||
}
|
}
|
||||||
System.out.println("Command: " + program[ProgramCounter.getPc()].toString());
|
String[] instructionName = program[ProgramCounter.getPc()].getClass().toString().split("\\.");
|
||||||
|
System.out.println("Command: " + instructionName[instructionName.length -1]);
|
||||||
program[ProgramCounter.getPc()].execute();
|
program[ProgramCounter.getPc()].execute();
|
||||||
|
Cli.showRegisters();
|
||||||
System.out.println(Integer.toHexString(Memory.workingRegister) + " " + Cycles.getCycles());
|
|
||||||
System.out.println(Integer.toHexString(Memory.getOption()) + " " + Integer.toHexString(Memory.getTimer()));
|
|
||||||
|
|
||||||
System.out.println(Integer.toHexString(Memory.getRegister(0x20)) + " " + Integer.toHexString(Memory.getRegister(0x21)));
|
|
||||||
System.out.println(Integer.toHexString(Memory.getRegister(0x22)) + " " + Integer.toHexString(Memory.getRegister(0x23)));
|
|
||||||
|
|
||||||
System.out.println(Integer.toHexString(Memory.getPCLATH()) + " " + Integer.toHexString(Memory.getPCL()) + "\n");
|
|
||||||
|
|
||||||
if(ProgramCounter.getPc() == 0x10) {
|
|
||||||
System.out.println(Memory.getRegister(0x20));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
36
de/darkress/pic16f84sim/cli/Cli.java
Normal file
36
de/darkress/pic16f84sim/cli/Cli.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package de.darkress.pic16f84sim.cli;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Stack;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Timer;
|
||||||
|
|
||||||
|
public class Cli
|
||||||
|
{
|
||||||
|
public static void showRegisters() {
|
||||||
|
printf(Memory.workingRegister, "W-Reg", true);
|
||||||
|
printf(Cycles.getCycles(), "Cycles", false);
|
||||||
|
System.out.printf("%n");
|
||||||
|
printf(Memory.getRegister(0x03), "Status", true);
|
||||||
|
printf(Memory.getOption(), "Option", true);
|
||||||
|
System.out.printf("%n");
|
||||||
|
printf(Memory.getFSR(), "FSR", true);
|
||||||
|
printf(Stack.getStackPointer(), "Stackpointer", true);
|
||||||
|
System.out.printf("%n");
|
||||||
|
printf(Memory.getTimer(), "Timer", true);
|
||||||
|
printf(Timer.getCyclesToTimerIncrease(), "Prescaler", true);
|
||||||
|
System.out.printf("%n");
|
||||||
|
printf(Memory.getPCLATH(), "PCLATH", true);
|
||||||
|
printf(Memory.getPCL(), "PCL", true);
|
||||||
|
System.out.printf("%n");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printf(int value, String description, boolean hex) {
|
||||||
|
if(hex) {
|
||||||
|
System.out.printf("%s:\t\t%s\t", description, Integer.toHexString(value));
|
||||||
|
} else {
|
||||||
|
System.out.printf("%s:\t\t%d\t", description, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
24
de/darkress/pic16f84sim/commands/Clrwdt.java
Normal file
24
de/darkress/pic16f84sim/commands/Clrwdt.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.*;
|
||||||
|
|
||||||
|
public class Clrwdt extends LiteralCommandUtils implements Command
|
||||||
|
{
|
||||||
|
|
||||||
|
public Clrwdt()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
Cycles.incCycles();
|
||||||
|
|
||||||
|
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x18);
|
||||||
|
if(Timer.getPrescalerAssignment()) {
|
||||||
|
Timer.resetTimeToTimerIncrease();
|
||||||
|
Watchdog.resetWatchdogTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -97,7 +97,7 @@ public class CommandDecoder
|
|||||||
|
|
||||||
if (input == 0x0064)
|
if (input == 0x0064)
|
||||||
{
|
{
|
||||||
//clrwdt();
|
return new Clrwdt();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == 0x0009)
|
if (input == 0x0009)
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class Memory
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getFSR()
|
public static int getFSR()
|
||||||
{
|
{
|
||||||
return memory[0x4];
|
return memory[0x4];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,6 @@ public class Stack
|
|||||||
return stack[stackPointer];
|
return stack[stackPointer];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int peek()
|
|
||||||
{
|
|
||||||
return stack[(stackPointer + 7) % 8]; //Get TopOfStack -1 +8 = 7 and modulo 8 to avoid IndexOutOfBound
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void pointNext()
|
private static void pointNext()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ public class Watchdog
|
|||||||
return watchdogTimer;
|
return watchdogTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void resetWatchdogTimer() {
|
||||||
|
watchdogTimer = 18000;
|
||||||
|
}
|
||||||
|
|
||||||
public static void decreaseWatchdogTimer()
|
public static void decreaseWatchdogTimer()
|
||||||
{
|
{
|
||||||
watchdogTimer--;
|
watchdogTimer--;
|
||||||
@@ -25,7 +29,8 @@ public class Watchdog
|
|||||||
|
|
||||||
public static void resetProgram()
|
public static void resetProgram()
|
||||||
{
|
{
|
||||||
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x10);
|
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x10); //Set !T0 in StatusReg
|
||||||
|
ProgramCounter.resetProgramCounter();
|
||||||
watchdogTimer = 18000;
|
watchdogTimer = 18000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user