RAEmus icon indicating copy to clipboard operation
RAEmus copied to clipboard

[RAP64] All RAM addresses are byteswapped

Open eldexterr opened this issue 4 years ago • 7 comments

Hi, this has been a problem for me for a very long time, I dunno if this was on purpose but all addresses appear byte swapped on the memory inspector, looks like is the only console on RA having this problem (or maybe i'm wrong?).

Just look the RAM using any other memory inspector and you can see what i'm talking about, even if you search gameshark codes for N64 games on the internet, you will find the addresses never match the ones from RAP64. image From Top to the bottom: RAP64 Bizhawk PJ64

My problem with this it just make harder to use RAP64 for debugging purposes, because when you are for example making a mod you always need to search for the true addresses by using another memory inspector.

Also I think it make harder for people that aren't familiar with RA, like someone want to use the code notes from RA but he doesn't know this is a thing and he will get really confused.

I usually use the Debugger version of PJ64 (PJ64D) for all of this, but tbh RAP64 have a lot of cool features that the normal version of pj64 lacks, or simply some things are easier to do on RAP64.

I dunno if this will be even possible to fix, because you will need to basically made a giant refactor of all addresses for ALL N64 games on RA's DB, also you will need to do the same for N64 achievements logics and Rich Presence.

But I hope this can be fixed, grettings :)

eldexterr avatar May 21 '20 22:05 eldexterr

Looks like an "endianess" issue.

I may be wrong but I think MemInspector always assumes little endian order.

Maybe if you change the Memory View to 32-bit the values will be "fixed".

meleu avatar May 22 '20 03:05 meleu

Actually yes, if you active a 32-bit view it appears as it should although the addresses are still wrong 🤔

eldexterr avatar May 22 '20 03:05 eldexterr

I've noticed you have a tendency to use byteswapped roms for some reason. While it seems somewhat unlikely, perhaps if you use tool64 to convert your roms to big endian (the standard format for n64 games), you'll find the memory layout changes to the expected format as well.

Sanaki avatar May 22 '20 03:05 Sanaki

RAM is RAM. It shouldn't matter which tool is viewing it. The emulator exposes a base pointer to the toolkit, which is used to extrapolate the entire contents of RAM. The RetroArch core does a similar thing, which is passed through RALibRetro to the toolkit, and used by RetroArch to process the achievements.

If there's any swapping going on, it's purely in the way it's being presented. As suggested above, you may be viewing the memory in 32-bit mode. For most systems, we do change the addresses of memory, but the N64 actually has it's RAM starting at address $000000, so it's unnecessary on that system. Note: The expansion pak memory is re-addressed (from $80000000 to $04000000). This is done when mapping the memory into the toolkit, and does not affect the emulator's view of the memory.

If RAProject64 were doing something to modify how the RAM was stored, don't you think it would break the games? They expect the RAM to appear exactly as it would in the real system.

Your screenshots do show a discrepency that I can't explain, but I will reiterate: RAProject64 just passes a pointer to a block on memory to the toolkit. There's absolutely nothing in the toolkit code that would be doing any byte swapping. If there is a problem, it's in the base Project64 code, and not something in code which we are responsible for.

Jamiras avatar May 22 '20 13:05 Jamiras

I've noticed you have a tendency to use byteswapped roms for some reason. While it seems somewhat unlikely, perhaps if you use tool64 to convert your roms to big endian (the standard format for n64 games), you'll find the memory layout changes to the expected format as well.

This. There's been a handful of times where I had to dig around for the right ROM for your sets (especially ones requiring patches) rather than using the standard No Intro ROMs. For the Yoshi's Story bonus set, I had to use tool64 to convert to byteswapped before I was able to successfully apply the bps patch.

televandalist avatar May 22 '20 13:05 televandalist

What I'm trying to say is all N64 notes on RA are wrong, all the notes saved for that system are wrong and the memory inspector shows the memory in a wrong way, isn't something about my ROM, if you start doing some hacking for any N64 game you will know what I'm talking about.

The way the addresses need to be shown is like in Bizhawk those are the true addresses, and those are how the console see it, actually you don't even need to even use bizhawk you can activate the debugger on RAP64 and watch them via PJ64's memory viewer (not the RA one)

eldexterr avatar May 22 '20 18:05 eldexterr

What I'm trying to say is all N64 notes on RA are wrong, all the notes saved for that system are wrong and the memory inspector shows the memory in a wrong way

What does "wrong" mean?

Alright... no need to go into a philosophical discussion here. That was just a rhetorical question...

What I'm trying to say is that a probably more accurate statement would be "the Memory Inspector shows the memory in a different way than Bizhawk".

Keep in mind these three facts about RA Memory Inspector:

  1. the addresses are "virtual addresses" (not physical addresses, matching the original architecture).
  2. each address is 8 bits long.
  3. it uses the little endian order.

Regarding N64, according to this resource, N64's kernel usually operates in 32-bit addressing mode, for performance reasons (it's also able to be in 64-bit addressing mode).

Then, if you want to be extremely faithful to the original architecture, you should code all your N64 achievements referencing addresses that are multiples of four and using 32-bit size.

meleu avatar May 22 '20 22:05 meleu