void HiscoreApply() { if (!CheckHiscoreAllowed() || !HiscoresInUse) return; if (nCpuType == -1) set_cpu_type(); for (unsigned int i = 0; i < nHiscoreNumRanges; i++) { if (HiscoreMemRange[i].Loaded && HiscoreMemRange[i].Applied == APPLIED_STATE_ATTEMPTED) { int Confirmed = 1; cpu_open(HiscoreMemRange[i].nCpu); for (unsigned int j = 0; j < HiscoreMemRange[i].NumBytes; j++) { if (cpu_read_byte(HiscoreMemRange[i].Address + j) != HiscoreMemRange[i].Data[j]) { Confirmed = 0; } } cpu_close(); if (Confirmed == 1) { HiscoreMemRange[i].Applied = APPLIED_STATE_CONFIRMED; #if 1 && defined FBA_DEBUG bprintf(PRINT_IMPORTANT, _T("Applied Hi Score Memory Range %i on frame number %i\n"), i, GetCurrentFrame()); #endif } else { HiscoreMemRange[i].Applied = APPLIED_STATE_NONE; HiscoreMemRange[i].ApplyNextFrame = 1; #if 1 && defined FBA_DEBUG bprintf(PRINT_IMPORTANT, _T("Failed attempt to apply Hi Score Memory Range %i on frame number %i\n"), i, GetCurrentFrame()); #endif } } if (HiscoreMemRange[i].Loaded && HiscoreMemRange[i].Applied == APPLIED_STATE_NONE && HiscoreMemRange[i].ApplyNextFrame) { cpu_open(HiscoreMemRange[i].nCpu); for (unsigned int j = 0; j < HiscoreMemRange[i].NumBytes; j++) { cpu_write_byte(HiscoreMemRange[i].Address + j, HiscoreMemRange[i].Data[j]); } cpu_close(); HiscoreMemRange[i].Applied = APPLIED_STATE_ATTEMPTED; HiscoreMemRange[i].ApplyNextFrame = 0; } if (HiscoreMemRange[i].Loaded && HiscoreMemRange[i].Applied == APPLIED_STATE_NONE) { cpu_open(HiscoreMemRange[i].nCpu); if (cpu_read_byte(HiscoreMemRange[i].Address) == HiscoreMemRange[i].StartValue && cpu_read_byte(HiscoreMemRange[i].Address + HiscoreMemRange[i].NumBytes - 1) == HiscoreMemRange[i].EndValue) { HiscoreMemRange[i].ApplyNextFrame = 1; } cpu_close(); } } }
void HiscoreReset() { #if defined FBA_DEBUG if (!Debug_HiscoreInitted) bprintf(PRINT_ERROR, _T("HiscoreReset called without init\n")); #endif if (!CheckHiscoreAllowed() || !HiscoresInUse) return; if (nCpuType == -1) set_cpu_type(); for (UINT32 i = 0; i < nHiscoreNumRanges; i++) { HiscoreMemRange[i].ApplyNextFrame = 0; HiscoreMemRange[i].Applied = APPLIED_STATE_NONE; if (HiscoreMemRange[i].Loaded) { cpu_open(HiscoreMemRange[i].nCpu); cpu_write_byte(HiscoreMemRange[i].Address, (UINT8)~HiscoreMemRange[i].StartValue); if (HiscoreMemRange[i].NumBytes > 1) cpu_write_byte(HiscoreMemRange[i].Address + HiscoreMemRange[i].NumBytes - 1, (UINT8)~HiscoreMemRange[i].EndValue); cpu_close(); #if 1 && defined FBA_DEBUG bprintf(PRINT_IMPORTANT, _T("Hi Score Memory Range %i Initted\n"), i); #endif } } }
void HiscoreExit() { #if defined FBA_DEBUG if (!Debug_HiscoreInitted) bprintf(PRINT_ERROR, _T("HiscoreExit called without init\n")); #endif if (!CheckHiscoreAllowed() || !HiscoresInUse) { Debug_HiscoreInitted = 0; return; } if (nCpuType == -1) set_cpu_type(); TCHAR szFilename[MAX_PATH]; _stprintf(szFilename, _T("%s%s.hi"), szAppHiscorePath, BurnDrvGetText(DRV_NAME)); FILE *fp = _tfopen(szFilename, _T("w")); if (fp) { for (UINT32 i = 0; i < nHiscoreNumRanges; i++) { UINT8 *Buffer = (UINT8*)malloc(HiscoreMemRange[i].NumBytes); cpu_open(HiscoreMemRange[i].nCpu); for (UINT32 j = 0; j < HiscoreMemRange[i].NumBytes; j++) { Buffer[j] = cpu_read_byte(HiscoreMemRange[i].Address + j); } cpu_close(); fwrite(Buffer, 1, HiscoreMemRange[i].NumBytes, fp); if (Buffer) { free(Buffer); Buffer = NULL; } } } fclose(fp); nCpuType = -1; nHiscoreNumRanges = 0; for (UINT32 i = 0; i < HISCORE_MAX_RANGES; i++) { HiscoreMemRange[i].Loaded = 0; HiscoreMemRange[i].nCpu = 0; HiscoreMemRange[i].Address = 0; HiscoreMemRange[i].NumBytes = 0; HiscoreMemRange[i].StartValue = 0; HiscoreMemRange[i].EndValue = 0; HiscoreMemRange[i].ApplyNextFrame = 0; HiscoreMemRange[i].Applied = 0; free(HiscoreMemRange[i].Data); HiscoreMemRange[i].Data = NULL; } Debug_HiscoreInitted = 0; }
void HiscoreExit() { if (!CheckHiscoreAllowed() || !HiscoresInUse) return; if (nCpuType == -1) set_cpu_type(); TCHAR szFilename[MAX_PATH]; _stprintf(szFilename, _T("%s%s.hi"), szAppHiscorePath, BurnDrvGetText(DRV_NAME)); FILE *fp = _tfopen(szFilename, _T("w")); if (fp) { for (unsigned int i = 0; i < nHiscoreNumRanges; i++) { unsigned char *Buffer = (unsigned char*)malloc(HiscoreMemRange[i].NumBytes); cpu_open(HiscoreMemRange[i].nCpu); for (unsigned int j = 0; j < HiscoreMemRange[i].NumBytes; j++) { Buffer[j] = cpu_read_byte(HiscoreMemRange[i].Address + j); } cpu_close(); fwrite(Buffer, 1, HiscoreMemRange[i].NumBytes, fp); if (Buffer) { free(Buffer); Buffer = NULL; } } } fclose(fp); nCpuType = -1; nHiscoreNumRanges = 0; for (unsigned int i = 0; i < HISCORE_MAX_RANGES; i++) { HiscoreMemRange[i].Loaded = 0; HiscoreMemRange[i].nCpu = 0; HiscoreMemRange[i].Address = 0; HiscoreMemRange[i].NumBytes = 0; HiscoreMemRange[i].StartValue = 0; HiscoreMemRange[i].EndValue = 0; HiscoreMemRange[i].ApplyNextFrame = 0; HiscoreMemRange[i].Applied = 0; free(HiscoreMemRange[i].Data); HiscoreMemRange[i].Data = NULL; } }