1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-03 07:29:30 +00:00

Standardized tabs, indent, and whitespace. Finally!

This commit is contained in:
Seth J. Morabito 2008-12-08 14:03:23 -08:00
parent e3300d3166
commit 316d0feac6
6 changed files with 225 additions and 268 deletions

View File

@ -3,66 +3,66 @@ 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() {}
/**
* Map of memory ranges to IO devices.
*/
private Map<MemoryRange, Device> m_ioMap;
public void addDevice(Device d)
public AddressDecoder() {}
public void addDevice(Device d)
throws MemoryConflictException {
// Make sure there's no memory overlap.
// Add the device to the map.
m_ioMap.put(d.getMemoryRange(), d);
}
// Make sure there's no memory overlap.
// Add the device to the map.
m_ioMap.put(d.getMemoryRange(), d);
}
/**
* 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 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();
}
/**
* 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;
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);
}
/**
* @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 setStartAddress(int startAddress) {
m_startAddress = startAddress;
}
public void setEndAddress(int endAddress) {
m_endAddress = endAddress;
}
public void setEndAddress(int endAddress) {
m_endAddress = endAddress;
}
public int getStartAddress() {
return m_startAddress;
}
public int getStartAddress() {
return m_startAddress;
}
public int getEndAddress() {
return m_endAddress;
}
public int getEndAddress() {
return m_endAddress;
}
}
/**

View File

@ -3,69 +3,69 @@ package com.loomcom.j6502;
import java.io.*;
public class CommandParser {
private BufferedReader m_in;
private BufferedWriter m_out;
private Simulator m_simulator;
public CommandParser(InputStream in, OutputStream out, Simulator s) {
m_in = new BufferedReader(new InputStreamReader(in));
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);
private BufferedReader m_in;
private BufferedWriter m_out;
private Simulator m_simulator;
public CommandParser(InputStream in, OutputStream out, Simulator s) {
m_in = new BufferedReader(new InputStreamReader(in));
m_out = new BufferedWriter(new OutputStreamWriter(out));
}
}
/**
* Dispatch the command.
*/
public void dispatch(String command) throws IOException {
writeLine("You entered: " + command);
}
/*******************************************************************
* Private
*******************************************************************/
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);
}
}
/**
* 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 {
m_out.write("j6502> ");
m_out.flush();
}
private void greeting() throws IOException {
writeLine("Welcome to the j6502 Simulator!");
}
private String readLine() throws IOException {
String line = m_in.readLine();
if (line == null) { return null; }
return line.trim();
}
private void prompt() throws IOException {
m_out.write("j6502> ");
m_out.flush();
}
private void writeLine(String line) throws IOException {
m_out.write(line);
m_out.newLine();
m_out.flush();
}
/**
* Returns true if the line is a quit.
*/
private boolean shouldQuit(String line) {
return (line == null || "q".equals(line.toLowerCase()));
}
private String readLine() throws IOException {
String line = m_in.readLine();
if (line == null) { return null; }
return line.trim();
}
private void writeLine(String line) throws IOException {
m_out.write(line);
m_out.newLine();
m_out.flush();
}
/**
* Returns true if the line is a quit.
*/
private boolean shouldQuit(String line) {
return (line == null || "q".equals(line.toLowerCase()));
}
}

View File

@ -5,69 +5,69 @@ package com.loomcom.j6502;
*/
public class Cpu {
/**
* The Program Counter.
*/
private int m_pc;
/**
* The Program Counter.
*/
private int m_pc;
/**
* The system stack pointer.
*/
private int m_sp;
/**
* Reference to the simulator
*/
private Simulator m_sim;
/**
* The system stack pointer.
*/
private int m_sp;
public Cpu(Simulator sim) {
reset();
this.m_sim = sim;
}
/**
* Reference to the simulator
*/
private Simulator m_sim;
/**
* Reset the CPU to known initial values.
*/
public void reset() {
m_sp = 0x01ff;
/* locations fffc and fffd hold the reset vector address */
m_pc = 0xfffc;
}
public Cpu(Simulator sim) {
reset();
this.m_sim = sim;
}
/**
* Trigger a maskable interrupt.
*/
public void interrupt() {
}
/**
* Reset the CPU to known initial values.
*/
public void reset() {
m_sp = 0x01ff;
/* locations fffc and fffd hold the reset vector address */
m_pc = 0xfffc;
}
/**
* Trigger a nonmaskable interrupt.
*/
public void nmiInterrupt() {
}
/**
* Trigger a maskable interrupt.
*/
public void interrupt() {
}
/**
* Trigger a nonmaskable interrupt.
*/
public void nmiInterrupt() {
}
/**
* @return An address specified by the two bytes immediately following the
* Program Counter.
*/
private int readAddress() {
return readAddress(m_pc);
}
/**
* Read the two bytes located at <tt>addr</tt> and <tt>addr + 1</tt>,
* and return the address held there.
*
* @param address
* @return The address specified in the two bytes at location <tt>addr</tt>
*/
private int readAddress(int address) {
return (m_sim.read(address)<<8 & m_sim.read(address+1));
}
public Simulator getSimulator() {
return m_sim;
}
private int readAddress() {
return readAddress(m_pc);
}
/**
* Read the two bytes located at <tt>addr</tt> and <tt>addr + 1</tt>,
* and return the address held there.
*
* @param address
* @return The address specified in the two bytes at location <tt>addr</tt>
*/
private int readAddress(int address) {
return (m_sim.read(address)<<8 & m_sim.read(address+1));
}
public Simulator getSimulator() {
return m_sim;
}
}

View File

@ -1,4 +1,4 @@
package com.loomcom.j6502;
package com.loomcom.j6502;
/**
* A memory-mapped IO Device.
@ -6,22 +6,22 @@ package com.loomcom.j6502;
public abstract class Device {
/** The memory range for this device. */
private MemoryRange m_memoryRange;
/** The memory range for this device. */
private MemoryRange m_memoryRange;
/** Reference to the CPU, for interrupts. */
private Cpu m_cpu;
public Device(MemoryRange range, Cpu cpu) {
m_memoryRange = range;
m_cpu = cpu;
}
public MemoryRange getMemoryRange() {
return m_memoryRange;
}
/** Reference to the CPU, for interrupts. */
private Cpu m_cpu;
public int getEndAddress() {
public Device(MemoryRange range, Cpu cpu) {
m_memoryRange = range;
m_cpu = cpu;
}
public MemoryRange getMemoryRange() {
return m_memoryRange;
}
public int getEndAddress() {
return m_memoryRange.getEndAddress();
}
@ -30,11 +30,11 @@ public abstract class Device {
}
public void generateInterrupt() {
m_cpu.interrupt();
}
m_cpu.interrupt();
}
public void generateNonMaskableInterrupt() {
m_cpu.nmiInterrupt();
}
public void generateNonMaskableInterrupt() {
m_cpu.nmiInterrupt();
}
}

View File

@ -6,43 +6,43 @@ import java.io.IOException;
* Main control class for the J6502 Simulator.
*/
public class Simulator {
/**
* Command-line parser used by this simulator.
*/
CommandParser m_parser;
/**
* The CPU itself.
*/
Cpu m_cpu;
* The CPU itself.
*/
Cpu m_cpu;
/**
* The Address Decoder responsible for routing memory
* read/write requests to the correct IO devices.
*/
AddressDecoder m_adc;
public Simulator() {
m_cpu = new Cpu(this);
m_parser = new CommandParser(System.in, System.out, this);
}
/**
* The Address Decoder responsible for routing memory
* read/write requests to the correct IO devices.
*/
AddressDecoder m_adc;
public void run() {
m_parser.run();
}
public static void main(String[] args) {
new Simulator().run();
}
public Simulator() {
m_cpu = new Cpu(this);
m_parser = new CommandParser(System.in, System.out, this);
}
public void step() {
}
public int read(int address) {
return 0;
}
public void write(int address, int value) {
}
public void run() {
m_parser.run();
}
public static void main(String[] args) {
new Simulator().run();
}
public void step() {
}
public int read(int address) {
return 0;
}
public void write(int address, int value) {
}
}

View File

@ -1,78 +1,35 @@
/**
*
*
*/
package com.loomcom.j6502;
import static org.junit.Assert.*;
import junit.framework.*;
import org.junit.Test;
import java.util.HashMap;
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() {
Cpu cpu = new Cpu(new Simulator());
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() {
Simulator sim = new Simulator();
Cpu cpu = new Cpu(sim);
assertEquals(sim, cpu.getSimulator());
assertEquals(sim, cpu.getSimulator());
}
}
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);
}
}
}