Merge pull request #96 from ethteck/cornucopia

SI funcs and cleanup
This commit is contained in:
Ethan Roseman 2020-10-24 00:33:03 -04:00 committed by GitHub
commit e8405620ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 102 additions and 114 deletions

View File

@ -1,50 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel si_handle_case_equal_AND
/* E9F68 802C55B8 27BDFFE0 */ addiu $sp, $sp, -0x20
/* E9F6C 802C55BC AFB10014 */ sw $s1, 0x14($sp)
/* E9F70 802C55C0 0080882D */ daddu $s1, $a0, $zero
/* E9F74 802C55C4 AFBF0018 */ sw $ra, 0x18($sp)
/* E9F78 802C55C8 AFB00010 */ sw $s0, 0x10($sp)
/* E9F7C 802C55CC 82300007 */ lb $s0, 7($s1)
/* E9F80 802C55D0 06010003 */ bgez $s0, .L802C55E0
/* E9F84 802C55D4 8E25000C */ lw $a1, 0xc($s1)
.L802C55D8:
/* E9F88 802C55D8 080B1576 */ j .L802C55D8
/* E9F8C 802C55DC 00000000 */ nop
.L802C55E0:
/* E9F90 802C55E0 8CA50000 */ lw $a1, ($a1)
/* E9F94 802C55E4 0C0B1EAF */ jal get_variable
/* E9F98 802C55E8 0220202D */ daddu $a0, $s1, $zero
/* E9F9C 802C55EC 0040302D */ daddu $a2, $v0, $zero
/* E9FA0 802C55F0 00101080 */ sll $v0, $s0, 2
/* E9FA4 802C55F4 02221021 */ addu $v0, $s1, $v0
/* E9FA8 802C55F8 02301821 */ addu $v1, $s1, $s0
/* E9FAC 802C55FC 80640110 */ lb $a0, 0x110($v1)
/* E9FB0 802C5600 8C420118 */ lw $v0, 0x118($v0)
/* E9FB4 802C5604 14800005 */ bnez $a0, .L802C561C
/* E9FB8 802C5608 2405FFFE */ addiu $a1, $zero, -2
/* E9FBC 802C560C 0C0B2279 */ jal si_goto_end_case
/* E9FC0 802C5610 0220202D */ daddu $a0, $s1, $zero
/* E9FC4 802C5614 080B1591 */ j .L802C5644
/* E9FC8 802C5618 AE220008 */ sw $v0, 8($s1)
.L802C561C:
/* E9FCC 802C561C 10850006 */ beq $a0, $a1, .L802C5638
/* E9FD0 802C5620 0220202D */ daddu $a0, $s1, $zero
/* E9FD4 802C5624 54C20004 */ bnel $a2, $v0, .L802C5638
/* E9FD8 802C5628 A0650110 */ sb $a1, 0x110($v1)
/* E9FDC 802C562C 2402FFFF */ addiu $v0, $zero, -1
/* E9FE0 802C5630 080B1591 */ j .L802C5644
/* E9FE4 802C5634 A0620110 */ sb $v0, 0x110($v1)
.L802C5638:
/* E9FE8 802C5638 0C0B2298 */ jal si_goto_next_case
/* E9FEC 802C563C 00000000 */ nop
/* E9FF0 802C5640 AE220008 */ sw $v0, 8($s1)
.L802C5644:
/* E9FF4 802C5644 24020002 */ addiu $v0, $zero, 2
/* E9FF8 802C5648 8FBF0018 */ lw $ra, 0x18($sp)
/* E9FFC 802C564C 8FB10014 */ lw $s1, 0x14($sp)
/* EA000 802C5650 8FB00010 */ lw $s0, 0x10($sp)
/* EA004 802C5654 03E00008 */ jr $ra
/* EA008 802C5658 27BD0020 */ addiu $sp, $sp, 0x20

View File

@ -1,50 +0,0 @@
.set noat # allow manual use of $at
.set noreorder # don't insert nops after branches
glabel si_handle_case_equal_OR
/* E9EC8 802C5518 27BDFFE0 */ addiu $sp, $sp, -0x20
/* E9ECC 802C551C AFB10014 */ sw $s1, 0x14($sp)
/* E9ED0 802C5520 0080882D */ daddu $s1, $a0, $zero
/* E9ED4 802C5524 AFBF0018 */ sw $ra, 0x18($sp)
/* E9ED8 802C5528 AFB00010 */ sw $s0, 0x10($sp)
/* E9EDC 802C552C 82300007 */ lb $s0, 7($s1)
/* E9EE0 802C5530 06010003 */ bgez $s0, .L802C5540
/* E9EE4 802C5534 8E25000C */ lw $a1, 0xc($s1)
.L802C5538:
/* E9EE8 802C5538 080B154E */ j .L802C5538
/* E9EEC 802C553C 00000000 */ nop
.L802C5540:
/* E9EF0 802C5540 8CA50000 */ lw $a1, ($a1)
/* E9EF4 802C5544 0C0B1EAF */ jal get_variable
/* E9EF8 802C5548 0220202D */ daddu $a0, $s1, $zero
/* E9EFC 802C554C 0040282D */ daddu $a1, $v0, $zero
/* E9F00 802C5550 00101080 */ sll $v0, $s0, 2
/* E9F04 802C5554 02221021 */ addu $v0, $s1, $v0
/* E9F08 802C5558 02302021 */ addu $a0, $s1, $s0
/* E9F0C 802C555C 80830110 */ lb $v1, 0x110($a0)
/* E9F10 802C5560 14600005 */ bnez $v1, .L802C5578
/* E9F14 802C5564 8C420118 */ lw $v0, 0x118($v0)
/* E9F18 802C5568 0C0B2279 */ jal si_goto_end_case
/* E9F1C 802C556C 0220202D */ daddu $a0, $s1, $zero
/* E9F20 802C5570 080B1568 */ j .L802C55A0
/* E9F24 802C5574 AE220008 */ sw $v0, 8($s1)
.L802C5578:
/* E9F28 802C5578 14A20004 */ bne $a1, $v0, .L802C558C
/* E9F2C 802C557C 2402FFFF */ addiu $v0, $zero, -1
/* E9F30 802C5580 2402FFFF */ addiu $v0, $zero, -1
/* E9F34 802C5584 080B1568 */ j .L802C55A0
/* E9F38 802C5588 A0820110 */ sb $v0, 0x110($a0)
.L802C558C:
/* E9F3C 802C558C 10620005 */ beq $v1, $v0, .L802C55A4
/* E9F40 802C5590 24020002 */ addiu $v0, $zero, 2
/* E9F44 802C5594 0C0B2298 */ jal si_goto_next_case
/* E9F48 802C5598 0220202D */ daddu $a0, $s1, $zero
/* E9F4C 802C559C AE220008 */ sw $v0, 8($s1)
.L802C55A0:
/* E9F50 802C55A0 24020002 */ addiu $v0, $zero, 2
.L802C55A4:
/* E9F54 802C55A4 8FBF0018 */ lw $ra, 0x18($sp)
/* E9F58 802C55A8 8FB10014 */ lw $s1, 0x14($sp)
/* E9F5C 802C55AC 8FB00010 */ lw $s0, 0x10($sp)
/* E9F60 802C55B0 03E00008 */ jr $ra
/* E9F64 802C55B4 27BD0020 */ addiu $sp, $sp, 0x20

116
src/si.c
View File

@ -255,7 +255,6 @@ ApiStatus si_handle_case_equal(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -279,7 +278,6 @@ ApiStatus si_handle_case_not_equal(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -303,7 +301,6 @@ ApiStatus si_handle_case_less(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -327,7 +324,6 @@ ApiStatus si_handle_case_less_equal(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -351,7 +347,6 @@ ApiStatus si_handle_case_greater(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -375,7 +370,6 @@ ApiStatus si_handle_case_greater_equal(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -402,7 +396,6 @@ ApiStatus si_handle_case_range(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -417,7 +410,6 @@ ApiStatus si_handle_case_default(ScriptInstance* script) {
script->ptrNextLine = si_goto_end_case(script);
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
@ -426,13 +418,15 @@ ApiStatus si_handle_case_AND(ScriptInstance* script) {
s32 switchDepth = script->switchDepth;
s32 var;
s32 switchBlockValue;
s32 switchBlockState;
ASSERT(switchDepth >= 0);
var = *args;
switchBlockValue = script->switchBlockValue[switchDepth];
switchBlockState = script->switchBlockState[switchDepth];
if (script->switchBlockState[switchDepth] <= 0) {
if (switchBlockState <= 0) {
script->ptrNextLine = si_goto_end_case(script);
} else if ((var & switchBlockValue) == 0) {
script->ptrNextLine = si_goto_next_case(script);
@ -441,13 +435,61 @@ ApiStatus si_handle_case_AND(ScriptInstance* script) {
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
INCLUDE_ASM(s32, "si", si_handle_case_equal_OR);
ApiStatus si_handle_case_equal_OR(ScriptInstance* script) {
Bytecode* args = script->ptrReadPos;
s32 switchDepth = script->switchDepth;
s32 var;
s32 switchBlockValue;
s32 switchBlockState;
INCLUDE_ASM(s32, "si", si_handle_case_equal_AND);
ASSERT(switchDepth >= 0);
var = get_variable(script, *args);
switchBlockValue = script->switchBlockValue[switchDepth];
switchBlockState = script->switchBlockState[switchDepth];
if (switchBlockState == 0) {
script->ptrNextLine = si_goto_end_case(script);
} else if (var == switchBlockValue) {
script->switchBlockState[switchDepth] = -1;
} else if (switchBlockState != -1) {
script->ptrNextLine = si_goto_next_case(script);
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
ApiStatus si_handle_case_equal_AND(ScriptInstance* script) {
Bytecode* args = script->ptrReadPos;
s32 switchDepth = script->switchDepth;
s32 var;
s32 switchBlockValue;
s32 switchBlockState;
ASSERT(switchDepth >= 0);
var = get_variable(script, *args);
switchBlockValue = script->switchBlockValue[switchDepth];
switchBlockState = script->switchBlockState[switchDepth];
if (switchBlockState == 0) {
script->ptrNextLine = si_goto_end_case(script);
} else if (switchBlockState == -2) {
script->ptrNextLine = si_goto_next_case(script);
} else if (var == switchBlockValue) {
script->switchBlockState[switchDepth] = -1;
} else {
script->switchBlockState[switchDepth] = -2;
script->ptrNextLine = si_goto_next_case(script);
}
return ApiStatus_DONE2;
do {} while (0); // Necessary to match
}
ApiStatus si_handle_end_case_group(ScriptInstance* script) {
ASSERT(script->switchDepth >= 0);
@ -1141,7 +1183,6 @@ INCLUDE_ASM(s32, "si", si_execute_next_command);
// TODO: consider renaming to si_get_variable
#ifdef NON_MATCHING
/*
s32 get_variable(ScriptInstance* script, Bytecode var) {
s32 wordIdx;
s32 bitIdx;
@ -1195,7 +1236,6 @@ s32 get_variable(ScriptInstance* script, Bytecode var) {
return var;
}
}
*/
#else
INCLUDE_ASM(s32, "si", get_variable, ScriptInstance* script, Bytecode var);
#endif
@ -1288,7 +1328,55 @@ s32 get_variable_index_alt(s32 var) {
INCLUDE_ASM(s32, "si", set_variable, ScriptInstance* script, Bytecode var, s32 value);
// Tiny regalloc issue with the var <= -80000000 / -60000000 blocks
#ifdef NON_MATCHING
f32 get_float_variable(ScriptInstance* script, Bytecode var) {
s32 temp;
if (var <= -270000000) {
return var;
} else if (var <= -250000000) {
return var;
} else if (var <= -220000000) {
return fixed_var_to_float(var);
} else if (var <= -180000000) {
var += 190000000;
return fixed_var_to_float(script->array[var]);
} else if (var <= -160000000) {
var += 170000000;
return fixed_var_to_float(get_global_byte(var));
} else if (var <= -140000000) {
var += 150000000;
return fixed_var_to_float(get_area_byte(var));
} else if (var <= -80000000) {
var += 90000000;
temp = var % 32;
if ((gMapFlags[var / 32] & (1 << temp))) {
return 1.0f;
} else {
return 0.0f;
}
} else if (var <= -60000000) {
var += 70000000;
temp = var % 32;
if ((script->varFlags[var / 32] & (1 << temp))) {
return 1.0f;
} else {
return 0.0f;
}
} else if (var <= -40000000) {
var += 50000000;
return fixed_var_to_float(gMapVars[var]);
} else if (var <= -20000000) {
var += 30000000;
return fixed_var_to_float(script->varTable[var]);
} else {
return fixed_var_to_float(var);
}
}
#else
INCLUDE_ASM(f32, "si", get_float_variable, ScriptInstance* script, Bytecode var);
#endif
INCLUDE_ASM(f32, "si", set_float_variable, ScriptInstance* script, Bytecode var, f32 value);