Python scripts for DCPU-16 emulation.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Microsoft.VC90.CRT
app
emulator
icons
programs
screenshots
util
LICENSE
README.markdown
build_emulator
build_emulator.bat
build_emulator_linux
build_icons
build_icons.bat
build_installer.bat
clean.bat
installer.iss
main.py
setup.py

README.markdown

DCPU-16 Emulator v1.7

Download (Windows Installer)

See the downloads page:

https://github.com/fogleman/DCPU-16/downloads

Implemented Specifications

Screenshots

Assembler Features

; Macros (can be nested)
#macro BRK { NOP } ; ignore breakpoints

#macro push(x) {
  SET PUSH x
}

; String Literals
DAT "Here is some text.", 0 ; null-terminated string

; Reserve block of memory
RESERVE 0xff

; Character Literals
SET A 'a' ; A = 0x61
SET B 'A' ; B = 0x41

; Negative Numbers
SET A -1    ; A = 0xffff
SET B -0xff ; B = 0xff01

; Breakpoints
BRK

; Opcode Aliases
SET A POP
SET A [SP++] ; equivalent to POP

SET PUSH A
SET [--SP] A ; equivalent to PUSH

SET A PICK 1
SET A [SP + 1] ; equivalent to PICK 1

SET A PEEK
SET A [SP] ; equivalent to PEEK

; Local Labels
:prefix
  SET A 10
:.loop ; becomes prefix.loop
  SUB A 1
  IFE A 0
    SET PC .done
  SET PC .loop
:.done ; becomes prefix.done

; Fixed Labels
:screen @ 0x8000

Hardware Enumeration

The following code enumerates available hardware devices and populates the variables lem, keyboard and clock with their respective hardware identifiers.

#macro match_hardware(a, b, location) {
    IFE A a
    IFE B b
    SET [location] I
}

JSR enumerate_hardware

; now you can use the devices, e.g.
SET A 0
SET B 0x8000
HWI [lem]

BRK

:enumerate_hardware
HWN I
:.loop
IFE I 0
SET PC .done
SUB I 1
HWQ I
match_hardware(0xf615, 0x7349, lem)
match_hardware(0x7406, 0x30cf, keyboard)
match_hardware(0xb402, 0x12d0, clock)
SET PC .loop
:.done
SET PC POP

:lem
DAT -1
:keyboard
DAT -1
:clock
DAT -1

Benchmarks

Usage: python benchmark.py

Run benchmarks on the emulator to test performance.

MacBook Air (1.7 GHz Intel Core i5)

Benchmarking "C" emulator using "programs/life.dasm"...
Result: 88728989 cycles per second

The C implementation could emulate over 800 DCPU-16 processors at their 100 kHz clock rate.

Pretty Print

Usage: python assembler.py programs/example.dasm > pretty_output.dasm

Assemble and output in pretty format. Shows machine code in comments. Comments from the input file are not retained.

    SET A, 48                   ; 7c01 0030
    SET [0x1000], 32            ; 7de1 1000 0020
    SUB A, [0x1000]             ; 7803 1000
    IFN A, 16                   ; c00d
        SET PC, crash           ; 7dc1 001a
    SET I, 10                   ; a861
    SET A, 0x2000               ; 7c01 2000
:loop
    SET [I + 0x2000], [A]       ; 2161 2000
    SUB I, 1                    ; 8463
    IFN I, 0                    ; 806d
        SET PC, loop            ; 7dc1 000d
    SET X, 4                    ; 9031
    JSR testsub                 ; 7c10 0018
    SET PC, crash               ; 7dc1 001a
:testsub
    SHL X, 4                    ; 9037
    SET PC, POP                 ; 61c1
:crash
    SET PC, crash               ; 7dc1 001a

Dependencies