-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aac78f5
commit 2b9e90f
Showing
11 changed files
with
575 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"""Provides a simple pass-by-reference wrapped flag.""" | ||
|
||
# pylint: disable=invalid-name | ||
|
||
|
||
class AbortFlag: | ||
"""Indicates whether the trace should be aborted""" | ||
|
||
def __init__(self): | ||
self.abort_now = False | ||
|
||
def abort(self): | ||
"""Sets the abort flag.""" | ||
self.abort_now = True | ||
|
||
@property | ||
def should_abort(self): | ||
"""Queries the abort flag.""" | ||
return self.abort_now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Manages the exchange_u32.asm patch.""" | ||
|
||
# pylint: disable=consider-using-f-string | ||
# pylint: disable=too-few-public-methods | ||
# pylint: disable=invalid-name | ||
|
||
import struct | ||
from Xbox import Xbox | ||
import XboxHelper | ||
|
||
|
||
class _ExchangeU32: | ||
"""Manages the exchange_u32.asm patch.""" | ||
|
||
def __init__(self, verbose=True): | ||
self.exchange_u32_addr = 0 | ||
self.verbose = verbose | ||
|
||
def _install_kicker(self, xbox: Xbox): | ||
with open("exchange_u32", "rb") as patch_file: | ||
data = patch_file.read() | ||
|
||
self.exchange_u32_addr = XboxHelper.load_binary(xbox, data) | ||
if self.verbose: | ||
print("exchange_u32 installed at 0x%08X" % self.exchange_u32_addr) | ||
|
||
def call(self, xbox: Xbox, address: int, value: int) -> int: | ||
"""Calls the kicker with the given argument.""" | ||
if not self.exchange_u32_addr: | ||
self._install_kicker(xbox) | ||
|
||
return xbox.call(self.exchange_u32_addr, struct.pack("<LL", value, address))[ | ||
"eax" | ||
] | ||
|
||
|
||
_instance = _ExchangeU32() | ||
|
||
|
||
def exchange_u32(xbox: Xbox, address: int, value: int) -> int: | ||
"""Exchanges `value` with the value at `address`, returning the original value.""" | ||
return _instance.call(xbox, address, value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""Manages the HTML log file.""" | ||
|
||
# pylint: disable=consider-using-f-string | ||
# pylint: disable=invalid-name | ||
# pylint: disable=line-too-long | ||
|
||
import atexit | ||
|
||
|
||
class HTMLLog: | ||
"""Manages the HTML log file.""" | ||
|
||
def __init__(self, path): | ||
self.path = path | ||
|
||
with open(path, "w", encoding="utf8") as logfile: | ||
logfile.write( | ||
"<html><head>" | ||
"<style>" | ||
"body { font-family: sans-serif; background:#333; color: #ccc } " | ||
"img { border: 1px solid #FFF; } " | ||
"td, tr, table { background: #444; padding: 10px; border:1px solid #888; border-collapse: collapse; }" | ||
"</style></head><body><table>\n" | ||
) | ||
|
||
self.log(["<b>#</b>", "<b>Opcode / Method</b>", "..."]) | ||
atexit.register(self._close_tags) | ||
|
||
def _close_tags(self): | ||
with open(self.path, "a", encoding="utf8") as logfile: | ||
logfile.write("</table></body></html>") | ||
|
||
def log(self, values): | ||
"""Append the given values to the HTML log.""" | ||
with open(self.path, "a", encoding="utf8") as logfile: | ||
logfile.write("<tr>") | ||
for val in values: | ||
logfile.write("<td>%s</td>" % val) | ||
logfile.write("</tr>\n") | ||
|
||
def print_log(self, message): | ||
"""Print the given string and append it to the HTML log.""" | ||
print(message) | ||
self.log([message]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Manages the nv2a log file.""" | ||
|
||
# pylint: disable=invalid-name | ||
# pylint: disable=consider-using-f-string | ||
|
||
Nv2aLogMethodDetails = False | ||
|
||
|
||
class NV2ALog: | ||
"""Manages the nv2a log file.""" | ||
|
||
def __init__(self, path): | ||
self.path = path | ||
|
||
with open(self.path, "w", encoding="utf8") as logfile: | ||
logfile.write("xemu style NV2A log from nv2a-trace.py") | ||
|
||
def log(self, message): | ||
"""Append the given string to the nv2a log.""" | ||
with open(self.path, "a", encoding="utf8") as logfile: | ||
logfile.write(message) | ||
|
||
def log_method(self, method_info, data, pre_info, post_info): | ||
"""Append a line describing the given pgraph call to the nv2a log.""" | ||
with open(self.path, "a", encoding="utf8") as logfile: | ||
logfile.write( | ||
"nv2a: pgraph method (%d): 0x%x -> 0x%x (0x%x)\n" | ||
% ( | ||
method_info["subchannel"], | ||
method_info["object"], | ||
method_info["method"], | ||
data, | ||
) | ||
) | ||
|
||
if Nv2aLogMethodDetails: | ||
logfile.write("Method info:\n") | ||
logfile.write("Address: 0x%X\n" % method_info["address"]) | ||
logfile.write("Method: 0x%X\n" % method_info["method"]) | ||
logfile.write("Nonincreasing: %d\n" % method_info["nonincreasing"]) | ||
logfile.write("Subchannel: 0x%X\n" % method_info["subchannel"]) | ||
logfile.write("data:\n") | ||
logfile.write(str(data)) | ||
logfile.write("\n\n") | ||
logfile.write("pre_info: %s\n" % pre_info) | ||
logfile.write("post_info: %s\n" % post_info) |
Oops, something went wrong.