As stated before, 8051 is here to say. Very much like the 8086 is still alive with the newest x86-64 architecture. Since the Arduino Uno is the de-facto form factor for many things, let’s try to emulate 8051 on AVR.
Planning & Choices
Some choices needs to happen, in order to be able to scope the project.
For simplicity, I’ll focus on emulating the AT89C2051 with an ATmega328P. Those 2 chips are very good examples of each architecture, as they are now ubiquitous, thanks to 4 digit clocks kits for the AT89C2051 and the Arduino UNO for the ATmega328P.
We need to assign pins. I’m trying to keep the functionality the same, even if it means to move bits around when programming.
A major difference is to assign a specific PIN to RST for the 8051, so we can reset the emulated 8051 without resetting the AVR.
Some emulator-related PINS are also used.
I’m thinking about reusing a GPIO (PC4/SLOW) to signal that the emulation is lagging from realtime. The idea being that emulator should be running at a precise clock divider from the main clock. Prescaling as much as needed to cope with the emulation tax, and also adding as much delay as needed on the fast instructions.
If there is an instruction that is expensive to emulate, I’m planning to “borrow” delay cycles from the following fast instructions in order to be accurate on average. And have the SLOW pin to signal that ‘borrowing’ state while active.
Some enhancements need to happen, as it needs to be optimized for running on the limited AVR platform.
I’ll also leverage every hardware accelerated feature, such as the AVR USART, in order to decrease the emulation tax.
Let’s see that in another post. 😉