diff --git a/configure.py b/configure.py index e3d9bc02b..237a904a3 100644 --- a/configure.py +++ b/configure.py @@ -962,28 +962,28 @@ config.libs = [ "os", [ Object(NonMatching, "dolphin/os/__start.c"), - Object(NonMatching, "dolphin/os/OS.c"), - Object(NonMatching, "dolphin/os/OSAlarm.c"), + Object(Matching, "dolphin/os/OS.c"), + Object(Matching, "dolphin/os/OSAlarm.c"), Object(NonMatching, "dolphin/os/OSAlloc.c"), Object(Matching, "dolphin/os/OSArena.c"), Object(Matching, "dolphin/os/OSAudioSystem.c"), - Object(NonMatching, "dolphin/os/OSCache.c"), - Object(NonMatching, "dolphin/os/OSContext.c"), - Object(NonMatching, "dolphin/os/OSError.c"), - Object(NonMatching, "dolphin/os/OSFont.c"), + Object(Matching, "dolphin/os/OSCache.c"), + Object(Matching, "dolphin/os/OSContext.c"), + Object(Matching, "dolphin/os/OSError.c"), + Object(Matching, "dolphin/os/OSFont.c"), Object(Matching, "dolphin/os/OSInterrupt.c"), Object(Matching, "dolphin/os/OSLink.c"), Object(Matching, "dolphin/os/OSMessage.c"), - Object(NonMatching, "dolphin/os/OSMemory.c"), + Object(Matching, "dolphin/os/OSMemory.c"), Object(Matching, "dolphin/os/OSMutex.c"), Object(NonMatching, "dolphin/os/OSReboot.c"), - Object(NonMatching, "dolphin/os/OSReset.c"), - Object(NonMatching, "dolphin/os/OSResetSW.c"), - Object(NonMatching, "dolphin/os/OSRtc.c"), + Object(Matching, "dolphin/os/OSReset.c"), + Object(Matching, "dolphin/os/OSResetSW.c"), + Object(Matching, "dolphin/os/OSRtc.c"), Object(Matching, "dolphin/os/OSSync.c"), - Object(NonMatching, "dolphin/os/OSThread.c"), - Object(NonMatching, "dolphin/os/OSTime.c"), - Object(NonMatching, "dolphin/os/__ppc_eabi_init.cpp"), + Object(Matching, "dolphin/os/OSThread.c"), + Object(Matching, "dolphin/os/OSTime.c"), + Object(Matching, "dolphin/os/__ppc_eabi_init.cpp"), ], ), DolphinLib( diff --git a/include/dolphin/amcstubs/AmcExi2Stubs.h b/include/dolphin/amcstubs/AmcExi2Stubs.h new file mode 100644 index 000000000..818d22610 --- /dev/null +++ b/include/dolphin/amcstubs/AmcExi2Stubs.h @@ -0,0 +1,30 @@ +#ifndef AMCEXI2STUBS_H +#define AMCEXI2STUBS_H + +#include "dolphin/os/OS.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef __OSInterruptHandler AmcEXICallback; + +typedef enum { + AMC_EXI_NO_ERROR = 0, + AMC_EXI_UNSELECTED +} AmcExiError; + +void EXI2_Init(vu8**, AmcEXICallback); +void EXI2_EnableInterrupts(void); +int EXI2_Poll(void); +AmcExiError EXI2_ReadN(void*, u32); +AmcExiError EXI2_WriteN(const void*, u32); +void EXI2_Reserve(void); +void EXI2_Unreserve(void); +BOOL AMC_IsStub(void); + +#ifdef __cplusplus +}; +#endif + +#endif /* AMCEXI2STUBS_H */ diff --git a/include/dolphin/db/db.h b/include/dolphin/db/db.h new file mode 100644 index 000000000..5727c9e2b --- /dev/null +++ b/include/dolphin/db/db.h @@ -0,0 +1,38 @@ +#ifndef DB_H +#define DB_H + +#include "dolphin/amcstubs/AmcExi2Stubs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define OS_DBINTERFACE_ADDR 0x00000040 + +typedef struct DBInterface { + /* 0x0 */ u32 bPresent; + /* 0x4 */ u32 exceptionMask; + /* 0x8 */ void (*ExceptionDestination)(void); + /* 0xC */ void* exceptionReturn; +} DBInterface; + +extern DBInterface* __DBInterface; + +void DBInit(void); +void __DBExceptionDestinationAux(void); +void __DBExceptionDestination(void); +BOOL __DBIsExceptionMarked(__OSException); +void DBPrintf(char* format, ...); +void DBInitComm(vu8**, AmcEXICallback); // possibly not this type, but some similar construction +void DBInitInterrupts(); +u32 DBQueryData(); +BOOL DBRead(void*, u32); +BOOL DBWrite(const void*, u32); +void DBOpen(); +void DBClose(); + +#ifdef __cplusplus +} +#endif + +#endif /* DB_H */ diff --git a/include/dolphin/dvd/dvd.h b/include/dolphin/dvd/dvd.h index a7d68f5ad..480cd5c5f 100644 --- a/include/dolphin/dvd/dvd.h +++ b/include/dolphin/dvd/dvd.h @@ -1,7 +1,7 @@ #ifndef DVD_H #define DVD_H -#include "dolphin/types.h" +#include "global.h" #ifdef __cplusplus extern "C" { @@ -84,7 +84,7 @@ typedef struct DVDDriveInfo { /* 0x02 */ u16 device_code; /* 0x04 */ u32 release_date; /* 0x08 */ u8 padding[24]; -} DVDDriveInfo; +} DVDDriveInfo ALIGN_DECL(32); typedef struct DVDBB1 { u32 appLoaderLength; @@ -142,9 +142,11 @@ BOOL DVDSetAutoInvalidation(BOOL autoInval); void DVDResume(void); static BOOL DVDCancelAsync(DVDCommandBlock* block, DVDCBCallback callback); s32 DVDCancel(DVDCommandBlock* block); - +void __DVDPrepareResetAsync(DVDCBCallback callbac); BOOL DVDCompareDiskID(DVDDiskID* id1, DVDDiskID* id2); +DVDCommandBlock* __DVDPopWaitingQueue(void); + #ifdef __cplusplus }; #endif diff --git a/include/dolphin/os/OS.h b/include/dolphin/os/OS.h index f9a91d8b3..fc5e9ce7c 100644 --- a/include/dolphin/os/OS.h +++ b/include/dolphin/os/OS.h @@ -90,7 +90,7 @@ extern u8 __OSReport_enable; extern BOOL __OSIsGcam; -extern u32 BOOT_REGION_START : 0x8044babc; +extern u32 BOOT_REGION_START : 0x812FDFF0; extern u32 BOOT_REGION_END : 0x812FDFEC; void OSReportInit__Fv(void); // needed for inline asm diff --git a/include/dolphin/os/OSThread.h b/include/dolphin/os/OSThread.h index 5052dd23c..f13bc3479 100644 --- a/include/dolphin/os/OSThread.h +++ b/include/dolphin/os/OSThread.h @@ -98,7 +98,7 @@ BOOL OSCreateThread(OSThread* thread, void* func, void* param, void* stackBase, void OSExitThread(void* exitValue); void OSCancelThread(OSThread* thread); void OSDetachThread(OSThread* thread); -BOOL OSJoinThread(OSThread* thread, void**); +BOOL OSJoinThread(OSThread* thread, void*); s32 OSResumeThread(OSThread* thread); s32 OSSuspendThread(OSThread* thread); void OSSleepThread(OSThreadQueue* queue); diff --git a/src/dolphin/os/OS.c b/src/dolphin/os/OS.c index e63e395bd..8e6a1a744 100644 --- a/src/dolphin/os/OS.c +++ b/src/dolphin/os/OS.c @@ -4,7 +4,7 @@ #include "dolphin/os/OS.h" #include "dolphin/base/PPCArch.h" -// #include "dolphin/db.h" +#include "dolphin/db/db.h" #include "dolphin/pad/Pad.h" #include "dolphin/dvd/dvdfs.h" // #include "TRK_MINNOW_DOLPHIN/Os/dolphin/dolphin_trk.h" @@ -38,20 +38,12 @@ OSTime __OSStartTime; BOOL __OSInIPL; -extern OSExceptionHandler* OSExceptionTable; -OSExceptionHandler* OSExceptionTable; - -extern BOOL AreWeInitialized; -BOOL AreWeInitialized; - extern f64 ZeroPS; f64 ZeroPS; extern f64 ZeroF; f64 ZeroF; -BOOL __OSIsGcam; - asm void __OSFPRInit(void) { // clang-format off nofralloc @@ -138,6 +130,11 @@ skip_ps_init: // clang-format on } +static void DisableWriteGatherPipe(void) +{ + PPCMthid2(PPCMfhid2() & ~0x40000000); +} + u32 OSGetConsoleType(void) { if (BootInfo == NULL || BootInfo->console_type == 0) { return OS_CONSOLE_ARTHUR; @@ -151,37 +148,40 @@ static DVDDriveInfo DriveInfo; void* __OSSavedRegionStart; void* __OSSavedRegionEnd; -extern OSExecParams __OSRebootParams; +extern OSExceptionHandler* OSExceptionTable; +OSExceptionHandler* OSExceptionTable; -static inline void ClearArena(void) { - BOOL var_r0; - if (OSGetResetCode() & 0x80000000) { - var_r0 = TRUE; - } else { - var_r0 = FALSE; - } +extern BOOL AreWeInitialized; +BOOL AreWeInitialized; - if (!var_r0) { +BOOL __OSIsGcam; + +static void ClearArena(void) { + if (OSGetResetCode() != 0x80000000) { + __OSSavedRegionStart = 0; + __OSSavedRegionEnd = 0; memset(OSGetArenaLo(), 0U, (u32)OSGetArenaHi() - (u32)OSGetArenaLo()); return; } - if (*(u32*)&__OSRebootParams.regionStart == 0U) { + __OSSavedRegionStart = (void*)BOOT_REGION_START; + __OSSavedRegionEnd = (void*)BOOT_REGION_END; + if (*(u32*)&BOOT_REGION_START == 0U) { memset(OSGetArenaLo(), 0U, (u32)OSGetArenaHi() - (u32)OSGetArenaLo()); return; } - if ((u32)OSGetArenaLo() < *(u32*)&__OSRebootParams.regionStart) { - if ((u32)OSGetArenaHi() <= *(u32*)&__OSRebootParams.regionStart) { + if ((u32)OSGetArenaLo() < *(u32*)&__OSSavedRegionStart) { + if ((u32)OSGetArenaHi() <= *(u32*)&__OSSavedRegionStart) { memset((u32)OSGetArenaLo(), 0U, (u32)OSGetArenaHi() - (u32)OSGetArenaLo()); return; } - memset(OSGetArenaLo(), 0U, *(u32*)&__OSRebootParams.regionStart - (u32)OSGetArenaLo()); + memset(OSGetArenaLo(), 0U, *(u32*)&__OSSavedRegionStart - (u32)OSGetArenaLo()); - if ((u32)OSGetArenaHi() > *(u32*)&__OSRebootParams.regionEnd) { - memset(*(u32*)&__OSRebootParams.regionEnd, 0, - (u32)OSGetArenaHi() - *(u32*)&__OSRebootParams.regionEnd); + if ((u32)OSGetArenaHi() > *(u32*)&__OSSavedRegionEnd) { + memset(*(u32*)&__OSSavedRegionEnd, 0, + (u32)OSGetArenaHi() - *(u32*)&__OSSavedRegionEnd); } } } @@ -199,9 +199,7 @@ static void InquiryCallback(s32 result, DVDCommandBlock* block) { static u8 DriveBlock[48]; -OSExecParams __OSRebootParams; - -static const char* __OSVersion = "<< Dolphin SDK - OS release build: Nov 10 2004 06:26:41 (0x2301) >>"; +static const char* __OSVersion = "<< Dolphin SDK - OS release build: Sep 27 2002 14:02:03 (0x2301) >>"; extern u8 __ArenaHi[]; extern u8 __ArenaLo[]; @@ -228,13 +226,6 @@ void OSInit(void) { __OSStartTime = __OSGetSystemTime(); OSDisableInterrupts(); - __OSGetExecParams(&__OSRebootParams); - PPCMtmmcr0(0); - PPCMtmmcr1(0); - PPCMtpmc1(0); - PPCMtpmc2(0); - PPCMtpmc3(0); - PPCMtpmc4(0); PPCDisableSpeculation(); PPCSetFpNonIEEEMode(); @@ -289,13 +280,13 @@ void OSInit(void) { __OSInitSram(); __OSThreadInit(); __OSInitAudioSystem(); - PPCMthid2(PPCMfhid2() & 0xBFFFFFFF); + DisableWriteGatherPipe(); if ((BOOL)__OSInIPL == FALSE) { __OSInitMemoryProtection(); } - OSReport("\nDolphin OS\n"); - OSReport("Kernel built : %s %s\n", "Nov 10 2004", "06:26:41"); + OSReport("\nDolphin OS $Revision: 58 $.\n"); + OSReport("Kernel built : %s %s\n", "Sep 27 2002", "14:02:03"); OSReport("Console Type : "); if (BootInfo == NULL || (inputConsoleType = BootInfo->console_type) == 0) { @@ -304,13 +295,12 @@ void OSInit(void) { inputConsoleType = BootInfo->console_type; } - switch (inputConsoleType & 0xF0000000) { + switch (inputConsoleType & 0xFFFF0000) { case OS_CONSOLE_RETAIL: OSReport("Retail %d\n", inputConsoleType); break; - case OS_CONSOLE_DEVELOPMENT: - case OS_CONSOLE_TDEV: - switch (inputConsoleType & 0x0FFFFFFF) { + default: + switch (inputConsoleType & 0x0000FFFF) { case OS_CONSOLE_EMULATOR: OSReport("Mac Emulator\n"); break; @@ -324,14 +314,11 @@ void OSInit(void) { OSReport("EPPC Minnow\n"); break; default: - tdev = (u32)inputConsoleType & 0x0FFFFFFF; + tdev = (u32)inputConsoleType & 0x0000FFFF; OSReport("Development HW%d (%08x)\n", tdev - 3, inputConsoleType); break; } break; - default: - OSReport("%08x\n", inputConsoleType); - break; } OSReport("Memory %d MB\n", (u32)BootInfo->memory_size >> 0x14U); @@ -632,14 +619,7 @@ asm void __OSPSInit(void){ sync li r3, 0 - mtspr 0x390, r3 - mtspr 0x391, r3 - mtspr 0x392, r3 - mtspr 0x393, r3 - mtspr 0x394, r3 - mtspr 0x395, r3 - mtspr 0x396, r3 - mtspr 0x397, r3 + mtspr GQR0, r3 lwz r0, 0xc(r1) addi r1, r1, 8 diff --git a/src/dolphin/os/OSAlarm.c b/src/dolphin/os/OSAlarm.c index 08808fd56..61e9af128 100644 --- a/src/dolphin/os/OSAlarm.c +++ b/src/dolphin/os/OSAlarm.c @@ -15,7 +15,6 @@ void OSInitAlarm(void) { if (__OSGetExceptionHandler(8) != DecrementerExceptionHandler) { AlarmQueue.head = AlarmQueue.tail = NULL; __OSSetExceptionHandler(8, DecrementerExceptionHandler); - OSRegisterResetFunction(&ResetFunctionInfo); } } diff --git a/src/dolphin/os/OSCache.c b/src/dolphin/os/OSCache.c index 81a28e465..0d3138e6f 100644 --- a/src/dolphin/os/OSCache.c +++ b/src/dolphin/os/OSCache.c @@ -1,6 +1,6 @@ #include "dolphin/os/OSCache.h" #include "dolphin/base/PPCArch.h" -// #include "dolphin/db.h" +#include "dolphin/db/db.h" #include "dolphin/os/OS.h" static asm void DCEnable(void) { @@ -335,10 +335,12 @@ asm void LCQueueWait(register u32 len) { // clang-format off nofralloc - mfspr r4, 0x398 + addi len, len, 1 +LCQueueWait_04: + mfspr r4, HID2 rlwinm r4, r4, 8, 28, 31 - cmpw r4, len - bgt LCQueueWait + cmpw cr2, r4, len + bge cr2, LCQueueWait_04 blr // clang-format on diff --git a/src/dolphin/os/OSContext.c b/src/dolphin/os/OSContext.c index 9c9b75095..f41d4aff2 100644 --- a/src/dolphin/os/OSContext.c +++ b/src/dolphin/os/OSContext.c @@ -1,5 +1,5 @@ #include "dolphin/os/OSContext.h" -// #include "dolphin/db.h" +#include "dolphin/db/db.h" #include "dolphin/os/OS.h" volatile OSContext* __OSCurrentContext : (OS_BASE_CACHED | 0x00D4); diff --git a/src/dolphin/os/OSFont.c b/src/dolphin/os/OSFont.c index 218f50c2c..7d15a8a99 100644 --- a/src/dolphin/os/OSFont.c +++ b/src/dolphin/os/OSFont.c @@ -2,256 +2,16 @@ #include "dolphin/os/OS.h" #include "dolphin/vi/vi.h" -static u16 HankakuToCode[192] = { - 0x020C, 0x020D, 0x020E, 0x020F, 0x0210, 0x0211, 0x0212, 0x0213, - 0x0214, 0x0215, 0x0216, 0x0217, 0x0218, 0x0219, 0x021A, 0x021B, - 0x021C, 0x021D, 0x021E, 0x021F, 0x0220, 0x0221, 0x0222, 0x0223, - 0x0224, 0x0225, 0x0226, 0x0227, 0x0228, 0x0229, 0x022A, 0x022B, - 0x022C, 0x022D, 0x022E, 0x022F, 0x0230, 0x0231, 0x0232, 0x0233, - 0x0234, 0x0235, 0x0236, 0x0237, 0x0238, 0x0239, 0x023A, 0x023B, - 0x023C, 0x023D, 0x023E, 0x023F, 0x0240, 0x0241, 0x0242, 0x0243, - 0x0244, 0x0245, 0x0246, 0x0247, 0x0248, 0x0249, 0x024A, 0x024B, - 0x024C, 0x024D, 0x024E, 0x024F, 0x0250, 0x0251, 0x0252, 0x0253, - 0x0254, 0x0255, 0x0256, 0x0257, 0x0258, 0x0259, 0x025A, 0x025B, - 0x025C, 0x025D, 0x025E, 0x025F, 0x0260, 0x0261, 0x0262, 0x0263, - 0x0264, 0x0265, 0x0266, 0x0267, 0x0268, 0x0269, 0x026A, 0x020C, - 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, - 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, - 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, - 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, 0x020C, - 0x020C, 0x026B, 0x026C, 0x026D, 0x026E, 0x026F, 0x0270, 0x0271, - 0x0272, 0x0273, 0x0274, 0x0275, 0x0276, 0x0277, 0x0278, 0x0279, - 0x027A, 0x027B, 0x027C, 0x027D, 0x027E, 0x027F, 0x0280, 0x0281, - 0x0282, 0x0283, 0x0284, 0x0285, 0x0286, 0x0287, 0x0288, 0x0289, - 0x028A, 0x028B, 0x028C, 0x028D, 0x028E, 0x028F, 0x0290, 0x0291, - 0x0292, 0x0293, 0x0294, 0x0295, 0x0296, 0x0297, 0x0298, 0x0299, - 0x029A, 0x029B, 0x029C, 0x029D, 0x029E, 0x029F, 0x02A0, 0x02A1, - 0x02A2, 0x02A3, 0x02A4, 0x02A5, 0x02A6, 0x02A7, 0x02A8, 0x02A9, -}; - -static u16 Zenkaku2Code[1221] = { - 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, - 0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, - 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017, - 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, - 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, - 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, - 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, - 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F, - 0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, - 0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F, - 0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, - 0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F, - 0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, - 0x0068, 0x0069, 0x006A, 0x006B, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x006C, - 0x006D, 0x006E, 0x006F, 0x0070, 0x0071, 0x0072, 0x0073, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0074, - 0x0075, 0x0076, 0x0077, 0x0078, 0x0079, 0x007A, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x007B, 0x007C, 0x007D, 0x007E, 0x007F, 0x0080, 0x0081, - 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088, 0x0089, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x008A, - 0x008B, 0x008C, 0x008D, 0x008E, 0x008F, 0x0090, 0x0091, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0092, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097, - 0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x009D, 0x009E, 0x009F, 0x00A0, - 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7, 0x00A8, - 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF, 0x00B0, - 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x00B7, 0x00B8, 0x00B9, 0x00BA, - 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF, 0x00C0, 0x00C1, 0x00C2, - 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7, 0x00C8, 0x00C9, 0x00CA, - 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF, 0x00D0, 0x0000, 0x0000, - 0x0000, 0x0000, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, - 0x00D7, 0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, - 0x00DF, 0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, - 0x00E7, 0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, - 0x00EF, 0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, - 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, - 0x00FF, 0x0100, 0x0101, 0x0102, 0x0103, 0x0104, 0x0105, 0x0106, - 0x0107, 0x0108, 0x0109, 0x010A, 0x010B, 0x010C, 0x010D, 0x010E, - 0x010F, 0x0110, 0x0111, 0x0112, 0x0113, 0x0114, 0x0115, 0x0116, - 0x0117, 0x0118, 0x0119, 0x011A, 0x011B, 0x011C, 0x011D, 0x011E, - 0x011F, 0x0120, 0x0121, 0x0122, 0x0123, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0124, 0x0125, 0x0126, 0x0127, 0x0128, 0x0129, 0x012A, 0x012B, - 0x012C, 0x012D, 0x012E, 0x012F, 0x0130, 0x0131, 0x0132, 0x0133, - 0x0134, 0x0135, 0x0136, 0x0137, 0x0138, 0x0139, 0x013A, 0x013B, - 0x013C, 0x013D, 0x013E, 0x013F, 0x0140, 0x0141, 0x0142, 0x0143, - 0x0144, 0x0145, 0x0146, 0x0147, 0x0148, 0x0149, 0x014A, 0x014B, - 0x014C, 0x014D, 0x014E, 0x014F, 0x0150, 0x0151, 0x0152, 0x0153, - 0x0154, 0x0155, 0x0156, 0x0157, 0x0158, 0x0159, 0x015A, 0x015B, - 0x015C, 0x015D, 0x015E, 0x015F, 0x0160, 0x0161, 0x0162, 0x0163, - 0x0164, 0x0165, 0x0166, 0x0167, 0x0168, 0x0169, 0x016A, 0x016B, - 0x016C, 0x016D, 0x016E, 0x016F, 0x0170, 0x0171, 0x0172, 0x0173, - 0x0174, 0x0175, 0x0176, 0x0177, 0x0178, 0x0179, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x017A, 0x017B, - 0x017C, 0x017D, 0x017E, 0x017F, 0x0180, 0x0181, 0x0182, 0x0183, - 0x0184, 0x0185, 0x0186, 0x0187, 0x0188, 0x0189, 0x018A, 0x018B, - 0x018C, 0x018D, 0x018E, 0x018F, 0x0190, 0x0191, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0192, 0x0193, - 0x0194, 0x0195, 0x0196, 0x0197, 0x0198, 0x0199, 0x019A, 0x019B, - 0x019C, 0x019D, 0x019E, 0x019F, 0x01A0, 0x01A1, 0x01A2, 0x01A3, - 0x01A4, 0x01A5, 0x01A6, 0x01A7, 0x01A8, 0x01A9, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x01AA, 0x01AB, 0x01AC, 0x01AD, - 0x01AE, 0x01AF, 0x01B0, 0x01B1, 0x01B2, 0x01B3, 0x01B4, 0x01B5, - 0x01B6, 0x01B7, 0x01B8, 0x01B9, 0x01BA, 0x01BB, 0x01BC, 0x01BD, - 0x01BE, 0x01BF, 0x01C0, 0x01C1, 0x01C2, 0x01C3, 0x01C4, 0x01C5, - 0x01C6, 0x01C7, 0x01C8, 0x01C9, 0x01CA, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x01CB, 0x01CC, 0x01CD, 0x01CE, - 0x01CF, 0x01D0, 0x01D1, 0x01D2, 0x01D3, 0x01D4, 0x01D5, 0x01D6, - 0x01D7, 0x01D8, 0x01D9, 0x01DA, 0x01DB, 0x01DC, 0x01DD, 0x01DE, - 0x01DF, 0x01E0, 0x01E1, 0x01E2, 0x01E3, 0x01E4, 0x01E5, 0x01E6, - 0x01E7, 0x01E8, 0x01E9, 0x01EA, 0x01EB, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x01EC, 0x01ED, 0x01EE, 0x01EF, 0x01F0, 0x01F1, - 0x01F2, 0x01F3, 0x01F4, 0x01F5, 0x01F6, 0x01F7, 0x01F8, 0x01F9, - 0x01FA, 0x01FB, 0x01FC, 0x01FD, 0x01FE, 0x01FF, 0x0200, 0x0201, - 0x0202, 0x0203, 0x0204, 0x0205, 0x0206, 0x0207, 0x0208, 0x0209, - 0x020A, 0x020B, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x020C, - 0x020D, 0x020E, 0x020F, 0x0210, 0x0211, 0x0212, 0x0213, 0x0214, - 0x0215, 0x0216, 0x0217, 0x0218, 0x0219, 0x021A, 0x021B, 0x021C, - 0x021D, 0x021E, 0x021F, 0x0220, 0x0221, 0x0222, 0x0223, 0x0224, - 0x0225, 0x0226, 0x0227, 0x0228, 0x0229, 0x022A, 0x022B, 0x022C, - 0x022D, 0x022E, 0x022F, 0x0230, 0x0231, 0x0232, 0x0233, 0x0234, - 0x0235, 0x0236, 0x0237, 0x0238, 0x0239, 0x023A, 0x023B, 0x023C, - 0x023D, 0x023E, 0x023F, 0x0240, 0x0241, 0x0242, 0x0243, 0x0244, - 0x0245, 0x0246, 0x0247, 0x0248, 0x0249, 0x024A, 0x024B, 0x024C, - 0x024D, 0x024E, 0x024F, 0x0250, 0x0251, 0x0252, 0x0253, 0x0254, - 0x0255, 0x0256, 0x0257, 0x0258, 0x0259, 0x025A, 0x025B, 0x025C, - 0x025D, 0x025E, 0x025F, 0x0260, 0x0261, 0x0262, 0x0263, 0x0264, - 0x0265, 0x0266, 0x0267, 0x0268, 0x0269, 0x026A, 0x026B, 0x026C, - 0x026D, 0x026E, 0x026F, 0x0270, 0x0271, 0x0272, 0x0273, 0x0274, - 0x0275, 0x0276, 0x0277, 0x0278, 0x0279, 0x027A, 0x027B, 0x027C, - 0x027D, 0x027E, 0x027F, 0x0280, 0x0281, 0x0282, 0x0283, 0x0284, - 0x0285, 0x0286, 0x0287, 0x0288, 0x0289, 0x028A, 0x028B, 0x028C, - 0x028D, 0x028E, 0x028F, 0x0290, 0x0291, 0x0292, 0x0293, 0x0294, - 0x0295, 0x0296, 0x0297, 0x0298, 0x0299, 0x029A, 0x029B, 0x029C, - 0x029D, 0x029E, 0x029F, 0x02A0, 0x02A1, 0x02A2, 0x02A3, 0x02A4, - 0x02A5, 0x02A6, 0x02A7, 0x02A8, 0x02A9, 0x02AA, 0x02AB, 0x02AC, - 0x02AD, 0x02AE, 0x02AF, 0x02B0, 0x02B1, 0x02B2, 0x02B3, 0x02B4, - 0x02B5, 0x02B6, 0x02B7, 0x02B8, 0x02B9, 0x02BA, 0x02BB, 0x02BC, - 0x02BD, 0x02BE, 0x02BF, 0x02C0, 0x02C1, 0x02C2, 0x02C3, 0x02C4, - 0x02C5, 0x02C6, 0x02C7, 0x02C8, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x02C9, 0x02CA, 0x02CB, 0x02CC, 0x02CD, 0x02CE, 0x02CF, 0x02D0, - 0x02D1, 0x02D2, 0x02D3, 0x02D4, 0x02D5, 0x02D6, 0x02D7, 0x02D8, - 0x02D9, 0x02DA, 0x02DB, 0x02DC, 0x02DD, 0x02DE, 0x02DF, 0x02E0, - 0x02E1, 0x02E2, 0x02E3, 0x02E4, 0x02E5, 0x02E6, 0x0000, 0x02E7, - 0x02E8, 0x02E9, 0x02EA, 0x02EB, 0x02EC, 0x02ED, 0x02EE, 0x02EF, - 0x02F0, 0x02F1, 0x02F2, 0x02F3, 0x02F4, 0x02F5, 0x02F6, 0x02F7, - 0x02F8, 0x02F9, 0x02FA, 0x02FB, 0x02FC, 0x02FD, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x02FE, 0x02FF, - 0x0300, 0x0301, 0x0302, 0x0303, 0x0304, 0x0305, 0x0306, 0x0307, - 0x0308, 0x0309, 0x030A, 0x030B, 0x030C, 0x030D, 0x030E, 0x030F, - 0x0310, 0x0311, 0x0312, 0x0313, 0x0314, 0x0315, 0x0316, 0x0317, - 0x0318, 0x0319, 0x031A, 0x031B, 0x0000, -}; - -static BOOL IsSjisLeadByte(u8 ch) { - return (0x81 <= ch && ch <= 0x9F) || (0xE0 <= ch && ch <= 0xFC); -} - -static BOOL IsSjisTrailByte(u8 ch) { - return (0x40 <= ch && ch <= 0xFC) && (ch != 0x7F); -} - -static u32 GetFontCode(u16 encode, u16 code) { - u32 tmp; - s32 trail; - - if (encode == OS_FONT_ENCODE_SJIS) { - if (0x20 <= code && code <= 0xDF) { - return HankakuToCode[code - 0x20]; - } else if (0x889E < code && code <= 0x9872) { - tmp = ((code >> 8) - 0x88) * 0xBC; - trail = code & 0xFF; - - if (!IsSjisTrailByte(trail)) { - return 0; - } - - trail -= 0x40; - if (trail >= 0x40) { - trail--; - } - - return tmp + trail + 0x2BE; - } else if (0x8140 <= code && code < 0x879E) { - tmp = ((code >> 8) - 0x81) * 0xBC; - trail = code & 0xFF; - - if (!IsSjisTrailByte(trail)) { - return 0; - } - - trail -= 0x40; - if (trail >= 0x40) { - trail--; - } - - return Zenkaku2Code[tmp + trail]; - } - } else if (code > 0x20 && code <= 0xFF) { - return code - 0x20; - } - - return 0; -} - -static u16 FontEncode = 0xFFFF; - -static OSFontHeader* FontDataAnsi; - -static OSFontHeader* FontDataSjis; - -static void* ParseString; - u16 OSGetFontEncode(void) { - if (FontEncode != 0xFFFF) { - return FontEncode; + static u16 fontEncode = 0xFFFF; + + if (fontEncode <= 1) { + return fontEncode; } switch (*(u32*)OSPhysicalToCached(0xCC)) { case VI_NTSC: - FontEncode = ((__VIRegs[55] & 2) != 0) + fontEncode = ((__VIRegs[55] & 2) != 0) ? OS_FONT_ENCODE_SJIS : OS_FONT_ENCODE_ANSI; break; @@ -261,43 +21,8 @@ u16 OSGetFontEncode(void) { case VI_DEBUG_PAL: case VI_EURGB60: default: - FontEncode = OS_FONT_ENCODE_ANSI; + fontEncode = OS_FONT_ENCODE_ANSI; } - ParseString = ParseStringS; - - return FontEncode; -} - -static const u8* ParseStringS(u16 encode, const u8* str, OSFontHeader** fontOut, - u32* codeOut) { - OSFontHeader* font; - u16 code = 0; - - switch (encode) { - case OS_FONT_ENCODE_ANSI: - font = FontDataAnsi; - code = *str; - if (code != 0) { - str++; - } - break; - case OS_FONT_ENCODE_SJIS: - font = FontDataSjis; - code = *str; - if (code == 0) { - break; - } - str++; - - if (IsSjisLeadByte(code) && IsSjisTrailByte(*str)) { - code = (code << 8 | *str++); - } - break; - } - - *fontOut = font; - *codeOut = GetFontCode(encode, code); - - return str; + return fontEncode; } diff --git a/src/dolphin/os/OSMemory.c b/src/dolphin/os/OSMemory.c index da66c1446..a91576ed4 100644 --- a/src/dolphin/os/OSMemory.c +++ b/src/dolphin/os/OSMemory.c @@ -8,6 +8,10 @@ vu16 __MEMRegs[64] : 0xCC004000; extern OSErrorHandlerEx __OSErrorTable[16]; +u32 OSGetConsoleSimulatedMemSize() { + return *(u32*)(OSPhysicalToCached(0x00F0)); +} + static BOOL OnReset(BOOL final) { if (final != FALSE) { __MEMRegs[8] = 0xFF; @@ -169,10 +173,6 @@ inline u32 OSGetPhysicalMemSize() { return *(u32*)(OSPhysicalToCached(0x0028)); } -inline u32 OSGetConsoleSimulatedMemSize() { - return *(u32*)(OSPhysicalToCached(0x00F0)); -} - void __OSInitMemoryProtection() { u32 padding[8]; u32 simulatedSize; @@ -180,6 +180,12 @@ void __OSInitMemoryProtection() { simulatedSize = OSGetConsoleSimulatedMemSize(); enabled = OSDisableInterrupts(); + if (simulatedSize <= 0x1800000) { + RealMode((u32)&Config24MB); + } else if (simulatedSize <= 0x3000000) { + RealMode((u32)&Config48MB); + } + __MEMRegs[16] = 0; __MEMRegs[8] = 0xFF; @@ -195,16 +201,9 @@ void __OSInitMemoryProtection() { if (OSGetConsoleSimulatedMemSize() < OSGetPhysicalMemSize() && OSGetConsoleSimulatedMemSize() == 0x1800000) { - DCInvalidateRange((void*)0x81800000, 0x1800000); __MEMRegs[20] = 2; } - if (simulatedSize <= 0x1800000) { - RealMode((u32)&Config24MB); - } else if (simulatedSize <= 0x3000000) { - RealMode((u32)&Config48MB); - } - __OSUnmaskInterrupts(OS_INTERRUPTMASK_MEM_ADDRESS); OSRestoreInterrupts(enabled); } diff --git a/src/dolphin/os/OSReset.c b/src/dolphin/os/OSReset.c index 77934c6f4..be39a12f3 100644 --- a/src/dolphin/os/OSReset.c +++ b/src/dolphin/os/OSReset.c @@ -4,8 +4,6 @@ vu16 __VIRegs[59] : 0xCC002000; OSThreadQueue __OSActiveThreadQueue : (OS_BASE_CACHED | 0x00DC); -extern OSExecParams __OSRebootParams; - static OSResetQueue ResetFunctionQueue; void OSRegisterResetFunction(OSResetFunctionInfo* func) { @@ -40,17 +38,13 @@ void OSRegisterResetFunction(OSResetFunctionInfo* func) { tmp->next = func; } -BOOL __OSCallResetFunctions(u32 arg0) { +inline BOOL __OSCallResetFunctions(u32 arg0) { OSResetFunctionInfo* iter; s32 retCode = 0; - u32 priority = 0; s32 temp; for (iter = ResetFunctionQueue.first; iter != NULL;) { - if (retCode != 0 && priority != iter->priority) - break; temp = !iter->func(arg0); - priority = iter->priority; iter = iter->next; retCode |= temp; } @@ -114,8 +108,7 @@ lbl_8033F7F8: // clang-format on } -#pragma dont_inline on -static void KillThreads(void) { +inline static void KillThreads(void) { OSThread* thread; OSThread* next; @@ -131,7 +124,6 @@ static void KillThreads(void) { } } } -#pragma dont_inline reset void __OSDoHotReset(s32 arg0) { OSDisableInterrupts(); @@ -140,13 +132,21 @@ void __OSDoHotReset(s32 arg0) { Reset(arg0 * 8); } -static u32 bootThisDol; - void OSResetSystem(int reset, u32 resetCode, BOOL forceMenu) { BOOL rc; BOOL disableRecalibration; - u32 unk; + u32 unk[3]; // dumb compiler + OSDisableScheduler(); + __OSStopAudioSystem(); + + if (reset == OS_RESET_SHUTDOWN) { + disableRecalibration = __PADDisableRecalibration(TRUE); + } + + while (!__OSCallResetFunctions(FALSE)) { + ; + } if (reset == OS_RESET_HOTRESET && forceMenu) { OSSram* sram; @@ -155,56 +155,36 @@ void OSResetSystem(int reset, u32 resetCode, BOOL forceMenu) { sram->flags |= 0x40; __OSUnlockSram(TRUE); - resetCode = 0; - } - - if (reset == OS_RESET_SHUTDOWN || - (reset == OS_RESET_RESTART && (bootThisDol || resetCode + 0x3fff0000 == 0))) - { - __OSStopAudioSystem(); - disableRecalibration = __PADDisableRecalibration(TRUE); - while (!__OSCallResetFunctions(FALSE)) - ; - while (!__OSSyncSram()) - ; - OSDisableInterrupts(); - __OSCallResetFunctions(TRUE); - LCDisable(); - __PADDisableRecalibration(disableRecalibration); - KillThreads(); - } else { - __OSStopAudioSystem(); - while (!__OSCallResetFunctions(FALSE)) - ; - while (!__OSSyncSram()) - ; - OSDisableInterrupts(); - __OSCallResetFunctions(TRUE); - LCDisable(); - KillThreads(); + while (!__OSSyncSram()) { + ; + } } + OSDisableInterrupts(); + __OSCallResetFunctions(TRUE); + LCDisable(); if (reset == OS_RESET_HOTRESET) { __OSDoHotReset(resetCode); } else if (reset == OS_RESET_RESTART) { - if (forceMenu == TRUE) { - OSReport( - "OSResetSystem(): You can't specify TRUE to forceMenu if you restart. Ignored\n"); - } + KillThreads(); OSEnableScheduler(); - __OSReboot(resetCode, bootThisDol); + __OSReboot(resetCode, forceMenu); } - memset(OSPhysicalToCached(0x40), 0, 0xcc - 0x40); - memset(OSPhysicalToCached(0xd4), 0, 0xe8 - 0xd4); - memset(OSPhysicalToCached(0xf4), 0, 0xf8 - 0xf4); - memset(OSPhysicalToCached(0x3000), 0, 0xc0); - memset(OSPhysicalToCached(0x30c8), 0, 0xd4 - 0xc8); - memset(OSPhysicalToCached(0x30e2), 0, 1); + + KillThreads(); + memset(OSPhysicalToCached(0x40), 0, 0xCC - 0x40); + memset(OSPhysicalToCached(0xD4), 0, 0xE8 - 0xD4); + memset(OSPhysicalToCached(0xF4), 0, 0xF8 - 0xF4); + memset(OSPhysicalToCached(0x3000), 0, 0xC0); + memset(OSPhysicalToCached(0x30C8), 0, 0xD4 - 0xC8); + memset(OSPhysicalToCached(0x30E2), 0, 1); + + __PADDisableRecalibration(disableRecalibration); } u32 OSGetResetCode(void) { - if (__OSRebootParams.valid) - return 0x80000000 | __OSRebootParams.restartCode; + if (*(u8*)OSPhysicalToCached(0x30E2) != 0) + return 0x80000000; return ((__PIRegs[9] & ~7) >> 3); } diff --git a/src/dolphin/os/OSResetSW.c b/src/dolphin/os/OSResetSW.c index 9fe625be7..386bc20db 100644 --- a/src/dolphin/os/OSResetSW.c +++ b/src/dolphin/os/OSResetSW.c @@ -69,8 +69,8 @@ BOOL OSGetResetButtonState(void) { LastState = state; - if (GameChoice & 0x1F) { - OSTime fire = (GameChoice & 0x1F) * 60; + if (GameChoice & 0x3F) { + OSTime fire = (GameChoice & 0x3F) * 60; fire = __OSStartTime + OSSecondsToTicks(fire); if (fire < now) { now -= fire; diff --git a/src/dolphin/os/OSRtc.c b/src/dolphin/os/OSRtc.c index 13b69ddd4..daf468cae 100644 --- a/src/dolphin/os/OSRtc.c +++ b/src/dolphin/os/OSRtc.c @@ -69,7 +69,6 @@ void __OSInitSram(void) { Scb.locked = Scb.enabled = FALSE; Scb.sync = ReadSram(Scb.sram); Scb.offset = RTC_SRAM_SIZE; - OSSetGbsMode(OSGetGbsMode()); } static void* LockSram(u32 offset) { @@ -117,13 +116,6 @@ static BOOL UnlockSram(BOOL commit, u32 offset) { Scb.offset = offset; } - if (Scb.offset <= 0x14) { - OSSramEx* sram = (OSSramEx*)(Scb.sram + sizeof(OSSram)); - if (((u32)sram->gbs & 0x7c00) == 0x5000 || ((u32)sram->gbs & 0xc0) == 0xc0) { - sram->gbs = 0; - } - } - Scb.sync = WriteSram(Scb.sram + Scb.offset, Scb.offset, RTC_SRAM_SIZE - Scb.offset); if (Scb.sync) { Scb.offset = RTC_SRAM_SIZE; @@ -221,31 +213,3 @@ void OSSetWirelessID(s32 channel, u16 id) { __OSUnlockSramEx(FALSE); } - -u16 OSGetGbsMode() { - OSSramEx* sram; - u16 gbs; - - sram = __OSLockSramEx(); - gbs = sram->gbs; - __OSUnlockSramEx(FALSE); - return gbs; -} - -void OSSetGbsMode(u16 mode) { - OSSramEx* sram; - - if (((u32)mode & 0x7c00) == 0x5000 || ((u32)mode & 0xc0) == 0xc0) { - mode = 0; - } - - sram = __OSLockSramEx(); - - if (mode == sram->gbs) { - __OSUnlockSramEx(FALSE); - return; - } - sram->gbs = mode; - - __OSUnlockSramEx(TRUE); -} diff --git a/src/dolphin/os/OSThread.c b/src/dolphin/os/OSThread.c index 6537c1b38..a420c7496 100644 --- a/src/dolphin/os/OSThread.c +++ b/src/dolphin/os/OSThread.c @@ -195,6 +195,22 @@ BOOL OSIsThreadTerminated(OSThread* thread) { FALSE; } +static BOOL __OSIsThreadActive(OSThread* thread) { + OSThread* active; + + if (thread->state == 0) { + return FALSE; + } + + for (active = __OSActiveThreadQueue.head; active; active = active->active_threads_link.next) { + if (thread == active) { + return TRUE; + } + } + + return FALSE; +} + s32 OSDisableScheduler(void) { BOOL intr = OSDisableInterrupts(); s32 ret = Reschedule++; @@ -354,8 +370,9 @@ static OSThread* SelectThread(BOOL yield) { } } + OSSetCurrentThread(NULL); + if (RunQueueBits == 0) { - OSSetCurrentThread(NULL); OSSetCurrentContext(&IdleContext); do { OSEnableInterrupts(); @@ -518,6 +535,29 @@ void OSCancelThread(OSThread* thread) { OSRestoreInterrupts(enabled); } +BOOL OSJoinThread(struct OSThread * thread, void * val) { + int enabled = OSDisableInterrupts(); + + if (!(thread->attributes & 1) && (thread->state != 8) && (thread->join_queue.head == NULL)) { + OSSleepThread(&thread->join_queue); + if (__OSIsThreadActive(thread) == 0) { + OSRestoreInterrupts(enabled); + return 0; + } + } + if (thread->state == 8) { + if (val) { + *(s32*)val = (s32)thread->exit_value; + } + RemoveItem(&__OSActiveThreadQueue, thread, active_threads_link); + thread->state = 0; + OSRestoreInterrupts(enabled); + return 1; + } + OSRestoreInterrupts(enabled); + return 0; +} + void OSDetachThread(OSThread* thread) { BOOL enabled; @@ -697,37 +737,37 @@ s32 OSCheckActiveThreads(void) { if (RunQueue[i].head == NULL || RunQueue[i].tail == NULL) { OSReport("OSCheckActiveThreads: Failed RunQueue[prio].head != NULL && " "RunQueue[prio].tail != NULL in %d\n", - 0x5e0); - OSPanic(__FILE__, 0x5e0, ""); + 0x5be); + OSPanic(__FILE__, 0x5be, ""); } } else { if (RunQueue[i].head != NULL || RunQueue[i].tail != NULL) { OSReport("OSCheckActiveThreads: Failed RunQueue[prio].head == NULL && " "RunQueue[prio].tail == NULL in %d\n", - 0x5e5); - OSPanic(__FILE__, 0x5e5, ""); + 0x5c3); + OSPanic(__FILE__, 0x5c3, ""); } } if (CheckThreadQueue(&RunQueue[i]) == 0) { OSReport("OSCheckActiveThreads: Failed CheckThreadQueue(&RunQueue[prio]) in %d\n", - 0x5e7); - OSPanic(__FILE__, 0x5e7, ""); + 0x5c5); + OSPanic(__FILE__, 0x5c5, ""); } } if (OS_THREAD_QUEUE.head != NULL && OS_THREAD_QUEUE.head->active_threads_link.prev != NULL) { OSReport("OSCheckActiveThreads: Failed __OSActiveThreadQueue.head == NULL || " "__OSActiveThreadQueue.head->linkActive.prev == NULL in %d\n", - 0x5ec); - OSPanic(__FILE__, 0x5ec, ""); + 0x5ca); + OSPanic(__FILE__, 0x5ca, ""); } if (OS_THREAD_QUEUE.tail != NULL && OS_THREAD_QUEUE.tail->active_threads_link.next != NULL) { OSReport("OSCheckActiveThreads: Failed __OSActiveThreadQueue.tail == NULL || " "__OSActiveThreadQueue.tail->linkActive.next == NULL in %d\n", - 0x5ee); - OSPanic(__FILE__, 0x5ee, ""); + 0x5cc); + OSPanic(__FILE__, 0x5cc, ""); } thread = OS_THREAD_QUEUE.head; @@ -739,8 +779,8 @@ s32 OSCheckActiveThreads(void) { { OSReport("OSCheckActiveThreads: Failed thread->linkActive.next == NULL || thread == " "thread->linkActive.next->linkActive.prev in %d\n", - 0x5f6); - OSPanic(__FILE__, 0x5f6, ""); + 0x5d4); + OSPanic(__FILE__, 0x5d4, ""); } if (thread->active_threads_link.prev != NULL && @@ -748,15 +788,15 @@ s32 OSCheckActiveThreads(void) { { OSReport("OSCheckActiveThreads: Failed thread->linkActive.prev == NULL || thread == " "thread->linkActive.prev->linkActive.next in %d\n", - 0x5f8); - OSPanic(__FILE__, 0x5f8, ""); + 0x5d6); + OSPanic(__FILE__, 0x5d6, ""); } if (*(u32*)thread->stack_end != OS_THREAD_STACK_MAGIC) { OSReport( "OSCheckActiveThreads: Failed *(thread->stackEnd) == OS_THREAD_STACK_MAGIC in %d\n", - 0x5fb); - OSPanic(__FILE__, 0x5fb, ""); + 0x5d9); + OSPanic(__FILE__, 0x5d9, ""); } if (OS_PRIORITY_MIN > thread->effective_priority || @@ -764,19 +804,19 @@ s32 OSCheckActiveThreads(void) { { OSReport("OSCheckActiveThreads: Failed OS_PRIORITY_MIN <= thread->priority && " "thread->priority <= OS_PRIORITY_MAX+1 in %d\n", - 0x5fe); - OSPanic(__FILE__, 0x5fe, ""); + 0x5dc); + OSPanic(__FILE__, 0x5dc, ""); } if (thread->suspend_count < 0) { - OSReport("OSCheckActiveThreads: Failed 0 <= thread->suspend in %d\n", 0x5ff); - OSPanic(__FILE__, 0x5ff, ""); + OSReport("OSCheckActiveThreads: Failed 0 <= thread->suspend in %d\n", 0x5dd); + OSPanic(__FILE__, 0x5dd, ""); } if (!CheckThreadQueue(&thread->join_queue)) { OSReport("OSCheckActiveThreads: Failed CheckThreadQueue(&thread->queueJoin) in %d\n", - 0x600); - OSPanic(__FILE__, 0x600, ""); + 0x5de); + OSPanic(__FILE__, 0x5de, ""); } switch (thread->state) { @@ -785,97 +825,97 @@ s32 OSCheckActiveThreads(void) { if (thread->queue != &RunQueue[thread->effective_priority]) { OSReport("OSCheckActiveThreads: Failed thread->queue == " "&RunQueue[thread->priority] in %d\n", - 0x606); - OSPanic(__FILE__, 0x606, ""); + 0x5e4); + OSPanic(__FILE__, 0x5e4, ""); } if (!isMember(&RunQueue[thread->effective_priority], thread)) { OSReport("OSCheckActiveThreads: Failed IsMember(&RunQueue[thread->priority], " "thread) in %d\n", - 0x607); - OSPanic(__FILE__, 0x607, ""); + 0x5e5); + OSPanic(__FILE__, 0x5e5, ""); } if (thread->effective_priority != __OSGetEffectivePriority(thread)) { OSReport("OSCheckActiveThreads: Failed thread->priority == " "__OSGetEffectivePriority(thread) in %d\n", - 0x608); - OSPanic(__FILE__, 0x608, ""); + 0x5e6); + OSPanic(__FILE__, 0x5e6, ""); } } break; case OS_THREAD_STATE_RUNNING: if (thread->suspend_count > 0) { OSReport("OSCheckActiveThreads: Failed !IsSuspended(thread->suspend) in %d\n", - 0x60c); - OSPanic(__FILE__, 0x60c, ""); + 0x5ea); + OSPanic(__FILE__, 0x5ea, ""); } if (thread->queue != NULL) { - OSReport("OSCheckActiveThreads: Failed thread->queue == NULL in %d\n", 0x60d); - OSPanic(__FILE__, 0x60d, ""); + OSReport("OSCheckActiveThreads: Failed thread->queue == NULL in %d\n", 0x5eb); + OSPanic(__FILE__, 0x5eb, ""); } if (thread->effective_priority != __OSGetEffectivePriority(thread)) { OSReport("OSCheckActiveThreads: Failed thread->priority == " "__OSGetEffectivePriority(thread) in %d\n", - 0x60e); - OSPanic(__FILE__, 0x60e, ""); + 0x5ec); + OSPanic(__FILE__, 0x5ec, ""); } break; case OS_THREAD_STATE_WAITING: if (thread->queue == NULL) { - OSReport("OSCheckActiveThreads: Failed thread->queue != NULL in %d\n", 0x611); - OSPanic(__FILE__, 0x611, ""); + OSReport("OSCheckActiveThreads: Failed thread->queue != NULL in %d\n", 0x5ef); + OSPanic(__FILE__, 0x5ef, ""); } if (CheckThreadQueue(thread->queue) == 0) { OSReport("OSCheckActiveThreads: Failed CheckThreadQueue(thread->queue) in %d\n", - 0x612); - OSPanic(__FILE__, 0x612, ""); + 0x5f0); + OSPanic(__FILE__, 0x5f0, ""); } if (!isMember(thread->queue, thread)) { OSReport("OSCheckActiveThreads: Failed IsMember(thread->queue, thread) in %d\n", - 0x613); - OSPanic(__FILE__, 0x613, ""); + 0x5f1); + OSPanic(__FILE__, 0x5f1, ""); } if (thread->suspend_count <= 0) { if (thread->effective_priority != __OSGetEffectivePriority(thread)) { OSReport("OSCheckActiveThreads: Failed thread->priority == " "__OSGetEffectivePriority(thread) in %d\n", - 0x616); - OSPanic(__FILE__, 0x616, ""); + 0x5f4); + OSPanic(__FILE__, 0x5f4, ""); } } else if (thread->effective_priority != 32) { - OSReport("OSCheckActiveThreads: Failed thread->priority == 32 in %d\n", 0x61a); - OSPanic(__FILE__, 0x61a, ""); + OSReport("OSCheckActiveThreads: Failed thread->priority == 32 in %d\n", 0x5f8); + OSPanic(__FILE__, 0x5f8, ""); } if (__OSCheckDeadLock(thread)) { - OSReport("OSCheckActiveThreads: Failed !__OSCheckDeadLock(thread) in %d\n", 0x61c); - OSPanic(__FILE__, 0x61c, ""); + OSReport("OSCheckActiveThreads: Failed !__OSCheckDeadLock(thread) in %d\n", 0x5fa); + OSPanic(__FILE__, 0x5fa, ""); } break; case OS_THREAD_STATE_DEAD: if (thread->owned_mutexes.head != NULL || thread->owned_mutexes.tail != NULL) { OSReport("OSCheckActiveThreads: Failed thread->queueMutex.head == NULL && " "thread->queueMutex.tail == NULL in %d\n", - 0x620); - OSPanic(__FILE__, 0x620, ""); + 0x5fe); + OSPanic(__FILE__, 0x5fe, ""); } break; default: OSReport("OSCheckActiveThreads: Failed. unkown thread state (%d) of thread %p\n", thread->state, thread); - OSPanic(__FILE__, 0x626, ""); + OSPanic(__FILE__, 0x604, ""); break; } if (!__OSCheckMutexes(thread)) { - OSReport("OSCheckActiveThreads: Failed __OSCheckMutexes(thread) in %d\n", 0x62b); - OSPanic(__FILE__, 0x62b, ""); + OSReport("OSCheckActiveThreads: Failed __OSCheckMutexes(thread) in %d\n", 0x609); + OSPanic(__FILE__, 0x609, ""); } thread = thread->active_threads_link.next; diff --git a/src/dolphin/os/__ppc_eabi_init.cpp b/src/dolphin/os/__ppc_eabi_init.cpp index ffa59dd69..662d60185 100644 --- a/src/dolphin/os/__ppc_eabi_init.cpp +++ b/src/dolphin/os/__ppc_eabi_init.cpp @@ -22,7 +22,7 @@ void _ExitProcess(); // typedef void (*voidfunctionptr)(); // pointer to function returning void -extern voidfunctionptr __init_cpp_exceptions_reference[]; +extern voidfunctionptr _ctors[]; void __init_user(void) { __init_cpp(); @@ -34,7 +34,7 @@ void __init_cpp(void) { * call static initializers */ voidfunctionptr* constructor; - for (constructor = __init_cpp_exceptions_reference; *constructor; constructor++) { + for (constructor = _ctors; *constructor; constructor++) { (*constructor)(); } }