From 79456640c548cff9125a5ba137538642e3c41141 Mon Sep 17 00:00:00 2001 From: alekseiplusplus Date: Tue, 12 Dec 2023 10:29:53 +1100 Subject: added cmd args; changed video implementation --- src/main.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 115 insertions(+), 21 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index f1dfada..bef94b1 100644 --- a/src/main.c +++ b/src/main.c @@ -2,15 +2,105 @@ #include "video/interface.h" #include #include "cpu/6502.h" +#include "string.h" -int main() { +#define HelpPrintout "\ +Usage: apple-c [ options ]\n\ +An Apple-I emulator written in C.\n\ +\n\ +Options:\n\ + -m, --memory [NUM] Set RAM memory size to NUM pages; one page is 1024 bytes.\n\ + Value must be between 4-64. 4 is the default.\n\ + -t, --terminal Use ncurses (terminal) display mode. Default mode.\n\ + -g, --graphical Use SDL (graphical) display mode.\n\ + -i, --information Turn information overlay (default off).\n\ + -l, --logging Toggle logging of computer state every cycle (default off).\n\ +" - AppleOn(); +int main(int argc, char* argv[]) { + + int print_info = 0; + int logging = 0; + int memory = 4; + + // + // ARGUMENT PARSING + // + + for (int i = 1; i < argc; i++) { + + // Help + + if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + // Print help and terminate straight away. + printf(HelpPrintout); + exit(0); + } + + // Memory + + if (!strcmp(argv[i], "-m") || !strcmp(argv[i], "--memory")) { + // Increment i, and check bounds. + if (++i >= argc) { + printf("Memory argument not set.\n"); + exit(1); + } + // If able, get next argument, and set memory to it. + else { + memory = strtol(argv[i], NULL, 10); + if ((4 > memory) || (memory > 64)) { + printf("Invalid value for setting memory.\n"); + exit(1); + } + } + goto SkipIteration; + } + + // Display + + if (!strcmp(argv[i], "-t") || !strcmp(argv[i], "--terminal")) { + SetDisplayMode(0); + goto SkipIteration; + } + + if (!strcmp(argv[i], "-g") || !strcmp(argv[i], "--graphical")) { + SetDisplayMode(1); + goto SkipIteration; + } + + // Logging + + if (!strcmp(argv[i], "-l") || !strcmp(argv[i], "--information")) { + logging = 1; + goto SkipIteration; + } + + // Information Display + + if (!strcmp(argv[i], "-i") || !strcmp(argv[i], "--information")) { + print_info = 1; + goto SkipIteration; + } + + printf("Unrecognized arguments.\n"); + exit(1); + SkipIteration: + } + + // + // EMULATION + // + + AppleOn(memory); DisplayInit(); - FILE *Log = fopen("log/log.raw", "w+"); + FILE *Log; + if (logging) { + Log = fopen("log/log.raw", "w+"); + } + int Time = 0; while(1) { @@ -18,27 +108,31 @@ int main() { CallInstructionTable(); // Logging - if (Time >= 0x2000) - // Stop logging after an arbitrary amount of time, so as to not create a huge file. - fclose(Log); - else { - fprintf(Log, - "%04x : %04x : %02x : %02x : %02x : %c%c_%c%c%c%c%c : %02x\n", - Time, PC, acc, X, Y, - GetFlag(flag_N) ? 'N':'.' , - GetFlag(flag_V) ? 'V':'.' , - GetFlag(flag_B) ? 'B':'.' , - GetFlag(flag_D) ? 'D':'.' , - GetFlag(flag_I) ? 'I':'.' , - GetFlag(flag_Z) ? 'Z':'.' , - GetFlag(flag_C) ? 'C':'.' , - S); - fflush(Log); - Time++; + if (logging) { + if (Time >= 0x2000) + // Stop logging after an arbitrary amount of time, so as to not create a huge file. + fclose(Log); + else { + fprintf(Log, + "%04x : %04x : %02x : %02x : %02x : %c%c_%c%c%c%c%c : %02x\n", + Time, PC, acc, X, Y, + GetFlag(flag_N) ? 'N':'.' , + GetFlag(flag_V) ? 'V':'.' , + GetFlag(flag_B) ? 'B':'.' , + GetFlag(flag_D) ? 'D':'.' , + GetFlag(flag_I) ? 'I':'.' , + GetFlag(flag_Z) ? 'Z':'.' , + GetFlag(flag_C) ? 'C':'.' , + S); + fflush(Log); + Time++; + } } // Display information - PrintInfo(); + if (print_info) { + PrintInfo(); + } } DisplayClose(); -- cgit v1.2.3