On reset Stack Pointer status

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

Post Reply
Concurser
Posts: 5
Joined: Fri Mar 06, 2020 12:30 pm

On reset Stack Pointer status

Post by Concurser » Sat Mar 21, 2020 1:03 am

Using the debugger provided in Mesen, and trying to compare with my early-coded 6502 simulator, I noticed that even with no initial opcode executed, the first instruction (SEI - Set Interrupt Disable) already shows some preset values:

1) Cycle: 8 - ok I found this number in some docs.
2) Flags: 100 (4) Interrupt Set - why? The SEI instruction wasn´t even stepped...well, after I step into it, the I flag will be set anyways.
3) Stack Pointer: here is the most odd part. The Stack is set at $FD, with two values already stacked ($00, $00).

Could someone explain this points? where can I find some documentation about it?

Fiskbit
Posts: 85
Joined: Sat Nov 18, 2017 9:15 pm

Re: On reset Stack Pointer status

Post by Fiskbit » Sat Mar 21, 2020 2:04 am

There's a wiki page on the CPU power-up state here. Regarding the stack, SP initializes to 0 on power-on. When the CPU follows the reset vector, it treats it like any interrupt and tries to push P and PC onto the stack, but special logic makes the CPU perform reads instead of writes for these stack accesses. SP is decremented by 3 because of these accesses.

Concurser
Posts: 5
Joined: Fri Mar 06, 2020 12:30 pm

Re: On reset Stack Pointer status

Post by Concurser » Sun Mar 22, 2020 10:38 pm

Thanks!

Post Reply