home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / DEMOVT15.ZIP / EXAMPLES.EXE / SETUP / READER.PAS < prev   
Pascal/Delphi Source File  |  1993-11-09  |  5KB  |  202 lines

  1. {$A+,B-,D+,E-,F-,G+,I-,L+,N-,O-,R-,S-,V-,X+}
  2. UNIT Reader;
  3.  
  4.    (* Copyright by Jare/Iguana in 1993, but given to the public domain. *)
  5.    (* Want more comments? Write'em!                                     *)
  6.  
  7.    (*   Text file reader. The text file can't be longer than it is now, *)
  8.    (* because I am a lazy coder and don't want to make a real scroller. *)
  9.    (* The text file must fit in the video memory, last six pages. That  *)
  10.    (* means 6*25 = 150 lines.                                           *)
  11.  
  12.    (*   Text colors are created on-the-fly, depending on the structure  *)
  13.    (* of the file, i.e. this line begins with '-', so make it yellow.   *)
  14.  
  15.    (*   This coloring idea came from the boss at my job. :-)            *)
  16.  
  17. INTERFACE
  18.  
  19. PROCEDURE ReadText;
  20.  
  21.  
  22.  
  23.    (* ========================================= *)
  24.  
  25. IMPLEMENTATION
  26.  
  27. USES
  28.    DOS,
  29.    Gfx, Output, HexConversions;
  30.  
  31.  
  32. PROCEDURE WriteLine(y : INTEGER; s : STRING);
  33. VAR
  34.    i   : INTEGER;
  35.    col : BYTE;
  36. BEGIN
  37.    col := 0;
  38.    FOR i := 1 TO Length(s) DO BEGIN
  39.        IF (col = 0) AND (s[i] <> ' ') THEN
  40.           IF (i = 2) THEN
  41.              col := 8
  42.           ELSE IF (s[i] = '-') THEN
  43.              col := 10
  44.           ELSE IF i = 10 THEN
  45.              col := 14
  46.           ELSE IF i = 17 THEN
  47.              col := 15
  48.           ELSE
  49.              col := 3;
  50.        Scr[y, i, 0] := BYTE(s[i]);
  51.        Scr[y, i, 1] := col;
  52.        IF (col = 14) AND ((s[i] = '-') OR (s[i] = ':')) THEN
  53.           col := 3;
  54.    END;
  55.    IF Length(s) < 80 THEN
  56.       FOR i := Length(s)+1 TO 80 DO BEGIN
  57.          Scr[y, i, 0] := 32;
  58.          Scr[y, i, 1] := col
  59.       END;
  60. END;
  61.  
  62.  
  63. VAR
  64.    NLines : INTEGER;
  65.    nfo    : ARRAY [1..200] OF STRING[80];
  66.    Pos    : WORD;
  67. CONST
  68.    key    : BYTE = 0;
  69.  
  70. PROCEDURE KbHandler; INTERRUPT;
  71. BEGIN
  72.    ASM
  73.         IN      AL,60h
  74.         TEST    AL,80h
  75.         JZ      @@ok
  76.          XOR    AL,AL
  77.      @@ok:
  78.         MOV     [key],AL
  79.  
  80.         IN      AL,61h
  81.         MOV     AH,AL
  82.         OR      AL,80h
  83.         OUT     61h,AL
  84.         MOV     AL,AH
  85.         OUT     61h,AL
  86.         MOV     AL,20h         { Signal EOI. }
  87.         OUT     20h,AL
  88.    END
  89. END;
  90.  
  91.  
  92. PROCEDURE ReadText;
  93. VAR
  94.    i   : INTEGER;
  95.    vel : INTEGER;
  96.    k   : BYTE;
  97.    time: INTEGER;
  98.    oldh : POINTER;
  99. BEGIN
  100.    SetKeyRate(0, 0);
  101.    GetIntVec(9, oldh);
  102.    SetIntVec(9, @KbHandler);
  103.    ClearScreen(scr[26]);
  104.    FOR i := 1 TO NLines DO
  105.       WriteLine(i+25*2, nfo[i]);
  106.    vel := 0;
  107.    i   := 0;
  108.    REPEAT
  109.       SetScanStart(i);
  110.       INC (vel);
  111.       i := i + vel DIV 7;
  112.    UNTIL i >= 25*16*1;
  113.    REPEAT
  114.       SetScanStart(i);
  115.       i := i + vel DIV 7;
  116.    UNTIL i >= Pos-25*16;
  117.    REPEAT
  118.       SetScanStart(i);
  119.       DEC (vel);
  120.       i := i + vel DIV 7;
  121.    UNTIL (i >= Pos) OR (vel = 0);
  122.    SetScanStart(Pos);
  123.  
  124.    vel  := 0;
  125.    time := 0;
  126.    REPEAT
  127. {            WriteLine(Pos DIV 16 + 3, HexByte(key));}
  128.       IF (Time > 0) OR (key <> 0) THEN BEGIN
  129.          IF key <> 0 THEN BEGIN
  130.             k := Key;
  131.             Key  := 0;
  132.             time := 3;
  133.          END;
  134.          CASE k OF
  135.             72 : IF (vel > -8*6) THEN DEC(vel,1);
  136.             80 : IF (vel <  8*6) THEN INC(vel,1);
  137.             81 : INC(vel, 3);
  138.             73 : DEC(vel, 3);
  139.          END;
  140.          DEC(time);
  141.       END ELSE
  142.          IF (vel > 0) THEN
  143.             DEC(vel,5)
  144.          ELSE IF (vel < 0) THEN
  145.             INC(vel,5);
  146.  
  147.       INC(Pos, vel DIV 8);
  148.  
  149.       IF (Pos < 25*16*2) THEN
  150.          Pos := 25*16*2
  151.       ELSE IF (Pos > (24+NLines)*16) THEN
  152.          Pos := (24+NLines)*16;
  153.  
  154.       SetScanStart(Pos)
  155.    UNTIL (k = 28) OR (k = 1);
  156.  
  157.    vel := 0;
  158.    i   := Pos;
  159.    REPEAT
  160.       SetScanStart(i);
  161.       DEC (vel);
  162.       i := i + vel DIV 7;
  163.    UNTIL i <= Pos-25*16;
  164.    REPEAT
  165.       SetScanStart(i);
  166.       i := i + vel DIV 7;
  167.    UNTIL i <= 25*16*1;
  168.    REPEAT
  169.       SetScanStart(i);
  170.       INC (vel);
  171.       i := i + vel DIV 7;
  172.    UNTIL (i <= 0) OR (vel = 0);
  173.    SetScanStart(0);
  174.    SetIntVec(9, oldh);
  175.    SetKeyRate(1, 12);
  176. END;
  177.  
  178.  
  179.   (* Here comes the reading of the text file. Shouldn't be here, but... *)
  180.  
  181. VAR
  182.    f   : TEXT;
  183.  
  184. BEGIN
  185.    Assign(f, 'DVT.NFO');
  186.    Reset(f);
  187.    nfo[1] := ' Browse the text with the cursor keys, PgUp & PgDn. Press ESC or RETURN to exit';
  188.    nfo[2] := ' ';
  189.    NLines := 2;
  190.    REPEAT
  191.       INC (NLines);
  192.       ReadLn(f, nfo[NLines])
  193.    UNTIL Eof(f);
  194.    Close(f);
  195.    IF IOResult <> 0 THEN BEGIN
  196.       WriteLn('DVT.NFO not found, aborting...');
  197.       WriteLn('Get the full version of DemoVT!');
  198.       HALT(1)
  199.    END;
  200.    Pos := 25*16*2
  201. END.
  202.