1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-07 19:29:27 +00:00

Whitespace and indentation canonicalization. That's what I get for using two editors.

This commit is contained in:
Seth J. Morabito 2008-12-27 21:09:47 -08:00
parent d54ad18b17
commit 8bcd8a4a75
18 changed files with 5249 additions and 5250 deletions

View File

@ -9,136 +9,136 @@ import com.loomcom.symon.exceptions.*;
*/
public class Bus {
// By default, our bus starts at 0, and goes up to 64K
private int startAddress = 0x0000;
private int endAddress = 0xffff;
// The CPU
private Cpu cpu;
// Ordered list of IO devices.
private SortedSet<Device> devices;
// By default, our bus starts at 0, and goes up to 64K
private int startAddress = 0x0000;
private int endAddress = 0xffff;
// The CPU
private Cpu cpu;
// Ordered list of IO devices.
private SortedSet<Device> devices;
public Bus(int size) {
this(0, size - 1);
}
public Bus(int size) {
this(0, size - 1);
}
public Bus(int startAddress, int endAddress) {
this.devices = new TreeSet<Device>();
this.startAddress = startAddress;
this.endAddress = endAddress;
}
public Bus(int startAddress, int endAddress) {
this.devices = new TreeSet<Device>();
this.startAddress = startAddress;
this.endAddress = endAddress;
}
public int startAddress() {
return startAddress;
}
public int startAddress() {
return startAddress;
}
public int endAddress() {
return endAddress;
}
public int endAddress() {
return endAddress;
}
public void addDevice(Device device)
throws MemoryRangeException {
// Make sure there's no memory overlap.
MemoryRange memRange = device.getMemoryRange();
for (Device d : devices) {
if (d.getMemoryRange().overlaps(memRange)) {
throw new MemoryRangeException("The device being added " +
"overlaps with an existing " +
"device.");
}
}
// Add the device
device.setBus(this);
devices.add(device);
}
public void addCpu(Cpu cpu) {
cpu.setBus(this);
this.cpu = cpu;
}
/**
* Returns true if the memory map is full, i.e., there are no
* gaps between any IO devices. All memory locations map to some
* device.
*/
public boolean isComplete() {
// Empty maps cannot be complete.
if (devices.isEmpty()) { return false; }
// Loop over devices and ensure they are contiguous.
MemoryRange prev = null;
int i = 0;
int length = devices.size();
for (Device d : devices) {
MemoryRange cur = d.getMemoryRange();
if (i == 0) {
// If the first entry doesn't start at 'startAddress', return false.
if (cur.startAddress() != startAddress) { return false; }
}
if (prev != null && i < length - 1) {
// Otherwise, compare previous map's end against this map's
// endAddress. They must be adjacent!
if (cur.startAddress() - 1 != prev.endAddress()) {
return false;
}
}
if (i == length - 1) {
// If the last entry doesn't end at endAddress, return false;
if (cur.endAddress() != endAddress) { return false; }
}
i++;
prev = cur;
}
// Must be complete.
return true;
}
public int read(int address) {
for (Device d : devices) {
MemoryRange range = d.getMemoryRange();
if (range.includes(address)) {
// Compute offset into this device's address space.
int devAddr = address - range.startAddress();
return d.read(devAddr);
}
}
// TODO: Raise access error.
throw new RuntimeException("Read failed! Device not found.");
}
public void write(int address, int value) {
for (Device d : devices) {
MemoryRange range = d.getMemoryRange();
if (range.includes(address)) {
// Compute offset into this device's address space.
int devAddr = address - range.startAddress();
d.write(devAddr, value);
return;
}
}
// TODO: Raise access error.
throw new RuntimeException("Write failed! Device not found.");
}
public SortedSet<Device> getDevices() {
// Expose a copy of the device list, not the original
return new TreeSet<Device>(devices);
}
public Cpu getCpu() {
return cpu;
}
public void loadProgram(int... program) {
int address = getCpu().getProgramCounter();
int i = 0;
for (int d : program) {
write(address + i++, d);
}
public void addDevice(Device device)
throws MemoryRangeException {
// Make sure there's no memory overlap.
MemoryRange memRange = device.getMemoryRange();
for (Device d : devices) {
if (d.getMemoryRange().overlaps(memRange)) {
throw new MemoryRangeException("The device being added " +
"overlaps with an existing " +
"device.");
}
}
// Add the device
device.setBus(this);
devices.add(device);
}
public void addCpu(Cpu cpu) {
cpu.setBus(this);
this.cpu = cpu;
}
/**
* Returns true if the memory map is full, i.e., there are no
* gaps between any IO devices. All memory locations map to some
* device.
*/
public boolean isComplete() {
// Empty maps cannot be complete.
if (devices.isEmpty()) { return false; }
// Loop over devices and ensure they are contiguous.
MemoryRange prev = null;
int i = 0;
int length = devices.size();
for (Device d : devices) {
MemoryRange cur = d.getMemoryRange();
if (i == 0) {
// If the first entry doesn't start at 'startAddress', return false.
if (cur.startAddress() != startAddress) { return false; }
}
if (prev != null && i < length - 1) {
// Otherwise, compare previous map's end against this map's
// endAddress. They must be adjacent!
if (cur.startAddress() - 1 != prev.endAddress()) {
return false;
}
}
if (i == length - 1) {
// If the last entry doesn't end at endAddress, return false;
if (cur.endAddress() != endAddress) { return false; }
}
i++;
prev = cur;
}
// Must be complete.
return true;
}
public int read(int address) {
for (Device d : devices) {
MemoryRange range = d.getMemoryRange();
if (range.includes(address)) {
// Compute offset into this device's address space.
int devAddr = address - range.startAddress();
return d.read(devAddr);
}
}
// TODO: Raise access error.
throw new RuntimeException("Read failed! Device not found.");
}
public void write(int address, int value) {
for (Device d : devices) {
MemoryRange range = d.getMemoryRange();
if (range.includes(address)) {
// Compute offset into this device's address space.
int devAddr = address - range.startAddress();
d.write(devAddr, value);
return;
}
}
// TODO: Raise access error.
throw new RuntimeException("Write failed! Device not found.");
}
public SortedSet<Device> getDevices() {
// Expose a copy of the device list, not the original
return new TreeSet<Device>(devices);
}
public Cpu getCpu() {
return cpu;
}
public void loadProgram(int... program) {
int address = getCpu().getProgramCounter();
int i = 0;
for (int d : program) {
write(address + i++, d);
}
}
}

View File

@ -4,69 +4,69 @@ import java.io.*;
public class CommandParser {
private BufferedReader in;
private BufferedWriter out;
private Simulator simulator;
private BufferedReader in;
private BufferedWriter out;
private Simulator simulator;
public CommandParser(InputStream i, OutputStream o, Simulator s) {
this.in = new BufferedReader(new InputStreamReader(i));
this.out = new BufferedWriter(new OutputStreamWriter(o));
this.simulator = s;
}
public CommandParser(InputStream i, OutputStream o, Simulator s) {
this.in = new BufferedReader(new InputStreamReader(i));
this.out = new BufferedWriter(new OutputStreamWriter(o));
this.simulator = s;
}
public void run() {
try {
String command = null;
greeting();
prompt();
while (!shouldQuit(command = readLine())) {
dispatch(command);
prompt();
}
writeLine("\n\nGoodbye!");
} catch (IOException ex) {
System.err.println("Error: " + ex.toString());
System.exit(1);
}
}
public void run() {
try {
String command = null;
greeting();
prompt();
while (!shouldQuit(command = readLine())) {
dispatch(command);
prompt();
}
writeLine("\n\nGoodbye!");
} catch (IOException ex) {
System.err.println("Error: " + ex.toString());
System.exit(1);
}
}
/**
* Dispatch the command.
*/
public void dispatch(String command) throws IOException {
writeLine("You entered: " + command);
}
/**
* Dispatch the command.
*/
public void dispatch(String command) throws IOException {
writeLine("You entered: " + command);
}
/*******************************************************************
* Private
*******************************************************************/
/*******************************************************************
* Private
*******************************************************************/
private void greeting() throws IOException {
writeLine("Welcome to the j6502 Simulator!");
}
private void greeting() throws IOException {
writeLine("Welcome to the j6502 Simulator!");
}
private void prompt() throws IOException {
out.write("j6502> ");
out.flush();
}
private void prompt() throws IOException {
out.write("j6502> ");
out.flush();
}
private String readLine() throws IOException {
String line = in.readLine();
if (line == null) { return null; }
return line.trim();
}
private String readLine() throws IOException {
String line = in.readLine();
if (line == null) { return null; }
return line.trim();
}
private void writeLine(String line) throws IOException {
out.write(line);
out.newLine();
out.flush();
}
private void writeLine(String line) throws IOException {
out.write(line);
out.newLine();
out.flush();
}
/**
* Returns true if the line is a quit.
*/
private boolean shouldQuit(String line) {
return (line == null || "q".equals(line.toLowerCase()));
}
/**
* Returns true if the line is a quit.
*/
private boolean shouldQuit(String line) {
return (line == null || "q".equals(line.toLowerCase()));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,248 +2,248 @@ package com.loomcom.symon;
public interface InstructionTable {
/**
* Enumeration of Addressing Modes.
*/
public enum Mode {
ACC {
public String toString() {
return "Accumulator";
}
},
/**
* Enumeration of Addressing Modes.
*/
public enum Mode {
ACC {
public String toString() {
return "Accumulator";
}
},
ABS {
public String toString() {
return "Absolute";
}
},
ABS {
public String toString() {
return "Absolute";
}
},
ABX {
public String toString() {
return "Absolute, X-indexed";
}
},
ABX {
public String toString() {
return "Absolute, X-indexed";
}
},
ABY {
public String toString() {
return "Absolute, Y-indexed";
}
},
ABY {
public String toString() {
return "Absolute, Y-indexed";
}
},
IMM {
public String toString() {
return "Immediate";
}
},
IMM {
public String toString() {
return "Immediate";
}
},
IMP {
public String toString() {
return "Implied";
}
},
IMP {
public String toString() {
return "Implied";
}
},
IND {
public String toString() {
return "Indirect";
}
},
IND {
public String toString() {
return "Indirect";
}
},
XIN {
public String toString() {
return "X-indexed Indirect";
}
},
XIN {
public String toString() {
return "X-indexed Indirect";
}
},
INY {
public String toString() {
return "Indirect, Y-indexedY";
}
},
INY {
public String toString() {
return "Indirect, Y-indexedY";
}
},
REL {
public String toString() {
return "Relative";
}
},
REL {
public String toString() {
return "Relative";
}
},
ZPG {
public String toString() {
return "Zeropage";
}
},
ZPG {
public String toString() {
return "Zeropage";
}
},
ZPX {
public String toString() {
return "Zeropage, X-indexed";
}
},
ZPX {
public String toString() {
return "Zeropage, X-indexed";
}
},
ZPY {
public String toString() {
return "Zeropage, Y-indexed";
}
},
ZPY {
public String toString() {
return "Zeropage, Y-indexed";
}
},
NUL {
public String toString() {
return "NULL";
}
}
}
NUL {
public String toString() {
return "NULL";
}
}
}
// 6502 opcodes. No 65C02 opcodes implemented.
/**
* Instruction opcode names.
*/
public static final String[] opcodeNames = {
"BRK", "ORA", null, null, null, "ORA", "ASL", null,
"PHP", "ORA", "ASL", null, null, "ORA", "ASL", null,
"BPL", "ORA", null, null, null, "ORA", "ASL", null,
"CLC", "ORA", null, null, null, "ORA", "ASL", null,
"JSR", "AND", null, null, "BIT", "AND", "ROL", null,
"PLP", "AND", "ROL", null, "BIT", "AND", "ROL", null,
"BMI", "AND", null, null, null, "AND", "ROL", null,
"SEC", "AND", null, null, null, "AND", "ROL", null,
"RTI", "EOR", null, null, null, "EOR", "LSR", null,
"PHA", "EOR", "LSR", null, "JMP", "EOR", "LSR", null,
"BVC", "EOR", null, null, null, "EOR", "LSR", null,
"CLI", "EOR", null, null, null, "EOR", "LSR", null,
"RTS", "ADC", null, null, null, "ADC", "ROR", null,
"PLA", "ADC", "ROR", null, "JMP", "ADC", "ROR", null,
"BVS", "ADC", null, null, null, "ADC", "ROR", null,
"SEI", "ADC", null, null, null, "ADC", "ROR", null,
"BCS", "STA", null, null, "STY", "STA", "STX", null,
"DEY", null, "TXA", null, "STY", "STA", "STX", null,
"BCC", "STA", null, null, "STY", "STA", "STX", null,
"TYA", "STA", "TXS", null, null, "STA", null, null,
"LDY", "LDA", "LDX", null, "LDY", "LDA", "LDX", null,
"TAY", "LDA", "TAX", null, "LDY", "LDA", "LDX", null,
null, "LDA", null, null, "LDY", "LDA", "LDX", null,
"CLV", "LDA", "TSX", null, "LDY", "LDA", "LDX", null,
"CPY", "CMP", null, null, "CPY", "CMP", "DEC", null,
"INY", "CMP", "DEX", null, "CPY", "CMP", "DEC", null,
"BNE", "CMP", null, null, null, "CMP", "DEC", null,
"CLD", "CMP", null, null, null, "CMP", "DEC", null,
"CPX", "SBC", null, null, "CPX", "SBC", "INC", null,
"INX", "SBC", "NOP", null, "CPX", "SBC", "INC", null,
"BEQ", "SBC", null, null, null, "SBC", "INC", null,
"SED", "SBC", null, null, null, "SBC", "INC", null
};
// 6502 opcodes. No 65C02 opcodes implemented.
/**
* Instruction addressing modes.
*/
public static final Mode[] instructionModes = {
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x00-0x03
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x04-0x07
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x08-0x0b
Mode.NUL, Mode.ABS, Mode.ABS, Mode.NUL, // 0x0c-0x0f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x10-0x13
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x14-0x17
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x18-0x1b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x1c-0x1f
Mode.ABS, Mode.XIN, Mode.NUL, Mode.NUL, // 0x20-0x23
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x24-0x27
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x28-0x2b
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x2c-0x2f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x30-0x33
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x34-0x37
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x38-0x3b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x3c-0x3f
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x40-0x43
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x44-0x47
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x48-0x4b
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x4c-0x4f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x50-0x53
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x54-0x57
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x58-0x5b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x5c-0x5f
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x60-0x63
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x64-0x67
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x68-0x6b
Mode.IND, Mode.ABS, Mode.ABS, Mode.NUL, // 0x6c-0x6f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x70-0x73
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x74-0x77
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x78-0x7b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x7c-0x7f
Mode.REL, Mode.XIN, Mode.NUL, Mode.NUL, // 0x80-0x83
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x84-0x87
Mode.IMP, Mode.NUL, Mode.IMP, Mode.NUL, // 0x88-0x8b
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x8c-0x8f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x90-0x93
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.NUL, // 0x94-0x97
Mode.IMP, Mode.ABX, Mode.IMP, Mode.NUL, // 0x98-0x9b
Mode.NUL, Mode.ABY, Mode.NUL, Mode.NUL, // 0x9c-0x9f
Mode.IMM, Mode.XIN, Mode.IMM, Mode.NUL, // 0xa0-0xa3
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xa4-0xa7
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xa8-0xab
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xac-0xaf
Mode.NUL, Mode.INY, Mode.NUL, Mode.NUL, // 0xb0-0xb3
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.NUL, // 0xb4-0xb7
Mode.IMP, Mode.ABX, Mode.IMP, Mode.NUL, // 0xb8-0xbb
Mode.ABX, Mode.ABY, Mode.ABY, Mode.NUL, // 0xbc-0xbf
Mode.IMM, Mode.XIN, Mode.NUL, Mode.NUL, // 0xc0-0xc3
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xc4-0xc7
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xc8-0xcb
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xcc-0xcf
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0xd0-0xd3
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0xd4-0xd7
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0xd8-0xdb
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0xdc-0xdf
Mode.IMM, Mode.XIN, Mode.NUL, Mode.NUL, // 0xe0-0xe3
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xe4-0xe7
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xe8-0xeb
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xec-0xef
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0xf0-0xf3
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0xf4-0xf7
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0xf8-0xfb
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL // 0xfc-0xff
};
/**
* Instruction opcode names.
*/
public static final String[] opcodeNames = {
"BRK", "ORA", null, null, null, "ORA", "ASL", null,
"PHP", "ORA", "ASL", null, null, "ORA", "ASL", null,
"BPL", "ORA", null, null, null, "ORA", "ASL", null,
"CLC", "ORA", null, null, null, "ORA", "ASL", null,
"JSR", "AND", null, null, "BIT", "AND", "ROL", null,
"PLP", "AND", "ROL", null, "BIT", "AND", "ROL", null,
"BMI", "AND", null, null, null, "AND", "ROL", null,
"SEC", "AND", null, null, null, "AND", "ROL", null,
"RTI", "EOR", null, null, null, "EOR", "LSR", null,
"PHA", "EOR", "LSR", null, "JMP", "EOR", "LSR", null,
"BVC", "EOR", null, null, null, "EOR", "LSR", null,
"CLI", "EOR", null, null, null, "EOR", "LSR", null,
"RTS", "ADC", null, null, null, "ADC", "ROR", null,
"PLA", "ADC", "ROR", null, "JMP", "ADC", "ROR", null,
"BVS", "ADC", null, null, null, "ADC", "ROR", null,
"SEI", "ADC", null, null, null, "ADC", "ROR", null,
"BCS", "STA", null, null, "STY", "STA", "STX", null,
"DEY", null, "TXA", null, "STY", "STA", "STX", null,
"BCC", "STA", null, null, "STY", "STA", "STX", null,
"TYA", "STA", "TXS", null, null, "STA", null, null,
"LDY", "LDA", "LDX", null, "LDY", "LDA", "LDX", null,
"TAY", "LDA", "TAX", null, "LDY", "LDA", "LDX", null,
null, "LDA", null, null, "LDY", "LDA", "LDX", null,
"CLV", "LDA", "TSX", null, "LDY", "LDA", "LDX", null,
"CPY", "CMP", null, null, "CPY", "CMP", "DEC", null,
"INY", "CMP", "DEX", null, "CPY", "CMP", "DEC", null,
"BNE", "CMP", null, null, null, "CMP", "DEC", null,
"CLD", "CMP", null, null, null, "CMP", "DEC", null,
"CPX", "SBC", null, null, "CPX", "SBC", "INC", null,
"INX", "SBC", "NOP", null, "CPX", "SBC", "INC", null,
"BEQ", "SBC", null, null, null, "SBC", "INC", null,
"SED", "SBC", null, null, null, "SBC", "INC", null
};
/**
* Size, in bytes, required for each instruction.
*/
public static final int[] instructionSizes = {
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 0, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
3, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 0, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 0, 3, 0, 0,
2, 2, 2, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
0, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0
};
/**
* Instruction addressing modes.
*/
public static final Mode[] instructionModes = {
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x00-0x03
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x04-0x07
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x08-0x0b
Mode.NUL, Mode.ABS, Mode.ABS, Mode.NUL, // 0x0c-0x0f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x10-0x13
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x14-0x17
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x18-0x1b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x1c-0x1f
Mode.ABS, Mode.XIN, Mode.NUL, Mode.NUL, // 0x20-0x23
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x24-0x27
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x28-0x2b
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x2c-0x2f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x30-0x33
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x34-0x37
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x38-0x3b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x3c-0x3f
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x40-0x43
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x44-0x47
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x48-0x4b
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x4c-0x4f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x50-0x53
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x54-0x57
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x58-0x5b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x5c-0x5f
Mode.IMP, Mode.XIN, Mode.NUL, Mode.NUL, // 0x60-0x63
Mode.NUL, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x64-0x67
Mode.IMP, Mode.IMM, Mode.ACC, Mode.NUL, // 0x68-0x6b
Mode.IND, Mode.ABS, Mode.ABS, Mode.NUL, // 0x6c-0x6f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x70-0x73
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0x74-0x77
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0x78-0x7b
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0x7c-0x7f
Mode.REL, Mode.XIN, Mode.NUL, Mode.NUL, // 0x80-0x83
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0x84-0x87
Mode.IMP, Mode.NUL, Mode.IMP, Mode.NUL, // 0x88-0x8b
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0x8c-0x8f
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0x90-0x93
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.NUL, // 0x94-0x97
Mode.IMP, Mode.ABX, Mode.IMP, Mode.NUL, // 0x98-0x9b
Mode.NUL, Mode.ABY, Mode.NUL, Mode.NUL, // 0x9c-0x9f
Mode.IMM, Mode.XIN, Mode.IMM, Mode.NUL, // 0xa0-0xa3
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xa4-0xa7
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xa8-0xab
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xac-0xaf
Mode.NUL, Mode.INY, Mode.NUL, Mode.NUL, // 0xb0-0xb3
Mode.ZPX, Mode.ZPX, Mode.ZPY, Mode.NUL, // 0xb4-0xb7
Mode.IMP, Mode.ABX, Mode.IMP, Mode.NUL, // 0xb8-0xbb
Mode.ABX, Mode.ABY, Mode.ABY, Mode.NUL, // 0xbc-0xbf
Mode.IMM, Mode.XIN, Mode.NUL, Mode.NUL, // 0xc0-0xc3
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xc4-0xc7
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xc8-0xcb
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xcc-0xcf
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0xd0-0xd3
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0xd4-0xd7
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0xd8-0xdb
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL, // 0xdc-0xdf
Mode.IMM, Mode.XIN, Mode.NUL, Mode.NUL, // 0xe0-0xe3
Mode.ZPG, Mode.ZPG, Mode.ZPG, Mode.NUL, // 0xe4-0xe7
Mode.IMP, Mode.IMM, Mode.IMP, Mode.NUL, // 0xe8-0xeb
Mode.ABS, Mode.ABS, Mode.ABS, Mode.NUL, // 0xec-0xef
Mode.REL, Mode.INY, Mode.NUL, Mode.NUL, // 0xf0-0xf3
Mode.NUL, Mode.ZPX, Mode.ZPX, Mode.NUL, // 0xf4-0xf7
Mode.IMP, Mode.ABY, Mode.NUL, Mode.NUL, // 0xf8-0xfb
Mode.NUL, Mode.ABX, Mode.ABX, Mode.NUL // 0xfc-0xff
};
/**
* Number of clock cycles required for each instruction
*/
public static final int[] instructionClocks = {
7, 6, 0, 0, 0, 3, 5, 0, 3, 2, 2, 0, 0, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
6, 6, 0, 0, 3, 3, 5, 0, 4, 2, 2, 0, 4, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
6, 6, 0, 0, 0, 3, 5, 0, 3, 2, 2, 0, 3, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
6, 6, 0, 0, 0, 3, 5, 0, 4, 2, 2, 0, 5, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
2, 6, 0, 0, 3, 3, 3, 0, 2, 0, 2, 0, 4, 4, 4, 0,
2, 6, 0, 0, 4, 4, 4, 0, 2, 5, 2, 0, 0, 5, 0, 0,
2, 6, 2, 0, 3, 3, 3, 0, 2, 2, 2, 0, 4, 4, 4, 0,
0, 5, 0, 0, 4, 4, 4, 0, 2, 4, 2, 0, 4, 4, 4, 0,
2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0
};
/**
* Size, in bytes, required for each instruction.
*/
public static final int[] instructionSizes = {
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 0, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
3, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
1, 2, 0, 0, 0, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 0, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 0, 3, 0, 0,
2, 2, 2, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
0, 2, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0,
2, 2, 0, 0, 2, 2, 2, 0, 1, 2, 1, 0, 3, 3, 3, 0,
2, 2, 0, 0, 0, 2, 2, 0, 1, 3, 0, 0, 0, 3, 3, 0
};
/**
* Number of clock cycles required for each instruction
*/
public static final int[] instructionClocks = {
7, 6, 0, 0, 0, 3, 5, 0, 3, 2, 2, 0, 0, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
6, 6, 0, 0, 3, 3, 5, 0, 4, 2, 2, 0, 4, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
6, 6, 0, 0, 0, 3, 5, 0, 3, 2, 2, 0, 3, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
6, 6, 0, 0, 0, 3, 5, 0, 4, 2, 2, 0, 5, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
2, 6, 0, 0, 3, 3, 3, 0, 2, 0, 2, 0, 4, 4, 4, 0,
2, 6, 0, 0, 4, 4, 4, 0, 2, 5, 2, 0, 0, 5, 0, 0,
2, 6, 2, 0, 3, 3, 3, 0, 2, 2, 2, 0, 4, 4, 4, 0,
0, 5, 0, 0, 4, 4, 4, 0, 2, 4, 2, 0, 4, 4, 4, 0,
2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0,
2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0,
2, 5, 0, 0, 0, 4, 6, 0, 2, 4, 0, 0, 0, 4, 7, 0
};
}

View File

@ -11,77 +11,77 @@ import com.loomcom.symon.exceptions.*;
*/
public class MemoryRange implements Comparable<MemoryRange> {
/** The starting address of the memory range. */
public int startAddress;
/** The ending address of the memory range. */
public int endAddress;
/** The starting address of the memory range. */
public int startAddress;
/** The ending address of the memory range. */
public int endAddress;
public MemoryRange(int startAddress, int endAddress)
throws MemoryRangeException {
if (startAddress < 0 || endAddress < 0) {
throw new MemoryRangeException("Addresses cannot be less than 0.");
}
if (startAddress >= endAddress) {
throw new MemoryRangeException("End address must be greater " +
"than start address.");
}
this.startAddress = startAddress;
this.endAddress = endAddress;
}
public MemoryRange(int startAddress, int endAddress)
throws MemoryRangeException {
if (startAddress < 0 || endAddress < 0) {
throw new MemoryRangeException("Addresses cannot be less than 0.");
}
if (startAddress >= endAddress) {
throw new MemoryRangeException("End address must be greater " +
"than start address.");
}
this.startAddress = startAddress;
this.endAddress = endAddress;
}
/**
* @returns the starting address.
*/
public int startAddress() {
return startAddress;
}
/**
* @returns the starting address.
*/
public int startAddress() {
return startAddress;
}
/**
* @returns the ending address.
*/
public int endAddress() {
return endAddress;
}
/**
* @returns the ending address.
*/
public int endAddress() {
return endAddress;
}
/**
* Checks for address inclusion in the range.
*
* @returns true if the address is included within this range,
* false otherwise.
*/
public boolean includes(int address) {
return (address <= endAddress &&
address >= startAddress);
}
/**
* Checks for address inclusion in the range.
*
* @returns true if the address is included within this range,
* false otherwise.
*/
public boolean includes(int address) {
return (address <= endAddress &&
address >= startAddress);
}
/**
* Checks for overlapping memory ranges.
*
* @returns true if this range overlaps in any way with the other.
*/
public boolean overlaps(MemoryRange other) {
return (this.includes(other.startAddress()) ||
other.includes(this.startAddress()));
}
/**
* Checks for overlapping memory ranges.
*
* @returns true if this range overlaps in any way with the other.
*/
public boolean overlaps(MemoryRange other) {
return (this.includes(other.startAddress()) ||
other.includes(this.startAddress()));
}
// Implementation of Comparable interface
public int compareTo(MemoryRange other) {
if (other == null) {
throw new NullPointerException("Cannot compare to null.");
}
if (this == other) {
return 0;
}
Integer thisStartAddr = new Integer(this.startAddress());
Integer thatStartAddr = new Integer(other.startAddress());
return thisStartAddr.compareTo(thatStartAddr);
}
// Implementation of Comparable interface
public int compareTo(MemoryRange other) {
if (other == null) {
throw new NullPointerException("Cannot compare to null.");
}
if (this == other) {
return 0;
}
Integer thisStartAddr = new Integer(this.startAddress());
Integer thatStartAddr = new Integer(other.startAddress());
return thisStartAddr.compareTo(thatStartAddr);
}
public String toString() {
StringBuffer desc = new StringBuffer("@");
desc.append(String.format("0x%04x", startAddress));
desc.append("-");
desc.append(String.format("0x%04x", endAddress));
return desc.toString();
}
public String toString() {
StringBuffer desc = new StringBuffer("@");
desc.append(String.format("0x%04x", startAddress));
desc.append("-");
desc.append(String.format("0x%04x", endAddress));
return desc.toString();
}
}

View File

@ -10,151 +10,150 @@ import com.loomcom.symon.exceptions.*;
public class Profiler implements InstructionTable {
public static void main(String[] args) {
// new Profiler().profileMemoryReads();
// new Profiler().dumpOpCodes();
new Profiler().profileProgram();
}
public static void main(String[] args) {
// new Profiler().profileMemoryReads();
// new Profiler().dumpOpCodes();
new Profiler().profileProgram();
}
public void dumpOpCodes() {
for (int i = 0; i < 0x100; i++) {
String name = opcodeNames[i];
Mode mode = instructionModes[i];
public void dumpOpCodes() {
for (int i = 0; i < 0x100; i++) {
String name = opcodeNames[i];
Mode mode = instructionModes[i];
System.out.print(String.format("0x%02x: ", i));
System.out.print(String.format("0x%02x: ", i));
if (name == null) {
System.out.println("n/a");
} else {
System.out.println(name + " (" + mode + ")");
}
}
}
if (name == null) {
System.out.println("n/a");
} else {
System.out.println(name + " (" + mode + ")");
}
}
}
public void profileProgram() {
Bus bus = new Bus(0, 65535);
Cpu cpu = new Cpu();
public void profileProgram() {
Bus bus = new Bus(0, 65535);
Cpu cpu = new Cpu();
bus.addCpu(cpu);
bus.addCpu(cpu);
try {
bus.addDevice(new Memory(0x0000, 0x10000));
} catch (MemoryRangeException ex) {
System.err.println("Memory Range Exception! " + ex.getMessage());
return;
}
try {
bus.addDevice(new Memory(0x0000, 0x10000));
} catch (MemoryRangeException ex) {
System.err.println("Memory Range Exception! " + ex.getMessage());
return;
}
// Start at 0x0300
bus.write(0xfffc, 0x00);
bus.write(0xfffd, 0x03);
// Start at 0x0300
bus.write(0xfffc, 0x00);
bus.write(0xfffd, 0x03);
// The program to run, in an infinite loop.
bus.write(0x0300, 0xa9); // LDA #$FF
bus.write(0x0301, 0xff);
bus.write(0x0302, 0xea); // NOP
bus.write(0x0303, 0xea); // NOP
bus.write(0x0304, 0xa0); // LDY #$1A
bus.write(0x0305, 0x1a);
bus.write(0x0306, 0xea); // NOP
bus.write(0x0307, 0xea); // NOP
bus.write(0x0308, 0xa2); // LDX #$03
bus.write(0x0309, 0x03);
// The program to run, in an infinite loop.
bus.write(0x0300, 0xa9); // LDA #$FF
bus.write(0x0301, 0xff);
bus.write(0x0302, 0xea); // NOP
bus.write(0x0303, 0xea); // NOP
bus.write(0x0304, 0xa0); // LDY #$1A
bus.write(0x0305, 0x1a);
bus.write(0x0306, 0xea); // NOP
bus.write(0x0307, 0xea); // NOP
bus.write(0x0308, 0xa2); // LDX #$03
bus.write(0x0309, 0x03);
bus.write(0x030a, 0xa9); // LDA #$00
bus.write(0x030b, 0x00);
bus.write(0x030c, 0xa2); // LDX #$00
bus.write(0x030d, 0x00);
bus.write(0x030e, 0xa0); // LDY #$00
bus.write(0x030f, 0x00);
bus.write(0x030a, 0xa9); // LDA #$00
bus.write(0x030b, 0x00);
bus.write(0x030c, 0xa2); // LDX #$00
bus.write(0x030d, 0x00);
bus.write(0x030e, 0xa0); // LDY #$00
bus.write(0x030f, 0x00);
bus.write(0x0310, 0x4c); // JMP #$0300
bus.write(0x0311, 0x00);
bus.write(0x0312, 0x03);
bus.write(0x0310, 0x4c); // JMP #$0300
bus.write(0x0311, 0x00);
bus.write(0x0312, 0x03);
long sum = 0;
long sum = 0;
// The number of times to run the program
long iters = 1000;
// The number of times to run the program
long iters = 1000;
// The number of steps to take when running the program
long steps = 100000;
// The number of steps to take when running the program
long steps = 100000;
for (int i = 0; i < iters; i++) {
long startTime = System.nanoTime();
for (int i = 0; i < iters; i++) {
long startTime = System.nanoTime();
// Reset the CPU (does not clear memory)
cpu.reset();
// Reset the CPU (does not clear memory)
cpu.reset();
for (int j = 0; j < steps; j++) {
cpu.step();
}
for (int j = 0; j < steps; j++) {
cpu.step();
}
long endTime = System.nanoTime();
long diff = endTime - startTime;
long endTime = System.nanoTime();
long diff = endTime - startTime;
sum += diff;
}
sum += diff;
}
long average = sum / iters;
long totalSteps = steps * iters;
long avgStep = sum / totalSteps;
long average = sum / iters;
long totalSteps = steps * iters;
long avgStep = sum / totalSteps;
System.out.println("Total instructions executed: " +
String.format("%,d", totalSteps));
System.out.println("Total time taken: " +
String.format("%,d us", sum / 1000));
System.out.println("Average time per step: " +
avgStep + " ns ");
}
System.out.println("Total instructions executed: " +
String.format("%,d", totalSteps));
System.out.println("Total time taken: " +
String.format("%,d us", sum / 1000));
System.out.println("Average time per step: " +
avgStep + " ns ");
}
public void profileMemoryReads() {
// Create a bus.
Bus b = new Bus(0, 65535);
public void profileMemoryReads() {
// Create a bus.
Bus b = new Bus(0, 65535);
try {
// Create eight devices, each 8KB, to fill the bus.
b.addDevice(new Memory(0x0000, 0x2000)); // 8KB @ $0000-$1fff
b.addDevice(new Memory(0x2000, 0x2000)); // 8KB @ $2000-$3fff
b.addDevice(new Memory(0x4000, 0x2000)); // 8KB @ $4000-$5fff
b.addDevice(new Memory(0x6000, 0x2000)); // 8KB @ $6000-$7fff
b.addDevice(new Memory(0x8000, 0x2000)); // 8KB @ $8000-$9fff
b.addDevice(new Memory(0xa000, 0x2000)); // 8KB @ $a000-$bfff
b.addDevice(new Memory(0xc000, 0x2000)); // 8KB @ $c000-$dfff
b.addDevice(new Memory(0xe000, 0x2000)); // 8KB @ $e000-$ffff
} catch (MemoryRangeException ex) {
System.err.println("Memory Range Exception! " + ex.getMessage());
return;
}
try {
// Create eight devices, each 8KB, to fill the bus.
b.addDevice(new Memory(0x0000, 0x2000)); // 8KB @ $0000-$1fff
b.addDevice(new Memory(0x2000, 0x2000)); // 8KB @ $2000-$3fff
b.addDevice(new Memory(0x4000, 0x2000)); // 8KB @ $4000-$5fff
b.addDevice(new Memory(0x6000, 0x2000)); // 8KB @ $6000-$7fff
b.addDevice(new Memory(0x8000, 0x2000)); // 8KB @ $8000-$9fff
b.addDevice(new Memory(0xa000, 0x2000)); // 8KB @ $a000-$bfff
b.addDevice(new Memory(0xc000, 0x2000)); // 8KB @ $c000-$dfff
b.addDevice(new Memory(0xe000, 0x2000)); // 8KB @ $e000-$ffff
} catch (MemoryRangeException ex) {
System.err.println("Memory Range Exception! " + ex.getMessage());
return;
}
// Read memory
long sum = 0;
long average = 0;
// Read memory
long sum = 0;
long average = 0;
long iters = 500;
for (int i = 0; i < iters; i++) {
long startTime = System.nanoTime();
// Read and assign to a buffer
int buf = 0;
for (int j = 0; j < 0xffff; j++) {
buf = b.read(j);
if (buf != 0xff) {
System.out.println("WARNING! MEMORY SHOULD HAVE " +
"BEEN $FF, WAS: " + buf);
System.exit(0);
}
}
long iters = 500;
for (int i = 0; i < iters; i++) {
long startTime = System.nanoTime();
// Read and assign to a buffer
int buf = 0;
for (int j = 0; j < 0xffff; j++) {
buf = b.read(j);
if (buf != 0xff) {
System.out.println("WARNING! MEMORY SHOULD HAVE " +
"BEEN $FF, WAS: " + buf);
System.exit(0);
}
}
long endTime = System.nanoTime();
long diff = endTime - startTime;
long endTime = System.nanoTime();
long diff = endTime - startTime;
sum += diff;
average = sum / (i + 1);
}
System.out.println("Average time to read 64KB: " + average +
" ns (" + (average / 1000) + " us)");
System.out.println("Average time to read one byte: " +
sum / (64 * 1024 * iters) + " ns");
}
sum += diff;
average = sum / (i + 1);
}
System.out.println("Average time to read 64KB: " + average +
" ns (" + (average / 1000) + " us)");
System.out.println("Average time to read one byte: " +
sum / (64 * 1024 * iters) + " ns");
}
}

View File

@ -8,107 +8,107 @@ import com.loomcom.symon.exceptions.*;
*/
public class Simulator {
/**
* Command-line parser used by this simulator.
*/
private CommandParser parser;
/**
* Command-line parser used by this simulator.
*/
private CommandParser parser;
/**
* The CPU itself.
*/
private Cpu cpu;
/**
* The CPU itself.
*/
private Cpu cpu;
/**
* The Bus responsible for routing memory read/write requests to the
* correct IO devices.
*/
private Bus bus;
/**
* The Bus responsible for routing memory read/write requests to the
* correct IO devices.
*/
private Bus bus;
public Simulator() throws MemoryRangeException {
cpu = new Cpu();
bus = new Bus(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(new Memory(0x0000, 0x10000));
parser = new CommandParser(System.in, System.out, this);
}
public Simulator() throws MemoryRangeException {
cpu = new Cpu();
bus = new Bus(0x0000, 0xffff);
bus.addCpu(cpu);
bus.addDevice(new Memory(0x0000, 0x10000));
parser = new CommandParser(System.in, System.out, this);
}
public void run() {
parser.run();
}
public void run() {
parser.run();
}
public void step() {
}
public void step() {
}
public int read(int address) {
return 0;
}
public int read(int address) {
return 0;
}
public void write(int address, int value) {
}
public void write(int address, int value) {
}
public void loadProgram(int address, int[] program) {
// Reset interrupt vector
int hi = (address&0xff00)>>>8;
int lo = address&0x00ff;
bus.write(0xfffc, lo);
bus.write(0xfffd, hi);
public void loadProgram(int address, int[] program) {
// Reset interrupt vector
int hi = (address&0xff00)>>>8;
int lo = address&0x00ff;
bus.write(0xfffc, lo);
bus.write(0xfffd, hi);
int i = 0;
for (int d : program) {
bus.write(address + i++, d);
}
}
int i = 0;
for (int d : program) {
bus.write(address + i++, d);
}
}
/**
* A test method.
*/
/**
* A test method.
*/
public void runTest() {
int[] program = {
0xa9, // LDA #$FF
0xff,
0xa0, // LDY #$1A
0x1a,
0xa2, // LDX #$90
0x90,
0xa2, // LDX #$02
0x02,
0x49, // EOR #$FF
0xff,
0xa9, // LDA #$00
0x00,
0xa2, // LDX #$00
0x00,
0x29, // AND #$FF
0xff,
0xa0, // LDY #$00
0x00,
0x4c, // JMP #$0300
0x00,
0x03
};
public void runTest() {
int[] program = {
0xa9, // LDA #$FF
0xff,
0xa0, // LDY #$1A
0x1a,
0xa2, // LDX #$90
0x90,
0xa2, // LDX #$02
0x02,
0x49, // EOR #$FF
0xff,
0xa9, // LDA #$00
0x00,
0xa2, // LDX #$00
0x00,
0x29, // AND #$FF
0xff,
0xa0, // LDY #$00
0x00,
0x4c, // JMP #$0300
0x00,
0x03
};
loadProgram(0x0300, program);
cpu.reset();
loadProgram(0x0300, program);
cpu.reset();
int steps = program.length;
int steps = program.length;
for (int i = 0; i <= steps; i++) {
cpu.step();
System.out.println(cpu.toString());
}
for (int i = 0; i <= steps; i++) {
cpu.step();
System.out.println(cpu.toString());
}
}
}
/**
* Main simulator routine.
*/
public static void main(String[] args) {
try {
new Simulator().runTest();
} catch (MemoryRangeException ex) {
System.err.println("Error: " + ex.toString());
}
}
/**
* Main simulator routine.
*/
public static void main(String[] args) {
try {
new Simulator().runTest();
} catch (MemoryRangeException ex) {
System.err.println("Error: " + ex.toString());
}
}
}

View File

@ -9,65 +9,65 @@ import com.loomcom.symon.exceptions.*;
public abstract class Device implements Comparable<Device> {
/** The memory range for this device. */
private MemoryRange memoryRange;
/** The memory range for this device. */
private MemoryRange memoryRange;
/** The name of the device. */
private String name;
/** The name of the device. */
private String name;
/** Reference to the bus where this Device is attached. */
private Bus bus;
/** Reference to the bus where this Device is attached. */
private Bus bus;
public Device(int address, int size, String name)
throws MemoryRangeException {
this.memoryRange = new MemoryRange(address, address + size - 1);
this.name = name;
}
public Device(int address, int size, String name)
throws MemoryRangeException {
this.memoryRange = new MemoryRange(address, address + size - 1);
this.name = name;
}
public Device(int address, int size) throws MemoryRangeException {
this(address, size, null);
}
public Device(int address, int size) throws MemoryRangeException {
this(address, size, null);
}
/* Methods required to be implemented by inheriting classes. */
public abstract void write(int address, int data);
public abstract int read(int address);
public abstract String toString();
/* Methods required to be implemented by inheriting classes. */
public abstract void write(int address, int data);
public abstract int read(int address);
public abstract String toString();
public void setBus(Bus bus) {
this.bus = bus;
}
public void setBus(Bus bus) {
this.bus = bus;
}
public MemoryRange getMemoryRange() {
return memoryRange;
}
public MemoryRange getMemoryRange() {
return memoryRange;
}
public int endAddress() {
return memoryRange.endAddress();
}
public int endAddress() {
return memoryRange.endAddress();
}
public int startAddress() {
return memoryRange.startAddress();
}
public int startAddress() {
return memoryRange.startAddress();
}
public String getName() {
return name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
/**
* Compares two devices. The sort order is defined by the sort
* order of the device's memory ranges.
*/
public int compareTo(Device other) {
if (other == null) {
throw new NullPointerException("Cannot compare to null.");
}
if (this == other) {
return 0;
}
return getMemoryRange().compareTo(other.getMemoryRange());
}
/**
* Compares two devices. The sort order is defined by the sort
* order of the device's memory ranges.
*/
public int compareTo(Device other) {
if (other == null) {
throw new NullPointerException("Cannot compare to null.");
}
if (this == other) {
return 0;
}
return getMemoryRange().compareTo(other.getMemoryRange());
}
}

View File

@ -7,33 +7,33 @@ import com.loomcom.symon.exceptions.*;
public class Memory extends Device {
private boolean readOnly;
private int[] mem;
private boolean readOnly;
private int[] mem;
public Memory(int address, int size, boolean readOnly)
throws MemoryRangeException {
super(address, size, "RW Memory");
this.readOnly = readOnly;
this.mem = new int[size];
// Initialize all locations to 0xff
Arrays.fill(this.mem, 0xff);
}
public Memory(int address, int size, boolean readOnly)
throws MemoryRangeException {
super(address, size, "RW Memory");
this.readOnly = readOnly;
this.mem = new int[size];
// Initialize all locations to 0xff
Arrays.fill(this.mem, 0xff);
}
public Memory(int address, int size)
throws MemoryRangeException {
this(address, size, false);
}
public Memory(int address, int size)
throws MemoryRangeException {
this(address, size, false);
}
public void write(int address, int data) {
this.mem[address] = data;
}
public void write(int address, int data) {
this.mem[address] = data;
}
public int read(int address) {
return this.mem[address];
}
public int read(int address) {
return this.mem[address];
}
public String toString() {
return "Memory: " + getMemoryRange().toString();
}
public String toString() {
return "Memory: " + getMemoryRange().toString();
}
}

View File

@ -5,7 +5,7 @@ package com.loomcom.symon.exceptions;
* accessed.
*/
public class MemoryAccessException extends Exception {
public MemoryAccessException(String msg) {
super(msg);
}
public MemoryAccessException(String msg) {
super(msg);
}
}

View File

@ -4,7 +4,7 @@ package com.loomcom.symon.exceptions;
* Exception that will be thrown if devices conflict in the IO map.
*/
public class MemoryRangeException extends Exception {
public MemoryRangeException(String msg) {
super(msg);
}
public MemoryRangeException(String msg) {
super(msg);
}
}

View File

@ -12,114 +12,114 @@ import java.util.*;
*/
public class BusTest extends TestCase {
public BusTest(String testName) {
super(testName);
}
public BusTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(BusTest.class);
}
public static Test suite() {
return new TestSuite(BusTest.class);
}
public void testCreatingWithStartAndEndAddresses() {
Bus b = null;
public void testCreatingWithStartAndEndAddresses() {
Bus b = null;
b = new Bus(0x00, 0xff);
assertEquals(0x00, b.startAddress());
assertEquals(0xff, b.endAddress());
b = new Bus(0x00, 0xff);
assertEquals(0x00, b.startAddress());
assertEquals(0xff, b.endAddress());
b = new Bus(0x20, 0xea);
assertEquals(0x20, b.startAddress());
assertEquals(0xea, b.endAddress());
}
b = new Bus(0x20, 0xea);
assertEquals(0x20, b.startAddress());
assertEquals(0xea, b.endAddress());
}
public void testCreatingWithSize() {
Bus b = null;
public void testCreatingWithSize() {
Bus b = null;
b = new Bus(256);
assertEquals(0x00, b.startAddress());
assertEquals(0xff, b.endAddress());
b = new Bus(256);
assertEquals(0x00, b.startAddress());
assertEquals(0xff, b.endAddress());
b = new Bus(4096);
assertEquals(0x000, b.startAddress());
assertEquals(0xfff, b.endAddress());
b = new Bus(4096);
assertEquals(0x000, b.startAddress());
assertEquals(0xfff, b.endAddress());
b = new Bus(65536);
assertEquals(0x0000, b.startAddress());
assertEquals(0xffff, b.endAddress());
}
b = new Bus(65536);
assertEquals(0x0000, b.startAddress());
assertEquals(0xffff, b.endAddress());
}
public void testAddDevice() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x0100, true);
Device rom = new Memory(0x0100, 0x0200, false);
public void testAddDevice() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x0100, true);
Device rom = new Memory(0x0100, 0x0200, false);
Bus b = new Bus(0x0000, 0xffff);
Bus b = new Bus(0x0000, 0xffff);
assertEquals(0, b.getDevices().size());
b.addDevice(memory);
assertEquals(1, b.getDevices().size());
b.addDevice(rom);
assertEquals(2, b.getDevices().size());
}
assertEquals(0, b.getDevices().size());
b.addDevice(memory);
assertEquals(1, b.getDevices().size());
b.addDevice(rom);
assertEquals(2, b.getDevices().size());
}
public void testOverlappingDevicesShouldFail() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x0100, true);
Device rom = new Memory(0x00ff, 0x0200, false);
public void testOverlappingDevicesShouldFail() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x0100, true);
Device rom = new Memory(0x00ff, 0x0200, false);
Bus b = new Bus(0x0000, 0xffff);
Bus b = new Bus(0x0000, 0xffff);
b.addDevice(memory);
b.addDevice(memory);
try {
b.addDevice(rom);
fail("Should have thrown a MemoryRangeException.");
} catch (MemoryRangeException ex) {
// expected
}
}
try {
b.addDevice(rom);
fail("Should have thrown a MemoryRangeException.");
} catch (MemoryRangeException ex) {
// expected
}
}
public void testIsCompleteWithFirstDeviceNotStartingAtStartAddress() throws MemoryRangeException {
Device memory = new Memory(0x00ff, 0xff00, true);
public void testIsCompleteWithFirstDeviceNotStartingAtStartAddress() throws MemoryRangeException {
Device memory = new Memory(0x00ff, 0xff00, true);
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
}
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
}
public void testIsCompleteWithOneDevice() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x10000, true);
public void testIsCompleteWithOneDevice() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x10000, true);
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertTrue("Address space should have been complete!", b.isComplete());
}
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertTrue("Address space should have been complete!", b.isComplete());
}
public void testIsCompleteWithTwoDevices() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x8000, true);
Device rom = new Memory(0x8000, 0x8000, false);
public void testIsCompleteWithTwoDevices() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x8000, true);
Device rom = new Memory(0x8000, 0x8000, false);
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(rom);
assertTrue("Address space should have been complete!", b.isComplete());
}
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(rom);
assertTrue("Address space should have been complete!", b.isComplete());
}
public void testIsCompleteWithThreeDevices() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x8000, true);
Device rom1 = new Memory(0x8000, 0x4000, false);
Device rom2 = new Memory(0xC000, 0x4000, false);
public void testIsCompleteWithThreeDevices() throws MemoryRangeException {
Device memory = new Memory(0x0000, 0x8000, true);
Device rom1 = new Memory(0x8000, 0x4000, false);
Device rom2 = new Memory(0xC000, 0x4000, false);
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(rom1);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(rom2);
assertTrue("Address space should have been complete!", b.isComplete());
}
Bus b = new Bus(0x0000, 0xffff);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(memory);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(rom1);
assertFalse("Address space was unexpectedly complete!", b.isComplete());
b.addDevice(rom2);
assertTrue("Address space should have been complete!", b.isComplete());
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -10,349 +10,349 @@ import com.loomcom.symon.exceptions.*;
*/
public class CpuTest extends TestCase {
private Cpu cpu;
private Bus bus;
private Memory mem;
public CpuTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(CpuTest.class);
}
public void setUp() throws MemoryRangeException {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
bus.addCpu(cpu);
bus.addDevice(mem);
// All test programs start at 0x0200;
bus.write(0xfffc, 0x00);
bus.write(0xfffd, 0x02);
cpu.reset();
}
public void testReset() {
assertEquals(0, cpu.getAccumulator());
assertEquals(0, cpu.getXRegister());
assertEquals(0, cpu.getYRegister());
assertEquals(0x0200, cpu.getProgramCounter());
assertFalse(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
}
public void testStack() {
cpu.stackPush(0x13);
assertEquals(0x13, cpu.stackPop());
cpu.stackPush(0x12);
assertEquals(0x12, cpu.stackPop());
for (int i = 0x00; i <= 0xff; i++) {
cpu.stackPush(i);
}
for (int i = 0xff; i >= 0x00; i--) {
assertEquals(i, cpu.stackPop());
}
}
public void testStackPush() {
assertEquals(0xff, cpu.getStackPointer());
assertEquals(0xff, bus.read(0x1ff));
cpu.stackPush(0x06);
assertEquals(0xfe, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
cpu.stackPush(0x05);
assertEquals(0xfd, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
cpu.stackPush(0x04);
assertEquals(0xfc, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
cpu.stackPush(0x03);
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
assertEquals(0x03, bus.read(0x1fc));
cpu.stackPush(0x02);
assertEquals(0xfa, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
assertEquals(0x03, bus.read(0x1fc));
assertEquals(0x02, bus.read(0x1fb));
cpu.stackPush(0x01);
assertEquals(0xf9, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
assertEquals(0x03, bus.read(0x1fc));
assertEquals(0x02, bus.read(0x1fb));
assertEquals(0x01, bus.read(0x1fa));
}
public void testStackPushWrapsAroundToStackTop() {
cpu.setStackPointer(0x01);
cpu.stackPush(0x01);
assertEquals(0x01, bus.read(0x101));
assertEquals(0x00, cpu.getStackPointer());
cpu.stackPush(0x02);
assertEquals(0x02, bus.read(0x100));
assertEquals(0xff, cpu.getStackPointer());
cpu.stackPush(0x03);
assertEquals(0x03, bus.read(0x1ff));
assertEquals(0xfe, cpu.getStackPointer());
}
public void testStackPop() {
bus.write(0x1ff, 0x06);
bus.write(0x1fe, 0x05);
bus.write(0x1fd, 0x04);
bus.write(0x1fc, 0x03);
bus.write(0x1fb, 0x02);
bus.write(0x1fa, 0x01);
cpu.setStackPointer(0xf9);
assertEquals(0x01, cpu.stackPop());
assertEquals(0xfa, cpu.getStackPointer());
assertEquals(0x02, cpu.stackPop());
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x03, cpu.stackPop());
assertEquals(0xfc, cpu.getStackPointer());
assertEquals(0x04, cpu.stackPop());
assertEquals(0xfd, cpu.getStackPointer());
assertEquals(0x05, cpu.stackPop());
assertEquals(0xfe, cpu.getStackPointer());
assertEquals(0x06, cpu.stackPop());
assertEquals(0xff, cpu.getStackPointer());
}
public void testStackPopWrapsAroundToStackBottom() {
bus.write(0x1ff, 0x0f); // top of stack
bus.write(0x100, 0xf0); // bottom of stack
bus.write(0x101, 0xf1);
bus.write(0x102, 0xf2);
cpu.setStackPointer(0xfe);
assertEquals(0x0f, cpu.stackPop());
assertEquals(0xff, cpu.getStackPointer());
assertEquals(0xf0, cpu.stackPop());
assertEquals(0x00, cpu.getStackPointer());
assertEquals(0xf1, cpu.stackPop());
assertEquals(0x01, cpu.getStackPointer());
assertEquals(0xf2, cpu.stackPop());
assertEquals(0x02, cpu.getStackPointer());
}
public void testStackPeekDoesNotAlterStackPointer() {
int val = 0;
assertEquals(0xff, cpu.stackPeek());
assertEquals(0xff, cpu.getStackPointer());
cpu.stackPush(0x01);
assertEquals(0x01, cpu.stackPeek());
assertEquals(0xfe, cpu.getStackPointer());
cpu.stackPush(0x02);
assertEquals(0x02, cpu.stackPeek());
assertEquals(0xfd, cpu.getStackPointer());
cpu.stackPush(0x03);
assertEquals(0x03, cpu.stackPeek());
assertEquals(0xfc, cpu.getStackPointer());
cpu.stackPush(0x04);
assertEquals(0x04, cpu.stackPeek());
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x04, cpu.stackPeek());
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x04, cpu.stackPeek());
assertEquals(0xfb, cpu.getStackPointer());
}
public void testGetProcessorStatus() {
// By default, no flags are set. Remember, bit 5
// is always '1'.
assertEquals(0x20, cpu.getProcessorStatus());
cpu.setCarryFlag();
assertEquals(0x21, cpu.getProcessorStatus());
cpu.setZeroFlag();
assertEquals(0x23, cpu.getProcessorStatus());
cpu.setIrqDisableFlag();
assertEquals(0x27, cpu.getProcessorStatus());
cpu.setDecimalModeFlag();
assertEquals(0x2f, cpu.getProcessorStatus());
cpu.setBreakFlag();
assertEquals(0x3f, cpu.getProcessorStatus());
cpu.setOverflowFlag();
assertEquals(0x7f, cpu.getProcessorStatus());
cpu.setNegativeFlag();
assertEquals(0xff, cpu.getProcessorStatus());
cpu.clearCarryFlag();
assertEquals(0xfe, cpu.getProcessorStatus());
cpu.clearZeroFlag();
assertEquals(0xfc, cpu.getProcessorStatus());
cpu.clearIrqDisableFlag();
assertEquals(0xf8, cpu.getProcessorStatus());
cpu.clearDecimalModeFlag();
assertEquals(0xf0, cpu.getProcessorStatus());
cpu.clearBreakFlag();
assertEquals(0xe0, cpu.getProcessorStatus());
cpu.clearOverflowFlag();
assertEquals(0xa0, cpu.getProcessorStatus());
cpu.clearNegativeFlag();
assertEquals(0x20, cpu.getProcessorStatus());
}
public void testSetProcessorStatus() {
// Default
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY);
assertTrue(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE);
assertTrue(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW|Cpu.P_BREAK);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertTrue(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertTrue(cpu.getDecimalModeFlag());
assertTrue(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL|
Cpu.P_IRQ_DISABLE);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertTrue(cpu.getIrqDisableFlag());
assertTrue(cpu.getDecimalModeFlag());
assertTrue(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20);
assertFalse(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x00);
assertFalse(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
}
public void testAddress() {
assertEquals(0xf1ea, cpu.address(0xea, 0xf1));
assertEquals(0x00ea, cpu.address(0xea, 0x00));
assertEquals(0xf100, cpu.address(0x00, 0xf1));
assertEquals(0x1234, cpu.address(0x34, 0x12));
assertEquals(0xffff, cpu.address(0xff, 0xff));
}
private Cpu cpu;
private Bus bus;
private Memory mem;
public CpuTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(CpuTest.class);
}
public void setUp() throws MemoryRangeException {
this.cpu = new Cpu();
this.bus = new Bus(0x0000, 0xffff);
this.mem = new Memory(0x0000, 0x10000);
bus.addCpu(cpu);
bus.addDevice(mem);
// All test programs start at 0x0200;
bus.write(0xfffc, 0x00);
bus.write(0xfffd, 0x02);
cpu.reset();
}
public void testReset() {
assertEquals(0, cpu.getAccumulator());
assertEquals(0, cpu.getXRegister());
assertEquals(0, cpu.getYRegister());
assertEquals(0x0200, cpu.getProgramCounter());
assertFalse(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
}
public void testStack() {
cpu.stackPush(0x13);
assertEquals(0x13, cpu.stackPop());
cpu.stackPush(0x12);
assertEquals(0x12, cpu.stackPop());
for (int i = 0x00; i <= 0xff; i++) {
cpu.stackPush(i);
}
for (int i = 0xff; i >= 0x00; i--) {
assertEquals(i, cpu.stackPop());
}
}
public void testStackPush() {
assertEquals(0xff, cpu.getStackPointer());
assertEquals(0xff, bus.read(0x1ff));
cpu.stackPush(0x06);
assertEquals(0xfe, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
cpu.stackPush(0x05);
assertEquals(0xfd, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
cpu.stackPush(0x04);
assertEquals(0xfc, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
cpu.stackPush(0x03);
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
assertEquals(0x03, bus.read(0x1fc));
cpu.stackPush(0x02);
assertEquals(0xfa, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
assertEquals(0x03, bus.read(0x1fc));
assertEquals(0x02, bus.read(0x1fb));
cpu.stackPush(0x01);
assertEquals(0xf9, cpu.getStackPointer());
assertEquals(0x06, bus.read(0x1ff));
assertEquals(0x05, bus.read(0x1fe));
assertEquals(0x04, bus.read(0x1fd));
assertEquals(0x03, bus.read(0x1fc));
assertEquals(0x02, bus.read(0x1fb));
assertEquals(0x01, bus.read(0x1fa));
}
public void testStackPushWrapsAroundToStackTop() {
cpu.setStackPointer(0x01);
cpu.stackPush(0x01);
assertEquals(0x01, bus.read(0x101));
assertEquals(0x00, cpu.getStackPointer());
cpu.stackPush(0x02);
assertEquals(0x02, bus.read(0x100));
assertEquals(0xff, cpu.getStackPointer());
cpu.stackPush(0x03);
assertEquals(0x03, bus.read(0x1ff));
assertEquals(0xfe, cpu.getStackPointer());
}
public void testStackPop() {
bus.write(0x1ff, 0x06);
bus.write(0x1fe, 0x05);
bus.write(0x1fd, 0x04);
bus.write(0x1fc, 0x03);
bus.write(0x1fb, 0x02);
bus.write(0x1fa, 0x01);
cpu.setStackPointer(0xf9);
assertEquals(0x01, cpu.stackPop());
assertEquals(0xfa, cpu.getStackPointer());
assertEquals(0x02, cpu.stackPop());
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x03, cpu.stackPop());
assertEquals(0xfc, cpu.getStackPointer());
assertEquals(0x04, cpu.stackPop());
assertEquals(0xfd, cpu.getStackPointer());
assertEquals(0x05, cpu.stackPop());
assertEquals(0xfe, cpu.getStackPointer());
assertEquals(0x06, cpu.stackPop());
assertEquals(0xff, cpu.getStackPointer());
}
public void testStackPopWrapsAroundToStackBottom() {
bus.write(0x1ff, 0x0f); // top of stack
bus.write(0x100, 0xf0); // bottom of stack
bus.write(0x101, 0xf1);
bus.write(0x102, 0xf2);
cpu.setStackPointer(0xfe);
assertEquals(0x0f, cpu.stackPop());
assertEquals(0xff, cpu.getStackPointer());
assertEquals(0xf0, cpu.stackPop());
assertEquals(0x00, cpu.getStackPointer());
assertEquals(0xf1, cpu.stackPop());
assertEquals(0x01, cpu.getStackPointer());
assertEquals(0xf2, cpu.stackPop());
assertEquals(0x02, cpu.getStackPointer());
}
public void testStackPeekDoesNotAlterStackPointer() {
int val = 0;
assertEquals(0xff, cpu.stackPeek());
assertEquals(0xff, cpu.getStackPointer());
cpu.stackPush(0x01);
assertEquals(0x01, cpu.stackPeek());
assertEquals(0xfe, cpu.getStackPointer());
cpu.stackPush(0x02);
assertEquals(0x02, cpu.stackPeek());
assertEquals(0xfd, cpu.getStackPointer());
cpu.stackPush(0x03);
assertEquals(0x03, cpu.stackPeek());
assertEquals(0xfc, cpu.getStackPointer());
cpu.stackPush(0x04);
assertEquals(0x04, cpu.stackPeek());
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x04, cpu.stackPeek());
assertEquals(0xfb, cpu.getStackPointer());
assertEquals(0x04, cpu.stackPeek());
assertEquals(0xfb, cpu.getStackPointer());
}
public void testGetProcessorStatus() {
// By default, no flags are set. Remember, bit 5
// is always '1'.
assertEquals(0x20, cpu.getProcessorStatus());
cpu.setCarryFlag();
assertEquals(0x21, cpu.getProcessorStatus());
cpu.setZeroFlag();
assertEquals(0x23, cpu.getProcessorStatus());
cpu.setIrqDisableFlag();
assertEquals(0x27, cpu.getProcessorStatus());
cpu.setDecimalModeFlag();
assertEquals(0x2f, cpu.getProcessorStatus());
cpu.setBreakFlag();
assertEquals(0x3f, cpu.getProcessorStatus());
cpu.setOverflowFlag();
assertEquals(0x7f, cpu.getProcessorStatus());
cpu.setNegativeFlag();
assertEquals(0xff, cpu.getProcessorStatus());
cpu.clearCarryFlag();
assertEquals(0xfe, cpu.getProcessorStatus());
cpu.clearZeroFlag();
assertEquals(0xfc, cpu.getProcessorStatus());
cpu.clearIrqDisableFlag();
assertEquals(0xf8, cpu.getProcessorStatus());
cpu.clearDecimalModeFlag();
assertEquals(0xf0, cpu.getProcessorStatus());
cpu.clearBreakFlag();
assertEquals(0xe0, cpu.getProcessorStatus());
cpu.clearOverflowFlag();
assertEquals(0xa0, cpu.getProcessorStatus());
cpu.clearNegativeFlag();
assertEquals(0x20, cpu.getProcessorStatus());
}
public void testSetProcessorStatus() {
// Default
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY);
assertTrue(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE);
assertTrue(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW|Cpu.P_BREAK);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertTrue(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertTrue(cpu.getDecimalModeFlag());
assertTrue(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20|Cpu.P_CARRY|Cpu.P_NEGATIVE|Cpu.P_ZERO|
Cpu.P_OVERFLOW|Cpu.P_BREAK|Cpu.P_DECIMAL|
Cpu.P_IRQ_DISABLE);
assertTrue(cpu.getCarryFlag());
assertTrue(cpu.getZeroFlag());
assertTrue(cpu.getIrqDisableFlag());
assertTrue(cpu.getDecimalModeFlag());
assertTrue(cpu.getBreakFlag());
assertTrue(cpu.getOverflowFlag());
assertTrue(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x20);
assertFalse(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
cpu.setProcessorStatus(0x00);
assertFalse(cpu.getCarryFlag());
assertFalse(cpu.getZeroFlag());
assertFalse(cpu.getIrqDisableFlag());
assertFalse(cpu.getDecimalModeFlag());
assertFalse(cpu.getBreakFlag());
assertFalse(cpu.getOverflowFlag());
assertFalse(cpu.getNegativeFlag());
}
public void testAddress() {
assertEquals(0xf1ea, cpu.address(0xea, 0xf1));
assertEquals(0x00ea, cpu.address(0xea, 0x00));
assertEquals(0xf100, cpu.address(0x00, 0xf1));
assertEquals(0x1234, cpu.address(0x34, 0x12));
assertEquals(0xffff, cpu.address(0xff, 0xff));
}
}

File diff suppressed because it is too large Load Diff

View File

@ -12,129 +12,129 @@ import com.loomcom.symon.exceptions.*;
*/
public class MemoryRangeTest extends TestCase {
public MemoryRangeTest(String testName) {
super(testName);
}
public MemoryRangeTest(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(MemoryRangeTest.class);
}
public static Test suite() {
return new TestSuite(MemoryRangeTest.class);
}
public void testConstructorThrowsWhenInvalid() {
// All of these should raise MemoryRangeException
doInvalidMemoryRangeTest(0, -1);
doInvalidMemoryRangeTest(-1, 0);
doInvalidMemoryRangeTest(0, 0);
doInvalidMemoryRangeTest(1, 1);
doInvalidMemoryRangeTest(1, 0);
doInvalidMemoryRangeTest(2, 1);
}
public void testConstructorThrowsWhenInvalid() {
// All of these should raise MemoryRangeException
doInvalidMemoryRangeTest(0, -1);
doInvalidMemoryRangeTest(-1, 0);
doInvalidMemoryRangeTest(0, 0);
doInvalidMemoryRangeTest(1, 1);
doInvalidMemoryRangeTest(1, 0);
doInvalidMemoryRangeTest(2, 1);
}
public void testConstructorShouldNotThrow() throws MemoryRangeException {
// None of these should throw.
new MemoryRange(0, 1);
new MemoryRange(0, 2);
new MemoryRange(1, 2);
new MemoryRange(2, 10);
}
public void testConstructorShouldNotThrow() throws MemoryRangeException {
// None of these should throw.
new MemoryRange(0, 1);
new MemoryRange(0, 2);
new MemoryRange(1, 2);
new MemoryRange(2, 10);
}
public void testStartAddress() throws MemoryRangeException {
MemoryRange r = new MemoryRange(0x101, 0x202);
assertEquals(0x101, r.startAddress());
}
public void testStartAddress() throws MemoryRangeException {
MemoryRange r = new MemoryRange(0x101, 0x202);
assertEquals(0x101, r.startAddress());
}
public void testEndAddress() throws MemoryRangeException {
MemoryRange r = new MemoryRange(0x101, 0x202);
assertEquals(0x202, r.endAddress());
}
public void testEndAddress() throws MemoryRangeException {
MemoryRange r = new MemoryRange(0x101, 0x202);
assertEquals(0x202, r.endAddress());
}
public void testOverlaps() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0100, 0x01ff);
MemoryRange b = new MemoryRange(0x0200, 0x02ff);
public void testOverlaps() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0100, 0x01ff);
MemoryRange b = new MemoryRange(0x0200, 0x02ff);
MemoryRange c = new MemoryRange(0x01a0, 0x01af); // inside a
MemoryRange d = new MemoryRange(0x00ff, 0x01a0); // overlaps a
MemoryRange e = new MemoryRange(0x01a0, 0x02ff); // overlaps a
MemoryRange c = new MemoryRange(0x01a0, 0x01af); // inside a
MemoryRange d = new MemoryRange(0x00ff, 0x01a0); // overlaps a
MemoryRange e = new MemoryRange(0x01a0, 0x02ff); // overlaps a
MemoryRange f = new MemoryRange(0x02a0, 0x02af); // inside b
MemoryRange g = new MemoryRange(0x01ff, 0x02a0); // overlaps b
MemoryRange h = new MemoryRange(0x02a0, 0x03ff); // overlaps b
MemoryRange f = new MemoryRange(0x02a0, 0x02af); // inside b
MemoryRange g = new MemoryRange(0x01ff, 0x02a0); // overlaps b
MemoryRange h = new MemoryRange(0x02a0, 0x03ff); // overlaps b
assertFalse(a.overlaps(b));
assertFalse(b.overlaps(a));
assertFalse(a.overlaps(b));
assertFalse(b.overlaps(a));
assertTrue(a.overlaps(c));
assertTrue(c.overlaps(a));
assertTrue(a.overlaps(c));
assertTrue(c.overlaps(a));
assertTrue(a.overlaps(d));
assertTrue(d.overlaps(a));
assertTrue(a.overlaps(d));
assertTrue(d.overlaps(a));
assertTrue(a.overlaps(e));
assertTrue(e.overlaps(a));
assertTrue(a.overlaps(e));
assertTrue(e.overlaps(a));
assertTrue(b.overlaps(f));
assertTrue(f.overlaps(b));
assertTrue(b.overlaps(f));
assertTrue(f.overlaps(b));
assertTrue(b.overlaps(g));
assertTrue(g.overlaps(b));
assertTrue(b.overlaps(g));
assertTrue(g.overlaps(b));
assertTrue(b.overlaps(h));
assertTrue(h.overlaps(b));
}
assertTrue(b.overlaps(h));
assertTrue(h.overlaps(b));
}
public void testToString() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0abf, 0xff00);
assertEquals("@0x0abf-0xff00", a.toString());
public void testToString() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0abf, 0xff00);
assertEquals("@0x0abf-0xff00", a.toString());
MemoryRange b = new MemoryRange(0, 255);
assertEquals("@0x0000-0x00ff", b.toString());
MemoryRange b = new MemoryRange(0, 255);
assertEquals("@0x0000-0x00ff", b.toString());
MemoryRange c = new MemoryRange(0, 65535);
assertEquals("@0x0000-0xffff", c.toString());
}
MemoryRange c = new MemoryRange(0, 65535);
assertEquals("@0x0000-0xffff", c.toString());
}
public void testIncluded() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0100, 0x0fff);
public void testIncluded() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0100, 0x0fff);
assertFalse(a.includes(0x0000));
assertFalse(a.includes(0x00ff));
assertTrue(a.includes(0x0100));
assertTrue(a.includes(0x0fff));
assertFalse(a.includes(0x1000));
assertFalse(a.includes(0xffff));
}
assertFalse(a.includes(0x0000));
assertFalse(a.includes(0x00ff));
assertTrue(a.includes(0x0100));
assertTrue(a.includes(0x0fff));
assertFalse(a.includes(0x1000));
assertFalse(a.includes(0xffff));
}
public void testCompareTo() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0000, 0x0100);
MemoryRange b = new MemoryRange(0x0200, 0x0300);
MemoryRange c = new MemoryRange(0x0200, 0x0300);
// a < b
assertTrue(a.compareTo(b) == -1);
// b > a
assertTrue(b.compareTo(a) == 1);
// Identity
assertTrue(a.compareTo(a) == 0);
assertTrue(b.compareTo(b) == 0);
// Equality
assertTrue(b.compareTo(c) == 0);
assertTrue(c.compareTo(b) == 0);
// Null
try {
a.compareTo(null);
fail("Should have thrown NullPointerException");
} catch (NullPointerException ex) {
// expected
}
}
public void testCompareTo() throws MemoryRangeException {
MemoryRange a = new MemoryRange(0x0000, 0x0100);
MemoryRange b = new MemoryRange(0x0200, 0x0300);
MemoryRange c = new MemoryRange(0x0200, 0x0300);
// a < b
assertTrue(a.compareTo(b) == -1);
// b > a
assertTrue(b.compareTo(a) == 1);
// Identity
assertTrue(a.compareTo(a) == 0);
assertTrue(b.compareTo(b) == 0);
// Equality
assertTrue(b.compareTo(c) == 0);
assertTrue(c.compareTo(b) == 0);
// Null
try {
a.compareTo(null);
fail("Should have thrown NullPointerException");
} catch (NullPointerException ex) {
// expected
}
}
// Helper method.
public void doInvalidMemoryRangeTest(int start, int end) {
try {
new MemoryRange(start, end);
fail("MemoryRangeException should have been thrown.");
} catch (MemoryRangeException e) {
// Expected.
}
}
// Helper method.
public void doInvalidMemoryRangeTest(int start, int end) {
try {
new MemoryRange(start, end);
fail("MemoryRangeException should have been thrown.");
} catch (MemoryRangeException e) {
// Expected.
}
}
}

View File

@ -8,26 +8,26 @@ import junit.framework.TestSuite;
* Unit test for the j6502 Simulator class.
*/
public class SimulatorTest extends TestCase {
/**
* Create the test case
*
* @param testName name of the test case
*/
public SimulatorTest(String testName) {
super(testName);
}
/**
* Create the test case
*
* @param testName name of the test case
*/
public SimulatorTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(SimulatorTest.class);
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(SimulatorTest.class);
}
/**
* Rigourous Test :-)
*/
public void testSimulator() {
assertTrue(true);
}
/**
* Rigourous Test :-)
*/
public void testSimulator() {
assertTrue(true);
}
}