home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / driver6s / pktmode.asm < prev    next >
Assembly Source File  |  1990-03-14  |  5KB  |  221 lines

  1. version    equ    0
  2.  
  3. ;  Russell Nelson, Clarkson University.  September 14, 1989
  4. ;  Copyright, 1989, Russell Nelson
  5.  
  6. ;   This program is free software; you can redistribute it and/or modify
  7. ;   it under the terms of the GNU General Public License as published by
  8. ;   the Free Software Foundation, version 1.
  9. ;
  10. ;   This program is distributed in the hope that it will be useful,
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ;   GNU General Public License for more details.
  14. ;
  15. ;   You should have received a copy of the GNU General Public License
  16. ;   along with this program; if not, write to the Free Software
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19.     include    defs.asm
  20.  
  21. code    segment byte public
  22.     assume    cs:code, ds:code
  23.  
  24.     org    80h
  25. phd_dioa    label    byte
  26.  
  27.     org    100h
  28. start:
  29.     jmp    start_1
  30.  
  31. copyleft_msg    label    byte
  32.  db "Packet mode version ",'0'+majver,".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  33.  db "This program is free software; see the file COPYING for details.",CR,LF
  34.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  35. crlf_msg    db    CR,LF,'$'
  36.  
  37. int_pkt    macro
  38.     pushf
  39.     cli
  40.     call    their_isr
  41.     endm
  42.  
  43. their_isr    dd    ?
  44. packet_int_no    db    ?,?,?,?
  45. packet_mode    dw    -1,?
  46.  
  47. handle        dw    0
  48. this_mode    dw    ?
  49. bogus_type    db    1,2,3,4,5,6,7,8        ;totally bogus type code.
  50.  
  51. signature    db    'PKT DRVR',0
  52. signature_len    equ    $-signature
  53. no_signature_msg    db    "No packet driver at that address",'$'
  54. usage_msg    db    "usage: pktmode <packet_int_no> [<mode>]",'$'
  55. bad_handle_msg    db    "Bad handle error",'$'
  56. bad_mode_msg    db    "Bad mode error",'$'
  57. bad_error_msg    db    "Unknown error",'$'
  58.  
  59. not_implemented    db    "xx ",'$'
  60. current_mode    db    "-> ",'$'
  61. two_spaces    db    "   ",'$'
  62.  
  63. mode_names    dw    mode_1_msg,mode_2_msg,mode_3_msg,mode_4_msg
  64.         dw    mode_5_msg,mode_6_msg
  65.  
  66. mode_1_msg    db    "1) Turn off receiver",CR,LF,'$'
  67. mode_2_msg    db    "2) Receive only packets sent to this interface",CR,LF,'$'
  68. mode_3_msg    db    "3) Mode 2 plus broadcast",CR,LF,'$'
  69. mode_4_msg    db    "4) Mode 3 plus limited multicast",CR,LF,'$'
  70. mode_5_msg    db    "5) Mode 3 plus all multicast",CR,LF,'$'
  71. mode_6_msg    db    "6) All packets",CR,LF,'$'
  72.  
  73.  
  74. usage_error:
  75.     mov    dx,offset usage_msg
  76. error:
  77.     mov    ah,9
  78.     int    21h
  79.     jmp    all_done
  80.  
  81. start_1:
  82.     mov    dx,offset copyleft_msg
  83.     mov    ah,9
  84.     int    21h
  85.  
  86.     mov    si,offset phd_dioa+1
  87.     cmp    byte ptr [si],CR    ;end of line?
  88.     je    usage_error
  89.  
  90.     mov    di,offset packet_int_no
  91.     call    get_number
  92.     mov    di,offset packet_mode
  93.     call    get_number
  94.  
  95.     mov    ah,35h            ;get their packet interrupt.
  96.     mov    al,packet_int_no
  97.     int    21h
  98.     mov    their_isr.offs,bx
  99.     mov    their_isr.segm,es
  100.  
  101.     lea    di,3[bx]
  102.     mov    si,offset signature
  103.     mov    cx,signature_len
  104.     repe    cmpsb
  105.     je    signature_ok
  106.     mov    dx,offset no_signature_msg
  107.     jmp    error
  108. bad_j_1:
  109.     jmp    bad
  110. signature_ok:
  111.  
  112.     push    ds
  113.     mov    ax,1ffh            ;driver_info
  114.     int_pkt
  115.     pop    ds
  116.     call    fatal_error
  117.  
  118.     mov    ah,2            ;access all packets.
  119.     mov    al,ch            ;their class from driver_info().
  120.     mov    bx,dx            ;their type from driver_info().
  121.     mov    dl,cl            ;their number from driver_info().
  122.     mov    cx,MAX_P_LEN        ;use the max type length.
  123.     mov    si,offset bogus_type
  124.     push    cs            ;es:di -> our receiver.
  125.     pop    es
  126.     mov    di,offset our_recv
  127.     int_pkt
  128.     call    fatal_error
  129.     mov    handle,ax
  130.  
  131.     mov    cx,packet_mode
  132.     cmp    cx,-1
  133.     je    get_mode
  134.  
  135.     mov    ah,20            ;set the receive mode.
  136.     mov    bx,handle
  137.     int_pkt
  138.     jc    bad_j_1
  139.     jmp    okay
  140. get_mode:
  141.     mov    ah,21            ;get the receive mode.
  142.     mov    bx,handle
  143.     int_pkt
  144.     jc    bad
  145.     mov    packet_mode,ax
  146.  
  147.     mov    this_mode,1        ;start trying with mode 1.
  148. try_mode:
  149.     cmp    this_mode,6        ;have we hit the last mode?
  150.     ja    no_more_modes        ;yes.
  151.  
  152.     mov    ah,20            ;set the receive mode.
  153.     mov    bx,handle
  154.     mov    cx,this_mode
  155.     int_pkt
  156.     mov    dx,offset not_implemented
  157.     jc    tried_mode        ;we tried it, and it didn't work.
  158.     mov    dx,offset current_mode
  159.     mov    cx,this_mode        ;is this the current mode?
  160.     cmp    packet_mode,cx
  161.     je    tried_mode
  162.     mov    dx,offset two_spaces
  163. tried_mode:
  164.     mov    ah,9            ;print either "  ", "xx", or "->"
  165.     int    21h
  166.  
  167.     mov    bx,this_mode        ;print the name of this mode.
  168.     shl    bx,1
  169.     mov    ah,9
  170.     mov    dx,mode_names[bx-2]
  171.     int    21h
  172.  
  173.     inc    this_mode        ;try the next mode.
  174.     jmp    try_mode
  175.  
  176. no_more_modes:
  177.  
  178.     mov    ah,20            ;set the receive mode.
  179.     mov    bx,handle
  180.     mov    cx,packet_mode
  181.     int_pkt
  182.  
  183. all_done:
  184.     xor    bx,bx            ;only release the handle once.
  185.     xchg    bx,handle
  186.     or    bx,bx
  187.     je    all_done_1        ;we've already released it.
  188.     mov    ah,3            ;release_type
  189.     int_pkt
  190.     jc    bad
  191. all_done_1:
  192.     int    20h
  193.  
  194. bad:
  195.     call    print_error
  196. okay:
  197.     jmp    all_done
  198.  
  199.  
  200. our_recv:
  201.     or    ax,ax            ;first or second call?
  202.     jne    our_recv_1        ;second -- we ignore the packet
  203.     push    cs
  204.     pop    es
  205.     mov    di,offset our_buffer
  206. our_recv_1:
  207.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  208.  
  209.  
  210.     include    getnum.asm
  211.     include    skipblk.asm
  212.     include    getdig.asm
  213.     include    pkterr.asm
  214.     include    chrout.asm
  215.  
  216. our_buffer    label    byte
  217.  
  218. code    ends
  219.  
  220.     end    start
  221.