summaryrefslogtreecommitdiff
path: root/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/debug.c b/debug.c
new file mode 100644
index 0000000..ec6a75a
--- /dev/null
+++ b/debug.c
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ *
+ */
+
+#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));
+ }
+}
+
+int main(){
+ char c;
+ unsigned char a, b;
+ while(true){
+ // Pass 1
+ c = getchar(); if (c == EOF) 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