News for hackers. Stuff that matters.
Re:“Holy Grail” Bugs in Emulation, Part 2 by jkarneges on Sunday August 27, 2017 @03:00AM (#15109528)
It didn't occur to me until I was developing a Game Boy Color game to understand just how difficult it would be to create an accurate emulator.

For Infinity (https://news.ycombinator.com/item?id=12291850) we employed a number of tricks, notably changing video parameters mid-render. For example, when walking around on the overworld, the screen looks tilted. This was done by adjusting the camera's X offset after each scanline.

Before this experience, I would have thought all an emulator needs to do is emulate the CPU, and render video frames as fast as possible based on video memory. Instead, the GPU needs to be fully emulated too, drawing pixels from top to bottom and left to right, at exactly the rate expected of real hardware and in sync with the CPU.

Speaking of hardware tricks, one neat thing we discovered during development was that if a cartridge isn't present, then reading from the ROM memory area returned zeros. This was possible to do if your code was running from RAM and could survive a cartridge being taken out while it was running. This only worked with Game Boy Color (and not original Game Boy) because Nintendo removed the safety lock from the power switch. There is actually code in Infinity to do something with this, although it is unfinished. Just another ridiculous thing emulator authors would have to support somehow. :)

Re:“Holy Grail” Bugs in Emulation, Part 2 by digi_owl on Sunday August 27, 2017 @03:30AM (#15109597)
The GBC is basically a handheld NES. And changing parameters mid-scanline was a trick on various microcomputers as well (i think it was used on the Amiga to push up the number of colors you could use by swapping the pallette).

And i am not surprised that a non-cartridge would read zeros. I suspect the GB(C) was set up somewhat similar to the C64, where the cartridge connector on the back was basically wired to certain RAM pins on CPU.

Re:“Holy Grail” Bugs in Emulation, Part 2 by jkarneges on Sunday August 27, 2017 @02:41PM (#15112006)
What surprised me was that the GBC didn't abruptly crash.

For something as critical as a memory chip going missing I would have expected either an abrupt halt due to inconsistent circuitry, or a halt on the next read to the ROM's addressable memory. That the CPU instructions would gracefully fall back to interpreting memory as zeros was unexpected to me. Although I don't know much about electronics.

Do you think this would work on other consoles, such as the NES? Given how finicky the NES is about the cartridge loading mechanism, I would think that cart removal while a game is running would cause the system to go into that panic mode with the power light flashing.

Re:“Holy Grail” Bugs in Emulation, Part 2 by eru on Sunday August 27, 2017 @12:44PM (#15111502)
> The GBC is basically a handheld NES.

Do they just have roughly comparable computational power--or do they actually share some chips?

Re:“Holy Grail” Bugs in Emulation, Part 2 by eropple on Sunday August 27, 2017 @01:21PM (#15111645)
The GBC is a significantly more powerful machine than an NES, with some caveats around graphical rendering.

The NES is a MOS 6502, the GBC has a weird chip by Sharp that hybridizes a Zilog Z80 and an Intel 8080 clocked about double in Game Boy mode and quadruple in GBC mode. The GBC also has sixteen times more RAM, eight times more VRAM, supports bigger carts (up to a megabit), and twice the palettized colors on screen, albeit with marginally fewer sprites.

Huge difference in hardware--the primary reason the GBC is looked at as being "NES-like" is because of the lateness of its release and the comparative jump to the GBA, which is a recognizably modern ARM environment.

Re:“Holy Grail” Bugs in Emulation, Part 2 by khedoros1 on Sunday August 27, 2017 @01:43PM (#15111742)
They don't share chips, and the GBC should be much more powerful than the NES.

The NES had a CPU based on the MOS Technology 6502 running at around 1MHz, 2KB of RAM, 2 screens of video tile memory, and 2 sprite layers, with support for 64 sprites, max of 8 per line.

The GBC had a CPU loosely based on a Z80 running at about 4 or 8MHz, 32KB of RAM, smaller resolution, more colors available (and more displayable on-screen at once), fewer sprites (40), but more displayable on one line (10).

Re:“Holy Grail” Bugs in Emulation, Part 2 by eropple on Sunday August 27, 2017 @02:43PM (#15112016)
> CPU loosely based on a Z80

Emphasis on "loosely". It's a weird thing.

https://realboyemulator.wordpress.com/2013/01/01/the-nintend...

Re:“Holy Grail” Bugs in Emulation, Part 2 by digi_owl on Sunday August 27, 2017 @02:04PM (#15111854)
Sorry, i didn't mean it in technical terms.

But as best i understand it, the basic conceptual design of the GB/GBC and the NES is pretty much the same.

Neither device do much if anything without a cartridge inserted. This unlike say a modern game console that have quite elaborate firmware that loads even without any game media present.

Re:“Holy Grail” Bugs in Emulation, Part 2 by eropple on Sunday August 27, 2017 @04:48PM (#15112633)
Can't speak to the NES, but the GB/GBC definitely has a boot ROM with firmware that remains operable without a cartridge in the system. (The SGB has a different one that shims into the slightly different SGB hardware itself. Also, if you've never read about the SGB, that thing is kind of wacky; it's basically a Game Boy that delegates colorization and, in some games, audio and multiplayer to the Super NES.)

The GB/GBC boot ROM doesn't do as much as even, say, the GBA, but if you're talking "conceptual" about firmware, we're talking about a pretty unbroken line to the current day. (Modern game consoles also have operating systems, but those aren't firmware.)

Re:“Holy Grail” Bugs in Emulation, Part 2 by eru on Sunday August 27, 2017 @06:13PM (#15113113)
The Super Game Boy was kind of gimmicky. I remember playing with it at a friend's house.
Re:“Holy Grail” Bugs in Emulation, Part 2 by eropple on Sunday August 27, 2017 @11:25PM (#15114228)
I had one as a kid. You could tell it was "too fast". Weird stuff.
Re:“Holy Grail” Bugs in Emulation, Part 2 by eru on Tuesday August 29, 2017 @05:50AM (#15123186)
I never noticed that. But our SNES in Europe ran at different frequencies from the American anyway.
Re:“Holy Grail” Bugs in Emulation, Part 2 by gens on Sunday August 27, 2017 @01:47PM (#15111766)
Interesting talk: "The Ultimate Game Boy Talk" at CCC https://media.ccc.de/v/33c3-8029-the_ultimate_game_boy_talk