diff options
Diffstat (limited to 'interpreter.c')
-rw-r--r-- | interpreter.c | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/interpreter.c b/interpreter.c index 14ef400..fece473 100644 --- a/interpreter.c +++ b/interpreter.c @@ -1,61 +1,47 @@ -//interpreter.c is a tool which can interpret 6502 assembly on the go, for the purposes of testing. -/* Special Commands for debug information - Q - Quit - P - Processor status dump - M - Dump a page of memory -*/ - -#include"headers/include.h" +// test.c +// Temporary .c file where arbitrary tests are carried out. + +#include"headers/include.h" //LOOK INTO PTHREADS #include"headers/debug.h" -int main(){ - AppleOn(); - - while(1){ - c = fgetc(stdin); - - // Exit condition - if ( (c == 'Q') || (c == 'q') || (c == EOF) ) break; - - if (dCharToNum(c) == -1){ - // Debug print conditions - switch(c){ - // Print debug information - case 'P': case 'p': - dStatusDump(); - break; - // Dump memory page - case 'M': case 'm': - byte m; - m += dCharToNum(fgetc(stdin)) << 4; - m += dCharToNum(fgetc(stdin)); - dPageDump(m); - break; - case ' ': case '\n': - break; - } - }else{ // RUN INSTRUCTION - // Pass in Instruction - byte inst = dCharToNum(c) << 4; - inst += dCharToNum(fgetc(stdin)); - // Pass in Value - address pass = 0x0000; - int range = fAddressGetLength(getITAddressing(inst)); - printf("range = %d\n", range); //DEBUG - range = ((2*range)-2); - c = fgetc(stdin); - for(int i = 0; i < range; i++){ - if ((c == ' ') || (c == '\n')){ - i--; - }else{ - pass <<= 4; - pass += c; - } - c = fgetc(stdin); - } - current_instruction = getITFunction(inst); - callIT(current_instruction, pass); - } - } - return 0; -}
\ No newline at end of file +int main(int argc, char *argv[]){ + AppleOn(); + + + byte c; + + // Interpreter loop + while(1){ + do { + c = getc(stdin); + } while (c == '\n' || c == ' '); + + if (c == 'P' || c == 'p'){ + dStatusDump(); + continue; + } + + if (c == 'M' || c == 'm'){ + c = dCharToNum(getc(stdin)) << 4; + c += dCharToNum(getc(stdin)); + dPageDump(c); + 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{ + i++; + } + } + callInstructionTable(c, x); + } + +} |