#cpu #emulator #simulator #assembler #dcpu16

bin+lib dcpu16

DCPU-16 assembler, disassembler and emulator

11 releases (4 breaking)

Uses old Rust 2015

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

#11 in Simulation

Download history 7/week @ 2020-11-06 5/week @ 2020-11-13 7/week @ 2020-11-20 18/week @ 2020-11-27 19/week @ 2020-12-04 16/week @ 2020-12-11 3/week @ 2020-12-18 4/week @ 2021-01-01 6/week @ 2021-01-08 5/week @ 2021-01-15 5/week @ 2021-01-22 6/week @ 2021-01-29 16/week @ 2021-02-05 36/week @ 2021-02-12 16/week @ 2021-02-19

66 downloads per month
Used in dcpu16-gui

MIT license

135KB
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