// emulator.c // SplitBit Emulator // Small 8-Bit Harvard Architecture CPU // Written by Anachronaut // 10/15/2024 // // ---- The machine with a terminal attached ---- // // This is a front end and nothing else. The machine itself is in machine.c, shared with // Voyager, which is the same machine with a screen and a speaker instead of a terminal. // // Keeping this file small is the point rather than a side effect: anything that ends up // here is behaviour Voyager does not have, and the two are supposed to differ only in // what they present. This builds and runs anywhere, with no graphics library, which is // what keeps the whole toolchain and the whole suite dependency free. #include "machine.h" #include "utility.h" #include #include int main(int argc, char *argv[]) { EmulatorOptions options; uint8_t result = parseOptions(argc, argv, &options); if (result == OPTIONS_HELP) { // The user asked for help and got it, which is not a failure. return 0; } else if (result == OPTIONS_ERROR) { // Bad command line, don't execute. return 1; } char *programFile = NULL; if (optind < argc) { programFile = argv[optind]; optind++; } if (optind < argc) { fprintf(stderr, "Error: Unexpected argument: %s\n", argv[optind]); return 1; } Machine machine; uint8_t started = machineStart(&machine, &options, programFile); if (started == MACHINE_NOTHING_TO_RUN) { fprintf(stderr, "Error: No boot image and no disk, so there is nothing to run.\n"); printHelp(argv[0]); return 1; } else if (started != MACHINE_OK) { return 1; } while (machineRunning(&machine)) { machineRunSlice(&machine); } machineStop(&machine); return machineReport(&machine); }