Geme Genie, memory access?

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Geme Genie, memory access?

Post by Zepper »

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?
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Geme Genie, memory access?

Post by lidnariq »

The Game Genie is a memory patcher; it doesn't keep track as to whether the 6502 is fetching instructions, instruction parameters, or data.
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: Geme Genie, memory access?

Post by Zepper »

Still not clear.
Can't the GG patch an instruction like LDA #$38 (the operand #$38) to another value?
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Geme Genie, memory access?

Post by tokumaru »

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.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: Geme Genie, memory access?

Post by lidnariq »

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)
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: Geme Genie, memory access?

Post by Zepper »

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?
zzo38
Posts: 1096
Joined: Mon Feb 07, 2011 12:46 pm

Re: Geme Genie, memory access?

Post by zzo38 »

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.
(Free Hero Mesh - FOSS puzzle game engine)
User avatar
Zepper
Formerly Fx3
Posts: 3262
Joined: Fri Nov 12, 2004 4:59 pm
Location: Brazil
Contact:

Re: Geme Genie, memory access?

Post by Zepper »

zzo38 wrote:Each of those four bytes can be patched individually.
It's clear enough. Thanks.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Geme Genie, memory access?

Post by tokumaru »

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.
User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 569
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Geme Genie, memory access?

Post by Jarhmander »

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. :)
((λ (x) (x x)) (λ (x) (x x)))
Post Reply