10 ms·
Notch's Specification for the In-Game DCPU-16
- acron0 14y agoI will admit, I used to think Notch was just a regular-joe programmer who had gotten extremely lucky with his strain of adventure game. Now I know I was dead wrong.
- unwind 14y agoJust waiting for the first post about programming this CPU to pop up on Stack Overflow ... :) It's quite an interesting architecture. From an initial perusal, I found these features note-worthy: * Explicit access to PC as a register, makes "computed goto" trivial and very natural. * Because of the above, there is no JMP instruction. * Treating operations on registers as "values" makes the instruction set very orthogonal. * No instructions for bit-manipulation. * Lots of possible NOP instructions, like "SET PC,PC" (which I think should work, depends a bit on exactly when it's incremented but it looks safe). * Word-addressed memory will make string processing interesting to implement. Maybe in space, everyone uses UTF-16. * Single 64 K address space will put quite the limit on the amount of code, I guess the game will show how much code is needed to do anything. * No I/O instructions means I/O must be memory-mapped, further reducing the space available for code. Maybe there will be bank-switching? * No interrupts.
- TomFrost 14y ago> * Word-addressed memory will make string processing interesting to implement. Maybe in space, everyone uses UTF-16. Everyone in Minecraft, too -- almost. The string encoding in Minecraft's protocol spec is UCS-2, just a sneeze away from UTF-16. It seems Notch has a soft-spot for large encodings. It makes sense from a calculation and lookup perspective, but I wonder if the increased bandwidth and storage of 16-bit blocks has a measurable impact.
- ajuc 14y agoI think Java strings are UCS-2, so that explains why Minecraft uses this?
- ealloc 14y agoBy going UTF-16, he would make the game much more accessible to those not using a latin alphabet. If I was designing the game, I would favor internationalization vs space efficiency in the virtual computer. That way russian kids would get to have fun learning to write silly programs too.
- asdfaoeu 14y agoUTF-8 still has all the characters UTF-16 does it just uses more bytes to encode them. UTF-8 makes more sense if most of your characters can be represented in 8 bits.
- ealloc 14y agoyou can encode all characters in the basic multilingual plane with a single utf-16 code unit, while in utf-8 BMP characters have variable lengths from 1 to 3 bytes. If Notch only allows BMP characters and uses utf-16, internationalized string maniulation is very easy, as easy as ASCII for kids to mess with.
- cpeterso 14y agoIf the DCPU has only 64KB of RAM, encoding strings using UCS-2 or UTF-16 seems rather wasteful.
- hobojoe 14y agoOk. Start coding now please.
- SideburnsOfDoom 14y agoContext: For those who are puzzled (as I was) as to what this CPU is for, I found this: > Notch's next game, 0x10c, "will allow players to create their own spaceship in the far, far future of an alternate universe ... More exciting - especially for those versed in programming languages - is the ship's computer. It's a fully-functional 16-Bit CPU that controls the entire vessel..." http://www.dealspwn.com/notchs-space-trading-game-real-called-0x10c-98501 http://www.dealspwn.com/notchs-space-trading-game-real-calle... Also: http://www.theverge.com/2012/4/4/2924594/minecraft-creator-notch-names-next-project-0x10c-sci-fi-game http://www.theverge.com/2012/4/4/2924594/minecraft-creator-n... http://0x10c.com/ http://0x10c.com/
- stephengillie 14y agoIt's good to see Notch working on the Little Coder problem, even if that's not his direct intention. :)
- lt 14y agoUgh. Googling Little Coder problem matches "small code problems" and "little codec problems" before something remotely related to what I wanted. There's a single relevant result in the first page. The verbatim search returns a very good match in #1 and about 80% of the results seem appropriate. It seems the recent synonyms fixes are not nearly enough. And, for the interested: http://blog.steveklabnik.com/posts/2009-12-28-the-little-coder-s-predicament http://blog.steveklabnik.com/posts/2009-12-28-the-little-cod...
- mdwrigh2 14y agoWell, you actually wanted a synonym (Little Coder's Predicament not problem), just not the ones they appear to give. For what its worth, _why's article is the third result for me, and a couple other articles on it are in the top 10.
- SideburnsOfDoom 14y agoLittle Coder problem = how to get people interested in coding by writing little programs. Hard to do on consoles and iPhones. I started thinking that if I was going to get people interested in coding, I'd start with something more approachable - maybe something like a subset of Python, Java, Ruby or even JavaScript (it's where so many people write little programs anyway now). I heard Lua mentioned as a good scripting language too. Then I wondered - is this CPU a reasonable target for those kinds of little languages? Is this a way to be language independent and have them all? If so, why not something more like the JVM to make it easy? It seems to me that coding for this CPU is more like a mini-game in the main game; the fact that it's a challenge is part of the game.
- davedx 14y agoI guess we'll be able to write our own malware to take over other peoples' ships, then? Pretty awesome, just call me Locutus :)
- gnarbarian 14y agothe borg vs the binars.
- phoboslab 14y agoNow here's an interesting bit: "Question: can we trade the programs we create? How will you stop malicious viruses etc?" "yes. And I won't stop viruses, the players will have to do that themselves." ~ https://twitter.com/#!/notch/status/187474819980328962 https://twitter.com/#!/notch/status/187474819980328962
- exch 14y agoNice. With a bit of fiddling one could perhaps invert an enemy's shield polarity. That always seems to work miracles in any sci-fi show.
- untog 14y agoReverse the polarity of the neutron flow. Works every time.
- dlikhten 14y agoThis opens a whole stream of electronic warfare, however, the problem is that this will be writing programs that have no real-world usage. Except... These programs will be a great way to introduce both kids and adults to programming as learning it will give an edge to people. Question: Will we need to program an OS? And does it run Linux?
- Florin_Andrei 14y ago> These programs will be a great way to introduce both kids and adults to programming This would be a tremendous way to do that. Programming on normal computers is always kind of disconnected from the real world. So, your program can add two and two. Great. Now what? Microcontrollers alleviate that issue to some extent. Now your program can walk and talk, and push real-world objects. But you kind of need to learn a bit of electronics too. Notch's Universe solves this issue neatly. It's a mock real world, with programmable computers. Now your software can do some interesting mock-real-world stuff, like fly spaceships. That's pretty neat.
- swang 14y ago
- evilpie 14y agoJust for fun, I wrote a disassembler for his instruction set. https://gist.github.com/2300590 https://gist.github.com/2300590 I previously wrote some assembler routines for x86, which is very complex, working with Notch's design is a breeze and actually enjoyable. Does he somewhere mention if the code is loaded into the RAM? This would make self-modifiable code possible.
- evincarofautumn 14y agoIt doesn’t say in the spec, unless you interpret the memory dump for his assembled example as residing at address 0x0000 rather than offset 0x0000. But I don’t see any reason why PC shouldn’t refer to a RAM address. It would be great for code economy in such a constrained system.
- eridius 14y agoIt's definitely loaded into ram. Some of the operands are defined in terms of "next word of ram", which clearly refers to reading (and incrementing) the PC.
- SimHacker 14y agoCan't wait to see FORTH running on this CPU! FORTH ?KNOW IF HONK ELSE FORTH LEARN THEN
- tvorryn 14y agoThat's my plan actually. It should be a lot easier to get going than C or an LLVM backend as others are suggesting.
- RodgerTheGreat 14y agoSame here. The main design decision is how to represent the secondary stack. I was thinking we could reserve a pair of registers to keep the parameter stack pointer and return stack pointer, and swap them out with SP as needed. 1 2 + >r becomes something like SET PUSH, 0x1 SET PUSH, 0x2 SET A, POP ADD A, POP SET X, SP // back up data stack pointer SET SP, Y // switch to return stack SET PUSH, A Thoughts?
- SimHacker 14y agoOh yeah, you could whip a sweet little Forth system up for this processor. The first thing to do is to write a DCPU-16 assembler in Forth, and use that to write the primitives. That's pretty simple -- just look at the 6502 assembler: http://www.forth.org/fd/FD-V03N5.pdf http://www.forth.org/fd/FD-V03N5.pdf Some Forth systems have metacompilers so they can retarget themselves to different architectures. http://www.ultratechnology.com/meta.html http://www.ultratechnology.com/meta.html Using a metacompiler with a Forth DCPU-16 assembler would be the best way to go. Then you could easily experiment with different threading schemes, stack architectures, etc.
- ericbb 14y agoMy first try would probably be to use SP for one stack and some other fixed register for the other stack. Also, traditional Forth interpreters don't use code like you showed. I think the main benefit of using Forth (unless you just happen to love RPN) is the compactness of the interpreted code. If you're not going to use an interpreter, then I'm not sure if Forth is really a win. Edit: Just to clarify about the interpreter point, I'd expect something like "1 2 + >r" to be represented at run time as four words in memory and there'd be an interpreter, written in machine code, reading code word sequences and jumping to small bits of machine code to either do a built-in function or push the call stack.
- DanBC 14y agoThis might be a stupid question but where does the output go? Is it just a memory location? And does that memory location map to a "ship function"? So, er, on a PC if I write data to address 0x378 it'll appear on LPT1. What's the equivalent on DCPU-16? If I write data to a certain address it'll appear on the missile bay ports? Or is there a level of abstraction?
- nightpool 14y agoI/O is still being developed: https://twitter.com/#!/notch/status/187454444571598848 https://twitter.com/#!/notch/status/187454444571598848
- a-priori 14y agoIf I had to guess, he's going to implement memory-mapped I/O. So, there's going to be another specification that lists various memory locations' functions. Reading from some will return information about the ship's systems; writing to other locations will control the ship.
- rplacd 14y agoReady - steady - port tcc!
- sp332 14y agoHere's some work (not mine) on a third-party implementation in Go :) https://github.com/kballard/dcpu.go/tree/master/dcpu https://github.com/kballard/dcpu.go/tree/master/dcpu
- rcamera 14y agoFor those interested, there is a C based implementation of Notch's DCPU-16 in github: https://github.com/swetland/dcpu16 https://github.com/swetland/dcpu16 I haven't tested it much, but it seems to work pretty well.
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]
- Symmetry 14y agoI've been tempted to learn Verilog, looks like I might have a fun project to start here, trying to pipeline this. If I were writing the instruction set I'd be tempted to put all the value codes for next word or PC next to each other so it would be easier to figure out at decode state if the PC would be doing anything wonky, but that isn't a huge impediment or anything. The instruction boundary problem with regards to going super scalar looks as bad as it is in x86, but that's straying pretty far from the design goals.
- ekosz 14y agoI'm not a low level programmer, but could someone tell me if you could write a LLVM backend for this CPU? If one does that, could it not then work with many programming languages that support LLVM? http://llvm.org/docs/WritingAnLLVMBackend.html http://llvm.org/docs/WritingAnLLVMBackend.html
- cobbal 14y agoI've never written an LLVM backend, but one difficulty that immediately jumps out at me is the 16-bit architecture. LLVM specifies types with bitwidths and 32 is most commonly used, meaning a backend would have to either emulate 32 bits, forbid the frontends from generating 32 bits, or silently cast them all down to 16 bits.
- _sh 14y ago32-bit types are only common in LLVM because typically the target architecture is 32/64-bit. LLVM will handle 16-bit (and even 8-bit or 13-bit) targets just fine. That said, a LLVM backend is overkill for this and I'm sure the simple interpreter Notch has rigged up will be just fine for its purpose.
- zoul 14y agohttps://github.com/krasin/llvm-dcpu16/ https://github.com/krasin/llvm-dcpu16/
- duaneb 14y agoI'd be interested to see details on memory protection. Self-modifying code means evolutionary programming, which I am very much for. Conditional branching is strange.
- chj 14y agoI think he should just use PDP8 ISA, just 6 instructions, even stupid people can manage that much.
- Zaak 14y agoNotch's original intention was to implement a real CPU like the 6502, but he decided to create a CPU optimized for software emulation instead. The PDP-8 was designed to be inexpensive to implement with the hardware available at the time. It would not be an ideal choice for this purpose.
- JEBailey 14y agoI follow most of what's occurring within this document, but there's a bit that's throwing me and I hope someone can shed some light. When you're processing the step SET A,B Does A have to represent a register, or is it a memory location or is it both and the registry is just a location in ram?
- viraptor 14y agoa and b are just decoded value bits. That means they can be either one of those things. 0x00-0x07: registers themselves, 0x08-0x0f: addressing via register, etc.
- overshard 14y agoI wonder if it's just me but this game has me more excited about programming in ASM than I ever have, ever... Also in this game I feel like I'll be playing the reverse role I play in real life. IRL I generally always advocate using things like Python and open sourcing everything. In this game I'm definitely going to pull a Steve Jobs, hire out a few friends of mine to program my ASM apps and sell them in some kind of Market for insanely marked up prices telling people that my Orange(TM) software is so much better than Macrosofts(TM)! (And it will be!)
- redthrowaway 14y agoWhen you sell it, however, you'll be selling the source. No pre-compiled binaries, here. Might be a bit difficult to charge for something people can trade for free.
- Benjo 14y agoNo, the binaries may be easier to disassemble, but it's still machine code. I don't have to include the assembly source if I don't want to.
- kierdavis 14y agoIs there an official assembler for this yet, or shall I roll my own?
- wccrawford 14y agoNo, but there's an emulator! https://github.com/swetland/dcpu16 https://github.com/swetland/dcpu16 (Found on Reddit. I haven't tried it.)
- deleted 14y ago[deleted]
- clavalle 14y agoI created a subreddit for this interesting aspect of 0x10c if anyone is interested: http://www.reddit.com/r/dcpu_16_programming/ http://www.reddit.com/r/dcpu_16_programming/
- rg0ne 14y agoThat compulses me to take Compiler class next semester, and write a C compiler for this precious fictional CPU. And what about creating this cpu?
- uvdiv 14y agoI'm not sure if it's well-specified. What does this do? JSR POP Does the argument POP (or [SP++]) get evaluated before, or after, the "[--SP] <- PC" implicit in JSR?
- Anderkent 14y agoInteresting question. Spec says 'a is always handled by the processor before b, and is the lower six bits.' For Non-basic opcodes, 'a' is actually the opcode, and b is the argument. This would imply JSR is evaluated before POP. What we want JSR POP to mean, of course, is 'jump to the last item on the stack, then push PC+1 to stack'. So I would guess that's how it actually works, and the spec needs a revision.
- uvdiv 14y agoI think that line is specific to the basic instructions only (if it weren't, "...and is the lower six bits" would be false). "For Non-basic opcodes, 'a' is actually the opcode" Actually it's the single argument -- 'o' is the opcode.
- Florin_Andrei 14y agoI'm guessing someone is already working on a real-world version of it in an FPGA. Just for fun.
- deleted 14y ago[deleted]
- mappum 14y agoI'm making a compiler/executor for it: https://github.com/mappum/DCPU-16 https://github.com/mappum/DCPU-16.
- lukesd 14y agoHey guys. If you're interesting in discussing this, head on over to #0x10c-dev on Freenode!