Finding Camera X coordinate.
You know now how RAM Search works, apply your knowledge to camera movements. Camera moves along the level map and always shows your character, but it doesn't move equally to him. You must move right enough to make camera move. But not too far, to not let its low byte overflow.
1. Walk around the left side of the first screen, not letting the camera move.
2. Search for value that does not change.
3. Advance the camera right a bit.
4. Search for the value that increased a bit.
5. Advance it a bit more and repeat the search.
6. Then go left and search for the value that decreased.
Find camera high byte the same way you found player's X high byte. Make camera low byte overflow and search for the value that increases by 1.
Add both values to RAM Watch and sign them accordingly.
If you have full camera X position (2 addresses) and full player X position (2 addresses), you can calculate the exact position where Mario is on the screen. It is needed to draw something with Lua. But at first you need to find your Y position (height).
Note: Y position may work in 2 ways. It either increases as you get lower (indicating the exact pixel on the screen your character is at), or it increases as you get higher (counting your position from the very bottom). Let's try the first way at first.
1. Pause the game. Reset search.
2. Press jump and advance some frames.
3. Search for the value that becomes LESS than the previous value.
4. Keep holding A and advance some more frames, as Mario gets higher.
5. Repeat searching for the value that decreases.
6. When Mario reaches the ground again, search for the value that became GREATER than previous.
7. Walk left and right, searching for the value that was EQUAL to the previous one.
I'm getting MANY addresses here, but you can add the first 2 that show different values (0002 and 00CE) to RAM Watch and then check what is more correct.
Drawing something over your character's sprite.
Download MarioDraw.luaLanguage: lua
function Draw()
-- prefix 0x before the number means it is not decimal but hex.
MarioXlow = memory.readbyte(0x86)
MarioXhigh = memory.readbyte(0x6D)
MarioX = MarioXlow + MarioXhigh*256
CameraXlow = memory.readbyte(0x71D)
CameraXhigh = memory.readbyte(0x71A)
CameraX = CameraXlow + CameraXhigh*256
MarioScreenX = MarioX - CameraX
MarioScreenY = memory.readbyte(0xCE)
gui.text(MarioScreenX, MarioScreenY, "Hi!")
end
emu.registerafter(Draw)
Download the script, drop it right onto FCEUX window, while SMB game is loaded.
We see that the Y position we used is a bit wrong. So just change one line in the script:
Language: lua
MarioScreenY = memory.readbyte(0xCE)
to
Language: lua
MarioScreenY = memory.readbyte(0x2)
Press Restart button on the Lua Script window.
Now as you move, you will see that sometimes your "Hi!" text jump up for a few frames. It means that the same addresses is used for something else, so we must find the one that ONLY indicates Mario Y. However we notice that 0x2 is exactly where Mario is vertically, so we just search for an address whose values are identical to 0x2. If you repeat your Y position search you will see them all again.
Let's try 0x4AF, and put it into the script instead of 0x2... Works for me!
I think that all those addresses that were changing identically with Mario movements, but were a bit shifted towards each other, indicate the whole Mario's HITBOX. Because 0x4AF indicates his bottom, that can collide with floor.