home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TOOL_INC.ZIP / POP2.INC < prev    next >
Encoding:
Text File  |  1988-01-29  |  4.7 KB  |  225 lines

  1.  
  2. (*
  3.  * popup - utility library for simple "pop-up" windows
  4.  *
  5.  * written by Samuel H. Smith, 7-Feb-86 (rev. 13-nov-87)
  6.  *
  7.  *)
  8.  
  9. var
  10.   Vmode:       byte    absolute $0040:$0049;   {Current video mode}
  11.  
  12. {video modes}
  13. const
  14.   NoDisplay = $00;   VgaMono   = $07;
  15.   MdaMono   = $01;   VgaColor  = $08;
  16.   CgaColor  = $02;   DCC9      = $09;
  17.   DCC3      = $03;   DCC10     = $0A;
  18.   EgaColor  = $04;   McgaMono  = $0B;
  19.   EgaMono   = $05;   McgaColor = $0C;
  20.   PgcColor  = $06;   Unknown   = $FF;
  21.  
  22. const
  23.    low_attr:  integer = 7;
  24.    norm_attr: integer = 15;
  25.    back_attr: integer = 0;
  26.  
  27. type
  28.    popup_string = string[255];
  29.  
  30.    screenloc =         record
  31.          character:          char;
  32.          attribute:          byte;
  33.    end;
  34.  
  35.    videoram =          array [0..1999] of screenloc;
  36.    videoptr =          ^videoram;
  37.  
  38.    window_rec = record
  39.       x1,y1,x2,y2: integer;
  40.       attr:        byte;
  41.    end;
  42.  
  43.    window_save_rec = record
  44.       win:      window_rec;
  45.       scr:      videoram;
  46.       cux,cuy:  integer;
  47.    end;
  48.  
  49.  
  50. var
  51.    cur_window:   window_rec;
  52.    saved_window: window_save_rec;
  53.    disp_mem:     videoptr;
  54.  
  55.  
  56. procedure setcolor(fg,bg: integer);
  57. begin
  58.    bg := bg and 7;
  59.    textcolor(fg);
  60.    textbackground(bg);
  61.    cur_window.attr := fg + bg shl 4;
  62. end;
  63.  
  64. procedure normvideo;
  65. begin
  66.    setcolor(norm_attr,back_attr);
  67. end;
  68.  
  69. procedure lowvideo;
  70. begin
  71.    setcolor(low_attr,back_attr);
  72. end;
  73.  
  74. procedure old_window(win: window_rec);   {redefine the old window
  75.                                           command so it can still be
  76.                                           used by other procs}
  77. begin
  78.    with win do
  79.       window(x1,y1,x2,y2);
  80. end;
  81.  
  82. procedure window(a1,b1,a2,b2: integer);    {make a new version of window
  83.                                             that saves the current state}
  84. begin
  85.    with cur_window do
  86.    begin
  87.       x1 := a1;
  88.       y1 := b1;
  89.       x2 := a2;
  90.       y2 := b2;
  91.    end;
  92.  
  93.    old_window(cur_window);
  94. end;
  95.  
  96.  
  97.  
  98. function make_string(c: char; len: integer): popup_string;
  99.    {make a string by repeating a character n times}
  100. var
  101.    i:  integer;
  102.    s:  popup_string;
  103. begin
  104.    for i := 1 to len do
  105.       s[i] := c;
  106.  
  107.    s[0] := chr(len);
  108.    make_string := s;
  109. end;
  110.  
  111.  
  112. procedure disp (s:                  popup_string);
  113.    {very fast dma string display}
  114. var
  115.    index:              integer;
  116.    i:                  integer;
  117.    c:                  char;
  118.    len:                integer;
  119.    max_index:          integer;
  120.  
  121. begin
  122.  
  123.    with cur_window do
  124.    begin
  125.       len := ord(s[0]);
  126.       index :=(wherey + y1 - 2)* 80 +(wherex + x1 - 2);
  127.       max_index := y2*80;
  128.  
  129.       for i := 1 to len do
  130.       begin
  131.          c := s [i];
  132.  
  133.          case c of
  134.             ^H:   dec(index);
  135.  
  136.             ^J:   begin
  137.                      index := index + 80;
  138.                      if index >= max_index then
  139.                      begin
  140.                         write(^J);
  141.                         index := index - 80;
  142.                      end;
  143.                   end;
  144.  
  145.             ^M:   index :=(index div 80)* 80 + x1 - 1;
  146.  
  147.             ^G:   write(^G);
  148.  
  149.             else  begin
  150.                      with disp_mem^[index] do
  151.                      begin
  152.                         character := c;
  153.                         attribute := attr;
  154.                      end;
  155.  
  156.                      inc(index);
  157.  
  158.                      if index >= max_index then
  159.                      begin
  160.                         index := index - 80;
  161.                         writeln;
  162.                      end;
  163.                   end;
  164.          end;
  165.       end;
  166.  
  167. (* place cursor at end of displayed string *)
  168.       gotoxy((index mod 80)- x1 + 2,(index div 80)- y1 + 2);
  169.    end;
  170. end;
  171.  
  172.  
  173.  
  174. procedure displn(s: popup_string);       {fast display and linefeed}
  175. begin
  176.    disp(s);
  177.    writeln;
  178. end;
  179.  
  180.  
  181. procedure save_window(var saved: window_save_rec);
  182.    (* save the current window so it can be restored later *)
  183. begin
  184.    saved.scr := disp_mem^;
  185.    saved.win := cur_window;
  186.    saved.cux := wherex;
  187.    saved.cuy := wherey;
  188. end;
  189.  
  190.  
  191. procedure restore_window(saved: window_save_rec);
  192.    (* restore the windowing settings *)
  193. begin
  194.    cur_window := saved.win;
  195.    old_window(cur_window);
  196.  
  197. (* restore the cursor position *)
  198.    gotoxy(saved.cux,saved.cuy);
  199.  
  200. (* restore the display contents *)
  201.    disp_mem^ := saved.scr;
  202.  
  203. (* restore current video mode *)
  204.    if cur_window.attr = low_attr then
  205.       lowvideo
  206.    else
  207.       normvideo;
  208. end;
  209.  
  210.  
  211. procedure init_pop_up;
  212.    {call once before anything else in this library}
  213. begin
  214.    case Vmode of
  215.       MdaMono, VgaMono:
  216.          disp_mem := ptr($B000,0);
  217.       else
  218.          disp_mem := ptr($B800,0);
  219.    end;
  220.  
  221.    window(1,1,80,25);
  222.    normvideo;
  223. end;
  224.  
  225.