Open in Dev Containers Crates.io docs.rs

MOS-Hardware

This crate contains hardware register tables and support functions for 8-bit retro computers like the Commodore 64, Commander X16, MEGA65 and others. Please check the examples directory to see how Rust can be used to generate simple demo effects.

Aims

Examples

Read and write to labelled hardware registers

~~~ rust use moshardware::{c64, vic2}; let oldbordercolor = c64::vic2().bordercolor.read(); unsafe { c64::vic2().bordercolor.write(vic2::LIGHTRED); c64::sid().potentiometer_x.write(3); // compile error: read-only register } ~~~

Use bitflags to safely control hardware

...for example where the VIC-II chip accesses screen memory and character sets:

~~~ rust use moshardware::{c64, vic2}; let bank = vic2::ScreenBank::AT2C00.bits() | vic2::CharsetBank::AT2000.bits(); unsafe { c64::vic2().screenandcharsetbank.write(bank); } ~~~

Convenience functions to perform hardware-specific tasks

...for example to generate random numbers using noise from the C64's SID chip:

~~~ rust use moshardware::c64::*; clearscreen(); sid().startrandomgenerator(); let value = sid().random_byte(); ~~~

Getting started

The project requires rust-mos and is setup to build for C64 by default. A docker image of rust-mos is available if you do not fancy compiling LLVM. If you want to start a new project which uses mos-hardware, there's a Github Template.

Docker and Visual Studio Code

The easiest way is to use the provided .devcontainer.json configuration for vscode by clicking the Dev Containers Open badge above, assuming you have VSC and Docker installed. You can also do this manually:

  1. Configure Visual Studio Code with the Remote - Containers extension
  2. Start Docker
  3. Open the project inside devcontainer when asked
  4. In the vscode terminal do: ~~~ bash

    if Docker uses qemu (i.e. on apple silicon)

    export CARGONETGITFETCHWITH_CLI=true

    build for the MEGA65:

    cargo build --target mos-mega65-none ~~~

Status

The hardware registers are currently incomplete and the library may be subject to significant changes.