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

  1. version    equ    1
  2.  
  3. ;  Copyright, 1989-1992, Russell Nelson, Crynwr Software
  4.  
  5. ;   This program is free software; you can redistribute it and/or modify
  6. ;   it under the terms of the GNU General Public License as published by
  7. ;   the Free Software Foundation, version 1.
  8. ;
  9. ;   This program is distributed in the hope that it will be useful,
  10. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ;   GNU General Public License for more details.
  13. ;
  14. ;   You should have received a copy of the GNU General Public License
  15. ;   along with this program; if not, write to the Free Software
  16. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18.     include    defs.asm
  19.  
  20. code    segment word public
  21.     assume    cs:code, ds:code
  22.  
  23.     org    80h
  24. phd_dioa    label    byte
  25.  
  26.     org    100h
  27. start:
  28.     jmp    start_1
  29.  
  30. copyleft_msg    label    byte
  31.  db "Packet multicast version ",'0'+(majver / 10),'0'+(majver mod 10),".",'0'+version," copyright 1990, Russell Nelson.",CR,LF
  32.  db "This program is free software; see the file COPYING for details.",CR,LF
  33.  db "NO WARRANTY; see the file COPYING for details.",CR,LF
  34. crlf_msg    db    CR,LF,'$'
  35.  
  36. their_isr    dd    ?
  37. entry_point    db    ?,?
  38. handle        dw    ?
  39. their_es    dw    ?
  40.  
  41. multi_count    dw    -1        ;default to not setting any.
  42.  
  43. signature    db    'PKT DRVR',0
  44. signature_len    equ    $-signature
  45.  
  46. no_signature_msg    db    "No packet driver at that address",'$'
  47. usage_msg    db    "usage: pktmulti <packet_int_no> [-f <filename> | <address> ...]",'$'
  48. file_not_found    db    "File not found",'$'
  49. read_trouble    db    "Trouble reading the file",'$'
  50.  
  51. line_buffer    db    128 dup(?)
  52.  
  53. usage_error:
  54.     mov    dx,offset usage_msg
  55. error:
  56.     mov    ah,9
  57.     int    21h
  58.     int    20h
  59.  
  60. start_1:
  61.     cld
  62.  
  63.     mov    dx,offset copyleft_msg
  64.     mov    ah,9
  65.     int    21h
  66.  
  67.     mov    si,offset phd_dioa+1
  68.     call    skip_blanks
  69.     cmp    al,CR            ;end of line?
  70.     je    usage_error
  71.  
  72.     mov    di,offset entry_point
  73.     call    get_number
  74.  
  75.     call    skip_blanks
  76.     cmp    al,CR            ;did they just give an interrupt?
  77.     jne    have_arguments
  78.     jmp    start_noset        ;yes, don't set any addresses.
  79. have_arguments:
  80.  
  81.     mov    al,[si]            ;did the give the packet inline?
  82.     cmp    al,'-'            ;did they specify a switch?
  83.     jne    not_switch
  84.     cmp    byte ptr [si+1],'f'    ;did they specify '-f'?
  85.     jne    usage_error        ;no, must be an error.
  86.     add    si,2
  87.     call    skip_blanks
  88.     jmp    start_file
  89. not_switch:
  90.     jmp    start_inline        ;yes.
  91.  
  92. start_file:
  93.     mov    dx,si            ;remember where the filename starts.
  94. start_3:
  95.     lodsb
  96.     cmp    al,' '
  97.     je    start_4
  98.     cmp    al,CR
  99.     jne    start_3
  100. start_4:
  101.     dec    si
  102.     mov    byte ptr [si],0
  103.  
  104. ;read the packet bytes from the named file.
  105.  
  106.     mov    ax,3d00h        ;open for reading.
  107.     int    21h
  108.     mov    dx,offset file_not_found
  109.     jc    error
  110.     mov    handle,ax
  111.  
  112.     mov    di,offset our_buffer
  113. start_line:
  114.     mov    si,offset line_buffer
  115. again_line:
  116.     mov    ah,3fh            ;read a single character.
  117.     mov    bx,handle
  118.     mov    cx,1
  119.     mov    dx,si
  120.     int    21h
  121.     mov    dx,offset read_trouble
  122.     jc    error
  123.     cmp    ax,1            ;did we actually read one?
  124.     jne    start_file_eof
  125.  
  126.     lodsb                ;get the character we just read.
  127.     cmp    al,LF            ;got the LF?
  128.     jne    again_line        ;no, read again.
  129.  
  130.     mov    si,offset line_buffer
  131. again_chars:
  132.     movseg    es,ds
  133.     call    get_eaddr        ;get_eaddr increments di.
  134.     call    skip_blanks
  135.     cmp    al,CR
  136.     jne    again_chars        ;keep going to the end.
  137.  
  138.     jmp    start_line
  139.  
  140. start_file_eof:
  141.     mov    [si],byte ptr CR    ;add an extra LF, just in case.
  142.     mov    si,offset line_buffer    ;and get the last address, just
  143.     movseg    es,ds
  144.     call    get_eaddr        ;  in case they didn't CRLF after it.
  145. start_file_1:
  146.     mov    ah,3eh            ;close the file.
  147.     mov    bx,handle
  148.     int    21h
  149.     jmp    short start_gotit
  150.  
  151. start_inline:
  152. ;read the multicast addresses off the command line.
  153.     mov    di,offset our_buffer
  154. start_2:
  155.     movseg    es,ds
  156.     call    get_eaddr        ;get an address.
  157.     call    skip_blanks
  158.     cmp    al,CR
  159.     jne    start_2            ;keep going to the end.
  160.  
  161. start_gotit:
  162.  
  163.     sub    di,offset our_buffer
  164.     mov    multi_count,di
  165.  
  166. start_noset:
  167.  
  168.     mov    ah,35h            ;get their packet interrupt.
  169.     mov    al,entry_point
  170.     int    21h
  171.     mov    their_isr.offs,bx
  172.     mov    their_isr.segm,es
  173.  
  174.     lea    di,3[bx]
  175.     mov    si,offset signature
  176.     mov    cx,signature_len
  177.     repe    cmpsb
  178.     je    signature_ok
  179.     jmp    no_signature_err
  180. signature_ok:
  181.  
  182.     mov    ax,1ffh            ;driver_info
  183.     call    int_pkt
  184.     call    fatal_error
  185.  
  186.     mov    ah,2            ;access all packets.
  187.     mov    al,ch            ;their class from driver_info().
  188.     mov    bx,dx            ;their type from driver_info().
  189.     mov    dl,cl            ;their number from driver_info().
  190.     mov    cx,0            ;type length of zero.
  191.     movseg    es,cs
  192.     mov    di,offset our_recv
  193.     call    int_pkt
  194.     call    fatal_error
  195.     mov    handle,ax
  196.  
  197.     cmp    multi_count,-1        ;should we not set any?
  198.     je    just_print        ;yes, just print the current list.
  199.  
  200.     mov    ah,22            ;set_multicast_list
  201.     movseg    es,ds
  202.     mov    di,offset our_buffer    ;ds:si -> buffer.
  203.     mov    cx,multi_count
  204.     call    int_pkt
  205.     call    print_error
  206.  
  207. just_print:
  208.     mov    ah,23            ;get_multicast_list
  209.     call    int_pkt
  210.     call    print_error
  211.  
  212.     push    ds
  213.     mov    ds,their_es
  214.     mov    si,di
  215.     jmp    short print_countdown
  216. print_another_address:
  217.     push    cx
  218.  
  219.     call    print_ether_addr
  220.  
  221.     push    ds
  222.     mov    ax,cs
  223.     mov    ds,ax
  224.     mov    dx,offset crlf_msg
  225.     mov    ah,9
  226.     int    21h
  227.     pop    ds
  228.  
  229.     pop    cx
  230. print_countdown:
  231.     sub    cx,EADDR_LEN
  232.     jae    print_another_address
  233.  
  234.     pop    ds
  235.  
  236.     mov    ah,3            ;release the handle.
  237.     mov    bx,handle
  238.     call    int_pkt
  239.     call    print_error
  240.  
  241.     int    20h
  242.  
  243. no_signature_err:
  244.     mov    dx,offset no_signature_msg
  245.     mov    ah,9
  246.     int    21h
  247.     int    20h
  248.  
  249.  
  250. our_recv:
  251.     or    ax,ax            ;first or second call?
  252.     jne    our_recv_1        ;second -- we ignore the packet
  253.     movseg    es,cs
  254.     mov    di,offset our_buffer
  255. our_recv_1:
  256.     retf
  257.  
  258.  
  259.     assume    ds:code
  260.  
  261. int_pkt:
  262.     push    ds
  263.     push    es
  264.     pushf
  265.     cli
  266.     call    their_isr
  267.     mov    cs:their_es,es
  268.     pop    es
  269.     pop    ds
  270.     ret
  271.  
  272.     include    getea.asm
  273.     include    printea.asm
  274.     include    getnum.asm
  275.     include    skipblk.asm
  276.     include    getdig.asm
  277.     include    digout.asm
  278.     include    chrout.asm
  279.     include    pkterr.asm
  280.  
  281.     align    4
  282. our_buffer    label    byte
  283.  
  284. code    ends
  285.  
  286.     end    start
  287.