Files
Diddy-Kong-Racing/tools/python/first_diff.py
Ryan Myers 39c01d4f5e Splat changes (#462)
* Merge changes from splat where it makes sense at this stage.

* Update score, and script for what seems like new map file style.

* format

* Fix accidental inclusion of version specific details.

* Match camera_init

* Update Score

* Near match for func_80046524

* Format

* Woops, it's NON_MATCHING

* Missed button pressed value

* Work on documenting func_80046524

* MAtch func_80046524

* Match func_80046524

* Minor changes

* Fix warnings in func_80046524

* format.py

* Update README

* Match func_800230D0

* Fix UB in mode_init_taj_race
2025-02-21 09:23:36 -05:00

54 lines
2.0 KiB
Python

#!/usr/bin/env python3
# SPDX-FileCopyrightText: © 2022 AngheloAlf
# SPDX-License-Identifier: MIT
from __future__ import annotations
import argparse
import mapfile_parser
from pathlib import Path
import rabbitizer
def decodeInstruction(bytesDiff: bytes, mapFile: mapfile_parser.MapFile) -> str:
word = (bytesDiff[0] << 24) | (bytesDiff[1] << 16) | (bytesDiff[2] << 8) | (bytesDiff[3] << 0)
instr = rabbitizer.Instruction(word)
immOverride = None
if instr.isJumpWithAddress():
# Instruction is a function call (jal)
# Get the embedded address of the function call
symAddress = instr.getInstrIndexAsVram()
# Search for the address in the mapfile
symInfo = mapFile.findSymbolByVramOrVrom(symAddress)
if symInfo is not None:
# Use the symbol from the mapfile instead of a raw value
immOverride = symInfo.symbol.name
return instr.disassemble(immOverride=immOverride, extraLJust=-20)
def firstDiffMain():
parser = argparse.ArgumentParser(description="Find the first difference(s) between the built ROM and the base ROM.")
parser.add_argument("-c", "--count", type=int, default=5, help="find up to this many instruction difference(s)")
parser.add_argument("-r", "--region", help="Which region should be processed", default="us")
parser.add_argument("-v", "--version", help="Which version should be processed", default="v77")
parser.add_argument("-a", "--add-colons", action='store_true', help="Add colon between bytes" )
args = parser.parse_args()
buildFolder = Path("build") / Path("us_1.0")
BUILTROM = buildFolder / f"dkr.z64"
BUILTMAP = buildFolder / f"dkr.map"
EXPECTEDROM = "expected" / BUILTROM
EXPECTEDMAP = "expected" / BUILTMAP
mapfile_parser.frontends.first_diff.doFirstDiff(BUILTMAP, EXPECTEDMAP, BUILTROM, EXPECTEDROM, args.count, mismatchSize=True, addColons=args.add_colons, bytesConverterCallback=decodeInstruction)
if __name__ == "__main__":
firstDiffMain()