Skip to content
36 changes: 3 additions & 33 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,6 @@ out
addons/out
/.project
*.class
tests/linker/factorial/factdemo.obj
tests/linker/factorial/linfac2_demo.obj
tests/linker/factorial/linfac_demo.obj
tests/linker/factorial/outfac.obj
tests/linker/multi/out.obj
tests/linker/nametest/extd.log
tests/linker/nametest/extd.lst
tests/linker/nametest/first.log
tests/linker/nametest/first.lst
tests/linker/nametest/nmtest.obj
tests/linker/nametest/test.log
tests/linker/nametest/test.lst
tests/linker/one/out.obj
tests/linker/partial/prtial.obj
tests/linker/stack/demostack.obj
tests/linker/factorial/ending.log
tests/linker/factorial/ending.lst
tests/linker/factorial/fact.log
tests/linker/factorial/fact.lst
tests/linker/factorial/linked.obj
tests/linker/factorial/main.log
tests/linker/factorial/main.lst
tests/linker/factorial/print.log
tests/linker/factorial/print.lst
tests/linker/factorial/print2.asm
tests/linker/factorial/print2.log
tests/linker/factorial/print2.lst
tests/linker/factorial/prt2fc.obj
tests/linker/factorial/stack.log
tests/linker/factorial/stack.lst
tests/linker/one2/linked.obj
tests/linker/one2/prog.log
tests/linker/one2/prog.lst
tests/**/*.log
tests/**/*.lst
tests/**/*.obj
2 changes: 1 addition & 1 deletion src/sic/asm/parsing/OperandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private Command parseF1(Location loc, String label, Mnemonic mnemonic) {
}

private Command parseF2n(Location loc, String label, Mnemonic mnemonic) throws AsmError {
int n = parser.readInt(0, 15);
int n = parser.readInt(0, 255);
return new InstructionF2n(loc, label, mnemonic, n);
}

Expand Down
3 changes: 2 additions & 1 deletion src/sic/ast/instructions/InstructionF2n.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public String operandToString() {

@Override
public void emitRawCode(byte[] data, int loc) {
emitRawCode(data, loc, number, 0);
// The original "specification" is a bit unclear about the size of number.
emitRawCode(data, loc, (number>>4)&0xf, number&0xf);
}

@Override
Expand Down
35 changes: 35 additions & 0 deletions src/sic/common/Opcode.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,41 @@ public class Opcode {
"TD", null, "STSW", "SSK", "SIO", "HIO", "TIO", null
};

public static boolean isF1(int opcode) {
switch (opcode) {
case FLOAT, FIX, NORM, SIO, HIO, TIO:
return true;
}
return false;
}

public static boolean isF2(int opcode) {
switch (opcode) {
case ADDR, SUBR, MULR, DIVR, COMPR, SHIFTL, SHIFTR, RMO, CLEAR, TIXR, SVC:
return true;
}
return false;
}

public static boolean isF34(int opcode) {
switch (opcode) {
case STA, STX, STL, STCH, STB, STS, STF, STT, STSW, JEQ, JGT, JLT, J,
RSUB, JSUB, LDA, LDX, LDL, LDCH, LDB, LDS, LDF, LDT, ADD, SUB, MUL,
DIV, AND, OR, COMP, TIX, RD, WD, TD, ADDF, SUBF, MULF, DIVF, COMPF,
LPS, STI, SSK:
return true;
}
return false;
}

public static boolean isPrivileged(int opcode) {
switch (opcode) {
case HIO, LPS, RD, SIO, SSK, STI, STSW, TD, TIO, WD:
return true;
}
return false;
}

public static String getName(int opcode) {
// 0 <= opcode <= 256
return opcodeToNames[opcode >> 2];
Expand Down
20 changes: 10 additions & 10 deletions src/sic/disasm/Disassembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ public void prev(int count) {
}

private int fetchAddr;
protected int fetch() {
protected int fetchByte() {
if (fetchAddr < 0) return 0;
if (fetchAddr > SICXE.MAX_ADDR) return 0;
return machine.memory.getByteRaw(fetchAddr++);
}

public Instruction disassemble(int addr) {
this.fetchAddr = addr;
int opcode = fetch();
int opcode = fetchByte();
String name = Opcode.getName(opcode & 0xFC);
if (name == null) return null;
Mnemonic mnemonic = mnemonics.get(name);
Expand All @@ -81,24 +81,24 @@ public Instruction disassemble(int addr) {
case F1:
return new InstructionF1(loc, "", mnemonic);
case F2n:
return new InstructionF2n(loc, "", mnemonic, fetch() >> 4);
return new InstructionF2n(loc, "", mnemonic, fetchByte() >> 4);
case F2r:
return new InstructionF2r(loc, "", mnemonic, fetch() >> 4);
return new InstructionF2r(loc, "", mnemonic, fetchByte() >> 4);
case F2rn:
b1 = fetch();
b1 = fetchByte();
return new InstructionF2rn(loc, "", mnemonic, (b1 & 0xF0) >> 4, (b1 & 0x0F) + 1);
case F2rr:
b1 = fetch();
b1 = fetchByte();
return new InstructionF2rr(loc, "", mnemonic, (b1 & 0xF0) >> 4, b1 & 0x0F);
case F3:
fetch(); fetch(); // should be zero?
fetchByte(); fetchByte(); // should be zero?
return new InstructionF3(loc, "", mnemonic);
case F3m:
case F4m:
b1 = fetch(); b2 = fetch();
b1 = fetchByte(); b2 = fetchByte();
Flags flags = new Flags(opcode, b1);
if (flags.isExtended()) {
int operand = flags.operandF4(b1, b2, fetch());
int operand = flags.operandF4(b1, b2, fetchByte());
mnemonic = mnemonics.get("+" + name);
return new InstructionF4m(loc, "", mnemonic, flags, operand, null);
}
Expand Down Expand Up @@ -138,4 +138,4 @@ public int getNextPCLocation() {
return getLocationAfter(machine.registers.getPC());
}

}
}
11 changes: 7 additions & 4 deletions src/sic/sim/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sic.sim.breakpoints.DataBreakpointException;
import sic.sim.breakpoints.DataBreakpoints;
import sic.sim.vm.Machine;
import sic.sim.vm.Interrupt;

import java.awt.event.ActionListener;
import java.util.Timer;
Expand Down Expand Up @@ -67,7 +68,7 @@ private void timerTickUntil(Predicate<Machine> stopPredicate) {
int oldPC = machine.registers.getPC();

try {
machine.execute();
machine.step();

if (!dataBreakpoints.isEnabled()) {
// Enable data breakpoints in case they got disabled because they were triggered.
Expand All @@ -83,7 +84,9 @@ private void timerTickUntil(Predicate<Machine> stopPredicate) {

hasChanged = true;
// check if the same instruction: halt J halt
if (oldPC == machine.registers.getPC()) {
if (oldPC == machine.registers.getPC()
&& !machine.registers.intEnabled(Interrupt.IntClass.TIMER)
&& !machine.registers.intEnabled(Interrupt.IntClass.IO)) {
stop();
if (printStats) {
System.out.printf("Instructions executed: %d\n", machine.getInstructionCount());
Expand Down Expand Up @@ -137,7 +140,7 @@ public void step() {
dataBreakpoints.disable();

try {
machine.execute();
machine.step();
} catch (DataBreakpointException ex) {
// Shouldn't be triggered when breakpoints are disabled
}
Expand Down Expand Up @@ -170,7 +173,7 @@ public void runToAddress(int stopAddress) {
* Step out of the current sub procedure
*/
public void stepOut() {
Integer addressAfterLastJSUB = machine.getAddressBelowLastJSUB();
Integer addressAfterLastJSUB = machine.getReturnAddress();
if (addressAfterLastJSUB == null) return;
runUntil(machine -> machine.registers.getPC() == addressAfterLastJSUB);
}
Expand Down
Loading