goobers
Member
Hey, I'm currently working on a little Chip8 emulator and I'm reading the contents of a file into an array.
Problem is that Chip8 programs all start at memory address 0x200. Basically, how could I shift all the data in the array 200 bytes?
The code I'm using at the moment is as below:
CODE
char * memory; // Set up an array for the memory
unsigned char V[16];
FILE * pFile;
long fSize;
size_t result;
char * pFileName;
pFileName = "test.bin";
pFile = fopen ( pFileName, "rb");
if (pFile==NULL) {fprintf(stderr, "Error opening file"); return 0;}
else
{
fseek (pFile, 0, SEEK_END);
fSize = ftell (pFile);
rewind (pFile);
// Size the memory buffer to the size of the input file
memory = (char*) malloc ((sizeof(char)*fSize)+200);
if (memory == NULL) {fprintf(stderr, "Error creating memory buffer"); return 0;}
// Copy the file into the memory buffer
result = fread (memory,1, fSize,pFile);
if (result != fSize) {fprintf(stderr, "Error reading file"); return 0;}
}
Problem is that Chip8 programs all start at memory address 0x200. Basically, how could I shift all the data in the array 200 bytes?
The code I'm using at the moment is as below:
CODE
char * memory; // Set up an array for the memory
unsigned char V[16];
FILE * pFile;
long fSize;
size_t result;
char * pFileName;
pFileName = "test.bin";
pFile = fopen ( pFileName, "rb");
if (pFile==NULL) {fprintf(stderr, "Error opening file"); return 0;}
else
{
fseek (pFile, 0, SEEK_END);
fSize = ftell (pFile);
rewind (pFile);
// Size the memory buffer to the size of the input file
memory = (char*) malloc ((sizeof(char)*fSize)+200);
if (memory == NULL) {fprintf(stderr, "Error creating memory buffer"); return 0;}
// Copy the file into the memory buffer
result = fread (memory,1, fSize,pFile);
if (result != fSize) {fprintf(stderr, "Error reading file"); return 0;}
}