Guide:Writing pnach files: Difference between revisions

General modification.
(Added pnach format section)
(General modification.)
Line 1:
This guide contains documentation on how to write patchespatch lines in pnach filesformat.
 
== Pnach Format ==
 
Pnach format takes inspiration from RAW PS2 cheat codes. RAW PS2 cheat codes are composed of 2 numbers, both always hexadecimal and always composed of 8 digits.
A pnach file is a sequence of patches in the following format:
<pre>
patch=1,EE,00000000,extended,00000000
</pre>
 
To convert a RAW PS2 cheat code to a patch line to be used in a pnach file, one must add "patch=1,EE," before the first number, and ",extended," before the second number.
For example, this patch writes the 4-byte value 0x64 to the address 123456:
<pre>
20123456 00000064
</pre>
 
For example, a RAW PS2 cheat code could be:
and in pnach format it becomes:
00E98100 00000064
<pre>
Converted to pnach-format:
patch=1,EE,20123456,extended,00000064
patch=1,EE,00E98100,extended,00000064
</pre>
This patch line will constantly write the 4-byte value 0x64 to the address 0xE98100.
 
Below is the documentation of all pnach codes.
 
Pnach format supports single-line ("//") comments. This means that prefixing a patch line with "//" it will be ignored.
== Constant writes ==
 
So, we can say that a pnach file is a sequence of patch lines.
 
Below you can find the documentation of the code types available with their respective syntax.
== Constant write ==
 
=== 8-bit constant write ===
Writes the 8-bit value @v to the address @a.<pre>
<pre>
0aaaaaaa 000000vv
</pre>
 
Constantly writes an 8-bit value @v to the address @a.
 
 
=== 16-bit constant write ===
Writes the 16-bit value @v to the address @a.<pre>
<pre>
1aaaaaaa 0000vvvv
</pre>
 
Constantly writes a 16-bit value @v to the address @a.
 
 
=== 32-bit constant write ===
Writes the 32-bit value @v to the address @a.<pre>
<pre>
2aaaaaaa vvvvvvvv
</pre>
 
== Increment / Decrement ==
Constantly writes a 32-bit value @v to the address @a.
Increment/decrement the current value at address @a by value @v.
 
 
== Increment / Decrement ==
=== 8-bit increment ===
<pre>
Line 78 ⟶ 68:
vvvvvvvv 00000000
</pre>
Increments/decrements the value at address @a by the value @v.
 
== Constant serial write ==
 
=== 328-bit constant serial write ===
Starting with address @a, this code writes the 8-bit value @v to @n addresses.
 
In each cycle, the address is incremented by @s * 2 and the value is incremented by @i.
<pre>
4aaaaaaa8aaaaaaa nnnnssss
000000vv 000000ii
vvvvvvvv iiiiiiii
</pre>
 
=== 16-bit constant serial write ===
Starting with address @a, this code writes the 16-bit value @v to @n addresses.
 
In each cycle, the address is incremented by @s * 2 and the value is incremented by @i.
<pre>
8aaaaaaa nnnnssss
1000vvvv 0000iiii
</pre>
 
=== 32-bit constant serial write ===
Starting with address @a, this code writes the 32-bit value @v to @n addresses.
 
In each cycle, the address is incremented by @s * 4 and the value is incremented by @i.
 
 
=== Copy bytes ===
<pre>
4aaaaaaa nnnnssss
vvvvvvvv iiiiiiii
</pre>
 
== Copy bytes ==
Copies a block of @n bytes from source address @s to destination address @d.<pre>
5sssssss nnnnnnnn
0ddddddd 00000000
</pre>
 
== Pointer write ==
Copies a block of @n bytes from source address @s to destination address @d.
This code reads a pointer address @a, follows it @n pointers deep, and writes the @v value to the calculated address.
 
NOTE: Execution of this code type will stop if a NULL pointer is encountered to prevent a crash.
 
==== Single dereference (n <= 1) ====
Loads the 32-bit base address from address @a, adds offset @p_0 to it, and constantly writes the value @v to the calculated address.
 
==== Multiple dereferences (n > 1) ====
Loads the 32-bit base address from address @a, adds offset @p_0 to it to get an initial pointer address P_0. Dereference P_0 and add @p_1 to the result to get the next pointer address P_1. This is done @n times until the final address P_n is found, at which point the value @v is written to the calculated address.
 
== Pointer write ==
=== 8-bit pointer write ===
<pre>
6aaaaaaa 000000vv
0000nnnn iiiiiiii p_0
p_1 p_2
pppppppp pppppppp # 1st. extra pointer line, required if
........ ........ @n > 1
p_(n-1) p_n
pppppppp pppppppp # N-th. extra pointer line, required if
@n > ((N << 1) - 1)
</pre>
 
=== 16-bit pointer write ===
<pre>
6aaaaaaa 0000vvvv
0001nnnn iiiiiiii p_0
p_1 p_2
pppppppp pppppppp
........ ........
p_(n-1) p_n
pppppppp pppppppp
</pre>
 
Line 124 ⟶ 135:
<pre>
6aaaaaaa vvvvvvvv
0002nnnn iiiiiiii p_0
p_1 p_2
pppppppp pppppppp
........ ........
p_(n-1) p_n
pppppppp pppppppp
</pre>
 
== Bitwise operations ==
This code reads a pointer address @a and follows it @n pointers deep. This is how it does it:
Performs a bitwise logical operation between the value @v and the value stored at address @a. Store the result at address @a.
 
# Loads the 32-bit pointer base from address @a
# Add offset @i to it to get either:
# If @n is 1, the final address. Skip to step 5.
# If @n > 1, a new pointer location. Continue to step 3.
# Load the 32-bit pointer address from the address computed at the previous step and add offset @p to it.
# Keep doing this until all (@n - 1) offsets @p have been processed
Constantly write the value @v to the final address.
 
 
== Bitwise operations ==
=== 8-bit OR ===
<pre>
Line 172 ⟶ 174:
</pre>
 
== Conditionals ==
Performs a bitwise logical operation between the value @v and the value stored at address @a.
 
=== C-Type ===
 
==== 32-bit execute all following codes if equal to ====
 
All following codes will be executed only if 32-bit value at address @a is equal to the value @v.<pre>
== 8-bit / 16-bit constant serial write ==
=== 8-bit write ===
<pre>
8aaaaaaa nnnnssss
000000vv 000000ii
</pre>
 
=== 16-bit write ===
<pre>
8aaaaaaa nnnnssss
1000vvvv 0000iiii
</pre>
 
Starting with address @a, this code type will write the value @v to @n addresses.
 
In each cycle, the address is incremented by @s or @s * 2 and the value is incremented by @i.
 
 
== Conditionals ==
=== 32-bit do all following codes if equal to ===
<pre>
Caaaaaaa vvvvvvvv
</pre>
 
=== D-Type (NOT RECOMMENDED) ===
All following codes will be executed only if 32-bit value at address @a is equal to the value @v.
=== Do multi-lines if conditional ===
 
==== 16Multi-bitline test"if" ====
Compares value at address @a to value @v, and executes next @n lines only if the test condition @t is true. Values for @t are:
<pre>
* 0 equal
Daaaaaaa 0000vvvv
* 1 not equal
</pre>
* 2 less than
* 3 greater than
* 4 NAND
* 5 AND
* 6 NOR
* 7 OR
 
==== 8-bit test ====
<pre>
Daaaaaaa 000000vvnnt100vv
</pre>
 
Compares value at address @a to value @v, and executes next 1 code lines if the value is equal
 
 
=== Do multi-lines if conditional ===
 
==== 16-bit test ====
<pre>
Daaaaaaa nnt0vvvv
E0nnvvvv taaaaaaa
</pre>
 
==== 8E-bitType test(RECOMMENDED) ====
<pre>
E1nn00vv taaaaaaa
</pre>
 
==== Multi-line "if" ====
Compares value at address @a to value @v, and executes next @n code llines only if the test condition @t is true. Values for @t are:
Compares value at address @a to value @v, and executes next @n lines only if the test condition @t is true. Values for @t are:
* 0 equal
* 1 not equal
Line 237 ⟶ 218:
* 6 NOR
* 7 OR
 
==== 8-bit test ====
<pre>
E1nn00vv taaaaaaa
</pre>
 
==== 16-bit test ====
<pre>
E0nnvvvv taaaaaaa
</pre>
*
 
{{WikiSEO helper
35

edits