What's new

Game Boy

Rüdiger

New member
And I finally had some time to work on my emulator.
I fixed some issues with my interrupt code (and I actually forgot to generate the normal vblank interrupt and only did the vblank-STAT one... :blush: ) and added timers.
That was enough to get some games running. Then I found a really nasty bug that was actually caused by the reference I was using:
The size of ld (ff00+C),A and ld A,(ff00+C) was stated as 2 bytes, but it is only one byte large.
I found this one by debugging the seemingly different issue of missing sprites in pokemon.

Pokemon does something like this on startup:
Code:
ld hl,source
loop:
ldi a,(hl)
ld (ff00+c),a
inc c
dec b
jr nz loop
This copies a small routine to HRAM which then updates the OAM each vblank via DMA.
By using the wrong instruction size, the inc c was skipped each time and everything except the ret at the end of the routine was overwritten.
So the emulator unwillingly removed the sprite code from pokemon. That was 'fun' to debug... :plain:

Now quite some games I tested run more or less perfect: Mario Land 1/2, Pokemon Red/Blue/Green/Yellow, Kirby's Dream Land 1/2, Harvest Moon, Tetris, Metroid II...
Pokemon Gold/Silver has some weird graphical issues but is otherwise playable. Zelda runs but sections of the map are corrupted and the sprite colors look off.

I looked into adding sound, but I will also consider using Blargg's library for the time being as it looks like quite a big task...
 

Attachments

  • 2013-10-30.21:57:17.png
    2013-10-30.21:57:17.png
    1.6 KB · Views: 124
  • 2013-10-30.21:58:45.png
    2013-10-30.21:58:45.png
    1.2 KB · Views: 128
  • 2013-10-30.22:02:01.png
    2013-10-30.22:02:01.png
    1.6 KB · Views: 119
  • 2013-10-30.22:11:06.png
    2013-10-30.22:11:06.png
    2.1 KB · Views: 110
  • 2013-10-30.21:59:52.png
    2013-10-30.21:59:52.png
    1.8 KB · Views: 129
  • 2013-10-30.23:07:53.png
    2013-10-30.23:07:53.png
    1.7 KB · Views: 113
  • 2013-10-30.22:05:07.png
    2013-10-30.22:05:07.png
    2.7 KB · Views: 114
  • 2013-10-30.23:11:24.png
    2013-10-30.23:11:24.png
    1.7 KB · Views: 125

Rüdiger

New member
I added Blargg's audio library and fixed some small issues. Now Zelda is one of the only games I tried that is not really playable yet...
Next up is GBC support. Does anyone have information on the palettes that are used to color some specific monochrome games?

Edit: Never mind, I found a useful reference: http://tcrf.net/CGB_Bootstrap_ROM
 

Attachments

  • 2013-11-10-192718_160x144_scrot.png
    2013-11-10-192718_160x144_scrot.png
    2.1 KB · Views: 558
Last edited:

Sergio89

New member
I added Blargg's audio library and fixed some small issues. Now Zelda is one of the only games I tried that is not really playable yet...
Next up is GBC support. Does anyone have information on the palettes that are used to color some specific monochrome games?

Edit: Never mind, I found a useful reference: http://tcrf.net/CGB_Bootstrap_ROM
Rüdiger, how do you manage to support monochrome Game Boy games in "GBC Mode"? I'd like to add support for that in my emulator.
Thanks!
 

Rüdiger

New member
I added color support and got a bunch of games running. It seems that my HDMA code has still bugs and trying to fix it for one game breaks another :( .
Problematic games seem to be pokemon crystal, oracle of ages/seasons, shantae and to some extend super mario bros...

Rüdiger, how do you manage to support monochrome Game Boy games in "GBC Mode"? I'd like to add support for that in my emulator.
Thanks!
On that screenshot I actually didn't yet have the GBC Mode but merely used the palettes.
However, I added that too and it should work by using the monochrome palettes as usual to get the shade and then use the first colored background palette
to assign the colors to the background and the first two colored object palettes to assign colors to OBP0/OBP1.
The color boot rom should load the palettes and then switch to monochrome compatibility mode. But I have not yet added support for the boot rom so I can't verify
it and have to set the palettes by myself.
 

Attachments

  • 2013-11-17-164537_160x144_scrot.png
    2013-11-17-164537_160x144_scrot.png
    8 KB · Views: 126
  • 2013-11-17-164732_160x144_scrot.png
    2013-11-17-164732_160x144_scrot.png
    2.2 KB · Views: 103
  • 2013-11-17-164840_160x144_scrot.png
    2013-11-17-164840_160x144_scrot.png
    5.7 KB · Views: 119
  • 2013-11-17-165132_160x144_scrot.png
    2013-11-17-165132_160x144_scrot.png
    5.9 KB · Views: 118
  • 2013-11-17-165436_160x144_scrot.png
    2013-11-17-165436_160x144_scrot.png
    4.1 KB · Views: 107

Sergio89

New member
I added color support and got a bunch of games running. It seems that my HDMA code has still bugs and trying to fix it for one game breaks another :( .
Problematic games seem to be pokemon crystal, oracle of ages/seasons, shantae and to some extend super mario bros...


On that screenshot I actually didn't yet have the GBC Mode but merely used the palettes.
However, I added that too and it should work by using the monochrome palettes as usual to get the shade and then use the first colored background palette
to assign the colors to the background and the first two colored object palettes to assign colors to OBP0/OBP1.
The color boot rom should load the palettes and then switch to monochrome compatibility mode. But I have not yet added support for the boot rom so I can't verify
it and have to set the palettes by myself.
Well, I do have support for CGB ROM (and CGB in general). It does do some things with the palettes, but I get weird results. The results are the same to the ones from the MESS emulator (that is, bad results), so I'd think there is more to it.
How exactly did you get the right colors in the pic of Gengar and Jigglypuff (that is Pokemon Blue, right?).
 

Rüdiger

New member
Well, I do have support for CGB ROM (and CGB in general). It does do some things with the palettes, but I get weird results. The results are the same to the ones from the MESS emulator (that is, bad results), so I'd think there is more to it.
How exactly did you get the right colors in the pic of Gengar and Jigglypuff (that is Pokemon Blue, right?).

Yes, that's Pokemon Blue. I manually load the BG0 and OBJ0/1 palettes, but as I still don't have CGB ROM support, I don't know if I'm actually doing it right. The manual suggests that the boot ROM does something similar but doesn't go into the details.

I didn't have enough time to work on my emulator, so no progress so far and HDMA is still broken :( .
 

Sergio89

New member
Yes, that's Pokemon Blue. I manually load the BG0 and OBJ0/1 palettes, but as I still don't have CGB ROM support, I don't know if I'm actually doing it right. The manual suggests that the boot ROM does something similar but doesn't go into the details.

I didn't have enough time to work on my emulator, so no progress so far and HDMA is still broken :( .

I got it now... Indeed, the Game Boy Color boot ROM selects the palette if the (monochrome) game is in the database; you can manually select the palettes during this boot time. But in the case of Pokemon Red/Blue, colors are horrible. What I didn't know is that the cool colors are used in the Super Game Boy, not the Game Boy Color.
 

Rüdiger

New member
But in the case of Pokemon Red/Blue, colors are horrible. What I didn't know is that the cool colors are used in the Super Game Boy, not the Game Boy Color.
Yes, it looks somewhat nice for Gengar and Jigglypuff, but almost everything else is... well... blue... :ermm:
 

Rüdiger

New member
I added some (very) basic SGB support. Nothing useable yet, but the emulator gets the packets from the games.

I also tried to go back to the basics to fix some timing issues that are probably breaking Zelda, but hit a wall.
The IRQ demo suggests that my timing is off but I don't know why.
Instr_timing fails for whatever reason before running the actual tests, not really helpful either...

And cpu_instrs fails for the HALT instruction but passes when running the individual test...

This looks like I have a lot of tedious debugging ahead of me and that I will not get anywhere anytime soon...
 

Attachments

  • 2014-01-05-195133_160x144_scrot.png
    2014-01-05-195133_160x144_scrot.png
    1.8 KB · Views: 107
  • 2014-01-05-195152_160x144_scrot.png
    2014-01-05-195152_160x144_scrot.png
    1 KB · Views: 107
  • 2014-01-05-195216_160x144_scrot.png
    2014-01-05-195216_160x144_scrot.png
    1.1 KB · Views: 108
  • 2014-01-05-195057_160x144_scrot.png
    2014-01-05-195057_160x144_scrot.png
    3.8 KB · Views: 101

fleroviux

Member
Hi just to let you know, I'm working on a opensource gameboy emulator in C#. It's just for the process of learning.
Currently I have a cpu core (which might have bugs, but not for sure), MBC3 support. I'm working on the video driver, but it's not finished yet so you'll have to wait, until you can see some screen of my emulator running games.
(Well I could post screens of my debug console xD). Although it's coded in C#, the cpu core is running at a good speed. Without limiting it, I had a clock rate between 40-200Mhz.

You can view the sourcecode on Github. Just follow this link https://github.com/hackiosa/geekboy/

If I have any questions, I'll ask you.
 

fleroviux

Member
So now I got my first question. I'm currently actively developing on my emulator, and I'm working on video emulation.
Well I'm testing my emulator with pokemon red :D
And when running the game I almost instantly get some kind of error screen ( I believe ).
This is a screenshot ( and yea', the tilemap handling is propably wrong :D )
hxxp://picload.org/image/ldpagip/error.png
Please replace the hxxp with http, I somehow can't post links ô0
You can read it saying "POCKETMONSTER" and there are some tiles of a pokemon I think. That is why I believe it's a error screen, because normally that wouldn't occur..

Greetz Flerovium.
 

Rüdiger

New member
It's nice to see that someone else is working on an emulator.

The screenshot looks like it shows some tiles from the beginning as they are stored in memory.
It says "POCKETMNSR...red" and each character appears only once, while displaying the text should use them multiple times.
Are you using the right background map? (Bit 3 in LCDC)

The other tiles look like Gengar and Jigglypuff so you seem to be on the right track.
I suspect an error in your display code. The only error screen at startup I can think of is the GBC-only screen, and that's obviously not the case...

Depending on how complete your emulated hardware is, some PD games are good for testing as some of them don't require interrupts or timers.
Blargg's test ROMs are also always a good idea.
 

fleroviux

Member
Hi Rüdiger.
I could almost finish the video emulation the last days (expect from oam emulation). It's working and I can play only a few games (such as Zelda - Links Awakening), but most of my games (also Pokemon Red) do not work, so it's the case that I'm suspecting the cpu core, because of the video emulation working. I tried to wipe out all errors I could find, but it still does not work with those games. I tried a lot to find mistakes in my cpu core, but recently I couldn't find any more. Well I think I'll rewrite the cpu core the next days. Blargg's test ROMs sadly do not work, too.. :(

Greets from Germany.
Flerovium
 

Rüdiger

New member
It took me a lot of time to find enough bugs in my CPU core to get the tests and some games running...
I found quite some bugs by taking a working emulator, dumping the registers for each instruction and comparing it with the output of my emulator.
Not all differences indicate errors in the CPU core and some can be caused by interrupts or unemulated hardware registers, but others are hopefully very obvious.

I have extended my instruction decoder to a disassembler and am now working on more sophisticated debugging mechanisms to find hopefully some of the remaining pesky bugs...
 

fleroviux

Member
I used the first method, too and I could find the most obvious bugs using this method. Well I'll try some more methods.
I hope to get it fully working some day :) Maybe I'll rewrite the core later, using my new method :)

EDIT: Found 2 bugs, but they did not change a lot. But they could have caused big problems. The first was the SRA opcode that was emulated incorrect and the second bug was that the booleans FlagZ, FlagN, FlagHc and FlagC weren't updated after POP AF. Pokemon Red and a lot of others games still don't work..
 
Last edited:

Shonumi

EmuTalk Member
Flerovium - While it's always good to get CPU bugs fixed, it might not be the issue in regards to games that won't work on your emulator (Pokemon and Legend of Zelda, as you mentioned). It could be any number of other areas (MMU, LCD, input). Depending on your understanding of the Game Boy, you might be able to pinpoint or guess where the problem is; it (sometimes) gets easier the more you deal with the Game Boy and your emulator.

If I were to take a guess, your LCD emulation probably isn't perfect, though I haven't thoroughly looked over your C# code. My advice is to make sure everything works, piece by piece, rather than trying to emulate everything the LCD does at once and scratching your head when you get bugs like this. For example, make sure you can do something basic, like properly render a simple background using Tile Set 1 using Tile Map 1 and 0. Then make sure you can properly render Tile Set 0 using Tile Map 1 and 0. Then move onto Window emulation, then sprites. It's a good idea to do one thing at a time, and make sure it's perfect before moving on.

Off the top of my head, I know of a few good Public Domain ROMs that are good for testing. You can find an old Tic-Tac-Toe demo (good for testing sprites) and a small space shooter (good for testing X/Y background scrolling and sprites) here: hxxps://github.com/Two9A/jsGB/tree/master/tests. Naturally both are good for testing your rendering of backgrounds (can't recall which Tile Sets and Maps they use though). For Window emulation, Balloon Man is really good.
 

Rüdiger

New member
I used my disassembler to implement a simple profiler. While the output is very messy and not very useful for most games,
I actually managed to find a regression in one of the first games I got running: http://i.imgur.com/43yRmUj.png
it now waits in an infinite loop for mode 0 or 1 while the display is disabled.
I'm not yet sure why the mode isn't right, but it's the first new bug I found in a long time. :)
 

fleroviux

Member
Shonumi - Background rendering and window rendering is correct (according to Legend of Zelda). This should not be the problem.

Rüdiger - This looks very nice! I had no time and motivation to work on my emulator the past week. School is eating a lot of time :(
 

Shonumi

EmuTalk Member
Flerovium - Simply because BG and Window rendering is correct in LoZ doesn't necessarily mean it will be so in something like Pokemon. A lot of games do different things in different ways. As I recall, Kirby's Dream Land seems to reserve Tile Set 1 exclusively for sprites, while Tile Set 0 is reserved exclusively for BG tiles. That's why I encouraged you to check a wider range of situations, to see if you can render Tile Set 1 and 0 correctly using either Tile Map 1 or 0. The best thing you can do is always test more games and scenarios. Aside from that, go over the documentation again and make sure you're doing everything to the Game Boy's specifications.

One of these days I'll get around to making a test ROM dedicated to things like graphical accuracy, but I'm currently gearing up for a 1.0 release of my own GB emulator. It's going to be a busy for me until then.

EDIT: Looking over your code on GitHub, I'm curious as to how you handle the MBC5. Just glancing over it, I don't see anything specifically pertaining to the MBC5. The LoZ uses an MBC5 cartridge, unlike the Pokemon games (Red through Crystal) which use the MBC3 cartridge. You should probably look into your MMU as well, as the way you manage MBC read/writes can be just as big a headache as CPU related issues.
 
Last edited:

Top