diff --git a/asm/MetroTRK/debugger/Portable/msg.s b/asm/MetroTRK/debugger/Portable/msg.s deleted file mode 100644 index b396f4f5..00000000 --- a/asm/MetroTRK/debugger/Portable/msg.s +++ /dev/null @@ -1,16 +0,0 @@ -.include "macros.inc" - -.section .text, "ax" -.global TRKMessageSend -TRKMessageSend: -/* 800C1578 000BC478 94 21 FF F0 */ stwu r1, -0x10(r1) -/* 800C157C 000BC47C 7C 08 02 A6 */ mflr r0 -/* 800C1580 000BC480 90 01 00 14 */ stw r0, 0x14(r1) -/* 800C1584 000BC484 80 83 00 08 */ lwz r4, 8(r3) -/* 800C1588 000BC488 38 63 00 10 */ addi r3, r3, 0x10 -/* 800C158C 000BC48C 48 00 49 21 */ bl TRKWriteUARTN -/* 800C1590 000BC490 80 01 00 14 */ lwz r0, 0x14(r1) -/* 800C1594 000BC494 38 60 00 00 */ li r3, 0 -/* 800C1598 000BC498 7C 08 03 A6 */ mtlr r0 -/* 800C159C 000BC49C 38 21 00 10 */ addi r1, r1, 0x10 -/* 800C15A0 000BC4A0 4E 80 00 20 */ blr diff --git a/include/MetroTRK.h b/include/MetroTRK.h index 173cdc24..36b0391d 100644 --- a/include/MetroTRK.h +++ b/include/MetroTRK.h @@ -5,6 +5,7 @@ extern "C" { #endif #include +#include #include #include #include diff --git a/include/MetroTRK/debugger/Os/dolphin/dolphin_trk_glue.h b/include/MetroTRK/debugger/Os/dolphin/dolphin_trk_glue.h new file mode 100644 index 00000000..cea81693 --- /dev/null +++ b/include/MetroTRK/debugger/Os/dolphin/dolphin_trk_glue.h @@ -0,0 +1,14 @@ +#ifndef METROTRK_DEBUGGER_OS_DOLPHIN_DOLPHIN_TRK_GLUE_H +#define METROTRK_DEBUGGER_OS_DOLPHIN_DOLPHIN_TRK_GLUE_H +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + +UARTError TRKWriteUARTN(const void* src, size_t n); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/include/MetroTRK/debugger/Portable/UART.h b/include/MetroTRK/debugger/Portable/UART.h new file mode 100644 index 00000000..44ee78d8 --- /dev/null +++ b/include/MetroTRK/debugger/Portable/UART.h @@ -0,0 +1,15 @@ +#ifndef METROTRK_DEBUGGER_PORTABLE_UART_H +#define METROTRK_DEBUGGER_PORTABLE_UART_H +#include +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + kUARTNoError = 0x0000, +} UARTError; + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/include/MetroTRK/debugger/Portable/msg.h b/include/MetroTRK/debugger/Portable/msg.h new file mode 100644 index 00000000..bf998784 --- /dev/null +++ b/include/MetroTRK/debugger/Portable/msg.h @@ -0,0 +1,15 @@ +#ifndef METROTRK_DEBUGGER_PORTABLE_MSG_H +#define METROTRK_DEBUGGER_PORTABLE_MSG_H +#include +#include +#include +#ifdef __cplusplus +extern "C" { +#endif + +DSError TRKMessageSend(TRKMessageBuffer* buf); + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/include/MetroTRK/debugger/Portable/msgbuf.h b/include/MetroTRK/debugger/Portable/msgbuf.h index fa2b332a..0d434225 100644 --- a/include/MetroTRK/debugger/Portable/msgbuf.h +++ b/include/MetroTRK/debugger/Portable/msgbuf.h @@ -1,5 +1,6 @@ #ifndef METROTRK_DEBUGGER_PORTABLE_MSGBUF_H #define METROTRK_DEBUGGER_PORTABLE_MSGBUF_H +#include #include #ifdef __cplusplus extern "C" { @@ -8,7 +9,7 @@ extern "C" { #define kMessageBufferSize 2048 /* data block */ + 128 /* additional items */ typedef struct TRKMessageBuffer { - unsigned int WORD_0x0; + TRKMutex mutex; // at 0x0 BOOL used; // at 0x4 unsigned int size; // at 0x8 unsigned int pos; // at 0xC diff --git a/include/MetroTRK/debugger/Portable/mutex_TRK.h b/include/MetroTRK/debugger/Portable/mutex_TRK.h index 9b569bda..706cd8ba 100644 --- a/include/MetroTRK/debugger/Portable/mutex_TRK.h +++ b/include/MetroTRK/debugger/Portable/mutex_TRK.h @@ -6,9 +6,14 @@ extern "C" { #endif -DSError TRKReleaseMutex(void* p); -DSError TRKAcquireMutex(void* p); -DSError TRKInitializeMutex(void* p); +// Unused? +typedef struct TRKMutex { + char dummy[4]; +} TRKMutex; + +DSError TRKReleaseMutex(TRKMutex* mutex); +DSError TRKAcquireMutex(TRKMutex* mutex); +DSError TRKInitializeMutex(TRKMutex* mutex); #ifdef __cplusplus } diff --git a/makefile b/makefile index 87b30ba7..db79689e 100644 --- a/makefile +++ b/makefile @@ -47,7 +47,7 @@ LDFLAGS := -map $(MAP) -mapunused -proc gekko -fp hard -nodefaults -nofail # # Compiler flags for the Metrowerks Target Resident Kernel (MetroTRK) -CFLAGS_TRK := -lang c -enum int -inline auto -Cpp_exceptions off -proc gekko -fp hard -O4,p -ir include/MetroTRK -I- -i include -ir include/MSL -nodefaults +CFLAGS_TRK := -lang c -sdata 0 -use_lmw_stmw on -enum int -inline auto -Cpp_exceptions off -proc gekko -fp hard -O4,p -ir include/MetroTRK -I- -i include -ir include/MSL -nodefaults # Compiler flags for the CodeWarrior runtime library CFLAGS_RUNTIME := -lang c -enum int -inline auto -rostr -Cpp_exceptions off -proc gekko -fp hard -O4,p -ir include/MetroTRK -I- -i include -ir include/MSL -nodefaults # Compiler flags for NintendoWare for Revolution diff --git a/obj_files.mk b/obj_files.mk index 4f771022..0f87fb11 100644 --- a/obj_files.mk +++ b/obj_files.mk @@ -358,7 +358,7 @@ METROTRK_O_FILES := \ build/asm/MetroTRK/debugger/Portable/mainloop.o \ build/MetroTRK/debugger/Portable/nubevent.o \ build/asm/MetroTRK/debugger/Portable/nubinit.o \ - build/asm/MetroTRK/debugger/Portable/msg.o \ + build/MetroTRK/debugger/Portable/msg.o \ build/asm/MetroTRK/debugger/Portable/msgbuf.o \ build/asm/MetroTRK/debugger/Portable/serpoll.o \ build/asm/MetroTRK/debugger/Os/usr_put.o \ diff --git a/src/MetroTRK/debugger/Portable/msg.c b/src/MetroTRK/debugger/Portable/msg.c new file mode 100644 index 00000000..362fe6f8 --- /dev/null +++ b/src/MetroTRK/debugger/Portable/msg.c @@ -0,0 +1,6 @@ +#include + +DSError TRKMessageSend(TRKMessageBuffer* buf) { + TRKWriteUARTN(buf->buf, buf->size); + return kNoError; +} diff --git a/src/MetroTRK/debugger/Portable/mutex_TRK.c b/src/MetroTRK/debugger/Portable/mutex_TRK.c index 4d115eab..8c7543ac 100644 --- a/src/MetroTRK/debugger/Portable/mutex_TRK.c +++ b/src/MetroTRK/debugger/Portable/mutex_TRK.c @@ -1,7 +1,16 @@ #include -DSError TRKReleaseMutex(void* p) { return kNoError; } +DSError TRKReleaseMutex(TRKMutex* mutex) { +#pragma unused(mutex) + return kNoError; +} -DSError TRKAcquireMutex(void* p) { return kNoError; } +DSError TRKAcquireMutex(TRKMutex* mutex) { +#pragma unused(mutex) + return kNoError; +} -DSError TRKInitializeMutex(void* p) { return kNoError; } +DSError TRKInitializeMutex(TRKMutex* mutex) { +#pragma unused(mutex) + return kNoError; +} diff --git a/src/MetroTRK/debugger/Portable/nubevent.c b/src/MetroTRK/debugger/Portable/nubevent.c index ff0e9a4b..cd4fbcae 100644 --- a/src/MetroTRK/debugger/Portable/nubevent.c +++ b/src/MetroTRK/debugger/Portable/nubevent.c @@ -3,7 +3,7 @@ #define QUEUE_CAPACITY 2 typedef struct TRKEventQueue { - char UNK_0x0[0x4]; + TRKMutex mutex; // at 0x0 int size; // at 0x4 int front; // at 0x8 TRKEvent queue[QUEUE_CAPACITY]; // at 0xC @@ -23,8 +23,7 @@ void TRKConstructEvent(TRKEvent* event, TRKEventType type) { DSError TRKPostEvent(TRKEvent* event) { s32 id; DSError err = kNoError; - - TRKAcquireMutex(&gTRKEventQueue); + TRKAcquireMutex(&gTRKEventQueue.mutex); if (gTRKEventQueue.size == QUEUE_CAPACITY) { err = kMsgQueueFull; @@ -40,14 +39,13 @@ DSError TRKPostEvent(TRKEvent* event) { gTRKEventQueue.size++; } - TRKReleaseMutex(&gTRKEventQueue); + TRKReleaseMutex(&gTRKEventQueue.mutex); return err; } BOOL TRKGetNextEvent(TRKEvent* event) { BOOL success = FALSE; - - TRKAcquireMutex(&gTRKEventQueue); + TRKAcquireMutex(&gTRKEventQueue.mutex); if (gTRKEventQueue.size > 0) { TRK_memcpy(event, &gTRKEventQueue.queue[gTRKEventQueue.front], @@ -62,18 +60,18 @@ BOOL TRKGetNextEvent(TRKEvent* event) { success = TRUE; } - TRKReleaseMutex(&gTRKEventQueue); + TRKReleaseMutex(&gTRKEventQueue.mutex); return success; } DSError TRKInitializeEventQueue(TRKEvent* event) { - TRKInitializeMutex(&gTRKEventQueue); - TRKAcquireMutex(&gTRKEventQueue); + TRKInitializeMutex(&gTRKEventQueue.mutex); + TRKAcquireMutex(&gTRKEventQueue.mutex); gTRKEventQueue.size = 0; gTRKEventQueue.front = 0; gTRKEventQueue.uid = 256; - TRKReleaseMutex(&gTRKEventQueue); + TRKReleaseMutex(&gTRKEventQueue.mutex); return kNoError; }