FLTK logo

Re: FLTK in an emulator: Concerns

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.general  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: FLTK in an emulator: Concerns matthiasm Oct 16, 2007  
 
On Oct 15, 2007, at 11:47 AM, MacArthur, Ian (SELEX) (UK) wrote:

>
>> The NES actually runs at a somewhat
>> awkward 60.1 Hz... and produces a fixed amount of audio
>> samples each frame.
>
> 60.1? Really? That is weird...

The best way to write an emulator with sound support is to use the  
sound as a timebase for everything. The oscillator on the sound board  
mayeven be much more stable than whatever generates timer interrupts  
on your OS.

I recommend that you write your main loop in standard FLTK using  
Fl::run(). Then write an emulator running in a second thread for all  
functions that fills an RGB buffer with video data and an audio  
buffer whit sound data.

Whenever you reach the end of your 60 Hz emulation cycle, call  
something like this:

for(;;) {
emulate();
waitForInt();
Fl::lock()
myNESScreen->redraw();
Fl::unlock();
Fl::awake();
sendSoundAndInt();
}

Now the main FLTK lopp wll kick in and bring your RGB buffer onto the  
screen.

sendSoundAndInt() is your function that sends just enough samples to  
fill the 60th of a second and when done creates an interrupt to let  
you know that the sound buffer is empty (and a 60th of a second is  
over). Of course you will need to double-buffer the sound.

That way, your GUI runs in the main thread without ever interfering  
with your emulator, and all your emulator has to do is fill the RGB  
buffer, not having to care about the deatails of the true screen  
buffer etc.



----
http://robowerk.com/
Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.