Galaga Emulator3/27/2021
Tiles are used for all the text that appears in the game, like the score; the content of each tile (a bitmapped font) is read from a ROM.When I was a kid I must have spent so many coins to play that game that I could probably drive a Ferrari, today, had I better invested them.
By emulation I dont mean writing a game just like Galaga (which would not be a trivial task, anyway) but really emulating the hardware of that old arcade machine in all its details: the original ISA we want to emulate is those of the old Z80 processor and the program we want to run is the one stored in the original ROMs. Of course I knew that MAME and MESS already existed, and I snooped through its sources to find out how that machine actually worked. For this reason I chose to use first Silverlight as host, a platform that looked very promising at the time. Galaga Emulator Code From CAfter that I quickly ported the code from C to C (even to see what the speed-up could be) and made it run as a WinRT app, more recently converted into a UWP app for Windows 10. ![]() But more recently I discovered the wonderful world of Emscripten and I wondered: how difficult can be to make the engine REALLY PORTABLE, compiling it to JavaScript and targeting HTML5 And can JavaScript run fast enough to emulate an arcade machine Its what we are going to discover In this blog post Ill present a few technical notes on this toy project, a small journey from the initial idea to the final HTML5 implementation. There were three Z80 8-bit processors, which shared the same address space and RAM, but executed each a different program, stored in a set of different ROMs. Other ROMs contained the graphics (sprites and a tiles) and the audio waveforms used to generate sound effects. In Galaga the interrupt handler managed a vector of commands with a jump table, so the main CPU could invoke a procedure on one of the other processors simply by setting the index of a command in a location in shared memory and signaling an interrupt. There was one just to handle the graphics effects of the star-field in the background, others were used to to render the graphics, to manage the input controls and to produce the sound effects. All the pieces must be connected as they were in their circuit board; and for this we need to find detailed information about the original schematics. Luckily, besides MAME, there are a numbers of sources for this info in the Internet. Galagas popularity meant that there has been a great deal of low-level hacking over the years. For example, someone entirely disassembled the 24K bytes of Z80 code from its ROMs ( 1, 2, 3 ) to the point of being able to find the root cause and fix the famous bug that made the alien bees stop firing after a while. ![]() The emulator, of course, should run in real time, so it is important that the emulation of the Z80 instruction set should be performed very efficiently. ![]() In other words, we want to emulate 10 msec of machine time in less than 10 msec). The most efficient one is binary translation, which converts whole blocks of a source program into a customized binary program in the target ISA. A much simpler technique is the decode-and-dispatch interpreter, which works by fetching one instruction at the time, analyzing and executing it and modifying the source state. Even so, this turns out to be the most computationally expensive part of the emulator, so its important to optimize carefully this code. This is not the whole story: some of the other chips are also memory-mapped, so the CPU instructions used to access the memory can also be used for accessing these devices; the emulator needs to take care of all this, managing the mapping of addresses into the right device. Our emulator, of course, must also take care of this port-mapping. The screen (of 224 x 288 pixels) was managed as a tilemap of 88 characters, and the graphics system also supported up to 64 sprites that were rendered above the tilemap. In the original, there is a custom chip to move and draw the stars; its behavior needs to be replicated.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |