From c0af5c030c981ba3687bdffa7e132cc3195749dc Mon Sep 17 00:00:00 2001 From: JoshuaMKW Date: Thu, 19 Nov 2020 03:45:53 -0600 Subject: [PATCH] misc fixes --- dolreader.py | 5 ++++- kernel.py | 5 ++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/dolreader.py b/dolreader.py index 25fece3..427e5ae 100644 --- a/dolreader.py +++ b/dolreader.py @@ -306,11 +306,14 @@ class DolFile(object): _from: address to branch from\n lk: 0 | 1, is branch linking? """ + _from &= 0xFFFFFFFC + to &= 0xFFFFFFFC self.seek(_from) + print(hex(to), hex(_from), hex((to - _from) & 0x3FFFFFD | 0x48000000 | lk)) write_uint32(self, (to - _from) & 0x3FFFFFD | 0x48000000 | lk) def extract_branch_addr(self, bAddr: int) -> tuple: - """ Returns the branch offset of the given instruction, + """ Returns the destination of the given branch, and if the branch is conditional """ self.seek(bAddr) diff --git a/kernel.py b/kernel.py index 3d7984d..19f6b6b 100644 --- a/kernel.py +++ b/kernel.py @@ -124,7 +124,7 @@ class GCT(object): value = int.from_bytes(info, byteorder='big', signed=False) data = read_uint16(self.codeList) - size = data & 0x3000 + size = data & 0x3 counter = data & 0xFFF address_increment = read_uint16(self.codeList) value_increment = read_uint32(self.codeList) @@ -151,8 +151,7 @@ class GCT(object): elif (codetype.startswith(b'\xC6') or codetype.startswith(b'\xC7') or codetype.startswith(b'\xC6') or codetype.startswith(b'\xC7')): - dolFile.seek(address) - dolFile.insert_branch(int.from_bytes(info, byteorder='big', signed=False), address) + dolFile.insert_branch(int.from_bytes(info, byteorder='big', signed=False), address, lk=address&1) continue if codetype.hex().startswith('2') or codetype.hex().startswith('3'):