Git Product home page Git Product logo

dcpu16-hs's Introduction

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.