Super-Hampster wrote:
It works in FCEUXD. It will be later this week before I can try real hardware.
Even if it works on hardware, I doubt it will be stable, because it's breaking several NES programming rules.
Quote:
Also, it is a very newb program that does very little, so it may be very careless.
That problem is that you might make a habit out of this. You should be more careful since the beginning to avoid that.
Before trying on hardware, I suggest you fix the problems I mentioned, and get it to run in more emulators. If you are not doing any crazy effects (raster effects, forced blanking, timing-sensitive effects, and so on), the program should work on all popular emulators. If it doesn't you can bet you are breaking a basic NES rule, and if it works on hardware it shouldn't be considered stable (it might still fail under certain circumstances or hardware revisions).
So here are some facts you might not know because your program didn't take them into consideration:
1. A lot of parts of the system are at unknown states when it's powered on, so you must perform some basic initialization in order to prepare a stable environment for your program. Disabling IRQs (SEI) and initializing the stack (LDX #$FF; TXS) are common initialization tasks.
2. The PPU needs some time to warm up before it can be safely used. A lot of PPU operations are not available as soon as the system is turned on, so you must wait at least 2 frames before drawing backgrounds, using sprites and setting palettes. You can poll $2002 and wait for 2 VBlanks.
3. PPU memory can only be written to during VBlank or when rendering is off. This means that before setting the palette you must either disable rendering or wait for Vblank, otherwise that transfer might happen at a time it's not allowed to, and all you'll get is visual glitches.
4. Polling $2002 to time the game logic misses VBlanks. If $2002 is read at the exact time VBlank starts (and that happens quite often), the flag will not return set for that frame, causing the game logic to miss a frame, which results in jerky movement and slowdowns. You should look into NMIs (even if all your NMI does is set a flag and the game logic polls this flag instead of $2002).