Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jakoberzar committed Oct 8, 2019
2 parents 1944054 + d85a1f1 commit 05f1501
Show file tree
Hide file tree
Showing 12 changed files with 116 additions and 28 deletions.
5 changes: 3 additions & 2 deletions src/sic/Asm.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
*/
public class Asm {

public static final int Version_Major = 1;
public static final int Version_Major = 2;
public static final int Version_Minor = 0;
public static final int Version_Patch = 1;

//
private boolean stdin;
Expand All @@ -31,7 +32,7 @@ public class Asm {

static void printHelp() {
System.out.print(
"Sic/XE Assembler " + Version_Major + "." + Version_Minor + "\n" +
"Sic/XE Assembler " + Version_Major + "." + Version_Minor + "." + Version_Patch + "\n" +
"Usage: java sic.Asm options parameters\n" +
"Options:\n" +
" -help|-h Print help.\n" +
Expand Down
31 changes: 27 additions & 4 deletions src/sic/Sim.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import sic.common.Mnemonics;
import sic.disasm.Disassembler;
import sic.sim.Args;
import sic.sim.Executor;
import sic.sim.MainView;
import sic.sim.vm.Machine;
Expand All @@ -17,25 +18,43 @@
*/
public class Sim {

public static final int Version_Major = 2;
public static final int Version_Minor = 0;
public static final int Version_Patch = 1;

// TODO: -freq 10
// -registers
// -memory start len
// -debug level

static void printHelp() {
System.out.print(
"Sic/XE Simulator " + Version_Major + "." + Version_Minor + "." + Version_Patch + "\n" +
"Usage: java sic.Sim options parameters\n" +
"Options:\n");
Args.printArgs();
}


public static void main(String[] args) throws Exception {
// ToolTipManager.sharedInstance().setDismissDelay(15000);
// UIManager.put("ToolTip.font", new FontUIResource("Courier New", Font.PLAIN, 14));
//
Args processedArgs = new Args(args);

if (processedArgs.isHelp()) {
printHelp();
return;
}

Machine machine = new Machine();
Executor executor = new Executor(machine);
Executor executor = new Executor(machine, processedArgs);
Disassembler disassembler = new Disassembler(new Mnemonics(), machine);

final MainView mainView = new MainView(executor, disassembler);
final MainView mainView = new MainView(executor, disassembler, processedArgs);

if (args.length > 0) mainView.load(new File(args[0]));
if (processedArgs.hasFilename()) mainView.load(new File(processedArgs.getFilename()));

// executor.start();
mainView.updateView();

executor.onBreakpoint = new ActionListener() {
Expand All @@ -44,5 +63,9 @@ public void actionPerformed(ActionEvent actionEvent) {
mainView.updateView();
}
};

if (processedArgs.isStart()) {
executor.start();
}
}
}
9 changes: 5 additions & 4 deletions src/sic/VM.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
*/
public class VM {

public static final int Version_Major = 1;
public static final int Version_Major = 2;
public static final int Version_Minor = 0;
public static final int Version_Patch = 1;

static void printHelp() {
System.out.print(
"Sic/XE Virtual Machine " + Version_Major + "." + Version_Minor + "\n" +
"Sic/XE Virtual Machine " + Version_Major + "." + Version_Minor + "." + Version_Patch + "\n" +
"Usage: java sic.VM options parameters\n" +
"Options:\n");
Args.printArgs();
Expand All @@ -34,8 +35,8 @@ public static void main(String[] args) throws Exception {
}

Machine machine = new Machine();
Executor executor = new Executor(machine);
if (arg.getFreq() > 0) executor.setSpeed(arg.getFreq());
Executor executor = new Executor(machine, arg);

if (arg.hasFilename()) {
String ext = arg.getFileext();
if ("asm".equals(ext)) Loader.loadAsm(machine, arg.getFilename());
Expand Down
12 changes: 9 additions & 3 deletions src/sic/asm/visitors/WriteText.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ public WriteText(Program program, ErrorCatcher errorCatcher, Writer writer, bool
// text-record builder

private StringBuilder buf = new StringBuilder();
private int recordBytes = 0;
private int textAddr;

private void flushBuf() {
if (buf.length() == 0) return;
w("T%s%06X%s%02X", space, textAddr, space, buf.length() / 2);
if (recordBytes == 0) return;
w("T%s%06X%s%02X", space, textAddr, space, recordBytes);
w(buf.toString());
w("\n");
buf = new StringBuilder();
recordBytes = 0;
}

// visitors
Expand Down Expand Up @@ -85,8 +87,12 @@ public void visit(Block block) throws AsmError {

public void visit(Command c) throws AsmError {
if (c.size() > 0) buf.append(space);

int bufLenBefore = buf.length();
boolean flush = c.emitText(buf);
if (flush || buf.length() > 56) {
recordBytes += (buf.length() - bufLenBefore) / 2;

if (flush || recordBytes > 28) {
flushBuf();
textAddr = program.locctr() + c.size();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sic/ast/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public String explain() {
// -------------------
// | DISASSEMBLY |
// -------------------
public Integer resolveRelativeOperand(int address) {
public Integer resolveOperandAddress(int addressPC) {
return null;
}
}
5 changes: 5 additions & 0 deletions src/sic/ast/Program.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sic.ast;

import sic.asm.AsmError;
import sic.ast.instructions.Instruction;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -182,4 +183,8 @@ public HashMap<Integer, StorageSymbol> getDataLabels() {

return map;
}

public long countInstructions() {
return commands.stream().filter(x -> x instanceof Instruction).count();
}
}
10 changes: 10 additions & 0 deletions src/sic/ast/instructions/InstructionF34Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,14 @@ public String explain() {
return super.explain() + "<br>" + nixbpe;
}

@Override
public Integer resolveOperandAddress(int addressPC) {
if (flags.isPCRelative()) {
return addressPC + size() + value;
} else if (!flags.isImmediate() && flags.isAbsolute() && !flags.isIndexed()) {
return value;
} else {
return null;
}
}
}
5 changes: 0 additions & 5 deletions src/sic/ast/instructions/InstructionF3m.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,4 @@ public void emitRawCode(byte[] data, int loc) {
(byte)(flags.get_xbpe() | (resolvedValue >> 8) & 0x0F);
data[loc + 2] = (byte)(resolvedValue & 0xFF);
}

@Override
public Integer resolveRelativeOperand(int address) {
return flags.isPCRelative() ? address + size() + value : null ;
}
}
27 changes: 23 additions & 4 deletions src/sic/sim/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class Args extends AbstractCmdLineArgs {

private int freq;
private int debug;
private boolean start;
private boolean stats;

private boolean textScr;
private int textScrCols;
Expand Down Expand Up @@ -78,6 +80,14 @@ public int getDebug() {
return debug;
}

public boolean isStart() {
return start;
}

public boolean isStats() {
return stats;
}

public boolean isTextScr() {
return textScr;
}
Expand All @@ -104,10 +114,13 @@ public int getGraphScrRows() {

public static void printArgs() {
System.out.print(
" -help|-h Print help.\n" +
" -freq hz Set the machine frequency.\n" +
" -debug level Set the debug level.\n" +
" -text rowsxcols\n");
" -help|-h Print help.\n" +
" -freq hz Set the machine frequency.\n" +
//" -debug level Set the debug level.\n" + // Don't display while not implemented (TODO)
" -start Start on load.\n" +
" -stats Print instruction statistics.\n" +
" -text rowsxcols Show and resize textual screen.\n" +
" -graph rowsxcols Show and resize graphical screen.\n");
}

int parseFreq(String s) {
Expand Down Expand Up @@ -136,6 +149,12 @@ void processArgs(String[] args) {
case "-h":
help = true;
break;
case "-stats":
stats = true;
break;
case "-start":
start = true;
break;
case "-freq":
freq = parseFreq(args[++last]);
break;
Expand Down
15 changes: 14 additions & 1 deletion src/sic/sim/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ public class Executor {
private Timer timer;
private int timerPeriod; // timer period in miliseconds
private int timerRepeat; // timer loop-repeat count

public final Breakpoints breakpoints;
private final DataBreakpoints dataBreakpoints;
public ActionListener onBreakpoint;
private boolean hasChanged;

private boolean printStats = false;

public Executor(final Machine machine) {
this.machine = machine;
this.breakpoints = new Breakpoints();
Expand All @@ -34,6 +37,13 @@ public Executor(final Machine machine) {
setSpeed(100);
}

public Executor(final Machine machine, Args arg) {
this(machine);

this.printStats = arg.isStats();
if (arg.getFreq() > 0) setSpeed(arg.getFreq());
}

public Machine getMachine() {
return machine;
}
Expand All @@ -44,7 +54,7 @@ public int getSpeed() {

public void setSpeed(int Hz) {
if (Hz > MaxSpeed) Hz = MaxSpeed;
timerRepeat = (Hz + 100) / 100;
timerRepeat = (Hz + 99) / 100;
timerPeriod = 1000 * timerRepeat / Hz;
}

Expand Down Expand Up @@ -75,6 +85,9 @@ private void timerTickUntil(Predicate<Machine> stopPredicate) {
// check if the same instruction: halt J halt
if (oldPC == machine.registers.getPC()) {
stop();
if (printStats) {
System.out.printf("Instructions executed: %d\n", machine.getInstructionCount());
}
break;
}
// check breakpoints
Expand Down
19 changes: 17 additions & 2 deletions src/sic/sim/MainView.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
public class MainView {
private final Executor executor;
private final Disassembler disassembler;
private final Args arg;

private JFrame mainFrame;
// core views
Expand All @@ -51,9 +52,10 @@ public class MainView {
private File lastLoadedFile;


public MainView(final Executor executor, Disassembler disassembler) {
public MainView(final Executor executor, Disassembler disassembler, Args arg) {
this.executor = executor;
this.disassembler = disassembler;
this.arg = arg;

cpuView = new CPUView(executor, disassembler);
disassemblyView = new DisassemblyView(executor, disassembler);
Expand Down Expand Up @@ -85,6 +87,15 @@ public MainView(final Executor executor, Disassembler disassembler) {
graphScreen = new GraphicalScreen(executor);
keyboard = new Keyboard(executor);

if (arg.isTextScr()) {
textScreen.setSize(arg.getTextScrCols(), arg.getTextScrRows());
textScreen.toggleView();
}
if (arg.isGraphScr()) {
graphScreen.setSize(arg.getGraphScrCols(), arg.getGraphScrRows());
graphScreen.toggleView();
}

Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
Expand Down Expand Up @@ -327,6 +338,10 @@ public void loadAsm(File file) {
watchView.clearLabelMap();
watchView.setLabelMap(program.getDataLabels());

if (arg.isStats()) {
System.out.printf("Instructions read: %d\n", program.countInstructions());
}

updateView();
}

Expand Down Expand Up @@ -381,7 +396,7 @@ private void showAboutMessage() {
JOptionPane.showMessageDialog(mainFrame, scrollPane, "License", JOptionPane.INFORMATION_MESSAGE);
});
Object[] options = { licenseButton, okButton };
JOptionPane.showOptionDialog(mainFrame, "SicTools: SIC/XE assembler and simulator 2.0\n\n(C) 2011-2018, Jurij Mihelič (jurij.mihelic@fri.uni-lj.si)\n\nContributors\nTomaž Dobravec (tomaz.dobravec@fri.uni-lj.si)\nNejc Kišek\nJakob Erzar\nand others, listed on GitHub", "About", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, okButton);
JOptionPane.showOptionDialog(mainFrame, "SicTools: SIC/XE assembler and simulator 2.0.1\n\n(C) 2011-2019, Jurij Mihelič (jurij.mihelic@fri.uni-lj.si)\n\nContributors\nTomaž Dobravec (tomaz.dobravec@fri.uni-lj.si)\nNejc Kišek\nJakob Erzar\nand others, listed on GitHub", "About", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, okButton);
}

}
4 changes: 2 additions & 2 deletions src/sic/sim/views/DisassemblyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ private void updateDisLine(int row, int addr, Command cmd) {
modelDis.setValueAt(cmd.operandToString(), row, 5);

// Try to resolve operand
Integer opAddress = cmd.resolveRelativeOperand(addr);
Integer opAddress = cmd.resolveOperandAddress(addr);
if (opAddress != null) {
String opText = toLabel(opAddress).equals("") ? Conversion.addrToHex(opAddress) : toLabel(opAddress);
String opText = toLabel(opAddress).equals("") ? "0x" + Conversion.addrToHex(opAddress) : toLabel(opAddress);
modelDis.setValueAt("=" + opText, row, 6);
} else {
modelDis.setValueAt("", row, 6);
Expand Down

0 comments on commit 05f1501

Please sign in to comment.