Hu-Boy: a GameBoy Emulator for the PC-EngineCD / SuperGrafx

^ Chris Covell's Webpage

What??

This is a program for NEC's PCE / TurboGrafx, etc. game hardware that emulates Nint*ndo's GameBoy system. Bear in mind that the PCE's CPU clock speed is not even twice that of the GameBoy, and that they both possess 8-bit CPUs (6502-like vs. Z80-like) with vastly different registers and instruction sets. So, yeah, it's a bit crazy to try to get a GB game running on the PCE in the first place, let alone hope for anything approaching actual speed.

I had the crazy idea for this in November 2022 as I was recuperating at home for a couple of weeks from a hernia operation, of all things. I guess it was the heavy medication that made this fever dream come to reality, then. This program is still at an early and unpolished stage, but I'm releasing it because perhaps it'll be fun for people to play around with. Also this year (2023) I have become swamped yet again at home and at work, so my free time to work on Hu-Boy has been severely cut down, sadly. :.-(

Some Main Features:

  • All CPU instructions emulated (no guarantees about accuracy!)
  • No promises about speed. It's not fast.
  • MBC1 cartridge mapper emulation, supporting cartridges <1 MByte in ROM / <192 KByte for CD-ROM version
  • Basic sound emulation (frequency, volume sweep, wave channel and pulse/noise channels)
  • DMG BG & sprite palette emulation, with separately adjustable palettes
  • Background layer, scrolling, per-scanline scrolling emulated
  • Window layer simulated but with some limitations
  • GB sprites, both 8x8 and 8x16, tile-flipping.
  • An options screen with plenty of controls to change speed/accuracy, enable/disable features
  • Did I mention it was not very fast?

Requirements:

You'll need either a SuperGrafx, or the CD attachment for PC-Engine/TurboGrafx, due to RAM requirements.

The stock PC-Engine / Turbografx consoles have only 8 KB of main system RAM, whereas even the original B&W GameBoy had over 16 KB of RAM that needs to be stored and emulated somewhere. I've therefore made versions of Hu-Boy that use either CD-RAM from the PCE CD-ROM2 system, or the SuperGrafx's extra built-in RAM. So you can use a SuperGrafx plus ROM flashcart (recommended), or burn/emulate an ISO and run it from your PCE+CD-ROM2 system with Super System Card.

Download:

Hu-Boy V 0.30621  Contains .PCE (AKA .SGX) ROM for flash carts, ISO for burning onto a CD, and binaries to join up with other .GB ROMs.

Preparation:

Hu-Boy needs a .GB ROM to run. A homebrew sample ROM is included, but if you want to run commercial ROMs you'll need to add them yourself. Concatenate (join) together the Hu-Boy ROM stub + the GB ROM to a new .pce/.sgx binary for the SuperGrafx ROM version. For the PCE-CD ISO version, you'll need to concatenate the Hu-Boy ISO stub + the GB ROM + filler bytes to make a proper-sized .ISO file. (I've included some example scripts for Windows computers to make the job a little easier.)

Controls:

Once the emulator starts up, you can control the game using the PCE's joypad, I+II buttons, etc. just as you would control the GameBoy with its pad, A+B buttons, etc. Holding Select and pressing RUN on the PCE controller brings up the options menu that lets you adjust timings, the palette, and so on. More about this menu below.

Explanation of menu options

By holding Select and pressing Run, you'll enter the options menu. Use the joypad Up/Down to move the cursor to the different options. For options that have an ON/OFF switch or a number to adjust, pressing Left/Right adjusts those values. You can press the I button to exit the menu at any of these options.

Continues the emulator where it had left off. (You can also press the control pad Right or Left here to go to the right-hand column of options.)

Adjusts the (very rough) number of instructions executed on the emulated GameBoy for each scanline. Hex '2A' would be more or less accurate to the real hardware, but that would make emulation very slow. You can of course set it almost to whatever you want. A very low value speeds up the frame rate quite a lot, but remember that this starves the running GameBoy of CPU cycles, meaning it could freeze or stop rendering sprites/graphics.

Many games which have scrolling effects on each scanline will need to have the "Scanline Length" setting put up higher than default for these effects to appear correctly.

There is a separate setting for scanline length during the 10 VBlank scanlines of the GB hardware. This time is less crucial to actual game speed and is more important for running the game logic, so keeping it at a high value has its benefits.

With this setting ON, the emulator will attempt to emulate split-screen scrolling effects that a large number of games perform. It's not perfect, but again, it helps if a game clearly needs to have some part of the screen scroll at a different rate from other sections.
HSync OFF
HSync ON
HSync OFF
HSync ON
With the above HSync scroll setting OFF, you can choose a global screen position from which the background will obtain its scrolling values. This can simplify game rendering and speed up emulation a bit if a game doesn't need its split-screen scrolling effects emulated.

This setting emulates the 2nd tile layer on the GameBoy called the Window. This is not the hardest task on the SuperGrafx with its two tile layers, but it has to be simulated in a single background layer on the regular PCE, with several limitations. If the Window emulation is badly affecting gameplay, you can turn its emulation off.

The "Hide Window" option disables this emulation if the Window is scrolled beyond a certain pixel value to the right. This is useful on the PC-Engine in cases where you want the Window emulated (and blocking the regular background) only when the Window is taking up most of the screen anyway.

More about these settings later. ***

This option skips the N*ntendo-like GB scrolling logo on game boot. Enable the logo if you want a more nostalgic experience, I suppose.
Most of the GameBoy sound channels are emulated in a rudimentary way, but if you don't like what you hear, you can turn the sound off.
Pressing the I button on this menu option resets the GameBoy.
This option sets the PCE/SuperGrafx background resolution to 256 pixels wide, revealing what is usually masked on the right edge of the GameBoy's screen. It breaks authenticity, but in some titles like scrolling games it might be interesting to see what is loaded off-screen.

The GameBoy has certain hardware features that the PCE doesn't, like two different 32x32 tile backgrounds (BGs) that can be switched at any time onscreen (the PCE can't switch them mid-screen.) Usually Hu-Boy will try to emulate the BG that is set by the game at start of screen drawing, but if this causes the wrong BG to be displayed, you can set the BG source manually with this option.

This option again breaks authenticity, but if you want to see what graphics get loaded in when a game has blanked its screen or set its palette all to white, you can turn on this option.
   
Finally, you can set the Background, Sprite Palette 1, and Sprite Palette 2 to use any of the eight different palette sets, to alter the game graphics to your liking.

That's it for the basics!

Feel free to play around with this program, run your favourite games or demos with it, and see if they are playable or not, if they crawl or glitch out or whatever! Remember to have fun, and if you have any questions, feel free to contact me (Chris Covell) at this address.

I also made a YouTube video demonstrating Hu-Boy!


LINK HERE


 

Tech Extras

*** What's all this about a Window layer... thing? ***

The GameBoy has two independent background layers, one of which (the Window) can overlap the background in a limited fashion -- no transparency, and the Window can be scrolled in a rectangular area starting at the bottom-right corner of the screen... is a simple way to explain it.

On the SuperGrafx with its two scrolling layers, GB Window emulation can be done more or less accurately. On the regular PC-Engine with its single scrolling layer, the GB Window has to be "simulated" by having the single background do double-duty. This means the Window emulation is less than perfect on the regular PCE. Well, both systems have their limitations, as you can see below.

Example one: GB Test Program (included with Hu-Boy)

on real GB Hardware
on Hu-Boy SGX
on Hu-Boy CD
Notice how the screen has basically 3 regions: the top half with no Window layer, the bottom left where there is no Window layer active, and the bottom right, which is where the Window is set to appear starting at hex (44,32).
The SuperGrafx can show both the GB Background Layer and Window Layer properly, but with the limitation that sprites cannot be shown where the Window Layer is.
The PC-Engine cannot have 2 overlapping backgrounds, so the Window is simulated, with the limitation that the Window can only start at a vertical position. Horizontally, the Window will wrap around to the whole screen width.
Another limitation on the PCE-CD is that when the GB's background is scrolled vertically, a portion of the 2nd BG (9C00) might appear incorrectly (top of screen).
How the GB hardware overlays the BG Map, Window Map, and Sprites, then shows a portion of it in its 160x144-pixel viewport

Example two: Mega Man 2

on real GB Hardware
on Hu-Boy SGX
on Hu-Boy CD
(real PCE hardware capture)
Hu-Boy CD on MiSTer /
Mednafen emulator
The boss you selected jumps as a sprite into the centre of the screen.
The SGX version has a limitation where the Window layer blocks the view of sprites.
Not game-breaking, but watch out sometimes.
The CD version's simulation of the two layers actually looks good on this screen.
This is a video capture from real PCE+CD hardware because...
Beware that running Hu-Boy CD version in most PCE emulators or on the MiSTer FPGA actually produces incorrect results, with the simulated Window merely doubling the BG layer!
Mega Man 2 on the GameBoy uses the BG to display the upper two robots, and the Window to display the lower two.
They scroll independently off-screen when you select a robot boss.

Example three: Amazing Tater

When you bring up the option menu in this game, a panel srolls on-screen from the bottom-right using the GB's Window layer. You can see how it overlaps a portion of the GB's background.

Hu-Boy SGX, showing the panel correctly (minus a missing cursor sprite):

By the way, here's a what you see if you run Hu-Boy CD on an emulator. Real PCE hardware (or an SGX) is recommended.

(Mednafen / MiSTer incorrectly doubling the GB's background where the Window map should be)
->
->
->
Hu-Boy CD (real hardware capture):
->
->
->
Obviously, here's a case where the simulated Window layer on the PCE-CD version displays unwanted graphics to the left of the Window.

Last Example: Using the "Hide Window..." Setting

Several games use the Window Layer to show a panel that slides on-screen, but Hu-Boy CD version can't normally show both the Background and Window side-by-side. Thus, if the Window is really distracting for you, you can set a horizontal limit so that Hu-Boy CD will hide the Window until it moves to the left of this limit.

 

   
With the default setting, the Window layer might show glitches as it scrolls, or otherwise completely block the BG layer in the CD version of Hu-Boy
Hide Window past Pixel: $A7:
(extreme right of screen, so Window is always shown)
->
->
->
(Image on real Game Boy)
   
By setting the pixel value lower (as below), the Window stays away until it is fully on-screen.
 
Hide Window past Pixel: $08:
(near left edge of screen, so Window is hidden unless fully to the left)
->
->
->
               

 

©2023 Chris Covell.  Please send comments or feature requests here!