summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--headers/apple.h4
-rw-r--r--interpreter.c93
-rw-r--r--makefile2
3 files changed, 86 insertions, 13 deletions
diff --git a/headers/apple.h b/headers/apple.h
index cfcc879..b17124b 100644
--- a/headers/apple.h
+++ b/headers/apple.h
@@ -5,7 +5,9 @@ void AppleOn(){
initInstructionTable();
}
-void AppleReset(){ //Firt few Zp addresses have gibberish, need to fix
+void AppleReset(){
+ acc = 0; X = 0; Y = 0; P = 0; S = 0;
+ idata.cycles = 0; idata.length = 0; idata.add = 0; idata.value = 0;
free(Memory);
Memory = calloc(MEMORY_SIZE, sizeof(byte));
} \ No newline at end of file
diff --git a/interpreter.c b/interpreter.c
index fece473..331da43 100644
--- a/interpreter.c
+++ b/interpreter.c
@@ -1,9 +1,41 @@
-// test.c
-// Temporary .c file where arbitrary tests are carried out.
+// interpreter.c
+// Useful for carrying out tests of the CPU instructions.
-#include"headers/include.h" //LOOK INTO PTHREADS
+/* 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.
+*/
+
+
+#include"headers/include.h"
#include"headers/debug.h"
+//Write a custom getc function here which ignores spaces
+
+
int main(int argc, char *argv[]){
AppleOn();
@@ -12,34 +44,73 @@ int main(int argc, char *argv[]){
// Interpreter loop
while(1){
+
+ // Retrieve first character of a line
do {
c = getc(stdin);
- } while (c == '\n' || c == ' ');
+ } while (c == '\n' || c == ' ' || c == '\t');
+
+ // The following are special debug commands.
+ // Quit program
+ if (c == 'Q' || c == 'q'){
+ break;
+ }
+
+ if (c == 'R' || c == 'r'){
+ AppleReset(); //need to flesh out this function
+ continue;
+ }
+
+ // Dump processor status
if (c == 'P' || c == 'p'){
dStatusDump();
continue;
}
- if (c == 'M' || c == 'm'){
- c = dCharToNum(getc(stdin)) << 4;
+ // Dump a page of memory
+ if (c == 'M' || c == 'm'){
+ do {
+ c = getc(stdin);
+ } while(c == ' ' || c == '\n');
+ c = dCharToNum(c) << 4;
c += dCharToNum(getc(stdin));
dPageDump(c);
continue;
}
+ // Print out a statement
+ if (c == '/'){
+ do {
+ c = getc(stdin);
+ printf("%c", c);
+ } while(c != '\n');
+ continue;
+ }
+
+ // Comment, so ignores until newline.
+ if (c == '#'){
+ do {
+ c = getc(stdin);
+ } while(c != '\n');
+ continue;
+ }
+
// From here on it is expected input will be mostly correct
c = dCharToNum(c) << 4;
c += dCharToNum(getc(stdin));
address x = 0x0000;
char z;
for(int i = ((fAddressGetLengthPrempt(c) * 2) - 2); i > 0; i--) {
- z = getc(stdin);
- if (z != '\n'){
- x += dCharToNum(z) << ((4 * (i - 1)));
- }else{
+ do {
+ z = getc(stdin);
+ } while (z == ' ' || z == '\t');
+
+ //if (z != '\n'){
+ x += dCharToNum(z) << ((4 * (i - 1)));
+ /*}else{
i++;
- }
+ }*/
}
callInstructionTable(c, x);
}
diff --git a/makefile b/makefile
index 7fe60de..44bb2c1 100644
--- a/makefile
+++ b/makefile
@@ -1,2 +1,2 @@
main:
- gcc interpreter.c -o a
+ gcc interpreter.c -o interpreter \ No newline at end of file