home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 500-599 / ff589.lza / Term / TermSrc.lha / ParseRoutines.c < prev    next >
C/C++ Source or Header  |  1991-12-08  |  27KB  |  1,785 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: ParseRoutines.c
  6.  *    Created ..: Monday 21-Jan-91 20:12
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    21-Jan-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17.     /* Flag indicating whether the cursor has already been
  18.      * erased or not.
  19.      */
  20.  
  21. STATIC BYTE CursorEnabled = FALSE;
  22.  
  23.     /* Global string buffer and backup style. */
  24.  
  25. STATIC UBYTE GlobalBuffer[20],StyleType = FS_NORMAL;
  26.  
  27.     /* ClearCursor():
  28.      *
  29.      *    Clear the cursor image.
  30.      */
  31.  
  32. VOID
  33. ClearCursor()
  34. {
  35.     if(CursorEnabled)
  36.     {
  37.         ClipBlitCursor(TRUE,FALSE);
  38.  
  39.         CursorEnabled = FALSE;
  40.     }
  41. }
  42.  
  43.     /* DrawCursor():
  44.      *
  45.      *    Explicitely (re-)draw the cursor image.
  46.      */
  47.  
  48. VOID
  49. DrawCursor()
  50. {
  51.     if(!CursorEnabled)
  52.     {
  53.         ClipBlitCursor(TRUE,FALSE);
  54.  
  55.         CursorEnabled = TRUE;
  56.     }
  57. }
  58.  
  59. VOID
  60. ClipBlitCursor(UBYTE DoClip,UBYTE DoMove)
  61. {
  62.     ULONG DestX,DestY,XSize;
  63.  
  64.     ULONG X,Y,lc;
  65.  
  66.     if(DoClip || DoMove)
  67.     {
  68.         if(CursorY > LastLine)
  69.             Y = LastLine;
  70.         else
  71.         {
  72.             if(CursorY < 0)
  73.                 Y = 0;
  74.             else
  75.                 Y = CursorY;
  76.         }
  77.  
  78.         if(Config . RasterEnabled)
  79.         {
  80.             lc = (RasterAttr[Y] == SCALE_ATTR_NORMAL) ? LastColumn : LastColumn >> 1;
  81.  
  82.             if(CursorX > lc)
  83.                 X = lc;
  84.             else
  85.             {
  86.                 if(CursorX < 0)
  87.                     X = 0;
  88.                 else
  89.                     X = CursorX;
  90.             }
  91.  
  92.             if(Config . FontScale == SCALE_NORMAL)
  93.             {
  94.                 if(RasterAttr[Y] == SCALE_ATTR_NORMAL)
  95.                 {
  96.                     DestX = X << 3;
  97.                     XSize = 8;
  98.                 }
  99.                 else
  100.                 {
  101.                     DestX = X << 4;
  102.                     XSize = 16;
  103.  
  104.                     if(X > (LastColumn >> 1))
  105.                         X = LastColumn >> 1;
  106.                 }
  107.             }
  108.             else
  109.             {
  110.                 if(RasterAttr[CursorY] == SCALE_ATTR_NORMAL)
  111.                 {
  112.                     DestX = X << 2;
  113.                     XSize = 4;
  114.                 }
  115.                 else
  116.                 {
  117.                     DestX = X << 3;
  118.                     XSize = 8;
  119.  
  120.                     if(X > (LastColumn >> 1))
  121.                         X = LastColumn >> 1;
  122.                 }
  123.             }
  124.         }
  125.         else
  126.         {
  127.             lc = (Config . FontScale == SCALE_NORMAL) ? LastColumn : LastColumn >> 1;
  128.  
  129.             if(CursorX > lc)
  130.                 X = lc;
  131.             else
  132.             {
  133.                 if(CursorX < 0)
  134.                     X = 0;
  135.                 else
  136.                     X = CursorX;
  137.             }
  138.  
  139.             if(Config . FontScale == SCALE_NORMAL)
  140.             {
  141.                 DestX = X << 3;
  142.  
  143.                 XSize = 8;
  144.             }
  145.             else
  146.             {
  147.                 DestX = X << 2;
  148.  
  149.                 XSize = 4;
  150.  
  151.                 if(X > (LastColumn >> 1))
  152.                     X = LastColumn >> 1;
  153.             }
  154.         }
  155.  
  156.         DestY = Y << 3;
  157.  
  158.         if(DoMove)
  159.             Move(RPort,DestX,DestY + 6);
  160.  
  161.         if(DoClip)
  162.             ClipBlit(RPort,0,0,RPort,DestX,DestY,XSize,8,0x50);
  163.     }
  164. }
  165.  
  166.     /* ColourValue(UWORD Colour):
  167.      *
  168.      *    Calculate the value of a given colour (brightness).
  169.      */
  170.  
  171. STATIC WORD
  172. ColourValue(UWORD Colour)
  173. {
  174.     BYTE    Red,Green,Blue;
  175.     WORD    Sum;
  176.  
  177.     Red    = (Colour >> 8) & 0xF;
  178.     Green    = (Colour >> 4) & 0xF;
  179.     Blue    = (Colour     ) & 0xF;
  180.  
  181.     Sum = (Red + Green + Blue) / 3;
  182.  
  183.     return(Sum);
  184. }
  185.  
  186.     /* SetCursor():
  187.      *
  188.      *    Move the cursor to a given location.
  189.      */
  190.  
  191. VOID
  192. SetCursor()
  193. {
  194.     ClipBlitCursor(!CursorEnabled,TRUE);
  195.  
  196.     CursorEnabled = TRUE;
  197. }
  198.  
  199.     /* BackupRender():
  200.      *
  201.      *    Save current draw modes, pen and position or restore
  202.      *    the data.
  203.      */
  204.  
  205. VOID
  206. BackupRender()
  207. {
  208.     STATIC BYTE    Called = FALSE;
  209.     STATIC UBYTE    DrMd,FgPen,BgPen;
  210.     STATIC UWORD    CpX,CpY;
  211.     STATIC UBYTE    Style;
  212.  
  213.     if(!Called)
  214.     {
  215.         DrMd    = RPort -> DrawMode;
  216.         FgPen    = RPort -> FgPen;
  217.         BgPen    = RPort -> BgPen;
  218.  
  219.         CpX    = RPort -> cp_x;
  220.         CpY    = RPort -> cp_y;
  221.  
  222.         Style    = StyleType;
  223.  
  224.         Called    = TRUE;
  225.     }
  226.     else
  227.     {
  228.         if(RPort -> DrawMode != DrMd)
  229.             SetDrMd(RPort,DrMd);
  230.  
  231.         if(RPort -> FgPen != FgPen)
  232.             SetAPen(RPort,FgPen);
  233.  
  234.         if(RPort -> BgPen != BgPen)
  235.             SetBPen(RPort,BgPen);
  236.  
  237.         if(RPort -> cp_x != CpX || RPort -> cp_y != CpY)
  238.             Move(RPort,CpX,CpY);
  239.  
  240.         if(Style != StyleType)
  241.         {
  242.             SetSoftStyle(RPort,Style,0xFF);
  243.  
  244.             StyleType = Style;
  245.         }
  246.  
  247.         Called    = FALSE;
  248.     }
  249. }
  250.  
  251.     /* ShiftChar(LONG Size):
  252.      *
  253.      *    Simulate character insertion at the current cursor
  254.      *    position by shifting the whole line Size times eight pixels
  255.      *    to the right.
  256.      */
  257.  
  258. VOID
  259. ShiftChar(LONG Size)
  260. {
  261.     LONG Dx,xMin,yMin,xMax,yMax;
  262.  
  263.     xMax = Window -> Width - 1;
  264.  
  265.     yMin = CursorY << 3;
  266.     yMax = yMin + 7;
  267.  
  268.     if(Config . RasterEnabled)
  269.     {
  270.         if(Config . FontScale == SCALE_NORMAL)
  271.         {
  272.             if(RasterAttr[CursorY] == SCALE_ATTR_NORMAL)
  273.             {
  274.                 Dx = Size << 3;
  275.                 xMin = CursorX << 3;
  276.             }
  277.             else
  278.             {
  279.                 Dx = Size << 4;
  280.                 xMin = CursorX << 4;
  281.             }
  282.         }
  283.         else
  284.         {
  285.             if(RasterAttr[CursorY] == SCALE_ATTR_NORMAL)
  286.             {
  287.                 Dx = Size << 2;
  288.                 xMin = CursorX << 2;
  289.             }
  290.             else
  291.             {
  292.                 Dx = Size << 3;
  293.                 xMin = CursorX << 3;
  294.             }
  295.         }
  296.     }
  297.     else
  298.     {
  299.         Dx = Size << 3;
  300.         xMin = CursorX << 3;
  301.     }
  302.  
  303.     BackupRender();
  304.  
  305.     SetBPen(RPort,0);
  306.  
  307.     ScrollRaster(RPort,-Dx,0,xMin,yMin,xMax,yMax);
  308.  
  309.     BackupRender();
  310. }
  311.  
  312.     /* ScrollRegion(WORD Direction):
  313.      *
  314.      *    Scroll the current scroll region up or down.
  315.      */
  316.  
  317. VOID
  318. ScrollRegion(WORD Direction)
  319. {
  320.     WORD RegionTop, RegionBottom, RegionLines;
  321.     LONG Dir,Dy,yMin,xMax,yMax;
  322.  
  323.     Dir = Direction < 0 ? -Direction : Direction;
  324.  
  325.     if(RegionSet)
  326.     {
  327.         yMin         = Top * 8;
  328.         yMax        = (Bottom + 1) * 8 - 1;
  329.  
  330.         RegionTop    = Top;
  331.         RegionBottom    = Bottom;
  332.         RegionLines    = Bottom - Top;
  333.     }
  334.     else
  335.     {
  336.         yMin        = 0;
  337.         yMax         = (LastLine + 1) * 8 - 1;
  338.  
  339.         RegionTop    = 0;
  340.         RegionBottom    = LastLine + 1;
  341.         RegionLines    = LastLine + 1;
  342.     }
  343.  
  344.     xMax = Window -> Width - 1;
  345.  
  346.     BackupRender();
  347.  
  348.     SetBPen(RPort,0);
  349.  
  350.     if(Config . RasterEnabled)
  351.         RasterScrollRegion(Direction,RegionTop,RegionBottom,RegionLines);
  352.  
  353.     if(Dir > RegionLines)
  354.     {
  355.         /* All that is needed is to delete the lines
  356.          * note: not too brilliant for smooth scroll
  357.          */
  358.  
  359.         RectFill(RPort,0,yMin,xMax,yMax);
  360.  
  361.     }
  362.     else
  363.     {
  364.         if(Config . JumpScroll)
  365.         {
  366.             Dy = Direction * 8;
  367.  
  368.             ScrollRaster(RPort,0,Dy,0,yMin,xMax,yMax);
  369.         }
  370.         else
  371.         {
  372.             WORD i, j= Dir * 4;
  373.  
  374.             if(Direction < 0)
  375.                 Dy = -2;
  376.             else
  377.                 Dy = 2;
  378.  
  379.             for(i = 0 ; i < j ; i++)
  380.             {
  381.                 WaitTOF();
  382.  
  383.                 ScrollRaster(RPort,0,Dy,0,yMin,xMax,yMax);
  384.             }
  385.         }
  386.     }
  387.  
  388.     BackupRender();
  389. }
  390.  
  391.     /* LastChar(UBYTE *Buffer):
  392.      *
  393.      *    Return the last character in a string.
  394.      */
  395.  
  396. STATIC UBYTE
  397. LastChar(UBYTE *Buffer)
  398. {
  399.     WORD Offset = 0;
  400.  
  401.     while(Buffer[Offset])
  402.         Offset++;
  403.  
  404.     return(Buffer[Offset - 1]);
  405. }
  406.  
  407.     /* ReadValue(UBYTE *Buffer,BYTE *Value):
  408.      *
  409.      *    Parse a buffer for numbers and return a pointer
  410.      *    to the next buffer element to contain additional
  411.      *    information.
  412.      */
  413.  
  414. STATIC UBYTE *
  415. ReadValue(UBYTE *Buffer,WORD *Value)
  416. {
  417.     while((*Buffer < '0' || *Buffer > '9') && (*Buffer != ';') && *Buffer)
  418.         Buffer++;
  419.  
  420.     if(*Buffer)
  421.     {
  422.         *Value = 0;
  423.  
  424.         while(*Buffer >= '0' && *Buffer <= '9')
  425.             *Value = (*Value * 10) + (*Buffer++ - '0');
  426.     }
  427.     else
  428.         *Value = -1;
  429.  
  430.     if(*Buffer == ';' || *Buffer == ' ')
  431.         return(&Buffer[1]);
  432.     else
  433.         return(NULL);
  434. }
  435.  
  436.     /* Ignore():
  437.      *
  438.      *    Do nothing, return immediately.
  439.      */
  440.  
  441. UBYTE *
  442. Ignore()
  443. {
  444.     return(NULL);
  445. }
  446.  
  447.     /* CursorScrollDown():
  448.      *
  449.      *    Move cursor down and scroll region if necessary.
  450.      */
  451.  
  452. UBYTE *
  453. CursorScrollDown()
  454. {
  455.     ClearCursor();
  456.  
  457.     DownLine();
  458.  
  459.     SetCursor();
  460.  
  461.     return(NULL);
  462. }
  463.  
  464. VOID
  465. DownLine()
  466. {
  467.     UBYTE InRegion = TRUE;
  468.     WORD  Hit      = LastLine;
  469.  
  470.     if(RegionSet)
  471.     {
  472.         if(CursorY <= Bottom)
  473.             Hit = Bottom;
  474.         else
  475.             InRegion = FALSE;
  476.     }
  477.  
  478.     if(CursorY == Hit)
  479.     {
  480.         if(InRegion)
  481.             ScrollRegion(1);
  482.     }
  483.     else
  484.     {
  485.         CursorY++;
  486.  
  487.         if(CursorY > LastLine)
  488.             CursorY = LastLine;
  489.     }
  490. }
  491.  
  492.     /* CursorScrollUp():
  493.      *
  494.      *    Move cursor up and scroll region if necessary.
  495.      */
  496.  
  497. UBYTE *
  498. CursorScrollUp()
  499. {
  500.     WORD Hit = 0;
  501.     UBYTE InRegion = TRUE;
  502.  
  503.     ClearCursor();
  504.  
  505.     if(RegionSet)
  506.     {
  507.         if(CursorY >= Top)
  508.             Hit = Top;
  509.         else
  510.             InRegion = FALSE;
  511.     }
  512.  
  513.     if(CursorY == Hit)
  514.     {
  515.         if(InRegion)
  516.             ScrollRegion(-1);
  517.     }
  518.     else
  519.     {
  520.         CursorY--;
  521.  
  522.         if(CursorY < 0)
  523.             CursorY = 0;
  524.     }
  525.  
  526.     SetCursor();
  527.  
  528.     return(NULL);
  529. }
  530.  
  531.     /* NextLine():
  532.      *
  533.      *    Do something like CR+LF.
  534.      */
  535.  
  536. UBYTE *
  537. NextLine()
  538. {
  539.  
  540.     ClearCursor();
  541.  
  542.     CursorX = 0;
  543.  
  544.     DownLine();
  545.  
  546.     SetCursor();
  547.  
  548.     return(NULL);
  549. }
  550.  
  551.     /* SaveCursor():
  552.      *
  553.      *    Save cursor position and rendering attributes.
  554.      */
  555.  
  556. UBYTE *
  557. SaveCursor()
  558. {
  559.     CursorBackup . Charset        = Charset;
  560.     CursorBackup . Attributes    = Attributes;
  561.     CursorBackup . UseRegion    = UseRegion;
  562.     CursorBackup . RegionSet    = RegionSet;
  563.     CursorBackup . Top        = Top;
  564.     CursorBackup . Bottom        = Bottom;
  565.     CursorBackup . CursorX        = CursorX;
  566.     CursorBackup . CursorY        = CursorY;
  567.  
  568.     return(NULL);
  569. }
  570.  
  571.     /* FontStuff(UBYTE *Buffer):
  572.      *
  573.      *    Set the drawing font (standard characters/line).
  574.      */
  575.  
  576. UBYTE *
  577. FontStuff(UBYTE *Buffer)
  578. {
  579.     switch(LastChar(Buffer))
  580.     {
  581.         case 'A':
  582.         case 'B':    if(Config . Font == FONT_IBM && IBM)
  583.                     CurrentFont = IBM;
  584.                 else
  585.                     CurrentFont = Topaz;
  586.  
  587.                 SetFont(RPort,CurrentFont);
  588.  
  589.                 break;
  590.  
  591.         default:    break;
  592.     }
  593.  
  594.     return(NULL);
  595. }
  596.  
  597.     /* LoadCursor():
  598.      *
  599.      *    Load cursor position and rendering attributes.
  600.      */
  601.  
  602. UBYTE *
  603. LoadCursor()
  604. {
  605.     LONG TextFlags = FS_NORMAL;
  606.  
  607.     ClearCursor();
  608.  
  609.     if(CursorBackup . Attributes & ATTR_UNDERLINE)
  610.         TextFlags |= FSF_UNDERLINED;
  611.  
  612.     if((CursorBackup . Attributes & ATTR_HIGHLIGHT) && Config . ColourMode != COLOUR_SIXTEEN)
  613.         TextFlags |= FSF_BOLD;
  614.  
  615.     if(CursorBackup . Attributes & ATTR_BLINK)
  616.     {
  617.         if(Config . Emulation == EMULATION_ANSIVT100)
  618.         {
  619.             switch(Config . ColourMode)
  620.             {
  621.                 case COLOUR_AMIGA:    if(CursorBackup . Attributes & ATTR_INVERSE)
  622.                                 BgPen = 3;
  623.                             else
  624.                                 FgPen = 3;
  625.  
  626.                             break;
  627.  
  628.                 case COLOUR_EIGHT:    if(CursorBackup . Attributes & ATTR_INVERSE)
  629.                                 BgPen |= 8;
  630.                             else
  631.                                 FgPen |= 8;
  632.  
  633.                             break;
  634.  
  635.                 case COLOUR_SIXTEEN:    break;
  636.             }
  637.         }
  638.     }
  639.  
  640.     if(StyleType != TextFlags)
  641.     {
  642.         SetSoftStyle(RPort,TextFlags,0xFF);
  643.  
  644.         StyleType = TextFlags;
  645.     }
  646.  
  647.     if(RPort -> FgPen != FgPen)
  648.         SetAPen(RPort,FgPen);
  649.  
  650.     if(RPort -> BgPen != BgPen)
  651.         SetBPen(RPort,BgPen);
  652.  
  653.     Attributes    = CursorBackup . Attributes;
  654.     UseRegion    = CursorBackup . UseRegion;
  655.     RegionSet    = CursorBackup . RegionSet;
  656.     Top        = CursorBackup . Top;
  657.     Bottom        = CursorBackup . Bottom;
  658.     CursorX        = CursorBackup . CursorX;
  659.     CursorY        = CursorBackup . CursorY;
  660.  
  661.     SetCursor();
  662.  
  663.     return(NULL);
  664. }
  665.  
  666. UBYTE *
  667. ScaleFont(UBYTE *Buffer)
  668. {
  669.     WORD NewScale,Scale;
  670.     WORD CursorXSave;
  671.     UBYTE *RasterPtr;
  672.  
  673.     Scale = RasterAttr[CursorY];
  674.  
  675.     ClearCursor();
  676.  
  677.     if(Config . RasterEnabled)
  678.         NewScale = Scale;
  679.     else
  680.         NewScale = Config . FontScale;
  681.  
  682.     switch(LastChar(Buffer))
  683.     {
  684.         case '3':
  685.  
  686.             NewScale = SCALE_ATTR_TOP2X;
  687.  
  688.             break;
  689.  
  690.         case '4':
  691.  
  692.             NewScale = SCALE_ATTR_BOT2X;
  693.  
  694.             break;
  695.  
  696.         case '5':
  697.  
  698.             NewScale = SCALE_NORMAL;
  699.  
  700.             break;
  701.  
  702.         case '6':
  703.  
  704.             NewScale = SCALE_ATTR_2X;
  705.  
  706.             break;
  707.     }
  708.  
  709.     if(Scale != NewScale)
  710.     {
  711.         UWORD i;
  712.  
  713.         CursorXSave = CursorX;
  714.  
  715.         i = LastColumn + 1;
  716.  
  717.         if(NewScale != SCALE_ATTR_NORMAL)
  718.             i >>= 1;
  719.  
  720.         if(Config . RasterEnabled)
  721.         {
  722.             RasterAttr[CursorY] = NewScale;
  723.  
  724.             RasterPtr = &Raster[CursorY * RasterWidth];
  725.  
  726.             if(((Config . FontScale == SCALE_NORMAL) && (NewScale == SCALE_ATTR_NORMAL)) || ((Config . FontScale == SCALE_HALF) && (NewScale == SCALE_ATTR_2X)))
  727.             {
  728.                 Move(RPort,0,(CursorY << 3) + 6);
  729.                 Text(RPort,RasterPtr,i);
  730.             }
  731.             else
  732.             {
  733.                 CursorX = 0;
  734.                 PrintScaled(RasterPtr,i,NewScale);
  735.             }
  736.         }
  737.  
  738.         if(CursorXSave >= i)
  739.             CursorX = i - 1;
  740.         else
  741.             CursorX = CursorXSave;
  742.     }
  743.  
  744.     SetCursor();
  745.  
  746.     return(NULL);
  747. }
  748.  
  749.     /* SetTab():
  750.      *
  751.      *    Set a tabulator stop at the current position.
  752.      */
  753.  
  754. UBYTE *
  755. SetTab()
  756. {
  757.     if(CursorX < 1024)
  758.         TabStops[CursorX] = TRUE;
  759.  
  760.     return(NULL);
  761. }
  762.  
  763.     /* RequestTerminal(UBYTE *Buffer):
  764.      *
  765.      *    Return the current terminal position.
  766.      */
  767.  
  768. UBYTE *
  769. RequestTerminal(UBYTE *Buffer)
  770. {
  771.     switch(Buffer[0])
  772.     {
  773.                 /* Make ourselves known as a VT200
  774.                  * terminal.
  775.                  */
  776.  
  777.         case '[':    if(Buffer[1] != '>')
  778.                     return("\033[?62;1;2;6;7;8;9c");
  779.                 else
  780.                     return("\033[>1;10;0c");
  781.  
  782.                 /* This is an old status request type,
  783.                  * we will return the standard `I am a
  784.                  * VT101' sequence.
  785.                  */
  786.  
  787.         case 'Z':    return("\033[?1;0c");
  788.  
  789.         default:    return(NULL);
  790.     }
  791. }
  792.  
  793.     /* Reset():
  794.      *
  795.      *    Reset terminal to initial state.
  796.      */
  797.  
  798. UBYTE *
  799. Reset()
  800. {
  801.     WORD i;
  802.  
  803.     ClearCursor();
  804.  
  805.     memset(&TabStops[0],FALSE,1024);
  806.  
  807.     for(i = 8 ; i < 1024 ; i += 8)
  808.         TabStops[i] = TRUE;
  809.  
  810.     SetRast(RPort,0);
  811.  
  812.     if(Config . RasterEnabled)
  813.         RasterEraseScreen(2);
  814.  
  815.     switch(Config . ColourMode)
  816.     {
  817.         case COLOUR_EIGHT:    FgPen = 7;
  818.                     break;
  819.  
  820.         case COLOUR_SIXTEEN:    FgPen = 15;
  821.                     break;
  822.  
  823.         case COLOUR_AMIGA:
  824.         default:        FgPen = 1;
  825.                     break;
  826.     }
  827.  
  828.     BgPen = 0;
  829.  
  830.     if(RPort -> FgPen != FgPen)
  831.         SetAPen(RPort,FgPen);
  832.  
  833.     if(RPort -> BgPen != BgPen)
  834.         SetBPen(RPort,BgPen);
  835.  
  836.     if(StyleType != FS_NORMAL)
  837.     {
  838.         SetSoftStyle(RPort,FS_NORMAL,0xFF);
  839.  
  840.         StyleType = FS_NORMAL;
  841.     }
  842.  
  843.     if(Config . Font == FONT_IBM && IBM)
  844.         CurrentFont = IBM;
  845.     else
  846.         CurrentFont = Topaz;
  847.     SetFont(RPort,CurrentFont);
  848.  
  849.     if(Config . EightyColumns)
  850.         LastColumn = 79;
  851.     else
  852.         LastColumn = (Window -> Width >> 3) - 1;
  853.  
  854.     UseRegion        = FALSE;
  855.     RegionSet        = FALSE;
  856.     Config . AutoWrap    = TRUE;
  857.     Config . NewLine    = FALSE;
  858.     Config . InsertChar    = FALSE;
  859.     Config . CursorApp    = FALSE;
  860.     Config . NumApp        = FALSE;
  861.     Config . FontScale    = SCALE_NORMAL;
  862.     Config . JumpScroll    = TRUE;
  863.  
  864.     Attributes    = 0;
  865.     Top        = 0;
  866.     Bottom        = LastLine;
  867.     CursorX        = 0;
  868.     CursorY        = 0;
  869.  
  870.     CursorBackup . Charset        = Charset;
  871.     CursorBackup . Attributes    = Attributes;
  872.     CursorBackup . UseRegion    = UseRegion;
  873.     CursorBackup . RegionSet    = RegionSet;
  874.     CursorBackup . Top        = Top;
  875.     CursorBackup . Bottom        = Bottom;
  876.     CursorBackup . CursorX        = CursorX;
  877.     CursorBackup . CursorY        = CursorY;
  878.  
  879.     SetCursor();
  880.  
  881.     return(NULL);
  882. }
  883.  
  884.     /* RequestInformation(UBYTE *Buffer):
  885.      *
  886.      *    Request miscellaneous information (state & cursor position).
  887.      */
  888.  
  889. UBYTE *
  890. RequestInformation(UBYTE *Buffer)
  891. {
  892.     WORD Value;
  893.  
  894.     ReadValue(Buffer,&Value);
  895.  
  896.     switch(Value)
  897.     {
  898.                 /* Terminal status report, return code
  899.                  * for `no malfunction'.
  900.                  */
  901.  
  902.         case 5:        return("\033[0n");
  903.  
  904.                 /* The origin is placed at 0/0 and the first
  905.                  * cursor position is 1/1. We'll have to add
  906.                  * 1 to our internal positions since our
  907.                  * universe has been shifted one field to the
  908.                  * left top corner.
  909.                  */
  910.  
  911.         case 6:        SPrintf(GlobalBuffer,"\033[%ld;%ldR",CursorY + 1,CursorX + 1);
  912.                 return(GlobalBuffer);
  913.  
  914.                 /* A VT200 command: request printer status.
  915.                  * We will return `no printer connected'.
  916.                  */
  917.  
  918.         case 15:    return("\033[?13n");
  919.  
  920.                 /* VT200 command: request user defined
  921.                  * key status. We will return `user
  922.                  * defined keys are locked'.
  923.                  */
  924.  
  925.         case 25:    return("\033[?21n");
  926.  
  927.                 /* Another VT200 command: request
  928.                  * keyboard language. We will return
  929.                  * `keyboard language unknown' - does
  930.                  * anybody know when locale.library will
  931.                  * be released?
  932.                  */
  933.  
  934.         case 26:    return("\033[?27;0n");
  935.  
  936.         default:    return(NULL);
  937.     }
  938. }
  939.  
  940.     /* SetSomething(UBYTE *Buffer):
  941.      *
  942.      *    Set a terminal option.
  943.      */
  944.  
  945. UBYTE *
  946. SetSomething(UBYTE *Buffer)
  947. {
  948.     if(Buffer[1] == '?')
  949.     {
  950.         switch(Buffer[2])
  951.         {
  952.             case '1':    if(Buffer[3] == 'h')
  953.                         Config . CursorApp = TRUE;
  954.                     else
  955.                         Config . CursorApp = FALSE;
  956.  
  957.                     return(NULL);
  958.  
  959.             case '3':    if(Buffer[3] == 'h')
  960.                     {
  961.                         if(Config . FontScale != SCALE_HALF)
  962.                         {
  963.                             Config . FontScale = SCALE_HALF;
  964.  
  965.                             if(Config . EightyColumns)
  966.                                 LastColumn = 131;
  967.                             else
  968.                                 LastColumn = (Window -> Width >> 2) - 1;
  969.                         }
  970.                     }
  971.                     else
  972.                     {
  973.                         if(Config . FontScale != SCALE_NORMAL)
  974.                         {
  975.                             Config . FontScale = SCALE_NORMAL;
  976.  
  977.                             if(Config . EightyColumns)
  978.                                 LastColumn = 79;
  979.                             else
  980.                                 LastColumn = (Window -> Width >> 3) - 1;
  981.                         }
  982.                     }
  983.  
  984.                     EraseScreen("2");
  985.  
  986.                     ClearCursor();
  987.  
  988.                     CursorX = 0;
  989.                     CursorY = 0;
  990.  
  991.                     SetCursor();
  992.  
  993.                     return(NULL);
  994.  
  995.             case '4':    if(Buffer[3] == 'h')
  996.                         Config . JumpScroll = FALSE;
  997.                     else
  998.                         Config . JumpScroll = TRUE;
  999.  
  1000.                     break;
  1001.  
  1002.             case '6':    if(Buffer[3] == 'h')
  1003.                         UseRegion = TRUE;
  1004.                     else
  1005.                         UseRegion = FALSE;
  1006.  
  1007.                     ResetCursor();
  1008.  
  1009.                     return(NULL);
  1010.  
  1011.             case '7':    if(Buffer[3] == 'h')
  1012.                         Config . AutoWrap = TRUE;
  1013.                     else
  1014.                         Config . AutoWrap = FALSE;
  1015.  
  1016.                     return(NULL);
  1017.  
  1018.             case '9':    if(Buffer[3] == 'h')
  1019.                     {
  1020.                         if(!(Config . DisplayMode & LACE))
  1021.                         {
  1022.                             CopyMem(&Config,&PrivateConfig,sizeof(struct Configuration));
  1023.  
  1024.                             Config . DisplayMode |= LACE;
  1025.  
  1026.                             ResetDisplay = TRUE;
  1027.                         }
  1028.                     }
  1029.                     else
  1030.                     {
  1031.                         if(Config . DisplayMode & LACE)
  1032.                         {
  1033.                             CopyMem(&Config,&PrivateConfig,sizeof(struct Configuration));
  1034.  
  1035.                             Config . DisplayMode &= ~LACE;
  1036.  
  1037.                             ResetDisplay = TRUE;
  1038.                         }
  1039.                     }
  1040.  
  1041.                     return(NULL);
  1042.  
  1043.             default:    return(NULL);
  1044.         }
  1045.     }
  1046.     else
  1047.     {
  1048.         if(Buffer[1] == '2' && Buffer[2] == '0')
  1049.         {
  1050.             if(Buffer[3] == 'h')
  1051.                 Config . NewLine = TRUE;
  1052.             else
  1053.                 Config . NewLine = FALSE;
  1054.         }
  1055.         else
  1056.         {
  1057.             if(Buffer[1] == '4')
  1058.             {
  1059.                 if(Buffer[2] == 'h')
  1060.                     Config . InsertChar = TRUE;
  1061.                 else
  1062.                     Config . InsertChar = FALSE;
  1063.             }
  1064.         }
  1065.     }
  1066.  
  1067.     return(NULL);
  1068. }
  1069.  
  1070.     /* NumericAppMode(UBYTE *Buffer):
  1071.      *
  1072.      *    Set the numeric pad applications mode.
  1073.      */
  1074.  
  1075. UBYTE *
  1076. NumericAppMode(UBYTE *Buffer)
  1077. {
  1078.     if(*Buffer == '=')
  1079.         Config . NumApp = TRUE;
  1080.     else
  1081.     {
  1082.         if(*Buffer == '>')
  1083.             Config . NumApp = FALSE;
  1084.     }
  1085.  
  1086.     return(NULL);
  1087. }
  1088.  
  1089.     /* MoveCursor(UBYTE *Buffer):
  1090.      *
  1091.      *    Move the cursor in some direction and stop at
  1092.      *    top/bottom/margin if necessary.
  1093.      */
  1094.  
  1095. UBYTE *
  1096. MoveCursor(UBYTE *Buffer)
  1097. {
  1098.     WORD Value;
  1099.     WORD Hit,lc;
  1100.     UBYTE InRegion = TRUE;
  1101.  
  1102.     ReadValue(Buffer,&Value);
  1103.  
  1104.     if(Value < 1)
  1105.         Value = 1;
  1106.  
  1107.     ClearCursor();
  1108.  
  1109.     switch(LastChar(Buffer))
  1110.     {
  1111.         /*
  1112.          *    Move cursor Up value lines
  1113.          */
  1114.  
  1115.         case 'A':
  1116.  
  1117.             ScrollUp:
  1118.  
  1119.                 Hit = 0;
  1120.  
  1121.                 if(RegionSet)
  1122.                 {
  1123.                     if(CursorY >= Top)
  1124.                         Hit = Top;
  1125.                     else
  1126.                         InRegion = FALSE;
  1127.                 }
  1128.  
  1129.                 CursorY -= Value;
  1130.  
  1131.                 if(CursorY < Hit)
  1132.                 {
  1133.                     Value = CursorY - Hit;
  1134.  
  1135.                     CursorY = Hit;
  1136.  
  1137.                     if(Config . CursorWrap && InRegion)
  1138.                         ScrollRegion(Value);
  1139.                 }
  1140.  
  1141.                 break;
  1142.  
  1143.         /*
  1144.          *    Move cursor Down value lines
  1145.          */
  1146.  
  1147.         case 'B':
  1148.  
  1149.             ScrollDown:
  1150.  
  1151.                 Hit = LastLine;
  1152.  
  1153.                 if(RegionSet)
  1154.                 {
  1155.                     if(CursorY <= Bottom)
  1156.                         Hit = Bottom;
  1157.                     else
  1158.                         InRegion = FALSE;
  1159.                 }
  1160.  
  1161.                 CursorY += Value;
  1162.  
  1163.                 if(CursorY > Hit)
  1164.                 {
  1165.                     Value = CursorY - Hit;
  1166.  
  1167.                     CursorY = Hit;
  1168.  
  1169.                     if(Config . CursorWrap && InRegion)
  1170.                         ScrollRegion(Value);
  1171.                 }
  1172.  
  1173.                 break;
  1174.  
  1175.         /*
  1176.          *    Move cursor Right value columns
  1177.          */
  1178.  
  1179.         case 'C':    CursorX += Value;
  1180.  
  1181.                 if(CursorX > LastColumn)
  1182.                 {
  1183.                     if(Config . CursorWrap)
  1184.                     {
  1185.                         Value = CursorX / LastColumn;
  1186.  
  1187.                         CursorX -= Value * LastColumn;
  1188.  
  1189.                         goto ScrollDown;
  1190.                     }
  1191.                     else
  1192.                         CursorX = LastColumn;
  1193.                 }
  1194.  
  1195.                 break;
  1196.  
  1197.         /*
  1198.          *    Move cursor Left value columns
  1199.          */
  1200.  
  1201.         case 'D':    CursorX -= Value;
  1202.  
  1203.                 if(CursorX < 0)
  1204.                 {
  1205.                     if(Config . CursorWrap)
  1206.                     {
  1207.                         Value = CursorX / LastColumn - 1;
  1208.                         CursorX -= Value * LastColumn;
  1209.                         Value = -Value;
  1210.  
  1211.                         goto ScrollDown;
  1212.                     }
  1213.                     else
  1214.                         CursorX = 0;
  1215.                 }
  1216.  
  1217.                 break;
  1218.  
  1219.         default:    break;
  1220.     }
  1221.  
  1222.     if(Config . RasterEnabled)
  1223.         lc = (RasterAttr[CursorY] == SCALE_ATTR_NORMAL) ? LastColumn : LastColumn >> 1;
  1224.     else
  1225.         lc = (Config . FontScale == SCALE_NORMAL) ? LastColumn : LastColumn >> 1;
  1226.  
  1227.     if(CursorX > lc)
  1228.         CursorX = lc;
  1229.  
  1230.     SetCursor();
  1231.  
  1232.     return(NULL);
  1233. }
  1234.  
  1235.     /* EraseLine(UBYTE *Buffer):
  1236.      *
  1237.      *    Erase a line on the display.
  1238.      */
  1239.  
  1240. UBYTE *
  1241. EraseLine(UBYTE *Buffer)
  1242. {
  1243.     WORD Value;
  1244.  
  1245.     ReadValue(Buffer,&Value);
  1246.  
  1247.     BackupRender();
  1248.  
  1249.     SetAPen(RPort,0);
  1250.  
  1251.     if(Config . RasterEnabled)
  1252.         RasterEraseLine(Value);
  1253.  
  1254.     ClearCursor();
  1255.  
  1256.     switch(Value)
  1257.     {
  1258.         case 1:    RectFill(RPort,0,CursorY * 8,(CursorX + 1) * 8 - 1,(CursorY + 1) * 8 - 1);
  1259.             break;
  1260.  
  1261.         case 2:    RectFill(RPort,0,CursorY * 8,Window -> Width - 1,(CursorY + 1) * 8 - 1);
  1262.             break;
  1263.  
  1264.         default:RectFill(RPort,CursorX * 8,CursorY * 8,Window -> Width - 1,(CursorY + 1) * 8 - 1);
  1265.             break;
  1266.     }
  1267.  
  1268.     DrawCursor();
  1269.  
  1270.     BackupRender();
  1271.  
  1272.     return(NULL);
  1273. }
  1274.  
  1275.     /* EraseScreen(UBYTE *Buffer):
  1276.      *
  1277.      *    Erase parts of the screen.
  1278.      */
  1279.  
  1280. UBYTE *
  1281. EraseScreen(UBYTE *Buffer)
  1282. {
  1283.     WORD Value;
  1284.  
  1285.     ClearCursor();
  1286.  
  1287.     ReadValue(Buffer,&Value);
  1288.  
  1289.     BackupRender();
  1290.  
  1291.     SetAPen(RPort,0);
  1292.  
  1293.     if(Config . RasterEnabled)
  1294.         RasterEraseScreen(Value);
  1295.  
  1296.     switch(Value)
  1297.     {
  1298.         case 1:    RectFill(RPort,0,0,Window -> Width - 1,(CursorY + 1) * 8 - 1);
  1299.             break;
  1300.  
  1301.         case 2:    RectFill(RPort,0,0,Window -> Width - 1,(LastLine + 1) * 8 - 1);
  1302.             break;
  1303.  
  1304.         default:RectFill(RPort,0,CursorY * 8,Window -> Width - 1,(LastLine + 1) * 8 - 1);
  1305.             break;
  1306.     }
  1307.  
  1308.     DrawCursor();
  1309.  
  1310.     BackupRender();
  1311.  
  1312.     return(NULL);
  1313. }
  1314.  
  1315.     /* EraseCharacters(UBYTE *Buffer):
  1316.      *
  1317.      *    Erase a number of characters.
  1318.      */
  1319.  
  1320. UBYTE *
  1321. EraseCharacters(UBYTE *Buffer)
  1322. {
  1323.     WORD Value;
  1324.  
  1325.     ReadValue(Buffer,&Value);
  1326.  
  1327.     BackupRender();
  1328.  
  1329.     SetBPen(RPort,0);
  1330.  
  1331.     if(Value == -1)
  1332.         Value = 1;
  1333.  
  1334.     if(Value > 0)
  1335.     {
  1336.         if(Config . RasterEnabled)
  1337.             RasterEraseCharacters(Value);
  1338.  
  1339.         ClearCursor();
  1340.  
  1341.         ScrollRaster(RPort,8 * Value,0,CursorX * 8,CursorY * 8,Window -> Width - 1,(LastLine + 1) * 8 - 1);
  1342.  
  1343.         DrawCursor();
  1344.     }
  1345.  
  1346.     BackupRender();
  1347.  
  1348.     return(NULL);
  1349. }
  1350.  
  1351.     /* InsertLine(UBYTE *Buffer):
  1352.      *
  1353.      *    Insert a number of lines and scroll the rest of the
  1354.      *    display down.
  1355.      */
  1356.  
  1357. UBYTE *
  1358. InsertLine(UBYTE *Buffer)
  1359. {
  1360.     WORD Value;
  1361.  
  1362.     ReadValue(Buffer,&Value);
  1363.  
  1364.     BackupRender();
  1365.  
  1366.     SetAPen(RPort,0);
  1367.  
  1368.     if(Value == -1)
  1369.         Value = 1;
  1370.  
  1371.     if(Value > 0)
  1372.     {
  1373.         if(Config . RasterEnabled)
  1374.             RasterInsertLine(Value);
  1375.  
  1376.         ClearCursor();
  1377.  
  1378.         ScrollRaster(RPort,0,-8 * Value,0,CursorY * 8,Window -> Width - 1,(LastLine + 1) * 8 - 1);
  1379.  
  1380.         DrawCursor();
  1381.     }
  1382.  
  1383.     BackupRender();
  1384.  
  1385.     return(NULL);
  1386. }
  1387.  
  1388.     /* ClearLine(UBYTE *Buffer):
  1389.      *
  1390.      *    Clear a number of lines and scroll up the ones below it.
  1391.      */
  1392.  
  1393. UBYTE *
  1394. ClearLine(UBYTE *Buffer)
  1395. {
  1396.     WORD Value;
  1397.  
  1398.     ReadValue(Buffer,&Value);
  1399.  
  1400.     BackupRender();
  1401.  
  1402.     SetAPen(RPort,0);
  1403.  
  1404.     if(Value == -1)
  1405.         Value = 1;
  1406.  
  1407.     if(Value > 0)
  1408.     {
  1409.         if(Config . RasterEnabled)
  1410.             RasterClearLine(Value);
  1411.  
  1412.         ClearCursor();
  1413.  
  1414.         ScrollRaster(RPort,0,Value * 8,0,CursorY * 8,Window -> Width - 1,(LastLine + 1) * 8 - 1);
  1415.  
  1416.         DrawCursor();
  1417.     }
  1418.  
  1419.     BackupRender();
  1420.  
  1421.     return(NULL);
  1422. }
  1423.  
  1424.     /* SetTabs(UBYTE *Buffer):
  1425.      *
  1426.      *    Set the current tab stops.
  1427.      */
  1428.  
  1429. UBYTE *
  1430. SetTabs(UBYTE *Buffer)
  1431. {
  1432.     WORD Value;
  1433.  
  1434.     ReadValue(Buffer,&Value);
  1435.  
  1436.     if(Value == -1)
  1437.         Value = 0;
  1438.  
  1439.     switch(Value)
  1440.     {
  1441.         case 0:    if(CursorX < 1024)
  1442.                 TabStops[CursorX] = FALSE;
  1443.  
  1444.             break;
  1445.  
  1446.         case 3:    memset(&TabStops[0],FALSE,1024);
  1447.  
  1448.             break;
  1449.  
  1450.         default:break;
  1451.     }
  1452.  
  1453.     return(NULL);
  1454. }
  1455.  
  1456.     /* SetPosition(UBYTE *Buffer):
  1457.      *
  1458.      *    Move the cursor to a given location on the display.
  1459.      */
  1460.  
  1461. UBYTE *
  1462. SetPosition(UBYTE *Buffer)
  1463. {
  1464.     WORD Value;
  1465.  
  1466.     Buffer = ReadValue(Buffer,&Value);
  1467.  
  1468.     ClearCursor();
  1469.  
  1470.     CursorX = 0;
  1471.     CursorY = 0;
  1472.  
  1473.     if(Value == -1)
  1474.     {
  1475.         if(UseRegion)
  1476.             CursorY = Top;
  1477.     }
  1478.     else
  1479.     {
  1480.             /* Our raster origin is 0/0 instead of 1/1. */
  1481.  
  1482.         if(Value)
  1483.             Value--;
  1484.  
  1485.         if(UseRegion)
  1486.             CursorY = Top + Value;
  1487.         else
  1488.             CursorY = Value;
  1489.  
  1490.         if(Buffer)
  1491.         {
  1492.             ReadValue(Buffer,&Value);
  1493.  
  1494.             if(Value > 0)
  1495.                 CursorX = Value - 1;
  1496.  
  1497.         }
  1498.  
  1499.             /* Truncate illegal positions (this took almost
  1500.              * two months to fix!).
  1501.              */
  1502.  
  1503.         if(CursorX > LastColumn)
  1504.             CursorX = LastColumn;
  1505.  
  1506.         if(RegionSet)
  1507.         {
  1508.             if(CursorY > Bottom)
  1509.                 CursorY = Bottom;
  1510.         }
  1511.         else
  1512.         {
  1513.             if(CursorY > LastLine)
  1514.                 CursorY = LastLine;
  1515.         }
  1516.     }
  1517.  
  1518.     SetCursor();
  1519.  
  1520.     return(NULL);
  1521. }
  1522.  
  1523.     /* SetAttributes(UBYTE *Buffer):
  1524.      *
  1525.      *    Set the current display rendering attributes.
  1526.      */
  1527.  
  1528. UBYTE *
  1529. SetAttributes(UBYTE *Buffer)
  1530. {
  1531.     LONG TextFlags = FS_NORMAL;
  1532.     WORD Value;
  1533.  
  1534.     do
  1535.     {
  1536.         Buffer = ReadValue(Buffer,&Value);
  1537.  
  1538.         if(Value == -1)
  1539.             Value = 0;
  1540.  
  1541.         switch(Value)
  1542.         {
  1543.             case 0:
  1544.                 if((Attributes & ATTR_HIGHLIGHT) && Config . ColourMode == COLOUR_SIXTEEN)
  1545.                 {
  1546.                     if(Attributes & ATTR_INVERSE)
  1547.                         BgPen &= ~8;
  1548.                     else
  1549.                         FgPen &= ~8;
  1550.                 }
  1551.  
  1552.                 if(Attributes & ATTR_BLINK)
  1553.                 {
  1554.                     switch(Config . ColourMode)
  1555.                     {
  1556.                         case COLOUR_AMIGA:
  1557.                         case COLOUR_MONO:    if(Attributes & ATTR_INVERSE)
  1558.                                         BgPen = 1;
  1559.                                     else
  1560.                                         FgPen = 1;
  1561.  
  1562.                                     break;
  1563.  
  1564.                         case COLOUR_EIGHT:    if(Attributes & ATTR_INVERSE)
  1565.                                         BgPen &= ~8;
  1566.                                     else
  1567.                                         FgPen &= ~8;
  1568.  
  1569.                                     break;
  1570.  
  1571.                         default:        break;
  1572.                     }
  1573.                 }
  1574.  
  1575.                 if(Attributes & ATTR_INVERSE)
  1576.                 {
  1577.                     BYTE Help;
  1578.  
  1579.                     Help    = FgPen;
  1580.                     FgPen    = BgPen;
  1581.                     BgPen    = Help;
  1582.                 }
  1583.  
  1584.                 if(RPort -> FgPen != FgPen)
  1585.                     SetAPen(RPort,FgPen);
  1586.  
  1587.                 if(RPort -> BgPen != BgPen)
  1588.                     SetBPen(RPort,BgPen);
  1589.  
  1590.                 Attributes = 0;
  1591.  
  1592.                 break;
  1593.  
  1594.             case 1:    Attributes |= ATTR_HIGHLIGHT;
  1595.  
  1596.                 break;
  1597.  
  1598.             case 4:    Attributes |= ATTR_UNDERLINE;
  1599.  
  1600.                 break;
  1601.  
  1602.             case 5:    Attributes |= ATTR_BLINK;
  1603.  
  1604.                 break;
  1605.  
  1606.             case 7:    if(!(Attributes & ATTR_INVERSE))
  1607.                 {
  1608.                     BYTE Help;
  1609.  
  1610.                     Help    = FgPen;
  1611.                     FgPen    = BgPen;
  1612.                     BgPen    = Help;
  1613.                 }
  1614.  
  1615.                 Attributes |= ATTR_INVERSE;
  1616.  
  1617.                 break;
  1618.  
  1619.             default:if(Value >= 30)
  1620.                 {
  1621.                     if(Value <= 37)
  1622.                     {
  1623.                         if(Attributes & ATTR_INVERSE)
  1624.                             BgPen = Value - 30;
  1625.                         else
  1626.                             FgPen = Value - 30;
  1627.                     }
  1628.                     else
  1629.                     {
  1630.                         if(Value >= 40 && Value <= 47)
  1631.                         {
  1632.                             if(Attributes & ATTR_INVERSE)
  1633.                                 FgPen = Value - 40;
  1634.                             else
  1635.                                 BgPen = Value - 40;
  1636.                         }
  1637.                     }
  1638.                 }
  1639.  
  1640.                 break;
  1641.         }
  1642.     }
  1643.     while(Buffer);
  1644.  
  1645.     if(Attributes & ATTR_UNDERLINE)
  1646.         TextFlags |= FSF_UNDERLINED;
  1647.  
  1648.     if(Attributes & ATTR_HIGHLIGHT)
  1649.     {
  1650.         if(Config . ColourMode == COLOUR_SIXTEEN)
  1651.         {
  1652.             if(Attributes & ATTR_INVERSE)
  1653.                 BgPen |= 8;
  1654.             else
  1655.                 FgPen |= 8;
  1656.         }
  1657.         else
  1658.             TextFlags |= FSF_BOLD;
  1659.     }
  1660.  
  1661.     if(Attributes & ATTR_BLINK)
  1662.     {
  1663.         if(Config . Emulation == EMULATION_ANSIVT100)
  1664.         {
  1665.             switch(Config . ColourMode)
  1666.             {
  1667.                 case COLOUR_AMIGA:    if(Attributes & ATTR_INVERSE)
  1668.                                 BgPen = 3;
  1669.                             else
  1670.                                 FgPen = 3;
  1671.                             break;
  1672.  
  1673.                 case COLOUR_EIGHT:    if(Attributes & ATTR_INVERSE)
  1674.                                 BgPen |= 8;
  1675.                             else
  1676.                                 FgPen |= 8;
  1677.                             break;
  1678.  
  1679.                 case COLOUR_SIXTEEN:    break;
  1680.  
  1681.                 case COLOUR_MONO:    if(Attributes & ATTR_INVERSE)
  1682.                                 BgPen = 1;
  1683.                             else
  1684.                                 FgPen = 1;
  1685.                             break;
  1686.             }
  1687.         }
  1688.     }
  1689.  
  1690.     if(TextFlags != StyleType)
  1691.     {
  1692.         SetSoftStyle(RPort,TextFlags,0xFF);
  1693.  
  1694.         StyleType = TextFlags;
  1695.     }
  1696.  
  1697.     if(Config . ColourMode == COLOUR_MONO)
  1698.     {
  1699.         if(ColourValue(FgPen) < ColourValue(BgPen))
  1700.         {
  1701.             FgPen = 0;
  1702.             BgPen = 1;
  1703.         }
  1704.         else
  1705.         {
  1706.             FgPen = 1;
  1707.             BgPen = 0;
  1708.         }
  1709.     }
  1710.  
  1711.     if(FgPen != RPort -> FgPen)
  1712.         SetAPen(RPort,FgPen);
  1713.  
  1714.     if(BgPen != RPort -> BgPen)
  1715.         SetBPen(RPort,BgPen);
  1716.  
  1717.     return(NULL);
  1718. }
  1719.  
  1720.     /* SetRegion(UBYTE *Buffer):
  1721.      *
  1722.      *    Set the current scroll region top and bottom.
  1723.      */
  1724.  
  1725. UBYTE *
  1726. SetRegion(UBYTE *Buffer)
  1727. {
  1728.     WORD Value;
  1729.  
  1730.     WORD NewTop = 0;
  1731.     WORD NewBottom = LastLine;
  1732.  
  1733.     Buffer = ReadValue(Buffer,&Value);
  1734.  
  1735.     if(Value != -1)
  1736.     {
  1737.         NewTop = Value;
  1738.  
  1739.         if(Value)
  1740.             NewTop--;
  1741.  
  1742.         if(Buffer)
  1743.         {
  1744.             ReadValue(Buffer,&Value);
  1745.  
  1746.             if(Value > 0)
  1747.                 NewBottom = Value - 1;
  1748.         }
  1749.     }
  1750.  
  1751.     if(NewTop < NewBottom)
  1752.     {
  1753.         RegionSet = TRUE;
  1754.  
  1755.         if(NewTop == 0 && (NewBottom == LastLine || NewBottom == 24))
  1756.             RegionSet = FALSE;
  1757.  
  1758.         Top    = NewTop;
  1759.         Bottom    = NewBottom;
  1760.  
  1761.         ResetCursor();
  1762.     }
  1763.  
  1764.     return(NULL);
  1765. }
  1766.  
  1767. /*
  1768.  *    Reset cursor to top of screen
  1769.  */
  1770.  
  1771. VOID
  1772. ResetCursor()
  1773. {
  1774.     ClearCursor();
  1775.  
  1776.     CursorX    = 0;
  1777.  
  1778.     if(UseRegion && RegionSet)
  1779.         CursorY = Top;
  1780.     else
  1781.         CursorY    = 0;
  1782.  
  1783.     SetCursor();
  1784. }
  1785.