// utility.h // Utilities for the SplitBit CPU Emulator // Written by Anachronaut // 10/15/2024 #ifndef UTILITY_H #define UTILITY_H #include #include "io.h" #include "cpu.h" // Results of reading the command line. #define OPTIONS_OK 0 // Carry on and run the program. #define OPTIONS_HELP 1 // The user asked for help, so stop, but not because of an error. #define OPTIONS_ERROR 2 // The command line was no good, stop and complain. typedef struct { uint8_t debug; // Step one instruction at a time, printing the registers. uint8_t fast; // Ignore the cycle rate and run as fast as the host allows. unsigned long cycles; // Stop after this many cycles. Zero means run until the program halts. unsigned long diskCycles; // How long a block move takes. Zero is instant, and the default. // ---- The drives, in the order they were named ---- // // --disk given more than once fills them in turn, so the first is drive 0 and the machine // has as many as were asked for. One name is the ordinary case and reads exactly as it // did when there could only be one. const char *disk; // Disk image to attach, or NULL for a machine with no disk. const char *disks[DISK_DRIVE_COUNT]; int diskCount; uint8_t writeProtect; // Attach the disk read only, the way a tab on a floppy would. const char *screen; // Where to save a picture of the screen when the machine stops. const char *keyboard; // Feed the console from this file as a keyboard, not a terminal. const char *sound; // Where to save the samples the machine made, as raw 16 bit. } EmulatorOptions; uint8_t parseOptions(int argc, char *argv[], EmulatorOptions *options); void printHelp(const char *programName); uint8_t loadFile(const char *path, uint8_t *Program, uint8_t *Data); void bootStrap(uint8_t *Program, uint8_t *Data); void printRegisters(CPURegisters *cpu, uint8_t *Program, uint8_t *Data); #endif // UTILITY_H