home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / qc_prog / chap13 / scrfun.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-07  |  5.4 KB  |  218 lines

  1. /*  scrfun.c -- contains several video BIOS calls     */
  2. /*  Setcurs() sets the cursor position                */
  3. /*  Getcurs() gets the cursor postion                 */
  4. /*  Setpage() sets the current video page             */
  5. /*  Setvmode() sets the video mode                    */
  6. /*  Clearscr() clears the screen                      */
  7. /*  Read_ch_atr() reads the character and             */
  8. /*                attribute at the cursor             */
  9. /*  Write_ch_atr() writes a character and             */
  10. /*                 attribute at the cursor            */
  11. /*  Rewrite() rewrites a screen character             */
  12. /*            with a new attribute                    */
  13. /*  Getvmode() gets the current video mode            */
  14. /*  Getpage() gets the current video page             */
  15. /*                                                    */
  16. /*  The following functions use Setcurs() to move the */
  17. /*  one position at a time up to a limit.             */
  18. /*  Curslt_lim() moves cursor one column left         */
  19. /*  Cursrt_lim() moves cursor one column right        */
  20. /*  Cursup_lim() moves cursor one line up             */
  21. /*  Cursdn_lim() moves cursor one line down           */
  22. /*                                                    */
  23. /*  Programs using these functions should include the */
  24. /*  scrn.h file                                       */
  25.  
  26. #include <dos.h>
  27. #include "scrn.h"
  28.  
  29. /* sets cursor to row, column, and page */
  30. void Setcurs(row, col, page)
  31. unsigned char row, col, page;
  32. {
  33.     union REGS reg;
  34.  
  35.     reg.h.ah = SETCURSOR;
  36.     reg.h.dh = row;
  37.     reg.h.dl = col;
  38.     reg.h.bh = page;
  39.     int86(VIDEO, ®, ®);
  40. }
  41.  
  42. /* gets current cursor row, column for given page */
  43. void Getcurs(pr, pc, page)
  44. unsigned char *pr, *pc, page;
  45. {
  46.     union REGS reg;
  47.  
  48.     reg.h.ah = GETCURSOR;
  49.     reg.h.bh = page;
  50.     int86(VIDEO, ®, ®);
  51.     *pr = reg.h.dh;  /* row number */
  52.     *pc = reg.h.dl;   /* column number */
  53. }
  54.  
  55.  
  56. /* sets page to given value */
  57. void Setpage(page)
  58. unsigned char page;
  59. {
  60.     union REGS reg;
  61.  
  62.     reg.h.ah = SETPAGE;
  63.     reg.h.al = page;
  64.     int86(VIDEO, ®, ®);
  65. }
  66.  
  67. /* sets video mode to given mode */
  68. void Setvmode(mode)
  69. unsigned char mode;
  70. {
  71.     union REGS reg;
  72.  
  73.     reg.h.ah = SETMODE;
  74.     reg.h.al = mode;
  75.     int86(VIDEO, ®, ®);
  76. }
  77.  
  78. /* clear the screen */
  79. void Clearscr()
  80. {
  81.     union REGS reg;
  82.  
  83.     reg.h.ah = SCROLL;
  84.     reg.h.al = 0;
  85.     reg.h.ch = 0;
  86.     reg.h.cl = 0;
  87.     reg.h.dh = ROWS - 1;
  88.     reg.h.dl = COLS - 1;
  89.     reg.h.bh = NORMAL;
  90.     int86(VIDEO, ®, ®);
  91. }
  92.  
  93. /* reads the character and attribute at the cursor */
  94. /* position on a given page                        */
  95. void Read_ch_atr(pc, pa, page)
  96. unsigned char *pc, *pa;
  97. unsigned char page;
  98. {
  99.     union REGS reg;
  100.  
  101.     reg.h.ah = READCHATR;
  102.     reg.h.bh = page;
  103.     int86(VIDEO, ®, ®);
  104.     *pc = reg.h.al;  /* character at cursor */
  105.     *pa = reg.h.ah;  /* attribute at cursor */
  106. }
  107.  
  108. /* writes a given character and attribute at the */
  109. /* cursor on a given page for num times          */
  110. void Write_ch_atr(ch, atr, page, num)
  111. unsigned char ch, atr, page;
  112. unsigned int num;
  113. {
  114.     union REGS reg;
  115.  
  116.     reg.h.ah = WRITECHATR;
  117.     reg.h.al = ch;
  118.     reg.h.bl = atr;
  119.     reg.h.bh = page;
  120.     reg.x.cx = num;
  121.     int86(VIDEO, ®, ®);
  122. }
  123.  
  124. /* rewrites the character at the cursor using    */
  125. /* attribute at                                  */
  126. void Rewrite(at, page)
  127. unsigned char at, page;
  128. {
  129.      unsigned char ch, atr;
  130.  
  131.      Read_ch_atr(&ch, &atr, page);
  132.      Write_ch_atr(ch, at, page, 1);
  133. }
  134.  
  135. /* obtains the current video mode */
  136. unsigned char Getvmode()
  137. {
  138.     union REGS reg;
  139.  
  140.     reg.h.ah = GETMODE;
  141.     int86(VIDEO, ®, ®);
  142.     return reg.h.al;
  143. }
  144.  
  145. /* obtains the current video page */
  146. unsigned char Getpage()
  147. {
  148.     union REGS reg;
  149.  
  150.     reg.h.ah = GETMODE;
  151.     int86(VIDEO, ®, ®);
  152.     return reg.h.bh;
  153. }
  154.  
  155. /* moves cursor one column left, but not past */
  156. /* the given limit                            */
  157. unsigned char Curslt_lim(limit)
  158. unsigned char limit;
  159. {
  160.     unsigned char row, col, page;
  161.     unsigned char status = 1;
  162.  
  163.     Getcurs(&row, &col, page = Getpage());
  164.     if (col > limit)
  165.         Setcurs(row, col - 1, page);
  166.     else
  167.         status = 0;
  168.     return status;
  169. }
  170.  
  171. /* moves cursor one column right, but not past */
  172. /* the given limit                             */
  173. unsigned char Cursrt_lim(limit)
  174. unsigned char limit;
  175. {
  176.     unsigned char row, col, page;
  177.     unsigned char status = 1;
  178.  
  179.     Getcurs(&row, &col, page = Getpage());
  180.     if (col < limit)
  181.         Setcurs(row, col + 1, page);
  182.     else
  183.         status = 0;
  184.     return status;
  185. }
  186.  
  187. /* move cursor one row down, but not past */
  188. /* the given limit                        */
  189. unsigned char Cursup_lim(limit)
  190. unsigned char limit;
  191. {
  192.     unsigned char row, col, page;
  193.     unsigned char status = 1;
  194.  
  195.     Getcurs(&row, &col, page = Getpage());
  196.     if (row > limit)
  197.         Setcurs(row - 1, col, page);
  198.     else
  199.         status = 0;
  200.     return status;
  201. }
  202.  
  203. /* move cursor one row down, but not past */
  204. /* the given limit                        */
  205. unsigned char Cursdn_lim(limit)
  206. unsigned char limit;
  207. {
  208.     unsigned char row, col, page;
  209.     unsigned char status = 1;
  210.  
  211.     Getcurs(&row, &col, page = Getpage());
  212.     if (row < limit)
  213.         Setcurs(row + 1, col, page);
  214.     else
  215.         status = 0;
  216.     return status;
  217. }
  218.