r/programminghelp • • Jun 22 '15

Screen glitch bug in my java gameboy emulator

I have written a gameboy emulator in java after reading the pandocs for many weeks, and I understand the architecture of the console very well. Regardless of this, my final product has a screen glitch bug which distorts what is on the screen. (See: http://imgur.com/VWeFBQil.png)

The image in the link is my backup ROM of tetris for the DMG playing. The text in the middle is the Nintendo logo I believe, as when the emulator starts it scrolls down from the top. The header glitch above this is what I believe is the tetris game start screen background. There is no sound, joypad interrupts, or sprites implemented as I have spent all my time trying to get the background to display properly. Once that is done I will easily be able to shift over and work on those components of the system.

What I am asking is for anyone to attempt to help me find the issue with this project? I have spent 2 weeks attempting to fix this bug, to no avail. I have wasted too much time trying to find and fix it; it is affecting my home life!

Github repo: https://github.com/glen-mac/jBoy

4 Upvotes

5 comments sorted by

2

u/LightShadow Jun 22 '15

I looked through your code for about 10 minutes...my guess would be there's an error in your main execute function. Those nested switch statements are incredibly dirty; you made a case for each combination of instructions and registers.

Because there's so much repetition, over 1000 lines, I think you missed a case or there's a typo.

1

u/Glenny5 Jun 22 '15

Would you recommend a nice way to format the handling of the opcodes further down the track?

I'll have another look - I did find some semantic issues when I did a sweep through of them the other day.

2

u/LightShadow Jun 22 '15

I'm not super familiar with the Z80 at that level, but when I wrote a virtual machine for generic assembly stuffs I used bit shifting to encode and decode registers/addresses into a single integer.

I'll look at your code again when i have a bit more time and see if anything stands out. I think even getting to where you're at deserves a pat on the back though. It's looking good!

1

u/Glenny5 Jun 22 '15

Thank you so much for your kind words!

I really want to squash this bug so I can move onto other projects I have lined up!

1

u/Glenny5 Jun 23 '15

I've got it to the stage where it scrolls a black rectangle in place of the 'Nintendo' text. See here for various game outputs: http://imgur.com/a/5R8KI After this the games freeze - see the album I linked to prior for a better explanation.

I do not understand why it is doing this - as the nintendo logo data in both the bootrom and all my tested roms match. And debugging the bootrom as it executes, on PC=0x27 the first byte of the ROM nintendo logo is request, and correctly 0xCE is returned. So no issue there so i'm not sure what the problem is.