I'm trying to port my CHIP-8 emulator from C# to C for the Prizm. I'm having a problem loading files, though:
Code:
It should prompt for a filename without the extension. The file is a .ch8 ROM, and it fails to load the file into memory. The file that I'm using is exactly 144 bytes, so I'm using that magic number for testing. I would like to get it working with files of any size in the future, but right now I want to get this file loaded successfully.
Code:
void LoadFile(void)
{
char errcode = 0;
char fh = 0;
PrintXY(1,2,"XXEnter filename:",TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);
getTextLine(inputBuf, INPUT_MAX_LEN, 1, 3, INPUT_MAX_LEN, INPUT_MODE_TEXT);
int a = strlen(inputBuf);
inputBuf[a] = '.'; //add file extension
inputBuf[a+1] = 'c';
inputBuf[a+2] = 'h';
inputBuf[a+3] = '8';
for (int x = 0; inputBuf[x]!=NULL && x < INPUT_MAX_LEN+4; x++)
{
file[x + FILENAME_OFFSET] = (unsigned short)inputBuf[x];
}
if (0 > (fh = Bfile_OpenFile_OS(file,0x01))) {
errcode= ERR_FILE_NOT_FOUND;
}
if (fh >= 0)
Bfile_CloseFile_OS(fh);
if (0 <= (fh = Bfile_OpenFile_OS(file,0x01)) && errcode != ERR_FILE_NOT_FOUND) {
if (Bfile_ReadFile_OS(fh,(void*)(RAM+0x0200),144,0) < 0) //this is where the file read fails
PrintXY(1,6,"XXERR",TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);
Bfile_CloseFile_OS(fh);
}
if (errcode == ERR_FILE_NOT_FOUND)
PrintXY(1,7,"XXERR: Not found",TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);
}
It should prompt for a filename without the extension. The file is a .ch8 ROM, and it fails to load the file into memory. The file that I'm using is exactly 144 bytes, so I'm using that magic number for testing. I would like to get it working with files of any size in the future, but right now I want to get this file loaded successfully.