From 5b1fefe1158f3c4bd884f943522f1132fa1be6b8 Mon Sep 17 00:00:00 2001 From: Yanis42 <35189056+Yanis42@users.noreply.github.com> Date: Mon, 14 Oct 2024 01:10:58 +0200 Subject: [PATCH] various improvements --- config/oot-e/symbols.txt | 2 +- config/oot-j/symbols.txt | 2 +- config/oot-u/symbols.txt | 2 +- configure.py | 6 ++- include/emulator/controller.h | 5 +-- include/emulator/errordisplay.h | 9 ++-- include/emulator/flash.h | 3 +- include/emulator/rom.h | 2 +- include/emulator/store.h | 13 +++--- include/emulator/stringtable.h | 30 +++++++------ include/emulator/system.h | 9 ++-- include/emulator/xlHeap.h | 2 +- include/macros.h | 4 ++ include/revolution/nand/nand.h | 28 ++++++------ src/emulator/controller.c | 49 +++++++++++---------- src/emulator/errordisplay.c | 4 +- src/emulator/flash.c | 6 +-- src/emulator/rom.c | 75 +++++++++++++++++---------------- src/emulator/store.c | 37 ++++++++-------- src/emulator/system.c | 12 +++--- src/emulator/vc64_RVL.c | 7 +-- src/emulator/xlCoreRVL.c | 19 +-------- src/emulator/xlFileRVL.c | 5 ++- src/emulator/xlHeap.c | 2 +- tools/project.py | 7 ++- 25 files changed, 173 insertions(+), 167 deletions(-) diff --git a/config/oot-e/symbols.txt b/config/oot-e/symbols.txt index 2bfa162..83c6b0b 100644 --- a/config/oot-e/symbols.txt +++ b/config/oot-e/symbols.txt @@ -1018,7 +1018,7 @@ xlHeapCopy = .text:0x800814EC; // type:function size:0x6C8 xlHeapFill8 = .text:0x80081BB4; // type:function size:0x160 xlHeapFill32 = .text:0x80081D14; // type:function size:0x164 __xlHeapGetFree = .text:0x80081E78; // type:function size:0xB0 scope:local -xlHeapGetFree = .text:0x80081F28; // type:function size:0xC +xlHeapGetHeap1Free = .text:0x80081F28; // type:function size:0xC xlHeapSetup = .text:0x80081F34; // type:function size:0x13C xlHeapReset = .text:0x80082070; // type:function size:0x34 xlFileGetSize = .text:0x800820A4; // type:function size:0x78 diff --git a/config/oot-j/symbols.txt b/config/oot-j/symbols.txt index 569d067..8d2dee0 100644 --- a/config/oot-j/symbols.txt +++ b/config/oot-j/symbols.txt @@ -1018,7 +1018,7 @@ xlHeapCopy = .text:0x800814BC; // type:function size:0x6C8 xlHeapFill8 = .text:0x80081B84; // type:function size:0x160 xlHeapFill32 = .text:0x80081CE4; // type:function size:0x164 __xlHeapGetFree = .text:0x80081E48; // type:function size:0xB0 scope:local -xlHeapGetFree = .text:0x80081EF8; // type:function size:0xC +xlHeapGetHeap1Free = .text:0x80081EF8; // type:function size:0xC xlHeapSetup = .text:0x80081F04; // type:function size:0x13C xlHeapReset = .text:0x80082040; // type:function size:0x34 xlFileGetSize = .text:0x80082074; // type:function size:0x78 diff --git a/config/oot-u/symbols.txt b/config/oot-u/symbols.txt index ba23dd9..5e73f0f 100644 --- a/config/oot-u/symbols.txt +++ b/config/oot-u/symbols.txt @@ -1018,7 +1018,7 @@ xlHeapCopy = .text:0x800814C8; // type:function size:0x6C8 xlHeapFill8 = .text:0x80081B90; // type:function size:0x160 xlHeapFill32 = .text:0x80081CF0; // type:function size:0x164 __xlHeapGetFree = .text:0x80081E54; // type:function size:0xB0 scope:local -xlHeapGetFree = .text:0x80081F04; // type:function size:0xC +xlHeapGetHeap1Free = .text:0x80081F04; // type:function size:0xC xlHeapSetup = .text:0x80081F10; // type:function size:0x13C xlHeapReset = .text:0x8008204C; // type:function size:0x34 xlFileGetSize = .text:0x80082080; // type:function size:0x78 diff --git a/configure.py b/configure.py index 3639cdd..f665c2a 100755 --- a/configure.py +++ b/configure.py @@ -182,7 +182,11 @@ def EmulatorLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]: return { "lib": lib_name, - "mw_version": "GC/3.0a5", + "mw_versions": { + "oot-j": "GC/3.0a5", + "oot-u": "GC/3.0a5", + "oot-e": "GC/3.0a5", + }, "cflags": [*cflags_base, "-Cpp_exceptions off", "-O4,p", "-enc SJIS"], "host": False, "objects": objects, diff --git a/include/emulator/controller.h b/include/emulator/controller.h index 2c5f177..66e779b 100644 --- a/include/emulator/controller.h +++ b/include/emulator/controller.h @@ -33,13 +33,12 @@ typedef struct Controller { /* 0x0BC */ s32 unk_BC[PAD_MAX_CONTROLLERS]; /* 0x0CC */ s32 unk_CC[PAD_MAX_CONTROLLERS]; /* 0x0DC */ u32 controllerConfiguration[PAD_MAX_CONTROLLERS][GCN_BTN_COUNT]; - /* 0x21C */ s32 unk_21C; + /* 0x21C */ ErrorIndex iString; /* 0x220 */ s32 unk_220; /* 0x224 */ s32 unk_224; /* 0x228 */ u32 unk_228[PAD_MAX_CONTROLLERS]; /* 0x238 */ u32 unk_238[PAD_MAX_CONTROLLERS]; - /* 0x248 */ s32 unk_248; - /* 0x24C */ s32 unk_24C; + /* 0x248 */ s64 unk_248; /* 0x250 */ u8 unk_250[0x20]; /* 0x270 */ u32 unk_270[PAD_MAX_CONTROLLERS]; /* 0x280 */ u32 unk_280[PAD_MAX_CONTROLLERS]; diff --git a/include/emulator/errordisplay.h b/include/emulator/errordisplay.h index 541b31b..3d59a3c 100644 --- a/include/emulator/errordisplay.h +++ b/include/emulator/errordisplay.h @@ -1,5 +1,5 @@ -#ifndef _CODE_800633F8_H -#define _CODE_800633F8_H +#ifndef _ERRORDISPLAY_H +#define _ERRORDISPLAY_H #include "emulator/banner.h" #include "emulator/stringtable.h" @@ -49,6 +49,7 @@ typedef enum ErrorIndex { ERROR_BLANK = 11, // (nothing) ERROR_NULL = 12, + ERROR_MAX = 12 } ErrorIndex; typedef struct DisplayFiles { @@ -58,7 +59,7 @@ typedef struct DisplayFiles { } DisplayFiles; // size = 0xC typedef struct EDString { - /* 0x00 */ struct ErrorDisplay* apStringDraw[ERROR_NULL]; + /* 0x00 */ struct ErrorDisplay* apStringDraw[ERROR_MAX]; /* 0x30 */ ErrorIndex iString; /* 0x34 */ s32 iAction; } EDString; // size = 0x38 @@ -107,7 +108,7 @@ void OSFreeToHeap(s32 handle, void* p); void errorDisplayInit(void); bool errorDisplayShow(ErrorIndex iString); -extern ErrorDisplay sStringDraw[12]; +extern ErrorDisplay sStringDraw[]; extern struct_80174988 lbl_80174988[17]; extern bool lbl_8025D130; extern s32 lbl_8025D12C; diff --git a/include/emulator/flash.h b/include/emulator/flash.h index 3b850cb..25f23b1 100644 --- a/include/emulator/flash.h +++ b/include/emulator/flash.h @@ -2,6 +2,7 @@ #define _FLASH_H #include "emulator/xlObject.h" +#include "macros.h" #include "revolution/types.h" #ifdef __cplusplus @@ -9,7 +10,7 @@ extern "C" { #endif typedef struct Flash { - /* 0x00 */ u32 unk_00; + /* 0x00 */ u32 nFlashSize; /* 0x04 */ struct Store* pStore; /* 0x08 */ s32 flashStatus; /* 0x0C */ s32 flashCommand; diff --git a/include/emulator/rom.h b/include/emulator/rom.h index 3455204..cabfd63 100644 --- a/include/emulator/rom.h +++ b/include/emulator/rom.h @@ -79,7 +79,7 @@ typedef struct Rom { /* 0x19A74 */ u8 acHeader[64]; /* 0x19AB4 */ u32* anOffsetBlock; /* 0x19AB8 */ s32 nCountOffsetBlocks; - /* 0x19ABC */ s32 unk_19ABC; // game's segment `boot` checksum? + /* 0x19ABC */ s32 nChecksum; /* 0x19AC0 */ DVDFileInfo fileInfo; /* 0x19AFC */ s32 offsetToRom; } Rom; // size = 0x19B00 diff --git a/include/emulator/store.h b/include/emulator/store.h index e8e45c0..774f705 100644 --- a/include/emulator/store.h +++ b/include/emulator/store.h @@ -11,13 +11,13 @@ extern "C" { #endif typedef struct Store { - /* 0x00 */ u32 unk_00; - /* 0x08 */ char szFileName[9]; + /* 0x00 */ u32 nFileSize; + /* 0x04 */ char szFileName[12]; /* 0x10 */ NANDFileInfo nandFileInfo; /* 0x9C */ u8* unk_9C; /* 0xA0 */ SystemRomType eTypeROM; /* 0xA4 */ s32 unk_A4; - /* 0xA8 */ u32 unk_A8; + /* 0xA8 */ void* unk_A8; /* 0xAC */ void* unk_AC; /* 0xB0 */ u32 unk_B0; /* 0xB4 */ u32 unk_B4; @@ -25,9 +25,12 @@ typedef struct Store { /* 0xB9 */ u8 unk_B9; /* 0xBA */ u8 unk_BA; /* 0xBB */ u8 unk_BB; - /* 0xBC */ u32 unk_BC; + /* 0xBC */ union { + NANDResult eResult; + u32 nSize2; + }; /* 0xC0 */ NANDCommandBlock nandCmdBlock; -} Store; // size = 0x178 +} Store; // size = 0x188 bool fn_80061770(void** pObject, char* szName, SystemRomType eTypeROM, void* pArgument); bool storeFreeObject(void** ppObject); diff --git a/include/emulator/stringtable.h b/include/emulator/stringtable.h index d30f541..655caa5 100644 --- a/include/emulator/stringtable.h +++ b/include/emulator/stringtable.h @@ -21,30 +21,36 @@ typedef enum StringID { SID_ERROR_CHOICE_OK = 0xF6C5198F, SID_ERROR_CHOICE_PRESS_A_TO_RETURN_TO_MENU = 0xBB628DD1, SID_ERROR_DATA_CORRUPT = 0x14A5B6E2, - SID_ERROR_DVD_STATE_FATAL_ERROR = 0xEBB077F2, // Brawl Demo only - SID_ERROR_DVD_STATE_NO_DISK = 0x3A1F93A8, // Brawl Demo only - SID_ERROR_DVD_STATE_RETRY = 0x25D38BC6, // Brawl Demo only - SID_ERROR_DVD_STATE_WRONG_DISK = 0x7527596C, // Brawl Demo only + SID_ERROR_DVD_STATE_FATAL_ERROR = 0xEBB077F2, + SID_ERROR_DVD_STATE_NO_DISK = 0x3A1F93A8, + SID_ERROR_DVD_STATE_RETRY = 0x25D38BC6, + SID_ERROR_DVD_STATE_WRONG_DISK = 0x7527596C, SID_ERROR_FATAL = 0x27A3CCC2, SID_ERROR_GAMECUBE_CONTROLLER_CONNECTED = 0xD6E8882D, SID_ERROR_INS_INNODE = 0xE136B8C3, SID_ERROR_INS_SPACE = 0xFBB27B1C, - SID_ERROR_INS_SPACE_PLURAL = 0x92FBDC3E, // Brawl Demo only + SID_ERROR_INS_SPACE_PLURAL = 0x92FBDC3E, SID_ERROR_MAX_BLOCKS = 0xC0192EA3, SID_ERROR_MAX_FILES = 0x5D3A795B, SID_ERROR_NEED_CLASSIC = 0x2F8DCDD7, SID_ERROR_NO_CONTROLLER = 0x1786067E, - SID_ERROR_NWC24_CORRUPTED_FILE = 0x19C2F27E, // Brawl Demo only - SID_ERROR_NWC24_ERROR_BUFFER = 0xB958D7EE, // Brawl Demo only - SID_ERROR_NWC24_FATAL_ERROR = 0xECC5F9D8, // Brawl Demo only - SID_ERROR_NWC24_SYSTEM_MENU_UPDATE_REQUIRED = 0x0522BEC0, // Brawl Demo only - SID_ERROR_NWC24_UNAVAILABLE = 0xE1347C92, // Brawl Demo only + SID_ERROR_NWC24_CORRUPTED_FILE = 0x19C2F27E, + SID_ERROR_NWC24_ERROR_BUFFER = 0xB958D7EE, + SID_ERROR_NWC24_FATAL_ERROR = 0xECC5F9D8, + SID_ERROR_NWC24_SYSTEM_MENU_UPDATE_REQUIRED = 0x0522BEC0, + SID_ERROR_NWC24_UNAVAILABLE = 0xE1347C92, SID_ERROR_REMOTE_BATTERY = 0x80E449BF, SID_ERROR_REMOTE_COMMUNICATION = 0xB35ABA8B, SID_ERROR_SYS_CORRUPT = 0x57D16861, - SID_ERROR_TIME_UP_OF_THE_TRIAL_VER = 0xA2B7EF38, // Brawl Demo only + SID_ERROR_TIME_UP_OF_THE_TRIAL_VER = 0xA2B7EF38, SID_COMMENT_GAME_NAME = 0x30690AFB, - SID_COMMENT_EMPTY = 0x30690AFD + SID_COMMENT_EMPTY = 0x30690AFD, + SID_ERROR_PHOTO_ALREADY_POSTED = 0x4016043D, + SID_ERROR_PHOTO_CANT_POST = 0xB93DC9EA, + SID_ERROR_PHOTO_POSTED = 0x24B1085E, + SID_ERROR_SYS_CORRUPT_REDOWNLOAD = 0x3D24B5C1, + SID_ERROR_SYS_MEM_CANT_ACCESS = 0xE46954BD, + SID_ERROR_SYS_MEM_CANT_ACCESS_2 = 0xEE30A5E0, } StringID; typedef struct STEntry { diff --git a/include/emulator/system.h b/include/emulator/system.h index 3308147..993304c 100644 --- a/include/emulator/system.h +++ b/include/emulator/system.h @@ -260,8 +260,8 @@ typedef struct SystemException { /* 0x00 */ char* szType; /* 0x04 */ u32 nMask; /* 0x08 */ CpuExceptionCode eCode; - /* 0x10 */ MIInterruptType eTypeMips; - /* 0x0C */ SystemInterruptType eType; + /* 0x0C */ MIInterruptType eTypeMips; + /* 0x10 */ SystemInterruptType eType; } SystemException; // size = 0x14 typedef struct System { @@ -270,10 +270,9 @@ typedef struct System { /* 0x08 */ SystemObjectType storageDevice; /* 0x0C */ SystemRomType eTypeROM; /* 0x10 */ void* apObject[SOT_COUNT]; - /* 0x6C */ s32 unk_6C; + /* 0x6C */ struct Store* unk_6C; /* 0x70 */ u64 nAddressBreak; - /* 0x78 */ s32 unk_78[19]; - /* 0xC4 */ void* pSound; + /* 0x78 */ CpuBlock aBlock[4]; /* 0xC8 */ u8 anException[16]; } System; // size = 0xD8 diff --git a/include/emulator/xlHeap.h b/include/emulator/xlHeap.h index d40f1b9..87f5f9e 100644 --- a/include/emulator/xlHeap.h +++ b/include/emulator/xlHeap.h @@ -15,7 +15,7 @@ bool xlHeapFree(void** ppHeap); bool xlHeapCopy(void* pHeapTarget, void* pHeapSource, s32 nByteCount); bool xlHeapFill8(void* pHeap, s32 nByteCount, u32 nData); bool xlHeapFill32(void* pHeap, s32 nByteCount, u32 nData); -bool xlHeapGetFree(s32* pnFreeBytes); +bool xlHeapGetHeap1Free(s32* pnFreeBytes); bool xlHeapSetup(void); bool xlHeapReset(void); diff --git a/include/macros.h b/include/macros.h index 743a1c1..01d3410 100644 --- a/include/macros.h +++ b/include/macros.h @@ -29,7 +29,11 @@ extern "C" { #define ROUND_DOWN_PTR(x, align) ((void*)(((u32)(x)) & (~((align) - 1)))) #define MEMCLR(x) __memclr((x), sizeof(*(x))) +#ifndef __INTELLISENSE__ #define NO_INLINE __attribute__((never_inline)) +#else +#define NO_INLINE +#endif #define __CONCAT(x, y) x##y #define CONCAT(x, y) __CONCAT(x, y) diff --git a/include/revolution/nand/nand.h b/include/revolution/nand/nand.h index 7f23795..9c44455 100644 --- a/include/revolution/nand/nand.h +++ b/include/revolution/nand/nand.h @@ -77,27 +77,27 @@ typedef enum { typedef void (*NANDAsyncCallback)(s32 result, struct NANDCommandBlock* block); typedef struct NANDStatus { - /* 0x0 */ u32 ownerId; - /* 0x4 */ u16 groupId; - /* 0x6 */ u8 attr; - /* 0x7 */ u8 perm; -} NANDStatus; + /* 0x00 */ u32 ownerId; + /* 0x04 */ u16 groupId; + /* 0x06 */ u8 attr; + /* 0x07 */ u8 perm; +} NANDStatus; // size = 0x8 typedef struct NANDFileInfo { - /* 0x0 */ s32 fd; - /* 0x4 */ s32 tempFd; - /* 0x8 */ char openPath[FS_MAX_PATH]; + /* 0x00 */ s32 fd; + /* 0x04 */ s32 tempFd; + /* 0x08 */ char openPath[FS_MAX_PATH]; /* 0x48 */ char tempPath[FS_MAX_PATH]; /* 0x88 */ u8 access; /* 0x89 */ u8 stage; /* 0x8A */ u8 mark; -} NANDFileInfo; +} NANDFileInfo; // size = 0x8C typedef struct NANDCommandBlock { - /* 0x0 */ void* userData; - /* 0x4 */ NANDAsyncCallback callback; - /* 0x8 */ NANDFileInfo* info; - /* 0xC */ void* bytes; + /* 0x00 */ void* userData; + /* 0x04 */ NANDAsyncCallback callback; + /* 0x08 */ NANDFileInfo* info; + /* 0x0C */ void* bytes; /* 0x10 */ void* inodes; /* 0x14 */ NANDStatus* status; /* 0x18 */ u32 ownerId; @@ -126,7 +126,7 @@ typedef struct NANDCommandBlock { /* 0xAC */ u32 workBlocks; /* 0xB0 */ u32 workInodes; /* 0xB4 */ const char** dir; -} NANDCommandBlock; +} NANDCommandBlock; // size = 0xB8 typedef struct NANDBanner { /* 0x0 */ u32 magic; diff --git a/src/emulator/controller.c b/src/emulator/controller.c index 25e60d4..0ff3925 100644 --- a/src/emulator/controller.c +++ b/src/emulator/controller.c @@ -3,6 +3,7 @@ #include "emulator/vc64_RVL.h" #include "emulator/xlCoreRVL.h" #include "emulator/xlHeap.h" +#include "macros.h" #include "math.h" #include "revolution/mem.h" #include "revolution/vi.h" @@ -48,7 +49,7 @@ void* fn_80061FB0(u32 nSize) { } bool fn_80061FF8(Controller* pController) { - MEMFreeToAllocator(&gControllerAllocator, pController->unk_00); + MEMFreeToAllocator(&gControllerAllocator, pController); return true; } @@ -68,10 +69,10 @@ s32 fn_80062028(EDString* pSTString) { OSGetTime(); pController = SYSTEM_CONTROLLER(gpSystem); - switch (pController->unk_21C) { - case 7: + switch (pController->iString) { + case ERROR_NO_CONTROLLER: return 2; - case 8: + case ERROR_NEED_CLASSIC: if (unk4C_UnknownInline(pController)) { return 2; } @@ -83,12 +84,25 @@ s32 fn_80062028(EDString* pSTString) { return 0; } +bool fn_80080C04(Controller* pController, ErrorIndex iString) { + pController->unk_248 = OSGetTime(); + pController->iString = iString; + errorDisplayShow(iString); + pController->iString = ERROR_NONE; + + if (!fn_800607C4(SYSTEM_HELP(gpSystem), 0)) { + return false; + } + + return true; +} + bool fn_800620A8(Controller* pController) { void* sp8; s32 i; pController->unk_220 = 1; - pController->unk_21C = -1; + pController->iString = ERROR_NONE; for (i = 0; i < PAD_MAX_CONTROLLERS; i++) { pController->unk_228[i] = 0; @@ -149,7 +163,7 @@ bool fn_800622B8(Controller* pController) { pController->unk_BC[i] = pController->unk_CC[i] = 0; pController->stickLeft[i][AXIS_X] = pController->stickLeft[i][AXIS_Y] = 0; pController->stickRight[i][AXIS_Y] = 0; - pController->unk_21C = -1; // why here + pController->iString = ERROR_NONE; // why here pController->stickRight[i][AXIS_X] = 0; if (!controllerValidateIndex(i)) { @@ -166,8 +180,6 @@ bool simulatorDetectController(Controller* pController, s32 arg1) { return arg1 bool fn_80062C18(Controller* pController, s32 iController, s32* arg2, s32* arg3, s32* arg4, s32* arg5, s32* arg6, s32* arg7) { - s32 temp_r3; - if (iController >= 0 && iController < PAD_MAX_CONTROLLERS) { if (arg2 != NULL) { *arg2 = pController->unk_BC[iController]; @@ -228,7 +240,7 @@ bool simulatorCopyControllerMap(Controller* pController, u32* mapDataOutput, u32 return true; } -bool fn_80062E5C(Controller* pController, s32, s32*) { return true; } +bool fn_80062E5C(Controller* pController, s32 arg1, s32* arg2) { return true; } static void* controllerThread(void* pArg) { Controller* pController = SYSTEM_CONTROLLER(gpSystem); @@ -263,16 +275,8 @@ bool fn_800631B8(Controller* pController, s32 arg1) { return true; } -static inline bool controllerEvent_Inline() { - if (!fn_800607C4(SYSTEM_HELP(gpSystem), 0)) { - return false; - } - - return true; -} - bool controllerEvent(Controller* pController, s32 nEvent, void* pArgument) { - s32 var_r31; + s32 i; switch (nEvent) { case 0: @@ -294,18 +298,13 @@ bool controllerEvent(Controller* pController, s32 nEvent, void* pArgument) { break; case 0x1003: if (!unk4C_UnknownInline(pController)) { - for (var_r31 = 0; var_r31 < 0x78; var_r31++) { + for (i = 0; i < 0x78; i++) { VIWaitForRetrace(); } } if (!unk4C_UnknownInline(pController)) { - pController->unk_24C = pController->unk_248 = OSGetTime(); - pController->unk_21C = 8; - errorDisplayShow(ERROR_NEED_CLASSIC); - pController->unk_21C = -1; - - if (!controllerEvent_Inline()) { + if (!fn_80080C04(pController, ERROR_NEED_CLASSIC)) { return false; } diff --git a/src/emulator/errordisplay.c b/src/emulator/errordisplay.c index 77fb8b6..734509e 100644 --- a/src/emulator/errordisplay.c +++ b/src/emulator/errordisplay.c @@ -581,13 +581,11 @@ void errorDisplayInit(void) { u32 nLanguage; nLanguage = SCGetLanguage(); - pDisplayFiles = &sSTFiles[0]; - while (pDisplayFiles->szErrorsFilename != NULL) { + for (pDisplayFiles = &sSTFiles[0]; pDisplayFiles->szErrorsFilename != NULL; pDisplayFiles++) { if (pDisplayFiles->eLanguage == nLanguage) { break; } - pDisplayFiles++; } if (pDisplayFiles->szErrorsFilename == NULL) { diff --git a/src/emulator/flash.c b/src/emulator/flash.c index 515fda4..e36c98a 100644 --- a/src/emulator/flash.c +++ b/src/emulator/flash.c @@ -35,7 +35,7 @@ static bool flashPut32(Flash* pFLASH, u32 nAddress, s32* pData) { } if (pFLASH->unk_14 == 0xFFFFFFFF) { - for (i = 0; i < pFLASH->pStore->unk_00; i += 0x80) { + for (i = 0; i < pFLASH->pStore->nFileSize; i += 0x80) { if (!fn_80061BC0(pFLASH->pStore, buffer, i, 0x80)) { return false; } @@ -151,7 +151,7 @@ bool fn_800452B0(Flash* pFLASH, s32 arg1, void* arg2) { } bool fn_80045300(Flash* pFLASH, u32* arg1) { - *arg1 = pFLASH->unk_00; + *arg1 = pFLASH->nFlashSize; return true; } @@ -167,7 +167,7 @@ static inline bool flashEvent_UnknownInline(Flash* pFLASH, void* pArgument) { pArgument = (void*)0x4000; } - pFLASH->unk_00 = (u32)pArgument; + pFLASH->nFlashSize = (u32)pArgument; if (!fn_80061770((void**)&pFLASH->pStore, "EEP", gpSystem->eTypeROM, pArgument)) { return false; diff --git a/src/emulator/rom.c b/src/emulator/rom.c index 68ca8cd..a6e43c3 100644 --- a/src/emulator/rom.c +++ b/src/emulator/rom.c @@ -7,6 +7,7 @@ #include "emulator/system.h" #include "emulator/vc64_RVL.h" #include "emulator/xlCoreRVL.h" +#include "emulator/xlFile.h" #include "emulator/xlHeap.h" #include "macros.h" #include "revolution/os.h" @@ -282,8 +283,8 @@ static bool romLoadUpdate(Rom* pROM) { return true; } - iBlock0 = pROM->load.nOffset0 >> 0xD; - iBlock1 = pROM->load.nOffset1 >> 0xD; + iBlock0 = pROM->load.nOffset0 >> 13; + iBlock1 = pROM->load.nOffset1 >> 13; while (iBlock0 <= iBlock1) { if (pCPU->nRetrace != pCPU->nRetraceUsed) { @@ -308,8 +309,8 @@ static bool romLoadUpdate(Rom* pROM) { pROM->load.nOffset0 = ++iBlock0 * 0x2000; } - pROM->load.nOffset1 = 0U; - pROM->load.nOffset0 = 0U; + pROM->load.nOffset1 = 0; + pROM->load.nOffset0 = 0; return true; } @@ -330,6 +331,8 @@ static inline bool romCheckOffsets(Rom* pROM) { return true; } +static inline void romSetEndianness(Rom* pROM) { pROM->bFlip = pROM->acHeader[0] == 0x37 && pROM->acHeader[1] == 0x80; } + static bool romCopyUpdate(Rom* pROM) { RomBlock* pBlock; s32 pad; @@ -406,30 +409,6 @@ static bool romCopyUpdate(Rom* pROM) { return true; } -static inline bool romLoadFullOrPartLoop(Rom* pROM) { - s32 i; - s32 iCache; - u32 temp_r27; - u32 temp_r30; - - temp_r27 = (u32)(pROM->nSize - 1) / 0x2000; - temp_r30 = pROM->nTick = temp_r27 + 1; - - for (i = 0; i < temp_r30; i++) { - pROM->aBlock[i].nTickUsed = temp_r27 - i; - - if (!romMakeFreeCache(pROM, &iCache, RCT_RAM)) { - return false; - } - - if (!romLoadBlock(pROM, i, iCache, NULL)) { - return false; - } - } - - return true; -} - static bool fn_80042C98(Rom* pROM) { tXL_FILE* pFile; @@ -502,6 +481,30 @@ s32 fn_80042E30(EDString* pSTString) { return ret; } +static inline bool romLoadFullOrPartLoop(Rom* pROM) { + s32 i; + s32 iCache; + u32 temp_r27; + u32 temp_r30; + + temp_r27 = (u32)(pROM->nSize - 1) / 0x2000; + temp_r30 = pROM->nTick = temp_r27 + 1; + + for (i = 0; i < temp_r30; i++) { + pROM->aBlock[i].nTickUsed = temp_r27 - i; + + if (!romMakeFreeCache(pROM, &iCache, RCT_RAM)) { + return false; + } + + if (!romLoadBlock(pROM, i, iCache, NULL)) { + return false; + } + } + + return true; +} + static bool romLoadFullOrPart(Rom* pROM) { if ((s32)pROM->nSize <= pROM->nSizeCacheRAM) { void* pBuffer; @@ -829,8 +832,8 @@ bool romSetImage(Rom* pROM, char* szNameFile) { s32 iName; s32 nSize; s32 nHeapSize; - s32 i; - u32 pData[0x400 / sizeof(u32)]; + s32 iCode; + u32 anData[256]; for (iName = 0; (szNameFile[iName] != '\0') && (iName < 0x200); iName++) { pROM->acNameFile[iName] = szNameFile[iName]; @@ -860,7 +863,7 @@ bool romSetImage(Rom* pROM, char* szNameFile) { return false; } - if (!xlFileOpen(&pFile, 1, szNameFile)) { + if (!xlFileOpen(&pFile, XLFT_BINARY, szNameFile)) { return false; } @@ -876,7 +879,7 @@ bool romSetImage(Rom* pROM, char* szNameFile) { return false; } - if (!xlFileGet(pFile, &pData, sizeof(pData))) { + if (!xlFileGet(pFile, &anData, sizeof(anData))) { return false; } @@ -884,13 +887,11 @@ bool romSetImage(Rom* pROM, char* szNameFile) { return false; } - pROM->unk_19ABC = 0; - - for (i = 0; i < ARRAY_COUNT(pData); i++) { - pROM->unk_19ABC += pData[i]; + for (pROM->nChecksum = 0, iCode = 0; iCode < ARRAY_COUNT(anData); iCode++) { + pROM->nChecksum += anData[iCode]; } - pROM->bFlip = (pROM->acHeader[0] == 0x37 && pROM->acHeader[1] == 0x80); + romSetEndianness(pROM); return true; } diff --git a/src/emulator/store.c b/src/emulator/store.c index 6a1fc21..1c4fe29 100644 --- a/src/emulator/store.c +++ b/src/emulator/store.c @@ -1,5 +1,6 @@ #include "emulator/store.h" #include "emulator/banner.h" +#include "emulator/controller.h" #include "emulator/flash.h" #include "emulator/pak.h" #include "emulator/sram.h" @@ -30,7 +31,7 @@ static inline bool unknownInline(Store* pStore, u8 access) { return true; } - if (!fn_800641CC(&pStore->nandFileInfo, pStore->szFileName, pStore->unk_00, 0xAA, access)) { + if (!fn_800641CC(&pStore->nandFileInfo, pStore->szFileName, pStore->nFileSize, 0xAA, access)) { pStore->unk_A4 = 0; } @@ -58,7 +59,7 @@ bool fn_80061770(void** ppObject, char* szName, SystemRomType eTypeROM, void* pA return false; } - STORE_OBJ->unk_00 = (s32)pArgument; + STORE_OBJ->nFileSize = (s32)pArgument; STORE_OBJ->eTypeROM = eTypeROM; // example: "RAM_CZLJ" @@ -81,7 +82,7 @@ bool fn_80061770(void** ppObject, char* szName, SystemRomType eTypeROM, void* pA STORE_OBJ->unk_B9 = 1; STORE_OBJ->unk_B8 = 0; STORE_OBJ->unk_BA = 1; - STORE_OBJ->unk_BC = (s32)pArgument; + STORE_OBJ->nSize2 = (s32)pArgument; fn_800618D4(*ppObject, (void*)STORE_OBJ->unk_A8, 0, (s32)pArgument); return true; @@ -171,12 +172,12 @@ static bool fn_800618D4(Store* pStore, void* arg1, s32 arg2, s32 arg3) { } bool fn_80061B88(Store* pStore, void* pHeapTarget, s32 nOffset, s32 nByteCount) { - xlHeapCopy((s32*)pHeapTarget, (void*)(pStore->unk_A8 + nOffset), nByteCount); + xlHeapCopy((s32*)pHeapTarget, (void*)((u32)pStore->unk_A8 + nOffset), nByteCount); return true; } bool fn_80061BC0(Store* pStore, void* pHeapTarget, s32 nOffset, s32 nByteCount) { - xlHeapCopy((void*)(pStore->unk_A8 + nOffset), (s32*)pHeapTarget, nByteCount); + xlHeapCopy((void*)((u32)pStore->unk_A8 + nOffset), (s32*)pHeapTarget, nByteCount); pStore->unk_B8 = 1; return true; } @@ -185,7 +186,7 @@ static void fn_80061C08(s32 nResult, NANDCommandBlock* block) { Store* pStore = (Store*)NANDGetUserData(block); if (nResult != 0) { - pStore->unk_BC = nResult; + pStore->eResult = nResult; } pStore->unk_B9 = 1; @@ -193,13 +194,13 @@ static void fn_80061C08(s32 nResult, NANDCommandBlock* block) { static void fn_80061C4C(s32 nResult, NANDCommandBlock* block) { Store* pStore = (Store*)NANDGetUserData(block); - bool bSuccess; + s32 nCloseResult; - pStore->unk_BC = nResult; - bSuccess = NANDCloseAsync(&pStore->nandFileInfo, fn_80061C08, &pStore->nandCmdBlock); + pStore->eResult = nResult; + nCloseResult = NANDCloseAsync(&pStore->nandFileInfo, fn_80061C08, &pStore->nandCmdBlock); - if (bSuccess) { - pStore->unk_BC = bSuccess; + if (nCloseResult) { + pStore->eResult = nCloseResult; pStore->unk_B9 = 1; } } @@ -208,9 +209,9 @@ static bool fn_80061CAC(Store* pStore) { pStore->unk_B9 = 0; pStore->unk_B8 = 0; - memcpy(pStore->unk_AC, (void*)pStore->unk_A8, pStore->unk_00); - DCFlushRange(pStore->unk_AC, pStore->unk_00); - NANDSetUserData(&pStore->nandCmdBlock, &pStore->unk_00); + memcpy(pStore->unk_AC, (void*)pStore->unk_A8, pStore->nFileSize); + DCFlushRange(pStore->unk_AC, pStore->nFileSize); + NANDSetUserData(&pStore->nandCmdBlock, pStore); while (true) { if (!unknownInline(pStore, 3)) { @@ -221,8 +222,8 @@ static bool fn_80061CAC(Store* pStore) { return true; } - if (NANDWriteAsync(&pStore->nandFileInfo, pStore->unk_AC, pStore->unk_00, fn_80061C4C, &pStore->nandCmdBlock) >= - 0) { + if (NANDWriteAsync(&pStore->nandFileInfo, pStore->unk_AC, pStore->nFileSize, fn_80061C4C, + &pStore->nandCmdBlock) >= 0) { break; } @@ -241,7 +242,7 @@ static inline void fn_80061DB8_Inline(Store* pStore) { unk_B9 = pStore->unk_B9; OSRestoreInterrupts(interrupts); - if (unk_B9 == 1 && pStore->unk_BC != pStore->unk_00) { + if (unk_B9 == 1 && pStore->nSize2 != pStore->nFileSize) { pStore->unk_B8 = 1; } @@ -270,7 +271,7 @@ bool fn_80061DB8(void) { unk_B9 = pStore->unk_B9; OSRestoreInterrupts(interrupts); - if (unk_B9 == 1 && pStore->unk_BC != pStore->unk_00) { + if (unk_B9 == 1 && pStore->nSize2 != pStore->nFileSize) { pStore->unk_B8 = 1; } diff --git a/src/emulator/system.c b/src/emulator/system.c index f609702..fe29ab2 100644 --- a/src/emulator/system.c +++ b/src/emulator/system.c @@ -1101,7 +1101,7 @@ static bool systemSetupGameALL(System* pSystem) { break; case NTEJ: case NTEP: - case 'NTEA': + case NTEA: pArgument = 0x8000; gSystemRomConfigurationList.storageDevice = SOT_PIF; storageDevice = SOT_SRAM; @@ -1416,8 +1416,8 @@ static bool systemGetBlock(System* pSystem, CpuBlock* pBlock) { static inline bool fn_8000A504_UnknownInline(System* pSystem, CpuBlock** pBlock) { s32 i; - for (i = 0; i < 4; i++) { - if (*pBlock == (CpuBlock*)(pSystem->unk_78 + (i * 5))) { + for (i = 0; i < ARRAY_COUNT(pSystem->aBlock); i++) { + if (*pBlock == &pSystem->aBlock[i]) { pSystem->storageDevice &= ~(1 << i); return true; } @@ -1474,10 +1474,10 @@ static bool fn_8000A504(CpuBlock* pBlock, bool bUnknown) { static inline bool systemGetNewBlock(System* pSystem, CpuBlock** ppBlock) { s32 i; - for (i = 0; i < 4; i++) { + for (i = 0; i < ARRAY_COUNT(pSystem->aBlock); i++) { if (!(pSystem->storageDevice & (1 << i))) { pSystem->storageDevice |= (1 << i); - *ppBlock = (CpuBlock*)(pSystem->unk_78 + (i * 5)); + *ppBlock = &pSystem->aBlock[i]; return true; } } @@ -1619,7 +1619,7 @@ bool systemReset(System* pSystem) { for (eObject = 0; eObject < SOT_COUNT; eObject++) { if (pSystem->apObject[eObject] != NULL) { - xlObjectEvent(pSystem->apObject[eObject], 0x1003, NULL); + if (!xlObjectEvent(pSystem->apObject[eObject], 0x1003, NULL)) {} } } } diff --git a/src/emulator/vc64_RVL.c b/src/emulator/vc64_RVL.c index 51b8806..eb088ea 100644 --- a/src/emulator/vc64_RVL.c +++ b/src/emulator/vc64_RVL.c @@ -56,6 +56,7 @@ static bool simulatorParseArguments(void) { } iArgument = 1; + while (iArgument < xlCoreGetArgumentCount()) { xlCoreGetArgument(iArgument, &szText); iArgument += 1; @@ -143,7 +144,7 @@ bool xlMain(void) { simulatorParseArguments(); - if (!xlHeapGetFree(&nSize0)) { + if (!xlHeapGetHeap1Free(&nSize0)) { return false; } @@ -172,7 +173,7 @@ bool xlMain(void) { GXSetCopyClear(color, 0xFFFFFF); - if (!xlHeapGetFree(&nSize0)) { + if (!xlHeapGetHeap1Free(&nSize0)) { return false; } @@ -202,7 +203,7 @@ bool xlMain(void) { return false; } - if (!xlHeapGetFree(&nSize1)) { + if (!xlHeapGetHeap1Free(&nSize1)) { return false; } diff --git a/src/emulator/xlCoreRVL.c b/src/emulator/xlCoreRVL.c index 252bc4b..125c1d7 100644 --- a/src/emulator/xlCoreRVL.c +++ b/src/emulator/xlCoreRVL.c @@ -139,7 +139,6 @@ void xlExit(void) { OSPanic("xlCoreRVL.c", 524, "xlExit"); } int main(int nCount, char** aszArgument) { s32 nSizeHeap; s32 nSize; - f32 aspectRatio; gnCountArgument = nCount; @@ -156,23 +155,7 @@ int main(int nCount, char** aszArgument) { VIInit(); xlCoreInitRenderMode(NULL); VIConfigure(rmode); - -#ifdef __MWERKS__ // clang-format off - asm { - li r3, 0x4 - oris r3, r3, 0x4 - mtspr GQR2, r3 - li r3, 0x5 - oris r3, r3, 0x5 - mtspr GQR3, r3 - li r3, 0x6 - oris r3, r3, 0x6 - mtspr GQR4, r3 - li r3, 0x7 - oris r3, r3, 0x7 - mtspr GQR5, r3 - } -#endif // clang-format on + OSInitFastCast(); if (!xlPostSetup()) { return false; diff --git a/src/emulator/xlFileRVL.c b/src/emulator/xlFileRVL.c index bc62689..d346420 100644 --- a/src/emulator/xlFileRVL.c +++ b/src/emulator/xlFileRVL.c @@ -61,6 +61,7 @@ bool xlFileGet(tXL_FILE* pFile, void* pTarget, s32 nSizeBytes) { s32 nOffsetExtra; s32 nSize; s32 nSizeUsed; + CNTResult result; if (pFile->nOffset + nSizeBytes > pFile->nSize) { nSizeBytes = pFile->nSize - pFile->nOffset; @@ -99,7 +100,7 @@ bool xlFileGet(tXL_FILE* pFile, void* pTarget, s32 nSizeBytes) { if (gpfRead != NULL) { gpfRead((DVDFileInfo*)pFile->pData, pTarget, nSizeBytes, nOffset, NULL); } else { - contentReadNAND((CNTFileInfoNAND*)pFile->pData, pTarget, nSizeBytes, nOffset); + result = contentReadNAND((CNTFileInfoNAND*)pFile->pData, pTarget, nSizeBytes, nOffset); } temp_r0 = pFile->nOffset + nSizeBytes; @@ -118,7 +119,7 @@ bool xlFileGet(tXL_FILE* pFile, void* pTarget, s32 nSizeBytes) { if (gpfRead != NULL) { gpfRead((DVDFileInfo*)pFile->pData, pFile->pBuffer, nSize, nOffset, NULL); } else { - contentReadNAND((CNTFileInfoNAND*)pFile->pData, pFile->pBuffer, nSize, nOffset); + result = contentReadNAND((CNTFileInfoNAND*)pFile->pData, pFile->pBuffer, nSize, nOffset); } } } diff --git a/src/emulator/xlHeap.c b/src/emulator/xlHeap.c index d5c19c4..25734c5 100644 --- a/src/emulator/xlHeap.c +++ b/src/emulator/xlHeap.c @@ -631,7 +631,7 @@ static bool __xlHeapGetFree(s32 iHeap, s32* pnFreeBytes) { return true; } -bool xlHeapGetFree(s32* pnFreeBytes) { return __xlHeapGetFree(0, pnFreeBytes); } +bool xlHeapGetHeap1Free(s32* pnFreeBytes) { return __xlHeapGetFree(0, pnFreeBytes); } bool xlHeapSetup(void) { s32 gpHeap_align[2]; diff --git a/tools/project.py b/tools/project.py index e0ee16d..831f7df 100755 --- a/tools/project.py +++ b/tools/project.py @@ -79,7 +79,12 @@ def set_default(key: str, value: Any) -> None: set_default("asflags", config.asflags) set_default("asm_dir", config.asm_dir) set_default("host", False) - set_default("mw_version", config.linker_version) + if obj.options.get("mw_version") is not None: + set_default("mw_version", config.linker_version) + elif obj.options.get("mw_versions") is not None: + obj.options["mw_version"] = obj.options["mw_versions"].get(version, config.linker_version) + else: + sys.exit(f"ERROR: compiler version not found for '{version}'.") set_default("shift_jis", config.shift_jis) set_default("src_dir", config.src_dir)