From 316d0feac62842aa781cfc65fe412c4b19310564 Mon Sep 17 00:00:00 2001 From: "Seth J. Morabito" Date: Mon, 8 Dec 2008 14:03:23 -0800 Subject: [PATCH] Standardized tabs, indent, and whitespace. Finally! --- .../com/loomcom/j6502/AddressDecoder.java | 96 +++++++------- .../java/com/loomcom/j6502/CommandParser.java | 118 +++++++++--------- src/main/java/com/loomcom/j6502/Cpu.java | 108 ++++++++-------- src/main/java/com/loomcom/j6502/Device.java | 40 +++--- .../java/com/loomcom/j6502/Simulator.java | 62 ++++----- src/test/java/com/loomcom/j6502/CpuTest.java | 69 ++-------- 6 files changed, 225 insertions(+), 268 deletions(-) diff --git a/src/main/java/com/loomcom/j6502/AddressDecoder.java b/src/main/java/com/loomcom/j6502/AddressDecoder.java index dd959ca..9faf9be 100644 --- a/src/main/java/com/loomcom/j6502/AddressDecoder.java +++ b/src/main/java/com/loomcom/j6502/AddressDecoder.java @@ -3,66 +3,66 @@ package com.loomcom.j6502; import java.util.Map; public class AddressDecoder { - /** - * Map of memory ranges to IO devices. - */ - private Map m_ioMap; - - public AddressDecoder() {} + /** + * Map of memory ranges to IO devices. + */ + private Map 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; + } } /** diff --git a/src/main/java/com/loomcom/j6502/CommandParser.java b/src/main/java/com/loomcom/j6502/CommandParser.java index 0e12e8f..1c5bea3 100644 --- a/src/main/java/com/loomcom/j6502/CommandParser.java +++ b/src/main/java/com/loomcom/j6502/CommandParser.java @@ -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())); + } + } \ No newline at end of file diff --git a/src/main/java/com/loomcom/j6502/Cpu.java b/src/main/java/com/loomcom/j6502/Cpu.java index fe47243..c44b291 100644 --- a/src/main/java/com/loomcom/j6502/Cpu.java +++ b/src/main/java/com/loomcom/j6502/Cpu.java @@ -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 addr and addr + 1, - * and return the address held there. - * - * @param address - * @return The address specified in the two bytes at location addr - */ - 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 addr and addr + 1, + * and return the address held there. + * + * @param address + * @return The address specified in the two bytes at location addr + */ + private int readAddress(int address) { + return (m_sim.read(address)<<8 & m_sim.read(address+1)); + } + + public Simulator getSimulator() { + return m_sim; + } + } diff --git a/src/main/java/com/loomcom/j6502/Device.java b/src/main/java/com/loomcom/j6502/Device.java index 35c3722..867add0 100644 --- a/src/main/java/com/loomcom/j6502/Device.java +++ b/src/main/java/com/loomcom/j6502/Device.java @@ -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(); + } } \ No newline at end of file diff --git a/src/main/java/com/loomcom/j6502/Simulator.java b/src/main/java/com/loomcom/j6502/Simulator.java index c0732c8..36cacb4 100644 --- a/src/main/java/com/loomcom/j6502/Simulator.java +++ b/src/main/java/com/loomcom/j6502/Simulator.java @@ -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) { + } } \ No newline at end of file diff --git a/src/test/java/com/loomcom/j6502/CpuTest.java b/src/test/java/com/loomcom/j6502/CpuTest.java index 811f606..150c534 100644 --- a/src/test/java/com/loomcom/j6502/CpuTest.java +++ b/src/test/java/com/loomcom/j6502/CpuTest.java @@ -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 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); - } -} +} \ No newline at end of file