0

I'm new here. Let me know if this is the wrong place to ask this kind of question.

I'm planning to build a Gameboy emulator. Before I start, I want to have a clear understanding of the startup behaviour of Gameboy, to ensure I implement it appropriately in my emulator.

The below is how I understand the startup process, and intend to implement it in my project.

Startup behaviour (no cartridge is selected):

  1. Load and read the emulator's configuration file to determine if the emulator is in debug mode or not, the size of its LCD display, etc. Change emulator's internal settings.

  2. Set up GUI and the blank graphics display.

After a user selects and loads a cartridge into the emulator:

  1. Read the cartridge header and configure the emulator's internal settings. Emulation will be stopped (the graphics display will be blank) if the cartridge requires unsupported hardware.

  2. If the boot ROM is not enabled, set the program counter to $100 and skip this step. Otherwise, run the boot ROM. Emulation will be stopped if the Nintendo logo in the cartridge is invalid. The boot ROM will be locked automatically after the last instruction executed. The program counter is then set to $100.

  3. Set the register values according to this documentation.

  4. Begin emulation loop.

Before shutdown:

  1. Free any memory.

I want to make sure there is nothing wrong with my understanding. Are there any problems? Did I miss anything important that the physical Gameboy would do?

Thanks in advance.

14
  • 3
    This might in fact be the wrong place. RC.SE is about the real old stuff and its behaviour. In contrast your question seems not to ask about the Game Boy or its working, but how your modern time program's sequence of action. Arqade might be a more appropriate to help with that.
    – Raffzahn
    Apr 11 at 2:42
  • 2
    @Raffzahn I'm not sure about this place. It focuses mostly on gaming. I doubt if there are any people there knowledgeable on emulator development.
    – Jimmy Yang
    Apr 11 at 2:54
  • Definitely not the right site for this question, also I'm not even sure it's really an emulator-author question, being primarily about the wrapping. That said: (i) you might consider using this copyright-free boot ROM replacement rather than writing a high-level version, just because it's less for you to do; and (ii) I learnt about that here.
    – Tommy
    Apr 11 at 3:39
  • 2
    To me, this is not a question how an old retro hardware works, in order to make a new and better emulator, or to emulate a certain behaviour properly. This is more of a question how a new emulator and UI should be designed in general to run user selectable games. And my opinion is that it is a completely auxiliary function of emulating the actual hardware. The emulator can freely implement the UI and emulation in any way they like really.
    – Justme
    Apr 11 at 9:31
  • 1
    It's an interesting case. On the face of it, the question's blatantly off-topic. However, it's important for an on-topic subject, and we're the best-equipped Stack Exchange site to answer it; it's tempting to frame this as a purity / pragmatism issue (though that's probably a bad idea).
    – wizzwizz4
    Apr 11 at 11:30
2

Putting aside my concern that this question perhaps isn't ideal for this site (on the basis that the limited close votes so far suggest that I might be wrong about that), this answer is community wiki because it's a bit vague and waffling, and adjustments might be useful.

  • You can implement the UI side of things however you like. Personally I try to make the emulators I write perform as identically as possible to regular desktop software on their target platforms.

    So maybe there's a config file, maybe you're using the Registry for the user defaults; standard behaviour is probably to load a data file (in your case a cartridge image) via File → Open…, by drag and drop or via the command line, and of course you should return any allocated resources to the system upon shutdown if your programming language leaves that responsibility to you.

    There's an alternative school of thought that emulators should be more like iTunes-esque media browsers with an import procedure leading to a catalogue of the user's titles; if your target were a device more likely to be used in the manner of a media player — typically, on a big screen that you sit a good distance from, with something more like a controller or a remote control than a keyboard and a mouse — then you might consider that.

  • As for the Game Boy and its boot ROM, you seem to be fully aware that there are copyright-free alternatives meaning that you don't need to implement your own at all: just put your hardware into the correct startup state and let it run either the original or the replacement (if the user hasn't supplied a copy of the original). If you want to include a high-level emulation of the original too, then obviously you can subject to it being one more thing to maintain.

    There's a full disassembly of the original here. From glancing at it, it looks like the VRAM is zeroed and then loaded with a copy of the Nintendo logo, which has been scaled up to 2×2 its original size and is available in the cartridge images, the scroll and the sound effect occurs, then the boot ROM is disabled as the final act before the PC rolls up to $100.

Not the answer you're looking for? Browse other questions tagged or ask your own question.