// get all romsets info, only do once int getAllRomsetInfo() { if (getinfo) { return 0; } char* sname = NULL; BurnRomInfo ri; unsigned int romCount = 0; string name = ""; unsigned int tempBurnDrvSelect = nBurnDrvSelect; // get all romset basic info for (nBurnDrvSelect = 0; nBurnDrvSelect < nBurnDrvCount; nBurnDrvSelect++) { // get game info GameInfo* gameInfo = new GameInfo; gameInfo->parent = BurnDrvGetTextA(DRV_PARENT) ? BurnDrvGetTextA(DRV_PARENT) : ""; gameInfo->board = BurnDrvGetTextA(DRV_BOARDROM) ? BurnDrvGetTextA(DRV_BOARDROM) : ""; name = BurnDrvGetTextA(DRV_NAME); // get rom info romCount = getRomCount(); for (unsigned int i = 0; i < romCount; i++) { memset(&ri, 0, sizeof(ri)); BurnDrvGetRomInfo(&ri, i); // doesn't contain rom name RomInfo romInfo; BurnDrvGetRomName(&sname, i, 0); // get rom name romInfo.name = sname; romInfo.size = ri.nLen; romInfo.type = ri.nType; if (ri.nCrc == 0) { romInfo.state = STAT_OK; // pass no_dump rom } else { romInfo.state = STAT_NOFIND; } gameInfo->roms[ri.nCrc] = romInfo; } // add gameinfo to list allGameMap[name] = gameInfo; } nBurnDrvSelect = tempBurnDrvSelect; getAllRomsetCloneInfo(); getinfo = true; return 0; }
// Catch calls to BurnLoadRom() once the emulation has started; // Intialise the zip module before forwarding the call, and exit cleanly. static int DrvLoadRom(unsigned char* Dest, int* pnWrote, int i) { int nRet; BzipOpen(false); if ((nRet = BurnExtLoadRom(Dest, pnWrote, i)) != 0) { char szText[256] = ""; char* pszFilename; BurnDrvGetRomName(&pszFilename, i, 0); sprintf(szText, "Error loading %s, requested by %s.\n" "The emulation will likely suffer problems.", pszFilename, BurnDrvGetTextA(0)); } BzipClose(); BurnExtLoadRom = DrvLoadRom; //ScrnTitle(); return nRet; }
// audio all romsets int auditRomset() { string name = BurnDrvGetTextA(DRV_NAME); // get rom info GameInfo* gameInfo = allGameMap[name]; if (!gameInfo) return AUDIT_FAIL; RomInfo* romInfo = NULL; int ret = AUDIT_FULLPASS; map<unsigned int, RomInfo>::iterator iter = gameInfo->roms.begin(); for (; iter != gameInfo->roms.end(); iter++) { romInfo = &iter->second; if (!romInfo) continue; if (romInfo->state != STAT_OK && romInfo->type && iter->first) { if (iter->first == 0) continue; // no_dump if (!(romInfo->type & BRF_OPT)) return AUDIT_FAIL; ret = AUDIT_PARTPASS; } } return ret; }
static void DrvGfxDecode(int size) { BurnSwap32(pPsikyoshTiles, size); if (strcmp(BurnDrvGetTextA(DRV_NAME), "soldivid") == 0) { BurnByteswap(pPsikyoshTiles, size); } }
static void DoPatchGame(const char* patch_name, char* game_name, UINT8* base) { char s[MAX_PATH]; char* p = NULL; char* rom_name = NULL; char* ips_name = NULL; FILE* fp = NULL; unsigned long nIpsSize; if ((fp = fopen(patch_name, "rb")) != NULL) { // get ips size fseek(fp, 0, SEEK_END); nIpsSize = ftell(fp); fseek(fp, 0, SEEK_SET); while (!feof(fp)) { if (fgets(s, sizeof s, fp) != NULL) { p = s; // skip UTF-8 sig if (strncmp(p, UTF8_SIGNATURE, strlen(UTF8_SIGNATURE)) == 0) p += strlen(UTF8_SIGNATURE); if (p[0] == '[') // '[' break; rom_name = strtok(p, " \t\r\n"); if (!rom_name) continue; if (*rom_name == '#') continue; if (_stricmp(rom_name, game_name)) continue; ips_name = strtok(NULL, " \t\r\n"); if (!ips_name) continue; // skip CRC check strtok(NULL, "\r\n"); char ips_path[MAX_PATH]; char ips_dir[MAX_PATH]; TCHARToANSI(szAppIpsPath, ips_dir, sizeof(ips_dir)); if (strchr(ips_name, '\\')) { // ips in parent's folder sprintf(ips_path, "%s\\%s%s", ips_dir, ips_name, IPS_EXT); } else { sprintf(ips_path, "%s%s\\%s%s", ips_dir, BurnDrvGetTextA(DRV_NAME), ips_name, IPS_EXT); } PatchFile(ips_path, base); } } fclose(fp); } }
static INT32 GalDoReset() { if (GalS2650Rom1Size) { s2650Open(0); s2650Reset(); s2650Close(); } if (GalZ80Rom1Size) { ZetOpen(0); if (!strcmp(BurnDrvGetTextA(DRV_NAME), "4in1")) { ZetMapArea(0x0000, 0x3fff, 0, GalZ80Rom1); ZetMapArea(0x0000, 0x3fff, 2, GalZ80Rom1); } ZetReset(); ZetClose(); } if (GalZ80Rom2Size) { ZetOpen(1); ZetReset(); ZetClose(); } if (GalZ80Rom3Size) { ZetOpen(2); ZetReset(); ZetClose(); } GalSoundReset(); HiscoreReset(); GalIrqFire = 0; GalFlipScreenX = 0; GalFlipScreenY = 0; ZigzagAYLatch = 0; GalSoundLatch = 0; GalSoundLatch2 = 0; KingballSpeechDip = 0; KingballSound = 0; GalStarsEnable = 0; GalStarsScrollPos = 0; GalBackgroundRed = 0; GalBackgroundGreen = 0; GalBackgroundBlue = 0; GalBackgroundEnable = 0; ScrambleProtectionState = 0; ScrambleProtectionResult = 0; MoonwarPortSelect = 0; MshuttleAY8910CS = 0; Fourin1Bank = 0; CavelonBankSwitch = 0; GalVBlank = 0; return 0; }
static void doPatchGame(const char* patch_name, char* game_name, UINT8* base, int base_len) { FILE* fp = NULL; if ((fp = fopen(patch_name, "rb")) == NULL) { return; } char s[1024]; char* p = NULL; char* rom_name = NULL; char* ips_name = NULL; long ips_size = 0; // get ips size ips_size = getFileSize(fp); while (!feof(fp)) { if (fgets(s, sizeof s, fp) != NULL) { p = s; // skip UTF-8 sig if (strncmp(p, UTF8_SIGNATURE, strlen(UTF8_SIGNATURE)) == 0) p += strlen(UTF8_SIGNATURE); if (p[0] == '[') // '[' break; rom_name = strtok(p, " \t\r\n"); if (!rom_name) continue; if (*rom_name == '#') continue; if (_stricmp(rom_name, game_name)) continue; ips_name = strtok(NULL, " \t\r\n"); if (!ips_name) continue; // skip CRC check strtok(NULL, "\r\n"); char ips_path[MAX_PATH]; if (strchr(ips_name, '\\')) { // ips in parent's folder sprintf(ips_path, "%s\\%s%s", WtoA(getMiscPath(PATH_IPS)), ips_name, IPS_EXT); } else { sprintf(ips_path, "%s%s\\%s%s", WtoA(getMiscPath(PATH_IPS)), BurnDrvGetTextA(DRV_NAME), ips_name, IPS_EXT); } applyIPSpatch(ips_path, ips_size, base, base_len); } } fclose(fp); }
static int FindDrvInfoByName(char * fn) { char sfn[256]; strcpy( sfn, fn ); sfn[strlen(fn)-4] = 0; for (nBurnDrvSelect=0; nBurnDrvSelect<nBurnDrvCount; nBurnDrvSelect++) if ( stricmp(sfn, BurnDrvGetTextA(DRV_NAME)) == 0 ) return nBurnDrvSelect; return -1; }
static int parseRelations() { depTable.clear(); confTable.clear(); char assistName[MAX_PATH]; sprintf(assistName, "%s\\%s\\%s", WtoA(getMiscPath(PATH_IPS)), BurnDrvGetTextA(DRV_NAME), "assistant.txt"); //parse ips dat and update the treewidget FILE* fp = fopen(assistName, "rt"); if (!fp) { return 1; } char s[1024]; char* p = NULL; string line; size_t nLen = 0; size_t pos = string::npos; while (!feof(fp)) { if (fgets(s, sizeof s, fp) != NULL) { p = s; // skip UTF-8 sig if (strncmp(p, UTF8_SIGNATURE, strlen(UTF8_SIGNATURE)) == 0) { p += strlen(UTF8_SIGNATURE); } if (p[0] == '#') { continue; // skip comment } getLine(p); line = p; pos = line.find(">"); if (pos != string::npos) { StringList depStrs = split2Str(line, ">"); string parent = *(depStrs.begin()); lowerString(parent); StringList children = stringSplit(depStrs.back(), ","); lowerTrimmed(children); depTable.insert(make_pair(parent, children)); } else { StringList conflicts = stringSplit(line, ","); lowerTrimmed(conflicts); confTable.push_back(conflicts); } } } return 0; }
// get nBurnDrvSelect index by game name, added by regret unsigned int BurnDrvGetIndexByNameA(const char* name) { unsigned int ret = ~0U; unsigned int nOldSelect = nBurnDrvSelect; for (unsigned int i = 0; i < nBurnDrvCount; i++) { nBurnDrvSelect = i; if (strcasecmp(BurnDrvGetTextA(DRV_NAME), name) == 0) { ret = i; break; } } nBurnDrvSelect = nOldSelect; return ret; }
char* DecorateGameName(unsigned int nBurnDrv) { static char szDecoratedName[256]; unsigned int nOldBurnDrv = nBurnDrvSelect; nBurnDrvSelect = nBurnDrv; const char* s1 = ""; const char* s2 = ""; const char* s3 = ""; const char* s4 = ""; const char* s5 = ""; const char* s6 = ""; const char* s7 = ""; const char* s8 = ""; s1 = BurnDrvGetTextA(DRV_FULLNAME); if (BurnDrvGetFlags() & BDF_PROTOTYPE || BurnDrvGetFlags() & BDF_BOOTLEG || BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0) { s2 = " ["; if (BurnDrvGetFlags() & BDF_PROTOTYPE) { s3 = "Prototype"; if (BurnDrvGetFlags() & BDF_BOOTLEG || BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0) { s4 = ", "; } } if (BurnDrvGetFlags() & BDF_BOOTLEG) { s5 = "Bootleg"; if (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0) { s6 = ", "; } } if (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0) { s7 = BurnDrvGetTextA(DRV_COMMENT); } s8 = "]"; } sprintf(szDecoratedName, "%s%s%s%s%s%s%s%s", s1, s2, s3, s4, s5, s6, s7, s8); nBurnDrvSelect = nOldBurnDrv; return szDecoratedName; }
static void savePatches() { // clear active patch index for (int i = 0; i < MAX_ACTIVE_PATCHES; i++) { _stprintf(szActivePatches[i], _T("")); } int nChecked = 0; int nActivePatches = 0; for (int i = 0; i < nNumPatches; i++) { nChecked = _TreeView_GetCheckState(hIpsList, hPatchHandlesIndex[i]); if (nChecked) { _tcscpy(szActivePatches[nActivePatches], szPatchFileNames[i]); nActivePatches++; if (nActivePatches >= MAX_ACTIVE_PATCHES) { break; } } } FILE* fp = _tfopen(gameIpsConfigName(), _T("wt")); if (fp) { _ftprintf(fp, _T("// ") _T(APP_TITLE) _T(" v%s --- IPS Config File for %s (%hs)\n\n"), szAppBurnVer, BurnDrvGetText(DRV_NAME), BurnDrvGetTextA(DRV_FULLNAME)); TCHAR szPatchName[MAX_PATH]; TCHAR szFileName[MAX_PATH]; TCHAR* Tokens = NULL; for (int i = 0; i < nActivePatches; i++) { _tcscpy(szPatchName, szActivePatches[i]); // make a copy, modified by regret Tokens = _tcstok(szPatchName, _T("\\")); while (Tokens != NULL) { szFileName[0] = _T('\0'); _tcscpy(szFileName, Tokens); Tokens = _tcstok(NULL, _T("\\")); } _ftprintf(fp, _T("%s\n"), szFileName); } fclose(fp); } // if no active patch, delete config file if (nActivePatches == 0) { _tremove(gameIpsConfigName()); } }
bool filterFavorite(const unsigned int& index) { unsigned int nOldBurnDrvSelect = nBurnDrvSelect; nBurnDrvSelect = index; string game = BurnDrvGetTextA(DRV_NAME); bool ret; map<string, int>::iterator iter = favoriteMap.find(game); if (iter != favoriteMap.end()) { ret = false; } else { ret = true; } nBurnDrvSelect = nOldBurnDrvSelect; return ret; }
int main(int argc, char *argv[]) { UINT32 i=0; ConfigAppLoad(); CheckFirstTime(); // check for first time run SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO); BurnLibInit(); SDL_WM_SetCaption( "FBA, SDL port.", "FBA, SDL port."); SDL_ShowCursor(SDL_DISABLE); if (argc == 2) { for (i = 0; i < nBurnDrvCount; i++) { nBurnDrvSelect[0] = i; if (strcmp(BurnDrvGetTextA(0), argv[1]) == 0) { break; } } if (i == nBurnDrvCount) { printf("%s is not supported by FB Alpha.",argv[1]); return 1; } } InputInit(); init_emu(i); RunMessageLoop(); InputExit(); DrvExit(); ConfigAppSave(); BurnLibExit(); SDL_Quit(); return 0; }
int FindDrvByFileName(const char *fn) { char romname[MAX_PATH]; char *p; // FIXME: use p = strrchr(fn, '/'); // and add given path to szAppRomPaths list strcpy(szAppRomPaths[0], fn); p = strrchr(szAppRomPaths[0], '/'); if(p) { p++; strcpy(romname, p); *p = 0; p = strrchr(romname, '.'); if(p) *p = 0; else { // error return -1; } } else { // error return -1; } // find rom by name for(nBurnDrvSelect[0] = 0; nBurnDrvSelect[0] < nBurnDrvCount; nBurnDrvSelect[0]++) { nBurnDrvActive = nBurnDrvSelect[0]; if(strcasecmp(romname, BurnDrvGetTextA(DRV_NAME)) == 0) return nBurnDrvActive; } if(nBurnDrvSelect[0] >= nBurnDrvCount) { // unsupport rom ... nBurnDrvSelect[0] = ~0U; nBurnDrvActive = nBurnDrvSelect[0]; printf("Rom %s not supported!\n", romname); return -1; } nBurnDrvSelect[0] = 0; return -1; }
void addFavorite(unsigned int index) { if (index >= nBurnDrvCount) return; unsigned int nOldBurnDrvSelect = nBurnDrvSelect; nBurnDrvSelect = index; string game = BurnDrvGetTextA(DRV_NAME); map<string, int>::iterator iter = favoriteMap.find(game); if (iter == favoriteMap.end()) { favoriteMap[game] = index; } nBurnDrvSelect = nOldBurnDrvSelect; favChanged = true; }
static INT32 LoadRoms() { if (!strcmp(BurnDrvGetTextA(DRV_NAME), "pipibibsp")) { // Load 68000 ROM ToaLoadCode(Rom01, 0, 2); // Load GP9001 tile data ToaLoadGP9001Tiles(GP9001ROM[0], 2, 4, nGP9001ROMSize[0]); BurnLoadRom(RomZ80, 6, 1); } else { // Load 68000 ROM ToaLoadCode(Rom01, 0, 2); // Load GP9001 tile data ToaLoadGP9001Tiles(GP9001ROM[0], 2, 2, nGP9001ROMSize[0]); BurnLoadRom(RomZ80, 4, 1); } return 0; }
char* DecorateGameName(unsigned int nBurnDrv) { static char szDecoratedName[256]; unsigned int nOldBurnDrv = nBurnDrvSelect; nBurnDrvSelect = nBurnDrv; const char* s1 = ""; const char* s2 = ""; const char* s3 = ""; const char* s4 = ""; const char* s5 = ""; const char* s6 = ""; const char* s7 = ""; const char* s8 = ""; const char* s9 = ""; const char* s10 = ""; const char* s11 = ""; const char* s12 = ""; const char* s13 = ""; const char* s14 = ""; s1 = BurnDrvGetTextA(DRV_FULLNAME); if ((BurnDrvGetFlags() & BDF_DEMO) || (BurnDrvGetFlags() & BDF_HACK) || (BurnDrvGetFlags() & BDF_HOMEBREW) || (BurnDrvGetFlags() & BDF_PROTOTYPE) || (BurnDrvGetFlags() & BDF_BOOTLEG) || (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0)) { s2 = " ["; if (BurnDrvGetFlags() & BDF_DEMO) { s3 = "Demo"; if ((BurnDrvGetFlags() & BDF_HACK) || (BurnDrvGetFlags() & BDF_HOMEBREW) || (BurnDrvGetFlags() & BDF_PROTOTYPE) || (BurnDrvGetFlags() & BDF_BOOTLEG) || (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0)) { s4 = ", "; } } if (BurnDrvGetFlags() & BDF_HACK) { s5 = "Hack"; if ((BurnDrvGetFlags() & BDF_HOMEBREW) || (BurnDrvGetFlags() & BDF_PROTOTYPE) || (BurnDrvGetFlags() & BDF_BOOTLEG) || (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0)) { s6 = ", "; } } if (BurnDrvGetFlags() & BDF_HOMEBREW) { s7 = "Homebrew"; if ((BurnDrvGetFlags() & BDF_PROTOTYPE) || (BurnDrvGetFlags() & BDF_BOOTLEG) || (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0)) { s8 = ", "; } } if (BurnDrvGetFlags() & BDF_PROTOTYPE) { s9 = "Prototype"; if ((BurnDrvGetFlags() & BDF_BOOTLEG) || (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0)) { s10 = ", "; } } if (BurnDrvGetFlags() & BDF_BOOTLEG) { s11 = "Bootleg"; if (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0) { s12 = ", "; } } if (BurnDrvGetTextA(DRV_COMMENT) && strlen(BurnDrvGetTextA(DRV_COMMENT)) > 0) { s13 = BurnDrvGetTextA(DRV_COMMENT); } s14 = "]"; } sprintf(szDecoratedName, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s", s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14); nBurnDrvSelect = nOldBurnDrv; return szDecoratedName; }
int main( int argc, char **argv ) { strcpy(szAppBurnVer,"0.2.97.24"); char path[MAX_PATH]; if (argc < 2) { int c; printf ("Usage: %s <path to rom><shortname>.zip\n ie: %s ./uopoko.zip\n Note: Path and .zip extension are mandatory.\n\n",argv[0], argv[0]); printf ("Supported (but not necessarily working via fba-gp2x) roms:\n\n"); config_options.option_create_lists=1; BurnLibInit(); for (nBurnDrvSelect[0]=0; nBurnDrvSelect[0]<nBurnDrvCount; nBurnDrvSelect[0]++) { nBurnDrvActive=nBurnDrvSelect[0]; printf ("%-20s ", BurnDrvGetTextA(DRV_NAME)); c++; if (c == 3) { c = 0; printf ("\n"); } } printf ("\n\n"); return 0; } /* int tmp; tmp = open("/proc/pandora/nub0/mode", O_RDWR); read (tmp,nub0,10); write (tmp,"absolute",9); close(tmp); printf("Changed nub 0 to joystick\n"); tmp = open("/proc/pandora/nub1/mode", O_RDWR); read (tmp,nub1,10); write (tmp,"absolute",9); close(tmp); printf("Changed nub 1 to joystick\n"); FILE * joyexists; joyexists=NULL; long timeout; timeout=0; while ((joyexists==NULL) && (timeout<100000)) { // printf("."); joyexists=fopen("/dev/input/js0","r"); usleep(20); timeout++; } if (joyexists) { printf("js0 now exists\n"); fclose(joyexists); } else { printf("timeout creating js0... reverting nub 0 to original setting\n"); tmp = open("/proc/pandora/nub0/mode", O_WRONLY); write (tmp,nub0,10); close(tmp); } joyexists=NULL; timeout=0; while ((joyexists==NULL) && (timeout<100000)) { joyexists=fopen("/dev/input/js1","r"); usleep(20); timeout++; } if (joyexists) { printf("js1 now exists\n"); fclose(joyexists); } else { printf("timeout creating js1... reverting nub 1 to original setting\n"); tmp = open("/proc/pandora/nub1/mode", O_WRONLY); write (tmp,nub1,10); close(tmp); } */ //Initialize configuration options config_options.option_sound_enable = 2; config_options.option_rescale = 2; config_options.option_rotate = 0; config_options.option_samplerate = 0; config_options.option_showfps = 1; config_options.option_create_lists=0; config_options.option_forcem68k=0; config_options.option_forcec68k=0; config_options.option_z80core=0; config_options.option_sense=100; strcpy(config_options.option_startspeed,"NULL"); strcpy(config_options.option_selectspeed,"NULL"); strcpy(config_options.option_frontend, "./capex.sh"); printf("about to parse cmd\n"); parse_cmd(argc, argv,path); printf("finshed parsing\n"); config_keymap.up=SDLK_UP; config_keymap.down=SDLK_DOWN; config_keymap.left=SDLK_LEFT; config_keymap.right=SDLK_RIGHT; config_keymap.fire1=SDLK_HOME; //a config_keymap.fire2=SDLK_PAGEDOWN; //x config_keymap.fire3=SDLK_END; //b config_keymap.fire4=SDLK_PAGEUP; //y config_keymap.fire5=SDLK_RSHIFT; config_keymap.fire6=SDLK_RCTRL; config_keymap.coin1=SDLK_LCTRL; config_keymap.start1=SDLK_LALT; config_keymap.pause=SDLK_p; config_keymap.quit=SDLK_q; // gp2x_initialize(); // printf("platform init finished\n"); //Initialize sound thread run_fba_emulator (path); /* if (strcmp(config_options.option_startspeed,config_options.option_selectspeed)) { printf("resetting cpu speed to %s\n",config_options.option_startspeed); int clk; clk = open("/proc/pandora/cpu_mhz_max", O_WRONLY); write (clk,config_options.option_startspeed,strlen(config_options.option_startspeed)+1); close(clk); } gp2x_terminate(config_options.option_frontend); */ return 0; }
void HiscoreInit() { Debug_HiscoreInitted = 1; if (!CheckHiscoreAllowed()) return; HiscoresInUse = 0; TCHAR szDatFilename[MAX_PATH]; _stprintf(szDatFilename, _T("%shiscore.dat"), szAppHiscorePath); FILE *fp = _tfopen(szDatFilename, _T("r")); if (fp) { char buffer[MAX_CONFIG_LINE_SIZE]; enum { FIND_NAME, FIND_DATA, FETCH_DATA } mode; mode = FIND_NAME; while (fgets(buffer, MAX_CONFIG_LINE_SIZE, fp)) { if (mode == FIND_NAME) { if (matching_game_name(buffer, BurnDrvGetTextA(DRV_NAME))) { mode = FIND_DATA; } } else { if (is_mem_range(buffer)) { if (nHiscoreNumRanges < HISCORE_MAX_RANGES) { const char *pBuf = buffer; HiscoreMemRange[nHiscoreNumRanges].Loaded = 0; HiscoreMemRange[nHiscoreNumRanges].nCpu = hexstr2num(&pBuf); HiscoreMemRange[nHiscoreNumRanges].Address = hexstr2num(&pBuf); HiscoreMemRange[nHiscoreNumRanges].NumBytes = hexstr2num(&pBuf); HiscoreMemRange[nHiscoreNumRanges].StartValue = hexstr2num(&pBuf); HiscoreMemRange[nHiscoreNumRanges].EndValue = hexstr2num(&pBuf); HiscoreMemRange[nHiscoreNumRanges].ApplyNextFrame = 0; HiscoreMemRange[nHiscoreNumRanges].Applied = 0; HiscoreMemRange[nHiscoreNumRanges].Data = (UINT8*)malloc(HiscoreMemRange[nHiscoreNumRanges].NumBytes); memset(HiscoreMemRange[nHiscoreNumRanges].Data, 0, HiscoreMemRange[nHiscoreNumRanges].NumBytes); #if 1 && defined FBA_DEBUG bprintf(PRINT_IMPORTANT, _T("Hi Score Memory Range %i Loaded - CPU %i, Address %x, Bytes %02x, Start Val %x, End Val %x\n"), nHiscoreNumRanges, HiscoreMemRange[nHiscoreNumRanges].nCpu, HiscoreMemRange[nHiscoreNumRanges].Address, HiscoreMemRange[nHiscoreNumRanges].NumBytes, HiscoreMemRange[nHiscoreNumRanges].StartValue, HiscoreMemRange[nHiscoreNumRanges].EndValue); #endif nHiscoreNumRanges++; mode = FETCH_DATA; } else { break; } } else { if (mode == FETCH_DATA) break; } } } fclose(fp); } if (nHiscoreNumRanges) HiscoresInUse = 1; TCHAR szFilename[MAX_PATH]; _stprintf(szFilename, _T("%s%s.hi"), szAppHiscorePath, BurnDrvGetText(DRV_NAME)); fp = _tfopen(szFilename, _T("r")); INT32 Offset = 0; if (fp) { UINT32 nSize = 0; while (!feof(fp)) { fgetc(fp); nSize++; } UINT8 *Buffer = (UINT8*)malloc(nSize); rewind(fp); fgets((char*)Buffer, nSize, fp); for (UINT32 i = 0; i < nHiscoreNumRanges; i++) { for (UINT32 j = 0; j < HiscoreMemRange[i].NumBytes; j++) { HiscoreMemRange[i].Data[j] = Buffer[j + Offset]; } Offset += HiscoreMemRange[i].NumBytes; HiscoreMemRange[i].Loaded = 1; #if 1 && defined FBA_DEBUG bprintf(PRINT_IMPORTANT, _T("Hi Score Memory Range %i Loaded from file\n"), i); #endif } if (Buffer) { free(Buffer); Buffer = NULL; } fclose(fp); } nCpuType = -1; }
void run_fba_emulator(const char *fn) { char build_version[] = "Finalburn Alpha Plus for Pi ("__DATE__")"; // process rom path and name char romname[MAX_PATH]; if (BurnCacheInit(fn, romname)) goto finish; if(config_options.option_showfps) bShowFPS=true; BurnLibInit(); // find rom by name for (nBurnDrvSelect=0; nBurnDrvSelect<nBurnDrvCount; nBurnDrvSelect++) if ( strcasecmp(romname, BurnDrvGetTextA(DRV_NAME)) == 0 ) break; if (nBurnDrvSelect >= nBurnDrvCount) { // unsupport rom ... nBurnDrvSelect = ~0U; logoutput ("rom not supported!\n"); printf ("rom not supported!\n"); goto finish; } logoutput("Attempt to initialise '%s'\n", BurnDrvGetTextA(DRV_FULLNAME)); memset (titlefb, 0, 320*240*2); DrawString (build_version, (uint16*)&titlefb, 10, 20, 320); DrawString ("Based on FinalBurnAlpha", (uint16*)&titlefb, 10, 35, 320); DrawString ("Now loading ... ", (uint16 *)&titlefb, 10, 105, 320); show_rom_loading_text("Open Zip", 0, 0); memcpy (VideoBuffer, titlefb, 320*240*2); pi_video_flip(); InpInit(); InpDIP(); VideoInit(); if (DrvInit(nBurnDrvSelect, false) != 0) { logoutput ("Driver initialisation failed! Likely causes are:\n- Corrupt/Missing ROM(s)\n- I/O Error\n- Memory error\n\n"); printf ("Driver initialisation failed! Likely causes are:\n- Corrupt/Missing ROM(s)\n- I/O Error\n- Memory error\n\n"); goto finish; } RunReset(); frame_count = 0; GameLooping = true; EZX_StartTicks(); logoutput ("Lets go!\n"); logflush(); if (config_options.option_sound_enable) { int timer = 0, tick=0, i=0, fps = 0; bool bRenderFrame; if (SndOpen() == 0) { while (GameLooping) { if (bShowFPS) { timer = EZX_GetTicks(); if(timer-tick>1000000) { fps = nFramesRendered; nFramesRendered = 0; tick = timer; } } //We need to render more audio: bRenderFrame=true; // Render last frame RunOneFrame(bRenderFrame,fps); update_audio_stream(pBurnSoundOut); pi_process_events(); } } } else { int now, done=0, timer = 0, ticks=0, tick=0, i=0, fps = 0; unsigned int frame_limit = nBurnFPS/100, frametime = 100000000/nBurnFPS; while (GameLooping) { timer = EZX_GetTicks()/frametime;; if(timer-tick>frame_limit && bShowFPS) { fps = nFramesRendered; nFramesRendered = 0; tick = timer; } now = timer; ticks=now-done; if(ticks<1) continue; if(ticks>10) ticks=10; for (i=0; i<ticks-1; i++) { RunOneFrame(false,fps); } if(ticks>=1) { RunOneFrame(true,fps); } done = now; } } logoutput ("Finished emulating\n"); finish: logoutput("---- Shutdown Finalburn Alpha plus ----\n\n"); DrvExit(); BurnLibExit(); if (config_options.option_sound_enable) SndExit(); VideoExit(); InpExit(); BurnCacheExit(); }
static int pgmGetRoms(bool bLoad) { int kov2 = (strncmp(BurnDrvGetTextA(DRV_NAME), "kov2", 4) == 0) ? 1 : 0; char* pRomName; struct BurnRomInfo ri; struct BurnRomInfo pi; unsigned char *PGMUSER0Load = PGMUSER0; unsigned char *PGM68KROMLoad = PGM68KROM; unsigned char *PGMTileROMLoad = PGMTileROM + 0x180000; unsigned char *PGMSPRMaskROMLoad = PGMSPRMaskROM; unsigned char *PGMSNDROMLoad = ICSSNDROM + 0x400000; if (kov2 && bLoad) { PGMSNDROMLoad += 0x400000; } for (int i = 0; !BurnDrvGetRomName(&pRomName, i, 0); i++) { BurnDrvGetRomInfo(&ri, i); if ((ri.nType & BRF_PRG) && (ri.nType & 0x0f) == 1) { if (bLoad) { BurnDrvGetRomInfo(&pi, i+1); if (ri.nLen == 0x80000 && pi.nLen == 0x80000) { BurnLoadRom(PGM68KROMLoad + 0, i + 0, 2); BurnLoadRom(PGM68KROMLoad + 1, i + 1, 2); PGM68KROMLoad += pi.nLen; i += 1; } else { BurnLoadRom(PGM68KROMLoad, i, 1); } PGM68KROMLoad += ri.nLen; } else { nPGM68KROMLen += ri.nLen; } continue; } if ((ri.nType & BRF_GRA) && (ri.nType & 0x0f) == 2) { if (bLoad) { BurnLoadRom(PGMTileROMLoad, i, 1); PGMTileROMLoad += ri.nLen; } else { nPGMTileROMLen += ri.nLen; } continue; } if ((ri.nType & BRF_GRA) && (ri.nType & 0x0f) == 3) { if (bLoad) { } else { nPGMSPRColROMLen += ri.nLen; } continue; } if ((ri.nType & BRF_GRA) && (ri.nType & 0x0f) == 4) { if (bLoad) { BurnLoadRom(PGMSPRMaskROMLoad, i, 1); PGMSPRMaskROMLoad += ri.nLen; } else { nPGMSPRMaskROMLen += ri.nLen; } continue; } if ((ri.nType & BRF_SND) && (ri.nType & 0x0f) == 5) { if (bLoad) { BurnLoadRom(PGMSNDROMLoad, i, 1); PGMSNDROMLoad += ri.nLen; } else { nPGMSNDROMLen += ri.nLen; } continue; } if ((ri.nType & BRF_PRG) && (ri.nType & 0x0f) == 7) { if (bLoad) { if (BurnDrvGetHardwareCode() & HARDWARE_IGS_USE_ARM_CPU) { BurnLoadRom(PGMARMROM, i, 1); } } continue; } if ((ri.nType & BRF_PRG) && (ri.nType & 0x0f) == 8) { if (BurnDrvGetHardwareCode() & HARDWARE_IGS_USE_ARM_CPU) { if (bLoad) { BurnLoadRom(PGMUSER0, i, 1); PGMUSER0Load += ri.nLen; } else { nPGMExternalARMLen += ri.nLen; } } continue; } } if (!bLoad) { nPGMTileROMLen += 0x180000; if (nPGMTileROMLen < 0x400000) nPGMTileROMLen = 0x400000; nPGMSNDROMLen += 0x400000; if (kov2) nPGMSNDROMLen += 0x400000; nPGMSNDROMLen = ((nPGMSNDROMLen-1) | 0xfffff) + 1; nICSSNDROMLen = (nPGMSNDROMLen-1) & 0xf00000; if (nPGMExternalARMLen == 0) nPGMExternalARMLen = 0x200000; bprintf (0, _T("%5.5x, %d\n"), nPGMExternalARMLen, nBurnFPS); } return 0; }
int write_datfile(int nDatType, int bIncMegadrive, FILE* fDat) { int nRet=0; unsigned int nOldSelect=0; unsigned int nGameSelect=0; unsigned int nParentSelect,nBoardROMSelect; nOldSelect=nBurnDrvSelect; // preserve the currently selected driver // Go over each of the games for (nGameSelect=0;nGameSelect<nBurnDrvCount;nGameSelect++) { char sgName[16]; char spName[16]; char sbName[16]; unsigned int i=0; int nPass=0; nBurnDrvSelect=nGameSelect; // Switch to driver nGameSelect if (BurnDrvGetFlags() & BDF_BOARDROM) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_MEGADRIVE) && (bIncMegadrive == 0)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_SEGA_MEGADRIVE) && (bIncMegadrive == 2)) { continue; } strcpy(sgName, BurnDrvGetTextA(DRV_NAME)); strcpy(spName, ""); // make sure this string is empty before we start strcpy(sbName, ""); // make sure this string is empty before we start // Check to see if the game has a parent if (BurnDrvGetTextA(DRV_PARENT)) { nParentSelect=-1U; while (BurnDrvGetTextA(DRV_PARENT)) { strcpy(spName, BurnDrvGetTextA(DRV_PARENT)); for (i=0;i<nBurnDrvCount;i++) { nBurnDrvSelect=i; if (!strcmp(spName, BurnDrvGetTextA(DRV_NAME))) { nParentSelect=i; break; } } } nBurnDrvSelect=nGameSelect; // restore driver select } else nParentSelect=nGameSelect; // Check to see if the game has a BoardROM if (BurnDrvGetTextA(DRV_BOARDROM)) { nBoardROMSelect=-1U; strcpy(sbName, BurnDrvGetTextA(DRV_BOARDROM)); for (i=0;i<nBurnDrvCount;i++) { nBurnDrvSelect=i; if (!strcmp(sbName, BurnDrvGetTextA(DRV_NAME))) { nBoardROMSelect=i; break; } } nBurnDrvSelect=nGameSelect; // restore driver select } else nBoardROMSelect=nGameSelect; if (nDatType == 0) { // Report problems if (nParentSelect==-1U) fprintf(fDat, "# Missing parent %s. It needs to be added to " APP_TITLE "!\n\n", spName); if (nBoardROMSelect==-1U) fprintf(fDat, "# Missing boardROM %s. It needs to be added to " APP_TITLE "!\n\n", sbName); // Write the header fprintf(fDat, "game (\n"); fprintf(fDat, "\tname %s\n", sgName); if (nParentSelect!=nGameSelect && nParentSelect!=-1U) { fprintf(fDat, "\tcloneof %s\n", spName); fprintf(fDat, "\tromof %s\n", spName); } else { // Add "romof" (but not 'cloneof') line for games that have boardROMs if (nBoardROMSelect!=nGameSelect && nBoardROMSelect!=-1U) { fprintf(fDat, "\tromof %s\n", sbName); } } fprintf(fDat, "\tdescription \"%s\"\n", DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "\tyear %s\n", BurnDrvGetTextA(DRV_DATE)); fprintf(fDat, "\tmanufacturer \"%s\"\n", BurnDrvGetTextA(DRV_MANUFACTURER)); } if (nDatType == 2) { // Report problems if (nParentSelect==-1U) fprintf(fDat, "# Missing parent %s. It needs to be added to " APP_TITLE "!\n\n", spName); if (nBoardROMSelect==-1U) fprintf(fDat, "# Missing boardROM %s. It needs to be added to " APP_TITLE "!\n\n", sbName); // Write the header if (nParentSelect!=nGameSelect && nParentSelect!=-1U) { fprintf(fDat, "\t<game name=\"%s\" cloneof=\"%s\" romof=\"%s\">\n", sgName, spName, sbName); } else { // Add "romof" (but not 'cloneof') line for games that have boardROMs if (nBoardROMSelect!=nGameSelect && nBoardROMSelect!=-1U) { fprintf(fDat, "\t<game name=\"%s\" romof=\"%s\">\n", sgName, sbName); } else { fprintf(fDat, "\t<game name=\"%s\">\n", sgName); } } char szGameName[255]; char szGameNameBuffer[255]; char szManufacturer[255]; char szManufacturerBuffer[255]; memset(szGameName, 0, 255); memset(szGameNameBuffer, 0, 255); memset(szManufacturer, 0, 255); memset(szManufacturerBuffer, 0, 255); strcpy(szGameName, DecorateGameName(nBurnDrvSelect)); ReplaceAmpersand(szGameNameBuffer, szGameName); strcpy(szManufacturer, BurnDrvGetTextA(DRV_MANUFACTURER)); ReplaceAmpersand(szManufacturerBuffer, szManufacturer); // fprintf(fDat, "\t\t<description>%s</description>\n", DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "\t\t<description>%s</description>\n", szGameNameBuffer); fprintf(fDat, "\t\t<year>%s</year>\n", BurnDrvGetTextA(DRV_DATE)); // fprintf(fDat, "\t\t<manufacturer>%s</manufacturer>\n", BurnDrvGetTextA(DRV_MANUFACTURER)); fprintf(fDat, "\t\t<manufacturer>%s</manufacturer>\n", szManufacturerBuffer); } // Write the individual ROM info for (nPass=0; nPass<2; nPass++) { nBurnDrvSelect=nGameSelect; // Skip pass 0 if possible if (nPass==0 && (nBoardROMSelect==nGameSelect || nBoardROMSelect==-1U || nDatType == 1 || nDatType == 2)) continue; // Go over each of the files needed for this game (upto 0x0100) for (i=0, nRet=0; nRet==0 && i<0x100; i++) { int nRetTmp=0; struct BurnRomInfo ri; int nLen; unsigned int nCrc; char *szPossibleName=NULL; int j, nMerged=0; memset(&ri,0,sizeof(ri)); // Get info on this file nBurnDrvSelect=nGameSelect; nRet=BurnDrvGetRomInfo(&ri,i); nRet+=BurnDrvGetRomName(&szPossibleName,i,0); if (ri.nLen==0) continue; if (nRet==0) { struct BurnRomInfo riTmp; char *szPossibleNameTmp; nLen=ri.nLen; nCrc=ri.nCrc; // Check for files from boardROMs if (nBoardROMSelect!=nGameSelect && nBoardROMSelect!=-1U) { nBurnDrvSelect=nBoardROMSelect; nRetTmp=0; // Go over each of the files needed for this game (upto 0x0100) for (j=0; nRetTmp==0 && j<0x100; j++) { memset(&riTmp,0,sizeof(riTmp)); nRetTmp+=BurnDrvGetRomInfo(&riTmp,j); nRetTmp+=BurnDrvGetRomName(&szPossibleNameTmp,j,0); if (nRetTmp==0) { if (riTmp.nLen && riTmp.nCrc==nCrc && !strcmp(szPossibleName, szPossibleNameTmp)) { // This file is from a boardROM nMerged|=2; nRetTmp++; } } } } if (!nMerged && nParentSelect!=nGameSelect && nParentSelect!=-1U) { nBurnDrvSelect=nParentSelect; nRetTmp=0; // Go over each of the files needed for this game (upto 0x0100) for (j=0; nRetTmp==0 && j<0x100; j++) { memset(&riTmp,0,sizeof(riTmp)); nRetTmp+=BurnDrvGetRomInfo(&riTmp,j); nRetTmp+=BurnDrvGetRomName(&szPossibleNameTmp,j,0); if (nRetTmp==0) { if (riTmp.nLen && riTmp.nCrc==nCrc && !strcmp(szPossibleName, szPossibleNameTmp)) { // This file is from a parent set nMerged|=1; nRetTmp++; } } } } nBurnDrvSelect=nGameSelect; // Switch back to game } if (nDatType == 0) { // Selectable BIOS meta info if (nPass==0 && nMerged&2 && ri.nType&BRF_SELECT) fprintf(fDat, "\tbiosset ( name %d description \"%s\" %s)\n", i - 128, szPossibleName, ri.nType & BRF_OPT ? "" : "default yes "); // File info if (nPass==1 && !nMerged) { if (ri.nType & BRF_NODUMP) { fprintf(fDat, "\trom ( name %s size %d flags nodump )\n", szPossibleName, ri.nLen); } else { fprintf(fDat, "\trom ( name %s size %d crc %08x )\n", szPossibleName, ri.nLen, ri.nCrc); } } if (nPass==1 && nMerged) { // Selectable BIOS file info if (nMerged&2 && ri.nType&BRF_SELECT) fprintf(fDat, "\trom ( name %s merge %s bios %d size %d crc %08x )\n", szPossibleName, szPossibleName, i - 128, ri.nLen, ri.nCrc); // Files from parent/boardROMs else { if (ri.nType & BRF_NODUMP) { fprintf(fDat, "\trom ( name %s merge %s size %d flags nodump )\n", szPossibleName, szPossibleName, ri.nLen); } else { fprintf(fDat, "\trom ( name %s merge %s size %d crc %08x )\n", szPossibleName, szPossibleName, ri.nLen, ri.nCrc); } } } } if (nDatType == 1) { if (nPass == 0) continue; // No meta info needed if (nParentSelect!=nGameSelect && nParentSelect!=-1U) { nBurnDrvSelect=nParentSelect; // Switch to parent fprintf(fDat, "¬%s¬%s", spName, DecorateGameName(nBurnDrvSelect)); nBurnDrvSelect=nGameSelect; // Switch back to game } else fprintf(fDat, "¬%s¬%s", BurnDrvGetTextA(DRV_NAME), DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "¬%s¬%s", BurnDrvGetTextA(DRV_NAME), DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "¬%s¬%08x¬%d", szPossibleName, ri.nCrc, ri.nLen); if (nParentSelect!=nGameSelect && nParentSelect!=-1U) { // Files from parent fprintf(fDat, "¬%s", spName); } else { // Files from boardROM if (nBoardROMSelect!=nGameSelect && nBoardROMSelect!=-1U) fprintf(fDat, "¬%s", sbName); } if (!nMerged) fprintf(fDat, "¬¬¬\n"); else fprintf(fDat, "¬%s¬\n", szPossibleName); } if (nDatType == 2) { char szPossibleNameBuffer[255]; memset(szPossibleNameBuffer, 0, 255); ReplaceAmpersand(szPossibleNameBuffer, szPossibleName); // File info if (nPass==1 && !nMerged) { if (ri.nType & BRF_NODUMP) { fprintf(fDat, "\t\t<rom name=\"%s\" size=\"%d\" status=\"nodump\"/>\n", szPossibleNameBuffer, ri.nLen); } else { fprintf(fDat, "\t\t<rom name=\"%s\" size=\"%d\" crc=\"%08x\"/>\n", szPossibleNameBuffer, ri.nLen, ri.nCrc); } } if (nPass==1 && nMerged) { // Files from parent/boardROMs if (ri.nType & BRF_NODUMP) { fprintf(fDat, "\t\t<rom name=\"%s\" merge=\"%s\" size=\"%d\" status=\"nodump\"/>\n", szPossibleNameBuffer, szPossibleNameBuffer, ri.nLen); } else { fprintf(fDat, "\t\t<rom name=\"%s\" merge=\"%s\" size=\"%d\" crc=\"%08x\"/>\n", szPossibleNameBuffer, szPossibleNameBuffer, ri.nLen, ri.nCrc); } } } } } if (nDatType == 0) fprintf(fDat, ")\n\n"); if (nDatType == 2) fprintf(fDat, "\t</game>\n"); } if (nDatType == 1 && (bIncMegadrive != 2)) fprintf(fDat, "[RESOURCES]\n"); // Do another pass over each of the games to find boardROMs for (nBurnDrvSelect=0; nBurnDrvSelect<nBurnDrvCount; nBurnDrvSelect++) { int i, nPass; if (!(BurnDrvGetFlags() & BDF_BOARDROM)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_SEGA_MEGADRIVE) && (bIncMegadrive == 2)) { continue; } if (nDatType == 0) { fprintf(fDat, "resource (\n"); fprintf(fDat, "\tname %s\n", BurnDrvGetTextA(DRV_NAME)); fprintf(fDat, "\tdescription \"%s\"\n", DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "\tyear %s\n", BurnDrvGetTextA(DRV_DATE)); fprintf(fDat, "\tmanufacturer \"%s\"\n", BurnDrvGetTextA(DRV_COMMENT)); } if (nDatType == 2) { fprintf(fDat, "\t<game isbios=\"yes\" name=\"%s\">\n", BurnDrvGetTextA(DRV_NAME)); fprintf(fDat, "\t\t<description>%s</description>\n", DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "\t\t<year>%s</year>\n", BurnDrvGetTextA(DRV_DATE)); fprintf(fDat, "\t\t<manufacturer>%s</manufacturer>\n", BurnDrvGetTextA(DRV_MANUFACTURER)); } for (nPass=0; nPass<2; nPass++) { // No meta information needed if (nPass==0 && (nDatType == 1 || nDatType == 2)) continue; // Go over each of the individual files (upto 0x0100) for (i=0; i<0x100; i++) { struct BurnRomInfo ri; char *szPossibleName=NULL; memset(&ri,0,sizeof(ri)); nRet=BurnDrvGetRomInfo(&ri,i); nRet+=BurnDrvGetRomName(&szPossibleName,i,0); if (ri.nLen==0) continue; if (nRet==0) { if (nDatType == 0) { if (nPass==0) { if (ri.nType&BRF_SELECT) fprintf(fDat, "\tbiosset ( name %d description \"%s\" %s)\n", i, szPossibleName, ri.nType & 0x80 ? "" : "default yes "); } else { if (ri.nType&BRF_SELECT) fprintf(fDat, "\trom ( name %s bios %d size %d crc %08x )\n", szPossibleName, i, ri.nLen, ri.nCrc); else fprintf(fDat, "\trom ( name %s size %d crc %08x )\n", szPossibleName, ri.nLen, ri.nCrc); } } if (nDatType == 1) { fprintf(fDat, "¬%s¬%s", BurnDrvGetTextA(DRV_NAME), DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "¬%s¬%s", BurnDrvGetTextA(DRV_NAME), DecorateGameName(nBurnDrvSelect)); fprintf(fDat, "¬%s¬%08x¬%d", szPossibleName, ri.nCrc, ri.nLen); fprintf(fDat, "¬¬¬\n"); } if (nDatType == 2) { char szPossibleNameBuffer[255]; memset(szPossibleNameBuffer, 0, 255); ReplaceAmpersand(szPossibleNameBuffer, szPossibleName); fprintf(fDat, "\t\t<rom name=\"%s\" size=\"%d\" crc=\"%08x\"/>\n", szPossibleNameBuffer, ri.nLen, ri.nCrc); } } } } if (nDatType == 0) fprintf(fDat, ")\n"); if (nDatType == 2) fprintf(fDat, "\t</game>\n"); } // Restore current driver nBurnDrvSelect=nOldSelect; if (nDatType == 2) fprintf(fDat, "</datafile>"); return 0; }
INT32 write_datfile(INT32 bType, FILE* fDat) { INT32 nRet=0; UINT32 nOldSelect=0; UINT32 nGameSelect=0; UINT32 nParentSelect,nBoardROMSelect; fprintf(fDat, "<?xml version=\"1.0\"?>\n"); fprintf(fDat, "<!DOCTYPE datafile PUBLIC \"-//FB Alpha//DTD ROM Management Datafile//EN\" \"http://www.logiqx.com/Dats/datafile.dtd\">\n\n"); fprintf(fDat, "<datafile>\n"); fprintf(fDat, "\t<header>\n"); fprintf(fDat, "\t\t<name>" APP_TITLE "</name>\n"); if (bType == DAT_ARCADE_ONLY) _ftprintf(fDat, _T("\t\t<description>") _T(APP_TITLE) _T(" v%s") _T(" Arcade Games</description>\n"), szAppBurnVer); if (bType == DAT_MEGADRIVE_ONLY) _ftprintf(fDat, _T("\t\t<description>") _T(APP_TITLE) _T(" v%s") _T(" Megadrive Games</description>\n"), szAppBurnVer); if (bType == DAT_PCENGINE_ONLY) _ftprintf(fDat, _T("\t\t<description>") _T(APP_TITLE) _T(" v%s") _T(" PC-Engine Games</description>\n"), szAppBurnVer); if (bType == DAT_TG16_ONLY) _ftprintf(fDat, _T("\t\t<description>") _T(APP_TITLE) _T(" v%s") _T(" TurboGrafx 16 Games</description>\n"), szAppBurnVer); if (bType == DAT_SGX_ONLY) _ftprintf(fDat, _T("\t\t<description>") _T(APP_TITLE) _T(" v%s") _T(" SuprGrafx Games</description>\n"), szAppBurnVer); fprintf(fDat, "\t\t<category>Standard DatFile</category>\n"); _ftprintf(fDat, _T("\t\t<version>%s</version>\n"), szAppBurnVer); fprintf(fDat, "\t\t<author>" APP_TITLE "</author>\n"); fprintf(fDat, "\t\t<homepage>http://www.barryharris.me.uk/</homepage>\n"); fprintf(fDat, "\t\t<url>http://www.barryharris.me.uk/</url>\n"); fprintf(fDat, "\t\t<clrmamepro forcenodump=\"ignore\"/>\n"); fprintf(fDat, "\t</header>\n"); nOldSelect=nBurnDrvActive; // preserve the currently selected driver // Go over each of the games for (nGameSelect=0;nGameSelect<nBurnDrvCount;nGameSelect++) { char sgName[32]; char spName[32]; char sbName[32]; char ssName[32]; UINT32 i=0; INT32 nPass=0; nBurnDrvActive=nGameSelect; // Switch to driver nGameSelect if ((BurnDrvGetFlags() & BDF_BOARDROM) || !strcmp(BurnDrvGetTextA(DRV_NAME), "neogeo")) { continue; } if ((((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_MEGADRIVE) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_PCENGINE_PCENGINE) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_PCENGINE_TG16) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_PCENGINE_SGX) ) && (bType == DAT_ARCADE_ONLY)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_SEGA_MEGADRIVE) && (bType == DAT_MEGADRIVE_ONLY)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_PCENGINE_PCENGINE) && (bType == DAT_PCENGINE_ONLY)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_PCENGINE_TG16) && (bType == DAT_TG16_ONLY)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_PCENGINE_SGX) && (bType == DAT_SGX_ONLY)) { continue; } strcpy(sgName, BurnDrvGetTextA(DRV_NAME)); strcpy(spName, ""); // make sure this string is empty before we start strcpy(sbName, ""); // make sure this string is empty before we start strcpy(ssName, ""); // make sure this string is empty before we start // Check to see if the game has a parent if (BurnDrvGetTextA(DRV_PARENT)) { nParentSelect=-1U; while (BurnDrvGetTextA(DRV_PARENT)) { strcpy(spName, BurnDrvGetTextA(DRV_PARENT)); for (i=0;i<nBurnDrvCount;i++) { nBurnDrvActive=i; if (!strcmp(spName, BurnDrvGetTextA(DRV_NAME))) { nParentSelect=i; break; } } } nBurnDrvActive=nGameSelect; // restore driver select } else nParentSelect=nGameSelect; // Check to see if the game has a BoardROM if (BurnDrvGetTextA(DRV_BOARDROM)) { nBoardROMSelect=-1U; strcpy(sbName, BurnDrvGetTextA(DRV_BOARDROM)); for (i=0;i<nBurnDrvCount;i++) { nBurnDrvActive=i; if (!strcmp(sbName, BurnDrvGetTextA(DRV_NAME))) { nBoardROMSelect=i; break; } } nBurnDrvActive=nGameSelect; // restore driver select } else nBoardROMSelect=nGameSelect; if (BurnDrvGetTextA(DRV_SAMPLENAME)) { strcpy(ssName, BurnDrvGetTextA(DRV_SAMPLENAME)); } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_SEGA_MEGADRIVE) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_PCENGINE_TG16) ) { // remove the md_ or tg_ char Temp[35]; INT32 Length; if (sgName[0]) { Length = strlen(sgName); memset(Temp, 0, 35); strcpy(Temp, sgName); memset(sgName, 0, 32); for (INT32 pos = 0; pos < Length; pos++) { sgName[pos] = Temp[pos + 3]; } } if (spName[0]) { Length = strlen(spName); memset(Temp, 0, 35); strcpy(Temp, spName); memset(spName, 0, 32); for (INT32 pos = 0; pos < Length; pos++) { spName[pos] = Temp[pos + 3]; } } } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_PCENGINE_PCENGINE) || ((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) == HARDWARE_PCENGINE_SGX) ) { // remove the pce__ or sgx__ char Temp[36]; INT32 Length; if (sgName[0]) { Length = strlen(sgName); memset(Temp, 0, 36); strcpy(Temp, sgName); memset(sgName, 0, 32); for (INT32 pos = 0; pos < Length; pos++) { sgName[pos] = Temp[pos + 4]; } } if (spName[0]) { Length = strlen(spName); memset(Temp, 0, 36); strcpy(Temp, spName); memset(spName, 0, 32); for (INT32 pos = 0; pos < Length; pos++) { spName[pos] = Temp[pos + 4]; } } } // Report problems if (nParentSelect==-1U) fprintf(fDat, "# Missing parent %s. It needs to be added to " APP_TITLE "!\n\n", spName); if (nBoardROMSelect==-1U) fprintf(fDat, "# Missing boardROM %s. It needs to be added to " APP_TITLE "!\n\n", sbName); // Write the header if (nParentSelect!=nGameSelect && nParentSelect!=-1U) { if (!strcmp(ssName, "") || !strcmp(ssName, sgName)) { fprintf(fDat, "\t<game name=\"%s\" cloneof=\"%s\" romof=\"%s\">\n", sgName, spName, spName); } else { fprintf(fDat, "\t<game name=\"%s\" cloneof=\"%s\" romof=\"%s\" sampleof=\"%s\">\n", sgName, spName, spName, ssName); } } else { // Add "romof" (but not 'cloneof') line for games that have boardROMs if (nBoardROMSelect!=nGameSelect && nBoardROMSelect!=-1U) { fprintf(fDat, "\t<game name=\"%s\" romof=\"%s\">\n", sgName, sbName); } else { if (!strcmp(ssName, "") || !strcmp(ssName, sgName)) { fprintf(fDat, "\t<game name=\"%s\">\n", sgName); } else { fprintf(fDat, "\t<game name=\"%s\" sampleof=\"%s\">\n", sgName, ssName); } } } char szGameName[255]; char szGameNameBuffer[255]; char szManufacturer[255]; char szManufacturerBuffer[255]; memset(szGameName, 0, 255); memset(szGameNameBuffer, 0, 255); memset(szManufacturer, 0, 255); memset(szManufacturerBuffer, 0, 255); strcpy(szGameName, DecorateGameName(nBurnDrvActive)); ReplaceAmpersand(szGameNameBuffer, szGameName); memset(szGameName, 0, 255); strcpy(szGameName, szGameNameBuffer); memset(szGameNameBuffer, 0, 255); ReplaceLessThan(szGameNameBuffer, szGameName); memset(szGameName, 0, 255); strcpy(szGameName, szGameNameBuffer); memset(szGameNameBuffer, 0, 255); ReplaceGreaterThan(szGameNameBuffer, szGameName); strcpy(szManufacturer, BurnDrvGetTextA(DRV_MANUFACTURER)); ReplaceAmpersand(szManufacturerBuffer, szManufacturer); memset(szManufacturer, 0, 255); strcpy(szManufacturer, szManufacturerBuffer); memset(szManufacturerBuffer, 0, 255); ReplaceLessThan(szManufacturerBuffer, szManufacturer); memset(szManufacturer, 0, 255); strcpy(szManufacturer, szManufacturerBuffer); memset(szManufacturerBuffer, 0, 255); ReplaceGreaterThan(szManufacturerBuffer, szManufacturer); fprintf(fDat, "\t\t<description>%s</description>\n", szGameNameBuffer); fprintf(fDat, "\t\t<year>%s</year>\n", BurnDrvGetTextA(DRV_DATE)); fprintf(fDat, "\t\t<manufacturer>%s</manufacturer>\n", szManufacturerBuffer); // Write the individual ROM info for (nPass=0; nPass<2; nPass++) { nBurnDrvActive=nGameSelect; // Skip pass 0 if possible (pass 0 only needed for old-style clrMAME format) if (nPass==0 /*&& (nBoardROMSelect==nGameSelect || nBoardROMSelect==-1U)*/) continue; // Go over each of the files needed for this game (upto 0x0100) for (i=0, nRet=0; nRet==0 && i<0x100; i++) { INT32 nRetTmp=0; struct BurnRomInfo ri; INT32 nLen; UINT32 nCrc; char *szPossibleName=NULL; INT32 j, nMerged=0; memset(&ri,0,sizeof(ri)); // Get info on this file nBurnDrvActive=nGameSelect; nRet=BurnDrvGetRomInfo(&ri,i); nRet+=BurnDrvGetRomName(&szPossibleName,i,0); if (ri.nLen==0) continue; if (nRet==0) { struct BurnRomInfo riTmp; char *szPossibleNameTmp; nLen=ri.nLen; nCrc=ri.nCrc; // Check for files from boardROMs if (nBoardROMSelect!=nGameSelect && nBoardROMSelect!=-1U) { nBurnDrvActive=nBoardROMSelect; nRetTmp=0; // Go over each of the files needed for this game (upto 0x0100) for (j=0; nRetTmp==0 && j<0x100; j++) { memset(&riTmp,0,sizeof(riTmp)); nRetTmp+=BurnDrvGetRomInfo(&riTmp,j); nRetTmp+=BurnDrvGetRomName(&szPossibleNameTmp,j,0); if (nRetTmp==0) { if (riTmp.nLen && riTmp.nCrc==nCrc && !strcmp(szPossibleName, szPossibleNameTmp)) { // This file is from a boardROM nMerged|=2; nRetTmp++; } } } } if (!nMerged && nParentSelect!=nGameSelect && nParentSelect!=-1U) { nBurnDrvActive=nParentSelect; nRetTmp=0; // Go over each of the files needed for this game (upto 0x0100) for (j=0; nRetTmp==0 && j<0x100; j++) { memset(&riTmp,0,sizeof(riTmp)); nRetTmp+=BurnDrvGetRomInfo(&riTmp,j); nRetTmp+=BurnDrvGetRomName(&szPossibleNameTmp,j,0); if (nRetTmp==0) { if (riTmp.nLen && riTmp.nCrc==nCrc && !strcmp(szPossibleName, szPossibleNameTmp)) { // This file is from a parent set nMerged|=1; nRetTmp++; } } } } nBurnDrvActive=nGameSelect; // Switch back to game } char szPossibleNameBuffer[255]; char szPossibleNameBuffer2[255]; memset(szPossibleNameBuffer, 0, 255); memset(szPossibleNameBuffer2, 0, 255); ReplaceAmpersand(szPossibleNameBuffer, szPossibleName); strcpy(szPossibleNameBuffer2, szPossibleNameBuffer); memset(szPossibleNameBuffer, 0, 255); ReplaceLessThan(szPossibleNameBuffer, szPossibleNameBuffer2); memset(szPossibleNameBuffer2, 0, 255); strcpy(szPossibleNameBuffer2, szPossibleNameBuffer); memset(szPossibleNameBuffer, 0, 255); ReplaceGreaterThan(szPossibleNameBuffer, szPossibleNameBuffer2); // File info if (nPass==1 && !nMerged) { if (ri.nType & BRF_NODUMP) { fprintf(fDat, "\t\t<rom name=\"%s\" size=\"%d\" status=\"nodump\"/>\n", szPossibleNameBuffer, ri.nLen); } else { fprintf(fDat, "\t\t<rom name=\"%s\" size=\"%d\" crc=\"%08x\"/>\n", szPossibleNameBuffer, ri.nLen, ri.nCrc); } } if (nPass==1 && nMerged) { // Files from parent/boardROMs if (ri.nType & BRF_NODUMP) { fprintf(fDat, "\t\t<rom name=\"%s\" merge=\"%s\" size=\"%d\" status=\"nodump\"/>\n", szPossibleNameBuffer, szPossibleNameBuffer, ri.nLen); } else { fprintf(fDat, "\t\t<rom name=\"%s\" merge=\"%s\" size=\"%d\" crc=\"%08x\"/>\n", szPossibleNameBuffer, szPossibleNameBuffer, ri.nLen, ri.nCrc); } } } // samples if (strcmp(ssName, "")) { for (i=0, nRet=0; nRet==0 && i<0x100; i++) { struct BurnSampleInfo si; char *szPossibleName=NULL; memset(&si,0,sizeof(si)); // Get info on this file nBurnDrvActive=nGameSelect; nRet=BurnDrvGetSampleInfo(&si,i); nRet+=BurnDrvGetSampleName(&szPossibleName,i,0); if (si.nFlags==0) continue; if (nPass == 1) { char szPossibleNameBuffer[255]; char szPossibleNameBuffer2[255]; memset(szPossibleNameBuffer, 0, 255); memset(szPossibleNameBuffer2, 0, 255); ReplaceAmpersand(szPossibleNameBuffer, szPossibleName); strcpy(szPossibleNameBuffer2, szPossibleNameBuffer); memset(szPossibleNameBuffer, 0, 255); ReplaceLessThan(szPossibleNameBuffer, szPossibleNameBuffer2); memset(szPossibleNameBuffer2, 0, 255); strcpy(szPossibleNameBuffer2, szPossibleNameBuffer); memset(szPossibleNameBuffer, 0, 255); ReplaceGreaterThan(szPossibleNameBuffer, szPossibleNameBuffer2); fprintf(fDat, "\t\t<sample name=\"%s\" />\n", szPossibleNameBuffer); } } } } fprintf(fDat, "\t</game>\n"); } // Do another pass over each of the games to find boardROMs for (nBurnDrvActive=0; nBurnDrvActive<nBurnDrvCount; nBurnDrvActive++) { INT32 i, nPass; if (!(BurnDrvGetFlags() & BDF_BOARDROM)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_SEGA_MEGADRIVE) && (bType == DAT_MEGADRIVE_ONLY)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_PCENGINE_PCENGINE) && (bType == DAT_PCENGINE_ONLY)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_PCENGINE_TG16) && (bType == DAT_TG16_ONLY)) { continue; } if (((BurnDrvGetHardwareCode() & HARDWARE_PUBLIC_MASK) != HARDWARE_PCENGINE_SGX) && (bType == DAT_SGX_ONLY)) { continue; } fprintf(fDat, "\t<game isbios=\"yes\" name=\"%s\">\n", BurnDrvGetTextA(DRV_NAME)); fprintf(fDat, "\t\t<description>%s</description>\n", DecorateGameName(nBurnDrvActive)); fprintf(fDat, "\t\t<year>%s</year>\n", BurnDrvGetTextA(DRV_DATE)); fprintf(fDat, "\t\t<manufacturer>%s</manufacturer>\n", BurnDrvGetTextA(DRV_MANUFACTURER)); for (nPass=0; nPass<2; nPass++) { // No meta information needed (pass 0 only needed for old-style clrMAME format) if (nPass==0) continue; // Go over each of the individual files (upto 0x0100) for (i=0; i<0x100; i++) { struct BurnRomInfo ri; char *szPossibleName=NULL; memset(&ri,0,sizeof(ri)); nRet=BurnDrvGetRomInfo(&ri,i); nRet+=BurnDrvGetRomName(&szPossibleName,i,0); if (ri.nLen==0) continue; if (nRet==0) { char szPossibleNameBuffer[255]; char szPossibleNameBuffer2[255]; memset(szPossibleNameBuffer, 0, 255); memset(szPossibleNameBuffer2, 0, 255); ReplaceAmpersand(szPossibleNameBuffer, szPossibleName); strcpy(szPossibleNameBuffer2, szPossibleNameBuffer); memset(szPossibleNameBuffer, 0, 255); ReplaceLessThan(szPossibleNameBuffer, szPossibleNameBuffer2); memset(szPossibleNameBuffer2, 0, 255); strcpy(szPossibleNameBuffer2, szPossibleNameBuffer); memset(szPossibleNameBuffer, 0, 255); ReplaceGreaterThan(szPossibleNameBuffer, szPossibleNameBuffer2); fprintf(fDat, "\t\t<rom name=\"%s\" size=\"%d\" crc=\"%08x\"/>\n", szPossibleNameBuffer, ri.nLen, ri.nCrc); } } } fprintf(fDat, "\t</game>\n"); } // Restore current driver nBurnDrvActive=nOldSelect; fprintf(fDat, "</datafile>"); return 0; }
// Write a savestate as a chunk of an "FB1 " file // nOffset is the absolute offset from the beginning of the file // -1: Append at current position // -2: Append at EOF int BurnStateSaveEmbed(FILE* fp, int nOffset, int bAll) { const char* szHeader = "FS1 "; // Chunk identifier int nLen = 0; int nNvMin = 0, nAMin = 0; int nZero = 0; char szGame[33]; unsigned char *Def = NULL; int nDefLen = 0; // Deflated version int nRet = 0; if (fp == NULL) { return -1; } StateInfo(&nLen, &nNvMin, 0); // Get minimum version for NV part nAMin = nNvMin; if (bAll) { // Get minimum version for All data StateInfo(&nLen, &nAMin, 1); } if (nLen <= 0) { // No memory to save return -1; } if (nOffset >= 0) { fseek(fp, nOffset, SEEK_SET); } else { if (nOffset == -2) { fseek(fp, 0, SEEK_END); } else { fseek(fp, 0, SEEK_CUR); } } fwrite(szHeader, 1, 4, fp); // Chunk identifier int nSizeOffset = ftell(fp); // Reserve space to write the size of this chunk fwrite(&nZero, 1, 4, fp); // fwrite(&nBurnVer, 1, 4, fp); // Version of FB this was saved from fwrite(&nNvMin, 1, 4, fp); // Min version of FB NV data will work with fwrite(&nAMin, 1, 4, fp); // Min version of FB All data will work with fwrite(&nZero, 1, 4, fp); // Reserve space to write the compressed data size memset(szGame, 0, sizeof(szGame)); // Game name sprintf(szGame, "%.32s", BurnDrvGetTextA(DRV_NAME)); // fwrite(szGame, 1, 32, fp); // fwrite(&nCurrentFrame, 1, 4, fp); // Current frame fwrite(&nZero, 1, 4, fp); // Reserved fwrite(&nZero, 1, 4, fp); // fwrite(&nZero, 1, 4, fp); // nRet = BurnStateCompress(&Def, &nDefLen, bAll); // Compress block from driver and return deflated buffer if (Def == NULL) { return -1; } nRet = fwrite(Def, 1, nDefLen, fp); // Write block to disk if (Def) { free(Def); // free deflated block and close file Def = NULL; } if (nRet != nDefLen) { // error writing block to disk return -1; } if (nDefLen & 3) { // Chunk size must be a multiple of 4 fwrite(&nZero, 1, 4 - (nDefLen & 3), fp); // Pad chunk if needed } fseek(fp, nSizeOffset + 0x10, SEEK_SET); // Write size of the compressed data fwrite(&nDefLen, 1, 4, fp); // nDefLen = (nDefLen + 0x43) & ~3; // Add for header size and align fseek(fp, nSizeOffset, SEEK_SET); // Write size of the chunk fwrite(&nDefLen, 1, 4, fp); // fseek (fp, 0, SEEK_END); // Set file pointer to the end of the chunk return nDefLen; }
// Write out the config file for the game-specific inputs int ConfigGameSave(bool bSave) { FILE* h; if (!bSave) { GameInpBlank(0); ConfigGameLoad(false); } h = _tfopen(GameConfigName(), _T("wt")); if (h == NULL) { return 1; } // Write title _ftprintf(h, _T("// ") _T(APP_TITLE) _T(" v%s --- Config File for %s (%s)\n\n"), szAppBurnVer, BurnDrvGetText(DRV_NAME), ANSIToTCHAR(BurnDrvGetTextA(DRV_FULLNAME), NULL, 0)); _ftprintf(h, _T("// --- Miscellaneous ----------------------------------------------------------\n\n")); // Write version number _ftprintf(h, _T("version 0x%06X\n\n"), nBurnVer); // Write speed for relative analog controls _ftprintf(h, _T("analog 0x%04X\n"), nAnalogSpeed); // Write CPU speed adjustment _ftprintf(h, _T("cpu 0x%04X\n"), nBurnCPUSpeedAdjust); _ftprintf(h, _T("\n\n\n")); _ftprintf(h, _T("// --- Inputs -----------------------------------------------------------------\n\n")); GameInpWrite(h); fclose(h); return 0; }
void BurnSampleInitOne(INT32 sample) { if (sample >= nTotalSamples) { return; } { struct sample_format *clr_ptr = &samples[0]; int i = 0; while (i < nTotalSamples) { if (clr_ptr->data != NULL && i != sample && (clr_ptr->flags & SAMPLE_NOSTORE)) { free(clr_ptr->data); clr_ptr->playing = 0; clr_ptr->data = NULL; } clr_ptr++, i++; } } if ((sample_ptr->flags & SAMPLE_NOSTORE) == 0) { return; } INT32 length; char path[256]; char setname[128]; void *destination = NULL; char szTempPath[MAX_PATH]; sprintf(szTempPath, _TtoA(SAMPLE_DIRECTORY)); strcpy(setname, BurnDrvGetTextA(DRV_SAMPLENAME)); sprintf(path, "%s%s.zip", szTempPath, setname); struct BurnSampleInfo si; BurnDrvGetSampleInfo(&si, sample); char *szSampleName = NULL; BurnDrvGetSampleName(&szSampleName, sample, 0); sample_ptr = &samples[sample]; // append .wav to filename szSampleName[strlen(szSampleName)] = '.'; szSampleName[strlen(szSampleName)] = 'w'; szSampleName[strlen(szSampleName)] = 'a'; szSampleName[strlen(szSampleName)] = 'v'; if (sample_ptr->playing || sample_ptr->data != NULL || sample_ptr->flags == SAMPLE_IGNORE) { return; } sprintf (path, "%s%s", szTempPath, setname); destination = NULL; length = 0; ZipLoadOneFile((char*)path, (const char*)szSampleName, &destination, &length); if (length) { make_raw((UINT8*)destination, length); } if (destination) { free (destination); destination = NULL; } }
void BurnSampleInit(INT32 bAdd /*add sample to stream?*/) { DebugSnd_SamplesInitted = 1; if (nBurnSoundRate == 0) { nTotalSamples = 0; return; } INT32 length; char path[256]; char setname[128]; void *destination = NULL; char szTempPath[MAX_PATH]; sprintf(szTempPath, _TtoA(SAMPLE_DIRECTORY)); // test to see if file exists INT32 nEnableSamples = 0; if (BurnDrvGetTextA(DRV_SAMPLENAME) == NULL) { // called with no samples nTotalSamples = 0; return; } strcpy(setname, BurnDrvGetTextA(DRV_SAMPLENAME)); sprintf(path, "%s%s.zip", szTempPath, setname); FILE *test = fopen(path, "rb"); if (test) { nEnableSamples = 1; fclose(test); } #ifdef INCLUDE_7Z_SUPPORT sprintf(path, "%s%s.7z", szTempPath, setname); test = fopen(path, "rb"); if (test) { nEnableSamples = 1; fclose(test); } #endif bAddToStream = bAdd; nTotalSamples = 0; if (!nEnableSamples) return; struct BurnSampleInfo si; INT32 nSampleOffset = -1; do { BurnDrvGetSampleInfo(&si, ++nSampleOffset); if (si.nFlags) nTotalSamples++; } while (si.nFlags); samples = (sample_format*)malloc(sizeof(sample_format) * nTotalSamples); memset (samples, 0, sizeof(sample_format) * nTotalSamples); for (INT32 i = 0; i < nTotalSamples; i++) { BurnDrvGetSampleInfo(&si, i); char *szSampleName = NULL; BurnDrvGetSampleName(&szSampleName, i, 0); sample_ptr = &samples[i]; // append .wav to filename szSampleName[strlen(szSampleName)] = '.'; szSampleName[strlen(szSampleName)] = 'w'; szSampleName[strlen(szSampleName)] = 'a'; szSampleName[strlen(szSampleName)] = 'v'; if (si.nFlags == 0) break; if (si.nFlags & SAMPLE_NOSTORE) { sample_ptr->flags = si.nFlags; sample_ptr->data = NULL; continue; } sprintf (path, "%s%s", szTempPath, setname); destination = NULL; length = 0; ZipLoadOneFile((char*)path, (const char*)szSampleName, &destination, &length); if (length) { sample_ptr->flags = si.nFlags; make_raw((UINT8*)destination, length); } else { sample_ptr->flags = SAMPLE_IGNORE; } sample_ptr->gain[BURN_SND_SAMPLE_ROUTE_1] = 1.00; sample_ptr->gain[BURN_SND_SAMPLE_ROUTE_2] = 1.00; sample_ptr->output_dir[BURN_SND_SAMPLE_ROUTE_1] = BURN_SND_ROUTE_BOTH; sample_ptr->output_dir[BURN_SND_SAMPLE_ROUTE_2] = BURN_SND_ROUTE_BOTH; if (destination) { free (destination); destination = NULL; } BurnSetProgressRange(1.0 / nTotalSamples); BurnUpdateProgress((double)1.0 / i * nTotalSamples, _T("Loading samples..."), 0); } }
// State load int BurnStateLoadEmbed(FILE* fp, int nOffset, int bAll, int (*pLoadGame)()) { const char* szHeader = "FS1 "; // Chunk identifier int nLen = 0; int nMin = 0, nFileVer = 0, nFileMin = 0; int t1 = 0, t2 = 0; char ReadHeader[4]; char szForName[33]; int nChunkSize = 0; unsigned char *Def = NULL; int nDefLen = 0; // Deflated version int nRet = 0; if (nOffset >= 0) { fseek(fp, nOffset, SEEK_SET); } else { if (nOffset == -2) { fseek(fp, 0, SEEK_END); } else { fseek(fp, 0, SEEK_CUR); } } memset(ReadHeader, 0, 4); fread(ReadHeader, 1, 4, fp); // Read identifier if (memcmp(ReadHeader, szHeader, 4)) { // Not the right file type return -2; } fread(&nChunkSize, 1, 4, fp); if (nChunkSize <= 0x40) { // Not big enough return -1; } int nChunkData = ftell(fp); fread(&nFileVer, 1, 4, fp); // Version of FB that this file was saved from fread(&t1, 1, 4, fp); // Min version of FB that NV data will work with fread(&t2, 1, 4, fp); // Min version of FB that All data will work with if (bAll) { // Get the min version number which applies to us nFileMin = t2; } else { nFileMin = t1; } fread(&nDefLen, 1, 4, fp); // Get the size of the compressed data block memset(szForName, 0, sizeof(szForName)); fread(szForName, 1, 32, fp); if (nBurnVer < nFileMin) { // Error - emulator is too old to load this state return -5; } // Check the game the savestate is for, and load it if needed. { bool bLoadGame = false; if (nBurnDrvActive < nBurnDrvCount) { if (strcmp(szForName, BurnDrvGetTextA(DRV_NAME))) { // The save state is for the wrong game bLoadGame = true; } } else { // No game loaded bLoadGame = true; } if (bLoadGame) { unsigned int nCurrentGame = nBurnDrvActive; unsigned int i; for (i = 0; i < nBurnDrvCount; i++) { nBurnDrvActive = i; if (strcmp(szForName, BurnDrvGetTextA(DRV_NAME)) == 0) { break; } } if (i == nBurnDrvCount) { nBurnDrvActive = nCurrentGame; return -3; } else { if (pLoadGame == NULL) { return -1; } if (pLoadGame()) { return -1; } } } } StateInfo(&nLen, &nMin, bAll); if (nLen <= 0) { // No memory to load return -1; } // Check if the save state is okay if (nFileVer < nMin) { // Error - this state is too old and cannot be loaded. return -4; } fseek(fp, nChunkData + 0x30, SEEK_SET); // Read current frame fread(&nCurrentFrame, 1, 4, fp); // fseek(fp, 0x0C, SEEK_CUR); // Move file pointer to the start of the compressed block Def = (unsigned char*)malloc(nDefLen); if (Def == NULL) { return -1; } memset(Def, 0, nDefLen); fread(Def, 1, nDefLen, fp); // Read in deflated block nRet = BurnStateDecompress(Def, nDefLen, bAll); // Decompress block into driver if (Def) { free(Def); // free deflated block Def = NULL; } fseek(fp, nChunkData + nChunkSize, SEEK_SET); if (nRet) { return -1; } else { return 0; } }
int QsndInit() { int nVolumeShift; int nRate; // Init QSound z80 if (QsndZInit()) { return 1; } BurnTimerInit(qsndTimerOver, NULL); if (Cps1Qs == 1) { nCpsZ80Cycles = 6000000 * 100 / nBurnFPS; BurnTimerAttachZet(6000000); } else { nCpsZ80Cycles = 8000000 * 100 / nBurnFPS; BurnTimerAttachZet(8000000); } if (nBurnSoundRate >= 0) { nRate = nBurnSoundRate; } else { nRate = 11025; } nVolumeShift = 0; // These games are too soft at normal volumes if (strncmp(BurnDrvGetTextA(DRV_NAME), "csclub", 6) == 0) { nVolumeShift = -1; } #if 0 // These games are loud at normal volumes (no clipping) if (strncmp(BurnDrvGetTextA(DRV_NAME), "1944", 4) == 0 || strcmp( BurnDrvGetTextA(DRV_NAME), "dimahoo" ) == 0 || strcmp( BurnDrvGetTextA(DRV_NAME), "gmahoo" ) == 0) { nVolumeShift = 1; } #endif // These games are too loud at normal volumes (no clipping) if (strncmp(BurnDrvGetTextA(DRV_NAME), "sgemf", 5) == 0 || strncmp(BurnDrvGetTextA(DRV_NAME), "pfght", 5) == 0 || strncmp(BurnDrvGetTextA(DRV_NAME), "mpang", 5) == 0 || strncmp(BurnDrvGetTextA(DRV_NAME), "spf2", 4) == 0 || strncmp(BurnDrvGetTextA(DRV_NAME), "sfa2", 4) == 0 || strncmp(BurnDrvGetTextA(DRV_NAME), "sfa2", 4) == 0) { nVolumeShift = 1; } // These games are too loud at normal volumes (clipping) if (strncmp(BurnDrvGetTextA(DRV_NAME), "19xx", 4) == 0 || strncmp(BurnDrvGetTextA(DRV_NAME), "ddtod", 5) == 0) { nVolumeShift = 2; } QscInit(nRate, nVolumeShift); // Init QSound chip return 0; }