Re: 6502 stack register at reset

From: Segher Boessenkool <segher_at_kernel.crashing.org>
Date: Sat, 25 Nov 2017 16:15:52 -0600
Message-ID: <20171125221552.GM10515@gate.crashing.org>
On Sat, Nov 25, 2017 at 10:03:49PM +0100, Spiro Trikaliotis wrote:
> * On Sat, Nov 25, 2017 at 08:50:21PM +0100 didier derny wrote:
> > Is there any 6502 starting with an initialized stack register at reset ?
> > 
> > a few month ago I was struggling with a strange bug...
> > 
> > the program was crashing or working randomly
> > 
> > I discovered that the machine had a stack register never initialized
> 
> But: Why is this a problem? I would expect the stack pointer just to
> wrap around.
> 
> That is, if you have RAM at $0100-$01FF and you do not use that area for
> anything else, why should the CPU crash at all as long as you do not
> push more than 256 byte on it?
> 
> Can anyone enlighten me?

See for example the 6530.  It has 64 bytes of RAM and some I/O registers,
and only 10 address lines.  The "simple" example in the MCS6500 hardware
manual has the RAM selected at xxxxxx0x11xxxxxx and the I/O at
xxxxxx1111xxxxxx.  So, stack accesses to $01c0..$01ff go to RAM, but also
e.g. zero-page accesses to $00c0..$00ff go to the *same* RAM.

So, you need to initialise the stack pointer here, or you will hit
areas where there is no RAM, so your stack will not work.

In all systems with the stack aliasing the zero page (or any other RAM),
you need to initialise the stack pointer before using that other RAM.

But even worse, and why a reset doesn't assert the write pin on its
"writes" to the stack: there could be I/O in $0100..$01ff, or aliasing it.
Writing there could be disastrous.

Long story short: older 6500 systems did not have a 256 byte stack, they
didn't even have 256 bytes RAM total :-)


Segher

       Message was sent through the cbm-hackers mailing list
Received on 2017-11-25 23:01:54

Archive generated by hypermail 2.2.0.