From ef8e984bcb46d8df4e0634d3df17b19a3c440fec Mon Sep 17 00:00:00 2001 From: michael Date: Mon, 15 Oct 2001 20:39:10 +0000 Subject: [PATCH] + Added example of custom video driver --- docs/videoex/Makefile | 3 +- docs/videoex/README | 3 +- docs/videoex/viddbg.pp | 142 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 docs/videoex/viddbg.pp diff --git a/docs/videoex/Makefile b/docs/videoex/Makefile index ab8887527d..b1253d4839 100644 --- a/docs/videoex/Makefile +++ b/docs/videoex/Makefile @@ -46,7 +46,8 @@ onetex : tex $(MAKETEX) $(TEXOBJECTS) clean : - rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS) vidutil.ppu vidutil.o + rm -f *.o *.s $(OBJECTS) $(TEXOBJECTS) + rm -f vidutil.ppu vidutil.o viddbg.ppu viddbg.o Video.log $(OBJECTS): %: %.pp vidutil.ppu $(PP) $(PPOPTS) $* diff --git a/docs/videoex/README b/docs/videoex/README index 375dcb0147..b5448c3087 100644 --- a/docs/videoex/README +++ b/docs/videoex/README @@ -1,6 +1,7 @@ This directory contains the examples for the video unit documentation. -vidutil.pp Containst the textout function. +vidutil.pp Contains the textout function. +viddbg.pp contains an example of how to write a custom video driver. ex1.pp demonstrates the vidutil unit. ex2.pp contains an example of the SetCursorPos function. diff --git a/docs/videoex/viddbg.pp b/docs/videoex/viddbg.pp new file mode 100644 index 0000000000..7de96cec1c --- /dev/null +++ b/docs/videoex/viddbg.pp @@ -0,0 +1,142 @@ +unit viddbg; + +Interface + +uses video; + + +Procedure StartVideoLogging; +Procedure StopVideoLogging; +Function IsVideoLogging : Boolean; +Procedure SetVideoLogFileName(FileName : String); + +Const + DetailedVideoLogging : Boolean = False; + +Implementation + +uses sysutils,keyboard; + +var + NewVideoDriver, + OldVideoDriver : TVideoDriver; + Active,Logging : Boolean; + LogFileName : String; + VideoLog : Text; + +Function TimeStamp : String; + +begin + TimeStamp:=FormatDateTime('hh:nn:ss',Time()); +end; + +Procedure StartVideoLogging; + +begin + Logging:=True; + Writeln(VideoLog,'Start logging video operations at: ',TimeStamp); +end; + +Procedure StopVideoLogging; + +begin + Writeln(VideoLog,'Stop logging video operations at: ',TimeStamp); + Logging:=False; +end; + +Function IsVideoLogging : Boolean; + +begin + IsVideoLogging:=Logging; +end; + +Var + ColUpd,RowUpd : Array[0..1024] of Integer; + +Procedure DumpScreenStatistics(Force : Boolean); + +Var + I,Count : Integer; + +begin + If Force then + Write(VideoLog,'forced '); + Writeln(VideoLog,'video update at ',TimeStamp,' : '); + FillChar(Colupd,SizeOf(ColUpd),#0); + FillChar(Rowupd,SizeOf(RowUpd),#0); + Count:=0; + For I:=0 to VideoBufSize div SizeOf(TVideoCell) do + begin + If VideoBuf^[i]<>OldVideoBuf^[i] then + begin + Inc(Count); + Inc(ColUpd[I mod ScreenWidth]); + Inc(RowUpd[I div ScreenHeight]); + end; + end; + Write(VideoLog,Count,' videocells differed divided over '); + Count:=0; + For I:=0 to ScreenWidth-1 do + If ColUpd[I]<>0 then + Inc(Count); + Write(VideoLog,Count,' columns and '); + Count:=0; + For I:=0 to ScreenHeight-1 do + If RowUpd[I]<>0 then + Inc(Count); + Writeln(VideoLog,Count,' rows.'); + If DetailedVideoLogging Then + begin + For I:=0 to ScreenWidth-1 do + If (ColUpd[I]<>0) then + Writeln(VideoLog,'Col ',i,' : ',ColUpd[I]:3,' rows changed'); + For I:=0 to ScreenHeight-1 do + If (RowUpd[I]<>0) then + Writeln(VideoLog,'Row ',i,' : ',RowUpd[I]:3,' colums changed'); + end; +end; + +Procedure LogUpdateScreen(Force : Boolean); + +begin + If Logging then + DumpScreenStatistics(Force); + OldVideoDriver.UpdateScreen(Force); +end; + +Procedure LogInitVideo; + +begin + OldVideoDriver.InitDriver(); + Assign(VideoLog,logFileName); + Rewrite(VideoLog); + Active:=True; + StartVideoLogging; +end; + +Procedure LogDoneVideo; + +begin + StopVideoLogging; + Close(VideoLog); + Active:=False; + OldVideoDriver.DoneDriver(); +end; + +Procedure SetVideoLogFileName(FileName : String); + +begin + If Not Active then + LogFileName:=FileName; +end; + +Initialization + GetVideoDriver(OldVideoDriver); + NewVideoDriver:=OldVideoDriver; + NewVideoDriver.UpdateScreen:=@LogUpdateScreen; + NewVideoDriver.InitDriver:=@LogInitVideo; + NewVideoDriver.DoneDriver:=@LogDoneVideo; + LogFileName:='Video.log'; + Logging:=False; + SetVideoDriver(NewVideoDriver); +end. \ No newline at end of file