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

  1.  /* LOADSCRN.C */
  2.  /* Restore cursor location and screen from 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 SETCUR      2
  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 load_data (unsigned char *filename);
  31. void read_screensize (int *rows, int *cols,int type);
  32. void read_screentype (int *type);
  33. void goyx (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.     load_data (argv[1]);
  49.     goyx (row,col);
  50.     exit (0);
  51. }
  52.  
  53. void load_data (unsigned char *filename)
  54. {
  55.     FILE *inp;
  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 ( (inp=fopen (filename,"rb")) == NULL)
  63.     {   printf ("Fatal error on opening '%s'\n",filename);
  64.         exit (1);
  65.     }
  66.     fread (&row,2,1,inp);
  67.     fread (&col,2,1,inp);
  68.     seg = (type == COLOR) ? COLOR_SEG : MONO_SEG;
  69.     linesize = cols * 2;
  70.     for (i=off=0; i < rows; i++,off += linesize)
  71.     {   fread (line,linesize,1,inp);
  72.         movedata (FP_SEG(pline),FP_OFF(pline),seg,off,linesize);
  73.     }
  74.     fclose (inp);
  75.     unlink (filename);
  76. }
  77.  
  78. void read_screensize (int *rows, int *cols,int type)
  79. {
  80.     union REGS regs;
  81.     unsigned int value;
  82.     unsigned int far *pvalue = &value;
  83.  
  84.     if (type == 1)
  85.     {   regs.h.ah = 0x0F;
  86.         int86(0x10,®s,®s);
  87.         *cols = regs.h.ah;
  88.         switch (regs.h.al)
  89.         {   case 0x00:
  90.             case 0x01:
  91.             case 0x02:
  92.             case 0x03:
  93.             case 0x07:
  94.                 *rows = 25;
  95.                 break;
  96.             default:
  97.                 printf ("Unexpected mode=0x%02x\n",regs.h.al);
  98.                 getch();
  99.         }
  100.     }
  101.     else
  102.     {   movedata (0x000,0x044A,FP_SEG(pvalue),FP_OFF(pvalue),2);
  103.         *cols = *pvalue;
  104.             /* this will return the total memory space in use */
  105.         movedata (0x000,0x044C,FP_SEG(pvalue),FP_OFF(pvalue),2);
  106.         *rows = *pvalue / (*cols * 2);
  107.     }
  108. }
  109.  
  110. void goyx(int row, int col)
  111. /* uses bios call to position cursor at row,col */
  112. {
  113.     union REGS regs;
  114.  
  115.     regs.h.dh = row;
  116.     regs.h.dl = col;
  117.     regs.h.ah = SETCUR;
  118.     regs.h.bh = 0x00; /* page # */
  119.     int86(0x10,®s,®s);
  120. }
  121.  
  122. void read_screentype (int *type)
  123. {
  124.     union REGS regs;
  125.  
  126.     regs.h.ah = 0x0F;
  127.     int86(0x10,®s,®s);
  128.     switch (regs.h.al)
  129.     {   case 0x00:
  130.         case 0x01:
  131.         case 0x02:
  132.         case 0x03:
  133.             *type = COLOR;
  134.             break;
  135.         case 0x07:
  136.             *type = MONO;
  137.             break;
  138.         default:
  139.             printf ("Unexpected mode=0x%02x\n",regs.h.al);
  140.             getch();
  141.     }
  142. }
  143.  
  144. void syntax()
  145. {   
  146.     printf ("Syntax:   LOADSCRN filename\n"
  147.             "Purpose:  Restore cursor location and screen from a file\n"
  148.             "          Will work with 40/43/50 line screens too!\n");
  149. }
  150.