Compare commits
4 Commits
btfscInstr
...
guiSRAM
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
43e79778fe | ||
|
|
7ef8a285e0 | ||
|
|
184c49f3ae | ||
|
|
5cb1573a08 |
@@ -2,9 +2,11 @@ package de.darkress.pic16f84sim;
|
|||||||
|
|
||||||
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.gui.SramTable;
|
||||||
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 javax.swing.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
class Main
|
class Main
|
||||||
@@ -13,11 +15,20 @@ class Main
|
|||||||
|
|
||||||
ArrayList<Command> program = new ArrayList<>();
|
ArrayList<Command> program = new ArrayList<>();
|
||||||
Memory.workingRegister = 0x01;
|
Memory.workingRegister = 0x01;
|
||||||
Memory.setRegister(0x14, 0xA5); //240 << 224
|
Memory.setRegister(0x14, 0xA7); //240 << 224
|
||||||
program.add(CommandDecoder.decode(0x1594));
|
program.add(CommandDecoder.decode(0x1C94));
|
||||||
for(int i = 0; i < program.size(); i++)
|
for(int i = 0; i < program.size(); i++)
|
||||||
{
|
{
|
||||||
program.get(ProgramCounter.getPc()).execute();
|
program.get(ProgramCounter.getPc()).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SramTable table = new SramTable();
|
||||||
|
JFrame frame = new JFrame("Table Example");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.add(table.getTable());
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
//table.setValueAt("test", 15, 7);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
29
de/darkress/pic16f84sim/commands/Btfsc.java
Normal file
29
de/darkress/pic16f84sim/commands/Btfsc.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
|
public class Btfsc extends BitOrientedCommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int address;
|
||||||
|
private int bitPlacement;
|
||||||
|
|
||||||
|
public Btfsc(int input)
|
||||||
|
{
|
||||||
|
address = input & 0x007F;
|
||||||
|
bitPlacement = checkBitPlacement(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
int result = Memory.getRegister(address);
|
||||||
|
|
||||||
|
if((result & (1 << bitPlacement)) == 0) //Test if bit is clear
|
||||||
|
{
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
}
|
||||||
29
de/darkress/pic16f84sim/commands/Btfss.java
Normal file
29
de/darkress/pic16f84sim/commands/Btfss.java
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package de.darkress.pic16f84sim.commands;
|
||||||
|
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.Memory;
|
||||||
|
import de.darkress.pic16f84sim.microcontroller.ProgramCounter;
|
||||||
|
|
||||||
|
public class Btfss extends BitOrientedCommandUtils implements Command
|
||||||
|
{
|
||||||
|
private final int address;
|
||||||
|
private int bitPlacement;
|
||||||
|
|
||||||
|
public Btfss(int input)
|
||||||
|
{
|
||||||
|
address = input & 0x007F;
|
||||||
|
bitPlacement = checkBitPlacement(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute()
|
||||||
|
{
|
||||||
|
int result = Memory.getRegister(address);
|
||||||
|
|
||||||
|
if((result & (1 << bitPlacement)) > 0) //Test if bit is set
|
||||||
|
{
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgramCounter.incPC();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,19 +61,15 @@ public class CommandDecoder
|
|||||||
case 0x1400:
|
case 0x1400:
|
||||||
return new Bsf(input);
|
return new Bsf(input);
|
||||||
case 0x1800:
|
case 0x1800:
|
||||||
//btfsc();
|
return new Btfsc(input);
|
||||||
break;
|
|
||||||
case 0x1C00:
|
case 0x1C00:
|
||||||
//btfss();
|
return new Btfss(input);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(input & 0x3E00)
|
switch(input & 0x3E00)
|
||||||
{
|
{
|
||||||
case 0x3E00:
|
case 0x3E00:
|
||||||
//addlw();
|
|
||||||
return new Addlw(input);
|
return new Addlw(input);
|
||||||
//break;
|
|
||||||
case 0x3C00:
|
case 0x3C00:
|
||||||
return new Sublw(input);
|
return new Sublw(input);
|
||||||
}
|
}
|
||||||
|
|||||||
52
de/darkress/pic16f84sim/gui/SramTable.java
Normal file
52
de/darkress/pic16f84sim/gui/SramTable.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package de.darkress.pic16f84sim.gui;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.geom.Dimension2D;
|
||||||
|
|
||||||
|
public class SramTable
|
||||||
|
{
|
||||||
|
private final int rows = 32;
|
||||||
|
private final int columns = 8;
|
||||||
|
private Object[][] data = new Object[rows][columns];
|
||||||
|
|
||||||
|
public JTable getTable()
|
||||||
|
{
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JTable table = new JTable(data, createColumns());
|
||||||
|
|
||||||
|
public SramTable()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (int i = 0; i < rows; i++) {
|
||||||
|
for (int j = 0; j < columns; j++) {
|
||||||
|
data[i][j] = Integer.toHexString(count).toUpperCase();
|
||||||
|
table.getColumnModel().getColumn(j).setPreferredWidth(30);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object[] createColumns(){
|
||||||
|
Object[] columnNames = new Object[columns];
|
||||||
|
for (int j = 0; j < columns; j++) {
|
||||||
|
columnNames[j] = j;
|
||||||
|
}
|
||||||
|
return columnNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void table() {
|
||||||
|
// Create a scroll pane and add the table to it
|
||||||
|
JScrollPane scrollPane = new JScrollPane(table);
|
||||||
|
|
||||||
|
// Create a panel and add the scroll pane to it
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
panel.add(scrollPane);
|
||||||
|
|
||||||
|
// Create a frame and add the panel to it
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user