home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 337_01 / l_scrn1.c < prev    next >
C/C++ Source or Header  |  1991-01-14  |  8KB  |  312 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_SCRN1.C   ***************************/
  4.  
  5. #include "mydef.h"
  6. #include <dos.h>
  7.  
  8.  
  9. /*****************************************************************
  10.  
  11.  Usage: void ceol(int x, int y);
  12.  
  13.  x= column.
  14.  y= row.
  15.  
  16.  Clears the active window from the x-y coordinate to the end
  17.  of the line.
  18.  
  19. *****************************************************************/
  20.  
  21. void ceol( int x, int y)
  22. {
  23. extern struct  screen_structure scr;
  24. extern struct window_structure w[];
  25.  
  26. int i;
  27. char string[255];
  28. int width;
  29. char old_current =scr.current;
  30.  if(x>(scr.right-scr.left+1))  return; /* out of bounds */
  31.  if(y>(scr.bottom-scr.top+1))  return;
  32.  
  33.  scr.current=w[scr.active].attribute;  /* set scr.current to window
  34.                                           attribute */
  35.  width=scr.right-scr.left -x +2;       /* figure width to clear */
  36.  
  37.   for(i=0;i<width;i++) string[i]=' ';  /* build a string of blanks */
  38.   string[i]='\0';                      /* terminate it */
  39.   dma_print (&x,&y,string);            /* print the string but
  40.                                           don't move cursor */
  41.   scr.current= old_current;    /* restore the current attribute */
  42. }
  43.  
  44.  
  45. /*****************************************************************
  46.  
  47.  Usage: void cls();
  48.  
  49.  Clears active window.
  50.  
  51. *****************************************************************/
  52.  
  53. void cls()
  54. {
  55. extern struct  screen_structure scr;
  56. extern struct window_structure w[];
  57. int height;
  58.  
  59.  height=scr.bottom-scr.top +1;
  60.    scroll_up(height+1); /* scrolling up more lines than possible
  61.                            clears the screen */
  62.    gotoxy(1,1);         /* move cursor to "home" position */
  63. }
  64.  
  65.  
  66. /*****************************************************************
  67.  
  68.  Usage: void gotoxy(int x, int y);
  69.  
  70.  x= column (x coordinate)
  71.  y= row    (y coordinate)
  72.  
  73.  Moves cursor to position indicated by x,y.  Movement relative
  74.  to active window.
  75.  
  76.  Numbering starts at 1,1.  ie gotoxy(1,1) moves cursor to upper
  77.  left corner of active window.
  78.  
  79. *****************************************************************/
  80.  
  81. void gotoxy(int x,int y)
  82. {
  83. extern struct  screen_structure scr;
  84. extern struct window_structure w[];
  85.  
  86. union REGS regs;
  87.  
  88.   /* store new cursor in window array */
  89.   w[scr.active].x=x; w[scr.active].y=y;
  90.  
  91.   if(scr.update!= TRUE ) return; /* return if update flag == FALSE */
  92.  
  93.    x=(x-1)+scr.left; /* adjust relative  x,y position */
  94.    y=(y-1)+scr.top;  /* to true "physical screen" co-ordinate */
  95.  
  96.    /* if outside window boundaries, correct */
  97.    if (x<scr.left) x=scr.left;
  98.    if (x>scr.right)
  99.          x=scr.right;
  100.    if (y<scr.top)
  101.          y=scr.top;
  102.    if (y>scr.bottom) y=scr.bottom;
  103.  
  104.     /* perform interrupt */
  105.  
  106.     y--;x--;              /* adjust to BIOS numbering system */
  107.  
  108.    regs.h.ah=2;           /* ah=2, the cursor position function */
  109.    regs.h.dh=y;           /* row */
  110.    regs.h.dl=x;           /* column */
  111.    regs.h.bh=scr.page;    /* page number */
  112.  
  113.    int86(0x10, ®s, ®s);    /* do interrupt */
  114. }
  115.  
  116.  
  117. /*****************************************************************
  118.  
  119.  Usage: void scroll_up (int lines);
  120.  
  121.  n= number of lines to scroll up.
  122.  
  123.  Scrolls the active window up n number of lines.
  124.  
  125. *****************************************************************/
  126.  
  127. void scroll_up(int lines)
  128. {
  129. extern struct  screen_structure scr;
  130. extern struct window_structure w[];
  131.  
  132. int width,height;
  133. int offset;
  134. char far *from;char far *to;
  135. int i,j;
  136. int abs_x,abs_y;
  137. char string[401];   /* big enough for 200-column display */
  138.  
  139.  width=scr.right-scr.left+1;
  140.  height=scr.bottom-scr.top +1;
  141.  
  142.  if(lines<1)return;
  143.  
  144.  abs_x=scr.left-1;   /* figure absolute start of window */
  145.  abs_y=scr.top-1;
  146.  
  147.     offset=( abs_x*2+(abs_y*scr.columns*2) );
  148.  
  149.     /* build a string (with attributes) = width */
  150.     for(i=0;i<=width*2;i+=2){
  151.      string[i]=' ';
  152.      string[i+1]=w[scr.active].attribute;
  153.     }
  154.     string[i-2]='\0';
  155.  
  156.      j=0;               /* starting line */
  157.  
  158.  if(lines<height){
  159.  
  160.  /*
  161.  The following code sets the j pointer to first line of the window
  162.  the second pointer "i" is set equal the number indicated by "lines"
  163.  each line of the window is moved from "i" to "j". This is repeated
  164.  for each line in the window with "i" and "j" incrementing.
  165.  If the call "scroll_up(3); " were made, line 4 would be moved to
  166.  moved to line 1, line 5 to line 2 etc */
  167.  
  168.      for(i=lines;i<=height-1;i++){
  169.       from=scr.buffer+offset+i*scr.columns*2;
  170.       to=scr.buffer+offset+j*scr.columns*2;
  171.         move_scr_mem(from,to,width*2);
  172.       j++;
  173.      }
  174.  }
  175.  
  176. /* clear the left over lines, (if a scroll of 3 lines were made,
  177.    the bottom 3 lines would need to be cleared) */
  178.  
  179.  for(i=j;i<height;i++){
  180.   to=scr.buffer+(offset+i*scr.columns*2);
  181.   move_scr_mem(string,to,width*2);
  182.  }
  183.  
  184.  if(w[scr.active].y >= lines){
  185.   w[scr.active].y=w[scr.active].y-lines;
  186.  } else
  187.   {
  188.    w[scr.active].x=1;
  189.    w[scr.active].y=1;
  190.   }
  191.   display_cursor();
  192. }
  193.  
  194.  
  195. /*****************************************************************
  196.  
  197.  Usage: void scroll_down (int lines);
  198.  
  199.  n= number of lines to scroll up.
  200.  
  201.  Scrolls the active window down n number of lines.
  202.  
  203. *****************************************************************/
  204.  
  205. void scroll_down(int lines)
  206. {
  207. extern struct  screen_structure scr;
  208. extern struct window_structure w[];
  209.  
  210. int width,height;
  211. int offset;
  212. char far *from;char far *to;
  213. int sourc_line,dest_line;
  214. int i;
  215. int abs_x,abs_y;
  216. char string[401];   /* big enough for 200-column display */
  217.  
  218.  width=scr.right-scr.left+1;  /* figure width and height of window */
  219.  height=scr.bottom-scr.top +1;
  220.  
  221.  if(lines<1)return;
  222.  
  223.  abs_x=scr.left-1;   /* figure absolute start of window */
  224.  abs_y=scr.top-1;
  225.  
  226.     offset=( abs_x*2+(abs_y*scr.columns*2) );
  227.  
  228.     /* build a string (with attributes) = width */
  229.     for(i=0;i<=width*2;i+=2){
  230.      string[i]=' ';
  231.      string[i+1]=w[scr.active].attribute;
  232.     }
  233.     string[i-2]='\0';
  234.  
  235.    /* The following works like the code described in scroll_up(), */
  236.    /* except that index pointers move the lines down */
  237.  
  238.    dest_line=height-1;
  239.    if(lines<height){
  240.  
  241.      for(sourc_line=height-1-lines;sourc_line>=0;sourc_line--){
  242.       from=scr.buffer+offset+sourc_line*scr.columns*2;
  243.       to=scr.buffer+offset+dest_line*scr.columns*2;
  244.         move_scr_mem(from,to,width*2);
  245.       dest_line--;
  246.      }
  247.     }
  248.  
  249.  for(sourc_line=dest_line;sourc_line>=0;sourc_line--){
  250.   to=scr.buffer+(offset+sourc_line*scr.columns*2);
  251.  
  252.   move_scr_mem(string,to,width*2);
  253.  }
  254.  
  255.  if(w[scr.active].y >= lines){
  256.   w[scr.active].y+= lines;         /*  =w[scr.active].y-lines;*/
  257.  } else
  258.  {
  259.   w[scr.active].y=height;
  260.  }
  261.   display_cursor();
  262. }
  263.  
  264.  
  265. /*****************************************************************
  266.  
  267.  Usage: void set_mode(int mode)
  268.  
  269.  Sets video mode.
  270.  
  271. *****************************************************************/
  272.  
  273. void set_mode(int mode)
  274. {
  275. extern struct  screen_structure scr;
  276. extern struct window_structure w[];
  277.  
  278.    union REGS regs;
  279.  
  280.    regs.h.ah= 0;         /* set video state function */
  281.    regs.h.al=mode;       /* mode to set */
  282.  
  283.     int86(0x10, ®s,®s);  /* do interrupt */
  284.     scr.mode=mode;             /* update external variable */
  285. }
  286.  
  287.  
  288. /*****************************************************************
  289.  
  290.  Usage: void what_mode(int *mode,int *page);
  291.  
  292.  Call with address of mode and page "what_mode(&mode,&page);"
  293.  
  294.  Sets mode and page variables to actual mode and page.
  295.  
  296.  Defines for mode are found in "mydef.h".
  297.  
  298. *****************************************************************/
  299.  
  300.  
  301. void what_mode(int *mode,int *page)
  302. {
  303.    union REGS regs;
  304.  
  305.    regs.h.ah= 15;         /* return video state function */
  306.  
  307.     int86(0x10, ®s,®s);  /* do interrupt */
  308.  
  309.    *mode= regs.h.al;   /* set mode */
  310.    *page= regs.h.bh;   /* set page */
  311. }
  312.