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

  1. version    equ    0
  2.  
  3. ;  Russell Nelson, Clarkson University.  October 20, 1988
  4. ;  Copyright, 1988, 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 receiver 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. packet_flag    dw    0
  47. first_count    dw    ?
  48. second_count    dw    ?
  49. signature    db    'PKT DRVR',0
  50. signature_len    equ    $-signature
  51. no_signature_msg    db    "No packet driver at that address",'$'
  52. usage_msg    db    "usage: pktall <packet_int_no>",'$'
  53. waiting_msg    label    byte
  54.     db    "Now waiting for packets to be received.  A dot will be printed when one is",CR,LF
  55.     db    "received.  Press any key to exit.",CR,LF,'$'
  56. counts_bad_msg    db    "First and second counts didn't match",CR,LF,'$'
  57. not_first_msg    db    "Driver maybe wrote too little",CR,LF,'$'
  58. not_second_msg    db    "Driver wrote too much",CR,LF,'$'
  59.  
  60.  
  61. usage_error:
  62.     mov    dx,offset usage_msg
  63. error:
  64.     mov    ah,9
  65.     int    21h
  66.     int    20h
  67.  
  68. start_1:
  69.     mov    dx,offset copyleft_msg
  70.     mov    ah,9
  71.     int    21h
  72.  
  73.     mov    si,offset phd_dioa+1
  74.     cmp    byte ptr [si],CR    ;end of line?
  75.     je    usage_error
  76.  
  77.     mov    di,offset packet_int_no
  78.     call    get_number
  79.  
  80.     mov    ah,35h            ;get their packet interrupt.
  81.     mov    al,packet_int_no
  82.     int    21h
  83.     mov    their_isr.offs,bx
  84.     mov    their_isr.segm,es
  85.  
  86.     lea    di,3[bx]
  87.     mov    si,offset signature
  88.     mov    cx,signature_len
  89.     repe    cmpsb
  90.     mov    dx,offset no_signature_msg
  91.     jne    error
  92.  
  93.     push    ds
  94.     mov    ax,1ffh            ;driver_info
  95.     int_pkt
  96.     pop    ds
  97.     call    fatal_error
  98.  
  99.     mov    ah,2            ;access all packets.
  100.     mov    al,ch            ;their class from driver_info().
  101.     mov    bx,dx            ;their type from driver_info().
  102.     mov    dl,cl            ;their number from driver_info().
  103.     mov    cx,0            ;type length of zero.
  104.     push    cs            ;es:di -> our receiver.
  105.     pop    es
  106.     mov    di,offset our_recv
  107.     int_pkt
  108.     call    fatal_error
  109.     mov    handle,ax
  110.  
  111.     mov    dx,offset waiting_msg
  112.     mov    ah,9
  113.     int    21h
  114.  
  115. wait_for_key:
  116.     cmp    packet_flag,0
  117.     je    no_packet
  118.  
  119.     mov    ax,first_count        ;do the counts match?
  120.     cmp    ax,second_count
  121.     je    counts_ok
  122.  
  123.     mov    ax,first_count
  124.     call    wordout
  125.  
  126.     mov    al,' '
  127.     call    chrout
  128.  
  129.     mov    ax,second_count
  130.     call    wordout
  131.  
  132.     mov    dx,offset counts_bad_msg
  133.     mov    ah,9
  134.     int    21h
  135. counts_ok:
  136.  
  137.     mov    bx,offset our_buffer    ;find the end of the buffer.
  138.     add    bx,first_count
  139.     cmp    [bx-1],bl        ;did we overwrite the first byte
  140.     jne    wrote_first        ;  of the magic value?
  141.     mov    dx,offset not_first_msg
  142.     mov    ah,9
  143.     int    21h
  144. wrote_first:
  145.  
  146.     cmp    [bx],bh            ;did we preserve the second byte
  147.     je    wrote_second        ;  of the magic value?
  148.     mov    dx,offset not_second_msg
  149.     mov    ah,9
  150.     int    21h
  151. wrote_second:
  152.  
  153.     mov    al,'.'
  154.     call    chrout
  155.  
  156.     mov    packet_flag,0
  157. no_packet:
  158.     mov    ah,1            ;check for any key.
  159.     int    16h
  160.     je    wait_for_key        ;no key -- keep waiting.
  161.  
  162.     mov    ah,0            ;fetch the key.
  163.     int    16h
  164.  
  165.     mov    ah,3
  166.     mov    bx,handle
  167.     int_pkt
  168.     call    fatal_error
  169.  
  170.     int    20h
  171.  
  172.  
  173. our_recv:
  174.     or    ax,ax            ;first or second call?
  175.     jne    our_recv_1        ;second -- bump the packet flag.
  176.     cmp    cs:packet_flag,0    ;Do we already have one?
  177.     jne    our_recv_2        ;yes - return zero.
  178.     push    cs
  179.     pop    es
  180.     mov    di,offset our_buffer
  181.     mov    bx,di            ;find the end of the buffer.
  182.     add    bx,cx
  183.     mov    cs:[bx-1],bx        ;store a magic value there.
  184.     mov    cs:first_count,cx    ;remember the first count.
  185.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  186. our_recv_2:
  187.     xor    di,di
  188.     mov    es,ax
  189.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  190. our_recv_1:
  191.     mov    cs:second_count,cx    ;remember the second count.
  192.     inc    cs:packet_flag
  193.     db    0cbh            ;masm 4.0 doesn't grok "retf"
  194.  
  195.  
  196.     include    pkterr.asm
  197.     include    getnum.asm
  198.     include    getdig.asm
  199.     include    skipblk.asm
  200.     include    digout.asm
  201.     include    chrout.asm
  202.  
  203. our_buffer    label    byte
  204.  
  205. code    ends
  206.  
  207.     end    start
  208.