From 5f11aac2f0a8c2bbc86180161d94158e890da285 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Mon, 27 Mar 2023 20:30:26 +1100 Subject: debug.c > interpreter.c --- debug.c | 63 --------------------------------------------------------- interpreter.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 63 deletions(-) delete mode 100644 debug.c create mode 100644 interpreter.c diff --git a/debug.c b/debug.c deleted file mode 100644 index 4e0b270..0000000 --- a/debug.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * debug.c is a tool which can be used to interpret 6502 machine code inline. - * Machine code is expected as hexadecimal of length 2 or 6, depending on the instruction. - * Note that zero-page addressing is not fully emulated yet; it will still address the zero-page - section of memory but the instructions still take an address of length 4. - This will be fixed later when the whole system is functional. - * There are a few special keywords which have particular debugging meaning - */ - -#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)); - } -} - -void debug_print(){ - printf("\nacc:\t%x\nX:\t%x\nY:\t%x\nstack:\t%x\nflags:\t%x", acc, X, Y, S, P); -} - -int main(){ - char c; - unsigned char a, b; - while(true){ - // Pass 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; - - } - a += charToNum(c, 0x10); - // Pass 2 - c = getchar(); if (c == EOF) break; - a += charToNum(c, 0x01); - //Check for next value - c = getchar(); - if (!(c == EOF || c == ' ')) { - // Four passes - b += charToNum(c, 0x1000); - c = getchar(); if (c == EOF) break; - b += charToNum(c, 0x0100); - c = getchar(); if (c == EOF) break; - b += charToNum(c, 0x0010); - c = getchar(); if (c == EOF) break; - b += charToNum(c, 0x0001); - } - runInstruction(a, b); - c = getchar(); if (c == EOF) break; - } -} \ No newline at end of file diff --git a/interpreter.c b/interpreter.c new file mode 100644 index 0000000..0df27ce --- /dev/null +++ b/interpreter.c @@ -0,0 +1,65 @@ +/* + * interpreter.c is a tool which can be used to interpret 6502 machine code inline. + * Machine code is expected as hexadecimal of length 2 or 6, depending on the instruction. + * Note that zero-page addressing is not fully emulated yet; it will still address the zero-page + section of memory but the instructions still take an address of length 4. + This will be fixed later when the whole system is functional. + * There are a few special characters which print debug information + d Prints main system information + mXXXX Prints contents of particular memory location + */ + +#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)); + } +} + +void debug_print(){ + printf("\nacc:\t%x\nX:\t%x\nY:\t%x\nstack:\t%x\nflags:\t%x", acc, X, Y, S, P); +} + +int main(){ + char c; + unsigned char a, b; + while(true){ + // Pass 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; + + } + a += charToNum(c, 0x10); + // Pass 2 + c = getchar(); if (c == EOF) break; + a += charToNum(c, 0x01); + //Check for next value + c = getchar(); + if (!(c == EOF || c == ' ')) { + // Four passes + b += charToNum(c, 0x1000); + c = getchar(); if (c == EOF) break; + b += charToNum(c, 0x0100); + c = getchar(); if (c == EOF) break; + b += charToNum(c, 0x0010); + c = getchar(); if (c == EOF) break; + b += charToNum(c, 0x0001); + } + runInstruction(a, b); + c = getchar(); if (c == EOF) break; + } +} \ No newline at end of file -- cgit v1.2.3