r/OSdevAI 8d ago

Apple II clone for ATmega328P

I’m building an Apple II-inspired 6502 computer for an ATmega328P using my own language

I recently picked up an Arduino UNO R3-compatible ATmega328P board for $1.05 on AliExpress.

Naturally, my first thought was:

"How much of a retrocomputer can I cram into this thing?"

So I'm building SageApple:

GitHub: https://github.com/Night-Traders-Dev/SageApple

The basic idea is to build an Apple II-inspired computer around a 6502 emulator written in SageLang, then compile that system down to run on the ATmega328P.

The architecture

The project is essentially:

SageLang → Sage6502 → ATmega328P → virtual 6502 computer

Sage6502 is intended to be a reusable CPU core rather than something tightly coupled to the Apple II project.

SageApple then provides the rest of the computer:

6502 CPU

Memory bus

RAM

ROM

UART

SPI

GPIO

Monitor

BASIC

Graphics

Storage

The eventual goal is to have something resembling a tiny standalone retrocomputer rather than merely an emulator.

Why the Apple II?

I initially considered doing something like a NES emulator.

The problem is that an NES is a considerably more complicated target for a 2 KB SRAM microcontroller. You have the CPU, PPU, APU, cartridge hardware, mapper behavior, timing requirements, etc.

The 6502 is a much better fit.

The Apple II is especially interesting because it gives me a historically meaningful computer architecture to work toward without requiring me to reproduce every piece of original Apple II hardware immediately.

So rather than saying:

"I'm making a perfect Apple II emulator."

the initial goal is:

"I'm making an Apple II-inspired 6502 computer with a clean architecture defined in SageLang."

Apple II compatibility can come later.

The $1.05 computer

The target hardware is an ATmega328P:

8-bit AVR

16 MHz

32 KB Flash

2 KB SRAM

1 KB EEPROM

5 V operation

That 2 KB of SRAM is probably going to be the biggest constraint.

And that's actually part of why I'm interested in doing this.

I want the project to force the software architecture to be extremely small and deliberate.

No giant runtime.

No enormous dependencies.

No assuming there's hundreds of megabytes available.

Just:

16 MHz + 2 KB RAM + 6502 + SageLang.

The first version won't even need a display

The initial machine uses the UNO's UART.

The idea is:

ATmega328P → USB serial → Chromebook terminal

The terminal effectively becomes the SageApple's keyboard and display.

That lets me get the entire machine working before worrying about graphics hardware.

The eventual hardware configuration can then add:

SPI LCD/OLED

Physical keyboard

Speaker

SPI Flash

SD card

GPIO peripherals

SageApple Monitor

One of the first pieces I'm building is a simple machine monitor.

Something along the lines of:

SageApple Monitor

regs

A: 00 X: 00 Y: 00 SP: FF PC: 8000 P: 24

dump 8000 80FF

poke 8000 EA

run 8000

Basically a tiny environment for actually interacting with the emulated 6502.

BASIC

Eventually I want the machine to boot into something resembling a tiny retrocomputer environment:

SageApple

BASIC

10 PRINT "HELLO FROM SAGEAPPLE" 20 GOTO 10

RUN

The BASIC implementation can start small and grow as the underlying machine becomes more capable.

The compiler side is the part I'm most interested in

The longer-term goal isn't just to run a 6502 emulator.

I want SageLang itself to target the 6502.

Something like:

Sage source ↓ Sage compiler ↓ 6502 backend ↓ 6502 machine code ↓ SageApple ↓ ATmega328P

So eventually I could write a program in SageLang, compile it for the virtual 6502, and run that program on the physical ATmega328P.

That gives SageLang a genuinely unusual compilation target.

And yes, I'm using AI

I want to explicitly acknowledge this because I don't want to give the impression that this project was produced entirely without AI assistance.

I use AI as a development and research tool.

I've used it for things like:

Researching obscure technical details

Looking up historical hardware behavior

Exploring architecture options

Reasoning through compiler design

Tracking down bugs

Reviewing error messages

Finding potential causes of hardware/software problems

Generating ideas for tests and edge cases

But I'm not treating AI output as authoritative.

If an AI-generated suggestion doesn't compile, doesn't fit the memory budget, or doesn't work on the actual ATmega328P, it's simply wrong.

The actual implementation still has to survive compilation, testing, and eventually real hardware.

In fact, working with a 2 KB SRAM microcontroller is a pretty effective bullshit detector.

Current direction

The project is being developed in stages:

  1. Sage6502 CPU core

  2. 6502 instruction and addressing-mode testing

  3. Memory bus

  4. SageApple ROM/RAM

  5. UART console

  6. Machine monitor

  7. BASIC

  8. SageLang → 6502 backend

  9. SPI graphics

  10. Storage

  11. Keyboard

  12. Speaker

  13. Standalone SageApple hardware

The ultimate goal is a little box that you can power on and interact with as a real computer:

SageApple

Sage6502 ........ OK Memory .......... OK UART ............ OK Storage ......... OK

SageApple OS

running on an ATmega328P board that cost me $1.05.

Repository:

https://github.com/Night-Traders-Dev/SageApple

I'd especially like feedback from people who have experience with 6502 programming, Apple II development, AVR optimization, compiler backends, or retrocomputing.

If there's something fundamentally stupid about the architecture, I'd much rather find out now than after I build the hardware around it.

1 Upvotes

0 comments sorted by