8c5d945d645c958caaa6ab64babb4139e7ee8bc7
[goodfet] / client / GoodFET.py
1 #!/usr/bin/env python
2 # GoodFET Client Library
3
4 # (C) 2009 Travis Goodspeed <travis at radiantmachines.com>
5 #
6 # This code is being rewritten and refactored.  You've been warned!
7
8 import sys, time, string, cStringIO, struct, glob, os;
9 import sqlite3;
10
11 fmt = ("B", "<H", None, "<L")
12
13 def getClient(name="GoodFET"):
14     import GoodFET, GoodFETCC, GoodFETAVR, GoodFETSPI, GoodFETMSP430, GoodFETNRF, GoodFETCCSPI;
15     if(name=="GoodFET" or name=="monitor"): return GoodFET.GoodFET();
16     elif name=="cc" or name=="cc51": return GoodFETCC.GoodFETCC();
17     elif name=="cc2420" or name=="ccspi": return GoodFETCCSPI.GoodFETCCSPI();
18     elif name=="avr": return GoodFETAVR.GoodFETAVR();
19     elif name=="spi": return GoodFETSPI.GoodFETSPI();
20     elif name=="msp430": return GoodFETMSP430.GoodFETMSP430();
21     elif name=="nrf": return GoodFETNRF.GoodFETNRF();
22     
23     print "Unsupported target: %s" % name;
24     sys.exit(0);
25
26 class SymbolTable:
27     """GoodFET Symbol Table"""
28     db=sqlite3.connect(":memory:");
29     
30     def __init__(self, *args, **kargs):
31         self.db.execute("create table if not exists symbols(adr,name,memory,size,comment);");
32     def get(self,name):
33         self.db.commit();
34         c=self.db.cursor();
35         try:
36             c.execute("select adr,memory from symbols where name=?",(name,));
37             for row in c:
38                 #print "Found it.";
39                 sys.stdout.flush();
40                 return row[0];
41             #print "No dice.";
42         except:# sqlite3.OperationalError:
43             #print "SQL error.";
44             return eval(name);
45         return eval(name);
46     def define(self,adr,name,comment="",memory="vn",size=16):
47         self.db.execute("insert into symbols(adr,name,memory,size,comment)"
48                         "values(?,?,?,?,?);", (
49                 adr,name,memory,size,comment));
50         #print "Set %s=%s." % (name,adr);
51 class GoodFETbtser:
52     """py-bluez class for emulating py-serial."""
53     def __init__(self,btaddr):
54         import bluetooth;
55         if btaddr==None or btaddr=="none" or btaddr=="bluetooth":
56             print "performing inquiry..."
57             nearby_devices = bluetooth.discover_devices(lookup_names = True)
58             print "found %d devices" % len(nearby_devices)
59             for addr, name in nearby_devices:
60                 print "  %s - '%s'" % (addr, name)
61                 if name=='FireFly-A6BD':
62                     btaddr=addr;
63             print "Please set $GOODFET to the address of your device.";
64             sys.exit();
65         print "Identified GoodFET at %s" % btaddr;
66
67         # Manually use the portnumber.
68         port=1;
69         
70         print "Connecting to %s on port %i." % (btaddr, port);
71         sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM);
72         self.sock=sock;
73         sock.connect((btaddr,port));
74         sock.settimeout(10);  #IMPORTANT Must be patient.
75         
76         ##This is what we'd do for a normal reset.
77         #str="";
78         #while not str.endswith("goodfet.sf.net/"):
79         #    str=self.read(64);
80         #    print str;
81         
82         # Instead, just return and hope for the best.
83         return;
84         
85     def write(self,msg):
86         """Send traffic."""
87         import time;
88         self.sock.send(msg);
89         #time.sleep(0.1);
90         return;
91     def read(self,length):
92         """Read traffic."""
93         data="";
94         while len(data)<length:
95             data=data+self.sock.recv(length-len(data));
96         return data;
97 class GoodFET:
98     """GoodFET Client Library"""
99
100     besilent=0;
101     app=0;
102     verb=0;
103     count=0;
104     data="";
105     verbose=False
106     
107     GLITCHAPP=0x71;
108     MONITORAPP=0x00;
109     symbols=SymbolTable();
110     
111     def __init__(self, *args, **kargs):
112         self.data=[0];
113     def getConsole(self):
114         from GoodFETConsole import GoodFETConsole;
115         return GoodFETConsole(self);
116     def name2adr(self,name):
117         return self.symbols.get(name);
118     def timeout(self):
119         print "timeout\n";
120     def serInit(self, port=None, timeout=2, attemptlimit=None):
121         """Open a serial port of some kind."""
122         import re;
123         
124         if port==None:
125             port=os.environ.get("GOODFET");
126         if port=="bluetooth" or (port is not None and re.match("..:..:..:..:..:..",port)):
127             self.btInit(port,timeout,attemptlimit);
128         else:
129             self.pyserInit(port,timeout,attemptlimit);
130     def btInit(self, port, timeout, attemptlimit):
131         """Open a bluetooth port.""";
132         #self.verbose=True;  #For debugging BT.
133         self.serialport=GoodFETbtser(port);
134         
135     def pyserInit(self, port, timeout, attemptlimit):
136         """Open the serial port"""
137         # Make timeout None to wait forever, 0 for non-blocking mode.
138         import serial;
139         
140         if os.name=='nt' and sys.version.find('64 bit')!=-1:
141             print "WARNING: PySerial requires a 32-bit Python build in Windows.";
142         
143         if port is None and os.environ.get("GOODFET")!=None:
144             glob_list = glob.glob(os.environ.get("GOODFET"));
145             if len(glob_list) > 0:
146                 port = glob_list[0];
147             else:
148                 port = os.environ.get("GOODFET");
149         if port is None:
150             glob_list = glob.glob("/dev/tty.usbserial*");
151             if len(glob_list) > 0:
152                 port = glob_list[0];
153         if port is None:
154             glob_list = glob.glob("/dev/ttyUSB*");
155             if len(glob_list) > 0:
156                 port = glob_list[0];
157         if port is None:
158             glob_list = glob.glob("/dev/ttyU0");
159             if len(glob_list) > 0:
160                 port = glob_list[0];
161         if port is None and os.name=='nt':
162             from scanwin32 import winScan;
163             scan=winScan();
164             for order,comport,desc,hwid in sorted(scan.comports()):
165                 try:
166                     if hwid.index('FTDI')==0:
167                         port=comport;
168                         #print "Using FTDI port %s" % port
169                 except:
170                     #Do nothing.
171                     a=1;
172         
173         baud=115200;
174         if(os.environ.get("platform")=='arduino'):
175             baud=19200; #Slower, for now.
176         self.serialport = serial.Serial(
177             port,
178             #9600,
179             baud,
180             parity = serial.PARITY_NONE,
181             timeout=timeout
182             )
183         
184         self.verb=0;
185         attempts=0;
186         connected=0;
187         while connected==0:
188             while self.verb!=0x7F or self.data!="http://goodfet.sf.net/":
189             #while self.data!="http://goodfet.sf.net/":
190                 #print "'%s'!=\n'%s'" % (self.data,"http://goodfet.sf.net/");
191                 if attemptlimit is not None and attempts >= attemptlimit:
192                     return
193                 elif attempts>2:
194                     print "Resyncing.";
195                 self.serialport.flushInput()
196                 self.serialport.flushOutput()
197                 
198                 #TelosB reset, prefer software to I2C SPST Switch.
199                 if(os.environ.get("platform")=='telosb'):
200                     #print "TelosB Reset";
201                     self.telosBReset();
202                 else:
203                     #Explicitly set RTS and DTR to halt board.
204                     self.serialport.setRTS(1);
205                     self.serialport.setDTR(1);
206                     #Drop DTR, which is !RST, low to begin the app.
207                     self.serialport.setDTR(0);
208                 
209                 #self.serialport.write(chr(0x80));
210                 #self.serialport.write(chr(0x80));
211                 #self.serialport.write(chr(0x80));
212                 #self.serialport.write(chr(0x80));
213                 
214                 
215                 #self.serialport.flushInput()
216                 #self.serialport.flushOutput()
217                 #time.sleep(60);
218                 attempts=attempts+1;
219                 self.readcmd(); #Read the first command.
220                 #print "Got %02x,%02x:'%s'" % (self.app,self.verb,self.data);
221             #Here we have a connection, but maybe not a good one.
222             #print "We have a connection."
223             connected=1;
224             olds=self.infostring();
225             clocking=self.monitorclocking();
226             #if(os.environ.get("platform")!='arduino'):
227             for foo in range(1,30):
228                 if not self.monitorecho():
229                     if self.verbose:
230                         print "Comm error on %i try, resyncing out of %s." % (foo,
231                                                                               clocking);
232                         connected=0;
233                         break;
234         if self.verbose: print "Connected after %02i attempts." % attempts;
235         self.mon_connected();
236         self.serialport.setTimeout(12);
237     def serClose(self):
238         self.serialport.close();
239     def telosSetSCL(self, level):
240         self.serialport.setRTS(not level)
241     def telosSetSDA(self, level):
242         self.serialport.setDTR(not level)
243
244     def telosI2CStart(self):
245         self.telosSetSDA(1)
246         self.telosSetSCL(1)
247         self.telosSetSDA(0)
248
249     def telosI2CStop(self):
250         self.telosSetSDA(0)
251         self.telosSetSCL(1)
252         self.telosSetSDA(1)
253
254     def telosI2CWriteBit(self, bit):
255         self.telosSetSCL(0)
256         self.telosSetSDA(bit)
257         time.sleep(2e-6)
258         self.telosSetSCL(1)
259         time.sleep(1e-6)
260         self.telosSetSCL(0)
261
262     def telosI2CWriteByte(self, byte):
263         self.telosI2CWriteBit( byte & 0x80 );
264         self.telosI2CWriteBit( byte & 0x40 );
265         self.telosI2CWriteBit( byte & 0x20 );
266         self.telosI2CWriteBit( byte & 0x10 );
267         self.telosI2CWriteBit( byte & 0x08 );
268         self.telosI2CWriteBit( byte & 0x04 );
269         self.telosI2CWriteBit( byte & 0x02 );
270         self.telosI2CWriteBit( byte & 0x01 );
271         self.telosI2CWriteBit( 0 );  # "acknowledge"
272
273     def telosI2CWriteCmd(self, addr, cmdbyte):
274         self.telosI2CStart()
275         self.telosI2CWriteByte( 0x90 | (addr << 1) )
276         self.telosI2CWriteByte( cmdbyte )
277         self.telosI2CStop()
278
279     def telosBReset(self,invokeBSL=0):
280         # "BSL entry sequence at dedicated JTAG pins"
281         # rst !s0: 0 0 0 0 1 1
282         # tck !s1: 1 0 1 0 0 1
283         #   s0|s1: 1 3 1 3 2 0
284
285         # "BSL entry sequence at shared JTAG pins"
286         # rst !s0: 0 0 0 0 1 1
287         # tck !s1: 0 1 0 1 1 0
288         #   s0|s1: 3 1 3 1 0 2
289
290         if invokeBSL:
291             self.telosI2CWriteCmd(0,1)
292             self.telosI2CWriteCmd(0,3)
293             self.telosI2CWriteCmd(0,1)
294             self.telosI2CWriteCmd(0,3)
295             self.telosI2CWriteCmd(0,2)
296             self.telosI2CWriteCmd(0,0)
297         else:
298             self.telosI2CWriteCmd(0,3)
299             self.telosI2CWriteCmd(0,2)
300
301         # This line was not defined inside the else: block, not sure where it
302         # should be however
303         self.telosI2CWriteCmd(0,0)
304         time.sleep(0.250)       #give MSP430's oscillator time to stabilize
305         self.serialport.flushInput()  #clear buffers
306
307
308     def getbuffer(self,size=0x1c00):
309         writecmd(0,0xC2,[size&0xFF,(size>>16)&0xFF]);
310         print "Got %02x%02x buffer size." % (self.data[1],self.data[0]);
311     def writecmd(self, app, verb, count=0, data=[]):
312         """Write a command and some data to the GoodFET."""
313         self.serialport.write(chr(app));
314         self.serialport.write(chr(verb));
315         
316         #if data!=None:
317         #    count=len(data); #Initial count ignored.
318         
319         #print "TX %02x %02x %04x" % (app,verb,count);
320         
321         #little endian 16-bit length
322         self.serialport.write(chr(count&0xFF));
323         self.serialport.write(chr(count>>8));
324
325         if self.verbose:
326             print "Tx: ( 0x%02x, 0x%02x, 0x%04x )" % ( app, verb, count )
327         
328         #print "count=%02x, len(data)=%04x" % (count,len(data));
329         
330         if count!=0:
331             if(isinstance(data,list)):
332                 for i in range(0,count):
333                 #print "Converting %02x at %i" % (data[i],i)
334                     data[i]=chr(data[i]);
335             #print type(data);
336             outstr=''.join(data);
337             self.serialport.write(outstr);
338         if not self.besilent:
339             return self.readcmd()
340         else:
341             return []
342
343     def readcmd(self):
344         """Read a reply from the GoodFET."""
345         while 1:#self.serialport.inWaiting(): # Loop while input data is available
346             try:
347                 #print "Reading...";
348                 self.app=ord(self.serialport.read(1));
349                 #print "APP=%02x" % self.app;
350                 self.verb=ord(self.serialport.read(1));
351                 
352                 #Fixes an obscure bug in the TelosB.
353                 if self.app==0x00:
354                     while self.verb==0x00:
355                         self.verb=ord(self.serialport.read(1));
356                 
357                 #print "VERB=%02x" % self.verb;
358                 self.count=(
359                     ord(self.serialport.read(1))
360                     +(ord(self.serialport.read(1))<<8)
361                     );
362
363                 if self.verbose:
364                     print "Rx: ( 0x%02x, 0x%02x, 0x%04x )" % ( self.app, self.verb, self.count )
365             
366                 #Debugging string; print, but wait.
367                 if self.app==0xFF:
368                     if self.verb==0xFF:
369                         print "# DEBUG %s" % self.serialport.read(self.count)
370                     elif self.verb==0xFE:
371                         print "# DEBUG 0x%x" % struct.unpack(fmt[self.count-1], self.serialport.read(self.count))[0]
372                     elif self.verb==0xFD:
373                         #Do nothing, just wait so there's no timeout.
374                         print "# NOP.";
375                         
376                     sys.stdout.flush();
377                 else:
378                     self.data=self.serialport.read(self.count);
379                     return self.data;
380             except TypeError:
381                 if self.connected:
382                     print "Warning: waiting for serial read timed out (most likely).";
383                     #print "This shouldn't happen after syncing.  Exiting for safety.";                    
384                     #sys.exit(-1)
385                 return self.data;
386     #Glitching stuff.
387     def glitchApp(self,app):
388         """Glitch into a device by its application."""
389         self.data=[app&0xff];
390         self.writecmd(self.GLITCHAPP,0x80,1,self.data);
391         #return ord(self.data[0]);
392     def glitchVerb(self,app,verb,data):
393         """Glitch during a transaction."""
394         if data==None: data=[];
395         self.data=[app&0xff, verb&0xFF]+data;
396         self.writecmd(self.GLITCHAPP,0x81,len(self.data),self.data);
397         #return ord(self.data[0]);
398     def glitchstart(self):
399         """Glitch into the AVR application."""
400         self.glitchVerb(self.APP,0x20,None);
401     def glitchstarttime(self):
402         """Measure the timer of the START verb."""
403         return self.glitchTime(self.APP,0x20,None);
404     def glitchTime(self,app,verb,data):
405         """Time the execution of a verb."""
406         if data==None: data=[];
407         self.data=[app&0xff, verb&0xFF]+data;
408         print "Timing app %02x verb %02x." % (app,verb);
409         self.writecmd(self.GLITCHAPP,0x82,len(self.data),self.data);
410         time=ord(self.data[0])+(ord(self.data[1])<<8);
411         print "Timed to be %i." % time;
412         return time;
413     def glitchVoltages(self,low=0x0880, high=0x0fff):
414         """Set glitching voltages. (0x0fff is max.)"""
415         self.data=[low&0xff, (low>>8)&0xff,
416                    high&0xff, (high>>8)&0xff];
417         self.writecmd(self.GLITCHAPP,0x90,4,self.data);
418         #return ord(self.data[0]);
419     def glitchRate(self,count=0x0800):
420         """Set glitching count period."""
421         self.data=[count&0xff, (count>>8)&0xff];
422         self.writecmd(self.GLITCHAPP,0x91,2,
423                       self.data);
424         #return ord(self.data[0]);
425     
426     
427     #Monitor stuff
428     def silent(self,s=0):
429         """Transmissions halted when 1."""
430         self.besilent=s;
431         print "besilent is %i" % self.besilent;
432         self.writecmd(0,0xB0,1,[s]);
433     connected=0;
434     def mon_connected(self):
435         """Announce to the monitor that the connection is good."""
436         self.connected=1;
437         self.writecmd(0,0xB1,0,[]);
438     def out(self,byte):
439         """Write a byte to P5OUT."""
440         self.writecmd(0,0xA1,1,[byte]);
441     def dir(self,byte):
442         """Write a byte to P5DIR."""
443         self.writecmd(0,0xA0,1,[byte]);
444     def call(self,adr):
445         """Call to an address."""
446         self.writecmd(0,0x30,2,
447                       [adr&0xFF,(adr>>8)&0xFF]);
448     def execute(self,code):
449         """Execute supplied code."""
450         self.writecmd(0,0x31,2,#len(code),
451                       code);
452     def MONpeek8(self,address):
453         """Read a byte of memory from the monitor."""
454         self.data=[address&0xff,address>>8];
455         self.writecmd(0,0x02,2,self.data);
456         #self.readcmd();
457         return ord(self.data[0]);
458     def MONpeek16(self,address):
459         """Read a word of memory from the monitor."""
460         return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8);
461     def peek(self,address):
462         """Read a word of memory from the monitor."""
463         return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8);
464     def eeprompeek(self,address):
465         """Read a word of memory from the monitor."""
466         print "EEPROM peeking not supported for the monitor.";
467         #return self.MONpeek8(address)+(self.MONpeek8(address+1)<<8);
468     def peekbysym(self,name):
469         """Read a value by its symbol name."""
470         #TODO include memory in symbol.
471         reg=self.symbols.get(name);
472         return self.peek8(reg,"data");
473     def pokebysym(self,name,val):
474         """Write a value by its symbol name."""
475         #TODO include memory in symbol.
476         reg=self.symbols.get(name);
477         return self.pokebyte(reg,val);
478     def pokebyte(self,address,value,memory="vn"):
479         """Set a byte of memory by the monitor."""
480         self.data=[address&0xff,address>>8,value];
481         self.writecmd(0,0x03,3,self.data);
482         return ord(self.data[0]);
483     def poke16(self,address,value):
484         """Set a word of memory by the monitor."""
485         self.pokebyte(address,value&0xFF);
486         self.pokebyte(address,(value>>8)&0xFF);
487         return value;
488     def setsecret(self,value):
489         """Set a secret word for later retreival.  Used by glitcher."""
490         #self.eeprompoke(0,value);
491         #self.eeprompoke(1,value);
492         print "Secret setting is not yet suppored for this target.";
493         print "Aborting.";
494         
495     def getsecret(self):
496         """Get a secret word.  Used by glitcher."""
497         #self.eeprompeek(0);
498         print "Secret getting is not yet suppored for this target.";
499         print "Aborting.";
500         sys.exit();
501     
502     def dumpmem(self,begin,end):
503         i=begin;
504         while i<end:
505             print "%04x %04x" % (i, self.MONpeek16(i));
506             i+=2;
507     def monitor_ram_pattern(self):
508         """Overwrite all of RAM with 0xBEEF."""
509         self.writecmd(0,0x90,0,self.data);
510         return;
511     def monitor_ram_depth(self):
512         """Determine how many bytes of RAM are unused by looking for 0xBEEF.."""
513         self.writecmd(0,0x91,0,self.data);
514         return ord(self.data[0])+(ord(self.data[1])<<8);
515     
516     #Baud rates.
517     baudrates=[115200, 
518                9600,
519                19200,
520                38400,
521                57600,
522                115200];
523     def setBaud(self,baud):
524         """Change the baud rate.  TODO fix this."""
525         rates=self.baudrates;
526         self.data=[baud];
527         print "Changing FET baud."
528         self.serialport.write(chr(0x00));
529         self.serialport.write(chr(0x80));
530         self.serialport.write(chr(1));
531         self.serialport.write(chr(baud));
532         
533         print "Changed host baud."
534         self.serialport.setBaudrate(rates[baud]);
535         time.sleep(1);
536         self.serialport.flushInput()
537         self.serialport.flushOutput()
538         
539         print "Baud is now %i." % rates[baud];
540         return;
541     def readbyte(self):
542         return ord(self.serialport.read(1));
543     def findbaud(self):
544         for r in self.baudrates:
545             print "\nTrying %i" % r;
546             self.serialport.setBaudrate(r);
547             #time.sleep(1);
548             self.serialport.flushInput()
549             self.serialport.flushOutput()
550             
551             for i in range(1,10):
552                 self.readbyte();
553             
554             print "Read %02x %02x %02x %02x" % (
555                 self.readbyte(),self.readbyte(),self.readbyte(),self.readbyte());
556     def monitortest(self):
557         """Self-test several functions through the monitor."""
558         print "Performing monitor self-test.";
559         self.monitorclocking();
560         for f in range(0,3000):
561             a=self.MONpeek16(0x0c00);
562             b=self.MONpeek16(0x0c02);
563             if a!=0x0c04 and a!=0x0c06:
564                 print "ERROR Fetched %04x, %04x" % (a,b);
565             self.pokebyte(0x0021,0); #Drop LED
566             if self.MONpeek8(0x0021)!=0:
567                 print "ERROR, P1OUT not cleared.";
568             self.pokebyte(0x0021,1); #Light LED
569             if not self.monitorecho():
570                 print "Echo test failed.";
571         print "Self-test complete.";
572         self.monitorclocking();
573     def monitorecho(self):
574         data="The quick brown fox jumped over the lazy dog.";
575         self.writecmd(self.MONITORAPP,0x81,len(data),data);
576         if self.data!=data:
577             print "Comm error recognized by monitorecho(), got:\n%s" % self.data;
578             return 0;
579         return 1;
580
581     def monitor_info(self):
582         print "GoodFET with %s MCU" % self.infostring();
583         print "Clocked at %s" % self.monitorclocking();
584         return 1;
585
586     def monitor_list_apps(self, full=False): 
587         self.monitor_info()
588         old_value = self.besilent
589         self.besilent = True    # turn off automatic call to readcmd
590         self.writecmd(self.MONITORAPP, 0x82, 1, [int(full)]);
591         self.besilent = old_value
592         
593         # read the build date string 
594         self.readcmd()
595         print "Build Date: %s" % self.data
596         print "Firmware apps:"
597         while True:
598             self.readcmd()
599             if self.count == 0:
600                 break
601             print self.data
602         return 1;
603
604     def monitorclocking(self):
605         """Return the 16-bit clocking value."""
606         return "0x%04x" % self.monitorgetclock();
607     
608     def monitorsetclock(self,clock):
609         """Set the clocking value."""
610         self.MONpoke16(0x56, clock);
611     def monitorgetclock(self):
612         """Get the clocking value."""
613         if(os.environ.get("platform")=='arduino'):
614             return 0xDEAD;
615         #Check for MSP430 before peeking this.
616         return self.MONpeek16(0x56);
617     # The following functions ought to be implemented in
618     # every client.
619     
620     def infostring(self):
621         if(os.environ.get("platform")=='arduino'):
622             return "Arduino";
623         else:
624             a=self.MONpeek8(0xff0);
625             b=self.MONpeek8(0xff1);
626             return "%02x%02x" % (a,b);
627     def lock(self):
628         print "Locking Unsupported.";
629     def erase(self):
630         print "Erasure Unsupported.";
631     def setup(self):
632         return;
633     def start(self):
634         return;
635     def test(self):
636         print "Unimplemented.";
637         return;
638     def status(self):
639         print "Unimplemented.";
640         return;
641     def halt(self):
642         print "Unimplemented.";
643         return;
644     def resume(self):
645         print "Unimplemented.";
646         return;
647     def getpc(self):
648         print "Unimplemented.";
649         return 0xdead;
650     def flash(self,file):
651         """Flash an intel hex file to code memory."""
652         print "Flash not implemented.";
653     def dump(self,file,start=0,stop=0xffff):
654         """Dump an intel hex file from code memory."""
655         print "Dump not implemented.";
656     def peek32(self,address, memory="vn"):
657         """Peek 32 bits."""
658         return (self.peek16(address,memory)+
659                 (self.peek16(address+2,memory)<<16));
660     def peek16(self,address, memory="vn"):
661         """Peek 16 bits of memory."""
662         return (self.peek8(address,memory)+
663                 (self.peek8(address+1,memory)<<8));
664     def peek8(self,address, memory="vn"):
665         """Peek a byte of memory."""
666         return self.MONpeek8(address); #monitor
667     def peekblock(self,address,length,memory="vn"):
668         """Return a block of data."""
669         data=range(0,length);
670         for foo in range(0,length):
671             data[foo]=self.peek8(address+foo,memory);
672         return data;
673     def pokeblock(self,address,bytes,memory="vn"):
674         """Poke a block of a data into memory at an address."""
675         for foo in bytes:
676             self.pokebyte(address,foo,memory);
677             address=address+1;
678         return;
679     def loadsymbols(self):
680         """Load symbols from a file."""
681         return;