mirror of
https://github.com/sethm/symon.git
synced 2025-08-09 11:25:13 +00:00
Playing around with the command parser and the Simulator class. Safe to ignore.
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
package com.loomcom.symon;
|
package com.loomcom.symon;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import com.loomcom.symon.devices.*;
|
||||||
|
import com.loomcom.symon.exceptions.*;
|
||||||
|
|
||||||
|
|
||||||
public class CommandParser {
|
public class CommandParser {
|
||||||
|
|
||||||
@@ -14,7 +17,7 @@ public class CommandParser {
|
|||||||
this.simulator = s;
|
this.simulator = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() throws MemoryAccessException {
|
||||||
try {
|
try {
|
||||||
String command = null;
|
String command = null;
|
||||||
greeting();
|
greeting();
|
||||||
@@ -41,8 +44,17 @@ public class CommandParser {
|
|||||||
/**
|
/**
|
||||||
* Dispatch the command.
|
* Dispatch the command.
|
||||||
*/
|
*/
|
||||||
public void dispatch(String command) throws IOException {
|
public void dispatch(String command)
|
||||||
writeLine("You entered: " + command);
|
throws MemoryAccessException, IOException {
|
||||||
|
// TODO: Real implementation. This first one is just
|
||||||
|
// for testing.
|
||||||
|
if ("test".equals(command)) {
|
||||||
|
simulator.runTest();
|
||||||
|
} else if ("ex".equals(command)) {
|
||||||
|
writeLine(simulator.getState());
|
||||||
|
} else {
|
||||||
|
writeLine("Huh?");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************************************
|
/*******************************************************************
|
||||||
|
@@ -158,7 +158,6 @@ public class Cpu implements InstructionTable {
|
|||||||
case 2:
|
case 2:
|
||||||
switch(irAddressMode) {
|
switch(irAddressMode) {
|
||||||
case 0: // #Immediate
|
case 0: // #Immediate
|
||||||
effectiveAddress = -1;
|
|
||||||
effectiveData = args[0];
|
effectiveData = args[0];
|
||||||
break;
|
break;
|
||||||
case 1: // Zero Page
|
case 1: // Zero Page
|
||||||
@@ -1297,6 +1296,11 @@ public class Cpu implements InstructionTable {
|
|||||||
return (zp+getYRegister())&0xff;
|
return (zp+getYRegister())&0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setResetVector(int address) throws MemoryAccessException {
|
||||||
|
bus.write(RST_VECTOR_H, (address&0xff00)>>>8);
|
||||||
|
bus.write(RST_VECTOR_L, address&0x00ff);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an opcode and its operands, return a formatted name.
|
* Given an opcode and its operands, return a formatted name.
|
||||||
*
|
*
|
||||||
|
@@ -32,27 +32,16 @@ public class Simulator {
|
|||||||
parser = new CommandParser(System.in, System.out, this);
|
parser = new CommandParser(System.in, System.out, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public String getState() throws MemoryAccessException {
|
||||||
|
return cpu.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() throws MemoryAccessException {
|
||||||
parser.run();
|
parser.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void step() {
|
public void load(int address, int[] program)
|
||||||
}
|
throws MemoryAccessException {
|
||||||
|
|
||||||
public int read(int address) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void write(int address, int value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadProgram(int address, int[] program) throws MemoryAccessException {
|
|
||||||
// Reset interrupt vector
|
|
||||||
int hi = (address&0xff00)>>>8;
|
|
||||||
int lo = address&0x00ff;
|
|
||||||
bus.write(0xfffc, lo);
|
|
||||||
bus.write(0xfffd, hi);
|
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (int d : program) {
|
for (int d : program) {
|
||||||
bus.write(address + i++, d);
|
bus.write(address + i++, d);
|
||||||
@@ -62,42 +51,43 @@ public class Simulator {
|
|||||||
/**
|
/**
|
||||||
* A test method.
|
* A test method.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void runTest() throws MemoryAccessException {
|
public void runTest() throws MemoryAccessException {
|
||||||
int[] program = {
|
int[] zpData = {
|
||||||
0xa9, // LDA #$FF
|
0x39, // $0000
|
||||||
0xff,
|
0x21, // $0001
|
||||||
0xa0, // LDY #$1A
|
0x12 // $0002
|
||||||
0x1a,
|
|
||||||
0xa2, // LDX #$90
|
|
||||||
0x90,
|
|
||||||
0xa2, // LDX #$02
|
|
||||||
0x02,
|
|
||||||
0x49, // EOR #$FF
|
|
||||||
0xff,
|
|
||||||
0xa9, // LDA #$00
|
|
||||||
0x00,
|
|
||||||
0xa2, // LDX #$00
|
|
||||||
0x00,
|
|
||||||
0x29, // AND #$FF
|
|
||||||
0xff,
|
|
||||||
0xa0, // LDY #$00
|
|
||||||
0x00,
|
|
||||||
0x4c, // JMP #$0300
|
|
||||||
0x00,
|
|
||||||
0x03
|
|
||||||
};
|
};
|
||||||
|
int[] data = {
|
||||||
|
0xae, // $c800
|
||||||
|
0x13, // $c801
|
||||||
|
0x29 // $c802
|
||||||
|
};
|
||||||
|
int[] program = {
|
||||||
|
0xa9, 0xff, // LDA #$FF
|
||||||
|
0xa0, 0x1a, // LDY #$1A
|
||||||
|
0xa2, 0x90, // LDX #$90
|
||||||
|
0xa2, 0x02, // LDX #$02
|
||||||
|
0x49, 0xff, // EOR #$FF
|
||||||
|
0xa9, 0x00, // LDA #$00
|
||||||
|
0xa2, 0x00, // LDX #$00
|
||||||
|
0x29, 0xff, // AND #$FF
|
||||||
|
0xa0, 0x00, // LDY #$00
|
||||||
|
0xa5, 0x00, // LDA $00
|
||||||
|
0xad, 0x00, 0xc8, // LDA $c800
|
||||||
|
0x4c, 0x00, 0x03 // JMP #$0300
|
||||||
|
};
|
||||||
|
int programLength = 12;
|
||||||
|
|
||||||
loadProgram(0x0300, program);
|
load(0x0000, zpData);
|
||||||
|
load(0x0300, program);
|
||||||
|
load(0xc800, data);
|
||||||
|
cpu.setResetVector(0x0300);
|
||||||
cpu.reset();
|
cpu.reset();
|
||||||
|
|
||||||
int steps = program.length;
|
for (int i = 0; i <= programLength; i++) {
|
||||||
|
|
||||||
for (int i = 0; i <= steps; i++) {
|
|
||||||
cpu.step();
|
cpu.step();
|
||||||
System.out.println(cpu.toString());
|
System.out.println(cpu.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -105,7 +95,7 @@ public class Simulator {
|
|||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws MemoryAccessException {
|
public static void main(String[] args) throws MemoryAccessException {
|
||||||
try {
|
try {
|
||||||
new Simulator().runTest();
|
new Simulator().run();
|
||||||
} catch (MemoryRangeException ex) {
|
} catch (MemoryRangeException ex) {
|
||||||
System.err.println("Error: " + ex.toString());
|
System.err.println("Error: " + ex.toString());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user