GBVisualizer – Demo using undocumented registers

Discussion of programming and development for the original Game Boy and Game Boy Color.
LIJI
Posts: 23
Joined: Mon Jan 18, 2016 5:36 pm

GBVisualizer – Demo using undocumented registers

Post by LIJI »

Hey,

I recently released a demo (including sources) called GBVisualizer. It's supposed to demonstrate the use of two undocumented hardware registers, nicknamed PCM12 and PCM34, which I previously mentioned in GBDev Wiki.

Basically, these two registers allow reading the current PCM samples of each of the 4 APU channels in real time. This allows me to display real time oscillator-like audio visualization while playing music.

Some interesting notes:
  • Since it's not documented, and as far as I know, never used in any official game or demo, not a single released emulator supports these registers. (My yet-to-be-released emulator does support them)
  • Some emulators read these registers as constant zeros, which are the correct values when sound is not playing.
  • These registers allow an entire different class of test ROMs to be created, which will eventually allow sample-perfect nanosecond-accurate APU emulation.
  • Music for this demo is adapted from another project of mine, a disassembly of Super Bomberman.
  • I actually discovered these registers by coincidence.
Feel free to fork this demo to add more kinds of visualizations (Winamp AVS anyone?), and suggest other uses for these registers. :)

Image
ccovell
Posts: 1045
Joined: Sun Mar 19, 2006 9:44 pm
Location: Japan
Contact:

Re: GBVisualizer – Demo using undocumented registers

Post by ccovell »

That is pretty cool. Does your demo separate out the 4 nybbles at all to make the visualizer?
User avatar
Jazzmarazz
Posts: 26
Joined: Mon Mar 30, 2015 2:22 pm
Location: Detroit, MI
Contact:

Re: GBVisualizer – Demo using undocumented registers

Post by Jazzmarazz »

Oh wow.
Are the registers Read-only, like flag register?
Shonumi
Posts: 342
Joined: Sun Jan 26, 2014 9:31 am

Re: GBVisualizer – Demo using undocumented registers

Post by Shonumi »

You're gonna give byuu and gekkio even more to handle on their plates :D

Maybe one of these days, I'll rewrite my entire GB/GBC core to be cycle accurate, but I've got too many other things on my plate right now (like accurately emulating the crappy scaling the GBA does for DMG/GBC games...) Though, forget about test ROMs for a second, think of all the demos you could make. I can see this being GBDEV 2016 compo material.

Great to see some of those undocumented registers actually had some functionality, even if Nintendo never intended people to use them. Cool stuff man 8-)
LIJI
Posts: 23
Joined: Mon Jan 18, 2016 5:36 pm

Re: GBVisualizer – Demo using undocumented registers

Post by LIJI »

ccovell wrote:That is pretty cool. Does your demo separate out the 4 nybbles at all to make the visualizer?
Yes, I separate and sum them, although it is obviously possible to read them individually and visualize each channel separately.
Jazzmarazz wrote:Oh wow.
Are the registers Read-only, like flag register?
TBH, I never tried writing to them, but I think it's safe to assume they are read only.
Shonumi wrote:You're gonna give byuu and gekkio even more to handle on their plates :D

Maybe one of these days, I'll rewrite my entire GB/GBC core to be cycle accurate, but I've got too many other things on my plate right now (like accurately emulating the crappy scaling the GBA does for DMG/GBC games...) Though, forget about test ROMs for a second, think of all the demos you could make. I can see this being GBDEV 2016 compo material.

Great to see some of those undocumented registers actually had some functionality, even if Nintendo never intended people to use them. Cool stuff man 8-)
Actually, implementing support for these registers, at least in my emulator, was quite trivial; but potential test ROMs using these registers are definitely going to be a nightmare. And yeah, I'd love seeing more demos using these. :)
gekkio
Posts: 49
Joined: Fri Oct 16, 2015 6:18 am

Re: GBVisualizer – Demo using undocumented registers

Post by gekkio »

That's a very nice find!
I'll test this on all my Game Boy devices later today and report my findings.
You're gonna give byuu and gekkio even more to handle on their plates :D
Well, if this is GBC-only, it's not immediately interesting for me, but I'll get to GBC eventually ;)
TBH, I never tried writing to them, but I think it's safe to assume they are read only.
Yes, my HWIO test ROM confirms that writes do not have an effect (at least from the Game Boy's point of view).
Although it's still possible in theory that it could affect the audio itself...
LIJI
Posts: 23
Joined: Mon Jan 18, 2016 5:36 pm

Re: GBVisualizer – Demo using undocumented registers

Post by LIJI »

I don't have a DMG to test it, but I read that these registers read constant FFs on non-CGBs. Btw, the demo assumes it runs on a CGB, so you need to comment out the processor speed change and configure DMG palettes for it to actually run.
Shonumi
Posts: 342
Joined: Sun Jan 26, 2014 9:31 am

Re: GBVisualizer – Demo using undocumented registers

Post by Shonumi »

> Actually, implementing support for these registers, at least in my emulator, was quite trivial; but potential test ROMs using these registers are definitely going to be a nightmare.

I wasn't exactly thinking about the difficulty of supporting them; a cycle-accurate emulator could just grab the sample from the APU whenever it's clocked and pass it to the MMU whenever the registers are read. Seems relatively straightforward. It's just that, if you're OCD, a perfectionist, or someone who just can't sleep at night until your project emulates every little obscure hardware behavior, this is *grumble, grumble* yet another thing you have to look into :P

My DMG/GBC cores were never designed to be accurate in any regards. I'd really have to make a new core, because I'd be grafting so much code trying to get two conflicting designs to work. One of these days though.

> And yeah, I'd love seeing more demos using these. :)

I've always wanted to make full-screen TV-static transitions (like changing a channel) to jump from one scene of a demo to the next. Polling Sound 4's nibble in PCM34 is a lot simpler than coding my own LSFR, and definitely much faster. Setup a couple of writes to Sound 4's registers, initialize it, then read PCM34.

Also, just FYI, GBVisualizer works just fine on GBA units. So, even though this was undocumented and never used in commercial games (at least it's not supposed to be) they still kept it around (probably not worth removing from the GBA honestly).
gekkio
Posts: 49
Joined: Fri Oct 16, 2015 6:18 am

Re: GBVisualizer – Demo using undocumented registers

Post by gekkio »

I don't have a DMG to test it, but I read that these registers read constant FFs on non-CGBs. Btw, the demo assumes it runs on a CGB, so you need to comment out the processor speed change and configure DMG palettes for it to actually run.
Yeah, I know...Sorry, I didn't explain myself very clearly, but I just meant all my GBC/AGB/AGS devices. Tested, and it works!

This is a bit off topic, but I tried GBVideoPlayer too a couple of weeks ago, and on my hardware it stops working at around half way. Any ideas? It's probably an issue with the EMS 64Mb cartridge I use (e.g. some incorrect edge case in MBC5 emulation), but I'm wondering if there's something in the code that relies on specific CGB hardware revision or flash cartridge behaviour. Have you received any success or failure reports from other people running it on real hardware?
LIJI
Posts: 23
Joined: Mon Jan 18, 2016 5:36 pm

Re: GBVisualizer – Demo using undocumented registers

Post by LIJI »

A video that stops playing in the middle means the cart does not contain the entire ROM. Is that the cart that allows flashing two ROMs? Because these cart actually supports only 32Mbs per ROM.
gekkio
Posts: 49
Joined: Fri Oct 16, 2015 6:18 am

Re: GBVisualizer – Demo using undocumented registers

Post by gekkio »

A video that stops playing in the middle means the cart does not contain the entire ROM. Is that the cart that allows flashing two ROMs? Because these cart actually supports only 32Mbs per ROM.
Ah, that's definitely it. I've never used the paging feature myself but apparently the cart is indeed 2x32Mb and does not work properly with 64Mb ROMs.
Lee
Posts: 1
Joined: Thu Feb 11, 2016 4:30 pm

Re: GBVisualizer – Demo using undocumented registers

Post by Lee »

Just a video of this on hardware: https://www.youtube.com/watch?v=rlrqg14q0Oc
Near
Founder of higan project
Posts: 1553
Joined: Mon Mar 27, 2006 5:23 pm

Re: GBVisualizer – Demo using undocumented registers

Post by Near »

Can someone please post a compiled .gbc of this demo?

I'm not really interested in the visualization aspect of this, but it's *extremely* promising to use these for better emulation of the APU channels. In the same way that the echo buffer was a lifeline into understanding the SNES DSP.
LIJI
Posts: 23
Joined: Mon Jan 18, 2016 5:36 pm

Re: GBVisualizer – Demo using undocumented registers

Post by LIJI »

Binary versions are available in the repo's releases in Github. :)
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: GBVisualizer – Demo using undocumented registers

Post by Dwedit »

Do these registers exist in GBC mode on a GBA? What about in GBA mode?
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Post Reply