Compare commits
1 Commits
interactiv
...
clrwdtInst
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02f7e52856 |
@@ -1,19 +1,20 @@
|
|||||||
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.microcontroller.Cycles;
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
import de.darkress.pic16f84sim.microcontroller.Watchdog;
|
import de.darkress.pic16f84sim.microcontroller.Watchdog;
|
||||||
import de.darkress.pic16f84sim.parser.Parser;
|
import de.darkress.pic16f84sim.parser.Parser;
|
||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
{
|
{
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) throws InterruptedException {
|
||||||
|
|
||||||
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim8.LST");
|
Command[] program = Parser.parser("de/darkress/pic16f84sim/TestPrograms/TPicSim11.LST");
|
||||||
|
|
||||||
Memory.initMemory();
|
Memory.initMemory();
|
||||||
|
|
||||||
@@ -23,18 +24,20 @@ class Main
|
|||||||
System.out.println("Resetting device");
|
System.out.println("Resetting device");
|
||||||
Watchdog.resetProgram();
|
Watchdog.resetProgram();
|
||||||
}
|
}
|
||||||
String[] instructionName = program[ProgramCounter.getPc()].getClass().toString().split("\\.");
|
System.out.println("Command: " + program[ProgramCounter.getPc()].toString());
|
||||||
System.out.println("Command: " + instructionName[instructionName.length -1]);
|
|
||||||
program[ProgramCounter.getPc()].execute();
|
program[ProgramCounter.getPc()].execute();
|
||||||
Cli.showDefaultRegisters();
|
|
||||||
askForInput();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void askForInput() {
|
System.out.println(Integer.toHexString(Memory.workingRegister) + " " + Cycles.getCycles());
|
||||||
System.out.println("Wanna give some more input?:");
|
System.out.println(Integer.toHexString(Memory.getOption()) + " " + Integer.toHexString(Memory.getTimer()));
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
String userInput = scanner.nextLine();
|
System.out.println(Integer.toHexString(Memory.getRegister(0x20)) + " " + Integer.toHexString(Memory.getRegister(0x21)));
|
||||||
if(!(userInput.equals(""))) askForInput();
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
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 showDefaultRegisters() {
|
|
||||||
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");
|
|
||||||
System.out.printf("%s:\t\t%s\t", "PortA", Integer.toBinaryString(Memory.getPortA()));
|
|
||||||
System.out.printf("%s:\t\t%s\t", "PortB", Integer.toBinaryString(Memory.getPortB()));
|
|
||||||
System.out.printf("%n");
|
|
||||||
printf(Memory.getRegister(0x0B), "IntCon", 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Cycles;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Stack;
|
|
||||||
|
|
||||||
public class Retfie extends LiteralCommandUtils implements Command
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void execute()
|
|
||||||
{
|
|
||||||
Cycles.incCycles();
|
|
||||||
Memory.setRegister(0x0B, Memory.getRegister(0x0B) | 0x80); //Set GIE
|
|
||||||
ProgramCounter.setPcFromStack(Stack.pop() + 1);
|
|
||||||
Cycles.incCycles(); // Simulate 2-Cycle Instruction
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -102,7 +102,7 @@ public class CommandDecoder
|
|||||||
|
|
||||||
if (input == 0x0009)
|
if (input == 0x0009)
|
||||||
{
|
{
|
||||||
return new Retfie();
|
//retfie();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == 0x0008)
|
if (input == 0x0008)
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package de.darkress.pic16f84sim.microcontroller;
|
|
||||||
|
|
||||||
public class Interrupt
|
|
||||||
{
|
|
||||||
private static boolean globalInterruptEnabled() {
|
|
||||||
return (Memory.getRegister(0x0B) & 0x80) == 0x80; // Check GIE
|
|
||||||
|
|
||||||
}
|
|
||||||
public static boolean checkTimerInterruptConditions() {
|
|
||||||
boolean timerInterruptEnabled = (Memory.getRegister(0x0B) & 0x20) == 0x20;
|
|
||||||
return globalInterruptEnabled() && timerInterruptEnabled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -111,7 +111,7 @@ public class Memory
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getFSR()
|
private static int getFSR()
|
||||||
{
|
{
|
||||||
return memory[0x4];
|
return memory[0x4];
|
||||||
}
|
}
|
||||||
@@ -143,13 +143,6 @@ public class Memory
|
|||||||
return memory[0x81];
|
return memory[0x81];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPortB() {
|
|
||||||
return memory[0x06];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getPortA() {
|
|
||||||
return memory[0x05] & 0x1F;
|
|
||||||
}
|
|
||||||
public static int getTimer()
|
public static int getTimer()
|
||||||
{
|
{
|
||||||
return memory[0x01];
|
return memory[0x01];
|
||||||
|
|||||||
@@ -37,11 +37,8 @@ public class ProgramCounter
|
|||||||
Memory.setPCL(pc & 0x00FF);
|
Memory.setPCL(pc & 0x00FF);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setProgramCounter(int value) {
|
public static void resetProgramCounter() {
|
||||||
if(value <= 0xFF && value >= 0)
|
pc = 0;
|
||||||
{
|
Memory.setPCL(0x0);
|
||||||
pc = value;
|
|
||||||
Memory.setPCL(pc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,10 @@ 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()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,12 +46,6 @@ public class Timer
|
|||||||
if(timerRegister == 0) //check for timer Overflow --> interrupt
|
if(timerRegister == 0) //check for timer Overflow --> interrupt
|
||||||
{
|
{
|
||||||
System.out.println("Timer Overflow");
|
System.out.println("Timer Overflow");
|
||||||
Memory.setRegister(0x0B, Memory.getRegister(0x0B) | 0x04); //set T0IF
|
|
||||||
if(Interrupt.checkTimerInterruptConditions())
|
|
||||||
{
|
|
||||||
Stack.push(ProgramCounter.getPc());
|
|
||||||
ProgramCounter.setProgramCounter(0x04); // Interrupt Vector
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Memory.setTimer(timerRegister);
|
Memory.setTimer(timerRegister);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ public class Watchdog
|
|||||||
|
|
||||||
public static void resetProgram()
|
public static void resetProgram()
|
||||||
{
|
{
|
||||||
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x10); //Set !T0 in StatusReg
|
Memory.setRegister(0x03, Memory.getRegister(0x03) | 0x10);
|
||||||
ProgramCounter.setProgramCounter(0);
|
|
||||||
watchdogTimer = 18000;
|
watchdogTimer = 18000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user