State of flag register after reset

For discussing the 65xx hardware itself or electronics projects.
Post Reply
User avatar
Ruud
Posts: 259
Joined: 12 Dec 2003
Location: Heerlen, NL
Contact:

State of flag register after reset

Post by Ruud »

Hallo allemaal,

Can anybody tell me what the level of the individual flags is after a reset?
It seems I simply cannot find this info in the books I have :(
Thanks!

Code: Select all

    ___
   / __|__
  / /  |_/     Groetjes, Ruud 
  \ \__|_\
   \___|       URL: www.baltissen.org

User avatar
8BIT
Posts: 1787
Joined: 30 Aug 2002
Location: Sacramento, CA
Contact:

Post by 8BIT »

Ruud,

On page 11 of the current WDC 65C02 datasheet, the flags setting after reset are decribed. Here is what it shows:

Code: Select all

   7   6   5   4   3   2   1   0
   N   V       B   D   I   Z   C
   *   *   1   1   0   1   *   *

* indicates software initialized.

I take this to mean that the hardware sets the B,D& I flags but its up to the software to configure the N,V,Z&C flags.

Daryl
Last edited by 8BIT on Sat Apr 08, 2006 4:03 am, edited 1 time in total.
raccoon
Posts: 21
Joined: 05 Feb 2006
Location: The Netherlands

Post by raccoon »

Well Ruud, this has been said before: If the datasheet doesn't cover some issue, it is.. err... literally undefined. You can safely assume it is for a reason.
I trust my somewhat flawed English is comprehensible to all.
User avatar
Ruud
Posts: 259
Joined: 12 Dec 2003
Location: Heerlen, NL
Contact:

Post by Ruud »

8BIT wrote:
....
I take this to mean that the hardware sets the B,D& I flags but its up to the software to configure the N,V,Z&C flags.

Daryl
Many thanks!

Code: Select all

    ___
   / __|__
  / /  |_/     Groetjes, Ruud 
  \ \__|_\
   \___|       URL: www.baltissen.org

ghaytack
Posts: 38
Joined: 24 Mar 2004

Post by ghaytack »

Hi Ruud,

To quote the original MOS 65xx Hardware Manual :

"It should be assumed that any time the RESET line has been pulled LOW and then HIGH, the internal states of the machine are unknown and all registers must be re-initialised during the restart sequence".

When dealing with IRQ it states :

"Until the various registers in the processor have been initialized, the processor is not able to respond properly to any external interrupts. For this reason it is important that the system RESET disable all external interrupt signals until they are enabled by the processor".

So it would seem that if there is any chance of the code being run on older variants of the 6502 than WDC's, it is prudent to start your reset code with SEI.
:)
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Post by GARTHWILSON »

ghaytack, I don't have a MOS data sheet, but my oldest 6502 datasheet is a Synertek one from 1979, and it does say that the reset sequence sets the interrupt disable bit before loading the reset vector. I think that in your quote above, they're probably just explaining why they do that, saying that if they didn't, even if your first instruction in the reset routine in ROM is SEI, you might still get into trouble if the interrupt line is being held low, because the interrupt vector could be taken before you even get to the SEI. All the interrupt types, including RST I'm sure, set the interrupt-disable flag.
ghaytack
Posts: 38
Joined: 24 Mar 2004

Post by ghaytack »

Hi Garth,

It puzzled me as well not finding any mention of it in the MOS hardware manual (it's labelled Frist Edition, August 1975) as I was fully expecting to find it. Other data sheets I looked at last night (Rockwell, CMD) state that RESET disables IRQ in the CPU and I've always written code on that basis since I started 6502 coding with the Lance A Leventhal "6502 Assembly Language Programming" book.

A 1978 edition of the Rockwell R65xx Programming Manual states it explicitly and appears to be a reprint of the MOS 1978 manual with a different cover. An early oversight by the MOS documentation department perhaps (to go with the mistakes in many 6522 data sheets)? :)

George
Post Reply