5 ms·
My unpopular opinion is to emulate an extremely reduced subset of x86. For example, jump to main and emulate the result of `int main() {return 2;}` compiled wit
by eatonphil 5y ago
My unpopular opinion is to emulate an extremely reduced subset of x86. For example, jump to main and emulate the result of `int main() {return 2;}` compiled with gcc. You already have the compiler (no need to cross compile), you already have the decompiler and you can run the binary on the reference machine without an emulator. You save so much time having this entire toolchain already and you can start emulating simple C programs for x86 with <10 instructions and 1 or 2 addressing modes. I've written about this process before in Node and Go [0].
Yeah everyone will comment after me that x86 gets way more complex over time but if you just want to get a quick intro and you aren't a perfectionist x86 is kind of compelling.
And recently I wanted to try emulating MSP341 at someone's recommendation because it has a very simple architecture. But just getting a C compiler for it isn't easy! When I've tried to cross-compile C to other archs like RISC-V it also wasn't straightforward and I just got stuck in this toolchain spot.
If it were easier to cross-compile simple languages like C then writing emulators for other environments would be easier.
If you're on a new Mac, my whole argument applies for aarch64 instead of x86.
[0] https://notes.eatonphil.com/tags/emulators.html https://notes.eatonphil.com/tags/emulators.html
- gavinray 5y agoI thoroughly enjoyed what little I read of this, bookmarked it for later -- thanks! https://notes.eatonphil.com/emulating-amd64-starting-with-elf.html https://notes.eatonphil.com/emulating-amd64-starting-with-el...
- pizza234 5y ago> My unpopular opinion is to emulate an extremely reduced subset of x86 I don't think 808x is such an unpopular machine for approaching emulation. Some people use Space invaders (or contemporary titles), which is based on an 8080, as stepping stone between CHIP-8 and more modern (complex) platforms.
- ant6n 5y agoI wish there was an easy way to compile to a subset of x86 (e.g. mem access only with simple mov, only using one flag, no extensions, no floats, pure 32bit instructions).
- eatonphil 5y agoYeah that would be even more convenient!
- dogprez 5y agoBut emulating the CPU is probably the least interesting part about writing an emulator for a video game system. Writing the other hardware components and getting them to work together is the interesting part imo. I'd say skip writing your own CPU emulator and just start with someone else's.
- eatonphil 5y agoAs a backend dev, being able to emulate my own program compiled with GCC was pretty rewarding personally. But I'm not arguing everyone must do it. Just trying to share why one unintuitive approach (the "complex" x86 architecture) might actually be easier and cooler than you think.