C0 Codetypes
C0 Codetypes

Thank you to Star for teaching me some details on the C0 Codes...

Chapter 1. What Are C0 Codes?

C0 Codes are called Execute ASM Codes. They are a bit different than 'C2/Insert ASM' Codes. C0 Codes are executed every time the designated hooktype is called upon by the game. This means they are executed every frame. For example, if your Hooktype for your Cheat/Ocarina settings is OSSleepThread, every time the address of OSSleepThread is executed, the C0 Code will be executed as well. To understand more about Hooktypes, read this thread HERE.

You can add certain instructions to make C0 Codes only execute once if desired. With some crafty ASM, you can even make C0 Codes only execute on set intervals. C0 Codes have no base address, and are thus region-free. You can also design some C0 codes to be wii-game-universal. 

Chapter 2: Format

C0000000 000000YY

YY = Amount of Compiled Lines Below (in Hex)
XXXXXXXX = ASM Instruction

The Z's (final line) of a C0 Code can vary. There are two outputs...

4E800020 00000000

Every C0 code must end in a blr instruction. This is because the code handler creates a subroutine for your C0 code via a 'blrl' instruction. So if you have an even amount of instructions (not including the final blr), your C0 code will end as 4E800020 00000000. If you have an odd amount of instructions (not including blr), your C0 Code will end as your last ASM instruction then the blr.

Chapter 3: Notes About Compiling

PyiiASMH Notes:
If you are using this compiler, simply select the 'C0' option before compiling. The compiler will auto-add the final blr for you, so there's no need for you to have it in your Source.

WiiRDGUI Notes:
There's no C0 option for WiiRDGUI. Leave the address as '80000000'. You will need to include the final blr in your source.

With the final blr included, if you have a an odd amount of ASM instructions, simply change the codetype to C0 after compilation.

With the final blr included, if you have an even amount of ASM instructions, compile the code, change the C2 to C0. Then, remove the final compiled line '60000000 00000000'. After that, subtract one from the YY value.

Chapter 4: Register Safety

Certain registers and condition fields are already taken up by the Code Handler so we want to make sure we don't edit those specific values

r0 = Safe
r1 = Not Safe (Can push/pop stack like any other ASM code if needed)
r2 = Not Safe ofc...
r3 = Safe
r4 = Not Safe
r5 = Safe
r6 thru r8 = Not Safe
r9 thru r12 = Safe
r13 thru r31 = Not Safe
All Condition Fields = Safe (CR backed up by code handler, CR's get set with new values with new instructions after C0 subroutine)
CTR = Safe (CTR backed up by code handler, CTR gets set with new value with new instructions after C0 subroutine)
LR = Not Safe ofc...
f0 & f1 = Follow Standard Safety Protocol
f2 & f3 = Safe (backed up by code handler)
f4 thru f31 = Follow Standard Safety Protocol

As noted above, you can push/pop the stack for more registers if needed. As usual, try using the least amount of stack space possible. Only allocate what you need.

Chapter 5: Make C0 Code Only Execute Once

If desired, here is a list of instructions to add to your Source to enable a C0 Code to only execute once. Make sure these instructions come before all other instructions of your Source.

lis rX, 0x4E80
ori rX, rX, 0x0020
stw rX, 0 (r15)

rX = Any of the safe registers

Anybody who created/helped-on the Gecko Code Handler
dcx2 (for his comments about this topic on the old WiiRD forums)

Forum Jump:

Users browsing this thread: 1 Guest(s)