ports.pp 2.5 KB

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