/* 2sf support for Desmume (c) 2007 Peter S. Conway DeSmuME is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. DeSmuME is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with DeSmuME; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include int istsfloaded=0; // these are all of static sizes, because I suck with pointers // feel free to convert them to pointers though. Byte uncompressedcode[0x2000000]; Byte uncompressedsave[0x2000000]; Byte *code; Byte *save; unsigned long uncompressedcodelength,uncompressedsavelength; unsigned long reservedstart,codestart; unsigned long reservedsize,codesize; FILE * tsfdata; void DisplayDebugInfo(char * Message, ...) { char Msg[400]; va_list ap; va_start( ap, Message ); vsprintf( Msg, Message, ap ); va_end( ap ); MessageBox(NULL,Msg,"debug crap",MB_OK); } int tsf_load_tsf(const char * filename) { tsfdata=fopen(filename,"rb"); if (!tsfdata) { MessageBox(NULL,"Error loading 2sf!","Fatal error",MB_OK); return 1; } fseek(tsfdata,0x4,SEEK_SET); fread(&reservedsize,1,4,tsfdata); save=(Byte*) malloc(reservedsize); fread(&codesize,1,4,tsfdata); code=(Byte*) malloc(codesize); // crc32 is not checked if (!reservedsize) { MessageBox(NULL,"Where's the savestate?","Huh?",MB_OK); return 1; } reservedstart=0x10; codestart=reservedsize+0x10; DisplayDebugInfo("reserved size: %x code size: %x\nreserved start: %x code start: %x",reservedsize,codesize,reservedstart,codestart); // load ROM if (tsf_load_ROM()!=0) { MessageBox(NULL,"error loading 2sf","too baaaaad",MB_OK); return 1; } // just return it anyways return 0; } int tsf_load_ROM(void) { /* Allocates a 2sf ROM in uncompressedcode. This is pretty damn unstable, so don't come whining to me if it crashes. */ fseek(tsfdata,codestart+1,SEEK_SET); fread(code,1,codesize,tsfdata); // uncompress zlib data uncompressedcodelength=0x328FD60; if(uncompress(*uncompressedcode,&uncompressedcodelength,code,codesize)!= Z_OK) { MessageBox(NULL,"zlib uncompress failed :(","oops",MB_OK); return 1; } return 0; } void tsf_load_state(void) { /* just a placeholder */ return; }