home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / driver6s / pktsend.asm < prev    next >
Assembly Source File  |  1990-03-14  |  7KB  |  335 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. copyleft_msg    label    byte
  31.  db "Packet sender version ",'0'+majver,".",'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. int_pkt    macro
  37.     pushf
  38.     cli
  39.     call    their_isr
  40.     endm
  41.  
  42. their_isr    dd    ?
  43. packet_int_no    db    ?,?
  44. handle        dw    ?
  45. repeat_switch    db    ?
  46.  
  47. send_count    dw    ?
  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: pktsend <packet_int_no> [-r] [-f filename | packet]",'$'
  54. sending_msg    label    byte
  55.     db    "Press space to re-send packet.  Any other key exits.",CR,LF,'$'
  56. repeat_msg    label    byte
  57.     db    "Sending repeat packets.  Any key exits.",CR,LF,'$'
  58. file_not_found    db    "File not found",'$'
  59. read_trouble    db    "Trouble reading the file",'$'
  60. non_number_msg    db    "Non-numeric input found",'$'
  61. mem_trashed_msg    db    "Found trashed memory",'$'
  62.  
  63. line_buffer    db    128 dup(?)
  64.  
  65. usage_error:
  66.     mov    dx,offset usage_msg
  67. error:
  68.     mov    ah,9
  69.     int    21h
  70.     int    20h
  71.  
  72. start_1:
  73.     mov    dx,offset copyleft_msg
  74.     mov    ah,9
  75.     int    21h
  76.  
  77.     mov    si,offset phd_dioa+1
  78.     cmp    byte ptr [si],CR    ;end of line?
  79.     je    usage_error
  80.  
  81.     mov    di,offset packet_int_no
  82.     call    get_number
  83.  
  84. another_switch:
  85.     call    skip_blanks
  86.  
  87.     mov    al,[si]            ;did the give the packet inline?
  88.     cmp    al,'-'            ;did they specify a switch?
  89.     jne    not_switch
  90.     cmp    byte ptr [si+1],'r'    ;did they specify '-r'?
  91.     je    got_repeat_switch
  92.     cmp    byte ptr [si+1],'f'    ;did they specify '-f'?
  93.     jne    usage_error        ;no, must be an error.
  94.     add    si,2
  95.     call    skip_blanks
  96.     jmp    start_file
  97. got_repeat_switch:
  98.     mov    repeat_switch,1
  99.     add    si,2
  100.     jmp    another_switch
  101. not_switch:
  102.     jmp    start_inline        ;yes.
  103.  
  104. start_file:
  105.     mov    dx,si            ;remember where the filename starts.
  106. start_3:
  107.     lodsb
  108.     cmp    al,' '
  109.     je    start_4
  110.     cmp    al,CR
  111.     jne    start_3
  112. start_4:
  113.     dec    si
  114.     mov    byte ptr [si],0
  115.  
  116. ;read the packet bytes from the named file.
  117.  
  118.     mov    ax,3d00h        ;open for reading.
  119.     int    21h
  120.     mov    dx,offset file_not_found
  121.     jc    error
  122.     mov    handle,ax
  123.  
  124.     mov    di,offset our_buffer
  125. start_line:
  126.     mov    si,offset line_buffer
  127. again_line:
  128.     mov    ah,3fh            ;read a single character.
  129.     mov    bx,handle
  130.     mov    cx,1
  131.     mov    dx,si
  132.     int    21h
  133.     mov    dx,offset read_trouble
  134.     jc    error
  135.     cmp    ax,1            ;did we actually read one?
  136.     je    not_eof
  137.     cmp    si,offset line_buffer    ;did we read anything this time?
  138.     je    start_file_eof        ;no, it's really eof this time.
  139.     mov    [si],byte ptr CR    ;add an extra CR, just in case.
  140.     jmp    short done_reading
  141. not_eof:
  142.     lodsb                ;get the character we just read.
  143.     cmp    al,LF            ;got the LF?
  144.     jne    again_line        ;no, read again.
  145.  
  146. done_reading:
  147.     mov    si,offset line_buffer
  148. again_chars:
  149.     call    get_number
  150.     jnc    got_a_number
  151.     mov    dx,offset non_number_msg
  152.     jmp    error
  153. got_a_number:
  154.     inc    di
  155.     call    skip_blanks
  156.     cmp    al,CR
  157.     jne    again_chars        ;keep going to the end.
  158.  
  159.     jmp    start_line
  160.  
  161. start_file_eof:
  162.     mov    ah,3eh            ;close the file.
  163.     mov    bx,handle
  164.     int    21h
  165.     jmp    short start_gotit
  166.  
  167. start_inline:
  168. ;read the packet bytes off the command line.
  169.     mov    di,offset our_buffer-1
  170. start_2:
  171.     inc    di            ;pre-increment
  172.     call    get_number        ;get a byte.
  173.     jnc    start_2            ;keep going to the end.
  174.  
  175. start_gotit:
  176.  
  177.     sub    di,offset our_buffer
  178.     mov    send_count,di
  179.  
  180.     mov    sp,offset start        ;now that we're finished with
  181.                     ;the parameters, put our stack there.
  182.  
  183.     mov    di,offset our_buffer + GIANT * 2
  184.     inc    di
  185.     and    di,not 1
  186.     push    cs
  187.     pop    es
  188. init_memory:
  189.     mov    ax,055aah        ;initialize a segment to 055aah.
  190.     mov    cx,di
  191.     neg    cx
  192.     shr    cx,1
  193.     stosw
  194.     sub    cx,2
  195.     rep    stosw
  196.     mov    ax,es
  197.     add    ax,1000h
  198.     mov    es,ax
  199.     cmp    ax,9000h        ;don't go past 9000h.
  200.     jbe    init_memory
  201.  
  202.     mov    ah,35h            ;get their packet interrupt.
  203.     mov    al,packet_int_no
  204.     int    21h
  205.     mov    their_isr.offs,bx
  206.     mov    their_isr.segm,es
  207.  
  208.     lea    di,3[bx]
  209.     mov    si,offset signature
  210.     mov    cx,signature_len
  211.     repe    cmpsb
  212.     je    signature_ok
  213.     jmp    no_signature_err
  214. signature_ok:
  215.  
  216.     push    ds
  217.     mov    ax,1ffh            ;driver_info
  218.     int_pkt
  219.     pop    ds
  220.     call    fatal_error
  221.  
  222.     mov    ah,2            ;access all packets.
  223.     mov    al,ch            ;their class from driver_info().
  224.     mov    bx,dx            ;their type from driver_info().
  225.     mov    dl,cl            ;their number from driver_info().
  226.     mov    cx,0            ;type length of zero.
  227.     push    cs            ;es:di -> our receiver.
  228.     pop    es
  229.     mov    di,offset our_recv
  230.     int_pkt
  231.     call    fatal_error
  232.     mov    handle,ax
  233.  
  234.     mov    dx,offset sending_msg
  235.     cmp    repeat_switch,0
  236.     je    say_sending
  237.     mov    dx,offset repeat_msg
  238. say_sending:
  239.     mov    ah,9
  240.     int    21h
  241.  
  242. wait_for_key:
  243.     mov    ah,4
  244.     mov    si,offset our_buffer    ;ds:si -> buffer.
  245.     mov    cx,send_count
  246.     int_pkt
  247.     jc    pkt_bad
  248.  
  249.     cmp    repeat_switch,0        ;did they ask for repeat sending?
  250.     jne    send_repeat
  251.  
  252.     mov    ah,0            ;read a key.
  253.     int    16h
  254.     cmp    al,' '
  255.     je    wait_for_key        ;a space -- send again.
  256.     jmp    short send_done
  257.  
  258. send_repeat:
  259.     mov    al,'.'
  260.     call    chrout
  261.  
  262.     mov    ah,1            ;check for any key.
  263.     int    16h
  264.     je    wait_for_key        ;no key -- keep waiting.
  265. send_done:
  266.  
  267.     mov    ah,0            ;read a key.
  268.     int    16h
  269.  
  270.     mov    ah,3            ;release the handle.
  271.     mov    bx,handle
  272.     int_pkt
  273.     call    fatal_error
  274.  
  275.     mov    di,offset our_buffer + GIANT * 2
  276.     inc    di
  277.     and    di,not 1
  278.     push    cs
  279.     pop    es
  280. compare_memory:
  281.     mov    ax,055aah        ;compare a segment against 055aah.
  282.     mov    cx,di
  283.     neg    cx
  284.     shr    cx,1
  285.     scasw
  286.     jne    memory_bad
  287.     sub    cx,2
  288.     repe    scasw
  289.     jne    memory_bad
  290.     mov    ax,es
  291.     add    ax,1000h
  292.     mov    es,ax
  293.     cmp    ax,9000h        ;don't go past 9000h.
  294.     jbe    compare_memory
  295.  
  296.     int    20h
  297. pkt_bad:
  298.     call    print_error
  299.     int    20h
  300.  
  301. memory_bad:
  302.     mov    dx,offset mem_trashed_msg
  303.     mov    ah,9
  304.     int    21h
  305.     int    20h
  306.  
  307. no_signature_err:
  308.     mov    dx,offset no_signature_msg
  309.     mov    ah,9
  310.     int    21h
  311.     int    20h
  312.  
  313.  
  314. our_recv:
  315.     or    ax,ax            ;first or second call?
  316.     jne    our_recv_1        ;second -- we ignore the packet
  317.     push    cs
  318.     pop    es
  319.     mov    di,offset our_buffer + GIANT
  320. our_recv_1:
  321.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  322.  
  323.  
  324.     include    pkterr.asm
  325.     include    getnum.asm
  326.     include    getdig.asm
  327.     include    skipblk.asm
  328.     include    chrout.asm
  329.  
  330. our_buffer    label    byte
  331.  
  332. code    ends
  333.  
  334.     end    start
  335.