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

  1. version    equ    2
  2. ;History:37,1
  3.  
  4.     include    defs.asm
  5.  
  6. code    segment    word public
  7.     assume    cs:code, ds:code
  8.  
  9. KOMBO    equ    1
  10.  
  11. ;This source code is for both 8-bit and 16-bit boards.  The 8-bit boards
  12. ;must be accessed 8 bits at a time, and the 16-bit boards must be accessed
  13. ;16 bits at a time.  Since the 16-bit access is a one-byte instruction
  14. ;(out dx,ax), it seems too wasteful to use a subroutine.  Therefore, we
  15. ;compile two different drivers.  Modify the following equate for the
  16. ;current driver:
  17.  
  18. BIT_8_NOT_16    equ    0        ;=1 for 8-bit, =0 for 16-bit.
  19.  
  20.   if BIT_8_NOT_16
  21.     include    io8.asm
  22. repouts    equ    repoutsb
  23. repins    equ    repinsb
  24.   else
  25.     include    io16.asm
  26. repouts    equ    obufeven
  27. repins    equ    ibufeven
  28.   endif
  29.  
  30. TP_XCVR        equ    0
  31. BNC_XCVR    equ    1
  32. AUI_XCVR    equ    2
  33. AUTO_XCVR    equ    3
  34.  
  35. current_xcvr    db    ?
  36.  
  37. ; Registers
  38.  
  39. K2WR    equ    07h            ;ksetup 2 write
  40. KSTAT    equ    07h            ;kombo status
  41.  
  42. ; Status Register (STAT, read only)
  43. ;
  44. C04_SQE        equ    0800h        ;only on 80c04
  45. C04_COLL16    equ    1000h        ;only on 80c04
  46.  
  47. ;
  48. ; on the Kombo, the following bits have the following definitions
  49. UTPDIS        equ     0800h
  50. SELECT_16_BIT    equ    1000h
  51. ;
  52. ; Kombo Setup 1 (K1RD)
  53. ;
  54. BASEBIT1    equ    1h        ; First I/O bit
  55. BASEBIT2    equ    2h        ; Second I/O bit
  56. BASEBIT3    equ    4h        ; Third I/O bit
  57. ROMBIT1        equ    10h        ; First rom bit
  58. ROMBIT2        equ    20h        ; Second rom bit
  59. ROMBIT3        equ    40h        ; Third rom bit
  60. ;
  61. ; Kombo Setup 2 (K2RD & K2WR)
  62. ;
  63. MODESELECT        equ    01h    ;=0 for PROM, =1 for RUN.
  64. INTBIT1            equ    02h    ;First IRQ bit
  65. INTBIT2            equ    04h    ;Second IRQ bit
  66. INTBIT3            equ    08h    ;Third IRQ bit
  67. COMPATIBILITY        equ    10h    ;bus compatibility select mode
  68. EEPROMWRITEENABLE    equ    20h    ;enable eeprom for writing
  69. ADDRESSBUMP        equ    40h    ;enable snoop
  70. COAXDIS            equ    80h    ;disable coax
  71. ;
  72. ; Kombo Setup 3 (K3RD)
  73. ;
  74. AUIEN            equ    1h    ; aui is selected
  75. ;
  76. ; Kombo Status 1 (KSTAT)
  77. ;
  78. LINKDETECT        equ    1    ; Link detect for 10baseT
  79.  
  80.     include    kodiak.inc
  81.  
  82.     even
  83. test_packet    label    byte
  84.     db    EADDR_LEN dup(?)
  85.     db    EADDR_LEN dup(?)
  86.     db    00h,2eh            ;A 46 in network order
  87.     db    0,0            ;DSAP=0 & SSAP=0 fields
  88.     db    0f3h,0            ;Control (Test Req + P bit set)
  89.  
  90. autosense:
  91.     cmp    bx,-1
  92.     jne    autosense_2
  93.     mov    bl,current_xcvr
  94.     xor    bh,bh
  95.     ret
  96. autosense_2:
  97.     cmp    bl,AUTO_XCVR
  98.     je    autosense_1
  99.     call    set_transceiver
  100.     clc
  101.     ret
  102. autosense_1:
  103.     and    setup2_reg,not COAXDIS    ;turn on TW transceiver
  104.     and    config2_reg,not (UTPDIS or SELECT_16_BIT)
  105.                     ;turn on TP transceiver, use 8 bits.
  106.     call    set_hardware
  107.     or    config2_reg,SELECT_16_BIT    ;go back to 16 bits next time.
  108.  
  109.     call    delay_150ms        ;wait for them to power up.
  110.  
  111.     loadport
  112.     setport    KSTAT            ;look for link beat.
  113.     mov    ax,1            ;(27.5 ms per increment).
  114.     call    set_timeout
  115. wait_for_TW:
  116.     in    al, dx
  117.     test    al, LINKDETECT        ;Do we have link detect?
  118.     jnz    cable_type_not_TP    ;yes, it must be TP.
  119.     mov    bl,TP_XCVR
  120.     call    set_transceiver
  121.     clc
  122.     ret
  123. cable_type_not_TP:
  124.  
  125.     call    do_timeout
  126.     jnz    wait_for_TW
  127.  
  128.     mov    bl,AUI_XCVR        ;Try this one first.
  129. ;
  130. ; Try sending a packet on each interface.  Configure ourselves to one that it
  131. ; works on.
  132. ;
  133. send_test_start:
  134. ;here with bl = transceiver
  135.     call    set_transceiver
  136.     mov    ax,(20000+274)/275    ;compute count (27.5 ms per increment).
  137.     call    delay_while
  138.  
  139.     mov    received_ours,0
  140.     mov    si,offset my_address    ;set the destination address.
  141.     movseg    es,cs
  142.     mov    di,offset test_packet
  143.     repmov    EADDR_LEN
  144.     mov    si,offset my_address    ;set the source address.
  145.     repmov    EADDR_LEN
  146.     mov    cx,6            ;try six times.
  147. send_test_again:
  148.     push    cx
  149.     mov    cx,60
  150.     mov    si,offset test_packet
  151.     call    send_pkt
  152.     pop    cx
  153.  
  154.     mov    ax,2            ;wait 27.5ms
  155.     call    set_timeout
  156. send_test_wait:
  157.     push    cx
  158.     call    recv
  159.     pop    cx
  160.     cmp    received_ours,0        ;did we get it?
  161.     jne    send_test_exit        ;yes, it worked.
  162.     loadport            ;get the status and see if it's COLL16.
  163.     setport    STAT
  164.     inw
  165.     test    ax,C04_COLL16        ;if this bit is a zero, we failed this
  166.     je    send_test_failed1    ;  test.
  167.     call    do_timeout
  168.     jnz    send_test_wait
  169. send_test_failed1:
  170.     to_scrn    23,78,'T'
  171.     loop    send_test_again
  172.  
  173. ;it failed multiple times.  Try again on a different interface.
  174.     cmp    current_xcvr,BNC_XCVR    ;did we just try this one?
  175.     je    send_test_fail        ;yes, no more to try, give up.
  176.  
  177.     mov    bl,BNC_XCVR
  178.     jmp    send_test_start
  179.  
  180. send_test_fail:
  181.     to_scrn    23,77,'F'
  182.     mov    bl,AUI_XCVR        ;turn off both power supplies.
  183.     call    set_transceiver
  184.     mov    dh,CANT_SET
  185.     mov    bl,AUTO_XCVR
  186.     stc
  187.     ret
  188.  
  189. send_test_exit:
  190.     mov    bl,current_xcvr
  191.     xor    bh,bh
  192.     clc
  193.     ret
  194.  
  195.  
  196. delay_150ms:
  197.     mov    ax,(1500+274)/275    ;compute count (27.5 ms per increment).
  198. delay_while:
  199.     call    set_timeout
  200. delay_150ms_1:
  201.     call    do_timeout
  202.     jnz    delay_150ms_1
  203.     ret
  204.  
  205.  
  206. set_transceiver:
  207. ;enter with bl = desired transceiver type.
  208.     assume    ds:code
  209.     cmp    bl,BNC_XCVR
  210.     jne    set_transceiver_TP
  211.     and    setup2_reg,not COAXDIS    ;turn on the TW transceiver
  212.     or    config2_reg,UTPDIS    ;turn off TP transceiver
  213.     jmp    short set_transceiver_done
  214.  
  215. set_transceiver_TP:
  216.     cmp    bl,TP_XCVR
  217.     jne    set_transceiver_AUI
  218.     or    setup2_reg,COAXDIS    ;turn off the TW transceiver
  219.     and    config2_reg,not UTPDIS    ;turn on TP transceiver
  220.     jmp    short set_transceiver_done
  221.  
  222. set_transceiver_AUI:
  223.     or    setup2_reg,COAXDIS    ;turn off the TW transceiver
  224.     or    config2_reg,UTPDIS    ;turn off TP transceiver
  225.  
  226. set_transceiver_done:
  227.     mov    current_xcvr,bl        ;remember which one we're using.
  228.  
  229. set_hardware:
  230.     loadport            ;inform the hardware of our decision.
  231.     setport    K2WR
  232.     mov    al,setup2_reg
  233.     out    dx,al
  234.  
  235.     setport    CONFIG2
  236.     mov    ax,config2_reg
  237.     outw
  238.     ret
  239.  
  240.     include    kodiak.asm
  241.  
  242. code    ends
  243.  
  244.     end
  245.