1
0
mirror of https://github.com/sethm/symon.git synced 2024-06-07 03:29:28 +00:00

Playing around with the command parser and the Simulator class. Safe to ignore.

This commit is contained in:
Seth Morabito 2010-01-16 08:56:34 +00:00
parent f174f0312f
commit 5c7a98df86
3 changed files with 57 additions and 51 deletions

View File

@ -1,6 +1,9 @@
package com.loomcom.symon;
import java.io.*;
import com.loomcom.symon.devices.*;
import com.loomcom.symon.exceptions.*;
public class CommandParser {
@ -14,7 +17,7 @@ public class CommandParser {
this.simulator = s;
}
public void run() {
public void run() throws MemoryAccessException {
try {
String command = null;
greeting();
@ -41,8 +44,17 @@ public class CommandParser {
/**
* Dispatch the command.
*/
public void dispatch(String command) throws IOException {
writeLine("You entered: " + command);
public void dispatch(String 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?");
}
}
/*******************************************************************

View File

@ -158,7 +158,6 @@ public class Cpu implements InstructionTable {
case 2:
switch(irAddressMode) {
case 0: // #Immediate
effectiveAddress = -1;
effectiveData = args[0];
break;
case 1: // Zero Page
@ -1297,6 +1296,11 @@ public class Cpu implements InstructionTable {
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.
*

View File

@ -32,27 +32,16 @@ public class Simulator {
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();
}
public void step() {
}
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);
public void load(int address, int[] program)
throws MemoryAccessException {
int i = 0;
for (int d : program) {
bus.write(address + i++, d);
@ -62,42 +51,43 @@ public class Simulator {
/**
* A test method.
*/
public void runTest() throws MemoryAccessException {
int[] program = {
0xa9, // LDA #$FF
0xff,
0xa0, // LDY #$1A
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[] zpData = {
0x39, // $0000
0x21, // $0001
0x12 // $0002
};
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();
int steps = program.length;
for (int i = 0; i <= steps; i++) {
for (int i = 0; i <= programLength; i++) {
cpu.step();
System.out.println(cpu.toString());
}
}
/**
@ -105,7 +95,7 @@ public class Simulator {
*/
public static void main(String[] args) throws MemoryAccessException {
try {
new Simulator().runTest();
new Simulator().run();
} catch (MemoryRangeException ex) {
System.err.println("Error: " + ex.toString());
}