home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / t / tctvid11.zip / TV_VIDEO.C < prev    next >
C/C++ Source or Header  |  1988-04-14  |  3KB  |  99 lines

  1. /*
  2. **    FUNCTIONS WHICH ALLOW TURBO C 1.5 VIDEO TEXT OUTPUT
  3. **    ROUTINES TO RUN IN A TOPVIEW, DESQVIEW OR MICROSOFT
  4. **    WINDOWS WINDOW, EVEN WHEN DIRECTVIDEO = 1.
  5. **
  6. **    Written by John Navas on Thursday April 14, 1988.
  7. */
  8.  
  9. /*
  10. **    Since these functions do no harm when windowing
  11. **    is not active, they should *always* be used!
  12. */
  13.  
  14. #include <conio.h>
  15. #include <dos.h>
  16.  
  17. #define VIDEOINT    0x10    /* video BIOS interrupt */
  18.  
  19. extern struct _VIDEO {        /* UNDOCUMENTED VIDEO INFORMATION STRUCTURE */
  20.     unsigned char winleft;        /* left window coordinate (0 relative) */
  21.     unsigned char wintop;        /* top window coordinate (0 relative) */
  22.     unsigned char winright;        /* right window coordinate (0 relative) */
  23.     unsigned char winbottom;    /* bottom window coordinate (0 relative) */
  24.     unsigned char attribute;    /* text attribute */
  25.     unsigned char normattr;        /* normal attribute */
  26.     unsigned char currmode;        /* current video text mode */
  27.     unsigned char screenheight;    /* bottom - top */
  28.     unsigned char screenwidth;    /* right - left */
  29.     unsigned char graphics;        /* mode type (0: text; 1: graphics) */
  30.     unsigned char needcgasync;    /* cga sync to prevent "snow" (1: yes) */
  31.     char far *videobuffer;        /* pointer to video buffer */
  32. } _video;
  33.  
  34. char TopViewActive;            /* NON-ZERO IF TOPVIEW WINDOWING IS ACTIVE */
  35.  
  36. /*
  37. **    SETUP FOR TOPVIEW/DESQVIEW VIDEO
  38. **    call at startup and whenever the video mode is changed.
  39. **    installs the shadow buffer address and sets TopViewActive.
  40. */
  41. void SetupTopView(void)
  42. {
  43.     union REGS reg;
  44.     struct SREGS sreg;
  45.  
  46.     if (_video.graphics) {                    /* if in a graphic mode */
  47.         TopViewActive = 0;                    /* TopView cannot be active */
  48.         return;
  49.     }
  50.     reg.h.ah = 0xFE;                        /* Get Video Buffer */
  51.     sreg.es = FP_SEG(_video.videobuffer);    /* assumed buffer address */
  52.     reg.x.di = FP_OFF(_video.videobuffer);
  53.     int86x(VIDEOINT, ®, ®, &sreg);    /* call video BIOS */
  54.     TopViewActive = (_video.videobuffer != MK_FP(sreg.es, reg.x.di));
  55.     if (TopViewActive)                        /* if under TopView */
  56.         _video.needcgasync = 0;                /* CGA sync is never needed */
  57.     _video.videobuffer = MK_FP(sreg.es, reg.x.di);    /* shadow buffer addr */
  58. }
  59.  
  60. /*
  61. **    UPDATE SCREEN FROM TOPVIEW VIDEO BUFFER
  62. **    (not required for DESQview)
  63. */
  64. void UpdateTopView(void)
  65. {
  66.     union REGS reg;
  67.     struct SREGS sreg;
  68.  
  69.     if (_video.graphics || !TopViewActive)    /* if graphic or not active */
  70.         return;                                /* TopView cannot be active */
  71.     reg.h.ah = 0xFF;                        /* update video buffer */
  72.     reg.x.cx = _video.screenheight * _video.screenwidth;    /* all of it */
  73.     sreg.es = FP_SEG(_video.videobuffer);    /* buffer address */
  74.     reg.x.di = FP_OFF(_video.videobuffer);
  75.     int86x(VIDEOINT, ®, ®, &sreg);    /* call video BIOS */
  76.     kbhit();                                /* yield Windows timeslice */
  77. }
  78.  
  79. /*
  80. **    Test the TopView Video Functions.
  81. */
  82.  
  83. int main()
  84. {
  85.     int i;
  86.  
  87.     SetupTopView();
  88.     cputs("This will run fine under DOS,"
  89.         " as well as in a TopView/DESQview/Windows window!\n");
  90.     UpdateTopView();
  91.     for (i=1; i<=25; ++i) {
  92.         sleep(1);
  93.         cprintf("line %2d: %s\n", i,
  94.             "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz");
  95.         UpdateTopView();
  96.     }
  97.     return 0;
  98. }
  99.