|
Short answer When in doubt, read binary files such as the PRG and CHR sections of a UNIF or iNES file into an array of unsigned char.
Long answer Extremely simplified, with no error checking (you'll need to test that fopen, fread, and malloc don't return 0), and untested, but hopefully enough to give the gist:
unsigned char *prg_data, *chr_data; unsigned long int prg_data_size, chr_data_size; char chr_writable; FILE *infile;
infile = fopen("Tetramino.nes", "rb"); fread(iNES_header, 16, 1, infile); unsigned long int prg_data_size = iNES_header.prg_size * 16384; unsigned char *prg_data = malloc(prg_data_size); fread(prg_data, prg_data_size, 1, infile); if(iNES_header.chr_size > 0) { chr_data_size = iNES_header.chr_size * 8192; chr_data = malloc(chr_data_size); fread(chr_data, chr_data_size, 1, infile); chr_writable = 0; } else { chr_data_size = 8192; chr_data = malloc(chr_data_size); chr_writable = 1; } fclose(infile);
____________________ My English is better than your Geberquen.
|