ports.pp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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) 1998-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. interface
  18. type
  19. tport = class
  20. procedure writeport(p : word;data : byte);
  21. function readport(p : word) : byte;
  22. property pp[w : word] : byte read readport write writeport;default;
  23. end;
  24. tportw = class
  25. procedure writeport(p : word;data : word);
  26. function readport(p : word) : word;
  27. property pp[w : word] : word read readport write writeport;default;
  28. end;
  29. tportl = class
  30. procedure writeport(p : word;data : longint);
  31. function readport(p : word) : longint;
  32. property pp[w : word] : longint read readport write writeport;default;
  33. end;
  34. var
  35. { we don't need to initialize port, because neither member
  36. variables nor virtual methods are accessed }
  37. port,
  38. portb : tport;
  39. portw : tportw;
  40. portl : tportl;
  41. implementation
  42. {$asmmode ATT}
  43. { to give easy port access like tp with port[] }
  44. procedure tport.writeport(p : word;data : byte);assembler;
  45. asm
  46. movw p,%dx
  47. movb data,%al
  48. outb %al,%dx
  49. end ['EAX','EDX'];
  50. function tport.readport(p : word) : byte;assembler;
  51. asm
  52. movw p,%dx
  53. inb %dx,%al
  54. end ['EAX','EDX'];
  55. procedure tportw.writeport(p : word;data : word);assembler;
  56. asm
  57. movw p,%dx
  58. movw data,%ax
  59. outw %ax,%dx
  60. end ['EAX','EDX'];
  61. function tportw.readport(p : word) : word;assembler;
  62. asm
  63. movw p,%dx
  64. inw %dx,%ax
  65. end ['EAX','EDX'];
  66. procedure tportl.writeport(p : word;data : longint);assembler;
  67. asm
  68. movw p,%dx
  69. movl data,%eax
  70. outl %eax,%dx
  71. end ['EAX','EDX'];
  72. function tportl.readport(p : word) : longint;assembler;
  73. asm
  74. movw p,%dx
  75. inl %dx,%eax
  76. end ['EAX','EDX'];
  77. end.
  78. {
  79. $Log$
  80. Revision 1.2 2000-01-07 16:32:23 daniel
  81. * copyright 2000 added
  82. Revision 1.1 1999/09/01 14:47:31 pierre
  83. TP port construction separated into this unit
  84. Revision 1.4 1999/05/13 21:54:27 peter
  85. * objpas fixes
  86. Revision 1.3 1999/03/26 00:01:52 peter
  87. * fixed rounding in global_dos_alloc
  88. Revision 1.2 1999/03/01 15:40:51 peter
  89. * use external names
  90. * removed all direct assembler modes
  91. Revision 1.1 1998/12/21 13:07:03 peter
  92. * use -FE
  93. Revision 1.12 1998/08/27 10:30:50 pierre
  94. * go32v1 RTL did not compile (LFNsupport outside go32v2 defines !)
  95. I renamed tb_selector to tb_segment because
  96. it is a real mode segment as opposed to
  97. a protected mode selector
  98. Fixed it for go32v1 (remove the $E0000000 offset !)
  99. Revision 1.11 1998/08/26 10:04:02 peter
  100. * new lfn check from mailinglist
  101. * renamed win95 -> LFNSupport
  102. + tb_selector, tb_offset for easier access to transferbuffer
  103. Revision 1.10 1998/08/11 00:07:17 peter
  104. * $ifdef ver0_99_5 instead of has_property
  105. Revision 1.9 1998/07/21 12:06:03 carl
  106. * restored working version
  107. }