It is currently Fri Dec 15, 2017 12:47 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Jul 07, 2015 6:35 pm 
Offline

Joined: Wed Jun 10, 2015 8:20 pm
Posts: 4
I'm trying to work out how to sync between my nascent Game Boy emulator's CPU/video/audio processors, and there's a sticky edge case: when a write to 0xff40 disables the LCD display.

Before implementing audio, I ran everything on a per-frame basis. When I hit the end of vblank, I would yield control to the renderer, wait until the next frame, and pick up. If display was disabled, I'd keep running until it was re-enabled and the following rendering frame completed. As a result frames would have a variable number of CPU cycles (which I think did cause some subtle timing bugs) but mostly it worked fine.

Now that I've added audio processing, I'm generating 735 audio samples (44100 / 60) per one frame's worth of CPU cycles (usually 456 * 154 = 70224 cycles.) This works until LCD is disabled and enabled again later, which results in too many audio samples being pushed to the audio buffer that frame, and the audio playback gets progressively more backed up. I've tried cutting the audio sample generation off after exactly 735 samples each frame, but this doesn't seem correct either and results in audible gaps in playback.

Any advice on how to resolve this, and how many cycles to run each processor per frame?


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 6:40 pm 
Online

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 19348
Location: NE Indiana, USA (NTSC)
If LCD is disabled, generate an all-white frame (Game Boy) or repeat the previous frame (Super Game Boy).

Licensed games aren't allowed to turn rendering on and off mid-frame because the output drivers don't get clocked to the next scanline. This results in visible artifacts and, over the long term, possible burn-in.


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 7:04 pm 
Offline

Joined: Wed Jun 10, 2015 8:20 pm
Posts: 4
Thanks for the tip. Can I rely on having it disabled for exact multiples of a frame or can the disabled period be an arbitrary number of cycles? If it's disabled for say 50 scanlines worth of CPU cycles and then re-enabled, and I treat the disabled period as a separate frame, I'll have an audio buffer underflow.


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 7:21 pm 
Offline

Joined: Sun Jan 26, 2014 9:31 am
Posts: 267
The disabled period can be arbitrary. As far as I know, the LCD's internal clock gets reset to 0 (e.g. when it's re-enabled, your next VBlank is in 70224 cycles), but there's no restriction on when it can be re-enabled. It can be 20 cycles, or 20 minutes. It's up the the game, so don't bet on any consistency.


Top
 Profile  
 
PostPosted: Sun Sep 03, 2017 7:46 am 
Offline

Joined: Tue May 17, 2016 10:15 pm
Posts: 66
In that case it LY also reset, cause otherwise it would go out of sync with that clock right?

And also, when it's disabled, is the clock stopped, or does it run and it just resets when re-enabled?


Top
 Profile  
 
PostPosted: Sun Sep 03, 2017 1:10 pm 
Offline

Joined: Sun Jan 26, 2014 9:31 am
Posts: 267
zerowalker wrote:
In that case it LY also reset, cause otherwise it would go out of sync with that clock right?


Already mentioned it here but yes, LY gets reset to 0 when the LCD is disabled. Otherwise weird things would happen.

zerowalker wrote:
And also, when it's disabled, is the clock stopped, or does it run and it just resets when re-enabled?


The LCD's internal timing is frozen. That means nothing related to the LCD clocks. LY isn't incremented. No STAT or VBlank interrupts. We tried testing this a while ago just to be sure.


Top
 Profile  
 
PostPosted: Sun Sep 03, 2017 11:40 pm 
Offline

Joined: Tue May 17, 2016 10:15 pm
Posts: 66
My bad missed that part about LY being reset directly on Disabled.

Will check the tests about the timing, thanks:)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group