Cursory Questions with regards to developing an Emulator

Discussion of programming and development for the original Game Boy and Game Boy Color.
Post Reply
hking0036
Posts: 4
Joined: Wed Oct 12, 2016 4:54 pm

Cursory Questions with regards to developing an Emulator

Post by hking0036 »

Hey there,

I'm a Junior CS Student, and as part of our senior year in our program we have to develop a capstone project which is sort of free-form in nature, the professors let you pick it and set your own goals within reason and they let you know how the scale seems as you go. In our Computer Systems class, we are writing a simulator for a toy architecture (Y86-64) and picking it up as we go. Truthfully this systems stuff speaks to me much more than some of the theoretical stuff does, and I think it would be more exciting to work on a serious application than some webdev stuff.

I figured, then, that maybe the next step would to attempt to simulate a z80, and maybe make a really basic GB emulator - nothing super functional, just enough to load a test rom with my teammate. With that in mind, I have some questions - and sorry, truthfully I have not done a ton of research into this, but I'm a year out so my plan was to move forward with that after I got at least some input:
  • For those who have dabbled into this, is it even feasible to do granted fairly limited embedded systems knowledge?
  • If it is feasible, is one college semester (about 15 weeks) a reasonable time for a team of two to work on it?
  • Is the pipelining process for a z80 complex/if we wanted to keep our project smaller-scale could we sacrifice the pipeline and go for a sequential approach or would that just break everything?
  • My professor's greatest concern when I approached him with this idea was that he couldn't come up with a way to test our progress off the top of his head. What sort of milestones would be feasible?
  • Following that, if we don't have a functioning display draw, how can we implement meaningful debug to ensure that we are progressing comfortably?
  • As someone with limited LinAlg knowledge, would it be really difficult to implement the GPU?
  • Would it be more reasonable to just go with a more standard z80, or to step down to something else entirely?
Thanks in advance for the help, hopefully I'm not brutally ignorant on this.
mid-kid
Posts: 1
Joined: Thu Mar 05, 2020 12:29 pm

Re: Cursory Questions with regards to developing an Emulator

Post by mid-kid »

I've never developed an emulator but as an initiated GB dev I can give you my 2ct.

The Gameboy is one of the simplest embedded systems I've encountered. This kind of comes with the era, but the gameboy simplifies some things by exposing the cartridge, on-board memory and I/O registers in the same address space. It lacks a _lot_ of what is now common on embedded platforms, like memory management and half a ton of peripherals. In fact, the entire system can be described in this relatively small (compared to your commonplace microcontroller/modern console) document: https://gbdev.github.io/pandocs/

Now, as for making an emulator, it's very hard to make an accurate emulator, due to all of the quirks in the system that some games rely on, but for example emulating the CPU inaccurately should be easy. There's no "real" pipelining going on (seasoned emudevs will tell me otherwise, but it doesn't really have a noticeable effect), and the instruction set is simple and concise. There's some interrupts that come with the peripherals (vblank, serial, joypad, timer), but nothing really fancy going on. Some peripherals are more complex, specifically the PPU (this system has no GPU) and the APU, but you can either implement them naïvely or just omit them, and pick what you need to make your programs run. You certainly don't need much (if any) Linear Algebra for the PPU, it's a pixel plotter that doesn't do any transformations.
I think it's completely feasible to emulate simple programs that use a couple of peripherals in 15 weeks, maybe even some commertial games, but it depends on how quickly you go through it.

As for testing your progress, there's many ways you can read state, or handle input/output through your emulator. You can just tell your emulator to stop at a certain instruction and output some state, or read some memory, or implement some kind of input/output register, like the serial (link) port or even abuse the way the joypad register works like what the Super GameBoy does. The possibilities here are endless but I'd just start making small programs you can essentially unit-test your emulator with, and then expand to some more interactive things.

In the end it kind of depends on what you're trying to do. Are you trying to emulate a Gameboy, such that whatever you write for it runs on the real thing (assuming it's a correct program), or are you making your own custom thing based on it? There's some differences between z80 and gbz80 that might be worth researching if you intend to just emulate your own toy system.

To end this post, I recommend you watch this video: https://media.ccc.de/v/33c3-8029-the_ul ... e_boy_talk
It pretty much gives you a rather in-depth overview of the entire system in an hour-or-so, and will clarify as to what you're getting into.
hking0036
Posts: 4
Joined: Wed Oct 12, 2016 4:54 pm

Re: Cursory Questions with regards to developing an Emulator

Post by hking0036 »

Thanks for the input!

I'm not looking to be especially accurate, seeing as we are going to be both time-constrained and coming in very fresh to it. If we can avoid the pipelining process I think it will expedite what we are trying to accomplish a lot (and, we could come back to it if we had the time later on). The PPU is what is most scary to me, but if it really is as simple as you say it is then it may be worth taking on. I almost feel like even though the GBz80 is non-standard, it is probably better documented online or at least more accessibly than the original just because of how much grassroots support there is for it.

At the end of the day, I'm not trying to create a cycle-accurate gameboy emulator as much as I just want to be able to show that I can implement something on this scale. My personal end goal will be to have Tetris work, but even just a basic test rom drawing on the screen is more than enough, I think. In doing so, I can skip out on all of the MBC mappers except for probably MBC1 and I think that will help to keep it a manageable size.
Post Reply