tinyptc.pp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {todo: handle exceptions}
  2. Unit TinyPTC;
  3. {$MODE objfpc}
  4. Interface
  5. Function ptc_open(title : String; width, height : Integer) : Boolean;
  6. Function ptc_update(buffer : Pointer) : Boolean;
  7. Procedure ptc_close;
  8. Implementation
  9. Uses
  10. ptc;
  11. Var
  12. console : TPTCConsole;
  13. format : TPTCFormat;
  14. palette : TPTCPalette;
  15. w, h : Integer;
  16. Function ptc_open(title : String; width, height : Integer) : Boolean;
  17. Begin
  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(title, width, height, format);
  25. w := width;
  26. h := height;
  27. ptc_open := True;
  28. End;
  29. Function ptc_update(buffer : Pointer) : Boolean;
  30. Begin
  31. console.load(buffer, w, h, w*4, format, palette);
  32. ptc_update := True;
  33. End;
  34. Procedure ptc_close;
  35. Begin
  36. If console <> Nil Then
  37. console.close;
  38. FreeAndNil(console);
  39. FreeAndNil(format);
  40. FreeAndNil(palette);
  41. End;
  42. Initialization
  43. console := Nil;
  44. Finalization
  45. ptc_close;
  46. End.