News for hackers. Stuff that matters.
Re:Show HN: Simple Gameboy Emulator by flohofwoe on Saturday December 30, 2017 @06:51AM (#16034895)
For Z80 emulation the most efficient method I found was indeed a big nested switch-case statement. Compilers turn this into a jump table (or several if there are gaps), but don't need the function entry/exit boilerplate if each instruction code block would be its own C function referenced through a function-pointer-table. The switch-case code is generated with a python script which uses the 'algorithmic decoding approach' described here: http://z80.info/decoding.htm

Here's what such a code-generated instruction decoder looks like: https://github.com/floooh/chips/blob/master/chips/_z80_decod... (this is for a "real" Z80 with all undocumented opcodes, so it has a lot more cases to handle than the simple Gameboy Z80 variant).

Re:Show HN: Simple Gameboy Emulator by deaddodo on Sunday December 31, 2017 @03:04PM (#16042558)
C macros would just take the place of your python script. It's literally the exact same idea.