home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / forth040.zip / PORTIO.ASM < prev    next >
Assembly Source File  |  1993-07-16  |  5KB  |  138 lines

  1. ; ******************************************************************
  2. ;   <portio.asm> code file
  3. ;
  4. ;   Function definitions for port access routines
  5. ;        inp(port)   - read single byte from I/O port
  6. ;        inpw(port)  - read single word from I/O port pair
  7. ;        outp(port)  - write single byte to I/O port
  8. ;        outpw(port) - write single word to I/O port pair
  9. ;
  10. ;   For IBM C Set/2  Version 1.0
  11. ;
  12. ;  DISCLAIMER:
  13. ;  -------------------------
  14. ;  This code and the accompanying documentation is hereby placed in
  15. ;  the public domain.  It is not part of any standard product and
  16. ;  is provided solely as an example for your private and/or
  17. ;  commercial use.  You may freely use or distribute this code in
  18. ;  derived works as long as you do not attempt to prevent others
  19. ;  from doing likewise.  Neither the author, nor his employer,
  20. ;  shall be liable for any damages arising from your use of this
  21. ;  code; it is provided solely ASIS with no warranty whatsoever.
  22. ;
  23. ;  Author contact:   Michael Thompson
  24. ;                    tommy@msc.cornell.edu
  25. ; ******************************************************************
  26. ;
  27. ; Register use modified 7/16/93 by Mike Warot (ka9dgx@chinet.com)
  28. ;
  29.  
  30. P@IOCODE        segment 'CODE'
  31.                 assume  cs:P@IOCODE
  32.  
  33. ;=============================================================================
  34. ; These routines must be declared as
  35. ;
  36. ;       unsigned short _Far16 _Fastcall inp(unsigned short port);
  37. ;       unsigned short _Far16 _Fastcall inpw(unsigned short port);
  38. ;       unsigned short _Far16 _Fastcall outp(unsigned short, unsigned short);
  39. ;       unsigned short _Far16 _Fastcall outpw(unsigned short, unsigned short);
  40. ;
  41. ; in the CSET/2 declarations.  The fastcall convention passes the values on
  42. ; the registers AX, DX as assumed below.  The short return allows use of AX
  43. ; only on exit.  This should be nearly at the limit of the 32->16 call 
  44. ; convention.
  45. ;
  46. ; Compiling and linkage requires these routines to be stored in a DLL so are
  47. ; 16 bit.  I could make them 32 bit IF I could get a true protected mode 32
  48. ; bit assembler.  Microsoft maybe there, but I refuse to buy their toys
  49. ; anymore.
  50. ;
  51. ; General make process:
  52. ;    masm /Mx portio;
  53. ;    link /map /noi /nod portio,portio.dll,,,portio.def
  54. ;    implib portio.lib portio.def
  55. ;
  56. ; portio.def must contain
  57. ;       LIBRARY PORTIO
  58. ;       DESCRIPTION 'Dynamically-linked Run-Time Library for Port Access'
  59. ;       PROTMODE
  60. ;       CODE PRELOAD EXECUTEONLY IOPL
  61. ;
  62. ;       EXPORTS
  63. ;       @inp
  64. ;       @outp
  65. ;       @inpw
  66. ;       @outpw
  67. ;
  68. ; The CODE IOPL is required - all CODE segments are give IOPL priveleges.
  69. ; For some reason, can't figure out how to override one MASM segment.
  70. ; @ indicates a fastcall routine apparently, /Mx preserves case.
  71. ;=============================================================================
  72.  
  73.  
  74.  
  75. ;=============================================================================
  76. ; Subroutine to output byte to specified port
  77. ;
  78. ; Usage:  unsigned short = outp (unsigned short port, unsigned short byte)
  79. ;         unsigned short = outpw(unsigned short port, unsigned short word)
  80. ;
  81. ; Inputs: DX - port
  82. ;         AX - contains value to be sent (low byte only for outp)
  83. ;
  84. ; Output: AX - byte value sent
  85. ;=============================================================================
  86. @outp           proc    far
  87.                 public  @outp
  88.                 assume  ds:nothing,es:nothing
  89. ;
  90.                 out     dx,al                           ; And send one byte
  91.                 xor     ah,ah                           ; Say didn't send hi
  92.                 ret
  93. ;
  94. @outp           endp
  95.  
  96. @outpw          proc    far
  97.                 public  @outpw
  98.                 assume  ds:nothing,es:nothing
  99. ;
  100.                 out     dx,ax                           ; And send one byte
  101.                 ret
  102. ;
  103. @outpw          endp
  104.  
  105.  
  106. ;=============================================================================
  107. ; Subroutine to read input from a specified port
  108. ;
  109. ; Usage:  unsigned short = inp (unsigned short port)
  110. ;         unsigned short = inpw(unsigned short port)
  111. ;
  112. ; Inputs: DX - port
  113. ;
  114. ; Output: AX - byte (word) value received
  115. ;=============================================================================
  116. @inp            proc    far
  117.                 public  @inp
  118.                 assume  ds:nothing,es:nothing
  119. ;
  120.                 in      al,dx                           ; Read the byte
  121.                 xor     ah,ah                           ; Clear AH
  122.                 ret
  123. ;
  124. @inp            endp
  125.  
  126. @inpw           proc    far
  127.                 public  @inpw
  128.                 assume  ds:nothing,es:nothing
  129. ;
  130.                 in      ax,dx                           ; Read the word
  131.                 ret
  132. ;
  133. @inpw           endp
  134.  
  135. P@IOCODE                ends
  136. ;
  137.                 end
  138.