tinyptc.pp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. unit TinyPTC;
  2. {$MODE objfpc}
  3. interface
  4. function ptc_open(const ATitle: string; AWidth, AHeight: Integer): Boolean;
  5. function ptc_update(ABuffer: Pointer): Boolean;
  6. procedure ptc_close;
  7. implementation
  8. uses
  9. SysUtils, ptc;
  10. var
  11. Console: TPTCConsole = nil;
  12. Format: TPTCFormat = nil;
  13. Palette: TPTCPalette = nil;
  14. Width, Height: Integer;
  15. function ptc_open(const ATitle: string; AWidth, AHeight: Integer): Boolean;
  16. begin
  17. try
  18. if Console = nil then
  19. Console := TPTCConsole.Create;
  20. if Format = nil then
  21. Format := TPTCFormat.Create(32, $FF0000, $FF00, $FF);
  22. if Palette = nil then
  23. Palette := TPTCPalette.Create;
  24. Console.Open(ATitle, AWidth, AHeight, Format);
  25. Width := AWidth;
  26. Height := AHeight;
  27. Result := true;
  28. except
  29. on error: TPTCError do
  30. Result := false;
  31. end;
  32. end;
  33. function ptc_update(ABuffer: Pointer): Boolean;
  34. begin
  35. try
  36. Console.Load(ABuffer, Width, Height, Width*4, Format, Palette);
  37. Result := true;
  38. except
  39. on error: TPTCError do
  40. Result := false;
  41. end;
  42. end;
  43. procedure ptc_close;
  44. begin
  45. if Assigned(Console) then
  46. Console.Close;
  47. FreeAndNil(Console);
  48. FreeAndNil(Format);
  49. FreeAndNil(Palette);
  50. end;
  51. finalization
  52. ptc_close;
  53. end.