home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-386-Vol-2of3.iso
/
c
/
ctkit11.zip
/
CTGRAPH.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1991-12-20
|
17KB
|
719 lines
Unit CTGraph;
interface
uses
ctu, graph, rdrivers, rfonts, crt, async2, ctsoundu, dos;
const
maxmemused = 20000; {31043;}
type
Images = array[1..MaxMemUsed] of word;
ColType = Array [0..3] of boolean;
CDType = array[1..2] of integer;
TPicType = array[1..2000] of word;
SeriesType = record
r, ExNum: byte;
ComStr: string[10];
end;
AnimType = record
PicN, Way: byte;
x, y, pause: word;
end;
var
lastok, grmode, ExitCT, Respon: boolean;
Pic: ^Images;
x1, y1, x2, y2, ndex, Fill1, Fill2, hx1, hx2, hy1, hy2,
sx1, sy1, sx2, sy2, scramt: word;
MemUsed: longint;
gd, gm, apage, vpage: integer;
{ global variables for screen mode }
{ always remember to give 'em a value if yer using
bitsizeof or stetobit. }
TPic: ^TPicType;
Pics: Array[1..200] of pointer;
PSizes: Array[1..200] of word;
CurPic: byte;
CurFN: string;
PicFile: file;
ExStrings: array[1..5] of string;
Series: array[1..3,1..9] of SeriesType;
Film: array[1..30,1..10] of AnimType;
Frames: array[1..30] of byte;
TheTime: longint;
Procedure DoCode (R: byte; ComStr, ExStr: String);
implementation
{$I SCSTUFF.PAS}
Procedure LoadPic(FName: string; Pos, len: Longint; PNum: byte);
{len in bytes;
pos starts at 0, also bytes}
var
a: integer;
fnd: boolean;
x: char;
s: string[10];
begin
{ Write ('Loading pic #,',pnum,'(',Fname,' ',pos,' ',len,') '); }
if FName <> CurFN then
begin
CurFN := FName;
{$I-}
Close (PicFile);
if Ioresult <> 0 then
;
Assign (PicFile, Cnf.CTDir+FName);
Reset (PicFile, 1);
{$I+}
if IOResult <> 0 then
begin
Assign (PicFile, FName);
{$I-}
Reset(PicFile,1);
{$I+}
if IOresult <> 0 then
begin
if grmode then
OutText('ERROR! File '+FName+' not found!')
else
writeln ('ERROR! File '+FName+' not found!');
{ Writeln ('Pos: ',Pos,' Len: ',Len,' PNum: ',PNum); }
CurFN := '';
lastok := false;
PSizes[PNum] := 0;
GetMem(Pics[Pnum],0);
Exit;
end;
end;
end;
a := filesize(PicFile);
{
if a < Len+Pos then
begin
lastok := false;
PSizes[PNum] := 0;
GetMem(Pics[Pnum],0);
Exit;
end;
}
if Len = 0 then
len := filesize(PicFile);
Ndex := Len div 2;
Seek(PicFile,Pos);
BlockRead (PicFile, Pic^[1], Len);
if pic^[2] = 9900 then
begin
{ Writeln (MemAvail); }
SteToBit (ndex);
end;
FreeMem (Pics[PNum],PSizes[PNum]);
PSizes[PNum] := ndex*2;
GetMem (Pics[PNum], PSizes[PNum]);
Move (Pic^, Pics[PNum]^, ndex*2);
end;
Procedure LoadSong (songnum: byte; numinfile: word; fn: string);
begin
FillChar (Song[songnum], sizeof(Songs), 0);
Assign (SongFile, cnf.ctdir+fn);
{$I-}
Reset (SongFile, 1);
{$I+}
if IOResult <> 0 then
begin
Assign (SongFile, fn);
{$I-}
Reset (SongFile, 1);
{$I+}
if IOResult <> 0 then
begin
writeln ('ERROR! File ',FN,' not found!');
lastok := false;
exit;
end;
end;
Seek (SongFile, NumInFile);
BlockRead (SongFile, Song[SongNum], SizeOf(Songs));
Close (SongFile);
end;
Procedure SwitchVPage;
begin
VPage := 1-VPage;
SetVisualPage(VPage);
end;
Procedure SwitchAPage;
begin
APage := 1-APage;
SetActivePage(APage);
end;
{
Procedure SetMems;
var r: byte;
begin
MemUsed := 0;
for r := 1 to 20 do
begin
Dispose(Pics[r]);
GetMem(Pics[r], PSizes[r]);
MemUsed := MemUsed + PSizes[r];
end;
end;
}
Procedure StartTime;
var
hh, mm, ss, s100: word;
begin
GetTime (hh, mm, ss, s100);
TheTime := (s100+100*(ss+60*(mm+60*hh)))*10;
end;
Procedure StopAndDel (Amt: word);
var
hh, mm, ss, s100: word;
TTime: longint;
begin
GetTime (hh, mm, ss, s100);
TTime := (s100+100*(ss+60*(mm+60*hh)))*10;
TheTime := TTime - TheTime;
if TheTime < 0 then
TheTime := TheTime + 24*60*60*1000;
if amt > TheTime then
Delay (Amt-TheTime);
end;
Procedure DoCode (R: byte; ComStr, ExStr: String);
var
w1, w2: word;
i1, i2: integer;
at, len, kp: byte;
ch: char;
ts: string;
tb: boolean;
Function PullWord(start: byte): word;
var
t2: word;
begin
move (ComStr[Start], t2, 2);
PullWord := t2;
end;
begin
lastok := true;
case r of
1: begin
CurPic := Ord(ComStr[1]);
x1 := PullWord(2);
y1 := PullWord(4);
w1 := ord(comstr[6]);
PutImage(x1, y1, pics[CurPic]^, w1);
end;
2: begin
CurPic := ord(ComStr[1]);
w1 := pullword(2);
w2 := PullWord(4);
LoadPic (ExStr, w1, w2, CurPic);
end;
3: begin
x1 := PullWord(1);
y1 := PullWord(3);
if exstr = #254 then
exstr := '';
if grmode then
begin
{ if gd > 1 then
switchapage; }
MoveTo (x1,y1);
OutText(ExStr);
{ if gd > 1 then
begin
switchvpage;
switchapage;
MoveTo(x1,y1);
OutText(ExStr);
SwitchApage;
end; }
end else begin
if (WhereX <> x1) or (WhereY <> y1) then
GotoXY(x1, y1);
Write (ExStr);
end;
end;
4: begin
DetectGraph (i1, i2);
kp := i1;
Async_Send(chr(kp));
kp := i2;
Async_Send(chr(kp));
end;
5: begin
gd := ord(ComStr[1]);
gm := ord(ComStr[2]);
if gd > 0 then
begin
InitGraph (gd, gm, '');
grmode := true;
vpage := 0;
apage := 0;
end else begin
CloseGraph;
grmode := false;
end;
end;
6: begin { only ega + }
apage := ord(comstr[1]);
vpage := ord(comstr[2]);
SetActivePage (Apage);
SetVisualPage (VPage);
end;
7: begin
x1 := PullWord(1);
y1 := PullWord(3);
x2 := PullWord(5);
y2 := PullWord(7);
SetColor (ord(ComStr[9]));
{ if gd > 1 then
switchapage; }
Line(x1, y1, x2, y2);
{ if gd > 1 then
begin
switchvpage;
switchapage;
Line(x1, y1, x2, y2);
SwitchAPage;
end; }
end;
8: begin
x1 := PullWord(1);
y1 := PullWord(3);
x2 := PullWord(5);
SetColor(Ord(ComStr[7]));
{ if gd > 1 then
SwitchAPage; }
Circle (x1, y1, x2);
{ if gd > 1 then
begin
switchvpage;
switchapage;
Circle (x1, y1, x2);
SwitchAPage;
end; }
end;
9: begin
x1 := PullWord(1);
y1 := PullWord(3);
x2 := PullWord(5);
y2 := PullWord(7);
SetColor (ord(ComStr[9]));
{ if gd > 1 then
SwitchAPage; }
Rectangle(x1, y1, x2, y2);
{ if gd > 1 then
begin
switchvpage;
switchapage;
Rectangle(x1, y1, x2, y2);
SwitchAPage;
end; }
end;
10: { nothin};
11: begin
MemUsed := MemAvail;
ts[0] := #4;
Move (MemUsed, ts[1], 4);
for at := 1 to 4 do
Async_send(ts[at]);
end;
{ begin
at := 2;
for w1 := 1 to 20 do
begin
PSizes[w1] := PullWord(at);
inc(at);
inc(at);
end;
SetMems;
end; }
12: begin
Writeln;
Writeln ('Returning to BBS...');
Delay(1000);
ExitCT := true;
end;
13: begin
if grmode then
ClearViewPort
else
ClrScr;
end;
14: begin
if GrMode then
begin
SetColor(ord(ComStr[1]));
if gd > 1 then
SetBkColor(ord(ComStr[2]));
end else begin
TextColor(ord(ComStr[1]));
TextBackGround(ord(ComStr[2]));
end;
end;
15: begin
{ len := Ord(ComStr[1]);
x1 := PullWord(2);
y1 := PullWord(4);
if grmode then
MoveTo (x1, y1)
else
gotoXY (x1, y1);
ts := '';
kp := 0;
repeat
repeat
until (keypressed) or (async_buffer_check);
if async_buffer_check then
ch := WaitForChar;
if keypressed then
ch := readkey;
if (ch = #8) and (kp > 0) then
begin
tS[0] := chr(ord(ts[0]) - 1);
if Grmode then
begin
MoveTo (x1+TextWidth(ts)+1, y1);
end else
Write (#8,' ',#8);
Dec (kp);
end;
if (kp < Len) and (ch <> #8) and (ch <> #13) and (ch > #3) then
begin
tS := ts + ch;
inc(kp);
if grmode then
begin
Outtext(ch);
MoveTo(x1+textwidth(ts)+1, y1);
end else
Write (ch);
end;
until ch = #13;
for x1 := 0 to Length(ts) do
Async_Send(ts[x1]);
} end;
16: begin
Fill1 := PullWord(1);
Fill2 := PullWord(3);
SetFillStyle (Fill1, Fill2);
end;
17: begin
CurPic := ord(ComStr[1]);
x1 := PullWord(2);
y1 := PullWord(4);
x2 := PullWord(6);
y2 := PullWord(8);
if psizes[curpic] > 0 then
freemem (Pics[CurPic], psizes[CurPic]);
PSizes[CurPic] := ImageSize(x1, y1, x2, y2);
GetMem (Pics[CurPic], PSizes[CurPic]);
GetImage (x1, y1, x2, y2, Pics[CurPic]^);
end;
18: begin
len := ord(ComStr[1]);
kp := ord(ComStr[2]);
if kp = 1 then
fillchar(Series[len], Sizeof(series[len]), 0);
Series[len,kp].r := ord(ComStr[3]);
Series[len,kp].exnum := ord(ComStr[4]);
Series[len,kp].ComStr := ExStr;
end;
19: begin
len := ord(ComStr[1]);
for kp := 1 to 9 do
if series[len,kp].r > 0 then
begin
if Series[len,kp].ExNum > 0 then
DoCode (Series[len,kp].r,Series[len,kp].ComStr,ExStrings[Series[len,kp].ExNum])
else
DoCode (Series[len,kp].r,Series[len,kp].ComStr,'');
end;
end;
20: begin
len := Ord(ComStr[1]);
ExStrings[len] := ExStr;
end;
21: gd := Ord(ComStr[1]);
22: begin
len := ord(ComStr[1]);
w1 := PullWord(2);
LoadSong (len, w1, ExStr);
end;
23: begin
len := ord(ComStr[1]);
PlaySong (len);
end;
24: begin
len := ord(ComStr[1]);
kp := ord(ComStr[2]);
Film[len,kp].PicN := Ord(ComStr[3]);
Film[len,kp].Pause := PullWord(4);
Film[len,kp].x := pullword(6);
film[len,kp].y := pullword(8);
Film[len,kp].Way := ord(ComStr[10]);
frames[len] := kp;
end;
25: begin
len := ord(ComStr[1]);
w1 := pullword(2);
w2 := pullword(4);
for kp := 1 to frames[len] do
begin
if film[len,kp].picn = 0 then
begin
len := film[len,kp].x;
kp := 1;
end;
with film[len,kp] do
begin
{ StartTime; }
{ if gd > 1 then
SwitchAPage; }
PutImage(w1+x, w2+y, pics[picn]^, Film[len,kp].Way);
{ if gd > 1 then
begin
SwitchVPage;
SwitchAPage;
PutImage(w1+x, w2+y, pics[picn]^, 0);
SwitchAPage;
end; }
{ StopAndDel (pause); }
Delay (pause);
end;
end;
end;
26: begin
w1 := PullWord (1);
w2 := PullWord (3);
settextstyle (w2, HorizDir, w1);
end;
27: begin
x1 := PullWord(1);
y1 := PullWord(3);
w1 := PullWord(5);
{ if gd > 1 then
SwitchAPage; }
PieSlice (x1, y1, 0, 360, w1);
{ if gd > 1 then
begin
switchvpage;
switchapage;
PieSlice (x1, y1, 0, 360, w1);
SwitchAPage;
end; }
end;
28: begin
x1 := PullWord(1);
y1 := PullWord(3);
x2 := PullWord(5);
y2 := PullWord(7);
{ if gd > 1 then
SwitchAPage; }
Bar(x1, y1, x2, y2);
{ if gd > 1 then
begin
switchvpage;
switchapage;
Bar(x1, y1, x2, y2);
SwitchAPage;
end; }
end;
29: begin
x1 := PullWord(1);
y1 := PullWord(3);
kp := ord(ComStr[5]);
{ if gd > 1 then
SwitchAPage; }
FloodFill (x1,y1,kp);
{ if gd > 1 then
begin
switchvpage;
switchapage;
FloodFill (x1,y1,kp);
SwitchAPage;
end; }
end;
30: begin
kp := ord(ComStr[1]);
len := ord(ComStr[2]);
Song[kp].l[len] := ord(ComStr[3]);
Song[kp].n[len] := ord(ComStr[4]);
Song[kp].o[len] := ord(ComStr[5]);
end;
31: begin
kp := ord(ComStr[1]);
if kp = 0 then
respon := false
else
respon := true;
end;
32: begin
w1 := PullWord(1);
kp := ord(ComStr[3]);
SetPalette (w1, kp);
end;
33: begin
x1 := Pullword(1);
y1 := PullWord(3);
x2 := PullWord(5);
y2 := Pullword(7);
w1 := PullWord(9);
Arc (x1,y1,x2,y2,w1);
end;
34: begin
x1 := PullWord(1);
y1 := PullWord(3);
x2 := PullWord(5);
y2 := PullWord(7);
if comstr[9] = #1 then
tb := true
else
tb := false;
SetViewPort (x1, y1, x2, y2, tb);
end;
35: begin
hx1 := PullWord(1);
hy1 := PullWord(3);
hx2 := PullWord(5);
hy2 := PullWord(7);
GetImage (hx1, hy1, hx2, hy2, Pic^);
PutImage (hx1, hy1, Pic^, NotPut);
end;
36: begin
if (hx1 = 0) and (hx2 = 0) then
exit;
if (Pic^[1] <> hx2-hx1) and (Pic^[2] <> hy2-hy1) then
begin
GetImage (hx1, hy1, hx2, hy2, Pic^);
PutImage (hx1, hy1, Pic^, NotPut);
end else
PutImage (hx1, hy1, Pic^,0);
hx1 := 0;
hx2 := 0;
end;
37: begin
sx1 := PullWord(1);
sy1 := PullWord(3);
sx2 := PullWord(5);
sy2 := PullWord(7);
scramt := pullword(9);
if gd = 1 then
scramt := (scramt div 2) * 2;
end;
38: begin
if gd = 3 then
begin
Port[$3ce] := 5;
Port[$3cf] := 1;
kp := (sx2-sx1+1) div 8;
len := sx1 div 8;
for w1 := sy1 to sy2-scramt do
move (mem[40960:(w1+Scramt)*80+len],mem[40960:w1*80+len],kp);
end;
if gd = 1 then
begin
if gm = 4 then
for w1 := sy1 div 2 to (sy2-scramt) div 2 + 1 do
begin
move (mem[$b800:w1*80+401+$2000],mem[$b800:w1*80+1+$2000],78);
move (mem[$b800:w1*80+401],mem[$b800:w1*80+1],78);
end;
{if gm = ... ???}
end;
bar (sx1,sy2-scramt+1,sx2,sy2);
end;
39: begin
len := sx1 div 8;
kp := (sx2-sx1+1) div 8;
if gd = 3 then
begin
Port[$3ce] := 5;
Port[$3cf] := 1;
for w1 := sy2-scramt downto sy1 do
move (mem[40960:w1*80+len],mem[40960:(w1+scramt)*80+len],kp);
end;
if gd = 1 then
begin
if gm = 4 then
for w1 := (sy2-scramt) div 2 downto (sy1 div 2) do
begin
move (Mem[$b800:w1*80+1+$2000],mem[$b800:w1*80+401+$2000],78);
move (mem[$b800:w1*80+1],mem[$b800:w1*80+401],78);
end;
{???}
end;
Bar (sx1,sy1,sx2,sy1+scramt-1);
end;
40: begin
if GrMode then
SetColor(ord(ComStr[1]))
else
TextColor(ord(ComStr[1]));
end
else
lastok := false;
end;
end;
begin
ExitCT := false;
grmode := false;
respon := true;
lastok := true;
CurFN := 'yaya';
New(Pic);
hx1 := 0;
hx2 := 0;
sx1 := 0;
sx2 := 0;
if RegisterBGIDriver (@CGADriverProc) < 0 then
;
if RegisterBGIDriver (@EGAVGADriverProc) < 0 then
;
if RegisterBGIFont (@TriplexFontProc) < 0 then
;
for x1 := 1 to 200 do
begin
getmem(Pics[x1], 0);
PSizes[x1] := 0;
end;
fillchar(frames, sizeof(frames), 0);
apage := 0;
vpage := 0;
Fill1 := 0;
Fill2 := 0;
gd := 0;
{ Cnf.CTDir := 'C:\MODEM\CTDATA\'; }
end.