home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / modem.madness / SMMPROG / ISC366.ZIP / DOSFREE / EXAMPLES / SNAP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-01  |  3.4 KB  |  101 lines

  1. ////////////////////////////////////////////////////////////////////////////
  2. //                                                                        //
  3. //            File: Snap.cpp                                              //
  4. //            started on: 30/8/93                                         //
  5. //                                                                        //
  6. ////////////////////////////////////////////////////////////////////////////
  7. //                                                                        //
  8. //  Uses Shift-Tab hotkey to save screen and append it to snap.dat        //
  9. //    Uses KBD class to hook hotkey, and DOSFREE to save data in file.    //
  10. //                                                                        //
  11. ////////////////////////////////////////////////////////////////////////////
  12. //                                                                        //
  13. //                    by Ofer Laor (AKA LeucroTTA)                        //
  14. //                                                                        //
  15. ////////////////////////////////////////////////////////////////////////////
  16.  
  17. #include <io.h>;       // open.
  18. #include <fcntl.h>;    // O_XXXX.
  19. #include <sys\stat.h>; // S_IXXX
  20.  
  21. #include "dosfree.h";  // DOSFREE.
  22. #include "kbd.h";      // KBD.
  23.  
  24.  
  25. // this class is my application.
  26. class SNAP : public KBD, public DOSFREE {
  27.  
  28.       char screen[2050];                // screen temp buffer.
  29.       virtual void hotkey(void);        // saves data in screen.
  30.       virtual void AppFunc(void);       // save screen buffer in file.
  31.  
  32. public:
  33.        SNAP(): KBD(KB_TAB, KBS_SHIFT) {};  // hook hotkey into SHIFT-TAB.
  34.  
  35. };
  36.  
  37.  
  38. // hotkey saves screen and calls AppFunc indirectly.
  39. void SNAP::hotkey(void)
  40. {
  41.     char far *pScreen= (char far *)0xb8000000L; // pointer to screen (non MDA).
  42.  
  43.     int len= 0;
  44.  
  45.     // save screen.
  46.     for (int y= 0; y< 25; y++) {
  47.         for (int x= 0; x< 80; x++)
  48.             screen[len++]= pScreen[(x*2)+ (y*160)]; // skip the char attributes (save every 2nd char).
  49.  
  50.         // add CR,LF on the end of every line (so that editors can edit data easy).
  51.         screen[len++]= 0xd; // CR.
  52.         screen[len++]= 0xa; // LF.
  53.     }
  54.  
  55.     // run AppFunc when dos is free.
  56.     Go();
  57. }
  58.  
  59. // this func. runs whenever dos is free. Save data into file.
  60. void SNAP::AppFunc(void)
  61. {
  62.     const char datafile[]= "snap.dat";
  63.  
  64.     // create file if it doesn't exist.
  65.     int handle= open(datafile, O_EXCL| O_CREAT| O_RDWR| O_BINARY, S_IWRITE| S_IREAD);
  66.     close(handle);
  67.  
  68.     // open it in append. (There's probably a simpler way to do this but I
  69.     // didn't wanna spend too much time on this foolery.
  70.     handle= open(datafile, O_APPEND| O_BINARY| O_RDWR, S_IWRITE| S_IREAD);
  71.  
  72.     // could not open file for some reason. BEEP....
  73.     if (handle== -1) {
  74.        // notice I used TTY BIOS func. to beep. DO NOT USE DOS TTY (int21h
  75.        // func. < 0xc!!!).
  76.        _AH= 0xe;
  77.        _AL= '\a';
  78.        _BX= 0;
  79.        asm int 10h
  80.  
  81.        return;
  82.     }
  83.  
  84.     // write file, and close it.
  85.     write(handle, screen, sizeof(screen));
  86.     close(handle);
  87. }
  88.  
  89. // activate SNAP. Stay resident if not already resident.
  90. int main()
  91. {
  92.     if (ISC::is_TSR("SNAP(:-D"))
  93.        return 1;
  94.  
  95.     // activate my app.
  96.     new SNAP;
  97.  
  98.     // stay resident (return 0 to dos).
  99.     return ISC::TSR(0);
  100. }
  101.