Skip to content

Instantly share code, notes, and snippets.

@cassiebeckley
Created March 5, 2013 20:11
Show Gist options
  • Save cassiebeckley/5093838 to your computer and use it in GitHub Desktop.
Save cassiebeckley/5093838 to your computer and use it in GitHub Desktop.
Test of saturn's Python interface This shows a Python device being created and attached to a DCPU.
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from galaxpy import saturn
>>> cpu = saturn.dcpu()
>>> cpu.A
0
>>> class test_device(saturn.device):
... def interrupt(self):
... print("Interrupted")
... def cycle(self):
... print("Cycled")
...
>>> hw = test_device()
>>> dir(hw)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__form
at__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__',
'__lt__', '__module__', '__ne__', '__new__', '__qualname__', '__reduce__', '__r
educe_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook
__', '__weakref__', 'cycle', 'id', 'interrupt', 'manufacturer', 'name', 'version
']
>>> cpu.attach_device(hw)
>>> cpu.flash([0x1a00])
>>> cpu[0]
6656
>>> cpu.I
0
>>> cpu.cycle()
Cycled
>>> cpu.I
1
>>> cpu.reset()
>>> cpu.PC
0
>>> cpu.flash([0x7e40, 0x0000])
>>> cpu.cycle()
Cycled
Interrupted
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment