Connomore64:使用并行微控制器进行C64的精确周期模拟
Connomore64: Cycle exact emulation of the C64 using parallel microcontrollers

原始链接: https://github.com/c1570/Connomore64

Connomore64是一个基于多个低成本RP2040/RP2350微控制器并行工作的、时钟精确的Commodore 64模拟器。它旨在实现逐芯片的精确度,重现原始C64的时序和行为,从而兼容真实的C64硬件,例如软盘驱动器和卡带。 该项目利用RP2040的可编程I/O (PIO)实现精确的信号时序,并使用DVI/HDMI进行视频和音频输出。开发利用了改进的rp2040js模拟器,支持RP2350和详细的PIO时序分析。C64模拟基于“芯片”库,并进行了大量的优化,包括重写后的更快VIC-II和CIA模拟。 原型包括堆叠的RP2040电路板和一个定制的PCB(“Breadbox v0”),可以安装在C64机箱内,并具有原始C64的接口。该项目成功运行了大量的游戏和演示,支持快速加载器,并能与用户端口硬件接口。虽然仍在开发中,尚未发布,但代码最终将开源。

Hacker News 上的一个帖子讨论了一个使用并行微控制器的精确到周期的 C64 模拟器。用户分享了相关的项目和资源,包括用于 SID 芯片操作的 SIDKick-pico8,以及 8bit Weapon 和 LukHash 供艺术家使用 C64 音效,还有 deepsid.chordian.net 用于在线 SID 音乐。macOS 系统下推荐的 SID 播放器包括 SIDPLAY、ZXTune 和 VLC。一些用户讨论了精确周期模拟和性能之间的权衡,指出模拟器的重写图形渲染代码牺牲了一些兼容性以换取速度。其他主题包括现代 C64 零件的更换,使用 RP2040 替换 CIA 芯片的可能性,以及对 C64 独特的编程限制及其产生的创造性编码技术的怀旧之情。一位用户表达了对新型 CIA 芯片可能存在后门的担忧。

原文

https://github.com/c1570/Connomore64

Realtime cycle exact emulation of the Commodore 64 using multiple microcontrollers in parallel.

This is a proof of concept and not end user ready.

Connomore64 breadbox v0 prototype

July 2024 poster (old prototype)

In a nutshell, this is (or aims to be)…

  • …a cycle exact Commodore 64 homecomputer emulator
  • …an (almost) chip-by-chip rebuild using multiple RP2040/RP2350 microcontrollers (<1€ per chip!)…
  • …interconnected using a multiplexed 8 bit bus running at about 8 MHz effectively…
  • …using DVI/HDMI as video and audio output…
  • …with microsecond exact true to original real world signal timing…
  • …able to interface with original hardware
    • …such as the C1541 floppy drive, including fastloaders…
    • …as well as userport and (some) expansion port based hardware.
  • …an example of running compute intensive software on cheap low powered interconnected microcontrollers
  • …an emulation framework to test and debug projects using several RP2040/RP2350s in parallel on a PC.
  • First and foremost, this was started as a holiday project (“porting an existing C64 emulator to a 400MHz ARM platform cannot take that long, can it?”) with a focus on playing a bit with the RP2040 microcontroller and getting an idea of what its PIOs (i.e., its GPIO handling coprocessors) are capable of.
    • The holiday of this “holiday project” was christmas 2022, and it turns out a single 400MHz M0+ core is definitely not enough to emulate a C64, if accuracy is some priority…
  • While a C64 emulator on the RP2040 already exists, it is using an extremely simplified model of the C64, e.g., not emulating the exact steps and timing of MOS 6510 CPU opcodes, and not emulating the VIC-II video chip exactly but doing video line based emulation instead which limits compatibility.
  • PC based emulators (VICE, BMC etc.) reach high emulation quality but do not feature perfect realtime timing. That means you cannot use physical retro hardware (floppy drives, etc.) with those emulators in general.
  • FPGA based emulators of the C64 reach high emulation quality and realtime accuracy, but those platforms strike yours truly as quite overpowered and expensive, not as hackable as would be nice, and typically come with a rather unwieldy (and typically closed source) toolchain.

For developing this project, the rp2040js emulator project by Uri Shaked of Wokwi.com fame has been extended. Very little debugging on real hardware happened. No logic analyzers were necessary at all!

You can find my fork of rp2040js here. It features:

  • RP2350 support (RISC-V/Hazard3 only)
  • cycle exact timing of PIOs
  • VCD trace files can get generated for the GPIO signals
  • a simple framework for running multiple chip emulation instances interfacing to each other (WIP code)
  • simulation of input/output latency of GPIOs
  • functionality to output statistics and monitor any PIO stalls is present in the emulation runner that has been customized for this project

The C64 emulation code is based on the “chips” emulation library by Andre Weissflog. A lot of optimizations have been done:

  • speed optimized VIC-II code
    • rewritten graphics rendering code (running 5-10 times as fast as the previous code while sacrificing some compatibility)
    • rendering bitmap/text mode is done using PIO/DMA
    • rewritten Sprite rendering (in contrast to the original VIC-II, sprites are rendered into a buffer in the offscreen time)
  • fixed a few VIC-II emulation bugs (VSP/AGSP works now)
  • faster CIA emulation using look up tables
  • replaced uint64_t pins interface with 32 bits pins/direct variables

HDMI/DVI output is based on the PicoDVI library by Luke Wren.

Provided by a port of the SIDKick pico firmware (by Carsten Dachsbacher, using reSID by Dag Lem) to the Connomore64 bus system.

Breadbox v0 prototype (latest)

This is a custom PCB that fits into the C64 case (shown on top of the page). It comes with the usual C64 ports (userport, IEC, expansion port, joystick ports) plus HDMI and audio jack. Currently, the userport, IEC, and joystick ports are functional. Support for select expansion port cartridges (e.g., Magic Desk) is upcoming.

Goals of this prototype:

  • All original C64 connectors available
  • Simple to build
  • Easy migration to RP2350 in development
  • Testbed for SWD-based firmware handling

Stacked Pico boards (early prototype)

The first prototype was several stacked RP2040 boards. Video output is done using a passive DVISock adapter. Using a small passive “hat”, it can connect to an original C64 keyboard, joysticks, as well as a floppy drive. Loading programs from the drive is possible using the original CBM routines as well as the much faster JiffyDOS or other speeders.

Early prototype

Smaller custom PCBs for the Connomore are possible. Those could be made very cheap and small as only one flash chip and crystal would be needed, and setting up the microcontrollers could be done via SWD. Total cost below 20€ might be possible.

  • Runs almost all games just fine
    • Mayhem in Monsterland, Hawkeye, Armalyte, Katakis, R-Type, Bubble Bobble, Turrican, ...
  • Runs a good portion of demos (e.g., Layers)
  • Fastloaders work just fine (tested with JiffyDOS and Transwarp)
  • User port hardware works (tested with WiC64)
  • Only the CPU half of each C64 cycle is emulated, limiting potential compatibility with C64 expansion port cartridges.
    • There is code for Phi low but RP2040/RP2350s are not fast enough for that.
  • Expansion port firmware and hardware is not done (needs some thought)

At the moment, the project and code is in no way release ready. I'll likely release it as (possibly non commercial) strong copyleft open source code at some point. If you are interested in the project or in contributing, please contact me.

联系我们 contact @ memedata.com