my stack keeps rising, and causes a crash

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
my stack keeps rising, and causes a crash
by on (#142288)
I keep getting in over my head here, heh. Anyway, the intro I'm working on has a sound engine, pcm sfx, irq split, and 1 sprite on the screen, which I have moving from left to right, and I make it change into another sprite, and I do this for quite awhile since I'm showcasing sprites. Anyway, all is good if I decide to exit out of it early, but, if I try to exit out far into this, i'll just get a random crash.

I then watched my stack, and for some reason, it slowly continues to grow upward, and I believe this is my issue, but I'm not that familiar with it. I know that I have LDX #$FF and then I transfer that to the stack pointer, within my reset vector code, but other than that, I really don't know what else im missing. :-/
Re: my stack keeps rising, and causes a crash
by on (#142289)
It means you have a misaligned set of push/pull operations, which also includes things like a jsr (or repeated jsrs) without a correlating rts.

For the latter situation, especially if it's the same subroutine over and over, it should be easy to tell from the contents of the stack (they would all contain the same next-byte address, and you should be able to look at it in the debugger to find out what piece of code that correlates with + fix it).

The ldx #$ff/txs just sets S to $FF (i.e. RAM used for the stack should range from $0100 to $01FF); it isn't the source of your problem.
Re: my stack keeps rising, and causes a crash
by on (#142291)
i do have some jsr routines going on and on, and using jmp's to continue on, rather than rts. Hmm, I will chip through the this and see if I can find some sort of alternative method to my madness. Thank you for the quick response on this!

edit: it looks like it has to do with the dpcm I'm using, cause when that is not running, my stack is completely normal, it resides within $1F0-$1FF. So I'm hoping maybe its a random pha or pla.

Thanks again for the info! I think I can fix this!

edit: yup! it was my dpcm, I accidently had a register to initiate the dpcm, that was actualy being used by the Capcom 6c80 sound engine, and what was taking place, was an extra jsr being initiated which was loading a pha. So now that I simply relocated the dpcm register, my stack is pristine, and no crashes! :-D