From f9251ba0ceac8ddd760d59185bb875a0f1bc670c Mon Sep 17 00:00:00 2001 From: ApacheThunder Date: Sun, 25 May 2025 13:39:52 -0500 Subject: [PATCH] Implement second SRAM bank for SuperCards. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Implemented unused second SRAM bank for SuperCards for storing GBA-Exploader metadata. Note that game patches are not yet updated for this so games like Pokémon can't use it yet. --- Makefile | 2 +- arm9/include/dsCard.itcm.cpp | 1 + arm9/include/io_sc_common.c | 2 +- arm9/source/ctrl_tbl.cpp | 12 ++++---- arm9/source/gbaldr.itcm.cpp | 57 +++++++++++++++++++++++++++++------- arm9/source/main.c | 2 +- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 3ef42ca..39ecb99 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ export TARGET := GBA_ExpLoader export TOPDIR := $(CURDIR) export VERSION_MAJOR := 0 -export VERSION_MINOR := 66 +export VERSION_MINOR := 67 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.itcm.cpp b/arm9/include/dsCard.itcm.cpp index faad7fb..08e5b20 100644 --- a/arm9/include/dsCard.itcm.cpp +++ b/arm9/include/dsCard.itcm.cpp @@ -265,6 +265,7 @@ u32 CheckSuperCardID() { // _SC_changeMode16(0x1510); *(vu16*)(FlashBase) = 0x4D54; if (*(vu16*)(FlashBase) == 0x4D54) { + _SC_changeMode(SC_MODE_RAM_RO); ID = 0x227E2202; return 0x227E0000; } diff --git a/arm9/include/io_sc_common.c b/arm9/include/io_sc_common.c index d448af3..45c06f2 100644 --- a/arm9/include/io_sc_common.c +++ b/arm9/include/io_sc_common.c @@ -34,7 +34,7 @@ #endif /*----------------------------------------------------------------- -_SC_changeMode (was SC_Unlock) +_SC_changeMode (was SC_Unlock) (toggling read/write of PSRAM also toggles SRAM bank!) Added by MightyMax Modified by Chishm Modified again by loopy diff --git a/arm9/source/ctrl_tbl.cpp b/arm9/source/ctrl_tbl.cpp index c02e00f..a6db0e9 100644 --- a/arm9/source/ctrl_tbl.cpp +++ b/arm9/source/ctrl_tbl.cpp @@ -35,16 +35,16 @@ void ctrl_get() { memset((u8*)&ctrl, 0, sizeof(struct ctrl_tbl)); - if (((carttype != 5) && !isSuperCard && !isOmega) || isOmegaDE) { + if (((carttype != 5) && /*!isSuperCard &&*/ !isOmega) || isOmegaDE) { _RamPG(); ReadSram(SRAM_ADDR, (u8*)&ctrl, sizeof(struct ctrl_tbl)); _RamSave(0); return; } - if (isSuperCard) { + /*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 { sprintf(expfile, "%s/EXP128K.dat", ini.sign_dir); @@ -60,16 +60,16 @@ void ctrl_set() { FILE *exp; char expfile[64]; - if (((carttype != 5) && !isSuperCard && !isOmega) || isOmegaDE) { + if (((carttype != 5) && /*!isSuperCard && */!isOmega) || isOmegaDE) { _RamPG(); WriteSram(SRAM_ADDR, (u8*)&ctrl, sizeof(struct ctrl_tbl)); _RamSave(0); return; } - if (isSuperCard) { + /*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 { sprintf(expfile, "%s/EXP128K.dat", ini.sign_dir); diff --git a/arm9/source/gbaldr.itcm.cpp b/arm9/source/gbaldr.itcm.cpp index c90b0c5..427e25f 100644 --- a/arm9/source/gbaldr.itcm.cpp +++ b/arm9/source/gbaldr.itcm.cpp @@ -28,6 +28,7 @@ #include "dsCard.h" #include "sc_patches.h" #include "sc_sram.h" +#include "io_sc_common.h" //#include //basic print funcionality @@ -483,7 +484,7 @@ int checkFlashID() { void _RamPG() { - if (isSuperCard)return; + // if (isSuperCard)return; switch (carttype) { case 3: SetRampage(USE_SRAM_PG_EZ4); @@ -495,7 +496,11 @@ void _RamPG() { SetEWINRam(USE_SRAM_PG_EWN128); return; case 6: - SetM3Ram(USE_SRAM_PG_M3); + if (isSuperCard) { + _SC_changeMode(SC_MODE_RAM); + } else { + SetM3Ram(USE_SRAM_PG_M3); + } return; } if (isOmega) { @@ -505,19 +510,27 @@ void _RamPG() { } SetRampage(USE_SRAM_PG_OMEGA); } else { - SetRampage(USE_SRAM_PG); + SetRampage(USE_SRAM_PG); } return; } void _RamSave(int bnk) { - if (isSuperCard)return; + if (isSuperCard && (bnk > 1))return; switch (carttype) { case 3: SetRampage(USE_SRAM_PSR_EZ4 + bnk * 16); return; case 6: - SetM3Ram(USE_SRAM_PSR_M3 + bnk); + if (isSuperCard) { + if (bnk == 0) { + _SC_changeMode(SC_MODE_RAM_RO); + } else { + _SC_changeMode(SC_MODE_RAM); + } + } else { + SetM3Ram(USE_SRAM_PSR_M3 + bnk); + } return; } @@ -590,6 +603,7 @@ int checkSRAM(char *name) { } // if (isOmega && (savesize > 0x10000))savesize = 0x10000; + if (isSuperCard && (savesize > 0x10000))savesize = 0x10000; strcpy(name, (char *)ctrl.sav_nam[GBAmode]); ln = strlen(name) - 3; @@ -708,8 +722,11 @@ void SRAMdump(int cmd) { case 4: mx = 4; break; case 5: mx = 2; break; case 6: - mx = 16; - if (isSuperCard)mx = 1; + if (isSuperCard) { + mx = 2; + } else { + mx = 16; + } break; } @@ -719,8 +736,16 @@ void SRAMdump(int cmd) { dsp_bar(4, -1); dmp = fopen(name, "wb"); for(i = 0; i < mx; i++) { - if((carttype == 6) && !isSuperCard) { - SetM3Ram(i); + if (carttype == 6) { + if (isSuperCard) { + if (i == 0) { + _SC_changeMode(SC_MODE_RAM_RO); + } else { + _SC_changeMode(SC_MODE_RAM); + } + } else { + SetM3Ram(i); + } } else if (!isSuperCard) { if((carttype >= 4)) { SetEWINRam(8 + i); @@ -767,8 +792,16 @@ void SRAMdump(int cmd) { memset(rwbuf, 0, USE_SRAM / 2); if(dmp != NULL) fread(rwbuf, 1, USE_SRAM / 2, dmp); - if((carttype == 6) && !isSuperCard) { - SetM3Ram(i); + if (carttype == 6) { + if (isSuperCard) { + if (i == 0) { + _SC_changeMode(SC_MODE_RAM_RO); + } else { + _SC_changeMode(SC_MODE_RAM); + } + } else { + SetM3Ram(i); + } } else { if((carttype >= 4) && !isSuperCard) { SetEWINRam(8 + i); @@ -1081,6 +1114,8 @@ int writeFileToRam(int sel) { Set_RTC_status(1); SetPSRampage(0); // Omega_InitFatBuffer(OMEGA_UNKNOWN, Omega_SetSaveSize(OMEGA_UNKNOWN), fs[sel].filesize); + } else if (isSuperCard) { + _SC_changeMode(SC_MODE_RAM); } // savesize = gba_check(gbaFile, fs[sel].filesize, rwbuf, 0x100000); diff --git a/arm9/source/main.c b/arm9/source/main.c index 25a9ea5..446dfe2 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -49,7 +49,7 @@ extern uint16* SubScreen; #define BG_256_COLOR (BIT(7)) -#define VERSTRING "v0.66" +#define VERSTRING "v0.67" int numFiles = 0; int numGames = 0;