bobbimanners / Applecorn

Allows Acorn BBC Microcomputer language ROMs to run on Apple //e enhanced, //c and IIGS.
GNU General Public License v3.0
47 stars 8 forks source link

Song 'ColdTea' plays on MAME, fails on real GS #190

Closed bobbimanners closed 1 year ago

bobbimanners commented 1 year ago

The BASIC program 'ColdTea' which is currently on the applecorn.po distribution media plays nicely on Applecorn under MAME (GS ROM03) but stops unexpectedly on my GS (ROM01).

bobbimanners commented 1 year ago

Fails in Crossrunner the same way it does on real hardware, so I probably need to install Crossrunner to debug this.

bobbimanners commented 1 year ago

The file 'LANDMUS' is the same song and fails at the same place, but the code is cleaner and doesn't have the visualization and other bling.

bobbimanners commented 1 year ago

'LANDMUS' runs on real hardware if I delete line 790, which seems to be redundant anyhow.

bobbimanners commented 1 year ago

@jgharston Any ideas? This one is a bit of a head scratcher.

bobbimanners commented 1 year ago

Actually I spoke too soon. It is wildly inconsistent whether it runs all the way to the end when running on a real GS (and also seems to fail the same way in Crossrunner, so I am told.)

jgharston commented 1 year ago

Hmm. Well LandDemo sets up some interupt-driven machine code, but LandMus on its own just plays music and should work on its own.

bobbimanners commented 1 year ago

Yes, LandMus is nice and straightforward in its coding, as you say. I will probably install Crossrunner (GS emulator for Windows) to try to investigate this. It is intriguing that it works on MAME flawlessly, but chokes non-deterministically on real hardware (and Crossrunner, so I am told.)

bobbimanners commented 1 year ago

@jgharston Incidentally, I have been enjoying your arrangement of 'All Creatures Great and Small'. Has been a few years since I heard that!

bobbimanners commented 1 year ago

'ARENAII' also plays nicely in MAME but chokes on real hardware.

bobbimanners commented 1 year ago

I recalibrated the Ensoniq note frequency using a tuner app on my iPhone. This also calibrates the duration accurately, since it is based on a 100Hz note from the Ensoniq. After the recalibration, I was able to play 'ARENAII' on the real GS. However 'Cold Tea' is still freezing up nondeterministically. It does seem that some of this code may be sensitive to the timing of the sound engine being roughly correct.

bobbimanners commented 1 year ago

'LANDMUS' is also choking on MAME, so I took advantage and stepped through it in the debugger. The reason it is stalled is there is a note enqueued with sequence number 1 (meaning a two note chord) but the other three audio channels have empty queues. I don't yet know why or how we ended up in this state. At least we know it is to do with sequence number / chord handling somehow.

So I replaced line 810 of 'LANDMUS' (the SOUND statement) with a PRINT statement. Interestingly, 'LANDMUS' does NOT use the chord synchronization function at all - it simply dispatches notes of duration 1 in round-robin to channels 1, 2, 3 repeatedly.

This strongly implies that the audio queue is getting corrupted somehow.

Also, consider that when I recalibrated the Ensoniq, which had the effect of changing the frequency at which the ISR is invoked, it changed the stability of the audio engine so that some songs that previously did not play, now do so. This strongly implies that it is an interaction of the mainline code and the ISR that has some window where the queue can get corrupted.

Will look at the code very carefully (again) tomorrow. (I thought that having interrupts disabled while I enqueue bytes in the audio queue should have done the trick.)

jgharston commented 1 year ago

The JGH Music 1 programs are demo'd here, so this is what they should shound like: https://youtu.be/8kRCjG3Z0j8?t=175

-- J.G.Harston - @.*** - mdfs.net/jgh

bobbimanners commented 1 year ago

Sounds mostly the same on the GS ... except that I have four tonal channels at the moment and no noise channel.

bobbimanners commented 1 year ago

'LANDMUS' problem is fixed!! I was using macros ENTMAIN and ENTAUX when transitioning from aux->main->aux for calls to INSHND and CNPHND. Those calls re-enable interrupts!! Replaced them with IENTMAIN and IENTAUX, which do not re-enable interrupts, and now 'LANDMUS' plays without issue.

Will do some more testing before closing this.

bobbimanners commented 1 year ago

Breaks 'ARENAII' (again). Haven't looked into how/why.

bobbimanners commented 1 year ago

I also had to briefly enable interrupts in WORD07 when waiting for space in the queue, otherwise the ISR never runs and the queue will never drain. Now 'ARENAII' runs again.

bobbimanners commented 1 year ago

Going to call this fixed. With the current build most stuff on the JGHMusic1 disk work and nothing seems to be choking part-way anymore.