From d5e24d8aedbed5166e03e8ffb0bd96a2ee25a957 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Mon, 8 Jul 2019 18:10:43 +0200 Subject: [PATCH] Cleaner init. Get rid of LastImage --- core/hw/aica/aica.cpp | 1 + core/hw/arm7/arm_mem.h | 3 - core/hw/arm7/vbaARM.cpp | 2 - core/hw/maple/maple_devs.cpp | 8 ++ core/imgread/common.cpp | 37 +++------- core/nullDC.cpp | 137 ++++++++++++++++------------------- core/types.h | 1 - 7 files changed, 83 insertions(+), 106 deletions(-) diff --git a/core/hw/aica/aica.cpp b/core/hw/aica/aica.cpp index 4ef983a31..381616838 100644 --- a/core/hw/aica/aica.cpp +++ b/core/hw/aica/aica.cpp @@ -216,4 +216,5 @@ void libAICA_Reset(bool manual) void libAICA_Term() { sgc_Term(); + term_mem(); } diff --git a/core/hw/arm7/arm_mem.h b/core/hw/arm7/arm_mem.h index ee4055e41..10db8a668 100644 --- a/core/hw/arm7/arm_mem.h +++ b/core/hw/arm7/arm_mem.h @@ -54,9 +54,6 @@ static inline void DYNACALL WriteMemArm(u32 addr,T data) u32 sh4_ReadMem_reg(u32 addr,u32 size); void sh4_WriteMem_reg(u32 addr,u32 data,u32 size); -void init_mem(); -void term_mem(); - #define aica_reg_16 ((u16*)aica_reg) #define AICA_RAM_SIZE (ARAM_SIZE) diff --git a/core/hw/arm7/vbaARM.cpp b/core/hw/arm7/vbaARM.cpp index 182e95868..037c7b28c 100644 --- a/core/hw/arm7/vbaARM.cpp +++ b/core/hw/arm7/vbaARM.cpp @@ -9,7 +9,6 @@ //called when plugin is used by emu (you should do first time init here) s32 libARM_Init() { - init_mem(); arm_Init(); return rv_ok; @@ -18,7 +17,6 @@ s32 libARM_Init() //called when plugin is unloaded by emu, only if dcInit is called (eg, not called to enumerate plugins) void libARM_Term() { - term_mem(); //arm7_Term ? } diff --git a/core/hw/maple/maple_devs.cpp b/core/hw/maple/maple_devs.cpp index f7acc5e38..dde4e456f 100755 --- a/core/hw/maple/maple_devs.cpp +++ b/core/hw/maple/maple_devs.cpp @@ -2189,6 +2189,14 @@ struct maple_naomi_jamma : maple_sega_controller break; + case MDCF_GetCondition: + w8(MDRE_UnknownCmd); + w8(0x00); + w8(0x00); + w8(0x00); + + break; + default: INFO_LOG(MAPLE, "Unknown Maple command %x", cmd); w8(MDRE_UnknownCmd); diff --git a/core/imgread/common.cpp b/core/imgread/common.cpp index 9f802e6d1..f7e2643e2 100644 --- a/core/imgread/common.cpp +++ b/core/imgread/common.cpp @@ -192,8 +192,7 @@ bool InitDrive(u32 fileflags) // FIXME: Data loss if buffer is too small wchar fn[512]; - strncpy(fn,settings.imgread.LastImage, sizeof(fn)); - fn[sizeof(fn) - 1] = '\0'; + fn[0] = '\0'; #ifdef BUILD_DREAMCAST int gfrv=GetFile(fn,0,fileflags); @@ -214,20 +213,14 @@ bool InitDrive(u32 fileflags) return false; } - // FIXME: Data loss if buffer is too small - strncpy(settings.imgread.LastImage, fn, sizeof(settings.imgread.LastImage)); - settings.imgread.LastImage[sizeof(settings.imgread.LastImage) - 1] = '\0'; - - SaveSettings(); - if (!InitDrive_(fn)) { //msgboxf("Selected image failed to load",MBX_ICONERROR); - NullDriveDiscType=NoDisk; - gd_setdisc(); - sns_asc=0x29; - sns_ascq=0x00; - sns_key=0x6; + NullDriveDiscType = NoDisk; + gd_setdisc(); + sns_asc = 0x29; + sns_ascq = 0x00; + sns_key = 0x6; return true; } else @@ -256,8 +249,7 @@ bool DiscSwap(u32 fileflags) // FIXME: Data loss if buffer is too small wchar fn[512]; - strncpy(fn, settings.imgread.LastImage, sizeof(fn)); - fn[sizeof(fn) - 1] = '\0'; + fn[0] = '\0'; #ifdef BUILD_DREAMCAST @@ -267,7 +259,7 @@ bool DiscSwap(u32 fileflags) #endif if (gfrv == 0) { - NullDriveDiscType=Open; + NullDriveDiscType = Open; gd_setdisc(); return true; } @@ -276,17 +268,10 @@ bool DiscSwap(u32 fileflags) return false; } - // FIXME: Data loss if buffer is too small - strncpy(settings.imgread.LastImage, fn, sizeof(settings.imgread.LastImage)); - settings.imgread.LastImage[sizeof(settings.imgread.LastImage) - 1] = '\0'; - - - SaveSettings(); - if (!InitDrive_(fn)) { //msgboxf("Selected image failed to load",MBX_ICONERROR); - NullDriveDiscType=Open; + NullDriveDiscType = Open; gd_setdisc(); } @@ -296,10 +281,10 @@ bool DiscSwap(u32 fileflags) void TermDrive() { - if (disc!=0) + if (disc != NULL) delete disc; - disc=0; + disc = NULL; } diff --git a/core/nullDC.cpp b/core/nullDC.cpp index bc7954970..e193a948d 100755 --- a/core/nullDC.cpp +++ b/core/nullDC.cpp @@ -311,7 +311,6 @@ void dc_reset(bool manual) sh4_cpu.Reset(manual); } -static bool init_done; static bool reset_requested; int reicast_init(int argc, char* argv[]) @@ -359,81 +358,14 @@ int reicast_init(int argc, char* argv[]) #define DATA_PATH "/" #endif -bool game_started; - -int dc_start_game(const char *path) +static int dc_init() { - if (path != NULL) - cfgSetVirtual("config", "image", path); + static bool init_done; if (init_done) - { - InitSettings(); - dc_reset(true); - LoadSettings(false); -#if DC_PLATFORM == DC_PLATFORM_DREAMCAST - if (!settings.bios.UseReios) -#endif - if (!LoadRomFiles(get_readonly_data_path(DATA_PATH))) - return -5; - -#if DC_PLATFORM == DC_PLATFORM_DREAMCAST - if (path == NULL) - { - // Boot BIOS - settings.imgread.LastImage[0] = 0; - TermDrive(); - InitDrive(); - } - else - { - if (DiscSwap()) - LoadCustom(); - } -#elif DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE - if (!naomi_cart_SelectFile()) - return -6; - LoadCustom(); -#if DC_PLATFORM == DC_PLATFORM_NAOMI - mcfg_CreateNAOMIJamma(); -#elif DC_PLATFORM == DC_PLATFORM_ATOMISWAVE - mcfg_CreateAtomisWaveControllers(); -#endif -#endif - - game_started = true; - dc_resume(); - return 0; - } - - if (settings.bios.UseReios || !LoadRomFiles(get_readonly_data_path(DATA_PATH))) - { -#ifdef USE_REIOS - if (!LoadHle(get_readonly_data_path(DATA_PATH))) - { - return -5; - } - else - { - NOTICE_LOG(BOOT, "Did not load bios, using reios\n"); - } -#else - ERROR_LOG(BOOT, "Cannot find BIOS files\n"); - return -5; -#endif - } - if (plugins_Init()) return -3; - -#if DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE - if (!naomi_cart_SelectFile()) - return -6; -#endif - - LoadCustom(); - #if FEAT_SHREC != DYNAREC_NONE Get_Sh4Recompiler(&sh4_cpu); sh4_cpu.Init(); // Also initialize the interpreter @@ -450,17 +382,74 @@ int dc_start_game(const char *path) } mem_Init(); + mem_map_default(); // TODO needs to be called again if changing platform - mem_map_default(); + init_done = true; + return 0; +} + +bool game_started; + +int dc_start_game(const char *path) +{ + if (path != NULL) + cfgSetVirtual("config", "image", path); + + int rc = dc_init(); + if (rc != 0) + return rc; + + InitSettings(); + dc_reset(true); + LoadSettings(false); + if (!LoadRomFiles(get_readonly_data_path(DATA_PATH))) + { +#if DC_PLATFORM == DC_PLATFORM_DREAMCAST +#ifdef USE_REIOS + if (settings.bios.UseReios) + { + if (!LoadHle(get_readonly_data_path(DATA_PATH))) + { + ERROR_LOG(BOOT, "Cannot init HLE BIOS"); + return -5; + } + else + { + NOTICE_LOG(BOOT, "Did not load bios, using reios"); + } + } + else +#endif + { + ERROR_LOG(BOOT, "Cannot find BIOS files"); + return -5; + } +#endif + } + +#if DC_PLATFORM == DC_PLATFORM_DREAMCAST + if (path == NULL) + { + // Boot BIOS + TermDrive(); + InitDrive(); + } + else + { + if (DiscSwap()) + LoadCustom(); + } +#elif DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE + if (!naomi_cart_SelectFile()) + return -6; + LoadCustom(); #if DC_PLATFORM == DC_PLATFORM_NAOMI mcfg_CreateNAOMIJamma(); #elif DC_PLATFORM == DC_PLATFORM_ATOMISWAVE mcfg_CreateAtomisWaveControllers(); #endif - init_done = true; - - dc_reset(true); +#endif game_started = true; dc_resume(); diff --git a/core/types.h b/core/types.h index e4a0e3c0b..cf5522668 100644 --- a/core/types.h +++ b/core/types.h @@ -707,7 +707,6 @@ struct settings_t bool PatchRegion; bool LoadDefaultImage; char DefaultImage[512]; - char LastImage[512]; } imgread; struct