Lots of whitespace changes after importing the project into Eclipse

This commit is contained in:
Seth Morabito committed 2008-12-06 14:39:54 -08:00
1 parent a6abc2cd23
commit e3300d3166
6 files changed
+147 -16

No files matched your search

+3
View File
@@ -1,3 +1,6 @@
*~ *~
*# *#
target target
.classpath
.project
.settings
@@ -3,7 +3,6 @@ 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.
*/ */
@@ -15,6 +14,7 @@ public class AddressDecoder {
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);
} }
/** /**
@@ -33,7 +33,6 @@ public class AddressDecoder {
public boolean isSparse() { public boolean isSparse() {
return !isComplete(); return !isComplete();
} }
} }
class MemoryRange { class MemoryRange {
+32 -11
View File
@@ -5,35 +5,33 @@ package com.loomcom.j6502;
*/ */
public class Cpu { 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. * The Program Counter.
*/ */
int m_pc; private int m_pc;
/** /**
* The system stack pointer. * The system stack pointer.
*/ */
int m_sp; private int m_sp;
/** /**
* The internal * Reference to the simulator
*/ */
private Simulator m_sim;
public Cpu() { public Cpu(Simulator sim) {
reset(); reset();
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;
/* locations fffc and fffd hold the reset vector address */
m_pc = 0xfffc;
} }
/** /**
@@ -48,5 +46,28 @@ public class Cpu {
public void nmiInterrupt() { 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;
}
} }
+13 -1
View File
@@ -9,7 +9,7 @@ public abstract class Device {
/** The memory range for this device. */ /** The memory range for this device. */
private MemoryRange m_memoryRange; private MemoryRange m_memoryRange;
/** Referece 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) {
@@ -17,6 +17,18 @@ public abstract class Device {
m_cpu = cpu; m_cpu = cpu;
} }
public MemoryRange getMemoryRange() {
return m_memoryRange;
}
public int getEndAddress() {
return m_memoryRange.getEndAddress();
}
public int getStartAddress() {
return m_memoryRange.getStartAddress();
}
public void generateInterrupt() { public void generateInterrupt() {
m_cpu.interrupt(); m_cpu.interrupt();
} }
+20 -2
View File
@@ -7,11 +7,24 @@ import java.io.IOException;
*/ */
public class Simulator { public class Simulator {
/**
* Command-line parser used by this simulator.
*/
CommandParser m_parser; CommandParser m_parser;
/**
* The CPU itself.
*/
Cpu m_cpu; Cpu m_cpu;
/**
* The Address Decoder responsible for routing memory
* read/write requests to the correct IO devices.
*/
AddressDecoder m_adc;
public Simulator() { public Simulator() {
m_cpu = new Cpu(); m_cpu = new Cpu(this);
m_parser = new CommandParser(System.in, System.out, this); m_parser = new CommandParser(System.in, System.out, this);
} }
@@ -24,7 +37,12 @@ public class Simulator {
} }
public void step() { public void step() {
} }
public int read(int address) {
return 0;
}
public void write(int address, int value) {
}
} }
@@ -0,0 +1,78 @@
/**
*
*/
package com.loomcom.j6502;
import static org.junit.Assert.*;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
/**
* @author sethm
*
*/
public class CpuTest {
@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());
}
}
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);
}
}