/* * interpreter.c WILL BE 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" #include"debug.h" int main(){ char c; unsigned char a, b; while(1){ c = getchar(); // 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 += dChar2Num(c, 0x10); // Pass 2 c = getchar(); if (c == EOF) break; a += dChar2Num(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; } return 0; }