nesemu/rom/rom.c

39 lines
860 B
C

//
// Created by william on 12/2/23.
//
#include <stdio.h>
#include "../include/rom.h"
#include "ines.c"
#include "../include/system.h"
bool rom_load(char *path) {
FILE *file = fopen(path, "r");
if (!file) {
log_error("Failed to open ROM");
return false;
}
char header_buffer[ROM_HEADER_SIZE] = {0};
size_t read_size = fread(header_buffer, sizeof(char), ROM_HEADER_SIZE, file);
if (read_size < ROM_HEADER_SIZE) {
log_error("Failed to read ROM");
return false;
}
if (!rom_is_ines(header_buffer)) {
log_error("Only iNes ROMs are supported");
return false;
}
log_info("Reading iNes 1.0 ROM at %s", path);
rom_ines_read(header_buffer, file);
if (fclose(file) != 0) {
log_error("Failed to close ROM file");
return false;
}
return true;
}