home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / sphinx / examples / tsr / grab.c__ < prev    next >
Encoding:
Text File  |  1994-05-27  |  7.9 KB  |  287 lines

  1. /*
  2.     NAME:  GRAB.C--
  3.     DESCRIPTION:  Screen grabber for all video modes of the CGA, EGA, MCGA
  4.                   and VGA video cards.
  5. */ 
  6.  
  7. ?print "Building GRAB.COM, the VGA and lower screen grabber.\n"
  8.  
  9. ?assumeDSSS  FALSE  // never assume DS==SS because of TSR
  10. ?jumptomain  NEAR   // NEAR jump to main () 
  11. ?resize      FALSE  // don't bother to resize memory to 64K
  12.  
  13. ?include "KEYCODES.H--"
  14. ?include "VIDEO.H--"
  15. ?include "WRITE.H--"
  16. ?include "SOUND.H--"
  17. ?include "FILE.H--"
  18. ?include "SYSTEM.H--"
  19. ?include "DOS.H--"
  20. ?include "TSR.H--"
  21.  
  22.  
  23. word filenumber = 0;          /* filename number */ 
  24. byte filename = "#####.EXT";  /* filename string */
  25.  
  26. word activeseg=0,activeoff=0; /* address of DOS active byte */
  27.  
  28. ? define MAXCOLORS 256        /* maximum readable palette values */
  29. byte palette[MAXCOLORS*3]=1;  /* temp hold for palette */
  30.  
  31. @ word writefile ();   // force location of writefile procedure here
  32.  
  33.  
  34. void savetextscreen (word screenseg,linesize,pagenum)
  35. {AL = @ TEXTROWS() +1;
  36. AH = 0;
  37. IF( AL < 25 )
  38.     AX = 25;
  39. linesize = AX * linesize;
  40. AX = pagenum * linesize;
  41. SI = AX;
  42. writefile(#filename,screenseg,SI,linesize);
  43. }
  44.  
  45.  
  46. void savegraphicscreen1 (word screenseg,screensize,colors)
  47. {writefile(#filename,screenseg,0x0000,screensize);
  48. savepalette(colors);
  49. }
  50.  
  51.  
  52.  
  53. void savegraphicscreen4 (word planesize,pagenum,colors)
  54. word filehandle,count;
  55. {DI = planesize;
  56. AX = pagenum * DI;
  57. SI = AX;
  58. AX = @ FCREATE( , ,0,#filename); 
  59. IF( AX != 0 )
  60.     {filehandle = AX;
  61.     $ PUSH DS
  62.     DS = 0xA000;
  63.     count = 0;
  64.     do {@ SETREADMASK( ,count);
  65.         @ FWRITE( ,filehandle,DI,SI);
  66.         count++;
  67.         } while( count < 4 );
  68.     $ POP DS
  69.     @ FCLOSE( ,filehandle);
  70.     }
  71. savepalette(colors);
  72. }
  73.  
  74.  
  75. void savepalette (word colors)
  76. {filename[6]='P';
  77. filename[7]='A';
  78. filename[8]='L';
  79. @ GETVGAPALETTE( ,0,colors,#palette);
  80. writefile(#filename,DS,#palette,colors*3);
  81. }
  82.  
  83.  
  84. void saveATIscreen (byte planes; word leftover,colors)
  85. byte count;
  86. word filehandle;
  87. {
  88. AX = @ FCREATE( , ,0,#filename); 
  89. if( AX != 0 )
  90.     {filehandle = AX;
  91.     $ PUSH DS
  92.     DS = 0xA000;
  93.     count = 0;
  94.     do {@ SETATIMASK( ,count);
  95.         @ FWRITE( ,filehandle,32768,0);      // 32K bytes from offset 0
  96.         @ FWRITE( ,filehandle,32768,32768);  // 32K bytes from offset 32K
  97.         count++;
  98.         } while( count < planes );
  99.     IF( leftover > 0 )
  100.         {@ SETATIMASK( ,count);
  101.         @ FWRITE( ,filehandle,leftover,0);}  // write remainning < 64K
  102.     $ POP DS
  103.     @ FCLOSE( ,filehandle);
  104.     }
  105. savepalette(colors);
  106. }
  107.  
  108.  
  109. void savescreen ()
  110. {@ SOUND(333);
  111. @ WORDTODIGITS(filenumber,#filename);
  112. filename[5]='.';
  113. filename[6]='S';
  114. filename[7]='C';
  115. filename[8]='R';
  116.  
  117. AL = @ GETVIDEOMODE();   // BH also equals current page
  118. IF( AL <= vid_text40c )
  119.     savetextscreen(0xB800,80,BH);
  120. else IF( AL <= vid_text80c )
  121.     savetextscreen(0xB800,160,BH);
  122. else IF( AL <= vid_320x200_4_RGB )
  123.     savegraphicscreen1(0xB800,16000,4);
  124. else IF( AL == vid_640x200_2 )
  125.     savegraphicscreen1(0xB800,16000,2);
  126. else IF( AL == vid_text80m )
  127.     savetextscreen(0xB000,160,BH);
  128. else IF( AL == vid_320x200_16 )
  129.     savegraphicscreen4(8000,BH,16);
  130. else IF( AL == vid_640x200_16 )
  131.     savegraphicscreen4(16000,BH,16);
  132. else IF( AL == vid_640x350_2 )
  133.     savegraphicscreen1(0xA000,28000,2);
  134. else IF( AL == vid_640x350_16 )
  135.     savegraphicscreen4(28000,BH,16);
  136. else IF( AL == vid_640x480_2 )
  137.     savegraphicscreen1(0xA000,38400,2);
  138. else IF( AL == vid_640x480_16 )
  139.     savegraphicscreen4(38400,BH,16);
  140. else IF( AL == vid_320x200_256 )
  141.     savegraphicscreen1(0xA000,64000,256);
  142. else IF( AL == vid_800x600_16_ATI_1 )
  143.     savegraphicscreen4(60000,DH,16);
  144. else IF( AL == vid_800x600_16_ATI_2 )
  145.     savegraphicscreen4(60000,DH,16);
  146. ELSE IF( AL == vid_640x400_256_ATI )
  147.     saveATIscreen(3,59392,256);
  148. ELSE IF( AL == vid_640x480_256_ATI )
  149.     saveATIscreen(4,45056,256);
  150. ELSE IF( AL == vid_800x600_256_ATI )
  151.     saveATIscreen(7,21248,256);
  152. ELSE IF( AL == vid_1024x768_16_ATI )
  153.     saveATIscreen(6,0,256);
  154. ELSE IF( AL == vid_1024x768_4_ATI )
  155.     saveATIscreen(3,0,256);
  156. ELSE filenumber--;
  157.  
  158. filenumber++;
  159. @ NOSOUND();
  160. }
  161.  
  162.  
  163. /*************** Start of new keyboard handle ********************/
  164.  
  165. word oldkeyboardhandle[2]={};   // holder for the old keyboard handle
  166.  
  167. byte ctrldown=FALSE;   // control key down flag
  168. byte altdown=FALSE;    // alt key down flag
  169. byte busy = FALSE;     // busy saving the screen flag
  170.  
  171. byte idcode = "grab";  // used to detect if already installed
  172.  
  173. interrupt keyboardhandle ()
  174. {$ PUSH DS
  175. $ PUSH AX
  176. DS = CS;
  177. $ IN AL,KEYBOARD_PORT
  178. IF( AL < 0x80 )
  179.     {IF( AL == s_ctrl )
  180.         ctrldown = TRUE;
  181.     IF( AL == s_alt )
  182.         altdown = TRUE;
  183.     IF( AL == s_g )
  184.         {IF( ctrldown )
  185.             {IF( altdown )
  186.                 {IF( busy == FALSE ) 
  187.                     {busy = TRUE;
  188.                     $ PUSH BX
  189.                     $ PUSH CX
  190.                     $ PUSH DX
  191.                     $ PUSH DI
  192.                     $ PUSH SI
  193.                     $ PUSH BP
  194.                     $ PUSH ES
  195.                     @ EATKEY();
  196.                     @ EOI();
  197.                     @ ENABLE();
  198.                     BX = activeoff;
  199.                     ES = activeseg;
  200.                     IF( ESBYTE[BX] == FALSE )
  201.                         savescreen(); 
  202.                     @ DISABLE();
  203.                     $ POP ES
  204.                     $ POP BP
  205.                     $ POP SI
  206.                     $ POP DI
  207.                     $ POP DX
  208.                     $ POP CX
  209.                     $ POP BX
  210.                     busy = FALSE; 
  211.                     $ POP AX
  212.                     $ POP DS
  213.                     $ IRET   
  214.                     }
  215.                 }
  216.             }
  217.         }
  218.     }
  219. ELSE IF( AL == s_ctrl+0x80 )
  220.     ctrldown = FALSE;
  221. ELSE IF( AL == s_alt+0x80 )
  222.     altdown = FALSE;
  223. $ POP AX
  224. $ POP DS
  225. $ CS:
  226. $ JMP FAR oldkeyboardhandle;
  227. }
  228.  
  229. /********************* end of NEW keyboard handle **********************/
  230.  
  231.  
  232. byte programinfo = 
  233.      "\nScreen Grabber:  GRAB   ver 3.0   by: SPHINX programming 1992\n"
  234.      "Will produce files ?????.SCR and ?????.PAL in current path.\n"
  235.      "\nGRAB was programmed and compiled using SPHINX C--.\n"
  236.      "Resident code 2640 bytes.\n"
  237.      "GRAB is freeware and may be used and copied so long as it is not\n"
  238.      "modified in anyway.\n"
  239.      "\nGRAB will capture the following video modes:\n"
  240.      "text: mono- 80x25\n"
  241.      "      colour- 40x25, 80x25, 40x28, 40x43, 40x50, 80x28, 80x43, 80x50\n"
  242.      "CGA graphics: 320x200-4, 640x200-2\n"
  243.      "EGA graphics: 320x200-16, 640x200-16, 640x350-16, 640x350-2\n"
  244.      "VGA graphics: 320x200-256, 640x480-2, 640x480-16\n"
  245.      "ATI VGA Wonder: 800x600-16, 1024x768-16, 1024x768-4,\n"
  246.      "                640x400-256, 640x480-256, 800x600-256\n"
  247.      "\n18 bit palette file (*.PAL) is created for all graphics modes,\n"
  248.      "the palette information will only be valid on systems with VGA or\n"
  249.      "higher BIOS.\n\n";
  250.  
  251. byte usekeys =
  252.     "Press <CTRL><ALT> and <g> to activate.\n";
  253.  
  254.  
  255. ?define ENDPROGOFFSET  #programinfo
  256.  
  257. main ()
  258. {AH = 52;      
  259. $ INT 0x21    /* get DOS active byte */
  260. activeseg = ES;
  261. activeoff = BX;
  262.  
  263. WRITESTR(#programinfo);
  264. @ GETINTVECT(#oldkeyboardhandle,KEYBOARD_INT);    // save old key handle
  265. IF( oldkeyboardhandle[0] == #keyboardhandle )
  266.     {ES = oldkeyboardhandle[2];
  267.     BX = oldkeyboardhandle[0];
  268.     IF( ESBYTE[BX-5] == 'g' )
  269.         IF( ESBYTE[BX-4] == 'r' )
  270.             IF( ESBYTE[BX-3] == 'a' )
  271.                 IF( ESBYTE[BX-2] == 'b' )
  272.                     IF( ESBYTE[BX-1] == 0 )
  273.                         {WRITESTR("GRAB already installed.  ");
  274.                         WRITESTR(#usekeys);
  275.                         @ EXIT(-1);
  276.                         }
  277.     }
  278.  
  279. @ SETINTVECT( ,KEYBOARD_INT,CS,#keyboardhandle);  // attach new handle
  280. WRITESTR("Screen Grabber Installed.  ");
  281. WRITESTR(#usekeys);
  282. @ KEEP( , , ,ENDPROGOFFSET);  // TSR to beginning of installed string
  283. }
  284.  
  285.  
  286. /* end of GRAB.C-- */
  287.