Stack here, stack there, every where a stack, stack…

I’m cleaning up the CD track play code, for NES2PCE CD games that use the CD play command. Though, this would also come in handy for hucards with hacked CD play commands as well.

Originally, I called the CD play command when the game code called the ‘play psg track’ subroutine call. But I’ve been thinking; this will throw the game code out of sync of the vblank interrupt. Megaman doesn’t seem to care, but it could result in a rare occasion that if they get out of sync of each other – glitches can happen (from simple graphic stuff, to anything else – really). And not just Megaman, but Castlevania and Dragon Warrior (yes, both are getting the CD play treatment).

So, I came up with a method to set a CD play request via an internal flag. On the first encountered vblank, which is handled as a higher level backend emulation code (which calls NES nmi code after doing some internal stuffs), looks for this flag. So the actual CD play request happens inside the start of the vblank interrupt routine.

I reserve the original ram bank $F8 for sys card stuffs, since it’s already initialized by the system card, and I swap this back in. As well as the hardware bank (where it needs to be for sys card stuff: $0000 instead of $6000) and the sys card interrupt vector bank ($00). From that point, I can simply call BIOS routines as if I’m directly working with a normal CD project.

The tricky part; hardware stack management. Thank god for TSX, else I’d have to write some hairy stack pointer position identification code – no good. But, I do have to manage two hardware stacks. Since a different bank of ram is now mapped into the stack area, I need to update the stack pointer with that corresponding pointer. Things get a little hairy – hee hee hee heeeee. But it’s just crazy enough to work 😉

Anyway. I have to disable the TIMER IRQ such type of management as well, since sys card setup has a different interrupt vector setup. I mean, this whole thing happens *inside* a vblank interrupt (of a different ram bank and hardware stack pointer), but needs to run though it’s ~not~. Plus, I made a ‘CD busy’ system screen for when it requests a track play – so the screen doesn’t look like crap on long(er) pauses (real system). And to animate this ‘icon’, I need vblank interrupts on the sys card side 😛

;>_> Yeah…….

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: