# Config file for Majora's Mask NTSC 1.0 Recompilation.

[input]
entrypoint = 0x80080000
# Paths are relative to the location of this config file.
elf_path = "mm.us.rev1.elf"
output_func_path = "RecompiledFuncs"
relocatable_sections_path = "overlays.us.rev1.txt"

[patches]
stubs = [
    # Stub out unused functions that directly manipulate RCP status.
    "RcpUtils_PrintRegisterStatus",
    "RcpUtils_Reset",
    # Stub out an unnecessary function that accesses kseg1 addresses.
    "CIC6105_Init"
]

ignored = [
    # Not actually a function
    "D_80186028"
]

# Hooks

# Function definition for the overlay loading function.
[[patches.func]]
name = "load_overlays"
args = ["u32", "u32", "u32"]

# Function hooks for overlay loading.
[[patches.hook]]
func = "Main_Init"
text = "    load_overlays((uint32_t)ctx->r6, (uint32_t)ctx->r5, (uint32_t)ctx->r7);"
after_vram = 0x800802A4

[[patches.hook]]
func = "Overlay_Load"
text = "    load_overlays((uint32_t)ctx->r4, MEM_W(0x10, ctx->r29), (uint32_t)(ctx->r5 - ctx->r4));"
# No after_vram means this will be placed at the start of the function

# Single-instruction patches

# Write audio dlists to kseg0 (cached, 0x80...) addresses instead of kseg1 (uncached, 0xA0...) ones.
# This saves the recompiler from needing to handle checking for kseg1 addresses on every memory operation.
[[patches.instruction]]
func = "AudioHeap_WritebackDCache"
vram = 0x8018B510
value = 0x3C010000 # lui $at, 0x2000 -> lui $at, 0x0000

# These two may not be needed with RCP timeout detection disabled
# # Pretend the RSP has already halted so that the game doesn't attempt to directly manipulate RSP registers.
# [[patches.instruction]]
# func = "Sched_HandleAudioCancel"
# vram = 0x801763D8
# value = 0x240F0001 # lw	$t7, 0x0($s1) -> li $t7, 1

# # Ditto.
# [[patches.instruction]]
# func = "Sched_HandleGfxCancel"
# vram = 0x80176534
# value = 0x240F0001 # lw	$t7, 0x0($s1) -> li $t7, 1

# Disable RCP timeout detection (sometimes throws false positives, not needed)
[[patches.instruction]]
func = "AudioMgr_HandleRetrace"
vram = 0x80172DBC
value = 0x00000000 # jal osSetTimer -> nop

# Ditto.
[[patches.instruction]]
func = "Graph_TaskSet00"
vram = 0x80174218
value = 0x00000000 # jal osSetTimer -> nop

# Prevent the minimap from drawing at a point where it can cause a crash when pausing.
[[patches.instruction]]
func = "func_80106644"
vram = 0x80106684
value = 0x29E10003 # slti $at, $t7, 0x4 -> slti $at, $t7, 0x3
