summaryrefslogtreecommitdiff
path: root/src/interpreter.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interpreter.c')
-rw-r--r--src/interpreter.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/interpreter.c b/src/interpreter.c
new file mode 100644
index 0000000..ed6aaee
--- /dev/null
+++ b/src/interpreter.c
@@ -0,0 +1,123 @@
+// interpreter.c
+// Useful for carrying out tests of the CPU instructions.
+// Refer to interpreter.md for the manual
+
+
+#include"include.h"
+#include"debug.h"
+
+//Write a custom getc function here which ignores spaces
+
+
+int main(int argc, char *argv[]){
+ AppleOn();
+
+ byte c;
+
+ // Interpreter loop
+ while(1){
+
+ // Retrieve first character of a line
+ do {
+ c = getc(stdin);
+ } 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;
+ }
+
+ // FIXME!!! PAGE IS CLAMPED TO 00 ON THE LONG MODE
+ // Dump a page of memory
+ if (c == 'M' || c == 'm'){
+ address x = 0;
+ do {
+ c = getc(stdin);
+ } while(c == ' ' || c == '\n');
+ x = dCharToNum(c) << 4;
+ x += dCharToNum(getc(stdin));
+ c = getc(stdin);
+ if (c != '\n'){
+ x <<= 8;
+ x += dCharToNum(c) << 4;
+ x += dCharToNum(getc(stdin));
+ printf("@%04x:%02x\n", x, Memory[x]);
+ }
+ else{
+ printf("Page %02x", x);
+ dPageDump(x);
+ }
+ 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;
+ }
+
+ 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));
+ }
+ 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;
+ char z = 0x00;
+ for(int i = ((fAddressGetLengthPrempt(c) * 2) - 2); i > 0; i--) {
+ do {
+ z = getc(stdin);
+ } while (z == ' ' || z == '\t');
+
+ //if (z != '\n'){
+ x += dCharToNum(z) << ((4 * (i - 1)));
+ /*}else{
+ i++;
+ }*/
+ }
+ callInstructionTable(c, x);
+ }
+
+}