home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / pcw_c.zip / SCROLL.C < prev    next >
Text File  |  1990-01-16  |  4KB  |  78 lines

  1. /**********************************************************/
  2. /* File Id.                  Scroll.C                     */
  3. /* Author.                   Stan Milam.                  */
  4. /* Date Started.             05/23/89.                    */
  5. /*                                                        */
  6. /*           (c) Copyright 1989-90 by Stan Milam          */
  7. /*                                                        */
  8. /* Purpose: To scroll a text window anywhere on the screen*/
  9. /* without causing flicker on the CGA and to do it very   */
  10. /* very fast on MDA, EGA, and VGA.  Can scroll the window */
  11. /* up or down.                                            */
  12. /**********************************************************/
  13.  
  14. #include <stdio.h>
  15. #include <dos.h>
  16. #include "pcwproto.h"
  17. #include "pcw.i"
  18.  
  19. int scroll(int ur,int uc,int lr,int lc,int fg,int bg,int count) {
  20.  
  21.    int far *source, far *dest, far *line;
  22.    int rows, cols, page, pagesize;
  23.    int cl, rw, attr, dir;
  24.    unsigned offset, scrnseg;
  25.  
  26.    if (!chk_video_state(&rw, &cl)) return(0);    /* Not a valid text mode */
  27.    if (count == 0) return(1);                    /* Fake good return */
  28.    if (count > 0) dir = DOWN;
  29.    else {
  30.      dir = UP;
  31.      count = -count;
  32.    }
  33.  
  34.    if (lc > cl) {
  35.       cl = lc - cl;                              /* Adjust cooridnates */
  36.       lc = lc - cl;
  37.       uc = uc - cl;
  38.    }
  39.    if (uc < 1) return(0);                        /* Could not adjust */
  40.  
  41.    if (lr > rw) {                                /* Adjust y coords */
  42.       rw -= lr;
  43.       lr -= rw;
  44.       ur -= rw;
  45.    }
  46.    if (ur < 1) return(0);                        /* Could not adjust */
  47.  
  48.    rows = (lr - ur) + 1;                         /* Compute total rows */
  49.    cols = (lc - uc) + 1;                         /* And columns */
  50.    pagesize = getpagesize();                     /* Get regen length */
  51.    scrnseg  = getscrnseg();                      /* Get video segment */
  52.    page     = getpage();                         /* Video Page we're using */
  53.  
  54.    if (dir) {                                   /* Going up */
  55.       offset = MK_SCRNOFF(ur+1,uc);             /* offset of source*/
  56.       source = (int far *)MK_FP(scrnseg,offset);/* Make source pointer */
  57.       offset = MK_SCRNOFF(ur, uc);              /* Offset of destination */
  58.       dest   = (int far *)MK_FP(scrnseg,offset);/* Make destination pointer */
  59.       cl     = lr;                              /* Row to clear */
  60.    }
  61.    else {                                       /* Going down */
  62.       offset = MK_SCRNOFF(lr-1,uc);             /* Make source offset */
  63.       source = (int far *)MK_FP(scrnseg,offset);/* Make source pointer */
  64.       offset = MK_SCRNOFF(lr,uc);               /* Make destination offset */
  65.       dest   = (int far *)MK_FP(scrnseg,offset);/* Make destination pointer */
  66.       cl     = ur;                              /* Row to clear */
  67.    }
  68.  
  69.    offset = MK_SCRNOFF(cl,uc);                  /* Offset of line to clear */
  70.    attr   = MK_ATTR(fg,bg) | 32;                /* Char & attr of line */
  71.    line   = (int far *)MK_FP(scrnseg,offset);   /* Make the pointer */
  72.    do {                                         /* Repeat until done */
  73.      Tscroll(source,dest,rows-1,cols,dir);      /* Call Assembler routine */
  74.      Thorzchar(cols,attr,line);                 /* Asm routine to clear */
  75.    } while(--count);                            /* Decrement & compare */
  76.    return(1);                                   /* Return good return code */
  77. }
  78.