From e2f3a64143ae84b436b9211c12700c06f6410da4 Mon Sep 17 00:00:00 2001 From: negativeExponent Date: Fri, 7 Oct 2022 15:28:31 +0800 Subject: [PATCH] Cleanup more libretro-specific branches --- src/Util.cpp | 2 -- src/gb/GB.cpp | 38 ++++++++------------------ src/gb/gbCheats.cpp | 2 +- src/gb/gbSound.cpp | 43 +++++++++++++++++------------ src/gba/GBA.cpp | 19 +++++++------ src/gba/Sound.cpp | 53 ++++++++++++++++++++++-------------- src/libretro/Makefile.common | 1 + 7 files changed, 83 insertions(+), 75 deletions(-) diff --git a/src/Util.cpp b/src/Util.cpp index 72f787b5..a1cb5fa8 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -175,7 +175,6 @@ void utilReadScreenPixels(uint8_t *dest, int w, int h) } } -#ifndef __LIBRETRO__ bool utilWritePNGFile(const char *fileName, int w, int h, uint8_t *pix) { #ifndef NO_PNG @@ -298,7 +297,6 @@ bool utilWritePNGFile(const char *fileName, int w, int h, uint8_t *pix) return false; #endif } -#endif /* !__LIBRETRO__ */ void utilPutDword(uint8_t *p, uint32_t value) { diff --git a/src/gb/GB.cpp b/src/gb/GB.cpp index 22290897..61750e7c 100644 --- a/src/gb/GB.cpp +++ b/src/gb/GB.cpp @@ -5800,27 +5800,7 @@ bool gbReadSaveState(const uint8_t* data) return true; } - -bool gbWriteMemSaveState(char*, int, long&) -{ - return false; -} - -bool gbReadMemSaveState(char*, int) -{ - return false; -} - -bool gbReadBatteryFile(const char*) -{ - return false; -} - -bool gbWriteBatteryFile(const char*) -{ - return false; -} -#endif +#endif /* __LIBRETRO__ */ struct EmulatedSystem GBSystem = { // emuMain @@ -5829,6 +5809,16 @@ struct EmulatedSystem GBSystem = { gbReset, // emuCleanUp gbCleanUp, +#ifdef __LIBRETRO__ + NULL, // emuReadBattery + NULL, // emuWriteBattery + gbReadSaveState, // emuReadState + gbWriteSaveState, // emuWriteState + NULL, // emuReadMemState + NULL, // emuWriteMemState + NULL, // emuWritePNG + NULL, // emuWriteBMP +#else // emuReadBattery gbReadBatteryFile, // emuWriteBattery @@ -5841,15 +5831,11 @@ struct EmulatedSystem GBSystem = { gbReadMemSaveState, // emuWriteMemState gbWriteMemSaveState, -#ifdef __LIBRETRO__ - NULL, // emuWritePNG - NULL, // emuWriteBMP -#else // emuWritePNG gbWritePNGFile, // emuWriteBMP gbWriteBMPFile, -#endif +#endif /* ! __LIBRETRO__ */ // emuUpdateCPSR NULL, // emuHasDebugger diff --git a/src/gb/gbCheats.cpp b/src/gb/gbCheats.cpp index e75039af..7a4c26a4 100644 --- a/src/gb/gbCheats.cpp +++ b/src/gb/gbCheats.cpp @@ -99,7 +99,7 @@ void gbCheatsReadGameSkip(gzFile gzFile, int version) } } } -#endif +#endif /* __LIBRETRO__ */ void gbCheatsSaveCheatList(const char* file) { diff --git a/src/gb/gbSound.cpp b/src/gb/gbSound.cpp index d2ff1bc0..05209978 100644 --- a/src/gb/gbSound.cpp +++ b/src/gb/gbSound.cpp @@ -393,7 +393,7 @@ static void gbSoundReadGameOld(int version, gzFile gzFile) memcpy(&s.regs[0x20], &gbMemory[0xFF30], 0x10); // wave } -#endif +#endif // ! __LIBRETRO__ // New state format static variable_desc gb_state[] = { @@ -429,11 +429,8 @@ static variable_desc gb_state[] = { { NULL, 0 } }; -#ifdef __LIBRETRO__ -void gbSoundSaveGame(uint8_t*& out) -#else +#ifndef __LIBRETRO__ void gbSoundSaveGame(gzFile out) -#endif { gb_apu->save_state(&state.apu); @@ -441,31 +438,43 @@ void gbSoundSaveGame(gzFile out) memset(dummy_state, 0, sizeof dummy_state); state.version = 1; -#ifdef __LIBRETRO__ - utilWriteDataMem(out, gb_state); -#else utilWriteData(out, gb_state); -#endif } -#ifdef __LIBRETRO__ -void gbSoundReadGame(const uint8_t*& in) -#else void gbSoundReadGame(int version, gzFile in) -#endif { // Prepare APU and default state reset_apu(); gb_apu->save_state(&state.apu); -#ifdef __LIBRETRO__ - utilReadDataMem(in, gb_state); -#else if (version > 11) utilReadData(in, gb_state); else gbSoundReadGameOld(version, in); -#endif gb_apu->load_state(state.apu); } +#endif // ! __LIBRETRO__ + +#ifdef __LIBRETRO__ +void gbSoundSaveGame(uint8_t*& out) +{ + gb_apu->save_state(&state.apu); + + // Be sure areas for expansion get written as zero + memset(dummy_state, 0, sizeof dummy_state); + + state.version = 1; + utilWriteDataMem(out, gb_state); +} + +void gbSoundReadGame(const uint8_t*& in) +{ + // Prepare APU and default state + reset_apu(); + gb_apu->save_state(&state.apu); + + utilReadDataMem(in, gb_state); + gb_apu->load_state(state.apu); +} +#endif // __LIBRETRO__ diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index 116b09e8..a5e467c3 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -4247,6 +4247,16 @@ struct EmulatedSystem GBASystem = { CPUReset, // emuCleanUp CPUCleanUp, +#ifdef __LIBRETRO__ + NULL, // emuReadBattery + NULL, // emuReadState + CPUReadState, // emuReadState + CPUWriteState, // emuWriteState + NULL, // emuReadMemState + NULL, // emuWriteMemState + NULL, // emuWritePNG + NULL, // emuWriteBMP +#else // emuReadBattery CPUReadBatteryFile, // emuWriteBattery @@ -4255,19 +4265,10 @@ struct EmulatedSystem GBASystem = { CPUReadState, // emuWriteState CPUWriteState, -#ifdef __LIBRETRO__ - NULL, // emuReadMemState - NULL, // emuWriteMemState -#else // emuReadMemState CPUReadMemState, // emuWriteMemState CPUWriteMemState, -#endif -#ifdef __LIBRETRO__ - NULL, // emuWritePNG - NULL, // emuWriteBMP -#else // emuWritePNG CPUWritePNGFile, // emuWriteBMP diff --git a/src/gba/Sound.cpp b/src/gba/Sound.cpp index 152d0681..ba714e4a 100644 --- a/src/gba/Sound.cpp +++ b/src/gba/Sound.cpp @@ -337,13 +337,16 @@ static void end_frame(blip_time_t time) stereo_buffer->end_frame(time); } +#ifdef __LIBRETRO__ void flush_samples(Multi_Buffer* buffer) { -#ifdef __LIBRETRO__ int numSamples = buffer->read_samples((blip_sample_t*)soundFinalWave, buffer->samples_avail()); soundDriver->write(soundFinalWave, numSamples); systemOnWriteDataToSoundBuffer(soundFinalWave, numSamples); +} #else +void flush_samples(Multi_Buffer* buffer) +{ // We want to write the data frame by frame to support legacy audio drivers // that don't use the length parameter of the write method. // TODO: Update the Win32 audio drivers (DS, OAL, XA2), and flush all the @@ -365,8 +368,8 @@ void flush_samples(Multi_Buffer* buffer) soundDriver->write(soundFinalWave, soundBufferLen); systemOnWriteDataToSoundBuffer(soundFinalWave, soundBufferLen); } -#endif } +#endif // ! __LIBRETRO__ static void apply_filtering() { @@ -726,25 +729,17 @@ static variable_desc gba_state[] = { { NULL, 0 } }; -#ifdef __LIBRETRO__ -void soundSaveGame(uint8_t*& out) -#else +#ifndef __LIBRETRO__ void soundSaveGame(gzFile out) -#endif { gb_apu->save_state(&state.apu); // Be sure areas for expansion get written as zero memset(dummy_state, 0, sizeof dummy_state); -#ifdef __LIBRETRO__ - utilWriteDataMem(out, gba_state); -#else utilWriteData(out, gba_state); -#endif } -#ifndef __LIBRETRO__ // Reads and discards count bytes from in static void skip_read(gzFile in, int count) { @@ -794,31 +789,49 @@ static void soundReadGameOld(gzFile in, int version) (void)utilReadInt(in); // ignore quality } -#endif #include -#ifdef __LIBRETRO__ -void soundReadGame(const uint8_t*& in) -#else void soundReadGame(gzFile in, int version) -#endif { // Prepare APU and default state reset_apu(); gb_apu->save_state(&state.apu); -#ifdef __LIBRETRO__ - utilReadDataMem(in, gba_state); -#else if (version > SAVE_GAME_VERSION_9) utilReadData(in, gba_state); else soundReadGameOld(in, version); -#endif gb_apu->load_state(state.apu); write_SGCNT0_H(READ16LE(&ioMem[SGCNT0_H]) & 0x770F); apply_muting(); } +#endif // !__LIBRETRO__ + +#ifdef __LIBRETRO__ +void soundSaveGame(uint8_t*& out) +{ + gb_apu->save_state(&state.apu); + + // Be sure areas for expansion get written as zero + memset(dummy_state, 0, sizeof dummy_state); + + utilWriteDataMem(out, gba_state); +} + +void soundReadGame(const uint8_t*& in) +{ + // Prepare APU and default state + reset_apu(); + gb_apu->save_state(&state.apu); + + utilReadDataMem(in, gba_state); + + gb_apu->load_state(state.apu); + write_SGCNT0_H(READ16LE(&ioMem[SGCNT0_H]) & 0x770F); + + apply_muting(); +} +#endif // __LIBRETRO__ diff --git a/src/libretro/Makefile.common b/src/libretro/Makefile.common index c91060c8..09b25da6 100644 --- a/src/libretro/Makefile.common +++ b/src/libretro/Makefile.common @@ -1,6 +1,7 @@ LIBRETRO_COMMON := $(CORE_DIR)/libretro/libretro-common INCFLAGS := -I$(CORE_DIR) -I$(LIBRETRO_COMMON)/include VBA_DEFINES := -D__LIBRETRO__ -DFINAL_VERSION -DC_CORE -DNO_DEBUGGER +VBA_DEFINES += -DNO_PNG ifeq ($(TILED_RENDERING), 1) VBA_DEFINES += -DTILED_RENDERING