M88kai+ patch (cheat code) function

[Intro]
This is a translation of the P88SR patch documentation, which was the basis for the patch (cheat code) feature in M88kai+.

[Usage]
Create a text file in the format below and change the extension to .PAT. The patch file will load automatically with a game if it has the same name as the game and is in the same directory.

[Format]
------------
;            ... Comments

# name1      ... Name of code, 20 letters max (also applies to M88?)
code1
code2

# name2
code3
code4
.
.
.
# name15     ... maximum of 15 individual code groups (also applies to M88?)
code63
code64       ... maximum of 64 individual codes (also applies to M88?)
------------

[Ys example]
Ys1.D88      Game disk image
Ys1.PAT      Patch file

Content of Ys1.PAT:
------------
; 
;   Ys patch
; 
#HP MAX 
D00047CF 4B00 
80004B00 FFFF 

#GOLD MAX 
D00047CF 4B00 
80004B04 FFFF 

#EXP MAX 
D00047CF 4B00 
80004B06 FFFF 
------------

[Codes]
All codes are in hexadecimal.
aa   = RAM/ROM type
bbbb = address
yyzz = data

  aa  Location        Address range (bbbb)
-----------------------------------------
  00  Main RAM	        0000-FFFF
  01  N88BASIC ROM	0000-5FFF
  02  High-speed RAM	F000-FFFF
  03  Sub-CPU RAM       4000-7FFF
  04  Sub-CPU ROM       0000-1FFF
  05  NBASIC ROM	6000-7FFF
  06  NBASIC ROM	0000-5FFF
  07  N88BASIC ROM	6000-7FFF
  08  E0-ROM		6000-7FFF
  09  E1-ROM		6000-7FFF
  0A  E2-ROM		6000-7FFF
  0B  E3-ROM		6000-7FFF
  0C  Ext. RAM-bank0	0000-7FFF
  0D  Ext. RAM-bank1	0000-7FFF
  0E  Ext. RAM-bank2	0000-7FFF
  0F  Ext. RAM-bank3	0000-7FFF

[1] Write commands

   [1-1] Overwrite

80aabbbb yyzz		16-bit
30aabbbb yyzz		 8-bit (zz only)

Writes the value yyzz/zz to the specified address (aabbbb).

   [1-2] Add

10aabbbb yyzz		16-bit
20aabbbb yyzz		 8-bit (zz only)

Continually adds the value yyzz/zz to the value at the specified address (aabbbb).

   [1-3] Subtract

11aabbbb yyzz		16-bit
21aabbbb yyzz		 8-bit (zz only)

Continually subtracts the value yyzz/zz to the value at the specified address (aabbbb).

Typically, the add/subtract commands are used in conjunction with the compare commands below.


[2] Compare commands

   [2-1] Equals

D0aabbbb yyzz		16-bit
E0aabbbb yyzz		 8-bit (zz only)

When the value at the specified address (aabbbb) equals yyzz/zz, the next code is evaluated.

   [2-2] Does not equal

D1aabbbb yyzz		16-bit
E1aabbbb yyzz		 8-bit (zz only)

When the value at the specified address (aabbbb) does not equal yyzz/zz, the next code is evaluated.

   [2-3] Less than

D2aabbbb yyzz		16-bit
E2aabbbb yyzz		 8-bit (zz only)

When the value at the specified address (aabbbb) is less than yyzz/zz, the next code is evaluated.

   [2-4] Greater than

D3aabbbb yyzz		16-bit
E3aabbbb yyzz		 8-bit (zz only)

When the value at the specified address (aabbbb) is greater than yyzz/zz, the next code is evaluated.

*Multiple codes (stacking compare codes)

By stacking the compare codes D0 to D3 and E0 to E3), it is possible to apply multiple compare conditions to a single code.

Example:
D0008000 0100      When the value at address 008000 is equal to 0100,
E0034000 0006      and when the value at address 034000 is equal to 06,
8000D000 0713      keep address 00D000 at the value 0713.


[3] Special codes

   [3-1] Serial

Not supported in M88.


[4] Other

   [4-1] Equals (strong)

Not supported in M88.

   [4-2] Timer

C1000000 zzzz

Specifies a time starting at boot up until the next code activates.
The units of zzzz are approximately 1/600th of a second, so specifying 0258 (600 in decimal) gives approximately 1 min.

*In M88 the timer probably doesn't start until you activate the code group.

   [4-3] Byte copy

Not supported in M88.

   [4-4] Compare key input

Not supported in M88.
