Naughtyemu, what is it doing? [solved]

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Naughtyemu, what is it doing? [solved]

Post by Alyosha_TAS »

I see this ROM as part of Gekkio's files, but I can't seem to find a lot of information about it.

So far every emulator I test it on prints the message "Naughty emulator! No presents for you!"

I'm guessing that means it's a failure. It looks like the what it's doing is using the timer and some midframe DMA's to do something, but I have no idea what.

Does anyone know what this ROM is testing and what the expected output is?

I can't even find the origin of this ROM, so any info is appreciated, thanks as always!
Last edited by Alyosha_TAS on Fri Dec 08, 2017 8:12 am, edited 1 time in total.
gekkio
Posts: 49
Joined: Fri Oct 16, 2015 6:18 am

Re: Naughtyemu, what is it doing?

Post by gekkio »

It's a silly test ROM I made two years ago around christmas time 8-)

It tests certain special behaviour that no emulator gets right. On real hardware you get just a blank screen instead of the text you saw.
However, this test ROM doesn't fully test that behaviour so some emulators end up with the blank screen without properly emulating this edge case.

I can post further details and the source if you're interested :)
However, I have to warn that emulating the behaviour correctly right now is probably not possible because we don't understand it well enough. IIRC the behaviour wasn't even the same on all models...I think even MGB and DMG were different.
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Re: Naughtyemu, what is it doing?

Post by Alyosha_TAS »

gekkio wrote: I can post further details and the source if you're interested :)
However, I have to warn that emulating the behaviour correctly right now is probably not possible because we don't understand it well enough. IIRC the behaviour wasn't even the same on all models...I think even MGB and DMG were different.
Yes I am very interested about what this mysterious behaviour might be. Even if I don't implement it right away I'd like to have some conceptual understanding about how it would fit into the rest of the emulator.

Also thanks for all your hardware research and test roms, they are awesome!
gekkio
Posts: 49
Joined: Fri Oct 16, 2015 6:18 am

Re: Naughtyemu, what is it doing?

Post by gekkio »

I published the sources here: https://github.com/Gekkio/naughtyemu

The basic idea involves OAM DMA and HALT. If OAM DMA is running when HALT is entered, the OAM DMA is suspended but ends up leaving some internal bus in a busy state.
If HALT is eventually exited, OAM DMA continues from where it stopped.

Now, while the internal bus is in this "busy state", PPU OAM accesses cause internal bus conflicts. This particular test ROM basically relies on this bus conflict to prevent sprites from being drawn.
By using clever timing, I'm making sure that we have a OAM DMA + HALT bus conflict every time the PPU is drawing a sprite, so OAM accesses end up seeing something else than the real sprite data.
It's possible to pass this test simply by not drawing sprites in this bus conflict mode.

However, this is not the real behaviour on real hardware... :twisted:
On real hardware the PPU sees some OAM values, which in some way depend on the model, the real OAM value underneath, and the value OAM DMA is trying to write. It's even possible that individual unit differences come to play here (which would make emulating this in detail completely pointless).
This is also why this in this test a blank screen is considered a "success": I don't fully understand how to control the value the PPU sees, so it's extremely difficult to show something on the screen.

There's a test called madness/mgb_oam_dma_halt_sprites in mooneye-gb tests directory, which shows an example where the screen ends up showing something in this bus conflict case.
Alyosha_TAS
Posts: 173
Joined: Wed Jun 15, 2016 11:49 am

Re: Naughtyemu, what is it doing?

Post by Alyosha_TAS »

Ahhh ok that makes sense. So the fundamental behaviour I was missing was the OAM DMA is halted when the CPU is halted, got it. The bus conflict this causes makes OAM unreadable/glitchy mess to the ppu when it's processing sprites.

Cool, implementing that was enough to get the blank screen in naughtyemu.gb, thanks!

I'll worry about the glitchy details at some later point.
Post Reply