home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d8xx / d832 / term.lha / Term / term-3.1-Source.lha / termScroll.c < prev    next >
C/C++ Source or Header  |  1993-01-04  |  21KB  |  942 lines

  1. /*
  2. **    termScroll.c
  3. **
  4. **    Support routines for optimized screen scrolling.
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12.     /* ScrollLineRectFill():
  13.      *
  14.      *    Fill a rectangular portion of the window raster with the help
  15.      *    of the scrolling information.
  16.      */
  17.  
  18. VOID __regargs
  19. ScrollLineRectFill(struct RastPort *RPort,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY)
  20. {
  21.     if(RPort -> BitMap -> Depth > 1)
  22.     {
  23.         if(MinX < MaxX)
  24.         {
  25.                 /* Is there anything on the screen at all? */
  26.  
  27.             if(ScrollLineFirst <= ScrollLineLast)
  28.             {
  29.                 if(UseMasking)
  30.                 {
  31.                     WORD    ScrollLineMask    = 0,
  32.                         ScrollLineLeft    = 32767,
  33.                         ScrollLineRight    = 0,
  34.                         Temp,
  35.                         i;
  36.  
  37.                         /* Determine screen colour mask. */
  38.  
  39.                     for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  40.                     {
  41.                         if(ScrollLines[i] . Width)
  42.                         {
  43.                             if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  44.                                 ScrollLineLeft = Temp;
  45.  
  46.                             if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  47.                                 ScrollLineRight = Temp;
  48.  
  49.                             ScrollLineMask |= ScrollLines[i] . ColourMask;
  50.                         }
  51.                     }
  52.  
  53.                         /* Wrap the bits. */
  54.  
  55.                     ScrollLineMask &= DepthMask;
  56.  
  57.                         /* Did we get a sensible colour? */
  58.  
  59.                     if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
  60.                     {
  61.                             /* Determine new left margin. */
  62.  
  63.                         if(ScrollLineLeft > MinX)
  64.                             MinX = ScrollLineLeft;
  65.  
  66.                             /* Determine new right margin. */
  67.  
  68.                         if(ScrollLineRight < MaxX)
  69.                             MaxX = ScrollLineRight;
  70.  
  71.                             /* Determine new top line margin. */
  72.  
  73.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  74.                             MinY = Temp;
  75.  
  76.                             /* Determine new bottom line margin. */
  77.  
  78.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  79.                             MaxY = Temp;
  80.  
  81.                             /* Set the colour mask. */
  82.  
  83.                         SetWrMsk(RPort,ScrollLineMask);
  84.  
  85.                             /* Add margin for italics or boldface. */
  86.  
  87.                         if(MaxX == ScrollLineRight)
  88.                         {
  89.                             MaxX += 4;
  90.  
  91.                             if(MaxX > LastPixel)
  92.                                 MaxX = LastPixel;
  93.                         }
  94.                     }
  95.                 }
  96.                 else
  97.                 {
  98.                     WORD    ScrollLineLeft    = 32767,
  99.                         ScrollLineRight    = 0,
  100.                         Temp,
  101.                         i;
  102.  
  103.                         /* Determine screen colour mask. */
  104.  
  105.                     for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  106.                     {
  107.                         if(ScrollLines[i] . Width)
  108.                         {
  109.                             if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  110.                                 ScrollLineLeft = Temp;
  111.  
  112.                             if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  113.                                 ScrollLineRight = Temp;
  114.                         }
  115.                     }
  116.  
  117.                         /* Did we get a sensible colour? */
  118.  
  119.                     if(ScrollLineLeft <= ScrollLineRight)
  120.                     {
  121.                             /* Determine new left margin. */
  122.  
  123.                         if(ScrollLineLeft > MinX)
  124.                             MinX = ScrollLineLeft;
  125.  
  126.                             /* Determine new right margin. */
  127.  
  128.                         if(ScrollLineRight < MaxX)
  129.                             MaxX = ScrollLineRight;
  130.  
  131.                             /* Determine new top line margin. */
  132.  
  133.                         if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  134.                             MinY = Temp;
  135.  
  136.                             /* Determine new bottom line margin. */
  137.  
  138.                         if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  139.                             MaxY = Temp;
  140.  
  141.                             /* Add margin for italics or boldface. */
  142.  
  143.                         if(MaxX == ScrollLineRight)
  144.                         {
  145.                             MaxX += 4;
  146.  
  147.                             if(MaxX > LastPixel)
  148.                                 MaxX = LastPixel;
  149.                         }
  150.                     }
  151.                 }
  152.             }
  153.         }
  154.     }
  155.  
  156.         /* And clear the raster. */
  157.  
  158.     if(MinX < MaxX && MinY < MaxY)
  159.         RectFill(RPort,WindowLeft + MinX,WindowTop + MinY,WindowLeft + MaxX,WindowTop + MaxY);
  160. }
  161.  
  162.     /* ScrollLineRaster():
  163.      *
  164.      *    Scroll the window raster with the help
  165.      *    of the scrolling information.
  166.      */
  167.  
  168. VOID __regargs
  169. ScrollLineRaster(struct RastPort *RPort,WORD DeltaX,WORD DeltaY,WORD MinX,WORD MinY,WORD MaxX,WORD MaxY,BYTE Smooth)
  170. {
  171.     if(RPort -> BitMap -> Depth > 1)
  172.     {
  173.         if(MinX < MaxX)
  174.         {
  175.             if(UseMasking)
  176.             {
  177.                 WORD ScrollLineMask;
  178.  
  179.                     /* Are we to scroll a line in horizontal direction? If so, use the
  180.                      * colour mask of the current line.
  181.                      */
  182.  
  183.                 if(DeltaX)
  184.                 {
  185.                         /* Set the colour mask. */
  186.  
  187.                     if(ScrollLineMask = ScrollLines[CursorY] . ColourMask & DepthMask)
  188.                         SetWrMsk(RPort,ScrollLineMask);
  189.                 }
  190.                 else
  191.                 {
  192.                         /* Any data on screen worth scrolling? */
  193.  
  194.                     if(ScrollLineFirst <= ScrollLineLast)
  195.                     {
  196.                         WORD Temp,First,Last,SaveMinY = MinY / TextFontHeight,SaveMaxY = MaxY / TextFontHeight,ScrollLineLeft = 32767,ScrollLineRight = 0,i;
  197.  
  198.                             /* Reset colourmask. */
  199.  
  200.                         ScrollLineMask = 0;
  201.  
  202.                             /* Build both the colour mask and the margins. */
  203.  
  204.                         for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  205.                         {
  206.                             if(ScrollLines[i] . Width)
  207.                             {
  208.                                 if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  209.                                     ScrollLineLeft = Temp;
  210.  
  211.                                 if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  212.                                     ScrollLineRight = Temp;
  213.  
  214.                                 ScrollLineMask |= ScrollLines[i] . ColourMask;
  215.                             }
  216.                         }
  217.  
  218.                             /* Wrap the bits. */
  219.  
  220.                         ScrollLineMask &= DepthMask;
  221.  
  222.                             /* Sensible results? */
  223.  
  224.                         if(ScrollLineMask && ScrollLineLeft <= ScrollLineRight)
  225.                         {
  226.                                 /* Determine new left margin. */
  227.  
  228.                             if(ScrollLineLeft > MinX)
  229.                                 MinX = ScrollLineLeft;
  230.  
  231.                                 /* Determine new right margin. */
  232.  
  233.                             if(ScrollLineRight < MaxX)
  234.                                 MaxX = ScrollLineRight;
  235.  
  236.                                 /* Scroll down or up? */
  237.  
  238.                             if(DeltaY < 0)
  239.                             {
  240.                                     /* So we are to scroll down, find the first
  241.                                      * blank line if any.
  242.                                      */
  243.  
  244.                                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  245.                                     MinY = Temp;
  246.  
  247.                                     /* Find the last blank lines if any. */
  248.  
  249.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - DeltaY - 1) < MaxY)
  250.                                     MaxY = Temp;
  251.  
  252.                                     /* Determine margins and the like... */
  253.  
  254.                                 Last    = (MaxY + 1) / TextFontHeight;
  255.                                 First    = Last - ((MaxY - MinY + TextFontHeight + DeltaY) / TextFontHeight);
  256.                                 Temp    = (-DeltaY) / TextFontHeight;
  257.  
  258.                                     /* Move the scroll line info up. */
  259.  
  260.                                 for(i = Last - 1 ; i >= First ; i--)
  261.                                     ScrollLines[i] = ScrollLines[i - Temp];
  262.  
  263.                                     /* Clear the remaining lines. */
  264.  
  265.                                 for(i = First - Temp ; i < First ; i++)
  266.                                 {
  267.                                     ScrollLines[i] . Left        = 32767;
  268.                                     ScrollLines[i] . Right        = 0;
  269.                                     ScrollLines[i] . ColourMask    = 0;
  270.                                     ScrollLines[i] . Width        = 0;
  271.                                 }
  272.  
  273.                                     /* Is the first line we were working
  274.                                      * on the first line of the whole display?
  275.                                      * If so, update the line marker.
  276.                                      */
  277.  
  278.                                 if(!SaveMinY)
  279.                                     ScrollLineFirst += Temp;
  280.  
  281.                                     /* Now take a look at the last line.
  282.                                      * If the last line we were working
  283.                                      * on is in fact the last line of the
  284.                                      * display, update the line marker.
  285.                                      */
  286.  
  287.                                 if(SaveMaxY == LastLine)
  288.                                 {
  289.                                     ScrollLineLast += Temp;
  290.  
  291.                                     if(ScrollLineLast > LastLine)
  292.                                         ScrollLineLast = LastLine;
  293.                                 }
  294.                             }
  295.                             else
  296.                             {
  297.                                     /* So we are to scroll up, find the last
  298.                                      * blank line if any.
  299.                                      */
  300.  
  301.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  302.                                     MaxY = Temp;
  303.  
  304.                                     /* Find the first blank lines if any. */
  305.  
  306.                                 if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  307.                                     MinY = Temp;
  308.  
  309.                                     /* Determine margins and the like... */
  310.  
  311.                                 First    = MinY / TextFontHeight;
  312.                                 Last    = ((MaxY - MinY + TextFontHeight - DeltaY) / TextFontHeight);
  313.                                 Temp    = DeltaY / TextFontHeight;
  314.  
  315.                                     /* Move the scroll line info down. */
  316.  
  317.                                 for(i = First ; i < First + Last ; i++)
  318.                                     ScrollLines[i] = ScrollLines[i + Temp];
  319.  
  320.                                     /* Clear the remaining lines. */
  321.  
  322.                                 for(i = First + Last ; i < First + Last + Temp ; i++)
  323.                                 {
  324.                                     ScrollLines[i] . Left        = 32767;
  325.                                     ScrollLines[i] . Right        = 0;
  326.                                     ScrollLines[i] . ColourMask    = 0;
  327.                                     ScrollLines[i] . Width        = 0;
  328.                                 }
  329.  
  330.                                     /* Decrease number of last line. */
  331.  
  332.                                 if(SaveMaxY == LastLine)
  333.                                 {
  334.                                     if(ScrollLineLast > Temp)
  335.                                         ScrollLineLast -= Temp;
  336.                                     else
  337.                                         ScrollLineLast = 0;
  338.                                 }
  339.  
  340.                                     /* Decrease number of first line. */
  341.  
  342.                                 if(!SaveMinY)
  343.                                 {
  344.                                     if(ScrollLineFirst > Temp)
  345.                                         ScrollLineFirst -= Temp;
  346.                                     else
  347.                                         ScrollLineFirst = 0;
  348.                                 }
  349.                             }
  350.  
  351.                                 /* Adapt possible changes in the lines for first and last line. */
  352.  
  353.                             while(ScrollLineFirst < RasterHeight)
  354.                             {
  355.                                 if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  356.                                     ScrollLineFirst++;
  357.                                 else
  358.                                     break;
  359.                             }
  360.  
  361.                             while(ScrollLineLast > 0)
  362.                             {
  363.                                 if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  364.                                     ScrollLineLast--;
  365.                                 else
  366.                                     break;
  367.                             }
  368.  
  369.                                 /* Set the colour mask. */
  370.  
  371.                             SetWrMsk(RPort,ScrollLineMask);
  372.  
  373.                                 /* Add margin for italics or boldface. */
  374.  
  375.                             if(MaxX == ScrollLineRight)
  376.                             {
  377.                                 MaxX += 4;
  378.  
  379.                                 if(MaxX > LastPixel)
  380.                                     MaxX = LastPixel;
  381.                             }
  382.                         }
  383.                     }
  384.                 }
  385.             }
  386.             else
  387.             {
  388.                     /* Are we to scroll a line in horizontal direction? If so, use the
  389.                      * colour mask of the current line.
  390.                      */
  391.  
  392.                 if(!DeltaX)
  393.                 {
  394.                         /* Any data on screen worth scrolling? */
  395.  
  396.                     if(ScrollLineFirst <= ScrollLineLast)
  397.                     {
  398.                         WORD Temp,First,Last,SaveMinY = MinY / TextFontHeight,SaveMaxY = MaxY / TextFontHeight,ScrollLineLeft = 32767,ScrollLineRight = 0,i;
  399.  
  400.                             /* Build both the colour mask and the margins. */
  401.  
  402.                         for(i = MinY / TextFontHeight ; i <= MaxY / TextFontHeight ; i++)
  403.                         {
  404.                             if(ScrollLines[i] . Width)
  405.                             {
  406.                                 if((Temp = ScrollLines[i] . Left * ScrollLines[i] . Width) < ScrollLineLeft)
  407.                                     ScrollLineLeft = Temp;
  408.  
  409.                                 if((Temp = (ScrollLines[i] . Right * ScrollLines[i] . Width) - 1) > ScrollLineRight)
  410.                                     ScrollLineRight = Temp;
  411.                             }
  412.                         }
  413.  
  414.                             /* Sensible results? */
  415.  
  416.                         if(ScrollLineLeft <= ScrollLineRight)
  417.                         {
  418.                                 /* Determine new left margin. */
  419.  
  420.                             if(ScrollLineLeft > MinX)
  421.                                 MinX = ScrollLineLeft;
  422.  
  423.                                 /* Determine new right margin. */
  424.  
  425.                             if(ScrollLineRight < MaxX)
  426.                                 MaxX = ScrollLineRight;
  427.  
  428.                                 /* Scroll down or up? */
  429.  
  430.                             if(DeltaY < 0)
  431.                             {
  432.                                     /* So we are to scroll down, find the first
  433.                                      * blank line if any.
  434.                                      */
  435.  
  436.                                 if((Temp = MUL_Y(ScrollLineFirst)) > MinY)
  437.                                     MinY = Temp;
  438.  
  439.                                     /* Find the last blank lines if any. */
  440.  
  441.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - DeltaY - 1) < MaxY)
  442.                                     MaxY = Temp;
  443.  
  444.                                     /* Determine margins and the like... */
  445.  
  446.                                 Last    = (MaxY + 1) / TextFontHeight;
  447.                                 First    = Last - ((MaxY - MinY + TextFontHeight + DeltaY) / TextFontHeight);
  448.                                 Temp    = (-DeltaY) / TextFontHeight;
  449.  
  450.                                     /* Move the scroll line info up. */
  451.  
  452.                                 for(i = Last - 1 ; i >= First ; i--)
  453.                                     ScrollLines[i] = ScrollLines[i - Temp];
  454.  
  455.                                     /* Clear the remaining lines. */
  456.  
  457.                                 for(i = First - Temp ; i < First ; i++)
  458.                                 {
  459.                                     ScrollLines[i] . Left        = 32767;
  460.                                     ScrollLines[i] . Right        = 0;
  461.                                     ScrollLines[i] . Width        = 0;
  462.                                 }
  463.  
  464.                                     /* Is the first line we were working
  465.                                      * on the first line of the whole display?
  466.                                      * If so, update the line marker.
  467.                                      */
  468.  
  469.                                 if(!SaveMinY)
  470.                                     ScrollLineFirst += Temp;
  471.  
  472.                                     /* Now take a look at the last line.
  473.                                      * If the last line we were working
  474.                                      * on is in fact the last line of the
  475.                                      * display, update the line marker.
  476.                                      */
  477.  
  478.                                 if(SaveMaxY == LastLine)
  479.                                 {
  480.                                     ScrollLineLast += Temp;
  481.  
  482.                                     if(ScrollLineLast > LastLine)
  483.                                         ScrollLineLast = LastLine;
  484.                                 }
  485.                             }
  486.                             else
  487.                             {
  488.                                     /* So we are to scroll up, find the last
  489.                                      * blank line if any.
  490.                                      */
  491.  
  492.                                 if((Temp = MUL_Y(ScrollLineLast + 1) - 1) < MaxY)
  493.                                     MaxY = Temp;
  494.  
  495.                                     /* Find the first blank lines if any. */
  496.  
  497.                                 if((Temp = MUL_Y(ScrollLineFirst) - DeltaY) > MinY)
  498.                                     MinY = Temp;
  499.  
  500.                                     /* Determine margins and the like... */
  501.  
  502.                                 First    = MinY / TextFontHeight;
  503.                                 Last    = ((MaxY - MinY + TextFontHeight - DeltaY) / TextFontHeight);
  504.                                 Temp    = DeltaY / TextFontHeight;
  505.  
  506.                                     /* Move the scroll line info down. */
  507.  
  508.                                 for(i = First ; i < First + Last ; i++)
  509.                                     ScrollLines[i] = ScrollLines[i + Temp];
  510.  
  511.                                     /* Clear the remaining lines. */
  512.  
  513.                                 for(i = First + Last ; i < First + Last + Temp ; i++)
  514.                                 {
  515.                                     ScrollLines[i] . Left        = 32767;
  516.                                     ScrollLines[i] . Right        = 0;
  517.                                     ScrollLines[i] . Width        = 0;
  518.                                 }
  519.  
  520.                                     /* Decrease number of last line. */
  521.  
  522.                                 if(SaveMaxY == LastLine)
  523.                                 {
  524.                                     if(ScrollLineLast > Temp)
  525.                                         ScrollLineLast -= Temp;
  526.                                     else
  527.                                         ScrollLineLast = 0;
  528.                                 }
  529.  
  530.                                     /* Decrease number of first line. */
  531.  
  532.                                 if(!SaveMinY)
  533.                                 {
  534.                                     if(ScrollLineFirst > Temp)
  535.                                         ScrollLineFirst -= Temp;
  536.                                     else
  537.                                         ScrollLineFirst = 0;
  538.                                 }
  539.                             }
  540.  
  541.                                 /* Adapt possible changes in the lines for first and last line. */
  542.  
  543.                             while(ScrollLineFirst < RasterHeight)
  544.                             {
  545.                                 if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  546.                                     ScrollLineFirst++;
  547.                                 else
  548.                                     break;
  549.                             }
  550.  
  551.                             while(ScrollLineLast > 0)
  552.                             {
  553.                                 if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  554.                                     ScrollLineLast--;
  555.                                 else
  556.                                     break;
  557.                             }
  558.  
  559.                                 /* Add margin for italics or boldface. */
  560.  
  561.                             if(MaxX == ScrollLineRight)
  562.                             {
  563.                                 MaxX += 4;
  564.  
  565.                                 if(MaxX > LastPixel)
  566.                                     MaxX = LastPixel;
  567.                             }
  568.                         }
  569.                     }
  570.                 }
  571.             }
  572.         }
  573.     }
  574.  
  575.         /* And scroll the raster. */
  576.  
  577.     if(MinX < MaxX && MinY < MaxY)
  578.     {
  579.         MinX += WindowLeft;
  580.         MaxX += WindowLeft;
  581.  
  582.         MinY += WindowTop;
  583.         MaxY += WindowTop;
  584.  
  585.         if(Smooth && DeltaY)
  586.         {
  587.             WORD Lines = DeltaY / 2;
  588.  
  589.             if(Lines > 0)
  590.             {
  591.                 while(Lines--)
  592.                 {
  593.                     WaitTOF();
  594.  
  595.                     ScrollRaster(RPort,0,2,MinX,MinY,MaxX,MaxY);
  596.                 }
  597.             }
  598.             else
  599.             {
  600.                 while(Lines++)
  601.                 {
  602.                     WaitTOF();
  603.  
  604.                     ScrollRaster(RPort,0,-2,MinX,MinY,MaxX,MaxY);
  605.                 }
  606.             }
  607.         }
  608.         else
  609.             ScrollRaster(RPort,DeltaX,DeltaY,MinX,MinY,MaxX,MaxY);
  610.     }
  611. }
  612.  
  613.     /* ScrollLineEraseScreen(BYTE Mode):
  614.      *
  615.      *    Erase a part of the screen.
  616.      */
  617.  
  618. VOID __regargs
  619. ScrollLineEraseScreen(BYTE Mode)
  620. {
  621.     if(RPort -> BitMap -> Depth > 1)
  622.     {
  623.         WORD i;
  624.  
  625.         switch(Mode)
  626.         {
  627.                 /* Erase from first line to current cursor line (inclusive). */
  628.  
  629.             case 1:    ScrollLineFirst = CursorY;
  630.  
  631.                     /* Reset the lines. */
  632.  
  633.                 for(i = 0 ; i < CursorY ; i++)
  634.                 {
  635.                     ScrollLines[i] . Left        = 32767;
  636.                     ScrollLines[i] . Right        = 0;
  637.                     ScrollLines[i] . ColourMask    = 0;
  638.                     ScrollLines[i] . Width        = 0;
  639.                 }
  640.  
  641.                 ScrollLines[CursorY] . Left = CursorX + 1;
  642.  
  643.                 if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
  644.                 {
  645.                     ScrollLines[CursorY] . Left    = 32767;
  646.                     ScrollLines[CursorY] . Right    = 0;
  647.                 }
  648.  
  649.                 break;
  650.  
  651.                 /* Erase entire screen. */
  652.  
  653.             case 2:    for(i = 0 ; i < RasterHeight ; i++)
  654.                 {
  655.                     ScrollLines[i] . Left        = 32767;
  656.                     ScrollLines[i] . Right        = 0;
  657.                     ScrollLines[i] . ColourMask    = 0;
  658.                     ScrollLines[i] . Width        = 0;
  659.                 }
  660.  
  661.                 ScrollLineFirst    = 32767;
  662.                 ScrollLineLast    = 0;
  663.  
  664.                 break;
  665.  
  666.                 /* Erase from current cursor position to end of screen. */
  667.  
  668.             default:for(i = CursorY + 1 ; i < RasterHeight ; i++)
  669.                 {
  670.                     ScrollLines[i] . Left        = 32767;
  671.                     ScrollLines[i] . Right        = 0;
  672.                     ScrollLines[i] . ColourMask    = 0;
  673.                     ScrollLines[i] . Width        = 0;
  674.                 }
  675.  
  676.                 if(CursorX)
  677.                 {
  678.                     ScrollLines[CursorY] . Right = CursorX;
  679.  
  680.                     if(ScrollLines[CursorY] . Right < ScrollLines[CursorY] . Left)
  681.                     {
  682.                         ScrollLines[CursorY] . Left    = 32767;
  683.                         ScrollLines[CursorY] . Right    = 0;
  684.                     }
  685.                 }
  686.                 else
  687.                 {
  688.                     ScrollLines[CursorY] . Left    = 32767;
  689.                     ScrollLines[CursorY] . Right    = 0;
  690.                 }
  691.  
  692.                     /* Cleared the entire screen? */
  693.  
  694.                 if(CursorY)
  695.                     ScrollLineLast = CursorY;
  696.                 else
  697.                 {
  698.                     ScrollLineFirst    = 32767;
  699.                     ScrollLineLast    = 0;
  700.                 }
  701.  
  702.                 break;
  703.         }
  704.  
  705.             /* Adapt possible changes in the lines for first and last line. */
  706.  
  707.         while(ScrollLineFirst < RasterHeight)
  708.         {
  709.             if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  710.                 ScrollLineFirst++;
  711.             else
  712.                 break;
  713.         }
  714.  
  715.         while(ScrollLineLast > 0)
  716.         {
  717.             if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  718.                 ScrollLineLast--;
  719.             else
  720.                 break;
  721.         }
  722.     }
  723. }
  724.  
  725.     /* ScrollLineEraseLine(BYTE Mode):
  726.      *
  727.      *    Erase parts of the current cursor line.
  728.      */
  729.  
  730. VOID __regargs
  731. ScrollLineEraseLine(BYTE Mode)
  732. {
  733.     if(RPort -> BitMap -> Depth > 1)
  734.     {
  735.         switch(Mode)
  736.         {
  737.                 /* Erase from left margin to current cursor position (inclusive). */
  738.  
  739.             case 1:    ScrollLines[CursorY] . Left = CursorX + 1;
  740.                 break;
  741.  
  742.                 /* Erase entire line. */
  743.  
  744.             case 2:    ScrollLines[CursorY] . Left    = 32767;
  745.                 ScrollLines[CursorY] . Right    = 0;
  746.  
  747.                 break;
  748.  
  749.                 /* Erase from current cursor position towards end of line. */
  750.  
  751.             default:if(CursorX)
  752.                     ScrollLines[CursorY] . Right = CursorX;
  753.                 else
  754.                 {
  755.                     ScrollLines[CursorY] . Left    = 32767;
  756.                     ScrollLines[CursorY] . Right    = 0;
  757.                 }
  758.  
  759.                 break;
  760.         }
  761.  
  762.             /* Adapt possible changes in the lines for first and last line. */
  763.  
  764.         while(ScrollLineFirst < RasterHeight)
  765.         {
  766.             if(ScrollLines[ScrollLineFirst] . Left > ScrollLines[ScrollLineFirst] . Right)
  767.                 ScrollLineFirst++;
  768.             else
  769.                 break;
  770.         }
  771.  
  772.         while(ScrollLineLast > 0)
  773.         {
  774.             if(ScrollLines[ScrollLineLast] . Left > ScrollLines[ScrollLineLast] . Right)
  775.                 ScrollLineLast--;
  776.             else
  777.                 break;
  778.         }
  779.     }
  780. }
  781.  
  782.     /* ScrollLineEraseCharacters(WORD Chars):
  783.      *
  784.      *    Erase a number of characters in the current cursor line.
  785.      */
  786.  
  787. VOID __regargs
  788. ScrollLineEraseCharacters(WORD Chars)
  789. {
  790.     if(RPort -> BitMap -> Depth > 1)
  791.     {
  792.             /* Any characters to erase? */
  793.  
  794.         if(ScrollLines[CursorY] . Right)
  795.             ScrollLines[CursorY] . Right -= Chars;
  796.     }
  797. }
  798.  
  799.     /* ScrollLineShiftChar(WORD Size):
  800.      *
  801.      *    Shift the characters following the current cursor position
  802.      *    Size characters to the right.
  803.      */
  804.  
  805. VOID __regargs
  806. ScrollLineShiftChar(WORD Size)
  807. {
  808.     if(RPort -> BitMap -> Depth > 1)
  809.     {
  810.             /* Any characters to scroll? */
  811.  
  812.         if(ScrollLines[CursorY] . Right > 0)
  813.             ScrollLines[CursorY] . Right += Size;
  814.     }
  815. }
  816.  
  817.     /* ScrollLinePutString(WORD Length):
  818.      *
  819.      *    Update the line info according to the length of a string
  820.      *    to be printed.
  821.      */
  822.  
  823. VOID __regargs
  824. ScrollLinePutString(WORD Length)
  825. {
  826.     if(RPort -> BitMap -> Depth > 1)
  827.     {
  828.         LONG Width;
  829.  
  830.             /* Which scale is the font we are currently using? */
  831.  
  832.         if(RasterAttr[CursorY] >= SCALE_ATTR_TOP2X)
  833.         {
  834.                 /* Valid length? */
  835.  
  836.             if(CursorX + Length >= RasterWidth / 2)
  837.                 Length = (RasterWidth / 2) - CursorX;
  838.  
  839.                 /* Double width. */
  840.  
  841.             Width = TextFontWidth * 2;
  842.         }
  843.         else
  844.         {
  845.             if(Config -> EmulationConfig -> FontScale == SCALE_HALF)
  846.             {
  847.                     /* Valid length? */
  848.  
  849.                 if(CursorX + Length >= RasterWidth * 2)
  850.                     Length = (RasterWidth * 2) - CursorX;
  851.  
  852.                     /* Half width. */
  853.  
  854.                 Width = TextFontWidth / 2;
  855.             }
  856.             else
  857.             {
  858.                     /* Valid length? */
  859.  
  860.                 if(CursorX + Length >= RasterWidth)
  861.                     Length = RasterWidth - CursorX;
  862.  
  863.                     /* Normal width. */
  864.  
  865.                 Width = TextFontWidth;
  866.             }
  867.         }
  868.  
  869.             /* Sensible value? */
  870.  
  871.         if(Length > 0)
  872.         {
  873.             if(UseMasking)
  874.             {
  875.                 struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
  876.  
  877.                     /* Update line colour mask. */
  878.  
  879.                 Alias -> ColourMask |= ReadAPen(RPort) | ReadBPen(RPort);
  880.  
  881.                     /* Update font scale. */
  882.  
  883.                 Alias -> Width = Width;
  884.  
  885.                     /* Set write mask (will affect Text() since it is called
  886.                      * after this routine has finished.
  887.                      */
  888.  
  889.                 SetWrMsk(RPort,Alias -> ColourMask);
  890.  
  891.                     /* Update right margin. */
  892.  
  893.                 if(CursorX < Alias -> Left)
  894.                     Alias -> Left = CursorX;
  895.  
  896.                     /* Update left margin. */
  897.  
  898.                 if(CursorX + Length > Alias -> Right)
  899.                     Alias -> Right = CursorX + Length;
  900.  
  901.                     /* Update topmost line. */
  902.  
  903.                 if(CursorY < ScrollLineFirst)
  904.                     ScrollLineFirst = CursorY;
  905.  
  906.                     /* Update bottommost line. */
  907.  
  908.                 if(CursorY > ScrollLineLast)
  909.                     ScrollLineLast = CursorY;
  910.             }
  911.             else
  912.             {
  913.                 struct ScrollLineInfo *Alias = &ScrollLines[CursorY];
  914.  
  915.                     /* Update font scale. */
  916.  
  917.                 Alias -> Width = Width;
  918.  
  919.                     /* Update right margin. */
  920.  
  921.                 if(CursorX < Alias -> Left)
  922.                     Alias -> Left = CursorX;
  923.  
  924.                     /* Update left margin. */
  925.  
  926.                 if(CursorX + Length > Alias -> Right)
  927.                     Alias -> Right = CursorX + Length;
  928.  
  929.                     /* Update topmost line. */
  930.  
  931.                 if(CursorY < ScrollLineFirst)
  932.                     ScrollLineFirst = CursorY;
  933.  
  934.                     /* Update bottommost line. */
  935.  
  936.                 if(CursorY > ScrollLineLast)
  937.                     ScrollLineLast = CursorY;
  938.             }
  939.         }
  940.     }
  941. }
  942.