home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / MULTIMAP.ZIP / MULTIMAP.BOX next >
Encoding:
Text File  |  1985-10-02  |  13.0 KB  |  439 lines

  1. TYPE Int_Rec     = RECORD
  2.                  AX,
  3.                  BX,
  4.                  CX,
  5.                  DX,
  6.                  BP,SI,DI,DS,ES,FLAGS: integer;
  7.                 END;
  8.  
  9.   Valid_pages         =  0..7;
  10.   Valid_Line          =  1..25;
  11.   Valid_Column        =  1..80;
  12.   Map_string          =  String[80];
  13.   Valid_Functionkeys  =  0..40;
  14.   Data_Pointer        =  ^Map_data;
  15.   Pointers            =  record
  16.                           First_field,
  17.                           Last_Field:   Data_Pointer;
  18.                          end;
  19.  
  20.   Map_Data     = record
  21.                   Previous_field,               (*  Pointers for           *)
  22.                   Next_field : Data_Pointer;    (*   linked list           *)
  23.                   ForeColor,                    (*  Foreground Color       *)
  24.                   BackColor  : Byte;            (*  Background Color       *)
  25.                   Line_Num   : Valid_Line;      (*  Line Number            *)
  26.                   Column_Num : Valid_Column;    (*  Column Number          *)
  27.                   Max_Len    : 0..80;           (*  Maximum Length of data *)
  28.                   Data       : Map_string;      (*  This is the field      *)
  29.                  end; {of record definition }
  30.  
  31. VAR
  32.     Intregs               :  Int_rec;
  33.     This_Field            :  Data_Pointer;
  34.     Functionkey_Pressed,
  35.      Escape               :  Boolean;
  36.     Functionkey           :  Valid_Functionkeys;
  37.     Pointer_Table         :  Array[Valid_Pages] of Pointers;
  38.  
  39. (******************************************)
  40. (* Reset the pointers for a page          *)
  41. (* Dispose of all pointers for this page  *) 
  42. (******************************************)
  43. Procedure Reset_Page(Page : Valid_Pages);
  44. Begin 
  45.  This_Field := Pointer_Table[Page].First_Field;
  46.  If This_Field <> Nil then
  47.  repeat
  48.   Dispose(This_Field^.Previous_Field);
  49.   This_Field := This_Field^.Next_Field;
  50.  Until This_Field = Pointer_Table[Page].Last_Field;
  51.  Pointer_Table[Page].First_Field := Nil;
  52.  Pointer_Table[Page].Last_Field := Nil;
  53. End;
  54.  
  55. (************************************)
  56. (* Initialize the Pointer Table     *)
  57. (************************************)
  58.  
  59. Procedure Init_Paging;
  60. Var x : Byte;
  61. Begin 
  62. For x := 0 to 7 do
  63.  Begin 
  64.   Pointer_Table[x].First_Field := Nil;
  65.   Pointer_Table[x].Last_Field := Nil
  66.  End;
  67. End;
  68.  
  69. (************************************)
  70. (*   Sets the size of the cursor    *)
  71. (************************************)
  72.  
  73. Procedure Cursorsize(Start,Stop:Byte);
  74. begin       
  75.  With Intregs do
  76.    begin
  77.      ax:=1 shl 8;
  78.      cx:=(Start shl 8) + Stop;
  79.      intr($10,Intregs)
  80.    end
  81. end;
  82.  
  83. (*************************************)
  84. (*       Shows a given page          *)
  85. (*************************************)
  86.  
  87. PROCEDURE Displaypage(Pagenumber:Valid_pages);
  88. Begin
  89.    With Intregs DO
  90.         Begin
  91.             ax:= (5 shl 8)+Pagenumber; { ax = function code 5 in the high }
  92.             INTR($10,INTREGS)          { issue interupt for  video_io  }
  93.         End
  94. End;
  95.  
  96. (********************************************)
  97. (*       Positions cursor on a page         *)
  98. (********************************************)
  99. Procedure Gotolc(  Line    : Valid_Line;
  100.                    Column  : Valid_Column;
  101.                    Page    : Valid_Pages );
  102.  
  103. Begin
  104.  With Intregs DO
  105.   Begin
  106.    AX := 2 SHL 8;
  107.    BX := (BX and $ff) or (Page SHL 8);
  108.    DX := ((Line-1) shl 8) + Column-1;
  109.    INTR($10,Intregs)
  110.   End
  111. End; { of Gotolc }
  112.  
  113. (**********************************************)
  114. (*  Writes the string at the cursor position  *)
  115. (*  with the specified colors                 *)
  116. (**********************************************)
  117.  
  118. Procedure Place(  Txt          : Map_String;
  119.                   Page         : Valid_pages;
  120.                   Foreground,
  121.                   Background   :Byte      );
  122.  
  123. Var I:Byte;
  124. Begin
  125.   With Intregs DO
  126.     Begin
  127.       BX := BX AND $ff;
  128.       BX := BX OR ( Page SHL 8 );
  129.       If Background IN [0..7] Then Begin
  130.                                     BX := BX AND $FF8F;
  131.                                     BX := Bx OR (Background SHL 4)
  132.                                    End;
  133.  
  134.       IF Foreground IN [0..31] Then Begin
  135.                                       BX := BX AND $FF70;
  136.                                       IF Foreground>15 THEN BX:=BX OR $80;
  137.                                       Foreground:=Foreground and $0f;
  138.                                       BX := BX OR Foreground
  139.                                     End;
  140.       For I:=1 To Length(Txt) DO
  141.          Begin
  142.           CX := 1;
  143.           AX:= 9 SHL 8 + Ord(Txt[I]);
  144.           INTR($10,Intregs);         (* Write one character *)
  145.           AX:=3 SHL 8;
  146.           INTR($10,Intregs);         (* Get cursor Position *)
  147.           DX:=DX+1;                  (* Add one column      *)
  148.           AX:=2 SHL 8;
  149.           INTR($10,Intregs)          (* Move cursor         *)
  150.          END
  151.     End { of with Intregs}
  152. End;
  153.  
  154. (**********************************************)
  155. (*   Write a string on a page                 *)
  156. (**********************************************)
  157. Procedure Map( Txt         :  Map_string;
  158.                Page        :  Valid_Pages;
  159.                Line        :  Valid_Line;
  160.                Column      :  Valid_Column;
  161.                Foreground,
  162.                Background  :  byte );
  163.  
  164.  Begin
  165.     Gotolc(Line,Column,Page);
  166.     Place(Txt,Page,Foreground,Background)
  167.  End;
  168.  
  169.  
  170.  PROCEDURE MAPU( Txt         :  Map_string;
  171.                  Page        :  Valid_Pages;
  172.                  Line        :  Valid_Line;
  173.                  Column      :  Valid_Column;
  174.                  Foreground,
  175.                  Background  :  byte );
  176.      BEGIN
  177.       map(Txt,Page,Line,Column,Foreground,Background);
  178.       new(This_Field);
  179.       If Pointer_Table[Page].First_Field=nil then
  180.        begin
  181.          Pointer_Table[Page].First_Field:=This_Field;
  182.          Pointer_Table[Page].Last_Field:=This_Field
  183.        end;
  184.       with This_Field^ do
  185.         begin
  186.          Forecolor      := Intregs.BX and $008F;
  187.          Backcolor      := (Intregs.BX and $70) shr 4;
  188.          Line_Num       := Line;
  189.          Column_Num     := Column;
  190.          Max_Len        := length(Txt);
  191.          Data           := '';
  192.          Next_Field     := Pointer_Table[Page].First_Field;
  193.          Previous_Field := Pointer_Table[Page].Last_Field;
  194.          Pointer_Table[Page].Last_Field := This_Field;
  195.          If Previous_Field<>This_Field then
  196.            Previous_Field^.Next_Field := This_field;
  197.          Pointer_Table[page].First_Field^.Previous_Field := This_Field;
  198.        end;
  199.      END;
  200.  
  201. Procedure Clearpage(Page, 
  202.                     Color : Valid_Pages);
  203. Begin
  204. Gotolc(1,1,Page);
  205. With Intregs DO
  206.   Begin
  207.    CX := 2000;
  208.    BX := (Page SHL 8) + (Color shl 4) ;
  209.    If Color = 0  then BX := BX + 7;     (* Eliminates Black on Black *)
  210.    AX := (9 SHL 8)+32;
  211.    INTR($10,INTREGS);
  212.   END;
  213. END;
  214.  
  215. Function Get_Data( Page  : Valid_Pages;
  216.                    Field : Byte)      
  217.                                  : Map_String;
  218. Var Hold : String[2];
  219.     x    : Integer;
  220.  
  221. Begin
  222.  This_Field := Pointer_Table[Page].First_field;
  223.  If This_Field=Nil then begin
  224.                          Clrscr;
  225.                          Str(Page,Hold);
  226.                          map('Error locating data for page ' +hold,page,1,1,red,black);
  227.                         end
  228.  Else
  229.  Begin 
  230.   For x:= 1 to Field-1 do
  231.      This_Field:= This_Field^.Next_Field;
  232.  
  233.   With This_Field^ do Get_Data :=Data;
  234.  End;
  235. End; {of Data Function}
  236.  
  237.  
  238. PROCEDURE ReadMap( Page:Valid_Pages;   (* Page number to be processed *)
  239.                    Start:Integer);     (* Position cursor at the Nth field *)
  240.  
  241. VAR Return:BOOLEAN;A:CHAR;X,Y:INTEGER;
  242.  
  243. Procedure Get_Starting_Field( Page:Valid_Pages;
  244.                               Start:Integer);
  245. Var hold:String[2];
  246. Begin
  247.  This_Field := Pointer_Table[Page].First_field;
  248.  If This_Field=Nil then begin
  249.                          Clrscr;
  250.                          Str(Page,Hold);
  251.                          map('Error locating data for page ' +hold,page,1,1,red,black);
  252.                         end
  253.  Else
  254.  Begin 
  255.   For x:= 1 to Start-1 do
  256.      This_Field:= This_Field^.Next_Field;
  257.  
  258.   With This_Field^ do
  259.    Begin
  260.     Textcolor(Forecolor);
  261.     TextBackground(Backcolor);
  262.     GotoLC(Line_Num,Column_Num,Page);
  263.    end;
  264.  End;
  265. End; {of Get_Starting_Field}
  266.  
  267. Procedure Get_Cursor_Position;
  268. Begin
  269. With Intregs do
  270. Begin
  271.   AX := 3 shl 8;
  272.   BX := Page shl 8;
  273.   Intr($10,Intregs);
  274.   x:= (DX and $00FF)+1;
  275.   y:= ( (DX and $FF00) shr 8) +1;
  276. End;
  277. End;
  278.  
  279. Procedure BackTab;
  280.  Begin
  281.   Get_Cursor_Position;
  282.   With This_Field^ do If x = Column_Num then This_Field := Previous_Field;
  283.   With This_Field^ do GotoLC(Line_Num,Column_Num,page)
  284.  end;
  285.  
  286. Procedure Goto_Next_Field;
  287. Begin
  288.   This_Field := This_Field^.Next_field;
  289.   With This_Field^ DO GotoLC(Line_Num,Column_num,Page);
  290. End;
  291.  
  292. Procedure Write_Char;
  293. Begin
  294. Get_Cursor_Position;
  295. With This_Field^ do
  296.   begin
  297.    map(A,Page,y,x,Forecolor,Backcolor);
  298.    Data[x-Column_Num+1] := a;
  299.    If x-Column_Num+1 > Length(Data) then
  300.        Data[0] := chr(Length(data) + 1);
  301.    If x+2 > Column_Num+Max_Len then Goto_Next_Field;
  302.   end;
  303. End;
  304.  
  305. Procedure Set_Functionkey;                (* Regular Function Keys  F1  - F10 *)
  306. Begin                                     (* Shift + Function Key = F11 - F20 *)
  307.  Functionkey_Pressed := True;             (* Ctrl + Function Key  = F21 - F30 *)  
  308.   Case Ord(A) of                          (* Alt + Functionkey    = F31 - F40 *)
  309.    59..68  : Functionkey := Ord(A)-58;    
  310.    84..113 : Functionkey := Ord(A)-73;    
  311.   End;
  312. End;
  313.  
  314. Procedure Get_Extended_Code;
  315. Begin
  316.  Read(Kbd,A);
  317.  Case Ord(A) of
  318.   59..68,84..113: Set_Functionkey;
  319.  
  320.   75 : { Left Arrow }
  321.        Begin
  322.          Get_Cursor_Position;
  323.          If x > This_Field^.Column_Num then
  324.                 Begin
  325.                   x := x-1;
  326.                   GotoLc(y,x,Page);
  327.                 End
  328.            Else BackTab;
  329.        End;
  330.  
  331.   77 : { Right Arrow }
  332.        Begin
  333.          Get_Cursor_Position;
  334.          With This_Field^ DO
  335.             If x+2 > Column_Num + Max_Len Then Goto_Next_Field
  336.                Else GotoLC(y,x+1,Page);
  337.        End;
  338.  
  339.   80 : { Down Arrow }
  340.        Begin 
  341.          Repeat
  342.            If This_Field^.Line_Num = This_Field^.Next_Field^.Line_Num
  343.               then This_Field := This_Field^.Next_Field;
  344.          Until (This_Field^.Line_num <> This_Field^.Next_Field^.Line_Num)
  345.             or (This_Field = Pointer_Table[Page].Last_Field);
  346.          Goto_Next_Field;
  347.        End;
  348.  
  349.   72 : { Up Arrow }
  350.        Begin 
  351.          Repeat
  352.            This_Field := This_Field^.Previous_Field;
  353.          Until (This_Field^.Line_Num <> This_Field^.Next_Field^.Line_Num)
  354.            or (This_Field = Pointer_Table[Page].Last_Field);
  355.          Repeat
  356.            This_Field := This_Field^.Previous_Field;
  357.          Until (This_Field^.Line_Num <> This_Field^.Next_Field^.Line_Num)
  358.            or (This_Field = Pointer_Table[Page].Last_Field);
  359.          Goto_Next_Field;
  360.        End;
  361.  
  362.  
  363.   15 : {Left Tab}
  364.        Begin 
  365.          This_Field := This_Field^.Previous_Field;
  366.          With This_Field^ DO GotoLC(Line_Num,Column_Num,Page);
  367.        End;
  368.  
  369.   71 : { Home }
  370.        Begin 
  371.          This_Field := Pointer_Table[Page].First_Field;
  372.          With This_Field^ DO GotoLC(Line_Num,Column_Num,Page);
  373.        End;
  374.  
  375.   79 : { End }
  376.        Begin 
  377.          This_Field := Pointer_Table[Page].Last_Field;
  378.          With This_Field^ DO GotoLC(Line_Num,Column_Num,Page);
  379.        End;
  380.  
  381.   82 : { Insert }
  382.        Begin 
  383.          Get_Cursor_Position;
  384.          With This_Field^ do
  385.          Begin 
  386.            Insert(' ',Data,x-Column_Num+1 );
  387.            If Length(Data) > Max_Len then Data[0] := Chr(Max_Len);
  388.            map(Data,Page,Line_Num,Column_Num,Forecolor,Backcolor);
  389.          End;
  390.          GotoLc(y,x,page);
  391.        End;
  392.  
  393.   83 : { Delete }
  394.        Begin
  395.           Get_Cursor_Position;
  396.           With This_Field^ do
  397.           Begin
  398.             Delete(Data,x-Column_Num+1,1);
  399.             Insert(' ',Data,Length(data)+1);
  400.             map(Data,Page,Line_Num,Column_Num,Forecolor,Backcolor);
  401.             Delete(data,Length(data),1);
  402.           End;
  403.           GotoLc(y,x,page);
  404.        End;
  405.  
  406.  
  407.  end; { of cases }
  408. End;
  409.  
  410. BEGIN                (***** This is the real start of Readmap  ***********)
  411.  Displaypage(page);  (* Ensures correct display *)
  412.  Return := False;
  413.  Functionkey_Pressed := False;
  414.  Functionkey := 0;
  415.  Escape := False;
  416.  Get_Starting_Field(Page,Start);
  417.  REPEAT
  418.  
  419.   READ(KBD,A);
  420.   case ord(a) of
  421.     8: BackTab;
  422.     9: {Right Tab}
  423.        Begin
  424.         This_Field := This_Field^.Next_Field;
  425.         With This_Field^ DO GotoLC(Line_Num,Column_Num,Page);
  426.        End;
  427.    13: {Return Key} Return := True;
  428.    Else
  429.     If Ord(A) in [32..126] then write_char
  430.       Else
  431.        If (Ord(A) = 27) and (not Keypressed) then Escape := True
  432.          Else Get_Extended_Code;
  433.   End; { of cases }
  434.  Until Return or Functionkey_Pressed or Escape;
  435. END;    {Of ReadMap Procedure}
  436.  
  437.  
  438.  
  439.