ports.pp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. This file is part of the Free Pascal run time library.
  3. and implements some stuff for protected mode programming
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. These files adds support for TP styled port accesses
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit ports;
  13. { this unit uses classes so
  14. ObjFpc mode is required PM }
  15. {$Mode ObjFpc}
  16. interface
  17. type
  18. tport = class
  19. procedure writeport(p : word;data : byte);
  20. function readport(p : word) : byte;
  21. property pp[w : word] : byte read readport write writeport;default;
  22. end;
  23. tportw = class
  24. procedure writeport(p : word;data : word);
  25. function readport(p : word) : word;
  26. property pp[w : word] : word read readport write writeport;default;
  27. end;
  28. { tportl = class
  29. procedure writeport(p : word;data : longint);
  30. function readport(p : word) : longint;
  31. property pp[w : word] : longint read readport write writeport;default;
  32. end;}
  33. var
  34. { we don't need to initialize port, because neither member
  35. variables nor virtual methods are accessed }
  36. port,
  37. portb : tport;
  38. portw : tportw;
  39. // portl : tportl;
  40. implementation
  41. { to give easy port access like tp with port[] }
  42. procedure tport.writeport(p : word;data : byte);assembler;
  43. asm
  44. mov dx, p
  45. mov al, data
  46. out dx, al
  47. end;
  48. function tport.readport(p : word) : byte;assembler;
  49. asm
  50. mov dx, p
  51. in al, dx
  52. end;
  53. procedure tportw.writeport(p : word;data : word);assembler;
  54. asm
  55. mov dx, p
  56. mov ax, data
  57. out dx, ax
  58. end;
  59. function tportw.readport(p : word) : word;assembler;
  60. asm
  61. mov dx, p
  62. in ax, dx
  63. end;
  64. {procedure tportl.writeport(p : word;data : longint);assembler;
  65. asm
  66. movw p,%dx
  67. movl data,%eax
  68. outl %eax,%dx
  69. end;
  70. function tportl.readport(p : word) : longint;assembler;
  71. asm
  72. movw p,%dx
  73. inl %dx,%eax
  74. end;}
  75. end.