gb6/src/rom.c

37 lines
578 B
C
Raw Permalink Normal View History

2019-04-16 06:25:00 +00:00
#include <stdlib.h>
#include <stdio.h>
#include "rom.h"
#include "types.h"
int rom_load(struct rom *rom, const char *filename)
{
FILE *fp;
int len;
fp = fopen(filename, "r");
if (!fp) {
return 0;
}
fseek(fp, 0, SEEK_END);
len = ftell(fp);
rewind(fp);
rom->data = malloc(len);
2022-07-21 03:21:36 +00:00
rom->length = len;
2019-04-16 06:25:00 +00:00
if (fread(rom->data, 1, len, fp) < len) {
return 0;
}
2022-08-02 03:45:37 +00:00
rom->mbc = mbc_new(rom->data[0x147]);
if (!rom->mbc) {
return 0;
}
2019-04-16 06:25:00 +00:00
return 1;
}
void rom_free(struct rom *rom)
{
free(rom->data);
}