diff --git a/configure.py b/configure.py index e52eab2b..f66d64ed 100755 --- a/configure.py +++ b/configure.py @@ -233,9 +233,17 @@ cflags_musyx_debug = [ # REL flags cflags_rel = [ - *cflags_base, + "-proc gecko", + "-fp hard", + "-nodefaults", + "-nosyspath", + "-i include", + "-i libc", + "-O0", "-sdata 0", "-sdata2 0", + "-str noreuse", + "-Cpp_exceptions off" ] config.linker_version = "GC/1.3.2" @@ -283,7 +291,7 @@ def MusyX(objects, mw_version="GC/1.3.2", debug=False, major=2, minor=0, patch=0 def Rel(lib_name, objects): return { "lib": lib_name, - "mw_version": "Wii/1.3", + "mw_version": "GC/1.3.2", "cflags": cflags_rel, "host": True, "objects": objects, @@ -1294,6 +1302,15 @@ config.libs = [ Object(Matching, "Dolphin/GBA/GBAKey.c"), ], ), + Rel( + "NESemuP", + [ + Object( + Matching, + "NESemu/modwrapper.c", + ), + ], + ), ] if args.mode == "configure": diff --git a/extern/musyx b/extern/musyx index 28424c82..ddfad60c 160000 --- a/extern/musyx +++ b/extern/musyx @@ -1 +1 @@ -Subproject commit 28424c828c8c462e26953ded3b08e6f3a0c8e489 +Subproject commit ddfad60c3e4fede55479c744a1c70081e0d6cd12 diff --git a/include/NESemu/modwrapper.h b/include/NESemu/modwrapper.h new file mode 100644 index 00000000..9b10bcb6 --- /dev/null +++ b/include/NESemu/modwrapper.h @@ -0,0 +1,27 @@ +#ifndef _MODWRAPPER_H_ +#define _MODWRAPPER_H_ + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void _prolog(); +void _epilog(); +void _unresolved(); + +// User functions +void ksNesInitModule(void); + +#ifdef __MWERKS__ +#define REL_EXPORT __declspec(export) +#else +#define REL_EXPORT +#endif + +#ifdef __cplusplus +} +#endif + +#endif // _MODWRAPPER_H_ diff --git a/include/dolphin/os/OSContext.h b/include/dolphin/os/OSContext.h index bbd0aaa1..febc3454 100644 --- a/include/dolphin/os/OSContext.h +++ b/include/dolphin/os/OSContext.h @@ -162,6 +162,7 @@ u32 OSSaveContext(OSContext* context); void OSClearContext(OSContext* context); OSContext* OSGetCurrentContext(); void OSSetCurrentContext(OSContext* context); +u32 OSGetStackPointer(); #ifdef __cplusplus } diff --git a/src/NESemu/modwrapper.c b/src/NESemu/modwrapper.c new file mode 100644 index 00000000..9834d71c --- /dev/null +++ b/src/NESemu/modwrapper.c @@ -0,0 +1,48 @@ +#include "NESemu/modwrapper.h" +#include "dolphin/os.h" + +typedef void (*voidfunctionptr)(void); // pointer to function returning void +__declspec(section ".init") extern voidfunctionptr _ctors[]; +__declspec(section ".init") extern voidfunctionptr _dtors[]; + +REL_EXPORT asm void _prolog(void) { + fralloc + lis r3, _ctors@ha + addi r0, r3, _ctors@l + mr r31, r0 + b @2 +@1: + mtctr r12 + bctrl + addi r31, r31, 0x4 +@2: + lwz r12, 0x0(r31) + cmplwi r12, 0x0 + bne+ @1 + + bl ksNesInitModule + + frfree + blr +} + +REL_EXPORT asm void _epilog(void) { + fralloc + lis r3, _dtors@ha + addi r0, r3, _dtors@l + mr r31, r0 + b @2 +@1: + mtctr r12 + bctrl + addi r31, r31, sizeof(voidfunctionptr) +@2: + lwz r12, 0x0(r31) + cmplwi r12, 0x0 + bne+ @1 + + frfree + blr +} + +REL_EXPORT void _unresolved(void) { OSPanic("modwrapper.c\0\0\0", 0x3d, "ksNesEmulator unresolved"); }