Compare commits
3 Commits
callInstru
...
retlwInstr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0f6179059 | ||
|
|
eed0b2e3eb | ||
|
|
666cc2881b |
@@ -12,14 +12,14 @@ class Main
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
ArrayList<Command> program = new ArrayList<>();
|
ArrayList<Command> program = new ArrayList<>();
|
||||||
Memory.workingRegister = 0xAA;
|
int input1 = 0x27FF;
|
||||||
int input1 = 0x2FFF;
|
program.add(CommandDecoder.decode(0x3011));
|
||||||
program.add(CommandDecoder.decode(input1));
|
program.add(CommandDecoder.decode(0x2003));
|
||||||
|
program.add(CommandDecoder.decode(0x3022));
|
||||||
Memory.setPCLATH(0xFF);
|
program.add(CommandDecoder.decode(0x0008));
|
||||||
program.get(0).execute();
|
while(true)
|
||||||
|
{
|
||||||
//ProgramCounter.incPC();
|
program.get(ProgramCounter.getPc()).execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
21
de/darkress/pic16f84sim/commands/Call.java
Normal file
21
de/darkress/pic16f84sim/commands/Call.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Stack;
|
||||||
|
|
||||||
|
public class Call extends CommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int literal;
|
||||||
|
|
||||||
|
public Call(int input)
|
||||||
|
{
|
||||||
|
literal = input & 0x07FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
Stack.push(ProgramCounter.getPc() + 1);
|
||||||
|
ProgramCounter.setPcFrom11BitLiteral(literal);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.darkress.pic16f84sim.commands;
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.Memory;
|
|
||||||
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
public class Goto extends CommandUtils implements Command
|
public class Goto extends CommandUtils implements Command
|
||||||
@@ -15,6 +14,6 @@ public class Goto extends CommandUtils implements Command
|
|||||||
@Override
|
@Override
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
ProgramCounter.setPcForGotoCall(literal);
|
ProgramCounter.setPcFrom11BitLiteral(literal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
24
de/darkress/pic16f84sim/commands/Retlw.java
Normal file
24
de/darkress/pic16f84sim/commands/Retlw.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Stack;
|
||||||
|
|
||||||
|
public class Retlw extends CommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int literal;
|
||||||
|
|
||||||
|
public Retlw(int input)
|
||||||
|
{
|
||||||
|
literal = input & 0x00FF;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
Memory.workingRegister = literal;
|
||||||
|
ProgramCounter.setPcFrom11BitLiteral(Stack.pop());
|
||||||
|
//TODO: This may need some rework since it does not really load all 13 Bit into the PC. Only 8 Bit are
|
||||||
|
// effectively set
|
||||||
|
}
|
||||||
|
}
|
||||||
15
de/darkress/pic16f84sim/commands/Return.java
Normal file
15
de/darkress/pic16f84sim/commands/Return.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Stack;
|
||||||
|
|
||||||
|
public class Return extends CommandUtils implements Command
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
ProgramCounter.setPcFrom11BitLiteral(Stack.pop());
|
||||||
|
//TODO: This may need some rework since it does not really load all 13 Bit into the PC. Only 8 Bit are
|
||||||
|
// effectively set
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -100,8 +100,7 @@ public class CommandDecoder
|
|||||||
switch(input & 0x3800)
|
switch(input & 0x3800)
|
||||||
{
|
{
|
||||||
case 0x2000:
|
case 0x2000:
|
||||||
//call();
|
return new Call(input);
|
||||||
break;
|
|
||||||
case 0x2800:
|
case 0x2800:
|
||||||
return new Goto(input);
|
return new Goto(input);
|
||||||
}
|
}
|
||||||
@@ -111,8 +110,7 @@ public class CommandDecoder
|
|||||||
case 0x3000:
|
case 0x3000:
|
||||||
return new Movlw(input);
|
return new Movlw(input);
|
||||||
case 0x3400:
|
case 0x3400:
|
||||||
//retlw();
|
return new Retlw(input);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((input | 0x0060) == 0x0060)
|
if ((input | 0x0060) == 0x0060)
|
||||||
@@ -132,8 +130,7 @@ public class CommandDecoder
|
|||||||
|
|
||||||
if (input == 0x0008)
|
if (input == 0x0008)
|
||||||
{
|
{
|
||||||
//return();
|
return new Return();
|
||||||
//This is the function name. Do not mistake this for a normal return!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input == 0x0063)
|
if (input == 0x0063)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class ProgramCounter
|
|||||||
return pc;
|
return pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setPcForGotoCall(int data)
|
public static void setPcFrom11BitLiteral(int data)
|
||||||
{
|
{
|
||||||
int pcl = data & 0x00FF;
|
int pcl = data & 0x00FF;
|
||||||
int pch = Memory.getPCLATH();
|
int pch = Memory.getPCLATH();
|
||||||
|
|||||||
@@ -14,9 +14,8 @@ public class Stack
|
|||||||
|
|
||||||
public static int pop()
|
public static int pop()
|
||||||
{
|
{
|
||||||
int tmp = stack[stackPointer];
|
|
||||||
pointPrevious();
|
pointPrevious();
|
||||||
return tmp;
|
return stack[stackPointer];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int peek()
|
public static int peek()
|
||||||
|
|||||||
Reference in New Issue
Block a user