python-dcpu_16/README.mdown
2012-04-08 20:16:57 +02:00

51 lines
2.1 KiB
Markdown

# What is this?
A DCPU-16 implementation in Python. See [the spec][0].
# What's the goal of this?
Many high-level implementations looked like C-in-other-language, so let's have a pythonic enough (whatever that means, but you should [read][1] [this][2]) implementation. The spirit of the thing is to be educative for everyone.
# How do I use this?
It's meant to be used interactively via the Python REPL as well as programmatically. A specific ASM REPL might be implemented at some point.
An example of a Python REPL session:
>>> from dcpu_16 import CPU, spec_demo
>>> c = CPU(debug=True)
>>> c.load_m(spec_demo) # loads demo program
>>> c.step() # step by one instruction
<< SET
<< c.r[0x0]
<< c.m[0x0001]
<< A=0030 B=0000 C=0000 X=0000 Y=0000 Z=0000 I=0000 J=0000 PC=0002 SP=0000 O=0000
>>> c.pc = 0xA # jump to 'loopy thing'
>>> c.step()
<< SET
<< c.r[0x6]
<< 0x000A
<< A=0030 B=0000 C=0000 X=0000 Y=0000 Z=0000 I=000A J=0000 PC=000B SP=0000 O=0000
>>> c.reset() # reset CPU
>>> c.clear() # clear memory
>>> c.dump_r() # get CPU register state as string
'A=0000 B=0000 C=0000 X=0000 Y=0000 Z=0000 I=0000 J=0000 PC=0000 SP=0000 O=0000'
# What is the status of this?
As of v1.0 the CPU implementation ought to be complete according to DCPU-16 spec v1.1.
# Features
Opcodes and valcodes are as declarative as possible using decorators, leaving the dispatcher as a quasi-one-liner and leveraging `dict` power instead of `if`/`elif`.
Using functions/methods mean there are doctrings everywhere, hence documentation is both very local and as exhaustive as possible. Try `help(dcpu_16)`.
You can use `cpu[]` to dispatch valcodes and get/set directly without having to handle a pointer structure.
The CPU is a class, so you can instantiate a bunch of them. I might move memory outside the CPU so that it would be shared by CPU instances (SMP!)
[0]: http://0x10c.com/doc/dcpu-16.txt
[1]: http://www.dabeaz.com/generators/
[2]: http://www.dabeaz.com/coroutines/