Code Patcher v1.0 [JoshuaMK]
#1
Code Patcher v1.0 [JoshuaMK]

NOTE: Currently only working in Dolphin.

This code allows you to actively patch codes into the code list without needing to restart the game after applying said codes. Future versions may include deletion of codes, patching GCT files, scrolling to allow larger codes, and maybe even relocating codes when needed. But until I figure those things out, this is v1.0!

Disclaimer: I am not responsible for any screen burn-in issues caused by this code. If playing on a real Wii on a flatscreen TV, please activate the screen burn-in reduction option in the Wii settings, and only keep this menu up for ~5 mins at a time at most. As long as you deactivate the menu without injecting the code, your code will be saved in memory to continue working on.



(NTSC-U)
C200A3F0 00000007
9421FF80 BC610008
806DA358 80630044
80630000 3D808002
618C23E0 7D8803A6
4E800021 B8610008
38210080 80010014
60000000 00000000
C0000000 00000048
9421FFA0 BD610008
3D808034 618CXXXX
A16C0000 3D808000
886C0198 28030000
41820210 A3EC1906
A3CC190A 57FF801E
7FFFF214 3DC0F000
3DE08000 61EF2FFC
865F0004 7C1F7800
41800010 38600001
986C01C0 480001DC
7C127000 4082FFE4
93EC01A0 280Buuuu
418200BC 280Bdddd
418200F8 280BRRRR
41820104 280BLLLL
41820138 280BUUUU
4182014C 280BDDDD
41820180 280BYESS
40820190 619C0F94
83EC01A0 7E9C84AA
2C150000 40A20014
2C160000 40A2000C
2C170000 4182016C
3BFFFFFC 89CC01A6
39CE0001 99CC01A6
280E000F 41A0015C
39C00000 7F98E378
861C0004 863C0004
961F0004 963F0004
7C1F7800 4181013C
7C107000 4082FFE4
2C110000 40A2FFDC
3BFFFFFC 93EC01A0
619F12FC 96380004
7C18F800 4180FFF8
48000108 3B600000
A24C01A4 A26C01A8
3A520F98 7E529A14
89CC01A6 39CE0001
99CC01A6 280E0004
41A000E8 39C00000
7C6C90AE 281B0001
41820018 38630001
7C6C91AE 480000C4
3B600001 4BFFFFBC
3863FFFF 7C6C91AE
480000B0 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A000A0 39C00000
A24C01A4 281B0001
41820020 3A520001
28120008 4080007C
B24C01A4 48000074
3B600001 4BFFFFC4
2C120000 41820064
3A52FFFF B24C01A4
48000058 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A00048 39C00000
A26C01A8 281B0001
41820020 28130048
40800028 3A730008
B26C01A8 4800001C
3B600001 4BFFFFC4
2C130000 4182000C
3A73FFF8 B26C01A8
39C00000 99CC01A6
B9610008 38210060
4C00012C 4E800020
2834XXXX YYYYZZZZ
C2009640 0000002A
9421FF70 BC610008
3D808000 896C0198
2C0B0000 41820128
896C01C0 280B0001
4182011C 48000035
53656C65 63746564
3A204279 74652C20
2558207C 204C696E
652C2025 580A2558
20202530 38582025
30385800 00000000
7C8802A6 7C9D2378
619E0F98 88AC01A5
A0CC01A8 38E00008
7CC63BD6 38E00000
7CFD3B78 7D1E44AA
61831500 3BE30030
4CC63182 3D808001
618C0ECC 7D8803A6
4E800021 2C030000
4180009C 3B800009
48000015 0A255820
20253038 58202530
38580000 7C8802A6
7FE3FB78 3BDE0008
3BBD0001 7FA5EB78
7CDEA4AA 3BE30015
3D808001 618C0ECC
7D8803A6 4E800021
2C030000 41800050
3B9CFFFF 2C1C0000
4082FFB0 38600009
3880000C 38A00001
7C1C0378 8B9CFFBF
1F9C0015 38DFFFD0
7CDC3050 3D808002
618C1DF0 7D8803A6
4E800021 3D808002
618C1DD0 7D8803A6
4E800021 B8610008
38210090 81830000
60000000 00000000
00000198 00000001
04009628 60000000
0454EECC 60000000
046046A8 60000000
CC000000 00000000
00000198 00000000
0454EECC 4BFFFBE9
046046A8 4BFECF9D
04009628 4E800421
04009640 81830000
E0000000 80008000

(PAL)
C200A430 00000007
9421FF80 BC610008
806DA360 80630044
80630000 3D808002
618C2480 7D8803A6
4E800021 B8610008
38210080 80010014
60000000 00000000
C0000000 00000048
9421FFA0 BD610008
3D808034 618CXXXX
A16C0000 3D808000
886C0198 28030000
41820210 A3EC1906
A3CC190A 57FF801E
7FFFF214 3DC0F000
3DE08000 61EF2FFC
85BF0004 7C1F7800
41800010 38600001
986C01C0 480001DC
7C0D7000 4082FFE4
93EC01A0 280Buuuu
418200BC 280Bdddd
418200F8 280BRRRR
41820104 280BLLLL
41820138 280BUUUU
4182014C 280BDDDD
41820180 280BYESS
40820190 619C0F94
83EC01A0 7E9C84AA
2C150000 40A20014
2C160000 40A2000C
2C170000 4182016C
3BFFFFFC 89CC01A6
39CE0001 99CC01A6
280E000F 41A0015C
39C00000 7F98E378
861C0004 863C0004
961F0004 963F0004
7C1F7800 4181013C
7C107000 4082FFE4
2C110000 40A2FFDC
3BFFFFFC 93EC01A0
619F12FC 96380004
7C18F800 4180FFF8
48000108 3B600000
A1AC01A4 A26C01A8
39AD0F98 7DAD9A14
89CC01A6 39CE0001
99CC01A6 280E0004
41A000E8 39C00000
7C6C68AE 281B0001
41820018 38630001
7C6C69AE 480000C4
3B600001 4BFFFFBC
3863FFFF 7C6C69AE
480000B0 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A000A0 39C00000
A1AC01A4 281B0001
41820020 39AD0001
280D0008 4080007C
B1AC01A4 48000074
3B600001 4BFFFFC4
2C0D0000 41820064
39ADFFFF B1AC01A4
48000058 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A00048 39C00000
A26C01A8 281B0001
41820020 28130048
40800028 3A730008
B26C01A8 4800001C
3B600001 4BFFFFC4
2C130000 4182000C
3A73FFF8 B26C01A8
39C00000 99CC01A6
B9610008 38210060
4C00012C 4E800020
2834XXXX YYYYZZZZ
C2009680 0000002A
9421FF70 BC610008
3D808000 896C0198
2C0B0000 41820128
896C01C0 280B0001
4182011C 48000035
53656C65 63746564
3A204279 74652C20
2558207C 204C696E
652C2025 580A2558
20202530 38582025
30385800 00000000
7C8802A6 7C9D2378
619E0F98 88AC01A5
A0CC01A8 38E00008
7CC63BD6 38E00000
7CFD3B78 7D1E44AA
61831500 3BE30030
4CC63182 3D808001
618C1A2C 7D8803A6
4E800021 2C030000
4180009C 3B800009
48000015 0A255820
20253038 58202530
38580000 7C8802A6
7FE3FB78 3BDE0008
3BBD0001 7FA5EB78
7CDEA4AA 3BE30015
3D808001 618C1A2C
7D8803A6 4E800021
2C030000 41800050
3B9CFFFF 2C1C0000
4082FFB0 38600009
3880000C 38A00001
7C1C0378 8B9CFFBF
1F9C0015 38DFFFD0
7CDC3050 3D808002
618C1E90 7D8803A6
4E800021 3D808002
618C1E70 7D8803A6
4E800021 B8610008
38210090 81830000
60000000 00000000
00000198 00000001
04009628 60000000
0454EECC 60000000
046046A8 60000000
CC000000 00000000
00000198 00000000
0454EECC 4BFFFBE9
046046A8 4BFECF9D
04009628 4E800421
04009640 81830000
E0000000 80008000

(NTSC-J)
C200A38C 00000007
9421FF80 BC610008
806DA360 80630044
80630000 3D808002
618C23A0 7D8803A6
4E800021 B8610008
38210080 80010014
60000000 00000000
C0000000 00000048
9421FFA0 BD610008
3D808034 618CXXXX
A16C0000 3D808000
886C0198 28030000
41820210 A3EC1906
A3CC190A 57FF801E
7FFFF214 3DC0F000
3DE08000 61EF2FFC
85BF0004 7C1F7800
41800010 38600001
986C01C0 480001DC
7C0D7000 4082FFE4
93EC01A0 280Buuuu
418200BC 280Bdddd
418200F8 280BRRRR
41820104 280BLLLL
41820138 280BUUUU
4182014C 280BDDDD
41820180 280BYESS
40820190 619C0F94
83EC01A0 7E9C84AA
2C150000 40A20014
2C160000 40A2000C
2C170000 4182016C
3BFFFFFC 89CC01A6
39CE0001 99CC01A6
280E000F 41A0015C
39C00000 7F98E378
861C0004 863C0004
961F0004 963F0004
7C1F7800 4181013C
7C107000 4082FFE4
2C110000 40A2FFDC
3BFFFFFC 93EC01A0
619F12FC 96380004
7C18F800 4180FFF8
48000108 3B600000
A1AC01A4 A26C01A8
39AD0F98 7DAD9A14
89CC01A6 39CE0001
99CC01A6 280E0004
41A000E8 39C00000
7C6C68AE 281B0001
41820018 38630001
7C6C69AE 480000C4
3B600001 4BFFFFBC
3863FFFF 7C6C69AE
480000B0 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A000A0 39C00000
A1AC01A4 281B0001
41820020 39AD0001
280D0008 4080007C
B1AC01A4 48000074
3B600001 4BFFFFC4
2C0D0000 41820064
39ADFFFF B1AC01A4
48000058 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A00048 39C00000
A26C01A8 281B0001
41820020 28130048
40800028 3A730008
B26C01A8 4800001C
3B600001 4BFFFFC4
2C130000 4182000C
3A73FFF8 B26C01A8
39C00000 99CC01A6
B9610008 38210060
4C00012C 4E800020
2834XXXX YYYYZZZZ
C20095DC 0000002A
9421FF70 BC610008
3D808000 896C0198
2C0B0000 41820128
896C01C0 280B0001
4182011C 48000035
53656C65 63746564
3A204279 74652C20
2558207C 204C696E
652C2025 580A2558
20202530 38582025
30385800 00000000
7C8802A6 7C9D2378
619E0F98 88AC01A5
A0CC01A8 38E00008
7CC63BD6 38E00000
7CFD3B78 7D1E44AA
61831500 3BE30030
4CC63182 3D808001
618C1950 7D8803A6
4E800021 2C030000
4180009C 3B800009
48000015 0A255820
20253038 58202530
38580000 7C8802A6
7FE3FB78 3BDE0008
3BBD0001 7FA5EB78
7CDEA4AA 3BE30015
3D808001 618C1950
7D8803A6 4E800021
2C030000 41800050
3B9CFFFF 2C1C0000
4082FFB0 38600009
3880000C 38A00001
7C1C0378 8B9CFFBF
1F9C0015 38DFFFD0
7CDC3050 3D808002
618C1DB0 7D8803A6
4E800021 3D808002
618C1D90 7D8803A6
4E800021 B8610008
38210090 81830000
60000000 00000000
00000198 00000001
04009628 60000000
0454EECC 60000000
046046A8 60000000
CC000000 00000000
00000198 00000000
0454EECC 4BFFFBE9
046046A8 4BFECF9D
04009628 4E800421
04009640 81830000
E0000000 80008000

(NTSC-K)
C200A538 00000007
9421FF80 BC610008
806DA380 80630044
80630000 3D808002
618C24E0 7D8803A6
4E800021 B8610008
38210080 80010014
60000000 00000000
C0000000 00000048
9421FFA0 BD610008
3D808033 618CXXXX
A16C0000 3D808000
886C0198 28030000
41820210 A3EC1906
A3CC190A 57FF801E
7FFFF214 3DC0F000
3DE08000 61EF2FFC
85BF0004 7C1F7800
41800010 38600001
986C01C0 480001DC
7C0D7000 4082FFE4
93EC01A0 280Buuuu
418200BC 280Bdddd
418200F8 280BRRRR
41820104 280BLLLL
41820138 280BUUUU
4182014C 280BDDDD
41820180 280BYESS
40820190 619C0F94
83EC01A0 7E9C84AA
2C150000 40A20014
2C160000 40A2000C
2C170000 4182016C
3BFFFFFC 89CC01A6
39CE0001 99CC01A6
280E000F 41A0015C
39C00000 7F98E378
861C0004 863C0004
961F0004 963F0004
7C1F7800 4181013C
7C107000 4082FFE4
2C110000 40A2FFDC
3BFFFFFC 93EC01A0
619F12FC 96380004
7C18F800 4180FFF8
48000108 3B600000
A1AC01A4 A26C01A8
39AD0F98 7DAD9A14
89CC01A6 39CE0001
99CC01A6 280E0004
41A000E8 39C00000
7C6C68AE 281B0001
41820018 38630001
7C6C69AE 480000C4
3B600001 4BFFFFBC
3863FFFF 7C6C69AE
480000B0 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A000A0 39C00000
A1AC01A4 281B0001
41820020 39AD0001
280D0008 4080007C
B1AC01A4 48000074
3B600001 4BFFFFC4
2C0D0000 41820064
39ADFFFF B1AC01A4
48000058 3B600000
89CC01A6 39CE0001
99CC01A6 280E0004
41A00048 39C00000
A26C01A8 281B0001
41820020 28130048
40800028 3A730008
B26C01A8 4800001C
3B600001 4BFFFFC4
2C130000 4182000C
3A73FFF8 B26C01A8
39C00000 99CC01A6
B9610008 38210060
4C00012C 4E800020
2833XXXX YYYYZZZZ
C2009788 0000002A
9421FF70 BC610008
3D808000 896C0198
2C0B0000 41820128
896C01C0 280B0001
4182011C 48000035
53656C65 63746564
3A204279 74652C20
2558207C 204C696E
652C2025 580A2558
20202530 38582025
30385800 00000000
7C8802A6 7C9D2378
619E0F98 88AC01A5
A0CC01A8 38E00008
7CC63BD6 38E00000
7CFD3B78 7D1E44AA
61831500 3BE30030
4CC63182 3D808001
618C1A94 7D8803A6
4E800021 2C030000
4180009C 3B800009
48000015 0A255820
20253038 58202530
38580000 7C8802A6
7FE3FB78 3BDE0008
3BBD0001 7FA5EB78
7CDEA4AA 3BE30015
3D808001 618C1A94
7D8803A6 4E800021
2C030000 41800050
3B9CFFFF 2C1C0000
4082FFB0 38600009
3880000C 38A00001
7C1C0378 8B9CFFBF
1F9C0015 38DFFFD0
7CDC3050 3D808002
618C1EF0 7D8803A6
4E800021 3D808002
618C1ED0 7D8803A6
4E800021 B8610008
38210090 81830000
60000000 00000000
00000198 00000001
04009628 60000000
0454EECC 60000000
046046A8 60000000
CC000000 00000000
00000198 00000000
0454EECC 4BFFFBE9
046046A8 4BFECF9D
04009628 4E800421
04009640 81830000
E0000000 80008000



Guide

Note: This code makes use of user input. See this guide for reference on filling in values: https://mkwii.com/showthread.php?tid=44

XXXX = Controller Address
YYYY = Mask
ZZZZ = Button to Activate/Deactivate Code
uuuu = Increase Value
dddd = Decrease Value
RRRR = Move Right 1 Byte
LLLL = Move Left 1 Byte
UUUU = Move Up 1 Line
DDDD = Move Down 1 Line
YESS = Inject Code Into Game



#~~~~~~#
#C0 Inject#
#~~~~~#

.set region, '' #Fill in E, P, J, or K within the quotes for your region when Compiling! Lowercase letters can also be used.

.macro push_stack
stwu r1, -0x60 (r1)
stmw r11, 0x8 (r1)
.endm

.macro pop_stack
lmw r11, 0x8 (r1)
addi r1, r1, 0x60
.endm

.macro grab_controller_input
lis r12, input_address
ori r12, r12, 0x3E80
lhz r11, 0 (r12)
.endm

.macro code_flag_check
lbz r3, 0x198 (r12)
cmplwi r3, 0
beq the_end
.endm

.macro mega_loop_find_end
lhz r31, 0x1906 (r12) #Grab Address Values
lhz r30, 0x190A (r12)
slwi r31, r31, 16 #Set Upper Address
add r31, r31, r30 #Combine Address Base
lis r14, 0xF000 #Set End of Codes Value
lis r15, 0x8000
ori r15, r15, 0x2FFC #Create a Cap of Mega Loop
mega_loop:
lwzu r18, 0x4 (r31) #Load Value of Address Into r18
cmpw r31, r15
blt continue #If r31's Address is Greater Than Cap, End Code
li r3, 1
stb r3, 0x1C0 (r12)
b the_end
continue:
cmpw r18, r14 #Compare r13 to r14 and Loop if Not Equal
bne mega_loop
stw r31, 0x1A0 (r12) #Store Address Into RAM
.endm

.macro find_movement_type_and_move
cmplwi r11, 0x88
beq increase_one
cmplwi r11, 0x84
beq decrease_one
cmplwi r11, 0x82
beq move_right
cmplwi r11, 0x81
beq move_left
cmplwi r11, 0x94
beq next_line
cmplwi r11, 0x98
beq previous_line
cmplwi r11, 0xF0
bne reset_and_end
ori r28, r12, 0xF94
lwz r31, 0x1A0 (r12) #Grab End Address
lswi r20, r28, 16
cmpwi r21, 0
bne+ valid
cmpwi r22, 0
bne+ valid
cmpwi r23, 0
beq- reset_and_end
valid:
subi r31, r31, 0x4
lbz r14, 0x1A6 (r12)
addi r14, r14, 1
stb r14, 0x1A6 (r12)
cmplwi r14, 0
blt+ the_end
li r14, 0
mr r24, r28
mega_loop_2: #Mega Loop
lwzu r16, 0x4 (r28)
lwzu r17, 0x4 (r28)
stwu r16, 0x4 (r31)
stwu r17, 0x4 (r31)
cmpw r31, r15 #Check for Address Higher Than Cap and End If So
bgt the_end
cmpw r16, r14 #Following checks for F0000000 00000000 and loops if not found
bne+ mega_loop_2
cmpwi r17, 0
bne- mega_loop_2
subi r31, r31, 0x4
stw r31, 0x1A0 (r12) #Subtract 8 from r31, to get new end address, and store to RAM
ori r31, r12, 0x12FC
clear:
stwu r17, 0x4 (r24)
cmpw r24, r31
blt+ clear
b reset_and_end
increase_one:
li r27, 0 #Load Increase Flag
decrease_recycle:
lhz r18, 0x1A4 (r12) #The Following Loads the chosen byte, adds 1 to it and stores.
lhz r19, 0x1A8 (r12)
addi r18, r18, 0xF98
add r18, r18, r19
lbz r14, 0x1A6 (r12)
addi r14, r14, 1
stb r14, 0x1A6 (r12)
cmplwi r14, 4
blt+ the_end
li r14, 0
lbzx r3, r12, r18
cmplwi r27, 1
beq decrease
addi r3, r3, 1
stbx r3, r12, r18
b reset_and_end
decrease_one:
li r27, 1
b decrease_recycle
decrease:
subi r3, r3, 1
stbx r3, r12, r18
b reset_and_end
move_right:
li r27, 0
left:
lbz r14, 0x1A6 (r12)
addi r14, r14, 1
stb r14, 0x1A6 (r12)
cmplwi r14, 6
blt+ the_end
li r14, 0
lhz r18, 0x1A4 (r12)
cmplwi r27, 1
beq left_move
addi r18, r18, 1
cmplwi r18, 0x8
bge reset_and_end
sth r18, 0x1A4 (r12)
b reset_and_end
move_left:
li r27, 1
b left
left_move:
cmpwi r18, 0
beq reset_and_end
subi r18, r18, 1
sth r18, 0x1A4 (r12)
b reset_and_end
next_line:
li r27, 0
line:
lbz r14, 0x1A6 (r12)
addi r14, r14, 1
stb r14, 0x1A6 (r12)
cmplwi r14, 6
blt+ the_end
li r14, 0
lhz r19, 0x1A8 (r12)
cmplwi r27, 1
beq backwards_line
cmplwi r19, 0x48
bge reset_and_end
addi r19, r19, 0x8
sth r19, 0x1A8 (r12)
b reset_and_end
previous_line:
li r27, 1
b line
backwards_line:
cmpwi r19, 0
beq reset_and_end
subi r19, r19, 0x8
sth r19, 0x1A8 (r12)
reset_and_end:
li r14, 0
stb r14, 0x1A6 (r12)
.endm

.if    (region == 'E' || region == 'e') # RMCE
    .set input_address, 0x8034
.elseif (region == 'P' || region == 'p') # RMCP
    .set input_address, 0x8034
.elseif (region == 'J' || region == 'j') # RMCJ
    .set input_address, 0x8034
.elseif (region == 'K' || region == 'k') # RMCK
    .set input_address, 0x8033
.else # Invalid Region
    .err
.endif


#START


push_stack

grab_controller_input

lis r12, 0x8000

code_flag_check

mega_loop_find_end

find_movement_type_and_move

the_end:

pop_stack

isync

#END

=================================================

#Second ASM

#~~~~~~~~~~~~~~~~~~#
#      Register Notes:              #
# No need to backup r0 or LR #
#~~~~~~~~~~~~~~~~~~#

#~~~~~~~~~~~~~~#
# Macros & Statements #
#~~~~~~~~~~~~~~#

.macro push_stack
stwu r1, -0x80 (r1)
stmw r3, 0x8 (r1)
.endm

.macro pop_stack
lmw r3, 0x8 (r1)
addi r1, r1, 0x80
.endm

.macro call_link address
lis r12, \address@h
ori r12, r12, \address@l
mtlr r12
blrl
.endm

.macro default_instruction
lwz r0, 0x0014 (r1)
.endm

.set region, '' #Must set region value, or else source will not compile

.if (region == 'E' || region == 'e') # RMCE
.set nw4r_db_DirectPrint_SetupFB, 0x800223E0
.elseif (region == 'P' || region == 'p') # RMCP
.set nw4r_db_DirectPrint_SetupFB, 0x80022480
.elseif (region == 'J' || region == 'j') # RMCJ
.set nw4r_db_DirectPrint_SetupFB, 0x800223A0
.elseif (region == 'K' || region == 'k') # RMCK
.set nw4r_db_DirectPrint_SetupFB, 0x800224E0
.else # Invalid Region
.abort
.endif

#~~~~~~~~~~~~~~#
# Start Register Safety #
#~~~~~~~~~~~~~#

push_stack

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# Get Render Mode (RKSystem->mpVideo()->pRenderMode) #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

.if (region == 'E' || region == 'e') # RMCE
lwz r3, -0x5CA8(r13)
.elseif (region == 'P' || region == 'p') # RMCP
lwz r3, -0x5CA0(r13)
.elseif (region == 'J' || region == 'j') # RMCJ
lwz r3, -0x5CA0(r13)
.elseif (region == 'K' || region == 'k') # RMCK
lwz r3, -0x5C80(r13)
.endif

lwz r3, 0x0044(r3)
lwz r3, 0x0 (r3)

#~~~~~~~~~~~~~~~~~~~~~~#
# Call nw4r::db: DirectPrint_SetupFB #
#        r3 = Render Mode                 #
#~~~~~~~~~~~~~~~~~~~~~~#

call_link nw4r_db_DirectPrint_SetupFB

#~~~~~~~~~~~~~~~~~~~~~~~~~#
# End Register Safety; Default Instruction #
#~~~~~~~~~~~~~~~~~~~~~~~~~#

pop_stack
default_instruction

==================================================

#Third ASM

#~~~~~~~~~~~~~~~~~~#
#      Register Notes:              #
# No need to backup r0 or LR #
#~~~~~~~~~~~~~~~~~#

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#                                  Mem Address Notes:                                                                     #
#                            0x80001660 Speed Float Word                                                             #
# 0x815F0000 "Status Word" If not zero, Draw Code will execute, auto clears after every race  #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

#~~~~~~~~~~~~~~#
# Macros & Statements #
#~~~~~~~~~~~~~~#

.macro push_stack
stwu r1, -0x90 (r1)
stmw r3, 0x8 (r1)
.endm

.macro pop_stack
lmw r3, 0x8 (r1)
addi r1, r1, 0x90
.endm

.macro call_link address
lis r12, \address@h
ori r12, r12, \address@l
mtlr r12
blrl
.endm

.macro default_instruction
lwz r12, 0x0 (r3)
.endm

.set region, '' #Must set region value, or else source will not compile

.if (region == 'E' || region == 'e') # RMCE

.set sprintf, 0x80010ECC
.set nw4r_db_DirectPrint_Printf, 0x80021DF0
.set nw4r_db_DirectPrint_StoreCache, 0x80021DD0

.elseif (region == 'P' || region == 'p') # RMCP

.set sprintf, 0x80011A2C
.set nw4r_db_DirectPrint_Printf, 0x80021E90
.set nw4r_db_DirectPrint_StoreCache, 0x80021E70

.elseif (region == 'J' || region == 'j') # RMCJ

.set sprintf, 0x80011950
.set nw4r_db_DirectPrint_Printf, 0x80021DB0
.set nw4r_db_DirectPrint_StoreCache, 0x80021D90

.elseif (region == 'K' || region == 'k') # RMCK

.set sprintf, 0x80011A94
.set nw4r_db_DirectPrint_Printf, 0x80021EF0
.set nw4r_db_DirectPrint_StoreCache, 0x80021ED0

.else # Invalid Region
.abort
.endif

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#      Check to See if a Race is Active:                   #
#        Load Status Word from Mem 81                 #
# If not zero, we know to execute the Draw Code #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#


push_stack

lis r12, 0x8000
lbz r11, 0x198 (r12)
cmpwi r11, 0
beq- dont_execute
lbz r11, 0x1C0 (r12)
cmplwi r11, 1
beq- _error

bl the_string #Create the C++ string

#Selected: Byte, %X | Line, %X | Address, %X\n%X  %08X %08X\0\0

.string "Selected: Byte, %X | Line, %X\n%X  %08X %08X\0\0\0\0"

the_string:
mflr r4 #Set 4th Arg of DirectPrint Printf
mr r29, r4

ori r30, r12, 0xF98 #Load Area of Code into r11
lbz r5, 0x1A5 (r12)
lhz r6, 0x1A8 (r12)
li r7, 8
divw r6, r6, r7
li r7, 0
mr r29, r7
lswi r8, r30, 8
ori r3, r12, 0x1500
addi r31, r3, 0x30

crclr 4*cr1+eq

call_link sprintf

cmpwi r3, 0x0
blt- _error

li r28, 9
string_loop:

bl second_string

#.string "\n%X  %08X %08X\n%08X %08X\0\0"

.string "\n%X  %08X %08X\0"

second_string:
mflr r4
mr r3, r31
addi r30, r30, 0x8
addi r29, r29, 1
mr r5, r29
lswi r6, r30, 20
addi r31, r3, 0x15

call_link sprintf

cmpwi r3, 0
blt- _error
subi r28, r28, 1
cmpwi r28, 0
bne+ string_loop

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#              DirectPrint Printf & Store Cache                            #
#                Purpose: Draw on Screen                                  #
#            r3 = X coordinate (starts far left)                            #
#          r4 = Y coordinate (starts at very top)                        #
#                r5 = 0 No Wrap; 1 Wrap                                    #
# r6 = Address Pointer to String that will be Drawn on Screen #
#              r7 thru r10 printf format args                               #
#            f1 thru f13 printf float format args                          #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

li r3, 0x9
li r4, 0xC
li r5, 0x1
mr r28, r0
lbz r28, -0x41 (r28)
mulli r28, r28, 0x15
addi r6, r31, -0x30 #Make r6 have 0x80001500, beginning of entire formatted string
sub r6, r6, r28

call_link nw4r_db_DirectPrint_Printf
call_link nw4r_db_DirectPrint_StoreCache

#~~~~~~~~~~~~~~~~~~~~~~~~~#
# dont_execute label; Default Instruction #
#~~~~~~~~~~~~~~~~~~~~~~~~~#

_error:
dont_execute:
pop_stack
default_instruction







Code Creator: JoshuaMK
Code Contributors: Star & RiiDefi (Draw Text To Screen Code)
Super Mario Eclipse, what Super Mario Sunshine could've been.
Reply
#2
Nice! Next up, GCT extender!

What is the purpose of the isync instruction for the C0 code? Have you tried the C0 without the isync?

On the ASM with the sprintf function, you should only need to allocate 0x80 stack space, not 0x90.

Also on the call_link macro, go to Stars thread on the Draw text, he's optimized the macro. You have the functions' first half address in a global variable register. Then do a macro with Ori, mtlr, blrl for both functions so the two occurrences of lis is not needed.

My current graphical codes (except Clock) use the old macro.
Reply
#3
Oh cool. I had no clue. I plan to go over this code again with more optimizations, and features as the v1.0 implies. I will go over that for sure.
Super Mario Eclipse, what Super Mario Sunshine could've been.
Reply
#4
I responded to your PM.

Btw here's another optimization for note--

In the C0 ASM, I don't see any function calls. You don't have to make a stack frame. You can use the negative area of the stack instead. This will save you 2 instructions right there. I've been so lazy I keep forgetting to add that note in the About Register Safety thread.

EDIT:
went ahead and added that note to About Stack Frames thread instead.
Reply
#5
This is awesome! I'm impressed.
(10-16-2019, 10:15 PM)Vega Wrote: went ahead and added that note to About Stack Frames thread instead.
I noticed in that thread you advise that stack frames should be quadword aligned. However, I've seen various sources, and they only mention doubleword alignment as a requirement for ppc32. Might be the case or might not for the Wii-specific EABI, but I would be surprised if quadword alignment truly is necessary.
Reply
#6
Neat to see something like this come into fruition. It kinda reminds me of the exception handler Kirby Air Ride:
[Image: GiVNKqR.png]
Reply
#7
(10-17-2019, 01:38 AM)salmon01 Wrote: This is awesome! I'm impressed.
(10-16-2019, 10:15 PM)Vega Wrote: went ahead and added that note to About Stack Frames thread instead.
I noticed in that thread you advise that stack frames should be quadword aligned. However, I've seen various sources, and they only mention doubleword alignment as a requirement for ppc32. Might be the case or might not for the Wii-specific EABI, but I would be surprised if quadword alignment truly is necessary.

Ye there was some IBM Article for the PPC32 that states all stacks must be quadword aligned. Regarding the Broadway, I booted up MKW on Dolphin really quick and looked at a bunch of function calls, couldn't find one that was not quadword aligned.
Reply
#8
Hey Joshua, here's how you can get Easy Extender to work... (the limit for display aka string lenghth is a lot less than Star/Riis code btw) So if everything is right and it still fails, you may have went beyond the string length limit. Or... YS's code is using some part of the Exception Vectors that you are using too, to get around that, just throw shit on the stack and increase the frame size accordingly... View some of star's complex codes to see how to save extra data to the stack for doing args for function calls

First, grab everything BUT the C0 code from the original Easy Extender - http://mkwii.com/showthread.php?tid=790 This will be at the beginning of your code.

So with this, you have two function calls available in an ASM code...

Sprintf:
lis rX, 0x8000
lwz rX, 0x1858 (rX)
mtlr rX
blrl

Draw Code:
lis rX, 0x8000
lwz rX, 0x1850 (rX)
mtlr rX
blrl

Next you will make a C0 code....

When you push the stack frame, do this instruction right before to backup the LR...
mflr r12

Once you pop the stack frame, do this instruction right after
mtlr r12

Args for the Draw code...
r3 = Pointer where data is (already converted from previous sprintf)
r4 1st byte = X coordinate (make this 01)
r4 2nd byte = Y coordinate (make this 02)
r4 3rd byte = font color (make this 02)
r4 4th byte = bg color (make this 01)

I use to have a list of ALL the color combos but wiped them by mistake. they may be on the wayback machine somewhere (when the site was mkwii.org)... if you care enough

ofc since you use the python compiler like me, you don't need to add the blr at the end for the C0 code.

I just did a test run for "hello world" with these guidelines and it works. So if this works for you, your code will for the Wii console on ALL games.
I tried doing this for my Mem Viewer code but I bypassed the string length limit by a mile, so there's really no point bothering with it anymore....
Reply
#9
What exactly is the byte limit? Direct print allows up to 100 bytes.
Super Mario Eclipse, what Super Mario Sunshine could've been.
Reply
#10
Less than 100 for sure. Too lazy to narrow down the exact amount.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)