C Other Python Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
|Failed to load latest commit information.|
DCPU-16 Playground This is an emulator, assembler, and an implementation of the Forth programming language for notch's DCPU-16. See http://0x10c.com/doc/dcpu-16.txt for details. There are also a couple of useful scripts for swapping endianness of binary images and dumping to hex in a format supported by some other emulators. Quick Start To build, just run: make To run the goforth interpreter image: ./goforth Other images can be run with: ./dcpu blah.img For options, just try: ./dcpu The Emulator The emulator is written in C with curses for video display. It's well tested and has a number of nice options. It builds on both Mac OS and Linux with gcc. I think it's about as close to the current consensus specs as is achievable with ncurses. Obviously bitmapped graphics aren't supported, so the terminal driver doesn't do anything special with the 'character table' (0x8180-0x827f), it just ignores the contents. The emulator supports the 'standard' 16-word keyboard ring buffer at 0x9000. I'm not sure what other emulators are doing, but this one will refuse to overflow the buffer, so it's important that your program reset each word to 0 after it's been read. If this is a problem for your program, it would be quite easy to make this behavior optional. For best colors, run in a terminal with good color support. You may have to fiddle around to get curses to realize your colors are good. For example, try setting TERM=xterm-256color if you're not having any luck. You can use ./dcpu colortest.img to test things out. Apparently ncurses 5 doesn't really support 256 distinct color pairs (well, it supports 256, but the first pair is reserved). So if you have ncurses 5 (most Linux distros, it seems), white-on-white will probably appear as your default terminal colors instead. goforth 'i figured i owned just dark skies, and that darkness fit me best. go, folks, go forth. trust your brain! trust your body!' The real fun starts in goforth.dasm and goforth.ft. goforth is an implementation of the Forth programming language for DCPU-16. There's still plenty of work to be done, but it's already quite usable. For example, it contains a built-in decompiler/disassembler and other amenities. (In fact, you might take a look at the file disasm.ft for an example of some non-trivial code written in goforth.) The bootstrapped goforth image should run on any DCPU-16 emulator that supports I/O. (It'll run on others, too, but won't do much...) goforth has been tested on several other emulators: * Notch's 'official' prototype, from http://dcpu.com/highnerd goforth runs correctly in this emulator, and you can play with it online here: http://matt.immute.net/files/goforth (This gives some evidence that my emulator is in good shape as well!) * interfect's dcpu-emu: https://bitbucket.org/interfect/dcpu-emu Runs correctly. * DCPU Studio: http://badsector.github.com/dcpustud Seems to run correctly (with 'use big endian words' and 'use keyboard buffer' options), but keyboard input is broken. I get mostly the right keypresses, but something about the buffer management is screwy and I end up losing sync, having to press keys twice, etc. I don't want to invest more time in keyboard compatibility until there's actually a spec. * deNULL's web emulator: http://dcpu.ru Seems to run correctly here, too, but the keyboard input is significantly different (all letters are caps, punctuation doesn't work) so it's a little hard to do too much testing. * http://0x10co.de Again, everything looks good, but keyboard input is (again, but differently) broken, so it's hard to do much. And again, I'm going to wait for a spec. I am most interested in hearing whether it works on other emulators. In order to bootstrap the image, I've augmented the DCPU instruction set with three new instructions (all in non-basic format): img: dump ram to the file core.img, from address 0x0000 to (but not including) the address in the 'a' argument. if 'a' is 0, dump the entire heap (0x0000 to 0x10000) die: exit the emulator dbg: enter the emulator debugger The latter two instructions are only used in special cases and are easily avoided. img is needed only to bootstrap the forth image. ONCE AGAIN, THE BOOTSTRAPPED IMAGE WILL RUN ON ANY EMULATOR. The Assembler The assembler (masm) is in Python and has a number of idiosyncrasies. The syntax has diverged from the consensus DCPU-16 assembler syntax in some rather pointless ways, and it's quite limited. It works for my purposes, but I don't recommend that you use it. Credits The built-in disassembler includes code from Brian Swetland's DCPU-16 emulator, see the file disassembler.c for license and copyright info.