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