News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Need help obtaining NES RAM addresses  (Read 1453 times)

Chicken Knife

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Need help obtaining NES RAM addresses
« on: September 16, 2018, 12:50:19 pm »
I'm working on adjusting a pointer in Dragon Warrior NES to a string of text at a new location. My problem is that the only application I've found so far that converts an offset location to the usable RAM address is Pointer Calculator. When I plug in the new location offset to that converter, it's giving me the wrong ram location. I've verified that by checking the RAM address coming up for existing locations and comparing to the pointer and it doesn't match.

For example, offset 007C80 is where monster names begin. The ram address according to Pointer Calculator is 707C
The pointer for that location can be found at 00684E. The hex value for the pointer is 70BC, which is not related at all to what the Pointer Calculator is producing.

My questions are, am I doing something wrong with the Pointer Calculator? Or is there another tool I should be using?

I've been using FCEUX, WindHex, and Translhextion. If I've overlooked a tool within those programs, please let me know.

Thank you guys! The help is always appreciated.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6585
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Need help obtaining NES RAM addresses
« Reply #1 on: September 16, 2018, 02:54:38 pm »
Is 7C80 the ROM address?
That's not a RAM address.

I'm not sure which this Pointer Calculator program is, but it may either be not for NES or you're not using the data correctly.

The contents of ROM are not directly related to the contents of RAM.

If what you mean is the CPU ADDRESS, then on the NES you need to know the ROM mapping for the Mapper of the game you're using.
I believe Dragon Warrior (the English version) is using MMC1 (whereas the Japanese Dragon Quest was a CNROM game).
MMC1 is likely using a 16KB ROM bank size (MMC1 can use 16 or 32 KB bank size), so that means a ROM bank is $4000 bytes.
You subtract the header ($10 bytes) because that's not part of the ROM.
It leaves you with 7C70.
Now, you need to know what that offset is relative to its current ROM bank. Well, the ROM bank starts at $4000 (not counting the header, again) since that is the nearest lower multiple of $4000. So that means, it is at $3C70 within that bank.

The MMC1 can map two ROM banks in at once (with 16KB bank size), since the CPU allows 32KB of ROM to be mapped in at once.
I forget if MMC1 allows it to be changed if either bank is swappable, but most likely the bank at CPU $8000 is swappable and the bank at $C000 is fixed to the last PRG ROM bank.
So, assuming $8000 is the swappable bank, then your pointer is $8000 + $3C70 = $BC70. Or 70 BC, because NES uses a "little-endian" CPU which means addresses are stored with the lower byte first.

Hoping I didn't make any mistakes, as I had to re-read the message a few times to check I got the addresses you said correct.
"My watch says 30 chickens" Google, 2018

Darrman

  • Jr. Member
  • **
  • Posts: 7
    • View Profile
Re: Need help obtaining NES RAM addresses
« Reply #2 on: September 16, 2018, 03:14:59 pm »
How NES pointers work depends on which mapper they use. English Dragon Warrior 1 uses MMC1, which judging by the pointers you've given has a swappable bank between 0x8000 and 0xC000 in the RAM. Pointer calculators don't always work very well, so learning how to convert them manually is helpful.

A pointer to 0x7C80 in the ROM would first have 0x10 subtracted to accommodate for the header, giving 0x7C70. In this case, the swappable bank lies between 0x8000 and 0xC000 in the ROM, so you need to adjust the address so it falls within that range. There's probably a more proper way, but I just simply replace the third digit with the corresponding equivalent;

0, 4, 8, C = 8
1, 5, 9, D = 9
2, 6, A, E = A
3, 7, B, F = B

7 falls in the B row, so convert it to a B. You'll have 0x7C B0 as bytes. Swap them, and you'll get 0x70BC.

https://wiki.nesdev.com/w/index.php/MMC1 has information on the technical details of the mapper, but the Banks section is what's relevant here.

Chicken Knife

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Need help obtaining NES RAM addresses
« Reply #3 on: September 16, 2018, 04:01:43 pm »
Thank you guys! I'm going to read over these replies about 30 times until I hopefully get it. I'm now regretting spending all my time playing Nintendo RPGs as a kid instead of advancing myself in mathematics. Ironic.  :laugh:

Psyklax

  • Hero Member
  • *****
  • Posts: 749
    • View Profile
    • Psyklax Translations
Re: Need help obtaining NES RAM addresses
« Reply #4 on: September 17, 2018, 08:02:29 am »
Thankfully FCEUX lets you find a CPU address and say "go here in the ROM", so it's clear which address it is. But yes, you just have to understand how the NES works.

The CPU address space is how the CPU accesses data. On the NES, it can access 64KB, and the upper half of that is dedicated to the ROM ($8000 onwards). 32KB isn't much to play with so mappers exist that reroute the CPU to different parts of the ROM. Think of it like a TV: you can only have one channel on TV at one time, so you change channels. Some mappers do just that, but some can increase the granularity - like having multiple channels on-screen at once.

So the ROM address rarely coincides with the CPU address, but at least you know the last three digits will be the same (after removing the $10 for the header).

Chicken Knife

  • Jr. Member
  • **
  • Posts: 94
    • View Profile
Re: Need help obtaining NES RAM addresses
« Reply #5 on: September 17, 2018, 12:12:35 pm »
Thank you Psyklax. I'm not going to lie and say I'm not using Darrman's little cheat method, but I really do want to eventually absorb all the science behind how this works that you and KingMike have been explaining. I'm sure that will help me find my own solutions to things more effectively going forward.

Psyklax

  • Hero Member
  • *****
  • Posts: 749
    • View Profile
    • Psyklax Translations
Re: Need help obtaining NES RAM addresses
« Reply #6 on: September 17, 2018, 03:59:59 pm »
I just reread your original post and KingMike's reply: the original pointer you found was the correct one. "70 BC" refers to $BC70 because as KM said, the 6502 in the NES is little endian and reads the smaller byte first. So just change the pointer at $684E to whatever you've changed it to, bearing in mind what we've already told you.

I wouldn't bother with a pointer calculator since it's really not difficult to figure out anyway. Once you get the hang of using the debugger in FCEUX and understanding the assembly, the addresses will be obvious. :)

If you're still trying to figure things out, might I suggest watching my YouTube tutorial? (cheap plug I know... :) )
https://youtu.be/vuL0CZrxSYo