Lots of whitespace changes after importing the project into Eclipse
This commit is contained in:
1 parent
a6abc2cd23
commit
e3300d3166
6 files changed
+162
-31
No files matched your search
@@ -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.
|
||||||
*/
|
*/
|
||||||
@@ -12,9 +11,10 @@ public class AddressDecoder {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,7 +23,7 @@ public class AddressDecoder {
|
|||||||
* device.
|
* device.
|
||||||
*/
|
*/
|
||||||
public boolean isComplete() {
|
public boolean isComplete() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,9 +31,8 @@ public class AddressDecoder {
|
|||||||
* are gaps between IO devices.
|
* are gaps between IO devices.
|
||||||
*/
|
*/
|
||||||
public boolean isSparse() {
|
public boolean isSparse() {
|
||||||
return !isComplete();
|
return !isComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MemoryRange {
|
class MemoryRange {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9,20 +9,32 @@ 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) {
|
||||||
m_memoryRange = range;
|
m_memoryRange = range;
|
||||||
m_cpu = cpu;
|
m_cpu = cpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateInterrupt() {
|
public MemoryRange getMemoryRange() {
|
||||||
m_cpu.interrupt();
|
return m_memoryRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEndAddress() {
|
||||||
|
return m_memoryRange.getEndAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartAddress() {
|
||||||
|
return m_memoryRange.getStartAddress();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generateInterrupt() {
|
||||||
|
m_cpu.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateNonMaskableInterrupt() {
|
public void generateNonMaskableInterrupt() {
|
||||||
m_cpu.nmiInterrupt();
|
m_cpu.nmiInterrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,24 +7,42 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class Simulator {
|
public class Simulator {
|
||||||
|
|
||||||
CommandParser m_parser;
|
/**
|
||||||
|
* Command-line parser used by this simulator.
|
||||||
|
*/
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user