/* * W2000A Screenshot Utility v0.2, * companion to firmware patch */ #include #include #include #include #include #include "ComTools.h" //von Anton Zechner: http://members.inode.at/anton.zechner/az/Seriell.htm #define ESC 27 #define MAXPLANES 16 /* * XXX: Please note: * This is _not_ 100% identical to the actual * output seen on the DSO. For example: * The math channel is drawn _over_ * the browse bar. Put the Math channel * behind UI in the planeorder to witness * the actual output. */ static const int planeorder[] = { 1, /* Grid */ 7, 8, 9, 10, /* Channels 1-4 */ /* XXX: Red Arrow and Stop-Sign in UI on 10/Channel4? */ 11, /* Math Channel */ 15, 16, /* Cursors and Trigger Mark */ 4, 5, 6, 2, 3, /* UI */ 12, 13, 14, /* Not yet determined */ 0 }; static const int planecolours[][3] = { /* Grid_Plane */ { 0x3F, 0x3F, 0x3F }, /* dark gray */ /* UI_Plane1 */ { 0xFB, 0xFB, 0xFB }, /* dark white */ /* UI_Plane2 */ { 0x00, 0x00, 0x00 }, /* black */ /* UI_Plane3 */ { 0xFF, 0xFD, 0xEE }, /* yellow tinted white */ /* UI_Plane4 */ { 0xE6, 0xE6, 0x83 }, /* beige-ish yellow */ /* UI_Plane5 */ { 0x7E, 0x7E, 0x7E }, /* gray */ /* Channel_Plane1 { 0xFF, 0xFF, 0x00 }, yellow */ /* Channel_Plane1 */ { 0xFF, 0xFF, 0x00 }, /* yellow */ /* Channel_Plane2 */ { 0x90, 0xEE, 0x90 }, /* light green */ /* Channel_Plane3 */ { 0x32, 0xAB, 0xFF }, /* light blue */ /* Channel_Plane4 */ { 0xFF, 0x00, 0x00 }, /* red */ /* Channel_Math_Plane */{ 0xFF, 0x96, 0xF6 }, /* pink */ /* Memory_Plane1 */ { 0x00, 0x00, 0x00 }, /* n.y.d. */ /* Memory_Plane2 */ { 0x00, 0x00, 0x00 }, /* n.y.d. */ /* Memory_Plane3 */ { 0x00, 0x00, 0x00 }, /* n.y.d. */ /* Marker_Plane1 */ { 0xFF, 0x67, 0x00 }, /* orange-red */ /* Marker_Plane2 */ { 0xFF, 0x67, 0x00 }, /* orange-red */ { 0x00, 0x00, 0x00 } /* don't remove this! */ }; static unsigned char pixmaps[MAXPLANES][640*480]; static int rdplanes; FILE *fp; char *com; static void retrieve(unsigned int com) { int iLen; int pnum, rd, total, ppos, z=0; unsigned char c, b, l; int i; printf("* Waiting for Screenshot...\nAbort with ESC\n"); if(!ComOpen(/*COM1*/com,115200,P_NONE,S_1BIT,D_8BIT)) { printf("\nKann die Schnittstelle COM%d nicht oeffnen !\n\n",com); } l = 0; while (1) { if(kbhit()) if(getch()==ESC) exit(0); iLen=ComRead(com); c=iLen; if (c == 255 && l == 'S') break; l = c; } printf("* Found Screenshot Start Marker\n"); total = 0; rdplanes = 0; for (pnum = 0; pnum < MAXPLANES; pnum++) { printf(" - Receiving Plane #%.2d...\n", pnum+1); rd = 0; ppos = 0; while ( 1 ) //while ( read(0, &c, 1) > 0 ) { { while(1) { iLen=ComRead(com); if(iLen != -1) break; } c=iLen; rd++; if (rd % 100 == 0) printf("\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; //(void)fputc(b, fp); } } total += rd; rdplanes++; printf("\r Read %d bytes.\n", rd); /*if (fclose(fp) != 0) printf("fclose(%s) failed", fnam);*/ if (c=ComRead(com)) { if (c == 'E') { printf("* End of Transmission\n"); break; } else if (c == 0xFF) printf(" (another plane follows)\n"); } else { printf("* Short read, ignoring\n"); break; } } printf("* Total bytes transferred: %d\n", total); ComClose(com); ComExit(); } static void combine(void) { int ppos, i, plane, colour; printf("* Combining...\n"); fprintf(fp, "P6\r640 480\r255\r"); for (ppos = 0; ppos < 640*480; ppos++) { colour = MAXPLANES; /* default colour, black */ for (i = 0; i < MAXPLANES && i < rdplanes; i++) { plane = planeorder[i] - 1; if (pixmaps[plane][ppos] == 0xFF) colour = plane; } (void)fputc(planecolours[colour][0], fp); (void)fputc(planecolours[colour][1], fp); (void)fputc(planecolours[colour][2], fp); } printf("* Done\n"); } int main(int argc, char **argv) { int number=0; char *string0="screen"; char string1[15]; char *string2=".ppm"; char string3[5]; //printf("%s%s%s\n",string1,string2,string3); if(argc == 2) { while(1) { retrieve((argv[1][3])-1-'0'); do { sprintf(string3,"%d",number); //mache aus Nummer einen String strcpy(string1,string0); strcat(string1,string3); strcat(string1,string2); number++; } while (fopen(string1,"r") !=NULL); if ((fp = fopen(string1, "w+")) == NULL) printf("fopen(%s, w+) failed", string1); combine(); if (fclose(fp) != 0) printf("fclose(%s) failed", string1); number=0; } } return 0; }