diff options
Diffstat (limited to 'interpreter.c')
-rw-r--r-- | interpreter.c | 73 |
1 files changed, 39 insertions, 34 deletions
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; |