NESDev and Strangulation Records messageboards
Forum Index | FAQ | New User | Login | Search

Previous ThreadView All ThreadsNext ThreadShow in Flat Mode*


SubjectUnsigned charmander go!  
Posted bytepples
Posted on9/14/04 03:53 AM
From IP68.53.188.30  



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.

-
Entire Thread
Subject  Posted byPosted On
*Importing and another question  Anonymous9/13/04 00:07 AM
.*Re: Importing and another question  Disch9/13/04 3:32 PM
..*Re: Importing and another question  Anonymous9/14/04 00:41 AM
...*Re: Importing and another question  Fx39/14/04 02:15 AM
....*Re: Importing and another question  Anonymous9/14/04 03:00 AM
.....*Re: Importing and another question  Anonymous9/14/04 2:44 PM
......Unsigned charmander go!  tepples9/14/04 03:53 AM
......*Re: Unsigned charmander go!  Fx39/14/04 03:59 AM
.......*Re: Unsigned charmander go!  Anonymous9/14/04 11:49 AM
..*Re: Importing and another question  Fx39/13/04 8:41 PM
...*Re: Importing and another question  Disch9/13/04 10:05 PM
.*Re: Importing and another question  Memblers9/13/04 11:20 AM
Jump to

Memblers' homepage             Contact Me

Forums powered by WWWThreads Demo