Open pablomayobre opened 7 years ago
I actually did consider a code generation system for opcodes, as the present z80 implementation is a bit call stack heavy, but I haven't considered writing an actual transpiler or doing a JIT. I feel like the complexity of the task (lots of games use self modifying code and copy routines around) wouldn't bring enough benefit to be worth it at the gameboy's low clock speed. The CPU isn't actually that slow, and the emulator spends a good chunk of it's time dealing with graphics and other hardware.
Apologies for the grave digging, but this is actually the approach I'm using for my PS2 emulator.
It seems to work okay for cold code, but (at least for my emulator) a trace of 50 instructions or so brings LuaJIT to its knees as it tries to generate snapshots for memory access failures/address alignment checks failing etc, and gives up. I suspect it's because my code could be significantly more JIT friendly though.
An option to speed up the execution would be to parse the Z80 machine code and turn it into lua code (horrible lua code but this doesn't matter), you could later on run this code directly with Lua.
This would allow for some transpilation optimizations and whatnot. This is not an easy job but could give better results in the far end. Maybe it would grant another project on itself.
I'm leaving this here so if someone is interested it may spark some discussion and ideas. It's not my intention to demand this feature, due to it's complexity.