I thought it was kind of weird that you're trying to do everything in 6502, here. Why not just have the emulator do it?
I don't know whether or not this will help, but this is how I do it in my emu:
- I only have a very tiny bit of 6502 to drive the NSF. It looks very similar to blargg's:
Code:
JSR INIT
Loop:
JSR PLAY
JAM ; 'illegal' opcode $F2
JMP Loop
- This code sits at $3000 (read-only). The rest of $2xxx and $3xxx is removed and emulated as open bus.
- When a new track is selected by the user, I clear RAM, reset the bankswapping regs ($5FFx) to their header supplied values, set A and X to the trank number and region, and set the PC to $3000.
- Every frame, instead of triggering an NMI, I just unjam the CPU.
- In addition to removing PPU regs as stated above, I also remove $4014 and $4016. NSFs should need nothing apart from APU regs.
- I don't do any PPU emulation at all. Or generate any image to be drawn.
- I disallow all IRQs and NMIs. I know there are several NSFs out there that CLI and will break if you emulate IRQs.
- As for any visual display.. this is done
by the emulator and not with some NSF driver in 6502. This lets you get around silly NES drawing restrictions, plus it prevents the NSF from messing with the display (some NSFs still access PPU regs when they probably shouldn't). My emulator calls a different drawing function if it's running an NSF, which blits the song name and stuff to the screen.
- Changing tracks, and start/stopping song playback is controlled through the UI of the emulator. I assign special keys for this like I assign keys for saving a state or taking a screenshot.