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