summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--headers/debug.h10
-rw-r--r--interpreter.c73
-rw-r--r--interpreter.md57
-rw-r--r--opcodes-reference.pdfbin0 -> 20266 bytes
-rw-r--r--test/adc.test0
-rw-r--r--test/load.test19
7 files changed, 121 insertions, 39 deletions
diff --git a/.gitignore b/.gitignore
index 8da0d65..cd49ac2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ instructions.bin
instruction-dump
.vscode/settings.json
a
+interpreter
diff --git a/headers/debug.h b/headers/debug.h
index 4b36710..4c2a9ba 100644
--- a/headers/debug.h
+++ b/headers/debug.h
@@ -34,10 +34,10 @@ void dPageDump(short m){
// Dump CPU values
void dStatusDump(void){
printf("\
-..acc:\t%x\tcycles:\t%d\n\
-....X:\t%x\tlength:\t%d\n\
-....Y:\t%x\t...add:\t%x\n\
-stack:\t%x\t.value:\t%x\n\
-flags:\t%x\n\
+\t..acc:\t%x\tcycles:\t%d\n\
+\t....X:\t%x\tlength:\t%d\n\
+\t....Y:\t%x\t...add:\t%x\n\
+\tstack:\t%x\t.value:\t%x\n\
+\tflags:\t%x\n\
", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P);
}
diff --git a/interpreter.c b/interpreter.c
index 331da43..ff96650 100644
--- a/interpreter.c
+++ b/interpreter.c
@@ -1,33 +1,6 @@
// interpreter.c
// Useful for carrying out tests of the CPU instructions.
-
-/* interpreter.c manual
-
-This program contains many functions which make it easy to write tests for the 6502 CPU.
-
-The expected input is machine code written in plaintext.
-
-The program accepts stdin, so it can be used in two ways.
- - Typing instructions inline.
- - Piping a file in with cat.
-I didn't implement arguments because this is only a debug program.
-
-Here are some valid ways to write an LDA with immediate addressing:
- a901
- A901
- A9 01
-
-The interpreter comes with multiple statements for the purpose of debugging the emulator.
- Qq Quits the program.
- Should be put at the end of a textfile, or the program will segfault (inconsequentially).
- Rr Resets the virtual computer.
- Pp Dumps processor state.
- Mm Dumps a specified page of memory.
- Takes an argument only of the form XX.
- Be aware that unallocated memory is permitted to be dumped.
- / Prints until newline.
- # Ignores until newline.
-*/
+// Refer to interpreter.md for the manual
#include"headers/include.h"
@@ -38,7 +11,6 @@ The interpreter comes with multiple statements for the purpose of debugging the
int main(int argc, char *argv[]){
AppleOn();
-
byte c;
@@ -69,13 +41,22 @@ int main(int argc, char *argv[]){
}
// Dump a page of memory
- if (c == 'M' || c == 'm'){
+ if (c == 'M' || c == 'm'){ //EXPAND, MAKE IT PRINT SINGLE AND PAGE
+ address x = 0;
do {
c = getc(stdin);
} while(c == ' ' || c == '\n');
- c = dCharToNum(c) << 4;
- c += dCharToNum(getc(stdin));
- dPageDump(c);
+ x = dCharToNum(c) << 4;
+ x += dCharToNum(getc(stdin));
+ c = getc(stdin);
+ if (c != '\n'){
+ x <<= 8;
+ x = dCharToNum(c) << 4;
+ x += dCharToNum(getc(stdin));
+ }
+ else{
+ dPageDump(x);
+ }
continue;
}
@@ -96,7 +77,31 @@ int main(int argc, char *argv[]){
continue;
}
- // From here on it is expected input will be mostly correct
+ if (c == 'S' || c == 's'){
+ address x = 0;
+ byte y = 0;
+
+ for(int i = 3; i >= 0; i--){
+ x += (dCharToNum(getc(stdin)) << (4*i));
+ }
+
+ c = getc(stdin);
+ if (c != '.'){
+ printf("Error assigning memory to 0x%x\n", x);
+ break;
+ }
+
+ for(int i = 1; i >= 0; i--){
+ y += (dCharToNum(getc(stdin)) << (4*i));
+ }
+
+ printf("%4x:%2x\n", x, y);
+ Memory[x] = y;
+
+ continue;
+ }
+
+ // From here on it is expected input will be an instruction
c = dCharToNum(c) << 4;
c += dCharToNum(getc(stdin));
address x = 0x0000;
diff --git a/interpreter.md b/interpreter.md
new file mode 100644
index 0000000..54a6c2a
--- /dev/null
+++ b/interpreter.md
@@ -0,0 +1,57 @@
+# interpreter
+
+This is a small program intended to help with testing the 6502 CPU, or running programs on it.
+
+The expected input is machine code written in plaintext.
+
+The program assumes you will write statements correctly so it doesn't waste time checking that you put four digits in instead of three. If you are using this I assume you know what you are doing.
+
+The program accepts stdin, so it can be used in two ways.
+- Typing instructions inline.
+- Piping a file in with cat.
+
+## Instructions
+
+To express the syntax of instructions, here are some valid examples to express LDA $01:
+
+ a901
+ A901
+ A9 01
+
+If you downloaded my project on Github, I have included a PDF called `opcodes_reference.pdf` which has a table with every legal opcode in it.
+
+Statements can be seperated or on a single line. For instance,
+
+ a901
+ p
+ q
+
+Can be written as
+
+ a901pq
+
+The only case in which this should be avoided is after an M/m command.
+
+## Debug Commands
+
+The interpreter comes with multiple statements for the purpose of debugging the emulator.
+
+`Q/q` Quits the program.
+Will cause segfault at end of file if not used.
+
+`R/r` Resets the virtual computer.
+
+`P/p` Dumps processor state.
+
+`M/m` Prints out memory.
+There are two forms which memory can be printed.
+The first is `sXX` where `XX` is a memory page. The whole page of memory is printed onto the screen.
+The second is `sXXXX` where `XXXX` is a specific address. This prints out the value of the 1 byte requested.
+Be aware that unallocated memory will be dumped if it happens to be accessed with this command. Also be aware that there should be a newline directly after this command.
+
+`S/s` Directly set a piece of memory.
+Syntax is strictly of form `sXXXX.xx` where `XXXX` is the address and `xx` is the value.
+
+`/` Prints until newline.
+
+`#` Ignores until newline. \ No newline at end of file
diff --git a/opcodes-reference.pdf b/opcodes-reference.pdf
new file mode 100644
index 0000000..ecff92b
--- /dev/null
+++ b/opcodes-reference.pdf
Binary files differ
diff --git a/test/adc.test b/test/adc.test
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/adc.test
diff --git a/test/load.test b/test/load.test
new file mode 100644
index 0000000..14cdc44
--- /dev/null
+++ b/test/load.test
@@ -0,0 +1,19 @@
+#/Beginning of test.
+s0000.01
+s0001.02
+s000a.64
+s000b.48
+s020c.7f
+
+a201 #LDX $1
+
+a9ff 8510 #LDA FF, store in 0010
+a50a 8511 #LDA ZP 0a, store in 0011
+b50a 8512 #LDA ZP+X 0a, store in 0012
+
+ad000a 8513 #LDA Abs, store in 0013
+bd000a 8513 #LDA Abs+X, store in 0014
+
+m00
+m0001
+q