From 07980e780e331352ea81d0176d9028325968a771 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Tue, 11 Apr 2023 13:30:17 +1000 Subject: interpreter.c can run, but segfaults. --- interpreter.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'interpreter.c') diff --git a/interpreter.c b/interpreter.c index 766d387..652c181 100644 --- a/interpreter.c +++ b/interpreter.c @@ -14,7 +14,7 @@ int main(){ char c; unsigned char a, b; while(1){ - c = getchar(); + c = fgetc(stdin); // Exit condition if ( (c == 'Q') || (c == 'q') || (c == EOF) ) break; @@ -28,29 +28,33 @@ int main(){ break; // Dump memory page case 'M': case 'm': - dPageDump(); + byte m; + m += dCharToNum(fgetc(stdin)) << 4; + m += dCharToNum(fgetc(stdin)); + dPageDump(m); break; case ' ': break; } - }else{ - // Run Instruction + }else{ // RUN INSTRUCTION + // Pass in Instruction byte inst = dCharToNum(c) << 4; - inst += dCharToNum(getch()); - address pass = 0; - int temp = fAddressGetLength(getITAddressing(inst)); - temp *= 2; - c = getch(); - for(int i = 0; i < temp; i++) + 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 = getch(); + c = fgetc(stdin); }else{ break; } } - current_instruction = IT[inst]; + current_instruction = getITFunction(inst); callIT(current_instruction, pass); } } -- cgit v1.2.3