From cf4cfc9b6cf52c25c2f4e188f73c70b19fd528ba Mon Sep 17 00:00:00 2001 From: octorock <79596758+octorock@users.noreply.github.com> Date: Thu, 13 May 2021 00:51:20 +0200 Subject: [PATCH 1/3] Rebuild progress script --- progress.py | 214 ++++++++++++++++++++++++++-------------------------- 1 file changed, 105 insertions(+), 109 deletions(-) diff --git a/progress.py b/progress.py index 7035cc35..f0288333 100644 --- a/progress.py +++ b/progress.py @@ -1,118 +1,114 @@ +import argparse +import git +import os -import csv, git, re, argparse, os -from itertools import chain -map = open("tmc.map", "r") -src = 0 -asm = 0 -srcData = 0 -data = 0 - -parser = argparse.ArgumentParser() -parser.add_argument("-m", "--matching", dest='matching', action='store_true', help="Output matching progress instead of decompilation progress") -args = parser.parse_args() -matching = args.matching - -NON_MATCHING_PATTERN = r'((?<=NONMATCH\(")asm/non_matching/.*\.inc)|((?<=NONMATCH\(")asm/non_matching/.*\.s)' -NON_ASM_PATTERN = r'(^\w+:)|(^\s@)|(^\s*\.)|(^\s*thumb_func_start)' - -#def remInvalid(x): - -def GetNonMatchingFunctions(files): - functions = [] - - for file in files: - with open(file) as f: - functions += re.findall(NON_MATCHING_PATTERN, f.read()) - - #functions = map(lambda x: x != "", functions) - return functions - -def ReadAllLines(fileName): - lineList = list() - with open(fileName) as f: - lineList = f.readlines() - - return lineList - -def GetFiles(path, ext): - files = [] - for r, d, f in os.walk(path): +def collect_non_matching_funcs(): + result = [] + for r, d, f in os.walk('asm/non_matching'): for file in f: - if file.endswith(ext): - files.append(os.path.join(r, file)) - - return files - -nonMatchingFunctions = GetNonMatchingFunctions(GetFiles("src", ".c")) if not args.matching else [] - -# this is actually the size of all non matching asm, not (total - non matching) -def GetNonMatchingSize(path): - size = 0 - - asmFiles = GetFiles(path, ".s") + GetFiles(path, ".inc") - - for asmFilePath in asmFiles: - for x in nonMatchingFunctions: # stupid tuple - if asmFilePath in x: - asmLines = ReadAllLines(asmFilePath) - - for asmLine in asmLines: - if len(re.findall(NON_ASM_PATTERN, asmLine, re.DOTALL)) == 0: - size += 2 - - return size - -nonMatchingASM = GetNonMatchingSize("asm/non_matching") - -for line in map: - reg = re.compile(r"^ \.(\w+)\s+0x[0-9a-f]+\s+(0x[0-9a-f]+) (\w+)\/(.+)\.o") - matches = reg.split(line) - - if (len(matches) < 5): - continue - - section = matches[1] - size = int(matches[2], 16) - direc = matches[3] - basename = matches[4] - - # alignment? idk - if (size & 3): - size += 4 - (size % 3) - - if (section == "text"): - if (direc == "src"): - src += size - elif (direc == "asm"): - asm += size - elif (section == "rodata"): - if (direc == "src"): - srcData += size - elif (direc == "data"): - data += size - -total = src + asm -dataTotal = srcData + data - -if matching: - srcPct = "%.4f" % (100 * (src) / total) - asmPct = "%.4f" % (100 * (asm) / total) -else: - srcPct = "%.4f" % (100 * (src + nonMatchingASM) / total) - asmPct = "%.4f" % (100 * (asm - nonMatchingASM) / total) + if file.endswith('.inc'): + # Assume that the filename is the function name + result.append(file[0:-4]) + else: + print(r,file) + return result -srcDataPct = "%.4f" % (100 * srcData / dataTotal) -dataPct = "%.4f" % (100 * data / dataTotal) +def parse_map(non_matching_funcs): + src = 0 + asm = 0 + src_data = 0 + data = 0 + non_matching = 0 -version = 1 -git_object = git.Repo().head.object -timestamp = str(git_object.committed_date) -git_hash = git_object.hexsha + with open('tmc.map', 'r') as map: + # Skip to the linker script section + line = map.readline() + while not line.startswith('Linker script and memory map'): + line = map.readline() + while not line.startswith('rom'): + line = map.readline() -#################################################### + prev_symbol = None + prev_addr = 0 + for line in map: + if line.startswith(' .'): + arr = line.split() + section = arr[0] + size = int(arr[2], 16) + filepath = arr[3] + dir = filepath.split('/')[0] -csv_list = [str(version), timestamp, git_hash, str(srcPct), str(asmPct), str(srcDataPct), str(dataPct)] + if section == '.text': + if dir == 'src': + src += size + elif dir == 'asm': + asm += size + elif dir == 'data': + # scripts + data += size + elif dir == '..': + # libc + src += size + elif section == '.rodata': + if dir == 'src': + src_data += size + elif dir == 'data': + data += size -print(",".join(csv_list)) + elif line.startswith(' '): + arr = line.split() + if len(arr) == 2 and arr[1] != '': # It is actually a symbol + + if prev_symbol in non_matching_funcs: + # Calculate the length for non matching function + non_matching += int(arr[0], 16) - prev_addr + + prev_symbol = arr[1] + prev_addr = int(arr[0], 16) + elif line.strip() == '': + # End of linker script section + break + + src -= non_matching + asm += non_matching + + return (src, asm, src_data, data) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('-m', '--matching', dest='matching', action='store_true', + help='Output matching progress instead of decompilation progress') + args = parser.parse_args() + matching = args.matching + + non_matching_funcs = [] + if matching: + non_matching_funcs = collect_non_matching_funcs() + + (src, asm, src_data, data) = parse_map(non_matching_funcs) + + total = src + asm + data_total = src_data + data + + src_pct = '%.4f' % (100 * src / total) + asm_pct = '%.4f' % (100 * asm / total) + + src_data_pct = '%.4f' % (100 * src_data / data_total) + data_pct = '%.4f' % (100 * data / data_total) + + version = 1 + git_object = git.Repo().head.object + timestamp = str(git_object.committed_date) + git_hash = git_object.hexsha + + csv_list = [str(version), timestamp, git_hash, str(src_pct), + str(asm_pct), str(src_data_pct), str(data_pct)] + + print(','.join(csv_list)) + + +if __name__ == '__main__': + main() From f2c69d0b7c5b51b38cf9a3c08d6dd7d85e23226d Mon Sep 17 00:00:00 2001 From: octorock <79596758+octorock@users.noreply.github.com> Date: Thu, 13 May 2021 00:54:00 +0200 Subject: [PATCH 2/3] Unify nonmatching namings --- asm/non_matching/CreateItemDrop.inc | 150 ++++++++++++++++++ asm/non_matching/ForceEquipItem.inc | 46 ++++++ .../{putItemOnSlot.s => PutItemOnSlot.inc} | 47 ------ .../{sub_08017530.inc => NPCUpdate.inc} | 0 .../{sub_08081E6C.s => sub_08081E6C.inc} | 0 .../moldworm/{moldworm.inc => Moldworm.inc} | 0 .../{sub_08070794.s => PlayerNormal.inc} | 0 ...{sub_08071634.s => PortalShrinkUpdate.inc} | 0 .../{sub_08070DC4.s => sub_08070DC4.inc} | 0 .../{sub_08072D54.s => sub_08072D54.inc} | 0 asm/non_matching/sub_0801CED8.inc | 33 ++++ .../{code_0805457C.inc => sub_0805457C.inc} | 149 ----------------- asm/non_matching/sub_0805EC9C.inc | 41 +++++ ...{sub_08061C60.inc => Townsperson_Head.inc} | 0 src/arm_proxy.c | 2 +- src/code_0805436C.c | 40 +++-- src/code_0805EC04.c | 45 +----- src/code_08077B98.c | 5 +- src/code_08077DF4.c | 5 +- src/code_0807CC3C.c | 12 +- src/enemy/bombPeahat.c | 10 +- src/enemy/businessScrub.c | 10 +- src/enemy/darkNut.c | 5 +- src/enemy/fallingBoulder.c | 14 +- src/enemy/likeLike.c | 10 +- src/enemy/madderpillar.c | 5 +- src/enemy/moldorm.c | 10 +- src/enemy/moldworm.c | 20 +-- src/enemy/pesto.c | 28 +--- src/enemy/puffstool.c | 10 +- src/enemy/spearMoblin.c | 14 +- src/enemy/wallMaster2.c | 5 +- src/ezloNag.c | 42 +---- src/gba/m4a.c | 2 +- src/manager/manager15.c | 14 +- src/manager/manager4.c | 12 +- src/manager/managerC.c | 14 +- src/npc/syrup.c | 18 +-- src/npc/townsperson.c | 10 +- src/object/button.c | 16 +- src/player.c | 8 +- src/room.c | 30 +--- src/textbox.c | 6 +- 43 files changed, 373 insertions(+), 515 deletions(-) create mode 100644 asm/non_matching/CreateItemDrop.inc create mode 100644 asm/non_matching/ForceEquipItem.inc rename asm/non_matching/{putItemOnSlot.s => PutItemOnSlot.inc} (55%) rename asm/non_matching/arm_proxy/{sub_08017530.inc => NPCUpdate.inc} (100%) rename asm/non_matching/button/{sub_08081E6C.s => sub_08081E6C.inc} (100%) rename asm/non_matching/moldworm/{moldworm.inc => Moldworm.inc} (100%) rename asm/non_matching/player/{sub_08070794.s => PlayerNormal.inc} (100%) rename asm/non_matching/player/{sub_08071634.s => PortalShrinkUpdate.inc} (100%) rename asm/non_matching/player/{sub_08070DC4.s => sub_08070DC4.inc} (100%) rename asm/non_matching/player/{sub_08072D54.s => sub_08072D54.inc} (100%) create mode 100644 asm/non_matching/sub_0801CED8.inc rename asm/non_matching/{code_0805457C.inc => sub_0805457C.inc} (62%) create mode 100644 asm/non_matching/sub_0805EC9C.inc rename asm/non_matching/townsperson/{sub_08061C60.inc => Townsperson_Head.inc} (100%) diff --git a/asm/non_matching/CreateItemDrop.inc b/asm/non_matching/CreateItemDrop.inc new file mode 100644 index 00000000..d84a8817 --- /dev/null +++ b/asm/non_matching/CreateItemDrop.inc @@ -0,0 +1,150 @@ +.syntax unified +CreateItemDrop: @ 0x08054754 + push {r4, r5, r6, lr} + adds r6, r0, #0 + adds r4, r1, #0 + adds r5, r2, #0 + cmp r4, #0x5e + beq _08054786 + cmp r4, #0x5e + bhi _08054772 + cmp r4, #0x5c + beq _080547A6 + cmp r4, #0x5c + bhi _08054782 + cmp r4, #0x3f + beq _08054794 + b _080547DA +_08054772: + cmp r4, #0xfc + blo _080547DA + cmp r4, #0xfe + bls _080547A6 + cmp r4, #0xff + bne _080547DA + movs r0, #1 + b _08054788 +_08054782: + movs r0, #0x65 + b _08054788 +_08054786: + movs r0, #9 +_08054788: + bl GetInventoryValue + cmp r0, #0 + bne _080547DA +_08054790: + movs r0, #0 + b _0805486C +_08054794: + movs r0, #0x40 + bl GetInventoryValue + cmp r0, #0 + beq _08054790 + cmp r5, #0 + bne _080547DA + movs r5, #1 + b _080547DA +_080547A6: + movs r0, #0x67 + bl GetInventoryValue + cmp r0, #0 + beq _08054790 + ldr r0, _080547FC @ =gRoomVars + ldrb r0, [r0, #5] + cmp r0, #3 + bhi _08054790 + cmp r4, #0x5c + beq _080547DA + adds r5, r4, #0 + subs r5, #0xfc + bl Random + movs r1, #0x3f + ands r1, r0 + ldr r2, _08054800 @ =gUnk_080FE1DD + lsls r0, r5, #6 + adds r1, r1, r0 + adds r1, r1, r2 + ldrb r5, [r1] + movs r4, #0x5c + cmp r5, #0 + bne _080547DA + movs r4, #0 +_080547DA: + cmp r4, #0 + beq _0805486A + cmp r4, #0xff + beq _08054842 + movs r0, #0 + adds r1, r4, #0 + adds r2, r5, #0 + bl CreateObject + adds r2, r0, #0 + cmp r2, #0 + beq _0805486A + ldr r0, _08054804 @ =gPlayerEntity + cmp r6, r0 + bne _08054808 + movs r0, #1 + b _0805480A + .align 2, 0 +_080547FC: .4byte gRoomVars +_08054800: .4byte gUnk_080FE1DD +_08054804: .4byte gPlayerEntity +_08054808: + movs r0, #0 +_0805480A: + strb r0, [r2, #0xe] + ldrb r0, [r6, #8] + cmp r0, #6 + bne _08054838 + ldrb r0, [r6, #9] + cmp r0, #0x63 + bne _0805481C + str r2, [r6, #0x54] + b _08054838 +_0805481C: + cmp r0, #0x1e + bne _08054838 + ldrb r0, [r6, #0x14] + lsls r0, r0, #3 + movs r3, #0x80 + rsbs r3, r3, #0 + adds r1, r3, #0 + orrs r0, r1 + strb r0, [r2, #0x15] + movs r0, #0xc0 + strh r0, [r2, #0x24] + movs r0, #0xc0 + lsls r0, r0, #9 + str r0, [r2, #0x20] +_08054838: + adds r0, r6, #0 + adds r1, r2, #0 + bl CopyPosition + b _0805486A +_08054842: + movs r0, #7 + movs r1, #0 + bl CreateEnemy + adds r2, r0, #0 + cmp r2, #0 + beq _0805486A + ldrh r0, [r6, #0x2e] + strh r0, [r2, #0x2e] + ldrh r0, [r6, #0x32] + strh r0, [r2, #0x32] + adds r0, r6, #0 + adds r0, #0x38 + ldrb r1, [r0] + adds r0, r2, #0 + adds r0, #0x38 + strb r1, [r0] + adds r0, r2, #0 + bl UpdateSpriteForCollisionLayer +_0805486A: + adds r0, r4, #0 +_0805486C: + pop {r4, r5, r6, pc} + .align 2, 0 +.syntax divided diff --git a/asm/non_matching/ForceEquipItem.inc b/asm/non_matching/ForceEquipItem.inc new file mode 100644 index 00000000..e12f3ea5 --- /dev/null +++ b/asm/non_matching/ForceEquipItem.inc @@ -0,0 +1,46 @@ + .syntax unified + .text + +ForceEquipItem: @ 0x08054414 + push {r4, r5, r6, r7, lr} + adds r4, r0, #0 + subs r0, r4, #1 + cmp r0, #0x1e + bhi _08054456 + cmp r1, #1 + bhi _08054456 + movs r2, #0 + cmp r1, #0 + bne _0805442A + movs r2, #1 +_0805442A: + ldr r0, _08054458 @ =gSave + adds r0, #0xb4 + adds r6, r1, r0 + ldrb r7, [r6] + adds r5, r2, r0 + ldrb r3, [r5] + ldr r2, _0805445C @ =gUnk_080FD5B4 + lsls r1, r3, #3 + adds r1, r1, r2 + lsls r0, r4, #3 + adds r0, r0, r2 + ldrb r1, [r1] + ldrb r0, [r0] + cmp r1, r0 + bne _0805444A + adds r3, r7, #0 +_0805444A: + strb r4, [r6] + strb r3, [r5] + ldr r1, _08054460 @ =gUnk_0200AF00 + movs r0, #0x7f + strb r0, [r1, #0x13] + strb r0, [r1, #0x14] +_08054456: + pop {r4, r5, r6, r7, pc} + .align 2, 0 +_08054458: .4byte gSave +_0805445C: .4byte gUnk_080FD5B4 +_08054460: .4byte gUnk_0200AF00 + .syntax divided diff --git a/asm/non_matching/putItemOnSlot.s b/asm/non_matching/PutItemOnSlot.inc similarity index 55% rename from asm/non_matching/putItemOnSlot.s rename to asm/non_matching/PutItemOnSlot.inc index d22d7828..af483e7b 100644 --- a/asm/non_matching/putItemOnSlot.s +++ b/asm/non_matching/PutItemOnSlot.inc @@ -1,7 +1,3 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - .syntax unified .text @@ -74,47 +70,4 @@ _08054410: pop {r4, r5, pc} .align 2, 0 - thumb_func_start ForceEquipItem -ForceEquipItem: @ 0x08054414 - push {r4, r5, r6, r7, lr} - adds r4, r0, #0 - subs r0, r4, #1 - cmp r0, #0x1e - bhi _08054456 - cmp r1, #1 - bhi _08054456 - movs r2, #0 - cmp r1, #0 - bne _0805442A - movs r2, #1 -_0805442A: - ldr r0, _08054458 @ =gSave - adds r0, #0xb4 - adds r6, r1, r0 - ldrb r7, [r6] - adds r5, r2, r0 - ldrb r3, [r5] - ldr r2, _0805445C @ =gUnk_080FD5B4 - lsls r1, r3, #3 - adds r1, r1, r2 - lsls r0, r4, #3 - adds r0, r0, r2 - ldrb r1, [r1] - ldrb r0, [r0] - cmp r1, r0 - bne _0805444A - adds r3, r7, #0 -_0805444A: - strb r4, [r6] - strb r3, [r5] - ldr r1, _08054460 @ =gUnk_0200AF00 - movs r0, #0x7f - strb r0, [r1, #0x13] - strb r0, [r1, #0x14] -_08054456: - pop {r4, r5, r6, r7, pc} - .align 2, 0 -_08054458: .4byte gSave -_0805445C: .4byte gUnk_080FD5B4 -_08054460: .4byte gUnk_0200AF00 .syntax divided diff --git a/asm/non_matching/arm_proxy/sub_08017530.inc b/asm/non_matching/arm_proxy/NPCUpdate.inc similarity index 100% rename from asm/non_matching/arm_proxy/sub_08017530.inc rename to asm/non_matching/arm_proxy/NPCUpdate.inc diff --git a/asm/non_matching/button/sub_08081E6C.s b/asm/non_matching/button/sub_08081E6C.inc similarity index 100% rename from asm/non_matching/button/sub_08081E6C.s rename to asm/non_matching/button/sub_08081E6C.inc diff --git a/asm/non_matching/moldworm/moldworm.inc b/asm/non_matching/moldworm/Moldworm.inc similarity index 100% rename from asm/non_matching/moldworm/moldworm.inc rename to asm/non_matching/moldworm/Moldworm.inc diff --git a/asm/non_matching/player/sub_08070794.s b/asm/non_matching/player/PlayerNormal.inc similarity index 100% rename from asm/non_matching/player/sub_08070794.s rename to asm/non_matching/player/PlayerNormal.inc diff --git a/asm/non_matching/player/sub_08071634.s b/asm/non_matching/player/PortalShrinkUpdate.inc similarity index 100% rename from asm/non_matching/player/sub_08071634.s rename to asm/non_matching/player/PortalShrinkUpdate.inc diff --git a/asm/non_matching/player/sub_08070DC4.s b/asm/non_matching/player/sub_08070DC4.inc similarity index 100% rename from asm/non_matching/player/sub_08070DC4.s rename to asm/non_matching/player/sub_08070DC4.inc diff --git a/asm/non_matching/player/sub_08072D54.s b/asm/non_matching/player/sub_08072D54.inc similarity index 100% rename from asm/non_matching/player/sub_08072D54.s rename to asm/non_matching/player/sub_08072D54.inc diff --git a/asm/non_matching/sub_0801CED8.inc b/asm/non_matching/sub_0801CED8.inc new file mode 100644 index 00000000..a976f73a --- /dev/null +++ b/asm/non_matching/sub_0801CED8.inc @@ -0,0 +1,33 @@ + .syntax unified + push {r4, lr} + adds r3, r0, #0 + ldr r0, _0801CF10 @ =gUnk_0200AF00 + adds r1, r0, #0 + adds r1, #0x24 + ldrb r4, [r1] + cmp r4, #1 + bne _0801CF0E + movs r2, #2 + movs r0, #2 + strb r0, [r1] + movs r1, #0 + movs r0, #0x10 + strh r0, [r3, #0xc] + movs r0, #0x90 + strh r0, [r3, #0xe] + strb r1, [r3, #6] + movs r0, #7 + strb r0, [r3, #1] + strb r4, [r3, #4] + ldrb r0, [r3] + orrs r0, r2 + strb r0, [r3] + ldr r1, _0801CF14 @ =gUnk_080C9094 + adds r0, r3, #0 + bl sub_0801CAB8 +_0801CF0E: + pop {r4, pc} + .align 2, 0 +_0801CF10: .4byte gUnk_0200AF00 +_0801CF14: .4byte gUnk_080C9094 + .syntax divided diff --git a/asm/non_matching/code_0805457C.inc b/asm/non_matching/sub_0805457C.inc similarity index 62% rename from asm/non_matching/code_0805457C.inc rename to asm/non_matching/sub_0805457C.inc index 4684cac8..3044a086 100644 --- a/asm/non_matching/code_0805457C.inc +++ b/asm/non_matching/sub_0805457C.inc @@ -215,153 +215,4 @@ _0805474E: pop {r4, r5, r6, r7, pc} .align 2, 0 - thumb_func_start CreateItemDrop -CreateItemDrop: @ 0x08054754 - push {r4, r5, r6, lr} - adds r6, r0, #0 - adds r4, r1, #0 - adds r5, r2, #0 - cmp r4, #0x5e - beq _08054786 - cmp r4, #0x5e - bhi _08054772 - cmp r4, #0x5c - beq _080547A6 - cmp r4, #0x5c - bhi _08054782 - cmp r4, #0x3f - beq _08054794 - b _080547DA -_08054772: - cmp r4, #0xfc - blo _080547DA - cmp r4, #0xfe - bls _080547A6 - cmp r4, #0xff - bne _080547DA - movs r0, #1 - b _08054788 -_08054782: - movs r0, #0x65 - b _08054788 -_08054786: - movs r0, #9 -_08054788: - bl GetInventoryValue - cmp r0, #0 - bne _080547DA -_08054790: - movs r0, #0 - b _0805486C -_08054794: - movs r0, #0x40 - bl GetInventoryValue - cmp r0, #0 - beq _08054790 - cmp r5, #0 - bne _080547DA - movs r5, #1 - b _080547DA -_080547A6: - movs r0, #0x67 - bl GetInventoryValue - cmp r0, #0 - beq _08054790 - ldr r0, _080547FC @ =gRoomVars - ldrb r0, [r0, #5] - cmp r0, #3 - bhi _08054790 - cmp r4, #0x5c - beq _080547DA - adds r5, r4, #0 - subs r5, #0xfc - bl Random - movs r1, #0x3f - ands r1, r0 - ldr r2, _08054800 @ =gUnk_080FE1DD - lsls r0, r5, #6 - adds r1, r1, r0 - adds r1, r1, r2 - ldrb r5, [r1] - movs r4, #0x5c - cmp r5, #0 - bne _080547DA - movs r4, #0 -_080547DA: - cmp r4, #0 - beq _0805486A - cmp r4, #0xff - beq _08054842 - movs r0, #0 - adds r1, r4, #0 - adds r2, r5, #0 - bl CreateObject - adds r2, r0, #0 - cmp r2, #0 - beq _0805486A - ldr r0, _08054804 @ =gPlayerEntity - cmp r6, r0 - bne _08054808 - movs r0, #1 - b _0805480A - .align 2, 0 -_080547FC: .4byte gRoomVars -_08054800: .4byte gUnk_080FE1DD -_08054804: .4byte gPlayerEntity -_08054808: - movs r0, #0 -_0805480A: - strb r0, [r2, #0xe] - ldrb r0, [r6, #8] - cmp r0, #6 - bne _08054838 - ldrb r0, [r6, #9] - cmp r0, #0x63 - bne _0805481C - str r2, [r6, #0x54] - b _08054838 -_0805481C: - cmp r0, #0x1e - bne _08054838 - ldrb r0, [r6, #0x14] - lsls r0, r0, #3 - movs r3, #0x80 - rsbs r3, r3, #0 - adds r1, r3, #0 - orrs r0, r1 - strb r0, [r2, #0x15] - movs r0, #0xc0 - strh r0, [r2, #0x24] - movs r0, #0xc0 - lsls r0, r0, #9 - str r0, [r2, #0x20] -_08054838: - adds r0, r6, #0 - adds r1, r2, #0 - bl CopyPosition - b _0805486A -_08054842: - movs r0, #7 - movs r1, #0 - bl CreateEnemy - adds r2, r0, #0 - cmp r2, #0 - beq _0805486A - ldrh r0, [r6, #0x2e] - strh r0, [r2, #0x2e] - ldrh r0, [r6, #0x32] - strh r0, [r2, #0x32] - adds r0, r6, #0 - adds r0, #0x38 - ldrb r1, [r0] - adds r0, r2, #0 - adds r0, #0x38 - strb r1, [r0] - adds r0, r2, #0 - bl UpdateSpriteForCollisionLayer -_0805486A: - adds r0, r4, #0 -_0805486C: - pop {r4, r5, r6, pc} - .align 2, 0 .syntax divided diff --git a/asm/non_matching/sub_0805EC9C.inc b/asm/non_matching/sub_0805EC9C.inc new file mode 100644 index 00000000..7c876fec --- /dev/null +++ b/asm/non_matching/sub_0805EC9C.inc @@ -0,0 +1,41 @@ + .syntax unified + push {r4, r5, r6, r7, lr} + adds r4, r0, #0 + adds r5, r1, #0 + adds r6, r2, #0 + adds r7, r3, #0 + ldrb r0, [r4, #0x1b] + lsls r0, r0, #0x1a + lsrs r0, r0, #0x1b + cmp r0, #0 + bne _0805ECBE + adds r0, r4, #0 + bl sub_0805EC04 + cmp r0, #0 + bne _0805ECBE + movs r0, #0 + b _0805ECE0 +_0805ECBE: + ldr r1, _0805ECE4 @ =gUnk_03000000 + ldr r0, _0805ECE8 @ =0x00000427 + adds r2, r1, r0 + movs r0, #1 + strb r0, [r2] + ldrb r0, [r4, #0x1b] + lsls r0, r0, #0x1a + lsrs r0, r0, #0x1b + lsls r0, r0, #3 + movs r2, #0x84 + lsls r2, r2, #3 + adds r1, r1, r2 + adds r0, r0, r1 + strh r5, [r0] + strh r6, [r0, #2] + strh r7, [r0, #4] + movs r0, #1 +_0805ECE0: + pop {r4, r5, r6, r7, pc} + .align 2, 0 +_0805ECE4: .4byte gUnk_03000000 +_0805ECE8: .4byte 0x00000427 + .syntax divided diff --git a/asm/non_matching/townsperson/sub_08061C60.inc b/asm/non_matching/townsperson/Townsperson_Head.inc similarity index 100% rename from asm/non_matching/townsperson/sub_08061C60.inc rename to asm/non_matching/townsperson/Townsperson_Head.inc diff --git a/src/arm_proxy.c b/src/arm_proxy.c index e564ced8..fb6612b9 100644 --- a/src/arm_proxy.c +++ b/src/arm_proxy.c @@ -345,7 +345,7 @@ void ManagerUpdate(Entity* this) { } // regalloc -NONMATCH("asm/non_matching/arm_proxy/sub_08017530.inc", void NPCUpdate(Entity* this)) { +NONMATCH("asm/non_matching/arm_proxy/NPCUpdate.inc", void NPCUpdate(Entity* this)) { if ((this->currentHealth & 0x7f) && !ReadBit(&gUnk_020342F8, this->currentHealth - 1)) DeleteThisEntity(); if ((this->action == 0) && ((this->flags & 1) == 0)) diff --git a/src/code_0805436C.c b/src/code_0805436C.c index 7e1fe6c3..61dfa3e0 100644 --- a/src/code_0805436C.c +++ b/src/code_0805436C.c @@ -2,6 +2,8 @@ #include "player.h" #include "room.h" #include "menu.h" +#include "area.h" +#include "utils.h" typedef struct { u8 filler[0xa8]; @@ -29,6 +31,9 @@ extern u8 gUnk_080FE1C6[]; extern u32 gUnk_02034398; extern void (*const gUnk_080FE2A0[])(); +void ForceEquipItem(u32, u8); +extern void sub_0807CAA0(u32, u32); + u32 IsItemEquipped(u32 itemID) { u32 ret; @@ -41,11 +46,11 @@ u32 IsItemEquipped(u32 itemID) { return ret; } -#if NON_MATCHING // reg-alloc -void PutItemOnSlot(u32 itemID) { +NONMATCH("asm/non_matching/PutItemOnSlot.inc", void PutItemOnSlot(u32 itemID)) { + // reg-alloc u32 itemSlot; if (itemID < 0x47) { - ModifyInventory(0, 1); + sub_0807CAA0(0, 1); } if (itemID - 1 < 0x1f) { itemSlot = 2; @@ -70,12 +75,9 @@ void PutItemOnSlot(u32 itemID) { ForceEquipItem(itemID, itemSlot); } } -#else -NAKED -void PutItemOnSlot(u32 itemID) { - asm(".include \"asm/non_matching/putItemOnSlot.s\""); -} -#endif +END_NONMATCH + +ASM_FUNC("asm/non_matching/ForceEquipItem.inc", void ForceEquipItem(u32 itemID, u8 itemSlot)) u32 SetBottleContents(u32 itemID, u32 bottleIndex) { @@ -146,8 +148,8 @@ u32 GetBottleContaining(u32 arg0) { } } -#if NON_MATCHING // reg-alloc -void sub_08054524(void) { +NONMATCH("asm/non_matching/sub_08054524.inc", void sub_08054524(void)) { + // reg-alloc u32 bVar1; bVar1 = gArea.locationIndex; @@ -160,12 +162,7 @@ void sub_08054524(void) { MemCopy(&gUnk_080015BC + gUnk_080FE1C6[bVar1] * 0x8, &gUnk_02034398, 0x20); } -#else -NAKED -void sub_08054524(void) { - asm(".include \"asm/non_matching/sub_08054524.inc\""); -} -#endif +END_NONMATCH void sub_08054564(void) { gRoomVars.filler[2] = 1; @@ -175,11 +172,12 @@ void sub_08054570(void) { gRoomVars.filler[2] = 0; } -NAKED -u32 sub_0805457C(u32 arg0, u32 arg1) { - asm(".include \"asm/non_matching/code_0805457C.inc\""); -} +ASM_FUNC("asm/non_matching/sub_0805457C.inc", u32 sub_0805457C(u32 arg0, u32 arg1)); +NONMATCH("asm/non_matching/CreateItemDrop.inc", u32 CreateItemDrop(Entity* arg0, u32 itemID, u32 itemParameter)) { + // TODO see below +} +END_NONMATCH /* extern u8 gUnk_080FE1DD[]; diff --git a/src/code_0805EC04.c b/src/code_0805EC04.c index 6c847707..bd38cac5 100644 --- a/src/code_0805EC04.c +++ b/src/code_0805EC04.c @@ -44,50 +44,7 @@ void sub_0805EC60(Entity* this) { } } -NAKED -bool32 sub_0805EC9C(Entity* ent, u32 param_2, u32 param_3, u32 param_4) { - asm_unified("\ - push {r4, r5, r6, r7, lr} \n\ - adds r4, r0, #0 \n\ - adds r5, r1, #0 \n\ - adds r6, r2, #0 \n\ - adds r7, r3, #0 \n\ - ldrb r0, [r4, #0x1b] \n\ - lsls r0, r0, #0x1a \n\ - lsrs r0, r0, #0x1b \n\ - cmp r0, #0 \n\ - bne _0805ECBE \n\ - adds r0, r4, #0 \n\ - bl sub_0805EC04 \n\ - cmp r0, #0 \n\ - bne _0805ECBE \n\ - movs r0, #0 \n\ - b _0805ECE0 \n\ -_0805ECBE: \n\ - ldr r1, _0805ECE4 @ =gUnk_03000000 \n\ - ldr r0, _0805ECE8 @ =0x00000427 \n\ - adds r2, r1, r0 \n\ - movs r0, #1 \n\ - strb r0, [r2] \n\ - ldrb r0, [r4, #0x1b] \n\ - lsls r0, r0, #0x1a \n\ - lsrs r0, r0, #0x1b \n\ - lsls r0, r0, #3 \n\ - movs r2, #0x84 \n\ - lsls r2, r2, #3 \n\ - adds r1, r1, r2 \n\ - adds r0, r0, r1 \n\ - strh r5, [r0] \n\ - strh r6, [r0, #2] \n\ - strh r7, [r0, #4] \n\ - movs r0, #1 \n\ -_0805ECE0: \n\ - pop {r4, r5, r6, r7, pc} \n\ - .align 2, 0 \n\ -_0805ECE4: .4byte gUnk_03000000 \n\ -_0805ECE8: .4byte 0x00000427 \n\ - "); -} +ASM_FUNC("asm/non_matching/sub_0805EC9C.inc", bool32 sub_0805EC9C(Entity* ent, u32 param_2, u32 param_3, u32 param_4)) void sub_0805ECEC(int param_1, u32 param_2, u32 param_3, u32 param_4) { u16* temp; diff --git a/src/code_08077B98.c b/src/code_08077B98.c index 856dc44b..86eb16eb 100644 --- a/src/code_08077B98.c +++ b/src/code_08077B98.c @@ -121,7 +121,4 @@ Entity* sub_08077CF8(u32 subtype, u32 form, u32 parameter, u32 unk) { return ent; } -NAKED -void sub_08077D38(ItemBehavior* beh, u32 arg1) { - asm(".include \"asm/non_matching/sub_08077D38.inc\""); -} +ASM_FUNC("asm/non_matching/sub_08077D38.inc", void sub_08077D38(ItemBehavior* beh, u32 arg1)) diff --git a/src/code_08077DF4.c b/src/code_08077DF4.c index de25d3b3..f3592e83 100644 --- a/src/code_08077DF4.c +++ b/src/code_08077DF4.c @@ -83,10 +83,7 @@ void sub_08077F10(ItemBehavior* arg0) { sub_08077F24(arg0, (u16)gPlayerState.field_0x90.HALF.HI); } -NAKED -void sub_08077F24(ItemBehavior* beh, u32 arg1) { - asm(".include \"asm/non_matching/sub_08077F24.inc\""); -} +ASM_FUNC("asm/non_matching/sub_08077F24.inc", void sub_08077F24(ItemBehavior* beh, u32 arg1)) void sub_08077F50(ItemBehavior* beh, u32 arg1) { sub_08079184(); diff --git a/src/code_0807CC3C.c b/src/code_0807CC3C.c index 4df3598d..25458be5 100644 --- a/src/code_0807CC3C.c +++ b/src/code_0807CC3C.c @@ -6,14 +6,8 @@ #include "save.h" // these three functions use gRoomControls, maybe once that is understood better, these can be decompiled easier -NONMATCH("asm/non_matching/code_0807CC3C/sub_0807D280.inc", void sub_0807D280(u32 unk_1, u32 unk_2)) { -} -END_NONMATCH +ASM_FUNC("asm/non_matching/code_0807CC3C/sub_0807D280.inc", void sub_0807D280(u32 unk_1, u32 unk_2)) -NONMATCH("asm/non_matching/code_0807CC3C/sub_0807D46C.inc", void sub_0807D46C(u32 unk_1, u32 unk_2)) { -} -END_NONMATCH +ASM_FUNC("asm/non_matching/code_0807CC3C/sub_0807D46C.inc", void sub_0807D46C(u32 unk_1, u32 unk_2)) -NONMATCH("asm/non_matching/code_0807CC3C/sub_0807D6D8.inc", void sub_0807D6D8(u32 unk_1, u32 unk_2)) { -} -END_NONMATCH +ASM_FUNC("asm/non_matching/code_0807CC3C/sub_0807D6D8.inc", void sub_0807D6D8(u32 unk_1, u32 unk_2)) diff --git a/src/enemy/bombPeahat.c b/src/enemy/bombPeahat.c index c661e0aa..fa170060 100644 --- a/src/enemy/bombPeahat.c +++ b/src/enemy/bombPeahat.c @@ -444,8 +444,7 @@ void sub_0802AF9C(Entity* this) { } } -#if NON_MATCHING -void sub_0802AFC8(Entity* this) { +NONMATCH("asm/non_matching/bombPeahat/sub_0802AFC8.inc", void sub_0802AFC8(Entity* this)) { u32 flag = 8; if (this->field_0xf < 0x29) { u32 tmp; @@ -470,12 +469,7 @@ void sub_0802AFC8(Entity* this) { this->palette.b.b0 = this->palette.b.b4; } } -#else -NAKED -void sub_0802AFC8(Entity* this) { - asm(".include \"asm/non_matching/bombPeahat/sub_0802AFC8.inc\""); -} -#endif +END_NONMATCH void sub_0802B048(Entity* this) { Entity* ent; diff --git a/src/enemy/businessScrub.c b/src/enemy/businessScrub.c index a6fa26a4..359c8861 100644 --- a/src/enemy/businessScrub.c +++ b/src/enemy/businessScrub.c @@ -523,8 +523,7 @@ bool32 sub_080291DC(Entity* this) { return FALSE; } -#if NON_MATCHING -void sub_0802922C(Entity* this) { +NONMATCH("asm/non_matching/businessScrub/sub_0802925C.inc", void sub_0802922C(Entity* this)) { const struct SalesOffering* offer = (const struct SalesOffering*)this->field_0x7c.WORD; this->action = 6; @@ -538,12 +537,7 @@ void sub_0802922C(Entity* this) { sub_080290E0(this, 3); } -#else -NAKED -void sub_0802922C(Entity* this) { - asm(".include \"asm/non_matching/businessScrub/sub_0802925C.inc\""); -} -#endif +END_NONMATCH void sub_0802925C(Entity* this) { sub_08078784(this, sub_0801E99C(this)); diff --git a/src/enemy/darkNut.c b/src/enemy/darkNut.c index 96585a58..6f9d08e7 100644 --- a/src/enemy/darkNut.c +++ b/src/enemy/darkNut.c @@ -391,10 +391,7 @@ void sub_0802124C(Entity* this) { } } -NAKED -u32 sub_08021274(u32 a, u32 b) { - asm(".include \"asm/non_matching/darkNut/sub_08021274.inc\""); -} +ASM_FUNC("asm/non_matching/darkNut/sub_08021274.inc", u32 sub_08021274(u32 a, u32 b)) void sub_080212B0(Entity* this) { u8 tmp; diff --git a/src/enemy/fallingBoulder.c b/src/enemy/fallingBoulder.c index 29076b1c..74135810 100644 --- a/src/enemy/fallingBoulder.c +++ b/src/enemy/fallingBoulder.c @@ -11,6 +11,8 @@ extern const u16 gUnk_080CD568[]; extern const u8 gUnk_080CD580[]; extern const s16 gUnk_080CD58C[]; +extern void sub_080AEFB4(Entity*); + void FallingBoulder(Entity* this) { EnemyFunctionHandler(this, gUnk_080CD540); } @@ -58,8 +60,7 @@ void sub_0802C318(Entity* this) { } } -#if NON_MATCHING -void sub_0802C334(Entity* this) { +NONMATCH("asm/non_matching/fallingBoulder/sub_0802C334.inc", void sub_0802C334(Entity* this)) { if ((u16)this->field_0x7c.HALF.LO == 0) { u32 tmp = gRoomControls.roomOriginY; if (&gPlayerEntity == NULL) @@ -99,7 +100,7 @@ void sub_0802C334(Entity* this) { diff += 0x18; } sub_0802C62C(this); - this->field_0x7a.HWORD = Random() & 0xff | 0x100; + this->field_0x7a.HWORD = (Random() & 0xff) | 0x100; return; } break; @@ -124,12 +125,7 @@ void sub_0802C334(Entity* this) { this->spritePriority.b0 = 1; UpdateSpriteForCollisionLayer(this); } -#else -NAKED -void sub_0802C334(Entity* this) { - asm(".include \"asm/non_matching/fallingBoulder/sub_0802C334.inc\""); -} -#endif +END_NONMATCH void nullsub_148(Entity* this) { /* ... */ diff --git a/src/enemy/likeLike.c b/src/enemy/likeLike.c index f04073d3..400233c6 100644 --- a/src/enemy/likeLike.c +++ b/src/enemy/likeLike.c @@ -204,8 +204,7 @@ void sub_0802805C(Entity* this) { } } -#if NON_MATCHING -void sub_0802810C(Entity* this) { +NONMATCH("asm/non_matching/likeLike/sub_0802810C.inc", void sub_0802810C(Entity* this)) { gPlayerState.jumpStatus = 0x41; gPlayerState.field_0xa = 0; gPlayerState.flags.all &= 0xffffffef; @@ -224,12 +223,7 @@ void sub_0802810C(Entity* this) { this->iframes = -18; } } -#else -NAKED -void sub_0802810C(Entity* this) { - asm(".include \"asm/non_matching/likeLike/sub_0802810C.inc\""); -} -#endif +END_NONMATCH void sub_080281A0(Entity* this) { this->field_0xf = 0x19; diff --git a/src/enemy/madderpillar.c b/src/enemy/madderpillar.c index 00cc3b3a..7d1fa2ee 100644 --- a/src/enemy/madderpillar.c +++ b/src/enemy/madderpillar.c @@ -318,10 +318,7 @@ void sub_08029DE4(Entity* this) { } } -NAKED -void sub_08029E0C(Entity* this) { - asm(".include \"asm/non_matching/madderpillar/sub_08029E0C.inc\""); -} +ASM_FUNC("asm/non_matching/madderpillar/sub_08029E0C.inc", void sub_08029E0C(Entity* this)) void sub_08029EEC(Entity* this) { u32 uVar1 = (this->direction >> 3) + this->field_0x74.HALF.HI; diff --git a/src/enemy/moldorm.c b/src/enemy/moldorm.c index 8076e1ca..ed08478d 100644 --- a/src/enemy/moldorm.c +++ b/src/enemy/moldorm.c @@ -141,15 +141,9 @@ void sub_08022DE8(Entity* this) { } } -NAKED -void sub_08022E40(Entity* this) { - asm(".include \"asm/non_matching/moldorm/sub_08022E40.inc\""); -} +ASM_FUNC("asm/non_matching/moldorm/sub_08022E40.inc", void sub_08022E40(Entity* this)) -NAKED -void sub_08022EAC(Entity* this) { - asm(".include \"asm/non_matching/moldorm/sub_08022EAC.inc\""); -} +ASM_FUNC("asm/non_matching/moldorm/sub_08022EAC.inc", void sub_08022EAC(Entity* this)) void sub_08022F14(Entity* this) { if (sub_08049FA0(this) == 0) { diff --git a/src/enemy/moldworm.c b/src/enemy/moldworm.c index 403ae1b5..cb27ab6d 100644 --- a/src/enemy/moldworm.c +++ b/src/enemy/moldworm.c @@ -27,8 +27,7 @@ extern void (*const gUnk_080CBC98[])(Entity*); extern void (*const gUnk_080CBCA8[])(Entity*); extern const s8 gUnk_080CBCB8[]; -#if NON_MATCHING -void Moldworm(Entity* this) { +NONMATCH("asm/non_matching/moldworm/Moldworm.inc", void Moldworm(Entity* this)) { u16 prevX = this->x.HALF.HI; u16 prevY = this->y.HALF.HI; @@ -56,12 +55,7 @@ void Moldworm(Entity* this) { (((this->x.HALF.HI - prevX + 8) & 0xf) << 4) | ((this->y.HALF.HI - prevY + 8U) & 0xf); } } -#else -NAKED -void Moldworm(Entity* this) { - asm(".include \"asm/non_matching/moldworm/moldworm.inc\""); -} -#endif +END_NONMATCH void sub_080230CC(Entity* this) { gUnk_080CBC50[this->action](this); @@ -472,10 +466,7 @@ void sub_08023990(Entity* this, u32 param_2, u32 param_3) { } /* TODO: fix struct */ -NAKED -void sub_080239F0(Entity* this) { - asm(".include \"asm/non_matching/moldworm/sub_080239F0.inc\""); -} +ASM_FUNC("asm/non_matching/moldworm/sub_080239F0.inc", void sub_080239F0(Entity* this)) bool32 sub_08023A38(u32 unk) { if (unk == 0x1a || unk == 0x29) { @@ -522,10 +513,7 @@ void sub_08023AB0(Entity* this) { } } -NAKED -bool32 sub_08023B38(Entity* this) { - asm(".include \"asm/non_matching/moldworm/sub_08023B38.inc\""); -} +ASM_FUNC("asm/non_matching/moldworm/sub_08023B38.inc", bool32 sub_08023B38(Entity* this)) // clang-format off void (*const gUnk_080CBC38[])(Entity*) = { diff --git a/src/enemy/pesto.c b/src/enemy/pesto.c index 3eeda562..1277f0c6 100644 --- a/src/enemy/pesto.c +++ b/src/enemy/pesto.c @@ -4,6 +4,7 @@ #include "createObject.h" #include "game.h" #include "functions.h" +#include "save.h" extern u32 sub_080002E0(u16, u32); extern void sub_0800449C(Entity*, u32); @@ -559,20 +560,14 @@ void sub_080249DC(Entity* this) { InitializeAnimation(this, this->animationState); } -#if NON_MATCHING -void sub_080249F4(Entity* this) { +NONMATCH("asm/non_matching/pesto/sub_080249F4.inc", void sub_080249F4(Entity* this)) { u8 direction = ((this->direction + 2) & 0x1c) >> 2; if (direction != this->animationState) { this->animationState = direction; InitializeAnimation(this, this->animationState); } } -#else -NAKED -void sub_080249F4(Entity* this) { - asm(".include \"asm/non_matching/pesto/sub_080249F4.inc\""); -} -#endif +END_NONMATCH void sub_08024A14(Entity* this, u32 param_2, u32 param_3) { u8 unk = FALSE; @@ -703,10 +698,7 @@ bool32 sub_08024B38(Entity* this) { return iVar4; } -NAKED -bool32 sub_08024C48(Entity* this, bool32 unk) { - asm(".include \"asm/non_matching/pesto/sub_08024C48.inc\""); -} +ASM_FUNC("asm/non_matching/pesto/sub_08024C48.inc", bool32 sub_08024C48(Entity* this, bool32 unk)) void sub_08024C7C(Entity* this) { this->action = 1; @@ -794,8 +786,7 @@ u32 sub_08024E34(void) { return gUnk_080CBF20[idx]; } -#if NON_MATCHING -void sub_08024E4C(Entity* this) { +NONMATCH("asm/non_matching/pesto/sub_08024E4C.inc", void sub_08024E4C(Entity* this)) { if (this->field_0x82.HALF.HI == 3) { this->field_0xf++; this->field_0xf &= 0xff; @@ -829,7 +820,7 @@ void sub_08024E4C(Entity* this) { player->animationState = 4; player->spritePriority.b1 = 0; if (this->field_0xf == 0) { - (this->field_0x86.HALF.HI++; + this->field_0x86.HALF.HI++; player->iframes = 8; ModHealth(-2); sub_0800449C(player, 0x7a); @@ -837,12 +828,7 @@ void sub_08024E4C(Entity* this) { } } } -#else -NAKED -void sub_08024E4C(Entity* this) { - asm(".include \"asm/non_matching/pesto/sub_08024E4C.inc\""); -} -#endif +END_NONMATCH void sub_08024F50(Entity* this) { gPlayerState.field_0xa = 0; diff --git a/src/enemy/puffstool.c b/src/enemy/puffstool.c index adc59447..0bce6e2a 100644 --- a/src/enemy/puffstool.c +++ b/src/enemy/puffstool.c @@ -468,8 +468,7 @@ bool32 sub_080258C4(Entity* this) { } } -#if NON_MATCHING -bool32 sub_0802594C(Entity* this, u32 param_2) { +NONMATCH("asm/non_matching/puffstool/sub_0802594C.inc", bool32 sub_0802594C(Entity* this, u32 param_2)) { const s8* unk = gUnk_080CC090[param_2]; u32 uVar1 = this->collisionLayer; RoomControls* ctrl = &gRoomControls; @@ -492,12 +491,7 @@ bool32 sub_0802594C(Entity* this, u32 param_2) { return 0; } -#else -NAKED -bool32 sub_0802594C(Entity* this, u32 param_2) { - asm(".include \"asm/non_matching/puffstool/sub_0802594C.inc\""); -} -#endif +END_NONMATCH void sub_08025A54(Entity* this) { u32 layer = this->collisionLayer; diff --git a/src/enemy/spearMoblin.c b/src/enemy/spearMoblin.c index 033c1ea7..b12186e0 100644 --- a/src/enemy/spearMoblin.c +++ b/src/enemy/spearMoblin.c @@ -240,14 +240,13 @@ void sub_08028528(Entity* this) { } } -#if NON_MATCHING -void sub_08028604(Entity* this) { +NONMATCH("asm/non_matching/spearMoblin/sub_08028604.inc", void sub_08028604(Entity* this)) { this->field_0xf = 0; if (this->field_0x82.HALF.LO == 1) { this->actionDelay = gUnk_080CC7BC[Random() & 3]; this->speed = 0x80; if (sub_08049FA0(this) != 0) { - this->direction = gUnk_080CC7D0[Random() & 7] + 0x18 + this->direction & 0x18; + this->direction = gUnk_080CC7D0[Random() & 7] + 0x18 + (this->direction & 0x18); } else { u32 iVar3 = sub_08049EE4(this); u32 uVar1; @@ -258,7 +257,7 @@ void sub_08028604(Entity* this) { this->actionDelay = this->actionDelay + 0x10; this->field_0x82.HALF.HI--; } - this->direction = iVar3 + uVar1 + 4U & 0x18; + this->direction = iVar3 + uVar1 + (4U & 0x18); } } else { this->actionDelay = 0xc; @@ -270,12 +269,7 @@ void sub_08028604(Entity* this) { sub_080287E0(this); } } -#else -NAKED -void sub_08028604(Entity* this) { - asm(".include \"asm/non_matching/spearMoblin/sub_08028604.inc\""); -} -#endif +END_NONMATCH bool32 sub_080286CC(Entity* this) { if (this->field_0x80.HALF.HI == 0) { diff --git a/src/enemy/wallMaster2.c b/src/enemy/wallMaster2.c index f6d32479..7c488c30 100644 --- a/src/enemy/wallMaster2.c +++ b/src/enemy/wallMaster2.c @@ -160,10 +160,7 @@ void sub_0802CF64(Entity* this) { sub_0802CF8C(this); } -NAKED -void sub_0802CF8C(Entity* this) { - asm(".include \"asm/non_matching/wallMaster2/sub_0802CF8C.inc\""); -} +ASM_FUNC("asm/non_matching/wallMaster2/sub_0802CF8C.inc", void sub_0802CF8C(Entity* this)) void sub_0802CFD8(Entity* this) { u32 unk = gUnk_080CD740[(this->field_0x7a.HALF.LO++ >> 3) & 7]; diff --git a/src/ezloNag.c b/src/ezloNag.c index 5d3ec162..aa45634e 100644 --- a/src/ezloNag.c +++ b/src/ezloNag.c @@ -34,10 +34,10 @@ void EzloNag(Element* arg0) { gUnk_080C904C[arg0->unk4](arg0); } -#ifdef NON_MATCHING // REG SWAP extern u32 gUnk_080C9094; +extern void sub_0801CAB8(Element*, u32*); -void sub_0801CED8(Element* arg0) { +NONMATCH("asm/non_matching/sub_0801CED8.inc", void sub_0801CED8(Element* arg0)) { if (gUnk_0200AF00.ezloNagFuncIndex == 1) { gUnk_0200AF00.ezloNagFuncIndex = 2; arg0->unkC = 0x10; @@ -49,43 +49,7 @@ void sub_0801CED8(Element* arg0) { sub_0801CAB8(arg0, &gUnk_080C9094); } } -#else -NAKED -void sub_0801CED8(Element* arg0) { - asm_unified("\ - push {r4, lr}\n\ - adds r3, r0, #0\n\ - ldr r0, _0801CF10 @ =gUnk_0200AF00\n\ - adds r1, r0, #0\n\ - adds r1, #0x24\n\ - ldrb r4, [r1]\n\ - cmp r4, #1\n\ - bne _0801CF0E\n\ - movs r2, #2\n\ - movs r0, #2\n\ - strb r0, [r1]\n\ - movs r1, #0\n\ - movs r0, #0x10\n\ - strh r0, [r3, #0xc]\n\ - movs r0, #0x90\n\ - strh r0, [r3, #0xe]\n\ - strb r1, [r3, #6]\n\ - movs r0, #7\n\ - strb r0, [r3, #1]\n\ - strb r4, [r3, #4]\n\ - ldrb r0, [r3]\n\ - orrs r0, r2\n\ - strb r0, [r3]\n\ - ldr r1, _0801CF14 @ =gUnk_080C9094\n\ - adds r0, r3, #0\n\ - bl sub_0801CAB8\n\ - _0801CF0E:\n\ - pop {r4, pc}\n\ - .align 2, 0\n\ - _0801CF10: .4byte gUnk_0200AF00\n\ - _0801CF14: .4byte gUnk_080C9094"); -} -#endif +END_NONMATCH void sub_0801CF18(Element* arg0) { u32 temp; diff --git a/src/gba/m4a.c b/src/gba/m4a.c index 2049ba5c..bcd552d9 100644 --- a/src/gba/m4a.c +++ b/src/gba/m4a.c @@ -1066,7 +1066,7 @@ void CgbModVol(CgbChannel* chan) { // Force chan->rightVolume and chan->leftVolume to be read from memory again, // even though there is no reason to do so. // The command line option "-fno-gcse" achieves the same result as this. -#ifndef NONMATCHING +#ifndef NON_MATCHING asm("" : : : "memory"); #endif diff --git a/src/manager/manager15.c b/src/manager/manager15.c index 709bef05..313fa487 100644 --- a/src/manager/manager15.c +++ b/src/manager/manager15.c @@ -427,8 +427,7 @@ void sub_0805A94C(Manager15* this) { gScreen.controls.window1VerticalDimensions = (tmp1 << 8 | tmp2); } -#ifdef NON_MATCHING -void sub_0805A9CC(Manager15* this) { +NONMATCH("asm/non_matching/manager15/sub_0805A9CC.inc", void sub_0805A9CC(Manager15* this)) { int tmp1, tmp2; void* tmp3; gScreen.affine.bg3xOffset = gRoomControls.roomScrollX - this->unk_24 + this->unk_34; @@ -448,19 +447,14 @@ void sub_0805A9CC(Manager15* this) { if (tmp1 < 0) tmp1 += 0x3F; tmp3 = (&gBG3Buffer[(tmp1 >> 6 << 9)]); - gScreen.affine.unk5 = (u32)tmp3; + gScreen.affine.bg2Tilemap = (u32*)tmp3; // TODO .unk5 gScreen.controls.window1VerticalDimensions = 0xa0; if (this->unk_28 == tmp3) return; this->unk_28 = tmp3; - gScreen.affine.unk4 = 1; + gScreen.affine.bg2Updated = 1; // TODO .unk4 } -#else -NAKED -void sub_0805A9CC(Manager15* this) { - asm(".include \"asm/non_matching/manager15/sub_0805A9CC.inc\""); -} -#endif +END_NONMATCH extern struct { u8 unk_00[0x20]; } gUnk_085A97A0[]; extern u16 gUnk_081085B8[]; diff --git a/src/manager/manager4.c b/src/manager/manager4.c index 3165042c..7066c507 100644 --- a/src/manager/manager4.c +++ b/src/manager/manager4.c @@ -62,11 +62,10 @@ void sub_08057920(Manager* this) { void sub_08057A18(Manager*, DiggingCaveEntrance*); -#ifdef NON_MATCHING -u32 sub_0805795C(Manager* this, DiggingCaveEntrance* entr) { +NONMATCH("asm/non_matching/manager4/sub_0805795C.inc", u32 sub_0805795C(Manager* this, DiggingCaveEntrance* entr)) { u16 offsetX, offsetY, offsetX2, offsetY2; u32 tmp; - if (gUnk_03004030.address_width) { + if (gUnk_03004030.unk_00) { // TODO .address_width (?) offsetX = gPlayerEntity.x.HALF.HI - gRoomControls.roomOriginX; offsetY = gPlayerEntity.y.HALF.HI - gRoomControls.roomOriginY; offsetX2 = (entr->unk_00 & 0x3F) * 16 + 8; @@ -93,12 +92,7 @@ u32 sub_0805795C(Manager* this, DiggingCaveEntrance* entr) { sub_08057A18(this, entr); return 1; } -#else -NAKED -u32 sub_0805795C(Manager* this, DiggingCaveEntrance* entr) { - asm(".include \"asm/non_matching/manager4/sub_0805795C.inc\""); -} -#endif +END_NONMATCH extern void sub_08080930(); diff --git a/src/manager/managerC.c b/src/manager/managerC.c index 83b35412..f1965a35 100644 --- a/src/manager/managerC.c +++ b/src/manager/managerC.c @@ -8,6 +8,8 @@ #include "coord.h" #include "functions.h" #include "save.h" +#include "area.h" +#include "utils.h" typedef struct { Manager manager; @@ -275,8 +277,7 @@ void sub_08058CFC() { } } -#ifdef NON_MATCHING -void sub_08058D34() { +NONMATCH("asm/non_matching/managerC/sub_08058D34.inc", void sub_08058D34()) { LoadPaletteGroup(0x28); MemCopy(gUnk_02017700, gUnk_02017700 + 0x240, 0x20); gUsedPalettes |= 0x200000; @@ -285,7 +286,7 @@ void sub_08058D34() { gScreen.affine.bg2Control = 0xBC82; gScreen.bg.bg1xOffset = 0x5E86; gScreen.bg.bg1yOffset = 0; - gScreen.bg.bg2xOffset = 0; + gScreen.bg.bg1Tilemap = 0; gScreen.controls.layerFXControl = 0x3456; gScreen.controls.alphaBlend = 0x909; gArea.musicIndex = gArea.pMusicIndex; @@ -294,9 +295,4 @@ void sub_08058D34() { LoadGfxGroup(0x4A); } } -#else -NAKED -void sub_08058D34() { - asm(".include \"asm/non_matching/managerC/sub_08058D34.inc\""); -} -#endif +END_NONMATCH diff --git a/src/npc/syrup.c b/src/npc/syrup.c index 8a60ddb7..5e71f5b4 100644 --- a/src/npc/syrup.c +++ b/src/npc/syrup.c @@ -3,6 +3,8 @@ #include "npc.h" #include "script.h" #include "functions.h" +#include "object.h" +#include "random.h" extern void (*gUnk_081121D4[])(Entity*); @@ -41,8 +43,9 @@ void sub_0806A234(Entity* this) { } } -#ifdef NON_MATCHING -void sub_0806A26C(Entity* this) { +extern u8 gUnk_081121DC[]; + +NONMATCH("asm/non_matching/syrup/sub_0806A26C.inc", void sub_0806A26C(Entity* this)) { u8 unk; u32 uVar2; Entity* pEVar1; @@ -52,13 +55,8 @@ void sub_0806A26C(Entity* this) { if (uVar2 = Random(), uVar2) { unk = -unk; // wtf?! } - pEVar1->spriteOffsetX = gUnk_081121D4[uVar2 & 7]; - pEVar1->spriteOffsetY = gUnk_081121D4[(uVar2 / 256) & 7] - 8; + pEVar1->spriteOffsetX = (u8)gUnk_081121DC[uVar2 & 7]; + pEVar1->spriteOffsetY = (u8)gUnk_081121DC[(uVar2 / 256) & 7] - 8; } } -#else -NAKED -void sub_0806A26C(Entity* this) { - asm(".include \"asm/non_matching/syrup/sub_0806A26C.inc\""); -} -#endif +END_NONMATCH diff --git a/src/npc/townsperson.c b/src/npc/townsperson.c index fc99bac6..de089fbe 100644 --- a/src/npc/townsperson.c +++ b/src/npc/townsperson.c @@ -73,19 +73,13 @@ void sub_08061C00(Entity* this) { } } -#if NON_MATCHING -void Townsperson_Head(Entity* this) { +NONMATCH("asm/non_matching/townsperson/Townsperson_Head.inc", void Townsperson_Head(Entity* this)) { SetExtraSpriteFrame(this, 0, *(gUnk_0810B78C + (this->animIndex & 3)) + gUnk_0810B680[this->type].frame1); SetExtraSpriteFrame(this, 1, this->frameIndex + gUnk_0810B680[this->type].frame2); SetSpriteSubEntryOffsetData1(this, 1, 0); sub_0807000C(this); } -#else -NAKED -void Townsperson_Head(Entity* this) { - asm(".include \"asm/non_matching/townsperson/sub_08061C60.inc\""); -} -#endif +END_NONMATCH void sub_08061CB4(Entity* this, u32 arg1) { if (this->animIndex != arg1) { diff --git a/src/object/button.c b/src/object/button.c index 0530d52f..5111575e 100644 --- a/src/object/button.c +++ b/src/object/button.c @@ -197,11 +197,12 @@ u32 sub_08081F00(u32*, u32*); extern u16 gMapDataTopSpecial[0x2000]; -#ifdef NON_MATCHING -void sub_08081E6C(Entity* this) { +extern u16* GetLayerByIndex(u32); +extern u16 gUnk_02019EE0[]; +NONMATCH("asm/non_matching/button/sub_08081E6C.inc", void sub_08081E6C(Entity* this)) { u32 r4; u16 *tmp, *r1; - u8* tmp2; + u16* tmp2; u32 r6 = this->field_0x74.HWORD; u32 r5 = this->collisionLayer; u32 tile = GetTileType(r6, r5); @@ -212,19 +213,14 @@ void sub_08081E6C(Entity* this) { tmp = r1 + 0x3802; r1 += 0x3002 + r4; tmp = tmp + (*r1 << 2); - tmp2 = (r5 == 2 ? gMapDataTopSpecial : (u8*)&gUnk_02019EE0); + tmp2 = (r5 == 2 ? gMapDataTopSpecial : gUnk_02019EE0); tmp2 += (((0x3f & r6) << 1) + ((0xfc0 & r6) << 2)) << 1; if (sub_08081F00((u32*)tmp2, (u32*)tmp)) return; SetTileType(r4, r6, r5); SetTile(tile, r6, r5); } -#else -NAKED -void sub_08081E6C(Entity* this) { - asm(".include \"asm/non_matching/button/sub_08081E6C.s\""); -} -#endif +END_NONMATCH u32 sub_08081F00(u32* unk1, u32* unk2) { if (*unk1 != *unk2) diff --git a/src/player.c b/src/player.c index 364e7821..4e634712 100644 --- a/src/player.c +++ b/src/player.c @@ -130,7 +130,7 @@ void PlayerInit(Entity* this) { } // PlayerState.flags need to be 100% before this one can reasonably be done -ASM_FUNC("asm/non_matching/player/sub_08070794.s", void PlayerNormal(Entity* this)) +ASM_FUNC("asm/non_matching/player/PlayerNormal.inc", void PlayerNormal(Entity* this)) void sub_08070BEC(Entity* this, u32 r0) { if (r0 & 1) @@ -219,7 +219,7 @@ void sub_08070D38(Entity* this) { } // minor regalloc -NONMATCH("asm/non_matching/player/sub_08070DC4.s", void sub_08070DC4(Entity* this)) { +NONMATCH("asm/non_matching/player/sub_08070DC4.inc", void sub_08070DC4(Entity* this)) { UpdateAnimationSingleFrame(this); sub_080085B0(this); sub_08079E08(); @@ -673,7 +673,7 @@ void PortalShrinkInit(Entity* this) { } // horrible -ASM_FUNC("asm/non_matching/player/sub_08071634.s", void PortalShrinkUpdate(Entity* this)) +ASM_FUNC("asm/non_matching/player/PortalShrinkUpdate.inc", void PortalShrinkUpdate(Entity* this)) void PortalEnterUpdate(Entity* this) { if (this->actionDelay == 0) { @@ -1712,7 +1712,7 @@ void sub_08072CFC(Entity* this) { extern const u16* gUnk_0811BBD4[]; -NONMATCH("asm/non_matching/player/sub_08072D54.s", void sub_08072D54(Entity* this)) { +NONMATCH("asm/non_matching/player/sub_08072D54.inc", void sub_08072D54(Entity* this)) { u32 bVar1; u32 uVar2; u32 iVar3; diff --git a/src/room.c b/src/room.c index 682a6935..c2b1f07b 100644 --- a/src/room.c +++ b/src/room.c @@ -981,10 +981,7 @@ void sub_0804BF38(u32 arg0, struct_0804BF38* arg1) SoundReq(gUnk_080D8E50[iVar2].sfx); } #else -NAKED -void sub_0804BF38(Entity* this, ScriptExecutionContext* context) { - asm(".include \"asm/non_matching/sub_0804BF38.inc\""); -} +ASM_FUNC("asm/non_matching/sub_0804BF38.inc", void sub_0804BF38(Entity* this, ScriptExecutionContext* context)) #endif u32 sub_0804C00C() { @@ -1041,20 +1038,11 @@ void sub_0804C108(void) { sub_0804C128(gArea.filler[7] |= 1); } -NAKED -void sub_0804C128(u32 arg0) { - asm(".include \"asm/non_matching/sub_0804C128.inc\""); -} +ASM_FUNC("asm/non_matching/sub_0804C128.inc", void sub_0804C128(u32 arg0)) -NAKED -void sub_0804C258(void) { - asm(".include \"asm/non_matching/sub_0804C258.inc\""); -} +ASM_FUNC("asm/non_matching/sub_0804C258.inc", void sub_0804C258(void)) -NAKED -void sub_0804C290(void) { - asm(".include \"asm/non_matching/sub_0804C290.inc\""); -} +ASM_FUNC("asm/non_matching/sub_0804C290.inc", void sub_0804C290(void)) u32 sub_0804C2BC() { return 1; @@ -4203,10 +4191,7 @@ u32 sub_0804DDF8() { void nullsub_374() { } -NAKED -u32 sub_0804DE00(void) { - asm(".include \"asm/non_matching/sub_0804DE00.inc\""); -} +ASM_FUNC("asm/non_matching/sub_0804DE00.inc", u32 sub_0804DE00(void)) extern EntityData gUnk_080EEB6C; extern EntityData gUnk_080EEB8C; @@ -4313,10 +4298,7 @@ void sub_0804E130(void) { } } -NAKED -void sub_0804E150(void) { - asm(".include \"asm/non_matching/sub_0804E150.inc\""); -} +ASM_FUNC("asm/non_matching/sub_0804E150.inc", void sub_0804E150(void)) u32 sub_0804E1F4() { return 1; diff --git a/src/textbox.c b/src/textbox.c index 54ec12f8..abbdc744 100644 --- a/src/textbox.c +++ b/src/textbox.c @@ -682,10 +682,8 @@ void CreateWindow(void) { sub_0801C494(); } -NONMATCH("asm/non_matching/textbox/DispMessageFrame.inc", - void DispMessageFrame(u16* buffer, u32 width_, u32 height_, u32 flags_)) { -} -END_NONMATCH +ASM_FUNC("asm/non_matching/textbox/DispMessageFrame.inc", + void DispMessageFrame(u16* buffer, u32 width_, u32 height_, u32 flags_)) extern u16 gUnk_02034CB2[]; extern u16 gUnk_0202281E[]; From 7069bd4aab8ae6a657b556dae5b5fe336935a8c3 Mon Sep 17 00:00:00 2001 From: octorock <79596758+octorock@users.noreply.github.com> Date: Sun, 16 May 2021 00:24:20 +0200 Subject: [PATCH 3/3] Always don't count ASM_FUNC functions --- progress.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/progress.py b/progress.py index f0288333..a0834d16 100644 --- a/progress.py +++ b/progress.py @@ -1,17 +1,18 @@ import argparse import git import os - +import re def collect_non_matching_funcs(): result = [] - for r, d, f in os.walk('asm/non_matching'): - for file in f: - if file.endswith('.inc'): - # Assume that the filename is the function name - result.append(file[0:-4]) - else: - print(r,file) + for root, dirs, files in os.walk('src'): + for file in files: + if file.endswith('.c'): + with open(os.path.join(root, file), 'r') as f: + data = f.read() + # Find all NONMATCH and ASM_FUNC macros + for match in re.findall(r'(NONMATCH|ASM_FUNC)\(".*",\W*\w*\W*(\w*).*\)', data): + result.append(match) return result @@ -85,8 +86,15 @@ def main(): matching = args.matching non_matching_funcs = [] + funcs = collect_non_matching_funcs() if matching: - non_matching_funcs = collect_non_matching_funcs() + # Remove all non matching funcs from count + non_matching_funcs = [x[1] for x in funcs] + else: + # Only remove ASM_FUNC functions from count + for func in funcs: + if func[0] == 'ASM_FUNC': + non_matching_funcs.append(func[1]) (src, asm, src_data, data) = parse_map(non_matching_funcs)