Doing too much in a frame - Stack corruption?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Doing too much in a frame - Stack corruption?
by on (#65283)
Well, this is a very weird one... Basically, here's what I'm doing in each frame:

Update player, shots, enemies... After this, I display the sprites using 2 routines... One goes: Player, shots, enemies, the other goes enemies, player, shots.

The way I update both enemies and these animations is like this: I have all relevant enemy memory stored and then it all gets transferred into some equivalent ZP memory. This gets updated and then written back into the memory, the index goes up, new enemy memory gets read in, repeat. I need to do this cloning process twice.

The game does NOT crash if I don't "unclone" the second time, which makes NO SENSE. The game also doesn't crash if fewer than 9 enemies are loaded in at one point... BK1 supported 16 objects just fine at a time, and that had music engine going and everything.

I don't know what the deal even would be for this... I don't think the game is doing too much in one frame, but could it be? Thanks.

I'm about ready to just use the BK1 method of sprite drawing. It wasn't perfect, but it worked....

by on (#65287)
Set the bottom byte of the stack ($100 if you start the stack out at $1FF) to a known value, then see whether this ever gets changed.

To see how much you're doing in the frame, set bit 0 of $2001 when you're done with everything for the frame. This should put a gray bar at the bottom portion of the screen, showing the free time. Start with a small number of objects, then add more until it crashes. Was the bar nearly at the bottom just before it crashed?