home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / VIDEO_2.C < prev    next >
C/C++ Source or Header  |  1992-04-11  |  6KB  |  175 lines

  1. /*------------------------------[ vhdw.c ]-----------------------------*/
  2. /*                     Hardware Interface Routines                     */
  3. /*---------------------------------------------------------------------
  4.  
  5. /*---------------------------------------------------------------------*/
  6. /* This code is a subset of a library copyrighted by Jeff Dunlop.      */
  7. /* License is hereby granted for unrestricted use.                     */
  8. /*---------------------------------------------------------------------*/
  9.  
  10. /*---------------------------------------------------------------------*/
  11. /* dv_info: get video and version info about DesqView                  */
  12. /* get_rows: determine number of rows on screen                        */
  13. /* get_cols: determine number of columns on screen                     */
  14. /* get_vidpage: determine the current text mode video page             */
  15. /* get_vidbase: determine the base of video ram                        */
  16. /* is_dv: determine if DesqView is loaded                              */
  17. /* is_egavga: determine if monitor is ega/vga                          */
  18. /*---------------------------------------------------------------------*/
  19.  
  20. /*--------------------------------------------------------------*/
  21. /*-----------------------[ include files ]----------------------*/
  22. /*--------------------------------------------------------------*/
  23.  
  24. #include <dos.h>
  25.  
  26. typedef struct
  27. {
  28.     int ver_major;
  29.     int ver_minor;
  30.     unsigned regen_buf;
  31.     int win_rows;
  32.     int win_cols;
  33. } DV_INFO;
  34.  
  35. /*------------------------[ get_vidpage ]-----------------------*/
  36. /* Determine the current text mode video page                   */
  37. /*--------------------------------------------------------------*/
  38. /* local:                                                       */
  39. /*      regs = register storage buffer                          */
  40. /* return:                                                      */
  41. /*      video page number as determined by bios call            */
  42. /*--------------------------------------------------------------*/
  43.  
  44. unsigned char get_vidpage(void)
  45. {
  46.     union REGS regs;
  47.  
  48.     regs.h.ah = 0x0f;
  49.     int86(0x10, ®s, ®s);
  50.     return regs.h.bh;
  51. }
  52.  
  53. /*---------------------------[ is_dv ]--------------------------*/
  54. /*             Determine whether DesqView is active             */
  55. /*--------------------------------------------------------------*/
  56.  
  57. int is_dv(void)
  58. {
  59.     union REGS regs;
  60.  
  61.     regs.h.ah = 0x2b;
  62.     regs.x.cx = 0x4445;         /* 'DE' */
  63.     regs.x.dx = 0x5351;         /* 'SQ' */
  64.     regs.h.al = 1;              /* get version */
  65.     int86(0x21, ®s, ®s);
  66.  
  67.     return regs.h.al != 0xff;
  68. }
  69.  
  70. /*--------------------------[ dv_info ]-------------------------*/
  71. /*      Return screen and version info about DesqView           */
  72. /*--------------------------------------------------------------*/
  73. /* return:                                                      */
  74. /*      -1 on error                                             */
  75. /*--------------------------------------------------------------*/
  76.  
  77. int get_dvinfo(DV_INFO *dv_info)
  78. {
  79.     union REGS regs;
  80.  
  81.     regs.h.ah = 0x2b;
  82.     regs.x.cx = 0x4445;         /* 'DE' */
  83.     regs.x.dx = 0x5351;         /* 'SQ' */
  84.     regs.h.al = 1;              /* get version */
  85.     int86(0x21, ®s, ®s);
  86.  
  87.     if (regs.h.al == 0xff)
  88.         return -1;
  89.     dv_info->ver_major = regs.h.bh;
  90.     dv_info->ver_minor = regs.h.bl;
  91.     regs.h.al = 4;              /* get screen info */
  92.     int86(0x21, ®s, ®s);
  93.  
  94.     if (regs.h.al == 0xff)
  95.         return -1;
  96.     dv_info->regen_buf = regs.x.dx;
  97.     dv_info->win_rows = regs.h.bh;
  98.     dv_info->win_cols = regs.h.bl;
  99.     return 0;
  100. }
  101.  
  102. /*------------------------[ get_vidbase ]-----------------------*/
  103. /* Determine the base of video ram                              */
  104. /*--------------------------------------------------------------*/
  105. /* local:                                                       */
  106. /*      regs = register union for ISR                           */
  107. /* return:                                                      */
  108. /*      the current text base segment                           */
  109. /*--------------------------------------------------------------*/
  110.  
  111. unsigned get_vidbase(void)
  112. {
  113.     union REGS regs;
  114.     DV_INFO dv_info;
  115.  
  116.     if (is_dv() && get_dvinfo(&dv_info) != -1)
  117.         return dv_info.regen_buf;
  118.     else
  119.     {
  120.         regs.h.ah = 0xf;
  121.         int86(0x10, ®s, ®s);
  122.  
  123.         if (regs.h.al == 7)
  124.             return 0xb000;
  125.         else
  126.             return 0xb800;
  127.     }
  128. }
  129.  
  130. /*-------------------------[ get_rows ]-------------------------*/
  131. /*  Determine the number of rows in current text mode screen    */
  132. /*--------------------------------------------------------------*/
  133.  
  134. int get_rows(void)
  135. {
  136.     DV_INFO dv_info;
  137.     char far *p = MK_FP(0x40, 0x84);
  138.  
  139.     if (is_dv() && get_dvinfo(&dv_info) != -1)
  140.         return dv_info.win_rows;
  141.     else
  142.         return *p + is_egavga();
  143. }
  144.  
  145. /*-------------------------[ get_cols ]-------------------------*/
  146. /*  Determine the number of columns in current text screen      */
  147. /*--------------------------------------------------------------*/
  148.  
  149. int get_cols(void)
  150. {
  151.     DV_INFO dv_info;
  152.     int far *p = MK_FP(0x40, 0x4a);
  153.  
  154.     if (is_dv() && get_dvinfo(&dv_info) != -1)
  155.         return dv_info.win_cols;
  156.     else
  157.         return *p;
  158. }
  159.  
  160. /*-------------------------[ is_egavga ]------------------------*/
  161. /*      Determine whether the current text mode is ega/vga      */
  162. /*--------------------------------------------------------------*/
  163.  
  164. int is_egavga(void)
  165. {
  166.     union REGS regs;
  167.  
  168.     regs.h.ah = 0x1a;
  169.     regs.h.al = 0;
  170.  
  171.     int86(0x10, ®s, ®s);
  172.  
  173.     return regs.h.al == 0x1a;
  174. }
  175.