The codes change locations in the PS1 PS2 memory using a program that inserts itself in a small unused portion of memory. It pirates the vertical sync ussually. The vertical sync or FRAME interrupt happens each time a new screen is to be sent to the video display. This is used by games often to know when it can update the display or swap viewed areas and update the next frame.
The code cheater program adjusts the memory location as 'needed' the series of codes perform different specialized actions.
DXXXXXXX watches a memory location (watches) and compares it to the value
8XXXXXXX sets a word sized memory location to a value
BXXXXXXX set a byte sized memory location to a value
etc. there are also repeat count codes that auto increment a memory location.
It's a very simple "HACK" program to allow one to do things. For example I played with Tomb Raider 4's vertical velocity value to make laura levitate (with rapid pushes of the jump button that is
). Many games have added code to prevent cheating. One of which is thousand arms. There is a common cheat of infinite health in combat, however this code is actually incomplete. Thousand Arms also keeps track of how much damage you received during combat and subtracts that after a battle. So you can survive a battle and DIE immediately thereafter.
Chrono Cross, Star Ocean 2 are two other games that do this as well. The next problem with this kind of cheat code system is that in some games it doesn't keep a single set of values. You have combat values and global values. The combat values location changes depending on what battle you are in. (This is because the game's stack changes depending on the battle I guess). These are temporary values. Vandel Heart's 1 and 2 have this issue.
The cheat systems are very dependent on bad programming practice (IE heavy use of global variables), so if the game used standard programming practice THAT could make things very difficult to cheat with.
Cheat codes are also used to trick the game into debug modes (Chrono Cross and Final Fantasy 7 both have these).
Cyb