viddbg.pp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. unit viddbg;
  2. Interface
  3. uses video;
  4. Procedure StartVideoLogging;
  5. Procedure StopVideoLogging;
  6. Function IsVideoLogging : Boolean;
  7. Procedure SetVideoLogFileName(FileName : String);
  8. Const
  9. DetailedVideoLogging : Boolean = False;
  10. Implementation
  11. uses sysutils,keyboard;
  12. var
  13. NewVideoDriver,
  14. OldVideoDriver : TVideoDriver;
  15. Active,Logging : Boolean;
  16. LogFileName : String;
  17. VideoLog : Text;
  18. Function TimeStamp : String;
  19. begin
  20. TimeStamp:=FormatDateTime('hh:nn:ss',Time());
  21. end;
  22. Procedure StartVideoLogging;
  23. begin
  24. Logging:=True;
  25. Writeln(VideoLog,'Start logging video operations at: ',TimeStamp);
  26. end;
  27. Procedure StopVideoLogging;
  28. begin
  29. Writeln(VideoLog,'Stop logging video operations at: ',TimeStamp);
  30. Logging:=False;
  31. end;
  32. Function IsVideoLogging : Boolean;
  33. begin
  34. IsVideoLogging:=Logging;
  35. end;
  36. Var
  37. ColUpd,RowUpd : Array[0..1024] of Integer;
  38. Procedure DumpScreenStatistics(Force : Boolean);
  39. Var
  40. I,Count : Integer;
  41. begin
  42. If Force then
  43. Write(VideoLog,'forced ');
  44. Writeln(VideoLog,'video update at ',TimeStamp,' : ');
  45. FillChar(Colupd,SizeOf(ColUpd),#0);
  46. FillChar(Rowupd,SizeOf(RowUpd),#0);
  47. Count:=0;
  48. For I:=0 to VideoBufSize div SizeOf(TVideoCell) do
  49. begin
  50. If VideoBuf^[i]<>OldVideoBuf^[i] then
  51. begin
  52. Inc(Count);
  53. Inc(ColUpd[I mod ScreenWidth]);
  54. Inc(RowUpd[I div ScreenHeight]);
  55. end;
  56. end;
  57. Write(VideoLog,Count,' videocells differed divided over ');
  58. Count:=0;
  59. For I:=0 to ScreenWidth-1 do
  60. If ColUpd[I]<>0 then
  61. Inc(Count);
  62. Write(VideoLog,Count,' columns and ');
  63. Count:=0;
  64. For I:=0 to ScreenHeight-1 do
  65. If RowUpd[I]<>0 then
  66. Inc(Count);
  67. Writeln(VideoLog,Count,' rows.');
  68. If DetailedVideoLogging Then
  69. begin
  70. For I:=0 to ScreenWidth-1 do
  71. If (ColUpd[I]<>0) then
  72. Writeln(VideoLog,'Col ',i,' : ',ColUpd[I]:3,' rows changed');
  73. For I:=0 to ScreenHeight-1 do
  74. If (RowUpd[I]<>0) then
  75. Writeln(VideoLog,'Row ',i,' : ',RowUpd[I]:3,' colums changed');
  76. end;
  77. end;
  78. Procedure LogUpdateScreen(Force : Boolean);
  79. begin
  80. If Logging then
  81. DumpScreenStatistics(Force);
  82. OldVideoDriver.UpdateScreen(Force);
  83. end;
  84. Procedure LogInitVideo;
  85. begin
  86. OldVideoDriver.InitDriver();
  87. Assign(VideoLog,logFileName);
  88. Rewrite(VideoLog);
  89. Active:=True;
  90. StartVideoLogging;
  91. end;
  92. Procedure LogDoneVideo;
  93. begin
  94. StopVideoLogging;
  95. Close(VideoLog);
  96. Active:=False;
  97. OldVideoDriver.DoneDriver();
  98. end;
  99. Procedure SetVideoLogFileName(FileName : String);
  100. begin
  101. If Not Active then
  102. LogFileName:=FileName;
  103. end;
  104. Initialization
  105. GetVideoDriver(OldVideoDriver);
  106. NewVideoDriver:=OldVideoDriver;
  107. NewVideoDriver.UpdateScreen:=@LogUpdateScreen;
  108. NewVideoDriver.InitDriver:=@LogInitVideo;
  109. NewVideoDriver.DoneDriver:=@LogDoneVideo;
  110. LogFileName:='Video.log';
  111. Logging:=False;
  112. SetVideoDriver(NewVideoDriver);
  113. end.