import array import StringIO import zlib import Image import struct import time import convert def pad4(s): while len(s) % 4: s += chr(0) return s import gameduino2.registers as reg import gameduino2.base class GD2Exception(Exception): pass class GD2(gameduino2.base.GD2): def __init__(self, transport): self.ramptr = 0 self.wp = 0 self.cc = StringIO.StringIO() self.transport = transport self.transport.reset() self.wr(reg.REG_GPIO, 0xff) self.wr32(reg.REG_HCYCLE, 525) self.wr32(reg.REG_HOFFSET, 43) self.wr32(reg.REG_HSIZE, 480) self.wr32(reg.REG_HSYNC0, 0) self.wr32(reg.REG_HSYNC1, 41) self.wr32(reg.REG_VCYCLE, 286) self.wr32(reg.REG_VOFFSET, 12) self.wr32(reg.REG_VSIZE, 272) self.wr32(reg.REG_VSYNC0, 0) self.wr32(reg.REG_VSYNC1, 10) self.wr32(reg.REG_CSPREAD, 1) self.wr32(reg.REG_DITHER, 1) self.wr32(reg.REG_PCLK_POL, 1) self.cmd_dlstart() self.Clear(1,1,1) self.Display() self.cmd_swap() self.cmd_regwrite(reg.REG_PCLK, 5) self.finish() def rdstr(self, a, n): return self.transport.rdstr(a, n) def wrstr(self, a, s): return self.transport.wrstr(a, s) def wr(self, a, v): """ Write a single byte ``v`` to address ``a``. """ self.wrstr(a, chr(v)) def rd(self, a): """ Read byte at address ``a`` """ return struct.unpack("