7 ms·
Python-based implementation of Notch's DCPU-16
- mahmud 15y agothis one is one of the more complete ones: has a disassembler. should be trivial to add stepping and breakpoints.
- dbh937 15y agoThere should just be one thread for all the dcpu-16 implementations
- look_lookatme 15y agoWhat is a good resource for understanding how all of this works? Books, site, tutorial, minix usenet threads... I don't care, just something to get me started. edit: Assuming I'm a standard, competent web dev-ish Ruby, Python programmer with little experience below those languages.
- jlawer 15y agoYour best bet is a university text book on computer architecture. The course I took used a decimal based CPU (not binary) and had many other "simplifications" but its probably your best bet, at least unless you want to learn assembly level programming full stop... in which case there is some really good 32bit linux asm tutorials out there (64 bit stuff isn't as common). This is basically part of most first year IT / CS courses, and kind of not used in day to day IT so many self taught programmers never learn it.
- jtauber 15y agoI'm actually planning on writing some tutorials based around DCPU-16 as it's a nice small instruction set with very orthogonal addressing modes (but don't worry if you don't know what that means :-) Sort of a "Assembly Language for Python programmers" guide
- patrickod 15y agoI would absolutely love to read this when it's done. Having never officially studied any of this I feel my knowledge is really lacking.
- jtauber 15y agoI wouldn't be able to help with the more modern stuff but given DCPU-16 is designed to be an 80s-era CPU it suits my experience quite well :-)
- patrickod 15y agoI'm not really looking to learn as a means to expand my field of working expertise but more for the sake of it. My programming experience has been firmly rooted in higher level languages and I think this is a perfect opportunity to learn something new and potentially useful. I don't like the idea of having the lower levels of programming remain a black box as such
- anthonyb 15y agoYou might be interested in py4fun - it has a fairly light weight introduction to a "mythical machine", including assembler and compiler: http://openbookproject.net/py4fun/ http://openbookproject.net/py4fun/
- hendzen 15y agoFirst read K&R C and get comfortable writing C programs. Then pick up the latest edition of Patterson & Hennessy and learn the MIPS ISA. It's a very simple instruction set that avoids most of the pedagogical distractions imposed by x86 or some other more complicated architecture.
- tptacek 15y agoSecond Hennesy & Patterson. Read it 12 years ago, still remember it vividly; everything made more sense afterwards. It's expensive though; you might do just as well with a used older edition. A somewhat perverse alternative approach: get a book on how debuggers work (like "How Debuggers Work").
- hendzen 15y agoI actually have the pleasure of taking a course with Patterson this semester. He's a great lecturer and he manages to keep the (sometimes very dry) material very interesting.
- mahmud 15y agoFucker broke my wrist .. wrong book to read on the crapper.
- nja 15y agoThe book is pretty well-written, but I've found the exercises to be very hard to get through. Still, it's a great resource for this type of work.
- AdamTReineke 15y agoWhy the latest edition? We're using the 2nd edition (from 1998) in my computer architecture class this semester and it seems just fine. Even better was getting it off Half.com for <$10 after shipping.
- hendzen 15y agoPersonally, I think that the latest edition has a lot of valuable material on parallelism and GPU programming. It's not strictly necessary for what he was asking, but its good stuff to know nonetheless.
- jmpeax 15y agoWaiting for a glsl implementation.
- jlawer 15y agoI am fairly sure notch would have one... if he is planning on running this, then I am going to imagine that he is basically going to have massive farms of GPGPUs planned for doing this emulation.
- jerf 15y agoYou could try to run a simulation of branch-heavy code on your hardware optimized for branchless number crunching, but you're probably better off compiling the opcodes into something that you can then use to simulate branch-heavy code on your branch-heavy-code-optimized hardware.
- jlawer 15y agoGood Point sir.... But I was kind of imagining that you could essentially emulate a single virtual system per "Stream processor" or whatever they are labeling the basic units. I was factoring that they could run a couple of hundred "virtual cores" per card despite the fact they weren't that optimized. But I will be the first to admit to not really knowing the details. The other option of course is something like intel's Knights Corner architecture, which wouldn't pay such a penalty on performance for branching.
- lucian1900 15y agoBranching used to be done by turning the memory of the cores that failed an if test to read-only and just letting all of them continue the computation. It's gotten better now, but branching is still extremely unwieldy to do. No branch prediction either.
- jlawer 15y agoI suppose the question is if you would need to have multiple cores running simultaneously on the same processing element, or if the fact you have some many processing elements means you can just be inefficent and give each core the role of emulating a processor. I haven't seen anything about the core speed of the virtual cpu. however if its 5 or 10mhz, you don't really need high performance or efficency, your just need a way of craming more jobs into your servers and leaving the CPUs to run other game code.
- binarycrusader 15y agoFor the love of pete; please put a copyright notice and license on your code! Even if you want to use the same license as notch, you must explicitly specify that, otherwise, no one can really use your code.
- guelo 15y agoDoesn't no copyright notice mean that it's in the public domain?
- iamwil 15y agoNo. copyright is automatically applied when the work is created. You have to explicitly give more relaxed rights, aka licenses and copylefts, for people to know whether they can use it.
- rplnt 15y agoAnd somewhere even that doesn't help.
- eridius 15y agoNo. Copyright is implicit. Something can only be in the Public Domain if it's explicitly placed there (and supposedly, not all countries even recognize Public Domain, hence the creation of the WTFPL[1]). [1] http://sam.zoy.org/wtfpl/ http://sam.zoy.org/wtfpl/
- masklinn 15y ago> and supposedly, not all countries even recognize Public Domain I'm not sure the phrasing is correct, at least for the most common example of this issue (european copyright tradition of moral rights): many european countries split the anglo-saxon copyright into estate rights (which are economic) and moral rights which are generally perpetual, inalienable, and imprescriptible. As a result, while an author can assign (or waive) their estate rights they can not assign or waive their moral rights. Unless there are additional special cases in the country's lawbooks an author in a moral-rights country can not put his works in the public domain (since it would require waiving rights he can't waive). Either the works can not be copyrighted (and are intrinsically in the public domain) or they will fall into the public domain when the author's rights expire.
- anthonyb 15y agoThat Cell class looks a bit odd, and I can't imagine it's doing good things for your memory use. Perhaps you could simplify it by making your registers a list or a dictionary, rather than a tuple? ie. self.registers = { 'A': 0x0000, ... } then you could access it directly: self.registers['A'] = 0x0001
- jerf 15y agoMemory use isn't the problem, it's the added code complexity. Not having self.registers = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] instead is adding ".value" all over the place where it isn't necessary. I haven't actually tried this but it looks like dropping the Cell class entirely, putting that line in as the definition of registers, then s/.values//g ought to work, or very nearly work. PC, SP, and O are already defined as variables containing the index for that register, a fine way to do it.
- anthonyb 15y agoUsing the array module for registers and memory might be even better - you're not likely to want to randomly add a register or memory bank.
- masklinn 15y agoDoes not fix the issue jtauber pointed out: you can't pass around a section of an array "by reference" so that people can set stuff in e.g. register A.
- jtauber 15y agoThe reason for the Cell() is explained in a comment; I have to be able to pass around references to registers and memory locations distinct from their value. I'm open to alternatives but the above won't work as how do you pass in "register A" or "memory location 0x1000" as the arg to an instruction method in that case?
- masklinn 15y ago
- severb 15y agoHere's a Python asm compiler to go with those tools https://github.com/severb/0x10c-asm https://github.com/severb/0x10c-asm
- coderdude 15y agoThis is so cool. Between jtauber's work and the other versions floating around I can't imagine that we won't be seeing basic compilers for higher level languages soon. So far there are emulators for the CPU, multiple assemblers, and a disassembler. Have you checked out the C version on the front page? He's been updating it like mad.
- jtauber 15y agoOh I hadn't seen this. I've actually implemented my own as part of dcpu16py.
- krollew 15y agoI wonder why so many started to implement VMs for that processor. Just impatience when his next game will be released?
- praptak 15y agoHow did you decide which value of the PC to use (current instruction? next instruction? second word of current instruction?) when PC is one of the operands? The spec is not very clear on when exactly is PC incremented.
- deleted 15y ago[deleted]
- fooooobar 15y agoThat's quite a regex you have.
- VMG 15y agoI'd love to see a Haskell or Lisp implementation
- clavalle 15y agoHere you go: https://docs.google.com/?pli=1#folders/0BxArLOveUH1bb081YWhDOHVTUzZCR2czdFdPOHNXZw https://docs.google.com/?pli=1#folders/0BxArLOveUH1bb081YWhD...
- tzs 15y agoLooks like implementing this thing is becoming the new national passtime, at least based on the number of different implementations that have been discussed on HN in the last day. I wonder how long till someone implements it in minecraft?
- Anirak 15y agoNotch should just put the game as a project on github and watch everyone else make it. Edit: Holy shit, is it just me or is this an amazing idea? It would take someone with a lot of sway to do a project like this (like Notch), but he could literally plan out what parts of the game need to be done and have other people do them. He could then give a piece of the profits back to the developers once the game started selling.
- overshard 15y agoThis is certainly the best implementation so far, clean, readable and actually works. Also allows for writing in ASM and not HEX with the assembler.