Fix for MPEG music issues (DSB2)

Technical discussion for those interested in Supermodel development and Model 3 reverse engineering. Prospective contributors welcome.
Forum rules
Keep it classy!

  • No ROM requests or links.
  • Do not ask to be a play tester.
  • Do not ask about release dates.
  • No drama!

Fix for MPEG music issues (DSB2)

Postby gm_matthew » Tue Jan 26, 2021 8:33 am

So one of the most noticeable problems with Supermodel at the moment is the MPEG music; specifically music tracks don't fade out and there is a significant delay when playing a new track. These issues are specific to DSB2 (Scud Race uses DSB1 and is unaffected).

However, it turns out there's a really simple fix for both issues: call an IRQ2 17 times per frame instead of just once! This approximates an IRQ2 frequency of 1000 Hz (17 x 60 = 1020; close enough).

Change this (DSB.cpp, line 1021):
Code: Select all
   // Per-frame interrupt
   M68KSetIRQ(2);
   M68KRun(4000000/60);

to this:
Code: Select all
   // 1000 Hz timer(?) interrupt
   for (int i = 0; i < 17; i++)
   {
      M68KSetIRQ(2);
      M68KRun(4000);
   }

I've tested on Daytona USA 2 and Sega Rally 2 and they work great; I'm not sure about other games.

I figured this out by noticing that tracks do eventually fade out; it just takes much longer than it's supposed to. I had starting digging into Daytona 2's MPEG program code before I got a flash of inspiration and tried increasing the IRQ2 frequency with immediate results. After a bit of testing I found that using 1000 Hz fades out music at the same speed as real hardware (I used this video as a reference). I'm guessing that IRQ2 is a timer interrupt and it helps the 68000 on the DSB2 keep track of how many milliseconds have elapsed.
gm_matthew
 
Posts: 224
Joined: Fri Oct 07, 2011 7:29 am
Location: Bristol, UK

Re: Fix for MPEG music issues (DSB2)

Postby Spindizzi » Wed Jan 27, 2021 3:18 am

Very interresting find :)

note : there is a similarity with the netboard
Spindizzi
 
Posts: 196
Joined: Thu Nov 17, 2016 8:55 am
Location: France

Re: Fix for MPEG music issues (DSB2)

Postby Bart » Wed Jan 27, 2021 2:05 pm

This is a great discovery! There is probably a timing register that is written and the frequency is probably variable. It is certainly possible that more or less the same driver code was used for all the sound board programs resulting in the same frequency being written. I have a DSB2 board here. I should look at the ICs to see if there is a known standard timer chip. But it is probably part of the Sega custom IC. This would make reverse engineering it tough. If I could find time to build a system to transfer code onto my Step 2.x board, the net board would be easier to analyze because the 68K program is loaded into RAM and can easily be modified from the PowerPC side.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Fix for MPEG music issues (DSB2)

Postby gm_matthew » Mon Feb 01, 2021 5:46 pm

Well it turns out that MPEG music fades out too slowly in Scud Race too! For example, after the player finishes entering their name on the high score screen it takes Supermodel slightly over 3 seconds for the music to fade out, while in this video we can hear that the real Model 3 fades the music out in less than a second.

This time the culprit was in this bit of code in the DSB1 RunFrame function:

Code: Select all
   // While FIFO not empty, fire interrupts, run for up to one frame
   for (cycles = (4000000/60)/4; (cycles > 0) && (fifoIdxR != fifoIdxW);  )
   {
      Z80.SetINT(true);   // fire an IRQ to indicate pending command
      //printf("Z80 INT fired\n");
      cycles -= Z80.Run(500);
   }   
      
   // Run remaining cycles
   Z80.Run(cycles);

Since the Z80 on the real DSB1 runs at 4 MHz and this code runs 60 times a second, it makes sense that we divide 4 million by 60 to determine how many cycles to run. But for some unknown reason we divide that number again by 4 which has the effect of reducing the clock speed to only 1 MHz, hence why music fades out at only 0.25x speed compared to real hardware.
gm_matthew
 
Posts: 224
Joined: Fri Oct 07, 2011 7:29 am
Location: Bristol, UK

Re: Fix for MPEG music issues (DSB2)

Postby Bart » Mon Feb 01, 2021 10:28 pm

That logic was originally written by R. Belmont. Maybe he thought there was some sort of bus multiplier involved. If we remove the division by 4, we quadruple the number of cycles that the Z80 needs to run for. I think the performance impact ought to be negligible though. Another possibility is that the IRQ fires more than once per frame.
User avatar
Bart
Site Admin
 
Posts: 3086
Joined: Thu Sep 01, 2011 2:13 pm
Location: Reno, Nevada

Re: Fix for MPEG music issues (DSB2)

Postby gm_matthew » Tue Feb 02, 2021 9:58 am

Another possibility is that the IRQ fires more than once per frame.

But the DSB1 only fires an IRQ if there are one or more commands in the FIFO buffer. On the high score screen for example, no IRQs are fired while the music is fading out. What I have noticed is that the Z80 sets the volume 52-53 times (running at 4 MHz) every single frame, even when no active adjustments are being made. It seems that unlike the 68000 on the DSB2, the Z80 on the DSB1 keeps track of its own timing.

Removing the division by 4 should have negligible impact on performance. I tried with a clock speed of 400 MHz and Supermodel runs with only a small amount of slowdown, so 4 MHz should be easy for any modern PC.
gm_matthew
 
Posts: 224
Joined: Fri Oct 07, 2011 7:29 am
Location: Bristol, UK


Return to The Dark Room

Who is online

Users browsing this forum: No registered users and 1 guest