mirror of
https://github.com/sethm/symon.git
synced 2025-08-09 11:25:13 +00:00
Fleshing out some of the interface for the CPU, Simulator, and Devices.
This commit is contained in:
13
pom.xml
13
pom.xml
@@ -18,6 +18,17 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<!-- Set Java version to 6 -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<!-- best lock down version of the plugin too -->
|
||||||
|
<configuration>
|
||||||
|
<source>5</source>
|
||||||
|
<target>5</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<!-- Set up Main-Class in the JAR manifest -->
|
<!-- Set up Main-Class in the JAR manifest -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
@@ -25,7 +36,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>com.loomcom.j6502.Control</mainClass>
|
<mainClass>com.loomcom.j6502.Simulator</mainClass>
|
||||||
<packageName>com.loomcom.j6502</packageName>
|
<packageName>com.loomcom.j6502</packageName>
|
||||||
</manifest>
|
</manifest>
|
||||||
<manifestEntries>
|
<manifestEntries>
|
||||||
|
72
src/main/java/com/loomcom/j6502/AddressDecoder.java
Normal file
72
src/main/java/com/loomcom/j6502/AddressDecoder.java
Normal file
@@ -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 BufferedReader m_in;
|
||||||
private BufferedWriter m_out;
|
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_in = new BufferedReader(new InputStreamReader(in));
|
||||||
m_out = new BufferedWriter(new OutputStreamWriter(out));
|
m_out = new BufferedWriter(new OutputStreamWriter(out));
|
||||||
}
|
}
|
||||||
@@ -21,7 +22,7 @@ public class CommandParser {
|
|||||||
dispatch(command);
|
dispatch(command);
|
||||||
prompt();
|
prompt();
|
||||||
}
|
}
|
||||||
writeLine("Goodbye!");
|
writeLine("\n\nGoodbye!");
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
System.err.println("Error: " + ex.toString());
|
System.err.println("Error: " + ex.toString());
|
||||||
System.exit(1);
|
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
52
src/main/java/com/loomcom/j6502/Cpu.java
Normal file
52
src/main/java/com/loomcom/j6502/Cpu.java
Normal file
@@ -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() {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
28
src/main/java/com/loomcom/j6502/Device.java
Normal file
28
src/main/java/com/loomcom/j6502/Device.java
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
30
src/main/java/com/loomcom/j6502/Simulator.java
Normal file
30
src/main/java/com/loomcom/j6502/Simulator.java
Normal file
@@ -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() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -5,15 +5,15 @@ import junit.framework.TestCase;
|
|||||||
import junit.framework.TestSuite;
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit test for the j6502 control class.
|
* Unit test for the j6502 Simulator class.
|
||||||
*/
|
*/
|
||||||
public class ControlTest extends TestCase {
|
public class SimulatorTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* Create the test case
|
* Create the test case
|
||||||
*
|
*
|
||||||
* @param testName name of the test case
|
* @param testName name of the test case
|
||||||
*/
|
*/
|
||||||
public ControlTest(String testName) {
|
public SimulatorTest(String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,13 +21,13 @@ public class ControlTest extends TestCase {
|
|||||||
* @return the suite of tests being tested
|
* @return the suite of tests being tested
|
||||||
*/
|
*/
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return new TestSuite(ControlTest.class);
|
return new TestSuite(SimulatorTest.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rigourous Test :-)
|
* Rigourous Test :-)
|
||||||
*/
|
*/
|
||||||
public void testControl() {
|
public void testSimulator() {
|
||||||
assertTrue(true);
|
assertTrue(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user