From de060d66ab1afd319b6290d58f0c58659db55043 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 20 Jul 2021 19:21:11 +0200 Subject: [PATCH] don't save flash if no game started. libretro: fix notifications compilation warnings, non-functional changes --- CMakeLists.txt | 2 +- core/cfg/cl.cpp | 4 +- core/emulator.cpp | 7 ++-- core/emulator.h | 2 +- core/hw/arm7/arm7_rec_arm64.cpp | 4 +- core/hw/flashrom/flashrom.h | 2 + core/hw/maple/maple_jvs.cpp | 5 ++- core/hw/naomi/naomi_cart.cpp | 14 +++---- core/hw/naomi/naomi_cart.h | 4 +- core/hw/sh4/dyna/decoder.cpp | 6 --- core/hw/sh4/dyna/decoder.h | 6 +++ core/hw/sh4/interpr/sh4_opcodes.cpp | 8 ---- core/hw/sh4/modules/mmu.cpp | 2 +- core/hw/sh4/sh4_mem.cpp | 2 + core/hw/sh4/sh4_opcode_list.cpp | 11 +---- core/imgread/common.h | 3 +- core/imgread/cue.cpp | 3 +- core/imgread/gdi.cpp | 3 +- core/input/gamepad_device.cpp | 4 +- core/linux-dist/main.cpp | 2 +- core/linux/common.cpp | 2 +- core/linux/libnx_vmem.cpp | 28 ++++++++----- core/nullDC.cpp | 2 +- core/rec-ARM64/rec_arm64.cpp | 10 +++-- core/reios/reios.cpp | 4 +- core/rend/gl4/gl4.h | 27 +------------ core/rend/gl4/gles.cpp | 27 +++++++++++++ core/rend/gles/gles.cpp | 38 ++++++++++++++++++ core/rend/gles/gles.h | 40 ++----------------- core/rend/gui.cpp | 9 ++--- core/rend/vulkan/vk_context_lr.h | 2 +- core/types.h | 6 +-- core/windows/winmain.cpp | 2 +- .../flycast/src/main/jni/src/Android.cpp | 2 +- .../emulator-osx/emulator-osx/osx-main.mm | 2 +- shell/libretro/libretro.cpp | 18 +++++++-- 36 files changed, 164 insertions(+), 149 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 13374092e..4e3e53bab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,7 +110,7 @@ set_target_properties(${PROJECT_NAME} PROPERTIES if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(${PROJECT_NAME} PRIVATE $<$:-fno-rtti> - -fno-strict-aliasing) + -fno-strict-aliasing -Wall) elseif(MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /GR- /GS-) endif() diff --git a/core/cfg/cl.cpp b/core/cfg/cl.cpp index 7f2bd0507..64f4533c9 100644 --- a/core/cfg/cl.cpp +++ b/core/cfg/cl.cpp @@ -81,9 +81,9 @@ int setconfig(char** arg,int cl) const char* constval = value; if (constval==0) constval=""; - INFO_LOG(COMMON, "Virtual cfg %s:%s=%s", sect, key, value); + INFO_LOG(COMMON, "Virtual cfg %s:%s=%s", sect, key, constval); - cfgSetVirtual(sect,key,value); + cfgSetVirtual(sect, key, constval); rv++; if (cl>=3 && stricmp(arg[2],",")==0) diff --git a/core/emulator.cpp b/core/emulator.cpp index 7c9fa8149..d0561a62d 100644 --- a/core/emulator.cpp +++ b/core/emulator.cpp @@ -455,7 +455,7 @@ void dc_start_game(const char *path) { // Boot BIOS if (!LoadRomFiles()) - throw ReicastException("No BIOS file found in " + get_writable_data_path("")); + throw FlycastException("No BIOS file found in " + get_writable_data_path("")); TermDrive(); InitDrive(); } @@ -478,7 +478,7 @@ void dc_start_game(const char *path) // Content load failed. Boot the BIOS settings.imgread.ImagePath[0] = '\0'; if (!LoadRomFiles()) - throw ReicastException("This media cannot be loaded"); + throw FlycastException("This media cannot be loaded"); InitDrive(); } } @@ -598,7 +598,8 @@ void dc_stop() sh4_cpu.Stop(); rend_cancel_emu_wait(); emuThread.WaitToEnd(); - SaveRomFiles(); + if (settings.gameStarted) + SaveRomFiles(); if (running) EventManager::event(Event::Pause); } diff --git a/core/emulator.h b/core/emulator.h index c51d87bbd..4e2be7c72 100644 --- a/core/emulator.h +++ b/core/emulator.h @@ -28,7 +28,7 @@ void SaveSettings(); extern std::atomic loading_canceled; -int reicast_init(int argc, char* argv[]); +int flycast_init(int argc, char* argv[]); void dc_reset(bool hard); void dc_init(); void* dc_run(void*); diff --git a/core/hw/arm7/arm7_rec_arm64.cpp b/core/hw/arm7/arm7_rec_arm64.cpp index eea86b2db..cf722d506 100644 --- a/core/hw/arm7/arm7_rec_arm64.cpp +++ b/core/hw/arm7/arm7_rec_arm64.cpp @@ -557,7 +557,7 @@ public: set_flags = op.flags & ArmOp::OP_SETS_FLAGS; logical_op_set_flags = op.isLogicalOp() && set_flags; set_carry_bit = false; - bool save_v_flag = true; // FIXME is this needed? + //bool save_v_flag = true; // FIXME is this needed? Label *condLabel = nullptr; @@ -600,7 +600,7 @@ public: B(&arm_dispatch_label); FinalizeCode(); - verify(GetBuffer()->GetCursorOffset() <= GetBuffer()->GetCapacity()); + verify((size_t)GetBuffer()->GetCursorOffset() <= GetBuffer()->GetCapacity()); vmem_platform_flush_cache( recompiler::writeToExec(GetBuffer()->GetStartAddress()), recompiler::writeToExec(GetBuffer()->GetEndAddress()), GetBuffer()->GetStartAddress(), GetBuffer()->GetEndAddress()); diff --git a/core/hw/flashrom/flashrom.h b/core/hw/flashrom/flashrom.h index 0d2a98f7f..f36a87623 100644 --- a/core/hw/flashrom/flashrom.h +++ b/core/hw/flashrom/flashrom.h @@ -470,6 +470,8 @@ struct DCFlashChip : MemChip *size = 64 * 1024; break; default: + *offset = 0; + *size = 0; die("unknown partition"); break; } diff --git a/core/hw/maple/maple_jvs.cpp b/core/hw/maple/maple_jvs.cpp index ce1361d45..7abd4b056 100644 --- a/core/hw/maple/maple_jvs.cpp +++ b/core/hw/maple/maple_jvs.cpp @@ -38,7 +38,8 @@ void load_naomi_eeprom() FILE* f = nowide::fopen(eeprom_file.c_str(), "rb"); if (f) { - std::fread(EEPROM, 1, 0x80, f); + if (std::fread(EEPROM, 1, 0x80, f) != 0x80) + WARN_LOG(MAPLE, "Failed or truncated read of EEPROM '%s'", eeprom_file.c_str()); std::fclose(f); DEBUG_LOG(MAPLE, "Loaded EEPROM from %s", eeprom_file.c_str()); } @@ -242,7 +243,7 @@ private: u32 source = NaomiGameInputs->buttons[i].source; int keyIdx = 0; for (; keyIdx < 32; keyIdx++) - if (1 << keyIdx == source) + if (1u << keyIdx == source) break; verify(keyIdx < 32); p1_mapping[keyIdx] = NaomiGameInputs->buttons[i].p1_target; diff --git a/core/hw/naomi/naomi_cart.cpp b/core/hw/naomi/naomi_cart.cpp index 366e91f7b..d241933e1 100644 --- a/core/hw/naomi/naomi_cart.cpp +++ b/core/hw/naomi/naomi_cart.cpp @@ -366,7 +366,7 @@ static void naomi_cart_LoadZip(const char *filename) strcpy(naomi_game_id, game->name); NOTICE_LOG(NAOMI, "NAOMI GAME ID [%s]", naomi_game_id); - } catch (const ReicastException& ex) { + } catch (const FlycastException& ex) { delete CurrentCartridge; CurrentCartridge = NULL; @@ -393,7 +393,7 @@ void naomi_cart_LoadRom(const char* file) if (!loadBios("naomi", NULL, NULL, -1)) { if (!bios_loaded) - throw new ReicastException("Error: cannot load BIOS from naomi.zip"); + throw FlycastException("Error: cannot load BIOS from naomi.zip"); } } @@ -412,14 +412,14 @@ void naomi_cart_LoadRom(const char* file) FILE *fl = nowide::fopen(file, "r"); if (!fl) - throw new ReicastException("Error: can't open " + std::string(file)); + throw FlycastException("Error: can't open " + std::string(file)); char t[512]; char* line = std::fgets(t, sizeof(t), fl); if (!line) { std::fclose(fl); - throw new ReicastException("Error: Invalid LST file"); + throw FlycastException("Error: Invalid LST file"); } char* eon = strstr(line, "\n"); @@ -435,7 +435,7 @@ void naomi_cart_LoadRom(const char* file) if (!line) { std::fclose(fl); - throw new ReicastException("Error: Invalid LST file"); + throw FlycastException("Error: Invalid LST file"); } while (line) @@ -461,7 +461,7 @@ void naomi_cart_LoadRom(const char* file) // BIN loading FILE* fp = nowide::fopen(file, "rb"); if (fp == NULL) - throw new ReicastException("Error: can't open " + std::string(file)); + throw FlycastException("Error: can't open " + std::string(file)); std::fseek(fp, 0, SEEK_END); u32 file_size = (u32)std::ftell(fp); @@ -521,7 +521,7 @@ void naomi_cart_LoadRom(const char* file) if (load_error) { free(romBase); - throw new ReicastException("Error: Failed to load BIN/DAT file"); + throw FlycastException("Error: Failed to load BIN/DAT file"); } DEBUG_LOG(NAOMI, "Legacy ROM loaded successfully"); diff --git a/core/hw/naomi/naomi_cart.h b/core/hw/naomi/naomi_cart.h index 24d8a065e..4c18376fc 100644 --- a/core/hw/naomi/naomi_cart.h +++ b/core/hw/naomi/naomi_cart.h @@ -77,10 +77,10 @@ private: u8 naomi_cart_ram[64 * 1024]; }; -class NaomiCartException : public ReicastException +class NaomiCartException : public FlycastException { public: - NaomiCartException(std::string reason) : ReicastException(reason) {} + NaomiCartException(const std::string& reason) : FlycastException(reason) {} }; void naomi_cart_LoadRom(const char* file); diff --git a/core/hw/sh4/dyna/decoder.cpp b/core/hw/sh4/dyna/decoder.cpp index cd6fd4b21..d8e3c9a39 100644 --- a/core/hw/sh4/dyna/decoder.cpp +++ b/core/hw/sh4/dyna/decoder.cpp @@ -128,12 +128,6 @@ static void dec_End(u32 dst, BlockEndType flags, bool delaySlot) verify(state.JumpAddr != NullAddress); } -#define GetN(str) ((str>>8) & 0xf) -#define GetM(str) ((str>>4) & 0xf) -#define GetImm4(str) ((str>>0) & 0xf) -#define GetImm8(str) ((str>>0) & 0xff) -#define GetSImm8(str) ((s8)((str>>0) & 0xff)) - #define SR_STATUS_MASK 0x700083F2 #define SR_T_MASK 1 diff --git a/core/hw/sh4/dyna/decoder.h b/core/hw/sh4/dyna/decoder.h index 5398e14d8..800585bb9 100644 --- a/core/hw/sh4/dyna/decoder.h +++ b/core/hw/sh4/dyna/decoder.h @@ -75,5 +75,11 @@ struct state_t }; const u32 NullAddress = 0xFFFFFFFF; + +#define GetN(str) ((str>>8) & 0xf) +#define GetM(str) ((str>>4) & 0xf) +#define GetImm4(str) ((str>>0) & 0xf) +#define GetImm8(str) ((str>>0) & 0xff) +#define GetSImm8(str) ((s8)((str>>0) & 0xff)) #define GetImm12(str) ((str>>0) & 0xfff) #define GetSImm12(str) (((short)((GetImm12(str))<<4))>>4) diff --git a/core/hw/sh4/interpr/sh4_opcodes.cpp b/core/hw/sh4/interpr/sh4_opcodes.cpp index ad48248f5..3ce78c92a 100644 --- a/core/hw/sh4/interpr/sh4_opcodes.cpp +++ b/core/hw/sh4/interpr/sh4_opcodes.cpp @@ -13,14 +13,6 @@ #include "hw/sh4/sh4_cache.h" #include "debug/gdb_server.h" -#define GetN(str) ((str>>8) & 0xf) -#define GetM(str) ((str>>4) & 0xf) -#define GetImm4(str) ((str>>0) & 0xf) -#define GetImm8(str) ((str>>0) & 0xff) -#define GetSImm8(str) ((s8)((str>>0) & 0xff)) -#define GetImm12(str) ((str>>0) & 0xfff) -#define GetSImm12(str) (((s16)((GetImm12(str))<<4))>>4) - #define iNimp cpu_iNimp //Read Mem macros diff --git a/core/hw/sh4/modules/mmu.cpp b/core/hw/sh4/modules/mmu.cpp index 1f036db7a..038bd75f7 100644 --- a/core/hw/sh4/modules/mmu.cpp +++ b/core/hw/sh4/modules/mmu.cpp @@ -530,7 +530,7 @@ void MMU_init() } mmu_set_state(); // pre-fill kernel memory - for (int vpn = ARRAY_SIZE(mmuAddressLUT) / 2; vpn < ARRAY_SIZE(mmuAddressLUT); vpn++) + for (u32 vpn = ARRAY_SIZE(mmuAddressLUT) / 2; vpn < ARRAY_SIZE(mmuAddressLUT); vpn++) mmuAddressLUT[vpn] = vpn << 12; } diff --git a/core/hw/sh4/sh4_mem.cpp b/core/hw/sh4/sh4_mem.cpp index d7112dc4f..015571c80 100644 --- a/core/hw/sh4/sh4_mem.cpp +++ b/core/hw/sh4/sh4_mem.cpp @@ -336,6 +336,8 @@ void SetMemoryHandlers() return; } interpreterRunning = false; +#else + (void)interpreterRunning; #endif if (CCN_MMUCR.AT == 1 && config::FullMMU) { diff --git a/core/hw/sh4/sh4_opcode_list.cpp b/core/hw/sh4/sh4_opcode_list.cpp index 8b2ccaa36..6998a3890 100644 --- a/core/hw/sh4/sh4_opcode_list.cpp +++ b/core/hw/sh4/sh4_opcode_list.cpp @@ -1,6 +1,7 @@ #include "types.h" #include "interpr/sh4_opcodes.h" #include "sh4_opcode_list.h" +#include "dyna/decoder.h" #include "dyna/decoder_opcodes.h" #include "hw/sh4/dyna/shil.h" #include "reios/reios.h" @@ -22,16 +23,6 @@ sh4_opcodelistentry* OpDesc[0x10000]; #define Mask_nh3bit 0xF1FF #define Mask_nh2bit 0xF3FF -#define GetN(str) ((str>>8) & 0xf) -#define GetM(str) ((str>>4) & 0xf) -#define GetImm4(str) ((str>>0) & 0xf) -#define GetImm8(str) ((str>>0) & 0xff) -#define GetSImm8(str) ((s8)((str>>0) & 0xff)) -#define GetImm12(str) ((str>>0) & 0xfff) -#define GetSImm12(str) (((s16)((GetImm12(str))<<4))>>4) - - - //,DEC_D_RN|DEC_S_RM|DEC_OP(shop_and) u64 dec_Fill(DecMode mode,DecParam d,DecParam s,shilop op,u32 extra=0) { diff --git a/core/imgread/common.h b/core/imgread/common.h index 731bbff5a..2f5001732 100644 --- a/core/imgread/common.h +++ b/core/imgread/common.h @@ -289,7 +289,8 @@ struct RawTrackFile : TrackFile } std::fseek(file, offset + FAD * fmt, SEEK_SET); - std::fread(dst, 1, fmt, file); + if (std::fread(dst, 1, fmt, file) != fmt) + WARN_LOG(GDROM, "Failed or truncated GD-Rom read"); } ~RawTrackFile() override { diff --git a/core/imgread/cue.cpp b/core/imgread/cue.cpp index b47d82c16..f026ee2ff 100644 --- a/core/imgread/cue.cpp +++ b/core/imgread/cue.cpp @@ -67,7 +67,8 @@ Disc* cue_parse(const char* file) return nullptr; } - std::fread(cue_data, 1, cue_len, fsource); + if (std::fread(cue_data, 1, cue_len, fsource) != cue_len) + WARN_LOG(GDROM, "Failed or truncated read of cue file '%s'", file); std::fclose(fsource); std::istringstream cuesheet(cue_data); diff --git a/core/imgread/gdi.cpp b/core/imgread/gdi.cpp index 72ad8c25d..b055c5235 100644 --- a/core/imgread/gdi.cpp +++ b/core/imgread/gdi.cpp @@ -76,7 +76,8 @@ Disc* load_gdi(const char* file) return nullptr; } - std::fread(gdi_data, 1, gdi_len, t); + if (std::fread(gdi_data, 1, gdi_len, t) != gdi_len) + WARN_LOG(GDROM, "Failed or truncated read of gdi file '%s'", file); std::fclose(t); std::istringstream gdi(gdi_data); diff --git a/core/input/gamepad_device.cpp b/core/input/gamepad_device.cpp index 4887f5e02..ebbd50680 100644 --- a/core/input/gamepad_device.cpp +++ b/core/input/gamepad_device.cpp @@ -537,13 +537,13 @@ void Mouse::setRelPos(int deltax, int deltay) { } void Mouse::setWheel(int delta) { - if (maple_port() >= 0 && maple_port() < ARRAY_SIZE(mo_wheel_delta)) + if (maple_port() >= 0 && maple_port() < (int)ARRAY_SIZE(mo_wheel_delta)) mo_wheel_delta[maple_port()] += delta; } void Mouse::setButton(Button button, bool pressed) { - if (maple_port() >= 0 && maple_port() < ARRAY_SIZE(mo_buttons)) + if (maple_port() >= 0 && maple_port() < (int)ARRAY_SIZE(mo_buttons)) { if (pressed) mo_buttons[maple_port()] &= ~(1 << (int)button); diff --git a/core/linux-dist/main.cpp b/core/linux-dist/main.cpp index 91e8743da..e895a7eb5 100644 --- a/core/linux-dist/main.cpp +++ b/core/linux-dist/main.cpp @@ -396,7 +396,7 @@ int main(int argc, char* argv[]) common_linux_setup(); #endif - if (reicast_init(argc, argv)) + if (flycast_init(argc, argv)) die("Flycast initialization failed\n"); mainui_loop(); diff --git a/core/linux/common.cpp b/core/linux/common.cpp index b2fd99a5b..89bc31da8 100644 --- a/core/linux/common.cpp +++ b/core/linux/common.cpp @@ -78,7 +78,7 @@ void fault_handler (int sn, siginfo_t * si, void *segfault_ctx) MemoryInfo meminfo; u32 pageinfo; svcQueryMemory(&meminfo, &pageinfo, (u64)&__start__); - ERROR_LOG(COMMON, ".text base: %p", meminfo.addr); + ERROR_LOG(COMMON, ".text base: %p", (void*)meminfo.addr); #endif // __SWITCH__ die("segfault"); signal(SIGSEGV, SIG_DFL); diff --git a/core/linux/libnx_vmem.cpp b/core/linux/libnx_vmem.cpp index 2e6a0b616..681b3a785 100644 --- a/core/linux/libnx_vmem.cpp +++ b/core/linux/libnx_vmem.cpp @@ -10,7 +10,7 @@ using mem_handle_t = uintptr_t; static mem_handle_t vmem_fd = -1; -static mem_handle_t vmem_fd_page = -1; +//static mem_handle_t vmem_fd_page = -1; static mem_handle_t vmem_fd_codememory = -1; static void *reserved_base; @@ -20,10 +20,10 @@ static VirtmemReservation *virtmemReservation; bool mem_region_lock(void *start, size_t len) { size_t inpage = (uintptr_t)start & PAGE_MASK; - len += inpage; - size_t inlen = len & PAGE_MASK; - if (inlen) - len = (len + PAGE_SIZE) & ~(PAGE_SIZE-1); + len += inpage; + size_t inlen = len & PAGE_MASK; + if (inlen) + len = (len + PAGE_SIZE) & ~(PAGE_SIZE-1); Result rc; uintptr_t start_addr = (uintptr_t)start - inpage; @@ -40,10 +40,10 @@ bool mem_region_lock(void *start, size_t len) bool mem_region_unlock(void *start, size_t len) { size_t inpage = (uintptr_t)start & PAGE_MASK; - len += inpage; - size_t inlen = len & PAGE_MASK; - if(inlen) - len = (len + PAGE_SIZE) & ~(PAGE_SIZE-1); + len += inpage; + size_t inlen = len & PAGE_MASK; + if (inlen) + len = (len + PAGE_SIZE) & ~(PAGE_SIZE-1); Result rc; uintptr_t start_addr = (uintptr_t)start - inpage; @@ -57,6 +57,7 @@ bool mem_region_unlock(void *start, size_t len) return true; } +/* static bool mem_region_set_exec(void *start, size_t len) { size_t inpage = (uintptr_t)start & PAGE_MASK; @@ -75,6 +76,7 @@ static void *mem_region_reserve(void *start, size_t len) virtmemUnlock(); return p; } +*/ static bool mem_region_release(void *start, size_t len) { @@ -92,9 +94,11 @@ static void *mem_region_map_file(void *file_handle, void *dest, size_t len, size { Result rc = svcMapProcessMemory(dest, envGetOwnProcessHandle(), (u64)(vmem_fd_codememory + offset), len); if (R_FAILED(rc)) - WARN_LOG(VMEM, "Fatal error creating the view... base: %p offset: 0x%x size: 0x%x src: %p err: 0x%x", vmem_fd, offset, len, vmem_fd_codememory + offset, rc); + WARN_LOG(VMEM, "Fatal error creating the view... base: %p offset: 0x%zx size: 0x%zx src: %p err: 0x%x", + (void*)vmem_fd, offset, len, (void*)(vmem_fd_codememory + offset), rc); else - INFO_LOG(VMEM, "Created the view... base: %p offset: 0x%x size: 0x%x src: %p err: 0x%x", vmem_fd, offset, len, vmem_fd_codememory + offset, rc); + INFO_LOG(VMEM, "Created the view... base: %p offset: 0x%zx size: 0x%zx src: %p err: 0x%x", + (void*)vmem_fd, offset, len, (void*)(vmem_fd_codememory + offset), rc); return dest; } @@ -104,12 +108,14 @@ static bool mem_region_unmap_file(void *start, size_t len) return mem_region_release(start, len); } +/* // Allocates memory via a fd on shmem/ahmem or even a file on disk static mem_handle_t allocate_shared_filemem(unsigned size) { void* mem = memalign(0x1000, size); return (uintptr_t)mem; } +*/ // Implement vmem initialization for RAM, ARAM, VRAM and SH4 context, fpcb etc. // The function supports allocating 512MB or 4GB addr spaces. diff --git a/core/nullDC.cpp b/core/nullDC.cpp index a37c63512..d81e8eb05 100644 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -17,7 +17,7 @@ static std::future loadingDone; -int reicast_init(int argc, char* argv[]) +int flycast_init(int argc, char* argv[]) { #if defined(TEST_AUTOMATION) setbuf(stdout, 0); diff --git a/core/rec-ARM64/rec_arm64.cpp b/core/rec-ARM64/rec_arm64.cpp index 5b610e463..b881677a9 100644 --- a/core/rec-ARM64/rec_arm64.cpp +++ b/core/rec-ARM64/rec_arm64.cpp @@ -1004,7 +1004,7 @@ public: // Args are pushed in reverse order by shil_canonical for (int i = CC_pars.size(); i-- > 0;) { - verify(fregused < call_fregs.size() && regused < call_regs.size()); + verify(fregused < (int)call_fregs.size() && regused < (int)call_regs.size()); shil_param& prm = *CC_pars[i].prm; switch (CC_pars[i].type) { @@ -1629,6 +1629,7 @@ private: rv = mmu_data_translation(addr, paddr); break; default: + rv = 0; die("Invalid immediate size"); break; } @@ -1839,6 +1840,7 @@ private: rv = mmu_data_translation(addr, paddr); break; default: + rv = 0; die("Invalid immediate size"); break; } @@ -2192,11 +2194,11 @@ bool ngen_Rewrite(host_context_t &context, void *faultAddress) //LOGI("ngen_Rewrite pc %zx\n", context.pc); u32 *code_ptr = (u32 *)CC_RX2RW(context.pc); u32 armv8_op = *code_ptr; - bool is_read; - u32 size; + bool is_read = false; + u32 size = 0; bool found = false; u32 masked = armv8_op & STR_LDR_MASK; - for (int i = 0; i < ARRAY_SIZE(armv8_mem_ops); i++) + for (u32 i = 0; i < ARRAY_SIZE(armv8_mem_ops); i++) { if (masked == armv8_mem_ops[i]) { diff --git a/core/reios/reios.cpp b/core/reios/reios.cpp index f16b5d6d0..aa69ef13f 100644 --- a/core/reios/reios.cpp +++ b/core/reios/reios.cpp @@ -150,7 +150,7 @@ static bool reios_locate_bootfile(const char* bootfile) data[8 + j] = _vmem_ReadMem8(0x0021a000 + j); // system settings - flash_syscfg_block syscfg; + flash_syscfg_block syscfg{}; verify(static_cast(flashrom)->ReadBlock(FLASH_PT_USER, FLASH_USER_SYSCFG, &syscfg)); memcpy(&data[16], &syscfg.time_lo, 8); @@ -210,7 +210,7 @@ static void reios_sys_system() { data[8 + i] = flashrom->Read8(0x1a000 + i); // system settings - flash_syscfg_block syscfg; + flash_syscfg_block syscfg{}; verify(static_cast(flashrom)->ReadBlock(FLASH_PT_USER, FLASH_USER_SYSCFG, &syscfg)); memcpy(&data[16], &syscfg.time_lo, 8); diff --git a/core/rend/gl4/gl4.h b/core/rend/gl4/gl4.h index e58b8cdab..f7081e68a 100755 --- a/core/rend/gl4/gl4.h +++ b/core/rend/gl4/gl4.h @@ -18,7 +18,6 @@ */ #pragma once #include "rend/gles/gles.h" -#include "glsl.h" #include void gl4DrawStrips(GLuint output_fbo, int width, int height); @@ -106,31 +105,7 @@ extern GLuint geom_fbo; extern GLuint texSamplers[2]; extern GLuint depth_fbo; -static const char* ShaderHeader = R"( -layout(r32ui, binding = 4) uniform coherent restrict uimage2D abufferPointerImg; - -layout(binding = 0, offset = 0) uniform atomic_uint buffer_index; -)" -OIT_POLY_PARAM -R"( -layout (binding = 0, std430) coherent restrict buffer PixelBuffer { - Pixel pixels[]; -}; - -uint getNextPixelIndex() -{ - uint index = atomicCounterIncrement(buffer_index); - if (index >= pixels.length()) - // Buffer overflow - discard; - - return index; -} - -layout (binding = 1, std430) readonly buffer TrPolyParamBuffer { - PolyParam tr_poly_params[]; -}; -)"; +extern const char* ShaderHeader; class OpenGl4Source : public ShaderSource { diff --git a/core/rend/gl4/gles.cpp b/core/rend/gl4/gles.cpp index 66bd7db78..a6274c04a 100644 --- a/core/rend/gl4/gles.cpp +++ b/core/rend/gl4/gles.cpp @@ -20,9 +20,36 @@ #include "rend/gles/glcache.h" #include "rend/transform_matrix.h" #include "rend/osd.h" +#include "glsl.h" //Fragment and vertex shaders code +const char* ShaderHeader = R"( +layout(r32ui, binding = 4) uniform coherent restrict uimage2D abufferPointerImg; + +layout(binding = 0, offset = 0) uniform atomic_uint buffer_index; +)" +OIT_POLY_PARAM +R"( +layout (binding = 0, std430) coherent restrict buffer PixelBuffer { + Pixel pixels[]; +}; + +uint getNextPixelIndex() +{ + uint index = atomicCounterIncrement(buffer_index); + if (index >= pixels.length()) + // Buffer overflow + discard; + + return index; +} + +layout (binding = 1, std430) readonly buffer TrPolyParamBuffer { + PolyParam tr_poly_params[]; +}; +)"; + static const char* VertexShaderSource = R"( #if pp_Gouraud == 0 #define INTERPOLATION flat diff --git a/core/rend/gles/gles.cpp b/core/rend/gles/gles.cpp index 96810f6f6..ac036456d 100644 --- a/core/rend/gles/gles.cpp +++ b/core/rend/gles/gles.cpp @@ -29,6 +29,44 @@ //Fragment and vertex shaders code +const char* ShaderCompatSource = R"( +#define GLES2 0 +#define GLES3 1 +#define GL2 2 +#define GL3 3 + +#if TARGET_GL == GL2 +#define highp +#define lowp +#define mediump +#endif +#if TARGET_GL == GLES3 +out highp vec4 FragColor; +#define gl_FragColor FragColor +#define FOG_CHANNEL a +#elif TARGET_GL == GL3 +out highp vec4 FragColor; +#define gl_FragColor FragColor +#define FOG_CHANNEL r +#else +#define texture texture2D +#define FOG_CHANNEL a +#endif +)"; + +const char *VertexCompatShader = R"( +#if TARGET_GL == GLES2 || TARGET_GL == GL2 +#define in attribute +#define out varying +#endif +)"; + +const char *PixelCompatShader = R"( +#if TARGET_GL == GLES2 || TARGET_GL == GL2 +#define in varying +#endif +)"; + static const char* GouraudSource = R"( #if TARGET_GL == GL3 || TARGET_GL == GLES3 #if pp_Gouraud == 0 diff --git a/core/rend/gles/gles.h b/core/rend/gles/gles.h index 1cf0387e4..15cbddf8b 100755 --- a/core/rend/gles/gles.h +++ b/core/rend/gles/gles.h @@ -298,43 +298,9 @@ void initQuad(); void termQuad(); void drawQuad(GLuint texId, bool rotate = false, bool swapY = false); -static const char* ShaderCompatSource = R"( -#define GLES2 0 -#define GLES3 1 -#define GL2 2 -#define GL3 3 - -#if TARGET_GL == GL2 -#define highp -#define lowp -#define mediump -#endif -#if TARGET_GL == GLES3 -out highp vec4 FragColor; -#define gl_FragColor FragColor -#define FOG_CHANNEL a -#elif TARGET_GL == GL3 -out highp vec4 FragColor; -#define gl_FragColor FragColor -#define FOG_CHANNEL r -#else -#define texture texture2D -#define FOG_CHANNEL a -#endif -)"; - -static const char *VertexCompatShader = R"( -#if TARGET_GL == GLES2 || TARGET_GL == GL2 -#define in attribute -#define out varying -#endif -)"; - -static const char *PixelCompatShader = R"( -#if TARGET_GL == GLES2 || TARGET_GL == GL2 -#define in varying -#endif -)"; +extern const char* ShaderCompatSource; +extern const char *VertexCompatShader; +extern const char *PixelCompatShader; class OpenGlSource : public ShaderSource { diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 8268617b7..9ea1589ae 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -746,13 +746,12 @@ static void controller_mapping_popup(const std::shared_ptr& gamep - ImGui::GetStyle().FramePadding.x * 3.0f - ImGui::GetStyle().ItemSpacing.x * 3.0f); ImGui::AlignTextToFramePadding(); - static ImGuiComboFlags flags = 0; + const char* items[] = { "Dreamcast Controls", "Arcade Controls" }; static int item_current_map_idx = 0; static int last_item_current_map_idx = 2; // Here our selection data is an index. - const char* combo_label = items[item_current_map_idx]; // Label to preview before opening the combo (technically it could be anything) ImGui::PushItemWidth(ImGui::CalcTextSize("Dreamcast Controls").x + ImGui::GetStyle().ItemSpacing.x * 2.0f * 3); @@ -2072,9 +2071,9 @@ static void gui_display_loadscreen() gui_state = GuiState::Closed; ImGui::Text("STARTING..."); } - } catch (const ReicastException& ex) { - ERROR_LOG(BOOT, "%s", ex.reason.c_str()); - error_msg = ex.reason; + } catch (const FlycastException& ex) { + ERROR_LOG(BOOT, "%s", ex.what()); + error_msg = ex.what(); #ifdef TEST_AUTOMATION die("Game load failed"); #endif diff --git a/core/rend/vulkan/vk_context_lr.h b/core/rend/vulkan/vk_context_lr.h index aa2616277..1df592fb9 100644 --- a/core/rend/vulkan/vk_context_lr.h +++ b/core/rend/vulkan/vk_context_lr.h @@ -43,7 +43,7 @@ public: vk::Device GetDevice() const { return device; } vk::PipelineCache GetPipelineCache() const { return *pipelineCache; } vk::DescriptorPool GetDescriptorPool() const { return *descriptorPool; } - int GetSwapChainSize() const { u32 m = retro_render_if->get_sync_index_mask(retro_render_if->handle); u32 n = 1; while (m >>= 1) n++; return n; } + size_t GetSwapChainSize() const { u32 m = retro_render_if->get_sync_index_mask(retro_render_if->handle); u32 n = 1; while (m >>= 1) n++; return n; } int GetCurrentImageIndex() const { return retro_render_if->get_sync_index(retro_render_if->handle); } // FIXME that's not quite correct void WaitIdle() const { retro_render_if->wait_sync_index(retro_render_if->handle); } diff --git a/core/types.h b/core/types.h index 912fccbf1..a00554975 100644 --- a/core/types.h +++ b/core/types.h @@ -425,12 +425,10 @@ struct OnLoad #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #endif -class ReicastException +class FlycastException : public std::runtime_error { public: - ReicastException(std::string reason) : reason(reason) {} - - std::string reason; + FlycastException(const std::string& reason) : std::runtime_error(reason) {} }; enum serialize_version_enum { diff --git a/core/windows/winmain.cpp b/core/windows/winmain.cpp index 63caff8f4..962d2b764 100644 --- a/core/windows/winmain.cpp +++ b/core/windows/winmain.cpp @@ -707,7 +707,7 @@ int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi setupPath(); findKeyboardLayout(); - if (reicast_init(argc, argv) != 0) + if (flycast_init(argc, argv) != 0) die("Flycast initialization failed"); os_InstallFaultHandler(); diff --git a/shell/android-studio/flycast/src/main/jni/src/Android.cpp b/shell/android-studio/flycast/src/main/jni/src/Android.cpp index bdf19d116..807839217 100644 --- a/shell/android-studio/flycast/src/main/jni/src/Android.cpp +++ b/shell/android-studio/flycast/src/main/jni/src/Android.cpp @@ -234,7 +234,7 @@ JNIEXPORT jstring JNICALL Java_com_reicast_emulator_emu_JNIdc_initEnvironment(JN EventManager::listen(Event::Pause, emuEventCallback); EventManager::listen(Event::Resume, emuEventCallback); jstring msg = NULL; - int rc = reicast_init(0, NULL); + int rc = flycast_init(0, NULL); if (rc == -4) msg = env->NewStringUTF("Cannot find configuration"); else if (rc == 69) diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index b636295d6..0bed48f41 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -243,7 +243,7 @@ int emu_reicast_init() argv[paramCount++] = strdup(arg); } - int rc = reicast_init(paramCount, argv); + int rc = flycast_init(paramCount, argv); for (unsigned long i = 0; i < paramCount; i++) free(argv[i]); diff --git a/shell/libretro/libretro.cpp b/shell/libretro/libretro.cpp index b4f23a29d..f24331b47 100644 --- a/shell/libretro/libretro.cpp +++ b/shell/libretro/libretro.cpp @@ -1229,6 +1229,9 @@ static void set_input_descriptors() if (name != NULL && name[0] != '\0') desc[descriptor_index++] = { i, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, name }; break; + + default: + break; } } } @@ -1294,6 +1297,9 @@ static void set_input_descriptors() desc[descriptor_index++] = { i, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_START, "Start" }; desc[descriptor_index++] = { i, RETRO_DEVICE_LIGHTGUN, 0, RETRO_DEVICE_ID_LIGHTGUN_AUX_A, "B" }; break; + + default: + break; } } } @@ -1831,7 +1837,7 @@ unsigned retro_get_region() // Controller void retro_set_controller_port_device(unsigned in_port, unsigned device) { - if (device_type[in_port] != device && in_port < MAPLE_PORTS) + if (device_type[in_port] != (int)device && in_port < MAPLE_PORTS) { devices_need_refresh = true; device_type[in_port] = device; @@ -2577,6 +2583,9 @@ static void UpdateInputState(u32 port) case MDT_Mouse: updateMouseState(port); break; + + default: + break; } } @@ -2628,16 +2637,19 @@ static void retro_keyboard_event(bool down, unsigned keycode, uint32_t character { // Dreamcast keyboard emulation if (keycode == RETROK_LSHIFT || keycode == RETROK_RSHIFT) + { if (!down) kb_shift[0] &= ~(0x02 | 0x20); else kb_shift[0] |= (0x02 | 0x20); + } if (keycode == RETROK_LCTRL || keycode == RETROK_RCTRL) + { if (!down) kb_shift[0] &= ~(0x01 | 0x10); else kb_shift[0] |= (0x01 | 0x10); - + } // Make sure modifier keys are released if ((key_modifiers & RETROKMOD_SHIFT) == 0) { @@ -2930,7 +2942,7 @@ void gui_display_notification(const char *msg, int duration) retro_message retromsg; retromsg.msg = msg; retromsg.frames = duration / 17; - environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &msg); + environ_cb(RETRO_ENVIRONMENT_SET_MESSAGE, &retromsg); } void gui_init() {