From 94d076760d9c63a8be75cac901ac877cc47258bb Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 15:00:47 +0800 Subject: [PATCH 1/8] Makefile: Remove sources we dont need --- src/libretro/Makefile.common | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/libretro/Makefile.common b/src/libretro/Makefile.common index 7cd277d2..b6de3201 100644 --- a/src/libretro/Makefile.common +++ b/src/libretro/Makefile.common @@ -10,15 +10,10 @@ SOURCES_CXX := $(CORE_DIR)/gba/GBA-thumb.cpp \ $(CORE_DIR)/gba/Mode4.cpp \ $(CORE_DIR)/gba/Mode3.cpp \ $(CORE_DIR)/gba/Mode5.cpp \ - $(CORE_DIR)/gba/GBALink.cpp \ $(CORE_DIR)/gba/Mode2.cpp \ - $(CORE_DIR)/gba/GBASockClient.cpp \ - $(CORE_DIR)/gba/elf.cpp \ $(CORE_DIR)/gba/ereader.cpp \ $(CORE_DIR)/gba/GBA-arm.cpp \ $(CORE_DIR)/gba/bios.cpp \ - $(CORE_DIR)/gba/gbafilter.cpp \ - $(CORE_DIR)/gba/remote.cpp \ $(CORE_DIR)/gba/Mode0.cpp \ $(CORE_DIR)/gba/Flash.cpp \ $(CORE_DIR)/gba/GBAGfx.cpp \ @@ -27,13 +22,11 @@ SOURCES_CXX := $(CORE_DIR)/gba/GBA-thumb.cpp \ $(CORE_DIR)/gba/EEprom.cpp \ $(CORE_DIR)/gba/RTC.cpp \ $(CORE_DIR)/gba/Sram.cpp \ - $(CORE_DIR)/apu/Effects_Buffer.cpp \ $(CORE_DIR)/apu/Gb_Oscs.cpp \ $(CORE_DIR)/apu/Gb_Apu_State.cpp \ $(CORE_DIR)/apu/Blip_Buffer.cpp \ $(CORE_DIR)/apu/Multi_Buffer.cpp \ $(CORE_DIR)/apu/Gb_Apu.cpp \ - $(CORE_DIR)/common/Patch.cpp \ $(CORE_DIR)/libretro/libretro.cpp \ $(CORE_DIR)/libretro/UtilRetro.cpp \ $(CORE_DIR)/libretro/SoundRetro.cpp \ From e0fe8365161a227d179e15796b8316131e560634 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 15:02:27 +0800 Subject: [PATCH 2/8] Makefile: Add option for sanitizer, add -DNO_DEBUGGER --- src/libretro/Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libretro/Makefile b/src/libretro/Makefile index 1adeea1d..a87bf87d 100644 --- a/src/libretro/Makefile +++ b/src/libretro/Makefile @@ -225,9 +225,14 @@ include Makefile.common OBJS := $(SOURCES_CXX:.cpp=.o) -VBA_DEFINES += -D__LIBRETRO__ -DFINAL_VERSION -DC_CORE -DUSE_GBA_ONLY -DNO_LINK +VBA_DEFINES += -D__LIBRETRO__ -DFINAL_VERSION -DC_CORE -DNO_LINK -DNO_DEBUGGER VBA_DEFINES += -DFRONTEND_SUPPORTS_RGB565 +ifneq ($(SANITIZER),) + CFLAGS += -fsanitize=$(SANITIZER) + LDFLAGS += -fsanitize=$(SANITIZER) +endif + ifeq ($(DEBUG), 1) CFLAGS += -g CXXFLAGS += -g From 710d2f3ebf46bc3531cd72c38511f2ce1119425d Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 15:08:04 +0800 Subject: [PATCH 3/8] UtilRetro: Remove LCD filter --- src/libretro/UtilRetro.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libretro/UtilRetro.cpp b/src/libretro/UtilRetro.cpp index 808e0b7c..5aea65d9 100644 --- a/src/libretro/UtilRetro.cpp +++ b/src/libretro/UtilRetro.cpp @@ -238,16 +238,12 @@ void utilUpdateSystemColorMaps(bool lcd) for (int i = 0; i < 0x10000; i++) { systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); } - if (lcd) - gbafilter_pal(systemColorMap16, 0x10000); } break; case 24: case 32: { for (int i = 0; i < 0x10000; i++) { systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); } - if (lcd) - gbafilter_pal32(systemColorMap32, 0x10000); } break; } } From 76389d8e942f490cc3aa4f1db854b1f630c75786 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 15:17:12 +0800 Subject: [PATCH 4/8] RTC: Change this #ifdef to GBA_LOGGING --- src/gba/RTC.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gba/RTC.cpp b/src/gba/RTC.cpp index 6060ae55..768bc9fc 100644 --- a/src/gba/RTC.cpp +++ b/src/gba/RTC.cpp @@ -243,7 +243,7 @@ bool rtcWrite(uint32_t address, uint16_t value) } break; default: -#ifndef __LIBRETRO__ +#ifdef GBA_LOGGING log(N_("Unknown RTC command %02x"), rtcClockData.command); #endif rtcClockData.state = IDLE; From f4b88ba63aa1f479a529dd16aebb53518430ecda Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 15:53:20 +0800 Subject: [PATCH 5/8] Libretro: Remove GBA LCD filter Libretro use shaders for filters etc. --- src/libretro/UtilRetro.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libretro/UtilRetro.cpp b/src/libretro/UtilRetro.cpp index 5aea65d9..808e0b7c 100644 --- a/src/libretro/UtilRetro.cpp +++ b/src/libretro/UtilRetro.cpp @@ -238,12 +238,16 @@ void utilUpdateSystemColorMaps(bool lcd) for (int i = 0; i < 0x10000; i++) { systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); } + if (lcd) + gbafilter_pal(systemColorMap16, 0x10000); } break; case 24: case 32: { for (int i = 0; i < 0x10000; i++) { systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); } + if (lcd) + gbafilter_pal32(systemColorMap32, 0x10000); } break; } } From 90bc79f299e5a96a1c05c7cc50f93a7ab12b3193 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 15:55:26 +0800 Subject: [PATCH 6/8] Libretro: implement vbam logging using libretro logging api --- src/libretro/libretro.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libretro/libretro.cpp b/src/libretro/libretro.cpp index 6aeffc44..11b38fad 100644 --- a/src/libretro/libretro.cpp +++ b/src/libretro/libretro.cpp @@ -1042,3 +1042,15 @@ SoundDriver* systemSoundInit() soundShutdown(); return new SoundRetro(); } + +void log(const char* defaultMsg, ...) +{ + va_list valist; + char buf[2048]; + va_start(valist, defaultMsg); + vsnprintf(buf, 2048, defaultMsg, valist); + va_end(valist); + + if (log_cb) + log_cb(RETRO_LOG_INFO, "%s", buf); +} From 009c09ef4a64254c1d5a65945f96c19c47e06e5e Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 15:59:53 +0800 Subject: [PATCH 7/8] GBA: Show log when rom uses SRAM of FLASH save types Log should only show once during the first write to SRAM or FLASH address using flashSaveDecide() --- src/gba/Flash.cpp | 21 ++++++++++++++------- src/gba/GBA.h | 5 +++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/gba/Flash.cpp b/src/gba/Flash.cpp index 259e55c5..72e0c8c7 100644 --- a/src/gba/Flash.cpp +++ b/src/gba/Flash.cpp @@ -164,13 +164,20 @@ void flashSaveDecide(uint32_t address, uint8_t byte) if (saveType == 1) return; - // log("Deciding save type %08x\n", address); - if (address == 0x0e005555) { - saveType = 3; - cpuSaveGameFunc = flashWrite; - } else { - saveType = 2; - cpuSaveGameFunc = sramWrite; + if (cpuSramEnabled && cpuFlashEnabled) { + // log("Deciding save type %08x\n", address); + if (address == 0x0e005555) { + saveType = 3; + cpuSramEnabled = false; + cpuSaveGameFunc = flashWrite; + } else { + saveType = 2; + cpuFlashEnabled = false; + cpuSaveGameFunc = sramWrite; + } + + log("%s emulation is enabled by writing to: $%08x : %02x\n", + cpuSramEnabled ? "SRAM" : "FLASH", address, byte); } (*cpuSaveGameFunc)(address, byte); diff --git a/src/gba/GBA.h b/src/gba/GBA.h index 61adcdc1..c07bff02 100644 --- a/src/gba/GBA.h +++ b/src/gba/GBA.h @@ -67,6 +67,11 @@ extern uint8_t biosProtected[4]; extern void (*cpuSaveGameFunc)(uint32_t, uint8_t); +extern bool cpuSramEnabled; +extern bool cpuFlashEnabled; +extern bool cpuEEPROMEnabled; +extern bool cpuEEPROMSensorEnabled; + #ifdef BKPT_SUPPORT extern uint8_t freezeWorkRAM[0x40000]; extern uint8_t freezeInternalRAM[0x8000]; From 9c859917730af730701bd783a7393b605e6ccb98 Mon Sep 17 00:00:00 2001 From: retro-wertz Date: Sat, 16 Jun 2018 16:47:44 +0800 Subject: [PATCH 8/8] Opps --- src/libretro/UtilRetro.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libretro/UtilRetro.cpp b/src/libretro/UtilRetro.cpp index 808e0b7c..5aea65d9 100644 --- a/src/libretro/UtilRetro.cpp +++ b/src/libretro/UtilRetro.cpp @@ -238,16 +238,12 @@ void utilUpdateSystemColorMaps(bool lcd) for (int i = 0; i < 0x10000; i++) { systemColorMap16[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); } - if (lcd) - gbafilter_pal(systemColorMap16, 0x10000); } break; case 24: case 32: { for (int i = 0; i < 0x10000; i++) { systemColorMap32[i] = ((i & 0x1f) << systemRedShift) | (((i & 0x3e0) >> 5) << systemGreenShift) | (((i & 0x7c00) >> 10) << systemBlueShift); } - if (lcd) - gbafilter_pal32(systemColorMap32, 0x10000); } break; } }