2 * Copyright © 2000-2001, Brian Beattie <beattie@aracnet.com>, et. al.
4 * This software was created with the help of proprietary
5 * information belonging to StarDot Technologies
7 * Permission to copy and use and modify this file is granted
8 * provided the above notices are retained, intact.
11 * See CVS log for later revisions
13 * 2001/03/10 - Port to gphoto2 Dan
15 * 2000/09/06 - Modified by Gregg Berg <gberg@covconn.net> GDB
16 * * Rewrite mesa_read_row() to use mesa_image_arg GDB
17 * * Add checksum to mesa_read_row() GDB
18 * * Add return with number of bytes to mesa_read_image() GDB
20 * $Id: mesalib.c 9330 2006-10-14 11:54:47Z hun $
32 #include <gphoto2/gphoto2.h>
33 #include "gphoto2-endian.h"
35 #define GP_MODULE "dimera"
36 #define debuglog(e) GP_DEBUG( "%s", (e))
39 static const uint16_t pixelTable[256] = {
40 0x000, 0x001, 0x002, 0x003, 0x004, 0x005, 0x006, 0x007,
41 0x008, 0x009, 0x00A, 0x00B, 0x00C, 0x00D, 0x00E, 0x00F,
42 0x010, 0x011, 0x012, 0x013, 0x014, 0x015, 0x016, 0x017,
43 0x018, 0x019, 0x01A, 0x01B, 0x01C, 0x01D, 0x01E, 0x01F,
44 0x020, 0x021, 0x022, 0x023, 0x024, 0x025, 0x026, 0x027,
45 0x028, 0x029, 0x02A, 0x02B, 0x02C, 0x02D, 0x02E, 0x02F,
46 0x030, 0x031, 0x032, 0x033, 0x034, 0x035, 0x036, 0x037,
47 0x038, 0x039, 0x03A, 0x03B, 0x03C, 0x03D, 0x03E, 0x03F,
48 0x040, 0x041, 0x042, 0x043, 0x044, 0x045, 0x046, 0x047,
50 0x048, 0x049, 0x04A, 0x04B, 0x04C, 0x04E, 0x04F, 0x050,
51 0x051, 0x052, 0x053, 0x054, 0x055, 0x056, 0x057, 0x058,
52 0x059, 0x05A, 0x05B, 0x05C, 0x05D, 0x05E, 0x05F, 0x060,
53 0x061, 0x062, 0x063, 0x064, 0x066, 0x067, 0x068, 0x069,
54 0x06A, 0x06C, 0x06D, 0x06E, 0x06F, 0x070, 0x072, 0x073,
55 0x074, 0x075, 0x076, 0x077, 0x078, 0x079, 0x07A, 0x07B,
56 0x07C, 0x07E, 0x07F, 0x081, 0x082, 0x084, 0x085, 0x087,
58 0x088, 0x08A, 0x08B, 0x08C, 0x08E, 0x08F, 0x090, 0x092,
59 0x093, 0x094, 0x096, 0x098, 0x09A, 0x09C, 0x09E, 0x0A0,
60 0x0A2, 0x0A3, 0x0A5, 0x0A6, 0x0A8, 0x0A9, 0x0AB, 0x0AC,
61 0x0AE, 0x0B0, 0x0B2, 0x0B4, 0x0B6, 0x0B8, 0x0BA, 0x0BC,
63 0x0BE, 0x0C0, 0x0C2, 0x0C4, 0x0C6, 0x0C8, 0x0CA, 0x0CD,
64 0x0CF, 0x0D2, 0x0D5, 0x0D8, 0x0DB, 0x0DE, 0x0E0, 0x0E2,
65 0x0E5, 0x0E7, 0x0EA, 0x0EC, 0x0EE, 0x0F1, 0x0F3, 0x0F6,
66 0x0FC, 0x102, 0x106, 0x10A, 0x10E, 0x111, 0x114, 0x117,
68 0x11A, 0x11D, 0x120, 0x123, 0x126, 0x12C, 0x132, 0x138,
69 0x13E, 0x142, 0x146, 0x14A, 0x150, 0x156, 0x15A, 0x15E,
70 0x162, 0x166, 0x16A, 0x16E, 0x17A, 0x180, 0x186, 0x18C,
71 0x192, 0x19E, 0x1AA, 0x1B0, 0x1B6, 0x1BA, 0x1BE, 0x1C2,
73 0x1C8, 0x1CE, 0x1DA, 0x1E6, 0x1F2, 0x1FE, 0x204, 0x20A,
74 0x216, 0x222, 0x22E, 0x23A, 0x240, 0x246, 0x24C, 0x252,
76 0x25E, 0x26A, 0x276, 0x282, 0x28E, 0x2A6, 0x2B2, 0x2BE,
77 0x2D6, 0x2EE, 0x2FA, 0x312, 0x336, 0x34E, 0x35e, 0x366
82 * return the difference in tenths of seconds, between t1 and t2.
85 timediff( struct timeval *t1, struct timeval *t2 )
89 t = (t1->tv_sec - t2->tv_sec) * 10;
90 t += (t1->tv_usec - t2->tv_usec) / 100000;
94 /* flush input. Wait for timeout deci-seconds to pass without input */
97 mesa_flush( GPPort *port, int timeout )
100 struct timeval start, now;
102 gettimeofday( &start, NULL );
104 /* Clear any pending input bytes */
105 gp_port_flush(port, 0);
107 /* Wait for silence */
109 if ( gp_port_read( port, b, sizeof( b ) ) > 0 )
111 gettimeofday( &start, NULL );
112 gettimeofday( &now, NULL );
113 } while ( timeout > timediff( &now, &start ) );
117 /* Read exactly this number of bytes from the port within the given timeouts */
119 mesa_read( GPPort *port, uint8_t *b, int s, int timeout2, int timeout1 )
123 struct timeval start, now;
125 t = timeout1 ? timeout1 : timeout2; /* set first byte timeout */
126 gettimeofday( &start, NULL );
130 /* limit reads to 1k segment */
131 r = gp_port_read( port, &b[n], s>1024?1024:s );
136 gettimeofday( &start, NULL );
139 gettimeofday( &now, NULL );
140 } while ( s > 0 && t > timediff( &now, &start ) );
144 /* Send a command to the camera and read the acknowledgement byte */
146 mesa_send_command( GPPort *port, uint8_t *cmd, int n, int ackTimeout )
150 CHECK (gp_port_write( port, cmd, n ));
152 if ( mesa_read( port, &c, 1, ackTimeout, 0 ) != 1 )
154 debuglog("mesa_send_command: timeout");
155 return GP_ERROR_TIMEOUT;
159 debuglog("mesa_send_command: error response");
160 return GP_ERROR_CORRUPTED_DATA;
165 /* Open the serial port and configure it */
167 mesa_port_open( GPPort *port )
169 GPPortSettings settings;
171 debuglog("mesa_port_open()");
172 gp_port_set_timeout(port, 5000);
174 gp_port_get_settings(port, &settings);
176 settings.serial.speed = 115200;
177 settings.serial.bits = 8;
178 settings.serial.parity = 0;
179 settings.serial.stopbits= 1;
181 return gp_port_set_settings(port, settings);
184 /* Close the serial port (now done by gphoto2 itself) */
186 mesa_port_close( GPPort *port )
193 mesa_reset( GPPort *port )
195 return gp_port_send_break( port, 1 );
198 /* set camera serial port speed, then our local port speed */
200 mesa_set_speed( GPPort *port, int speed )
203 gp_port_settings settings;
206 speed = 115200; /* use default speed */
209 "mesa_set_speed: speed %d", speed);
243 return GP_ERROR_BAD_PARAMETERS;
245 CHECK (mesa_send_command( port, b, sizeof( b ), 10 ));
247 gp_port_get_settings(port, &settings);
248 settings.serial.speed = speed;
249 return gp_port_set_settings(port, settings);
252 /* get camera version number */
254 mesa_version( GPPort *port, char *version_string)
259 char *v = version_string;
263 CHECK (mesa_send_command( port, &b, 1, 10 ));
265 if ( ( i = mesa_read( port, r, sizeof( r ), 10, 0 ) ) != sizeof( r ) )
267 return GP_ERROR_TIMEOUT;
271 "mesa_version: %02x:%02x:%02x\n", r[0], r[1], r[2] );
272 sprintf(v, "%2x.%02x%c", r[1], r[0], r[2]);
273 /* highest byte must be < MESA_VERSION_SZ */
277 /* test camera serial port transmit */
279 mesa_transmit_test( GPPort *port )
287 CHECK (mesa_send_command( port, &b, 1, 10 ));
289 if ( mesa_read( port, r, sizeof( r ), 10, 0 ) != sizeof( r ) )
291 return GP_ERROR_TIMEOUT;
294 for ( i = 0; i < 256; i++ )
297 return GP_ERROR_CORRUPTED_DATA;
302 /* test camera ram */
304 mesa_ram_test( GPPort *port )
311 CHECK (mesa_send_command( port, &b, 1, 100 ));
313 if ( mesa_read( port, &r, 1, 10, 0 ) != 1 )
315 return GP_ERROR_TIMEOUT;
322 * Read image row from camera.
323 * ******************************************************************** GDB
324 * * The following contradicted by traces from my Win98 twain driver* GDB
325 * ******************************************************************** GDB
326 * The image is stored in the camera as 504 row (0 - 503), the first 8 and the
328 * The rows are 18 dummy pixels, 2 blanks, 646 pixels, 13 bytes garbage,
331 * start - offset into row;
332 * send - bytes to send;
333 * skip - bytes to skip;
334 * repeat - # repeats of send skip
335 * 640 bytes start = 28, send = 2, skip = 0, repeat = 320
336 * 320 bytes start = 28, send = 2, skip = 2, repeat = 160
338 * return number of bytes read, or < 0 if an error was detected.
340 * ******************************************************************** GDB
342 * 640 bytes start = 30, send = 4, skip = 0, repeat = 160 GDB
343 * 320 bytes start = 30, send = 4, skip = 0, repeat = 80 GDB
345 * return value >0 number of bytes read GDB
346 * GP_ERROR_TIMEOUT read time-out
347 * GP_ERROR_BAD_PARAMETERS bad values
348 * GP_ERROR command failure
349 * GP_ERROR_CORRUPTED_DATA checksum failure
353 mesa_read_row( GPPort *port, uint8_t *r, struct mesa_image_arg *s ) /*GDB*/
356 unsigned int bytes, i; /*GDB*/
357 uint8_t checksum = 0; /*GDB*/
359 if ( (bytes = s->send * s->repeat) > 680 ) /*GDB*/
361 return GP_ERROR_BAD_PARAMETERS;
365 htole16a(&b[1], s->row);
366 htole16a(&b[3], s->start);
369 htole16a(&b[7], s->repeat);
371 CHECK (mesa_send_command( port, b, sizeof( b ), 10 ));
373 /* return ( mesa_read( port, r, n, 10, 0 )); GDB*/
374 if ( mesa_read( port, r, bytes, 10, 0 ) != bytes ) /*GDB*/
376 return GP_ERROR_TIMEOUT;
379 if ( mesa_read( port, b, 1, 10, 0 ) != 1) /*GDB*/
381 return GP_ERROR_TIMEOUT;
384 for (i = 0; i < bytes; i++ ) /*GDB*/
386 checksum += r[i]; /*GDB*/
389 if ( checksum != b[0] ) /*GDB*/
391 return GP_ERROR_CORRUPTED_DATA;
394 return bytes; /*GDB*/
398 * Snaps a full resolution image, with no flash, or shutter click
400 * exposure is in units of 1/50000 seconds
403 mesa_snap_image( GPPort *port, uint16_t exposure )
409 timeout = (exposure/50000) + 10;
414 htole16a(&b[1], exposure);
415 return mesa_send_command( port, b, sizeof( b ), timeout );
418 /* return black levels, overwrites image memory */
420 mesa_black_levels( GPPort *port, uint8_t r[2] )
426 CHECK (mesa_send_command( port, &b, 1, 10 ));
428 return mesa_read( port, r, 2, 10, 0 );
432 * snap a view finder image, optionally return image in buffer.
434 * if hi_res is true, image is 128x96 packed 4 bits per pixel (6144 bytes).
435 * else image is 64x48 packed 4 bits per pixel (1536 bytes).
437 * the image can be full scale, 0, zoom 2x 1, zoom 4x, 2, and for
438 * low res images, 8x, 3.
440 * row and column may be offset 0-197 and 0-223 for zoom.
442 * exposure is * 1/50000 seconds.
444 * download specifies how, of if thge image is downloaded.
445 * 0-47 returns one 32 byte (64 pixel) row.
446 * 128-223 returns on 64 byte row.
447 * 249 returns all odd rows of a hi-res image 1536 bytes.
448 * 250 returns all even rows of a hi-res image 1536 bytes.
449 * 251 returns complete hi res image 6144 bytes.
450 * 252 returns nothing.
451 * 253 returns all odd rows of low res image 768 bytes.
452 * 254 returns all even rows of low res image 768 bytes.
453 * 255 returns entire image of 1536 bytes.
457 mesa_snap_view( GPPort *port, uint8_t *r, unsigned int hi_res,
458 unsigned int zoom, unsigned int row, unsigned int col, uint16_t exposure,
461 unsigned int timeout, i;
462 unsigned int bytes = 0;
465 if ( download <= 47 )
467 else if ( download >= 48 && download <= 127 )
468 return GP_ERROR_BAD_PARAMETERS;
469 else if ( download >= 128 && download <= 223 )
471 else if ( download >= 224 && download <= 248 )
472 return GP_ERROR_BAD_PARAMETERS;
473 else if ( download == 249 || download == 250 )
475 else if ( download == 251 )
477 else if ( download == 252 )
479 else if ( download == 253 || download == 254 )
481 else /* if ( download == 255 ) */
484 if ( bytes != 0 && r == NULL )
486 return GP_ERROR_BAD_PARAMETERS;
490 timeout = (exposure/50000) + 10;
495 b[1] = (zoom&3)+(hi_res?0x80:0);
498 htole16a(&b[4], exposure);
501 CHECK (mesa_send_command( port, b, sizeof( b ), timeout ));
505 if ( mesa_read( port, r, bytes, 10, 0 ) != bytes )
507 return GP_ERROR_TIMEOUT;
510 if ( mesa_read( port, b, 1, 10, 0 ) != 1 )
512 return GP_ERROR_TIMEOUT;
515 for ( i = 0, cksum = 0; i < bytes; i++ )
521 return GP_ERROR_CORRUPTED_DATA;
529 * tell camera to insert extra stop bits between bytes.
530 * slows down transmission without using a slower speed.
533 mesa_set_stopbits( GPPort *port, unsigned int bits )
540 return mesa_send_command( port, b, sizeof( b ), 10 );
543 /* download viewfinder image ( see mesa_snap_view ) */
545 mesa_download_view( GPPort *port, uint8_t *r, uint8_t download )
547 unsigned int bytes, i;
550 if ( download <= 47 )
552 else if ( download >= 48 && download <= 127 )
553 return GP_ERROR_BAD_PARAMETERS;
554 else if ( download >= 128 && download <= 223 )
556 else if ( download >= 224 && download <= 248 )
557 return GP_ERROR_BAD_PARAMETERS;
558 else if ( download == 249 )
560 else if ( download == 250 || download == 251 )
562 else if ( download == 252 )
564 else if ( download == 253 )
566 else /* if ( download == 254 || download == 255 ) */
569 if ( bytes != 0 && r == NULL )
571 return GP_ERROR_BAD_PARAMETERS;
577 CHECK (mesa_send_command( port, b, sizeof( b ), 10 ));
581 if ( mesa_read( port, r, bytes, 10, 0 ) != bytes )
583 return GP_ERROR_TIMEOUT;
586 if ( mesa_read( port, b, 1, 10, 0 ) != 1 )
588 return GP_ERROR_TIMEOUT;
591 for ( i = 0, cksum = 0; i < bytes; i++ )
596 return GP_ERROR_CORRUPTED_DATA;
603 * take a picture, with flash and shutter click
606 mesa_snap_picture( GPPort *port, uint16_t exposure )
608 unsigned int timeout;
612 timeout = (exposure/50000) + 10;
617 htole16a(&b[1], exposure);
619 return mesa_send_command( port, b, sizeof( b ), timeout );
622 /* Get the camera chipset identification */
624 mesa_send_id( GPPort *port, struct mesa_id *id )
630 CHECK (mesa_send_command( port, &b, 1, 10 ));
632 if ( mesa_read( port, r, sizeof( r ), 10, 0 ) != sizeof( r ) )
634 return GP_ERROR_TIMEOUT;
637 id->man = r[0] + ((r[1]&15)<<8);
639 id->year = 1996 + r[2];
646 * check for a camera, or a modem, send AT, if the response is 0x21,
647 * it is a camera, if it is "AT" it's a modem.
649 * returns GP_OK = camera
650 * GP_ERROR_MODEL_NOT_FOUND = modem
654 mesa_modem_check( GPPort *port )
662 CHECK (gp_port_write( port, b, sizeof( b ) ));
664 /* Expect at least one byte */
665 if ( mesa_read( port, b, 1, 5, 0 ) < 1 )
667 return GP_ERROR_TIMEOUT;
670 if ( b[0] == CMD_ACK )
673 /* Anything past this point results in an error */
674 if ( mesa_read( port, b+1, sizeof(b) - 1, 2, 2 ) == sizeof(b) - 1 )
676 if ( b[0] == 'A' && b[1] == 'T' )
678 mesa_flush( port, 10 );
679 return GP_ERROR_MODEL_NOT_FOUND;
683 mesa_flush( port, 10 );
688 * mesa_read_image - returns all or part of an image in the supplied buffer
689 * uint8_t *r, buffer to return image in.
690 * struct mesa_image_arg *i, download specifier.
692 * return value >0 number of bytes read
693 * GP_ERROR_TIMEOUT read time-out
694 * GP_ERROR command failure
695 * GP_ERROR_CORRUPTED_DATA checksum failure
699 mesa_read_image( GPPort *port, uint8_t *r, struct mesa_image_arg *s )
702 unsigned long bytes, i;
703 uint8_t checksum = 0;
705 bytes = s->row_cnt * (s->repeat * s->send);
708 htole16a(&b[1], s->row);
709 htole16a(&b[3], s->start);
712 htole16a(&b[7], s->repeat);
719 CHECK (mesa_send_command( port, b, sizeof( b ), 10 ));
721 if ( mesa_read( port, r, bytes, 10, 0 ) != bytes )
723 return GP_ERROR_TIMEOUT;
726 if ( mesa_read( port, b, 1, 10, 0 ) != 1 )
728 return GP_ERROR_TIMEOUT;
731 for ( i = 0; i < bytes; i++ )
736 if ( checksum != b[0] )
738 return GP_ERROR_CORRUPTED_DATA;
745 * test serial link, send six bytes
747 * returns GP_OK - success
748 * GP_ERROR_TIMEOUT - no data received
749 * GP_ERROR - command failed (no or bad ack)
750 * GP_ERROR_CORRUPTED_DATA - returned bytes do not match
753 mesa_recv_test( GPPort *port, uint8_t r[6] )
759 memcpy( &b[1], r, 6 );
761 CHECK (mesa_send_command( port, b, sizeof( b ), 10 ));
763 if ( mesa_read( port, r, 6, 10, 0 ) != 6 )
765 return GP_ERROR_TIMEOUT;
768 for ( i = 0; i < 6; i++ )
769 if ( r[i] != b[i+1] )
770 return GP_ERROR_CORRUPTED_DATA;
774 /* Return the number of images in the EEPROM */
776 mesa_get_image_count( GPPort *port )
783 CHECK (mesa_send_command( port, &b, 1, 10 ));
785 if ( mesa_read( port, r, sizeof( r ), 10, 0 ) != sizeof( r ) )
787 return GP_ERROR_TIMEOUT;
793 /* load image from eeprom, into ram */
795 mesa_load_image( GPPort *port, int image )
800 htole16a(&b[1], image);
802 return mesa_send_command( port, b, sizeof( b ), 1000 );
806 * Read EEPROM information
807 * Bytes 10..16 of info correspond to the Device ID field, bytes 45..51
810 mesa_eeprom_info( GPPort *port, int long_read, uint8_t info[MESA_EEPROM_SZ] )
816 CHECK (mesa_send_command( port, &b, 1, 10 ));
818 return mesa_read( port, info, long_read ? 49 : 33, 10, 0 );
826 mesa_read_thumbnail( GPPort *port, int picture, uint8_t *image )
828 uint8_t b[3], checksum = 0;
830 unsigned int standard_res, i;
833 htole16a(&b[1], picture);
835 CHECK (mesa_send_command( port, b, sizeof( b ), 10 ));
837 if ( mesa_read( port, b, 3, 10, 0 ) != 3 )
839 return GP_ERROR_TIMEOUT;
842 checksum = b[0] + b[1] + b[2];
844 standard_res = ((b[2] & 128) != 0);
845 bytes = b[0] + (b[1]<<8) + ((b[2] & 127)<<16);
847 if ( mesa_read( port, image, MESA_THUMB_SZ, 10, 0 ) != MESA_THUMB_SZ )
849 return GP_ERROR_TIMEOUT;
852 if ( mesa_read( port, b, 1, 10, 0 ) != 1 )
854 return GP_ERROR_TIMEOUT;
857 for ( i = 0; i < MESA_THUMB_SZ; i++ )
859 checksum += image[i];
862 if ( checksum != b[0] )
863 return GP_ERROR_CORRUPTED_DATA;
865 return (bytes + standard_res ? 0x1000000 : 0);
868 /* Return the camera's feature bits */
870 mesa_read_features( GPPort *port, struct mesa_feature *f )
876 CHECK (mesa_send_command( port, &b, 1, 10 ));
878 return ( mesa_read( port, (uint8_t *)f, sizeof( *f ), 10, 0 ) );
881 /* return percentage battery level */
883 mesa_battery_check( GPPort *port )
885 struct mesa_feature f;
888 if ( (rc = mesa_read_features( port, &f )) != sizeof( f ))
893 if ( (f.feature_bits_hi & BAT_VALID) == 0 )
894 return GP_ERROR_MODEL_NOT_FOUND;
896 /* (df) Does BAT_DIGITAL need to be checked here? */
898 if ( ( l = f.battery_level - f.battery_zero ) < 0 )
901 r = f.battery_full - f.battery_zero;
903 return ( (l*100)/r );
907 mesa_read_image_info( GPPort *port, int i, struct mesa_image_info *info )
911 int32_t standard_res;
916 CHECK (mesa_send_command( port, b, sizeof( b ), 10 ));
918 if ( mesa_read( port, r, sizeof( r ), 10, 0 ) != sizeof( r ) )
920 return GP_ERROR_TIMEOUT;
923 standard_res = ((r[2] & 128) != 0);
924 bytes = r[0] + (r[1]<<8) + ((r[2] & 127)<<16);
928 info->standard_res = standard_res;
929 info->num_bytes = bytes;
935 #ifdef CONVERT_PIXELS
937 * return and image with raw pixels expanded.
940 mesa_get_image( GPPort *port, int image )
942 static uint8_t buffer[640*480L];
943 static struct mesa_image_info info;
944 static struct mesa_image_arg ia;
948 unsigned long size, i;
950 if ( image != RAM_IMAGE_NUM )
952 if ( mesa_load_image( port, image ) != GP_OK )
954 mesa_flush( port, 100 );
958 if ( mesa_read_image_info( port, image, &info ) < 0 )
960 mesa_flush( port, 100 );
963 if ( info.standard_res )
975 rbuffer = (uint16_t *)malloc( size*(sizeof (uint16_t)) );
976 if ( rbuffer == NULL )
982 ia.repeat = (res ? 80 : 160);
986 ia.inc3 = ia.inc4 = 0;
988 for ( ia.row = 4; ia.row < (res ? 244 : 484) ; ia.row += ia.row_cnt )
991 if ( (r = mesa_read_image( port, b, &ia )) < 0 )
999 for ( i = 0; i < size; i++ )
1001 *rbuffer++ = pixelTable[*b++];
1008 * return and raw image retransmit on errors
1011 mesa_get_image( GPPort *port, int image )
1013 static struct mesa_image_info info;
1014 static struct mesa_image_arg ia;
1015 uint8_t *rbuffer, *b;
1019 if ( image != RAM_IMAGE_NUM )
1021 if ( mesa_load_image( port, image ) < 0 )
1023 mesa_flush( port, 100 );
1027 if ( mesa_read_image_info( port, image, &info ) < 0 )
1029 mesa_flush( port, 100 );
1032 if ( info.standard_res )
1044 rbuffer = (uint8_t *)malloc( size );
1045 if ( rbuffer == NULL )
1052 ia.repeat = (res ? 80 : 160);
1056 ia.inc3 = ia.inc4 = 0;
1058 for ( ia.row = 4; ia.row < (res ? 244 : 484) ; ia.row += ia.row_cnt )
1061 for ( retry = 10;; )
1063 if ( (r = mesa_read_image( port, b, &ia )) > 0)
1066 /* if checksum error count retries */
1067 if ( r == -2 && --retry > 0)
1068 continue; /* not exceeded, try again */