
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>



main()
{
   int fd;
   unsigned char buf[512*512];
   char* bufp;
   int sizex=100;
   int sizey=100;
   int startx=200;
   int starty=200;
   int x,y;
   bufp = buf;
   
   
   fprintf(stderr,"ctest two start\n");
   
   fd = open( "/dev/cortex" , O_RDWR );
   if ( fd < 0 )
   {
      fprintf(stderr,"ctest open failed with %d \n",fd);
      exit(1);
   }
   fprintf(stderr,"ctest opened device \n");

   for( y=starty; y<starty+sizey; y++ )
   { 
      lseek(fd,y*512+startx,SEEK_SET );
      read(fd,bufp,sizex);
      bufp+=sizex;
   }

   close(fd);
   fprintf(stderr,"ctest closed device \n");

   printf("P5\n%d %d\n255\n",sizex,sizey);
   fwrite( buf , 1 , sizex*sizey, stdout );

   fprintf(stderr,"ctest done\n");
   exit(0);
}
