Guide:Writing pnach files: Difference between revisions
TheOnlyZac (talk | contribs) (Added pnach documentation) |
TheOnlyZac (talk | contribs) (Added formatting) |
||
Line 1: | Line 1: | ||
This |
This guide contains documentation on how to write patches in pnach files. |
||
== Constant writes ==0 |
|||
8-bit constant write |
=== 8-bit constant write === |
||
<pre> |
|||
0aaaaaaa 000000vv |
0aaaaaaa 000000vv |
||
</pre> |
|||
Constantly writes an 8-bit value @v to the address @a. |
Constantly writes an 8-bit value @v to the address @a. |
||
16-bit constant write |
=== 16-bit constant write === |
||
<pre> |
|||
1aaaaaaa 0000vvvv |
1aaaaaaa 0000vvvv |
||
</pre> |
|||
Constantly writes a 16-bit value @v to the address @a. |
Constantly writes a 16-bit value @v to the address @a. |
||
32-bit constant write |
=== 32-bit constant write === |
||
<pre> |
|||
2aaaaaaa vvvvvvvv |
2aaaaaaa vvvvvvvv |
||
</pre> |
|||
Constantly writes a 32-bit value @v to the address @a. |
Constantly writes a 32-bit value @v to the address @a. |
||
Increment / Decrement |
== Increment / Decrement == |
||
8-bit increment |
=== 8-bit increment === |
||
<pre> |
|||
300000vv 0aaaaaaa |
300000vv 0aaaaaaa |
||
</pre> |
|||
8-bit decrement |
=== 8-bit decrement === |
||
<pre> |
|||
301000vv 0aaaaaaa |
301000vv 0aaaaaaa |
||
</pre> |
|||
16-bit increment |
=== 16-bit increment === |
||
<pre> |
|||
3020vvvv 0aaaaaaa |
3020vvvv 0aaaaaaa |
||
</pre> |
|||
16-bit decrement |
=== 16-bit decrement === |
||
<pre> |
|||
3030vvvv 0aaaaaaa |
3030vvvv 0aaaaaaa |
||
</pre> |
|||
32-bit increment |
=== 32-bit increment === |
||
<pre> |
|||
30400000 0aaaaaaa |
30400000 0aaaaaaa |
||
vvvvvvvv 00000000 |
vvvvvvvv 00000000 |
||
</pre> |
|||
32-bit decrement |
=== 32-bit decrement === |
||
<pre> |
|||
30500000 0aaaaaaa |
30500000 0aaaaaaa |
||
vvvvvvvv 00000000 |
vvvvvvvv 00000000 |
||
</pre> |
|||
Increments/decrements the value at address @a by the value @v. |
Increments/decrements the value at address @a by the value @v. |
||
32-bit constant serial write |
== 32-bit constant serial write == |
||
<pre> |
|||
4-aaaaaaa nnnnssss |
4-aaaaaaa nnnnssss |
||
vvvvvvvv iiiiiiii |
vvvvvvvv iiiiiiii |
||
</pre> |
|||
Starting with address @a, this code writes the 32-bit value @v to @n addresses. |
Starting with address @a, this code writes the 32-bit value @v to @n addresses. |
||
Line 49: | Line 72: | ||
Copy bytes |
=== Copy bytes === |
||
<pre> |
|||
5-sssssss nnnnnnnn |
5-sssssss nnnnnnnn |
||
0ddddddd 00000000 |
0ddddddd 00000000 |
||
</pre> |
|||
Copies a block of @n bytes from source address @s to destination address @d. |
Copies a block of @n bytes from source address @s to destination address @d. |
||
Pointer write |
== Pointer write == |
||
8-bit pointer write |
=== 8-bit pointer write === |
||
<pre> |
|||
6-aaaaaaa 000000vv |
6-aaaaaaa 000000vv |
||
0000nnnn iiiiiiii |
0000nnnn iiiiiiii |
||
Line 64: | Line 90: | ||
pppppppp pppppppp # N-th. extra pointer line, required if |
pppppppp pppppppp # N-th. extra pointer line, required if |
||
@n > ((N << 1) - 1) |
@n > ((N << 1) - 1) |
||
</pre> |
|||
16-bit pointer write |
=== 16-bit pointer write === |
||
<pre> |
|||
6-aaaaaaa 0000vvvv |
6-aaaaaaa 0000vvvv |
||
0001nnnn iiiiiiii |
0001nnnn iiiiiiii |
||
Line 71: | Line 99: | ||
........ ........ |
........ ........ |
||
pppppppp pppppppp |
pppppppp pppppppp |
||
</pre> |
|||
32-bit pointer write |
=== 32-bit pointer write === |
||
<pre> |
|||
6-aaaaaaa vvvvvvvv |
6-aaaaaaa vvvvvvvv |
||
0002nnnn iiiiiiii |
0002nnnn iiiiiiii |
||
Line 78: | Line 108: | ||
........ ........ |
........ ........ |
||
pppppppp pppppppp |
pppppppp pppppppp |
||
</pre> |
|||
This code reads a pointer address @a and follows it @n pointers deep. This is how it does it: |
This code reads a pointer address @a and follows it @n pointers deep. This is how it does it: |
||
Loads the 32-bit pointer base from address @a |
# Loads the 32-bit pointer base from address @a |
||
Add offset @i to it to get either: |
# Add offset @i to it to get either: |
||
⚫ | |||
If @n |
# If @n is 1, the final address. Skip to step 5. |
||
⚫ | |||
Load the 32-bit pointer address from the address computed at the previous step and add offset @p to it. |
# 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 |
# Keep doing this until all (@n - 1) offsets @p have been processed |
||
Constantly write the value @v to the final address. |
Constantly write the value @v to the final address. |
||
== Bitwise operations == |
|||
Boolean Operations |
|||
8-bit OR |
=== 8-bit OR === |
||
<pre> |
|||
7-aaaaaaa 000000vv |
7-aaaaaaa 000000vv |
||
</pre> |
|||
16-bit OR |
=== 16-bit OR === |
||
<pre> |
|||
7-aaaaaaa 0010vvvv |
7-aaaaaaa 0010vvvv |
||
</pre> |
|||
8-bit AND |
=== 8-bit AND === |
||
<pre> |
|||
7-aaaaaaa 002000vv |
7-aaaaaaa 002000vv |
||
</pre> |
|||
16-bit AND |
=== 16-bit AND === |
||
<pre> |
|||
7-aaaaaaa 0030vvvv |
7-aaaaaaa 0030vvvv |
||
</pre> |
|||
8-bit XOR |
=== 8-bit XOR === |
||
<pre> |
|||
7-aaaaaaa 004000vv |
7-aaaaaaa 004000vv |
||
</pre> |
|||
16-bit XOR |
=== 16-bit XOR === |
||
<pre> |
|||
7-aaaaaaa 0050vvvv |
7-aaaaaaa 0050vvvv |
||
</pre> |
|||
Performs a bitwise logical operation between the value @v and the value stored at address @a. |
Performs a bitwise logical operation between the value @v and the value stored at address @a. |
||
Line 112: | Line 156: | ||
8-bit / 16-bit constant serial write |
== 8-bit / 16-bit constant serial write == |
||
8-bit write |
=== 8-bit write === |
||
<pre> |
|||
8-aaaaaaa nnnnssss |
8-aaaaaaa nnnnssss |
||
000000vv 000000ii |
000000vv 000000ii |
||
</pre> |
|||
16-bit write |
=== 16-bit write === |
||
<pre> |
|||
8-aaaaaaa nnnnssss |
8-aaaaaaa nnnnssss |
||
1000vvvv 0000iiii |
1000vvvv 0000iiii |
||
</pre> |
|||
Starting with address @a, this code type will write the value @v to @n addresses. |
Starting with address @a, this code type will write the value @v to @n addresses. |
||
Line 126: | Line 174: | ||
== Conditionals == |
|||
32-bit do all following codes if equal to |
=== 32-bit do all following codes if equal to === |
||
<pre> |
|||
C-aaaaaaa vvvvvvvv |
C-aaaaaaa vvvvvvvv |
||
</pre> |
|||
All following codes will be executed only if 32-bit value at address @a is equal to the value @v. |
All following codes will be executed only if 32-bit value at address @a is equal to the value @v. |
||
Line 134: | Line 184: | ||
Do multi-lines if conditional |
=== Do multi-lines if conditional === |
||
16-bit test |
=== 16-bit test === |
||
<pre> |
|||
D-aaaaaaa 0000vvvv |
D-aaaaaaa 0000vvvv |
||
</pre> |
|||
8-bit test |
=== 8-bit test === |
||
<pre> |
|||
D-aaaaaaa 000000vv |
D-aaaaaaa 000000vv |
||
</pre> |
|||
Compares value at address @a to value @v, and executes next 1 code lines if the value is equal |
Compares value at address @a to value @v, and executes next 1 code lines if the value is equal |
||
Do multi-lines if conditional |
=== Do multi-lines if conditional === |
||
16-bit test |
=== 16-bit test === |
||
<pre> |
|||
E-0nnvvvv taaaaaaa |
E-0nnvvvv taaaaaaa |
||
</pre> |
|||
8-bit test |
=== 8-bit test === |
||
<pre> |
|||
E-1nn00vv taaaaaaa |
E-1nn00vv taaaaaaa |
||
</pre> |
|||
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 code llines only if the test condition @t is true. Values for @t are: |
||
0 equal |
* 0 equal |
||
1 not equal |
* 1 not equal |
||
2 less than |
* 2 less than |
||
3 greater than |
* 3 greater than |
||
4 NAND |
* 4 NAND |
||
5 AND |
* 5 AND |
||
6 NOR |
* 6 NOR |
||
7 OR |
* 7 OR |
||
{{WikiSEO helper |
{{WikiSEO helper |
Revision as of 21:55, 6 April 2023
This guide contains documentation on how to write patches in pnach files.
== Constant writes ==0
8-bit constant write
0aaaaaaa 000000vv
Constantly writes an 8-bit value @v to the address @a.
16-bit constant write
1aaaaaaa 0000vvvv
Constantly writes a 16-bit value @v to the address @a.
32-bit constant write
2aaaaaaa vvvvvvvv
Constantly writes a 32-bit value @v to the address @a.
Increment / Decrement
8-bit increment
300000vv 0aaaaaaa
8-bit decrement
301000vv 0aaaaaaa
16-bit increment
3020vvvv 0aaaaaaa
16-bit decrement
3030vvvv 0aaaaaaa
32-bit increment
30400000 0aaaaaaa vvvvvvvv 00000000
32-bit decrement
30500000 0aaaaaaa vvvvvvvv 00000000
Increments/decrements the value at address @a by the value @v.
32-bit constant serial write
4-aaaaaaa nnnnssss vvvvvvvv iiiiiiii
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
5-sssssss nnnnnnnn 0ddddddd 00000000
Copies a block of @n bytes from source address @s to destination address @d.
Pointer write
8-bit pointer write
6-aaaaaaa 000000vv 0000nnnn iiiiiiii pppppppp pppppppp # 1st. extra pointer line, required if ........ ........ @n > 1 pppppppp pppppppp # N-th. extra pointer line, required if @n > ((N << 1) - 1)
16-bit pointer write
6-aaaaaaa 0000vvvv 0001nnnn iiiiiiii pppppppp pppppppp ........ ........ pppppppp pppppppp
32-bit pointer write
6-aaaaaaa vvvvvvvv 0002nnnn iiiiiiii pppppppp pppppppp ........ ........ pppppppp pppppppp
This code reads a pointer address @a and follows it @n pointers deep. This is how it does it:
- 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
7-aaaaaaa 000000vv
16-bit OR
7-aaaaaaa 0010vvvv
8-bit AND
7-aaaaaaa 002000vv
16-bit AND
7-aaaaaaa 0030vvvv
8-bit XOR
7-aaaaaaa 004000vv
16-bit XOR
7-aaaaaaa 0050vvvv
Performs a bitwise logical operation between the value @v and the value stored at address @a.
8-bit / 16-bit constant serial write
8-bit write
8-aaaaaaa nnnnssss 000000vv 000000ii
16-bit write
8-aaaaaaa nnnnssss 1000vvvv 0000iiii
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
C-aaaaaaa vvvvvvvv
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
16-bit test
D-aaaaaaa 0000vvvv
8-bit test
D-aaaaaaa 000000vv
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
E-0nnvvvv taaaaaaa
8-bit test
E-1nn00vv taaaaaaa
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:
- 0 equal
- 1 not equal
- 2 less than
- 3 greater than
- 4 NAND
- 5 AND
- 6 NOR
- 7 OR