I like emulators…
As many folks who like tech, I enjoy emulators. Most recently, I am working on one that does its best to emulate the Intel 8080 chip, mostly because I came across a Space Invaders ROM and wanted to play that. The choice to tinker with these things was also because I wanted/needed an “excuse” to write some “real-world” Rust code for a project. In my day-to-day life I write a lot of Java, big-data stuff, and other crap. However, being the only person on a team who knows a language (like Rust) is not a very production-friendly behavior. Enter: emulation.
Actually
Before I get into rambling about how much I enjoy reading chipset specs, I wanted to note: A cool way to learn a new language is by doing the problems at Project Euler. Start with problem 1, with the language you’d like to learn, and do as many as you can. They come in what I consider, “mini-spec” form - with things you might see in the real world. Plain English “do this and figure out that”, sometimes with examples, etc. I love it. It’s how I learned Ruby many years ago.
Chip-8
Initially I had started with a Chip-8 interpreter. You can find the source for that on my github page, here: https://github.com/sullivant/rust-8
8080
Continuing on this, I felt that the UI I had chose for Chip-8 would not be as performant as I needed for an 8080. This is, mostly, because I likely suck at performant code. So, for this one I chose egui. I found it quick, snappy, and easy to get detail up and running.
I mean, look at this crappy main loop - I need to spend some attention to detail on timing, when I finish all the little opcodes:
// Create a thread that will be our running cpu
// It's just gonna tick like a boss, until it's told not to.
let cpu_thread_handle = thread::spawn(move || {
while cpu_alive.load(Ordering::Relaxed) {
match cpu_thread.lock().unwrap().update() {
Ok(_) => (),
Err(e) => {
println!("Unable to tick: {e}");
break;
}
}
// TODO: Make some form of cycle based speed regulation
}
println!(
"Shutting down. Final CPU state:\n{}",
cpu_thread.lock().unwrap().cpu
);
});
You can see the current position of my 8080 code here: https://github.com/sullivant/eightyeighty.