Atomis Development Blog

The 4-Hour Sunday Project: Building a 6502 & Apple II Emulator

Sometimes, the best way to test the limits of your own language is to build something that shouldn't belong there. This past Sunday, I set a challenge for myself: Emulate the 6502 CPU and a basic Apple II environment within jdBasic.

With the help of Claude as a pair-programmer, I managed to go from an empty file to a booting Apple II prompt in just four hours.

jdBasic Apple II Emulation

1. The Core: 6502 Emulator (`cpu6502.jdb`)

The heart of the project is a modular 6502 core. It features a full instruction set dispatch table, status flag management, and even the famous page-wrap bug in the JMP ($nnnn) instruction. Using EXPORT MODULE, I kept the CPU logic completely isolated from the platform-specific hardware.

2. The Platform: Apple II Skeleton (`apple2.jdb`)

On top of the CPU, I built the Apple II logic. This includes:

3. Running the ROMs (`emu_run.jdb`)

The final piece was the front-end. I implemented a keyboard mapper to translate modern German QWERTZ inputs into the Apple II strobe convention. As you can see in the screenshot, seeing the original APPLE ][ header and running a FOR loop in Applesoft BASIC—inside my own language—is a surreal full-circle moment for me as a developer.

This project was a massive stress test for jdBasic's performance and modularity. While the interpreter currently hits about 820k cycles per second, the "Edit and Continue" workflow made debugging the CPU flags incredibly fast.

What's Next?

Now that the 6502 core is stable, I'm tempted to wire up a C64 module. But for now, I'm just going to enjoy a few minutes of retro-coding on my "fake" Apple II.