From 2f3863328205b355f543a2c286464e8c300d6ac2 Mon Sep 17 00:00:00 2001 From: CreateSource Date: Wed, 22 Nov 2023 11:55:14 -0500 Subject: [PATCH] first commit --- ctx.c | 57 ++++++++++++++++++++++ src/REL/subchrselDll/subchrselDll.c | 18 +++++++ src/REL/subchrselDll/subchrselDll.h | 11 +++++ tools/m2ctx.py | 73 +++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+) create mode 100644 ctx.c create mode 100644 src/REL/subchrselDll/subchrselDll.c create mode 100644 src/REL/subchrselDll/subchrselDll.h create mode 100644 tools/m2ctx.py diff --git a/ctx.c b/ctx.c new file mode 100644 index 00000000..cc4bd52f --- /dev/null +++ b/ctx.c @@ -0,0 +1,57 @@ +#define _FUNCTIONS_H_ +#define _COMMON_H_ +#define REL_EXECUTOR_H +#define _TYPES_H_ +#define F3DEX_GBI_2 1 +#define M2CTX 1 +#define _COMMON_STRUCTS_H +#define _LANGUAGE_C 1 +#define _MIPS_SZLONG 32 +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned long u32; +typedef unsigned long long u64; +typedef signed char s8; +typedef short s16; +typedef long s32; +typedef long long s64; +typedef volatile unsigned char vu8; +typedef volatile unsigned short vu16; +typedef volatile unsigned long vu32; +typedef volatile unsigned long long vu64; +typedef volatile signed char vs8; +typedef volatile short vs16; +typedef volatile long vs32; +typedef volatile long long vs64; +typedef float f32; +typedef double f64; +typedef struct UnkOvl { + s32 unk0; + char unk4[4]; + s32 unk8; +} UnkOvl; +typedef struct Vec3f { + f32 x; + f32 y; + f32 z; +} Vec3f; +void OSReport(const char * format, ...); +void* HuPrcCreate(void (*), s32, s32, s32); +void Hu3DBGColorSet(u8, u8, u8); +void Hu3DCameraCreate(s16); +void Hu3DCameraPerspectiveSet(s16, f32, f32, f32, f32); +void Hu3DCameraViewportSet(s16, f32, f32, f32, f32, f32, f32); +void omOvlHisChg(s32, s32, s32, s32); +UnkOvl* omOvlHisGet(s32); +void* omInitObjMan(s32, s32); +void fn_80044920(s16); +void fn_80045F74(s16, s32); +s32 fn_800578E4(void); +void fn_1_26C(void); +extern int _prolog(); +extern void _epilog(); +typedef void (*VoidFunc)(void); +extern const VoidFunc _ctors[]; +extern const VoidFunc _dtors[]; +extern void ModuleProlog(void); +extern void ModuleEpilog(void); diff --git a/src/REL/subchrselDll/subchrselDll.c b/src/REL/subchrselDll/subchrselDll.c new file mode 100644 index 00000000..9f9678e9 --- /dev/null +++ b/src/REL/subchrselDll/subchrselDll.c @@ -0,0 +1,18 @@ +#include "subchrselDll.h" + +void fn_1_A0(void) { + void* sp8 = omInitObjMan(0x32, 0x2000); + Hu3DBGColorSet(0U, 0U, 0U); + fn_8000C760(&fn_1_164, 0x1000, 0x3000, 0, fn_8000CA3C()); + fn_800414AC(1, 0, -1); +} + +u16 fn_1_10C(void) { + u16 var_r31; + + var_r31 = lbl_801D3AD0; + if (lbl_1_bss_0 != lbl_801D3AAC) { + var_r31 |= lbl_801D3AAC; + } + return var_r31; +} diff --git a/src/REL/subchrselDll/subchrselDll.h b/src/REL/subchrselDll/subchrselDll.h new file mode 100644 index 00000000..b996b549 --- /dev/null +++ b/src/REL/subchrselDll/subchrselDll.h @@ -0,0 +1,11 @@ +#include "common.h" +#include "REL/executor.h" + +void fn_8000C760(void*, s32, s32, s32, s32); +s32 fn_8000CA3C(); +void fn_800414AC(s16, s16, s16); +extern void fn_1_164(void); + +extern u8 lbl_1_bss_0; +extern u8 lbl_801D3AAC; +extern u16 lbl_801D3AD0; diff --git a/tools/m2ctx.py b/tools/m2ctx.py new file mode 100644 index 00000000..824145c9 --- /dev/null +++ b/tools/m2ctx.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python3 + +import argparse +import os +import sys +import subprocess +import tempfile + +script_dir = os.path.dirname(os.path.realpath(__file__)) +root_dir = os.path.abspath(os.path.join(script_dir, "..")) +src_dir = root_dir + "src/" + +# Project-specific +CPP_FLAGS = [ + "-Iinclude", + "-Isrc", + "-Ibuild/include", + "-Iinclude/engine", + "-D_LANGUAGE_C", + "-DF3DEX_GBI_2", + "-D_MIPS_SZLONG=32", + "-D__attribute__(...)=", + "-D__asm__(...)=", + "-ffreestanding", + "-DM2CTX", +] + +def import_c_file(in_file) -> str: + in_file = os.path.relpath(in_file, root_dir) + cpp_command = ["gcc", "-E", "-P", "-dM", *CPP_FLAGS, in_file] + cpp_command2 = ["gcc", "-E", "-P", *CPP_FLAGS, in_file] + + with tempfile.NamedTemporaryFile(suffix=".c") as tmp: + stock_macros = subprocess.check_output(["gcc", "-E", "-P", "-dM", tmp.name], cwd=root_dir, encoding="utf-8") + + out_text = "" + try: + out_text += subprocess.check_output(cpp_command, cwd=root_dir, encoding="utf-8") + out_text += subprocess.check_output(cpp_command2, cwd=root_dir, encoding="utf-8") + except subprocess.CalledProcessError: + print( + "Failed to preprocess input file, when running command:\n" + + ' '.join(cpp_command), + file=sys.stderr, + ) + sys.exit(1) + + if not out_text: + print("Output is empty - aborting") + sys.exit(1) + + for line in stock_macros.strip().splitlines(): + out_text = out_text.replace(line + "\n", "") + return out_text + +def main(): + parser = argparse.ArgumentParser( + description="""Create a context file which can be used for mips_to_c""" + ) + parser.add_argument( + "c_file", + help="""File from which to create context""", + ) + args = parser.parse_args() + + output = import_c_file(args.c_file) + + with open(os.path.join(root_dir, "ctx.c"), "w", encoding="UTF-8") as f: + f.write(output) + + +if __name__ == "__main__": + main() \ No newline at end of file