Decomp CompareScriptVariables and make CalcScriptVariables consistent

This commit is contained in:
slaw-22 2025-11-21 19:08:12 +00:00
parent 152f7a3473
commit 4f59b29d2a
8 changed files with 2613 additions and 2658 deletions

View File

@ -1,22 +1,20 @@
#pragma once
.public _0209CF48
.public _0209CF64
.public _0209CF84
.public _0209DFA0
.public Debug_FatalError
.public CalcScriptVariables
.public DEBUG_SPECIAL_EPISODE_NUMBER
.public Debug_Print
.public Debug_Print0
.public DEBUG_SPECIAL_EPISODE_NUMBER
.public EVENT_FLAG_PROG_POS_INFO
.public CalcScriptVariables
.public GetGameMode
.public LoadScriptVariableRaw
.public LoadScriptVariableValue
.public LoadScriptVariableValueAtIndex
.public MemcpySimple
.public SCRIPT_VARS_VALUES
.public SaveScriptVariableValue
.public SaveScriptVariableValueAtIndex
.public ScenarioFlagBackup
.public SCRIPT_VARS_VALUES
.public sub_0204CBE8
.public ZinitScriptVariable
.public _0209CF64
.public _0209CF84
.public _0209DFA0
.public CompareScriptVariables
.public sub_0204CBE8

View File

@ -1,104 +1,8 @@
.include "asm/macros.inc"
.include "main_0204BD98.inc"
.include "main_0204BECC.inc"
.text
arm_func_start sub_0204BD98
sub_0204BD98: ; 0x0204BD98
stmdb sp!, {r3, lr}
sub sp, sp, #8
cmp r2, #0xa
addls pc, pc, r2, lsl #2
b _0204BE9C
_0204BDAC: ; jump table
b _0204BDD8 ; case 0
b _0204BDE0 ; case 1
b _0204BDE8 ; case 2
b _0204BE10 ; case 3
b _0204BE38 ; case 4
b _0204BE24 ; case 5
b _0204BE4C ; case 6
b _0204BDFC ; case 7
b _0204BE60 ; case 8
b _0204BE74 ; case 9
b _0204BE88 ; case 10
_0204BDD8:
mov r0, #1
b _0204BEBC
_0204BDE0:
mov r0, #0
b _0204BEBC
_0204BDE8:
cmp r0, r1
moveq r0, #1
movne r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BDFC:
cmp r0, r1
movne r0, #1
moveq r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BE10:
cmp r0, r1
movgt r0, #1
movle r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BE24:
cmp r0, r1
movge r0, #1
movlt r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BE38:
cmp r0, r1
movlt r0, #1
movge r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BE4C:
cmp r0, r1
movle r0, #1
movgt r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BE60:
tst r0, r1
movne r0, #1
moveq r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BE74:
teq r0, r1
movne r0, #1
moveq r0, #0
and r0, r0, #0xff
b _0204BEBC
_0204BE88:
mov r2, #1
tst r0, r2, lsl r1
moveq r2, #0
and r0, r2, #0xff
b _0204BEBC
_0204BE9C:
ldr r1, _0204BEC4 ; =EVENT_FLAG_PROG_POS_INFO
add r0, sp, #0
ldr r3, [r1, #0xc]
ldr ip, [r1, #8]
ldr r1, _0204BEC8 ; =_0209CF48
str ip, [sp]
str r3, [sp, #4]
bl Debug_FatalError
_0204BEBC:
add sp, sp, #8
ldmia sp!, {r3, pc}
.align 2, 0
_0204BEC4: .word EVENT_FLAG_PROG_POS_INFO
_0204BEC8: .word _0209CF48
arm_func_end sub_0204BD98
arm_func_start sub_0204BECC
sub_0204BECC: ; 0x0204BECC
ldr ip, _0204BED4 ; =CalcScriptVariables
@ -150,10 +54,10 @@ sub_0204BF10: ; 0x0204BF10
arm_func_start sub_0204BF5C
sub_0204BF5C: ; 0x0204BF5C
ldr ip, _0204BF64 ; =sub_0204BD98
ldr ip, _0204BF64 ; =CompareScriptVariables
bx ip
.align 2, 0
_0204BF64: .word sub_0204BD98
_0204BF64: .word CompareScriptVariables
arm_func_end sub_0204BF5C
arm_func_start sub_0204BF68
@ -164,7 +68,7 @@ sub_0204BF68: ; 0x0204BF68
bl LoadScriptVariableValue
mov r1, r5
mov r2, r4
bl sub_0204BD98
bl CompareScriptVariables
ldmia sp!, {r3, r4, r5, pc}
arm_func_end sub_0204BF68
@ -182,7 +86,7 @@ sub_0204BF88: ; 0x0204BF88
mov r1, r0
mov r0, r4
mov r2, r5
bl sub_0204BD98
bl CompareScriptVariables
ldmia sp!, {r3, r4, r5, r6, r7, pc}
arm_func_end sub_0204BF88

File diff suppressed because it is too large Load Diff

2533
asm/main_rodata_0209CECC.s Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3464,4 +3464,18 @@ enum performance_progress_flag
PERFORMANCE_PROGRESS_FLAG_RANDOM_MISSION = 3
};
enum compare_operation { // Taken from pmd-red's FlagJudgeOperation
CMP_TRUE,
CMP_FALSE,
CMP_EQ,
CMP_GT,
CMP_LT,
CMP_GE,
CMP_LE,
CMP_NE,
CMP_AND_NONZERO,
CMP_XOR_NONZERO, // logically identical to CMP_NE
CMP_BIT_SET,
};
#endif //PMDSKY_ENUMS_H

View File

@ -42,5 +42,6 @@ void LoadScriptVariableValueString(const enum script_var_id sv_id, u8* result, u
void SaveScriptVariableValueBytes(const enum script_var_id sv_id, u8* result, s32 num_bytes);
s32 ScriptVariablesEqual(union script_var_value sv_val_ptr_local[], enum script_var_id sv_id_1, enum script_var_id sv_id_2);
s32 CalcScriptVariables(s32 param_1, s32 param_2, enum script_calc_operation operation);
bool8 CompareScriptVariables(s32 param_1, s32 param_2, enum compare_operation operation);
#endif //PMDSKY_SCRIPTING_H

View File

@ -81,7 +81,8 @@ Static main
Object src/main_0204AFF8.o
Object asm/main_0204B018.o
Object src/scripting.o
Object asm/main_0204BD98.o
Object asm/main_rodata_0209CECC.o
Object asm/main_0204BECC.o
Object src/main_0204C938.o
Object asm/main_0204C94C.o
Object src/dungeon_recruitment_3.o

View File

@ -24,15 +24,25 @@ extern s32 SetMoneyStored(s32 arg0);
extern s32 SetNotifyNote(s32 arg0);
extern s32 sub_0204C928(s32 arg0);
const short LOCAL_SCRIPT_VAR_OFFSET = 0x400;
extern struct prog_pos_info EVENT_FLAG_PROG_POS_INFO;
extern u8 EVENT_FLAG_EXPANSION_ERROR;
extern u8 EVENT_FLAG_RULE_ERROR;
const u8 EVENT_FLAG_FILE_NAME[] = "event_flag.c";
const struct prog_pos_info ppi_line_1011 = {
(u8*) EVENT_FLAG_FILE_NAME,
1001
};
const struct prog_pos_info ppi_line_1044 = {
(u8*) EVENT_FLAG_FILE_NAME,
1044
};
void LoadScriptVariableRaw(struct script_var_raw* sv_raw,
union script_var_value sv_val_local[],
const enum script_var_id sv_id) {
short LOCAL_SCRIPT_VAR_OFFSET = 0x400;
if (sv_id < LOCAL_SCRIPT_VAR_OFFSET) {
// global script var
sv_raw->def = &SCRIPT_VARS[sv_id];
@ -392,10 +402,42 @@ s32 CalcScriptVariables(s32 param_1, s32 param_2, enum script_calc_operation ope
case CALC_RANDOM:
return RandInt(param_2);
default:
// EVENT_FLAG_PROG_POS_INFO contains a pointer to the filename event_flag.c
// and a line number of 1001
struct prog_pos_info prog_pos_info = EVENT_FLAG_PROG_POS_INFO;
// EVENT_FLAG_EXPANSION_ERROR contains the string "event flag expansion error %d"
Debug_FatalError(&prog_pos_info, &EVENT_FLAG_EXPANSION_ERROR, operation);
struct prog_pos_info ppi = ppi_line_1011;
Debug_FatalError(&ppi, &EVENT_FLAG_EXPANSION_ERROR, operation);
}
}
bool8 CompareScriptVariables(s32 param_1, s32 param_2, enum compare_operation operation)
{
switch (operation) {
case CMP_TRUE:
return TRUE;
case CMP_FALSE:
return FALSE;
case CMP_EQ:
return param_1 == param_2;
case CMP_NE:
return param_1 != param_2;
case CMP_GT:
return param_1 > param_2;
case CMP_GE:
return param_1 >= param_2;
case CMP_LT:
return param_1 < param_2;
case CMP_LE:
return param_1 <= param_2;
case CMP_AND_NONZERO:
return (param_1 & param_2) != 0;
case CMP_XOR_NONZERO:
return (param_1 ^ param_2) != 0;
case CMP_BIT_SET:
if(param_1 & (1 << param_2)) {
return 1;
} else {
return 0;
}
default:
struct prog_pos_info ppi = ppi_line_1044;
Debug_FatalError(&ppi, &EVENT_FLAG_RULE_ERROR, operation);
}
}