FILE_HANDLE FileOpenROM(const char * fileName, const char *mode) { #if defined STACK_USE_MPFS2 return MPFSOpenROM((BYTE*)fileName); #elif defined STACK_USE_MDD return FSfopen(fileName, mode); #endif }
/********************************************************************* * Function: DWORD HTTPIncFile(TCP_SOCKET skt, * DWORD callbackPos, ROM BYTE* file) * * PreCondition: curHTTP is loaded * * Input: None * * Output: Updates curHTTP.callbackPos * * Side Effects: None * * Overview: Writes an MPFS file to the socket and returns * * Note: Provides rudimentary include support for dynamic * files which allows them to use header, footer, * and/or menu inclusion files rather than * duplicating code across all files. ********************************************************************/ void HTTPIncFile(ROM BYTE* file) { WORD count, len; BYTE data[64]; MPFS_HANDLE fp; // Check if this is a first round call if(curHTTP.callbackPos == 0x00) {// On initial call, open the file and save its ID fp = MPFSOpenROM(file); if(fp == MPFS_INVALID_HANDLE) {// File not found, so abort return; } ((DWORD_VAL*)&curHTTP.callbackPos)->w[0] = MPFSGetID(fp); } else {// The file was already opened, so load up it's ID and seek fp = MPFSOpenID(((DWORD_VAL*)&curHTTP.callbackPos)->w[0]); if(fp == MPFS_INVALID_HANDLE) {// File not found, so abort curHTTP.callbackPos = 0x00; return; } MPFSSeek(fp, ((DWORD_VAL*)&curHTTP.callbackPos)->w[1], MPFS_SEEK_FORWARD); } // Get/put as many bytes as possible count = TCPIsPutReady(sktHTTP); while(count > 0) { len = MPFSGetArray(fp, data, mMIN(count, 64)); if(len == 0) {// If no bytes were read, an EOF was reached MPFSClose(fp); curHTTP.callbackPos = 0x00; return; } else {// Write the bytes to the socket TCPPutArray(sktHTTP, data, len); count -= len; } } // Save the new address and close the file ((DWORD_VAL*)&curHTTP.callbackPos)->w[1] = MPFSTell(fp); MPFSClose(fp); return; }