- Continued refactoring of address decoding.
- Device read and write may now throw MemoryAccessException, and appropriate throws clauses have been added throughout the code.
This commit is contained in:
1 parent
a01090a16e
commit
ac88786df7
21 files changed
+465
-446
No files matched your search
@@ -29,13 +29,17 @@ public abstract class Device implements Comparable<Device> {
|
||||
}
|
||||
|
||||
/* Methods required to be implemented by inheriting classes. */
|
||||
public abstract void write(int address, int data);
|
||||
public abstract int read(int address);
|
||||
public abstract void write(int address, int data) throws MemoryAccessException;
|
||||
public abstract int read(int address) throws MemoryAccessException;
|
||||
public abstract String toString();
|
||||
|
||||
public void setBus(Bus bus) {
|
||||
this.bus = bus;
|
||||
}
|
||||
|
||||
public Bus getBus() {
|
||||
return this.bus;
|
||||
}
|
||||
|
||||
public MemoryRange getMemoryRange() {
|
||||
return memoryRange;
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.loomcom.symon.devices;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.loomcom.symon.*;
|
||||
import com.loomcom.symon.exceptions.*;
|
||||
|
||||
public class Memory extends Device {
|
||||
@@ -24,11 +23,15 @@ public class Memory extends Device {
|
||||
this(address, size, false);
|
||||
}
|
||||
|
||||
public void write(int address, int data) {
|
||||
this.mem[address] = data;
|
||||
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) {
|
||||
public int read(int address) throws MemoryAccessException {
|
||||
return this.mem[address];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user