mirror of
https://github.com/sethm/symon.git
synced 2025-04-09 20:38:06 +00:00
Lots of whitespace changes after importing the project into Eclipse
This commit is contained in:
parent
a6abc2cd23
commit
e3300d3166
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
*~
|
||||
*#
|
||||
target
|
||||
.classpath
|
||||
.project
|
||||
.settings
|
||||
|
@ -3,7 +3,6 @@ package com.loomcom.j6502;
|
||||
import java.util.Map;
|
||||
|
||||
public class AddressDecoder {
|
||||
|
||||
/**
|
||||
* Map of memory ranges to IO devices.
|
||||
*/
|
||||
@ -11,10 +10,11 @@ public class AddressDecoder {
|
||||
|
||||
public AddressDecoder() {}
|
||||
|
||||
public void addDevice(Device d)
|
||||
throws MemoryConflictException {
|
||||
// Make sure there's no memory overlap.
|
||||
// Add the device to the map.
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -23,7 +23,7 @@ public class AddressDecoder {
|
||||
* device.
|
||||
*/
|
||||
public boolean isComplete() {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,9 +31,8 @@ public class AddressDecoder {
|
||||
* are gaps between IO devices.
|
||||
*/
|
||||
public boolean isSparse() {
|
||||
return !isComplete();
|
||||
return !isComplete();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MemoryRange {
|
||||
|
@ -5,35 +5,33 @@ package com.loomcom.j6502;
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
int m_pc;
|
||||
private int m_pc;
|
||||
|
||||
/**
|
||||
* The system stack pointer.
|
||||
*/
|
||||
int m_sp;
|
||||
|
||||
private int m_sp;
|
||||
|
||||
/**
|
||||
* The internal
|
||||
* Reference to the simulator
|
||||
*/
|
||||
private Simulator m_sim;
|
||||
|
||||
public Cpu() {
|
||||
reset();
|
||||
public Cpu(Simulator sim) {
|
||||
reset();
|
||||
this.m_sim = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,6 +45,29 @@ public class Cpu {
|
||||
*/
|
||||
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. */
|
||||
private MemoryRange m_memoryRange;
|
||||
|
||||
/** Referece to the CPU, for interrupts. */
|
||||
/** Reference to the CPU, for interrupts. */
|
||||
private Cpu m_cpu;
|
||||
|
||||
public Device(MemoryRange range, Cpu cpu) {
|
||||
m_memoryRange = range;
|
||||
m_cpu = cpu;
|
||||
m_memoryRange = range;
|
||||
m_cpu = cpu;
|
||||
}
|
||||
|
||||
public MemoryRange getMemoryRange() {
|
||||
return m_memoryRange;
|
||||
}
|
||||
|
||||
public void generateInterrupt() {
|
||||
m_cpu.interrupt();
|
||||
public int getEndAddress() {
|
||||
return m_memoryRange.getEndAddress();
|
||||
}
|
||||
|
||||
public int getStartAddress() {
|
||||
return m_memoryRange.getStartAddress();
|
||||
}
|
||||
|
||||
public void generateInterrupt() {
|
||||
m_cpu.interrupt();
|
||||
}
|
||||
|
||||
public void generateNonMaskableInterrupt() {
|
||||
m_cpu.nmiInterrupt();
|
||||
m_cpu.nmiInterrupt();
|
||||
}
|
||||
|
||||
}
|
@ -7,24 +7,42 @@ import java.io.IOException;
|
||||
*/
|
||||
public class Simulator {
|
||||
|
||||
CommandParser m_parser;
|
||||
/**
|
||||
* Command-line parser used by this simulator.
|
||||
*/
|
||||
CommandParser m_parser;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
m_parser = new CommandParser(System.in, System.out, this);
|
||||
m_cpu = new Cpu(this);
|
||||
m_parser = new CommandParser(System.in, System.out, this);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
m_parser.run();
|
||||
m_parser.run();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Simulator().run();
|
||||
new Simulator().run();
|
||||
}
|
||||
|
||||
public void step() {
|
||||
|
||||
}
|
||||
|
||||
public int read(int address) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void write(int address, int value) {
|
||||
}
|
||||
}
|
78
src/test/java/com/loomcom/j6502/CpuTest.java
Normal file
78
src/test/java/com/loomcom/j6502/CpuTest.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user