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

  1. version    equ    0
  2.  
  3. ;  Russell Nelson, Clarkson University.  December 24, 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 multicast 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. handle        dw    ?
  46.  
  47. multi_count    dw    -1        ;default to not setting any.
  48.  
  49. signature    db    'PKT DRVR',0
  50. signature_len    equ    $-signature
  51.  
  52. no_signature_msg    db    "No packet driver at that address",'$'
  53. usage_msg    db    "usage: pktmulti <packet_int_no> [-f <filename> | <address> ...]",'$'
  54. file_not_found    db    "File not found",'$'
  55. read_trouble    db    "Trouble reading the file",'$'
  56.  
  57. line_buffer    db    128 dup(?)
  58.  
  59. usage_error:
  60.     mov    dx,offset usage_msg
  61. error:
  62.     mov    ah,9
  63.     int    21h
  64.     int    20h
  65.  
  66. start_1:
  67.     mov    dx,offset copyleft_msg
  68.     mov    ah,9
  69.     int    21h
  70.  
  71.     mov    si,offset phd_dioa+1
  72.     cmp    byte ptr [si],CR    ;end of line?
  73.     je    usage_error
  74.  
  75.     mov    di,offset packet_int_no
  76.     call    get_number
  77.  
  78.     call    skip_blanks
  79.     cmp    al,CR            ;did they just give an interrupt?
  80.     jne    have_arguments
  81.     jmp    start_noset        ;yes, don't set any addresses.
  82. have_arguments:
  83.  
  84.     mov    al,[si]            ;did the give the packet inline?
  85.     cmp    al,'-'            ;did they specify a switch?
  86.     jne    not_switch
  87.     cmp    byte ptr [si+1],'f'    ;did they specify '-f'?
  88.     jne    usage_error        ;no, must be an error.
  89.     add    si,2
  90.     call    skip_blanks
  91.     jmp    start_file
  92. not_switch:
  93.     jmp    start_inline        ;yes.
  94.  
  95. start_file:
  96.     mov    dx,si            ;remember where the filename starts.
  97. start_3:
  98.     lodsb
  99.     cmp    al,' '
  100.     je    start_4
  101.     cmp    al,CR
  102.     jne    start_3
  103. start_4:
  104.     dec    si
  105.     mov    byte ptr [si],0
  106.  
  107. ;read the packet bytes from the named file.
  108.  
  109.     mov    ax,3d00h        ;open for reading.
  110.     int    21h
  111.     mov    dx,offset file_not_found
  112.     jc    error
  113.     mov    handle,ax
  114.  
  115.     mov    di,offset our_buffer
  116. start_line:
  117.     mov    si,offset line_buffer
  118. again_line:
  119.     mov    ah,3fh            ;read a single character.
  120.     mov    bx,handle
  121.     mov    cx,1
  122.     mov    dx,si
  123.     int    21h
  124.     mov    dx,offset read_trouble
  125.     jc    error
  126.     cmp    ax,1            ;did we actually read one?
  127.     jne    start_file_eof
  128.  
  129.     lodsb                ;get the character we just read.
  130.     cmp    al,LF            ;got the LF?
  131.     jne    again_line        ;no, read again.
  132.  
  133.     mov    si,offset line_buffer
  134. again_chars:
  135.     call    get_address
  136.     add    di,EADDR_LEN
  137.     call    skip_blanks
  138.     cmp    al,CR
  139.     jne    again_chars        ;keep going to the end.
  140.  
  141.     jmp    start_line
  142.  
  143. start_file_eof:
  144.     mov    [si],byte ptr CR    ;add an extra LF, just in case.
  145.     mov    si,offset line_buffer    ;and get the last address, just
  146.     call    get_address        ;  in case they didn't CRLF after it.
  147. start_file_1:
  148.     mov    ah,3eh            ;close the file.
  149.     mov    bx,handle
  150.     int    21h
  151.     jmp    short start_gotit
  152.  
  153. start_inline:
  154. ;read the multicast addresses off the command line.
  155.     mov    di,offset our_buffer
  156. start_2:
  157.     call    get_address        ;get an address.
  158.     call    skip_blanks
  159.     cmp    al,CR
  160.     jne    start_2            ;keep going to the end.
  161.  
  162. start_gotit:
  163.  
  164.     sub    di,offset our_buffer
  165.     mov    multi_count,di
  166.  
  167. start_noset:
  168.  
  169.     mov    ah,35h            ;get their packet interrupt.
  170.     mov    al,packet_int_no
  171.     int    21h
  172.     mov    their_isr.offs,bx
  173.     mov    their_isr.segm,es
  174.  
  175.     lea    di,3[bx]
  176.     mov    si,offset signature
  177.     mov    cx,signature_len
  178.     repe    cmpsb
  179.     je    signature_ok
  180.     jmp    no_signature_err
  181. signature_ok:
  182.  
  183.     push    ds
  184.     mov    ax,1ffh            ;driver_info
  185.     int_pkt
  186.     pop    ds
  187.     call    fatal_error
  188.  
  189.     mov    ah,2            ;access all packets.
  190.     mov    al,ch            ;their class from driver_info().
  191.     mov    bx,dx            ;their type from driver_info().
  192.     mov    dl,cl            ;their number from driver_info().
  193.     mov    cx,0            ;type length of zero.
  194.     push    cs            ;es:di -> our receiver.
  195.     pop    es
  196.     mov    di,offset our_recv
  197.     int_pkt
  198.     call    fatal_error
  199.     mov    handle,ax
  200.  
  201.     cmp    multi_count,-1        ;should we not set any?
  202.     je    just_print        ;yes, just print the current list.
  203.  
  204.     mov    ah,22            ;set_multicast_list
  205.     push    ds
  206.     pop    es
  207.     mov    di,offset our_buffer    ;ds:si -> buffer.
  208.     mov    cx,multi_count
  209.     int_pkt
  210.     call    print_error
  211.  
  212. just_print:
  213.     mov    ah,23            ;get_multicast_list
  214.     int_pkt
  215.     call    print_error
  216.  
  217.     push    ds
  218.     mov    ax,es
  219.     mov    ds,ax
  220.     mov    si,di
  221.     jmp    short print_countdown
  222. print_another_address:
  223.     push    cx
  224.  
  225.     call    print_ether_addr
  226.  
  227.     push    ds
  228.     mov    ax,cs
  229.     mov    ds,ax
  230.     mov    dx,offset crlf_msg
  231.     mov    ah,9
  232.     int    21h
  233.     pop    ds
  234.  
  235.     pop    cx
  236. print_countdown:
  237.     sub    cx,EADDR_LEN
  238.     jae    print_another_address
  239.  
  240.     pop    ds
  241.  
  242.     mov    ah,3            ;release the handle.
  243.     mov    bx,handle
  244.     int_pkt
  245.     call    print_error
  246.  
  247.     int    20h
  248.  
  249. no_signature_err:
  250.     mov    dx,offset no_signature_msg
  251.     mov    ah,9
  252.     int    21h
  253.     int    20h
  254.  
  255.  
  256. our_recv:
  257.     or    ax,ax            ;first or second call?
  258.     jne    our_recv_1        ;second -- we ignore the packet
  259.     push    cs
  260.     pop    es
  261.     mov    di,offset our_buffer
  262. our_recv_1:
  263.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  264.  
  265.  
  266.     assume    ds:code
  267.  
  268.     include    getea.asm
  269.     include    printea.asm
  270.     include    getnum.asm
  271.     include    skipblk.asm
  272.     include    getdig.asm
  273.     include    digout.asm
  274.     include    chrout.asm
  275.     include    pkterr.asm
  276.  
  277. our_buffer    label    byte
  278.  
  279. code    ends
  280.  
  281.     end    start
  282.