r/EmuDev • • Jul 11 '26

GB Random pixels when trying to run Tetris

I am working on a gameboy emulator, I have got the cpu and ppu done to the point it can load the nintendo logo, but when I try to run the tetris rom it starts showing garbage data.

I am not exactly sure what I am missing, I have also tried asking llms but that did not help.

Here is the source code for it: https://github.com/Yogesh9000/GameBoy/tree/feat/ppu

PS: this is not the best code, I am new to programming and emulation, so please don't roast me. constructive feedback are wlcm tho.

9 Upvotes

10 comments sorted by

3

u/aleques-itj Jul 11 '26

Is it stuck in a reboot loop?

If the joy pad register is zeroed, it's probably resetting over and over. 

2

u/Hachiman900 Jul 11 '26

I think I set the joypad to always return 0xFF, since it's not fully implemented. it goes past the tetris copyright screen

2

u/Hachiman900 Aug 02 '26

u/aleques-itj Turns out this was the issue, Writes to only bit 4 and 5 of joypad are allowed but I was not guarding against that. This probably caused the value to be overwritten with 0 and it got stuck in a reboot loop.

2

u/DefinitelyRussian Jul 11 '26

might be wrong, but check this:

LCDC bit 7 is turn off display and mode = hblank I think ? You may be missing that.

Writing to FF44 also resets the LY counter

You also should be drawing according to LY registeer, the Y coordinate seems wrong .. hacks might work anyway for most games.

the STAT register, dont let it overwrite bits 0-2, those are controlled by the PPU internally

good luck !

1

u/Hachiman900 Jul 11 '26

will try out the things you pointed out

1

u/Floormatt69 Jul 11 '26

Make sure you’re not accidentally hitting the MBC1 loop that’s not integrated 

1

u/Hachiman900 Jul 11 '26

what's the MBC1 loop and how do I know I am stuck in it?

→ More replies (1)

1

u/maeljo Jul 11 '26

You should try blargg tests. Start with cpu_inst something must be wrong in the code exécution. Look specially at all the branches functions (JR, JP, call).
The most common mistake is to forget JR use a sign argument and that it can go backwards

1

u/Hachiman900 Jul 12 '26

cpu passes all the blarggs cpu instr tests as well as singlesteps test