Geme Genie, memory access?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Geme Genie, memory access?
by on (#187793)
A bit of language barrier... :? :oops: :oops:

Example: IGEIAGIP -> address=$D400, value=$15, compare=$45.

If the CPU PC register is at $D400 and the instruction is LDA $D400,X (effective read from $D400). Does the GameGenie compares the PC register fetching the operator at $D400, or only the memory access at $D400? Or both?

In other words, does the GG address compare the PC register OR only memory accesses, like in a LDA $xxxx or LDA $xx?
Re: Geme Genie, memory access?
by on (#187794)
The Game Genie is a memory patcher; it doesn't keep track as to whether the 6502 is fetching instructions, instruction parameters, or data.
Re: Geme Genie, memory access?
by on (#187804)
Still not clear.
Can't the GG patch an instruction like LDA #$38 (the operand #$38) to another value?
Re: Geme Genie, memory access?
by on (#187807)
It can, it just can't tell the difference between that instruction being executed as code from another instruction loading that operand as data. The GG will patch every access to that memory location the same way, seeing as it's just watching the address/data lines and is completely unaware of what happens inside the CPU.
Re: Geme Genie, memory access?
by on (#187808)
Exactly. The game genie behaves in exactly one of two ways:

1, six digit code: When the memory address is $XXXX, instead drive the value $YY instead of whatever's coming from the ROM
2, eight digit code: When the memory address is $XXXX, if the value from the ROM is $ZZ, then instead drive the value $YY
At all other times, pass through the ROM verbatim.

So, for an emulator, this is often equivalent to a tiny IPS patch, and thus you can often pre-patch the image according to the game genie code.

(Obviously, a program could be written to make sure that the same value in ROM shows up in multiple different banks, thus detecting the game genie. But I suspect few, if any, do)
Re: Geme Genie, memory access?
by on (#187810)
tokumaru wrote:
It can, it just can't tell the difference between that instruction being executed as code from another instruction loading that operand as data. The GG will patch every access to that memory location the same way, seeing as it's just watching the address/data lines and is completely unaware of what happens inside the CPU.

Let me give you an example. Take LDA $8520. Will the GG analyse each fetch (LDA byte, $20 and $85) or only the byte at $8520 memory location?
Re: Geme Genie, memory access?
by on (#187811)
Zepper wrote:
Let me give you an example. Take LDA $8520. Will the GG analyse each fetch (LDA byte, $20 and $85) or only the byte at $8520 memory location?
Each of those four bytes can be patched individually.
Re: Geme Genie, memory access?
by on (#187812)
zzo38 wrote:
Each of those four bytes can be patched individually.

It's clear enough. Thanks.
Re: Geme Genie, memory access?
by on (#187813)
Zepper wrote:
Let me give you an example. Take LDA $8520. Will the GG analyse each fetch (LDA byte, $20 and $85) or only the byte at $8520 memory location?

The GG analyzes every fetch, but whether it will patch the value will depend on what code you use. Like zzo38 said, these are 4 different addresses.
Re: Geme Genie, memory access?
by on (#187992)
The best way to understand the Game Genie is to be the Game Genie.

Suppose you sit between between the cartridge connector and the game pak. In that place, you can see the clock, address lines, data lines, R/W etc. but how can you tell the CPU is fetching an instruction, an operand or a target memory location? If you're not smart, you just can't. If you're smart, you can look at the addresses and fetch values to understand if an instruction is being fetched, which one, and affect only explicit loads from a target address. This is way beyond what was technically feasible at that price point for such a console accessory (you almost reimplemented a 6502), so the Game Genie is not smart and patches whatever load it sees that matches one of the supplied codes. :)