Jump to content



Photo

PinMAME Sound Command Mode with WPC games

PinMAME Emulator Bug

  • Please log in to reply
11 replies to this topic

#1 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 28 February 2015 - 11:23 PM

Hey there.  I'm the user formerly known as Dorsola, and I just recently got back into playing around with Visual Pinball and VPinMAME.  Today, I was trying to play around with the Sound Command Mode feature in VPinMAME and ran into the same problems I hit way back in 2001 when trying to populate sounds.dat with voice clips from games like Doctor Who and Fun House: The Sound Command mode can't access the voice bank in some WPC games.

 

I don't know if the folks who wrote PinMAME are still around and active, but the SourceForge site says that the best way to get in touch with them is via this forum, so here goes. :)

 

In WPC games like Dr. Who, the sound hardware receives single-byte commands to play music.  For example:

dw_l2:
:00:Reset sound hardware
:01:MUSIC: Title Theme
:02:MUSIC: Intro/Plunger
:03:MUSIC: Plunger
:04:MUSIC: Intro end

...etc.

 

However, to access voice banks, it requires a two-byte command in the form 7aXX - 7a directs the hardware to play a sound at the next byte from an alternate bank.  Presumably there are other bank directives as well.  For example, from Twilight Zone:

tz_94h:
:7a13:"Hi! I'm Talking Tina!"
:7a22:"Feel lucky?"
:7a44:"Note the hitchhiker..."

I can watch commands like this being played in the "Last Commands" output in Sound Command Mode if I switch to it immediately after a voice clip has started, but I can't play those same commands for Dr. Who in the Command Mode itself.  Based on my research, "7a49" should play Davros's clip, "Time Expander restored to Factor 15."  But if I type in that command or load it into sounds.dat and play it from there, I instead get a messed-up version of the "Video Mode" music.

 

I did discover, however, that I can play the Davros clip exactly once if I start VPinMAME and go into the Sound Command mode immediately, while the sound hardware is still initializing.  If I execute the two-byte command before the "Ding!" sound that signals the sound board is ready, the Davros clip plays immediately after that ding.  Repeating the command results in the Video Mode music again.

 

This gives me a clue as to what's wrong: I think the sound hardware is expecting the second byte of the command to be delivered much faster than it actually is - in fact, there's evidence that the ROM sends pretty complex command sequences "all at once".  But if I chain together multiple "play music/sfx" commands in Sound Commander, I can hear each one being played in rapid succession, slowly enough that I can make out each individual piece.  I think that's too slow for what the hardware is expecting.

 

So, I poked around in the source code and came across this: https://github.com/q.../snd_cmd.c#L387 .

  /* currently sending a command ? */
  if (locals.cmdIdx > 0) {
    locals.cmdIdx += 1;
    if ((locals.cmdIdx % 4) == 2) { /* only send cmd every 4th frame */
      if      (locals.nextCmd[locals.cmdIdx/4] == -1)
        locals.cmdIdx = 0;
      else if (locals.boards == 3) { // if we have 2 sound boards we need to send board no as well
        sndbrd_manCmd(locals.nextCmd[locals.cmdIdx/4], locals.nextCmd[locals.cmdIdx/4+1]); locals.cmdIdx += 4;
      }
      else
        sndbrd_manCmd(locals.boards - 1, locals.nextCmd[locals.cmdIdx/4]);
    }
  }

I believe the sound commander is sending only one byte at a time to the sound hardware every fourth frame (assuming VPinMAME runs at 60 FPS, that means once every 15th of a second), so the 7a "read alternate bank" command isn't properly followed up with the location in that bank, and the hardware either ignores that command or ends up doing something else with it.  When the second byte is sent a moment later, it's treated as a separate command, which of course can lead to unexpected results.

 

This doesn't have any direct impact on normal emulation, but it has meant, for 14 years now, that anyone using the Sound Command Mode to explore WPC ROMs (Pre-DCS) has been unable to browse through the voice sample banks in some games.  I don't know why it works in both Creature From the Black Lagoon and Twilight Zone, since those run on the same (or similar) pre-DCS hardware - perhaps their sound boards are willing to wait longer for the alt-bank commands?

 

I'm not currently equipped to try to fix this - I've forgotten most of what I know about programming in C, and I don't have the compiler tools handy.  If someone more experienced is interested in taking a crack at it, I'd be curious to see if we can squash this silly little bug. :)



#2 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 02 March 2015 - 06:43 AM

I managed to find an old copy of Visual Studio 2008 sitting around and installed it, along with the current DirectX SDK, and am getting much closer to having this thing compile properly.  However, now I'm running into the problem of not being able to find "d3d.h" - the header file for Direct3D 7.  Seems Microsoft no longer supports that file, and trying to substitute it with a different version (eg. d3d9.h) doesn't work either.

 

How are you guys compiling this code these days?  For reference, I pulled from the "PinMame Master" at https://github.com/qno/PinMAME


Edited by KieferSkunk, 02 March 2015 - 06:43 AM.


#3 bosvrucht

bosvrucht

    Enthusiast

  • Members
  • PipPipPip
  • 410 posts

  • Flag: Netherlands

  • Favorite Pinball: LOTR

Posted 02 March 2015 - 08:23 AM

Toxie said on the "other" forum that you will need a copy of the DX7 SDK, or you can try this guys solution:

 

http://pinballprojec...h-visual-c.html



#4 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 02 March 2015 - 09:05 AM

Thanks for the link. I tried some things similar to what he listed there, but didn't have much success. However, I did find someone with a minimal dx7 zip for a different project, so I'll give that a try tomorrow.

#5 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 02 March 2015 - 05:01 PM

Okay, good news: I was able to compile with a minimal DX7 library from the Allegro project.  That's all I needed.  Now to see if I can figure out what's wrong with the silly thing.



#6 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 05 March 2015 - 05:40 AM

Well, I've been hacking away at this thing for a few days, and while I think I have the sound commander working better overall (providing more useful data, sending complete commands all at once, etc.), I'm still seeing the exact same behavior: Sound commands starting with "7a" work fine when generated in the game itself, but not from the sound commander, only for SOME games:

 

Twilight Zone: "7a20" = The Power laughing (plays correctly)

CFTBL: "7a49" = "Well, maybe..." (plays correctly)

 

FunHouse: "7a2b" SHOULD BE "I thought we were pals!", but instead is one of the system test sounds.

Dr. Who: "7a49" SHOULD BE "Time Expander restored to Factor 15", but instead plays the Video Mode music.

 

I scanned through the source code for all four of these sims and added some diagnostics to the sound handler code, and I could not find *anything* substantially different between any of them - as far as the hardware emulation is concerned, these machines are basically identical and only the ROMs are different.  But clearly, the sound commander is talking to the emulated hardware differently than the ROM is.

 

Only thing I can think at this point is that when you go into sound-command mode, the overall emulation is paused - in some cases, the sound hardware may behave differently if some other clock isn't running (eg. callbacks don't happen).

 

Strange.



#7 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 05 March 2015 - 07:11 AM

And as for that last theory (that pausing the CPUs and such causes the behavior to change), no dice.  I tried commenting that part out.  No difference, and of course that makes using the sound commander harder since the rest of the emulator responds to some of the same keyboard commands (eg. typing '5' also inserts a coin and causes the game to play the corresponding sound).

 

So, I'm baffled.  I saw a comment in part of the code that someone else already figured out "manual commands" aren't getting piped through, but they didn't know why.  So I'm certainly not the first one to try to tackle this.

 

And in the grand scheme of things, it's really not all that important.  C'est la vie!



#8 toxie

toxie

    VPF Veteran

  • VP Dev Team
  • PipPipPipPipPipPip
  • 5,660 posts
  • Location:berlin, germany

  • Flag: Germany

  • Favorite Pinball: AFM

Posted 05 March 2015 - 09:18 PM

If you have some patches after your experiments, please send them to me via PM, so that these don't get lost and i can incorporate the fixes into the trunk.



#9 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 05 March 2015 - 10:39 PM

Sure, I'd love to.  Thanks.

 

Since my experiments haven't changed anything behavior-wise, the only changes of any substance I've made are to the sound-commander itself:

- Clean the code up a little

- Remove the "only send once every 4 frames" restriction

- Send all of the bytes of the sound command in a single call to playCmd, rather than sending one byte at a time.

- Remove the "don't log manual commands" restriction

 

Which, of those changes, are you interested in?



#10 toxie

toxie

    VPF Veteran

  • VP Dev Team
  • PipPipPipPipPipPip
  • 5,660 posts
  • Location:berlin, germany

  • Flag: Germany

  • Favorite Pinball: AFM

Posted 06 March 2015 - 07:23 AM

Honestly, i don't really have a clue about the sound commander, so if you think these are all useful and stable changes (seems like you tested all cases?), then just give me everything.  ;)



#11 KieferSkunk

KieferSkunk

    Enthusiast

  • VIP
  • 96 posts
  • Location:Seattle, WA area

  • Flag: United States of America

  • Favorite Pinball: Twilight Zone

Posted 06 March 2015 - 07:28 AM

Give me some time to validate that, and I'll get back to you. :)



#12 toxie

toxie

    VPF Veteran

  • VP Dev Team
  • PipPipPipPipPipPip
  • 5,660 posts
  • Location:berlin, germany

  • Flag: Germany

  • Favorite Pinball: AFM

Posted 06 March 2015 - 07:34 AM

Please give me a shout via PM, so that i don't miss this then.







Also tagged with one or more of these keywords: PinMAME, Emulator, Bug