first commit

This commit is contained in:
CreateSource 2023-11-22 11:55:14 -05:00
parent 0b4ae7caba
commit 2f38633282
4 changed files with 159 additions and 0 deletions

57
ctx.c Normal file
View file

@ -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);

View file

@ -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;
}

View file

@ -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;

73
tools/m2ctx.py Normal file
View file

@ -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()