How does Sonic2 sync music update on z80?

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Post Reply
sbroumley
Interested
Posts: 29
Joined: Wed Feb 11, 2009 11:23 pm

How does Sonic2 sync music update on z80?

Post by sbroumley » Fri Mar 20, 2009 2:04 pm

I'm having a hard time tracking down a problem in my genesis emulator which is making music playback in Sonic2 be a bit slow and it also sporadically slows down and speeds up.

At first I thought it was bad implementation of ym2612 timers, but setting breakpoints, Sonic2 never enables them or tests the timer overflow bits. Can anyone confrim this for Sonic2?

Adding diagnostics it looks like z80 vbl interrupt is disabled during ym2612 DAC playback (z80 sits in a tight loop feeding the DAC data register). Listening carefully, it almost sounds like when DAC drum sounds are played, the music time syncing is paused during that time.

So I'm curious does anyone know what the z80 music driver is using to keep music tempo constant? Is there some timer register in z80 that's being read that I haven't implemented perhaps?

One thing I haven't implemented yet which could be part of the problem is that I'm not emulating freezing the 68k during VDP dmas. Does anyone know the side effects of this?

cheers,
Steve.

mickagame
Very interested
Posts: 256
Joined: Sat Jun 07, 2008 7:37 am

Post by mickagame » Fri Mar 20, 2009 2:10 pm

Do you see the blue bar wich split the screen into 2 parts in sonic 2 vs mode?

sbroumley
Interested
Posts: 29
Joined: Wed Feb 11, 2009 11:23 pm

Post by sbroumley » Fri Mar 20, 2009 2:44 pm

I haven't implemented interlace mode on VDP yet.

The music tempo problems are on the title screen and single player levels. (the "Sega" DAC sample on the sega screen plays at the correct pitch BTW).

AamirM
Very interested
Posts: 472
Joined: Mon Feb 18, 2008 8:23 am
Contact:

Post by AamirM » Fri Mar 20, 2009 2:52 pm

Does it also happen in Sonic 3 and Sonic 3D?

EDIT:
Also how are you running the Z80?

EDIT2:
Ah...I remember slightly now. Z80 interrupts lasts a certain length which needs to be emulated correctly. Now I can't remember how long was that.

EDIT3:
Okay....remembering some more :) . The interrupt length is a frame and a scanline.

sbroumley
Interested
Posts: 29
Joined: Wed Feb 11, 2009 11:23 pm

Post by sbroumley » Fri Mar 20, 2009 3:42 pm

unfortunately those games don't currently work in my emu.

my main emulator loop is basically like this:

for each scan line (262 in total)
{
set vdp vbl,hbl info depending upon line
exec 68k x cycles
exec z80 y cycles
update ym2612 DAC and timers
}
render

sbroumley
Interested
Posts: 29
Joined: Wed Feb 11, 2009 11:23 pm

Post by sbroumley » Fri Mar 20, 2009 9:04 pm

Thanks for the reply AamirM.

Can you explain exactly what you mean the z80 vbl lasts a frame and 1 scan line? Doesn't the z80 just return from the vbl interrupt when it hits an RETI instruction - how can you make it last a frame and 1 scan line?

thanks
Steve.

Eke
Very interested
Posts: 885
Joined: Wed Feb 28, 2007 2:57 pm
Contact:

Post by Eke » Fri Mar 20, 2009 11:02 pm

it's not really one frame and a line:

it means z80 interrupt occurs once per frame (on line 224) and remains active during one full line if not acknowledged by Z80

once the exception is processed on z80 side, interrupt is cleared until next frame

if Z80 interrupt is masked, interrupt remains pending for one line and should be processed if unmasked during this period

sbroumley
Interested
Posts: 29
Joined: Wed Feb 11, 2009 11:23 pm

Post by sbroumley » Sun Mar 22, 2009 6:06 am

thanks for the clarification.

It turns out the problem was indeed interrupt related. Z80 was missing vbl interrupt due to some broken interrupt logic code.

thanks for you help guys
-Steve

Post Reply