2023-06-26 12:27:37 +02:00
|
|
|
from typing import List
|
2021-07-31 16:32:19 +02:00
|
|
|
from yaml.loader import Loader
|
2024-01-02 18:16:18 +01:00
|
|
|
from splat.segtypes.n64.segment import N64Segment
|
|
|
|
from splat.util import options
|
2022-06-12 17:33:32 +02:00
|
|
|
import yaml as yaml_loader
|
2021-07-31 16:32:19 +02:00
|
|
|
|
2023-06-26 12:27:37 +02:00
|
|
|
|
2021-07-31 16:32:19 +02:00
|
|
|
class N64SegPm_effect_shims(N64Segment):
|
2023-06-26 12:27:37 +02:00
|
|
|
shims: List[str] = []
|
2021-07-31 16:32:19 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_shim_asm(index, name):
|
|
|
|
return f""".include "macro.inc"
|
|
|
|
|
|
|
|
# assembler directives
|
|
|
|
.set noat # allow manual use of $at
|
|
|
|
.set noreorder # don't insert nops after branches
|
|
|
|
.set gp=64 # allow use of 64-bit general purpose registers
|
|
|
|
|
|
|
|
.section .text, "ax"
|
|
|
|
|
|
|
|
glabel {name}
|
|
|
|
/* 0 3C01E020 */ lui $at, %hi(effectFuncs + 0x{index * 4:X})
|
|
|
|
/* 4 8C210694 */ lw $at, %lo(effectFuncs + 0x{index * 4:X})($at)
|
|
|
|
/* 8 00200008 */ jr $at
|
|
|
|
/* C 00000000 */ nop
|
|
|
|
"""
|
|
|
|
|
2023-06-26 12:27:37 +02:00
|
|
|
def shim_path(self, shim: str):
|
2022-09-28 22:52:12 +02:00
|
|
|
return options.opts.build_path / "asm" / "effect_shims" / f"{shim}.s"
|
2021-07-31 16:32:19 +02:00
|
|
|
|
2022-06-12 17:33:32 +02:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
rom_start,
|
|
|
|
rom_end,
|
|
|
|
type,
|
|
|
|
name,
|
|
|
|
vram_start,
|
|
|
|
args,
|
|
|
|
yaml,
|
|
|
|
):
|
|
|
|
super().__init__(
|
|
|
|
rom_start,
|
|
|
|
rom_end,
|
|
|
|
type,
|
|
|
|
name,
|
|
|
|
vram_start,
|
|
|
|
args=args,
|
|
|
|
yaml=yaml,
|
|
|
|
)
|
2021-07-31 16:32:19 +02:00
|
|
|
|
2023-07-24 19:51:48 +02:00
|
|
|
with open(options.opts.src_path / "effect_shims.yaml") as f:
|
2022-06-12 17:33:32 +02:00
|
|
|
self.shims = yaml_loader.load(f.read(), Loader=yaml_loader.SafeLoader)
|
2021-07-31 16:32:19 +02:00
|
|
|
|
|
|
|
def split(self, rom_bytes):
|
|
|
|
for i, shim in enumerate(self.shims):
|
|
|
|
shim_asm = N64SegPm_effect_shims.get_shim_asm(i, shim)
|
|
|
|
|
|
|
|
self.shim_path("").parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
with open(self.shim_path(shim), "w") as f:
|
|
|
|
f.write(shim_asm)
|
|
|
|
|
|
|
|
def get_linker_entries(self):
|
2024-01-02 18:16:18 +01:00
|
|
|
from splat.segtypes.linker_entry import LinkerEntry
|
2021-07-31 16:32:19 +02:00
|
|
|
|
|
|
|
ret = []
|
|
|
|
|
|
|
|
for shim in self.shims:
|
2023-11-10 03:48:23 +01:00
|
|
|
ret.append(LinkerEntry(self, [self.shim_path(shim)], self.shim_path(shim), ".text", ".text"))
|
2021-07-31 16:32:19 +02:00
|
|
|
|
|
|
|
return ret
|