Guide:Writing pnach files

Revision as of 21:55, 6 April 2023 by TheOnlyZac (talk | contribs) (Added formatting)

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:

  1. Loads the 32-bit pointer base from address @a
  2. Add offset @i to it to get either:
  3. If @n is 1, the final address. Skip to step 5.
  4. If @n > 1, a new pointer location. Continue to step 3.
  5. Load the 32-bit pointer address from the address computed at the previous step and add offset @p to it.
  6. 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