ports.pp 2.2 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. {$Calling StdCall}
  14. interface
  15. type
  16. tport = object
  17. procedure writeport(p : word;data : byte);
  18. function readport(p : word) : byte;
  19. property pp[w : word] : byte read readport write writeport;default;
  20. end;
  21. tportw = object
  22. procedure writeport(p : word;data : word);
  23. function readport(p : word) : word;
  24. property pp[w : word] : word read readport write writeport;default;
  25. end;
  26. tportl = object
  27. procedure writeport(p : word;data : longint);
  28. function readport(p : word) : longint;
  29. property pp[w : word] : longint read readport write writeport;default;
  30. end;
  31. var
  32. { we don't need to initialize port, because neither member
  33. variables nor virtual methods are accessed }
  34. port,
  35. portb : tport;
  36. portw : tportw;
  37. portl : tportl;
  38. implementation
  39. {$asmmode ATT}
  40. { to give easy port access like tp with port[] }
  41. procedure tport.writeport(p : word;data : byte);assembler;
  42. asm
  43. movw p,%dx
  44. movb data,%al
  45. outb %al,%dx
  46. end;
  47. function tport.readport(p : word) : byte;assembler;
  48. asm
  49. movw p,%dx
  50. inb %dx,%al
  51. end;
  52. procedure tportw.writeport(p : word;data : word);assembler;
  53. asm
  54. movw p,%dx
  55. movw data,%ax
  56. outw %ax,%dx
  57. end;
  58. function tportw.readport(p : word) : word;assembler;
  59. asm
  60. movw p,%dx
  61. inw %dx,%ax
  62. end;
  63. procedure tportl.writeport(p : word;data : longint);assembler;
  64. asm
  65. movw p,%dx
  66. movl data,%eax
  67. outl %eax,%dx
  68. end;
  69. function tportl.readport(p : word) : longint;assembler;
  70. asm
  71. movw p,%dx
  72. inl %dx,%eax
  73. end;
  74. end.