home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * sc_handl.c - screen handler routines.
- *
- * Purpose: This file contains the cursor move functions as well
- * as the line move functions for delete and insert modes.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include "blackstr.h"
- #include "sc_head.h"
- #include "gr_head.h"
- #include "sc_defs.h"
- #include "kb_head.h" /* contains #defines for CR, etc */
-
-
- /********
- *
- * sc_movcur(dcol,drow) - move cursor on screen
- *
- **/
-
- void sc_movcur(int dcol, int drow)
- {
- int col,row;
-
- col = sc_col_+dcol;
- row = sc_row_+drow;
- sc_setcur(col,row);
- }
-
-
- /********
- *
- * sc_cursor(flag) - set cursor on/off flag = 0 for OFF,
- * 1 for ON
- **/
-
- void sc_cursor(int flag)
- {
- if(flag)
- sc_cson_();
- else
- sc_csof_(); /* set cursor off */
- }
-
-
- /********
- *
- * sc_clip(&col,&row) - clip the cursor location,wrap, & scroll
- *
- **/
-
- void sc_clip(int *col, int *row)
- {
- int nrows;
-
- if (*col < colst_) /* Check for too far left */
- *col = colst_; /* if so, clip to left boundary */
-
- else if (*col > colen_) { /* Check for too far right */
- if (!wrapf_) /* check if wrap is off */
- *col = colen_; /* if so, clip to right boundary */
- else { /* if clip is on */
- *col = colst_; /* wrap to left boundary */
- *row += 1; /* and down to next row */
- }
- }
-
- if (*row < rowst_) /* Check for too far up */
- *row = rowst_; /* if so, clip to top boundary */
- else if (*row > rowen_) { /* Check for too far down */
- if (!scrollf_) /* check if scroll is off */
- *row = rowen_; /* if so, clip to bottom boundary */
- else { /* if scroll is on */
- /* if up, and set to bottom */
- nrows = -(*row - rowen_);
- sc_scroll(nrows,colst_,rowst_,colen_,rowen_);
- *row = rowen_;
- }
- }
- }
-
-
- /********
- *
- * sc_getrow() - get cursor row
- *
- **/
-
- int sc_getrow(void)
- {
- sc_cget_(); /* use primitive */
- return(sc_row_);
- }
-
-
- /********
- *
- * sc_getcol() - get cursor column
- *
- **/
-
- int sc_getcol(void)
- {
- sc_cget_(); /* use primitive */
- return(sc_col_); /* return column only */
- }
-
-
- /********
- *
- * sc_setcur(col,row) - set cursor position (absolute )
- *
- **/
-
- void sc_setcur(int col, int row)
- {
- int s_col,s_row;
-
- s_col = col;
- s_row = row;
- sc_clip(&s_col,&s_row);
- sc_cset_(s_col,s_row);
- }
-
-
- /********
- *
- * sc_init(mode,fcolr,bcolr) - initialize screen
- *
- **/
-
- void sc_init(int mode,char fcolr, char bcolr)
- {
- if(mode) {
- sc_smod_(mode); /* first set mode */
- if(sc_adp_&EGA_ADP)
- sc_s7bit_(FALSE); /* set bit 7 for intensity */
- } else {
- if(!rattr_)
- sc_color(WHITE,BLACK); /* default attributes */
- sc_gmod_(); /* or just get current settings */
- }
- if(fcolr|bcolr) {
- if((mode==MO_BW80)||(mode==MO_BW40))/* check for color mode */
- sc_color(WHITE,BLACK); /* only b&w */
- else
- sc_color(fcolr,bcolr); /* then set color */
- }
- sc_attr(AT_REG); /* set attribute to regular */
- scolst_ = srowst_ = 0;
- scolen_ = sc_cols_-1;
- srowen_ = sc_rows_-1;
- sc_windo(scolst_,srowst_,scolen_,srowen_); /* full screen */
- sc_setcur(0,0); /* home cursor */
- sc_cursor(TRUE); /* and turn it on */
- scrollf_=wrapf_= TRUE; /* set wrap & scroll on */
- nlexpf_ = TRUE; /* \n expansion on */
- }
-
-
- /********
- *
- * sc_color(fcolr,bcolr) - set screen color for characters
- *
- **/
-
- void sc_color(char fcolr, char bcolr)
- {
- if (sc_adp_&CGA_ADP) {
- rattr_ = ( ((bcolr&0x07)<<4) | (fcolr&0x07)); /* regular */
- nattr_ = ( ((fcolr&0x07)<<4) | (bcolr&0x07)); /* inverse */
-
- /* EGA is set for bit 7 background intensity */
- }
- else if ( (sc_adp_&EGA_ADP) && (sc_mode_<7) ) { /* check for EGA */
- rattr_ = ( ((bcolr&0x0f)<<4) | (fcolr&0x0f)); /* regular */
- nattr_ = ( ((fcolr&0x0f)<<4) | (bcolr&0x0f)); /* inverse */
- }
- else {
- rattr_ = fcolr; /* for EGA graphic modes */
- nattr_ = bcolr;
- }
- sc_sattr_(rattr_); /* set to regular */
- }
-
-
- /********
- *
- * sc_font(fonts) - load a new character font
- *
- **/
-
- void sc_font(struct FONT *fonts)
- {
- if(sc_adp_&EGA_ADP)
- sc_font_(fonts); /* just use asm driver */
- srowen_ = sc_rows_ - 1; /* reset maximum screen */
- sc_winfull();
- }
-
-
- /********
- *
- * sc_attr(atype) - set display attribute
- *
- **/
-
- void sc_attr(int atype)
- {
- switch(atype){
- case AT_REG:
- sc_sattr_(rattr_);
- if(sc_adp_&EGA_ADP)
- sc_s7bit_(FALSE); /* set bit 7 for intensity) */
- break;
- case AT_INV:
- sc_sattr_(nattr_);
- break;
- case AT_HIGH:
- sc_sattr_(sc_attr_ | AT_HIM);
- break;
- case AT_LOW:
- sc_sattr_(sc_attr_ & AT_LOM);
- break;
- case AT_BLINK:
- sc_sattr_(sc_attr_ | AT_BLM);
- if(sc_adp_&EGA_ADP)
- sc_s7bit_(TRUE); /* set bit 7 for blinking */
- break;
- }
- }
-
-
- /********
- *
- * sc_putc(c) - put char on screen and move cursor
- *
- **/
-
- int sc_putc(char c)
- {
- if (c == CR) /* Return to left edge of window, same row for <CR> */
- sc_setcur(colst_,sc_row_);
-
- else if (c == NEWLINE) { /* Newline processing */
- if (nlexpf_) /* expand \n to \r\n if expand flag is on */
- sc_putc(CR);
- sc_movcur(0,1); /* Move cursor down one line for newline */
- } else {
- if(!wrapf_ && sc_col_ >= colen_)
- return 0;
- if(c==TAB) { /* For tab, move to next 8th column */
- do {
- if(!wrapf_ && sc_col_ >= colen_)
- return 0;
- sc_putc_(BLANK);
- sc_movcur(1,0);
- } while ((sc_col_%8) != 0);
- } else { /* Otherwise, output character and */
- sc_putc_(c); /* move one column right */
- sc_movcur(1,0);
- }
- }
- return 0;
- }
-
- /********
- *
- * sc_putsv(str) - put string in vertical orientation
- *
- **/
-
- void sc_putsv(char *str) /* string to print in vertical */
- {
- while(*str) {
- sc_putc_(*str++);
- sc_movcur(0,1); /* move cursor down */
- }
- }
-
-
- /********
- *
- * sc_puts(str) - output string to screen
- *
- **/
-
- int sc_puts(char *str) /* output string onto screen */
- {
- while (*str != NUL) {
- sc_putc(*str++);
- }
- return 0;
- }
-
-
- /********
- *
- * sc_putl(str) - output line to screen
- *
- **/
-
- void sc_putl(char *str) /* output line onto screen */
- {
- sc_eeol();
- while ((*str != NUL) && (*str!=NEWLINE)) {
- if(*str!=CR)
- sc_putc(*str);
- str++;
- }
- }
-
-
- /********
- *
- * sc_getch() - get character from screen at col,row
- *
- **/
-
- int sc_getch(int col, int row)
- {
- int ocol,orow;
- int c;
-
- ocol = sc_col_; /* Save cursor location */
- orow = sc_row_;
- sc_setcur(col,row);
- c = sc_getc_();
- sc_setcur(ocol,orow); /* Restore cursor position */
- return(c);
- }
-
-
- /********
- *
- * sc_putch(c) - put character to screen with wrap & scroll
- *
- **/
-
- void sc_putch(char c)
- {
- int owrapf,oscrollf;
-
- owrapf = wrapf_;
- oscrollf = scrollf_;
- scrollf_=wrapf_ = TRUE;
- sc_putc(c);
- scrollf_ = oscrollf;
- wrapf_ = owrapf;
- }
-
-
- /********
- *
- * sc_eeol() - erase to end of line
- *
- **/
-
- void sc_eeol(void)
- {
- int ocol,orow,owrapf;
-
- ocol = sc_col_;
- orow = sc_row_; /* save cursor position */
- owrapf = wrapf_;
- wrapf_=FALSE; /* can't wrap now */
- while(sc_col_<colen_)
- sc_putc(BLANK); /* blank fill */
- sc_putc(BLANK); /* blank last spot */
- wrapf_= owrapf;
- sc_setcur(ocol,orow); /* restore cursor position */
- }
-
-
- /********
- *
- * sc_clr() - clear the current window
- *
- **/
-
- void sc_clr(void)
- {
- sc_clrwin(colst_,rowst_,colen_,rowen_);
- sc_setcur(colst_,rowst_);
- }
-
-
- /********
- *
- * sc_clrwin(col1,row1,col2,row2) - clear a screen window
- *
- **/
-
- void sc_clrwin(int col1, int row1, int col2, int row2) /* clear a window */
- {
- sc_swdn_(0,row1,col1,row2,col2);
- }
-
-
- /********
- *
- * sc_scroll(nrows,col1,row1,col2,row2) - scroll portion of screen
- *
- **/
-
- void sc_scroll(int nrows, int col1, int row1, int col2, int row2)
- /* nrows < 0 to scroll portion of screen up */
- /* = 0 to clear portion of screen */
- /* > 0 to scroll portion of screen down */
- /* Top left corner of portion of screen */
- /* Bottom right corner of portion of screen */
- {
- if (nrows < 0) /* Scroll up */
- sc_swup_(-nrows,row1,col1,row2,col2);
- else if (nrows == 0) /* sc_swup_ clears if nrows = 0 */
- sc_swup_(0,row1,col1,row2,col2);
- else /* Scroll down */
- sc_swdn_(nrows,row1,col1,row2,col2);
- }
-
-
- /********
- *
- * sc_windo(col1,row1,col2,row2) - set window dimensions
- *
- **/
-
- void sc_windo(int col1, int row1, int col2, int row2)
- {
- colst_ = col1;
- rowst_ = row1;
- colen_ = col2;
- rowen_ = row2;
- }
-
-
- /********
- *
- * sc_getwin() - get graphics windo
- *
- **/
-
- char *sc_getwin(int x1, int y1, int x2, int y2)
- {
- extern char *malloc();
- char *ptr; /* pointer to windo buffer */
-
- sc_winpush(); /* save current windo */
- sc_windo(x1,y1,x2,y2); /* set current windo */
- ptr = malloc(2*(x2-(--x1))*(y2-(--y1))); /* buffer size for windo */
- sc_gwin_(sc_page_, ptr);
- sc_winpop(); /* restore previous windo */
- return(ptr);
- }
-
-
- /********
- *
- * sc_putwin(buff,x1,y1,x2,y2) - put graphics windo
- *
- **/
-
- void sc_putwin(char *buff, int x1, int y1, int x2, int y2)
- {
- sc_winpush(); /* save current windo */
- sc_windo(x1,y1,x2,y2);
- sc_pwin_(sc_page_, buff); /* put buffer to windo */
- sc_winpop(); /* restore previous windo */
- }
-
-
-