Skip to content
/ c64 Public

๐ŸŽฎ Basic Commodore 64 emulator in Python. Loads .prg files, emulates CPU/VIC-II/memory with Pygame UI. Great for learning how emulators work.

License

Notifications You must be signed in to change notification settings

ToolSynth/c64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Commodore 64 Emulator

Description

This project is a basic emulator of the Commodore 64 written in Python. Its main purpose is to run simple BASIC programs stored in .prg files and to show how an emulator is built, step by step. It covers the MOS 6510 CPU, memory map, a minimal VIC-II display, and input handling.

๐Ÿ–ผ๏ธ Screenshot

This screenshot shows a simple PRINT command executed in the BASIC interpreter, demonstrating text rendering and keyboard input handling in the emulated environment.

C64 emulator running

โ–ถ๏ธ Demo 1: Sprite & RAM Tester

A lightweight diagnostic program that visualizes C64 RAM and sprite memory. Useful for verifying basic video memory access and display via the VIC-II module.

demo 64-tester gif

โ–ถ๏ธ Demo 2: Memory Mapper & CIA Tester

A more advanced diagnostic tool that tests multiple hardware components including CIA-driven memory mapping. Demonstrates support for dynamically remapped address spaces and I/O handling.

demo 64-tester gif

Project Assumptions

  • The goal is not to reach 100 % hardware accuracy.
  • It must be able to load and start small .prg files without extra loaders.
  • Extra chips such as SID and full CIA1/CIA2 support are still missing.
  • Code should stay clear and short so it is easy to study.

Author & AI Collaboration

I developed this project with strong help from AI tools. The AI supported me with:

  • Code flow ideas and naming
  • Quick research on C-64 internals and data-sheets
  • Small assembler examples and bug hunting

However, the project also shows that AI alone cannot finish a full emulator. A human still has to design the structure, understand corner cases, and test the result. My background is software engineering with a focus on quality-process automation, which helped in planning and testing the codebase.

Features

Status Module Notes
โœ… MOS 6510 CPU All documented 6502 instructions
โœ… Memory map BASIC, KERNAL, CHAR ROM, RAM
โœ… Basic VIC-II Text and bitmap modes, drawn with Pygame
๐ŸŸก CIA1 & CIA2 Only timers A/B and IRQ mask; no TOD clock
โŒ SID sound Not yet implemented
๐ŸŸก 1541 drive Skeleton class; disabled by default

Legend: โœ… ready ยท ๐ŸŸก partial ยท โŒ missing

Additional details:

  • Drag-and-drop: Drop a .prg file on the window to auto-load it.
  • Pygame interface: Keyboard mapping and window output.
  • Works without custom loaders; the emulator adjusts the BASIC pointers for you.

Limitations

  • No sound, because SID emulation is still on the to-do list.
  • CIA1/CIA2 do not yet cover all registers, so some demos or games can fail.
  • Cycle timing is approximate; programs that depend on exact raster timing may break.

Roadmap

  1. Finish CIA1/CIA2 (TOD clock, serial lines, full interrupts).
  2. Add a very rough SID channel so simple tones can play.
  3. Improve timing and add a โ€œfast-loadโ€ option for large files.
  4. Optional: grow the 1541 module into a working drive with GCR decoding.

Requirements

  • Pythonย >=ย 3.12
  • numpyย ==ย 2.2.1
  • pygameย ==ย 2.6.1

Installation

git clone <REPO_URL>
cd c64
python3 -m venv .venv
source .venv/bin/activate        # or .venv\Scripts\activate on Windows
pip install -r requirements.txt

Then place the original ROM images in the rom/ folder (see below).

ROM Download

mkdir -p rom
   curl -L https://www.zimmers.net/anonftp/pub/cbm/firmware/computers/c64/basic.901226-01.bin -o rom/basic.bin
   curl -L https://www.zimmers.net/anonftp/pub/cbm/firmware/computers/c64/kernal.901227-01.bin -o rom/kernel.bin
   curl -L https://www.zimmers.net/anonftp/pub/cbm/firmware/computers/c64/characters.901225-01.bin -o rom/chargen.bin
   curl -L https://www.zimmers.net/anonftp/pub/cbm/firmware/drives/new/1541/1540-c000.325302-01.bin -o rom/dos1541.bin

(Replace the URLs with mirrors of your choice.)

Quick Start

python main.py
  • A C-64 screen appears.
  • Drag a .prg file onto it.
  • Type RUN and press Enter.

Press Esc or close the window to quit.

Debug logging

Run the emulator with verbose debug logs:

python main.py --debug

UML Diagrams

Class Diagram

classDiagram
    class Emulator {
        +run()
        -init_pygame()
        -main_loop()
    }
    class CPU6510 {
        +reset()
        +step()
        -executeInstruction()
    }
    class VICII {
        +renderFrame()
        -drawTextMode()
        -drawBitmapMode()
    }
    class SID {
        +clock()
        -updateRegisters()
    }
    class CIA {
        +tick()
        -handleIRQ()
    }
    class Bus {
        +read(addr)
        +write(addr, data)
    }
    class IOHandler {
        +loadPrg(file)
        +processInput()
    }

    Emulator --> CPU6510 : uses
    Emulator --> VICII : uses
    Emulator --> SID : uses
    Emulator --> CIA : uses
    Emulator --> Bus : uses
    Emulator --> IOHandler : uses
    CPU6510 --> Bus : accesses
    VICII --> Bus : accesses
    SID --> Bus : accesses
    CIA --> Bus : accesses
    IOHandler --> Bus : accesses
Loading

Project Structure

c64/
โ”œโ”€โ”€ rom/               # ROM files and sample .prg files
โ”œโ”€โ”€ src/               # Emulator source code
โ”‚   โ”œโ”€โ”€ emulator/      # Emulator class and Pygame setup
โ”‚   โ”œโ”€โ”€ bus/           # System bus and memory mapping
โ”‚   โ”œโ”€โ”€ cpu/           # MOSย 6510 CPU emulation
โ”‚   โ”œโ”€โ”€ vic/           # VIC-II graphics emulation
โ”‚   โ”œโ”€โ”€ sid/           # SID sound chip emulation
โ”‚   โ”œโ”€โ”€ cia/           # CIA1 and CIA2 timers/I/O emulation
โ”‚   โ”œโ”€โ”€ io/            # Keyboard input, .prg loader, disk drive interface
โ”‚   โ””โ”€โ”€ utils/         # Logging and utility functions
โ”œโ”€โ”€ tests/             # Unit and integration tests
โ”œโ”€โ”€ main.py            # Entry point
โ”œโ”€โ”€ requirements.txt   # Dependencies
โ”œโ”€โ”€ LICENSE            # MIT License
โ””โ”€โ”€ README.md          # This file

Testing

Run all unit tests with:

pytest

Contributing

Pull requests are very welcome, especially for missing chips or performance fixes. Feel free to open issues for discussion.

Contact

Interested in working together or adding new components? Write to jaroslawtrepkowski@gmail.com โ€“ I am open to ideas and cooperation.

License

This project is released under the GNU GPL. See the LICENSE file for details.

About

๐ŸŽฎ Basic Commodore 64 emulator in Python. Loads .prg files, emulates CPU/VIC-II/memory with Pygame UI. Great for learning how emulators work.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages