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

Devices use start/end address

This commit is contained in:
Max840 2013-12-23 23:31:51 -05:00
parent a5af522c5c
commit d1a05aeb2b
5 changed files with 20 additions and 20 deletions

View File

@ -152,7 +152,7 @@ public class Simulator {
this.via = new Via(VIA_BASE); this.via = new Via(VIA_BASE);
this.bus = new Bus(BUS_BOTTOM, BUS_TOP); this.bus = new Bus(BUS_BOTTOM, BUS_TOP);
this.cpu = new Cpu(); this.cpu = new Cpu();
this.ram = new Memory(MEMORY_BASE, MEMORY_SIZE, false); this.ram = new Memory(MEMORY_BASE, MEMORY_BASE + MEMORY_SIZE - 1, false);
bus.addCpu(cpu); bus.addCpu(cpu);
bus.addDevice(ram); bus.addDevice(ram);
@ -163,11 +163,11 @@ public class Simulator {
File romImage = new File("rom.bin"); File romImage = new File("rom.bin");
if (romImage.canRead()) { if (romImage.canRead()) {
logger.info("Loading ROM image from file " + romImage); logger.info("Loading ROM image from file " + romImage);
this.rom = Memory.makeROM(ROM_BASE, ROM_SIZE, romImage); this.rom = Memory.makeROM(ROM_BASE, ROM_BASE + ROM_SIZE - 1, romImage);
} else { } else {
logger.info("Default ROM file " + romImage + logger.info("Default ROM file " + romImage +
" not found, loading empty R/W memory image."); " not found, loading empty R/W memory image.");
this.rom = Memory.makeRAM(ROM_BASE, ROM_SIZE); this.rom = Memory.makeRAM(ROM_BASE, ROM_BASE + ROM_SIZE - 1);
} }
bus.addDevice(rom); bus.addDevice(rom);
} }
@ -568,7 +568,7 @@ public class Simulator {
bus.removeDevice(rom); bus.removeDevice(rom);
} }
// Load the new ROM image // Load the new ROM image
rom = Memory.makeROM(ROM_BASE, ROM_SIZE, romFile); rom = Memory.makeROM(ROM_BASE, ROM_BASE + ROM_SIZE - 1, romFile);
bus.addDevice(rom); bus.addDevice(rom);
// Now, reset // Now, reset

View File

@ -75,7 +75,7 @@ public class Acia extends Device {
private boolean txEmpty = true; private boolean txEmpty = true;
public Acia(int address) throws MemoryRangeException { public Acia(int address) throws MemoryRangeException {
super(address, ACIA_SIZE, "ACIA"); super(address, address + ACIA_SIZE - 1, "ACIA");
this.baseAddress = address; this.baseAddress = address;
} }

View File

@ -41,14 +41,14 @@ public abstract class Device implements Comparable<Device> {
/** Reference to the bus where this Device is attached. */ /** Reference to the bus where this Device is attached. */
private Bus bus; private Bus bus;
public Device(int address, int size, String name) public Device(int startAddress, int endAddress, String name)
throws MemoryRangeException { throws MemoryRangeException {
this.memoryRange = new MemoryRange(address, address + size - 1); this.memoryRange = new MemoryRange(startAddress, endAddress);
this.name = name; this.name = name;
} }
public Device(int address, int size) throws MemoryRangeException { public Device(int startAddress, int endAddress) throws MemoryRangeException {
this(address, size, null); this(startAddress, endAddress, null);
} }
/* Methods required to be implemented by inheriting classes. */ /* Methods required to be implemented by inheriting classes. */

View File

@ -38,26 +38,26 @@ public class Memory extends Device {
/* Initialize all locations to 0x00 (BRK) */ /* Initialize all locations to 0x00 (BRK) */
private static final int DEFAULT_FILL = 0x00; private static final int DEFAULT_FILL = 0x00;
public Memory(int address, int size, boolean readOnly) public Memory(int startAddress, int endAddress, boolean readOnly)
throws MemoryRangeException { throws MemoryRangeException {
super(address, size, (readOnly ? "RO Memory" : "RW Memory")); super(startAddress, endAddress, (readOnly ? "RO Memory" : "RW Memory"));
this.readOnly = readOnly; this.readOnly = readOnly;
this.mem = new int[size]; this.mem = new int[endAddress - startAddress + 1];
this.fill(DEFAULT_FILL); this.fill(DEFAULT_FILL);
} }
public Memory(int address, int size) throws MemoryRangeException { public Memory(int startAddress, int endAddress) throws MemoryRangeException {
this(address, size, false); this(startAddress, endAddress, false);
} }
public static Memory makeROM(int address, int size, File f) throws MemoryRangeException, IOException { public static Memory makeROM(int startAddress, int endAddress, File f) throws MemoryRangeException, IOException {
Memory memory = new Memory(address, size, true); Memory memory = new Memory(startAddress, endAddress, true);
memory.loadFromFile(f); memory.loadFromFile(f);
return memory; return memory;
} }
public static Memory makeRAM(int address, int size) throws MemoryRangeException { public static Memory makeRAM(int startAddress, int endAddress) throws MemoryRangeException {
Memory memory = new Memory(address, size, false); Memory memory = new Memory(startAddress, endAddress, false);
return memory; return memory;
} }

View File

@ -47,7 +47,7 @@ public class Via extends Device {
private static final int ORA_H = 15; private static final int ORA_H = 15;
public Via(int address) throws MemoryRangeException { public Via(int address) throws MemoryRangeException {
super(address, VIA_SIZE, "VIA"); super(address, address + VIA_SIZE - 1, "VIA");
} }
@Override @Override