unit normtext;
{$A+,B-,D-,F-,G+,I+,L+,O-,P-,Q-,R-,T-,V+,X+,Y-}
interface
var
    Music : integer;

procedure RunText;

implementation
Uses dos, crt, normvga, normfont, normgus;

var
    BiosFlag    : Byte Absolute $0040 : $0017;
    OldInt091   : Pointer;
    TastLeft, F1: Boolean;
    TastRight, m: Boolean;
    TastStraight: Boolean;
    TastBack, n : Boolean;
    Taste : Char;
  F: Text;
  ec : integer;
  ep, e1 : boolean;
  S : array[0..199] of String;
  s2, s3 : string;
  Ch: Char;
  cursorxx : integer;
  Y : Integer;
  t,i : integer;
  oldoffset, offset, coffset : integer;
  CounterY : integer;

procedure PlayMusix(Nr : integer);
var s3 : string;
begin;
str(Nr,s3);
if GUSMOD then begin;
  _gus_initialisieren;
  if Music<10 then _gus_modload('SDT96.M0'+s3);
  if Music>=10 then _gus_modload('SDT96.M'+s3);
  fillchar(Play_Chanel,14,1);
  _gus_modstarten;
  ModPl:=True;
end;
end;
procedure StopMusix1;
begin;
if GUSMOD then begin;
FadeOut:=0;
repeat
vga.Wait(1);
inc(FadeOut);
until FadeOut=70;
_gus_mod_beenden;
FadeOut:=0;
end;
end;

procedure GlobalKeys;
begin;
if M then begin; {M}
 if GUSMOD then begin;
 if not ModPl then begin;
 _gus_player_continue;
 ModPl:=True;
 m:=False;
 end;
 end;
 end;

 if M then begin; {M}
 if GUSMOD then begin;
 if ModPl then begin;
 _gus_player_pause;
 ModPl:=False;
 m:=False;
 end;
 end;
 end;

 if n then begin;
 StopMusix1;
 inc(Music);
 if Music=9 then begin; Music:=1; end;
 PlayMusix(Music);
 n:=False;
 end;
end;

Procedure KbHandler; Interrupt;
Begin
If Port[$60] = $48 Then TastStraight:= True;
If Port[$60] = $C8 Then TastStraight:= False;
If Port[$60] = $50 Then TastBack:= True;
If Port[$60] = $D0 Then TastBack:= False;
If Port[$60] = $4B Then TastLeft:= True;
If Port[$60] = $CB Then TastLeft:= False;
If Port[$60] = $4D Then TastRight:= True;
If Port[$60] = $CD Then TastRight:= False;
If Port[$60] = $3B Then F1:= True;
If Port[$60] = $3B+$80 Then F1:= False;
If Port[$60] = $32 Then m:= True;
If Port[$60] = $32+$80 Then m:= False;
If Port[$60] = $31 Then n:= True;
If Port[$60] = $31+$80 Then n:= False;
If Port[$60] = 1 Then Taste:= #27;
If Port[$60] = $1c Then Taste:= #13;
If Port[$60] = $1c+$80 Then Taste:=#0;
Memw[$40:$1A]:= Memw[$40:$1C];
Asm
pushf
call dword ptr[OldInt091]
End;
Port[$20]:= $20;
End;

procedure SlideTextUp;
var slideoffset : integer;
begin;
SlideOffset:=14;
repeat
csr:=0;
offset:=1;
i:=0;
while (i<t) and (csr<12) do
begin
  inc(i);
  if (Pos('Û',s[i])>0) and (offset+1>=coffset) then Bold:=True;
  offset:=offset+1;
  if (offset>=coffset) and (csr<12) then begin;
  if csr=0 then begin;
  CopyMem2Mem(DritteSeite,ZweiteSeite,0,0,0,0,320,200);
  end;
  if Bold then
  begin
  if i>1 then Font.BoldPrint(S[i], 7, (csr*15)+11-SlideOffset, 0);
  Bold:=False;
  end
  else
  begin
  if i>1 then Font.Print(S[i], 7, (csr*15)+11-SlideOffset, 0);
  end;
  csr:=csr+1;
  end;
  Bold:=False;
end;
vga.MemBox(0,0,319,199,0,False);
CopyMem2Vram(ZweiteSeite,0,0,0,0,320,200);
dec(SlideOffset,2);
until SlideOffset<=1;
end;

procedure SlideTextDown;
var slideoffset : integer;
begin;
SlideOffset:=1;
repeat
csr:=0;
offset:=1;
i:=0;
while (i<t) and (csr<12) do
begin
  inc(i);
  if (Pos('Û',s[i])>0) and (offset+1>=coffset) then Bold:=True;
  offset:=offset+1;
  if (offset>=coffset) and (csr<12) then begin;
  if csr=0 then begin;
  CopyMem2Mem(DritteSeite,ZweiteSeite,0,0,0,0,320,200);
  end;
  if Bold then
  begin
  if i>1 then Font.BoldPrint(S[i], 7, (csr*15)+11-SlideOffset, 0);
  Bold:=False;
  end
  else
  begin
  if i>1 then Font.Print(S[i], 7, (csr*15)+11-SlideOffset, 0);
  end;
  csr:=csr+1;
  end;
  Bold:=False;
end;
vga.MemBox(0,0,319,199,0,False);
CopyMem2Vram(ZweiteSeite,0,0,0,0,320,200);
inc(SlideOffset,2);
until SlideOffset>=14;
end;

procedure ShowTextPage;
begin;
vga.Init(False);
vga.ReadGFX('MARMOR.GFX',True);
vga.MemBox(0,0,319,199,0,False);
CopyMem2Mem(ZweiteSeite,DritteSeite,0,0,0,0,320,200);
Assign(F, 'topgum.dat');
Reset(F);
inc(cursorxx);
t:=1;
ec:=0;
s[t]:='';
e1:=False;
repeat
Read(F,ch);
if ord(ch)=10 then ch:=#0;
if ch='Ÿ' then
begin;
repeat
Read(F,ch);
until (ch=#13);
ch:='Ÿ';
inc(ec);
end;
if (ec=cursorxx) and (not (ch='Ÿ')) then begin;
if (Ord(ch)=13) then
begin
inc(t);
s[t]:='';
end
else
begin
if (not (ch=#0)) then s[t]:=s[t]+ch;
end;
end;
until (eof(F)) or (t>=199) or (ec=cursorxx+1);
e1:=False;
Close(F);
Coffset:=1;
Repeat
csr:=0;
offset:=0;
i:=0;
while (i<t) and (csr<12) do
begin
  inc(i);
  if (Pos('Û',s[i])>0) and (offset+1>=coffset) then Bold:=True;
  offset:=offset+1;
  if (offset>=coffset) and (csr<12) then begin;
  if csr=0 then begin;
  CopyMem2Mem(DritteSeite,ZweiteSeite,0,0,0,0,320,200);
  end;
  if Bold then
  begin
  Font.BoldPrint(S[i], 7, (csr*15)+11, 0);
  Bold:=False;
  end
  else
  begin
  Font.Print(S[i], 7, (csr*15)+11, 0);
  end;
  csr:=csr+1;
  end;
  Bold:=False;
end;
vga.MemBox(0,0,319,199,0,False);
CopyMem2Vram(ZweiteSeite,0,0,0,0,320,200);
if DEBUG then begin;
if GUSMOD then vga.Print('Soundcard: GUS',1,1,30);
if {(not SB_MOD) and} (not GUSMOD) then vga.Print('No Sound',1,1,30);
str(MemAvail,s3);
vga.Print(s3+ ' bytes Heap available',1,18,30);
str(MaxAvail,s3);
vga.print('Largest Heap block '+ s3, 1,27,30);
end;
repeat
GlobalKeys;
until (Taste=#27) or (TastStraight) or (TastBack);
if (TastBack) and (Coffset<(t-12)) then begin; inc(Coffset); SlideTextDown; end;
if (TastStraight) and (Coffset>1) then begin; SlideTextUp; dec(Coffset); end;
until (Taste=#27);
Taste:=#0;
vga.FadeOutAll;
vga.Done;
end;
{
procedure SlideUp;
var slideoffset : integer;
begin;
SlideOffset:=15;
repeat
dec(SlideOffset);
csr:=0;
offset:=1;
i:=0;
while (i<t) and (csr<12) do
begin
  inc(i);
  offset:=offset+1;
  if (offset>=coffset) and (csr<12) then begin;
  if csr=0 then begin;
  CopyMem2Mem(DritteSeite,ZweiteSeite,0,0,0,0,320,200);
  end;
  if Cursorxx-1=csr then
  begin
  Font.BoldPrint(S[i], 7, (csr*15)+11, 1);
  end
  else
  begin
  Font.BoldPrint(S[i], 7, (csr*15)+11, 0);
  end;
  csr:=csr+1;
  end;
end;
vga.MemBox(0,0,319,199,0,False);
CopyMem2Vram(ZweiteSeite,0,0,0,0,320,200);
until SlideOffset<=0;
end;

procedure SlideDown;
var slideoffset : integer;
begin;
SlideOffset:=0;
repeat
inc(SlideOffset);
csr:=0;
offset:=1;
i:=0;
while (i<t) and (csr<12) do
begin
  inc(i);
  offset:=offset+1;
  if (offset>=coffset) and (csr<12) then begin;
  if csr=0 then begin;
  CopyMem2Mem(DritteSeite,ZweiteSeite,0,0,0,0,320,200);
  end;
  if Cursorxx-1=csr then
  begin
  Font.BoldPrint(S[i], 7, (csr*15)+11, 1);
  end
  else
  begin
  Font.BoldPrint(S[i], 7, (csr*15)+11, 0);
  end;
  csr:=csr+1;
  end;
end;
vga.MemBox(0,0,319,199,0,False);
CopyMem2Vram(ZweiteSeite,0,0,0,0,320,200);
until SlideOffset>=14;
end;
}


procedure RunText;
Begin;

{Font.Init;}
vga.Init(False);
vga.ReadGFX('MARMOR.GFX',True);
vga.MemBox(0,0,319,199,0,False);
CopyMem2Mem(ZweiteSeite,DritteSeite,0,0,0,0,320,200);
BiosFlag := BiosFlag or 32;
Asm
mov ah,01h
int 16h
End;
GetIntVec($09,OldInt091);
SetIntVec($09,Addr(KbHandler));
repeat
Assign(F, 'topgum.dat');
Reset(F);
t:=1;
s[t]:='';
e1:=False;
repeat
Read(F,ch);
if ch=#10 then ch:=#0;
if ch='Ÿ' then e1:=True;
if (Ord(ch)=13) and (not e1) then
begin
inc(t);
s[t]:='';
end
else
begin
if (not e1) and (not (ch=#0)) then s[t]:=s[t]+ch;
end;
until (eof(F)) or (t>=199) or (e1);
e1:=False;
Close(F);
cursorxx:=1;
coffset:=1;
oldoffset:=1;
Taste:=#0;
ep:=False;
Repeat
OldOffset:=coffset;
csr:=0;
offset:=0;
i:=0;
while (i<t) and (csr<12) do
begin
  inc(i);
  offset:=offset+1;
  if (offset>=coffset) and (csr<12) then begin;
  if csr=0 then begin;
  CopyMem2Mem(DritteSeite,ZweiteSeite,0,0,0,0,320,200);
  end;
  if Cursorxx-1=csr then
  begin
  Font.BoldPrint(S[i], 7, (csr*15)+11, 1);
  end
  else
  begin
  Font.BoldPrint(S[i], 7, (csr*15)+11, 2);
  end;
  csr:=csr+1;
  end;
end;
vga.MemBox(0,0,319,199,0,False);
CopyMem2Vram(ZweiteSeite,0,0,0,0,320,200);
if DEBUG then begin;
if GUSMOD then vga.Print('Soundcard: GUS',1,1,30);
if {(not SB_MOD) and} (not GUSMOD) then vga.Print('No Sound',1,1,30);
str(MemAvail,s3);
vga.Print(s3+ ' bytes Heap available',1,18,30);
str(MaxAvail,s3);
vga.print('Largest Heap block '+ s3, 1,27,30);
end;
if oldoffset<>coffset then
begin
oldoffset:=coffset;
end
else
begin
vga.Wait(6);
end;
repeat
GlobalKeys;
until (Taste=#27) or (Taste=#13) or (TastStraight) or (TastBack);
if (TastBack) and (Cursorxx<(t-coffset-1)) then begin; inc(Cursorxx);
if (Coffset<t) and (cursorxx>12) then begin; inc(Coffset); Cursorxx:=12; end; end;
if (TastStraight) then begin; dec(Cursorxx);
if (Coffset>1) and (cursorxx<1) then
begin dec(Coffset); Cursorxx:=1;
end
else
begin
if (Coffset=1) and (cursorxx<1) then cursorxx:=1;
end;
end;
until (Taste=#27) or (Taste=#13);
if Taste=#27 then ep:=True;
cursorxx:=coffset-1+cursorxx-1;
{str(cursorxx,s2);
vga.Print(s2,20,20,50);
readln;}
if (not ep) then begin;
vga.FadeOutAll;
vga.ClearScreen;
vga.Done;
ShowTextPage;
vga.Init(False);
vga.ReadGFX('MARMOR.GFX',True);
vga.MemBox(0,0,319,199,0,False);
CopyMem2Mem(ZweiteSeite,DritteSeite,0,0,0,0,320,200);
end;
until ep;
vga.FadeOutAll;
{Font.Done;}
vga.Done;
SetIntVec($09,OldInt091);
end;

begin
end.