parser now acounts for instruction address #31
@@ -2,22 +2,28 @@ package de.darkress.pic16f84sim;
|
||||
|
||||
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.ProgramCounter;
|
||||
import de.darkress.pic16f84sim.parser.Parser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
class Main
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
|
||||
ArrayList<Command> program = new ArrayList<>();
|
||||
Memory.workingRegister = 0x01;
|
||||
Memory.setRegister(0x14, 0xA7); //240 << 224
|
||||
program.add(CommandDecoder.decode(0x1C94));
|
||||
for(int i = 0; i < program.size(); i++)
|
||||
Command[] program = Parser.parser("de/darkress/pic16f84sim/TPicSim101.LST");
|
||||
/*for(int i = 0; i < instructions.size(); i++)
|
||||
{
|
||||
program.get(ProgramCounter.getPc()).execute();
|
||||
program.add(CommandDecoder.decode(instructions.get(i)));
|
||||
}*/
|
||||
|
||||
while(ProgramCounter.getPc() < 1024)
|
||||
{
|
||||
program[ProgramCounter.getPc()].execute();
|
||||
System.out.println(Memory.workingRegister + " " + Cycles.getCycles());
|
||||
System.out.println(Memory.getPCLATH() + " " + Memory.getPCL() + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,6 @@ public class Memory
|
||||
if(address == 0x2) //Check if PCL is destination
|
||||
{
|
||||
ProgramCounter.loadPc();
|
||||
Cycles.addToCycles(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package de.darkress.pic16f84sim.parser;
|
||||
|
||||
import de.darkress.pic16f84sim.commands.Command;
|
||||
import de.darkress.pic16f84sim.decoder.CommandDecoder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
@@ -8,9 +11,9 @@ import java.util.Scanner;
|
||||
|
||||
public class Parser
|
||||
{
|
||||
public static List<Integer> parser(String filePath)
|
||||
public static Command[] parser(String filePath)
|
||||
{
|
||||
ArrayList<Integer> program = new ArrayList<>();
|
||||
ArrayList<String> instructions = new ArrayList<>();
|
||||
try {
|
||||
File file = new File(filePath);
|
||||
Scanner scanner = new Scanner(file);
|
||||
@@ -19,8 +22,10 @@ public class Parser
|
||||
if(!data.startsWith(" "))
|
||||
{
|
||||
String commandAndParametersString = "0x" + data.split(" ")[1];
|
||||
int commandAndParameters = Integer.decode(commandAndParametersString);
|
||||
program.add(commandAndParameters);
|
||||
String instructionAddress = "0x" + data.split(" ")[0];
|
||||
//int commandAndParameters = Integer.decode(commandAndParametersString);
|
||||
//program.add(commandAndParameters);
|
||||
instructions.add(instructionAddress + ", " + commandAndParametersString);
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
@@ -28,6 +33,16 @@ public class Parser
|
||||
System.out.println("An error occurred.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Command[] program = new Command[1024];
|
||||
|
||||
for(int i = 0; i < instructions.size(); i++)
|
||||
{
|
||||
int instructionAddress = Integer.decode(instructions.get(i).split(", ")[0]);
|
||||
int instruction = Integer.decode(instructions.get(i).split(", ")[1]);
|
||||
program[instructionAddress] = CommandDecoder.decode(instruction);
|
||||
}
|
||||
|
||||
return program;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user