From 173e876db1287224164fbca60217817932d03e25 Mon Sep 17 00:00:00 2001 From: Treeki Date: Sat, 21 May 2011 23:47:47 +0200 Subject: fixed switch blocks --- src/switchblock.S | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ switchblock.yaml | 7 +++++++ 2 files changed, 65 insertions(+) diff --git a/src/switchblock.S b/src/switchblock.S index fd192df..b86d5e2 100644 --- a/src/switchblock.S +++ b/src/switchblock.S @@ -13,6 +13,7 @@ .align 4 .extern GameMgr .extern BG_GM_ptr +.extern _restgpr_27 .global BG_GM_InitRedSwitchFlag_Patch BG_GM_InitRedSwitchFlag_Patch: @@ -25,6 +26,63 @@ BG_GM_InitRedSwitchFlag_Patch: stb r0, 0xAA8(r4) blr +.global CheckBehaviourOverride_EndPatch +CheckBehaviourOverride_EndPatch: + lis r5, BG_GM_ptr@h + ori r5, r5, BG_GM_ptr@l + lwz r5, 0(r5) + + # Get the switch value + addis r5, r5, 9 + lbz r5, 0xAA8(r5) + + # not sure why this happens + cmpwi r28, 0 + bne returnRegularBehaviour + + # now do the rest of the checks: + cmplwi r29, 0x58 + bne cboNotRed + andi. r3, r5, 1 + beq cboNotRed + b returnSbBehaviour +cboNotRed: + cmplwi r29, 0x5A + bne cboNotGreen + andi. r3, r5, 2 + beq cboNotGreen + b returnSbBehaviour +cboNotGreen: + cmplwi r29, 0x56 + bne cboNotYellow + andi. r3, r5, 4 + beq cboNotYellow + b returnSbBehaviour +cboNotYellow: + cmplwi r29, 0x54 + bne cboNotBlue + andi. r3, r5, 8 + beq cboNotBlue + b returnSbBehaviour +cboNotBlue: + b returnRegularBehaviour + + # done! +returnSbBehaviour: + li r4, 3 + li r3, 8 + b cboReturn +returnRegularBehaviour: + mr r4, r27 + mr r3, r28 +cboReturn: + addi r11, r1, 0x20 + bl _restgpr_27 + lwz r0, 0x24(r1) + mtlr r0 + addi r1, r1, 0x20 + blr + .global ProcessTileNum_EndPatch ProcessTileNum_EndPatch: lis r5, BG_GM_ptr@h diff --git a/switchblock.yaml b/switchblock.yaml index 20ecf24..6f142b2 100644 --- a/switchblock.yaml +++ b/switchblock.yaml @@ -23,3 +23,10 @@ hooks: branch_type: b target_func: 'ProcessTileNum_EndPatch' + - name: CheckBehaviourOverride_EndPatch + type: branch_insn + src_addr_pal: 0x80081A4C + branch_type: b + target_func: 'CheckBehaviourOverride_EndPatch' + + -- cgit v1.2.3