Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Gameboy Emulator  (Read 136 times)

0 Members and 1 Guest are viewing this topic.

lordseanington

  • Jr. Member
  • **
  • Posts: 76
  • Coffee is the blood of a coder.
    • View Profile
SFML Gameboy Emulator
« on: November 09, 2019, 09:17:37 am »
Hello there everyone!
Long time no see.

I have been working on a project for the last 4 months or so during my spare time, and I decided to show it off here a bit. It isn't anything overly complex as far as emulators go, and it's still got heaps of bugs and inaccuracies, but it can run a few games and looks/sounds okay.

I posted a video I took here:
https://youtu.be/alVzvLPZ3TU

There is still quite a bit to to for it before I am fully content with it, but as always I am never content with it.
A few TODOs:
Implement the 4th audio channel (the noise channel)
Implement some more cartridge types (right now it only does MBC1 and rom only carts)
Add support for gameboy color
and add a per channel waveform renderer (this is just for style, and because I love old video game music).

SFML is used for audio, video, and events (so basically everything).
Let me know what you think, like, ect.

fallahn

  • Sr. Member
  • ****
  • Posts: 367
  • Buns.
    • View Profile
    • Trederia
Re: SFML Gameboy Emulator
« Reply #1 on: November 10, 2019, 10:49:11 am »
Nice work!

How did you handle the audio with SFML? When I did mine I had real trouble keeping the audio in sync/at the right speed due to the sample rate effectively being that of the emulated CPU speed. I ended up resampling the output and sent it to the soundcard via SDL because it gave more direct access to the audio hardware. Would be nice to drop the dependency and use only sfml! :D

lordseanington

  • Jr. Member
  • **
  • Posts: 76
  • Coffee is the blood of a coder.
    • View Profile
Re: SFML Gameboy Emulator
« Reply #2 on: November 10, 2019, 07:16:43 pm »
I created custom sound streams that were essentially waveform generators that were controlled by the values in the hardware registers. The audio is completely disconnected from the CPU clock cycles other than the length counter, sweep, and envelope.
This ensures that the audio keeps at the propper frequency at all times. It is kinda a non purist way of doing it, because of how gameboy hardware works if the cpu slows down so does the audio, but I think it still worked nice.

fallahn

  • Sr. Member
  • ****
  • Posts: 367
  • Buns.
    • View Profile
    • Trederia
Re: SFML Gameboy Emulator
« Reply #3 on: November 10, 2019, 09:33:00 pm »
Ah! That's a much more practical approach. I'll definitely have to try that next time I work on something similar - I'm by no means a purist and would much rather get good results :D

lordseanington

  • Jr. Member
  • **
  • Posts: 76
  • Coffee is the blood of a coder.
    • View Profile
Re: SFML Gameboy Emulator
« Reply #4 on: November 11, 2019, 09:16:20 am »
Most of the waves that the gameboy outputs are really simple and can be calculated fairly quickly. So, it works nicely to generate them on the spot. The only issue i have noticed is that i need to provide at least a certain ammount of samples into the future, so there is a tiny lag in changing the audio registers and it actually being reflected.
However, it is excessively small and doesnt diminish audio quality. Im not sure exactly how many samples should be provided by my custom audio stream each time though...

 

anything