Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Haskell implementation of Notch's dcpu-16 specification (assembler, emulator)

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 examples
Octocat-spinner-32 src Add self-modifying code example April 11, 2012
Octocat-spinner-32 tests
Octocat-spinner-32 .ghci
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Setup.hs
Octocat-spinner-32 dcpu16-hs.cabal
README.markdown

dcpu16-hs

Implementation of Notch's dcpu-16 CPU in Haskell. This project includes an assembler and an emulator.

Status

We can assemble and run at least Notch's example program, this fibonacci example, and the stuff in examples/.

Like the assembler Notch uses, short form for labels isn't supported yet.

The emulator just runs until it crashes (usually when it tries to execute a 0x0000 opcode), there is no stopping strategy for now.

Building

cabal configure && cabal build

Running

./dist/build/dcpu16-assembler/dcpu16-assembler examples/notch.dasm16

This produces a.out.

./dist/build/dcpu16-emulator/dcpu16-emulator --pretty out a.out

This gives you a pretty-printed memory dump in out you can study.

Design

We use a homogeneous Memory type for all kinds of memory the CPU has access to:

  • Special values such as SP, PC and O
  • Custom defined (i.e. not in the spec) values such as CYCLES
  • Registers (A, B...)
  • RAM

These values can accessed by an Address, which is a simple ADT:

data Address
    = Sp
    | Pc
    | Ram Word16
    | ...

The core of the design is hence a monadic typeclass:

class Monad m => MonadEmulator m where
    load  :: Address -> m Word16
    store :: Address -> Word16 -> m ()

Currently, there is only one implementation of this class, STEmulator, which is able to simulate programs in a pure way (so a program is guaranteed to always yield the same result!).

When the spec is better defined, an IOEmulator will be added which will not be pure, in order to be able to grab keyboard events and display video.

Something went wrong with that request. Please try again.