From 4b6a368ab6d63c18f5f3f5a76662455d27680717 Mon Sep 17 00:00:00 2001 From: R-YaTian <47445484+R-YaTian@users.noreply.github.com> Date: Thu, 26 May 2022 02:13:18 +0800 Subject: [PATCH 01/22] Support latest fbneo core --- pfbneo/sources/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pfbneo/sources/main.cpp b/pfbneo/sources/main.cpp index e49babf9..ac2f2ce2 100644 --- a/pfbneo/sources/main.cpp +++ b/pfbneo/sources/main.cpp @@ -54,6 +54,11 @@ INT32 GetIpsesMaxLen(char *) return 0; } +bool GetIpsDrvProtection() +{ + return false; +} + int main(int argc, char **argv) { #ifdef __PSP2__ // set max cpu speed From 41376255d2a771d1b2a17e6fb50bb0cf174c5558 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Mon, 6 Jun 2022 10:19:57 +0200 Subject: [PATCH 02/22] pfbn: support latest fbneo core (25f8e93) --- cores/fbneo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/fbneo b/cores/fbneo index eda8ae46..25f8e935 160000 --- a/cores/fbneo +++ b/cores/fbneo @@ -1 +1 @@ -Subproject commit eda8ae461a8c431080cebb17e753352d6354ba16 +Subproject commit 25f8e93595cc895deae427a7487eed082df451b1 From 9fac6d2c58c6845ad69ca3d6de7c3e507f951bc5 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Mon, 6 Jun 2022 10:21:32 +0200 Subject: [PATCH 03/22] switch: remove libarchive workflow hacks --- .github/workflows/switch-dev.yml | 15 --------------- .github/workflows/switch-release.yml | 15 --------------- 2 files changed, 30 deletions(-) diff --git a/.github/workflows/switch-dev.yml b/.github/workflows/switch-dev.yml index aabf3174..5790af91 100644 --- a/.github/workflows/switch-dev.yml +++ b/.github/workflows/switch-dev.yml @@ -24,21 +24,6 @@ jobs: sudo apt -yq update sudo apt -yq install git build-essential cmake zip - - name: Update pacman packages - run: | - dkp-pacman -Syyu --noconfirm - - # TODO: remove when merged - - name: Install libarchive - run: | - dkp-pacman -S --noconfirm dkp-toolchain-vars - mkdir libarchive && cd libarchive - wget https://github.com/Cpasjuste/pacman-packages/raw/switch-libarchive/switch/libarchive/PKGBUILD - wget https://github.com/Cpasjuste/pacman-packages/raw/switch-libarchive/switch/libarchive/libarchive-3.3.2.patch - chown -R nobody ../libarchive - sudo -E -u nobody dkp-makepkg - dkp-pacman -U --noconfirm *.pkg.tar.xz - # TODO: remove when merged - name: Update SDL2 run: | diff --git a/.github/workflows/switch-release.yml b/.github/workflows/switch-release.yml index cbc93c5f..3d0dddcf 100644 --- a/.github/workflows/switch-release.yml +++ b/.github/workflows/switch-release.yml @@ -24,21 +24,6 @@ jobs: sudo apt -yq update sudo apt -yq install git build-essential cmake zip - - name: Update pacman packages - run: | - dkp-pacman -Syyu --noconfirm - - # TODO: remove when merged - - name: Install libarchive - run: | - dkp-pacman -S --noconfirm dkp-toolchain-vars - mkdir libarchive && cd libarchive - wget https://github.com/Cpasjuste/pacman-packages/raw/switch-libarchive/switch/libarchive/PKGBUILD - wget https://github.com/Cpasjuste/pacman-packages/raw/switch-libarchive/switch/libarchive/libarchive-3.3.2.patch - chown -R nobody ../libarchive - sudo -E -u nobody dkp-makepkg - dkp-pacman -U --noconfirm *.pkg.tar.xz - - name: Update SDL2 run: | git clone --depth 1 --branch switch-sdl2-2.0.14-dev https://github.com/devkitPro/SDL.git From ffa5ed4a70168d43a0111408c321ad9ae015df01 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Mon, 6 Jun 2022 10:42:20 +0200 Subject: [PATCH 04/22] switch: fix sdl2 workflow --- .github/workflows/switch-dev.yml | 10 ++++------ .github/workflows/switch-release.yml | 7 +++++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/switch-dev.yml b/.github/workflows/switch-dev.yml index 5790af91..47777ad0 100644 --- a/.github/workflows/switch-dev.yml +++ b/.github/workflows/switch-dev.yml @@ -29,13 +29,14 @@ jobs: run: | git clone --depth 1 --branch switch-sdl2-2.0.14-dev https://github.com/devkitPro/SDL.git cd SDL && mkdir build && cd build - cmake -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake \ - -DCMAKE_INSTALL_PREFIX=/opt/devkitpro/portlibs/switch .. + cmake \ + -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake \ + -DCMAKE_INSTALL_PREFIX=/opt/devkitpro/portlibs/switch \ + -DCMAKE_BUILD_TYPE=Debug .. make -j $(getconf _NPROCESSORS_ONLN) install - name: Build pfbneo run: | - cd $GITHUB_WORKSPACE mkdir cmake-build-pfbneo && cd cmake-build-pfbneo source /etc/profile.d/devkit-env.sh cmake -G "Unix Makefiles" -DPLATFORM_SWITCH=ON -DOPTION_EMU=pfbneo -DCMAKE_BUILD_TYPE=Debug .. @@ -44,7 +45,6 @@ jobs: - name: Build pgen run: | - cd $GITHUB_WORKSPACE mkdir cmake-build-pgen && cd cmake-build-pgen source /etc/profile.d/devkit-env.sh cmake -G "Unix Makefiles" -DPLATFORM_SWITCH=ON -DOPTION_EMU=pgen -DCMAKE_BUILD_TYPE=Debug .. @@ -52,7 +52,6 @@ jobs: - name: Build pnes run: | - cd $GITHUB_WORKSPACE mkdir cmake-build-pnes && cd cmake-build-pnes source /etc/profile.d/devkit-env.sh cmake -G "Unix Makefiles" -DPLATFORM_SWITCH=ON -DOPTION_EMU=pnes -DCMAKE_BUILD_TYPE=Debug .. @@ -60,7 +59,6 @@ jobs: - name: Build psnes run: | - cd $GITHUB_WORKSPACE mkdir cmake-build-psnes && cd cmake-build-psnes source /etc/profile.d/devkit-env.sh cmake -G "Unix Makefiles" -DPLATFORM_SWITCH=ON -DOPTION_EMU=psnes -DCMAKE_BUILD_TYPE=Debug .. diff --git a/.github/workflows/switch-release.yml b/.github/workflows/switch-release.yml index 3d0dddcf..6885160f 100644 --- a/.github/workflows/switch-release.yml +++ b/.github/workflows/switch-release.yml @@ -24,12 +24,15 @@ jobs: sudo apt -yq update sudo apt -yq install git build-essential cmake zip + # TODO: remove when merged - name: Update SDL2 run: | git clone --depth 1 --branch switch-sdl2-2.0.14-dev https://github.com/devkitPro/SDL.git cd SDL && mkdir build && cd build - cmake -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake \ - -DCMAKE_INSTALL_PREFIX=/opt/devkitpro/portlibs/switch .. + cmake \ + -DCMAKE_TOOLCHAIN_FILE=/opt/devkitpro/cmake/Switch.cmake \ + -DCMAKE_INSTALL_PREFIX=/opt/devkitpro/portlibs/switch \ + -DCMAKE_BUILD_TYPE=Release .. make -j $(getconf _NPROCESSORS_ONLN) install - name: Build pfbneo From 33d054cdece0419bc2d4e064cf1a9623534661d6 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Tue, 7 Jun 2022 14:02:03 +0200 Subject: [PATCH 05/22] pfbn: use fbneo state.cpp --- pfbneo/CMakeLists.txt | 1 - pfbneo/sources/fbneo/drv.cpp | 16 +- pfbneo/sources/fbneo/state.cpp | 421 --------------------------------- 3 files changed, 14 insertions(+), 424 deletions(-) delete mode 100644 pfbneo/sources/fbneo/state.cpp diff --git a/pfbneo/CMakeLists.txt b/pfbneo/CMakeLists.txt index 900e60b9..e1e55b89 100644 --- a/pfbneo/CMakeLists.txt +++ b/pfbneo/CMakeLists.txt @@ -47,7 +47,6 @@ list(REMOVE_ITEM SRC_BURNER ${CMAKE_SOURCE_DIR}/cores/fbneo/src/burner/image.cpp ${CMAKE_SOURCE_DIR}/cores/fbneo/src/burner/ioapi.c ${CMAKE_SOURCE_DIR}/cores/fbneo/src/burner/sshot.cpp - ${CMAKE_SOURCE_DIR}/cores/fbneo/src/burner/state.cpp ${CMAKE_SOURCE_DIR}/cores/fbneo/src/burner/unzip.c ${CMAKE_SOURCE_DIR}/cores/fbneo/src/burner/zipfn.cpp ${CMAKE_SOURCE_DIR}/cores/fbneo/src/burner/luaengine.cpp diff --git a/pfbneo/sources/fbneo/drv.cpp b/pfbneo/sources/fbneo/drv.cpp index 5e3614b0..e37e97dc 100644 --- a/pfbneo/sources/fbneo/drv.cpp +++ b/pfbneo/sources/fbneo/drv.cpp @@ -8,16 +8,28 @@ using namespace c2dui; extern UiMain *ui; extern UINT8 NeoSystem; -int bDrvOkay = 0; // 1 if the Driver has been initted okay, and it's okay to use the BurnDrv functions +int bDrvOkay = 0; // 1 if the Driver has been initted okay, and it's okay to use the BurnDrv functions int kNetGame = 0; int nIpsMaxFileLen = 0; -static int ProgressCreate(); +// burner/state.cpp +bool bReplayReadOnly; +INT32 nReplayStatus = 0; +INT32 nReplayUndoCount = 0; +UINT32 nReplayCurrentFrame = 0; +UINT32 nStartFrame = 0; + +INT32 FreezeInput(UINT8 **buf, INT32 *size) { return 0; } + +INT32 UnfreezeInput(const UINT8 *buf, INT32 size) { return 0; } +// burner/state.cpp bool is_netgame_or_recording() { return false; } +static int ProgressCreate(); + static UINT8 NeoSystemList[] = { 0x13, // "Universe BIOS ver. 4.0" 0x14, // "Universe BIOS ver. 3.3" diff --git a/pfbneo/sources/fbneo/state.cpp b/pfbneo/sources/fbneo/state.cpp deleted file mode 100644 index de07b672..00000000 --- a/pfbneo/sources/fbneo/state.cpp +++ /dev/null @@ -1,421 +0,0 @@ -// Driver Save State module -#include "burner.h" - -/* -// from dynhuff.cpp -INT32 FreezeDecode(UINT8 **buffer, INT32 *size); -INT32 UnfreezeDecode(const UINT8* buffer, INT32 size); -INT32 FreezeEncode(UINT8 **buffer, INT32 *size); -INT32 UnfreezeEncode(const UINT8* buffer, INT32 size); - -// from replay.cpp -INT32 FreezeInput(UINT8** buf, int* size); -INT32 UnfreezeInput(const UINT8* buf, INT32 size); - -extern INT32 nReplayStatus; -extern bool bReplayReadOnly; -extern INT32 nReplayUndoCount; -extern UINT32 nReplayCurrentFrame; -extern UINT32 nStartFrame; -*/ - -// If bAll=0 save/load all non-volatile ram to .fs -// If bAll=1 save/load all ram to .fs - -// ------------ State len -------------------- -static INT32 nTotalLen = 0; - -static INT32 __cdecl StateLenAcb(struct BurnArea* pba) -{ - nTotalLen += pba->nLen; - - return 0; -} - -static INT32 StateInfo(int* pnLen, int* pnMinVer, INT32 bAll) -{ - INT32 nMin = 0; - nTotalLen = 0; - BurnAcb = StateLenAcb; - - BurnAreaScan(ACB_NVRAM, &nMin); // Scan nvram - if (bAll) { - INT32 m; - BurnAreaScan(ACB_MEMCARD, &m); // Scan memory card - if (m > nMin) { // Up the minimum, if needed - nMin = m; - } - BurnAreaScan(ACB_VOLATILE, &m); // Scan volatile ram - if (m > nMin) { // Up the minimum, if needed - nMin = m; - } - } - *pnLen = nTotalLen; - *pnMinVer = nMin; - - return 0; -} - -// State load -INT32 BurnStateLoadEmbed(FILE* fp, INT32 nOffset, INT32 bAll, INT32 (*pLoadGame)()) -{ - const char* szHeader = "FS1 "; // Chunk identifier - - INT32 nLen = 0; - INT32 nMin = 0, nFileVer = 0, nFileMin = 0; - INT32 t1 = 0, t2 = 0; - char ReadHeader[4]; - char szForName[33]; - INT32 nChunkSize = 0; - UINT8 *Def = NULL; - INT32 nDefLen = 0; // Deflated version - INT32 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; - } - - INT32 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) { - UINT32 nCurrentGame = nBurnDrvActive; - UINT32 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 (nCurrentGame != nBurnDrvActive) { - INT32 nOldActive = nBurnDrvActive; // Exit current game if loading a state from another game - nBurnDrvActive = nCurrentGame; - DrvExit(); - nBurnDrvActive = nOldActive; - } - 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 = (UINT8*)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 - free(Def); // free deflated block - - fseek(fp, nChunkData + nChunkSize, SEEK_SET); - - if (nRet == 0) { // Force the palette to recalculate on state load - BurnRecalcPal(); - } - - if (nRet) { - return -1; - } else { - return 0; - } -} - -// State load -INT32 BurnStateLoad(TCHAR* szName, INT32 bAll, INT32 (*pLoadGame)()) -{ - const char szHeader[] = "FB1 "; // File identifier - char szReadHeader[4] = ""; - INT32 nRet = 0; - - FILE* fp = _tfopen(szName, _T("rb")); - if (fp == NULL) { - return 1; - } - - fread(szReadHeader, 1, 4, fp); // Read identifier - if (memcmp(szReadHeader, szHeader, 4) == 0) { // Check filetype - nRet = BurnStateLoadEmbed(fp, -1, bAll, pLoadGame); - } - - fclose(fp); - - if (nRet < 0) { - return -nRet; - } else { - 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 -INT32 BurnStateSaveEmbed(FILE* fp, INT32 nOffset, INT32 bAll) -{ - const char* szHeader = "FS1 "; // Chunk identifier - - INT32 nLen = 0; - INT32 nNvMin = 0, nAMin = 0; - INT32 nZero = 0; - char szGame[33]; - UINT8 *Def = NULL; - INT32 nDefLen = 0; // Deflated version - INT32 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 - INT32 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 - free(Def); // free deflated block and close file - - 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; -} - -#ifdef BUILD_WIN32 -INT32 FileExists(const TCHAR *fileName) -{ - DWORD dwAttrib = GetFileAttributes(fileName); - return (dwAttrib != INVALID_FILE_ATTRIBUTES && - !(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)); -} -#endif - -#define MAX_STATEBACKUPS 10 -// SaveState Undo - restores the last savestate backup file. Windows-only at the moment. -INT32 BurnStateUNDO(TCHAR* szName) -{ -#ifdef BUILD_WIN32 - /* - Savestate Undo - derp.fs.backup0 -> derp.fs - derp.fs.backup1 -> derp.fs.backup0 - derp.fs.backup2 -> derpfs.backup1 - derp.fs.backup3 -> derpfs.backup2 - */ - INT32 cantundo = 0; - - for (INT32 i = 0; i <= MAX_STATEBACKUPS; i++) { - TCHAR szBackupNameTo[1024] = _T(""); - TCHAR szBackupNameFrom[1024] = _T(""); - TCHAR szBackupNamePrev[1024] = _T(""); - - if (i == 0) { - _stprintf(szBackupNameTo, _T("%s.UNDO"), szName);// game.fs -> game.fs.UNDO - _stprintf(szBackupNamePrev, _T("%s.backup0"), szName); - if (FileExists(szName) && FileExists(szBackupNamePrev)) { - DeleteFileW(szBackupNameTo); - MoveFileW(szName, szBackupNameTo); - } else { - cantundo = 1; - } - - _stprintf(szBackupNameTo, _T("%s"), szName);// game.fs - } else { - _stprintf(szBackupNameTo, _T("%s.backup%d"), szName, i - 1); //game.fs.backup0 - } - _stprintf(szBackupNameFrom, _T("%s.backup%d"), szName, i); //game.fs.backup1 - //bprintf(0, _T("%d: %s -> %s\n"), i, szBackupNameFrom, szBackupNameTo); - MoveFileW(szBackupNameFrom, szBackupNameTo); - } - return cantundo; -#else - return 0; -#endif - -} - -// State save -INT32 BurnStateSave(TCHAR* szName, INT32 bAll) -{ - const char szHeader[] = "FB1 "; // File identifier - INT32 nLen = 0, nVer = 0; - INT32 nRet = 0; - - if (bAll) { // Get amount of data - StateInfo(&nLen, &nVer, 1); - } else { - StateInfo(&nLen, &nVer, 0); - } - if (nLen <= 0) { // No data, so exit without creating a savestate - return 0; // Don't return an error code - } - -#ifdef BUILD_WIN32 - /* - Save State backups - used in conjunction with BurnStateUNDO(); - derp.fs -> derp.fs.backup - derp.fs.backup -> derp.fs.backup1 - derp.fs.backup1 -> derpfs.backup2 - derp.fs.backup3 -> derpfs.backup4 - */ - if (_tcsstr(szName, _T(" slot "))) { - for (INT32 i=MAX_STATEBACKUPS;i>=0;i--) { - TCHAR szBackupNameTo[1024] = _T(""); - TCHAR szBackupNameFrom[1024] = _T(""); - - _stprintf(szBackupNameTo, _T("%s.backup%d"), szName, i + 1); - _stprintf(szBackupNameFrom, _T("%s.backup%d"), szName, i); - if (i == MAX_STATEBACKUPS) { - DeleteFileW(szBackupNameFrom); // make sure there is only MAX_STATEBACKUPS :) - } else { - MoveFileW(szBackupNameFrom, szBackupNameTo); //derp.fs.backup0 -> derp.fs.backup1 - if (i == 0) { - MoveFileW(szName, szBackupNameFrom); //derp.fs -> derp.fs.backup0 - } - } - } - } -#endif - - FILE* fp = _tfopen(szName, _T("wb")); - if (fp == NULL) { - return 1; - } - - fwrite(&szHeader, 1, 4, fp); - nRet = BurnStateSaveEmbed(fp, -1, bAll); - - fclose(fp); - - if (nRet < 0) { - return 1; - } else { - return 0; - } -} From 4583f9af989d7b2261feabfe2691260e98c2ada4 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Tue, 7 Jun 2022 14:10:52 +0200 Subject: [PATCH 06/22] pfbn: move dummy funcs to drv.cpp --- pfbneo/sources/fbneo/drv.cpp | 14 +++++++++++++- pfbneo/sources/fbneo/paths.cpp | 7 ------- pfbneo/sources/main.cpp | 10 ---------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/pfbneo/sources/fbneo/drv.cpp b/pfbneo/sources/fbneo/drv.cpp index e37e97dc..6b2a5a8e 100644 --- a/pfbneo/sources/fbneo/drv.cpp +++ b/pfbneo/sources/fbneo/drv.cpp @@ -7,11 +7,23 @@ using namespace c2dui; extern UiMain *ui; + extern UINT8 NeoSystem; -int bDrvOkay = 0; // 1 if the Driver has been initted okay, and it's okay to use the BurnDrv functions +int bDrvOkay = 0; int kNetGame = 0; int nIpsMaxFileLen = 0; +INT32 GetIpsesMaxLen(char *) { return 0; } + +bool GetIpsDrvProtection() { return false; } + +// replaces ips_manager.cpp +bool bDoIpsPatch = false; + +void IpsApplyPatches(UINT8 *base, char *rom_name) {} + +bool bRunPause; + // burner/state.cpp bool bReplayReadOnly; INT32 nReplayStatus = 0; diff --git a/pfbneo/sources/fbneo/paths.cpp b/pfbneo/sources/fbneo/paths.cpp index cf13c536..3ae496c8 100644 --- a/pfbneo/sources/fbneo/paths.cpp +++ b/pfbneo/sources/fbneo/paths.cpp @@ -12,13 +12,6 @@ #define VERSION _a(VER_MAJOR.VER_MINOR.VER_BETA.VER_ALPHA) char szAppBurnVer[16] = VERSION; -// replaces ips_manager.cpp -bool bDoIpsPatch = false; - -void IpsApplyPatches(UINT8 *base, char *rom_name) {} - -bool bRunPause; - // windows fix #undef MAX_PATH #define MAX_PATH 512 diff --git a/pfbneo/sources/main.cpp b/pfbneo/sources/main.cpp index ac2f2ce2..fec902e0 100644 --- a/pfbneo/sources/main.cpp +++ b/pfbneo/sources/main.cpp @@ -49,16 +49,6 @@ Skin *skin; void BurnPathsInit(C2DIo *io); -INT32 GetIpsesMaxLen(char *) -{ - return 0; -} - -bool GetIpsDrvProtection() -{ - return false; -} - int main(int argc, char **argv) { #ifdef __PSP2__ // set max cpu speed From f20172555ecc2e87572179a1508b25c55c6651d2 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Wed, 8 Jun 2022 13:12:29 +0200 Subject: [PATCH 07/22] pfbn: minor cleanup --- pfbneo/sources/uiEmu.cpp | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/pfbneo/sources/uiEmu.cpp b/pfbneo/sources/uiEmu.cpp index d01e2aed..017ce9a6 100644 --- a/pfbneo/sources/uiEmu.cpp +++ b/pfbneo/sources/uiEmu.cpp @@ -276,42 +276,6 @@ bool PFBAUiEmu::onInput(c2d::Input::Player *players) { } } -#if 0 - int rotation_config = - getUi()->getConfig()->get(Option::Index::ROM_ROTATION, true)->getValueBool(); - int rotate_input = 0; -#ifdef __PSP2__ - // TODO: find a way to unify platforms, - // or allow rotation config from main.cpp - if (BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) { - if (rotation_config == 0) { - //rotate controls by 90 degrees - rotate_input = 1; - } else if (rotation_config == 2) { - //rotate controls by 270 degrees - rotate_input = 3; - } - } -#elif __SWITCH__ - if (BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) { - if (rotation_config == 0) { // OFF - //rotate controls by 270 degrees - rotate_input = 3; - } else if (rotation_config == 1) { // ON - //rotate controls by 270 degrees - rotate_input = 0; - } else if (rotation_config == 2) { // FLIP - //rotate controls by 270 degrees - rotate_input = 1; - } - } -#else - if (BurnDrvGetFlags() & BDF_ORIENTATION_VERTICAL) { - rotate_input = rotation_config ? 0 : 3; - } -#endif -#endif - return UiEmu::onInput(players); } From 5a32cef8fc53f531ad43322b7bdd1c881f6cf318 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Wed, 8 Jun 2022 13:17:09 +0200 Subject: [PATCH 08/22] pfbn: fix memory leak on stop --- pfbneo/sources/uiEmu.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pfbneo/sources/uiEmu.cpp b/pfbneo/sources/uiEmu.cpp index 017ce9a6..bb7095d8 100644 --- a/pfbneo/sources/uiEmu.cpp +++ b/pfbneo/sources/uiEmu.cpp @@ -249,6 +249,9 @@ void Reinitialise(void) { void PFBAUiEmu::stop() { DrvExit(); + if (pBurnSoundOut) { + free(pBurnSoundOut); + } UiEmu::stop(); } From 1bba5e050b31f587ec6e7b1f2878219acbd36847 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Thu, 9 Jun 2022 09:37:16 +0200 Subject: [PATCH 09/22] pfbn: minor cleanup --- pfbneo/sources/fbneo/drv.cpp | 27 +++++++++++---------------- pfbneo/sources/uiEmu.cpp | 3 +-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/pfbneo/sources/fbneo/drv.cpp b/pfbneo/sources/fbneo/drv.cpp index 6b2a5a8e..471d37bd 100644 --- a/pfbneo/sources/fbneo/drv.cpp +++ b/pfbneo/sources/fbneo/drv.cpp @@ -64,8 +64,7 @@ static UINT8 NeoSystemList[] = { 0x11, // "Development Kit" }; -static int DoLibInit() // Do Init of Burn library driver -{ +static int DoLibInit() { int nRet; ProgressCreate(); @@ -95,18 +94,15 @@ static int DoLibInit() // Do Init of Burn library driver // 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); - char szText[256] = ""; - sprintf(szText, - "Error loading %s for %s.\nEmulation will likely have problems.", + sprintf(szText, "Error loading %s for %s.\nEmulation will likely have problems.", pszFilename, BurnDrvGetTextA(DRV_NAME)); printf("DrvLoadRom: %s\n", szText); ui->getUiMessageBox()->show("ERROR", szText, "OK"); @@ -120,7 +116,6 @@ static int DrvLoadRom(unsigned char *Dest, int *pnWrote, int i) { } int DrvInit(int nDrvNum, bool bRestore) { - printf("DrvInit(%i, %i)\n", nDrvNum, bRestore); DrvExit(); @@ -148,16 +143,17 @@ int DrvInit(int nDrvNum, bool bRestore) { char path[1024]; snprintf(path, 1023, "%s%s.fs", szAppEEPROMPath, BurnDrvGetTextA(DRV_NAME)); - BurnStateLoad(path, 0, NULL); + BurnStateLoad(path, 0, nullptr); - bDrvOkay = 1; // Okay to use all BurnDrv functions - nBurnLayer = 0xFF; // show all layers + bDrvOkay = 1; + nBurnLayer = 0xff; + nSpriteEnable = 0xff; return 0; } int DrvInitCallback() { - return DrvInit(nBurnDrvSelect[0], false); + return DrvInit((int) nBurnDrvSelect[0], false); } int DrvExit() { @@ -167,13 +163,13 @@ int DrvExit() { snprintf(path, 1023, "%s%s.fs", szAppEEPROMPath, BurnDrvGetTextA(DRV_NAME)); BurnStateSave(path, 0); InputExit(); - BurnDrvExit(); // Exit the driver + BurnDrvExit(); } } BurnExtLoadRom = nullptr; - bDrvOkay = 0; // Stop using the BurnDrv functions - nBurnDrvSelect[0] = ~0U; // no driver selected + bDrvOkay = 0; + nBurnDrvSelect[0] = ~0U; return 0; } @@ -188,7 +184,6 @@ static int ProgressCreate() { } int ProgressUpdateBurner(double dProgress, const TCHAR *pszText, bool bAbs) { - ui->getUiProgressBox()->setTitle(BurnDrvGetTextA(DRV_FULLNAME)); if (pszText) { diff --git a/pfbneo/sources/uiEmu.cpp b/pfbneo/sources/uiEmu.cpp index bb7095d8..e4826eee 100644 --- a/pfbneo/sources/uiEmu.cpp +++ b/pfbneo/sources/uiEmu.cpp @@ -108,7 +108,6 @@ int PFBAUiEmu::getSekCpuCore() { #endif int PFBAUiEmu::load(const ss_api::Game &game) { - currentGame = game; std::string zipName = Utility::removeExt(game.path); @@ -221,7 +220,7 @@ int PFBAUiEmu::load(const ss_api::Game &game) { BurnHighCol = myHighCol16; BurnRecalcPal(); // video may already be initialized from fbneo driver (Reinitialise) - if (!getVideo()) { + if (!video) { auto v = new PFBAVideo(ui, &pBurnDraw, &nBurnPitch, size, aspect); addVideo(v); printf("PFBAUiEmu::load: size: %i x %i, aspect: %i x %i, pitch: %i\n", From 23c0c90b6399b747428733480e79e15b1a149f89 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Thu, 9 Jun 2022 12:59:33 +0200 Subject: [PATCH 10/22] common: fix adding favorites in some cases --- sscrap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sscrap b/sscrap index a67d45b6..2e96382c 160000 --- a/sscrap +++ b/sscrap @@ -1 +1 @@ -Subproject commit a67d45b695ce6b545949fd88e9ba5ae21e48cc00 +Subproject commit 2e96382ca9861330e5af20b1a4a9dc45c1b2fa48 From 9522b703af2600e77e0f8bf11274ebb5be1e2535 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Thu, 9 Jun 2022 13:59:03 +0200 Subject: [PATCH 11/22] pfbn: fix default dip switch values (fix red hearth, some megadrive games, ...) --- pfbneo/sources/fbneo/drv.cpp | 1 + pfbneo/sources/fbneo/retro_input_wrapper.cpp | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pfbneo/sources/fbneo/drv.cpp b/pfbneo/sources/fbneo/drv.cpp index 471d37bd..32611f8d 100644 --- a/pfbneo/sources/fbneo/drv.cpp +++ b/pfbneo/sources/fbneo/drv.cpp @@ -152,6 +152,7 @@ int DrvInit(int nDrvNum, bool bRestore) { return 0; } +// for uiStateMenu.cpp (BurnStateLoad) int DrvInitCallback() { return DrvInit((int) nBurnDrvSelect[0], false); } diff --git a/pfbneo/sources/fbneo/retro_input_wrapper.cpp b/pfbneo/sources/fbneo/retro_input_wrapper.cpp index 38e63800..bd2753da 100644 --- a/pfbneo/sources/fbneo/retro_input_wrapper.cpp +++ b/pfbneo/sources/fbneo/retro_input_wrapper.cpp @@ -32,8 +32,8 @@ int16_t input_cb(unsigned port, unsigned device, unsigned index, unsigned id) { void poll_cb() {} -static void InpDIPSWGetOffset(void) { - BurnDIPInfo bdi; +static void InpDIPSWGetOffset() { + BurnDIPInfo bdi{}; nDIPOffset = 0; for (int i = 0; BurnDrvGetDIPInfo(&bdi, i) == 0; i++) { @@ -45,18 +45,23 @@ static void InpDIPSWGetOffset(void) { } } -void InpDIPSWResetDIPs(void) { +void InpDIPSWResetDIPs() { int i = 0; - BurnDIPInfo bdi; - struct GameInp *pgi = NULL; + BurnDIPInfo bdi{}; + struct GameInp *pgi; InpDIPSWGetOffset(); while (BurnDrvGetDIPInfo(&bdi, i) == 0) { if (bdi.nFlags == 0xFF) { pgi = GameInp + bdi.nInput + nDIPOffset; - if (pgi) - pgi->Input.Constant.nConst = (pgi->Input.Constant.nConst & ~bdi.nMask) | (bdi.nSetting & bdi.nMask); + if (pgi) { + pgi->Input.Constant.nConst = pgi->Input.nVal = + (pgi->Input.Constant.nConst & ~bdi.nMask) | (bdi.nSetting & bdi.nMask); + if (pgi->Input.pVal) { + *(pgi->Input.pVal) = pgi->Input.nVal; + } + } } i++; } From 41efc02951b66d4ef37e2a8e47693189048d1710 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Fri, 10 Jun 2022 07:56:08 +0200 Subject: [PATCH 12/22] common: revert roms paths to default if not available --- ui/c2dui_config.cpp | 16 ++++++++++------ ui/c2dui_config.h | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ui/c2dui_config.cpp b/ui/c2dui_config.cpp index 3b590451..6c482f16 100644 --- a/ui/c2dui_config.cpp +++ b/ui/c2dui_config.cpp @@ -5,7 +5,7 @@ #include "c2dui.h" Config::Config(c2d::Io *io, int ver, const std::string &defaultRomsPath) { - + m_io = io; dataPath = io->getDataPath(); configPath = dataPath + "config.cfg"; version = ver; @@ -179,15 +179,19 @@ void Config::load(const ss_api::Game &game) { if (!isRomCfg) { settings = config_setting_lookup(settings_root, "ROMS_PATHS"); if (settings != nullptr) { + char p[MAX_PATH]; for (size_t i = 0; i < roms_paths.size(); i++) { - char p[MAX_PATH]; + memset(p, 0, MAX_PATH); snprintf(p, MAX_PATH, "ROMS_PATH%i", (int) i); const char *value = nullptr; if (config_setting_lookup_string(settings, p, &value) != 0) { - roms_paths[i] = value; - if (!roms_paths[i].empty() && roms_paths[i].back() != '/') - roms_paths[i] += '/'; - printf("%s: %s\n", p, value); + if (m_io->exist(value)) { + roms_paths[i] = value; + if (!roms_paths[i].empty() && roms_paths[i].back() != '/') { + roms_paths[i] += '/'; + } + } + printf("%s: %s\n", p, roms_paths[i].c_str()); } } } diff --git a/ui/c2dui_config.h b/ui/c2dui_config.h index defcbf5d..1ab38e01 100644 --- a/ui/c2dui_config.h +++ b/ui/c2dui_config.h @@ -76,6 +76,7 @@ namespace c2dui { std::vector roms_paths; private: + c2d::Io *m_io; std::vector