diff options
author | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-03 11:32:39 +1100 |
---|---|---|
committer | alekseiplusplus <alekseijeaves@protonmail.com> | 2023-12-03 11:32:39 +1100 |
commit | 991c09b01e6b099a5b00d7a9236d252b85a714b5 (patch) | |
tree | bee9445cbd318bbf7a805c80b5bc4b94517b44df /src | |
parent | 7a5672d085399d0de9d2c77431ea7a2f089faacb (diff) |
half-fixed infinite loop; new debug util, old one out
Diffstat (limited to 'src')
-rw-r--r-- | src/apple.h | 2 | ||||
-rw-r--r-- | src/cpu/instructions.c | 2 | ||||
-rw-r--r-- | src/debug.h | 58 | ||||
-rw-r--r-- | src/interpreter.c | 122 | ||||
-rw-r--r-- | src/main.c | 14 |
5 files changed, 14 insertions, 184 deletions
diff --git a/src/apple.h b/src/apple.h index d423074..244f1b3 100644 --- a/src/apple.h +++ b/src/apple.h @@ -4,7 +4,7 @@ #include <stdio.h> #include <stdlib.h> -#define MEMORY_SIZE 4096 +#define MEMORY_SIZE 0x0400 #define XAML 0x24 #define XAMH 0x25 diff --git a/src/cpu/instructions.c b/src/cpu/instructions.c index da093ec..2d4fc9e 100644 --- a/src/cpu/instructions.c +++ b/src/cpu/instructions.c @@ -309,7 +309,7 @@ void fPLP(Addressing addr, address val){ void fJSR(Addressing addr, address val){ SetStack((PC+3) >> 8); SetStack((PC+3) & 0x00FF); - PC = idata.add; + PC = idata.add; PC -= 3; } void fRTS(Addressing addr, address val){ diff --git a/src/debug.h b/src/debug.h deleted file mode 100644 index 59e3c47..0000000 --- a/src/debug.h +++ /dev/null @@ -1,58 +0,0 @@ -// debug.h -// Various functions useful for use during development. - -#include"stdio.h" -#include"cpu/6502.h" -#include"cpu/addressing.h" -#include"cpu/core.h" -#include"cpu/instructions.h" -#include"cpu/table.h" - - - -// Converts a single character to hexadecimal -int dCharToNum(char c){ - // 0x0 - 0x9 - if (c != 0x20 && (c >= 0x30 && c <= 0x39)){ - return (c - 0x30); - } - // 0xA - 0xF - else if (c != 0x20 && (c >= 0x41 && c <= 0x46)){ - return (c - 0x37); - // 0xa - 0xf - }else if (c != 0x20 && (c >= 0x61 && c <= 0x66)){ - return (c - 0x57); - // Invalid - }else{ - return -1; - } -} - -// Dump page m from memory to stdout. -void dPageDump(short m){ - m <<= 8; - for(int i = 0; i < 256; i+=16){ - printf("\t"); - for(int j = 0; j < 16; j+=1){ - if ((j+1) % 4 == 0){ - printf("%02x ", GetMemory((m+(i+j)))); - } - else { - printf("%02x ", GetMemory((m+(i+j)))); - } - } - printf("\n"); - } -} - -// Dump CPU values -void dStatusDump(void){ -printf("\ -\t..acc:\t%x\tcycles:\t%d\n\ -\t....X:\t%x\tlength:\t%d\n\ -\t....Y:\t%x\t...add:\t%x\n\ -\tstack:\t%x\t.value:\t%x\n\ -\tflags:\t%x\t....PC:\t%x\n\ -\n\ -", acc, idata.cycles, X, idata.length, Y, idata.add, S, idata.value, P, PC); -} diff --git a/src/interpreter.c b/src/interpreter.c deleted file mode 100644 index 6dc7178..0000000 --- a/src/interpreter.c +++ /dev/null @@ -1,122 +0,0 @@ -// interpreter.c -// Useful for carrying out tests of the CPU instructions. -// Refer to interpreter.md for the manual - -#include"apple.h" -#include"debug.h" - -//Write a custom getc function here which ignores spaces - - -int main(int argc, char *argv[]){ - AppleOn(); - - byte c; - - // Interpreter loop - while(1){ - - // Retrieve first character of a line - do { - c = getc(stdin); - } while (c == '\n' || c == ' ' || c == '\t'); - - // The following are special debug commands. - - // Quit program - if (c == 'Q' || c == 'q'){ - break; - } - - if (c == 'R' || c == 'r'){ - AppleReset(); //need to flesh out this function - continue; - } - - // Dump processor status - if (c == 'P' || c == 'p'){ - dStatusDump(); - continue; - } - - // FIXME!!! PAGE IS CLAMPED TO 00 ON THE LONG MODE - // Dump a page of memory - if (c == 'M' || c == 'm'){ - address x = 0; - do { - c = getc(stdin); - } while(c == ' ' || c == '\n'); - x = dCharToNum(c) << 4; - x += dCharToNum(getc(stdin)); - c = getc(stdin); - if (c != '\n'){ - x <<= 8; - x += dCharToNum(c) << 4; - x += dCharToNum(getc(stdin)); - printf("@%04x:%02x\n", x, GetMemory(x)); - } - else{ - printf("Page %02x", x); - dPageDump(x); - } - continue; - } - - // Print out a statement - if (c == '/'){ - do { - c = getc(stdin); - printf("%c", c); - } while(c != '\n'); - continue; - } - - // Comment, so ignores until newline. - if (c == '#'){ - do { - c = getc(stdin); - } while(c != '\n'); - continue; - } - - if (c == 'S' || c == 's'){ - address x = 0; - byte y = 0; - - for(int i = 3; i >= 0; i--){ - x += (dCharToNum(getc(stdin)) << (4*i)); - } - - c = getc(stdin); - if (c != '.'){ - printf("Error assigning memory to 0x%x\n", x); - break; - } - - for(int i = 1; i >= 0; i--){ - y += (dCharToNum(getc(stdin)) << (4*i)); - } - Memory[x] = y; - continue; - } - - // From here on it is expected input will be an instruction - c = dCharToNum(c) << 4; - c += dCharToNum(getc(stdin)); - address x = 0x0000; - char z = 0x00; - for(int i = ((getInstructionLength(c) * 2) - 2); i > 0; i--) { - do { - z = getc(stdin); - } while (z == ' ' || z == '\t'); - - //if (z != '\n'){ - x += dCharToNum(z) << ((4 * (i - 1))); - /*}else{ - i++; - }*/ - } - CallInstructionTable(c, x); - } - -} @@ -3,6 +3,8 @@ #include <ncurses.h> #include <unistd.h> + + int main() { @@ -10,11 +12,19 @@ int main() { DisplayInit(); + FILE *Log = fopen("log/log.raw", "w+"); + int Time = 0; + while(1) { + // Logging + fprintf(Log, "%04x : %04x\n", Time, PC); + fflush(Log); + // Computing CallInstructionTable(GetMemory(PC), 0); + // Display information PrintInfo(); - //sleep(3); - //getch(); + // Logging + Time++; } DisplayClose(); |