#cpu #emulator #simulator #assembler #dcpu16

bin+lib dcpu16

DCPU-16 assembler, disassembler and emulator

11 releases (4 breaking)

0.4.0 Dec 18, 2016
0.3.0 Dec 17, 2016
0.2.0 Dec 16, 2016
0.1.0 Dec 15, 2016
0.0.6 Jun 16, 2015

#5 in Emulators

Download history 66/week @ 2018-11-25 21/week @ 2018-12-02 11/week @ 2018-12-09 24/week @ 2018-12-16 77/week @ 2018-12-23 4/week @ 2018-12-30 13/week @ 2019-01-06 3/week @ 2019-01-13 8/week @ 2019-01-27 3/week @ 2019-02-03 3/week @ 2019-02-10 13/week @ 2019-02-24 22/week @ 2019-03-03

52 downloads per month
Used in 1 crate

MIT license

133KB
3K SLoC

Crates.io

DCPU-16

DCPU-16 assembler, disassembler and emulator written in Rust.

DCPU-16 is a CPU specification from the never-completed game 0x10c by Notch (from 2012). More info about the DCPU-16:

To run DCPU-16 programs with hardware devices (such as a monitor, keyboard, etc.), use:

Completed features

The DCPU-16 is feature complete and ready for use:

  • Assembler
    • Labels
    • String literals
    • Arithmetic literals (e.g. SET A, 0x8000+100*3)
    • Readable error messages
  • Disassembler
    • Separate tokenizer
    • Colorized output
  • Emulator
    • All DCPU-16 v1.7 instructions are supported
    • A few extra instructions, good for debugging and testing
    • Devices
      • Monitor (LEM1802)
      • Keyboard
      • Floppy drive (M35FD)

Planned extended features

  • More unit tests
  • Concurrency support
  • Communication between DCPU-16 computers
  • A simple programming language that compiles to DCPU-16

Binaries

Run cargo build --release and add dcpu16/target/release to your PATH:

  • assembler
    • $ dcpu16-assembler program.asm -o program.bin
  • disassembler
    • $ dcpu16-disassembler program.bin
  • tokenizer
    • $ dcpu16-tokenizer program.bin
  • emulator
    • $ dcpu16 -p program.bin

Library

Apart from providing binaries, this crate can also be used as a library and embedded into other programs. An example of this can be seen in dcpu16-gui.

Extentions

Some extensions (possibly temporary):

--- Special opcodes: (5 bits) --------------------------------------------------
 C | VAL  | NAME  | DESCRIPTION
---+------+-------+-------------------------------------------------------------
 0 | 0x13 | OUT a | prints a null-terminated string located at a in memory
 0 | 0x14 | OUV a | prints a value in decimal and then a newline
---+------+-------+-------------------------------------------------------------

Since hardware is not supported, you can use OUT to print to regular standard output. Another temporary behavior is that the CPU is terminated if it reads a 0x00 instruction.

Extensions to the assembler:

-- Assembler instructions ------------------------------------------------------
 FORMAT       | DESCRIPTION
--------------+-----------------------------------------------------------------
 DAF c, v     | DATA FILL - repeats a value a certain number of times
              | c (count) and v (value) must be numerical literals
              | e.g. DAF 256, 0xffff  ; Fill 256 words with -1
--------------+-----------------------------------------------------------------

Example

Save the following as prog.asm:

            OUT hello                   ; Print the string defined at 'hello'
            DAT 0                       ; This will terminate the program    

:hello      DAT "Hello World!\n", 0

Assemble the program:

$ assembler prog.asm -o prog.bin

Run it:

$ emulator prog.bin
Hello World!

Dependencies

~105KB