Skip to content

Commit 5d2b58e

Browse files
committed
Push kernel-20240622v0004 upstream. Added NGPGBA support
1 parent 72c059c commit 5d2b58e

File tree

1 file changed

+85
-6
lines changed
  • SCFW_Kernel_GBA_OmDRetro/source

1 file changed

+85
-6
lines changed

SCFW_Kernel_GBA_OmDRetro/source/main.c

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ struct settings settings = {
101101
.cold_boot_save = 1
102102
};
103103

104+
struct ngp_h{
105+
u32 id; //NGP,0x1A
106+
u32 filesize;
107+
u32 flags; // flags + branch hacks + reserved
108+
u32 follow;
109+
u32 bios, res0, res1, res2; // bit 0 = bios file.
110+
char name[32];
111+
};
112+
104113
struct pcea_h {
105114
char name[32];
106115
u32 filesize;
@@ -125,10 +134,7 @@ struct smsa_h {
125134
u16 flags;
126135
u16 hacks;
127136
u32 follow;
128-
u32 B_flag;
129-
u32 res0;
130-
u32 res1;
131-
u32 res2;
137+
u32 B_flag, res0, res1, res2; //BIOS flags + 15 bytes of reserved data
132138
char name[32];
133139
};
134140

@@ -167,6 +173,8 @@ bool filter_game(struct dirent *dirent) {
167173
return true;
168174
if (namelen > 4 && !strcasecmp(dirent->d_name + namelen - 4, ".nes"))
169175
return true;
176+
if (namelen > 4 && (!strcasecmp(dirent->d_name + namelen - 4, ".ngp") || !strcasecmp(dirent->d_name + namelen - 4, ".ngc")))
177+
return true;
170178
if (namelen > 4 && !strcasecmp(dirent->d_name + namelen - 4, ".pce"))
171179
return true;
172180
if (namelen > 4 && !strcasecmp(dirent->d_name + namelen - 4, ".sms"))
@@ -191,6 +199,8 @@ bool filter_selectable(struct dirent *dirent) {
191199
return true;
192200
if (namelen > 4 && !strcasecmp(dirent->d_name + namelen - 4, ".nes"))
193201
return true;
202+
if (namelen > 4 && (!strcasecmp(dirent->d_name + namelen - 4, ".ngp") || !strcasecmp(dirent->d_name + namelen - 4, ".ngc")))
203+
return true;
194204
if (namelen > 4 && !strcasecmp(dirent->d_name + namelen - 4, ".pce"))
195205
return true;
196206
if (namelen > 4 && !strcasecmp(dirent->d_name + namelen - 4, ".sms"))
@@ -893,6 +903,75 @@ void selectFile(char *path) {
893903
fclose(emu);
894904
L_Seq(path);
895905
}
906+
} else if ((pathlen > 4 && !strcasecmp(path + pathlen - 4, ".ngp")) || (pathlen > 4 && !strcasecmp(path + pathlen - 4, ".ngc"))){
907+
u32 romsize = 0;
908+
total_bytes = 0,bytes = 0;
909+
FILE *emu = fopen("/scfw/ngp.gba", "rb");
910+
if (!emu) {
911+
iprintf("NGP/NGC emu not found!\n");
912+
do {
913+
scanKeys();
914+
pressed = keysDownRepeat();
915+
VBlankIntrWait();
916+
} while (!(pressed & KEY_A));
917+
} else {
918+
fseek(emu,0,SEEK_END);
919+
romsize = ftell(emu);
920+
romSize = romsize;
921+
fseek(emu, 0, SEEK_SET);
922+
iprintf("Loading NGPGBA\n\n");
923+
FlashROM(path,pathlen,emu,romSize,false);
924+
struct ngp_h header;
925+
header.id = u32conv("PGN") | (0x1A << 24);
926+
FILE *rom = fopen(path, "rb");
927+
fseek(rom, 0, SEEK_END);
928+
romsize = ftell(rom);
929+
header.filesize = 0;
930+
header.filesize = romsize;
931+
header.flags = 0;
932+
if(!strcasecmp(path + pathlen - 4, ".ngc"))
933+
header.flags |= (1 << 2);
934+
else
935+
header.flags |= (0 << 2);
936+
iprintf("Analyzing ROM...\n\n");
937+
header.follow = 0;
938+
header.bios = 0;
939+
if (strcasestr(basename(path), "[BIOS]")) {
940+
header.bios |= (1 << 0);
941+
iprintf("BIOS ROM detected\n\n");
942+
}
943+
else
944+
{
945+
header.bios |= (0 << 0);
946+
iprintf("Non-BIOS ROM\n\n");
947+
}
948+
header.res0 = 0;
949+
header.res1 = 0;
950+
header.res2 = 0;
951+
char bname_b[32];
952+
strncpy(bname_b, basename(path), sizeof(bname_b) - 1);
953+
bname_b[sizeof(bname_b) - 1] = '\0';
954+
strcpy(header.name, bname_b);
955+
FILE *out_h = fopen("/scfw/ngp_h.dat", "wb");
956+
fwrite(&header,1, sizeof header, out_h);
957+
fclose(out_h);
958+
out_h = fopen("/scfw/ngp_h.dat", "rb");
959+
fseek(out_h,0,SEEK_END);
960+
romsize = ftell(out_h);
961+
romSize += romsize;
962+
fseek(out_h, 0, SEEK_SET);
963+
FlashROM(path,pathlen,out_h,romSize,false);
964+
fseek(rom, 0, SEEK_END);
965+
romsize = ftell(rom);
966+
romSize += romsize;
967+
fseek(rom, 0, SEEK_SET);
968+
iprintf("Loading ROM:\n\n");
969+
FlashROM(path,pathlen,rom,romSize,true);
970+
fclose(rom);
971+
fclose(out_h);
972+
fclose(emu);
973+
L_Seq(path);
974+
}
896975
} else {
897976
iprintf("Unrecognised file extension!\n");
898977
do {
@@ -906,7 +985,7 @@ void selectFile(char *path) {
906985
void change_settings(char *path) {
907986
for (int cursor = 0;;) {
908987
iprintf("\x1b[2J"
909-
"SCFW Kernel v0.5.2-Wasabi GBA-mode\n\n");
988+
"SCFW Kernel v0.5.2-NeoGeo GBA-mode\n\n");
910989

911990
iprintf("%cAutosave: %i\n", cursor == 0 ? '>' : ' ', settings.autosave);
912991
iprintf("%cSRAM Patch: %i\n", cursor == 1 ? '>' : ' ', settings.sram_patch);
@@ -982,7 +1061,7 @@ int main() {
9821061

9831062
consoleDemoInit();
9841063

985-
iprintf("SCFW Kernel v0.5.2-Wasabi GBA-mode\n\n");
1064+
iprintf("SCFW Kernel v0.5.2-NeoGeo GBA-mode\n\n");
9861065

9871066
*(vu16*) 0x04000204 = 0x40c0;
9881067
if (overclock_ewram())

0 commit comments

Comments
 (0)