From 7b62f440d2b3a8fa867102a5b0d20fd8c954f3a1 Mon Sep 17 00:00:00 2001 From: ApacheThunder Date: Sun, 7 Jul 2024 15:41:46 -0500 Subject: [PATCH] Fully remove NorFlash menu for Omega * NorFlash menu fully disabled for Omega. Pressing L no longer causes NorFlash menu to come up while in rumble/expansion ram selection menu. * Bug with ini file setup that causes default folders to always be created despite ini file defining custom folder locations has been resolved. * Menu display for Omega now changed to Omega DE. DE is currently the only cart that will have functional saves for games. --- .gitignore | 1 + Makefile | 2 +- arm9/include/dsCard.h | 89 ++++++---- arm9/include/dsCard.itcm.cpp | 117 +++++++++---- arm9/source/GBA_ini.cpp | 18 +- arm9/source/ctrl_tbl.cpp | 12 +- arm9/source/gba_patch.cpp | 38 ++-- arm9/source/gbaldr.itcm.cpp | 329 ++++++++++++++++++----------------- arm9/source/main.c | 53 +++--- 9 files changed, 364 insertions(+), 295 deletions(-) diff --git a/.gitignore b/.gitignore index d217261..3d54fda 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,7 @@ *.arm9 *.elf *.dldi +*.sav build data title diff --git a/Makefile b/Makefile index 1a2cc38..ee0ded9 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ export TARGET := GBA_ExpLoader export TOPDIR := $(CURDIR) export VERSION_MAJOR := 0 -export VERSION_MINOR := 63 +export VERSION_MINOR := 64 export VERSTRING := $(VERSION_MAJOR).$(VERSION_MINOR) # GMAE_ICON is the image used to create the game icon, leave blank to use default rule diff --git a/arm9/include/dsCard.h b/arm9/include/dsCard.h index fe3c689..a002902 100644 --- a/arm9/include/dsCard.h +++ b/arm9/include/dsCard.h @@ -28,57 +28,72 @@ typedef unsigned long DWORD; #endif #ifndef BOOL -typedef bool BOOL ; +typedef bool BOOL; #endif // export interface - - //--------------------------------------------------- //DS 卡 基本操作 - //Arm9 方面基本操作容许ARM7访问slot1 - // void Enable_Arm7DS(void); + //Arm9 方面基本操作容许ARM7访问slot1 + // void Enable_Arm7DS(void); - //Arm9 方面基本操作容许ARM9访问slot1 - // void Enable_Arm9DS(void); + //Arm9 方面基本操作容许ARM9访问slot1 + // void Enable_Arm9DS(void); - - //下面是访问震动卡的函数 + + //下面是访问震动卡的函数 #define FlashBase 0x08000000 #define PSRAMBase_S98 0x08800000 // EZ Flash Omega PSRAM location while in Kernal mode. (only writable in Kernal mode) #define FlashBase_S98 0x09000000 #define SRAM_ADDR 0x0A000000 #define SRAM_ADDR_OMEGA 0x0E000000 #define RTC_ENABLE ((vu16*)0x080000C8) - void OpenNorWrite(); - void CloseNorWrite(); - void SetRompage(u16 page); - void SetRampage(u16 page); - void SetSDControl(u16 control); - void Set_AUTO_save(u16 mode); - u16 Read_S71NOR_ID(); // For Reading EZFlash Omega ID - u16 Read_S98NOR_ID(); // For Reading EZFlash Omega ID - void SetPSRampage(u16 page); // EZFlash Omega uses this to change what 8MB of 32MB PSRAM is accessible at 0x08800000 - void Set_RTC_status(u16 status); // EZFlash Omega RTC thingy - u16 Read_SET_info(u32 offset); - void rtc_toggle(bool enable); - void SetbufferControl(u16 control); - void Omega_Bank_Switching(u8 bank); - void Omega_InitFatBuffer(BYTE saveMODE); - void OpenRamWrite(); - void CloseRamWrite(); - void SetSerialMode(); - uint32 ReadNorFlashID(); - void chip_reset(); - void Block_EraseIntel(u32 blockAdd); - void Block_Erase(u32 blockAdd); - // void ReadNorFlash(u8* pBuf,u32 address,u16 len); // Not used anywhere right now. Disabled out for now. - void WriteNorFlashINTEL(u32 address,u8 *buffer,u32 size); - void WriteNorFlash(u32 address,u8 *buffer,u32 size); - void WriteSram(uint32 address, u8* data , uint32 size ); - void ReadSram(uint32 address, u8* data , uint32 size ); - void SetShake(u16 data); + +#define OMEGA_NOSAVE 0 +#define OMEGA_UNKNOWN 0xFF +#define OMEGA_EEPROM_512 0x21 +#define OMEGA_EEPROM_8K 0x22 +#define OMEGA_EEPROM_V125 0x23 +#define OMEGA_FLASH_64K 0x32 +#define OMEGA_FLASH_512 0x33 +#define OMEGA_FLASH_1M 0x31 +#define OMEGA_SRAM_32K 0x11 +#define OMEGA_SRAM_64K 0x10 +// #define OMEGA_SRAM_64K 0xEE + + void OpenNorWrite(); + void CloseNorWrite(); + void SetRompage(u16 page); + void SetRampage(u16 page); + void SetSDControl(u16 control); + void Set_AUTO_save(u16 mode); + u16 Read_S71NOR_ID(); // For Reading EZFlash Omega ID + u16 Read_S98NOR_ID(); // For Reading EZFlash Omega ID + void SetPSRampage(u16 page); // EZFlash Omega uses this to change what 8MB of 32MB PSRAM is accessible at 0x08800000 + void Set_RTC_status(u16 status); // EZFlash Omega RTC thingy + u16 Read_SET_info(u32 offset); + void rtc_toggle(bool enable); + void SetbufferControl(u16 control); + void Omega_Bank_Switching(u8 bank); + void Omega_InitFatBuffer(BYTE saveMODE, u32 saveSize, u32 gameSize); + u32 Omega_SetSaveSize(u8 SaveMode); + void OpenRamWrite(); + void CloseRamWrite(); + void SetSerialMode(); + u32 CheckSuperCardID(); + u32 CheckOmegaID(); + uint32 ReadNorFlashID(); + void chip_reset(); + void Block_EraseIntel(u32 blockAdd); + void Block_Erase(u32 blockAdd); + // void ReadNorFlash(u8* pBuf,u32 address,u16 len); // Not used anywhere right now. Disabled out for now. + void WriteNorFlashINTEL(u32 address,u8 *buffer,u32 size); + void WriteNorFlash(u32 address,u8 *buffer,u32 size); + void WriteSram(uint32 address, u8* data , uint32 size ); + void ReadSram(uint32 address, u8* data , uint32 size ); + void SetShake(u16 data); + #ifdef __cplusplus } #endif diff --git a/arm9/include/dsCard.itcm.cpp b/arm9/include/dsCard.itcm.cpp index 2fd0609..b72ecda 100644 --- a/arm9/include/dsCard.itcm.cpp +++ b/arm9/include/dsCard.itcm.cpp @@ -21,15 +21,9 @@ extern "C" { static u32 ID = 0x227E2218; -u16 gl_ingame_RTC_open_status = 0; +static u32 FAT_table_buffer[0x400/4]; -static bool checkForSuperCard() { - _SC_changeMode(SC_MODE_RAM); // Try again with SuperCard - // _SC_changeMode16(0x1510); - *(vu16*)(0x08000000) = 0x4D54; - if (*(vu16*)(0x08000000) == 0x4D54)return true; - return false; -} +u16 gl_ingame_RTC_open_status = 0; //&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& //--------------------------------------------------- @@ -138,10 +132,10 @@ void rtc_toggle(bool enable) { } void Omega_Bank_Switching(u8 bank) { - *((vu8*)(SRAM_ADDR_OMEGA+0x5555)) = 0xAA; + *((vu8*)(SRAM_ADDR_OMEGA+0x5555)) = 0xAA; // SRAM_ADDR_OMEGA *((vu8*)(SRAM_ADDR_OMEGA+0x2AAA)) = 0x55; *((vu8*)(SRAM_ADDR_OMEGA+0x5555)) = 0xB0; - *((vu8*)SRAM_ADDR_OMEGA) = bank; + *((vu8*)SRAM_ADDR_OMEGA) = bank; } void SetbufferControl(u16 control) { @@ -153,24 +147,65 @@ void SetbufferControl(u16 control) { *(u16*)0x9fc0000 = 0x1500; } -static u32 FAT_table_buffer[0x400/4]; +u16 SD_Response(void) { return *(vu16*)0x9E00000; } -void Omega_InitFatBuffer(BYTE saveMODE) { - toncset((void*)FAT_table_buffer, 0, (0x400/4)); +void Omega_InitFatBuffer(BYTE saveMODE, u32 saveSize, u32 gameSize) { + toncset((u32*)FAT_table_buffer, 0, 0x400); + // FAT_table_buffer[1] = 0; // sector location of game rom to be copies FAT_table_buffer[2] = 0xFFFFFFFF; - // FAT_table_buffer[0x1F0/4] = 0; //size + // FAT_table_buffer[0x1F0/4] = gameSize; // rom copy size FAT_table_buffer[0x1F4/4] = 0x2; // 0x1 == rom copy to psram // 0x2 == copy mode - // FAT_table_buffer[0x1F8/4] = 0; // secort of cluster - // FAT_table_buffer[0x1FC/4] = (0x31<<24) | 0x20000; // save mode and save file size - FAT_table_buffer[0x1FC/4] = (saveMODE<<24) | 0x10000; // save mode and save file size + FAT_table_buffer[0x1F8/4] = 0x40; // secort of cluster + FAT_table_buffer[0x1FC/4] = ((saveMODE << 24) | saveSize); // save mode and save file size + // FAT_table_buffer[0x204/4] = 0x363100; // Save file sector location + FAT_table_buffer[0x204/4] = 0x00C07644; + FAT_table_buffer[0x208/4] = 0xFFFFFFFF; + // FAT_table_buffer[0x308/4] = 0x100; // RTS? + // FAT_table_buffer[0x320/4] = 0xFFFFFFFF; // RTS? + // FAT_table_buffer[0x210/4] = 0xFFFFFFFF; + // FAT_table_buffer[0x210/4] = 0xFFFFFFFF; + /*FILE *testFile = fopen("/fatTableTest.bin", "wb"); + if (testFile) { + fwrite((void*)FAT_table_buffer, 0x400, 1, testFile); + fclose(testFile); + }*/ SetbufferControl(1); - // tonccpy((void*)0x9E00000, FAT_table_buffer, 0x400); // dmaCopy(FAT_table_buffer, (void*)0x9E00000, 0x400); - tonccpy((void*)0x9E00000, FAT_table_buffer, 0x400); - SetbufferControl(3); - SetbufferControl(0); + tonccpy((u16*)0x9E00000, (u32*)FAT_table_buffer, 0x400); + SetbufferControl(3); + SetbufferControl(0); + /*SetbufferControl(0); + u16 res; + while(1) { + res = SD_Response(); + if(res != 0)break; + } + + while(1) { + res = SD_Response(); + if(res != 0x0001)break; + } + SetbufferControl(0);*/ } +u32 Omega_SetSaveSize(u8 SaveMode) { + switch (SaveMode) { + case OMEGA_NOSAVE: return 0; + case OMEGA_UNKNOWN: return 0x10000; + case OMEGA_EEPROM_512: return 0x200; + case OMEGA_EEPROM_8K: return 0x2000; + case OMEGA_EEPROM_V125: return 0x2000; + case OMEGA_FLASH_64K: return 0x10000; + case OMEGA_FLASH_512: return 0x10000; + case OMEGA_FLASH_1M: return 0x20000; + case OMEGA_SRAM_32K: return 0x8000; + case OMEGA_SRAM_64K: return 0x10000; + default: return 0; + } +} + + + void SetRampage(u16 page) { *(vu16*)0x9fe0000 = 0xd200; *(vu16*)0x8000000 = 0x1500; @@ -189,6 +224,29 @@ void SetSerialMode() { *(vu16*)0x9fc0000 = 0x1500; } +u32 CheckSuperCardID() { + SetRompage(0); // Prevent possible chain boot issue where previously booted app put card into similar mode to SuperCard if it's a card that responds to SetRompage. + _SC_changeMode(SC_MODE_RAM); // Try again with SuperCard + // _SC_changeMode16(0x1510); + *(vu16*)(FlashBase) = 0x4D54; + if (*(vu16*)(FlashBase) == 0x4D54) { + ID = 0x227E2202; + return 0x227E0000; + } + return 0; +} + + +u32 CheckOmegaID() { + // Check For EZ Flash Omega + if (Read_S98NOR_ID() == 0x223D) { + ID = 0x227EEA00; + return 0x227EEA00; + } + return 0; +} + + u32 ReadNorFlashID() { vu16 id1, id2, id3, id4; ID = 0; @@ -226,20 +284,7 @@ u32 ReadNorFlashID() { fclose(testFile); }*/ - if ((id1 != 0x227E) || (id2 != 0x227E)) { - if (checkForSuperCard()) { - ID = 0x227E2202; - return 0x227E0000; - } - // Check For EZ Flash Omega - SetRompage(0x8000); - id1 = Read_S98NOR_ID(); - if ((id1 == 0x223D)) { - ID = 0x227EEA00; - return 0x227EEA00; - } - return 0; - } + if ((id1 != 0x227E) || (id2 != 0x227E))return 0; id1 = *((vu16*)(FlashBase+0xE*2)); id2 = *((vu16*)(FlashBase+0x100e*2)); @@ -267,7 +312,7 @@ u32 ReadNorFlashID() { void chip_reset() { if (ID == 0x227EEA00) { - *((vu16*)(FlashBase_S98)) = 0xF0; + *((vu16*)0x08600000) = 0xF0; return; } else if(ID == 0x89168916) { *((vu16*)(FlashBase+0)) = 0x50; diff --git a/arm9/source/GBA_ini.cpp b/arm9/source/GBA_ini.cpp index ddc9a6f..f9eb737 100644 --- a/arm9/source/GBA_ini.cpp +++ b/arm9/source/GBA_ini.cpp @@ -15,7 +15,7 @@ extern u8 *rwbuf; extern u8 defaultSettings[]; extern u8 defaultSettingsEnd[]; -void GBA_ini() { +void GBA_ini() { FILE *fini; int len, p, s; char key[20]; @@ -26,8 +26,6 @@ void GBA_ini() { if(access("/GBA_ExpLoader.ini", F_OK) == 0) { fini = fopen("/GBA_ExpLoader.ini", "rb"); - if(access(ini.save_dir, F_OK) != 0)mkdir(ini.save_dir, 0777); - if(access(ini.sign_dir, F_OK) != 0)mkdir(ini.sign_dir, 0777); } else { fini = fopen("/GBA_ExpLoader.ini", "wb"); if (fini) { @@ -120,19 +118,15 @@ void GBA_ini() { while(p < len) { p++; - if(rwbuf[p - 1] == 0x0A) - break; + if(rwbuf[p - 1] == 0x0A)break; } } fclose(fini); - if(ini.save_dir[0] != '/') - strcpy(ini.save_dir, "/GBA_SAVE"); - if(ini.sign_dir[0] != '/') - strcpy(ini.sign_dir, "/GBA_SIGN"); - - mkdir(ini.save_dir, 0777); - mkdir(ini.sign_dir, 0777); + if(ini.save_dir[0] != '/')strcpy(ini.save_dir, "/GBA_SAVE"); + if(ini.sign_dir[0] != '/')strcpy(ini.sign_dir, "/GBA_SIGN"); + if(access(ini.save_dir, F_OK) != 0)mkdir(ini.save_dir, 0777); + if(access(ini.sign_dir, F_OK) != 0)mkdir(ini.sign_dir, 0777); } diff --git a/arm9/source/ctrl_tbl.cpp b/arm9/source/ctrl_tbl.cpp index 99c4d2a..b8617ae 100644 --- a/arm9/source/ctrl_tbl.cpp +++ b/arm9/source/ctrl_tbl.cpp @@ -34,7 +34,7 @@ void ctrl_get() { memset((u8*)&ctrl, 0, sizeof(struct ctrl_tbl)); - if(carttype != 5 && !isSuperCard && !isOmega) { + if(carttype != 5 && !isSuperCard/* && !isOmega*/) { _RamPG(); ReadSram(SRAM_ADDR, (u8*)&ctrl, sizeof(struct ctrl_tbl)); _RamSave(0); @@ -43,9 +43,9 @@ void ctrl_get() { if (isSuperCard) { sprintf(expfile, "%s/SUPERCRD.dat", ini.sign_dir); - } else if (isOmega) { + } else /*if (isOmega) { sprintf(expfile, "%s/OMEGA.dat", ini.sign_dir); - } else { + } else*/ { sprintf(expfile, "%s/EXP128K.dat", ini.sign_dir); } exp = fopen(expfile, "rb"); @@ -59,7 +59,7 @@ void ctrl_set() { FILE *exp; char expfile[64]; - if(carttype != 5 && !isSuperCard && !isOmega) { + if(carttype != 5 && !isSuperCard/* && !isOmega*/) { _RamPG(); WriteSram(SRAM_ADDR, (u8*)&ctrl, sizeof(struct ctrl_tbl)); _RamSave(0); @@ -68,9 +68,9 @@ void ctrl_set() { if (isSuperCard) { sprintf(expfile, "%s/SUPERCRD.dat", ini.sign_dir); - } else if (isOmega) { + } else/* if (isOmega) { sprintf(expfile, "%s/OMEGA.dat", ini.sign_dir); - } else { + } else*/ { sprintf(expfile, "%s/EXP128K.dat", ini.sign_dir); } exp = fopen(expfile, "wb"); diff --git a/arm9/source/gba_patch.cpp b/arm9/source/gba_patch.cpp index 7e1ccb2..c7beec3 100644 --- a/arm9/source/gba_patch.cpp +++ b/arm9/source/gba_patch.cpp @@ -1551,10 +1551,26 @@ static void _patch_ram(u8 *buf, u32 ofs, const u8 *data, u32 size) { u16 *pdata; u32 i; + if (isOmega) { + u32 romAddress = (u32)buf; + if ((romAddress >= 0x08800000) && (romAddress < 0x09000000)) { + SetPSRampage(0); + } else if ((romAddress >= 0x09000000) && (romAddress < 0x09800000)) { + SetPSRampage(0x1000); + } else if ((romAddress >= 0x09800000) && (romAddress < 0x0A000000)) { + SetPSRampage(0x2000); + } else if ((romAddress >= 0x0A000000) && (romAddress < 0x0A800000)) { + SetPSRampage(0x3000); + } + } + + pbuf = (u16*)buf; pdata = (u16*)data; for(i = 0; i < size/2; i++, ofs++)pbuf[ofs] = pdata[i]; + + SetPSRampage(0); } static void _patch(u8 *buf, u32 ofs, const u8 *data, u32 size, u32 bend) { @@ -1632,12 +1648,12 @@ void gba_patch_Ram(u32 exp, char *name, int cart) { fmini = 124; - u8 _OmegaPage = 0; + // u8 _OmegaPage = 0; for(i = 1; i < PatchCnt; i++) { // EZ Flash Omega and it's silly mapping schemes.... :P - if (isOmega) { + /*if (isOmega) { if ((exp + PatchAddr[i]) >= 0x08800000 && (exp + PatchAddr[i]) < 0x09000000) { SetPSRampage(0); _OmegaPage = 0; @@ -1651,13 +1667,11 @@ void gba_patch_Ram(u32 exp, char *name, int cart) { SetPSRampage(0x3000); _OmegaPage = 0x03; } - } - - if (isOmega) { buf = (u8*)((exp + PatchAddr[i]) - (_OmegaPage * 0x00800000)); } else { buf = (u8*)(exp + PatchAddr[i]); - } + }*/ + buf = (u8*)(exp + PatchAddr[i]); switch(SaveType) { case 2: // EEPROM @@ -1868,7 +1882,7 @@ void gba_patch_Ram(u32 exp, char *name, int cart) { break; } } - if (isOmega)SetPSRampage(0); + // if (isOmega)SetPSRampage(0); } u32 gba_check_Ram1(u8 *buf, u32 bufsize, u32 size, u32 ofs) { @@ -1950,18 +1964,8 @@ void gba_check_Ram2(u32 exp, u8 *buf, u32 bufsize, u32 size) { SetPSRampage(OmegaPage); exp = PSRAMBase_S98; } - /*if (exp >= 0x08800000 && exp < 0x09000000) { - SetPSRampage(0); - } else if (exp >= 0x09000000 && exp < 0x09800000) { - SetPSRampage(0x1000); - } else if (exp >= 0x0A000000 && exp < 0x0A800000) { - SetPSRampage(0x2000); - } else if (exp >= 0x0B000000 && exp < 0x0B800000) { - SetPSRampage(0x3000); - }*/ } // u32 currentAddress = exp; - // if (isOmega && currentAddress >= 0x08800000 && _OmegaPage != 0)currentAddress = (currentAddress - (_OmegaPage * 0x00800000)); _ReadPSram(exp, buf, bufsize+0x400); // dmaCopy((void *)exp, buf, bufsize); // dmaCopyWords(3, buf, (void *)exp, 0x100000); diff --git a/arm9/source/gbaldr.itcm.cpp b/arm9/source/gbaldr.itcm.cpp index f424262..3bf387f 100644 --- a/arm9/source/gbaldr.itcm.cpp +++ b/arm9/source/gbaldr.itcm.cpp @@ -30,26 +30,25 @@ //#include //basic print funcionality -#define MAX_NOR 0x2000000 // 32MByte -#define MAX_NORPLUS 0x4000000 // 64MByte (3 in 1 Plus) -#define MAX_PSRAM 0x1000000 // 16MByte -#define SRAM_PAGE_SIZE 0x1000 // SRAM Page Size -#define MAX_SRAM 0x80000 // 4MBit/512KByte total SRAM +#define MAX_NOR 0x2000000 // 32MByte +#define MAX_NORPLUS 0x4000000 // 64MByte (3 in 1 Plus) +#define MAX_PSRAM 0x1000000 // 16MByte +#define SRAM_PAGE_SIZE 0x10000 // SRAM Page Size +#define MAX_SRAM 0x80000 // 4MBit/512KByte total SRAM -#define USE_SRAM 0x20000 // 128KByte -#define USE_SRAM_PG 48 // 0x0A030000-0A031FFF +#define USE_SRAM 0x20000 // 128KByte +#define USE_SRAM_PG 48 // 0x0A030000-0A031FFF #define USE_SRAM_PG_EZ4 11 // 0x0A008000-0A00FFFF #define USE_SRAM_PG_EWN 10 // 0x0A020000-0A02FFFF #define USE_SRAM_PG_EWN128 9 // 0x0A010000-0A01FFFF #define USE_SRAM_PG_M3 6 - #define USE_SRAM_NOR 16 // 0x0A010000-0A02FFFF - #define USE_SRAM_PSR 50 // 0x0A032000-0A051FFF #define USE_SRAM_PSR_EZ4 16 // 0x0A010000-0A02FFFF #define USE_SRAM_PSR_EWN 8 // 0x0A000000-0A01FFFF #define USE_SRAM_PSR_M3 4 +#define USE_SRAM_PSR_OMEGA 0 #define PSRAM_BUF 0x8000 // 32KB @@ -389,72 +388,40 @@ int check_M3() { } -void _RamPG() { - if (isSuperCard)return; - if (isOmega)return; - switch (carttype) { - case 3: - SetRampage(USE_SRAM_PG_EZ4); - return; - case 4: - SetEWINRam(USE_SRAM_PG_EWN); - return; - case 5: - SetEWINRam(USE_SRAM_PG_EWN128); - return; - case 6: - SetM3Ram(USE_SRAM_PG_M3); - return; +static bool CheckForSuperCard() { + if (CheckSuperCardID() == 0x227E0000) { + carttype = 6; + is3in1Plus = false; + isSuperCard = true; + return true; } - if (isOmega) { - // Omega_Bank_Switching(0); - // SetRampage(0x20); - SetRampage(0x40); - // SetRampage(USE_SRAM_PG); - - } else { - SetRampage(USE_SRAM_PG); - } - // SetRampage(USE_SRAM_PG); - return; + return false; } -void _RamSave(int bnk) { - if (isSuperCard)return; - // if (isOmega)return; - switch (carttype) { - case 3: - SetRampage(USE_SRAM_PSR_EZ4 + bnk * 16); - return; - case 6: - SetM3Ram(USE_SRAM_PSR_M3 + bnk); - return; +static bool CheckForOmega() { // EZFlash Omega + SetRompage(0x8002); + if (CheckOmegaID() == 0x227EEA00) { + carttype = 1; + is3in1Plus = false; + isSuperCard = false; + isOmega = true; + // Set_AUTO_save(0); + return true; } - - if(carttype >= 4) { - SetEWINRam(USE_SRAM_PSR_EWN + bnk); - return; - } - - if(GBAmode == 0) { - if (isOmega) { - SetRampage(bnk * 0x10); - /*switch (bnk) { - case 0: SetRampage(0); break; - case 1: SetRampage(0x10); break; - default: return; - }*/ - } else { - SetRampage(USE_SRAM_PSR + bnk * 16); - } - } else { - if (isOmega)return; - SetRampage(USE_SRAM_NOR + bnk * 16); - } - return; + return false; } int checkFlashID() { + // Check for special carts before using standard checks. + if (CheckForOmega())return carttype; + if (CheckForSuperCard())return carttype; + + // Moved this out of main.c to avoid causing issues with Omega/Non EZ Flash carts. + CloseNorWrite(); + SetRompage(0); + SetRampage(16); + SetShake(0x08); + int ewin; u32 id; @@ -493,27 +460,60 @@ int checkFlashID() { carttype = 1; return carttype; case 0x227E2220: carttype = 3; return carttype; // EZ4 - case 0x227EEA00: // EZFlash Omega - carttype = 1; - is3in1Plus = false; - isSuperCard = false; - isOmega = true; - SetSDControl(0); - Set_RTC_status(1); - gl_ingame_RTC_open_status = Read_SET_info(13); - if ((gl_ingame_RTC_open_status != 0x0) && (gl_ingame_RTC_open_status != 0x1))gl_ingame_RTC_open_status = 0x1; - // Set_AUTO_save(0); - // Omega_Bank_Switching(0); - return carttype; - case 0x227E0000: // SuperCard - carttype = 6; - is3in1Plus = false; - isSuperCard = true; - return carttype; default: return 0; // Unsupported/Unimplemented Cart ID } } + +void _RamPG() { + if (isSuperCard)return; + switch (carttype) { + case 3: + SetRampage(USE_SRAM_PG_EZ4); + return; + case 4: + SetEWINRam(USE_SRAM_PG_EWN); + return; + case 5: + SetEWINRam(USE_SRAM_PG_EWN128); + return; + case 6: + SetM3Ram(USE_SRAM_PG_M3); + return; + } + if (isOmega) { SetRampage(16); } else { SetRampage(USE_SRAM_PG); } + return; +} + +void _RamSave(int bnk) { + if (isSuperCard)return; + switch (carttype) { + case 3: + SetRampage(USE_SRAM_PSR_EZ4 + bnk * 16); + return; + case 6: + SetM3Ram(USE_SRAM_PSR_M3 + bnk); + return; + } + + if(carttype >= 4) { + SetEWINRam(USE_SRAM_PSR_EWN + bnk); + return; + } + + if(GBAmode == 0) { + if (isOmega) { + SetRampage(USE_SRAM_PSR_OMEGA + (bnk * 16)); + } else { + SetRampage(USE_SRAM_PSR + bnk * 16); + } + } else { + if (isOmega) { SetRampage(USE_SRAM_PSR_OMEGA + (bnk * 16)); return; } + SetRampage(USE_SRAM_NOR + bnk * 16); + } + return; +} + bool checkSRAM_cnf() { int i; @@ -547,6 +547,7 @@ int checkSRAM(char *name) { } savesize = ctrl.save_siz[GBAmode]; + // if (isOmega && savesize > 0x10000)savesize = 0x10000; if((savesize < 0x2000) || (savesize > USE_SRAM)) { savesize = 0x10000; ctrl.save_siz[GBAmode] = savesize; @@ -649,53 +650,11 @@ bool getSaveFilename(int sel, char *savename) *******************/ bool checkBackup() { - if(GBAmode == 1)return true; - - if(ctrl.save_flg[GBAmode] == 0xFF)return false; - + if (GBAmode == 1) { return true; } else if (ctrl.save_flg[GBAmode] == 0xFF) { return false; } return true; } -void writeSramToFile(char *savename) { - FILE *saver; - u32 len; - - if(savename[0] == 0) return; - -// if((GBAmode == 0) && (checkBackup() == false))return; - -// getSaveFilename(filename, tbuf); - sprintf(tbuf, "%s/%s", ini.save_dir, savename); - saver = fopen(tbuf, "wb"); -// memset(rwbuf, 0, USE_SRAM / 2); -// OpenNorWrite(); - - _RamSave(0); - - if (isOmega) { ReadSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { ReadSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } - - if(saver != NULL) { - len = USE_SRAM / 2; - if(len > savesize)len = savesize; - fwrite(rwbuf, 1, len, saver); - } - if((savesize > (USE_SRAM / 2)) && !isSuperCard) { - _RamSave(1); - if (isOmega) { ReadSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { ReadSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } - if(saver != NULL)fwrite(rwbuf, 1, USE_SRAM / 2, saver); - } - fclose(saver); - - ctrl.save_flg[GBAmode] = 0xFF; - - if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)OpenNorWrite(); - - ctrl_set(); - - if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)CloseNorWrite(); -} - void SRAMdump(int cmd) { FILE *dmp; int i; @@ -711,12 +670,13 @@ void SRAMdump(int cmd) { case 4: mx = 4; break; case 5: mx = 2; break; case 6: - if (isSuperCard) { mx = 1; } else { mx = 16; } + mx = 16; + if (isSuperCard)mx = 1; break; } sprintf(name, "%s/SRAM.BIN", ini.save_dir); - + if(cmd == 0) { dsp_bar(4, -1); dmp = fopen(name, "wb"); @@ -726,13 +686,14 @@ void SRAMdump(int cmd) { } else if (!isSuperCard) { if((carttype >= 4)) { SetEWINRam(8 + i); + } else if (isOmega) { + SetRampage(USE_SRAM_PSR_OMEGA + (i * 16)); } else { - // if (isOmega && (i > 4))Omega_Bank_Switching(1); - SetRampage(i * 16); + SetRampage(i * 16); } } - if (isOmega) { ReadSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { ReadSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } + ReadSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); if(dmp != NULL)fwrite(rwbuf, 1, USE_SRAM / 2, dmp); @@ -759,7 +720,7 @@ void SRAMdump(int cmd) { dsp_bar(5, -1); dmp = fopen(name, "rb"); if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)OpenNorWrite(); - + if (isOmega)Omega_Bank_Switching(0); for(i = 0; i < mx; i++) { @@ -771,12 +732,15 @@ void SRAMdump(int cmd) { } else { if((carttype >= 4) && !isSuperCard) { SetEWINRam(8 + i); + } else if (isOmega) { + SetRampage(USE_SRAM_PSR_OMEGA + (i * 16)); } else { - // if (isOmega && (i > 4))Omega_Bank_Switching(1); SetRampage(i * 16); } } - if (isOmega) { WriteSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } + + WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); + if (i == 0) { dsp_bar(5, 0); } else { @@ -799,7 +763,6 @@ void SRAMdump(int cmd) { if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)CloseNorWrite(); } fclose(dmp); - // if (isOmega)Omega_Bank_Switching(0); _RamSave(0); dsp_bar(-1, 100); } @@ -810,16 +773,16 @@ void blankSRAM(char *savename) { if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)OpenNorWrite(); - _RamSave(0); - if (isOmega)Omega_Bank_Switching(0); - if (isOmega) { WriteSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } + _RamSave(0); + + WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); // if(carttype != 5) { - if (!isSuperCard) { + if (!isSuperCard && !isOmega) { _RamSave(1); - if (isOmega) { WriteSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } + WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } // } @@ -832,6 +795,45 @@ void blankSRAM(char *savename) { if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)CloseNorWrite(); } +void writeSramToFile(char *savename) { + FILE *saver; + u32 len; + + if(savename[0] == 0) return; + +// if((GBAmode == 0) && (checkBackup() == false))return; + +// getSaveFilename(filename, tbuf); + sprintf(tbuf, "%s/%s", ini.save_dir, savename); + saver = fopen(tbuf, "wb"); +// memset(rwbuf, 0, USE_SRAM / 2); +// OpenNorWrite(); + + _RamSave(0); + + ReadSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); + + if(saver != NULL) { + len = USE_SRAM / 2; + if(len > savesize)len = savesize; + fwrite(rwbuf, 1, len, saver); + } + if((savesize > (USE_SRAM / 2)) && !isSuperCard && !isOmega) { + _RamSave(1); + ReadSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); + if(saver != NULL)fwrite(rwbuf, 1, USE_SRAM / 2, saver); + } + fclose(saver); + + ctrl.save_flg[GBAmode] = 0xFF; + + if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)OpenNorWrite(); + + ctrl_set(); + + if((carttype < 4) && !isSuperCard && !isOmega && !is3in1Plus)CloseNorWrite(); +} + void writeSramFromFile(char *savename) { FILE *saver; @@ -857,21 +859,21 @@ void writeSramFromFile(char *savename) { // OpenNorWrite(); + if (isOmega)Omega_Bank_Switching(0); + _RamSave(0); memset(rwbuf, 0xFF, USE_SRAM / 2); fread(rwbuf, 1, USE_SRAM / 2, saver); - if (isOmega)Omega_Bank_Switching(0); - - if (isOmega) { WriteSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } + WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); // if(carttype != 5) { - if((savesize > (USE_SRAM / 2)) && !isSuperCard) { + if((savesize > (USE_SRAM / 2)) && !isSuperCard && !isOmega) { _RamSave(1); memset(rwbuf, 0xFF, USE_SRAM / 2); fread(rwbuf, 1, USE_SRAM / 2, saver); - if (isOmega) { WriteSram(SRAM_ADDR_OMEGA, rwbuf, USE_SRAM / 2); } else { WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); } + WriteSram(SRAM_ADDR, rwbuf, USE_SRAM / 2); _RamSave(0); } // } @@ -996,6 +998,7 @@ int writeFileToNor(int sel) { int writeFileToRam(int sel) { + FILE *gbaFile; char savName[512]; u32 siz; @@ -1032,15 +1035,20 @@ int writeFileToRam(int sel) { if((carttype < 4) && !isSuperCard && !isOmega) { if(carttype == 3) { SetRompage(0x300 - 3); } else { SetRompage(384 - 3); } OpenNorWrite(); + } else if (isOmega) { + SetSDControl(0); + Set_RTC_status(1); + SetPSRampage(0); + // Omega_InitFatBuffer(OMEGA_UNKNOWN, Omega_SetSaveSize(OMEGA_UNKNOWN), fs[sel].filesize); } + // savesize = gba_check(gbaFile, fs[sel].filesize, rwbuf, 0x100000); // if(savesize == 0)savesize = 0x8000; dsp_bar(2, -1); + gba_check_int(fs[sel].filename); - if (isOmega)SetPSRampage(0); - DC_FlushRange((void*)rwbuf, (0x100000 + 0x400)); for(siz = 0; siz < fs[sel].filesize; siz += 0x100000, exp += 0x100000) { @@ -1051,7 +1059,7 @@ int writeFileToRam(int sel) { if(siz == 0 && gba)header_rep(rwbuf); - if (!isOmega)savesize = gba_check_Ram1(rwbuf, 0x100000, fs[sel].filesize, siz); + savesize = gba_check_Ram1(rwbuf, 0x100000, fs[sel].filesize, siz); // EZ Flash Omega and it's silly mapping schemes.... :P if (isOmega) { @@ -1062,20 +1070,23 @@ int writeFileToRam(int sel) { } } - // _WritePSram(exp, rwbuf, 0x100000); dmaCopy((void*)rwbuf, (void*)exp, 0x100000); + // _WritePSram(exp, rwbuf, 0x100000); // dmaCopyWords(3, rwbuf, (void *)exp, 0x100000); } - + DC_FlushRange((void*)rwbuf, 0x100000); - if (isOmega)SetPSRampage(0); + if (isOmega) { + if (savesize > 0x10000)savesize = 0x10000; + SetPSRampage(0); + } dsp_bar(2, 100); - - bool allowPatches = true; - + if (isSuperCard) { + if (savesize > 0x10000)savesize = 0x10000; + bool allowPatches = true; dsp_bar(-1, 100); dsp_bar(3, -1); dsp_bar(3, 25); @@ -1099,7 +1110,6 @@ int writeFileToRam(int sel) { if (!isSuperCard)gba_patch_Ram(exps, fs[sel].filename, carttype); fclose(gbaFile); - // if(carttype == 5 && savesize == 0x20000) { // dsp_bar(-1, 100); @@ -1107,11 +1117,10 @@ int writeFileToRam(int sel) { // } // getSaveFilename(sel, savName); - dsp_bar(5, 50); if(cmd >= 0) { writeSramFromFile(savName); } else { blankSRAM(savName); } - + if((carttype < 4) && !isSuperCard && !isOmega)CloseNorWrite(); _RamSave(0); @@ -1129,9 +1138,7 @@ int writeFileToRam(int sel) { if (isSuperCard)return 0; if (isOmega) { - Set_RTC_status(gl_ingame_RTC_open_status); rtc_toggle(true); - // Omega_InitFatBuffer(0x10); SetRompage(0x200); return 0; } diff --git a/arm9/source/main.c b/arm9/source/main.c index b00af7b..7be09cf 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -48,7 +48,7 @@ extern uint16* SubScreen; #define BG_256_COLOR (BIT(7)) -#define VERSTRING "v0.63" +#define VERSTRING "v0.64" int numFiles = 0; int numGames = 0; @@ -434,6 +434,7 @@ int rumble_cmd() { if(ky & KEY_A) break; if(ky & KEY_L) { GBAmode = 1; + if (isOmega)GBAmode = 0; setGBAmode(); cmd = -1; break; @@ -822,11 +823,7 @@ int gba_sel() { if(softReset && (carttype > 2)) { cmd = 3; break; - } /*else if (softReset && isOmega) { - cmd = 3; - break; - }*/ - if(GBAmode < cn && carttype <= 2) { + } else if(GBAmode < cn && carttype <= 2) { GBAmode++; if ((GBAmode == 1) && isOmega)GBAmode++; setGBAmode(); @@ -842,13 +839,16 @@ int gba_sel() { if(ky & KEY_START) { - if(softReset) { + if(softReset && !isOmega) { cmd = 99; if(carttype == 1) { SetRompage(0); SetRampage(16); } break; + } else if (isOmega && (GBAmode == 0)) { + SetRampage(0x8002); + gbaMode(); } } if(ky & KEY_SELECT) { @@ -1007,10 +1007,10 @@ REG_EXMEMCNT = (reg & 0xFFE0) | (1 << 4) | (1 << 2) | 1; if(isDSiMode()) { err_cnf(14, 15); turn_off(0); } - CloseNorWrite(); + /*CloseNorWrite(); SetRompage(0); SetRampage(16); - SetShake(0x08); + SetShake(0x08);*/ /******** @@ -1036,7 +1036,7 @@ REG_EXMEMCNT = (reg & 0xFFE0) | (1 << 4) | (1 << 2) | 1; if (is3in1Plus) { ShinoPrint_SUB( SubScreen, 23*6, 1*12-2, (u8*)"[3in1Pls]", 0, 0, 0 ); } else if (isOmega) { - ShinoPrint_SUB( SubScreen, 23*6, 1*12-2, (u8*)"[ Omega ]", 0, 0, 0 ); + ShinoPrint_SUB( SubScreen, 23*6, 1*12-2, (u8*)"[ 兌 DE ]", 0, 0, 0 ); } else { ShinoPrint_SUB( SubScreen, 23*6, 1*12-2, (u8*)" [ 3in1 ]", 0, 0, 0 ); } @@ -1098,7 +1098,7 @@ inp_key(); *(vu8*)0x027FFC35 = 0x01; // GBA rwbuf = (u8*)malloc(0x100000 + 1024); - + GBA_ini(); if(!checkSRAM_cnf() && (carttype != 5) && (cnf_inp(9, 10) & KEY_B))turn_off(softReset); @@ -1117,12 +1117,16 @@ inp_key(); dsp_bar(4, -1); dsp_bar(4, 0); for (int I = 0; I < 30; I++)swiWaitForVBlank(); - if(save_sel(1, filename) >= 0)writeSramToFile(filename); - dsp_bar(4, 50); - for (int I = 0; I < 30; I++)swiWaitForVBlank(); - dsp_bar(4, 100); - for (int I = 0; I < 30; I++)swiWaitForVBlank(); - dsp_bar(-1, 100); + if(save_sel(1, filename) >= 0) { + writeSramToFile(filename); + dsp_bar(4, 50); + for (int I = 0; I < 30; I++)swiWaitForVBlank(); + dsp_bar(4, 100); + for (int I = 0; I < 30; I++)swiWaitForVBlank(); + dsp_bar(-1, 100); + } else { + dsp_bar(-1, 100); + } } getGBAmode(); @@ -1156,15 +1160,14 @@ inp_key(); break; case 3: if((carttype != 4) && !isSuperCard && !isOmega) { - /*if (isOmega) { - Set_RTC_status(gl_ingame_RTC_open_status); - SetRompage(0x200);*/ - // } else { - if (is3in1Plus) { SetRompage(0x100); } else { SetRompage(0x300); } - OpenNorWrite(); - // } + if (isOmega) { + SetRompage(0x8002); + } else { + if (is3in1Plus) { SetRompage(0x100); } else { SetRompage(0x300); } + OpenNorWrite(); + } } - if(!isSuperCard)RamClear(); + if(!isSuperCard && !isOmega)RamClear(); break; }