From a4137d0dddc156c85848a3d3bb4191c6b8ea74ab Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Tue, 7 Feb 2023 05:51:34 -0800 Subject: [PATCH] Cleanup HW register usage Former-commit-id: b1137488f68f313d671768befa5748f45244abf9 --- .vscode/settings.json | 3 ++- include/dolphin/DVDPriv.h | 5 ++--- include/dolphin/dsp_regs.h | 9 --------- include/dolphin/dvd_regs.h | 6 ------ include/dolphin/hw_regs.h | 35 +++++++++++++++++++++++++++++++++ include/dolphin/os/OSPriv.h | 2 +- include/dolphin/vi.h | 6 +----- src/Dolphin/ai.c | 2 +- src/Dolphin/ar/ar.c | 2 +- src/Dolphin/card/CARDFormat.c | 1 + src/Dolphin/dsp/dsp.c | 2 +- src/Dolphin/dsp/dsp_task.c | 2 +- src/Dolphin/dvd/dvd.c | 2 +- src/Dolphin/dvd/dvdidutils.c | 2 +- src/Dolphin/dvd/dvdlow.c | 1 - src/Dolphin/dvd/fstload.c | 2 +- src/Dolphin/exi/EXIBios.c | 3 +-- src/Dolphin/os/OS.c | 1 - src/Dolphin/os/OSAudioSystem.c | 2 +- src/Dolphin/os/OSError.c | 3 +-- src/Dolphin/os/OSInterrupt.c | 8 +------- src/Dolphin/os/OSReset.c | 1 + src/Dolphin/si/SISamplingRate.c | 2 ++ 23 files changed, 56 insertions(+), 46 deletions(-) delete mode 100644 include/dolphin/dsp_regs.h delete mode 100644 include/dolphin/dvd_regs.h create mode 100644 include/dolphin/hw_regs.h diff --git a/.vscode/settings.json b/.vscode/settings.json index 80c6ee7a..e94951fc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -58,7 +58,8 @@ "osfastcast.h": "c", "osfont.h": "c", "arq.h": "c", - "string.h": "c" + "string.h": "c", + "hw_regs.h": "c" }, "files.autoSave": "onFocusChange", "files.insertFinalNewline": true, diff --git a/include/dolphin/DVDPriv.h b/include/dolphin/DVDPriv.h index f49b8ca8..66560730 100644 --- a/include/dolphin/DVDPriv.h +++ b/include/dolphin/DVDPriv.h @@ -2,7 +2,7 @@ #define _DOLPHIN_DVDPRIV #include -#include +#include #include #ifdef __cplusplus @@ -37,10 +37,9 @@ typedef struct DVDBB2 { typedef void (*DVDOptionalCommandChecker)(DVDCommandBlock* block, void (*cb)(u32 intType)); typedef void (*DVDLowCallback)(u32 intType); - +extern DVDDiskID* DVDGetCurrentDiskID(); DVDLowCallback DVDLowClearCallback(); BOOL DVDLowSeek(u32 offset, DVDLowCallback callback); - void __DVDLowSetWAType(u32 type, u32 location); DVDCommandBlock* __DVDPopWaitingQueue(); diff --git a/include/dolphin/dsp_regs.h b/include/dolphin/dsp_regs.h deleted file mode 100644 index eee93764..00000000 --- a/include/dolphin/dsp_regs.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef _DOLPHIN_DSP_REGS -#define _DOLPHIN_DSP_REGS - -#include "types.h" - -vu16 __DSPRegs[32] : 0xCC005000; -vu32 __AIRegs[8] : 0xCC006C00; - -#endif // _DOLPHIN_DSP_REGS diff --git a/include/dolphin/dvd_regs.h b/include/dolphin/dvd_regs.h deleted file mode 100644 index 85be4688..00000000 --- a/include/dolphin/dvd_regs.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _DOLPHIN_DVD_REGS -#define _DOLPHIN_DVD_REGS - -vu32 __DIRegs[16] : 0xCC006000; - -#endif // _DOLPHIN_DVD_REGS diff --git a/include/dolphin/hw_regs.h b/include/dolphin/hw_regs.h new file mode 100644 index 00000000..c12c01a5 --- /dev/null +++ b/include/dolphin/hw_regs.h @@ -0,0 +1,35 @@ +#ifndef _DOLPHIN_HW_REGS +#define _DOLPHIN_HW_REGS + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __MWERKS__ +vu16 __VIRegs[59] : 0xCC002000; +vu32 __PIRegs[12] : 0xCC003000; +vu16 __MEMRegs[64] : 0xCC004000; +vu16 __DSPRegs[32] : 0xCC005000; +vu32 __DIRegs[16] : 0xCC006000; +vu32 __SIRegs[64] : 0xCC006400; +vu32 __EXIRegs[16] : 0xCC006800; +vu32 __AIRegs[8] : 0xCC006C00; + +#else +#define __VIRegs ((vu16*)0xCC002000) +#define __PIRegs ((vu32*)0xCC003000) +#define __MEMRegs ((vu16*)0xCC004000) +#define __DSPRegs ((vu16*)0xCC005000) +#define __DIRegs ((vu32*)0xCC006000) +#define __SIRegs ((vu32*)0xCC006400) +#define __EXIRegs ((vu32*)0xCC006800) +#define __AIRegs ((vu32*)0xCC006C00) +#endif + +#ifdef __cplusplus +} +#endif + +#endif // _DOLPHIN_HW_REGS diff --git a/include/dolphin/os/OSPriv.h b/include/dolphin/os/OSPriv.h index b3db3278..8b914f25 100644 --- a/include/dolphin/os/OSPriv.h +++ b/include/dolphin/os/OSPriv.h @@ -12,7 +12,7 @@ OSTime __OSGetSystemTime(); OSTime __OSTimeToSystemTime(OSTime); #ifdef __cplusplus -extern "C" { +} #endif #endif // _DOLPHIN_OSPRIV diff --git a/include/dolphin/vi.h b/include/dolphin/vi.h index fdedc8c5..474f5e39 100644 --- a/include/dolphin/vi.h +++ b/include/dolphin/vi.h @@ -22,11 +22,7 @@ void VISetWindowFullscreen(bool fullscreen); bool VIGetWindowFullscreen(); #endif -#ifdef __MWERKS__ -vu16 __VIRegs[59] : 0xCC002000; -#else -vu16 __VIRegs[59]; -#endif + #ifdef __cplusplus } diff --git a/src/Dolphin/ai.c b/src/Dolphin/ai.c index 9d65b1ec..32e3ab43 100644 --- a/src/Dolphin/ai.c +++ b/src/Dolphin/ai.c @@ -1,5 +1,5 @@ #include "dolphin/ai.h" -#include "dolphin/dsp_regs.h" +#include "dolphin/hw_regs.h" #include "dolphin/os.h" const char* __AIVersion = "<< Dolphin SDK - AI\trelease build: Sep 5 2002 05:34:25 (0x2301) >>"; diff --git a/src/Dolphin/ar/ar.c b/src/Dolphin/ar/ar.c index af44c4c7..af2586e5 100644 --- a/src/Dolphin/ar/ar.c +++ b/src/Dolphin/ar/ar.c @@ -1,6 +1,6 @@ #include "dolphin/ar.h" -#include "dolphin/dsp_regs.h" +#include "dolphin/hw_regs.h" #include "dolphin/os.h" static const char* __ARVersion = diff --git a/src/Dolphin/card/CARDFormat.c b/src/Dolphin/card/CARDFormat.c index ebfff8ba..cd7e84f1 100644 --- a/src/Dolphin/card/CARDFormat.c +++ b/src/Dolphin/card/CARDFormat.c @@ -6,6 +6,7 @@ #include #include #include +#include static void FormatCallback(s32 chan, s32 result) { CARDControl* card; diff --git a/src/Dolphin/dsp/dsp.c b/src/Dolphin/dsp/dsp.c index c40e0e35..3a15b3e7 100644 --- a/src/Dolphin/dsp/dsp.c +++ b/src/Dolphin/dsp/dsp.c @@ -1,7 +1,7 @@ #include "dolphin/dsp.h" #include "dolphin/os.h" -#include "dolphin/dsp_regs.h" +#include "dolphin/hw_regs.h" #ifdef __cplusplus extern "C" { diff --git a/src/Dolphin/dsp/dsp_task.c b/src/Dolphin/dsp/dsp_task.c index 2fe7f157..ea539b52 100644 --- a/src/Dolphin/dsp/dsp_task.c +++ b/src/Dolphin/dsp/dsp_task.c @@ -1,5 +1,5 @@ #include "dolphin/dsp.h" -#include "dolphin/dsp_regs.h" +#include "dolphin/hw_regs.h" DSPTaskInfo* __DSP_curr_task; DSPTaskInfo* __DSP_first_task; diff --git a/src/Dolphin/dvd/dvd.c b/src/Dolphin/dvd/dvd.c index 65c67f6b..144c55d2 100644 --- a/src/Dolphin/dvd/dvd.c +++ b/src/Dolphin/dvd/dvd.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/src/Dolphin/dvd/dvdidutils.c b/src/Dolphin/dvd/dvdidutils.c index 3c58e98d..a3680ace 100644 --- a/src/Dolphin/dvd/dvdidutils.c +++ b/src/Dolphin/dvd/dvdidutils.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include diff --git a/src/Dolphin/dvd/dvdlow.c b/src/Dolphin/dvd/dvdlow.c index 2f379610..3575236a 100644 --- a/src/Dolphin/dvd/dvdlow.c +++ b/src/Dolphin/dvd/dvdlow.c @@ -4,7 +4,6 @@ extern DVDDiskID* DVDGetCurrentDiskID(); extern OSTime __OSGetSystemTime(); -vu32 __PIRegs[12] : 0xCC003000; static BOOL FirstRead = TRUE; static volatile BOOL StopAtNextInt = FALSE; diff --git a/src/Dolphin/dvd/fstload.c b/src/Dolphin/dvd/fstload.c index 1f7a81b2..bfae3492 100644 --- a/src/Dolphin/dvd/fstload.c +++ b/src/Dolphin/dvd/fstload.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include diff --git a/src/Dolphin/exi/EXIBios.c b/src/Dolphin/exi/EXIBios.c index 8ff770fb..dc377d98 100644 --- a/src/Dolphin/exi/EXIBios.c +++ b/src/Dolphin/exi/EXIBios.c @@ -1,9 +1,8 @@ #include "dolphin/os.h" +#include "dolphin/hw_regs.h" #pragma scheduling off -vu32 __EXIRegs[16] : 0xCC006800; - static const char* __EXIVersion = "<< Dolphin SDK - EXI\trelease build: Sep 5 2002 05:33:04 (0x2301) >>"; diff --git a/src/Dolphin/os/OS.c b/src/Dolphin/os/OS.c index ec4b2690..100e7eff 100644 --- a/src/Dolphin/os/OS.c +++ b/src/Dolphin/os/OS.c @@ -605,7 +605,6 @@ void __OSPSInit(void) // clang-format on } -vu32 __DIRegs[16] : 0xCC006000; #define DI_CONFIG_IDX 0x9 #define DI_CONFIG_CONFIG_MASK 0xFF u32 __OSGetDIConfig(void) { return (__DIRegs[DI_CONFIG_IDX] & DI_CONFIG_CONFIG_MASK); } diff --git a/src/Dolphin/os/OSAudioSystem.c b/src/Dolphin/os/OSAudioSystem.c index 1eddcbf8..f8c4606c 100644 --- a/src/Dolphin/os/OSAudioSystem.c +++ b/src/Dolphin/os/OSAudioSystem.c @@ -1,4 +1,5 @@ #include "types.h" +#include "dolphin/hw_regs.h" #ifdef __cplusplus extern "C" { @@ -17,7 +18,6 @@ static u8 DSPInitCode[128] = { // clang-format on }; -volatile u16 __DSPRegs[] : 0xCC005000; #define __DSPWorkBuffer (void*)0x81000000 void __OSInitAudioSystem(void) { diff --git a/src/Dolphin/os/OSError.c b/src/Dolphin/os/OSError.c index 71853996..e9bcfce2 100644 --- a/src/Dolphin/os/OSError.c +++ b/src/Dolphin/os/OSError.c @@ -1,6 +1,5 @@ #include -#include -#include +#include #include #include diff --git a/src/Dolphin/os/OSInterrupt.c b/src/Dolphin/os/OSInterrupt.c index 30b6e813..a7bed16a 100644 --- a/src/Dolphin/os/OSInterrupt.c +++ b/src/Dolphin/os/OSInterrupt.c @@ -1,15 +1,9 @@ #include +#include static asm void ExternalInterruptHandler(register __OSException exception, register OSContext* context); -// TODO: Move these to a more appropriate location -vu32 __PIRegs[12] : 0xCC003000; -vu32 __EXIRegs[16] : 0xCC006800; -vu16 __MEMRegs[64] : 0xCC004000; -vu16 __DSPRegs[32] : 0xCC005000; -vu32 __AIRegs[8] : 0xCC006C00; - extern void __RAS_OSDisableInterrupts_begin(void); extern void __RAS_OSDisableInterrupts_end(void); diff --git a/src/Dolphin/os/OSReset.c b/src/Dolphin/os/OSReset.c index ebd0b04e..0e2bd1be 100644 --- a/src/Dolphin/os/OSReset.c +++ b/src/Dolphin/os/OSReset.c @@ -1,6 +1,7 @@ #include "dolphin/OSRtcPriv.h" #include "dolphin/os.h" #include "dolphin/vi.h" +#include "dolphin/hw_regs.h" volatile u8 DAT_800030e2 : 0x800030e2; typedef struct Unk { diff --git a/src/Dolphin/si/SISamplingRate.c b/src/Dolphin/si/SISamplingRate.c index c9b96ca6..9b799fbc 100644 --- a/src/Dolphin/si/SISamplingRate.c +++ b/src/Dolphin/si/SISamplingRate.c @@ -1,5 +1,7 @@ #include "dolphin/sipriv.h" #include "dolphin/vi.h" +#include "dolphin/hw_regs.h" + #pragma dont_inline on static u32 SamplingRate;