Skip to content

Commit

Permalink
Initial NESemu
Browse files Browse the repository at this point in the history
  • Loading branch information
Antidote committed Dec 19, 2023
1 parent ae888d4 commit 454723c
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
21 changes: 19 additions & 2 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,17 @@

# 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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1294,6 +1302,15 @@ def Rel(lib_name, objects):
Object(Matching, "Dolphin/GBA/GBAKey.c"),
],
),
Rel(
"NESemuP",
[
Object(
Matching,
"NESemu/modwrapper.c",
),
],
),
]

if args.mode == "configure":
Expand Down
2 changes: 1 addition & 1 deletion extern/musyx
27 changes: 27 additions & 0 deletions include/NESemu/modwrapper.h
Original file line number Diff line number Diff line change
@@ -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_
1 change: 1 addition & 0 deletions include/dolphin/os/OSContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ u32 OSSaveContext(OSContext* context);
void OSClearContext(OSContext* context);
OSContext* OSGetCurrentContext();
void OSSetCurrentContext(OSContext* context);
u32 OSGetStackPointer();

#ifdef __cplusplus
}
Expand Down
48 changes: 48 additions & 0 deletions src/NESemu/modwrapper.c
Original file line number Diff line number Diff line change
@@ -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"); }

0 comments on commit 454723c

Please sign in to comment.