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

  1. version    equ    2
  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 mode 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. packet_mode    dw    -1,?
  39.  
  40. handle        dw    0
  41. this_mode    dw    ?
  42. bogus_type    db    0,0        ;totally bogus type code.
  43.  
  44. signature    db    'PKT DRVR',0
  45. signature_len    equ    $-signature
  46. no_signature_msg    db    "No packet driver at that address",'$'
  47. usage_msg    db    "usage: pktmode <packet_int_no> [<mode>]",'$'
  48. bad_handle_msg    db    "Bad handle error",'$'
  49. bad_mode_msg    db    "Bad mode error",'$'
  50. bad_error_msg    db    "Unknown error",'$'
  51.  
  52. not_implemented    db    "no      ",'$'
  53. current_mode    db    "current ",'$'
  54. two_spaces    db    "yes     ",'$'
  55.  
  56. mode_names    dw    mode_1_msg,mode_2_msg,mode_3_msg,mode_4_msg
  57.         dw    mode_5_msg,mode_6_msg,mode_7_msg
  58.  
  59. mode_1_msg    db    "1) Turn off receiver",CR,LF,'$'
  60. mode_2_msg    db    "2) Receive only packets sent to this interface",CR,LF,'$'
  61. mode_3_msg    db    "3) Mode 2 plus broadcast",CR,LF,'$'
  62. mode_4_msg    db    "4) Mode 3 plus limited multicast",CR,LF,'$'
  63. mode_5_msg    db    "5) Mode 3 plus all multicast",CR,LF,'$'
  64. mode_6_msg    db    "6) All packets",CR,LF,'$'
  65. mode_7_msg    db    "7) Raw mode",CR,LF,'$'
  66.  
  67.  
  68. usage_error:
  69.     mov    dx,offset usage_msg
  70. error:
  71.     mov    ah,9
  72.     int    21h
  73.     jmp    all_done
  74.  
  75. start_1:
  76.     cld
  77.  
  78.     mov    dx,offset copyleft_msg
  79.     mov    ah,9
  80.     int    21h
  81.  
  82.     mov    si,offset phd_dioa+1
  83.     cmp    byte ptr [si],CR    ;end of line?
  84.     je    usage_error
  85.  
  86.     mov    di,offset entry_point
  87.     call    get_number
  88.     mov    di,offset packet_mode
  89.     call    get_number
  90.  
  91.     mov    ah,35h            ;get their packet interrupt.
  92.     mov    al,entry_point
  93.     int    21h
  94.     mov    their_isr.offs,bx
  95.     mov    their_isr.segm,es
  96.  
  97.     lea    di,3[bx]
  98.     mov    si,offset signature
  99.     mov    cx,signature_len
  100.     repe    cmpsb
  101.     je    signature_ok
  102.     mov    dx,offset no_signature_msg
  103.     jmp    error
  104. bad_j_1:
  105.     jmp    bad
  106. signature_ok:
  107.  
  108.     mov    ax,1ffh            ;driver_info
  109.     call    int_pkt
  110.     call    fatal_error
  111.  
  112.     mov    ah,2            ;access all packets.
  113.     mov    al,ch            ;their class from driver_info().
  114.     mov    bx,dx            ;their type from driver_info().
  115.     mov    dl,cl            ;their number from driver_info().
  116.     mov    cx,2            ;use a type length of 2.
  117.     mov    si,offset bogus_type
  118.     movseg    es,cs
  119.     mov    di,offset our_recv
  120.     call    int_pkt
  121.     call    fatal_error
  122.     mov    handle,ax
  123.  
  124.     mov    cx,packet_mode
  125.     cmp    cx,-1
  126.     je    get_mode
  127.  
  128.     mov    ah,20            ;set the receive mode.
  129.     mov    bx,handle
  130.     call    int_pkt
  131.     jc    bad_j_1
  132.  
  133.     mov    bx,cx            ;print the name of this mode.
  134.     shl    bx,1
  135.     mov    ah,9
  136.     mov    dx,mode_names[bx-2]
  137.     int    21h
  138.  
  139.     jmp    okay
  140. ;now print the current mode.
  141.  
  142. get_mode:
  143.     mov    ah,21            ;get the receive mode.
  144.     mov    bx,handle
  145.     call    int_pkt
  146.     jc    bad
  147.     mov    packet_mode,ax
  148.  
  149.     mov    this_mode,1        ;start trying with mode 1.
  150. try_mode:
  151.     cmp    this_mode,6        ;have we hit the last mode?
  152.     ja    no_more_modes        ;yes.
  153.  
  154.     mov    ah,20            ;set the receive mode.
  155.     mov    bx,handle
  156.     mov    cx,this_mode
  157.     call    int_pkt
  158.     mov    dx,offset not_implemented
  159.     jc    tried_mode        ;we tried it, and it didn't work.
  160.     mov    dx,offset current_mode
  161.     mov    cx,this_mode        ;is this the current mode?
  162.     cmp    packet_mode,cx
  163.     je    tried_mode
  164.     mov    dx,offset two_spaces
  165. tried_mode:
  166.     mov    ah,9            ;print either "  ", "xx", or "->"
  167.     int    21h
  168.  
  169.     mov    bx,this_mode        ;print the name of this mode.
  170.     shl    bx,1
  171.     mov    ah,9
  172.     mov    dx,mode_names[bx-2]
  173.     int    21h
  174.  
  175.     inc    this_mode        ;try the next mode.
  176.     jmp    try_mode
  177.  
  178. no_more_modes:
  179.  
  180.     mov    ah,20            ;set the receive mode.
  181.     mov    bx,handle
  182.     mov    cx,packet_mode
  183.     call    int_pkt
  184.  
  185. all_done:
  186.     xor    bx,bx            ;only release the handle once.
  187.     xchg    bx,handle
  188.     or    bx,bx
  189.     je    all_done_1        ;we've already released it.
  190.     mov    ah,3            ;release_type
  191.     call    int_pkt
  192.     jc    bad
  193. all_done_1:
  194.     int    20h
  195.  
  196. bad:
  197.     call    print_error
  198. okay:
  199.     jmp    all_done
  200.  
  201.  
  202. our_recv:
  203.     or    ax,ax            ;first or second call?
  204.     jne    our_recv_1        ;second -- we ignore the packet
  205.     movseg    es,cs
  206.     mov    di,offset our_buffer
  207. our_recv_1:
  208.     retf
  209.  
  210.  
  211. int_pkt:
  212.     push    ds
  213.     push    es
  214.     pushf
  215.     cli
  216.     call    their_isr
  217.     pop    es
  218.     pop    ds
  219.     ret
  220.  
  221.     include    getnum.asm
  222.     include    skipblk.asm
  223.     include    getdig.asm
  224.     include    pkterr.asm
  225.     include    chrout.asm
  226.  
  227.     align    4
  228. our_buffer    label    byte
  229.  
  230. code    ends
  231.  
  232.     end    start
  233.