diff -c w2000a-screenshot-0.3/w2000a-screenshot.cpp w2000a-screenshot-0.3-dl3daz/w2000a-screenshot.cpp
*** w2000a-screenshot-0.3/w2000a-screenshot.cpp	2009-07-02 17:55:07.000000000 +0200
--- w2000a-screenshot-0.3-dl3daz/w2000a-screenshot.cpp	2009-07-04 22:08:42.000000000 +0200
***************
*** 133,142 ****
  	char fnam[256];
  	int r, pnum, rd, total, ppos;
  	unsigned char c, l, b;
! 	int i;
  
  #ifdef WIN32
! 	if (!ComOpen(0, 115200, P_NONE, S_1BIT, D_8BIT))
  		err(1, "Unable to open COM port");
  #endif
  	(void)fprintf(stderr, "* Waiting for Screenshot...\n");
--- 133,148 ----
  	char fnam[256];
  	int r, pnum, rd, total, ppos;
  	unsigned char c, l, b;
! 	unsigned int i,j;
! 
! 	unsigned char *buffer,*bufptr,*bufend;
! 	unsigned int   llength=0;
! 	unsigned char   cout,lastbyte=0,esc=0;
! 	int out,outcnt=0,incnt=0;
! 
  
  #ifdef WIN32
! 	if (!ComOpen(com, 115200, P_NONE, S_1BIT, D_8BIT))
  		err(1, "Unable to open COM port");
  #endif
  	(void)fprintf(stderr, "* Waiting for Screenshot...\n");
***************
*** 152,157 ****
--- 158,209 ----
  		exit(1);
  
  	(void)fprintf(stderr, "* Found Screenshot Start Marker\n");
+ /*********************************************************************
+ * Allocate enough space for all planes
+ *********************************************************************/
+ 	buffer=(unsigned char *)malloc(640*480*MAXPLANES/8);
+ 	if (!buffer)
+ 			err(1, "malloc %d failed", 640*480*MAXPLANES/8);
+ 	bufptr=buffer;
+ /*********************************************************************
+ * Read all from stdin/COMx, decompress and fill buffer
+ *********************************************************************/
+ 	while (((r = rdchar()) >= 0) && (bufptr<buffer+640*480*MAXPLANES/8)) {
+ 		c=(unsigned char)r;
+ 		incnt++;
+ 		if (incnt % 100 == 0)
+ 			(void)fprintf(stderr, "\r    %d bytes...", incnt);
+ 
+ 		if (esc==2) {
+ 			llength|=(c);							//2nb Byte after ESC is MSB
+ 			for (i=0;i<llength;i++) {
+ 				*bufptr++=lastbyte;
+ 				outcnt++;
+ 				}
+ 			llength=0;
+ 			esc=0; }
+ 		else if (esc==1) {								//2nd escape
+ 			if (c==0xFF) {								//escaped 0xFF
+ 				*bufptr++=c;
+ 				outcnt++;
+ 				lastbyte=c;
+ 				llength=0;
+ 				esc=0; }								//Escape-Sequence finished
+ 			else {										//1st Byte after ESC is MSB
+ 				llength=c<<8;
+ 				esc++; }
+ 			}
+ 		else if (c != 0xFF) {
+ 			*bufptr++=c;
+ 			outcnt++;
+ 			lastbyte=c;
+ 			}
+ 		else {
+ 			esc=1; }
+ 	}
+ 
+ 	bufend=bufptr;
+ 	bufptr=buffer;
  
  	total = 0;
  	rdplanes = 0;
***************
*** 169,191 ****
  
  		rd = 0;
  		ppos = 0;
! 		while ((r = rdchar()) > 0) {
! 			c = (unsigned char)r;
  			rd++;
! 			if (rd % 100 == 0)
! 				(void)fprintf(stderr, "\r    %d bytes...", rd);
! 			if (c == 255)
! 				break;
! 			b = 0x00;
! 			if (c & (1 << 7))
! 				b = 0xff;
! 			c &= ~(1 << 7);
! 
! 			for (i = 0; i < c; i++) {
! 				pixmaps[pnum][ppos++] = b;
! 				if (all)
! 					(void)fputc(b, fp);
  			}
  		}
  		total += rd;
  		rdplanes++;
--- 221,239 ----
  
  		rd = 0;
  		ppos = 0;
! /*********************************************************************
! * get data from buffers
! *********************************************************************/
! 		while (bufptr<bufend) {
! 			c = *bufptr++;;
  			rd++;
! 			for (j=0;j<8;j++) {
! 				pixmaps[pnum][ppos++] = ((c & (1<<j)) ? 255 : 0);
! 				(void)fputc(((c & (1<<j)) ? 255 : 0), fp);
  			}
+ 
+ 			if (rd==640*480/8) break;
+ 
  		}
  		total += rd;
  		rdplanes++;
***************
*** 195,202 ****
  		if (all && fclose(fp) != 0)
  			err(1, "fclose(%s) failed", fnam);
  
! 		if ((r = rdchar()) > 0) {
! 			c = (unsigned char)r;
  			if (c == 'E') {
  				(void)fprintf(stderr, "* End of Transmission\n");
  				break;
--- 243,250 ----
  		if (all && fclose(fp) != 0)
  			err(1, "fclose(%s) failed", fnam);
  
! 		if (bufptr<=bufend) {
! 			c=*bufptr++;
  			if (c == 'E') {
  				(void)fprintf(stderr, "* End of Transmission\n");
  				break;
***************
*** 285,291 ****
  	int ch, bflag;
  
  #ifdef WIN32
! 	int com = 0;
  #endif
  	bflag = 0;
  	(void)snprintf(fnamprefix, sizeof(fnamprefix), "screenshot");
--- 333,339 ----
  	int ch, bflag;
  
  #ifdef WIN32
! 	com = 0;
  #endif
  	bflag = 0;
  	(void)snprintf(fnamprefix, sizeof(fnamprefix), "screenshot");
***************
*** 298,304 ****
  #ifdef WIN32
  		case 'c':
  			com = atoi(optarg) - 1;
! 			if (com < 0 || com > 9)
  				err(1, "invalid COM port given, use -c n, where 0 < n < 10");
  			break;
  #endif
--- 346,352 ----
  #ifdef WIN32
  		case 'c':
  			com = atoi(optarg) - 1;
! 			if (com < 0 || com > 8)
  				err(1, "invalid COM port given, use -c n, where 0 < n < 10");
  			break;
  #endif
