From eba96bba073c8ac033935c2d7d00de8dff13bb28 Mon Sep 17 00:00:00 2001 From: dborth Date: Thu, 9 Oct 2008 21:44:53 +0000 Subject: [PATCH] cleanup ARAM ROM injection code --- README.txt | 8 +++++- source/ngc/filesel.cpp | 13 ++++------ source/ngc/filesel.h | 1 + source/ngc/menu.cpp | 4 +-- source/ngc/snes9xGX.cpp | 56 ++++++++++++++++++++++++---------------- source/ngc/video.cpp | 2 -- source/snes9x/memmap.cpp | 28 +++++--------------- 7 files changed, 54 insertions(+), 58 deletions(-) diff --git a/README.txt b/README.txt index eb80d62..eb49da0 100644 --- a/README.txt +++ b/README.txt @@ -259,7 +259,13 @@ and changed the setting, reset the game for the settings to take effect. These controllers can be controlled by either the Gamecube controller analog sticks,the Classic controller analog sticks, or by aiming at the screen with the wiimote. -(these configurations cannot be changed, yet) + +Aim Offscreen - Wiimote Minus, GameCube Z button +Fire - B button +Cursor - A button +Turbo Toggle - Wiimote D-Pad Down, GameCube Y button + +These configurations cannot be changed. ח–­—–­—–­—–­ –­—–­—–­—–­—–­—–­—–­—–­—–­—–­— ­—–­—–­—–­—–­—–­—–­—–­—-­—–­-–•Ĵ |0O×ĝo· ZIP SUPPORT ·oĝ×O0| diff --git a/source/ngc/filesel.cpp b/source/ngc/filesel.cpp index 135462a..11a3908 100644 --- a/source/ngc/filesel.cpp +++ b/source/ngc/filesel.cpp @@ -45,14 +45,12 @@ int selection; char currentdir[MAXPATHLEN]; int maxfiles; extern int screenheight; -extern unsigned long ARAM_ROMSIZE; +unsigned long ROMSize = 0; int havedir = -1; extern u64 dvddir; extern int dvddirlength; -int hasloaded = 0; - // Global file entry table FILEENTRIES filelist[MAXFILES]; @@ -389,23 +387,22 @@ int FileSelector (int method) { case METHOD_SD: case METHOD_USB: - ARAM_ROMSIZE = LoadFATFile ((char *)Memory.ROM, 0); + ROMSize = LoadFATFile ((char *)Memory.ROM, 0); break; case METHOD_DVD: dvddir = filelist[selection].offset; dvddirlength = filelist[selection].length; - ARAM_ROMSIZE = LoadDVDFile (Memory.ROM, 0); + ROMSize = LoadDVDFile (Memory.ROM, 0); break; case METHOD_SMB: - ARAM_ROMSIZE = LoadSMBFile ((char *)Memory.ROM, 0); + ROMSize = LoadSMBFile ((char *)Memory.ROM, 0); break; } - if (ARAM_ROMSIZE > 0) + if (ROMSize > 0) { - hasloaded = 1; // indicator for memmap.cpp Memory.LoadROM ("BLANK.SMC"); Memory.LoadSRAM ("BLANK"); haverom = 1; diff --git a/source/ngc/filesel.h b/source/ngc/filesel.h index b06df09..a98f418 100644 --- a/source/ngc/filesel.h +++ b/source/ngc/filesel.h @@ -36,6 +36,7 @@ extern int offset; extern int selection; extern char currentdir[MAXPATHLEN]; extern int maxfiles; +extern unsigned long ROMSize; void AllocSaveBuffer(); void FreeSaveBuffer(); diff --git a/source/ngc/menu.cpp b/source/ngc/menu.cpp index f6e67a9..ab4d8e9 100644 --- a/source/ngc/menu.cpp +++ b/source/ngc/menu.cpp @@ -39,7 +39,6 @@ extern "C" { #include "cheats.h" #include "snes9xGX.h" -#include "aram.h" #include "video.h" #include "filesel.h" #include "unzip.h" @@ -61,7 +60,6 @@ extern void DrawMenu (char items[][50], char *title, int maxitems, int selected, extern SCheatData Cheat; extern int menu; -extern unsigned long ARAM_ROMSIZE; #define SOFTRESET_ADR ((volatile u32*)0xCC003024) @@ -1053,7 +1051,7 @@ MainMenu (int selectedMenu) int ret; // disable game-specific menu items if a ROM isn't loaded - if ( ARAM_ROMSIZE == 0 ) + if (ROMSize == 0) menuitems[2][0] = '\0'; else sprintf (menuitems[2], "Game Menu"); diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index 06579cd..2af1955 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -61,7 +61,6 @@ extern "C" { #include "gui.h" -unsigned long ARAM_ROMSIZE = 0; int ConfigRequested = 0; FILE* debughandle; @@ -197,12 +196,6 @@ emulate () * 7. Initialise Snes9x/GC Sound System * 8. Initialise Snes9x Graphics subsystem * 9. Let's Party! - * - * The SNES ROM is delivered from ARAM. (AR_SNESROM) - * Any method of loading a ROM - RAM, DVD, SMB, SDCard, etc - * MUST place the unpacked ROM at this location. - * This provides a single consistent interface in memmap.cpp. - * Refer to that file if you need to change it. ***************************************************************************/ int main () @@ -233,15 +226,28 @@ main () // GC Audio RAM (for ROM and backdrop storage) AR_Init (NULL, 0); + // GameCube only - Injected ROM // Before going any further, let's copy any injected ROM image + // We'll put it in ARAM for safe storage + + #ifdef HW_DOL int *romptr = (int *) 0x81000000; // location of injected rom if (memcmp ((char *) romptr, "SNESROM0", 8) == 0) { - ARAM_ROMSIZE = romptr[2]; - romptr = (int *) 0x81000020; - ARAMPut ((char *) romptr, (char *) AR_SNESROM, ARAM_ROMSIZE); + ROMSize = romptr[2]; + + if(ROMSize > (1024*128) && ROMSize < (1024*1024*8)) + { + romptr = (int *) 0x81000020; + ARAMPut ((char *) romptr, (char *) AR_SNESROM, ROMSize); + } + else // not a valid ROM size + { + ROMSize = 0; + } } + #endif // Initialise freetype font system if (FT_Init ()) @@ -300,23 +306,29 @@ main () selectedMenu = 1; // change to preferences menu } - // No appended ROM, so get the user to load one - if (ARAM_ROMSIZE == 0) + // GameCube only - Injected ROM + // Everything's been initialized, we can copy our ROM back + // from ARAM into main memory + + #ifdef HW_DOL + if(ROMSize > 0) { - while (ARAM_ROMSIZE == 0) - { - MainMenu (selectedMenu); - } + ARAMFetchSlow( (char *)Memory.ROM, (char *)AR_SNESROM, ROMSize); + Memory.LoadROM ("BLANK.SMC"); + Memory.LoadSRAM ("BLANK"); } - else + #endif + + // Get the user to load a ROM + while (ROMSize <= 0) { - // Load ROM - save_flags = CPU.Flags; - if (!Memory.LoadROM ("VIRTUAL.ROM")) - while (1); - CPU.Flags = save_flags; + MainMenu (selectedMenu); } + // Load ROM + save_flags = CPU.Flags; + CPU.Flags = save_flags; + // Emulate emulate (); diff --git a/source/ngc/video.cpp b/source/ngc/video.cpp index 9e263b0..7c7339d 100644 --- a/source/ngc/video.cpp +++ b/source/ngc/video.cpp @@ -27,8 +27,6 @@ /*** Snes9x GFX Buffer ***/ static unsigned char snes9xgfx[1024 * 512 * 2]; -/*** Memory ROM Loading ***/ -extern unsigned long ARAM_ROMSIZE; extern unsigned int SMBTimer; /*** 2D Video ***/ diff --git a/source/snes9x/memmap.cpp b/source/snes9x/memmap.cpp index 5293709..81e6914 100644 --- a/source/snes9x/memmap.cpp +++ b/source/snes9x/memmap.cpp @@ -196,11 +196,8 @@ #include "cheats.h" #else #include -#include "aram.h" /*** Nintendo GameCube ARAM loader. - FileLoader requires that the ROM is preloaded in ARAM first - ***/ -extern unsigned long ARAM_ROMSIZE; -extern int hasloaded; + +extern unsigned long ROMSize; #endif #include "controls.h" @@ -1139,30 +1136,17 @@ uint32 CMemory::FileLoader (uint8 *buffer, const char *filename, int32 maxsize) } #else -//#include "ftfont.h" -/*** Nintendo Gamecube ARAM ROM File Loader - This is simply a modified version of FILE_DEFAULT, which uses - the ARAM as temporary ROM storage. - - NB: Make sure ARAM_ROMSIZE is correct! All hell ensues if you don't + /*** Nintendo Wii/Gamecube ROM File Loader + By now we've already loaded the ROM into main memory + This is simply a modified version of FILE_DEFAULT ***/ HeaderCount = 0; uint8 *ptr = buffer; - - long unsigned int size = 0; - uint32 ARAM_max = maxsize + 0x200 - (ptr - buffer); - size = ARAM_ROMSIZE; - - if ( size > ARAM_max ) - size = ARAM_max; - - if ( hasloaded == 0 ) - ARAMFetchSlow( (char *)ptr, (char *)AR_SNESROM, size ); + uint32 size = ROMSize; size = HeaderRemove(size, HeaderCount, ptr); ptr += size; totalSize += size; - #endif if (HeaderCount == 0) S9xMessage(S9X_INFO, S9X_HEADERS_INFO, "No ROM file header found.");