diff --git a/asm/nonmatchings/si/si_execute_next_command.s b/asm/nonmatchings/si/si_execute_next_command.s index c5f4ae4cb5..63c0d201bd 100644 --- a/asm/nonmatchings/si/si_execute_next_command.s +++ b/asm/nonmatchings/si/si_execute_next_command.s @@ -16,7 +16,7 @@ glabel si_execute_next_command /* EBDDC 802C742C 00220821 */ addu $at, $at, $v0 /* EBDE0 802C7430 8C229F20 */ lw $v0, -0x60e0($at) /* EBDE4 802C7434 00400008 */ jr $v0 -/* EBDE8 802C7438 00000000 */ nop +/* EBDE8 802C7438 00000000 */ nop /* EBDEC 802C743C 8E030008 */ lw $v1, 8($s0) /* EBDF0 802C7440 24050003 */ addiu $a1, $zero, 3 /* EBDF4 802C7444 0060102D */ daddu $v0, $v1, $zero @@ -57,11 +57,11 @@ glabel si_execute_next_command /* EBE80 802C74D0 0200202D */ daddu $a0, $s0, $zero /* EBE84 802C74D4 080B1E95 */ j .L802C7A54 /* EBE88 802C74D8 0040282D */ daddu $a1, $v0, $zero -/* EBE8C 802C74DC 0C0B12D7 */ jal si_handle_wait +/* EBE8C 802C74DC 0C0B12D7 */ jal si_handle_sleep_frames /* EBE90 802C74E0 0200202D */ daddu $a0, $s0, $zero /* EBE94 802C74E4 080B1E95 */ j .L802C7A54 /* EBE98 802C74E8 0040282D */ daddu $a1, $v0, $zero -/* EBE9C 802C74EC 0C0B12EE */ jal si_handle_wait_seconds +/* EBE9C 802C74EC 0C0B12EE */ jal si_handle_sleep_seconds /* EBEA0 802C74F0 0200202D */ daddu $a0, $s0, $zero /* EBEA4 802C74F4 080B1E95 */ j .L802C7A54 /* EBEA8 802C74F8 0040282D */ daddu $a1, $v0, $zero @@ -89,11 +89,11 @@ glabel si_execute_next_command /* EBF00 802C7550 0200202D */ daddu $a0, $s0, $zero /* EBF04 802C7554 080B1E95 */ j .L802C7A54 /* EBF08 802C7558 0040282D */ daddu $a1, $v0, $zero -/* EBF0C 802C755C 0C0B13A4 */ jal si_handle_if_AND +/* EBF0C 802C755C 0C0B13A4 */ jal si_handle_if_flag /* EBF10 802C7560 0200202D */ daddu $a0, $s0, $zero /* EBF14 802C7564 080B1E95 */ j .L802C7A54 /* EBF18 802C7568 0040282D */ daddu $a1, $v0, $zero -/* EBF1C 802C756C 0C0B13BA */ jal si_handle_if_not_AND +/* EBF1C 802C756C 0C0B13BA */ jal si_handle_if_not_flag /* EBF20 802C7570 0200202D */ daddu $a0, $s0, $zero /* EBF24 802C7574 080B1E95 */ j .L802C7A54 /* EBF28 802C7578 0040282D */ daddu $a1, $v0, $zero @@ -105,11 +105,11 @@ glabel si_execute_next_command /* EBF40 802C7590 0200202D */ daddu $a0, $s0, $zero /* EBF44 802C7594 080B1E95 */ j .L802C7A54 /* EBF48 802C7598 0040282D */ daddu $a1, $v0, $zero -/* EBF4C 802C759C 0C0B13DD */ jal si_handle_switch +/* EBF4C 802C759C 0C0B13DD */ jal si_handle_match /* EBF50 802C75A0 0200202D */ daddu $a0, $s0, $zero /* EBF54 802C75A4 080B1E95 */ j .L802C7A54 /* EBF58 802C75A8 0040282D */ daddu $a1, $v0, $zero -/* EBF5C 802C75AC 0C0B13F9 */ jal si_handle_switch_const +/* EBF5C 802C75AC 0C0B13F9 */ jal si_handle_match_const /* EBF60 802C75B0 0200202D */ daddu $a0, $s0, $zero /* EBF64 802C75B4 080B1E95 */ j .L802C7A54 /* EBF68 802C75B8 0040282D */ daddu $a1, $v0, $zero @@ -137,27 +137,27 @@ glabel si_execute_next_command /* EBFC0 802C7610 0200202D */ daddu $a0, $s0, $zero /* EBFC4 802C7614 080B1E95 */ j .L802C7A54 /* EBFC8 802C7618 0040282D */ daddu $a1, $v0, $zero -/* EBFCC 802C761C 0C0B1511 */ jal si_handle_case_default +/* EBFCC 802C761C 0C0B1511 */ jal si_handle_case_else /* EBFD0 802C7620 0200202D */ daddu $a0, $s0, $zero /* EBFD4 802C7624 080B1E95 */ j .L802C7A54 /* EBFD8 802C7628 0040282D */ daddu $a1, $v0, $zero -/* EBFDC 802C762C 0C0B15B5 */ jal si_handle_break_case +/* EBFDC 802C762C 0C0B15B5 */ jal si_handle_break_match /* EBFE0 802C7630 0200202D */ daddu $a0, $s0, $zero /* EBFE4 802C7634 080B1E95 */ j .L802C7A54 /* EBFE8 802C7638 0040282D */ daddu $a1, $v0, $zero -/* EBFEC 802C763C 0C0B1546 */ jal si_handle_case_equal_OR +/* EBFEC 802C763C 0C0B1546 */ jal si_handle_case_multi_or_equal /* EBFF0 802C7640 0200202D */ daddu $a0, $s0, $zero /* EBFF4 802C7644 080B1E95 */ j .L802C7A54 /* EBFF8 802C7648 0040282D */ daddu $a1, $v0, $zero -/* EBFFC 802C764C 0C0B1597 */ jal si_handle_end_case_group +/* EBFFC 802C764C 0C0B1597 */ jal si_handle_end_case_multi /* EC000 802C7650 0200202D */ daddu $a0, $s0, $zero /* EC004 802C7654 080B1E95 */ j .L802C7A54 /* EC008 802C7658 0040282D */ daddu $a1, $v0, $zero -/* EC00C 802C765C 0C0B156E */ jal si_handle_case_equal_AND +/* EC00C 802C765C 0C0B156E */ jal si_handle_case_multi_and_equal /* EC010 802C7660 0200202D */ daddu $a0, $s0, $zero /* EC014 802C7664 080B1E95 */ j .L802C7A54 /* EC018 802C7668 0040282D */ daddu $a1, $v0, $zero -/* EC01C 802C766C 0C0B1527 */ jal si_handle_case_AND +/* EC01C 802C766C 0C0B1527 */ jal si_handle_case_flag /* EC020 802C7670 0200202D */ daddu $a0, $s0, $zero /* EC024 802C7674 080B1E95 */ j .L802C7A54 /* EC028 802C7678 0040282D */ daddu $a1, $v0, $zero @@ -165,7 +165,7 @@ glabel si_execute_next_command /* EC030 802C7680 0200202D */ daddu $a0, $s0, $zero /* EC034 802C7684 080B1E95 */ j .L802C7A54 /* EC038 802C7688 0040282D */ daddu $a1, $v0, $zero -/* EC03C 802C768C 0C0B15C6 */ jal si_handle_end_switch +/* EC03C 802C768C 0C0B15C6 */ jal si_handle_end_match /* EC040 802C7690 0200202D */ daddu $a0, $s0, $zero /* EC044 802C7694 080B1E95 */ j .L802C7A54 /* EC048 802C7698 0040282D */ daddu $a1, $v0, $zero @@ -277,7 +277,7 @@ glabel si_execute_next_command /* EC1F0 802C7840 0200202D */ daddu $a0, $s0, $zero /* EC1F4 802C7844 080B1E95 */ j .L802C7A54 /* EC1F8 802C7848 0040282D */ daddu $a1, $v0, $zero -/* EC1FC 802C784C 0C0B1A1C */ jal si_handle_kill +/* EC1FC 802C784C 0C0B1A1C */ jal si_handle_kill_script /* EC200 802C7850 0200202D */ daddu $a0, $s0, $zero /* EC204 802C7854 080B1E95 */ j .L802C7A54 /* EC208 802C7858 0040282D */ daddu $a1, $v0, $zero @@ -301,19 +301,19 @@ glabel si_execute_next_command /* EC250 802C78A0 0200202D */ daddu $a0, $s0, $zero /* EC254 802C78A4 080B1E95 */ j .L802C7A54 /* EC258 802C78A8 0040282D */ daddu $a1, $v0, $zero -/* EC25C 802C78AC 0C0B191B */ jal si_handle_exec1 +/* EC25C 802C78AC 0C0B191B */ jal si_handle_spawn_script /* EC260 802C78B0 0200202D */ daddu $a0, $s0, $zero /* EC264 802C78B4 080B1E95 */ j .L802C7A54 /* EC268 802C78B8 0040282D */ daddu $a1, $v0, $zero -/* EC26C 802C78BC 0C0B1949 */ jal si_handle_exec2 +/* EC26C 802C78BC 0C0B1949 */ jal si_handle_spawn_script_get_id /* EC270 802C78C0 0200202D */ daddu $a0, $s0, $zero /* EC274 802C78C4 080B1E95 */ j .L802C7A54 /* EC278 802C78C8 0040282D */ daddu $a1, $v0, $zero -/* EC27C 802C78CC 0C0B197F */ jal si_handle_exec_wait +/* EC27C 802C78CC 0C0B197F */ jal si_handle_await_script /* EC280 802C78D0 0200202D */ daddu $a0, $s0, $zero /* EC284 802C78D4 080B1E95 */ j .L802C7A54 /* EC288 802C78D8 0040282D */ daddu $a1, $v0, $zero -/* EC28C 802C78DC 0C0B19C5 */ jal si_handle_bind +/* EC28C 802C78DC 0C0B19C5 */ jal si_handle_bind_trigger /* EC290 802C78E0 0200202D */ daddu $a0, $s0, $zero /* EC294 802C78E4 080B1E95 */ j .L802C7A54 /* EC298 802C78E8 0040282D */ daddu $a1, $v0, $zero @@ -357,11 +357,11 @@ glabel si_execute_next_command /* EC330 802C7980 0200202D */ daddu $a0, $s0, $zero /* EC334 802C7984 080B1E95 */ j .L802C7A54 /* EC338 802C7988 0040282D */ daddu $a1, $v0, $zero -/* EC33C 802C798C 0C0B1A88 */ jal si_handle_suspend +/* EC33C 802C798C 0C0B1A88 */ jal si_handle_suspend_script /* EC340 802C7990 0200202D */ daddu $a0, $s0, $zero /* EC344 802C7994 080B1E95 */ j .L802C7A54 /* EC348 802C7998 0040282D */ daddu $a1, $v0, $zero -/* EC34C 802C799C 0C0B1A93 */ jal si_handle_resume +/* EC34C 802C799C 0C0B1A93 */ jal si_handle_resume_script /* EC350 802C79A0 0200202D */ daddu $a0, $s0, $zero /* EC354 802C79A4 080B1E95 */ j .L802C7A54 /* EC358 802C79A8 0040282D */ daddu $a1, $v0, $zero @@ -369,19 +369,19 @@ glabel si_execute_next_command /* EC360 802C79B0 0200202D */ daddu $a0, $s0, $zero /* EC364 802C79B4 080B1E95 */ j .L802C7A54 /* EC368 802C79B8 0040282D */ daddu $a1, $v0, $zero -/* EC36C 802C79BC 0C0B1B1E */ jal si_handle_thread +/* EC36C 802C79BC 0C0B1B1E */ jal si_handle_spawn_thread /* EC370 802C79C0 0200202D */ daddu $a0, $s0, $zero /* EC374 802C79C4 080B1E95 */ j .L802C7A54 /* EC378 802C79C8 0040282D */ daddu $a1, $v0, $zero -/* EC37C 802C79CC 0C0B1B53 */ jal si_handle_end_thread +/* EC37C 802C79CC 0C0B1B53 */ jal si_handle_end_spawn_thread /* EC380 802C79D0 0200202D */ daddu $a0, $s0, $zero /* EC384 802C79D4 080B1E95 */ j .L802C7A54 /* EC388 802C79D8 0040282D */ daddu $a1, $v0, $zero -/* EC38C 802C79DC 0C0B1B5B */ jal si_handle_child_thread +/* EC38C 802C79DC 0C0B1B5B */ jal si_handle_parallel_thread /* EC390 802C79E0 0200202D */ daddu $a0, $s0, $zero /* EC394 802C79E4 080B1E95 */ j .L802C7A54 /* EC398 802C79E8 0040282D */ daddu $a1, $v0, $zero -/* EC39C 802C79EC 0C0B1B7D */ jal si_handle_end_child_thread +/* EC39C 802C79EC 0C0B1B7D */ jal si_handle_end_parallel_thread /* EC3A0 802C79F0 0200202D */ daddu $a0, $s0, $zero /* EC3A4 802C79F4 080B1E95 */ j .L802C7A54 /* EC3A8 802C79F8 0040282D */ daddu $a1, $v0, $zero @@ -407,7 +407,7 @@ glabel si_execute_next_command /* EC3F8 802C7A48 0040282D */ daddu $a1, $v0, $zero .L802C7A4C: /* EC3FC 802C7A4C 080B1E93 */ j .L802C7A4C -/* EC400 802C7A50 00000000 */ nop +/* EC400 802C7A50 00000000 */ nop .L802C7A54: /* EC404 802C7A54 24020003 */ addiu $v0, $zero, 3 /* EC408 802C7A58 10A2FE6E */ beq $a1, $v0, .L802C7414 @@ -424,13 +424,13 @@ glabel si_execute_next_command /* EC434 802C7A84 A2000002 */ sb $zero, 2($s0) .L802C7A88: /* EC438 802C7A88 14A2FE62 */ bne $a1, $v0, .L802C7414 -/* EC43C 802C7A8C 00000000 */ nop +/* EC43C 802C7A8C 00000000 */ nop /* EC440 802C7A90 A2000002 */ sb $zero, 2($s0) /* EC444 802C7A94 3C028007 */ lui $v0, %hi(gGameStatusPtr) /* EC448 802C7A98 8C42419C */ lw $v0, %lo(gGameStatusPtr)($v0) /* EC44C 802C7A9C 80420078 */ lb $v0, 0x78($v0) /* EC450 802C7AA0 1445FE5C */ bne $v0, $a1, .L802C7414 -/* EC454 802C7AA4 00000000 */ nop +/* EC454 802C7AA4 00000000 */ nop .L802C7AA8: /* EC458 802C7AA8 0000102D */ daddu $v0, $zero, $zero .L802C7AAC: diff --git a/asm/nonmatchings/si/si_handle_child_thread.s b/asm/nonmatchings/si/si_handle_parallel_thread.s similarity index 98% rename from asm/nonmatchings/si/si_handle_child_thread.s rename to asm/nonmatchings/si/si_handle_parallel_thread.s index b64104d3a3..37ff838d73 100644 --- a/asm/nonmatchings/si/si_handle_child_thread.s +++ b/asm/nonmatchings/si/si_handle_parallel_thread.s @@ -1,7 +1,7 @@ .set noat # allow manual use of $at .set noreorder # don't insert nops after branches -glabel si_handle_child_thread +glabel si_handle_parallel_thread /* EB71C 802C6D6C 27BDFFE8 */ addiu $sp, $sp, -0x18 /* EB720 802C6D70 AFB00010 */ sw $s0, 0x10($sp) /* EB724 802C6D74 0080802D */ daddu $s0, $a0, $zero diff --git a/asm/nonmatchings/si/si_handle_thread.s b/asm/nonmatchings/si/si_handle_spawn_thread.s similarity index 99% rename from asm/nonmatchings/si/si_handle_thread.s rename to asm/nonmatchings/si/si_handle_spawn_thread.s index af61337469..80a2c50ff6 100644 --- a/asm/nonmatchings/si/si_handle_thread.s +++ b/asm/nonmatchings/si/si_handle_spawn_thread.s @@ -1,7 +1,7 @@ .set noat # allow manual use of $at .set noreorder # don't insert nops after branches -glabel si_handle_thread +glabel si_handle_spawn_thread /* EB628 802C6C78 27BDFFE8 */ addiu $sp, $sp, -0x18 /* EB62C 802C6C7C AFB00010 */ sw $s0, 0x10($sp) /* EB630 802C6C80 0080802D */ daddu $s0, $a0, $zero diff --git a/format.sh b/format.sh index 7cb8d8430e..7ce4d215ff 100755 --- a/format.sh +++ b/format.sh @@ -25,9 +25,10 @@ astyle ${FILES} \ --style=attach \ --align-pointer=type --align-reference=name \ --indent-switches \ - --indent-labels \ --pad-oper --pad-comma --pad-header --unpad-paren \ --attach-return-type \ + --keep-one-line-blocks \ + --keep-one-line-statements # add newline at eof find ${FILES} -exec sed -i -e '$a\' {} \; diff --git a/include/si.h b/include/si.h index 9fab7e9dae..798d5d6b18 100644 --- a/include/si.h +++ b/include/si.h @@ -6,6 +6,99 @@ typedef s32 Bytecode; typedef s32 ScriptID; +typedef enum ScriptOpcode { + ScriptOpcode_END = 0x01, + ScriptOpcode_RETURN, + ScriptOpcode_LABEL, ///< Args: index + ScriptOpcode_GOTO, ///< Args: index + ScriptOpcode_LOOP, ///< Args: number of repeats (0 = infinite) + ScriptOpcode_END_LOOP, + ScriptOpcode_BREAK_LOOP, + ScriptOpcode_SLEEP_FRAMES, + ScriptOpcode_SLEEP_SECS, + ScriptOpcode_IF_EQ, ///< Args: a, b + ScriptOpcode_IF_NE, ///< Args: a, b + ScriptOpcode_IF_LT, ///< Args: a, b + ScriptOpcode_IF_GT, ///< Args: a, b + ScriptOpcode_IF_LE, ///< Args: a, b + ScriptOpcode_IF_GE, ///< Args: a, b + ScriptOpcode_IF_FLAG, ///< Args: a, b + ScriptOpcode_IF_NOT_FLAG, ///< Args: a, b + ScriptOpcode_ELSE, + ScriptOpcode_END_IF, + ScriptOpcode_MATCH, ///< Args: expression to test against + ScriptOpcode_MATCH_CONST, ///< Args: value to test against + ScriptOpcode_CASE_EQ, ///< Args: expression to test for + ScriptOpcode_CASE_NE, ///< Args: expression to test for + ScriptOpcode_CASE_LT, ///< Args: expression to test for + ScriptOpcode_CASE_GT, ///< Args: expression to test for + ScriptOpcode_CASE_LE, ///< Args: expression to test for + ScriptOpcode_CASE_GE, ///< Args: expression to test for + ScriptOpcode_CASE_ELSE, + ScriptOpcode_CASE_MULTI_OR_EQ, ///< Args: expression to test for + ScriptOpcode_CASE_MULTI_AND_EQ, ///< Args: expression to test for + ScriptOpcode_CASE_FLAG, ///< Args: expression to test for + ScriptOpcode_END_CASE_MULTI, ///< Ends the case block of ScriptOpcode_CASE_MULTI_OR_EQ condition(s). + ScriptOpcode_CASE_RANGE, ///< Args: from, to + ScriptOpcode_BREAK_MATCH, + ScriptOpcode_END_MATCH, + ScriptOpcode_SET, ///< Args: container, expression + ScriptOpcode_SET_CONST, ///< Args: container, value + ScriptOpcode_SET_F, ///< Args: container, expression + ScriptOpcode_ADD, ///< Args: container, expression to increment by + ScriptOpcode_SUB, ///< Args: container, expression to decrement by + ScriptOpcode_MUL, ///< Args: container, expression to multiply by + ScriptOpcode_DIV, ///< Integer division. Args: container, expression to divide by + ScriptOpcode_MOD, ///< Args: container, expression to divide by + ScriptOpcode_ADD_F, ///< Args: container, expression to increment by + ScriptOpcode_SUB_F, ///< Args: container, expression to decrement by + ScriptOpcode_MUL_F, ///< Args: container, expression to multiply by + ScriptOpcode_DIV_F, ///< Args: container, expression to divide by + ScriptOpcode_USE_BUFFER, ///< Args: s32* + ScriptOpcode_BUFFER_READ_1, /// Args: container + ScriptOpcode_BUFFER_READ_2, /// Args: container, container + ScriptOpcode_BUFFER_READ_3, /// Args: container, container, container + ScriptOpcode_BUFFER_READ_4, /// Args: container, container, container, container + ScriptOpcode_BUFFER_PEEK, ///< Args: index, container + ScriptOpcode_USE_BUFFER_F, ///< Identical to USE_BUFFER. Args: f32* + ScriptOpcode_BUFFER_READ_1_F, /// Args: container + ScriptOpcode_BUFFER_READ_2_F, /// Args: container, container + ScriptOpcode_BUFFER_READ_3_F, /// Args: container, container, container + ScriptOpcode_BUFFER_READ_4_F, /// Args: container, container, container, container + ScriptOpcode_BUFFER_PEEK_F, ///< Args: index, container + ScriptOpcode_USE_ARRAY, ///< Args: *s32 + ScriptOpcode_USE_FLAGS, ///< Args: *s32 + ScriptOpcode_NEW_ARRAY, ///< Allocates a new array. Args: length, s32* + ScriptOpcode_AND, ///< Args: container, expression to bitwise AND with + ScriptOpcode_AND_CONST, ///< Args: container, value to bitwise AND with + ScriptOpcode_OR, ///< Args: container, expression to bitwise OR with + ScriptOpcode_OR_CONST, ///< Args: container, value to bitwise OR with + ScriptOpcode_CALL, ///< Args: *function, ... + ScriptOpcode_SPAWN_SCRIPT, ///< Args: Script* + ScriptOpcode_SPAWN_SCRIPT_GET_ID, ///< Args: Script*, container + ScriptOpcode_AWAIT_SCRIPT, ///< Spawns a script and waits for it to return before continuing. Args: Script* + ScriptOpcode_BIND_TRIGGER, ///< Args: Script*, trigger flags, s32 target, 1, Trigger* + ScriptOpcode_UNBIND, ///< Unbinds any triggers bound to this script. + ScriptOpcode_KILL_SCRIPT, ///< Args: ScriptID + ScriptOpcode_JUMP, ///< Args: Script* + ScriptOpcode_SET_PRIORITY, ///< Args: priority + ScriptOpcode_SET_TIMESCALE, ///< Args: timescale + ScriptOpcode_SET_GROUP, ///< Args: group + ScriptOpcode_BIND_PADLOCK, ///< Args: Script*, trigger flags, s32 target, ItemList*, 0, 1 + ScriptOpcode_SUSPEND_GROUP, ///< Args: group + ScriptOpcode_RESUME_GROUP, ///< Args: group + ScriptOpcode_SUSPEND_OTHERS, ///< Args: group + ScriptOpcode_RESUME_OTHERS, ///< Args: group + ScriptOpcode_SUSPEND_SCRIPT, ///< Args: ScriptID + ScriptOpcode_RESUME_SCRIPT, ///< Args: ScriptID + ScriptOpcode_SCRIPT_EXISTS, ///< Args: ScriptID, container + ScriptOpcode_SPAWN_THREAD, + ScriptOpcode_END_SPAWN_THREAD, + ScriptOpcode_PARALLEL_THREAD, ///< Parallel threads are killed as soon as the parent script returns. + ScriptOpcode_END_PARALLEL_THREAD, + ScriptOpcode_DEBUG_PRINT = 0x5B, ///< Args: expression +} ScriptOpcode; + #define SI_VAR(v) (v - 30000000) #define SI_MAP_VAR(v) (v - 50000000) #define SI_FLAG(v) (v - 70000000) @@ -36,111 +129,6 @@ typedef s32 ApiStatus; /* argc */ (sizeof((Bytecode[]){argv})/sizeof(Bytecode)), \ ##argv -#define SI_END() SI_CMD(0x01) -#define SI_RETURN() SI_CMD(0x02) - -#define SI_LABEL(i) SI_CMD(0x03, i) -#define SI_GOTO(i) SI_CMD(0x04, i) - -#define SI_LOOP(i) SI_CMD(0x05, i) -#define SI_END_LOOP() SI_CMD(0x06) -#define SI_BREAK_LOOP() SI_CMD(0x07) - -#define SI_WAIT_FRAMES(i) SI_CMD(0x08, i) -#define SI_WAIT_SECS(i) SI_CMD(0x09, i) - -#define SI_IF_EQ(a, b) SI_CMD(0x0A, a, b) -#define SI_IF_NE(a, b) SI_CMD(0x0B, a, b) -#define SI_IF_LT(a, b) SI_CMD(0x0C, a, b) -#define SI_IF_GT(a, b) SI_CMD(0x0D, a, b) -#define SI_IF_LE(a, b) SI_CMD(0x0E, a, b) -#define SI_IF_GE(a, b) SI_CMD(0x0F, a, b) -#define SI_IF_BITS_ON(a, b) SI_CMD(0x10, a, b) -#define SI_IF_BITS_OFF(a, b) SI_CMD(0x11, a, b) -#define SI_ELSE() SI_CMD(0x12) -#define SI_END_IF() SI_CMD(0x13) - -#define SI_SWITCH(a) SI_CMD(0x14, a) -#define SI_SWITCH_CONST(a) SI_CMD(0x15, a) // Does not get_variable -#define SI_CASE_EQ(b) SI_CMD(0x16, b) -#define SI_CASE_NE(b) SI_CMD(0x17, b) -#define SI_CASE_LT(b) SI_CMD(0x18, b) -#define SI_CASE_GT(b) SI_CMD(0x19, b) -#define SI_CASE_LE(b) SI_CMD(0x1A, b) -#define SI_CASE_GE(b) SI_CMD(0x1B, b) -#define SI_CASE_DEFAULT() SI_CMD(0x1C) -#define SI_CASE_OR_EQ(b) SI_CMD(0x1D, b) -#define SI_CASE_BITS_ON(b) SI_CMD(0x1F, b) -#define SI_END_MULTI_CASE() SI_CMD(0x20) -#define SI_CASE_RANGE(from, to) SI_CMD(0x21, from, to) -#define SI_BREAK_CASE() SI_CMD(0x22) -#define SI_END_SWITCH() SI_CMD(0x23) - -#define SI_SET(varA, varB) SI_CMD(0x24, varA, varB) -#define SI_SET_CONST(var, value) SI_CMD(0x25, var, value) // Does not get_variable -#define SI_ADD(a, b) SI_CMD(0x27, a, b) // += -#define SI_SUB(a, b) SI_CMD(0x28, a, b) // -= -#define SI_MUL(a, b) SI_CMD(0x29, a, b) // *= -#define SI_DIV(a, b) SI_CMD(0x2A, a, b) // /= -#define SI_MOD(a, b) SI_CMD(0x2B, a, b) // %= - -#define SI_SET_F(var, value) SI_CMD(0x26, var, value) -#define SI_ADD_F(a, b) SI_CMD(0x2C, a, b) // += -#define SI_SUB_F(a, b) SI_CMD(0x2D, a, b) // -= -#define SI_MUL_F(a, b) SI_CMD(0x2E, a, b) // *= -#define SI_DIV_F(a, b) SI_CMD(0x2F, a, b) // /= - -// BUF_READ and BUF_READ_F take 1..4 args only -#define SI_USE_BUFFER(buf_ptr) SI_CMD(0x30, buf_ptr) -#define SI_BUF_READ(vars...) SI_CMD( \ - 0x30 + (sizeof((Bytecode[]){vars})/sizeof(Bytecode)), \ - vars) -#define SI_BUF_PEEK(n, var) SI_CMD(0x35, n, var) -#define SI_USE_BUFFER_F(buf_ptr) SI_CMD(0x36, buf_ptr) -#define SI_BUF_READ_F(vars...) SI_CMD( \ - 0x36 + (sizeof((Bytecode[]){vars})/sizeof(Bytecode)), \ - vars) -#define SI_BUF_PEEK_F(n, var) SI_CMD(0x3B, n, var) - -#define SI_USE_ARRAY(arrPtr) SI_CMD(0x3C, arrPtr) -#define SI_NEW_ARRAY(len, arrPtr) SI_CMD(0x3D, len, arrPtr) -#define SI_USE_FLAGS(arrPtr) SI_CMD(0x3E, arrPtr) - -#define SI_AND(varA, varB) SI_CMD(0x3F, varA, varB) // &= -#define SI_AND_CONST(var, value) SI_CMD(0x40, var, value) // &= -#define SI_OR(varA, varB) SI_CMD(0x41, varA, varB) // |= -#define SI_OR_CONST(var, value) SI_CMD(0x41, var, value) // |= - -#define SI_CALL(func, argv...) SI_CMD(0x43, func, ##argv) -#define SI_EXEC(script) SI_CMD(0x44, script) -#define SI_EXEC_GET_ID(script, outScriptID) SI_CMD(0x45, script, outScriptID) -#define SI_EXEC_WAIT(script) SI_CMD(0x46, script) -#define SI_JUMP(script) SI_CMD(0x4A, script) - -#define SI_BIND(script, trigger, target, outTriggerPtr) SI_CMD(0x47, script, trigger, target, 1, outTriggerPtr) -#define SI_BIND_PADLOCK(script, trigger, target, itemList) SI_CMD(0x4E, script, trigger, target, itemList, 0, 1) -#define SI_UNBIND_ME() SI_CMD(0x48) - -#define SI_PRIORITY(p) SI_CMD(0x4B, p) -#define SI_TIMESCALE(t) SI_CMD(0x4C, t) -#define SI_GROUP(g) SI_CMD(0x4D, g) - -#define SI_SUSPEND_GROUP(group) SI_CMD(0x4F, group) -#define SI_RESUME_GROUP(group) SI_CMD(0x50, group) -#define SI_SUSPEND_GROUP_NOT_ME(group) SI_CMD(0x51, group) -#define SI_RESUME_GROUP_NOT_ME(group) SI_CMD(0x52, group) - -#define SI_KILL(scriptID) SI_CMD(0x49, scriptID) -#define SI_SUSPEND(scriptID) SI_CMD(0x53, scriptID) -#define SI_RESUME(scriptID) SI_CMD(0x54, scriptID) -#define SI_EXISTS(scriptID) SI_CMD(0x55, scriptID) - -#define SI_THREAD() SI_CMD(0x56) -#define SI_END_THREAD() SI_CMD(0x57) - -#define SI_CHILD_THREAD() SI_CMD(0x58) -#define SI_END_CHILD_THREAD() SI_CMD(0x59) - #define EXIT_WALK_SCRIPT(walkDistance, exitIdx, map, entryIdx) \ SCRIPT({ \ group 0x1B; \ diff --git a/src/si.c b/src/si.c index 397b434d5c..2c06e25f40 100644 --- a/src/si.c +++ b/src/si.c @@ -84,7 +84,7 @@ ApiStatus si_handle_break_loop(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_wait(ScriptInstance* script) { +ApiStatus si_handle_sleep_frames(ScriptInstance* script) { Bytecode* ptrReadPos = script->ptrReadPos; if (!script->blocked) { @@ -102,7 +102,7 @@ ApiStatus si_handle_wait(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_wait_seconds(ScriptInstance* script) { +ApiStatus si_handle_sleep_seconds(ScriptInstance* script) { Bytecode* ptrReadPos = script->ptrReadPos; if (!script->blocked) { @@ -180,7 +180,7 @@ ApiStatus si_handle_if_greater_equal(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_if_AND(ScriptInstance* script) { +ApiStatus si_handle_if_flag(ScriptInstance* script) { Bytecode* args = script->ptrReadPos; Bytecode var = *args++; @@ -191,7 +191,7 @@ ApiStatus si_handle_if_AND(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_if_not_AND(ScriptInstance* script) { +ApiStatus si_handle_if_not_flag(ScriptInstance* script) { Bytecode* args = script->ptrReadPos; Bytecode var = *args++; @@ -211,7 +211,7 @@ ApiStatus si_handle_end_if(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_switch(ScriptInstance* script) { +ApiStatus si_handle_match(ScriptInstance* script) { Bytecode value = get_variable(script, *script->ptrReadPos); s32 switchDepth = ++script->switchDepth; @@ -223,7 +223,7 @@ ApiStatus si_handle_switch(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_switch_const(ScriptInstance* script) { +ApiStatus si_handle_match_const(ScriptInstance* script) { Bytecode* args = *script->ptrReadPos; s32 switchDepth = ++script->switchDepth; @@ -399,7 +399,7 @@ ApiStatus si_handle_case_range(ScriptInstance* script) { do {} while (0); // Necessary to match } -ApiStatus si_handle_case_default(ScriptInstance* script) { +ApiStatus si_handle_case_else(ScriptInstance* script) { s32 switchDepth = script->switchDepth; ASSERT(switchDepth >= 0); @@ -413,7 +413,7 @@ ApiStatus si_handle_case_default(ScriptInstance* script) { do {} while (0); // Necessary to match } -ApiStatus si_handle_case_AND(ScriptInstance* script) { +ApiStatus si_handle_case_flag(ScriptInstance* script) { Bytecode* args = script->ptrReadPos; s32 switchDepth = script->switchDepth; s32 var; @@ -438,7 +438,7 @@ ApiStatus si_handle_case_AND(ScriptInstance* script) { do {} while (0); // Necessary to match } -ApiStatus si_handle_case_equal_OR(ScriptInstance* script) { +ApiStatus si_handle_case_multi_or_equal(ScriptInstance* script) { Bytecode* args = script->ptrReadPos; s32 switchDepth = script->switchDepth; s32 var; @@ -463,7 +463,7 @@ ApiStatus si_handle_case_equal_OR(ScriptInstance* script) { do {} while (0); // Necessary to match } -ApiStatus si_handle_case_equal_AND(ScriptInstance* script) { +ApiStatus si_handle_case_multi_and_equal(ScriptInstance* script) { Bytecode* args = script->ptrReadPos; s32 switchDepth = script->switchDepth; s32 var; @@ -491,7 +491,7 @@ ApiStatus si_handle_case_equal_AND(ScriptInstance* script) { do {} while (0); // Necessary to match } -ApiStatus si_handle_end_case_group(ScriptInstance* script) { +ApiStatus si_handle_end_case_multi(ScriptInstance* script) { ASSERT(script->switchDepth >= 0); if (script->switchBlockState[script->switchDepth] == 0) { @@ -509,13 +509,13 @@ ApiStatus si_handle_end_case_group(ScriptInstance* script) { do {} while (0); // Necessary to match } -ApiStatus si_handle_break_case(ScriptInstance* script) { +ApiStatus si_handle_break_match(ScriptInstance* script) { ASSERT(script->switchDepth >= 0); script->ptrNextLine = si_goto_end_case(script); return ApiStatus_DONE2; } -ApiStatus si_handle_end_switch(ScriptInstance* script) { +ApiStatus si_handle_end_match(ScriptInstance* script) { s32 switchDepth = script->switchDepth; ASSERT(switchDepth >= 0); @@ -898,7 +898,7 @@ ApiStatus si_handle_call(ScriptInstance* script) { return func(newScript, isInitialCall); // todo fake match } -ApiStatus si_handle_exec1(ScriptInstance* script) { +ApiStatus si_handle_spawn_script(ScriptInstance* script) { ScriptInstance* newScript; s32 i; @@ -924,7 +924,7 @@ ApiStatus si_handle_exec1(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_exec2(ScriptInstance* script) { +ApiStatus si_handle_spawn_script_get_id(ScriptInstance* script) { Bytecode* args = script->ptrReadPos; ScriptInstance* var = (ScriptInstance*)get_variable(script, *args++); Bytecode arg2 = *args++; @@ -952,7 +952,7 @@ ApiStatus si_handle_exec2(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_exec_wait(ScriptInstance* script) { +ApiStatus si_handle_await_script(ScriptInstance* script) { start_child_script(script, get_variable(script, *script->ptrReadPos), 0); script->currentOpcode = 0; return ApiStatus_FINISH; @@ -991,7 +991,7 @@ s32 _bound_script_trigger_handler(Trigger* trigger) { return 1; } -ApiStatus si_handle_bind(ScriptInstance* script) { +ApiStatus si_handle_bind_trigger(ScriptInstance* script) { Bytecode* args = script->ptrReadPos; Trigger* trigger; Bytecode* triggerScript = get_variable(script, *args++); @@ -1033,7 +1033,7 @@ ApiStatus si_handle_unbind(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_kill(ScriptInstance* script) { +ApiStatus si_handle_kill_script(ScriptInstance* script) { kill_script_by_ID(get_variable(script, *script->ptrReadPos)); return ApiStatus_DONE2; } @@ -1073,12 +1073,12 @@ ApiStatus si_handle_resume_others(ScriptInstance* script) { return ApiStatus_DONE2; } -ApiStatus si_handle_suspend(ScriptInstance* script) { +ApiStatus si_handle_suspend_script(ScriptInstance* script) { suspend_all_script(get_variable(script, *script->ptrReadPos)); return ApiStatus_DONE2; } -ApiStatus si_handle_resume(ScriptInstance* script) { +ApiStatus si_handle_resume_script(ScriptInstance* script) { resume_all_script(get_variable(script, *script->ptrReadPos)); return ApiStatus_DONE2; } @@ -1139,16 +1139,16 @@ ApiStatus si_handle_bind_lock(ScriptInstance* script) { return ApiStatus_DONE2; } -INCLUDE_ASM(s32, "si", si_handle_thread, ScriptInstance* script, s32 isInitialCall); +INCLUDE_ASM(s32, "si", si_handle_spawn_thread, ScriptInstance* script, s32 isInitialCall); -ApiStatus si_handle_end_thread(ScriptInstance* script) { +ApiStatus si_handle_end_spawn_thread(ScriptInstance* script) { kill_script(script); return ApiStatus_FINISH; } -INCLUDE_ASM(s32, "si", si_handle_child_thread, ScriptInstance* script, s32 isInitialCall); +INCLUDE_ASM(s32, "si", si_handle_parallel_thread, ScriptInstance* script, s32 isInitialCall); -ApiStatus si_handle_end_child_thread(ScriptInstance* script) { +ApiStatus si_handle_end_parallel_thread(ScriptInstance* script) { kill_script(script); return ApiStatus_BLOCK; } diff --git a/src/world/area_kmr/kmr_03/8C7F90.c b/src/world/area_kmr/kmr_03/8C7F90.c index 2a88dc5cc8..c3221df9b2 100644 --- a/src/world/area_kmr/kmr_03/8C7F90.c +++ b/src/world/area_kmr/kmr_03/8C7F90.c @@ -64,8 +64,6 @@ MapConfig M(config) = { .tattle = MessageID_TATTLE_KMR_03, }; -Script M(script_802406C0) = { - SI_CALL(SetMusicTrack, 0, 17, 0, 8), - SI_RETURN(), - SI_END(), -}; +Script M(Script_802406C0) = SCRIPT({ + SetMusicTrack(0, 17, 0, 8) +}); diff --git a/src/world/area_kmr/kmr_03/8C8140.c b/src/world/area_kmr/kmr_03/8C8140.c index 331f63b956..e7b2158b10 100644 --- a/src/world/area_kmr/kmr_03/8C8140.c +++ b/src/world/area_kmr/kmr_03/8C8140.c @@ -1,9 +1,9 @@ #include "kmr_03.h" s32 M(npcGroupList_80241450)[]; -Script M(script_MakeEntities); -Script M(script_802422B8); -Script M(script_80242340); +Script M(MakeEntities); +Script M(Script_802422B8); +Script M(Script_80242340); ApiStatus func_802401B0_8C8140(ScriptInstance* script, s32 isInitialCall) { Npc* npc = get_npc_unsafe(0); @@ -15,60 +15,38 @@ ApiStatus func_802401B0_8C8140(ScriptInstance* script, s32 isInitialCall) { #include "world/common/UnkPositionFunc.inc.c" // 8C8680 -Script M(script_ExitWalk_802406F0) = { - SI_GROUP(27), - SI_CALL(0x802D216C, 60, 0), - SI_EXEC(0x80285CF4), - SI_CALL(0x802CA400, "kmr_04", 0), - SI_WAIT_FRAMES(100), - SI_RETURN(), - SI_END(), -}; +Script M(ExitWalk_802406F0) = EXIT_WALK_SCRIPT(60, 0, "kmr_04", 0); -Script M(script_ExitWalk_8024074C) = { - SI_GROUP(27), - SI_CALL(0x802D216C, 60, 1), - SI_EXEC(0x80285CF4), - SI_CALL(0x802CA400, "kmr_05", 0), - SI_WAIT_FRAMES(100), - SI_RETURN(), - SI_END(), -}; +Script M(ExitWalk_8024074C) = EXIT_WALK_SCRIPT(60, 1, "kmr_05", 0); -Script M(script_802407A8) = { - SI_BIND(M(script_ExitWalk_802406F0), 524288, 3, NULL), - SI_BIND(M(script_ExitWalk_8024074C), 524288, 5, NULL), - SI_RETURN(), - SI_END(), -}; +Script M(Script_802407A8) = SCRIPT({ + bind M(ExitWalk_802406F0) to 0x80000 3 + bind M(ExitWalk_8024074C) to 0x80000 5 +}); -// *INDENT-OFF* -Script M(Main) = { - SI_SET(SI_SAVE_VAR(425), 30), - SI_CALL(0x802D9700, -1), - SI_CALL(0x802CA828, 0, 3, 25, 16, 4096), - SI_CALL(0x802CAD98, 0, 0, 0, 0), - SI_CALL(0x802CA6C0, 0, 1), - SI_CALL(0x802CB680, 0, 0), - SI_SET(SI_AREA_FLAG(8), 0), - SI_CALL(0x80044298, 0, M(npcGroupList_80241450)), - SI_CALL(0x80045640), - SI_EXEC_WAIT(M(script_MakeEntities)), - SI_EXEC_WAIT(M(script_802422B8)), - SI_EXEC(M(script_802406C0)), - SI_CALL(0x802CA460, SI_VAR(0)), - SI_IF_NE(SI_VAR(0), 2), - SI_SET(SI_VAR(0), M(script_802407A8)), - SI_EXEC(0x80285960), - SI_ELSE(), - SI_EXEC(M(script_802407A8)), - SI_EXEC(M(script_80242340)), - SI_END_IF(), - SI_WAIT_FRAMES(1), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(Main) = SCRIPT({ + SI_SAVE_VAR(425) = 30 + SetSpriteShading(-1) + SetCamPerspective(0, 3, 25, 16, 4096) + SetCamBGColor(0, 0, 0, 0) + SetCamEnabled(0, 1) + SetCamLeadPlayer(0, 0) + SI_AREA_FLAG(8) = 0 + MakeNpcs(0, M(npcGroupList_80241450)) + ClearDefeatedEnemies() + await M(MakeEntities) + await M(Script_802422B8) + spawn M(Script_802406C0) + GetEntryID(SI_VAR(0)) + if SI_VAR(0) != 2 { + SI_VAR(0) = M(Script_802407A8) + spawn EnterWalk + } else { + spawn M(Script_802407A8) + spawn M(Script_80242340) + } + sleep 1 +}); s32 padding[] = {0, 0}; @@ -78,159 +56,147 @@ s32 M(npcSettings_80240950)[] = { 0x00000000, 0x00000000, 0x00630010, }; -// *INDENT-OFF* -Script M(script_8024097C) = { - SI_LABEL(1), - SI_IF_EQ(SI_AREA_FLAG(8), 1), - SI_LABEL(100), - SI_CALL(0x802D4A5C, 294, 123, 170), - SI_CALL(0x80044CF0, 0, 0), - SI_CALL(0x802D0E28, 1), - SI_CALL(0x802CE01C, 0, SI_FIXED(4.0f)), - SI_CALL(0x802CE0F4, 0, 0x9D0003), - SI_CALL(func_802401B0_8C8140), - SI_CALL(0x802D4830, 0, SI_VAR(2)), - SI_LOOP(SI_VAR(1)), - SI_CALL(0x802CF0F4, 0, SI_VAR(7), SI_VAR(8), SI_VAR(9)), - SI_CALL(0x802D4B14, SI_VAR(7), SI_VAR(9), SI_FIXED(4.0f), SI_VAR(2)), - SI_CALL(0x802CDCB0, 0, SI_VAR(7), SI_VAR(8), SI_VAR(9)), - SI_WAIT_FRAMES(1), - SI_END_LOOP(), - SI_CALL(0x802D1B04, 0, 3), - SI_CALL(0x802D1024, SI_FIXED(3.0f)), - SI_CALL(0x802D1134, 243, 243, 0), - SI_CALL(0x80045320, 0, 0, 1), - SI_CALL(0x80044CF0, 0, 1), - SI_CALL(0x802D0E28, 0), - SI_GOTO(100), - SI_END_IF(), - SI_WAIT_FRAMES(1), - SI_GOTO(1), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(Script_8024097C) = SCRIPT({ +1: + if SI_AREA_FLAG(8) == 1 { +100: + AwaitPlayerLeave(294, 123, 170) + EnableNpcAI(0, 0) + DisablePlayerInput(1) + SetNpcSpeed(0, 4.0) + SetNpcAnimation(0, 0x9D0003) + func_802401B0_8C8140() + GetAngleToPlayer(0, SI_VAR(2)) + loop SI_VAR(1) { + GetNpcPos(0, SI_VAR(7), SI_VAR(8), SI_VAR(9)) + AddVectorPolar(SI_VAR(7), SI_VAR(9), 4.0, SI_VAR(2)) + SetNpcPos(0, SI_VAR(7), SI_VAR(8), SI_VAR(9)) + sleep 1 + } + PlayerFaceNpc(0, 3) + SetPlayerSpeed(3.0) + PlayerMoveTo(243, 243, 0) + SetNpcVar(0, 0, 1) + EnableNpcAI(0, 1) + DisablePlayerInput(0) + goto 100 + } + sleep 1 + goto 1 +}); -// *INDENT-OFF* -Script M(script_NpcAI_80240B50) = { - SI_LABEL(1), - SI_SWITCH(SI_SAVE_VAR(0)), - SI_CASE_EQ(0xFFFFFF86), - SI_LABEL(89), - SI_CALL(UnkPositionFunc, 0xFFFFFF8A, 86, 0xFFFFFFBA, 0xFFFFFFF1), - SI_WAIT_FRAMES(1), - SI_IF_EQ(SI_VAR(0), 0), - SI_GOTO(89), - SI_END_IF(), - SI_CALL(0x802D0E28, 1), - SI_CALL(0x80044DA4, 0, 0), - SI_CALL(0x802D01AC, 0, 610, 0), - SI_CALL(0x802D78A0, 0, 0, 45, 15, 1, 0, 0, 0, 0), - SI_WAIT_FRAMES(15), - SI_CALL(0x802CECC8, -1, 5), - SI_WAIT_FRAMES(10), - SI_CALL(0x802D02B0, 0, 0x9D0008, 0x9D0001, 0, 0xB00A6), - SI_CALL(0x802CB860, 0, 0xFFFFFF24, 20, 0xFFFFFFB8), - SI_CALL(0x802CBE2C, 0, 0xFFFFFFEC, 0, 68), - SI_CALL(0x802CBB48, 0, SI_FIXED(15.0f), SI_FIXED(-8.5f)), - SI_CALL(0x802CBBE4, 0, 275), - SI_CALL(0x802CBEF0, 0, SI_FIXED(1.5f)), - SI_CALL(0x802CB79C, 0, 0, 1), - SI_THREAD(), - SI_WAIT_FRAMES(20), - SI_CALL(0x802D1024, SI_FIXED(2.0f)), - SI_CALL(0x802D1134, 0xFFFFFFDA, 68, 0), - SI_END_THREAD(), - SI_CALL(0x802CF0F4, 0, SI_VAR(7), SI_VAR(8), SI_VAR(9)), - SI_CALL(0x802CE01C, 0, SI_FIXED(4.0f)), - SI_CALL(0x802CE0F4, 0, 0x9D0003), - SI_CALL(0x802CE22C, 0, 0, 70, 0), - SI_CALL(0x802CE0F4, 0, 0x9D0001), - SI_CALL(0x802CEB04, 0, 276, 20), - SI_WAIT_FRAMES(30), - SI_CALL(0x802D02B0, 0, 0x9D0008, 0x9D0001, 0, 0xB00A7), - SI_WAIT_FRAMES(5), - SI_CALL(0x802D1084, 0x80007), - SI_WAIT_FRAMES(30), - SI_CALL(0x802D02B0, 0, 0x9D0008, 0x9D0001, 0, 0xB00A8), - SI_CALL(func_80240000_8C7F90, 0, 5), - SI_SET(SI_SAVE_VAR(0), 0xFFFFFF87), - SI_CALL(0x802CB860, 0, 0xFFFFFF24, 20, 0xFFFFFFB8), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CBE2C, 0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CBEF0, 0, SI_FIXED(3.0f)), - SI_CALL(0x802CB79C, 0, 0, 1), - SI_CALL(0x802CC354, 0, SI_FIXED(1.0f)), - SI_CALL(0x802CB79C, 0, 0, 0), - SI_CALL(0x802CF52C), - SI_CALL(0x802D0E28, 0), - SI_WAIT_FRAMES(1), - SI_END_SWITCH(), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(NpcAI_80240B50) = SCRIPT({ +1: + match SI_SAVE_VAR(0) { + == 0xFFFFFF86 { +89: + UnkPositionFunc(0xFFFFFF8A, 86, 0xFFFFFFBA, 0xFFFFFFF1) + sleep 1 + if SI_VAR(0) == 0 { + goto 89 + } + DisablePlayerInput(1) + SetNpcAux(0, 0) + PlaySoundAtNpc(0, 610, 0) + ShowEmote(0, 0, 45, 15, 1, 0, 0, 0, 0) + sleep 15 + NpcFacePlayer(-1, 5) + sleep 10 + SpeakToPlayer(0, 0x9D0008, 0x9D0001, 0, 0xB00A6) + UseSettingsFrom(0, 0xFFFFFF24, 20, 0xFFFFFFB8) + SetPanTarget(0, 0xFFFFFFEC, 0, 68) + SetCamPitch(0, 15.0, -8.5) + SetCamDistance(0, 275) + SetCamSpeed(0, 1.5) + PanToTarget(0, 0, 1) + spawn { + sleep 20 + SetPlayerSpeed(2.0) + PlayerMoveTo(0xFFFFFFDA, 68, 0) + } + GetNpcPos(0, SI_VAR(7), SI_VAR(8), SI_VAR(9)) + SetNpcSpeed(0, 4.0) + SetNpcAnimation(0, 0x9D0003) + NpcMoveTo(0, 0, 70, 0) + SetNpcAnimation(0, 0x9D0001) + InterpNpcYaw(0, 276, 20) + sleep 30 + SpeakToPlayer(0, 0x9D0008, 0x9D0001, 0, 0xB00A7) + sleep 5 + SetPlayerAnimation(0x80007) + sleep 30 + SpeakToPlayer(0, 0x9D0008, 0x9D0001, 0, 0xB00A8) + func_80240000_8C7F90(0, 5) + SI_SAVE_VAR(0) = 0xFFFFFF87 + UseSettingsFrom(0, 0xFFFFFF24, 20, 0xFFFFFFB8) + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetPanTarget(0, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetCamSpeed(0, 3.0) + PanToTarget(0, 0, 1) + WaitForCam(0, 1.0) + PanToTarget(0, 0, 0) + EnablePartnerAI() + DisablePlayerInput(0) + sleep 1 + } + } +}); -// *INDENT-OFF* -Script M(script_Hit_80240F64) = { - SI_CALL(0x802CE0F4, -1, 0x9D0007), - SI_WAIT_FRAMES(10), - SI_CALL(0x802CE0F4, -1, 0x9D0001), - SI_ADD(SI_MAP_VAR(0), 1), - SI_IF_LT(SI_MAP_VAR(0), 3), - SI_CALL(0x80044600, SI_VAR(0)), - SI_SWITCH(SI_VAR(0)), - SI_CASE_EQ(2), - SI_CALL(0x80045320, 0, 0, 1), - SI_IF_EQ(SI_AREA_FLAG(6), 1), - SI_ELSE(), - SI_SET(SI_AREA_FLAG(6), 1), - SI_SET(SI_AREA_FLAG(7), 0), - SI_END_IF(), - SI_CASE_EQ(4), - SI_CALL(0x80045320, 0, 0, 1), - SI_IF_EQ(SI_AREA_FLAG(7), 1), - SI_ELSE(), - SI_SET(SI_AREA_FLAG(6), 0), - SI_SET(SI_AREA_FLAG(7), 1), - SI_END_IF(), - SI_END_SWITCH(), - SI_WAIT_FRAMES(10), - SI_CALL(0x802CE0F4, -1, 0x9D0003), - SI_ELSE(), - SI_WAIT_FRAMES(10), - SI_CALL(0x802CF0F4, 0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CDCB0, 0xFFFFFFFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CF060, 0xFFFFFFFC, 512, 1), - SI_CALL(0x802CDCB0, 0, 0, 0xFFFFFC18, 0), - SI_CALL(0x802CF060, 0, 256, 0), - SI_CALL(0x802CF52C), - SI_CALL(0x80044DA4, -1, M(script_8024097C)), - SI_CALL(0x80044A78, -1, M(script_NpcAI_80240B50)), - SI_END_IF(), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(Hit_80240F64) = SCRIPT({ + SetNpcAnimation(-1, 0x9D0007) + sleep 10 + SetNpcAnimation(-1, 0x9D0001) + SI_MAP_VAR(0) += 1 + if SI_MAP_VAR(0) < 3 { + GetOwnerEncounterTrigger(SI_VAR(0)) + match SI_VAR(0) { + == 2 { + SetNpcVar(0, 0, 1) + if SI_AREA_FLAG(6) == 1 { + } else { + SI_AREA_FLAG(6) = 1 + SI_AREA_FLAG(7) = 0 + } + } + == 4 { + SetNpcVar(0, 0, 1) + if SI_AREA_FLAG(7) == 1 { + } else { + SI_AREA_FLAG(6) = 0 + SI_AREA_FLAG(7) = 1 + } + } + } + sleep 10 + SetNpcAnimation(-1, 0x9D0003) + } else { + sleep 10 + GetNpcPos(0, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetNpcPos(0xFFFFFFFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetNpcFlagBits(0xFFFFFFFC, 512, 1) + SetNpcPos(0, 0, 0xFFFFFC18, 0) + SetNpcFlagBits(0, 256, 0) + EnablePartnerAI() + SetNpcAux(-1, M(Script_8024097C)) + BindNpcAI(-1, M(NpcAI_80240B50)) + } +}); -// *INDENT-OFF* -Script M(script_Init_802411A8) = { - SI_CALL(0x80044BAC, -1, M(script_NpcAI_80240B50)), - SI_CALL(0x80044EB8, -1, M(script_8024097C)), - SI_CALL(0x80045140, -1, M(script_Hit_80240F64)), - SI_SWITCH(SI_SAVE_VAR(0)), - SI_CASE_GE(0xFFFFFF87), - SI_CALL(0x802CF060, -1, 512, 0), - SI_CALL(0x802CF060, -1, 8, 1), - SI_CALL(0x802CDCB0, -1, 0, 0xFFFFFC18, 0), - SI_END_SWITCH(), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(Init_802411A8) = SCRIPT({ + BindNpcIdle(-1, M(NpcAI_80240B50)) + BindNpcAux(-1, M(Script_8024097C)) + BindNpcHit(-1, M(Hit_80240F64)) + match SI_SAVE_VAR(0) { + >= 0xFFFFFF87 { + SetNpcFlagBits(-1, 512, 0) + SetNpcFlagBits(-1, 8, 1) + SetNpcPos(-1, 0, 0xFFFFFC18, 0) + } + } +}); s32 M(npcGroup_80241260)[] = { - 0x00000000, M(npcSettings_80240950), 0xC2480000, 0x00000000, 0x42A00000, 0x00400105, M(script_Init_802411A8), 0x00000000, + 0x00000000, M(npcSettings_80240950), 0xC2480000, 0x00000000, 0x42A00000, 0x00400105, M(Init_802411A8), 0x00000000, 0x00000000, 0x0000002D, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00007FFF, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, @@ -254,59 +220,48 @@ s32 M(npcGroupList_80241450)[] = { s32 padding2[] = {0, 0}; -// 8C9400 -Script M(script_80241470) = { - SI_CALL(0x802C9DCC, 0, 9, 0x7FFFFE00), - SI_SET(SI_SAVE_VAR(0), 0xFFFFFF8B), - SI_RETURN(), - SI_END(), -}; +Script M(Script_80241470) = SCRIPT({ + ModifyColliderFlags(0, 9, 0x7FFFFE00) + SI_SAVE_VAR(0) = 0xFFFFFF8B +}); -Script M(script_802414A8) = { - SI_SET(SI_SAVE_FLAG(54), 1), - SI_RETURN(), - SI_END(), -}; +Script M(Script_802414A8) = SCRIPT({ + SI_SAVE_FLAG(54) = 1 +}); -Script M(script_802414C8) = { - SI_LABEL(0), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CAF2C, 0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_WAIT_FRAMES(1), - SI_GOTO(0), - SI_RETURN(), - SI_END(), -}; +Script M(Script_802414C8) = SCRIPT({ +0: + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetCamTarget(0, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + sleep 1 + goto 0 +}); -// *INDENT-OFF* -Script M(script_MakeEntities) = { - SI_IF_LT(SI_SAVE_VAR(0), 0xFFFFFF8B), - SI_CALL(0x80111D38, 0x802EA10C, 45, 0, 70, 15, 0x80000000), - SI_CALL(0x80111FB0, M(script_80241470)), - SI_ELSE(), - SI_CALL(0x802C9DCC, 0, 9, 0x7FFFFE00), - SI_END_IF(), - SI_IF_EQ(SI_SAVE_FLAG(54), 0), - SI_CALL(0x80111D38, 0x802EA19C, 230, 0, 310, 15, 0x80000000), - SI_CALL(0x80111FB0, M(script_802414A8)), - SI_END_IF(), - SI_CALL(0x80111D38, 0x802EA588, 230, 60, 310, 15, 151, 0x80000000), - SI_CALL(0x8011206C, SI_SAVE_FLAG(52)), - SI_CALL(0x80111D38, 0x802EA0C4, 230, 50, 0xFFFFFF60, 15, 0x80000000), - SI_CALL(0x80111D38, 0x802EA0C4, 165, 0, 380, 20, 0x80000000), - SI_CALL(0x80111D38, 0x802EA564, 0xFFFFFF56, 0, 370, 43, 343, 0x80000000), - SI_CALL(0x8011206C, SI_SAVE_FLAG(50)), - SI_CALL(0x80111D38, 0x802EAA54, 345, 75, 0xFFFFFF06, 0, 100, 0x80000000), - SI_CALL(0x802D6CC0, 343, 345, 205, 0xFFFFFF06, 17, SI_SAVE_FLAG(56)), - SI_CALL(0x802D6CC0, 343, 345, 230, 0xFFFFFF06, 17, SI_SAVE_FLAG(57)), - SI_CALL(0x802D6CC0, 343, 345, 255, 0xFFFFFF06, 17, SI_SAVE_FLAG(58)), - SI_CALL(0x802D6CC0, 343, 345, 280, 0xFFFFFF06, 17, SI_SAVE_FLAG(59)), - SI_CALL(0x802D6CC0, 128, 229, 250, 0xFFFFFF64, 17, SI_SAVE_FLAG(49)), - SI_CALL(0x80111D38, 0x802EAB04, 300, 0, 150, 0, 18, 0x80000000), - SI_CALL(0x80112114, SI_SAVE_FLAG(88)), - SI_CALL(0x80111D38, 0x802EA7E0, 130, 60, 0, 0, 0x80000000), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(MakeEntities) = SCRIPT({ + if SI_SAVE_VAR(0) < 0xFFFFFF8B { + MakeEntity(0x802EA10C, 45, 0, 70, 15, 0x80000000) + AssignScript(M(Script_80241470)) + } else { + ModifyColliderFlags(0, 9, 0x7FFFFE00) + } + if SI_SAVE_FLAG(54) == 0 { + MakeEntity(0x802EA19C, 230, 0, 310, 15, 0x80000000) + AssignScript(M(Script_802414A8)) + } + MakeEntity(0x802EA588, 230, 60, 310, 15, 151, 0x80000000) + AssignBlockFlag(SI_SAVE_FLAG(52)) + MakeEntity(0x802EA0C4, 230, 50, 0xFFFFFF60, 15, 0x80000000) + MakeEntity(0x802EA0C4, 165, 0, 380, 20, 0x80000000) + MakeEntity(0x802EA564, 0xFFFFFF56, 0, 370, 43, 343, 0x80000000) + AssignBlockFlag(SI_SAVE_FLAG(50)) + MakeEntity(0x802EAA54, 345, 75, 0xFFFFFF06, 0, 100, 0x80000000) + MakeItemEntity(343, 345, 205, 0xFFFFFF06, 17, SI_SAVE_FLAG(56)) + MakeItemEntity(343, 345, 230, 0xFFFFFF06, 17, SI_SAVE_FLAG(57)) + MakeItemEntity(343, 345, 255, 0xFFFFFF06, 17, SI_SAVE_FLAG(58)) + MakeItemEntity(343, 345, 280, 0xFFFFFF06, 17, SI_SAVE_FLAG(59)) + MakeItemEntity(128, 229, 250, 0xFFFFFF64, 17, SI_SAVE_FLAG(49)) + MakeEntity(0x802EAB04, 300, 0, 150, 0, 18, 0x80000000) + AssignPanelFlag(SI_SAVE_FLAG(88)) + MakeEntity(0x802EA7E0, 130, 60, 0, 0, 0x80000000) +}); diff --git a/src/world/area_kmr/kmr_03/8C83A0.c b/src/world/area_kmr/kmr_03/8C83A0.c index de44b33c5e..1e2f655be9 100644 --- a/src/world/area_kmr/kmr_03/8C83A0.c +++ b/src/world/area_kmr/kmr_03/8C83A0.c @@ -3,181 +3,179 @@ #include "world/common/SomeMatrixOperations.inc.c" // *INDENT-OFF* -Script M(script_SearchBush_802417F0) = { - SI_USE_BUFFER(SI_VAR(0)), - SI_CMD(0x34, 0xFE363C81, 0xFE363C82, 0xFE363C83, 0xFE363C84), - SI_CALL(0x802D1DFC, SI_VAR(5), SI_VAR(15), SI_VAR(7)), - SI_THREAD(), - SI_SET(SI_FLAG(0), 0), - SI_IF_NE(SI_VAR(1), 0), - SI_LOOP(5), - SI_USE_BUFFER(SI_VAR(1)), - SI_CMD(0x31, 0xFE363C82), - SI_LOOP(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_CALL(SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1), 1, SI_VAR(15), 0), - SI_IF_EQ(SI_FLAG(0), 0), - SI_SET(SI_FLAG(0), 1), - SI_CALL(0x802CA558, SI_VAR(3), 339, 0), - SI_END_IF(), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_USE_BUFFER(SI_VAR(1)), - SI_CMD(0x31, 0xFE363C82), - SI_LOOP(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_CALL(SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1), -1, SI_VAR(15), 0), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_END_LOOP(), - SI_USE_BUFFER(SI_VAR(1)), - SI_CMD(0x31, 0xFE363C82), - SI_LOOP(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_CALL(0x802C8B60, SI_VAR(3), 0, 0, 0), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_END_IF(), - SI_END_THREAD(), - SI_THREAD(), - SI_IF_NE(SI_VAR(2), 0), - SI_USE_BUFFER(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_LOOP(SI_VAR(3)), - SI_CMD(0x31, 0xFE363C84), - SI_CMD(0x33, 0xFE363C85, 0xFE363C86, 0xFE363C87), - SI_CMD(0x33, 0xFE363C88, 0xFE363C89, 0xFE363C8A), - SI_IF_EQ(SI_VAR(10), 0), - SI_CALL(0x802D6DC0, SI_VAR(4), SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9)), - SI_ELSE(), - SI_CALL(0x802D593C, SI_VAR(10), SI_VAR(11)), - SI_IF_EQ(SI_VAR(11), 0), - SI_CALL(0x802D58E0, SI_VAR(10), 1), - SI_CALL(0x802D6DC0, SI_VAR(4), SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9)), - SI_END_IF(), - SI_END_IF(), - SI_END_LOOP(), - SI_END_IF(), - SI_END_THREAD(), - SI_WAIT_FRAMES(15), - SI_IF_NE(SI_VAR(4), 0), - SI_EXEC_WAIT(0xFE363C84), - SI_END_IF(), - SI_RETURN(), - SI_END(), +Script M(SearchBush_802417F0) = { + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(0)), + SI_CMD(ScriptOpcode_BUFFER_READ_4, SI_VAR(1), SI_VAR(2), SI_VAR(3), SI_VAR(4)), + SI_CMD(ScriptOpcode_CALL, GetPlayerPos, SI_VAR(5), SI_VAR(15), SI_VAR(7)), + SI_CMD(ScriptOpcode_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SET, SI_FLAG(0), 0), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(1), 0), + SI_CMD(ScriptOpcode_LOOP, 5), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(1)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(2)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_CALL, SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1005859375), 1, SI_VAR(15), 0), + SI_CMD(ScriptOpcode_IF_EQ, SI_FLAG(0), 0), + SI_CMD(ScriptOpcode_SET, SI_FLAG(0), 1), + SI_CMD(ScriptOpcode_CALL, PlaySoundAtModel, SI_VAR(3), 339, 0), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(1)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(2)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_CALL, SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1005859375), -1, SI_VAR(15), 0), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(1)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(2)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_CALL, TranslateModel, SI_VAR(3), 0, 0, 0), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SPAWN_THREAD), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(2), 0), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(3)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(4)), + SI_CMD(ScriptOpcode_BUFFER_READ_3, SI_VAR(5), SI_VAR(6), SI_VAR(7)), + SI_CMD(ScriptOpcode_BUFFER_READ_3, SI_VAR(8), SI_VAR(9), SI_VAR(10)), + SI_CMD(ScriptOpcode_IF_EQ, SI_VAR(10), 0), + SI_CMD(ScriptOpcode_CALL, DropItemEntity, SI_VAR(4), SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9)), + SI_CMD(ScriptOpcode_ELSE), + SI_CMD(ScriptOpcode_CALL, GetValueByRef, SI_VAR(10), SI_VAR(11)), + SI_CMD(ScriptOpcode_IF_EQ, SI_VAR(11), 0), + SI_CMD(ScriptOpcode_CALL, SetValueByRef, SI_VAR(10), 1), + SI_CMD(ScriptOpcode_CALL, DropItemEntity, SI_VAR(4), SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9)), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 15), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(4), 0), + SI_CMD(ScriptOpcode_AWAIT_SCRIPT, 0xFE363C84), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_RETURN), + SI_CMD(ScriptOpcode_END) }; -// *INDENT-ON* -// *INDENT-OFF* -Script M(script_ShakeTree_80241B50) = { - SI_TIMESCALE(SI_FIXED(2.0f)), - SI_USE_BUFFER(SI_VAR(0)), - SI_CMD(0x34, 0xFE363C81, 0xFE363C82, 0xFE363C83, 0xFE363C84), - SI_CMD(0x31, 0xFE363C85), - SI_CALL(0x802D1DFC, SI_VAR(6), SI_VAR(15), SI_VAR(8)), - SI_CALL(0x802D6150, 357), - SI_CALL(0x802D6150, 358), - SI_THREAD(), - SI_SET(SI_FLAG(0), 0), - SI_IF_NE(SI_VAR(1), 0), - SI_WAIT_FRAMES(1), - SI_LOOP(5), - SI_USE_BUFFER(SI_VAR(1)), - SI_CMD(0x31, 0xFE363C82), - SI_LOOP(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_CALL(SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1), SI_FIXED(0.2), SI_VAR(15), 0), - SI_IF_EQ(SI_FLAG(0), 0), - SI_SET(SI_FLAG(0), 1), - SI_CALL(0x802CA558, SI_VAR(3), 358, 0), - SI_END_IF(), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_USE_BUFFER(SI_VAR(1)), - SI_CMD(0x31, 0xFE363C82), - SI_LOOP(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_CALL(SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1), SI_FIXED(-0.2), SI_VAR(15), 0), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_END_LOOP(), - SI_USE_BUFFER(SI_VAR(1)), - SI_CMD(0x31, 0xFE363C82), - SI_LOOP(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_CALL(0x802C8B60, SI_VAR(3), 0, 0, 0), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_END_IF(), - SI_END_THREAD(), - SI_THREAD(), - SI_SET(SI_FLAG(0), 0), - SI_IF_NE(SI_VAR(2), 0), - SI_LOOP(5), - SI_USE_BUFFER(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_LOOP(SI_VAR(3)), - SI_CMD(0x31, 0xFE363C84), - SI_CALL(SomeMatrixOperation2, SI_VAR(4), SI_FIXED(0.1), SI_FIXED(0.2), SI_VAR(15), 0), - SI_IF_EQ(SI_FLAG(0), 0), - SI_SET(SI_FLAG(0), 1), - SI_CALL(0x802CA558, SI_VAR(4), 357, 0), - SI_END_IF(), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_USE_BUFFER(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_LOOP(SI_VAR(3)), - SI_CMD(0x31, 0xFE363C84), - SI_CALL(SomeMatrixOperation2, SI_VAR(4), SI_FIXED(0.1), SI_FIXED(-0.2), SI_VAR(15), 0), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_END_LOOP(), - SI_USE_BUFFER(SI_VAR(2)), - SI_CMD(0x31, 0xFE363C83), - SI_LOOP(SI_VAR(3)), - SI_CMD(0x31, 0xFE363C84), - SI_CALL(0x802C8B60, SI_VAR(4), 0, 0, 0), - SI_END_LOOP(), - SI_WAIT_FRAMES(1), - SI_END_IF(), - SI_END_THREAD(), - SI_THREAD(), - SI_IF_NE(SI_VAR(3), 0), - SI_USE_BUFFER(SI_VAR(3)), - SI_CMD(0x31, 0xFE363C84), - SI_LOOP(SI_VAR(4)), - SI_CMD(0x31, 0xFE363C85), - SI_CMD(0x33, 0xFE363C86, 0xFE363C87, 0xFE363C88), - SI_CMD(0x33, 0xFE363C89, 0xFE363C8A, 0xFE363C8B), - SI_IF_EQ(SI_VAR(11), 0), - SI_CALL(0x802D6DC0, SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9), SI_VAR(10)), - SI_ELSE(), - SI_CALL(0x802D593C, SI_VAR(11), SI_VAR(12)), - SI_IF_EQ(SI_VAR(12), 0), - SI_CALL(0x802D58E0, SI_VAR(11), 1), - SI_CALL(0x802D6DC0, SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9), SI_VAR(10)), - SI_END_IF(), - SI_END_IF(), - SI_END_LOOP(), - SI_END_IF(), - SI_END_THREAD(), - SI_THREAD(), - SI_IF_NE(SI_VAR(4), 0), - SI_USE_BUFFER(SI_VAR(4)), - SI_CMD(0x31, 0xFE363C85), - SI_LOOP(SI_VAR(5)), - SI_CMD(0x33, 0xFE363C86, 0xFE363C87, 0xFE363C88), - SI_CALL(0x802D829C, 20, 0, SI_VAR(6), SI_VAR(7), SI_VAR(8), 100, 0, 0, 0, 0, 0, 0, 0, 0), - SI_END_LOOP(), - SI_END_IF(), - SI_END_THREAD(), - SI_IF_NE(SI_VAR(5), 0), - SI_EXEC_WAIT(0xFE363C85), - SI_END_IF(), - SI_WAIT_FRAMES(15), - SI_RETURN(), - SI_END(), +Script M(ShakeTree_80241B50) = { + SI_CMD(ScriptOpcode_SET_TIMESCALE, SI_FIXED(2.0)), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(0)), + SI_CMD(ScriptOpcode_BUFFER_READ_4, SI_VAR(1), SI_VAR(2), SI_VAR(3), SI_VAR(4)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(5)), + SI_CMD(ScriptOpcode_CALL, GetPlayerPos, SI_VAR(6), SI_VAR(15), SI_VAR(8)), + SI_CMD(ScriptOpcode_CALL, PlaySound, 357), + SI_CMD(ScriptOpcode_CALL, PlaySound, 358), + SI_CMD(ScriptOpcode_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SET, SI_FLAG(0), 0), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(1), 0), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_LOOP, 5), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(1)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(2)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_CALL, SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1005859375), SI_FIXED(0.2001953125), SI_VAR(15), 0), + SI_CMD(ScriptOpcode_IF_EQ, SI_FLAG(0), 0), + SI_CMD(ScriptOpcode_SET, SI_FLAG(0), 1), + SI_CMD(ScriptOpcode_CALL, PlaySoundAtModel, SI_VAR(3), 358, 0), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(1)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(2)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_CALL, SomeMatrixOperation2, SI_VAR(3), SI_FIXED(0.1005859375), SI_FIXED(-0.19921875), SI_VAR(15), 0), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(1)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(2)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_CALL, TranslateModel, SI_VAR(3), 0, 0, 0), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SET, SI_FLAG(0), 0), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(2), 0), + SI_CMD(ScriptOpcode_LOOP, 5), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(3)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(4)), + SI_CMD(ScriptOpcode_CALL, SomeMatrixOperation2, SI_VAR(4), SI_FIXED(0.1005859375), SI_FIXED(0.2001953125), SI_VAR(15), 0), + SI_CMD(ScriptOpcode_IF_EQ, SI_FLAG(0), 0), + SI_CMD(ScriptOpcode_SET, SI_FLAG(0), 1), + SI_CMD(ScriptOpcode_CALL, PlaySoundAtModel, SI_VAR(4), 357, 0), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(3)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(4)), + SI_CMD(ScriptOpcode_CALL, SomeMatrixOperation2, SI_VAR(4), SI_FIXED(0.1005859375), SI_FIXED(-0.19921875), SI_VAR(15), 0), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(2)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(3)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(3)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(4)), + SI_CMD(ScriptOpcode_CALL, TranslateModel, SI_VAR(4), 0, 0, 0), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 1), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SPAWN_THREAD), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(3), 0), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(3)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(4)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(4)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(5)), + SI_CMD(ScriptOpcode_BUFFER_READ_3, SI_VAR(6), SI_VAR(7), SI_VAR(8)), + SI_CMD(ScriptOpcode_BUFFER_READ_3, SI_VAR(9), SI_VAR(10), SI_VAR(11)), + SI_CMD(ScriptOpcode_IF_EQ, SI_VAR(11), 0), + SI_CMD(ScriptOpcode_CALL, DropItemEntity, SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9), SI_VAR(10)), + SI_CMD(ScriptOpcode_ELSE), + SI_CMD(ScriptOpcode_CALL, GetValueByRef, SI_VAR(11), SI_VAR(12)), + SI_CMD(ScriptOpcode_IF_EQ, SI_VAR(12), 0), + SI_CMD(ScriptOpcode_CALL, SetValueByRef, SI_VAR(11), 1), + SI_CMD(ScriptOpcode_CALL, DropItemEntity, SI_VAR(5), SI_VAR(6), SI_VAR(7), SI_VAR(8), SI_VAR(9), SI_VAR(10)), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_SPAWN_THREAD), + SI_CMD(ScriptOpcode_SPAWN_THREAD), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(4), 0), + SI_CMD(ScriptOpcode_USE_BUFFER, SI_VAR(4)), + SI_CMD(ScriptOpcode_BUFFER_READ_1, SI_VAR(5)), + SI_CMD(ScriptOpcode_LOOP, SI_VAR(5)), + SI_CMD(ScriptOpcode_BUFFER_READ_3, SI_VAR(6), SI_VAR(7), SI_VAR(8)), + SI_CMD(ScriptOpcode_CALL, PlayEffect, 20, 0, SI_VAR(6), SI_VAR(7), SI_VAR(8), 100, 0, 0, 0, 0, 0, 0, 0, 0), + SI_CMD(ScriptOpcode_END_LOOP), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_END_SPAWN_THREAD), + SI_CMD(ScriptOpcode_IF_NE, SI_VAR(5), 0), + SI_CMD(ScriptOpcode_AWAIT_SCRIPT, 0xFE363C85), + SI_CMD(ScriptOpcode_END_IF), + SI_CMD(ScriptOpcode_SLEEP_FRAMES, 15), + SI_CMD(ScriptOpcode_RETURN), + SI_CMD(ScriptOpcode_END) }; // *INDENT-ON* @@ -205,41 +203,36 @@ s32 M(treeEffectVectors_Tree1)[] = { 0x00000002, 0xFFFFFFB0, 0x00000082, 0x00000012, 0x0000001C, 0x00000082, 0x00000027, }; -// *INDENT-OFF* -Script M(script_Tree1_Callback) = { - SI_IF_EQ(SI_SAVE_FLAG(53), 1), - SI_RETURN(), - SI_END_IF(), - SI_IF_EQ(SI_MAP_FLAG(10), 1), - SI_RETURN(), - SI_END_IF(), - SI_WAIT_FRAMES(10), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_IF_LT(SI_VAR(0), 0xFFFFFFE2), - SI_CALL(0x802D6CC0, 138, 0xFFFFFFE9, 100, 35, 13, SI_SAVE_FLAG(53)), - SI_ELSE(), - SI_CALL(0x802D6CC0, 138, 0xFFFFFFAB, 100, 16, 13, SI_SAVE_FLAG(53)), - SI_END_IF(), - SI_SET(SI_MAP_FLAG(10), 1), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(Tree1_Callback) = SCRIPT({ + if SI_SAVE_FLAG(53) == 1 { + return + } + if SI_MAP_FLAG(10) == 1 { + return + } + sleep 10 + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + if SI_VAR(0) < 0xFFFFFFE2 { + MakeItemEntity(138, 0xFFFFFFE9, 100, 35, 13, SI_SAVE_FLAG(53)) + } else { + MakeItemEntity(138, 0xFFFFFFAB, 100, 16, 13, SI_SAVE_FLAG(53)) + } + SI_MAP_FLAG(10) = 1 +}); s32 M(shakeTreeEvent_Tree1)[] = { - M(treeModelList_Tree1_Leaves), M(treeModelList_Tree1_Trunk), 0x00000000, M(treeEffectVectors_Tree1), M(script_Tree1_Callback), + M(treeModelList_Tree1_Leaves), M(treeModelList_Tree1_Trunk), 0x00000000, M(treeEffectVectors_Tree1), M(Tree1_Callback), }; s32 M(triggerCoord_802422A8)[] = { 0xC2280000, 0x00000000, 0xC1500000, 0x00000000, }; -Script M(script_802422B8) = { - SI_SET(SI_VAR(0), M(searchBushEvent_Bush1)), - SI_BIND(M(script_SearchBush_802417F0), TriggerFlag_WALL_INTERACT, 53, NULL), - SI_SET(SI_VAR(0), M(shakeTreeEvent_Tree1)), - SI_BIND(M(script_ShakeTree_80241B50), TriggerFlag_WALL_HAMMER, 52, NULL), - SI_BIND(M(script_ShakeTree_80241B50), TriggerFlag_BOMB, M(triggerCoord_802422A8), NULL), - SI_RETURN(), - SI_END(), -}; +Script M(Script_802422B8) = SCRIPT({ + SI_VAR(0) = M(searchBushEvent_Bush1) + bind M(SearchBush_802417F0) to TriggerFlag_WALL_INTERACT 53 + SI_VAR(0) = M(shakeTreeEvent_Tree1) + bind M(ShakeTree_80241B50) to TriggerFlag_WALL_HAMMER 52 + bind M(ShakeTree_80241B50) to TriggerFlag_BOMB M(triggerCoord_802422A8) +}); + diff --git a/src/world/area_kmr/kmr_03/8C85E0.c b/src/world/area_kmr/kmr_03/8C85E0.c index b2a4a3b6b1..891b9090f3 100644 --- a/src/world/area_kmr/kmr_03/8C85E0.c +++ b/src/world/area_kmr/kmr_03/8C85E0.c @@ -1,90 +1,86 @@ #include "kmr_03.h" -// *INDENT-OFF* -Script M(script_80242340) = { - SI_CALL(0x802CB860, 0, 0xFFFFFEF2, 20, 0xFFFFFFB0), - SI_CALL(0x802CBE2C, 0, 0xFFFFFEF2, 20, 0xFFFFFFB0), - SI_CALL(0x802CBBE4, 0, SI_FIXED(700.0f)), - SI_CALL(0x802CBEF0, 0, SI_FIXED(90.0f)), - SI_CALL(0x802CB79C, 0, 0, 1), - SI_IF_GE(SI_SAVE_VAR(0), 0xFFFFFF89), - SI_CALL(0x802D0EF0, 0, 0xFFFFFC18, 0), - SI_CALL(0x802D0E28, 1), - SI_CALL(0x802D0EF0, 0xFFFFFF20, 20, 0xFFFFFFB0), - SI_CALL(0x802CDCB0, 0xFFFFFFFC, 0xFFFFFF20, 20, 0xFFFFFFB0), - SI_WAIT_FRAMES(20), - SI_CALL(0x802CBEF0, 0, SI_FIXED(3.0f)), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CB860, 0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CBE2C, 0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CB79C, 0, 0, 1), - SI_CALL(0x802CC354, 0, SI_FIXED(1.0f)), - SI_CALL(0x802CB79C, 0, 0, 0), - SI_CALL(0x802D0E28, 0), - SI_RETURN(), - SI_END_IF(), - SI_CALL(0x802D0E28, 1), - SI_CALL(0x802D0DE4, 1), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802D0EF0, SI_VAR(0), 0xFFFFFC18, SI_VAR(2)), - SI_WAIT_FRAMES(30), - SI_CALL(0x802CBBE4, 0, 220), - SI_CALL(0x802CBEF0, 0, SI_FIXED(1.0f)), - SI_CALL(0x802CB79C, 0, 0, 1), - SI_CALL(0x802CC354, 0, SI_FIXED(1.0f)), - SI_THREAD(), - SI_WAIT_FRAMES(18), - SI_CALL(0x802D2CD8, 373, 0), - SI_WAIT_FRAMES(30), - SI_CALL(0x802D2CD8, 374, 0), - SI_WAIT_FRAMES(28), - SI_CALL(0x802D2CD8, 373, 0), - SI_END_THREAD(), - SI_CALL(0x802D0DA0, 1), - SI_CALL(0x802D1084, 0x10002), - SI_CALL(0x802D0EF0, 0xFFFFFF20, 120, 0xFFFFFFB0), - SI_CALL(0x802D193C, 90, 0), - SI_LABEL(0), - SI_WAIT_FRAMES(1), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_ADD(SI_VAR(1), 0xFFFFFFFE), - SI_CALL(0x802D0EF0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_IF_GT(SI_VAR(1), 86), - SI_GOTO(0), - SI_END_IF(), - SI_CALL(0x802D0EF0, 0xFFFFFECA, 20, 0xFFFFFFB0), - SI_THREAD(), - SI_WAIT_FRAMES(20), - SI_CALL(0x802CBE2C, 0, 0xFFFFFECA, 20, 0xFFFFFFB0), - SI_CALL(0x802CBEF0, 0, SI_FIXED(0.2)), - SI_CALL(0x802CB79C, 0, 0, 1), - SI_END_THREAD(), - SI_CALL(0x802D286C, 0x2800), - SI_CALL(0x802D2520, 0x10002, 5, 5, 1, 1, 0), - SI_WAIT_FRAMES(100), - SI_CALL(0x802CC354, 0, SI_FIXED(1.0f)), - SI_CALL(0x802D2520, 0x10002, 0, 0, 0, 0, 0), - SI_CALL(0x802D0DA0, 0), - SI_CALL(0x802D1084, 0x10006), - SI_WAIT_FRAMES(10), - SI_CALL(0x802D1084, 0x10007), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802D1054, SI_FIXED(1.0f)), - SI_CALL(0x802D18E8, SI_VAR(0), SI_VAR(1), SI_VAR(2), 10), - SI_CALL(0x802D1084, 0x10002), - SI_THREAD(), - SI_CALL(0x802CBEF0, 0, SI_FIXED(3.0f)), - SI_CALL(0x802D1DFC, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CB860, 0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CBE2C, 0, SI_VAR(0), SI_VAR(1), SI_VAR(2)), - SI_CALL(0x802CB79C, 0, 0, 1), - SI_CALL(0x802CC354, 0, SI_FIXED(1.0f)), - SI_CALL(0x802CB79C, 0, 0, 0), - SI_END_THREAD(), - SI_WAIT_FRAMES(30), - SI_CALL(0x802D0DE4, 0), - SI_CALL(0x802D0E28, 0), - SI_RETURN(), - SI_END(), -}; -// *INDENT-ON* +Script M(Script_80242340) = SCRIPT({ + UseSettingsFrom(0, 0xFFFFFEF2, 20, 0xFFFFFFB0) + SetPanTarget(0, 0xFFFFFEF2, 20, 0xFFFFFFB0) + SetCamDistance(0, 700.0) + SetCamSpeed(0, 90.0) + PanToTarget(0, 0, 1) + if SI_SAVE_VAR(0) >= 0xFFFFFF89 { + SetPlayerPos(0, 0xFFFFFC18, 0) + DisablePlayerInput(1) + SetPlayerPos(0xFFFFFF20, 20, 0xFFFFFFB0) + SetNpcPos(0xFFFFFFFC, 0xFFFFFF20, 20, 0xFFFFFFB0) + sleep 20 + SetCamSpeed(0, 3.0) + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + UseSettingsFrom(0, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetPanTarget(0, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + PanToTarget(0, 0, 1) + WaitForCam(0, 1.0) + PanToTarget(0, 0, 0) + DisablePlayerInput(0) + return + } + DisablePlayerInput(1) + DisablePlayerPhysics(1) + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetPlayerPos(SI_VAR(0), 0xFFFFFC18, SI_VAR(2)) + sleep 30 + SetCamDistance(0, 220) + SetCamSpeed(0, 1.0) + PanToTarget(0, 0, 1) + WaitForCam(0, 1.0) + spawn { + sleep 18 + PlaySoundAtPlayer(373, 0) + sleep 30 + PlaySoundAtPlayer(374, 0) + sleep 28 + PlaySoundAtPlayer(373, 0) + } + HidePlayerShadow(1) + SetPlayerAnimation(0x10002) + SetPlayerPos(0xFFFFFF20, 120, 0xFFFFFFB0) + InterpPlayerYaw(90, 0) +0: + sleep 1 + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SI_VAR(1) += 0xFFFFFFFE + SetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + if SI_VAR(1) > 86 { + goto 0 + } + SetPlayerPos(0xFFFFFECA, 20, 0xFFFFFFB0) + spawn { + sleep 20 + SetPanTarget(0, 0xFFFFFECA, 20, 0xFFFFFFB0) + SetCamSpeed(0, 0.2001953125) + PanToTarget(0, 0, 1) + } + 0x802D286C(0x2800) + 0x802D2520(0x10002, 5, 5, 1, 1, 0) + sleep 100 + WaitForCam(0, 1.0) + 0x802D2520(0x10002, 0, 0, 0, 0, 0) + HidePlayerShadow(0) + SetPlayerAnimation(0x10006) + sleep 10 + SetPlayerAnimation(0x10007) + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetPlayerJumpscale(1.0) + PlayerJump(SI_VAR(0), SI_VAR(1), SI_VAR(2), 10) + SetPlayerAnimation(0x10002) + spawn { + SetCamSpeed(0, 3.0) + GetPlayerPos(SI_VAR(0), SI_VAR(1), SI_VAR(2)) + UseSettingsFrom(0, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + SetPanTarget(0, SI_VAR(0), SI_VAR(1), SI_VAR(2)) + PanToTarget(0, 0, 1) + WaitForCam(0, 1.0) + PanToTarget(0, 0, 0) + } + sleep 30 + DisablePlayerPhysics(0) + DisablePlayerInput(0) +}); diff --git a/src/world/area_kmr/kmr_03/kmr_03.h b/src/world/area_kmr/kmr_03/kmr_03.h index 2e655ab085..34fd49c070 100644 --- a/src/world/area_kmr/kmr_03/kmr_03.h +++ b/src/world/area_kmr/kmr_03/kmr_03.h @@ -5,4 +5,4 @@ ApiStatus func_80240000_8C7F90(ScriptInstance* script, s32 isInitialCall); Script M(Main); -Script M(script_802406C0); +Script M(Script_802406C0); diff --git a/src/world/area_kmr/kmr_12/header.c b/src/world/area_kmr/kmr_12/header.c index 5d9a96fdf0..7541f47bc7 100644 --- a/src/world/area_kmr/kmr_12/header.c +++ b/src/world/area_kmr/kmr_12/header.c @@ -13,11 +13,9 @@ MapConfig M(config) = { .tattle = MessageID_TATTLE_KMR_12, }; -Script M(PlayMusic) = { - SI_CALL(SetMusicTrack, 0, Song_PLEASANT_PATH, 0, 8), - SI_RETURN(), - SI_END(), -}; +Script M(PlayMusic) = SCRIPT({ + SetMusicTrack(0, Song_PLEASANT_PATH, 0, 8) +}); ApiStatus GetGoomba(ScriptInstance* script, s32 isInitialCall) { script->varTable[0] = get_enemy_safe(NpcId_GOOMBA); diff --git a/tools/compile_dsl_macros.py b/tools/compile_dsl_macros.py index fa759bd752..e471d2ba43 100755 --- a/tools/compile_dsl_macros.py +++ b/tools/compile_dsl_macros.py @@ -5,6 +5,8 @@ from lark import Lark, exceptions, Tree, Transformer, Visitor, v_args, Token from lark.visitors import Discard import traceback +DEBUG_OUTPUT = None + def eprint(*args, **kwargs): print(*args, file=stderr, **kwargs) @@ -14,6 +16,9 @@ def write(s): #write_buf += s print(s, end="") + if DEBUG_OUTPUT: + print(s, file=DEBUG_OUTPUT, end="") + ANSI_RED = "\033[1;31;40m" ANSI_RESET = "\u001b[0m" @@ -26,12 +31,16 @@ def pairs(seq): script_parser = Lark(r""" - block: "{" NEWLINE* (stmt STMT_SEP)* NEWLINE* "}" + block: "{" NEWLINE* (_block STMT_SEP*)? "}" + + _block: stmt STMT_SEP _block + | stmt ?stmt: call | label ":" [stmt] -> label_decl | "goto" label -> label_goto | if_stmt + | match_stmt | "return" -> return_stmt | "break" -> break_stmt | "sleep" expr -> sleep_stmt @@ -40,7 +49,8 @@ script_parser = Lark(r""" | "await" expr -> await_stmt | lhs "=" "spawn" expr -> spawn_set_stmt | lhs set_op expr -> set_stmt - | "const" lhs set_op expr -> set_const_stmt + | lhs set_op "f" expr -> set_float_stmt + | lhs set_op "c" expr -> set_const_stmt | bind_stmt | bind_set_stmt | "unbind" -> unbind_stmt @@ -54,15 +64,27 @@ script_parser = Lark(r""" | "spawn" block -> spawn_block_stmt | "parallel" block -> parallel_block_stmt - call: CNAME "(" [expr ("," expr)* [","]] ")" + call: (CNAME | HEX_INT) "(" [expr ("," expr)* [","]] ")" - if_stmt: "if" expr if_op expr block ["else" block] - ?if_op: "==" -> if_op_eq - | "!=" -> if_op_ne - | ">" -> if_op_gt - | "<" -> if_op_lt - | ">=" -> if_op_ge - | "<=" -> if_op_le + if_stmt: "if" expr cond_op expr block ["else" block] + + ?cond_op: "==" -> cond_op_eq + | "!=" -> cond_op_ne + | ">" -> cond_op_gt + | "<" -> cond_op_lt + | ">=" -> cond_op_ge + | "<=" -> cond_op_le + | "?" -> cond_op_flag + + match_stmt: "match" expr "{" NEWLINE* (match_cases STMT_SEP*)? "}" + match_const_stmt: "matchc" expr "{" NEWLINE* (match_cases STMT_SEP*)? "}" + match_cases: match_case STMT_SEP* match_cases + | match_case + ?match_case: "else" block -> case_else + | cond_op expr ["," multi_case] block -> case_op + | expr ".." expr ["," multi_case] block -> case_range + | multi_case block -> case_multi + multi_case: expr ("," expr)* suspend_stmt: "suspend" control_type expr ("," control_type expr)* [","] resume_stmt: "resume" control_type expr ("," control_type expr)* [","] @@ -75,12 +97,12 @@ script_parser = Lark(r""" bind_set_stmt: lhs "=" "bind" expr "to" expr expr loop_stmt: "loop" [expr] block - loop_until_stmt: "loop" block "until" expr if_op expr + loop_until_stmt: "loop" block "until" expr cond_op expr ?expr: c_const_expr | ESCAPED_STRING | SIGNED_INT - | DECIMAL + | SIGNED_DECIMAL | HEX_INT | CNAME @@ -94,9 +116,6 @@ script_parser = Lark(r""" | "%=" -> set_op_mod | "&=" -> set_op_and | "|=" -> set_op_or - | ":=" -> set_op_eq_const - | ":&=" -> set_op_and_const - | ":|=" -> set_op_or_const c_const_expr: c_const_expr_internal c_const_expr_internal: "(" (c_const_expr_internal | NOT_PARENS)+ ")" @@ -112,6 +131,7 @@ script_parser = Lark(r""" %import common.HEXDIGIT %import common.ESCAPED_STRING + SIGNED_DECIMAL: ["+"|"-"] DECIMAL HEX_INT: ["+"|"-"] "0x" HEXDIGIT+ LINE_COMMENT: "//" /[^\n]*/ NEWLINE @@ -135,7 +155,7 @@ class BaseCmd(): self.context.insert(0, ctx) # must be overloaded - def opcode(): + def opcode(self): raise Exception() def to_bytecode(self): @@ -171,18 +191,18 @@ class CmdCtx(): class RootCtx(CmdCtx): def break_opcode(self, meta): - return 0x01 + return "ScriptOpcode_END" class IfCtx(CmdCtx): pass -class SwitchCtx(CmdCtx): +class MatchCtx(CmdCtx): def break_opcode(self, meta): - return 0x22 + return "ScriptOpcode_BREAK_MATCH" class LoopCtx(CmdCtx): def break_opcode(self, meta): - return 0x07 + return "ScriptOpcode_BREAK_LOOP" class LoopUntilCtx(CmdCtx): def break_opcode(self, meta): @@ -226,7 +246,16 @@ class LabelAllocation(Visitor): name = tree.children[0].children[0] if name in self.labels: raise CompileError(f"label `{name}' already declared", tree.meta) - self.labels.append(name) + + try: + label_idx = int(name, base=0) + + while len(self.labels) < label_idx: + self.labels.append(None) + + self.labels.insert(label_idx, name) + except ValueError: + self.labels.append(name) def gen_label(self): self.labels.append("$generated") @@ -254,7 +283,7 @@ class Compile(Transformer): def c_const_expr(self, tree): return f"(Bytecode){tree.children[0]}" - def DECIMAL(self, v): + def SIGNED_DECIMAL(self, v): # fixed-point return int((float(v) * 1024) - 230000000) @@ -262,7 +291,7 @@ class Compile(Transformer): # flatten children list flat = [] for node in tree.children: - if type(node) == list: + if type(node) is list: flat += node elif isinstance(node, BaseCmd): flat.append(node) @@ -271,23 +300,96 @@ class Compile(Transformer): else: raise Exception(f"block statment {type(node)} is not a BaseCmd: {node}") return flat + def _block(self, tree): + if len(tree.children) == 1: + return [tree.children[0]] + else: + return [tree.children[0], *tree.children[2]] def call(self, tree): # TODO: type checking etc - return Cmd(0x43, *tree.children, meta=tree.meta) + return Cmd("ScriptOpcode_CALL", *tree.children, meta=tree.meta) def if_stmt(self, tree): - a, op, b, block = tree.children - for cmd in block: + if len(tree.children) == 4: # no else + a, op, b, block = tree.children + for cmd in block: + if isinstance(cmd, BaseCmd): + cmd.add_context(IfCtx()) + return [ Cmd(op["if"], a, b, meta=tree.meta), *block, Cmd("ScriptOpcode_END_IF") ] + else: + a, op, b, block, else_block = tree.children + for cmd in block: + if isinstance(cmd, BaseCmd): + cmd.add_context(IfCtx()) + for cmd in else_block: + if isinstance(cmd, BaseCmd): + cmd.add_context(IfCtx()) + return [ Cmd(op["if"], a, b, meta=tree.meta), *block, Cmd("ScriptOpcode_ELSE"), *else_block, Cmd("ScriptOpcode_END_IF") ] + + def cond_op_eq(self, tree): return { "if": "ScriptOpcode_IF_EQ", "case": "ScriptOpcode_CASE_EQ" } + def cond_op_ne(self, tree): return { "if": "ScriptOpcode_IF_NE", "case": "ScriptOpcode_CASE_NE" } + def cond_op_lt(self, tree): return { "if": "ScriptOpcode_IF_LT", "case": "ScriptOpcode_CASE_LT" } + 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 match_stmt(self, tree): + expr = tree.children[0] + + cases = [] + for node in tree.children[1:]: + if type(node) is list: + for el in node: + if type(el) is list: + cases += el + else: + cases.append(el) + + for cmd in cases: if isinstance(cmd, BaseCmd): - cmd.add_context(IfCtx()) - return [ Cmd(op, a, b, meta=tree.meta), *block, Cmd(0x13) ] - def if_op_eq(self, tree): return 0x0A - def if_op_ne(self, tree): return 0x0B - def if_op_lt(self, tree): return 0x0C - def if_op_gt(self, tree): return 0x0D - def if_op_le(self, tree): return 0x0E - def if_op_ge(self, tree): return 0x0F + cmd.add_context(MatchCtx()) + else: + raise Exception(f"uncompiled match case: {cmd}") + + return [ + Cmd("ScriptOpcode_MATCH", expr, meta=tree.meta), + *cases, + Cmd("ScriptOpcode_END_MATCH"), + ] + def match_const_stmt(self, tree): + commands = self.match_stmt(tree) + commands[0].opcode = "ScriptOpcode_MATCH_CONST" + return commands + def match_cases(self, tree): + if len(tree.children) == 1: + return [tree.children[0]] + else: + return [tree.children[0], *tree.children[2]] + + def case_else(self, tree): + return [Cmd("ScriptOpcode_ELSE"), *tree.children[0]] + def case_op(self, tree): + if len(tree.children) == 4: + op, expr, multi_case, block = tree.children + return [Cmd(op["case"], expr), *multi_case, *block, Cmd("ScriptOpcode_END_CASE_MULTI")] + else: + op, expr, block = tree.children + return [Cmd(op["case"], expr), *block] + def case_range(self, tree): + if len(tree.children) == 4: + a, b, multi_case, block = tree.children + return [Cmd("ScriptOpcode_CASE_RANGE", a, b), *multi_case, *block, Cmd("ScriptOpcode_END_CASE_MULTI")] + else: + a, b, block = tree.children + return [Cmd("ScriptOpcode_CASE_RANGE", a, b), *block] + def case_multi(self, tree): + multi_case, block = tree.children + return [*multi_case, *block, Cmd("ScriptOpcode_END_CASE_MULTI")] + + def multi_case(self, tree): + return [Cmd("ScriptOpcode_CASE_MULTI_OR_EQ", expr) for expr in tree.children] def loop_stmt(self, tree): expr = tree.children.pop(0) if len(tree.children) > 1 else 0 @@ -297,7 +399,7 @@ class Compile(Transformer): if isinstance(cmd, BaseCmd): cmd.add_context(LoopCtx()) - return [ Cmd(0x05, expr, meta=tree.meta), *block, Cmd(0x06) ] + return [ Cmd("ScriptOpcode_LOOP", expr, meta=tree.meta), *block, Cmd("ScriptOpcode_END_LOOP") ] # loop..until pseudoinstruction def loop_until_stmt(self, tree): @@ -310,21 +412,21 @@ class Compile(Transformer): label = self.alloc.gen_label() return [ - Cmd(0x03, label, meta=tree.meta), # label: + Cmd("ScriptOpcode_LABEL", label, meta=tree.meta), *block, - Cmd(op, a, b, meta=tree.meta), # if a op b - Cmd(0x04, label, meta=tree.meta), # goto label - Cmd(0x13, meta=tree.meta), # end if + Cmd(op["if"], a, b, meta=tree.meta), + Cmd("ScriptOpcode_GOTO", label, meta=tree.meta), + Cmd("ScriptOpcode_END_IF", meta=tree.meta), ] def return_stmt(self, tree): - return Cmd(0x02, meta=tree.meta) + return Cmd("ScriptOpcode_RETURN", meta=tree.meta) def break_stmt(self, tree): return BreakCmd(meta=tree.meta) def set_group(self, tree): - return Cmd(0x4D, tree.children[0], meta=tree.meta) + return Cmd("ScriptOpcode_SET_GROUP", tree.children[0], meta=tree.meta) def suspend_stmt(self, tree): commands = [] @@ -350,115 +452,121 @@ class Compile(Transformer): def control_type_group(self, tree): return { "__control_type__": "group", - "suspend": 0x4F, - "resume": 0x50, + "suspend": "ScriptOpcode_SUSPEND_GROUP", + "resume": "ScriptOpcode_RESUME_GROUP", } def control_type_others(self, tree): return { "__control_type__": "others", - "suspend": 0x51, - "resume": 0x52, + "suspend": "ScriptOpcode_SUSPEND_OTHERS", + "resume": "ScriptOpcode_RESUME_OTHERS", } def control_type_script(self, tree): return { "__control_type__": "script", - "suspend": 0x53, - "resume": 0x54, - "kill": 0x49, + "suspend": "ScriptOpcode_SUSPEND_SCRIPT", + "resume": "ScriptOpcode_RESUME_SCRIPT", + "kill": "ScriptOpcode_KILL_SCRIPT", } def sleep_stmt(self, tree): - return Cmd(0x08, tree.children[0], meta=tree.meta) + return Cmd("ScriptOpcode_SLEEP_FRAMES", tree.children[0], meta=tree.meta) def sleep_secs_stmt(self, tree): - return Cmd(0x09, tree.children[0], meta=tree.meta) + return Cmd("ScriptOpcode_SLEEP_SECS", tree.children[0], meta=tree.meta) def bind_stmt(self, tree): script, trigger, target = tree.children - return Cmd(0x47, script, trigger, target, 1, 0, meta=tree.meta) + return Cmd("ScriptOpcode_BIND_TRIGGER", script, trigger, target, 1, 0, meta=tree.meta) def bind_set_stmt(self, tree): ret, script, trigger, target = tree.children - return Cmd(0x47, script, trigger, target, 1, ret, meta=tree.meta) + return Cmd("ScriptOpcode_BIND_TRIGGER", script, trigger, target, 1, ret, meta=tree.meta) def unbind_stmt(self, tree): - return Cmd(0x48, meta=tree.meta) + return Cmd("ScriptOpcode_UNBIND", meta=tree.meta) def spawn_stmt(self, tree): - return Cmd(0x44, tree.children[0], meta=tree.meta) + return Cmd("ScriptOpcode_SPAWN_SCRIPT", tree.children[0], meta=tree.meta) def spawn_set_stmt(self, tree): lhs, script = tree.children - return Cmd(0x45, script, lhs, meta=tree.meta) + return Cmd("ScriptOpcode_SPAWN_SCRIPT_GET_ID", script, lhs, meta=tree.meta) def await_stmt(self, tree): - return Cmd(0x46, tree.children[0], meta=tree.meta) + return Cmd("ScriptOpcode_AWAIT_SCRIPT", tree.children[0], meta=tree.meta) def set_stmt(self, tree): lhs, opcodes, rhs = tree.children if is_fixed_var(rhs): opcode = opcodes.get("float", None) if not opcode: - raise CompileError(f"operation `{opcodes['__op__']}' not supported for floats", tree.meta) + raise CompileError(f"float operation `{opcodes['__op__']}' not supported", tree.meta) else: opcode = opcodes.get("int", None) if not opcode: - raise CompileError(f"operation `{opcodes['__op__']}' not supported for ints", tree.meta) + raise CompileError(f"int operation `{opcodes['__op__']}' not supported", tree.meta) + return Cmd(opcode, lhs, rhs) + def set_float_stmt(self, tree): + lhs, opcodes, rhs = tree.children + opcode = opcodes.get("float", None) + if not opcode: + raise CompileError(f"float operation `{opcodes['__op__']}' not supported", tree.meta) return Cmd(opcode, lhs, rhs) def set_const_stmt(self, tree): lhs, opcodes, rhs = tree.children opcode = opcodes.get("const", None) if not opcode: - raise CompileError(f"operation `{opcodes['__op__']}' not supported for consts", tree.meta) + raise CompileError(f"const operation `{opcodes['__op__']}' not supported", tree.meta) return Cmd(opcode, lhs, rhs) def set_op_eq(self, tree): return { "__op__": "=", - "int": 0x24, - "const": 0x25, - "float": 0x26, + "int": "ScriptOpcode_SET", + "const": "ScriptOpcode_SET_CONST", + "float": "ScriptOpcode_SET_F", } def set_op_add(self, tree): return { "__op__": "+", - "int": 0x27, - "float": 0x2C, + "int": "ScriptOpcode_ADD", + "float": "ScriptOpcode_ADD_F", } def set_op_sub(self, tree): return { "__op__": "-", - "int": 0x28, - "float": 0x2D, + "int": "ScriptOpcode_SUB", + "float": "ScriptOpcode_SUB_F", } def set_op_mul(self, tree): return { "__op__": "*", - "int": 0x29, - "float": 0x2E, + "int": "ScriptOpcode_MUL", + "float": "ScriptOpcode_MUL_F", } def set_op_div(self, tree): return { "__op__": "/", - "int": 0x2A, - "float": 0x2F, + "int": "ScriptOpcode_DIV", + "float": "ScriptOpcode_DIV_F", } def set_op_mod(self, tree): return { "__op__": "%", - "int": 0x2B, + "int": "ScriptOpcode_MOD", } def set_op_and(self, tree): return { "__op__": "&", - "int": 0x3F, - "const": 0x41, + "int": "ScriptOpcode_AND", + "const": "ScriptOpcode_AND_CONST", } def set_op_or(self, tree): return { "__op__": "|", - "int": 0x40, - "const": 0x42, + "int": "ScriptOpcode_OR", + "const": "ScriptOpcode_OR_CONST", } def label_decl(self, tree): - if len(tree.children) == 0: + if len(tree.children) == 1: label = tree.children[0] - return Cmd(0x03, label, meta=tree.meta) + return Cmd("ScriptOpcode_LABEL", label, meta=tree.meta) else: label, cmd_or_block = tree.children @@ -470,12 +578,12 @@ class Compile(Transformer): cmd.add_context(LabelCtx(label)) return [ - Cmd(0x03, label, meta=tree.meta), + Cmd("ScriptOpcode_LABEL", label, meta=tree.meta), *cmd_or_block ] def label_goto(self, tree): label = tree.children[0] - return Cmd(0x04, label, meta=tree.meta) + return Cmd("ScriptOpcode_GOTO", label, meta=tree.meta) def label(self, tree): name = tree.children[0] if name in self.alloc.labels: @@ -493,13 +601,13 @@ class Compile(Transformer): for cmd in block: if isinstance(cmd, BaseCmd): cmd.add_context(SpawnCtx()) - return [ Cmd(0x56, meta=tree.meta), *block, Cmd(0x57) ] + return [ Cmd("ScriptOpcode_SPAWN_THREAD", meta=tree.meta), *block, Cmd("ScriptOpcode_END_SPAWN_THREAD") ] def parallel_block_stmt(self, tree): block, = tree.children for cmd in block: if isinstance(cmd, BaseCmd): cmd.add_context(ParallelCtx()) - return [ Cmd(0x58, meta=tree.meta), *block, Cmd(0x59) ] + return [ Cmd("ScriptOpcode_PARALLEL_THREAD", meta=tree.meta), *block, Cmd("ScriptOpcode_END_PARALLEL_THREAD") ] def compile_script(s): tree = script_parser.parse(s) @@ -509,8 +617,8 @@ def compile_script(s): commands = Compile().transform(tree) # add RETURN END if no explicit END (top-level `break') was given - if next((cmd for cmd in commands if cmd.opcode() == 0x01), None) == None: - commands += (Cmd(0x02), Cmd(0x01)) + if next((cmd for cmd in commands if cmd.opcode() == "ScriptOpcode_END"), None) == None: + commands += (Cmd("ScriptOpcode_RETURN"), Cmd("ScriptOpcode_END")) return commands @@ -581,6 +689,9 @@ def gen_line_map(source, source_line_no = 1): # Expects output from C preprocessor on argv if __name__ == "__main__": + if DEBUG_OUTPUT is not None: + DEBUG_OUTPUT = open(DEBUG_OUTPUT, "w") + line_no = 1 char_no = 1 file_info = [] diff --git a/tools/disasm_map.py b/tools/disasm_map.py index 3c3bbb993a..d0ffe9b910 100755 --- a/tools/disasm_map.py +++ b/tools/disasm_map.py @@ -16,8 +16,6 @@ def disassemble(bytes, offset, midx, symbol_map = {}, map_name = "map"): struct = midx.pop(0) name = struct["name"] - print(name) - if name == "Script_Main": name = f"M(Main)" #print(f"{offset:X} ({name}, start = {struct['start']:X}, len = {struct['length']:X})") @@ -35,6 +33,8 @@ def disassemble(bytes, offset, midx, symbol_map = {}, map_name = "map"): 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": @@ -222,6 +222,8 @@ if __name__ == "__main__": 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: diff --git a/tools/disasm_script.py b/tools/disasm_script.py index 2a789dc408..6950269df1 100755 --- a/tools/disasm_script.py +++ b/tools/disasm_script.py @@ -38,10 +38,12 @@ def script_lib(): # symbol_addrs.txt with open(Path(path.dirname(__file__), "symbol_addrs.txt"), "r") as file: for line in file.readlines(): - s = line.split("=") - name = s[0].strip() - addr = int(s[1].strip()[0:10], 0) - _script_lib[addr] = name + line = line.split(";")[0] + + s = [s.strip() for s in line.split("=", 1)] + name = s[0] + addr = s[1] + _script_lib[int(addr, 16)] = name return _script_lib @@ -76,12 +78,15 @@ class ScriptDisassembler: if self.done: return self.prefix + self.out - def write_line(self, line): + def write(self, line): if self.indent < 0: self.indent = 0 if self.indent > 1: self.indent_used = True self.out += " " * self.indent self.out += line + + def write_line(self, line): + self.write(line) self.out += "\n" def prefix_line(self, line): @@ -131,14 +136,14 @@ class ScriptDisassembler: if trigger == 0x00010000: trigger = "TriggerFlag_SAVE_FLAG_SET" if trigger == 0x00020000: trigger = "TriggerFlag_AREA_FLAG_SET" if trigger == 0x00100000: trigger = "TriggerFlag_BOMB" - return trigger + return f"0x{trigger:X}" if type(trigger) is int else trigger def read_word(self): return int.from_bytes(self.bytes.read(4), byteorder="big") def disassemble_command(self, opcode, argc, argv): if opcode == 0x01: - self.write_line("SI_END(),") + self.write_line("SI_CMD(ScriptOpcode_END)") self.indent -= 1 if self.indent_used: @@ -151,167 +156,195 @@ class ScriptDisassembler: self.write_line("};") self.done = True - elif opcode == 0x02: self.write_line(f"SI_RETURN(),") - elif opcode == 0x03: self.write_line(f"SI_LABEL({self.var(argv[0])}),") - elif opcode == 0x04: self.write_line(f"SI_GOTO({self.var(argv[0])}),") + elif opcode == 0x02: self.write_line(f"SI_CMD(ScriptOpcode_RETURN),") + elif opcode == 0x03: self.write_line(f"SI_CMD(ScriptOpcode_LABEL, {self.var(argv[0])}),") + elif opcode == 0x04: self.write_line(f"SI_CMD(ScriptOpcode_GOTO, {self.var(argv[0])}),") elif opcode == 0x05: - self.write_line(f"SI_LOOP({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_LOOP, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x06: self.indent -= 1 - self.write_line("SI_END_LOOP(),") - elif opcode == 0x07: self.write_line(f"SI_BREAK_LOOP(),") - elif opcode == 0x08: self.write_line(f"SI_WAIT_FRAMES({self.var(argv[0])}),") - elif opcode == 0x09: self.write_line(f"SI_WAIT_SECS({self.var(argv[0])}),") + self.write_line("SI_CMD(ScriptOpcode_END_LOOP),") + elif opcode == 0x07: self.write_line(f"SI_CMD(ScriptOpcode_BREAK_LOOP),") + elif opcode == 0x08: self.write_line(f"SI_CMD(ScriptOpcode_SLEEP_FRAMES, {self.var(argv[0])}),") + elif opcode == 0x09: self.write_line(f"SI_CMD(ScriptOpcode_SLEEP_SECS, {self.var(argv[0])}),") elif opcode == 0x0A: - self.write_line(f"SI_IF_EQ({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_EQ, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x0B: - self.write_line(f"SI_IF_NE({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_NE, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x0C: - self.write_line(f"SI_IF_LT({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_LT, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x0D: - self.write_line(f"SI_IF_GT({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_GT, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x0E: - self.write_line(f"SI_IF_LE({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_LE, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x0F: - self.write_line(f"SI_IF_GE({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_GE, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x10: - self.write_line(f"SI_IF_BITS_ON({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_FLAG, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x11: - self.write_line(f"SI_IF_BITS_OFF({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_IF_NOT_FLAG, ({self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 elif opcode == 0x12: self.indent -= 1 - self.write_line(f"SI_ELSE(),") + self.write_line(f"SI_CMD(ScriptOpcode_ELSE),") self.indent += 1 elif opcode == 0x13: self.indent -= 1 - self.write_line(f"SI_END_IF(),") + self.write_line(f"SI_CMD(ScriptOpcode_END_IF),") elif opcode == 0x14: - self.write_line(f"SI_SWITCH({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_MATCH, {self.var(argv[0])}),") self.indent += 2 elif opcode == 0x15: - self.write_line(f"SI_SWITCH_CONST(0x{argv[0]:X}),") + self.write_line(f"SI_CMD(ScriptOpcode_MATCH_CONST, 0x{argv[0]:X}),") self.indent += 2 elif opcode == 0x16: self.indent -= 1 - self.write_line(f"SI_CASE_EQ({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_EQ, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x17: self.indent -= 1 - self.write_line(f"SI_CASE_NE({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_NE, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x18: self.indent -= 1 - self.write_line(f"SI_CASE_LT({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_LT, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x19: self.indent -= 1 - self.write_line(f"SI_CASE_GT({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_GT, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x1A: self.indent -= 1 - self.write_line(f"SI_CASE_LE({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_LE, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x1B: self.indent -= 1 - self.write_line(f"SI_CASE_GE({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_GE, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x1C: self.indent -= 1 - self.write_line(f"SI_CASE_DEFAULT(),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_ELSE),") self.indent += 1 elif opcode == 0x1D: self.indent -= 1 - self.write_line(f"SI_CASE_OR_EQ({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_MULTI_OR_EQ, {self.var(argv[0])}),") + self.indent += 1 + elif opcode == 0x1E: + self.indent -= 1 + self.write_line(f"SI_CMD(ScriptOpcode_CASE_MULTI_AND_EQ, {self.var(argv[0])}),") self.indent += 1 - # opcode 0x1E? elif opcode == 0x1F: self.indent -= 1 - self.write_line(f"SI_CASE_BITS_ON({self.var(argv[0])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_FLAG, {self.var(argv[0])}),") self.indent += 1 elif opcode == 0x20: self.indent -= 1 - self.write_line(f"SI_END_MULTI_CASE(),") + self.write_line(f"SI_CMD(ScriptOpcode_END_CASE_MULTI),") self.indent += 1 elif opcode == 0x21: self.indent -= 1 - self.write_line(f"SI_CASE_RANGE({self.var(argv[0])}, {self.var(argv[1])}),") + self.write_line(f"SI_CMD(ScriptOpcode_CASE_RANGE, {self.var(argv[0])}, {self.var(argv[1])}),") self.indent += 1 - elif opcode == 0x22: self.write_line(f"SI_BREAK_CASE(),") + elif opcode == 0x22: self.write_line(f"SI_CMD(ScriptOpcode_BREAK_CASE),") elif opcode == 0x23: self.indent -= 2 - self.write_line(f"SI_END_SWITCH(),") - elif opcode == 0x24: self.write_line(f"SI_SET({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x25: self.write_line(f"SI_SET_CONST({self.var(argv[0])}, 0x{argv[1]:X}),") - elif opcode == 0x26: self.write_line(f"SI_SET_F({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x27: self.write_line(f"SI_ADD({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x28: self.write_line(f"SI_SUB({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x29: self.write_line(f"SI_MUL({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x2A: self.write_line(f"SI_DIV({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x2B: self.write_line(f"SI_MOD({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x2C: self.write_line(f"SI_ADD_F({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x2D: self.write_line(f"SI_SUB_F({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x2E: self.write_line(f"SI_MUL_F({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x2F: self.write_line(f"SI_DIV_F({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x30: self.write_line(f"SI_USE_BUFFER({self.var(argv[0])}),") - # TODO: SI_BUF commands - elif opcode == 0x3C: self.write_line(f"SI_USE_ARRAY({self.var(argv[0])}),") - elif opcode == 0x3D: self.write_line(f"SI_NEW_ARRAY({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x3E: self.write_line(f"SI_USE_FLAGS({self.var(argv[0])}),") - elif opcode == 0x3F: self.write_line(f"SI_AND({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x40: self.write_line(f"SI_OR({self.var(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x41: self.write_line(f"SI_AND_CONST({self.var(argv[0])}, 0x{argv[1]:X})") - elif opcode == 0x42: self.write_line(f"SI_OR_CONST({self.var(argv[0])}, 0x{argv[1]:X})") + self.write_line(f"SI_CMD(ScriptOpcode_END_MATCH),") + elif opcode == 0x24: self.write_line(f"SI_CMD(ScriptOpcode_SET, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x25: self.write_line(f"SI_CMD(ScriptOpcode_SET_CONST, {self.var(argv[0])}, 0x{argv[1]:X}),") + elif opcode == 0x26: self.write_line(f"SI_CMD(ScriptOpcode_SET_F, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x27: self.write_line(f"SI_CMD(ScriptOpcode_ADD, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x28: self.write_line(f"SI_CMD(ScriptOpcode_SUB, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x29: self.write_line(f"SI_CMD(ScriptOpcode_MUL, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x2A: self.write_line(f"SI_CMD(ScriptOpcode_DIV, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x2B: self.write_line(f"SI_CMD(ScriptOpcode_MOD, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x2C: self.write_line(f"SI_CMD(ScriptOpcode_ADD_F, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x2D: self.write_line(f"SI_CMD(ScriptOpcode_SUB_F, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x2E: self.write_line(f"SI_CMD(ScriptOpcode_MUL_F, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x2F: self.write_line(f"SI_CMD(ScriptOpcode_DIV_F, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x30: self.write_line(f"SI_CMD(ScriptOpcode_USE_BUFFER, {self.var(argv[0])}),") + elif opcode == 0x31: + args = ["ScriptOpcode_BUFFER_READ_1",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x32: + args = ["ScriptOpcode_BUFFER_READ_2",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x33: + args = ["ScriptOpcode_BUFFER_READ_3",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x34: + args = ["ScriptOpcode_BUFFER_READ_4",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x35: + args = ["ScriptOpcode_BUFFER_PEEK",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x36: self.write_line(f"SI_CMD(ScriptOpcode_USE_BUFFER_f, {self.var(argv[0])}),") + elif opcode == 0x37: + args = ["ScriptOpcode_BUFFER_READ_1_F",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x38: + args = ["ScriptOpcode_BUFFER_READ_2_F",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x39: + args = ["ScriptOpcode_BUFFER_READ_3_F",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x3A: + args = ["ScriptOpcode_BUFFER_READ_4_F",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x3B: + args = ["ScriptOpcode_BUFFER_PEEK_F",*map(self.var, argv)] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x3C: self.write_line(f"SI_CMD(ScriptOpcode_USE_ARRAY, {self.var(argv[0])}),") + elif opcode == 0x3D: self.write_line(f"SI_CMD(ScriptOpcode_NEW_ARRAY, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x3E: self.write_line(f"SI_CMD(ScriptOpcode_USE_FLAGS, {self.var(argv[0])}),") + elif opcode == 0x3F: self.write_line(f"SI_CMD(ScriptOpcode_AND, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x40: self.write_line(f"SI_CMD(ScriptOpcode_OR, {self.var(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x41: self.write_line(f"SI_CMD(ScriptOpcode_AND_CONST, {self.var(argv[0])}, 0x{argv[1]:X})") + elif opcode == 0x42: self.write_line(f"SI_CMD(ScriptOpcode_OR_CONST, {self.var(argv[0])}, 0x{argv[1]:X})") elif opcode == 0x43: - argv_str = "" - for arg in argv[1:]: - argv_str += ", " - argv_str += self.var(arg) - - self.write_line(f"SI_CALL({self.addr_ref(argv[0])}{argv_str}),") - elif opcode == 0x44: self.write_line(f"SI_EXEC({self.addr_ref(argv[0])}),") - elif opcode == 0x45: self.write_line(f"SI_EXEC_GET_ID({self.addr_ref(argv[0])}, {self.var(argv[1])}),") - elif opcode == 0x46: self.write_line(f"SI_EXEC_WAIT({self.addr_ref(argv[0])}),") + args = ["ScriptOpcode_CALL", self.addr_ref(argv[0]), *map(self.var, argv[1:])] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x44: self.write_line(f"SI_CMD(ScriptOpcode_SPAWN, {self.addr_ref(argv[0])}),") + elif opcode == 0x45: self.write_line(f"SI_CMD(ScriptOpcode_SPAWN_GET_ID, {self.addr_ref(argv[0])}, {self.var(argv[1])}),") + elif opcode == 0x46: self.write_line(f"SI_CMD(ScriptOpcode_AWAIT_SCRIPT, {self.addr_ref(argv[0])}),") elif opcode == 0x47: - assert argv[3] == 1 - self.write_line(f"SI_BIND({self.addr_ref(argv[0])}, {self.trigger(argv[1])}, {self.var(argv[2])}, {'NULL' if argv[4] == 0 else self.var(argv[4])}),") - elif opcode == 0x48: self.write_line(f"SI_UNBIND_ME(),") - elif opcode == 0x49: self.write_line(f"SI_KILL({self.var(argv[0])}),") - elif opcode == 0x4A: self.write_line(f"SI_JUMP({self.var(argv[0])}),") - elif opcode == 0x4B: self.write_line(f"SI_PRIORITY({self.var(argv[0])}),") - elif opcode == 0x4C: self.write_line(f"SI_TIMESCALE({self.var(argv[0])}),") - elif opcode == 0x4D: self.write_line(f"SI_GROUP({self.var(argv[0])}),") + args = ["ScriptOpcode_BIND_TRIGGER", self.addr_ref(argv[0]), self.trigger(argv[1]), *map(self.var, argv[2:])] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x48: self.write_line(f"SI_CMD(ScriptOpcode_UNBIND),") + elif opcode == 0x49: self.write_line(f"SI_CMD(ScriptOpcode_KILL_SCRIPT, {self.var(argv[0])}),") + elif opcode == 0x4A: self.write_line(f"SI_CMD(ScriptOpcode_JUMP, {self.var(argv[0])}),") + elif opcode == 0x4B: self.write_line(f"SI_CMD(ScriptOpcode_SET_PRIORITY, {self.var(argv[0])}),") + elif opcode == 0x4C: self.write_line(f"SI_CMD(ScriptOpcode_SET_TIMESCALE, {self.var(argv[0])}),") + elif opcode == 0x4D: self.write_line(f"SI_CMD(ScriptOpcode_SET_GROUP, {self.var(argv[0])}),") elif opcode == 0x4E: - assert argv[4] == 0 - assert argv[5] == 1 - self.write_line(f"SI_BIND_PADLOCK({self.addr_ref(argv[0])}, {self.trigger(argv[1])}, {self.var(argv[2])}, {self.var(argv[3])}),") - elif opcode == 0x4F: self.write_line(f"SI_SUSPEND_GROUP({self.var(argv[0])}),") - elif opcode == 0x50: self.write_line(f"SI_RESUME_GROUP({self.var(argv[0])}),") - elif opcode == 0x51: self.write_line(f"SI_SUSPEND_GROUP_NOT_ME({self.var(argv[0])}),") - elif opcode == 0x52: self.write_line(f"SI_RESUME_GROUP_NOT_ME({self.var(argv[0])}),") - elif opcode == 0x53: self.write_line(f"SI_SUSPEND({self.var(argv[0])}),") - elif opcode == 0x54: self.write_line(f"SI_RESUME({self.var(argv[0])}),") - elif opcode == 0x55: self.write_line(f"SI_EXISTS({self.var(argv[0])}),") + args = ["ScriptOpcode_BIND_TRIGGER", self.addr_ref(argv[0]), self.trigger(argv[1]), *map(self.var, argv[2:])] + self.write_line(f"SI_CMD({', '.join(args)}),") + elif opcode == 0x4F: self.write_line(f"SI_CMD(ScriptOpcode_SUSPEND_GROUP, {self.var(argv[0])}),") + elif opcode == 0x50: self.write_line(f"SI_CMD(ScriptOpcode_RESUME_GROUP, {self.var(argv[0])}),") + elif opcode == 0x51: self.write_line(f"SI_CMD(ScriptOpcode_SUSPEND_OTHERS, {self.var(argv[0])}),") + elif opcode == 0x52: self.write_line(f"SI_CMD(ScriptOpcode_RESUME_OTHERS, {self.var(argv[0])}),") + elif opcode == 0x53: self.write_line(f"SI_CMD(ScriptOpcode_SUSPEND_SCRIPT, {self.var(argv[0])}),") + elif opcode == 0x54: self.write_line(f"SI_CMD(ScriptOpcode_RESUME_SCRIPT, {self.var(argv[0])}),") + elif opcode == 0x55: self.write_line(f"SI_CMD(ScriptOpcode_SCRIPT_EXISTS, {self.var(argv[0])}, {self.var(argv[1])}),") elif opcode == 0x56: - self.write_line("SI_THREAD(),") + self.write_line("SI_CMD(ScriptOpcode_SPAWN_THREAD),") self.indent += 1 elif opcode == 0x57: self.indent -= 1 - self.write_line("SI_END_THREAD(),") + self.write_line("SI_CMD(ScriptOpcode_END_SPAWN_THREAD),") elif opcode == 0x58: - self.write_line("SI_CHILD_THREAD(),") + self.write_line("SI_CMD(ScriptOpcode_PARALLEL_THREAD),") self.indent += 1 elif opcode == 0x59: self.indent -= 1 - self.write_line("SI_END_CHILD_THREAD(),") + self.write_line("SI_CMD(ScriptOpcode_END_PARALLEL_THREAD),") else: # unknown opcode argv_str = "" @@ -324,6 +357,21 @@ class UnsupportedScript(Exception): pass class ScriptDSLDisassembler(ScriptDisassembler): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # True: case block + # CASE: single condition + # MULTI: multi-condition(s) + # MATCH: match block + self.case_stack = [] + + self.was_multi_case = False + + @property + def in_case(self): + return self.case_stack[-1] if self.case_stack else False + def var(self, arg): if arg in self.symbol_map: return self.symbol_map[arg] @@ -349,16 +397,41 @@ class ScriptDSLDisassembler(ScriptDisassembler): else: return f"{arg}" - def verify_float(self, var): + def is_float(self, var): try: float(var) + return True except Exception: - # not a float! - raise UnsupportedScript("non-float used in float command") - - return var + return False def disassemble_command(self, opcode, argc, argv): + # write case block braces + if self.in_case == "CASE" or self.in_case == "MULTI": + if opcode == 0x1D: # multi case + pass + elif 0x16 <= opcode <= 0x21: # standard case conditions + # open and close empty case + self.out += " {}\n" + + self.case_stack.pop() + assert self.in_case == "MATCH" + + self.was_multi_case = False + else: + # open case + self.out += " {\n" + + self.case_stack.append(True) + + self.indent += 1 + elif self.in_case != "MATCH" and 0x16 <= opcode <= 0x21: # new case, not including the first + assert self.case_stack.pop() == True + self.was_multi_case = self.case_stack.pop() == "MULTI" + assert self.in_case == "MATCH" + + self.indent -= 1 + self.write_line("}") + if opcode == 0x01: if self.out.endswith("return\n"): # implicit return; break @@ -373,8 +446,8 @@ class ScriptDSLDisassembler(ScriptDisassembler): self.done = True elif opcode == 0x02: self.write_line(f"return") - elif opcode == 0x03: self.write_line(f"lbl{self.var(argv[0])}:") - elif opcode == 0x04: self.write_line(f"goto lbl{self.var(argv[0])}") + elif opcode == 0x03: self.write_line(f"{self.var(argv[0])}:") + elif opcode == 0x04: self.write_line(f"goto {self.var(argv[0])}") elif opcode == 0x05: if argv[0] == 0: self.write_line("loop {") @@ -405,6 +478,9 @@ class ScriptDSLDisassembler(ScriptDisassembler): elif opcode == 0x0F: 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.indent += 1 elif opcode == 0x12: self.indent -= 1 self.write_line("} else {") @@ -412,77 +488,111 @@ class ScriptDSLDisassembler(ScriptDisassembler): elif opcode == 0x13: self.indent -= 1 self.write_line("}") - # elif opcode == 0x14: - # self.write_line(f"SI_SWITCH({self.var(argv[0])}),") - # self.indent += 2 - # elif opcode == 0x15: - # self.write_line(f"SI_SWITCH_CONST(0x{argv[0]:X}),") - # self.indent += 2 - # elif opcode == 0x16: - # self.indent -= 1 - # self.write_line(f"SI_CASE_EQ({self.var(argv[0])}),") - # self.indent += 1 - # elif opcode == 0x17: - # self.indent -= 1 - # self.write_line(f"SI_CASE_NE({self.var(argv[0])}),") - # self.indent += 1 - # elif opcode == 0x18: - # self.indent -= 1 - # self.write_line(f"SI_CASE_LT({self.var(argv[0])}),") - # self.indent += 1 - # elif opcode == 0x19: - # self.indent -= 1 - # self.write_line(f"SI_CASE_GT({self.var(argv[0])}),") - # self.indent += 1 - # elif opcode == 0x1A: - # self.indent -= 1 - # self.write_line(f"SI_CASE_LE({self.var(argv[0])}),") - # self.indent += 1 - # elif opcode == 0x1B: - # self.indent -= 1 - # self.write_line(f"SI_CASE_GE({self.var(argv[0])}),") - # self.indent += 1 - # elif opcode == 0x1C: - # self.indent -= 1 - # self.write_line(f"SI_CASE_DEFAULT(),") - # self.indent += 1 - # elif opcode == 0x1D: - # self.indent -= 1 - # self.write_line(f"SI_CASE_OR_EQ({self.var(argv[0])}),") - # self.indent += 1 - # # opcode 0x1E? - # elif opcode == 0x1F: - # self.indent -= 1 - # self.write_line(f"SI_CASE_BITS_ON({self.var(argv[0])}),") - # self.indent += 1 - # elif opcode == 0x20: - # self.indent -= 1 - # self.write_line(f"SI_END_MULTI_CASE(),") - # self.indent += 1 - # elif opcode == 0x21: - # self.indent -= 1 - # self.write_line(f"case {self.var(argv[0])}..{self.var(argv[1])}:") - # self.indent += 1 - # elif opcode == 0x22: self.write_line("break") - # elif opcode == 0x23: - # self.indent -= 2 - # self.write_line("}") + elif opcode == 0x14: + self.write_line(f"match {self.var(argv[0])} {{") + self.indent += 1 + self.case_stack.append("MATCH") + elif opcode == 0x15: + self.write_line(f"matchc {self.var(argv[0])} {{") + self.indent += 1 + self.case_stack.append("MATCH") + elif opcode == 0x16: + self.case_stack.append("CASE") + self.write(f"== {self.var(argv[0])}") + elif opcode == 0x17: + self.case_stack.append("CASE") + self.write(f"!= {self.var(argv[0])}") + elif opcode == 0x18: + self.case_stack.append("CASE") + self.write(f"< {self.var(argv[0])}") + elif opcode == 0x19: + self.case_stack.append("CASE") + self.write(f"> {self.var(argv[0])}") + elif opcode == 0x1A: + self.case_stack.append("CASE") + self.write(f"<= {self.var(argv[0])}") + elif opcode == 0x1B: + self.case_stack.append("CASE") + self.write(f">= {self.var(argv[0])}") + elif opcode == 0x1C: + self.case_stack.append("CASE") + self.write(f"else") + elif opcode == 0x1D: + if self.in_case == "CASE" or self.in_case == "MULTI": + self.out += f", {self.var(argv[0])}" + + # replace(!) CASE with MULTI + self.case_stack.pop() + self.case_stack.append("MULTI") + else: + self.write(f"{self.var(argv[0])}") + self.case_stack.append("MULTI") + # opcode 0x1E? + elif opcode == 0x1F: + self.case_stack.append("CASE") + self.write_line(f"? {self.var(argv[0])}") + elif opcode == 0x20: + if not self.was_multi_case: + raise UnsupportedScript("unexpected SI_END_MULTI_CASE") + elif opcode == 0x21: + self.indent -= 1 + self.write_line(f"{self.var(argv[0])}..{self.var(argv[1])}") + self.indent += 1 + elif opcode == 0x22: self.write_line("break") + elif opcode == 0x23: + # close open case if needed + if self.in_case != "MATCH": + self.case_stack.pop() == True + self.case_stack.pop() in ["MULTI", "CASE"] + + self.indent -= 1 + self.write_line("}") + + assert self.case_stack.pop() == "MATCH" + + self.indent -= 1 + self.write_line("}") elif opcode == 0x24: self.write_line(f"{self.var(argv[0])} = {self.var(argv[1])}") - elif opcode == 0x25: self.write_line(f"const {self.var(argv[0])} = 0x{argv[1]:X}") - elif opcode == 0x26: self.write_line(f"{self.var(argv[0])} = {self.verify_float(self.var(argv[1]))}") + elif opcode == 0x25: self.write_line(f"{self.var(argv[0])} =c 0x{argv[1]:X}") + elif opcode == 0x26: + lhs = self.var(argv[1]) + if self.is_float(lhs): + self.write_line(f"{self.var(argv[0])} = {lhs}") + else: + self.write_line(f"{self.var(argv[0])} =f {lhs}") elif opcode == 0x27: self.write_line(f"{self.var(argv[0])} += {self.var(argv[1])}") elif opcode == 0x28: self.write_line(f"{self.var(argv[0])} -= {self.var(argv[1])}") elif opcode == 0x29: self.write_line(f"{self.var(argv[0])} *= {self.var(argv[1])}") elif opcode == 0x2A: self.write_line(f"{self.var(argv[0])} /= {self.var(argv[1])}") elif opcode == 0x2B: self.write_line(f"{self.var(argv[0])} %= {self.var(argv[1])}") - elif opcode == 0x2C: self.write_line(f"{self.var(argv[0])} += {self.verify_float(self.var(argv[1]))}") - elif opcode == 0x2D: self.write_line(f"{self.var(argv[0])} -= {self.verify_float(self.var(argv[1]))}") - elif opcode == 0x2E: self.write_line(f"{self.var(argv[0])} *= {self.verify_float(self.var(argv[1]))}") - elif opcode == 0x2F: self.write_line(f"{self.var(argv[0])} /= {self.verify_float(self.var(argv[1]))}") + elif opcode == 0x2C: + lhs = self.var(argv[1]) + if self.is_float(lhs): + self.write_line(f"{self.var(argv[0])} += {lhs}") + else: + self.write_line(f"{self.var(argv[0])} +=f {lhs}") + elif opcode == 0x2D: + lhs = self.var(argv[1]) + if self.is_float(lhs): + self.write_line(f"{self.var(argv[0])} -= {lhs}") + else: + self.write_line(f"{self.var(argv[0])} -=f {lhs}") + elif opcode == 0x2E: + lhs = self.var(argv[1]) + if self.is_float(lhs): + self.write_line(f"{self.var(argv[0])} *= {lhs}") + else: + self.write_line(f"{self.var(argv[0])} *=f {lhs}") + elif opcode == 0x2F: + lhs = self.var(argv[1]) + if self.is_float(lhs): + self.write_line(f"{self.var(argv[0])} /= {lhs}") + else: + self.write_line(f"{self.var(argv[0])} /=f {lhs}") elif opcode == 0x3F: self.write_line(f"{self.var(argv[0])} &= {self.var(argv[1])}") elif opcode == 0x40: self.write_line(f"{self.var(argv[0])} |= {self.var(argv[1])}") - elif opcode == 0x41: self.write_line(f"const {self.var(argv[0])} &= {argv[1]:X})") - elif opcode == 0x42: self.write_line(f"const {self.var(argv[0])} |= {argv[1]:X})") + elif opcode == 0x41: self.write_line(f"{self.var(argv[0])} &=c {argv[1]:X}") + 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})") @@ -517,7 +627,7 @@ class ScriptDSLDisassembler(ScriptDisassembler): self.indent -= 1 self.write_line("}") else: - raise UnsupportedScript(f"DSL does not support script opcode {opcode:X}") + raise UnsupportedScript(f"DSL does not support script opcode 0x{opcode:X}") if __name__ == "__main__": if len(sys.argv) <= 1: diff --git a/tools/symbol_addrs.txt b/tools/symbol_addrs.txt index be53038f32..be3ee0c4d9 100644 --- a/tools/symbol_addrs.txt +++ b/tools/symbol_addrs.txt @@ -1558,20 +1558,20 @@ si_handle_goto = 0x802C49C0; si_handle_loop = 0x802C4A00; si_handle_end_loop = 0x802C4A48; si_handle_break_loop = 0x802C4B0C; -si_handle_wait = 0x802C4B5C; -si_handle_wait_seconds = 0x802C4BB8; +si_handle_sleep_frames = 0x802C4B5C; +si_handle_sleep_seconds = 0x802C4BB8; si_handle_if_equal = 0x802C4C40; si_handle_if_not_equal = 0x802C4CA0; si_handle_if_less = 0x802C4D00; si_handle_if_greater = 0x802C4D64; si_handle_if_less_equal = 0x802C4DC8; si_handle_if_greater_equal = 0x802C4E2C; -si_handle_if_AND = 0x802C4E90; -si_handle_if_not_AND = 0x802C4EE8; +si_handle_if_flag = 0x802C4E90; +si_handle_if_not_flag = 0x802C4EE8; si_handle_else = 0x802C4F40; si_handle_end_if = 0x802C4F6C; -si_handle_switch = 0x802C4F74; -si_handle_switch_const = 0x802C4FE4; +si_handle_match = 0x802C4F74; +si_handle_match_const = 0x802C4FE4; si_handle_case_equal = 0x802C5030; si_handle_case_not_equal = 0x802C50BC; si_handle_case_less = 0x802C5148; @@ -1579,13 +1579,13 @@ si_handle_case_less_equal = 0x802C51D8; si_handle_case_greater = 0x802C5268; si_handle_case_greater_equal = 0x802C52F8; si_handle_case_range = 0x802C5388; -si_handle_case_default = 0x802C5444; -si_handle_case_AND = 0x802C549C; -si_handle_case_equal_OR = 0x802C5518; -si_handle_case_equal_AND = 0x802C55B8; -si_handle_end_case_group = 0x802C565C; -si_handle_break_case = 0x802C56D4; -si_handle_end_switch = 0x802C5718; +si_handle_case_else = 0x802C5444; +si_handle_case_flag = 0x802C549C; +si_handle_case_multi_or_equal = 0x802C5518; +si_handle_case_multi_and_equal = 0x802C55B8; +si_handle_end_case_multi = 0x802C565C; +si_handle_break_match = 0x802C56D4; +si_handle_end_match = 0x802C5718; si_handle_set_var = 0x802C5744; si_handle_set_const = 0x802C5790; si_handle_set_float = 0x802C57B8; @@ -1618,15 +1618,15 @@ si_handle_AND_const = 0x802C62D4; si_handle_OR = 0x802C632C; si_handle_OR_const = 0x802C6390; si_handle_call = 0x802C63E8; -si_handle_exec1 = 0x802C646C; -si_handle_exec2 = 0x802C6524; -si_handle_exec_wait = 0x802C65FC; +si_handle_spawn_script = 0x802C646C; +si_handle_spawn_script_get_id = 0x802C6524; +si_handle_await_script = 0x802C65FC; si_handle_jump = 0x802C6640; _bound_script_trigger_handler = 0x802C667C; -si_handle_bind = 0x802C6714; +si_handle_bind_trigger = 0x802C6714; DeleteTrigger = 0x802C6824; si_handle_unbind = 0x802C6850; -si_handle_kill = 0x802C6870; +si_handle_kill_script = 0x802C6870; si_handle_set_priority = 0x802C689C; si_handle_set_timescale = 0x802C68D8; si_handle_set_group = 0x802C6914; @@ -1634,15 +1634,15 @@ si_handle_suspend_all = 0x802C6950; si_handle_resume_all = 0x802C697C; si_handle_suspend_others = 0x802C69A8; si_handle_resume_others = 0x802C69E4; -si_handle_suspend = 0x802C6A20; -si_handle_resume = 0x802C6A4C; +si_handle_suspend_script = 0x802C6A20; +si_handle_resume_script = 0x802C6A4C; si_handle_does_script_exist = 0x802C6A78; si_standard_trigger_executor = 0x802C6AD0; si_handle_bind_lock = 0x802C6B54; -si_handle_thread = 0x802C6C78; -si_handle_end_thread = 0x802C6D4C; -si_handle_child_thread = 0x802C6D6C; -si_handle_end_child_thread = 0x802C6DF4; +si_handle_spawn_thread = 0x802C6C78; +si_handle_end_spawn_thread = 0x802C6D4C; +si_handle_parallel_thread = 0x802C6D6C; +si_handle_end_parallel_thread = 0x802C6DF4; si_handle_print_debug_var = 0x802C6E1C; si_execute_next_command = 0x802C7404; get_variable = 0x802C7ABC;