From 466a31fe4ea4267caf0cb212e937a3e05fa83bc2 Mon Sep 17 00:00:00 2001 From: Mark Street Date: Thu, 24 Dec 2020 23:39:47 +0000 Subject: [PATCH 01/16] Matching code_39cb0_len_100.c --- Makefile | 2 +- .../os/code_39cb0_len_100/boot_idle.s | 47 ------------------- .../os/code_39cb0_len_100/nuBoot.s | 27 ----------- include/functions.h | 5 ++ include/variables.h | 5 ++ src/os/code_39cb0_len_100.c | 32 ++++++++++++- undefined_funcs.txt | 1 + undefined_syms.txt | 4 ++ undefined_syms_auto.txt | 4 -- 9 files changed, 46 insertions(+), 81 deletions(-) delete mode 100644 asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s delete mode 100644 asm/nonmatchings/os/code_39cb0_len_100/nuBoot.s diff --git a/Makefile b/Makefile index af2187bd6f..37f9dc42db 100644 --- a/Makefile +++ b/Makefile @@ -80,7 +80,7 @@ CC=tools/$(OS)/cc1 ### Compiler Options ### -CPPFLAGS := -Iinclude -Isrc -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 -Wundef -Wcomment +CPPFLAGS := -Iinclude -Isrc -D _LANGUAGE_C -D _FINALROM -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 -Wundef -Wcomment ASFLAGS := -EB -Iinclude -march=vr4300 -mtune=vr4300 OLDASFLAGS := -EB -Iinclude -G 0 CFLAGS := -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32 -Wimplicit -Wuninitialized -Wshadow diff --git a/asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s b/asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s deleted file mode 100644 index 1545a44358..0000000000 --- a/asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s +++ /dev/null @@ -1,47 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel boot_idle -/* 39D0C 8005E90C 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 39D10 8005E910 AFBF001C */ sw $ra, 0x1c($sp) -/* 39D14 8005E914 AFB00018 */ sw $s0, 0x18($sp) -/* 39D18 8005E918 3C01800A */ lui $at, %hi(D_8009A630) -/* 39D1C 8005E91C 0C017D14 */ jal nuPiInit -/* 39D20 8005E920 AC20A630 */ sw $zero, %lo(D_8009A630)($at) -/* 39D24 8005E924 24040002 */ addiu $a0, $zero, 2 -/* 39D28 8005E928 0C017A6C */ jal nuScCreateScheduler -/* 39D2C 8005E92C 24050001 */ addiu $a1, $zero, 1 -/* 39D30 8005E930 0C019B98 */ jal osViSetSpecialFeatures -/* 39D34 8005E934 2404005A */ addiu $a0, $zero, 0x5a -/* 39D38 8005E938 3C10800A */ lui $s0, %hi(D_800A4420) -/* 39D3C 8005E93C 26104420 */ addiu $s0, $s0, %lo(D_800A4420) -/* 39D40 8005E940 0200202D */ daddu $a0, $s0, $zero -/* 39D44 8005E944 24050003 */ addiu $a1, $zero, 3 -/* 39D48 8005E948 3C02800C */ lui $v0, %hi(D_800B8590) -/* 39D4C 8005E94C 24428590 */ addiu $v0, $v0, %lo(D_800B8590) -/* 39D50 8005E950 AFA20010 */ sw $v0, 0x10($sp) -/* 39D54 8005E954 2402000A */ addiu $v0, $zero, 0xa -/* 39D58 8005E958 3C068002 */ lui $a2, %hi(boot_main) -/* 39D5C 8005E95C 24C65F70 */ addiu $a2, $a2, %lo(boot_main) -/* 39D60 8005E960 0000382D */ daddu $a3, $zero, $zero -/* 39D64 8005E964 0C019798 */ jal osCreateThread -/* 39D68 8005E968 AFA20014 */ sw $v0, 0x14($sp) -/* 39D6C 8005E96C 0C019808 */ jal osStartThread -/* 39D70 8005E970 0200202D */ daddu $a0, $s0, $zero -/* 39D74 8005E974 3C04800A */ lui $a0, %hi(D_800A4270) -/* 39D78 8005E978 24844270 */ addiu $a0, $a0, %lo(D_800A4270) -/* 39D7C 8005E97C 0C0197D4 */ jal osSetThreadPri -/* 39D80 8005E980 0000282D */ daddu $a1, $zero, $zero -.L8005E984: -/* 39D84 8005E984 3C02800A */ lui $v0, %hi(D_8009A630) -/* 39D88 8005E988 8C42A630 */ lw $v0, %lo(D_8009A630)($v0) -.L8005E98C: -/* 39D8C 8005E98C 1040FFFF */ beqz $v0, .L8005E98C -/* 39D90 8005E990 00000000 */ nop -/* 39D94 8005E994 0040F809 */ jalr $v0 -/* 39D98 8005E998 00000000 */ nop -/* 39D9C 8005E99C 08017A61 */ j .L8005E984 -/* 39DA0 8005E9A0 00000000 */ nop -/* 39DA4 8005E9A4 00000000 */ nop -/* 39DA8 8005E9A8 00000000 */ nop -/* 39DAC 8005E9AC 00000000 */ nop diff --git a/asm/nonmatchings/os/code_39cb0_len_100/nuBoot.s b/asm/nonmatchings/os/code_39cb0_len_100/nuBoot.s deleted file mode 100644 index 311c616db4..0000000000 --- a/asm/nonmatchings/os/code_39cb0_len_100/nuBoot.s +++ /dev/null @@ -1,27 +0,0 @@ -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches - -glabel nuBoot -/* 39CB0 8005E8B0 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 39CB4 8005E8B4 AFBF001C */ sw $ra, 0x1c($sp) -/* 39CB8 8005E8B8 0C01A9C2 */ jal osInitialize -/* 39CBC 8005E8BC AFB00018 */ sw $s0, 0x18($sp) -/* 39CC0 8005E8C0 3C10800A */ lui $s0, %hi(D_800A4270) -/* 39CC4 8005E8C4 26104270 */ addiu $s0, $s0, %lo(D_800A4270) -/* 39CC8 8005E8C8 0200202D */ daddu $a0, $s0, $zero -/* 39CCC 8005E8CC 3C02800A */ lui $v0, %hi(nuScStack) -/* 39CD0 8005E8D0 244265D0 */ addiu $v0, $v0, %lo(nuScStack) -/* 39CD4 8005E8D4 AFA20010 */ sw $v0, 0x10($sp) -/* 39CD8 8005E8D8 2402000A */ addiu $v0, $zero, 0xa -/* 39CDC 8005E8DC 24050001 */ addiu $a1, $zero, 1 -/* 39CE0 8005E8E0 3C068006 */ lui $a2, %hi(boot_idle) -/* 39CE4 8005E8E4 24C6E90C */ addiu $a2, $a2, %lo(boot_idle) -/* 39CE8 8005E8E8 0000382D */ daddu $a3, $zero, $zero -/* 39CEC 8005E8EC 0C019798 */ jal osCreateThread -/* 39CF0 8005E8F0 AFA20014 */ sw $v0, 0x14($sp) -/* 39CF4 8005E8F4 0C019808 */ jal osStartThread -/* 39CF8 8005E8F8 0200202D */ daddu $a0, $s0, $zero -/* 39CFC 8005E8FC 8FBF001C */ lw $ra, 0x1c($sp) -/* 39D00 8005E900 8FB00018 */ lw $s0, 0x18($sp) -/* 39D04 8005E904 03E00008 */ jr $ra -/* 39D08 8005E908 27BD0020 */ addiu $sp, $sp, 0x20 diff --git a/include/functions.h b/include/functions.h index 2921bf6ff7..9179f519d3 100644 --- a/include/functions.h +++ b/include/functions.h @@ -5,6 +5,11 @@ #include "common_structs.h" #include "enums.h" + +void nuBoot(void); +void boot_idle(void); +void boot_main(void); + void osCleanupThread(void); s32 heap_malloc(s32 size); diff --git a/include/variables.h b/include/variables.h index 031cf2b4d2..762a4acb3f 100644 --- a/include/variables.h +++ b/include/variables.h @@ -246,4 +246,9 @@ extern s16 gMusicTargetVolume; extern MusicPlayer gMusicPlayers[4]; extern MusicPlayer D_8014F6F0; +// OS +extern OSThread D_800A4270; // idle thread, id 1 +extern OSThread D_800A4420; // id 3 +extern s32 D_800B8590; + #endif diff --git a/src/os/code_39cb0_len_100.c b/src/os/code_39cb0_len_100.c index 32a49c67c6..ab1d0caa66 100644 --- a/src/os/code_39cb0_len_100.c +++ b/src/os/code_39cb0_len_100.c @@ -1,5 +1,33 @@ #include "common.h" +#include "nu/nusys.h" +#include "functions.h" +#include "variables.h" -INCLUDE_ASM(s32, "os/code_39cb0_len_100", nuBoot); -INCLUDE_ASM(s32, "os/code_39cb0_len_100", boot_idle); +// TODO: create src/os/nusys/nuSched.h? +extern u64 nuScStack[NU_SC_STACK_SIZE / sizeof(u64)]; + +void (*D_8009A630)(void) = NULL; + +void nuBoot(void) { + osInitialize(); // __osInitialize_common + osCreateThread(&D_800A4270, 1, (void*) &boot_idle, 0, &nuScStack, 10); + osStartThread(&D_800A4270); +} + +void boot_idle(void) { + void (*temp_v0)(void); + + D_8009A630 = NULL; + + nuPiInit(); + nuScCreateScheduler(2, 1); + osViSetSpecialFeatures(0x5A); + osCreateThread(&D_800A4420, 3, (void*) &boot_main, 0, &D_800B8590, 10); + osStartThread(&D_800A4420); + osSetThreadPri(&D_800A4270, OS_PRIORITY_IDLE); + do { + do { /* nothing */ } while ((temp_v0 = D_8009A630) == NULL); + temp_v0(); + } while (1); +} diff --git a/undefined_funcs.txt b/undefined_funcs.txt index c8189fe23e..53e88de141 100644 --- a/undefined_funcs.txt +++ b/undefined_funcs.txt @@ -61,3 +61,4 @@ func_802AA0D8 = 0x802AA0D8; func_802AB330 = 0x802AB330; func_802AB338 = 0x802AB338; func_802B71E8 = 0x802B71E8; +__osInitialize_common = 0x8006A708; diff --git a/undefined_syms.txt b/undefined_syms.txt index 6545cca669..856bba9e04 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -43,6 +43,10 @@ D_800A0960 = 0x800A0960; D_800A0963 = 0x800A0963; D_800A0964 = 0x800A0964; +D_800A4270 = 0x800A4270; +D_800A4420 = 0x800A4420; +D_800B8590 = 0x800B8590; + D_800E92D8 = 0x800E92D8; gPartnerAnimations = 0x800F8348; diff --git a/undefined_syms_auto.txt b/undefined_syms_auto.txt index 1472a9edd3..15dd081b4d 100644 --- a/undefined_syms_auto.txt +++ b/undefined_syms_auto.txt @@ -570,7 +570,6 @@ D_8009A61C = 0x8009A61C; D_8009A620 = 0x8009A620; D_8009A628 = 0x8009A628; D_8009A62C = 0x8009A62C; -D_8009A630 = 0x8009A630; D_8009A634 = 0x8009A634; D_8009A63C = 0x8009A63C; D_8009A640 = 0x8009A640; @@ -678,8 +677,6 @@ D_800A425C = 0x800A425C; D_800A4260 = 0x800A4260; D_800A4264 = 0x800A4264; D_800A4268 = 0x800A4268; -D_800A4270 = 0x800A4270; -D_800A4420 = 0x800A4420; D_800AC6B0 = 0x800AC6B0; D_800AE6D0 = 0x800AE6D0; D_800AE6D4 = 0x800AE6D4; @@ -785,7 +782,6 @@ D_800B451E = 0x800B451E; D_800B451F = 0x800B451F; D_800B4520 = 0x800B4520; D_800B6590 = 0x800B6590; -D_800B8590 = 0x800B8590; D_800B91A0 = 0x800B91A0; D_800B91D0 = 0x800B91D0; D_800D91D0 = 0x800D91D0; From efee13f6866212d3eb1784fe986c8bf4575344fa Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Sun, 27 Dec 2020 17:11:33 +0000 Subject: [PATCH 02/16] add data disassembly tool --- tools/compile_dsl_macros.py | 12 +- tools/disasm_map.py | 232 ------------------------------------ tools/disasm_script.py | 16 ++- tools/star_rod_idx_to_c.py | 198 ++++++++++++++++++++++++++++++ 4 files changed, 220 insertions(+), 238 deletions(-) delete mode 100755 tools/disasm_map.py create mode 100755 tools/star_rod_idx_to_c.py diff --git a/tools/compile_dsl_macros.py b/tools/compile_dsl_macros.py index 14b7d01aac..f3c757aa61 100755 --- a/tools/compile_dsl_macros.py +++ b/tools/compile_dsl_macros.py @@ -78,6 +78,7 @@ script_parser = Lark(r""" | ">=" -> cond_op_ge | "<=" -> cond_op_le | "?" -> cond_op_flag + | "!?" -> cond_op_not_flag match_stmt: "match" expr "{" (match_cases SEMICOLON*)? "}" match_const_stmt: "matchc" expr "{" (match_cases SEMICOLON*)? "}" @@ -353,7 +354,8 @@ class Compile(Transformer): def cond_op_gt(self, tree): return { "if": "ScriptOpcode_IF_GT", "case": "ScriptOpcode_CASE_GT" } def cond_op_le(self, tree): return { "if": "ScriptOpcode_IF_LE", "case": "ScriptOpcode_CASE_LE" } def cond_op_ge(self, tree): return { "if": "ScriptOpcode_IF_GE", "case": "ScriptOpcode_CASE_GE" } - def cond_op_flag(self, tree): return { "if": "ScriptOpcode_IF_FLAG", "case": "ScriptOpcode_CASE_FLAG" } + def cond_op_flag(self, tree): return { "__op__": "!?", "if": "ScriptOpcode_IF_FLAG", "case": "ScriptOpcode_CASE_FLAG" } + def cond_op_not_flag(self, tree): return { "if": "ScriptOpcode_IF_NOT_FLAG" } def match_stmt(self, tree): expr = tree.children[0] @@ -393,9 +395,17 @@ class Compile(Transformer): def case_op(self, tree): if len(tree.children) == 4: op, expr, multi_case, block = tree.children + + if not "case" in op: + raise CompileError(f"operation `{opcodes['__op__']}' not supported in match cases", tree.meta) + return [Cmd(op["case"], expr), *multi_case, *block, Cmd("ScriptOpcode_END_CASE_MULTI")] else: op, expr, block = tree.children + + if not "case" in op: + raise CompileError(f"operation `{opcodes['__op__']}' not supported in match cases", tree.meta) + return [Cmd(op["case"], expr), *block] def case_range(self, tree): if len(tree.children) == 4: diff --git a/tools/disasm_map.py b/tools/disasm_map.py deleted file mode 100755 index d0ffe9b910..0000000000 --- a/tools/disasm_map.py +++ /dev/null @@ -1,232 +0,0 @@ -#! /usr/bin/python3 - -import sys -import os -import yaml -import json -from struct import unpack - -import disasm_script - -def disassemble(bytes, offset, midx, symbol_map = {}, map_name = "map"): - out = "" - found_data = False - - while len(midx) > 0: - struct = midx.pop(0) - name = struct["name"] - - if name == "Script_Main": name = f"M(Main)" - - #print(f"{offset:X} ({name}, start = {struct['start']:X}, len = {struct['length']:X})") - - if struct["start"] == offset: - found_data = True - - if struct["start"] != offset: - # end of data / padding - break - - # format struct - if struct["type"].startswith("Script"): - pos = bytes.tell() - try: - out += disasm_script.ScriptDSLDisassembler(bytes, f"M({name})", symbol_map).disassemble() - except disasm_script.UnsupportedScript as e: - print(f"Unable to use DSL for {struct['name']}: {e}") - - bytes.seek(pos) - out += disasm_script.ScriptDisassembler(bytes, f"M({name})", symbol_map).disassemble() - elif struct["type"] == "Padding": - # nops at end of file - bytes.seek(offset % 4, 1) - return out - elif struct["type"] == "EntryList": - out += f"EntryList M(entryList) = {{" - for i in range(0, struct["length"], 4 * 4): - x,y,z,yaw = unpack(">ffff", bytes.read(4 * 4)) - out += f"\n {{ {x}f, {y}f, {z}f, {yaw}f }}," - out += f"\n}};\n" - elif struct["type"] == "Header": - out += f"MapConfig M(config) = {{\n" - - bytes.read(0x10) - - main,entry_list,entry_count = unpack(">IIi", bytes.read(4 * 3)) - out += f" .main = M(Main),\n" - out += f" .entryList = M(entryList),\n" - out += f" .entryCount = ENTRY_COUNT(M(entryList)),\n" - - bytes.read(0x1C) - - bg,tattle = unpack(">II", bytes.read(4 * 2)) - if bg == 0x80200000: - out += f" .background = &gBackgroundImage,\n" - elif bg != 0: - raise Exception(f"unknown MapConfig background {bg:X}") - out += f" .tattle = 0x{tattle:X},\n" - - out += f"}};\n" - elif struct["type"] == "ASCII": - string_data = bytes.read(struct["length"]).decode("ascii") - - # strip null terminator(s) - while string_data[-1] == "\0": - string_data = string_data[:-1] - - string_literal = json.dumps(string_data) - out += f"const char M({struct['name']})[] = {string_literal};" - else: # unknown type of struct - out += f"s32 M({name})[] = {{" - for i in range(0, struct["length"], 4): - if (i % 0x20) == 0: - out += f"\n " - - word = int.from_bytes(bytes.read(4), byteorder="big") - - if word in symbol_map: - out += f" {symbol_map[word]}," - else: - out += f" 0x{word:08X}," - - out += f"\n}};\n" - - out += "\n" - elif found_data: - if struct["type"] != "Padding": - # put struct back on list - midx.insert(0, struct) - - # nops at end of file - bytes.seek(offset % 4, 1) - - return out - - if struct["type"] != "Function" and not struct["type"] == "Padding" and not (struct["type"] == "Missing" and not found_data): - offset += struct["length"] - - # end of data - return out - -def parse_midx(file, prefix = ""): - structs = [] - - for line in file.readlines(): - s = line.split("#") - if len(s) == 5: - if s[0] == "$Start": continue - if s[0] == "$End": continue - - structs.append({ - "name": prefix + name_struct(s[0]), - "type": s[1], - "start": int(s[2], 16), - "vaddr": int(s[3], 16), - "length": int(s[4], 16), - "end": int(s[2], 16) + int(s[4], 16), - }) - elif "Missing" in s: - start = int(s[1], 16) - end = int(s[2], 16) - vaddr = start + 0x80240000 - structs.append({ - "name": f"{prefix}unk_missing_{vaddr:X}", - "type": "Missing", - "start": start, - "vaddr": vaddr, - "length": end - start, - "end": end, - }) - elif "Padding" in s: - start = int(s[1], 16) - end = int(s[2], 16) - vaddr = start + 0x80240000 - structs.append({ - "name": f"{prefix}__padding__", - "type": "Padding", - "start": start, - "vaddr": vaddr, - "length": end - start, - "end": end, - }) - - structs.sort(key=lambda s: s["start"]) - return structs - -def name_struct(s): - s = s[1:].replace("???", "unk") - - # use ThisCase for scripts - if s.startswith("Script_"): - s = s[7].upper() + s[8:] - - # if `s` is hex, prefix it with Script_ again - try: - int(s, 16) - return "Script_" + s - except Exception: - pass - - if s.startswith("Main"): - return "Main" - - return s - - if s.startswith("ASCII"): - return s - - return s[0].lower() + s[1:] - -if __name__ == "__main__": - if len(sys.argv) == 1: - print("usage: ./disasm_map.py ") - print("Converts split map data into C files using a .midx file from Star Rod.") - exit() - - map_name = os.path.splitext(os.path.basename(sys.argv[1]))[0] - area_name = "area_" + map_name.split("_")[0] - if len(area_name) > 8: - area_name = area_name[:8] - - with open(sys.argv[1], "r") as f: - midx = parse_midx(f) - - symbol_map = {} - for struct in midx: - symbol_map[struct["vaddr"]] = "M(" + struct["name"] + ")" - - bin_dir = f"bin/world/{area_name}/{map_name}" - src_dir = f"src/world/{area_name}/{map_name}" - - splits = [] - rom_start = 0 - with open(os.path.join(os.path.dirname(__file__), "splat.yaml")) as splat: - splat = yaml.safe_load(splat) - - for segment in splat["segments"]: - if type(segment) == dict and segment.get("name") == f"world/{area_name}/{map_name}/": - rom_start = segment.get("start", 0) - splits = segment.get("files", []) - continue - if len(splits) == 0: - print(f"unable to find {map_name} in splat.yaml") - exit(1) - - # advance to the EntryList (start of data) - while midx[0]["type"] != "EntryList": - midx.pop(0) - - for split in splits: - rom_addr = split[0] - filetype = split[1] - - if filetype == "bin": - with open(f"{bin_dir}/{rom_addr:X}.bin", "rb") as bytes: - print(f"Disassembling {rom_addr:X}") - - disasm = disassemble(bytes, rom_addr - rom_start, midx, symbol_map, map_name) - - if len(disasm.strip()) > 0: - with open(f"{src_dir}/{rom_addr:X}.bin.c", "w") as f: - f.write(f'#include "{map_name}.h"\n\n') - f.write(disasm.rstrip() + "\n") diff --git a/tools/disasm_script.py b/tools/disasm_script.py index 9c571b931c..840c674b28 100755 --- a/tools/disasm_script.py +++ b/tools/disasm_script.py @@ -433,11 +433,11 @@ class ScriptDSLDisassembler(ScriptDisassembler): self.write_line("}") if opcode == 0x01: - if self.out.endswith("return\n"): + if self.out.endswith("return;\n"): # implicit return; break - self.out = self.out[:-7].rstrip() + "\n" + self.out = self.out[:-8].rstrip() + "\n" else: - self.write_line("break") + self.write_line("break;") self.indent -= 1 @@ -446,7 +446,10 @@ class ScriptDSLDisassembler(ScriptDisassembler): self.done = True elif opcode == 0x02: self.write_line(f"return;") - elif opcode == 0x03: self.write_line(f"{self.var(argv[0])}:") + elif opcode == 0x03: + self.indent -= 1 + self.write_line(f"{self.var(argv[0])}:") + self.indent += 1 elif opcode == 0x04: self.write_line(f"goto {self.var(argv[0])};") elif opcode == 0x05: if argv[0] == 0: @@ -481,6 +484,9 @@ class ScriptDSLDisassembler(ScriptDisassembler): elif opcode == 0x10: self.write_line(f"if ({self.var(argv[0])} ? {self.var(argv[1])}) {{") self.indent += 1 + elif opcode == 0x11: + self.write_line(f"if ({self.var(argv[0])} !? {self.var(argv[1])}) {{") + self.indent += 1 elif opcode == 0x12: self.indent -= 1 self.write_line("} else {") @@ -595,7 +601,7 @@ class ScriptDSLDisassembler(ScriptDisassembler): elif opcode == 0x42: self.write_line(f"{self.var(argv[0])} |=c {argv[1]:X};") elif opcode == 0x43: argv_str = ", ".join(self.var(arg) for arg in argv[1:]) - self.write_line(f"{self.addr_ref(argv[0])}({argv_str})") + self.write_line(f"{self.addr_ref(argv[0])}({argv_str});") elif opcode == 0x44: self.write_line(f"spawn {self.addr_ref(argv[0])};") elif opcode == 0x45: self.write_line(f"{self.var(argv[1])} = spawn {self.addr_ref(argv[0])};") elif opcode == 0x46: self.write_line(f"await {self.addr_ref(argv[0])};") diff --git a/tools/star_rod_idx_to_c.py b/tools/star_rod_idx_to_c.py new file mode 100755 index 0000000000..c6901bea14 --- /dev/null +++ b/tools/star_rod_idx_to_c.py @@ -0,0 +1,198 @@ +#! /usr/bin/python3 + +import sys +import os +import yaml +import json +from struct import unpack +import argparse + +import disasm_script + +DIR = os.path.dirname(__file__) + +def disassemble(bytes, midx, symbol_map={}, comments=True): + out = "" + + entry_list_name = None + main_script_name = None + + while len(midx) > 0: + struct = midx.pop(0) + name = struct["name"] + + if comments: + out += f"// {struct['start']:X}-{struct['end']:X} (VRAM: {struct['vaddr']:X})\n" + + # format struct + if struct["type"].startswith("Script"): + if struct["type"] == "Script_Main": + main_script_name = name + + pos = bytes.tell() + try: + out += disasm_script.ScriptDSLDisassembler(bytes, name, symbol_map).disassemble() + except disasm_script.UnsupportedScript as e: + out += f"// Unable to use DSL: {e}\n" + + bytes.seek(pos) + out += disasm_script.ScriptDisassembler(bytes, name, symbol_map).disassemble() + elif struct["type"] == "EntryList": + entry_list_name = name + out += f"EntryList {name} = {{" + for i in range(0, struct["length"], 4 * 4): + x,y,z,yaw = unpack(">ffff", bytes.read(4 * 4)) + out += f"\n {{ {x}f, {y}f, {z}f, {yaw}f }}," + out += f"\n}};\n" + elif struct["type"] == "Header": + out += f"MapConfig {name} = {{\n" + + bytes.read(0x10) + + main,entry_list,entry_count = unpack(">IIi", bytes.read(4 * 3)) + out += f" .main = {main_script_name},\n" + out += f" .entryList = {entry_list_name},\n" + out += f" .entryCount = ENTRY_COUNT({entry_list_name}),\n" + + bytes.read(0x1C) + + bg,tattle = unpack(">II", bytes.read(4 * 2)) + if bg == 0x80200000: + out += f" .background = &gBackgroundImage,\n" + elif bg != 0: + raise Exception(f"unknown MapConfig background {bg:X}") + out += f" .tattle = 0x{tattle:X},\n" + + out += f"}};\n" + elif struct["type"] == "ASCII": + string_data = bytes.read(struct["length"]).decode("ascii") + + # strip null terminator(s) + while string_data[-1] == "\0": + string_data = string_data[:-1] + + string_literal = json.dumps(string_data) + out += f"const char {struct['name']}[] = {string_literal};\n" + elif struct["type"].startswith("Function"): + bytes.read(struct["length"]) + out += f"// function: {name}\n" + elif struct["type"] == "FloatTable": + out += f"f32 {name}[] = {{" + for i in range(0, struct["length"], 4): + if (i % 0x20) == 0: + out += f"\n " + + word = unpack(">f", bytes.read(4))[0] + out += " %ff," % word + + out += f"\n}};\n" + else: # unknown type of struct + out += f"s32 {name}[] = {{" + for i in range(0, struct["length"], 4): + if (i % 0x20) == 0: + out += f"\n " + + word = int.from_bytes(bytes.read(4), byteorder="big") + + if word in symbol_map: + out += f" {symbol_map[word]}," + else: + out += f" 0x{word:08X}," + + out += f"\n}};\n" + + out += "\n" + + # end of data + return out + +def parse_midx(file, prefix = ""): + structs = [] + + for line in file.readlines(): + s = line.split("#") + if len(s) == 5: + if s[0] == "$Start": continue + if s[0] == "$End": continue + + structs.append({ + "name": prefix + name_struct(s[0]), + "type": s[1], + "start": int(s[2], 16), + "vaddr": int(s[3], 16), + "length": int(s[4], 16), + "end": int(s[2], 16) + int(s[4], 16), + }) + elif "Missing" in s: + start = int(s[1], 16) + end = int(s[2], 16) + vaddr = start + 0x80240000 + structs.append({ + "name": f"{prefix}unk_missing_{vaddr:X}", + "type": "Missing", + "start": start, + "vaddr": vaddr, + "length": end - start, + "end": end, + }) + elif "Padding" in s: + start = int(s[1], 16) + end = int(s[2], 16) + vaddr = start + 0x80240000 + structs.append({ + "name": f"{prefix}pad_{start:X}", + "type": "Padding", + "start": start, + "vaddr": vaddr, + "length": end - start, + "end": end, + }) + + structs.sort(key=lambda s: s["start"]) + return structs + +def name_struct(s): + s = s[1:].replace("???", "unk") + + """ + # use ThisCase for scripts + if s.startswith("Script_"): + s = s[7].upper() + s[8:] + + # if `s` is hex, prefix it with Script_ again + try: + int(s, 16) + return "Script_" + s + except Exception: + pass + + if s.startswith("Main"): + return "Main" + + return s + """ + + if s.startswith("ASCII"): + return s + + return s[0].lower() + s[1:] + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Converts split data to C using a Star Rod idx file") + parser.add_argument("idxfile", help="Input .*idx file from Star Rod dump") + parser.add_argument("offset", help="Starting ROM offset") + parser.add_argument("--comments", action="store_true", help="Write offset/vaddr comments") + + args = parser.parse_args() + + with open(args.idxfile, "r") as f: + midx = parse_midx(f) + + symbol_map = {} + for struct in midx: + symbol_map[struct["vaddr"]] = struct["name"] + + with open(os.path.join(DIR, "../baserom.z64"), "rb") as romfile: + romfile.seek(eval(args.offset)) + disasm = disassemble(romfile, midx, symbol_map, args.comments) + print(disasm.rstrip()) From 8f9afce5e9b74e512281523e9f71f06e578d3ff9 Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Mon, 28 Dec 2020 09:36:17 +0900 Subject: [PATCH 03/16] Adding defines --- src/os/code_39cb0_len_100.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/os/code_39cb0_len_100.c b/src/os/code_39cb0_len_100.c index ab1d0caa66..6ba52210e6 100644 --- a/src/os/code_39cb0_len_100.c +++ b/src/os/code_39cb0_len_100.c @@ -3,7 +3,6 @@ #include "functions.h" #include "variables.h" - // TODO: create src/os/nusys/nuSched.h? extern u64 nuScStack[NU_SC_STACK_SIZE / sizeof(u64)]; @@ -11,23 +10,27 @@ void (*D_8009A630)(void) = NULL; void nuBoot(void) { osInitialize(); // __osInitialize_common - osCreateThread(&D_800A4270, 1, (void*) &boot_idle, 0, &nuScStack, 10); + osCreateThread(&D_800A4270, NU_IDLE_THREAD_ID, boot_idle, NULL, &nuScStack, 10); osStartThread(&D_800A4270); } void boot_idle(void) { - void (*temp_v0)(void); - D_8009A630 = NULL; nuPiInit(); - nuScCreateScheduler(2, 1); - osViSetSpecialFeatures(0x5A); - osCreateThread(&D_800A4420, 3, (void*) &boot_main, 0, &D_800B8590, 10); + nuScCreateScheduler(OS_VI_NTSC_LAN1, 1); + osViSetSpecialFeatures(OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | OS_VI_DITHER_FILTER_ON); + osCreateThread(&D_800A4420, NU_MAIN_THREAD_ID, boot_main, NULL, &D_800B8590, 10); osStartThread(&D_800A4420); osSetThreadPri(&D_800A4270, OS_PRIORITY_IDLE); + do { - do { /* nothing */ } while ((temp_v0 = D_8009A630) == NULL); - temp_v0(); + void (*func)(void); + + do { + func = D_8009A630; + } while (func == NULL); + + func(); } while (1); } From a1957b7f0ffeaef7f3da0490442db336b875a47a Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Mon, 28 Dec 2020 10:19:34 +0900 Subject: [PATCH 04/16] Further define improvements, NON_MATCHING --- .../os/code_39cb0_len_100/boot_idle.s | 47 +++++++++++++++++++ src/os/code_39cb0_len_100.c | 26 +++++----- undefined_syms.txt | 1 + 3 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s diff --git a/asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s b/asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s new file mode 100644 index 0000000000..531b2d3fa9 --- /dev/null +++ b/asm/nonmatchings/os/code_39cb0_len_100/boot_idle.s @@ -0,0 +1,47 @@ +.set noat # allow manual use of $at +.set noreorder # don't insert nops after branches + +glabel boot_idle +/* 39D0C 8005E90C 27BDFFE0 */ addiu $sp, $sp, -0x20 +/* 39D10 8005E910 AFBF001C */ sw $ra, 0x1c($sp) +/* 39D14 8005E914 AFB00018 */ sw $s0, 0x18($sp) +/* 39D18 8005E918 3C01800A */ lui $at, %hi(D_8009A630) +/* 39D1C 8005E91C 0C017D14 */ jal nuPiInit +/* 39D20 8005E920 AC20A630 */ sw $zero, %lo(D_8009A630)($at) +/* 39D24 8005E924 24040002 */ addiu $a0, $zero, 2 +/* 39D28 8005E928 0C017A6C */ jal nuScCreateScheduler +/* 39D2C 8005E92C 24050001 */ addiu $a1, $zero, 1 +/* 39D30 8005E930 0C019B98 */ jal osViSetSpecialFeatures +/* 39D34 8005E934 2404005A */ addiu $a0, $zero, 0x5a +/* 39D38 8005E938 3C10800A */ lui $s0, %hi(D_800A4420) +/* 39D3C 8005E93C 26104420 */ addiu $s0, $s0, %lo(D_800A4420) +/* 39D40 8005E940 0200202D */ daddu $a0, $s0, $zero +/* 39D44 8005E944 24050003 */ addiu $a1, $zero, 3 +/* 39D48 8005E948 3C02800C */ lui $v0, %hi(D_800B8590) +/* 39D4C 8005E94C 24428590 */ addiu $v0, $v0, %lo(D_800B8590) +/* 39D50 8005E950 AFA20010 */ sw $v0, 0x10($sp) +/* 39D54 8005E954 2402000A */ addiu $v0, $zero, 0xa +/* 39D58 8005E958 3C068002 */ lui $a2, %hi(boot_main) +/* 39D5C 8005E95C 24C65F70 */ addiu $a2, $a2, %lo(boot_main) +/* 39D60 8005E960 0000382D */ daddu $a3, $zero, $zero +/* 39D64 8005E964 0C019798 */ jal osCreateThread +/* 39D68 8005E968 AFA20014 */ sw $v0, 0x14($sp) +/* 39D6C 8005E96C 0C019808 */ jal osStartThread +/* 39D70 8005E970 0200202D */ daddu $a0, $s0, $zero +/* 39D74 8005E974 3C04800A */ lui $a0, %hi(D_800A4270) +/* 39D78 8005E978 24844270 */ addiu $a0, $a0, %lo(D_800A4270) +/* 39D7C 8005E97C 0C0197D4 */ jal osSetThreadPri +/* 39D80 8005E980 0000282D */ daddu $a1, $zero, $zero +.L8005E984: +/* 39D84 8005E984 3C02800A */ lui $v0, %hi(D_8009A630) +/* 39D88 8005E988 8C42A630 */ lw $v0, %lo(D_8009A630)($v0) +.L8005E98C: +/* 39D8C 8005E98C 1040FFFF */ beqz $v0, .L8005E98C +/* 39D90 8005E990 00000000 */ nop +/* 39D94 8005E994 0040F809 */ jalr $v0 +/* 39D98 8005E998 00000000 */ nop +/* 39D9C 8005E99C 08017A61 */ j .L8005E984 +/* 39DA0 8005E9A0 00000000 */ nop +/* 39DA4 8005E9A4 00000000 */ nop +/* 39DA8 8005E9A8 00000000 */ nop +/* 39DAC 8005E9AC 00000000 */ nop diff --git a/src/os/code_39cb0_len_100.c b/src/os/code_39cb0_len_100.c index 6ba52210e6..f14ff4d712 100644 --- a/src/os/code_39cb0_len_100.c +++ b/src/os/code_39cb0_len_100.c @@ -6,7 +6,7 @@ // TODO: create src/os/nusys/nuSched.h? extern u64 nuScStack[NU_SC_STACK_SIZE / sizeof(u64)]; -void (*D_8009A630)(void) = NULL; +//void (*nuIdleFunc)(void) = NULL; void nuBoot(void) { osInitialize(); // __osInitialize_common @@ -14,23 +14,23 @@ void nuBoot(void) { osStartThread(&D_800A4270); } +#ifdef NON_MATCHING void boot_idle(void) { - D_8009A630 = NULL; + nuIdleFunc = NULL; nuPiInit(); nuScCreateScheduler(OS_VI_NTSC_LAN1, 1); osViSetSpecialFeatures(OS_VI_GAMMA_OFF | OS_VI_GAMMA_DITHER_OFF | OS_VI_DIVOT_ON | OS_VI_DITHER_FILTER_ON); - osCreateThread(&D_800A4420, NU_MAIN_THREAD_ID, boot_main, NULL, &D_800B8590, 10); + osCreateThread(&D_800A4420, NU_MAIN_THREAD_ID, boot_main, NULL, &D_800B8590, NU_MAIN_THREAD_PRI); osStartThread(&D_800A4420); - osSetThreadPri(&D_800A4270, OS_PRIORITY_IDLE); + osSetThreadPri(&D_800A4270, NU_IDLE_THREAD_PRI); - do { - void (*func)(void); - - do { - func = D_8009A630; - } while (func == NULL); - - func(); - } while (1); + while (1) { + if (nuIdleFunc != NULL) { + nuIdleFunc(); + } + } } +#else +INCLUDE_ASM(void, "os/code_39cb0_len_100", boot_idle, void); +#endif diff --git a/undefined_syms.txt b/undefined_syms.txt index 856bba9e04..b43ebf203c 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -114,6 +114,7 @@ nuGfxZBuffer = 0x8009A5DC; nuGfxDisplay = 0x8009A5F8; gGameState = 0x8009A600; D_8009A610 = 0x8009A610; +D_8009A630 = 0x8009A630; nuGfxTaskSpool = 0x8009A618; carthandle = 0x8009A638; From 8c177ca0aeae85b49c76dcd3527da4b43a13df7d Mon Sep 17 00:00:00 2001 From: Mark Street Date: Mon, 28 Dec 2020 12:26:41 +0000 Subject: [PATCH 05/16] Dockerfile with install.sh script --- Dockerfile | 6 +++++- README.md | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f787524548..f6a908cfc2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,11 @@ FROM ubuntu:20.04 as build ENV DEBIAN_FRONTEND=noninteractive -RUN sudo ./install.sh +COPY requirements.txt / +COPY requirements_extra.txt / +COPY install.sh / + +RUN apt-get update && apt-get install -y sudo && ./install.sh --extra RUN mkdir /papermario WORKDIR /papermario diff --git a/README.md b/README.md index 03882ee791..d599574a5f 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,16 @@ $ ./install.sh Our install script does not yet support distros other than Ubuntu, Arch, and their derivatives. Please consider contributing to the script if you use another distro! +##### Docker + +A Docker image containing all dependencies can be built and ran as follows: +```sh +# build image +$ docker build . -t pm +# spin up container, mounting current directory inside +$ docker run --rm -ti -v $(pwd):/papermario pm +``` + #### Base ROM You'll need a Paper Mario (USA) ROM to work on this project. Copy it into the root directory of the repository with the name `baserom.z64`. From 724a15c99d71a336be6ecda02f4b9737f96495ba Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 02:17:34 +0000 Subject: [PATCH 06/16] i did it --- include/common_structs.h | 27 +- src/battle/actor/goomba.c | 443 +++++++++++++++++++++++++++ src/battle/actor/goomba.h | 5 +- src/battle/area_kmr_part_1/battles.c | 30 +- src/battle/battle.h | 34 +- src/code_190B20.c | 6 +- src/code_197F40.c | 1 + src/code_1A5830.c | 1 + src/code_1AC760.c | 1 + tools/compile_dsl_macros.py | 35 +-- tools/splat.yaml | 3 +- tools/star_rod_idx_to_c.py | 6 +- undefined_syms.txt | 4 + 13 files changed, 512 insertions(+), 84 deletions(-) create mode 100644 src/battle/actor/goomba.c diff --git a/include/common_structs.h b/include/common_structs.h index f53b71e623..2e386297ee 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -658,31 +658,6 @@ typedef struct TextureHeader { /* 0x2F */ u8 filtering; } TextureHeader; // size = 0x30 -typedef struct StaticActorData { - /* 0x00 */ s32 flags; - /* 0x04 */ char unk_04; - /* 0x05 */ u8 type; - /* 0x06 */ u8 level; - /* 0x07 */ u8 maxHP; - /* 0x08 */ s16 partCount; - /* 0x0A */ char unk_0A[2]; - /* 0x0C */ struct StaticActorPart** partsData; - /* 0x10 */ UNK_PTR script; - /* 0x14 */ UNK_PTR statusTable; - /* 0x18 */ u8 escapeChance; - /* 0x19 */ u8 airLiftChance; - /* 0x1A */ u8 spookChance; - /* 0x1B */ u8 baseStatusChance; - /* 0x1C */ u8 upAndAwayChance; - /* 0x1D */ u8 spinSmashReq; - /* 0x1E */ u8 powerBounceChance; - /* 0x1F */ u8 coinReward; - /* 0x20 */ u8 size[2]; - /* 0x22 */ Vec2b hpBarOffset; - /* 0x24 */ u8 statusIconOffset[2]; - /* 0x26 */ u8 statusMessageOffset[2]; -} StaticActorData; // size = 0x28 - typedef struct StaticMove { /* 0x00 */ s32 moveNameID; /* 0x04 */ s32 flags; @@ -1236,7 +1211,7 @@ typedef struct ActorFlyPos { typedef struct Actor { /* 0x000 */ s32 flags; /* 0x004 */ char unk_04[4]; - /* 0x008 */ struct StaticActorData* staticActorData; + /* 0x008 */ struct ActorDesc* staticActorData; /* 0x00C */ ActorMovePos movePos; /* 0x030 */ char unk_30[24]; /* 0x048 */ f32 jumpAccel; diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c new file mode 100644 index 0000000000..c932082f13 --- /dev/null +++ b/src/battle/actor/goomba.c @@ -0,0 +1,443 @@ +#include "common.h" +#include "battle/battle.h" +#include "script_api/battle.h" +#include "goomba.h" + +ApiStatus func_8021818C_430B2C(ScriptInstance* script, s32 isInitialCall); +s32 idleAnimations_80219760[]; +s32 idleAnimations_80219714[]; +s32 defenseTable_80219610[]; +s32 statusTable_8021961C[]; +s32 defenseTable_80219610[]; +s32 partsTable_802196C8[]; +Script script_Init_802197AC; +Script script_TakeTurn_8021A300; +Script script_Idle_802197F8; +Script script_HandleEvent_80219AD4; + +// 431FB0-431FBC (VRAM: 80219610) +s32 defenseTable_80219610[] = { + 0x00000001, 0x00000000, 0x00000000, +}; + +// 431FBC-432068 (VRAM: 8021961C) +s32 statusTable_8021961C[] = { + 0x00000001, 0x00000000, 0x00000002, 0x00000000, 0x00000006, 0x00000064, 0x00000009, 0x00000064, + 0x00000007, 0x00000064, 0x00000004, 0x00000064, 0x00000003, 0x00000064, 0x0000000B, 0x00000064, + 0x00000005, 0x00000064, 0x0000000A, 0x00000064, 0x00000008, 0x00000064, 0x0000001F, 0x00000000, + 0x00000020, 0x00000000, 0x00000025, 0x00000000, 0x00000022, 0x00000000, 0x00000024, 0x00000000, + 0x00000023, 0x00000000, 0x00000021, 0x00000000, 0x00000026, 0x00000000, 0x00000027, 0x00000000, + 0x00000029, 0x00000000, 0x00000000, +}; + +// 432068-43208C (VRAM: 802196C8) +s32 partsTable_802196C8[] = { + 0x00800000, 0x01000000, 0x001400FF, idleAnimations_80219714, defenseTable_80219610, 0x00000000, 0x00000000, 0x00F60000, + 0x00000000, +}; + +// 43208C-4320B4 (VRAM: 802196EC) +ActorDesc goomba = { + .flags = 0, + .type = 7, + .level = 5, + .maxHP = 2, + .partCount = 1, + .partsData = &partsTable_802196C8, + .script = &script_Init_802197AC, + .statusTable = &statusTable_8021961C, + .escapeChance = 90, + .airLiftChance = 100, + .spookChance = 90, + .baseStatusChance = 100, + .upAndAwayChance = 95, + .spinSmashReq = 0, + .powerBounceChance = 100, + .coinReward = 1, + .size = { 24, 24 }, + .hpBarOffset = { 0, 0 }, + .statusIconOffset = { -10, 20 }, + .statusMessageOffset = { 10, 20 }, +}; + +// 4320B4-432100 (VRAM: 80219714) +s32 idleAnimations_80219714[] = { + 0x00000001, 0x00260001, 0x0000000C, 0x00260000, 0x00000006, 0x00260008, 0x00000009, 0x00260001, + 0x00000008, 0x00260000, 0x0000000B, 0x00260001, 0x00000005, 0x00260000, 0x00000004, 0x00260007, + 0x00000003, 0x00260007, 0x00000000, +}; + +// 432100-43214C (VRAM: 80219760) +s32 idleAnimations_80219760[] = { + 0x00000001, 0x00260003, 0x0000000C, 0x00260000, 0x00000006, 0x00260008, 0x00000009, 0x00260001, + 0x00000008, 0x00260000, 0x0000000B, 0x00260003, 0x00000005, 0x00260000, 0x00000004, 0x00260007, + 0x00000003, 0x00260007, 0x00000000, +}; + +// 43214C-432198 (VRAM: 802197AC) +Script script_Init_802197AC = SCRIPT({ + BindTakeTurn(0xFFFFFF81, script_TakeTurn_8021A300); + BindIdle(0xFFFFFF81, script_Idle_802197F8); + BindHandleEvent(0xFFFFFF81, script_HandleEvent_80219AD4); +}); + +// 432198-432474 (VRAM: 802197F8) +Script script_Idle_802197F8 = SCRIPT({ +10: + RandInt(80, SI_VAR(0)); + SI_VAR(0) += 80; + loop SI_VAR(0) { + 0: + GetStatusFlags(0xFFFFFF81, SI_VAR(1)); + if (SI_VAR(1) ? 0x35D000) { + sleep 1; + goto 0; + } + sleep 1; + } + GetActorPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SI_VAR(0) += 5; + SetActorIdleSpeed(0xFFFFFF81, 1.0); + SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219760); + SetIdleGoal(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + IdleRunToGoal(0xFFFFFF81, 0); + SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219714); + loop 20 { + 1: + GetStatusFlags(0xFFFFFF81, SI_VAR(1)); + if (SI_VAR(1) ? 0x35D000) { + sleep 1; + goto 1; + } + sleep 1; + } + GetActorPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SI_VAR(0) -= 5; + SetActorIdleSpeed(0xFFFFFF81, 1.0); + SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219760); + SetIdleGoal(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + IdleRunToGoal(0xFFFFFF81, 0); + SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219714); + loop 80 { + 2: + GetStatusFlags(0xFFFFFF81, SI_VAR(1)); + if (SI_VAR(1) ? 0x35D000) { + sleep 1; + goto 2; + } + sleep 1; + } + goto 10; +}); + +// 432474-432B34 (VRAM: 80219AD4) +Script script_HandleEvent_80219AD4 = SCRIPT({ + UseIdleAnimation(0xFFFFFF81, 0); + EnableIdleScript(0xFFFFFF81, 0); + SetActorScale(0xFFFFFF81, 1.0, 1.0, 1.0); + GetLastEvent(0xFFFFFF81, SI_VAR(0)); + match SI_VAR(0) { + 9, 10 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260005; + await DoNormalHit; + } + == 14 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260009; + SI_VAR(2) =c 0x26000A; + await DoBurnHit; + } + == 36 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260009; + SI_VAR(2) =c 0x26000A; + await DoBurnHit; + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x26000A; + await DoDeath; + return; + } + == 11 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260005; + await DoSpinSmashHit; + } + == 33 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260005; + await DoSpinSmashHit; + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260006; + await DoDeath; + return; + } + == 47 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x26000E; + await DoShockHit; + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260005; + await DoJumpBack; + JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); + SetAnimationRate(0xFFFFFF81, 1, 2.0); + SetAnimation(0xFFFFFF81, 1, 0x260007); + SetGoalToHome(0xFFFFFF81); + SetActorSpeed(0xFFFFFF81, 8.0); + RunToGoal(0xFFFFFF81, 0, 0); + SetAnimationRate(0xFFFFFF81, 1, 1.0); + sleep 5; + SetAnimation(0xFFFFFF81, 1, 0x260001); + SetActorJumpGravity(0xFFFFFF81, 1.6005859375); + JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); + } + == 38 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x26000E; + await DoShockHit; + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260006; + await DoDeath; + return; + } + == 19, 23, 25, 31 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260001; + await DoImmune; + } + == 32 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260005; + await DoNormalHit; + sleep 10; + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260006; + await DoDeath; + return; + } + == 53 { + SetAnimationRate(0xFFFFFF81, 1, 2.0); + SetAnimation(0xFFFFFF81, 1, 0x260003); + SetGoalToHome(0xFFFFFF81); + SetActorSpeed(0xFFFFFF81, 4.0); + RunToGoal(0xFFFFFF81, 0, 0); + SetAnimationRate(0xFFFFFF81, 1, 1.0); + HPBarToHome(0xFFFFFF81); + } + == 49 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260001; + await DoRecover; + } + == 57 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260003; + SI_VAR(2) =c 0x260005; + await DoScareAway; + return; + } + == 58 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260003; + await DoAirLift; + } + == 22 { + SI_VAR(0) =c 0x1; + SI_VAR(1) =c 0x260005; + await DoBlowAway; + return; + } + else { + } + } + SetAnimation(0xFFFFFF81, 1, 0x260001); + EnableIdleScript(0xFFFFFF81, 1); + UseIdleAnimation(0xFFFFFF81, 1); +}); + +// 432B34-432CA0 (VRAM: 8021A194) +f32 floatTable_8021A194[] = { + 0.000000f, 0.017452f, 0.034899f, 0.052336f, 0.069756f, 0.087156f, 0.104528f, 0.121869f, + 0.139173f, 0.156434f, 0.173648f, 0.190809f, 0.207912f, 0.224951f, 0.241922f, 0.258819f, + 0.275637f, 0.292372f, 0.309017f, 0.325568f, 0.342020f, 0.358368f, 0.374607f, 0.390731f, + 0.406737f, 0.422618f, 0.438371f, 0.453990f, 0.469472f, 0.484810f, 0.500000f, 0.515038f, + 0.529919f, 0.544639f, 0.559193f, 0.573576f, 0.587785f, 0.601815f, 0.615661f, 0.629320f, + 0.642788f, 0.656059f, 0.669131f, 0.681998f, 0.694658f, 0.707107f, 0.719340f, 0.731354f, + 0.743145f, 0.754710f, 0.766044f, 0.777146f, 0.788011f, 0.798636f, 0.809017f, 0.819152f, + 0.829038f, 0.838671f, 0.848048f, 0.857167f, 0.866025f, 0.874620f, 0.882948f, 0.891007f, + 0.898794f, 0.906308f, 0.913545f, 0.920505f, 0.927184f, 0.933580f, 0.939693f, 0.945519f, + 0.951057f, 0.956305f, 0.961262f, 0.965926f, 0.970296f, 0.974370f, 0.978148f, 0.981627f, + 0.984808f, 0.987688f, 0.990268f, 0.992546f, 0.994522f, 0.996195f, 0.997564f, 0.998630f, + 0.999391f, 0.999848f, 1.000000f, +}; + +// 432CA0-433968 (VRAM: 8021A300) +Script script_TakeTurn_8021A300 = SCRIPT({ + UseIdleAnimation(0xFFFFFF81, 0); + EnableIdleScript(0xFFFFFF81, 0); + SetTargetActor(0xFFFFFF81, 0); + UseCamPreset(63); + BattleCamTargetActor(0xFFFFFF81); + 0x8024ECF8(-1, 1, 0); + SetAnimation(0xFFFFFF81, 1, 0x260003); + SetGoalToTarget(0xFFFFFF81); + AddGoalPos(0xFFFFFF81, 50, 0, 0); + SetActorSpeed(0xFFFFFF81, 6.0); + RunToGoal(0xFFFFFF81, 0, 0); + SetAnimation(0xFFFFFF81, 1, 0x260001); + SetActorDispOffset(0xFFFFFF81, 0, -1, 0); + sleep 1; + SetActorDispOffset(0xFFFFFF81, 0, 0xFFFFFFFE, 0); + sleep 5; + SetActorDispOffset(0xFFFFFF81, 0, 0, 0); + SetAnimation(0xFFFFFF81, 1, 0x260004); + EnemyTestTarget(0xFFFFFF81, SI_VAR(0), 0, 0, 1, 16); + match SI_VAR(0) { + 6, 5 { + SI_VAR(10) = SI_VAR(0); + SetGoalToTarget(0xFFFFFF81); + GetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SI_VAR(0) -= 10; + SI_VAR(1) = 10; + SI_VAR(2) += 3; + SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SetActorJumpGravity(0xFFFFFF81, 1.2001953125); + spawn { + GetActorPos(0xFFFFFF81, SI_VAR(1), SI_VAR(2), SI_VAR(0)); + SI_VAR(0) = 0; + loop 16 { + GetActorPos(0xFFFFFF81, SI_VAR(4), SI_VAR(5), SI_VAR(6)); + func_8021818C_430B2C(SI_VAR(1), SI_VAR(2), SI_VAR(4), SI_VAR(5), SI_VAR(0)); + SetActorRotation(0xFFFFFF81, 0, 0, SI_VAR(0)); + SI_VAR(1) = SI_VAR(4); + SI_VAR(2) = SI_VAR(5); + SI_VAR(3) = SI_VAR(6); + sleep 1; + } + } + spawn { + sleep 6; + SetAnimation(0xFFFFFF81, 1, 0x260004); + } + JumpToGoal(0xFFFFFF81, 16, 0, 1, 0); + SetAnimation(0xFFFFFF81, 1, 0x260008); + SetActorScale(0xFFFFFF81, 1.1005859375, 0.80078125, 1.0); + SetActorDispOffset(0xFFFFFF81, 0, 5, 0); + sleep 1; + SetActorScale(0xFFFFFF81, 1.30078125, 0.5, 1.0); + SetActorDispOffset(0xFFFFFF81, 0, 0xFFFFFFFE, 0); + sleep 1; + SetActorScale(0xFFFFFF81, 1.0, 1.0, 1.0); + SetActorDispOffset(0xFFFFFF81, 0, 7, 0); + SetAnimation(0xFFFFFF81, 1, 0x260005); + sleep 5; + if (SI_VAR(10) == 5) { + EnemyTestTarget(0xFFFFFF81, SI_VAR(0), 0x80000000, 0, 0, 0); + } + sleep 5; + SetActorDispOffset(0xFFFFFF81, 0, 0, 0); + SetAnimation(0xFFFFFF81, 1, 0x260004); + SetGoalToTarget(0xFFFFFF81); + GetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SI_VAR(0) += 20; + SI_VAR(1) = 0; + SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SetActorJumpGravity(0xFFFFFF81, 2.0); + spawn { + sleep 4; + SI_VAR(0) = 180; + loop 4 { + SI_VAR(0) -= 45; + SetActorRotation(0xFFFFFF81, 0, 0, SI_VAR(0)); + sleep 1; + } + SetAnimation(0xFFFFFF81, 1, 0x260004); + } + JumpToGoal(0xFFFFFF81, 15, 0, 1, 0); + SetAnimation(0xFFFFFF81, 1, 0x260007); + sleep 5; + UseCamPreset(2); + YieldTurn(); + SetActorYaw(0xFFFFFF81, 180); + AddActorDecoration(0xFFFFFF81, 1, 0, 2); + SetAnimationRate(0xFFFFFF81, 1, 2.0); + SetGoalToHome(0xFFFFFF81); + SetActorSpeed(0xFFFFFF81, 8.0); + RunToGoal(0xFFFFFF81, 0, 0); + SetAnimationRate(0xFFFFFF81, 1, 1.0); + SetActorYaw(0xFFFFFF81, 0); + sleep 5; + SetAnimation(0xFFFFFF81, 1, 0x260001); + SetActorJumpGravity(0xFFFFFF81, 1.6005859375); + JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); + RemoveActorDecoration(0xFFFFFF81, 1, 0); + EnableIdleScript(0xFFFFFF81, 1); + UseIdleAnimation(0xFFFFFF81, 1); + return; + } + else { + SetGoalToTarget(0xFFFFFF81); + SetActorJumpGravity(0xFFFFFF81, 1.2001953125); + spawn { + GetActorPos(0xFFFFFF81, SI_VAR(1), SI_VAR(2), SI_VAR(0)); + SI_VAR(0) = 0; + loop 16 { + GetActorPos(0xFFFFFF81, SI_VAR(4), SI_VAR(5), SI_VAR(6)); + func_8021818C_430B2C(SI_VAR(1), SI_VAR(2), SI_VAR(4), SI_VAR(5), SI_VAR(0)); + SetActorRotation(0xFFFFFF81, 0, 0, SI_VAR(0)); + SI_VAR(1) = SI_VAR(4); + SI_VAR(2) = SI_VAR(5); + SI_VAR(3) = SI_VAR(6); + sleep 1; + } + } + spawn { + sleep 6; + SetAnimation(0xFFFFFF81, 1, 0x260004); + } + JumpToGoal(0xFFFFFF81, 16, 0, 1, 0); + SetAnimation(0xFFFFFF81, 1, 0x26000B); + SetActorScale(0xFFFFFF81, 1.1005859375, 0.80078125, 1.0); + sleep 1; + SetActorScale(0xFFFFFF81, 1.30078125, 0.5, 1.0); + sleep 1; + } + } + EnemyDamageTarget(0xFFFFFF81, SI_VAR(0), 0, 0, 0, 1, 32); + match SI_VAR(0) { + 0, 2 { + UseCamPreset(2); + SetActorScale(0xFFFFFF81, 1.1005859375, 0.80078125, 1.0); + sleep 1; + SetActorScale(0xFFFFFF81, 1.0, 1.0, 1.0); + sleep 1; + SetActorRotation(0xFFFFFF81, 0, 0, 0); + SetActorDispOffset(0xFFFFFF81, 0, 0, 0); + SetAnimation(0xFFFFFF81, 1, 0x260001); + GetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SI_VAR(0) += 40; + SI_VAR(1) = 0; + SetActorJumpGravity(0xFFFFFF81, 1.80078125); + SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + JumpToGoal(0xFFFFFF81, 10, 0, 1, 0); + SI_VAR(0) += 30; + SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + JumpToGoal(0xFFFFFF81, 8, 0, 1, 0); + SI_VAR(0) += 20; + SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + JumpToGoal(0xFFFFFF81, 6, 0, 1, 0); + SetAnimation(0xFFFFFF81, 1, 0x260001); + sleep 3; + YieldTurn(); + SetAnimationRate(0xFFFFFF81, 1, 2.0); + SetAnimation(0xFFFFFF81, 1, 0x260003); + SetGoalToHome(0xFFFFFF81); + SetActorSpeed(0xFFFFFF81, 8.0); + RunToGoal(0xFFFFFF81, 0, 0); + SetAnimationRate(0xFFFFFF81, 1, 1.0); + } + } + EnableIdleScript(0xFFFFFF81, 1); + UseIdleAnimation(0xFFFFFF81, 1); +}); + diff --git a/src/battle/actor/goomba.h b/src/battle/actor/goomba.h index 04e018590b..6bdb5a5f59 100644 --- a/src/battle/actor/goomba.h +++ b/src/battle/actor/goomba.h @@ -1,7 +1,8 @@ #ifndef _BATTLE_ACTOR_GOOMBA_ #define _BATTLE_ACTOR_GOOMBA_ -// TODO: disasm -#define goomba 0x802196EC +#include "common.h" + +ActorDesc goomba; #endif diff --git a/src/battle/area_kmr_part_1/battles.c b/src/battle/area_kmr_part_1/battles.c index 46c4e894de..2acb47e752 100644 --- a/src/battle/area_kmr_part_1/battles.c +++ b/src/battle/area_kmr_part_1/battles.c @@ -6,41 +6,41 @@ #include "battle/actor/spiked_goomba.h" Formation formation0 = { - { goomba, .position = 1, .priority = 10 }, + { &goomba, .position = 1, .priority = 10 }, }; Formation formation1 = { - { goomba, .position = 1, .priority = 10 }, - { goomba, .position = 2, .priority = 9 }, + { &goomba, .position = 1, .priority = 10 }, + { &goomba, .position = 2, .priority = 9 }, }; Formation formation2 = { - { goomba, .position = 0, .priority = 10 }, - { goomba, .position = 1, .priority = 9 }, - { goomba, .position = 2, .priority = 8 }, + { &goomba, .position = 0, .priority = 10 }, + { &goomba, .position = 1, .priority = 9 }, + { &goomba, .position = 2, .priority = 8 }, }; Formation formation3 = { - { goomba, .position = 1, .priority = 10 }, + { &goomba, .position = 1, .priority = 10 }, { paragoomba, .position = 6, .priority = 9 }, }; Formation formation4 = { - { goomba, .position = 0, .priority = 10 }, - { goomba, .position = 1, .priority = 9 }, - { goomba, .position = 2, .priority = 8 }, - { goomba, .position = 3, .priority = 7 }, + { &goomba, .position = 0, .priority = 10 }, + { &goomba, .position = 1, .priority = 9 }, + { &goomba, .position = 2, .priority = 8 }, + { &goomba, .position = 3, .priority = 7 }, }; Formation formation5 = { - { goomba, .position = 1, .priority = 10 }, + { &goomba, .position = 1, .priority = 10 }, { spikedGoomba, .position = 2, .priority = 9 }, }; Formation formation6 = { - { goomba, .position = 0, .priority = 10 }, + { &goomba, .position = 0, .priority = 10 }, { paragoomba, .position = 5, .priority = 9 }, - { goomba, .position = 2, .priority = 8 }, + { &goomba, .position = 2, .priority = 8 }, { paragoomba, .position = 7, .priority = 7 }, }; @@ -65,7 +65,7 @@ Formation formation10 = { Formation formation11 = { { spikedGoomba, .position = 1, .priority = 10 }, - { goomba, .position = 2, .priority = 9 }, + { &goomba, .position = 2, .priority = 9 }, }; BattleList area_kmr_part_1_battles = { diff --git a/src/battle/battle.h b/src/battle/battle.h index 2d97adfa11..e906371cf5 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -3,6 +3,31 @@ #include "common.h" +typedef struct ActorDesc { + /* 0x00 */ s32 flags; + /* 0x04 */ char unk_04; + /* 0x05 */ u8 type; + /* 0x06 */ u8 level; + /* 0x07 */ u8 maxHP; + /* 0x08 */ s16 partCount; + /* 0x0A */ char unk_0A[2]; + /* 0x0C */ struct StaticActorPart** partsData; + /* 0x10 */ Bytecode* script; + /* 0x14 */ s32* statusTable; + /* 0x18 */ u8 escapeChance; + /* 0x19 */ u8 airLiftChance; + /* 0x1A */ u8 spookChance; + /* 0x1B */ u8 baseStatusChance; + /* 0x1C */ u8 upAndAwayChance; + /* 0x1D */ u8 spinSmashReq; + /* 0x1E */ u8 powerBounceChance; + /* 0x1F */ u8 coinReward; + /* 0x20 */ Vec2b size; + /* 0x22 */ Vec2b hpBarOffset; + /* 0x24 */ Vec2b statusIconOffset; + /* 0x26 */ Vec2b statusMessageOffset; +} ActorDesc; // size = 0x28 + typedef struct Stage { /* 0x00 */ const char* texture; /* 0x04 */ const char* shape; @@ -23,7 +48,7 @@ typedef struct StageListRow { } StageList[]; // size = 0x08 * n typedef struct FormationRow { - /* 0x00 */ StaticActorData* actor; + /* 0x00 */ ActorDesc* actor; /* 0x04 */ s32 position; ///< Home position. May also be a `Vector3*`. /* 0x08 */ s32 priority; ///< Actors with higher priority values take their turn first. /* 0x0C */ s32 var0; @@ -41,6 +66,13 @@ typedef struct Battle { /* 0x10 */ s32 unk_10; } BattleList[]; // size = 0x14 * n +typedef struct { + Element element; + s32 defense; +} DefenseTableEntry; + +typedef DefenseTableEntry DefenseTable[]; + #define BATTLE(name, formation, stage) { name, ARRAY_COUNT(formation), formation, stage } // TODO: enum for home position (0..3 are floor, 4..7 are air, etc.) diff --git a/src/code_190B20.c b/src/code_190B20.c index 82b8cfae99..5d73b2d9b7 100644 --- a/src/code_190B20.c +++ b/src/code_190B20.c @@ -1,4 +1,5 @@ #include "code_190B20.h" +#include "battle/battle.h" INCLUDE_ASM(s32, "code_190B20", create_target_list); @@ -93,11 +94,6 @@ INCLUDE_ASM(s32, "code_190B20", func_80265CE8); INCLUDE_ASM(s32, "code_190B20", func_80265D44); -typedef struct { - Element element; - s32 defense; -} DefenseTableEntry; - s32 lookup_defense(DefenseTableEntry* defenseTable, Element elementKey) { DefenseTableEntry* row; s32 normalDefense = 0; diff --git a/src/code_197F40.c b/src/code_197F40.c index 0cc624d125..29db736be7 100644 --- a/src/code_197F40.c +++ b/src/code_197F40.c @@ -1,4 +1,5 @@ #include "common.h" +#include "battle/battle.h" s32 count_targets(Actor* actor, s32 targetHomeIndex, s32 targetSelectionFlags) { BattleStatus* battleStatus = BATTLE_STATUS; diff --git a/src/code_1A5830.c b/src/code_1A5830.c index 64de475aa0..812ef1c94f 100644 --- a/src/code_1A5830.c +++ b/src/code_1A5830.c @@ -1,4 +1,5 @@ #include "common.h" +#include "battle/battle.h" void dispatch_event_actor(Actor* actor, Event event); diff --git a/src/code_1AC760.c b/src/code_1AC760.c index 4a27ff9f56..2059bc8e35 100644 --- a/src/code_1AC760.c +++ b/src/code_1AC760.c @@ -1,4 +1,5 @@ #include "common.h" +#include "battle/battle.h" INCLUDE_ASM(s32, "code_1AC760", dispatch_event_partner); diff --git a/tools/compile_dsl_macros.py b/tools/compile_dsl_macros.py index f3c757aa61..b01285121a 100755 --- a/tools/compile_dsl_macros.py +++ b/tools/compile_dsl_macros.py @@ -260,12 +260,12 @@ class LabelAllocation(Visitor): raise CompileError(f"label `{name}' already declared", tree.meta) try: - label_idx = int(name, base=0) + label_idx = int(name) - while len(self.labels) < label_idx: + while len(self.labels) <= label_idx: self.labels.append(None) - self.labels.insert(label_idx, name) + self.labels[label_idx] = name except ValueError: self.labels.append(name) @@ -391,7 +391,7 @@ class Compile(Transformer): return [tree.children[0], *tree.children[1]] def case_else(self, tree): - return [Cmd("ScriptOpcode_ELSE"), *tree.children[0]] + return [Cmd("ScriptOpcode_CASE_ELSE"), *tree.children[0]] def case_op(self, tree): if len(tree.children) == 4: op, expr, multi_case, block = tree.children @@ -593,33 +593,6 @@ class Compile(Transformer): "const": "ScriptOpcode_OR_CONST", } - def label_decl(self, tree): - if len(tree.children) == 1: - label = tree.children[0] - return Cmd("ScriptOpcode_LABEL", label, meta=tree.meta) - else: - label, cmd_or_block = tree.children - - if type(cmd_or_block) is not list: - cmd_or_block = [cmd_or_block] - - for cmd in cmd_or_block: - if isinstance(cmd, BaseCmd): - cmd.add_context(LabelCtx(label)) - - return [ - Cmd("ScriptOpcode_LABEL", label, meta=tree.meta), - *cmd_or_block - ] - def label_goto(self, tree): - label = tree.children[0] - return Cmd("ScriptOpcode_GOTO", label, meta=tree.meta) - def label(self, tree): - name = tree.children[0] - if name in self.alloc.labels: - return self.alloc.labels.index(name) - raise CompileError(f"label `{name}' is undeclared", tree.meta) - def variable(self, tree): name = tree.children[0] return self.alloc.variables.index(name) - 30000000 diff --git a/tools/splat.yaml b/tools/splat.yaml index d3c1234d93..657d17ea85 100644 --- a/tools/splat.yaml +++ b/tools/splat.yaml @@ -934,7 +934,8 @@ segments: files: - [0x4309A0, c] - [0x431B80, .data, battle/area_kmr_part_1/battles] - - [0x431FB0, bin, battle/area_kmr_part_1/goomba] + - [0x431FB0, .data, battle/actor/goomba] + - [0x433970, bin] - [0x4398A0, .rodata, battle/area_kmr_part_1/battles] - [0x439984, bin] - name: battle/area_kmr_part_2/ diff --git a/tools/star_rod_idx_to_c.py b/tools/star_rod_idx_to_c.py index c6901bea14..b1d561a246 100755 --- a/tools/star_rod_idx_to_c.py +++ b/tools/star_rod_idx_to_c.py @@ -11,7 +11,7 @@ import disasm_script DIR = os.path.dirname(__file__) -def disassemble(bytes, midx, symbol_map={}, comments=True): +def disassemble(bytes, midx, symbol_map={}, comments=True, romstart=0): out = "" entry_list_name = None @@ -22,7 +22,7 @@ def disassemble(bytes, midx, symbol_map={}, comments=True): name = struct["name"] if comments: - out += f"// {struct['start']:X}-{struct['end']:X} (VRAM: {struct['vaddr']:X})\n" + out += f"// {romstart+struct['start']:X}-{romstart+struct['end']:X} (VRAM: {struct['vaddr']:X})\n" # format struct if struct["type"].startswith("Script"): @@ -194,5 +194,5 @@ if __name__ == "__main__": with open(os.path.join(DIR, "../baserom.z64"), "rb") as romfile: romfile.seek(eval(args.offset)) - disasm = disassemble(romfile, midx, symbol_map, args.comments) + disasm = disassemble(romfile, midx, symbol_map, args.comments, eval(args.offset)) print(disasm.rstrip()) diff --git a/undefined_syms.txt b/undefined_syms.txt index 34d8df9aab..86a1b2204e 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -324,6 +324,10 @@ DoShockHit = 0x8029A6FC; DoSleepHit = 0x802945E0; DoSpinSmashHit = 0x8029B998; DoStopHit = 0x80294650; +DoAirLift = 0x8029C37C; +DoBlowAway = 0x8029C4A8; +DoBurnHit = 0x8029A0D0; +DoDeath = 0x8029AEC0; ShakeCam1 = 0x802D9CB0; ShakeCamX = 0x802D9CE8; From c1e7d3310c677897c5cdb07149bb3fe13f9674ca Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 10:59:00 +0000 Subject: [PATCH 07/16] format --- src/battle/actor/goomba.c | 90 +++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index c932082f13..4f2341f36c 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -87,7 +87,7 @@ Script script_Idle_802197F8 = SCRIPT({ RandInt(80, SI_VAR(0)); SI_VAR(0) += 80; loop SI_VAR(0) { - 0: +0: GetStatusFlags(0xFFFFFF81, SI_VAR(1)); if (SI_VAR(1) ? 0x35D000) { sleep 1; @@ -103,7 +103,7 @@ Script script_Idle_802197F8 = SCRIPT({ IdleRunToGoal(0xFFFFFF81, 0); SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219714); loop 20 { - 1: +1: GetStatusFlags(0xFFFFFF81, SI_VAR(1)); if (SI_VAR(1) ? 0x35D000) { sleep 1; @@ -119,7 +119,7 @@ Script script_Idle_802197F8 = SCRIPT({ IdleRunToGoal(0xFFFFFF81, 0); SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219714); loop 80 { - 2: +2: GetStatusFlags(0xFFFFFF81, SI_VAR(1)); if (SI_VAR(1) ? 0x35D000) { sleep 1; @@ -138,46 +138,46 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ GetLastEvent(0xFFFFFF81, SI_VAR(0)); match SI_VAR(0) { 9, 10 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260005; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260005; await DoNormalHit; } == 14 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260009; - SI_VAR(2) =c 0x26000A; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260009; + SI_VAR(2) = c 0x26000A; await DoBurnHit; } == 36 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260009; - SI_VAR(2) =c 0x26000A; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260009; + SI_VAR(2) = c 0x26000A; await DoBurnHit; - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x26000A; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x26000A; await DoDeath; return; } == 11 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260005; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260005; await DoSpinSmashHit; } == 33 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260005; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260005; await DoSpinSmashHit; - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260006; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260006; await DoDeath; return; } == 47 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x26000E; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x26000E; await DoShockHit; - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260005; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260005; await DoJumpBack; JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); SetAnimationRate(0xFFFFFF81, 1, 2.0); @@ -192,26 +192,26 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); } == 38 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x26000E; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x26000E; await DoShockHit; - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260006; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260006; await DoDeath; return; } == 19, 23, 25, 31 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260001; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260001; await DoImmune; } == 32 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260005; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260005; await DoNormalHit; sleep 10; - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260006; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260006; await DoDeath; return; } @@ -225,29 +225,28 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ HPBarToHome(0xFFFFFF81); } == 49 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260001; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260001; await DoRecover; } == 57 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260003; - SI_VAR(2) =c 0x260005; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260003; + SI_VAR(2) = c 0x260005; await DoScareAway; return; } == 58 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260003; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260003; await DoAirLift; } == 22 { - SI_VAR(0) =c 0x1; - SI_VAR(1) =c 0x260005; + SI_VAR(0) = c 0x1; + SI_VAR(1) = c 0x260005; await DoBlowAway; return; - } - else { + } else { } } SetAnimation(0xFFFFFF81, 1, 0x260001); @@ -374,8 +373,7 @@ Script script_TakeTurn_8021A300 = SCRIPT({ EnableIdleScript(0xFFFFFF81, 1); UseIdleAnimation(0xFFFFFF81, 1); return; - } - else { + } else { SetGoalToTarget(0xFFFFFF81); SetActorJumpGravity(0xFFFFFF81, 1.2001953125); spawn { From 77a3238a3b9a937a5014145b8cb0988fa877699d Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 11:35:59 +0000 Subject: [PATCH 08/16] clean up --- include/common_structs.h | 21 +-- src/battle/actor/goomba.c | 331 +++++++++++++++++++++----------------- src/battle/battle.h | 21 ++- 3 files changed, 209 insertions(+), 164 deletions(-) diff --git a/include/common_structs.h b/include/common_structs.h index 2e386297ee..c58871b240 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -21,6 +21,12 @@ typedef struct Vec2bu { /* 0x01 */ u8 y; } Vec2bu; // size = 0x02 +typedef struct Vec3b { + /* 0x00 */ s8 x; + /* 0x01 */ s8 y; + /* 0x02 */ s8 z; +} Vec3b; // size = 0x03 + typedef struct Vec3f { /* 0x00 */ f32 x; /* 0x04 */ f32 y; @@ -1017,7 +1023,7 @@ typedef struct ActorPartMovement { typedef struct ActorPart { /* 0x00 */ s32 flags; /* 0x04 */ s32 targetFlags; /* initialized to 0 */ - /* 0x08 */ struct StaticActorPart* staticData; + /* 0x08 */ struct ActorPartDesc* staticData; /* 0x0C */ struct ActorPart* nextPart; /* 0x10 */ struct ActorPartMovement* movement; /* 0x14 */ Vec3s partOffset; @@ -1333,19 +1339,6 @@ typedef struct Actor { /* 0x440 */ struct MenuIcon* ptrDefuffIcon; } Actor; // size = 0x444 -typedef struct StaticActorPart { - /* 0x00 */ s32 flags; - /* 0x04 */ s8 index; - /* 0x05 */ u8 posOffset[3]; - /* 0x08 */ u8 targetOffset[2]; - /* 0x0A */ s16 opacity; - /* 0x0C */ u32* idleAnimations; - /* 0x10 */ u32* defenseTable; - /* 0x14 */ s32 eventFlags; - /* 0x18 */ s32 flags3; - /* 0x1C */ char unk_1C[8]; -} StaticActorPart; // size = 0x24 - typedef struct TileDescriptor { /* 0x00 */ s8 name[32]; /* 0x20 */ s16 auxW; diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index 4f2341f36c..c355b76eb7 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -1,6 +1,7 @@ #include "common.h" #include "battle/battle.h" #include "script_api/battle.h" +#include "sprite/npc/goomba.h" #include "goomba.h" ApiStatus func_8021818C_430B2C(ScriptInstance* script, s32 isInitialCall); @@ -9,7 +10,7 @@ s32 idleAnimations_80219714[]; s32 defenseTable_80219610[]; s32 statusTable_8021961C[]; s32 defenseTable_80219610[]; -s32 partsTable_802196C8[]; +ActorPartDesc partsTable_802196C8[]; Script script_Init_802197AC; Script script_TakeTurn_8021A300; Script script_Idle_802197F8; @@ -17,23 +18,53 @@ Script script_HandleEvent_80219AD4; // 431FB0-431FBC (VRAM: 80219610) s32 defenseTable_80219610[] = { - 0x00000001, 0x00000000, 0x00000000, + Element_NORMAL, 0, + + Element_END, }; // 431FBC-432068 (VRAM: 8021961C) s32 statusTable_8021961C[] = { - 0x00000001, 0x00000000, 0x00000002, 0x00000000, 0x00000006, 0x00000064, 0x00000009, 0x00000064, - 0x00000007, 0x00000064, 0x00000004, 0x00000064, 0x00000003, 0x00000064, 0x0000000B, 0x00000064, - 0x00000005, 0x00000064, 0x0000000A, 0x00000064, 0x00000008, 0x00000064, 0x0000001F, 0x00000000, - 0x00000020, 0x00000000, 0x00000025, 0x00000000, 0x00000022, 0x00000000, 0x00000024, 0x00000000, - 0x00000023, 0x00000000, 0x00000021, 0x00000000, 0x00000026, 0x00000000, 0x00000027, 0x00000000, - 0x00000029, 0x00000000, 0x00000000, + Debuff_NORMAL, 0, + Debuff_DEFAULT, 0, + Debuff_SLEEP, 100, + Debuff_POISON, 100, + Debuff_FROZEN, 100, + Debuff_DIZZY, 100, + Debuff_FEAR, 100, + Debuff_STATIC, 100, + Debuff_PARALYZE, 100, + Debuff_SHRINK, 100, + Debuff_STOP, 100, + + Debuff_DEFAULT_TURN_MOD, 0, + Debuff_SLEEP_TURN_MOD, 0, + Debuff_POISON_TURN_MOD, 0, + Debuff_FROZEN_TURN_MOD, 0, + Debuff_DIZZY_TURN_MOD, 0, + Debuff_FEAR_TURN_MOD, 0, + Debuff_STATIC_TURN_MOD, 0, + Debuff_PARALYZE_TURN_MOD, 0, + Debuff_SHRINK_TURN_MOD, 0, + Debuff_STOP_TURN_MOD, 0, + + Debuff_END, }; // 432068-43208C (VRAM: 802196C8) -s32 partsTable_802196C8[] = { - 0x00800000, 0x01000000, 0x001400FF, idleAnimations_80219714, defenseTable_80219610, 0x00000000, 0x00000000, 0x00F60000, - 0x00000000, +ActorPartDesc partsTable_802196C8[] = { + { + .flags = 0x00800000, + .index = 1, + .posOffset = { 0, 0, 0 }, + .targetOffset = { 0, 0x14 }, + .opacity = 0xFF, + .idleAnimations = idleAnimations_80219714, + .defenseTable = defenseTable_80219610, + .eventFlags = 0, + .elementImmunityFlags = 0, + 0x00, 0xF6, + }, }; // 43208C-4320B4 (VRAM: 802196EC) @@ -62,9 +93,17 @@ ActorDesc goomba = { // 4320B4-432100 (VRAM: 80219714) s32 idleAnimations_80219714[] = { - 0x00000001, 0x00260001, 0x0000000C, 0x00260000, 0x00000006, 0x00260008, 0x00000009, 0x00260001, - 0x00000008, 0x00260000, 0x0000000B, 0x00260001, 0x00000005, 0x00260000, 0x00000004, 0x00260007, - 0x00000003, 0x00260007, 0x00000000, + Debuff_NORMAL, NPC_ANIM(goomba, normal, idle), + Debuff_STONE, NPC_ANIM(goomba, normal, still), + Debuff_SLEEP, NPC_ANIM(goomba, normal, asleep), + Debuff_POISON, NPC_ANIM(goomba, normal, idle), + Debuff_STOP, NPC_ANIM(goomba, normal, still), + Debuff_STATIC, NPC_ANIM(goomba, normal, idle), + Debuff_PARALYZE, NPC_ANIM(goomba, normal, still), + Debuff_DIZZY, NPC_ANIM(goomba, normal, dizzy), + Debuff_FEAR, NPC_ANIM(goomba, normal, dizzy), + + Debuff_END, }; // 432100-43214C (VRAM: 80219760) @@ -76,9 +115,9 @@ s32 idleAnimations_80219760[] = { // 43214C-432198 (VRAM: 802197AC) Script script_Init_802197AC = SCRIPT({ - BindTakeTurn(0xFFFFFF81, script_TakeTurn_8021A300); - BindIdle(0xFFFFFF81, script_Idle_802197F8); - BindHandleEvent(0xFFFFFF81, script_HandleEvent_80219AD4); + BindTakeTurn(ActorID_SELF, script_TakeTurn_8021A300); + BindIdle(ActorID_SELF, script_Idle_802197F8); + BindHandleEvent(ActorID_SELF, script_HandleEvent_80219AD4); }); // 432198-432474 (VRAM: 802197F8) @@ -88,39 +127,39 @@ Script script_Idle_802197F8 = SCRIPT({ SI_VAR(0) += 80; loop SI_VAR(0) { 0: - GetStatusFlags(0xFFFFFF81, SI_VAR(1)); + GetStatusFlags(ActorID_SELF, SI_VAR(1)); if (SI_VAR(1) ? 0x35D000) { sleep 1; goto 0; } sleep 1; } - GetActorPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + GetActorPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) += 5; - SetActorIdleSpeed(0xFFFFFF81, 1.0); - SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219760); - SetIdleGoal(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - IdleRunToGoal(0xFFFFFF81, 0); - SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219714); + SetActorIdleSpeed(ActorID_SELF, 1.0); + SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219760); + SetIdleGoal(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + IdleRunToGoal(ActorID_SELF, 0); + SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219714); loop 20 { 1: - GetStatusFlags(0xFFFFFF81, SI_VAR(1)); + GetStatusFlags(ActorID_SELF, SI_VAR(1)); if (SI_VAR(1) ? 0x35D000) { sleep 1; goto 1; } sleep 1; } - GetActorPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + GetActorPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) -= 5; - SetActorIdleSpeed(0xFFFFFF81, 1.0); - SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219760); - SetIdleGoal(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - IdleRunToGoal(0xFFFFFF81, 0); - SetIdleAnimations(0xFFFFFF81, 1, idleAnimations_80219714); + SetActorIdleSpeed(ActorID_SELF, 1.0); + SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219760); + SetIdleGoal(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + IdleRunToGoal(ActorID_SELF, 0); + SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219714); loop 80 { 2: - GetStatusFlags(0xFFFFFF81, SI_VAR(1)); + GetStatusFlags(ActorID_SELF, SI_VAR(1)); if (SI_VAR(1) ? 0x35D000) { sleep 1; goto 2; @@ -132,10 +171,10 @@ Script script_Idle_802197F8 = SCRIPT({ // 432474-432B34 (VRAM: 80219AD4) Script script_HandleEvent_80219AD4 = SCRIPT({ - UseIdleAnimation(0xFFFFFF81, 0); - EnableIdleScript(0xFFFFFF81, 0); - SetActorScale(0xFFFFFF81, 1.0, 1.0, 1.0); - GetLastEvent(0xFFFFFF81, SI_VAR(0)); + UseIdleAnimation(ActorID_SELF, 0); + EnableIdleScript(ActorID_SELF, 0); + SetActorScale(ActorID_SELF, 1.0, 1.0, 1.0); + GetLastEvent(ActorID_SELF, SI_VAR(0)); match SI_VAR(0) { 9, 10 { SI_VAR(0) = c 0x1; @@ -179,17 +218,17 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ SI_VAR(0) = c 0x1; SI_VAR(1) = c 0x260005; await DoJumpBack; - JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); - SetAnimationRate(0xFFFFFF81, 1, 2.0); - SetAnimation(0xFFFFFF81, 1, 0x260007); - SetGoalToHome(0xFFFFFF81); - SetActorSpeed(0xFFFFFF81, 8.0); - RunToGoal(0xFFFFFF81, 0, 0); - SetAnimationRate(0xFFFFFF81, 1, 1.0); + JumpToGoal(ActorID_SELF, 5, 0, 1, 0); + SetAnimationRate(ActorID_SELF, 1, 2.0); + SetAnimation(ActorID_SELF, 1, 0x260007); + SetGoalToHome(ActorID_SELF); + SetActorSpeed(ActorID_SELF, 8.0); + RunToGoal(ActorID_SELF, 0, 0); + SetAnimationRate(ActorID_SELF, 1, 1.0); sleep 5; - SetAnimation(0xFFFFFF81, 1, 0x260001); - SetActorJumpGravity(0xFFFFFF81, 1.6005859375); - JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); + SetAnimation(ActorID_SELF, 1, 0x260001); + SetActorJumpGravity(ActorID_SELF, 1.6005859375); + JumpToGoal(ActorID_SELF, 5, 0, 1, 0); } == 38 { SI_VAR(0) = c 0x1; @@ -216,13 +255,13 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ return; } == 53 { - SetAnimationRate(0xFFFFFF81, 1, 2.0); - SetAnimation(0xFFFFFF81, 1, 0x260003); - SetGoalToHome(0xFFFFFF81); - SetActorSpeed(0xFFFFFF81, 4.0); - RunToGoal(0xFFFFFF81, 0, 0); - SetAnimationRate(0xFFFFFF81, 1, 1.0); - HPBarToHome(0xFFFFFF81); + SetAnimationRate(ActorID_SELF, 1, 2.0); + SetAnimation(ActorID_SELF, 1, 0x260003); + SetGoalToHome(ActorID_SELF); + SetActorSpeed(ActorID_SELF, 4.0); + RunToGoal(ActorID_SELF, 0, 0); + SetAnimationRate(ActorID_SELF, 1, 1.0); + HPBarToHome(ActorID_SELF); } == 49 { SI_VAR(0) = c 0x1; @@ -249,9 +288,9 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ } else { } } - SetAnimation(0xFFFFFF81, 1, 0x260001); - EnableIdleScript(0xFFFFFF81, 1); - UseIdleAnimation(0xFFFFFF81, 1); + SetAnimation(ActorID_SELF, 1, 0x260001); + EnableIdleScript(ActorID_SELF, 1); + UseIdleAnimation(ActorID_SELF, 1); }); // 432B34-432CA0 (VRAM: 8021A194) @@ -272,42 +311,42 @@ f32 floatTable_8021A194[] = { // 432CA0-433968 (VRAM: 8021A300) Script script_TakeTurn_8021A300 = SCRIPT({ - UseIdleAnimation(0xFFFFFF81, 0); - EnableIdleScript(0xFFFFFF81, 0); - SetTargetActor(0xFFFFFF81, 0); + UseIdleAnimation(ActorID_SELF, 0); + EnableIdleScript(ActorID_SELF, 0); + SetTargetActor(ActorID_SELF, 0); UseCamPreset(63); - BattleCamTargetActor(0xFFFFFF81); + BattleCamTargetActor(ActorID_SELF); 0x8024ECF8(-1, 1, 0); - SetAnimation(0xFFFFFF81, 1, 0x260003); - SetGoalToTarget(0xFFFFFF81); - AddGoalPos(0xFFFFFF81, 50, 0, 0); - SetActorSpeed(0xFFFFFF81, 6.0); - RunToGoal(0xFFFFFF81, 0, 0); - SetAnimation(0xFFFFFF81, 1, 0x260001); - SetActorDispOffset(0xFFFFFF81, 0, -1, 0); + SetAnimation(ActorID_SELF, 1, 0x260003); + SetGoalToTarget(ActorID_SELF); + AddGoalPos(ActorID_SELF, 50, 0, 0); + SetActorSpeed(ActorID_SELF, 6.0); + RunToGoal(ActorID_SELF, 0, 0); + SetAnimation(ActorID_SELF, 1, 0x260001); + SetActorDispOffset(ActorID_SELF, 0, -1, 0); sleep 1; - SetActorDispOffset(0xFFFFFF81, 0, 0xFFFFFFFE, 0); + SetActorDispOffset(ActorID_SELF, 0, 0xFFFFFFFE, 0); sleep 5; - SetActorDispOffset(0xFFFFFF81, 0, 0, 0); - SetAnimation(0xFFFFFF81, 1, 0x260004); - EnemyTestTarget(0xFFFFFF81, SI_VAR(0), 0, 0, 1, 16); + SetActorDispOffset(ActorID_SELF, 0, 0, 0); + SetAnimation(ActorID_SELF, 1, 0x260004); + EnemyTestTarget(ActorID_SELF, SI_VAR(0), 0, 0, 1, 16); match SI_VAR(0) { 6, 5 { SI_VAR(10) = SI_VAR(0); - SetGoalToTarget(0xFFFFFF81); - GetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SetGoalToTarget(ActorID_SELF); + GetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) -= 10; SI_VAR(1) = 10; SI_VAR(2) += 3; - SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - SetActorJumpGravity(0xFFFFFF81, 1.2001953125); + SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SetActorJumpGravity(ActorID_SELF, 1.2001953125); spawn { - GetActorPos(0xFFFFFF81, SI_VAR(1), SI_VAR(2), SI_VAR(0)); + GetActorPos(ActorID_SELF, SI_VAR(1), SI_VAR(2), SI_VAR(0)); SI_VAR(0) = 0; loop 16 { - GetActorPos(0xFFFFFF81, SI_VAR(4), SI_VAR(5), SI_VAR(6)); + GetActorPos(ActorID_SELF, SI_VAR(4), SI_VAR(5), SI_VAR(6)); func_8021818C_430B2C(SI_VAR(1), SI_VAR(2), SI_VAR(4), SI_VAR(5), SI_VAR(0)); - SetActorRotation(0xFFFFFF81, 0, 0, SI_VAR(0)); + SetActorRotation(ActorID_SELF, 0, 0, SI_VAR(0)); SI_VAR(1) = SI_VAR(4); SI_VAR(2) = SI_VAR(5); SI_VAR(3) = SI_VAR(6); @@ -316,73 +355,73 @@ Script script_TakeTurn_8021A300 = SCRIPT({ } spawn { sleep 6; - SetAnimation(0xFFFFFF81, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, 0x260004); } - JumpToGoal(0xFFFFFF81, 16, 0, 1, 0); - SetAnimation(0xFFFFFF81, 1, 0x260008); - SetActorScale(0xFFFFFF81, 1.1005859375, 0.80078125, 1.0); - SetActorDispOffset(0xFFFFFF81, 0, 5, 0); + JumpToGoal(ActorID_SELF, 16, 0, 1, 0); + SetAnimation(ActorID_SELF, 1, 0x260008); + SetActorScale(ActorID_SELF, 1.1005859375, 0.80078125, 1.0); + SetActorDispOffset(ActorID_SELF, 0, 5, 0); sleep 1; - SetActorScale(0xFFFFFF81, 1.30078125, 0.5, 1.0); - SetActorDispOffset(0xFFFFFF81, 0, 0xFFFFFFFE, 0); + SetActorScale(ActorID_SELF, 1.30078125, 0.5, 1.0); + SetActorDispOffset(ActorID_SELF, 0, 0xFFFFFFFE, 0); sleep 1; - SetActorScale(0xFFFFFF81, 1.0, 1.0, 1.0); - SetActorDispOffset(0xFFFFFF81, 0, 7, 0); - SetAnimation(0xFFFFFF81, 1, 0x260005); + SetActorScale(ActorID_SELF, 1.0, 1.0, 1.0); + SetActorDispOffset(ActorID_SELF, 0, 7, 0); + SetAnimation(ActorID_SELF, 1, 0x260005); sleep 5; if (SI_VAR(10) == 5) { - EnemyTestTarget(0xFFFFFF81, SI_VAR(0), 0x80000000, 0, 0, 0); + EnemyTestTarget(ActorID_SELF, SI_VAR(0), 0x80000000, 0, 0, 0); } sleep 5; - SetActorDispOffset(0xFFFFFF81, 0, 0, 0); - SetAnimation(0xFFFFFF81, 1, 0x260004); - SetGoalToTarget(0xFFFFFF81); - GetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SetActorDispOffset(ActorID_SELF, 0, 0, 0); + SetAnimation(ActorID_SELF, 1, 0x260004); + SetGoalToTarget(ActorID_SELF); + GetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) += 20; SI_VAR(1) = 0; - SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - SetActorJumpGravity(0xFFFFFF81, 2.0); + SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SetActorJumpGravity(ActorID_SELF, 2.0); spawn { sleep 4; SI_VAR(0) = 180; loop 4 { SI_VAR(0) -= 45; - SetActorRotation(0xFFFFFF81, 0, 0, SI_VAR(0)); + SetActorRotation(ActorID_SELF, 0, 0, SI_VAR(0)); sleep 1; } - SetAnimation(0xFFFFFF81, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, 0x260004); } - JumpToGoal(0xFFFFFF81, 15, 0, 1, 0); - SetAnimation(0xFFFFFF81, 1, 0x260007); + JumpToGoal(ActorID_SELF, 15, 0, 1, 0); + SetAnimation(ActorID_SELF, 1, 0x260007); sleep 5; UseCamPreset(2); YieldTurn(); - SetActorYaw(0xFFFFFF81, 180); - AddActorDecoration(0xFFFFFF81, 1, 0, 2); - SetAnimationRate(0xFFFFFF81, 1, 2.0); - SetGoalToHome(0xFFFFFF81); - SetActorSpeed(0xFFFFFF81, 8.0); - RunToGoal(0xFFFFFF81, 0, 0); - SetAnimationRate(0xFFFFFF81, 1, 1.0); - SetActorYaw(0xFFFFFF81, 0); + SetActorYaw(ActorID_SELF, 180); + AddActorDecoration(ActorID_SELF, 1, 0, 2); + SetAnimationRate(ActorID_SELF, 1, 2.0); + SetGoalToHome(ActorID_SELF); + SetActorSpeed(ActorID_SELF, 8.0); + RunToGoal(ActorID_SELF, 0, 0); + SetAnimationRate(ActorID_SELF, 1, 1.0); + SetActorYaw(ActorID_SELF, 0); sleep 5; - SetAnimation(0xFFFFFF81, 1, 0x260001); - SetActorJumpGravity(0xFFFFFF81, 1.6005859375); - JumpToGoal(0xFFFFFF81, 5, 0, 1, 0); - RemoveActorDecoration(0xFFFFFF81, 1, 0); - EnableIdleScript(0xFFFFFF81, 1); - UseIdleAnimation(0xFFFFFF81, 1); + SetAnimation(ActorID_SELF, 1, 0x260001); + SetActorJumpGravity(ActorID_SELF, 1.6005859375); + JumpToGoal(ActorID_SELF, 5, 0, 1, 0); + RemoveActorDecoration(ActorID_SELF, 1, 0); + EnableIdleScript(ActorID_SELF, 1); + UseIdleAnimation(ActorID_SELF, 1); return; } else { - SetGoalToTarget(0xFFFFFF81); - SetActorJumpGravity(0xFFFFFF81, 1.2001953125); + SetGoalToTarget(ActorID_SELF); + SetActorJumpGravity(ActorID_SELF, 1.2001953125); spawn { - GetActorPos(0xFFFFFF81, SI_VAR(1), SI_VAR(2), SI_VAR(0)); + GetActorPos(ActorID_SELF, SI_VAR(1), SI_VAR(2), SI_VAR(0)); SI_VAR(0) = 0; loop 16 { - GetActorPos(0xFFFFFF81, SI_VAR(4), SI_VAR(5), SI_VAR(6)); + GetActorPos(ActorID_SELF, SI_VAR(4), SI_VAR(5), SI_VAR(6)); func_8021818C_430B2C(SI_VAR(1), SI_VAR(2), SI_VAR(4), SI_VAR(5), SI_VAR(0)); - SetActorRotation(0xFFFFFF81, 0, 0, SI_VAR(0)); + SetActorRotation(ActorID_SELF, 0, 0, SI_VAR(0)); SI_VAR(1) = SI_VAR(4); SI_VAR(2) = SI_VAR(5); SI_VAR(3) = SI_VAR(6); @@ -391,51 +430,51 @@ Script script_TakeTurn_8021A300 = SCRIPT({ } spawn { sleep 6; - SetAnimation(0xFFFFFF81, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, 0x260004); } - JumpToGoal(0xFFFFFF81, 16, 0, 1, 0); - SetAnimation(0xFFFFFF81, 1, 0x26000B); - SetActorScale(0xFFFFFF81, 1.1005859375, 0.80078125, 1.0); + JumpToGoal(ActorID_SELF, 16, 0, 1, 0); + SetAnimation(ActorID_SELF, 1, 0x26000B); + SetActorScale(ActorID_SELF, 1.1005859375, 0.80078125, 1.0); sleep 1; - SetActorScale(0xFFFFFF81, 1.30078125, 0.5, 1.0); + SetActorScale(ActorID_SELF, 1.30078125, 0.5, 1.0); sleep 1; } } - EnemyDamageTarget(0xFFFFFF81, SI_VAR(0), 0, 0, 0, 1, 32); + EnemyDamageTarget(ActorID_SELF, SI_VAR(0), 0, 0, 0, 1, 32); match SI_VAR(0) { 0, 2 { UseCamPreset(2); - SetActorScale(0xFFFFFF81, 1.1005859375, 0.80078125, 1.0); + SetActorScale(ActorID_SELF, 1.1005859375, 0.80078125, 1.0); sleep 1; - SetActorScale(0xFFFFFF81, 1.0, 1.0, 1.0); + SetActorScale(ActorID_SELF, 1.0, 1.0, 1.0); sleep 1; - SetActorRotation(0xFFFFFF81, 0, 0, 0); - SetActorDispOffset(0xFFFFFF81, 0, 0, 0); - SetAnimation(0xFFFFFF81, 1, 0x260001); - GetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + SetActorRotation(ActorID_SELF, 0, 0, 0); + SetActorDispOffset(ActorID_SELF, 0, 0, 0); + SetAnimation(ActorID_SELF, 1, 0x260001); + GetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) += 40; SI_VAR(1) = 0; - SetActorJumpGravity(0xFFFFFF81, 1.80078125); - SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - JumpToGoal(0xFFFFFF81, 10, 0, 1, 0); + SetActorJumpGravity(ActorID_SELF, 1.80078125); + SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + JumpToGoal(ActorID_SELF, 10, 0, 1, 0); SI_VAR(0) += 30; - SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - JumpToGoal(0xFFFFFF81, 8, 0, 1, 0); + SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + JumpToGoal(ActorID_SELF, 8, 0, 1, 0); SI_VAR(0) += 20; - SetGoalPos(0xFFFFFF81, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - JumpToGoal(0xFFFFFF81, 6, 0, 1, 0); - SetAnimation(0xFFFFFF81, 1, 0x260001); + SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); + JumpToGoal(ActorID_SELF, 6, 0, 1, 0); + SetAnimation(ActorID_SELF, 1, 0x260001); sleep 3; YieldTurn(); - SetAnimationRate(0xFFFFFF81, 1, 2.0); - SetAnimation(0xFFFFFF81, 1, 0x260003); - SetGoalToHome(0xFFFFFF81); - SetActorSpeed(0xFFFFFF81, 8.0); - RunToGoal(0xFFFFFF81, 0, 0); - SetAnimationRate(0xFFFFFF81, 1, 1.0); + SetAnimationRate(ActorID_SELF, 1, 2.0); + SetAnimation(ActorID_SELF, 1, 0x260003); + SetGoalToHome(ActorID_SELF); + SetActorSpeed(ActorID_SELF, 8.0); + RunToGoal(ActorID_SELF, 0, 0); + SetAnimationRate(ActorID_SELF, 1, 1.0); } } - EnableIdleScript(0xFFFFFF81, 1); - UseIdleAnimation(0xFFFFFF81, 1); + EnableIdleScript(ActorID_SELF, 1); + UseIdleAnimation(ActorID_SELF, 1); }); diff --git a/src/battle/battle.h b/src/battle/battle.h index e906371cf5..1496cb0600 100644 --- a/src/battle/battle.h +++ b/src/battle/battle.h @@ -11,7 +11,7 @@ typedef struct ActorDesc { /* 0x07 */ u8 maxHP; /* 0x08 */ s16 partCount; /* 0x0A */ char unk_0A[2]; - /* 0x0C */ struct StaticActorPart** partsData; + /* 0x0C */ struct ActorPartDesc** partsData; /* 0x10 */ Bytecode* script; /* 0x14 */ s32* statusTable; /* 0x18 */ u8 escapeChance; @@ -66,6 +66,10 @@ typedef struct Battle { /* 0x10 */ s32 unk_10; } BattleList[]; // size = 0x14 * n +#define BATTLE(name, formation, stage) { name, ARRAY_COUNT(formation), formation, stage } + +// TODO: enum for home position (0..3 are floor, 4..7 are air, etc.) + typedef struct { Element element; s32 defense; @@ -73,8 +77,17 @@ typedef struct { typedef DefenseTableEntry DefenseTable[]; -#define BATTLE(name, formation, stage) { name, ARRAY_COUNT(formation), formation, stage } - -// TODO: enum for home position (0..3 are floor, 4..7 are air, etc.) +typedef struct ActorPartDesc { + /* 0x00 */ s32 flags; + /* 0x04 */ s8 index; + /* 0x05 */ Vec3b posOffset; + /* 0x08 */ Vec2b targetOffset; + /* 0x0A */ s16 opacity; + /* 0x0C */ s32* idleAnimations; + /* 0x10 */ s32* defenseTable; + /* 0x14 */ s32 eventFlags; + /* 0x18 */ s32 elementImmunityFlags; + /* 0x1C */ char unk_1C[8]; +} ActorPartDesc; // size = 0x24 #endif From 9855c6202d7c1561b3f203d9c9bf74e021dab782 Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 11:37:19 +0000 Subject: [PATCH 09/16] dsl: change flag set operator to & --- src/battle/actor/goomba.c | 20 ++++++++++++++------ tools/compile_dsl_macros.py | 8 ++++---- tools/disasm_script.py | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index c355b76eb7..c426a96abe 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -108,9 +108,17 @@ s32 idleAnimations_80219714[] = { // 432100-43214C (VRAM: 80219760) s32 idleAnimations_80219760[] = { - 0x00000001, 0x00260003, 0x0000000C, 0x00260000, 0x00000006, 0x00260008, 0x00000009, 0x00260001, - 0x00000008, 0x00260000, 0x0000000B, 0x00260003, 0x00000005, 0x00260000, 0x00000004, 0x00260007, - 0x00000003, 0x00260007, 0x00000000, + Debuff_NORMAL, NPC_ANIM(goomba, normal, run), + Debuff_STONE, NPC_ANIM(goomba, normal, still), + Debuff_SLEEP, NPC_ANIM(goomba, normal, asleep), + Debuff_POISON, NPC_ANIM(goomba, normal, idle), + Debuff_STOP, NPC_ANIM(goomba, normal, still), + Debuff_STATIC, NPC_ANIM(goomba, normal, run), + Debuff_PARALYZE, NPC_ANIM(goomba, normal, still), + Debuff_DIZZY, NPC_ANIM(goomba, normal, dizzy), + Debuff_FEAR, NPC_ANIM(goomba, normal, dizzy), + + Debuff_END, }; // 43214C-432198 (VRAM: 802197AC) @@ -128,7 +136,7 @@ Script script_Idle_802197F8 = SCRIPT({ loop SI_VAR(0) { 0: GetStatusFlags(ActorID_SELF, SI_VAR(1)); - if (SI_VAR(1) ? 0x35D000) { + if (SI_VAR(1) & 0x35D000) { sleep 1; goto 0; } @@ -144,7 +152,7 @@ Script script_Idle_802197F8 = SCRIPT({ loop 20 { 1: GetStatusFlags(ActorID_SELF, SI_VAR(1)); - if (SI_VAR(1) ? 0x35D000) { + if (SI_VAR(1) & 0x35D000) { sleep 1; goto 1; } @@ -160,7 +168,7 @@ Script script_Idle_802197F8 = SCRIPT({ loop 80 { 2: GetStatusFlags(ActorID_SELF, SI_VAR(1)); - if (SI_VAR(1) ? 0x35D000) { + if (SI_VAR(1) & 0x35D000) { sleep 1; goto 2; } diff --git a/tools/compile_dsl_macros.py b/tools/compile_dsl_macros.py index b01285121a..379c27eb4f 100755 --- a/tools/compile_dsl_macros.py +++ b/tools/compile_dsl_macros.py @@ -77,8 +77,8 @@ script_parser = Lark(r""" | "<" -> cond_op_lt | ">=" -> cond_op_ge | "<=" -> cond_op_le - | "?" -> cond_op_flag - | "!?" -> cond_op_not_flag + | "&" -> cond_op_flag + | "!&" -> cond_op_not_flag match_stmt: "match" expr "{" (match_cases SEMICOLON*)? "}" match_const_stmt: "matchc" expr "{" (match_cases SEMICOLON*)? "}" @@ -354,8 +354,8 @@ class Compile(Transformer): def cond_op_gt(self, tree): return { "if": "ScriptOpcode_IF_GT", "case": "ScriptOpcode_CASE_GT" } def cond_op_le(self, tree): return { "if": "ScriptOpcode_IF_LE", "case": "ScriptOpcode_CASE_LE" } def cond_op_ge(self, tree): return { "if": "ScriptOpcode_IF_GE", "case": "ScriptOpcode_CASE_GE" } - def cond_op_flag(self, tree): return { "__op__": "!?", "if": "ScriptOpcode_IF_FLAG", "case": "ScriptOpcode_CASE_FLAG" } - def cond_op_not_flag(self, tree): return { "if": "ScriptOpcode_IF_NOT_FLAG" } + def cond_op_flag(self, tree): return { "__op__": "&", "if": "ScriptOpcode_IF_FLAG", "case": "ScriptOpcode_CASE_FLAG" } + def cond_op_not_flag(self, tree): return { "__op__": "!&", "if": "ScriptOpcode_IF_NOT_FLAG" } def match_stmt(self, tree): expr = tree.children[0] diff --git a/tools/disasm_script.py b/tools/disasm_script.py index 840c674b28..75d58efd81 100755 --- a/tools/disasm_script.py +++ b/tools/disasm_script.py @@ -482,10 +482,10 @@ class ScriptDSLDisassembler(ScriptDisassembler): self.write_line(f"if ({self.var(argv[0])} >= {self.var(argv[1])}) {{") self.indent += 1 elif opcode == 0x10: - self.write_line(f"if ({self.var(argv[0])} ? {self.var(argv[1])}) {{") + self.write_line(f"if ({self.var(argv[0])} & {self.var(argv[1])}) {{") self.indent += 1 elif opcode == 0x11: - self.write_line(f"if ({self.var(argv[0])} !? {self.var(argv[1])}) {{") + self.write_line(f"if ({self.var(argv[0])} !& {self.var(argv[1])}) {{") self.indent += 1 elif opcode == 0x12: self.indent -= 1 From ea1bec4399372b547e966c908999d5fa5f9f6427 Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 11:49:29 +0000 Subject: [PATCH 10/16] ok --- src/battle/actor/goomba.c | 104 +++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index c426a96abe..9f69136610 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -186,85 +186,85 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ match SI_VAR(0) { 9, 10 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260005; + SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoNormalHit; } == 14 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260009; - SI_VAR(2) = c 0x26000A; + SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_pain); + SI_VAR(2) = c NPC_ANIM(goomba, normal, burn_dead); await DoBurnHit; } == 36 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260009; - SI_VAR(2) = c 0x26000A; + SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_pain); + SI_VAR(2) = c NPC_ANIM(goomba, normal, burn_dead); await DoBurnHit; SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x26000A; + SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_dead); await DoDeath; return; } == 11 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260005; + SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoSpinSmashHit; } == 33 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260005; + SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoSpinSmashHit; SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260006; + SI_VAR(1) = c NPC_ANIM(goomba, normal, dead); await DoDeath; return; } == 47 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x26000E; + SI_VAR(1) = c NPC_ANIM(goomba, normal, electrocute); await DoShockHit; SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260005; + SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoJumpBack; JumpToGoal(ActorID_SELF, 5, 0, 1, 0); SetAnimationRate(ActorID_SELF, 1, 2.0); - SetAnimation(ActorID_SELF, 1, 0x260007); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, dizzy)); SetGoalToHome(ActorID_SELF); SetActorSpeed(ActorID_SELF, 8.0); RunToGoal(ActorID_SELF, 0, 0); SetAnimationRate(ActorID_SELF, 1, 1.0); sleep 5; - SetAnimation(ActorID_SELF, 1, 0x260001); - SetActorJumpGravity(ActorID_SELF, 1.6005859375); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, idle)); + SetActorJumpGravity(ActorID_SELF, 1.6); JumpToGoal(ActorID_SELF, 5, 0, 1, 0); } == 38 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x26000E; + SI_VAR(1) = c NPC_ANIM(goomba, normal, electrocute); await DoShockHit; SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260006; + SI_VAR(1) = c NPC_ANIM(goomba, normal, dead); await DoDeath; return; } == 19, 23, 25, 31 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260001; + SI_VAR(1) = c NPC_ANIM(goomba, normal, idle); await DoImmune; } == 32 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260005; + SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoNormalHit; sleep 10; SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260006; + SI_VAR(1) = c NPC_ANIM(goomba, normal, dead); await DoDeath; return; } == 53 { SetAnimationRate(ActorID_SELF, 1, 2.0); - SetAnimation(ActorID_SELF, 1, 0x260003); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, run)); SetGoalToHome(ActorID_SELF); SetActorSpeed(ActorID_SELF, 4.0); RunToGoal(ActorID_SELF, 0, 0); @@ -273,30 +273,30 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ } == 49 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260001; + SI_VAR(1) = c NPC_ANIM(goomba, normal, idle); await DoRecover; } == 57 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260003; - SI_VAR(2) = c 0x260005; + SI_VAR(1) = c NPC_ANIM(goomba, normal, run); + SI_VAR(2) = c NPC_ANIM(goomba, normal, pain); await DoScareAway; return; } == 58 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260003; + SI_VAR(1) = c NPC_ANIM(goomba, normal, run); await DoAirLift; } == 22 { SI_VAR(0) = c 0x1; - SI_VAR(1) = c 0x260005; + SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoBlowAway; return; } else { } } - SetAnimation(ActorID_SELF, 1, 0x260001); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, idle)); EnableIdleScript(ActorID_SELF, 1); UseIdleAnimation(ActorID_SELF, 1); }); @@ -325,18 +325,18 @@ Script script_TakeTurn_8021A300 = SCRIPT({ UseCamPreset(63); BattleCamTargetActor(ActorID_SELF); 0x8024ECF8(-1, 1, 0); - SetAnimation(ActorID_SELF, 1, 0x260003); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, run)); SetGoalToTarget(ActorID_SELF); AddGoalPos(ActorID_SELF, 50, 0, 0); SetActorSpeed(ActorID_SELF, 6.0); RunToGoal(ActorID_SELF, 0, 0); - SetAnimation(ActorID_SELF, 1, 0x260001); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, idle)); SetActorDispOffset(ActorID_SELF, 0, -1, 0); sleep 1; - SetActorDispOffset(ActorID_SELF, 0, 0xFFFFFFFE, 0); + SetActorDispOffset(ActorID_SELF, 0, -2, 0); sleep 5; SetActorDispOffset(ActorID_SELF, 0, 0, 0); - SetAnimation(ActorID_SELF, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, headbonk)); EnemyTestTarget(ActorID_SELF, SI_VAR(0), 0, 0, 1, 16); match SI_VAR(0) { 6, 5 { @@ -347,7 +347,7 @@ Script script_TakeTurn_8021A300 = SCRIPT({ SI_VAR(1) = 10; SI_VAR(2) += 3; SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); - SetActorJumpGravity(ActorID_SELF, 1.2001953125); + SetActorJumpGravity(ActorID_SELF, 1.2); spawn { GetActorPos(ActorID_SELF, SI_VAR(1), SI_VAR(2), SI_VAR(0)); SI_VAR(0) = 0; @@ -363,26 +363,26 @@ Script script_TakeTurn_8021A300 = SCRIPT({ } spawn { sleep 6; - SetAnimation(ActorID_SELF, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, headbonk)); } JumpToGoal(ActorID_SELF, 16, 0, 1, 0); - SetAnimation(ActorID_SELF, 1, 0x260008); - SetActorScale(ActorID_SELF, 1.1005859375, 0.80078125, 1.0); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, asleep)); + SetActorScale(ActorID_SELF, 1.1, 0.8, 1.0); SetActorDispOffset(ActorID_SELF, 0, 5, 0); sleep 1; - SetActorScale(ActorID_SELF, 1.30078125, 0.5, 1.0); - SetActorDispOffset(ActorID_SELF, 0, 0xFFFFFFFE, 0); + SetActorScale(ActorID_SELF, 1.3, 0.5, 1.0); + SetActorDispOffset(ActorID_SELF, 0, -2, 0); sleep 1; SetActorScale(ActorID_SELF, 1.0, 1.0, 1.0); SetActorDispOffset(ActorID_SELF, 0, 7, 0); - SetAnimation(ActorID_SELF, 1, 0x260005); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, pain)); sleep 5; if (SI_VAR(10) == 5) { EnemyTestTarget(ActorID_SELF, SI_VAR(0), 0x80000000, 0, 0, 0); } sleep 5; SetActorDispOffset(ActorID_SELF, 0, 0, 0); - SetAnimation(ActorID_SELF, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, headbonk)); SetGoalToTarget(ActorID_SELF); GetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) += 20; @@ -397,10 +397,10 @@ Script script_TakeTurn_8021A300 = SCRIPT({ SetActorRotation(ActorID_SELF, 0, 0, SI_VAR(0)); sleep 1; } - SetAnimation(ActorID_SELF, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, headbonk)); } JumpToGoal(ActorID_SELF, 15, 0, 1, 0); - SetAnimation(ActorID_SELF, 1, 0x260007); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, dizzy)); sleep 5; UseCamPreset(2); YieldTurn(); @@ -413,8 +413,8 @@ Script script_TakeTurn_8021A300 = SCRIPT({ SetAnimationRate(ActorID_SELF, 1, 1.0); SetActorYaw(ActorID_SELF, 0); sleep 5; - SetAnimation(ActorID_SELF, 1, 0x260001); - SetActorJumpGravity(ActorID_SELF, 1.6005859375); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, idle)); + SetActorJumpGravity(ActorID_SELF, 1.6); JumpToGoal(ActorID_SELF, 5, 0, 1, 0); RemoveActorDecoration(ActorID_SELF, 1, 0); EnableIdleScript(ActorID_SELF, 1); @@ -422,7 +422,7 @@ Script script_TakeTurn_8021A300 = SCRIPT({ return; } else { SetGoalToTarget(ActorID_SELF); - SetActorJumpGravity(ActorID_SELF, 1.2001953125); + SetActorJumpGravity(ActorID_SELF, 1.2); spawn { GetActorPos(ActorID_SELF, SI_VAR(1), SI_VAR(2), SI_VAR(0)); SI_VAR(0) = 0; @@ -438,13 +438,13 @@ Script script_TakeTurn_8021A300 = SCRIPT({ } spawn { sleep 6; - SetAnimation(ActorID_SELF, 1, 0x260004); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, headbonk)); } JumpToGoal(ActorID_SELF, 16, 0, 1, 0); - SetAnimation(ActorID_SELF, 1, 0x26000B); - SetActorScale(ActorID_SELF, 1.1005859375, 0.80078125, 1.0); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, pre_headbonk)); + SetActorScale(ActorID_SELF, 1.1, 0.8, 1.0); sleep 1; - SetActorScale(ActorID_SELF, 1.30078125, 0.5, 1.0); + SetActorScale(ActorID_SELF, 1.3, 0.5, 1.0); sleep 1; } } @@ -452,17 +452,17 @@ Script script_TakeTurn_8021A300 = SCRIPT({ match SI_VAR(0) { 0, 2 { UseCamPreset(2); - SetActorScale(ActorID_SELF, 1.1005859375, 0.80078125, 1.0); + SetActorScale(ActorID_SELF, 1.1, 0.8, 1.0); sleep 1; SetActorScale(ActorID_SELF, 1.0, 1.0, 1.0); sleep 1; SetActorRotation(ActorID_SELF, 0, 0, 0); SetActorDispOffset(ActorID_SELF, 0, 0, 0); - SetAnimation(ActorID_SELF, 1, 0x260001); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, idle)); GetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) += 40; SI_VAR(1) = 0; - SetActorJumpGravity(ActorID_SELF, 1.80078125); + SetActorJumpGravity(ActorID_SELF, 1.8); SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); JumpToGoal(ActorID_SELF, 10, 0, 1, 0); SI_VAR(0) += 30; @@ -471,11 +471,11 @@ Script script_TakeTurn_8021A300 = SCRIPT({ SI_VAR(0) += 20; SetGoalPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); JumpToGoal(ActorID_SELF, 6, 0, 1, 0); - SetAnimation(ActorID_SELF, 1, 0x260001); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, idle)); sleep 3; YieldTurn(); SetAnimationRate(ActorID_SELF, 1, 2.0); - SetAnimation(ActorID_SELF, 1, 0x260003); + SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, run)); SetGoalToHome(ActorID_SELF); SetActorSpeed(ActorID_SELF, 8.0); RunToGoal(ActorID_SELF, 0, 0); From 519910fae9b44b57d3d71be4ccf06c946b9955fb Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 11:55:58 +0000 Subject: [PATCH 11/16] use Event enum --- src/battle/actor/goomba.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index 9f69136610..ba8cbc2868 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -184,18 +184,18 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ SetActorScale(ActorID_SELF, 1.0, 1.0, 1.0); GetLastEvent(ActorID_SELF, SI_VAR(0)); match SI_VAR(0) { - 9, 10 { + Event_HIT_COMBO, Event_HIT { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoNormalHit; } - == 14 { + == Event_BURN_HIT { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_pain); SI_VAR(2) = c NPC_ANIM(goomba, normal, burn_dead); await DoBurnHit; } - == 36 { + == Event_BURN_DEATH { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_pain); SI_VAR(2) = c NPC_ANIM(goomba, normal, burn_dead); @@ -205,12 +205,12 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ await DoDeath; return; } - == 11 { + == Event_SPIN_SMASH_HIT { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoSpinSmashHit; } - == 33 { + == Event_SPIN_SMASH_DEATH { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoSpinSmashHit; @@ -219,7 +219,7 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ await DoDeath; return; } - == 47 { + == Event_SHOCK_HIT { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, electrocute); await DoShockHit; @@ -238,7 +238,7 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ SetActorJumpGravity(ActorID_SELF, 1.6); JumpToGoal(ActorID_SELF, 5, 0, 1, 0); } - == 38 { + == Event_SHOCK_DEATH { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, electrocute); await DoShockHit; @@ -247,12 +247,12 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ await DoDeath; return; } - == 19, 23, 25, 31 { + == Event_STAR_BEAM, 23, Event_IMMUNE, Event_AIR_LIFT_FAILED { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, idle); await DoImmune; } - == 32 { + == Event_DEATH { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoNormalHit; @@ -262,7 +262,7 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ await DoDeath; return; } - == 53 { + == Event_END_FIRST_STRIKE { SetAnimationRate(ActorID_SELF, 1, 2.0); SetAnimation(ActorID_SELF, 1, NPC_ANIM(goomba, normal, run)); SetGoalToHome(ActorID_SELF); @@ -271,24 +271,24 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ SetAnimationRate(ActorID_SELF, 1, 1.0); HPBarToHome(ActorID_SELF); } - == 49 { + == Event_RECOVER_STATUS { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, idle); await DoRecover; } - == 57 { + == Event_SCARE_AWAY { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, run); SI_VAR(2) = c NPC_ANIM(goomba, normal, pain); await DoScareAway; return; } - == 58 { + == Event_BEGIN_AIR_LIFT { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, run); await DoAirLift; } - == 22 { + == Event_BLOW_AWAY { SI_VAR(0) = c 0x1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoBlowAway; From f620285ad375379c5b8244b69dd4a7fe7533d361 Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 12:47:32 +0000 Subject: [PATCH 12/16] goomba updates --- src/battle/actor/goomba.c | 64 ++++++++++++++--------------- src/battle/actor/goomba.h | 1 + src/battle/area_kmr_part_1/4309A0.c | 2 +- 3 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index ba8cbc2868..a379ede9f9 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -5,26 +5,26 @@ #include "goomba.h" ApiStatus func_8021818C_430B2C(ScriptInstance* script, s32 isInitialCall); -s32 idleAnimations_80219760[]; -s32 idleAnimations_80219714[]; -s32 defenseTable_80219610[]; -s32 statusTable_8021961C[]; -s32 defenseTable_80219610[]; -ActorPartDesc partsTable_802196C8[]; -Script script_Init_802197AC; -Script script_TakeTurn_8021A300; -Script script_Idle_802197F8; -Script script_HandleEvent_80219AD4; +s32 goomba_anims_running[]; +s32 goomba_anims[]; +s32 goomba_defense_table[]; +s32 goomba_status_table[]; +s32 goomba_defense_table[]; +ActorPartDesc goomba_parts[]; +Script goomba_init; +Script goomba_turn; +Script goomba_idle; +Script goomba_dispatch; // 431FB0-431FBC (VRAM: 80219610) -s32 defenseTable_80219610[] = { +s32 goomba_defense_table[] = { Element_NORMAL, 0, Element_END, }; // 431FBC-432068 (VRAM: 8021961C) -s32 statusTable_8021961C[] = { +s32 goomba_status_table[] = { Debuff_NORMAL, 0, Debuff_DEFAULT, 0, Debuff_SLEEP, 100, @@ -52,15 +52,15 @@ s32 statusTable_8021961C[] = { }; // 432068-43208C (VRAM: 802196C8) -ActorPartDesc partsTable_802196C8[] = { +ActorPartDesc goomba_parts[] = { { .flags = 0x00800000, .index = 1, .posOffset = { 0, 0, 0 }, .targetOffset = { 0, 0x14 }, .opacity = 0xFF, - .idleAnimations = idleAnimations_80219714, - .defenseTable = defenseTable_80219610, + .idleAnimations = goomba_anims, + .defenseTable = goomba_defense_table, .eventFlags = 0, .elementImmunityFlags = 0, 0x00, 0xF6, @@ -74,9 +74,9 @@ ActorDesc goomba = { .level = 5, .maxHP = 2, .partCount = 1, - .partsData = &partsTable_802196C8, - .script = &script_Init_802197AC, - .statusTable = &statusTable_8021961C, + .partsData = &goomba_parts, + .script = &goomba_init, + .statusTable = &goomba_status_table, .escapeChance = 90, .airLiftChance = 100, .spookChance = 90, @@ -92,7 +92,7 @@ ActorDesc goomba = { }; // 4320B4-432100 (VRAM: 80219714) -s32 idleAnimations_80219714[] = { +s32 goomba_anims[] = { Debuff_NORMAL, NPC_ANIM(goomba, normal, idle), Debuff_STONE, NPC_ANIM(goomba, normal, still), Debuff_SLEEP, NPC_ANIM(goomba, normal, asleep), @@ -107,7 +107,7 @@ s32 idleAnimations_80219714[] = { }; // 432100-43214C (VRAM: 80219760) -s32 idleAnimations_80219760[] = { +s32 goomba_anims_running[] = { Debuff_NORMAL, NPC_ANIM(goomba, normal, run), Debuff_STONE, NPC_ANIM(goomba, normal, still), Debuff_SLEEP, NPC_ANIM(goomba, normal, asleep), @@ -122,14 +122,14 @@ s32 idleAnimations_80219760[] = { }; // 43214C-432198 (VRAM: 802197AC) -Script script_Init_802197AC = SCRIPT({ - BindTakeTurn(ActorID_SELF, script_TakeTurn_8021A300); - BindIdle(ActorID_SELF, script_Idle_802197F8); - BindHandleEvent(ActorID_SELF, script_HandleEvent_80219AD4); +Script goomba_init = SCRIPT({ + BindTakeTurn(ActorID_SELF, goomba_turn); + BindIdle(ActorID_SELF, goomba_idle); + BindHandleEvent(ActorID_SELF, goomba_dispatch); }); // 432198-432474 (VRAM: 802197F8) -Script script_Idle_802197F8 = SCRIPT({ +Script goomba_idle = SCRIPT({ 10: RandInt(80, SI_VAR(0)); SI_VAR(0) += 80; @@ -145,10 +145,10 @@ Script script_Idle_802197F8 = SCRIPT({ GetActorPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) += 5; SetActorIdleSpeed(ActorID_SELF, 1.0); - SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219760); + SetIdleAnimations(ActorID_SELF, 1, goomba_anims_running); SetIdleGoal(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); IdleRunToGoal(ActorID_SELF, 0); - SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219714); + SetIdleAnimations(ActorID_SELF, 1, goomba_anims); loop 20 { 1: GetStatusFlags(ActorID_SELF, SI_VAR(1)); @@ -161,10 +161,10 @@ Script script_Idle_802197F8 = SCRIPT({ GetActorPos(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); SI_VAR(0) -= 5; SetActorIdleSpeed(ActorID_SELF, 1.0); - SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219760); + SetIdleAnimations(ActorID_SELF, 1, goomba_anims_running); SetIdleGoal(ActorID_SELF, SI_VAR(0), SI_VAR(1), SI_VAR(2)); IdleRunToGoal(ActorID_SELF, 0); - SetIdleAnimations(ActorID_SELF, 1, idleAnimations_80219714); + SetIdleAnimations(ActorID_SELF, 1, goomba_anims); loop 80 { 2: GetStatusFlags(ActorID_SELF, SI_VAR(1)); @@ -178,7 +178,7 @@ Script script_Idle_802197F8 = SCRIPT({ }); // 432474-432B34 (VRAM: 80219AD4) -Script script_HandleEvent_80219AD4 = SCRIPT({ +Script goomba_dispatch = SCRIPT({ UseIdleAnimation(ActorID_SELF, 0); EnableIdleScript(ActorID_SELF, 0); SetActorScale(ActorID_SELF, 1.0, 1.0, 1.0); @@ -302,7 +302,7 @@ Script script_HandleEvent_80219AD4 = SCRIPT({ }); // 432B34-432CA0 (VRAM: 8021A194) -f32 floatTable_8021A194[] = { +f32 float_table_for_func_80218000[] = { 0.000000f, 0.017452f, 0.034899f, 0.052336f, 0.069756f, 0.087156f, 0.104528f, 0.121869f, 0.139173f, 0.156434f, 0.173648f, 0.190809f, 0.207912f, 0.224951f, 0.241922f, 0.258819f, 0.275637f, 0.292372f, 0.309017f, 0.325568f, 0.342020f, 0.358368f, 0.374607f, 0.390731f, @@ -318,7 +318,7 @@ f32 floatTable_8021A194[] = { }; // 432CA0-433968 (VRAM: 8021A300) -Script script_TakeTurn_8021A300 = SCRIPT({ +Script goomba_turn = SCRIPT({ UseIdleAnimation(ActorID_SELF, 0); EnableIdleScript(ActorID_SELF, 0); SetTargetActor(ActorID_SELF, 0); diff --git a/src/battle/actor/goomba.h b/src/battle/actor/goomba.h index 6bdb5a5f59..3845021230 100644 --- a/src/battle/actor/goomba.h +++ b/src/battle/actor/goomba.h @@ -2,6 +2,7 @@ #define _BATTLE_ACTOR_GOOMBA_ #include "common.h" +#include "battle/battle.h" ActorDesc goomba; diff --git a/src/battle/area_kmr_part_1/4309A0.c b/src/battle/area_kmr_part_1/4309A0.c index e755dbb50f..6718a11dc6 100644 --- a/src/battle/area_kmr_part_1/4309A0.c +++ b/src/battle/area_kmr_part_1/4309A0.c @@ -1,6 +1,6 @@ #include "common.h" -INCLUDE_ASM(s32, "battle/area_kmr_part_1/4309A0", func_80218000_4309A0); +INCLUDE_ASM(s32, "battle/area_kmr_part_1/4309A0", func_80218000_4309A0); // goomba.c INCLUDE_ASM(s32, "battle/area_kmr_part_1/4309A0", func_8021818C_430B2C); From 508a61c4d274bb27311b5d5f25f9edcfb30d1b5c Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Tue, 29 Dec 2020 16:28:00 +0000 Subject: [PATCH 13/16] use new vscode extension --- .vscode/extensions.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index a40435c7fa..8e081bdb4d 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,7 +1,7 @@ { "recommendations": [ "ms-vscode.cpptools", - "nanaian.vscode-star-rod", + "nanaian.papermario", "notskm.clang-tidy", "EditorConfig.EditorConfig", ], From 3ddb184ab9b3c5e6f6edf86e82a7874089335ccb Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Wed, 30 Dec 2020 09:31:26 +0000 Subject: [PATCH 14/16] remove comments --- src/battle/actor/goomba.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index a379ede9f9..5ee31949d2 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -16,14 +16,12 @@ Script goomba_turn; Script goomba_idle; Script goomba_dispatch; -// 431FB0-431FBC (VRAM: 80219610) s32 goomba_defense_table[] = { Element_NORMAL, 0, Element_END, }; -// 431FBC-432068 (VRAM: 8021961C) s32 goomba_status_table[] = { Debuff_NORMAL, 0, Debuff_DEFAULT, 0, @@ -51,7 +49,6 @@ s32 goomba_status_table[] = { Debuff_END, }; -// 432068-43208C (VRAM: 802196C8) ActorPartDesc goomba_parts[] = { { .flags = 0x00800000, @@ -67,7 +64,6 @@ ActorPartDesc goomba_parts[] = { }, }; -// 43208C-4320B4 (VRAM: 802196EC) ActorDesc goomba = { .flags = 0, .type = 7, @@ -91,7 +87,6 @@ ActorDesc goomba = { .statusMessageOffset = { 10, 20 }, }; -// 4320B4-432100 (VRAM: 80219714) s32 goomba_anims[] = { Debuff_NORMAL, NPC_ANIM(goomba, normal, idle), Debuff_STONE, NPC_ANIM(goomba, normal, still), @@ -106,7 +101,6 @@ s32 goomba_anims[] = { Debuff_END, }; -// 432100-43214C (VRAM: 80219760) s32 goomba_anims_running[] = { Debuff_NORMAL, NPC_ANIM(goomba, normal, run), Debuff_STONE, NPC_ANIM(goomba, normal, still), @@ -121,14 +115,12 @@ s32 goomba_anims_running[] = { Debuff_END, }; -// 43214C-432198 (VRAM: 802197AC) Script goomba_init = SCRIPT({ BindTakeTurn(ActorID_SELF, goomba_turn); BindIdle(ActorID_SELF, goomba_idle); BindHandleEvent(ActorID_SELF, goomba_dispatch); }); -// 432198-432474 (VRAM: 802197F8) Script goomba_idle = SCRIPT({ 10: RandInt(80, SI_VAR(0)); @@ -177,7 +169,6 @@ Script goomba_idle = SCRIPT({ goto 10; }); -// 432474-432B34 (VRAM: 80219AD4) Script goomba_dispatch = SCRIPT({ UseIdleAnimation(ActorID_SELF, 0); EnableIdleScript(ActorID_SELF, 0); @@ -301,7 +292,6 @@ Script goomba_dispatch = SCRIPT({ UseIdleAnimation(ActorID_SELF, 1); }); -// 432B34-432CA0 (VRAM: 8021A194) f32 float_table_for_func_80218000[] = { 0.000000f, 0.017452f, 0.034899f, 0.052336f, 0.069756f, 0.087156f, 0.104528f, 0.121869f, 0.139173f, 0.156434f, 0.173648f, 0.190809f, 0.207912f, 0.224951f, 0.241922f, 0.258819f, @@ -317,7 +307,6 @@ f32 float_table_for_func_80218000[] = { 0.999391f, 0.999848f, 1.000000f, }; -// 432CA0-433968 (VRAM: 8021A300) Script goomba_turn = SCRIPT({ UseIdleAnimation(ActorID_SELF, 0); EnableIdleScript(ActorID_SELF, 0); From 87e2e13eedfd410f7b89107ddad3c32bfba40a77 Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Wed, 30 Dec 2020 09:33:40 +0000 Subject: [PATCH 15/16] clean up --- src/battle/actor/goomba.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/battle/actor/goomba.c b/src/battle/actor/goomba.c index 5ee31949d2..1ed7f9d1e1 100644 --- a/src/battle/actor/goomba.c +++ b/src/battle/actor/goomba.c @@ -54,7 +54,7 @@ ActorPartDesc goomba_parts[] = { .flags = 0x00800000, .index = 1, .posOffset = { 0, 0, 0 }, - .targetOffset = { 0, 0x14 }, + .targetOffset = { 0, 20 }, .opacity = 0xFF, .idleAnimations = goomba_anims, .defenseTable = goomba_defense_table, @@ -176,45 +176,45 @@ Script goomba_dispatch = SCRIPT({ GetLastEvent(ActorID_SELF, SI_VAR(0)); match SI_VAR(0) { Event_HIT_COMBO, Event_HIT { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoNormalHit; } == Event_BURN_HIT { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_pain); SI_VAR(2) = c NPC_ANIM(goomba, normal, burn_dead); await DoBurnHit; } == Event_BURN_DEATH { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_pain); SI_VAR(2) = c NPC_ANIM(goomba, normal, burn_dead); await DoBurnHit; - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, burn_dead); await DoDeath; return; } == Event_SPIN_SMASH_HIT { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoSpinSmashHit; } == Event_SPIN_SMASH_DEATH { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoSpinSmashHit; - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, dead); await DoDeath; return; } == Event_SHOCK_HIT { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, electrocute); await DoShockHit; - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoJumpBack; JumpToGoal(ActorID_SELF, 5, 0, 1, 0); @@ -230,25 +230,25 @@ Script goomba_dispatch = SCRIPT({ JumpToGoal(ActorID_SELF, 5, 0, 1, 0); } == Event_SHOCK_DEATH { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, electrocute); await DoShockHit; - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, dead); await DoDeath; return; } == Event_STAR_BEAM, 23, Event_IMMUNE, Event_AIR_LIFT_FAILED { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, idle); await DoImmune; } == Event_DEATH { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoNormalHit; sleep 10; - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, dead); await DoDeath; return; @@ -263,24 +263,24 @@ Script goomba_dispatch = SCRIPT({ HPBarToHome(ActorID_SELF); } == Event_RECOVER_STATUS { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, idle); await DoRecover; } == Event_SCARE_AWAY { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, run); SI_VAR(2) = c NPC_ANIM(goomba, normal, pain); await DoScareAway; return; } == Event_BEGIN_AIR_LIFT { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, run); await DoAirLift; } == Event_BLOW_AWAY { - SI_VAR(0) = c 0x1; + SI_VAR(0) = c 1; SI_VAR(1) = c NPC_ANIM(goomba, normal, pain); await DoBlowAway; return; From fdf9454cde476668dd2d18ea7374a67b1ef5f00b Mon Sep 17 00:00:00 2001 From: Alex Bates Date: Wed, 30 Dec 2020 09:36:44 +0000 Subject: [PATCH 16/16] extern ActorDescs --- src/battle/actor/paragoomba.h | 4 +++- src/battle/actor/spiked_goomba.h | 4 +++- src/battle/area_kmr_part_1/battles.c | 24 ++++++++++++------------ undefined_syms.txt | 3 +++ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/battle/actor/paragoomba.h b/src/battle/actor/paragoomba.h index 0f90efadec..1bea71359c 100644 --- a/src/battle/actor/paragoomba.h +++ b/src/battle/actor/paragoomba.h @@ -1,7 +1,9 @@ #ifndef _BATTLE_ACTOR_PARAGOOMBA_ #define _BATTLE_ACTOR_PARAGOOMBA_ +#include "battle/battle.h" + // TODO: disasm -#define paragoomba 0x8021CD00 +extern ActorDesc paragoomba; #endif diff --git a/src/battle/actor/spiked_goomba.h b/src/battle/actor/spiked_goomba.h index 0c1b89f363..f4a8bb9eb1 100644 --- a/src/battle/actor/spiked_goomba.h +++ b/src/battle/actor/spiked_goomba.h @@ -1,7 +1,9 @@ #ifndef _BATTLE_ACTOR_SPIKED_GOOMBA_ #define _BATTLE_ACTOR_SPIKED_GOOMBA_ +#include "battle/battle.h" + // TODO: disasm -#define spikedGoomba 0x8021B0AC +extern ActorDesc spiked_goomba; #endif diff --git a/src/battle/area_kmr_part_1/battles.c b/src/battle/area_kmr_part_1/battles.c index 2acb47e752..5b2401b56f 100644 --- a/src/battle/area_kmr_part_1/battles.c +++ b/src/battle/area_kmr_part_1/battles.c @@ -22,7 +22,7 @@ Formation formation2 = { Formation formation3 = { { &goomba, .position = 1, .priority = 10 }, - { paragoomba, .position = 6, .priority = 9 }, + { ¶goomba, .position = 6, .priority = 9 }, }; Formation formation4 = { @@ -34,37 +34,37 @@ Formation formation4 = { Formation formation5 = { { &goomba, .position = 1, .priority = 10 }, - { spikedGoomba, .position = 2, .priority = 9 }, + { &spiked_goomba, .position = 2, .priority = 9 }, }; Formation formation6 = { { &goomba, .position = 0, .priority = 10 }, - { paragoomba, .position = 5, .priority = 9 }, + { ¶goomba, .position = 5, .priority = 9 }, { &goomba, .position = 2, .priority = 8 }, - { paragoomba, .position = 7, .priority = 7 }, + { ¶goomba, .position = 7, .priority = 7 }, }; Formation formation7 = { - { paragoomba, .position = 5, .priority = 10 }, + { ¶goomba, .position = 5, .priority = 10 }, }; Formation formation8 = { - { paragoomba, .position = 5, .priority = 10 }, - { paragoomba, .position = 6, .priority = 9 }, + { ¶goomba, .position = 5, .priority = 10 }, + { ¶goomba, .position = 6, .priority = 9 }, }; Formation formation9 = { - { paragoomba, .position = 4, .priority = 10 }, - { paragoomba, .position = 5, .priority = 9 }, - { paragoomba, .position = 6, .priority = 8 }, + { ¶goomba, .position = 4, .priority = 10 }, + { ¶goomba, .position = 5, .priority = 9 }, + { ¶goomba, .position = 6, .priority = 8 }, }; Formation formation10 = { - { spikedGoomba, .position = 1, .priority = 10 }, + { &spiked_goomba, .position = 1, .priority = 10 }, }; Formation formation11 = { - { spikedGoomba, .position = 1, .priority = 10 }, + { &spiked_goomba, .position = 1, .priority = 10 }, { &goomba, .position = 2, .priority = 9 }, }; diff --git a/undefined_syms.txt b/undefined_syms.txt index b8eb46d8db..263fae24e2 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -357,3 +357,6 @@ D_DE0079B8 = 0xDE0079B8; D_DE003E00 = 0xDE003E00; D_C1F06370 = 0xC1F06370; D_DE001F00 = 0xDE001F00; + +paragoomba = 0x8021CD00; +spiked_goomba = 0x8021B0AC;