+  RHDN Forum Archive
|-+  Romhacking
| |-+  ROM Hacking Discussion
| | |-+  Random Stack Question
Pages: [1]
Author Topic: Random Stack Question  (Read 2 times)
Dr. Floppy
Guest
« on: February 26, 2009, 04:53:00 pm »

Greetings once again,


       I was viewing the RAM (via the hex editor portion of FCEUxD SP) of Zelda 1 when I noticed a few numbers in the middle of the bottom Stack line $[1F0-1FF] being written/rewritten at the pace of a hummingbird's wingflap. The other values in the line, as well as the line above it (the Stack was about halfway up the $1E0 line), were static.

I was under the impression that the Stack was first-in/last-out. How exactly are values in the middle of the existing sequence being played with, without the values after/above them being affected? Is it just that said values are being replaced with the same thing, a la SMB2's infamous static animation?
Tauwasser
Guest
« Reply #1 on: February 26, 2009, 05:09:17 pm »

Well, you can always address this ram directly, so it's not that you cannot change anything other than by pushing/poping. Also, at least for the game boy there is an opcode that basically lets you store the current stack pointer (sp) and add an offset value to it in a register (ld hl, sp ± $XX). So you can address stuff that was popped before a routine was called. This might be the case if it is in the main loop (as it needs a constant offset of SP to the data being changed).

Also, you could look where the stack is initialized (usually after ram for that slot was cleared) and see if those offsets are actually meant to be in the stack. Depending on the stack type, you can tell if it just happens that you can pop this and it was not planned or if it was to be included in the stack and is just a clever trick used by the engine to call different routines in different places.

cYa,

Tauwasser
KingMike
Guest
« Reply #2 on: February 26, 2009, 09:28:38 pm »

Heh, I remember SOBS used the SP to read data.
It sets the SP to the data it wants to read, then uses pop instructions to read it.
Doesn't that hold great bug potential? Tongue
Tauwasser
Guest
« Reply #3 on: February 26, 2009, 09:37:37 pm »

Well, I've seen that, too. But it's entirely possible as long as any interrupts are disabled. It's faster than reading from other registers it seems... at least on gb Wink

cYa,

Tauwasser
Pages: [1]  


Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC