First work toward moving to a Swing UI for the simulator.

This commit is contained in:
Seth Morabito committed 2012-04-22 20:49:18 -07:00
1 parent b44859e096
commit a1d07bf223
31 files changed
+2765 -2437

No files matched your search

@@ -6,38 +6,43 @@ import com.loomcom.symon.exceptions.*;
public class Memory extends Device {
private boolean readOnly;
private int[] mem;
private boolean readOnly;
private int[] mem;
/* Initialize all locations to 0x00 (BRK) */
private static final int DEFAULT_FILL = 0x00;
/* Initialize all locations to 0x00 (BRK) */
private static final int DEFAULT_FILL = 0x00;
public Memory(int address, int size, boolean readOnly)
throws MemoryRangeException {
super(address, size, (readOnly ? "RO Memory" : "RW Memory"));
this.readOnly = readOnly;
this.mem = new int[size];
Arrays.fill(this.mem, DEFAULT_FILL);
}
public Memory(int address, int size) throws MemoryRangeException {
this(address, size, false);
}
public void write(int address, int data) throws MemoryAccessException {
if (readOnly) {
throw new MemoryAccessException("Cannot write to read-only memory at address " + address);
} else {
this.mem[address] = data;
public Memory(int address, int size, boolean readOnly)
throws MemoryRangeException {
super(address, size, (readOnly ? "RO Memory" : "RW Memory"));
this.readOnly = readOnly;
this.mem = new int[size];
this.fill(DEFAULT_FILL);
}
}
public int read(int address) throws MemoryAccessException {
return this.mem[address];
}
public Memory(int address, int size) throws MemoryRangeException {
this(address, size, false);
}
public String toString() {
return "Memory: " + getMemoryRange().toString();
}
public void write(int address, int data) throws MemoryAccessException {
if (readOnly) {
throw new MemoryAccessException("Cannot write to read-only memory at address " + address);
} else {
this.mem[address] = data;
}
}
public int read(int address) throws MemoryAccessException {
return this.mem[address];
}
public void fill(int val) {
Arrays.fill(this.mem, val);
}
public String toString() {
return "Memory: " + getMemoryRange().toString();
}
}