Fleshing out some of the interface for the CPU, Simulator, and Devices.
This commit is contained in:
1 parent
0163ae47b4
commit
a6abc2cd23
8 files changed
+202
-25
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package com.loomcom.j6502;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class AddressDecoder {
|
||||
|
||||
/**
|
||||
* Map of memory ranges to IO devices.
|
||||
*/
|
||||
private Map<MemoryRange, Device> m_ioMap;
|
||||
|
||||
public AddressDecoder() {}
|
||||
|
||||
public void addDevice(Device d)
|
||||
throws MemoryConflictException {
|
||||
// Make sure there's no memory overlap.
|
||||
// Add the device to the map.
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the memory map is 'sparse', i.e., there
|
||||
* are gaps between IO devices.
|
||||
*/
|
||||
public boolean isSparse() {
|
||||
return !isComplete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MemoryRange {
|
||||
public int m_startAddress;
|
||||
public int m_endAddress;
|
||||
|
||||
/**
|
||||
* @returns true if the address is included within this range,
|
||||
* false otherwise.
|
||||
*/
|
||||
public boolean includes(int address) {
|
||||
return (address <= m_endAddress &&
|
||||
address >= m_startAddress);
|
||||
}
|
||||
|
||||
public void setStartAddress(int startAddress) {
|
||||
m_startAddress = startAddress;
|
||||
}
|
||||
|
||||
public void setEndAddress(int endAddress) {
|
||||
m_endAddress = endAddress;
|
||||
}
|
||||
|
||||
public int getStartAddress() {
|
||||
return m_startAddress;
|
||||
}
|
||||
|
||||
public int getEndAddress() {
|
||||
return m_endAddress;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Excption that will be thrown if devices conflict in the IO map.
|
||||
*/
|
||||
class MemoryConflictException extends Exception {}
|
||||
@@ -6,8 +6,9 @@ public class CommandParser {
|
||||
|
||||
private BufferedReader m_in;
|
||||
private BufferedWriter m_out;
|
||||
private Simulator m_simulator;
|
||||
|
||||
public CommandParser(InputStream in, OutputStream out) {
|
||||
public CommandParser(InputStream in, OutputStream out, Simulator s) {
|
||||
m_in = new BufferedReader(new InputStreamReader(in));
|
||||
m_out = new BufferedWriter(new OutputStreamWriter(out));
|
||||
}
|
||||
@@ -21,7 +22,7 @@ public class CommandParser {
|
||||
dispatch(command);
|
||||
prompt();
|
||||
}
|
||||
writeLine("Goodbye!");
|
||||
writeLine("\n\nGoodbye!");
|
||||
} catch (IOException ex) {
|
||||
System.err.println("Error: " + ex.toString());
|
||||
System.exit(1);
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
package com.loomcom.j6502;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Main control class for the J6502 Simulator.
|
||||
*/
|
||||
public class Control {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
CommandParser parser = new CommandParser(System.in, System.out);
|
||||
parser.run();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.loomcom.j6502;
|
||||
|
||||
/**
|
||||
* Main 6502 CPU Simulation.
|
||||
*/
|
||||
public class Cpu {
|
||||
|
||||
/**
|
||||
* The Address Decoder responsible for routing memory
|
||||
* read/write requests to the correct IO devices. Any
|
||||
* simulated device can be
|
||||
*/
|
||||
AddressDecoder m_adc;
|
||||
|
||||
/**
|
||||
* The Program Counter.
|
||||
*/
|
||||
int m_pc;
|
||||
|
||||
/**
|
||||
* The system stack pointer.
|
||||
*/
|
||||
int m_sp;
|
||||
|
||||
/**
|
||||
* The internal
|
||||
*/
|
||||
|
||||
public Cpu() {
|
||||
reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the CPU to known initial values.
|
||||
*/
|
||||
public void reset() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a maskable interrupt.
|
||||
*/
|
||||
public void interrupt() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a nonmaskable interrupt.
|
||||
*/
|
||||
public void nmiInterrupt() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.loomcom.j6502;
|
||||
|
||||
/**
|
||||
* A memory-mapped IO Device.
|
||||
*/
|
||||
|
||||
public abstract class Device {
|
||||
|
||||
/** The memory range for this device. */
|
||||
private MemoryRange m_memoryRange;
|
||||
|
||||
/** Referece to the CPU, for interrupts. */
|
||||
private Cpu m_cpu;
|
||||
|
||||
public Device(MemoryRange range, Cpu cpu) {
|
||||
m_memoryRange = range;
|
||||
m_cpu = cpu;
|
||||
}
|
||||
|
||||
public void generateInterrupt() {
|
||||
m_cpu.interrupt();
|
||||
}
|
||||
|
||||
public void generateNonMaskableInterrupt() {
|
||||
m_cpu.nmiInterrupt();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.loomcom.j6502;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Main control class for the J6502 Simulator.
|
||||
*/
|
||||
public class Simulator {
|
||||
|
||||
CommandParser m_parser;
|
||||
Cpu m_cpu;
|
||||
|
||||
public Simulator() {
|
||||
m_cpu = new Cpu();
|
||||
m_parser = new CommandParser(System.in, System.out, this);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
m_parser.run();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Simulator().run();
|
||||
}
|
||||
|
||||
public void step() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user