From 7bb50c1714a74ba7e8468ead8f92b1f1ccceef6d Mon Sep 17 00:00:00 2001 From: Stephen Simpson Date: Wed, 28 Sep 2011 10:20:20 -0500 Subject: started adding classic controller analog not yet implemented tilt not yet implemented --- NewerProject.yaml | 1 + classic_controller.yaml | 34 ++++++++++++++++++++ src/classic_controller.S | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 classic_controller.yaml create mode 100644 src/classic_controller.S diff --git a/NewerProject.yaml b/NewerProject.yaml index 46d1259..e3806e7 100644 --- a/NewerProject.yaml +++ b/NewerProject.yaml @@ -29,3 +29,4 @@ modules: - processed/compression.yaml # - processed/crowdclapper.yaml - processed/blocksnake.yaml + - processed/classic_controller.yaml diff --git a/classic_controller.yaml b/classic_controller.yaml new file mode 100644 index 0000000..eb02398 --- /dev/null +++ b/classic_controller.yaml @@ -0,0 +1,34 @@ +--- +source_files: [../src/classic_controller.S] +hooks: + - name: AddClassicController + type: branch_insn + branch_type: bl + src_addr_ntsc: 0xdeadbeef + target_func: '_switch_buttons' + + - name: Patch1 + type: patch + addr_ntsc: 0x801EAE30 + data: '39800000 91840000' + + - name: PatchExtensionScall + type: patch + addr_ntsc: 0x80019EE0 + data: '38000000' + + - name: Patch3 + type: patch + addr_ntsc: 0x800B3B30 + data: '38000000' + + - name: Patch4 + type: patch + addr_ntsc: 0x8076DBA8 + data: '38000000' + + - name: Patch5 + type: patch + addr_ntsc: 0x8076DBE8 + data: '38000000' + diff --git a/src/classic_controller.S b/src/classic_controller.S new file mode 100644 index 0000000..2ae5ed7 --- /dev/null +++ b/src/classic_controller.S @@ -0,0 +1,84 @@ +#ifndef __MWERKS__ +.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4 +.set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9 +.set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14 +.set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19 +.set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24 +.set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29 +.set r30,30; .set r31,31; .set f0,0; .set f2,2; .set f3,3 +.set f1,1; .set f30,30; .set f31,31 +#endif + +.global _switch_buttons +_switch_buttons: + addi r1,r1,0x50 # replaced instruction + + mflr r0 + lwz r5,0x60(r26) # wiimote cc data + bl map_buttons + lwz r4,0(r26) + or r5,r5,r4 + stw r5,0(r26) + lwz r5,0x64(r26) + bl map_buttons + lwz r4,4(r26) + or r5,r5,r4 + stw r5,4(r26) + lwz r5,0x68(r26) + bl map_buttons + lwz r4,8(r26) + or r5,r5,r4 + stw r5,8(r26) + mtlr r0 + blr + +map_buttons: + andi. r4,r5,0x200 // WPAD_CLASSIC_BUTTON_FULL_R + beq- skip_waggle + lis r6,0x7fc0 // float +skip_waggle: + stw r6,0x10(r26) // set waggle + li r6,0 + andi. r4,r5,0x800 // WPAD_CLASSIC_BUTTON_HOME + beq- skip_home + ori r6,r6,0x8000 // WPAD_BUTTON_HOME +skip_home: + andi. r4,r5,0x20 // WPAD_CLASSIC_BUTTON_Y + beq- skip_run_one + ori r6,r6,0x200 // WPAD_BUTTON_1 +skip_run_one: + andi. r4,r5,0x8 // WPAD_CLASSIC_BUTTON_X + beq- skip_run_two + ori r6,r6,0x200 // WPAD_BUTTON_1 +skip_run_two: + andi. r4,r5,0x40 // WPAD_CLASSIC_BUTTON_B + beq- skip_jump + ori r6,r6,0x100 // WPAD_BUTTON_2 +skip_jump: + andi. r4,r5,1 // WPAD_CLASSIC_BUTTON_UP + beq- skip_right + ori r6,r6,2 // WPAD_BUTTON_RIGHT +skip_right: + andi. r4,r5,2 // WPAD_CLASSIC_BUTTON_LEFT + beq- skip_up + ori r6,r6,8 // WPAD_BUTTON_UP +skip_up: + andi. r4,r5,0x8000 // WPAD_CLASSIC_BUTTON_RIGHT + beq- skip_down + ori r6,r6,4 // WPAD_BUTTON_DOWN +skip_down: + andi. r4,r5,0x4000 // WPAD_CLASSIC_BUTTON_DOWN + beq- skip_left + ori r6,r6,1 // WPAD_BUTTON_LEFT +skip_left: + andi. r4,r5,0x400 // WPAD_CLASSIC_BUTTON_PLUS + beq- skip_plus + ori r6,r6,0x10 // WPAD_BUTTON_PLUS +skip_plus: + andi. r4,r5,0x1000 // WPAD_CLASSIC_BUTTON_MINUS + beq- skip_minus + ori r6,r6,0x1000 // WPAD_BUTTON_MINUS +skip_minus: + mr r5,r6 + blr + -- cgit v1.2.3 From fe4f07bb5c43566a799058f8a52e30e35be55003 Mon Sep 17 00:00:00 2001 From: Stephen Simpson Date: Wed, 28 Sep 2011 11:33:05 -0500 Subject: fixed ntsc addresses to pal in the classic_controller.yaml added basic support for left analog stick in classic_controller.S --- classic_controller.yaml | 20 +++++++++++++------- kamek_ntsc.x | 2 +- kamek_ntsc2.x | 2 +- kamek_pal2.x | 2 +- src/classic_controller.S | 39 ++++++++++++++++++++++++++++++++++++--- tools/hooks.pyc | Bin 5873 -> 6006 bytes 6 files changed, 52 insertions(+), 13 deletions(-) diff --git a/classic_controller.yaml b/classic_controller.yaml index eb02398..08354c2 100644 --- a/classic_controller.yaml +++ b/classic_controller.yaml @@ -4,31 +4,37 @@ hooks: - name: AddClassicController type: branch_insn branch_type: bl - src_addr_ntsc: 0xdeadbeef + src_addr_pal: 0x801eb6f8 + #src_addr_ntsc: 0x801eb5b8 target_func: '_switch_buttons' - name: Patch1 type: patch - addr_ntsc: 0x801EAE30 + addr_pal: 0x801EAF70 + #addr_ntsc: 0x801EAE30 data: '39800000 91840000' - name: PatchExtensionScall type: patch - addr_ntsc: 0x80019EE0 + addr_pal: 0x80019EE0 + #addr_ntsc: 0x80019EE0 data: '38000000' - name: Patch3 type: patch - addr_ntsc: 0x800B3B30 + addr_pal: 0x800B3B30 + #addr_ntsc: 0x800B3B30 data: '38000000' - name: Patch4 type: patch - addr_ntsc: 0x8076DBA8 - data: '38000000' + addr_pal: 0x8076DB98 + #addr_ntsc: 0x8076DBA8 + data: '38000004' - name: Patch5 type: patch - addr_ntsc: 0x8076DBE8 + addr_pal: 0x8076DBd8 + #addr_ntsc: 0x8076DBE8 data: '38000000' diff --git a/kamek_ntsc.x b/kamek_ntsc.x index f8c9a41..802aba3 100644 --- a/kamek_ntsc.x +++ b/kamek_ntsc.x @@ -29,7 +29,7 @@ SECTIONS { HandleYSpeed = 0x8006CDE0; UpdateObjectPosBasedOnSpeedValues_real = 0x8006CD40; dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3 = 0x80096240; - + CalculateDistanceFromActorsNextPosToFurthestPlayer = 0x80064740; diff --git a/kamek_ntsc2.x b/kamek_ntsc2.x index 42d9898..730ff74 100644 --- a/kamek_ntsc2.x +++ b/kamek_ntsc2.x @@ -29,7 +29,7 @@ SECTIONS { HandleYSpeed = 0x8006CDE0; UpdateObjectPosBasedOnSpeedValues_real = 0x8006CD40; dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3 = 0x80096240; - + CalculateDistanceFromActorsNextPosToFurthestPlayer = 0x80064740; diff --git a/kamek_pal2.x b/kamek_pal2.x index 6e3d6fa..1c25357 100644 --- a/kamek_pal2.x +++ b/kamek_pal2.x @@ -29,7 +29,7 @@ SECTIONS { HandleYSpeed = 0xDEADBEEF; UpdateObjectPosBasedOnSpeedValues_real = 0xDEADBEEF; dSprite_c__getXDirectionOfFurthestPlayerRelativeToVEC3 = 0xDEADBEEF; - + CalculateDistanceFromActorsNextPosToFurthestPlayer = 0xDEADBEEF; diff --git a/src/classic_controller.S b/src/classic_controller.S index 2ae5ed7..86be34f 100644 --- a/src/classic_controller.S +++ b/src/classic_controller.S @@ -1,14 +1,18 @@ #ifndef __MWERKS__ -.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4 +.set r0,0; .set r1,1; .set r2,2; .set r3,3; .set r4,4 .set r5,5; .set r6,6; .set r7,7; .set r8,8; .set r9,9 .set r10,10; .set r11,11; .set r12,12; .set r13,13; .set r14,14 .set r15,15; .set r16,16; .set r17,17; .set r18,18; .set r19,19 .set r20,20; .set r21,21; .set r22,22; .set r23,23; .set r24,24 .set r25,25; .set r26,26; .set r27,27; .set r28,28; .set r29,29 -.set r30,30; .set r31,31; .set f0,0; .set f2,2; .set f3,3 -.set f1,1; .set f30,30; .set f31,31 +.set r30,30; .set r31,31; .set f0,0; .set f2,2; .set f3,3 +.set f1,1; .set f8,8; .set f9,9; .set f10,10; .set f11,11; +.set f30,30; .set f31,31 #endif +.text +.align 4 + .global _switch_buttons _switch_buttons: addi r1,r1,0x50 # replaced instruction @@ -79,6 +83,35 @@ skip_plus: beq- skip_minus ori r6,r6,0x1000 // WPAD_BUTTON_MINUS skip_minus: + lfs f8,0x6c(r26) // left analog x + lfs f9,0x70(r26) // left analog y + lis r5,float_one@h + lfs f10,float_one@l(r5) + lfs f11,float_neg_one@l(r5) + fcmpu cr1,f8,f10 + bne cr1,skip_right_analog + ori r6,r6,4 // WPAD_BUTTON_DOWN +skip_right_analog: + fcmpu cr1,f9,f10 + bne cr1,skip_right_analog + ori r6,r6,2 // WPAD_BUTTON_RIGHT +skip_up_analog: + fcmpu cr1,f9,f11 + bne cr1,skip_right_analog + ori r6,r6,1 // WPAD_BUTTON_LEFT +skip_down_analog: + fcmpu cr1,f8,f11 + bne cr1,skip_right_analog + ori r6,r6,8 // WPAD_BUTTON_UP +skip_left_analog: mr r5,r6 blr +.data + +float_one: +.float 1.0 +float_neg_one: +.float -1.0 +float_zero: +.float 0.0 diff --git a/tools/hooks.pyc b/tools/hooks.pyc index 84b5c26..a8c227c 100644 Binary files a/tools/hooks.pyc and b/tools/hooks.pyc differ -- cgit v1.2.3 From 63d9a470f3e508097741522f899a3da0b5c67e12 Mon Sep 17 00:00:00 2001 From: Stephen Simpson Date: Wed, 28 Sep 2011 18:23:55 -0500 Subject: fixed region offsets in classic_controller.yaml fixed branch type from bl to b in classic_controller.yaml still missing analog sticks and tilt --- classic_controller.yaml | 18 +++++++------- src/classic_controller.S | 62 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/classic_controller.yaml b/classic_controller.yaml index 08354c2..8165c7d 100644 --- a/classic_controller.yaml +++ b/classic_controller.yaml @@ -3,38 +3,38 @@ source_files: [../src/classic_controller.S] hooks: - name: AddClassicController type: branch_insn - branch_type: bl + branch_type: b src_addr_pal: 0x801eb6f8 - #src_addr_ntsc: 0x801eb5b8 + src_addr_ntsc: 0x801eb5b8 target_func: '_switch_buttons' - name: Patch1 type: patch addr_pal: 0x801EAF70 - #addr_ntsc: 0x801EAE30 + addr_ntsc: 0x801EAE30 data: '39800000 91840000' - name: PatchExtensionScall type: patch addr_pal: 0x80019EE0 - #addr_ntsc: 0x80019EE0 + addr_ntsc: 0x80019EE0 data: '38000000' - name: Patch3 type: patch addr_pal: 0x800B3B30 - #addr_ntsc: 0x800B3B30 + addr_ntsc: 0x800B3B30 data: '38000000' - name: Patch4 type: patch - addr_pal: 0x8076DB98 - #addr_ntsc: 0x8076DBA8 + addr_pal: 0x8076DB68 + addr_ntsc: 0x8076DBA8 data: '38000004' - name: Patch5 type: patch - addr_pal: 0x8076DBd8 - #addr_ntsc: 0x8076DBE8 + addr_pal: 0x8076DBa8 + addr_ntsc: 0x8076DBE8 data: '38000000' diff --git a/src/classic_controller.S b/src/classic_controller.S index 86be34f..2ba7a9e 100644 --- a/src/classic_controller.S +++ b/src/classic_controller.S @@ -10,6 +10,16 @@ .set f30,30; .set f31,31 #endif +.set stackSize,0x30; +.set r4Place,0x10; +.set r5Place,0x14; +.set r6Place,0x18; +.set r26Place,0x1c; +.set f8Place,0x20; +.set f9Place,0x24; +.set f10Place,0x28; +.set f11Place,0x2c; + .text .align 4 @@ -17,7 +27,17 @@ _switch_buttons: addi r1,r1,0x50 # replaced instruction + stwu r1,-stackSize(r1) # provide new stack for saving regs mflr r0 + stw r4,r4Place(r1) + stw r5,r5Place(r1) + stw r6,r6Place(r1) + stw r26,r26Place(r1) + stfs f8,f8Place(r1) + stfs f9,f9Place(r1) + stfs f10,f10Place(r1) + stfs f11,f11Place(r1) + lwz r5,0x60(r26) # wiimote cc data bl map_buttons lwz r4,0(r26) @@ -33,7 +53,17 @@ _switch_buttons: lwz r4,8(r26) or r5,r5,r4 stw r5,8(r26) + + lwz r4,r4Place(r1) + lwz r5,r5Place(r1) + lwz r6,r6Place(r1) + lwz r26,r26Place(r1) + lfs f8,f8Place(r1) + lfs f9,f9Place(r1) + lfs f10,f10Place(r1) + lfs f11,f11Place(r1) mtlr r0 + addi r1,r1,stackSize blr map_buttons: @@ -88,22 +118,22 @@ skip_minus: lis r5,float_one@h lfs f10,float_one@l(r5) lfs f11,float_neg_one@l(r5) - fcmpu cr1,f8,f10 - bne cr1,skip_right_analog - ori r6,r6,4 // WPAD_BUTTON_DOWN -skip_right_analog: - fcmpu cr1,f9,f10 - bne cr1,skip_right_analog - ori r6,r6,2 // WPAD_BUTTON_RIGHT -skip_up_analog: - fcmpu cr1,f9,f11 - bne cr1,skip_right_analog - ori r6,r6,1 // WPAD_BUTTON_LEFT -skip_down_analog: - fcmpu cr1,f8,f11 - bne cr1,skip_right_analog - ori r6,r6,8 // WPAD_BUTTON_UP -skip_left_analog: +# fcmpu cr0,f8,f10 +# bne skip_right_analog +# ori r6,r6,4 // WPAD_BUTTON_DOWN +#skip_right_analog: +# fcmpu cr0,f9,f10 +# bne skip_right_analog +# ori r6,r6,2 // WPAD_BUTTON_RIGHT +#skip_up_analog: +# fcmpu cr0,f9,f11 +# bne skip_right_analog +# ori r6,r6,1 // WPAD_BUTTON_LEFT +#skip_down_analog: +# fcmpu cr0,f8,f11 +# bne skip_right_analog +# ori r6,r6,8 // WPAD_BUTTON_UP +#skip_left_analog: mr r5,r6 blr -- cgit v1.2.3 From 9cde0784c0d82a4e95d7ff7195537d3a519efeb9 Mon Sep 17 00:00:00 2001 From: Stephen Simpson Date: Wed, 28 Sep 2011 19:18:19 -0500 Subject: fixed issue with waggle not responding for classic_controller.S --- src/classic_controller.S | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/classic_controller.S b/src/classic_controller.S index 2ba7a9e..6fe057e 100644 --- a/src/classic_controller.S +++ b/src/classic_controller.S @@ -67,11 +67,12 @@ _switch_buttons: blr map_buttons: - andi. r4,r5,0x200 // WPAD_CLASSIC_BUTTON_FULL_R + andi. r4,r5,0x10 // WPAD_CLASSIC_BUTTON_A + cmpwi r4,0 beq- skip_waggle lis r6,0x7fc0 // float -skip_waggle: stw r6,0x10(r26) // set waggle +skip_waggle: li r6,0 andi. r4,r5,0x800 // WPAD_CLASSIC_BUTTON_HOME beq- skip_home -- cgit v1.2.3