fix(rom): display error message and free memory on rom load failure

This commit is contained in:
Stevan Freeborn
2026-07-18 15:16:39 -05:00
parent 4f3ea9697e
commit 0e48860b69
+9 -3
View File
@@ -282,9 +282,15 @@ int main(int argc, char *argv[]) {
int load_rom_result = load_rom(chip, argv[1]);
if (load_rom_result != 0) {
// TODO: Check for return value
// print helpful error message
if (load_rom_result != COMPLETED_SUCCESSFULLY) {
if (load_rom_result == FILE_MISSING) {
println("Error: The file '%s' could not be found or opened.", argv[1]);
} else if (load_rom_result == PROGRAM_TOO_LARGE) {
println("Error: The program is too large to fit in CHIP-8 memory.");
} else {
println("Error: Failed to load ROM (code %d).", load_rom_result);
}
free(chip);
return load_rom_result;
}