home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / saveload.zip / SAVESCRN.C < prev    next >
Text File  |  1990-08-24  |  4KB  |  149 lines

  1.  /* SAVESCRN.C */
  2.  /* Store cursor location and screen into file */
  3.  
  4.     /* Coding for TC 2.0 */
  5.  
  6.  /*
  7.     Coding by Albert Stein, Chemical Bank, 212-310-3927
  8.               Software Ideology
  9.               PO Box 305, Brooklyn, NY  11204
  10.  
  11.     Any comments are welcome.  Enjoy!
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <mem.h>
  17. #include <conio.h>
  18. #include <dos.h>
  19. #include <io.h>
  20.  
  21. #define READCUR     3
  22. #define STATE       15
  23.  
  24. #define COLOR       1
  25. #define MONO        0
  26.  
  27. #define COLOR_SEG   0xB800
  28. #define MONO_SEG    0xB000
  29.  
  30. void store_data (unsigned char *filename);
  31. void read_screentype (int *type);
  32. void read_screensize (int *rows, int *cols,int type);
  33. void read_cursor(int *row, int *col);
  34. void syntax(void);
  35.  
  36. int type;
  37. int row,col;
  38. int rows,cols;
  39.  
  40. void main(int argc, char *argv[])
  41. {
  42.     if (argc == 1)
  43.     {   syntax();
  44.         exit (0);
  45.     }
  46.     read_screentype (&type);
  47.     read_screensize (&rows,&cols,0);
  48.     read_cursor (&row,&col);
  49.     store_data (argv[1]);
  50.     exit (0);
  51. }
  52.  
  53. void store_data (unsigned char *filename)
  54. {
  55.     FILE *out;
  56.     unsigned int seg,off;
  57.     unsigned int line[266];         /* store up to 133 columns w/ attribs */
  58.     unsigned char far *pline = (void far *)line;
  59.     unsigned int linesize;
  60.     unsigned int i;
  61.  
  62.     if ( (out=fopen (filename,"wb")) == NULL)
  63.     {   printf ("Fatal error on opening '%s'\n",filename);
  64.         exit (1);
  65.     }
  66.     fwrite (&row,2,1,out);
  67.     fwrite (&col,2,1,out);
  68.     seg = (type == COLOR) ? COLOR_SEG : MONO_SEG;
  69.     linesize = cols * 2;
  70.     for (i=off=0; i < rows; i++,off += linesize)
  71.     {   movedata (seg,off,FP_SEG(pline),FP_OFF(pline),linesize);
  72.         fwrite (line,linesize,1,out);
  73.     }
  74.     fclose (out);
  75. }
  76.  
  77. void read_screensize (int *rows, int *cols,int type)
  78. {
  79.     union REGS regs;
  80.     unsigned int value;
  81.     unsigned int far *pvalue = &value;
  82.  
  83.     if (type == 1)
  84.     {   regs.h.ah = 0x0F;
  85.         int86(0x10,®s,®s);
  86.         *cols = regs.h.ah;
  87.         switch (regs.h.al)
  88.         {   case 0x00:
  89.             case 0x01:
  90.             case 0x02:
  91.             case 0x03:
  92.             case 0x07:
  93.                 *rows = 25;
  94.                 break;
  95.             default:
  96.                 printf ("Unexpected mode=0x%02x\n",regs.h.al);
  97.                 getch();
  98.         }
  99.     }
  100.     else
  101.     {   movedata (0x000,0x044A,FP_SEG(pvalue),FP_OFF(pvalue),2);
  102.         *cols = *pvalue;
  103.             /* this will return the total memory space in use */
  104.         movedata (0x000,0x044C,FP_SEG(pvalue),FP_OFF(pvalue),2);
  105.         *rows = *pvalue / (*cols * 2);
  106.     }
  107. }
  108.  
  109. void read_cursor(int *row, int *col)
  110. /* read cursor position */
  111. {
  112.     union REGS regs;
  113.  
  114.     regs.h.ah = READCUR;
  115.     regs.h.bh = 0x00;    /* page */
  116.     int86(0x10,®s,®s);
  117.     *row = regs.h.dh;
  118.     *col = regs.h.dl;
  119. }
  120.  
  121. void read_screentype (int *type)
  122. {
  123.     union REGS regs;
  124.  
  125.     regs.h.ah = 0x0F;
  126.     int86(0x10,®s,®s);
  127.     switch (regs.h.al)
  128.     {   case 0x00:
  129.         case 0x01:
  130.         case 0x02:
  131.         case 0x03:
  132.             *type = COLOR;
  133.             break;
  134.         case 0x07:
  135.             *type = MONO;
  136.             break;
  137.         default:
  138.             printf ("Unexpected mode=0x%02x\n",regs.h.al);
  139.             getch();
  140.     }
  141. }
  142.  
  143. void syntax()
  144. {
  145.     printf ("Syntax:   SAVESCRN filename\n"
  146.             "Purpose:  Store cursor location and screen into a file\n"
  147.             "          Will work with 40/43/50 line screens too!\n");
  148. }
  149.