I've been fighting a small problem for the last two days, and I finally just figured it out. It's such a relief to finally have it make sense that I decided to write it up before I even coded the fix, which it was still fresh. It was a small issue, but in a very large project, which made debugging difficult.
Back in the beginning of this whole pandemic I published version 2 of my VGM compression toolset, this one much more flexible and able to import many more formats. Last month someone finally used it. Yes, retro development is sure rewarding! Anyway...
This guy ported all the tunes from the NES version of Smurfs over to the TI, and released individual programs with my Quickplayer, which wraps a tune with a standalone player and lets you add some text. It was sweet, but awkward... and since he asked if anyone could make a cartridge, I wrote a tool that would take a folder full of program images, and build a loader cart with a menu.
This was a good start, but I decided that I also wanted to take all the visualizers I've done over the years (four of them), and make them available in the Quickplayer too. I adapted all of them to fit in the 8k low memory block on the TI, and ported them to Coleco as well. Then I coded a couple of flags that could be externally set that could be used to find a selection program for chaining (with random play as my intent.) It took some fiddling, but that all came together eventually.
So before diving into the issues that the random player gave me, let's recap...
First, we have the music player libraries themselves.
They are wrapped around a song in a standalone player program -- there are FIVE player programs (four with visualizers, and one just text like I originally released). Plus the program that does the actual wrapping and generates the final code.
Then we have a tool that packages these programs up, and auto-generates a loader program for them (so, the tool, and the loader program).
And we have a menu that selects which loader will be executed. So we're up to 9 programs, and then I wrote the randomizer.
I expected this part to be easy, because I had carefully compartmentalized everything. To explain a bit, the TI file system loads program files in individual 8kb chunks. In addition, the TI's memory map splits the RAM - an 8k block at 0x2000 is where I store the player, and a 24k block at 0xA000 gets the music data. So, the player was always in a separate copy block to the data.
The autogenerated code thus always looks a lot like this:
> 60B6 0200 li R0,>6004 Ball
60BA 0201 li R1,>6000
60BE 0202 li R2,>2000
60C2 0203 li R3,>0cb4
60C6 06A0 bl @>619c (Copy data)
60CA 0200 li R0,>6006 Data
60CE 0201 li R1,>6000
60D2 0202 li R2,>a000
60D6 0203 li R3,>058a
60DA 06A0 bl @>619c
60DE 06A0 bl @>600c Trampoline to start
60E2 2000 data >2000 Start address