diff options
Diffstat (limited to 'interpreter.c')
-rw-r--r-- | interpreter.c | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/interpreter.c b/interpreter.c index 82cb9b2..ee30258 100644 --- a/interpreter.c +++ b/interpreter.c @@ -10,41 +10,40 @@ */ #include"include.h" - -int charToNum (char c, int mul) { - if (c != 0x20 && (c >= 0x30 && c <= 0x39)){ - a = (mul * (c - 0x30)); - }else if (c != 0x20 && (c >= 0x41 && c <= 0x46)){ - a = (mul * (c - 0x31)); - } -} - - +#include"debug.h" int main(){ char c; unsigned char a, b; - while(true){ - // Pass 1 + while(1){ c = getchar(); - if (c == EOF) break; - switch(c){ - case D: case d: - debug_print(); - break; - case M: case m: - int m = 0; - for(int i = 1; i <= 1000; i *= 10){ - m += charToNum(getchar(), 1000/i); - } - printf("Address %d has %x", m, Memory[m]); - break; + + // Exit condition + if ( (c == 'X') || (c == 'x') ) break; + + if (dChar2Num(c) == -1){ + // Debug print conditions + switch(c){ + case 'P': case 'p': // Print debug information + debug_print(); + break; + case 'M': case 'm': // Dump memory page + dChar2Num(getchar()); + printf("Address %d has %x", m, Memory[m]); + break; + case ' ': + break; + } + }else{ + // Run Instruction + } - a += charToNum(c, 0x10); + + a += dChar2Num(c, 0x10); // Pass 2 c = getchar(); if (c == EOF) break; - a += charToNum(c, 0x01); + a += dChar2Num(c, 0x01); //Check for next value c = getchar(); if (!(c == EOF || c == ' ')) { @@ -57,7 +56,8 @@ int main(){ c = getchar(); if (c == EOF) break; b += charToNum(c, 0x0001); } - runInstruction(a, b); + //runInstruction(a, b); c = getchar(); if (c == EOF) break; } + return 0; }
\ No newline at end of file |