Re: [stella] CLD
Subject: Re: [stella] CLD|
From: Kevin Horton <khorton@xxxxxxxxxxx>
Date: Mon, 03 Sep 2001 15:59:25 -0500
At 12:51 9/3/01 -0500, you wrote:
I'm working on a 255 game menu multicart, and during testing, every game
worked except for Rescue Terra I. I was looking through the Rescue Terra
I code, and noticed the suspicious absence of the SEI and CLD commands at
the start of the code. Sure enough, using the PCAEWin debugger, if you
set the decimal flag before the program runs, it crashes that same way as
on my multicart.
OK, I'm gonna let everyone know a "secret" about the 6502 processor line
(including the 6507). On any interrupt (reset, NMI, IRQ) the decimal flag
is cleared. On any interrupt (except reset) the flags are saved (including
the IRQ enable flag) THEN the IRQ flag is set, disabling further
IRQ's. Interrupts get re-enabled when you do an RTI because it pulls the
flags, including the IRQ flag, so if it was clear originally it will be
cleared once the interrupt ends, re-enabling the interrupts
"automagically". BTW, yes, reset *IS* identical to NMI, only it is
level-sensitive. If you hold the processor in reset it will continually
try to save the flags and PC to the stack (but, the R/W line is forced high
so no write takes place, even though the addressing to write to the stack
does, and the SP decrements). And, since it is an interrupt, the interrupt
flag will be set, and decimal flag cleared.
So, at the start of your code, you DO NOT EVER need CLD or SEI because the
processor does these for you :-). I always include them though since it's
only 2 bytes, and the 6502 gods smile down on you if you do so. :-) If
you're strapped for space you can leave 'em out.
BTW I got this info out of the original MOS semiconductor programming
manual for the 65xx series parts.
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/