From cce5028ed3816faf1f25a4d1334028ef68e9e45f Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 26 Mar 2019 11:54:03 +0100 Subject: [PATCH] AW: fix flash sector size. Implement SB_SFRES soft reset Fixes Atomiswave freezing when exiting the service menu and problems when saving to flash. --- core/hw/flashrom/flashrom.h | 24 ++++++++++++------------ core/hw/holly/sb.cpp | 5 ++++- core/nullDC.cpp | 21 +++++++++++++++++++-- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/core/hw/flashrom/flashrom.h b/core/hw/flashrom/flashrom.h index 4b915385d..d3282e003 100644 --- a/core/hw/flashrom/flashrom.h +++ b/core/hw/flashrom/flashrom.h @@ -378,19 +378,19 @@ struct DCFlashChip : MemChip else if ((val & 0xff) == 0x30) { // sector erase - addr = max(addr, write_protect_size); -#if DC_PLATFORM != DC_PLATFORM_ATOMISWAVE - printf("Erase Sector %08X! (%08X)\n",addr,addr&(~0x3FFF)); - memset(&data[addr&(~0x3FFF)],0xFF,0x4000); -#else - // AtomisWave's Macronix 29L001mc has 64k blocks - printf("Erase Sector %08X! (%08X)\n",addr,addr&(~0xFFFF)); - u8 save[0x2000]; - // this area is write-protected on AW - memcpy(save, data + 0x1a000, 0x2000); - memset(&data[addr&(~0xFFFF)], 0xFF, 0x10000); - memcpy(data + 0x1a000, save, 0x2000); + if (addr >= write_protect_size) + { +#if DC_PLATFORM == DC_PLATFORM_ATOMISWAVE + u8 save[0x2000]; + // this area is write-protected on AW + memcpy(save, data + 0x1a000, 0x2000); #endif + printf("Erase Sector %08X! (%08X)\n",addr,addr&(~0x3FFF)); + memset(&data[addr&(~0x3FFF)],0xFF,0x4000); +#if DC_PLATFORM == DC_PLATFORM_ATOMISWAVE + memcpy(data + 0x1a000, save, 0x2000); +#endif + } state = FS_Normal; } else diff --git a/core/hw/holly/sb.cpp b/core/hw/holly/sb.cpp index 53064c4d6..69c809a82 100644 --- a/core/hw/holly/sb.cpp +++ b/core/hw/holly/sb.cpp @@ -14,6 +14,8 @@ #include "hw/naomi/naomi.h" +extern void dc_request_reset(); + Array sb_regs(0x540); //(addr>= 0x005F6800) && (addr<=0x005F7CFF) -> 0x1500 bytes -> 0x540 possible registers , 125 actually exist only @@ -194,7 +196,8 @@ void SB_SFRES_write32(u32 addr, u32 data) { if ((u16)data==0x7611) { - printf("SB/HOLLY: System reset requested -- but cannot SOFT_RESET\n"); + printf("SB/HOLLY: System reset requested\n"); + dc_request_reset(); } } void sb_Init() diff --git a/core/nullDC.cpp b/core/nullDC.cpp index fc1cf9f95..d14dc2d91 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -259,6 +259,7 @@ void dc_reset() } static bool init_done; +static bool reset_requested; int reicast_init(int argc, char* argv[]) { @@ -414,9 +415,18 @@ void* dc_run(void*) Get_Sh4Interpreter(&sh4_cpu); printf("Using Interpreter\n"); } - sh4_cpu.Run(); + do { + reset_requested = false; + + sh4_cpu.Run(); + + SaveRomFiles(get_writable_data_path("/data/")); + if (reset_requested) + { + dc_reset(); + } + } while (reset_requested); - SaveRomFiles(get_writable_data_path("/data/")); TermAudio(); return NULL; @@ -444,6 +454,13 @@ void dc_stop() emu_thread.WaitToEnd(); } +// Called on the emulator thread for soft reset +void dc_request_reset() +{ + reset_requested = true; + sh4_cpu.Stop(); +} + void dc_exit() { dc_stop();