home *** CD-ROM | disk | FTP | other *** search
- {$R+,S+,I+,D+,T-,F-,V+,B-,N-,L+ }
- {$M 16384,0,16384 }
- {$define trace} { decide if using internal tracing or DOS DEBUG }
-
- { >>> CHECK STATMENTS FLAGGED WITH !PATH! BEFORE RUNNING! <<< }
-
- uses
- Dos, Graph;
-
- const copyright : array[1..66] of char =
- 'Copyright 1988 by Sam Denton, St. Louis, MO, CompuServ 76314,1512.';
-
- {$ifdef trace}
-
- function Nybble(x:byte):char;
- inline($58/ { POP AX }
- $24/$0F/ { AND AL,0F }
- $04/$90/ { ADD AL,90 }
- $27/ { DAA }
- $14/$40/ { ADC AL,40 }
- $27/ { DAA }
- $24/$7F); { AND AL,7F }
- function HexByte(h:byte):string;
- begin
- HexByte[0]:=#2;
- HexByte[1]:=Nybble(h shr 4);
- HexByte[2]:=Nybble(h);
- end;
- function HexWord(h:word):string;
- begin
- HexWord:=HexByte(hi(h))+HexByte(lo(h));
- end;
-
- {$endif}
-
- { This is a quick steal from the GRLINK demo program. To disect a different }
- { driver, just change this and the reference at RegisterBGIDriver. Or, do }
- { your own BINOBJ to the BGI stuff and give them the same entry point name. }
- procedure CGADriverProc; external;
- {$L CGA.OBJ } {!PATH!}
-
- type
- DriverPtr = ^ Driver;
- Driver = record
- case integer of
- 0: (chars : array[0..499] of char);
- 1: (bytes : array[0..499] of byte);
- 2: (words : array[0..249] of word);
- end;
-
- procedure PatchDriver(d:DriverPtr);
- var
- i,j : integer;
- begin
- with d^ do
- begin
- if (bytes[0] <> ord('p')) or (bytes[1] <> ord('k')) then
- halt(99);
- i := 4;
- repeat
- write(chars[i]);
- inc(i);
- until (i>256) or (bytes[i] = ord(^Z));
- end;
- writeln;
- j := DriverPtr(ptr(seg(d^),ofs(d^)+i+1))^.words[0];
- { change CALL [SI+$0016] into INT 3; CALL [SI+$16] }
- d^.bytes[j+5] := $CC; { was $FF }
- d^.bytes[j+6] := $FF; { was $94 }
- d^.bytes[j+7] := $54; { was $16 }
- d^.bytes[j+8] := $16; { was $00 }
- end;
-
- {$ifdef trace}
-
- var
- tracetable : array[0..511] of record
- flags,ax,bx,cx,dx,si,di,es : word;
- mem : array[0..47] of byte;
- end;
- const
- trace : word = 0;
-
- procedure Int3(flags,cs,ip,ax,bx,cx,dx,si,di,ds,es,bp : word);
- interrupt;
- var
- i : word;
- begin
- tracetable[trace].flags := flags;
- tracetable[trace].ax := ax;
- tracetable[trace].bx := bx;
- tracetable[trace].cx := cx;
- tracetable[trace].dx := dx;
- tracetable[trace].si := si;
- tracetable[trace].di := di;
- tracetable[trace].es := es;
- if bx < $f000 then
- for i := 0 to 47 do
- tracetable[trace].mem[i] := {$R-}mem[es:bx+i]{$R+};
- trace := succ(trace) and 511;
- end;
-
- {$endif}
-
- procedure dumptrace(msg:string);
- var
- i,l : integer;
- traceout : text;
- begin
- assign(traceout,'trace.out');
- {$I-}
- append(traceout);
- {$I+}
- if IOResult <> 0 then
- rewrite(traceout);
- writeln(traceout,'<<< ',msg,' >>>');
- {$ifdef trace}
- if trace = 0 then
- begin
- close(traceout);
- exit;
- end;
- for trace := 0 to pred(trace) do
- with tracetable[trace] do
- begin
- write(traceout,'AX=',HexWord(ax),' BX=',HexWord(bx),
- ' CX=',HexWord(cx),' DX=',HexWord(dx),
- ' SI=',HexWord(si),' DI=',HexWord(di));
- if (flags and FOverflow) = FOverflow then
- write(traceout,' OV')
- else
- write(traceout,' NV');
- if (flags and FSign) = FSign then
- write(traceout,' MI')
- else
- write(traceout,' PL');
- if (flags and FZero) = FZero then
- write(traceout,' ZE')
- else
- write(traceout,' NZ');
- if (flags and FParity) = FParity then
- write(traceout,' PO')
- else
- write(traceout,' PE');
- if (flags and FCarry) = FCarry then
- write(traceout,' CA')
- else
- write(traceout,' NC');
- writeln(traceout);
- if bx < $F000 then
- for l := 0 to 2 do
- begin
- write(traceout,HexWord(es),':',HexWord(bx+16*l),' ');
- for i := 0 to 15 do
- begin
- write(traceout,HexByte(mem[16*l+i]));
- if (i and 15) = 7 then
- write(traceout,'-')
- else
- write(traceout,' ');
- end;
- write(traceout,' ');
- for i := 0 to 15 do
- begin
- if mem[16*l+i] in [32..126] then
- write(traceout,chr(mem[16*l+i]))
- else
- write(traceout,'.');
- end;
- writeln(traceout);
- end;
- writeln(traceout);
- end;
- trace := 0;
- {$endif}
- i := GraphResult;
- if i <> 0 then
- WriteLn(traceout,'*** Error ***',GraphErrorMsg(i));
- close(traceout);
- end;
-
- const
- UserPattern : FillPatternType = ($00,$70,$20,$27,$25,$27,$04,$04);
- pentagon : array[0..5] of PointType = ((x:500;y:50),(x:480;y:70),
- (x:490;y:90),(x:510;y:90),(x:520;y:70),(x:500;y:50));
-
- var
- GraphDriver, GraphMode : integer;
- i : longint;
- Old3,ImageBuffer : pointer;
-
- begin
- { erase old copy of file (I also hunt rabbits with elephant guns!) }
- Exec('C:\Dos\Command.Com','/c erase Trace.Out'); {!PATH!}
- { (I am violating my own standards by NOT looking up COMSPEC, }
- { because the stupid DOS unit has no environment functions!) }
-
- {$ifdef trace}
- { install spy program at same vector used by DEBUG and the like }
- GetIntVec(3,Old3);
- SetIntVec(3,@Int3);
- {$endif}
- PatchDriver(@CGADriverProc);
- { start doing things and see what happens }
- if RegisterBGIdriver(@CGADriverProc) < 0 then
- halt(99);
- GraphDriver := 1;
- GraphMode := 4;
- InitGraph(GraphDriver, GraphMode, ''); { activate graphics }
- if GraphResult <> grOk then
- begin
- writeln('error: ',GraphErrorMsg(GraphDriver));
- halt;
- end;
- DumpTrace('InitGraph');
- Line(53,54,55,56); DumpTrace('Line');
- MoveTo(57,58); DumpTrace('MoveTo');
- LineTo(59,60); DumpTrace('LineTo');
- MoveRel(61,62); DumpTrace('MoveRel');
- LineRel(63,64); DumpTrace('LineRel');
- GetMem(ImageBuffer,ImageSize(53,54,63,62)); DumpTrace('ImageSize');
- GetImage(53,54,63,62,ImageBuffer^); DumpTrace('GetImage');
- i := GetGraphMode; DumpTrace('GetGraphMode');
- RestoreCrtMode; DumpTrace('RestoreCrtMode');
- SetGraphMode(i); DumpTrace('SetGraphMode');
- PutPixel(1,1,1); DumpTrace('PutPixel');
- if GetPixel(1,1) = 0 then ; DumpTrace('GetPixel');
- PutImage(53,54,ImageBuffer^,0); DumpTrace('PutImage, MOV');
- PutImage(63,64,ImageBuffer^,4); DumpTrace('PutImage, NOT');
- SetColor(1); DumpTrace('SetColor');
- SetFillPattern(UserPattern,1); DumpTrace('SetFillPattern');
- Bar(16,48,32,64); DumpTrace('Bar');
- SetFillStyle(CloseDotFill,1); DumpTrace('SetFillStyle');
- Bar3D(24,56,32,64,2,TopOn); DumpTrace('Bar3D');
- PieSlice(99,99,90,180,30); DumpTrace('PieSlice');
- Ellipse(99,99,180,360,30,45); DumpTrace('Ellipse');
- Arc(99,99,0,90,30); DumpTrace('Arc');
- Circle(200,100,30); DumpTrace('Circle');
- FloodFill(200,100,1); DumpTrace('FloodFill');
- SetLineStyle(DottedLn,7,NormWidth); DumpTrace('SetLineStyle');
- Rectangle(0,100,50,150); DumpTrace('Rectangle');
- DrawPoly(6,pentagon); DumpTrace('DrawPoly');
- FillPoly(5,pentagon); DumpTrace('FillPoly');
- OutText('Hello'); DumpTrace('OutText');
- SetTextJustify(CenterText,CenterText); DumpTrace('SetTextJustfy');
- SetTextStyle(DefaultFont,HorizDir,3); DumpTrace('SetTextStyle');
- OutTextXY(320,100,'Hello, again'); DumpTrace('OutTextXY');
- SetBkColor(Blue); DumpTrace('SetBkColor');
- SetColor(5); DumpTrace('SetColor');
- SetPalette(1,5); DumpTrace('SetPalette');
- SetViewport(0,0,100,100,true); DumpTrace('SetViewport');
- ClearViewport; DumpTrace('ClearViewport');
- SetActivePage(1); DumpTrace('SetActivePage');
- SetVisualPage(1); DumpTrace('SetVisualPage');
- ClearDevice; DumpTrace('ClearDevice');
- CloseGraph; DumpTrace('CloseGraph');
- {$ifdef trace}
- { kill the spy, he knows too much! }
- SetIntVec(3,Old3);
- {$endif}
- { invoke Vernon D. Buerg's LIST utility to look at the results }
- Exec('C:\User\V.Com','Trace.Out'); {!PATH!}
- end.