/* =================================================================================== Cygne WIN v 2.1a (c) Dox 2002 dox@space.pl =================================================================================== NEC cpu core by Bryan McPhail,Oliver Bergmann, Fabrice Frances and David Hedley Zlib by Jean-loup Gailly and Mark Adler =================================================================================== Files - ROM Load, Save/Load state =================================================================================== */ #include #include #include "globals.h" #include "zlib/unzip.h" #include "gfx.h" #include "memory.h" #define mSTOREREG(REGNAME) \ uReg=nec_get_reg(REGNAME); \ fwrite(&uReg,sizeof(uReg),1,fState); #define mMENUFRAMES(OPTION1,OPTION2,OPTION3,OPTION4,OPTION5,OPTION6) \ CheckMenuItem(hMenu,ID_OPTIONS_VIDEO_FRAMESKIP_0,OPTION1); \ char path_app[1024]; char path_save[1024]; char path_sram[1024]; char path_rom[1024]; char dirname[2048]; extern DWORD cycles_line; DWORD ws_maxbank; enum { I86_IP=1, I86_AX, I86_CX, I86_DX, I86_BX, I86_SP, I86_BP, I86_SI, I86_DI, I86_FLAGS, I86_ES, I86_CS, I86_SS, I86_DS, I86_VECTOR, I86_PENDING, I86_NMI_STATE, I86_IRQ_STATE}; void saveSRAM(void) { FILE* file; if(!sram_size)return; if(!(sram_size&1)){file=fopen(path_sram,"wb");if(file!=NULL){ fwrite(wsSRAM,1,sram_size,file);fclose(file);}} else {file=fopen(path_sram,"wb");if(file!=NULL){ fwrite(wsEEPROM,1,sram_size-1,file);fclose(file);}} } DWORD unziprom(char* RomPath) { unzFile fp; unsigned long gROMLength; //size in bytes of the ROM if(fp = unzOpen(RomPath)) { char szFileName[256]; if(unzGoToFirstFile(fp) == UNZ_OK) { do { unz_file_info file_info; if(unzGetCurrentFileInfo(fp,&file_info, szFileName,256,NULL,0,NULL,0) == UNZ_OK) { if(stricmp(&szFileName[strlen(szFileName) - 3], ".ws") == 0 || stricmp(&szFileName[strlen(szFileName) - 4], ".wsc") == 0) { gROMLength = file_info.uncompressed_size; if(unzOpenCurrentFile(fp)== UNZ_OK) { if(unzReadCurrentFile(fp,wsmem ,gROMLength) == (int)( gROMLength)) { unzClose(fp); return gROMLength; } else { unzClose(fp); return 0; } unzCloseCurrentFile(fp); } else { unzClose(fp); return 0; } } } else { unzClose(fp); return 0; } } while(unzGoToNextFile(fp) == UNZ_OK); } unzClose(fp); } return 0; } void wsROMLoad(HWND dialog) { FILE* file; char buf[256]; char romname[1024]; char fil[]="ws files\0*.ws;*.wsc;*.zip\0"; OPENFILENAME ofn; char dirname[256]; int hh,index; f_load=FALSE; buf[0]=0; GetCurrentDirectory(sizeof(dirname),dirname); memset(&ofn,0,sizeof(ofn)); ofn.lStructSize=sizeof(OPENFILENAME); ofn.hwndOwner=dialog; ofn.lpstrFilter=fil; ofn.nFilterIndex=1; ofn.lpstrFile=buf; ofn.lpstrInitialDir=dirname; ofn.nMaxFile=256; ofn.Flags=OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; GetOpenFileName(&ofn); if(buf[0]) { strcpy(romname,"Cygne - "); strcat(romname,buf); SetWindowText(window,romname); if(!stricmp(&buf[strlen(buf) - 4], ".zip")) rom_size=unziprom(buf); else { file=fopen(buf,"rb"); fseek(file,0,SEEK_END); rom_size=ftell(file); fseek(file,0,SEEK_SET); fread(wsmem,1,rom_size,file); fclose(file); } index=0; sram_size=0; if(wsmem[rom_size-5]==01)sram_size=8*1024; if(wsmem[rom_size-5]==02)sram_size=32*1024; if(wsmem[rom_size-5]==0x10)sram_size=128+1;/* Bit 1 set = EEPROM */ if(wsmem[rom_size-5]==0x20)sram_size=2*1024+1; if(wsmem[rom_size-5]==0x50)sram_size=1024+1; for(int x=strlen(buf);x>0;x--) { if(buf[x]==92) { for(hh=x;hh