Doing too much in a frame - Stack corruption?

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
Sivak
Posts: 316
Joined: Tue Jul 17, 2007 9:04 am
Location: Somewhere
Contact:

Doing too much in a frame - Stack corruption?

Post by Sivak »

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....
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

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?
Post Reply