Skip to content

Commit

Permalink
Add prompt for Omega DE...
Browse files Browse the repository at this point in the history
* Now prompts if user is using DE or regaulr Omega if EZFlash Omega is
detected. Regular omega can be used if soft reset method is used (aka, a
cart like EZFlash Parellel is used to cause console to reboot on
reinsert). If DE mode is selected setRamPage is set to normal range and
will make it use FRAM chip. Regular Omega will use page 0x40 for RTS
section of SRAM. (normal range is read only for some reason. FPGA must
unlock it after sending specific table data to SD card buffer register
which I have not got working yet)
* NDS files can now be booted. Since bootloader from nds-hb-menu was
added to fix soft-reset stuff I might as well just add in support to
boot NDS files. :P
  • Loading branch information
ApacheThunder committed Aug 12, 2024
1 parent ead3daa commit b0e0250
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export TARGET := GBA_ExpLoader
export TOPDIR := $(CURDIR)

export VERSION_MAJOR := 0
export VERSION_MINOR := 64
export VERSION_MINOR := 65
export VERSTRING := $(VERSION_MAJOR).$(VERSION_MINOR)

# GMAE_ICON is the image used to create the game icon, leave blank to use default rule
Expand Down
7 changes: 7 additions & 0 deletions arm9/include/dsCard.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ typedef bool BOOL;
void Omega_Bank_Switching(u8 bank);
void Omega_InitFatBuffer(BYTE saveMODE, u32 saveSize, u32 gameSize);
u32 Omega_SetSaveSize(u8 SaveMode);
void SetSPIWrite(u16 control);
void SetSPIControl(u16 control);
void SPI_Enable();
void SPI_Disable();
void SPI_Write_Enable();
void SPI_Write_Disable();
u16 Read_FPGA_ver();
void OpenRamWrite();
void CloseRamWrite();
void SetSerialMode();
Expand Down
34 changes: 34 additions & 0 deletions arm9/include/dsCard.itcm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,40 @@ u32 Omega_SetSaveSize(u8 SaveMode) {
}
}

void SetSPIWrite(u16 control) {
*(u16*)0x9fe0000 = 0xd200;
*(u16*)0x8000000 = 0x1500;
*(u16*)0x8020000 = 0xd200;
*(u16*)0x8040000 = 0x1500;
*(u16*)0x9680000 = control;
*(u16*)0x9fc0000 = 0x1500;
}

void SetSPIControl(u16 control) {
*(u16*)0x9fe0000 = 0xd200;
*(u16*)0x8000000 = 0x1500;
*(u16*)0x8020000 = 0xd200;
*(u16*)0x8040000 = 0x1500;
*(u16*)0x9660000 = control;
*(u16*)0x9fc0000 = 0x1500;
}

void SPI_Enable() { SetSPIControl(1); }

void SPI_Disable() { SetSPIControl(0); }

void SPI_Write_Enable() { SetSPIWrite(1); }

void SPI_Write_Disable() { SetSPIWrite(0); }

u16 Read_FPGA_ver() {
u16 Read_SPI;
SPI_Enable();
Read_SPI = *(vu16*)0x9E00000;
SPI_Disable();
return Read_SPI;
}



void SetRampage(u16 page) {
Expand Down
15 changes: 8 additions & 7 deletions arm9/source/ctrl_tbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C" {
extern void _RamPG(void);
extern void _RamSave(int bnk);
extern bool isOmega;
extern bool isOmegaDE;
extern bool isSuperCard;

#ifdef __cplusplus
Expand All @@ -34,18 +35,18 @@ void ctrl_get() {

memset((u8*)&ctrl, 0, sizeof(struct ctrl_tbl));

if(carttype != 5 && !isSuperCard/* && !isOmega*/) {
if (((carttype != 5) && !isSuperCard && !isOmega) || isOmegaDE) {
_RamPG();
ReadSram(SRAM_ADDR, (u8*)&ctrl, sizeof(struct ctrl_tbl));
_RamSave(0);
return;
}

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");
Expand All @@ -59,7 +60,7 @@ void ctrl_set() {
FILE *exp;
char expfile[64];

if(carttype != 5 && !isSuperCard/* && !isOmega*/) {
if (((carttype != 5) && !isSuperCard && !isOmega) || isOmegaDE) {
_RamPG();
WriteSram(SRAM_ADDR, (u8*)&ctrl, sizeof(struct ctrl_tbl));
_RamSave(0);
Expand All @@ -68,9 +69,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");
Expand Down
1 change: 1 addition & 0 deletions arm9/source/ctrl_tbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct GBA_File {
char gamecode[5];
u32 type;
u32 filesize;
int isNDSFile;
};


Expand Down
144 changes: 101 additions & 43 deletions arm9/source/gbaldr.itcm.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <nds.h>
#include <nds/arm9/dldi.h>

#include <fat.h>
#include <sys/iosupport.h>
Expand Down Expand Up @@ -30,25 +31,26 @@

//#include <nds/arm9/console.h> //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 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_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 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_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 40
#define USE_SRAM_PSR_OMEGA_DE 0

#define PSRAM_BUF 0x8000 // 32KB

Expand Down Expand Up @@ -76,10 +78,17 @@ extern int GBAmode;

static u32 savesize;

static const char *validExtensions[3] = {
".GBA",
".BIN",
".NDS"
};

int carttype = 0;
bool isSuperCard = false;
bool is3in1Plus = false;
bool isOmega = false;
bool isOmegaDE = false;

extern int save_sel(int mod, char *name);
extern u16 gl_ingame_RTC_open_status;
Expand Down Expand Up @@ -390,7 +399,7 @@ int check_M3() {

static bool CheckForSuperCard() {
if (CheckSuperCardID() == 0x227E0000) {
carttype = 6;
carttype = 6;
is3in1Plus = false;
isSuperCard = true;
return true;
Expand All @@ -401,11 +410,21 @@ static bool CheckForSuperCard() {
static bool CheckForOmega() { // EZFlash Omega
SetRompage(0x8002);
if (CheckOmegaID() == 0x227EEA00) {
Set_AUTO_save(0);
carttype = 1;
is3in1Plus = false;
isSuperCard = false;
isOmega = true;
// Set_AUTO_save(0);
isOmegaDE = false;
/*char ct[4];
ct[0] = (io_dldi_data->ioInterface.ioType & 0xFF);
ct[1] = ((io_dldi_data->ioInterface.ioType >> 8) & 0xFF);
ct[2] = ((io_dldi_data->ioInterface.ioType >> 16) & 0xFF);
ct[3] = ((io_dldi_data->ioInterface.ioType >> 24) & 0xFF);
ct[4] = 0;
if ((ct[0] != 'E') && (ct[1] != 'Z') && (ct[2] != '5') && (ct[3] != 'N'))isOmegaDE = true;*/
/*u16 fpgaVer = (Read_FPGA_ver() & 0xF000);
if (fpgaVer != 0 && fpgaVer != 0xE000)isOmegaDE = true;*/
return true;
}
return false;
Expand Down Expand Up @@ -481,7 +500,15 @@ void _RamPG() {
SetM3Ram(USE_SRAM_PG_M3);
return;
}
if (isOmega) { SetRampage(16); } else { SetRampage(USE_SRAM_PG); }
if (isOmega) {
if (isOmegaDE) {
SetRampage(16);
return;
}
SetRampage(96);
} else {
SetRampage(USE_SRAM_PG);
}
return;
}

Expand All @@ -503,13 +530,24 @@ void _RamSave(int bnk) {

if(GBAmode == 0) {
if (isOmega) {
if (isOmegaDE) {
SetRampage(USE_SRAM_PSR_OMEGA_DE + (bnk * 16));
return;
}
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);
if (isOmega) {
if (isOmegaDE) {
SetRampage(USE_SRAM_PSR_OMEGA_DE + (bnk * 16));
return;
}
SetRampage(USE_SRAM_PSR_OMEGA + (bnk * 16));
} else {
SetRampage(USE_SRAM_NOR + bnk * 16);
}
}
return;
}
Expand Down Expand Up @@ -547,11 +585,13 @@ int checkSRAM(char *name) {
}

savesize = ctrl.save_siz[GBAmode];
// if (isOmega && savesize > 0x10000)savesize = 0x10000;
if((savesize < 0x2000) || (savesize > USE_SRAM)) {

if ((savesize < 0x2000) || (savesize > USE_SRAM)) {
savesize = 0x10000;
ctrl.save_siz[GBAmode] = savesize;
}

if (isOmega && (savesize > 0x10000))savesize = 0x10000;

strcpy(name, (char *)ctrl.sav_nam[GBAmode]);
ln = strlen(name) - 3;
Expand Down Expand Up @@ -664,9 +704,7 @@ void SRAMdump(int cmd) {
mx = 8;

switch (carttype) {
case 1:
if (isOmega)mx = 2;
break;
case 1: if (isOmega)mx = 2; break;
case 4: mx = 4; break;
case 5: mx = 2; break;
case 6:
Expand All @@ -681,15 +719,17 @@ void SRAMdump(int cmd) {
dsp_bar(4, -1);
dmp = fopen(name, "wb");
for(i = 0; i < mx; i++) {
if(carttype == 6 && !isSuperCard) {
if((carttype == 6) && !isSuperCard) {
SetM3Ram(i);
} else if (!isSuperCard) {
if((carttype >= 4)) {
SetEWINRam(8 + i);
} else if (isOmega) {
} else if (isOmega && !isOmegaDE) {
SetRampage(USE_SRAM_PSR_OMEGA + (i * 16));
} else if (isOmegaDE) {
SetRampage(USE_SRAM_PSR_OMEGA_DE + (i * 16));
} else {
SetRampage(i * 16);
if(!isSuperCard)SetRampage(i * 16);
}
}

Expand Down Expand Up @@ -727,15 +767,17 @@ void SRAMdump(int cmd) {
memset(rwbuf, 0, USE_SRAM / 2);
if(dmp != NULL)
fread(rwbuf, 1, USE_SRAM / 2, dmp);
if(carttype == 6) {
if((carttype == 6) && !isSuperCard) {
SetM3Ram(i);
} else {
if((carttype >= 4) && !isSuperCard) {
SetEWINRam(8 + i);
} else if (isOmega) {
} else if (isOmega && !isOmegaDE) {
SetRampage(USE_SRAM_PSR_OMEGA + (i * 16));
} else if (isOmegaDE) {
SetRampage(USE_SRAM_PSR_OMEGA_DE + (i * 16));
} else {
SetRampage(i * 16);
if (!isSuperCard)SetRampage(i * 16);
}
}

Expand Down Expand Up @@ -1225,13 +1267,19 @@ bool nameEndsWith (const string& name, const string& extension) {
return false;
}

bool isValidFile(const string& name) {
for (int i = 0; i < 3; i++) {
if (nameEndsWith(name, validExtensions[i]))return true;
}
return false;
}


void FileListGBA() {
DIR *dir;
struct stat st;
FILE *gbaFile;
int i;
const char* GBAEXT = ".GBA";
const char* BINEXT = ".BIN";

numFiles = 0;
numGames = 0;
Expand All @@ -1253,10 +1301,12 @@ void FileListGBA() {
// if(pent == NULL)break;
if(!pent)break;
stat(pent->d_name, &st);
if ((((st.st_mode & S_IFMT) == S_IFDIR) && (((string)pent->d_name).compare(".") != 0)) || nameEndsWith(pent->d_name, GBAEXT) || nameEndsWith(pent->d_name, BINEXT)) {
if ((((st.st_mode & S_IFMT) == S_IFDIR) && (((string)pent->d_name).compare(".") != 0)) || isValidFile(pent->d_name)) {
strcpy(fs[numFiles].filename, pent->d_name);
// strcpy(fs[numFiles].Alias, pent->d_name);
fs[numFiles].type = st.st_mode;
fs[numFiles].isNDSFile = 0;
if (nameEndsWith(pent->d_name, validExtensions[2]))fs[numFiles].isNDSFile = 1;
if ((((string)pent->d_name).compare(".") != 0) && (((string)pent->d_name).compare("..") != 0) && ((st.st_mode & S_IFMT) != S_IFDIR)) {
FILE *file = fopen(pent->d_name, "rb");
if (file) {
Expand All @@ -1282,11 +1332,19 @@ void FileListGBA() {
gbaFile = fopen(tbuf, "rb");
memset(tbuf, 0, 256);
if(gbaFile != NULL) {
fread(tbuf, 1, 256, gbaFile);
tbuf[0xB0] = 0;
strcpy(fs[i].gamecode, tbuf + 0xAC);
tbuf[0xAC] = 0;
strcpy(fs[i].gametitle, tbuf + 0xA0);
if (fs[i].isNDSFile == 1) {
fread(tbuf, 1, 256, gbaFile);
tbuf[0x10] = 0;
strcpy(fs[i].gamecode, tbuf + 0x0C);
tbuf[0x0C] = 0;
strcpy(fs[i].gametitle, tbuf); // 0x0
} else {
fread(tbuf, 1, 256, gbaFile);
tbuf[0xB0] = 0;
strcpy(fs[i].gamecode, tbuf + 0xAC);
tbuf[0xAC] = 0;
strcpy(fs[i].gametitle, tbuf + 0xA0);
}
fclose(gbaFile);
} else {
fs[i].gamecode[0] = 0;
Expand Down
Loading

0 comments on commit b0e0250

Please sign in to comment.