CPU bug fixes and Simulator enhancements.
Bug Fixes: - Fixed several bugs in the CPU that caused processor status flags to be set incorrectly. Instructions affected were: STA, STX, STY, CMP, CPX, CPY, BIT. - Made some internal-use-only methods on the CPU class private. - Fixed incorrect disassembly of (Indirect,X) and (Indirect),Y instructions. Although this didn't affect behavior, it certainly caused me some confusion in debugging. - Added missing "BCS" instruction to instruction table. Enhancements: - Now includes a full version of Lee Davison's Enhanced 6502 BASIC bundled as source code and a ROM image. Get that REAL COMPUTER EXPERIENCE!(tm) - If a file named "rom.bin" exists in the same directory where the simulator is executed, it will be loaded at addresses $d000-$ffff. - Gave the CPU an idle loop to make simulated timing a little more realistic (but this is still an area needing major improvement) - Changed the CPU's toString() method to give better debugging output. - Added a small typeahead buffer to the Console. - Better exception messaging. Misc: - Bumped version to 0.5, updated README.
This commit is contained in:
1 parent
c1caf8c6b4
commit
795ccfde5d
25 files changed
+13622
-4508
No files matched your search
@@ -1,9 +1,12 @@
|
||||
package com.loomcom.symon.devices;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import com.loomcom.symon.exceptions.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class Memory extends Device {
|
||||
|
||||
private boolean readOnly;
|
||||
@@ -24,6 +27,17 @@ public class Memory extends Device {
|
||||
this(address, size, false);
|
||||
}
|
||||
|
||||
public static Memory makeROM(int address, int size, File f) throws MemoryRangeException, IOException {
|
||||
Memory memory = new Memory(address, size, true);
|
||||
memory.loadFromFile(f);
|
||||
return memory;
|
||||
}
|
||||
|
||||
public static Memory makeRAM(int address, int size) throws MemoryRangeException {
|
||||
Memory memory = new Memory(address, size, false);
|
||||
return memory;
|
||||
}
|
||||
|
||||
public void write(int address, int data) throws MemoryAccessException {
|
||||
if (readOnly) {
|
||||
throw new MemoryAccessException("Cannot write to read-only memory at address " + address);
|
||||
@@ -32,6 +46,34 @@ public class Memory extends Device {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the memory from a file.
|
||||
*
|
||||
* @param file The file to read an array of bytes from.
|
||||
* @throws MemoryRangeException if the file and memory size do not match.
|
||||
* @throws IOException if the file read fails.
|
||||
*/
|
||||
public void loadFromFile(File file) throws MemoryRangeException, IOException {
|
||||
if (file.canRead()) {
|
||||
long fileSize = file.length();
|
||||
|
||||
if (fileSize > mem.length) {
|
||||
throw new MemoryRangeException("File will not fit in available memory.");
|
||||
} else {
|
||||
int i = 0;
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
BufferedInputStream bis = new BufferedInputStream(fis);
|
||||
DataInputStream dis = new DataInputStream(bis);
|
||||
while (dis.available() != 0) {
|
||||
mem[i++] = dis.readUnsignedByte();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new IOException("Cannot open file " + file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int read(int address) throws MemoryAccessException {
|
||||
return this.mem[address];
|
||||
}
|
||||
@@ -40,7 +82,6 @@ public class Memory extends Device {
|
||||
Arrays.fill(this.mem, val);
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "Memory: " + getMemoryRange().toString();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user