home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / packetdrivers.tar.gz / pd.tar / src / io16.asm < prev    next >
Assembly Source File  |  1995-06-25  |  2KB  |  82 lines

  1. ;input a word from IO port
  2. inw    macro
  3.     in    ax,dx            ;read IO port
  4.     endm
  5.  
  6. ;write a word to an IO port
  7. outw    macro
  8.     out    dx,ax            ;write IO port
  9.     endm
  10.  
  11.     extrn    is_186: byte        ;=0 if 808[68], =1 if 80[123]86.
  12.  
  13. ;this code inputs from a port that can accept either byte or word transfers.
  14. ;if the board is in a 8-bit slot, it always receives byte transfers.
  15. ;if the board is in a 16-bit slot, it has the IOCS16 line asserted on word I/O.
  16.  
  17. repinsw:
  18. ; If buffer doesn't begin on a word boundary, get the first byte
  19.     test    di,1            ; if(buf & 1){
  20.     jz    ibufeven        ;
  21.     in    al,dx            ; al = in(dx);
  22.     stosb                ; *di++ = al
  23.     dec    cx            ; cx--;
  24.     je    icnteven
  25. ibufeven:
  26.     cmp    is_186,0        ; Can we use rep insw?
  27.     je    repinsw_1        ; no - have to do it slowly.
  28.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  29.     .286
  30.     rep    insw
  31.     .8086
  32.     jmp    short inobuf
  33. repinsw_1:
  34. ; Do the bulk of the buffer, a word at a time
  35.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  36.     jcxz    inobuf            ; if(cx != 0){
  37. rb:    in    ax,dx            ; do { al = in(dx);
  38.     stosw                ; *si++ = ax; (di is word pointer)
  39.     loop    rb            ; } while(--cx != 0);
  40. ; now check for odd trailing byte
  41. inobuf:
  42.     jnc    icnteven
  43.     in    al,dx
  44.     stosb                ; *di++ = al
  45. icnteven:
  46.     ret
  47.  
  48.  
  49. ;this code outputs to a port that can accept either byte or word transfers.
  50. ;if the board is in a 8-bit slot, it always receives byte transfers.
  51. ;if the board is in a 16-bit slot, it has the IOCS16 line asserted on word I/O.
  52.  
  53. repoutsw:
  54.     test    si,1            ; (buf & 1) ?
  55.     jz    obufeven        ; no
  56.     lodsb                ; al = *si++;
  57.     out    dx,al            ; out(dx,al);
  58.     dec    cx            ; cx--;
  59.     je    ocnteven
  60. obufeven:
  61.     cmp    is_186,0        ; Can we use rep outsb?
  62.     je    out86            ; no - have to do it slowly.
  63.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  64.     .286
  65.     rep    outsw
  66.     .8086
  67.     jmp    short onobuf
  68. out86:
  69.     shr    cx,1            ; cx = cnt >> 1; (convert to word count)
  70. ; Do the bulk of the buffer, a word at a time
  71.     jcxz    onobuf            ; if(cx != 0){
  72. xb:    lodsw                ; do { ax = *si++; (si is word pointer)
  73.     out    dx,ax
  74.     loop    xb            ; } while(--cx != 0); }
  75. ; now check for odd trailing byte
  76. onobuf:
  77.     jnc    ocnteven
  78.     lodsb                ;   out(dx,*si++);
  79.     out    dx,al
  80. ocnteven:
  81.     ret
  82.