home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DISPIO.ZIP / DISPIOF.C < prev    next >
Encoding:
Text File  |  1988-07-27  |  13.0 KB  |  431 lines

  1. /*      Small functions which use DISPIO BIOS calls and include file       */
  2. /* DISPIO.H.                                                               */
  3. /*                                                                         */
  4. /* set_dfull()                  - Set up display parameters except         */
  5. /*                                the attribute (d_attr).                  */
  6. /*                                                                         */
  7. /* d_tomono()                   - Change monitor to mono                   */
  8. /* d_toc80()                    - Change monitor to 80 column color        */
  9. /* d_toc40()                    - Change monitor to 40 column color        */
  10. /*                                                                         */
  11. /* i = d_newmode(newmode)       - Change mode to newmode.  i = 1 if mode   */
  12. /*                                newmode is valid for this monitor, 0     */
  13. /*                                otherwise.                               */
  14. /*                                                                         */
  15. /* i = d_newpage(newpage)       - Change active page to newpage.  i = 1    */
  16. /*                                if newpage is valid for this mode, 0     */
  17. /*                                otherwise.                               */
  18. /*                                                                         */
  19. /* clrscr()                     - Clear the current window.  Leave the     */
  20. /*                                cursor in the upper left hand corner.    */
  21. /*                                                                         */
  22. /* d_erasel()                   - Erase current line.  Leave cursor at its */
  23. /*                                start.                                   */
  24. /*                                                                         */
  25. /* d_ereol()                    - Erase from the cursor to the end of the  */
  26. /*                                current line.  Do not move the cursor.   */
  27. /*                                                                         */
  28. /* d_nextc()                    - Move the cursor to the next position.    */
  29. /*                                If at the end of the window, scroll up   */
  30. /*                                one line and move to the lower left      */
  31. /*                                corner.                                  */
  32. /*                                                                         */
  33. /* d_nextl()                    - Move the cursor to the next line.  If    */
  34. /*                                at the end of the window, scroll up one  */
  35. /*                                line and move to the lower left corner.  */
  36. /*                                                                         */
  37. /* d_putc(ch)                   - Write a single character at the cursor   */
  38. /*                                position and move the cursore to the     */
  39. /*                                next position.  If at the end of the     */
  40. /*                                window, scroll up one line and move to   */
  41. /*                                the lower left hand corner.              */
  42. /*                                                                         */
  43. /* i = d_puts(s)                - Write the string s, starting at the      */
  44. /*                                cursor position.  If the window would    */
  45. /*                                overflow, scroll it up enough lines to   */
  46. /*                                fit.  The cursor ends one position       */
  47. /*                                after the end of the string.  The        */
  48. /*                                function returns the number of           */
  49. /*                                characters written.                      */
  50. /*                                                                         */
  51. /*      Draw vertical lines                                                */
  52. /*      If length > 0, draw down, but not beyond the bottom of the screen  */
  53. /*      If length < 0, draw up, but not beyond the top of the screen       */
  54. /*      The functions return the number of characters written, 0 for       */
  55. /* error.  They leave the cursor one beyone the end of the line drawn.     */
  56. /* verline(ch, length)          - draw a vertical line of length length    */
  57. /*                                starting at the current cursor position  */
  58. /* vline(row, col, ch, length) - draw a vertical line of length length     */
  59. /*                                characters ch, starting at row, col.     */
  60. /*                                Checks row and col for validity.         */
  61. /*      row is in the range 0 - 24.                                        */
  62. /*      col is either in range 0 - 39 or 0 - 79                            */
  63. /* _vline(row, col, ch, length) - draw a vertical line of length length    */
  64. /*                                characters ch, starting at row, col.     */
  65. /*                                Does not check row and col.              */
  66. /*                                                                         */
  67. /*      Draw horizontal lines                                              */
  68. /*      If width > 0, draw down, but not beyond the bottom of the screen   */
  69. /*      If width < 0, draw up, but not beyond the top of the screen        */
  70. /*      The functions return the number of characters written, 0 for       */
  71. /* error.  They leave the cursor one beyone the end of the line drawn.     */
  72. /* horline(ch, width)           - draw a horizontal line of width width    */
  73. /*                                starting at the current cursor position  */
  74. /* hline(row, col, ch, width)   - draw a horizontal line of width width    */
  75. /*                                characters ch, starting at row, col.     */
  76. /*                                Checks row and col for validity.         */
  77. /*      row is in the range 0 - 24.                                        */
  78. /*      col is either in range 0 - 39 or 0 - 79                            */
  79. /* _hline(row, col, ch, width)  - draw a horizontal line of width width    */
  80. /*                                characters ch, starting at row, col.     */
  81. /*                                Does not check row and col.              */
  82. /*                                                                         */
  83. /* Lew Paper                                                               */
  84. /*                                                                         */
  85. /*                                                                         */
  86.  
  87. #include "dispio.h"
  88.  
  89. #undef PAGE
  90. #define PAGE d_page
  91.  
  92. #undef WRTCHAR
  93. #define WRTCHAR(CH) write_ac(d_attr, CH, PAGE, 1);
  94.  
  95. /*  Initial values for display parameters.  Change to suit the application */
  96. /*  These are for the full screen of the monochrome monitor*/
  97. #define INIT_DMODE     7        /* Monochrome */
  98. #define INIT_DCOLS    80        /* 80 columns wide */
  99. #define INIT_DPAGE     0        /* Page 0 */
  100. #define INIT_DTOP      0        /* Top row is 0 */
  101. #define INIT_DBOTTOM  24        /* Bottom row is 24 */
  102. #define INIT_DLEFT     0        /* Left hand column is 0 */
  103. #define INIT_DRIGHT   79        /* Right hand column is 79 */
  104. #define INIT_DULC      0        /* Upper left hand corner */
  105. #define INIT_DLRC 0x184f        /* Lower right hand corner, (24<<8) + 79 */
  106. #define INIT_DATTR     7        /* Standard attribute */
  107.  
  108. #define MAXSTRING 254
  109.  
  110. #define SCRL_UP1 dispio(0x0601, STD_CHAR, d_ulc, d_lrc)
  111.  
  112. /* Display parameters.  Note that they can be declared external in other
  113.    modules */
  114. int d_mode = INIT_DMODE;
  115. int d_cols = INIT_DCOLS;
  116. int d_page = INIT_DPAGE;
  117. int d_top = INIT_DTOP;
  118. int d_bottom = INIT_DBOTTOM;
  119. int d_left = INIT_DLEFT;
  120. int d_right = INIT_DRIGHT;
  121. int d_ulc = INIT_DULC;
  122. int d_lrc = INIT_DLRC;
  123. int d_attr = INIT_DATTR;
  124.  
  125. int set_dfull()
  126.  
  127. {
  128.    
  129.    dispio(GET_STATE, &d_mode, &d_cols, &d_page);
  130.    d_top = d_left = d_ulc = 0;
  131.    d_bottom = 24;
  132.    d_right = d_cols - 1;
  133.    d_lrc = (24 << 8) + d_right;
  134.    
  135. }
  136.  
  137. int d_tomono() 
  138.  
  139. {
  140.    
  141.    mono_dsp();
  142.    set_dfull();
  143.    
  144. }
  145.  
  146. int d_toc80() 
  147.  
  148. {
  149.    
  150.    c80_disp();
  151.    set_dfull();
  152.    
  153. }
  154.  
  155. int d_toc40() 
  156.  
  157. {
  158.    
  159.    c40_disp();
  160.    set_dfull();
  161.    
  162. }
  163.  
  164. int d_newmode(newmode)
  165.  
  166. int newmode;
  167.  
  168. {
  169.    
  170.    if (d_mode == 7 || newmode < 0 || newmode > 6) return(0);
  171.    dispio(newmode);
  172.    set_dfull();
  173.    return(1);
  174.    
  175. }
  176.  
  177. int d_newpage(new_page)
  178.  
  179. int new_page;
  180.  
  181. {
  182.    
  183.    if (new_page < 0) return(0);
  184.    switch (d_mode) {
  185.       case 2: case 3:
  186.          if (new_page > 3) return(0);
  187.          break;
  188.       case 0: case 1:
  189.          if (new_page > 7) return(0);
  190.          break;
  191.       default: return(0);
  192.    }
  193.    dispio(SELECT_PAGE + new_page);
  194.    d_page = new_page;
  195.    return(1);
  196.    
  197. }
  198.  
  199. int clrscr() {
  200.    
  201.    if (d_top == d_bottom) {
  202.       CURPOS(d_top, d_left);
  203.       write_ac(STD_CHAR, ' ', PAGE, d_right - d_left + 1);
  204.    }
  205.    /* SCROLL_UP has number of columns = 0, so the next line 
  206.       clears the window */
  207.       else dispio(SCROLL_UP, STD_CHAR, d_ulc, d_lrc); 
  208.    dispio(SET_CUR, PAGE, d_ulc);
  209.    
  210. }
  211.  
  212. int d_erasel()
  213.  
  214. {
  215.    
  216.    int row, col;
  217.    
  218.    read_loc(PAGE, &row, &col);
  219.    CURPOS(row, d_left);
  220.    write_ac(STD_CHAR, ' ', PAGE, d_right - d_left + 1);
  221.    CURPOS(row, d_left);
  222.  
  223. }
  224.  
  225. int d_ereol()
  226.  
  227. {
  228.    
  229.    int row, col;
  230.    
  231.    read_loc(PAGE, &row, &col);
  232.    write_ac(STD_CHAR, ' ', PAGE, d_right - col + 1);
  233.    CURPOS(row, col);
  234. }
  235.  
  236. int d_nextc()
  237.  
  238. {
  239.    
  240.    int row, col;
  241.    
  242.    read_loc(PAGE, &row, &col);
  243.    if (col < d_right) ++col;
  244.    else {
  245.       col = d_left;
  246.       if (row < d_bottom) ++row;
  247.       else SCRL_UP1;
  248.    }
  249.    CURPOS(row, col);
  250.    
  251. }
  252.  
  253. int d_nextl()
  254.  
  255. {
  256.    
  257.    int row, col;
  258.    
  259.    read_loc(PAGE, &row, &col);
  260.    col = d_left;
  261.    if (row < d_bottom) ++row;
  262.    else SCRL_UP1;
  263.    CURPOS(row, col);
  264.    
  265. }
  266.  
  267. int d_putc(ch)
  268.  
  269. char ch;
  270.  
  271. {
  272.    
  273.    if (ch == '\n') d_nextl();
  274.    else {
  275.       WRTCHAR(ch);
  276.       d_nextc();
  277.    }
  278.    
  279. }
  280.  
  281. int d_puts(s)
  282.  
  283. char *s;
  284.  
  285. {
  286.    
  287.    char *i, c;
  288.    int row, col, j;
  289.    
  290.    read_loc(PAGE, &row, &col);
  291.    
  292.    for (i = s, j = MAXSTRING; j; --j, ++i) {
  293.       if (!(c = *i)) break; /* End of string */
  294.       if (c != '\n') {
  295.          WRTCHAR(*i);
  296.          if (col < d_right) {  /* Stay on same line */
  297.             ++col;
  298.             CURPOS(row, col);
  299.             continue;
  300.          }
  301.       }
  302.       col = d_left;              /* Go to next line */
  303.       if (row < d_bottom) ++row;
  304.       else SCRL_UP1;
  305.       CURPOS(row, col);
  306.    }
  307.    return(i - s);
  308. }
  309.  
  310. int verline(ch, length)
  311.  
  312. char ch;
  313. int length;
  314.  
  315. {
  316.    int row, col;
  317.    
  318.    read_loc(d_page, &row, &col);
  319.    return(_vline(row, col, ch, length));
  320.    
  321. }
  322.  
  323. int vline(row, col, ch, length)
  324.  
  325. char ch;
  326. int row, col, length;
  327.  
  328. {
  329.    
  330.    if (row < d_top || row > d_bottom || col < d_left || col > d_right) 
  331.        return(0);
  332.    return(_vline(row, col, ch, length));
  333.    
  334. }
  335.  
  336. int _vline(row, col, ch, length)
  337.  
  338. char ch;
  339. int row, col, length;
  340.  
  341. {
  342.    
  343.    int start_r, end_r, count, return_r;
  344.    
  345.    if (length == 0) return(0);
  346.    
  347.    if (length > 0) {
  348.       start_r = row;
  349.       end_r = start_r + length - 1;
  350.       if (end_r > d_bottom) end_r = d_bottom;  /* Don't go beyond bottom */
  351.       count = end_r - start_r + 1;
  352.       return_r = end_r + (end_r < d_bottom);   /* Don't go beyond bottom */
  353.    }
  354.    else {
  355.       start_r = row + length + 1;  /* length < 0, so start_r < row */
  356.       if (start_r < d_top) start_r = d_top;  /* Don't go beyond top */
  357.       end_r = row;
  358.       count = start_r - end_r - 1;
  359.       return_r = start_r -(start_r > d_top); /* Don't go beyone top */
  360.    }
  361.    
  362.    for ( ; start_r <= end_r; ++start_r) {
  363.       CURPOS(start_r, col);
  364.       WRTCHAR(ch);
  365.    }
  366.    
  367.    CURPOS(return_r, col);
  368.    return(count);
  369.    
  370. }
  371.  
  372. int horline(ch, width)
  373.  
  374. char ch;
  375. int width;
  376.  
  377. {
  378.    int row, col;
  379.    
  380.    read_loc(d_page, &row, &col);
  381.    return(_hline(row, col, ch, width));
  382.    
  383. }
  384.  
  385. int hline(row, col, ch, width)
  386.  
  387. char ch;
  388. int row, col, width;
  389.  
  390. {
  391.    
  392.    if (row < d_top || row > d_bottom || col < d_left || col > d_right) 
  393.        return(0);
  394.    return(_hline(row, col, ch, width));
  395.    
  396. }
  397.  
  398. int _hline(row, col, ch, width)
  399.  
  400. char ch;
  401. int row, col, width;
  402.  
  403. {
  404.    
  405.    int start_c, end_c, count, return_c;
  406.    
  407.    if (width == 0) return(0);
  408.    
  409.    if (width > 0) {
  410.       start_c = col;
  411.       end_c = start_c + width - 1;
  412.       if (end_c > d_right) end_c = d_right;  /* Don't go beyond right end */
  413.       return_c = end_c + (end_c < d_right);   /* Don't go beyond right end */
  414.    }
  415.    else {
  416.       start_c = col + width + 1;  /* width < 0, so start_c < col */
  417.       if (start_c < d_left) start_c = d_left;  /* Don't go beyond left end */
  418.       end_c = col;
  419.       return_c = start_c -(start_c > d_left); /* Don't go beyone left end */
  420.    }
  421.    
  422.    CURPOS(row, start_c);
  423.    count = end_c - start_c + 1;
  424.    write_ac(d_attr, ch, PAGE, count);
  425.    
  426.    CURPOS(row, return_c);
  427.    return(width > 0 ? count: -count);
  428.    
  429. }
  430.  
  431.