4 ms·
I made something similar for the Z80: https://github.com/ggambetta/libz80 https://github.com/ggambetta/libz80 The interesting thing is that I wrote very little
by ggambetta 13y ago
I made something similar for the Z80: https://github.com/ggambetta/libz80 https://github.com/ggambetta/libz80
The interesting thing is that I wrote very little of the code by hand; instead I wrote a program that generates the opcode implementations from a concise specification. The end result is remarkably compact, and the whole thing was really fun to make.
- csmuk 13y agoNeat solution - really like that. Great work.
- userbinator 13y agoA little hint for improvement: condition() could be implemented as a switch instead of a long if-chain. Did you use this for generating the opcodes? The Z80 ISA encoding is quite regular and octal-based: http://www.z80.info/decoding.htm http://www.z80.info/decoding.htm
- ggambetta 13y agoThanks for the reference! This was a long time ago but I think I didn't use that decoding table. Just a couple of days ago I was reading about the x86 one, I really wasn't aware that opcodes were anything but random bytes mapped to operations. As for the improvement, I never liked switch, for unknown reasons :) You mean an improvement in style, performance or both?
- userbinator 13y agoThere's always a pattern to the opcodes, even though in some cases it's not quite so obvious (like x86 - it's octal too). The reason has to do with how it's implemented in hardware. The 6502's is only slightly less regular than the z80 and here's an interesting article about that: http://www.pagetable.com/?p=39 http://www.pagetable.com/?p=39 IMHO the switch would improve both style and performance, what caught my eye when I looked over the code was that different flags would require different amounts of time to execute, which really seems an odd thing for an emulator to do.