Cycle-accurate 6502 emulator as coroutine in Rust
github.com·8h·
Flag this post

Motivation

A simple CPU emulator generally looks something like this:

while (1) {
switch (code[pc++]) {
case OP_ADC: {
// execute add with carry
}
case OP_HLT: {
// terminate execution
break;
}
// cases for other opcodes ...
}
}

Details may vary, like using a lookup table instead of a switch statement, but the key thing is that each instruction is implemented by a section of code that is a direct interpretation of its semantics, which makes it easy to write and understand.

But there’s a big downside: the timing details are abstracted away. Each instruction executes all at once, unlike in real hardware where it proceeds through a series of states over multiple clock cycles.

This can be a challenge when integrating the CPU in a larger system in which it has timing-sensit…

Similar Posts

Loading similar posts...