mirror of
https://codeberg.org/sethm/symon.git
synced 2026-11-07 19:12:23 +00:00
Standardized tabs, indent, and whitespace. Finally!
This commit is contained in:
1 parent
e3300d3166
commit
316d0feac6
6 files changed
+225
-268
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user