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