/* * 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. * There are a few special characters which print debug information Q - Quit P - Processor status dump M - Dump a page of memory */ #include"include.h" #include"debug.h" int main(){ char c; unsigned char a, b; 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 ' ': 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)); range = ((2*range)-2); c = fgetc(stdin); for(int i = 0; i < range; i++){ if (c != ' ' && c != EOF){ pass <<= 4; pass += c; c = fgetc(stdin); }else{ break; } } current_instruction = getITFunction(inst); callIT(current_instruction, pass); } } return 0; }