What's new

Game Boy

Sagon

New member
Wow great job ShizZie! I still have no GBC support at all. Hope soon i'll have some time to implement it.
How about sound in your emu? I haven't ever worked with sound, so i do't know ever where to start.
 

ShizZy

Emulator Developer
Thank you! Sound scares me... a lot. I found this http://www.slack.net/~ant/libs/#Gb_Snd_Emu if anyone is interested. It's a portable sound system for GB emulators. Looked interested, but when I tried fooling around with it I was getting some weird build issues. But all the code is there. Then again, using that would be cheating... sound is gonna be tough :p
 

ShizZy

Emulator Developer
Hehe.. better slow down before I hurt myself :bouncy:

Good GBC compat requires really good GB compat... which I don't really have. Things are VERY buggy, even zelda I still have all the same tile glitching problems as I do in the GB version (I show just the clean shots :D). But go for it Sagon, I'm sure you'll have better luck with your emulator. I avoided the dirty work, and now I got to go back and do it. :p

Question for everyone: Where do you guys disable the Stop command? I had to disable stop in GBC mode because right at startup most games switch to double speed mode (and to do that they use the stop command) but then the emulator freezes because it isn't getting turned back on. The only place I disable stop is when an interrupt is executed. Enabling interrupts/turning off stop in KEY1 didn't fix it.
 
Last edited:

bcrew1375

New member
You should continue from stop after a key is pressed. It shouldn't matter whether an interrupt is called. At anytime stop is enabled, if any of the bits 0-3 in P1 get turned off, you should disable stop.
 
Last edited:

ShizZy

Emulator Developer
If the cpu is stopped, how does it check if a key is pressed to turn it back on?

I've been kind of poking through my code tonight, rewriting tidbits here and there. I don't remember specifically spotting any bugs, but some glitches are getting fixed in some games. So at least I'm making progress.

Edit: Still can't fix my falling through the floor problems in Super Mario Land and Metroid 2. Which is interesting because Mario Deluxe is fully playable :p
 
Last edited:

bcrew1375

New member
The same way interrupts are executed to terminate halt :p. If you're counting cycles when the CPU is off, you can update the I/O registers without executing instructions. The program doesn't check for the keypress, your emulator does. If bits 0-3 of P1 are lower than 0x0F, terminate stop.
 
Last edited:

Sagon

New member
After a night of struggling with implentation of GBC support, i finally maked some progress. Here some shots.
 

ShizZy

Emulator Developer
Wow awesome job Sagon! I'm still debugging. Fixed a lot of issues with my gbc vram bank switching. With vertical mirroring, multiple banks and what not, my gbc sprite tile data retrieval is a very swisted mess :p

@bcrew.. thank you, I'll fix how I have mine set up.
 

ShizZy

Emulator Developer
After help from Blargg and getting his fixed version of his PAPU emulator, I managed to get sound working in my emulator with SDL. I wrapped it up nicelly with some basic audio calls for reading/writing audio io, and a frame counter. If anyone is interested in these files I'll post them, it's pretty much plug and play. I feel kind of cheating-ish for using it, but I have every intention to code my own sound when I get a better emulator. And hell, that's what he made it for.

Here's the latest version.

+GB/GBC Emulation
+MBC1, MBC2, and MBC5 Cartridge Support
+Sprites
+BG Tile maps
+Window Display
+Sound Emulation
+All CPU Opcodes
+Timings and IO Registers
+JoyPad
+Saving/Loading (Partial for MBC5)
+"Casual" Debugger, Logging, and Options

+DirectX7 For Video
+SDL and Blargg's GB PAPU Library for Sound
http://shizzy.emulation64.com/

Please let me know what you think! It's still pretty buggy, but getting there. Some good GBC games to try are the Bomberman Max games, Zelda DX, and Mario Deluxe.

Regards
 

Sagon

New member
Great job, ShizZie! Sound is working good. I've tried many games and you right you have problems with retrieving gbc data from right banks, i had the same problem with my emulator.
And yeah, i'm interested how did you implement sound with SDL and Blargg's library, so please post your files.
 

ShizZy

Emulator Developer
Thanks for trying it out :) Any tips on vram bank switching? My code is really plain, I simply have 2 external banks and I switch them in and out into memory whenever VBK is written too. Then in my drawing code, I retrieve the data from whatever bank. (and if the bank is the current one in memory, I just read straight from mem).

As for the sound, here is all the included files. Set up is REALLY simple. Add all the files to your project. Boost is a library of common functions used, if you already have it setup in your compiler you don't need it, otherwise you can add the files that are there. Include Audio.h, which is the main wrapper which is very basic. Declare a AUDIO aud; somewhere. Then when the program initializes, call aud.Initialize(). In your write to memory function, do something like:

Code:
if(address>=0xff10 && address<=0xff26)
{
   aud.WriteRegister(address,data);
   return;
}

Same thing goes for aud.ReadRegister in your read register function, though this one isn't entirelly necessary. I think only some GBC games rely on reading back the values of the sound io registers.

Lastly, when LY=144 (when you just finished drawing the screen) call aud.EndFrame();

Voila! Sound. Just make sure that you include the sdl libs. Here is some extra information Blargg sent me in an email:

I guess you can tell by now that the simplified APU is simulating the Z80
as if it were writing to the sound chip every instruction at the beginning
of the frame. Once you are ready to switch to the full APU, you'll be
passing the actual number of clocks since the beginning of the frame.

> Also, reseting
> doesn't reset the sound properly. But none of that is anything I
> can't work out on my own.

I'll have to look into reset behavior. I originally wrote the APU only for
a GBS music player, so most problems are due this.

Even if you work out problems, let me know so I can fix the
library/documentation.

Here are a couple of features you could add in the future, once everything
else it working well (my standard pitch, heh):

You can adjust the treble and bass frequency response, good for simulating
the small speaker in a Game Boy:

Basic_Gb_Apu::Basic_Gb_Apu()
{
time = 0;
apu.treble_eq( -20.0 ); // lower values reduce treble
buf.bass_freq( 461 ); // higher values reduce bass
}

These can be adjusted at any time, not just during initialization.

There's also Effects_Buffer, which adds adjustable panning and stereo echo
to the sound channels. Since most Game Boy games never even use stereo, it
makes them sound a little better on headphones.

As you may of guessed, this isn't using his full APU, but a basic version for getting started.

EDIT: If anyone gets his APU working with DirectSound, please let me know. It was giving me a hard time, so I just stuck with SDL.

EDIT: Also note there was a bug in the sound in the last build of my emu that messed up the timings and it eventually turned to static. This is fixed in this code here, and in the current build of my emulator.

Regards
 
Last edited:

gunder

New member
That looks great Sagon! Evertime I see screen shots like this it makes me want to drop my other projects and start up a game boy emulator. I know it's way beyond my skill level right now so I'm not letting myself. You people make it really hard though! :)

-gunder
 

ShizZy

Emulator Developer
Sagon, what methods do you use for debugging? Can't seem to figure out how you can do it so efficiently.
 

bcrew1375

New member
ShizZie, I tried the sound library. I just get a bunch of errors in all the header files. Hmm, could it have to do with the fact I'm using C instead of C++?

These are the first couple of messages I get:

Code:
blip_buffer.h(12) : error C2061: syntax error : identifier 'Blip_Reader'
blip_buffer.h(12) : error C2059: syntax error : ';'
blip_buffer.h(18) : error C2059: syntax error : ':'
blip_buffer.h(20) : error C2061: syntax error : identifier 'Blip_Buffer'
blip_buffer.h(20) : error C2059: syntax error : ';'
blip_buffer.h(20) : error C2449: found '{' at file scope (missing function header?)
blip_buffer.h(114) : error C2059: syntax error : '}'
blip_buffer.h(129) : error C2061: syntax error : identifier 'Blip_Reader'
blip_buffer.h(129) : error C2059: syntax error : ';'
blip_buffer.h(129) : error C2449: found '{' at file scope (missing function header?)
blip_buffer.h(156) : error C2059: syntax error : '}'
blip_buffer.h(166) : error C2059: syntax error : ':'
blip_buffer.h(168) : error C2061: syntax error : identifier 'Blip_Impulse_'
 
Last edited:

bcrew1375

New member
I'm using MSVC++ 6.0 :p. I was just wondering if it's not allowing C++ syntax. It seems like each file should compile depending on it's extension, but could it somehow be in "C Mode" since my code is in C?
 

ShizZy

Emulator Developer
bcrew: change all your file's extensions to cpp, create a new empty win32 workspace, and copy all your files in, and all the audio library files. Include Audio.h. It is *important* that all the audio files are actually in the workspace, so add them all in. Also make sure it's getting the files in the boost folder. If you're still having problems, let me know, and I'll post a simple workspace that will build with the files in it.

Edit: Yes it's because you're using .C files, and the files you are including use classes. If the file is .C, the compiler automatically assumes it is strickly C code.
 
Last edited:

bcrew1375

New member
Well, I had to type cast alot to get my code to compile :p, but it finally works. Sound seems to work nice. This should make debugging a little less boring :). I intend to code my own after my code is a bit more compatible. Thanks, ShizZie!
 

Sagon

New member
ShizZie said:
Sagon, what methods do you use for debugging? Can't seem to figure out how you can do it so efficiently.
I'm using just plain look and guess method, nothing more. And of couse I spent hours in my own coded debugger to catch and kill non trivial bugs.
Thanks for the sound framework and explainations!
 
Last edited:

ShizZy

Emulator Developer
No problem guys.

bcrew: you should release a build of your emulator, havn't seen much from it in a while :p

Nailed a couple of bugs this weekend that were really hurting my emu, and I got to say compatability is finally starting to get fairly good. Fixed my metroid, mario, and zelda bug, DK and DKLand are now flawless, and every single GB Mono game in my roms folder boots as it's supposed to. (Granted one or two of them crash in game). It was all two simple things, I was rotating instead of shifting for one of my shifts, and one of my loads was HL=SP instead of SP=HL.

Questions... documents say to delay interrupt enables/disables by one instruction. Do you guys do this? I tried doing it, and it breaks Waverace, which otherwise runs flawless. Also, most of my games display scores in hex. How did you guys fix this? And does anyone know of any MBC3 games?
 
Last edited:

Top