From 70ed8569f3f898b6b7b3351dccf1b55ed0464ba9 Mon Sep 17 00:00:00 2001 From: Prakxo Date: Sun, 18 Jun 2023 18:07:06 +0200 Subject: [PATCH] prepare TRK and link mainloop.c --- common.py | 9 ++++++++ config/dol_slices.yml | 2 ++ configure.py | 4 ++++ include/TRK/_mem_trk.h | 17 ++++++++++++++ include/TRK/dispatch.h | 16 +++++++++++++ include/TRK/dolphin_trk.h | 4 +--- include/TRK/mainloop.h | 16 +++++++++++++ include/TRK/msgbuf.h | 23 +++++++++++++++++++ include/TRK/nubevent.h | 16 +++++++++++++ include/TRK/serpoll.h | 16 +++++++++++++ include/TRK/targimpl.h | 17 ++++++++++++++ include/TRK/trk.h | 26 +++++++++++++++++++++ src/TRK/dolphin_trk.c | 4 ++-- src/TRK/mainloop.c | 48 +++++++++++++++++++++++++++++++++++++++ src/TRK/mem_TRK.c | 2 +- src/dolphin/os/__start.c | 2 +- 16 files changed, 215 insertions(+), 7 deletions(-) create mode 100644 include/TRK/_mem_trk.h create mode 100644 include/TRK/dispatch.h create mode 100644 include/TRK/mainloop.h create mode 100644 include/TRK/msgbuf.h create mode 100644 include/TRK/nubevent.h create mode 100644 include/TRK/serpoll.h create mode 100644 include/TRK/targimpl.h create mode 100644 include/TRK/trk.h create mode 100644 src/TRK/mainloop.c diff --git a/common.py b/common.py index 8e2cfe8f..613f7eb5 100644 --- a/common.py +++ b/common.py @@ -352,6 +352,14 @@ DVDERR_CFLAGS = CFLAGS + [ "-sdata2 0", "-pool off" ] + DOL_DEFINES +TRK_CFLAGS = [ + "-O4,p", + "-sdata 0", + "-fp hard", + "-enum int", + "-char unsigned", + "-inline deferred" +] + DOL_DEFINES BASE_REL_CFLAGS = CFLAGS + [ "-sdata 0", f"-sdata2 {REL_SDATA2_SIZE}", @@ -403,6 +411,7 @@ DOL_CFLAGS = ' '.join(BASE_DOL_CFLAGS + LOCAL_CFLAGS) DOL_BOOT_CFLAGS = ' '.join(BOOT_CFLAGS + LOCAL_CFLAGS) DOL_DVDERR_CFLAGS = ' '.join(DVDERR_CFLAGS + LOCAL_CFLAGS) DOL_CFLAGS_SDATA0_CFLAGS = ' '.join(DOL_CFLAGS_NO_SDATA + LOCAL_CFLAGS) +DOL_TRK_CFLAGS = ' '.join(TRK_CFLAGS + LOCAL_CFLAGS) SDK_FLAGS = ' '.join(SDK_CFLAG + LOCAL_CFLAGS) ALIGN16 = ' '.join(BASE_DOL_CFLAGS + LOCAL_CFLAGS + ALIGN16_CFLAG) DOL_CPPFLAGS = ' '.join(CPLFLAGS + BASE_DOL_CFLAGS + LOCAL_CFLAGS) diff --git a/config/dol_slices.yml b/config/dol_slices.yml index a57c0dca..1496b061 100644 --- a/config/dol_slices.yml +++ b/config/dol_slices.yml @@ -189,6 +189,8 @@ dolphin/os/OSRtc.c: MSL_C/rand.c: .text: [0x8009f46c, 0x8009f494] .sdata: [0x80218260, 0x80218268] +TRK/mainloop.c: + .text: [0x800A1FF4, 0x800A20EC] dolphin/odenotstub/odenotstub.c: .text: [0x800a9770, 0x800a9780] dolphin/amcstubs/AmcExi2Stubs.c: diff --git a/configure.py b/configure.py index 7fce39e4..3a008bfa 100644 --- a/configure.py +++ b/configure.py @@ -647,6 +647,10 @@ class CSource(Source): self.cc = c.CC self.cflags = c.DOL_CPPFLAGS self.frank = False + elif path == "src/TRK/mainloop.c": + self.cc = c.CC + self.cflags = c.DOL_TRK_CFLAGS + self.frank = False else: self.cflags = ctx.cflags self.cc = c.CC diff --git a/include/TRK/_mem_trk.h b/include/TRK/_mem_trk.h new file mode 100644 index 00000000..06817820 --- /dev/null +++ b/include/TRK/_mem_trk.h @@ -0,0 +1,17 @@ +#ifndef MEM_TRK_H +#define MEM_TRK_H +#include "types.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +void* TRK_memcpy(void* dst, const void* src, size_t size); +void* TRK_memset(void* dst, int val, size_t size); +void TRK_fill_mem(void*, int, size_t); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/TRK/dispatch.h b/include/TRK/dispatch.h new file mode 100644 index 00000000..3bdbaeb0 --- /dev/null +++ b/include/TRK/dispatch.h @@ -0,0 +1,16 @@ +#ifndef TRK_DISPATCH +#define TRK_DISPATCH +#include "types.h" +#include "TRK/trk.h" +#include "TRK/msgbuf.h" + +#ifdef __cplusplus +extern "C" { +#endif + +TRKResult TRKDispatchMessage(MessageBuffer* mBuf); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/TRK/dolphin_trk.h b/include/TRK/dolphin_trk.h index ba2b32c6..f883063f 100644 --- a/include/TRK/dolphin_trk.h +++ b/include/TRK/dolphin_trk.h @@ -8,9 +8,7 @@ extern "C"{ void InitMetroTRK(void); void exit(void); -void* TRK_memcpy(void* dst, const void* src, size_t size); -void* TRK_memset(void* dst, int val, size_t size); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/include/TRK/mainloop.h b/include/TRK/mainloop.h new file mode 100644 index 00000000..7898d26e --- /dev/null +++ b/include/TRK/mainloop.h @@ -0,0 +1,16 @@ +#ifndef TRK_MAINLOOP +#define TRK_MAINLOOP +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +void TRKNubMainLoop(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/TRK/msgbuf.h b/include/TRK/msgbuf.h new file mode 100644 index 00000000..27a263b8 --- /dev/null +++ b/include/TRK/msgbuf.h @@ -0,0 +1,23 @@ +#ifndef TRK_MSGBUF +#define TRK_MSGBUF +#include "types.h" +#include "TRK/trk.h" +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct MessageBuffer { + int unk0; + int unk4; + int unk8; + u32 unkC; + u8 mBuffer[0x87C]; +} MessageBuffer; + +MessageBuffer* TRKGetBuffer(int); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/TRK/nubevent.h b/include/TRK/nubevent.h new file mode 100644 index 00000000..c1fec6e5 --- /dev/null +++ b/include/TRK/nubevent.h @@ -0,0 +1,16 @@ +#ifndef TRK_NUBEVENT +#define TRK_NUBEVENT +#include "types.h" +#include "TRK/trk.h" +#ifdef __cplusplus +extern "C" { +#endif + +BOOL TRKGetNextEvent(TRKEvent*); +void TRKDestructEvent(TRKEvent*); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/TRK/serpoll.h b/include/TRK/serpoll.h new file mode 100644 index 00000000..54518d5b --- /dev/null +++ b/include/TRK/serpoll.h @@ -0,0 +1,16 @@ +#ifndef TRK_SERPOLL +#define TRK_SERPOLL +#include "types.h" +#ifdef __cplusplus +extern "C" { +#endif + +void TRKGetInput(); + +extern u8* gTRKInputPendingPtr; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/include/TRK/targimpl.h b/include/TRK/targimpl.h new file mode 100644 index 00000000..c3ff029f --- /dev/null +++ b/include/TRK/targimpl.h @@ -0,0 +1,17 @@ +#ifndef TRK_TARGIMPL +#define TRK_TARGIMPL +#include "types.h" +#include "TRK/trk.h" +#ifdef __cplusplus +extern "C" { +#endif + +void TRKTargeInterrupt(TRKEvent*); +void TRKTargetSupportRequest(); +BOOL TRKTargetStopped(); +void TRKTargetContinue(); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/TRK/trk.h b/include/TRK/trk.h new file mode 100644 index 00000000..9213ba45 --- /dev/null +++ b/include/TRK/trk.h @@ -0,0 +1,26 @@ +#ifndef TRK_H +#define TRK_H +#include "types.h" + +#ifdef __cplusplus +extern "C"{ +#endif + +typedef enum { + TRKSuccess = 0, + TRKError100 = 0x100, + TRKError301 = 0x301, + TRKError302 = 0x302, + TRKError500 = 0x500 +}TRKResult; + +typedef struct TRKEvent{ + u8 mEventType; + int mMax; + int mBufferIndex; +}TRKEvent; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/TRK/dolphin_trk.c b/src/TRK/dolphin_trk.c index 5dc56798..3378060f 100644 --- a/src/TRK/dolphin_trk.c +++ b/src/TRK/dolphin_trk.c @@ -1,4 +1,4 @@ -#include "types.h" +#include "TRK/_mem_trk.h" __declspec(section ".init") asm void __TRK_reset(void){ nofralloc @@ -73,4 +73,4 @@ lbl_80005548: /* 80005560 7C0803A6 */ mtlr r0 /* 80005564 38210020 */ addi r1, r1, 0x20 /* 80005568 4E800020 */ blr -} \ No newline at end of file +} diff --git a/src/TRK/mainloop.c b/src/TRK/mainloop.c new file mode 100644 index 00000000..46097025 --- /dev/null +++ b/src/TRK/mainloop.c @@ -0,0 +1,48 @@ +#include "TRK/mainloop.h" +#include "TRK/nubevent.h" +#include "TRK/dispatch.h" +#include "TRK/targimpl.h" +#include "TRK/serpoll.h" + +void TRKNubMainLoop(void){ + + MessageBuffer* msg; + TRKEvent event; + BOOL loop = FALSE; + BOOL statInput = FALSE; + + while(loop == FALSE){ + if(TRKGetNextEvent(&event) != FALSE){ + statInput = FALSE; + switch(event.mEventType){ + case 0: + break; + case 2: + msg = TRKGetBuffer(event.mBufferIndex); + TRKDispatchMessage(msg); + break; + case 1: + loop = TRUE; + break; + case 3: + case 4: + TRKTargetInterrupt(&event); + break; + case 5: + TRKTargetSupportRequest(); + break; + } + TRKDestructEvent(&event); + } + else if((statInput == FALSE) || ((u8)*gTRKInputPendingPtr != 0)){ + statInput = TRUE; + TRKGetInput(); + } + else{ + if(TRKTargetStopped() == FALSE){ + TRKTargetContinue(); + } + statInput = FALSE; + } + } +} diff --git a/src/TRK/mem_TRK.c b/src/TRK/mem_TRK.c index 61b9da61..c2cdf56c 100644 --- a/src/TRK/mem_TRK.c +++ b/src/TRK/mem_TRK.c @@ -1,4 +1,4 @@ -#include "TRK/dolphin_trk.h" +#include "TRK/_mem_trk.h" __declspec(section ".init") void* TRK_memset(void* dst, int val, size_t size){ TRK_fill_mem(dst, val, size); diff --git a/src/dolphin/os/__start.c b/src/dolphin/os/__start.c index 7dd94f2f..a297820c 100644 --- a/src/dolphin/os/__start.c +++ b/src/dolphin/os/__start.c @@ -1,6 +1,6 @@ #include "dolphin/os.h" #include "dolphin/db.h" -#include "TRK/dolphin_trk.h" +#include "TRK/trk.h" #include "dolphin/os/__ppc_eabi_init.h" __declspec(section ".init")void __init_registers(void);