Sunday, June 14, 2009

Weekend exposure

I dint so much coding work, but I researched a bit on the inner workings of ScummVM and Monkey Island.

A TFMX-Song doesnt need to have an end, it can loop a section indefinitly or even just repeat the same sample all over. Yet Monkey Island has a coulple of scenes like the intro where the game waits a preset time to show up the MI-Logo and then waits for the song to stop before loading the next scene.

Yet the corresponding TFMX-Song (#4) has no ending, the only reason it does end is because I added some additional checks that did work nicely in the case of the intro. The same checks fail on another Song (#3) which runs endlessly. So its time to explore how this kind of timing works in the original Amiga-Version and how ScummVM expects it to work.

Timing on the Intro is twofold, I could not find any reference in the TFMX-Player that would signal the time the song "really starts" (after just some ambient sound, sorry cant express this better ;) ), even if that would be easy to archive it hasnt be done. Instead the original executable must have a own counter which runs independent of the music-playback, but Im not going to reverse the whole executeable to find out how this is done exactly. 
ScummVM does poll regulary for a "musictimer" and counting 1/25 seconds since songstart seems to just about work (guess the timer is a multiple of the 50 VBlank interrupts per second). Still would be good to hear from some ScummVM Devs if there are some custom hacks for MI Amiga already in place.

Ending of songs however is something thats controlled indirectly by the TFMX-Player. A TFMX-Song has special commands to talk back to the application - writing values to a shared block of Memory, perfect to notify if a specific pattern has be reached. And the songs in question (#3 and #4) both use them to signal the end of the Song. They do so by writing a 1 to a shared Memory Block at start and writing a 0 to the same position at the end. (and song #3 just loops and overrides the value with 1 again!?).
Since ScummVM aint providing a function which directly correspond to that I will have to figure out a way to make this work seemlessly, it already polls if a song is still running so I will try putting a check for this flag. Still that might not be enough as not all Songs set this flag to 1.

7 comments:

  1. Actually, all replayers I've tried DOES detect sound end for song #3 (starting with song #0, should be Elaine love theme, right?). Using Eagleplayer on emulated amiga, I see there are some reference to "positions", see this screenshot [1]: the song #3 (fourth song) is 3 "positions" long and the end is correctly detected (see "The song is over!" status). Megaplayer (see comments on the first post of this blog) also detects song end correctly. Megaplayer uses stolen engine routines.

    [1] http://web.cheapnet.it/imeriopretto/eagleplayer-mi-song3.png

    ReplyDelete
  2. "DO detect" :D
    oh, is there a way to change the language of this blog? Actually is all in german, I'd be much more confortable with english.

    ReplyDelete
  3. czetko: Yeah those 3 positions are the tracksteps, but they are supposed to loop (theres no way to disable that in the original Player). If I disable looping alltogether then that would obviously break songs that are suposed to be endless.
    I dont have time playing through the game, but maybe the scene with elaine even expects the Song to loop (ie doesnt depend on the song-end).

    Also several players "patch" the songs or have special handling, Id try mimicing the original player first ;)

    ReplyDelete
  4. Well, found a bug which cause Song 3 to loop.

    ReplyDelete
  5. Lol, first bug report without actually testing the product itself. Tell me when you prefer to receive extensive bug reporting about quality of playback: I will take recordings of tunes in Winuae to use as reference in the mean time.

    ReplyDelete
  6. If you do record from WinUAE, you should disable Interpolation and the Filter. Should provide a better point of reference as that would be similar to how ScummVM does it.

    ReplyDelete
  7. I already do that way :) This is a recent bug report of mine about stereo separation in winuae: http://eab.abime.net/showthread.php?t=44762

    ReplyDelete