mirror of
https://codeberg.org/sethm/symon.git
synced 2026-11-09 03:22:24 +00:00
Standardized tabs, indent, and whitespace. Finally!
This commit is contained in:
1 parent
e3300d3166
commit
316d0feac6
6 files changed
+204
-247
No files matched your search
@@ -3,66 +3,66 @@ package com.loomcom.j6502;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class AddressDecoder {
|
public class AddressDecoder {
|
||||||
/**
|
/**
|
||||||
* Map of memory ranges to IO devices.
|
* Map of memory ranges to IO devices.
|
||||||
*/
|
*/
|
||||||
private Map<MemoryRange, Device> m_ioMap;
|
private Map<MemoryRange, Device> m_ioMap;
|
||||||
|
|
||||||
public AddressDecoder() {}
|
public AddressDecoder() {}
|
||||||
|
|
||||||
public void addDevice(Device d)
|
public void addDevice(Device d)
|
||||||
throws MemoryConflictException {
|
throws MemoryConflictException {
|
||||||
// Make sure there's no memory overlap.
|
// Make sure there's no memory overlap.
|
||||||
// Add the device to the map.
|
// Add the device to the map.
|
||||||
m_ioMap.put(d.getMemoryRange(), d);
|
m_ioMap.put(d.getMemoryRange(), d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the memory map is full, i.e., there are no
|
* Returns true if the memory map is full, i.e., there are no
|
||||||
* gaps between any IO devices. All memory locations map to some
|
* gaps between any IO devices. All memory locations map to some
|
||||||
* device.
|
* device.
|
||||||
*/
|
*/
|
||||||
public boolean isComplete() {
|
public boolean isComplete() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the memory map is 'sparse', i.e., there
|
* Returns true if the memory map is 'sparse', i.e., there
|
||||||
* are gaps between IO devices.
|
* are gaps between IO devices.
|
||||||
*/
|
*/
|
||||||
public boolean isSparse() {
|
public boolean isSparse() {
|
||||||
return !isComplete();
|
return !isComplete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MemoryRange {
|
class MemoryRange {
|
||||||
public int m_startAddress;
|
public int m_startAddress;
|
||||||
public int m_endAddress;
|
public int m_endAddress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns true if the address is included within this range,
|
* @returns true if the address is included within this range,
|
||||||
* false otherwise.
|
* false otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean includes(int address) {
|
public boolean includes(int address) {
|
||||||
return (address <= m_endAddress &&
|
return (address <= m_endAddress &&
|
||||||
address >= m_startAddress);
|
address >= m_startAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStartAddress(int startAddress) {
|
public void setStartAddress(int startAddress) {
|
||||||
m_startAddress = startAddress;
|
m_startAddress = startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEndAddress(int endAddress) {
|
public void setEndAddress(int endAddress) {
|
||||||
m_endAddress = endAddress;
|
m_endAddress = endAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStartAddress() {
|
public int getStartAddress() {
|
||||||
return m_startAddress;
|
return m_startAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndAddress() {
|
public int getEndAddress() {
|
||||||
return m_endAddress;
|
return m_endAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,68 +4,68 @@ import java.io.*;
|
|||||||
|
|
||||||
public class CommandParser {
|
public class CommandParser {
|
||||||
|
|
||||||
private BufferedReader m_in;
|
private BufferedReader m_in;
|
||||||
private BufferedWriter m_out;
|
private BufferedWriter m_out;
|
||||||
private Simulator m_simulator;
|
private Simulator m_simulator;
|
||||||
|
|
||||||
public CommandParser(InputStream in, OutputStream out, Simulator s) {
|
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));
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
String command = null;
|
|
||||||
greeting();
|
|
||||||
prompt();
|
|
||||||
while (!shouldQuit(command = readLine())) {
|
|
||||||
dispatch(command);
|
|
||||||
prompt();
|
|
||||||
}
|
|
||||||
writeLine("\n\nGoodbye!");
|
|
||||||
} catch (IOException ex) {
|
|
||||||
System.err.println("Error: " + ex.toString());
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public void run() {
|
||||||
* Dispatch the command.
|
try {
|
||||||
*/
|
String command = null;
|
||||||
public void dispatch(String command) throws IOException {
|
greeting();
|
||||||
writeLine("You entered: " + command);
|
prompt();
|
||||||
}
|
while (!shouldQuit(command = readLine())) {
|
||||||
|
dispatch(command);
|
||||||
|
prompt();
|
||||||
|
}
|
||||||
|
writeLine("\n\nGoodbye!");
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Error: " + ex.toString());
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************
|
/**
|
||||||
* Private
|
* Dispatch the command.
|
||||||
*******************************************************************/
|
*/
|
||||||
|
public void dispatch(String command) throws IOException {
|
||||||
|
writeLine("You entered: " + command);
|
||||||
|
}
|
||||||
|
|
||||||
private void greeting() throws IOException {
|
/*******************************************************************
|
||||||
writeLine("Welcome to the j6502 Simulator!");
|
* Private
|
||||||
}
|
*******************************************************************/
|
||||||
|
|
||||||
private void prompt() throws IOException {
|
private void greeting() throws IOException {
|
||||||
m_out.write("j6502> ");
|
writeLine("Welcome to the j6502 Simulator!");
|
||||||
m_out.flush();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private String readLine() throws IOException {
|
private void prompt() throws IOException {
|
||||||
String line = m_in.readLine();
|
m_out.write("j6502> ");
|
||||||
if (line == null) { return null; }
|
m_out.flush();
|
||||||
return line.trim();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void writeLine(String line) throws IOException {
|
private String readLine() throws IOException {
|
||||||
m_out.write(line);
|
String line = m_in.readLine();
|
||||||
m_out.newLine();
|
if (line == null) { return null; }
|
||||||
m_out.flush();
|
return line.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private void writeLine(String line) throws IOException {
|
||||||
* Returns true if the line is a quit.
|
m_out.write(line);
|
||||||
*/
|
m_out.newLine();
|
||||||
private boolean shouldQuit(String line) {
|
m_out.flush();
|
||||||
return (line == null || "q".equals(line.toLowerCase()));
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Returns true if the line is a quit.
|
||||||
|
*/
|
||||||
|
private boolean shouldQuit(String line) {
|
||||||
|
return (line == null || "q".equals(line.toLowerCase()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -5,69 +5,69 @@ package com.loomcom.j6502;
|
|||||||
*/
|
*/
|
||||||
public class Cpu {
|
public class Cpu {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Program Counter.
|
* The Program Counter.
|
||||||
*/
|
*/
|
||||||
private int m_pc;
|
private int m_pc;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The system stack pointer.
|
* The system stack pointer.
|
||||||
*/
|
*/
|
||||||
private int m_sp;
|
private int m_sp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the simulator
|
* Reference to the simulator
|
||||||
*/
|
*/
|
||||||
private Simulator m_sim;
|
private Simulator m_sim;
|
||||||
|
|
||||||
public Cpu(Simulator sim) {
|
public Cpu(Simulator sim) {
|
||||||
reset();
|
reset();
|
||||||
this.m_sim = sim;
|
this.m_sim = sim;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset the CPU to known initial values.
|
* Reset the CPU to known initial values.
|
||||||
*/
|
*/
|
||||||
public void reset() {
|
public void reset() {
|
||||||
m_sp = 0x01ff;
|
m_sp = 0x01ff;
|
||||||
/* locations fffc and fffd hold the reset vector address */
|
/* locations fffc and fffd hold the reset vector address */
|
||||||
m_pc = 0xfffc;
|
m_pc = 0xfffc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger a maskable interrupt.
|
* Trigger a maskable interrupt.
|
||||||
*/
|
*/
|
||||||
public void interrupt() {
|
public void interrupt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger a nonmaskable interrupt.
|
* Trigger a nonmaskable interrupt.
|
||||||
*/
|
*/
|
||||||
public void nmiInterrupt() {
|
public void nmiInterrupt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return An address specified by the two bytes immediately following the
|
* @return An address specified by the two bytes immediately following the
|
||||||
* Program Counter.
|
* Program Counter.
|
||||||
*/
|
*/
|
||||||
private int readAddress() {
|
private int readAddress() {
|
||||||
return readAddress(m_pc);
|
return readAddress(m_pc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read the two bytes located at <tt>addr</tt> and <tt>addr + 1</tt>,
|
* Read the two bytes located at <tt>addr</tt> and <tt>addr + 1</tt>,
|
||||||
* and return the address held there.
|
* and return the address held there.
|
||||||
*
|
*
|
||||||
* @param address
|
* @param address
|
||||||
* @return The address specified in the two bytes at location <tt>addr</tt>
|
* @return The address specified in the two bytes at location <tt>addr</tt>
|
||||||
*/
|
*/
|
||||||
private int readAddress(int address) {
|
private int readAddress(int address) {
|
||||||
return (m_sim.read(address)<<8 & m_sim.read(address+1));
|
return (m_sim.read(address)<<8 & m_sim.read(address+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Simulator getSimulator() {
|
public Simulator getSimulator() {
|
||||||
return m_sim;
|
return m_sim;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.loomcom.j6502;
|
package com.loomcom.j6502;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A memory-mapped IO Device.
|
* A memory-mapped IO Device.
|
||||||
@@ -6,22 +6,22 @@ package com.loomcom.j6502;
|
|||||||
|
|
||||||
public abstract class Device {
|
public abstract class Device {
|
||||||
|
|
||||||
/** The memory range for this device. */
|
/** The memory range for this device. */
|
||||||
private MemoryRange m_memoryRange;
|
private MemoryRange m_memoryRange;
|
||||||
|
|
||||||
/** Reference to the CPU, for interrupts. */
|
/** Reference to the CPU, for interrupts. */
|
||||||
private Cpu m_cpu;
|
private Cpu m_cpu;
|
||||||
|
|
||||||
public Device(MemoryRange range, Cpu cpu) {
|
public Device(MemoryRange range, Cpu cpu) {
|
||||||
m_memoryRange = range;
|
m_memoryRange = range;
|
||||||
m_cpu = cpu;
|
m_cpu = cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MemoryRange getMemoryRange() {
|
public MemoryRange getMemoryRange() {
|
||||||
return m_memoryRange;
|
return m_memoryRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEndAddress() {
|
public int getEndAddress() {
|
||||||
return m_memoryRange.getEndAddress();
|
return m_memoryRange.getEndAddress();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,11 +30,11 @@ public abstract class Device {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateInterrupt() {
|
public void generateInterrupt() {
|
||||||
m_cpu.interrupt();
|
m_cpu.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateNonMaskableInterrupt() {
|
public void generateNonMaskableInterrupt() {
|
||||||
m_cpu.nmiInterrupt();
|
m_cpu.nmiInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,36 +13,36 @@ public class Simulator {
|
|||||||
CommandParser m_parser;
|
CommandParser m_parser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CPU itself.
|
* The CPU itself.
|
||||||
*/
|
*/
|
||||||
Cpu m_cpu;
|
Cpu m_cpu;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Address Decoder responsible for routing memory
|
* The Address Decoder responsible for routing memory
|
||||||
* read/write requests to the correct IO devices.
|
* read/write requests to the correct IO devices.
|
||||||
*/
|
*/
|
||||||
AddressDecoder m_adc;
|
AddressDecoder m_adc;
|
||||||
|
|
||||||
public Simulator() {
|
public Simulator() {
|
||||||
m_cpu = new Cpu(this);
|
m_cpu = new Cpu(this);
|
||||||
m_parser = new CommandParser(System.in, System.out, this);
|
m_parser = new CommandParser(System.in, System.out, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
m_parser.run();
|
m_parser.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new Simulator().run();
|
new Simulator().run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void step() {
|
public void step() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int read(int address) {
|
public int read(int address) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(int address, int value) {
|
public void write(int address, int value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,40 +3,29 @@
|
|||||||
*/
|
*/
|
||||||
package com.loomcom.j6502;
|
package com.loomcom.j6502;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import junit.framework.*;
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author sethm
|
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class CpuTest {
|
public class CpuTest extends TestCase {
|
||||||
|
|
||||||
|
public CpuTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Test suite() {
|
||||||
|
return new TestSuite(CpuTest.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCpu() {
|
public void testCpu() {
|
||||||
Cpu cpu = new Cpu(new Simulator());
|
Cpu cpu = new Cpu(new Simulator());
|
||||||
assertNotNull(cpu);
|
assertNotNull(cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testReset() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testInterrupt() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testNmiInterrupt() {
|
|
||||||
fail("Not yet implemented");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testGetSimulator() {
|
public void testGetSimulator() {
|
||||||
Simulator sim = new Simulator();
|
Simulator sim = new Simulator();
|
||||||
Cpu cpu = new Cpu(sim);
|
Cpu cpu = new Cpu(sim);
|
||||||
@@ -44,35 +33,3 @@ public class CpuTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockSimulator extends Simulator {
|
|
||||||
public int step;
|
|
||||||
public boolean hasRun = false;
|
|
||||||
public Map<Integer,Integer> memory;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int read(int address) {
|
|
||||||
Integer val = memory.get(new Integer(address));
|
|
||||||
if (val == null) {
|
|
||||||
throw new NullPointerException("Read from a non-existent memory location");
|
|
||||||
} else {
|
|
||||||
return val.intValue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
hasRun = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void step() {
|
|
||||||
step++;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void write(int address, int value) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
super.write(address, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user