diff --git a/asm/Kyoto/Basics/CBasicsDolphin.s b/asm/Kyoto/Basics/CBasicsDolphin.s index 4ab77771..d350252b 100644 --- a/asm/Kyoto/Basics/CBasicsDolphin.s +++ b/asm/Kyoto/Basics/CBasicsDolphin.s @@ -3,8 +3,7 @@ .section .sbss, "wa" .balign 8 -.global lbl_805A9240 -lbl_805A9240: +gInitialized: .skip 0x8 .section .text, "ax" @@ -14,7 +13,7 @@ Init__7CBasicsFv: /* 802D6354 002D32B4 94 21 FF F0 */ stwu r1, -0x10(r1) /* 802D6358 002D32B8 7C 08 02 A6 */ mflr r0 /* 802D635C 002D32BC 90 01 00 14 */ stw r0, 0x14(r1) -/* 802D6360 002D32C0 88 0D A6 80 */ lbz r0, lbl_805A9240@sda21(r13) +/* 802D6360 002D32C0 88 0D A6 80 */ lbz r0, gInitialized@sda21(r13) /* 802D6364 002D32C4 28 00 00 00 */ cmplwi r0, 0 /* 802D6368 002D32C8 40 82 00 48 */ bne lbl_802D63B0 /* 802D636C 002D32CC 48 0A 75 3D */ bl OSInit @@ -33,10 +32,10 @@ Init__7CBasicsFv: /* 802D63A0 002D3300 48 09 B8 05 */ bl DVDInit /* 802D63A4 002D3304 4B FF FF 15 */ bl InitGlobalTimer__10CStopwatchFv /* 802D63A8 002D3308 38 00 00 01 */ li r0, 1 -/* 802D63AC 002D330C 98 0D A6 80 */ stb r0, lbl_805A9240@sda21(r13) +/* 802D63AC 002D330C 98 0D A6 80 */ stb r0, gInitialized@sda21(r13) lbl_802D63B0: /* 802D63B0 002D3310 80 01 00 14 */ lwz r0, 0x14(r1) -/* 802D63B4 002D3314 88 6D A6 80 */ lbz r3, lbl_805A9240@sda21(r13) +/* 802D63B4 002D3314 88 6D A6 80 */ lbz r3, gInitialized@sda21(r13) /* 802D63B8 002D3318 7C 08 03 A6 */ mtlr r0 /* 802D63BC 002D331C 38 21 00 10 */ addi r1, r1, 0x10 /* 802D63C0 002D3320 4E 80 00 20 */ blr diff --git a/configure.py b/configure.py index 8e1464ae..8a6df538 100755 --- a/configure.py +++ b/configure.py @@ -468,7 +468,7 @@ LIBS = [ "objects": [ "Kyoto/Basics/CBasics", ["Kyoto/Basics/CStopwatch", True], - "Kyoto/Basics/CBasicsDolphin", + ["Kyoto/Basics/CBasicsDolphin", True], ["Kyoto/Alloc/CCallStackDolphin", True], ["Kyoto/Basics/COsContextDolphin", True], ["Kyoto/Basics/CSWDataDolphin", True], diff --git a/include/Kyoto/Basics/CBasics.hpp b/include/Kyoto/Basics/CBasics.hpp index 3d685d93..23ea9f90 100644 --- a/include/Kyoto/Basics/CBasics.hpp +++ b/include/Kyoto/Basics/CBasics.hpp @@ -4,7 +4,7 @@ #include "types.h" namespace CBasics { -void Init(); +bool Init(); char* Stringize(const char* fmt, ...); inline uint SwapBytes(uint x) { #if 0 diff --git a/include/dolphin/dvd.h b/include/dolphin/dvd.h index d5abb871..2078eacc 100644 --- a/include/dolphin/dvd.h +++ b/include/dolphin/dvd.h @@ -46,6 +46,8 @@ struct DVDFileInfo { DVDCallback callback; }; +void DVDInit(); + void DVDSetAutoFatalMessaging(BOOL); void DVDReset(); diff --git a/include/dolphin/os.h b/include/dolphin/os.h index e28f43f7..e9525f63 100644 --- a/include/dolphin/os.h +++ b/include/dolphin/os.h @@ -154,6 +154,7 @@ void OSFatal(GXColor fg, GXColor bg, const char* msg); #include #include #include +#include #include #include #include diff --git a/include/dolphin/os/OSFastCast.h b/include/dolphin/os/OSFastCast.h index 1be2a9a4..d615bb8a 100644 --- a/include/dolphin/os/OSFastCast.h +++ b/include/dolphin/os/OSFastCast.h @@ -5,9 +5,57 @@ extern "C" { #endif +#define OS_GQR_F32 0x0000 +#define OS_GQR_U8 0x0004 +#define OS_GQR_U16 0x0005 +#define OS_GQR_S8 0x0006 +#define OS_GQR_S16 0x0007 + #define OS_FASTCAST_U8 2 #define OS_FASTCAST_U16 3 #define OS_FASTCAST_S16 5 +// clang-format off +static inline void OSInitFastCast(void) { +#ifdef __MWERKS__ + asm + { + li r3, OS_GQR_U8 + oris r3, r3, OS_GQR_U8 + mtspr GQR2, r3 + + li r3, OS_GQR_U16 + oris r3, r3, OS_GQR_U16 + mtspr GQR3, r3 + + li r3, OS_GQR_S8 + oris r3, r3, OS_GQR_S8 + mtspr GQR4, r3 + + li r3, OS_GQR_S16 + oris r3, r3, OS_GQR_S16 + mtspr GQR5, r3 + } +#else + asm volatile (" + li 3, 0x0004 + oris 3, 3, 0x0004 + mtspr GQR2, 3 + + li 3, 0x0005 + oris 3, 3, 0x0005 + mtspr GQR3, 3 + + li 3, 0x0006 + oris 3, 3, 0x0006 + mtspr GQR4, 3 + + li 3, 0x0007 + oris 3, 3, 0x0007 + mtspr GQR5, 3 + " : : : "r3" ); +#endif +} +// clang-format off #ifdef __cplusplus } diff --git a/src/Kyoto/Basics/CBasicsDolphin.cpp b/src/Kyoto/Basics/CBasicsDolphin.cpp new file mode 100644 index 00000000..7f4a6c7c --- /dev/null +++ b/src/Kyoto/Basics/CBasicsDolphin.cpp @@ -0,0 +1,19 @@ +#include "Kyoto/Basics/CBasics.hpp" + +#include "Kyoto/Basics/CStopwatch.hpp" + +#include "dolphin/os.h" +#include "dolphin/dvd.h" + +static bool gInitialized = false; +bool CBasics::Init() { + if (!gInitialized) { + OSInit(); + OSInitFastCast(); + DVDInit(); + + CStopwatch::InitGlobalTimer(); + gInitialized = true; + } + return gInitialized; +}