home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / SC_HANDL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-23  |  10.7 KB  |  477 lines

  1. /*********************
  2.  *
  3.  *  sc_handl.c - screen handler routines.
  4.  *
  5.  *  Purpose: This file contains the cursor move functions as well
  6.  *           as the line move functions for delete and insert modes.
  7.  *
  8.  *  Blackstar C Function Library
  9.  *  (c) Copyright 1985,1989 Sterling Castle Software
  10.  *
  11.  *******/
  12.  
  13. #include "blackstr.h"
  14. #include "sc_head.h"
  15. #include "gr_head.h"
  16. #include "sc_defs.h"
  17. #include "kb_head.h"               /* contains #defines for CR, etc */   
  18.  
  19.  
  20. /********
  21.  *
  22.  *   sc_movcur(dcol,drow) - move cursor on screen
  23.  *
  24.  **/
  25.  
  26. void sc_movcur(int dcol, int drow)
  27. {
  28.     int col,row;
  29.  
  30.     col = sc_col_+dcol;
  31.     row = sc_row_+drow;
  32.     sc_setcur(col,row);
  33. }
  34.  
  35.  
  36. /********
  37.  *
  38.  *   sc_cursor(flag) - set cursor on/off    flag = 0 for OFF,
  39.  *                                                 1 for ON
  40.  **/
  41.  
  42. void sc_cursor(int flag)
  43. {
  44.     if(flag)
  45.     sc_cson_();
  46.     else
  47.     sc_csof_();     /* set cursor off */
  48. }
  49.  
  50.  
  51. /********
  52.  *
  53.  *   sc_clip(&col,&row) - clip the cursor location,wrap, & scroll
  54.  *
  55.  **/
  56.  
  57. void sc_clip(int *col, int *row)
  58. {
  59.     int  nrows;
  60.  
  61.     if (*col < colst_)        /* Check for too far left           */
  62.     *col = colst_;        /*  if so, clip to left boundary    */
  63.  
  64.     else if (*col > colen_) { /* Check for too far right          */
  65.     if (!wrapf_)          /*  check if wrap is off            */
  66.         *col = colen_;    /*   if so, clip to right boundary  */
  67.     else {                /*  if clip is on                   */
  68.         *col = colst_;    /*   wrap to left boundary          */
  69.         *row += 1;        /*   and down to next row           */
  70.         }
  71.     }
  72.  
  73.     if (*row < rowst_)        /*  Check for too far up            */
  74.     *row = rowst_;        /*   if so, clip to top boundary    */
  75.     else if (*row > rowen_) { /*  Check for too far down          */
  76.     if (!scrollf_)        /*   check if scroll is off         */
  77.         *row = rowen_;    /*  if so, clip to bottom boundary  */
  78.     else {                /*  if scroll is on                 */
  79.                   /*  if up, and set to bottom        */
  80.         nrows = -(*row - rowen_);
  81.         sc_scroll(nrows,colst_,rowst_,colen_,rowen_);
  82.         *row = rowen_;
  83.         }
  84.     } 
  85. }
  86.  
  87.  
  88. /********
  89.  *
  90.  *   sc_getrow() - get cursor row
  91.  *
  92.  **/
  93.  
  94. int sc_getrow(void)
  95. {
  96.     sc_cget_();             /* use primitive */
  97.     return(sc_row_);
  98. }
  99.  
  100.  
  101. /********
  102.  *
  103.  *   sc_getcol() - get cursor column
  104.  *
  105.  **/
  106.  
  107. int sc_getcol(void)
  108. {
  109.     sc_cget_();             /* use primitive */
  110.     return(sc_col_);        /* return column only */
  111. }
  112.  
  113.  
  114. /********
  115.  *
  116.  *   sc_setcur(col,row) - set cursor position (absolute )
  117.  *
  118.  **/
  119.  
  120. void sc_setcur(int col, int row)
  121. {
  122.     int s_col,s_row;
  123.  
  124.     s_col = col;
  125.     s_row = row;
  126.     sc_clip(&s_col,&s_row);
  127.     sc_cset_(s_col,s_row);
  128. }
  129.  
  130.  
  131. /********
  132.  *
  133.  *   sc_init(mode,fcolr,bcolr) - initialize screen
  134.  *
  135.  **/
  136.  
  137. void sc_init(int mode,char fcolr, char bcolr)
  138. {
  139.     if(mode) {
  140.     sc_smod_(mode);                 /* first set mode */
  141.     if(sc_adp_&EGA_ADP)
  142.         sc_s7bit_(FALSE);           /* set bit 7 for intensity */
  143.     } else {
  144.     if(!rattr_)
  145.         sc_color(WHITE,BLACK);      /* default attributes */
  146.     sc_gmod_();                                                             /* or just get current settings */
  147.     }
  148.     if(fcolr|bcolr) {
  149.     if((mode==MO_BW80)||(mode==MO_BW40))/* check for color mode */
  150.         sc_color(WHITE,BLACK);      /* only b&w */
  151.     else
  152.         sc_color(fcolr,bcolr);      /* then set color */
  153.     }
  154.     sc_attr(AT_REG);                                                                /* set attribute to regular */
  155.     scolst_ = srowst_ = 0;
  156.     scolen_ = sc_cols_-1;
  157.     srowen_ = sc_rows_-1;
  158.     sc_windo(scolst_,srowst_,scolen_,srowen_);      /* full screen */
  159.     sc_setcur(0,0);                     /* home cursor */
  160.     sc_cursor(TRUE);                    /* and turn it on */
  161.     scrollf_=wrapf_= TRUE;              /* set wrap & scroll on */
  162.     nlexpf_ = TRUE;                     /* \n expansion on     */
  163. }
  164.  
  165.  
  166. /********
  167.  *
  168.  *   sc_color(fcolr,bcolr) - set screen color for characters
  169.  *
  170.  **/
  171.  
  172. void sc_color(char fcolr, char bcolr)
  173. {
  174.     if (sc_adp_&CGA_ADP) {
  175.     rattr_ = ( ((bcolr&0x07)<<4) | (fcolr&0x07));  /* regular */
  176.     nattr_ = ( ((fcolr&0x07)<<4) | (bcolr&0x07));  /* inverse */
  177.  
  178.     /*  EGA is set for bit 7 background intensity */
  179.     }
  180.     else if ( (sc_adp_&EGA_ADP) && (sc_mode_<7) ) {    /* check for EGA */
  181.     rattr_ = ( ((bcolr&0x0f)<<4) | (fcolr&0x0f));  /* regular */
  182.     nattr_ = ( ((fcolr&0x0f)<<4) | (bcolr&0x0f));  /* inverse */
  183.     }
  184.     else {
  185.     rattr_ = fcolr;                                                                 /* for EGA graphic modes */
  186.     nattr_ = bcolr;
  187.     }
  188.     sc_sattr_(rattr_);                  /* set to regular */
  189. }
  190.  
  191.  
  192. /********
  193.  *
  194.  *   sc_font(fonts) - load a new character font
  195.  *
  196.  **/
  197.  
  198. void sc_font(struct FONT *fonts)
  199. {
  200.     if(sc_adp_&EGA_ADP)
  201.     sc_font_(fonts);                /* just use asm driver */
  202.     srowen_ = sc_rows_ - 1;             /* reset maximum screen */
  203.     sc_winfull();
  204. }
  205.      
  206.  
  207. /********
  208.  *
  209.  *   sc_attr(atype) - set display attribute
  210.  *
  211.  **/
  212.  
  213. void sc_attr(int atype)
  214. {
  215.     switch(atype){
  216.       case AT_REG:
  217.       sc_sattr_(rattr_);
  218.       if(sc_adp_&EGA_ADP)
  219.           sc_s7bit_(FALSE);         /* set bit 7 for intensity) */
  220.       break;
  221.       case AT_INV:
  222.       sc_sattr_(nattr_);
  223.       break;
  224.       case AT_HIGH:
  225.       sc_sattr_(sc_attr_ | AT_HIM);
  226.       break;
  227.       case AT_LOW:
  228.       sc_sattr_(sc_attr_ & AT_LOM);
  229.       break;
  230.       case AT_BLINK:
  231.       sc_sattr_(sc_attr_ | AT_BLM);
  232.       if(sc_adp_&EGA_ADP)
  233.           sc_s7bit_(TRUE); /* set bit 7 for blinking */
  234.       break;
  235.     }
  236. }
  237.  
  238.  
  239. /********
  240.  *
  241.  *   sc_putc(c) - put char on screen and move cursor
  242.  *
  243.  **/
  244.  
  245. int sc_putc(char c)
  246. {
  247.     if (c == CR)         /* Return to left edge of window, same row for <CR> */
  248.     sc_setcur(colst_,sc_row_);
  249.  
  250.     else if (c == NEWLINE) {   /* Newline processing                          */
  251.     if (nlexpf_)           /*  expand \n to \r\n if expand flag is on     */
  252.         sc_putc(CR);
  253.     sc_movcur(0,1);        /* Move cursor down one line for newline       */
  254.     } else {
  255.         if(!wrapf_ && sc_col_ >= colen_)
  256.         return 0;
  257.         if(c==TAB) {        /* For tab, move to next 8th column           */
  258.         do {
  259.             if(!wrapf_ && sc_col_ >= colen_)
  260.             return 0;
  261.             sc_putc_(BLANK);
  262.             sc_movcur(1,0);
  263.         } while ((sc_col_%8) != 0);
  264.         } else {             /* Otherwise, output character and */
  265.         sc_putc_(c);   /*  move one column right */
  266.         sc_movcur(1,0);
  267.         }
  268.     }
  269.     return 0;
  270. }
  271.  
  272. /********
  273.  *
  274.  *   sc_putsv(str) - put string in vertical orientation
  275.  *
  276.  **/
  277.  
  278. void sc_putsv(char *str)              /* string to print in vertical */
  279. {
  280.     while(*str) {
  281.     sc_putc_(*str++);
  282.     sc_movcur(0,1);         /* move cursor down */
  283.     }
  284. }
  285.  
  286.  
  287. /********
  288.  *
  289.  *   sc_puts(str) - output string to screen
  290.  *
  291.  **/
  292.  
  293. int sc_puts(char *str)    /* output string onto screen */
  294. {
  295.     while (*str != NUL) {
  296.     sc_putc(*str++);
  297.     }
  298.     return 0;
  299. }
  300.  
  301.  
  302. /********
  303.  *
  304.  *   sc_putl(str) - output line to screen
  305.  *
  306.  **/
  307.  
  308. void sc_putl(char *str)    /* output line onto screen */
  309. {
  310.     sc_eeol();
  311.     while ((*str != NUL) && (*str!=NEWLINE)) {
  312.     if(*str!=CR)
  313.         sc_putc(*str);
  314.     str++;
  315.     }
  316. }
  317.  
  318.  
  319. /********
  320.  *
  321.  *   sc_getch() - get character from screen at col,row
  322.  *
  323.  **/
  324.  
  325. int sc_getch(int col, int row)
  326. {
  327.     int ocol,orow;
  328.     int c;
  329.  
  330.     ocol = sc_col_;          /* Save cursor location    */
  331.     orow = sc_row_;
  332.     sc_setcur(col,row);
  333.     c = sc_getc_();
  334.     sc_setcur(ocol,orow);    /* Restore cursor position */
  335.     return(c);
  336. }
  337.  
  338.  
  339. /********
  340.  *
  341.  *   sc_putch(c) - put character to screen with wrap & scroll
  342.  *
  343.  **/
  344.  
  345. void sc_putch(char c)
  346. {
  347.     int owrapf,oscrollf;
  348.  
  349.     owrapf = wrapf_;
  350.     oscrollf = scrollf_;
  351.     scrollf_=wrapf_ = TRUE;
  352.     sc_putc(c);
  353.     scrollf_ = oscrollf;
  354.     wrapf_ = owrapf;
  355. }
  356.  
  357.  
  358. /********
  359.  *
  360.  *   sc_eeol() - erase to end of line
  361.  *
  362.  **/
  363.  
  364. void sc_eeol(void)
  365. {
  366.     int ocol,orow,owrapf;
  367.  
  368.     ocol = sc_col_;
  369.     orow = sc_row_;             /* save cursor position */
  370.     owrapf = wrapf_;
  371.     wrapf_=FALSE;               /* can't wrap now */
  372.     while(sc_col_<colen_)
  373.     sc_putc(BLANK);         /* blank fill */
  374.     sc_putc(BLANK);             /* blank last spot */
  375.     wrapf_= owrapf;
  376.     sc_setcur(ocol,orow);       /* restore cursor position */
  377. }
  378.  
  379.  
  380. /********
  381.  *
  382.  *   sc_clr() - clear the current window
  383.  *
  384.  **/
  385.  
  386. void sc_clr(void)
  387. {
  388.     sc_clrwin(colst_,rowst_,colen_,rowen_);
  389.     sc_setcur(colst_,rowst_);
  390. }
  391.  
  392.  
  393. /********
  394.  *
  395.  *   sc_clrwin(col1,row1,col2,row2) - clear a screen window
  396.  *
  397.  **/
  398.  
  399. void sc_clrwin(int col1, int row1, int col2, int row2)  /* clear a window */
  400. {
  401.     sc_swdn_(0,row1,col1,row2,col2);
  402. }
  403.  
  404.  
  405. /********
  406.  *
  407.  *   sc_scroll(nrows,col1,row1,col2,row2) - scroll portion of screen
  408.  *
  409.  **/
  410.  
  411. void sc_scroll(int nrows, int col1, int row1, int col2, int row2)
  412.         /* nrows < 0 to scroll portion of screen up   */
  413.         /*       = 0 to clear portion of screen       */
  414.         /*       > 0 to scroll portion of screen down */
  415.         /* Top left corner of portion of screen       */
  416.         /* Bottom right corner of portion of screen   */
  417. {
  418.     if (nrows < 0)            /* Scroll up                    */
  419.         sc_swup_(-nrows,row1,col1,row2,col2);
  420.     else if (nrows == 0)      /* sc_swup_ clears if nrows = 0 */
  421.         sc_swup_(0,row1,col1,row2,col2);
  422.     else                      /* Scroll down                  */
  423.         sc_swdn_(nrows,row1,col1,row2,col2);
  424. }
  425.  
  426.  
  427. /********
  428.  *
  429.  *   sc_windo(col1,row1,col2,row2) - set window dimensions
  430.  *
  431.  **/
  432.  
  433. void sc_windo(int col1, int row1, int col2, int row2)
  434. {
  435.     colst_ = col1;
  436.     rowst_ = row1;
  437.     colen_ = col2;
  438.     rowen_ = row2;
  439. }
  440.  
  441.  
  442. /********
  443.  *
  444.  *   sc_getwin() - get graphics windo
  445.  *
  446.  **/
  447.  
  448. char *sc_getwin(int x1, int y1, int x2, int y2)
  449. {
  450.     extern char *malloc();
  451.     char *ptr;                                                                                              /* pointer to windo buffer */
  452.  
  453.     sc_winpush();                                                                           /* save current windo */
  454.     sc_windo(x1,y1,x2,y2);                    /* set current windo */
  455.     ptr = malloc(2*(x2-(--x1))*(y2-(--y1)));  /* buffer size for windo */
  456.     sc_gwin_(sc_page_, ptr);
  457.     sc_winpop();                                                                            /* restore previous windo */
  458.     return(ptr);
  459. }
  460.  
  461.  
  462. /********
  463.  *
  464.  *   sc_putwin(buff,x1,y1,x2,y2) - put graphics windo
  465.  *
  466.  **/
  467.  
  468. void sc_putwin(char *buff, int x1, int y1, int x2, int y2)
  469. {
  470.     sc_winpush();               /* save current windo */
  471.     sc_windo(x1,y1,x2,y2);
  472.     sc_pwin_(sc_page_, buff);   /* put buffer to windo */
  473.     sc_winpop();                /* restore previous windo */
  474. }
  475.  
  476.  
  477.