All Projects → jaspervdj → dcpu16-hs

jaspervdj / dcpu16-hs

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

Programming Languages

haskell
3896 projects
assembly
5116 projects

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].