timer0 #32
@@ -19,7 +19,9 @@ class Main
|
|||||||
|
|
||||||
while(ProgramCounter.getPc() < 1024)
|
while(ProgramCounter.getPc() < 1024)
|
||||||
{
|
{
|
||||||
|
System.out.println("Command: " + program[ProgramCounter.getPc()].toString());
|
||||||
program[ProgramCounter.getPc()].execute();
|
program[ProgramCounter.getPc()].execute();
|
||||||
|
|
||||||
System.out.println(Integer.toHexString(Memory.workingRegister) + " " + Cycles.getCycles());
|
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.getOption()) + " " + Integer.toHexString(Memory.getTimer()));
|
||||||
System.out.println(Integer.toHexString(Memory.getPCLATH()) + " " + Integer.toHexString(Memory.getPCL()) + "\n");
|
System.out.println(Integer.toHexString(Memory.getPCLATH()) + " " + Integer.toHexString(Memory.getPCL()) + "\n");
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ public class Memory
|
|||||||
setDataFromIndirectAddress(indirectAddress, data);
|
setDataFromIndirectAddress(indirectAddress, data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
||||||
|
{
|
||||||
|
Timer.resetTimeToTimerIncrease();
|
||||||
|
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
||||||
|
// this command execution
|
||||||
|
}
|
||||||
if((Arrays.stream(bank0UniqueSpecialRegister).anyMatch(x -> x == address)) && getRegisterBank() == 0)
|
if((Arrays.stream(bank0UniqueSpecialRegister).anyMatch(x -> x == address)) && getRegisterBank() == 0)
|
||||||
{
|
{
|
||||||
memory[address] = data;
|
memory[address] = data;
|
||||||
@@ -67,10 +73,6 @@ public class Memory
|
|||||||
}
|
}
|
||||||
memory[address] = data;
|
memory[address] = data;
|
||||||
memory[address + 128] = data; //Ensure data is written to both banks to simulate mapping
|
memory[address + 128] = data; //Ensure data is written to both banks to simulate mapping
|
||||||
if(address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
|
||||||
{
|
|
||||||
Timer.resetTimeToTimerIncrease();
|
|
||||||
}
|
|
||||||
if(address == 0x2) //Check if PCL is destination
|
if(address == 0x2) //Check if PCL is destination
|
||||||
{
|
{
|
||||||
ProgramCounter.loadPc();
|
ProgramCounter.loadPc();
|
||||||
@@ -84,6 +86,12 @@ public class Memory
|
|||||||
|
|
||||||
private static void setDataFromIndirectAddress(int address, int data)
|
private static void setDataFromIndirectAddress(int address, int data)
|
||||||
{
|
{
|
||||||
|
if(address == 0x81 || address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
||||||
|
{
|
||||||
|
Timer.resetTimeToTimerIncrease();
|
||||||
|
Timer.setCyclesToTimerIncrease(Timer.getCyclesToTimerIncrease() - 1); //Decrease by one to account for
|
||||||
|
// this command execution
|
||||||
|
}
|
||||||
if((Arrays.stream(bank0UniqueSpecialRegister).anyMatch(x -> x == address)) || (Arrays.stream(bank1UniqueSpecialRegister).anyMatch(x -> x == address)))
|
if((Arrays.stream(bank0UniqueSpecialRegister).anyMatch(x -> x == address)) || (Arrays.stream(bank1UniqueSpecialRegister).anyMatch(x -> x == address)))
|
||||||
{
|
{
|
||||||
memory[address] = data;
|
memory[address] = data;
|
||||||
@@ -91,14 +99,6 @@ public class Memory
|
|||||||
}
|
}
|
||||||
memory[address % 128] = data; // else: Registers.Registers which are mapped
|
memory[address % 128] = data; // else: Registers.Registers which are mapped
|
||||||
memory[address % 128 + 128] = data; //Ensure data is written to both banks to simulate mapping
|
memory[address % 128 + 128] = data; //Ensure data is written to both banks to simulate mapping
|
||||||
if(address == 0x81 || address == 0x01) //Reset PrescalerCounter if change on Option or Timer Register
|
|
||||||
{
|
|
||||||
Timer.resetTimeToTimerIncrease();
|
|
||||||
}
|
|
||||||
if(address == 0x2 || address == 0x82) //Check if PCL is destination
|
|
||||||
{
|
|
||||||
ProgramCounter.loadPc();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getRegisterBank()
|
private static int getRegisterBank()
|
||||||
|
|||||||
@@ -2,6 +2,16 @@ package de.darkress.pic16f84sim.microcontroller;
|
|||||||
|
|
||||||
public class Timer
|
public class Timer
|
||||||
{
|
{
|
||||||
|
public static int getCyclesToTimerIncrease()
|
||||||
|
{
|
||||||
|
return cyclesToTimerIncrease;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCyclesToTimerIncrease(int cyclesToTimerIncrease)
|
||||||
|
{
|
||||||
|
Timer.cyclesToTimerIncrease = cyclesToTimerIncrease;
|
||||||
|
}
|
||||||
|
|
||||||
private static int cyclesToTimerIncrease = 1;
|
private static int cyclesToTimerIncrease = 1;
|
||||||
|
|
||||||
private static boolean timerEnabled()
|
private static boolean timerEnabled()
|
||||||
|
|||||||
Reference in New Issue
Block a user