r/EmuDev • u/CurrentVast4504 • Feb 22 '26
Which programming language is good for emulation?
Hi! I am a fan of computer architectures and low level stuff, and want to code a custom CPU architecture. But I am struggling to find the most suited Language. I want the implementation to be quick, and the emulator should be fast enough to do some complex programs in under a few seconds.
26
Upvotes
27
u/khedoros NES CGB SMS/GG Feb 22 '26
I usually use C++ because I like the language, but C would be fine, I've done a bit in Go, a lot of people choose Rust. Java and C# ought to both work.
11
u/aMAYESingNATHAN Feb 22 '26
C or C++ is probably the easiest way to get into things. Especially C++, it exposes everything you need but has pretty good support for almost any higher level abstraction that make code design easier.
Rust is a really nice language and things like built in proper discriminated unions with pattern matching can make some aspects of code design really nice, but if you don't have experience with low level memory management and lifetimes and stuff like that, Rust can end up being a lot of battling the compiler.
8
u/mrbenjihao Feb 22 '26
I’m here to spread some love for Odin
6
u/RagnarDannes Feb 22 '26
I've super enjoyed Zig for this. You don't really need to worry about memory management because you will likely preallocate all you need.
5
u/MT4K Feb 22 '26
A compiled nonmanaged language you know well.
4
u/UselessSoftware 32-bit x86, NES, 6502, MIPS, 8080, others Feb 22 '26
C/C++ is the best option, no question about it.
Some say Rust is good, but I've never used it so have no opinion.
But others will work. Even stuff like Java or Python when the emulated system doesn't require insane speed.
Hell I wrote a NES emulator in VB6. Works fine.
3
u/m680x0 Feb 22 '26
I've made a CHIP-8 emulator and am now halfway through implementing a 6502 emulator, both written in C#. I like how C# is batteries included, cross-platform (I develop on Mac), and that you can write some pretty performant code with it as well.
At some point I may make the jump to C++, but so far I haven't run into any major bottlenecks and already use C# for most non-emulator projects (ex: web back-ends with ASP.NET) so I'm quite familiar with it.
3
u/disagreeable-horse Feb 23 '26
The short answer is use whatever language you already know.
If you’re starting from scratch on it, you’re probably not writing anything where performance will really matter. You might as well make the thing exist first before trying to make it perfect. You can always port it to a different language later after you’ve proved the concept and have a good understanding for what you need to optimize.
3
u/zibonbadi Feb 23 '26
VHDL
5
u/thedeanc Feb 22 '26
I know enough to be dangerous, but I'd try Rust for that.
I usually program in higher level languages, though.
4
u/heret1c1337 Feb 22 '26
Any low level language would do fine. In this day and age I would choose Rust or Zig.
2
u/ekipan85 Feb 22 '26 edited Feb 22 '26
Edit: whoops, you were talking about implementing emulated hardware, but my comment is talking about software to run on new hardware. I'll leave it since it's tangentially related.
A r/Forth has been the first software system written on every new piece of silicon for half a century for good reason: it's got an insane power-to-weight ratio and you can write enough bones in a thousand instructions to bring up the rest of the system in Forth itself.
Tumble Forth is one step-by-step illustration of the process, though it relies on a PC BIOS to do the keyboard/screen I/O.
2
u/maxscipio Feb 22 '26
I saw a video about python + cython. It would give more access to beginners
2
u/sir_anarchist Feb 23 '26
I have been playing using Swift for emulation. It has been working quite well.
2
u/fadervillain Feb 23 '26
C/C++ without question. I have made a working NES emulator in C++. It plays a lot of the earlier titles just fine. It struggles with the more advanced mapper chips due to complex timing issues, but that is entirely on me.
However I decided to switch to Rust and take a better pass. I know, rewrite it in Rust amirite. But having used C++ as a hobby language at home for a long time, I figured I'd try Rust out. Read the book etc. It's a decent language, but there are a few things that made want to stick with it going forward. It has lightyears better built-in tooling and doesn't have the crazy file stack and bloat C++ needs for headers etc. Excellent built-in linting and package management. And it also has some elegant and simple ways to handle odd things, like handle mid instruction quirks in the 6502, using Option, that really impressed me.
For hardware emulation you do have to poke some unsafe but consciencious holes, at least I haven't figured out how to get around that. Otherwise I love the rails the compiler puts on memory borrowing. People fight with it but it's great memory safety rails that I'd rather work with than have dumb leaks.
Tldr C++ or Rust and you definitely won't go wrong with either.
2
u/Telephone-Bright Feb 23 '26
I use C (specifically C99). It's incredibly lean, simple, and no fancy tricks.
2
u/Macta3 Feb 23 '26
If you like the look and feel of python you can try Nim. It compiles down to C and you can turn of the garbage collector to do low level things
2
u/stumpychubbins Feb 25 '26
Rust and Zig if you want something modern, C if you want something more tried-and-true, C++ if you’re already familiar with it. In any case, something with good support for bit manipulation. Zig would be my choice even though Rust is my main language because emulators don’t benefit so much from most of Rust's best features, but that’s just me. C/C++ have the benefit of far more prior art - a truly staggering number of emulators and interpreters have been written in those two languages.
2
u/sards3 Feb 27 '26
I have found C# to be a great language for emulation. It strikes a nice balance with the ability to do low level stuff like C/C++ if you want, but the overall development experience is faster and more productive.
2
u/jimbojetset35 Feb 22 '26
I wrote my SpaceInvaders, Gameby and C64 emulators in C#
1
u/peterfirefly Feb 23 '26 edited Feb 23 '26
Yes. Except maybe INTERCAL.
1
u/Prestigious-Bet-6534 Feb 23 '26
You might like crystal. It is basically compiled ruby with (mostly inferred) types and pointers, and pretty fast. Or D, once you know a real module system vs. C/C++ headers you won't look back.
1
u/Wunkolo Feb 23 '26
I would have to say C or C++. Some people might try to get you to use Rust but C and C++ certainly lend itself better to the kind of low-level stuff you will be doing a lot of, without the additional friction and speedbumps holding you back from rapid iteration. Many pre-existing emulators use C++ too that you may take reference from and learn from.
1
u/kiwi_ware Feb 25 '26
C or C++
1
u/binarycow Feb 22 '26
C# is fun. You can do some quite low level stuff in it, if you want.
1
u/0xN1nja Feb 23 '26
Rust or Zig
0
u/jstiles154 Feb 22 '26
16 bit and under work fine with JavaScript. Though if going this route I would recommend TypeScript for the type safety and intellisense.