cpu initial state

Topics pertaining to the emulation or simulation of the 65xx microprocessors and their peripheral chips.
Post Reply
tano6502
Posts: 4
Joined: 19 Apr 2009

cpu initial state

Post by tano6502 »

Hello,
what are exactly the state of the cpu registers and flags at startup
(or after a reset)? Datasheets and many docs on the net seems
not to answer this (perhaps obvious) question.
Thanks,
tano
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

The interrupt-disable flag is set, the decimal flag is cleared, and the program counter is loaded with the value at FFFC-FFFD. Nothing else is guaranteed. In fact, on the NMOS 6502, even the decimal flag is not guaranteed after reset or interrupt. That fact that it is guaranteed on the CMOS ones is one of the many improvements that came with CMOS.

The 65816 appropriately has a few more guarantees. The data and program bank registers are zeroed, the high byte of the stack pointer is set to 01, the high bytes of the X and Y registers are zeroed, the 6502 emulation bit is set, and the direct-page register is zeroed.

Welcome to the forum. We've had quite a few legitimate new members join in the last several weeks.
tano6502
Posts: 4
Joined: 19 Apr 2009

Post by tano6502 »

Thanks! I forget to specify that I intend the NMOS version.
Looking in emulators source code I noted that reset code
seems also to clear all registers (a, x and y), and set the Zero
flag. Naturally the stack pointer should be set to 0x01ff.
But I think these are additions in respect to the natural behavior.
Bye,
tano
User avatar
HansO
Posts: 206
Joined: 31 Oct 2003

Post by HansO »

GARTHWILSON wrote:
In fact, on the NMOS 6502, even the decimal flag is not guaranteed after reset or interrupt.


Indeed that seems to be random. The KIM-1 monitor ROM does not clear the decimal flag after reset. A major flaw and number 1 problem for new KIM-1 users in the old days. Second one was not connecting the +12V that was required for the cassette interface.
User avatar
GARTHWILSON
Forum Moderator
Posts: 8775
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

Quote:
Indeed that seems to be random. The KIM-1 monitor ROM does not clear the decimal flag after reset. A major flaw and number 1 problem for new KIM-1 users in the old days.
In the microprocessor class in 1982 on AIM-65's, we were taught to just initialize the decimal flag at the beginning of anything we did, just as we would not assume the accumulator or X or Y somehow automatically held the exact value we would happen to want first. It was no problem, but later with the 65c02 it was nice to be able to save a byte, and more importantly in ISRs, a couple of clocks, by being able to leave out the CLD.
Post Reply