home *** CD-ROM | disk | FTP | other *** search
/ PC Press: Internet / PC_PRESS.ISO / software / dos / comm / mx5.arj / TTY.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-05-18  |  11.3 KB  |  718 lines

  1. .model small
  2. dosseg
  3. .stack 2048
  4.  
  5. ;-----------------------
  6. .data
  7.  
  8. titstr        db    'TTY (c)1989 MagicSoft, Inc.  All Rights Reserved',13,10,0,26
  9. titstr1        db    13,10,10
  10.         db    'Press F1 for Help, Alt-X to Exit to DOS.',13,10
  11.         db    13,10
  12.         db    'Ready.',13,10,0
  13. nomx5        db    'ERROR: MX5 Not Installed.',7,13,10,0
  14. port_str    db    13,10,'What Com Port (1-4) [CR=COM1]? ',0
  15.  
  16. online_str    db    13,10,'═══ On-Line ═══',13,10,0
  17. offline_str    db    13,10,'═══ OffLine ═══',13,10,0
  18.  
  19. yesmnp_str    db    13,10,'═══ CONNECT/MNP'
  20. disp_lvl    db    'x ═══',13,10,0
  21. nomnp_str    db    13,10,'═══ NO CARRIER/MNP ═══',13,10,0
  22.  
  23.  
  24. instruct_str    db    'Press SPACE to Toggle, CR to Accept',13,10,0
  25.  
  26. baud_str    db    'Baud Rate',0
  27. baud        db    5
  28. bauds        dw    b192,b384,b3,b6,b12,b24,b48,b96
  29. b192        db    '19200',0
  30. b384        db    '38400',0
  31. b3        db    '300  ',0
  32. b6        db    '600  ',0
  33. b12        db    '1200 ',0
  34. b24        db    '2400 ',0
  35. b48        db    '4800 ',0
  36. b96        db    '9600 ',0
  37.  
  38. parity_str    db    'Wordlength/Parity',0
  39. parity        db    0
  40. paritys        dw    p1,p2,p3
  41. p1        db    '8/None ',0
  42. p2        db    '7/Odd  ',0
  43. p3        db    '7/Even ',0
  44.  
  45. level_str    db    'MNP Level',0
  46. real_levels    db    0,2,4,5
  47. level        db    3
  48. levels        dw    l0,l2,l4,l5
  49. l0        db    'No MNP',0
  50. l2        db    '2     ',0
  51. l4        db    '4     ',0
  52. l5        db    '5     ',0
  53.  
  54. sound_str    db    'MNP Sound Level',0
  55. sound        db    0
  56. sounds        dw    off_str,on_str
  57. off_str        db    'Off',0
  58. on_str        db    'On ',0
  59.  
  60. stuff_str    db    13,10
  61.         db    '══════ MNP Status Information ══════',13,10,10
  62.         db    ' ┌─────── Last Occurrence ────────┐',13,10,0
  63. stuff_str1    db    ' │         MNP Level : ',0
  64. stuff_str2    db    ' │         Series ID : ',0
  65.  
  66. tx_str        db    ' ┌─────────── Transmit ───────────┐',13,10,0
  67. alti_str1    db    ' │     Total Packets : ',0
  68. alti_str2    db    ' │ Duplicate Packets : ',0
  69. alti_str3    db    ' │         Max Speed : ',0
  70. tx_str1        db    ' └────────────────────────────────┘',13,10,0
  71.  
  72. rx_str        db    ' ┌─────────── Receive ────────────┐',13,10,0
  73.  
  74. help_str    db    13,10
  75.         db    ' ┌─────── TTY Alt Key Help ────────┐',13,10
  76.         db    ' │                                 │',13,10
  77.         db    ' │  F1     Help                    │',13,10
  78.         db    ' │  Alt-X  Exit to DOS             │',13,10
  79.         db    ' │  Alt-H  Hangup                  │',13,10
  80.         db    ' │  Alt-I  MNP Status Information  │',13,10
  81.         db    ' │  Alt-B  Set Baud Rate           │',13,10
  82.         db    ' │  Alt-P  Set Wordlength/Parity   │',13,10
  83.         db    ' │  Alt-L  Set MNP Connect Level   │',13,10
  84.         db    ' │  Alt-S  Set MNP Sound Level     │',13,10
  85.         db    ' │                                 │',13,10
  86.         db    ' └─────────────────────────────────┘',13,10
  87.         db    0
  88.  
  89. putdbuf        db    11 dup(0)
  90. charbuf        db    0
  91. mnpflag        db    0
  92. carrier        db    0
  93. port        dw    0
  94. ;-----------------------
  95. .code
  96. start:
  97.     mov    ax,@data        ;standard EXE segment adjust
  98.     mov    ds,ax            ;for SMALL model
  99.     mov    es,ax
  100.     mov    ss,ax
  101.     mov    sp,offset STACK
  102.  
  103.     lea    si,titstr        ;print title string
  104.     call    print
  105.  
  106.     mov    ah,0e0h            ;see if MX5 is installed
  107.     mov    al,6
  108.     mov    bx,0
  109.     int    14h
  110.     cmp    bx,'MX'
  111.     je    yesdrvr
  112.  
  113.     lea    si,nomx5        ;no, error message
  114.     call    print
  115.  
  116.     mov    al,1            ;and exit to DOS
  117.     mov    ah,4ch
  118.     int    21h
  119.  
  120. yesdrvr:
  121.     lea    si,port_str        ;ask "What port?"
  122.     call    print
  123.  
  124. askport:
  125.     call    getkey
  126.  
  127.     cmp    al,'1'
  128.     jb    bong
  129.     cmp    al,'4'
  130.     jbe    nobong
  131. bong:
  132.     cmp    al,13
  133.     je    com1
  134.  
  135.     mov    al,7
  136.     call    putc
  137.     jmp    askport
  138.  
  139. com1:
  140.     mov    al,'1'
  141. nobong:
  142.     push    ax
  143.     call    putc
  144.     pop    ax
  145.  
  146.     sub    al,'1'
  147.     mov    byte ptr port,al
  148.  
  149.     mov    ah,04h            ;Init driver
  150.     mov    dx,port
  151.     int    14h
  152.  
  153. ;----- Read Current MX5 Settings
  154.  
  155.     mov    bh,0            ;get sound level
  156.     mov    ah,0e0h
  157.     mov    al,4
  158.     mov    dx,port
  159.     int    14h
  160.     mov    sound,bl
  161.  
  162. ;----- Set MX5 Defaults
  163.  
  164.     mov    bh,1            ;set MNP level to 5
  165.     mov    bl,5
  166.     mov    ah,0e0h
  167.     mov    al,1
  168.     mov    dx,port
  169.     int    14h
  170.  
  171.     call    set_rate        ;2400,n,8,1
  172. ;-----
  173.  
  174.     lea    si,titstr1        ;"Alt-X to Exit..."
  175.     call    print
  176.  
  177. ;--------------------------------------------
  178. ;    Main Terminal Loop
  179. ;--------------------------------------------
  180. mloop:
  181.     call    checkkey        ;is there a char in kbd buffer?
  182.     jnz    yeskey
  183.     jmp    nochar            ;no, jump
  184.  
  185. yeskey:
  186.     cmp    al,0            ;yes, is it a extended key?
  187.     je    yesext            ;yes, jump
  188.     jmp    noext
  189.  
  190. yesext:
  191.     call    getkey            ;get the char from kbd buffer
  192.  
  193. ;-----------
  194.     cmp    ah,45            ;Alt-X? (exit)
  195.     jne    noaltx
  196.  
  197.     mov    ah,6            ;lower DTR
  198.     mov    al,0
  199.     mov    dx,port
  200.     int    14h
  201.  
  202.     mov    ah,5            ;deinit driver
  203.     mov    dx,port
  204.     int    14h
  205.  
  206.     mov    ah,4ch            ;exit to DOS
  207.     mov    al,0
  208.     int    21h
  209.  
  210. noaltx:
  211. ;-----------
  212.     cmp    ah,35            ;Alt-H
  213.     jne    noalth
  214.  
  215.     mov    ah,6            ;lower DTR
  216.     mov    al,0
  217.     mov    dx,port
  218.     int    14h
  219.  
  220.     mov    ah,0e0h            ;wait 500ms
  221.     mov    al,7
  222.     mov    cx,9
  223.     int    14h
  224.  
  225.     mov    ah,6            ;lower DTR
  226.     mov    al,1
  227.     mov    dx,port
  228.     int    14h
  229.  
  230.     jmp    nochar
  231.  
  232. noalth:
  233. ;-----------
  234.     cmp    ah,48            ;Alt-B
  235.     jne    noaltb
  236.  
  237.     lea    si,baud_str        ;point to "Baud Rate"
  238.     mov    cl,8            ;8 choices
  239.     lea    di,bauds        ;point to list of choices ([di][-1] => BYTE variable)
  240.     call    toggles            ;go...
  241.     call    set_rate        ;set baudrate, etc...
  242.     jmp    nochar
  243.  
  244. noaltb:
  245. ;-----------
  246.     cmp    ah,25            ;Alt-P
  247.     jne    noaltp
  248.  
  249.     lea    si,parity_str
  250.     mov    cl,3
  251.     lea    di,paritys
  252.     call    toggles
  253.     call    set_rate
  254.     jmp    nochar
  255.  
  256. noaltp:
  257. ;-----------
  258.     cmp    ah,31            ;Alt-S
  259.     jne    noalts
  260.  
  261.     lea    si,sound_str
  262.     mov    cl,2
  263.     lea    di,sounds
  264.     call    toggles
  265.  
  266.     mov    bl,sound
  267.     mov    bh,1
  268.     mov    ah,0e0h
  269.     mov    al,4
  270.     mov    dx,port
  271.     int    14h
  272.  
  273.     jmp    nochar
  274.  
  275. noalts:
  276. ;-----------
  277.     cmp    ah,38            ;Alt-L
  278.     jne    noaltl
  279.  
  280.     lea    si,level_str
  281.     mov    cl,4
  282.     lea    di,levels
  283.     call    toggles
  284.  
  285.     mov    bl,level
  286.     xor    bh,bh
  287.     mov    bl,real_levels[bx]
  288.     mov    bh,1
  289.     mov    ah,0e0h
  290.     mov    al,1
  291.     mov    dx,port
  292.     int    14h
  293.  
  294.     jmp    nochar
  295.  
  296. noaltl:
  297. ;-----------
  298.     cmp    ah,23            ;Alt-I (Info)
  299.     je    yesalti
  300.     jmp    noalti
  301.  
  302. yesalti:
  303.     push    es
  304.     mov    ah,0e0h            ;get MNP information
  305.     mov    al,0
  306.     mov    dx,port
  307.     int    14h
  308.  
  309.     xor    dx,dx
  310.     lea    si,stuff_str
  311.     call    print
  312.     xor    ah,ah
  313.     mov    al,es:[bx][1]
  314.     lea    si,stuff_str1
  315.     call    print_long1
  316.     lea    si,stuff_str2
  317.     xor    ah,ah
  318.     mov    al,es:[bx][2]
  319.     call    print_long1
  320.     lea    si,tx_str1
  321.     call    print
  322.  
  323.     lea    si,tx_str
  324.     call    print
  325.     mov    di,3
  326.     lea    si,alti_str1
  327.     call    print_long
  328.     lea    si,alti_str2
  329.     call    print_long
  330.     lea    si,alti_str3
  331.     call    print_long
  332.     lea    si,tx_str1
  333.     call    print
  334.  
  335.     lea    si,rx_str
  336.     call    print
  337.     lea    si,alti_str1
  338.     call    print_long
  339.     lea    si,alti_str2
  340.     call    print_long
  341.     lea    si,alti_str3
  342.     call    print_long
  343.     lea    si,tx_str1
  344.     call    print
  345.  
  346.     mov    al,10
  347.     call    putc
  348.  
  349.     pop    es
  350.     jmp    nochar
  351.  
  352. print_long:
  353.     mov    ax,es:[bx][di]
  354.     mov    dx,es:[bx][di][2]
  355. print_long1:
  356.     push    bx
  357.     push    di
  358.     push    si
  359.  
  360.     push    ax
  361.     call    print
  362.     pop    ax
  363.  
  364.     lea    si,putdbuf
  365.     call    xlmputd
  366.     lea    si,putdbuf
  367.     call    print
  368.  
  369.     mov    al,' '
  370.     call    putc
  371.     mov    al,179
  372.     call    putc
  373.     mov    al,13
  374.     call    putc
  375.     mov    al,10
  376.     call    putc
  377.  
  378.     pop    si
  379.     pop    di
  380.     pop    bx
  381.     add    di,4
  382.     ret
  383.  
  384. noalti:
  385. ;-----------
  386.     cmp    ah,59            ;F1? (Help)
  387.     jne    nof1
  388.     lea    si,help_str
  389.     call    print
  390.     jmp    nochar
  391.  
  392. nof1:
  393. ;-----------
  394.     jmp    nochar
  395.  
  396. ;--------------------------------------------
  397. noext:
  398.     push    ax
  399.     mov    ah,3            ;is there room in com output buffer?
  400.     mov    dx,port
  401.     int    14h
  402.     test    ah,20h
  403.     pop    ax
  404.     jz    nochar            ;no, try again later
  405.  
  406. ;*** USE WRITE BLOCK METHOD ***
  407.     lea    di,charbuf        ;point to 1 char buffer
  408.     mov    [di],al            ;place char in buffer
  409.     mov    cx,1            ;1 character
  410.     mov    ah,19h
  411.     mov    dx,port
  412.     int    14h
  413.  
  414. ;*** USE WRITE CHARACTER METHOD ***
  415. ;    mov    ah,1            ;send the character
  416. ;    mov    dx,port
  417. ;    int    14h
  418.  
  419.     call    getkey            ;eat the char from kbd buffer
  420.  
  421. nochar:
  422.     mov    ah,3            ;any received characters?
  423.     mov    dx,port
  424.     int    14h
  425.     test    ah,1
  426.     jnz    char_ready        ;yes, jump
  427.  
  428.     call    stat            ;check carrier, etc...
  429.     jmp    mloop
  430.  
  431. char_ready:
  432.     mov    ah,2            ;get the RX char
  433.     mov    dx,port
  434.     int    14h
  435.  
  436.     call    putc            ;print it to the screen
  437.     jmp    mloop
  438.  
  439. ;--------------------------------------------
  440. ;    Subroutines
  441. ;--------------------------------------------
  442. ;
  443. ; PUTC
  444. ;    Outputs a character in AL to the screen.
  445. ;
  446. putc    proc
  447.  
  448.     mov    ah,14
  449.     int    10h
  450.     ret
  451.  
  452. ;    push    dx
  453. ;    mov    ah,2
  454. ;    mov    dl,al
  455. ;    int    21h
  456. ;    pop    dx
  457. ;    ret
  458.  
  459. putc    endp
  460. ;
  461. ;--------------
  462. ;
  463. ; PRINT
  464. ;    Outputs an ASCIIZ string at DS:SI to the screen (uses PUTC).
  465. ;
  466. print    proc            
  467.  
  468.     push    si
  469. printlp:
  470.     lodsb
  471.     cmp    al,0
  472.     je    pdone
  473.     call    putc
  474.     jmp    printlp
  475. pdone:
  476.     pop    si
  477.     ret
  478.  
  479. print    endp
  480. ;
  481. ;--------------
  482. ;
  483. ; STAT
  484. ;    Monitors for Delta CD and Delta MNP and prints
  485. ;    "On-Line", "OffLine", "CONNECT/MNPx" and "MNP Disconnect"
  486. ;    when applicable.
  487. ;
  488. stat    proc
  489.  
  490.     mov    ah,3            ;get carrier status
  491.     mov    dx,port
  492.     int    14h
  493.     and    al,80h
  494.  
  495.     cmp    carrier,al
  496.     je    nodeltacd
  497.     mov    carrier,al
  498.  
  499.     lea    si,online_str
  500.     cmp    al,0
  501.     jne    stat_print
  502.     lea    si,offline_str
  503. stat_print:
  504.     call    print
  505. nodeltacd:
  506. ;---
  507.     push    es
  508.     mov    ah,0e0h            ;get carrier status
  509.     mov    al,0
  510.     mov    dx,port
  511.     int    14h
  512.     mov    al,es:[bx]
  513.     mov    ah,es:[bx][1]
  514.     pop    es
  515.  
  516.     cmp    mnpflag,al
  517.     je    nodeltamnp
  518.     mov    mnpflag,al
  519.  
  520.     lea    si,nomnp_str
  521.     cmp    al,0
  522.     je    stat_print1
  523.     lea    si,yesmnp_str
  524.     add    ah,'0'
  525.     mov    disp_lvl,ah
  526. stat_print1:
  527.     call    print
  528. nodeltamnp:
  529.  
  530.     ret
  531.  
  532. stat    endp
  533. ;
  534. ;--------------
  535. ;
  536. checkkey    proc
  537.  
  538.     mov    ah,1            ;check for a key
  539.     int    16h
  540.     ret
  541.  
  542. checkkey    endp
  543. ;
  544. ;--------------
  545. ;
  546. getkey    proc
  547.  
  548.     mov    ah,0            ;get the key
  549.     int    16h
  550.     ret
  551.  
  552. getkey    endp
  553. ;
  554. ;--------------
  555. ;
  556. set_rate    proc
  557.  
  558.     xor    ah,ah            ;put baud rate in bits 7-5
  559.     mov    al,baud
  560.     mov    cl,5
  561.     shl    al,cl
  562.     or    ah,al
  563.  
  564.     mov    al,parity        ;put parity in bits 4-3
  565.     cmp    al,0
  566.     jz    nosp
  567.     or    al,1
  568. nosp:
  569.     mov    cl,3
  570.     shl    al,cl
  571.     or    ah,al
  572.  
  573.     mov    al,2            ;put wordlength in bits 1-0
  574.     cmp    parity,0
  575.     jne    nonone
  576.     or    al,1
  577. nonone:
  578.     or    ah,al
  579.  
  580.     mov    al,ah            ;go...
  581.     mov    ah,0
  582.     mov    dx,port
  583.     int    14h
  584.     ret
  585.  
  586. set_rate    endp
  587. ;
  588. ; -----------------------------
  589. ;
  590. toggles    proc
  591.  
  592.     call    crlf
  593.     push    si
  594.     lea    si,instruct_str
  595.     call    print
  596.     pop    si
  597.     jmp    toggle_print
  598.  
  599. toggle_loop:
  600.     call    getkey            ;wait for a key
  601.     cmp    al,' '
  602.     je    toggle_space
  603.     cmp    al,13
  604.     je    toggle_cr
  605.     jmp    toggle_loop
  606.  
  607. toggle_space:
  608.     inc    byte ptr [di][-1]
  609.     cmp    byte ptr [di][-1],cl
  610.     jb    toggle_print
  611.     mov    byte ptr [di][-1],0
  612. toggle_print:
  613.     mov    al,13
  614.     call    putc
  615.     call    print
  616.     mov    al,' '
  617.     call    putc
  618.     mov    al,'='
  619.     call    putc
  620.     mov    al,' '
  621.     call    putc
  622.     push    si
  623.     mov    al,byte ptr [di][-1]
  624.     xor    ah,ah
  625.     shl    ax,1
  626.     mov    si,ax
  627.     add    si,di
  628.     mov    si,[si]
  629.     call    print            ;'xxxx'
  630.     pop    si
  631.     jmp    toggle_loop
  632.  
  633. toggle_cr:
  634.     call    crlf
  635.     mov    al,10
  636.     call    putc
  637.     ret
  638.  
  639. toggles    endp
  640. ;
  641. ; -----------------------------
  642. ;
  643. crlf    proc
  644.  
  645.     mov    al,13
  646.     call    putc
  647.     mov    al,10
  648.     call    putc
  649.     ret
  650.  
  651. crlf    endp
  652. ;
  653. ; -----------------------------
  654. ;
  655. ;  Call with    DX:AX    = Unsigned 32 bit value
  656. ;        DS:SI    = 10 byte buffer
  657. ;              (make sure it is ASCIIZ if you are going to print
  658. ;               it alone.)
  659. ;
  660. ;  Destroys AX, BX, CX, DX, and SI.
  661. ;
  662.     public    xlmputd
  663. xlmputd        proc    near
  664.  
  665.     mov    cx,10
  666. splp:
  667.     mov    byte ptr [si],' '
  668.     inc    si
  669.     loop    splp
  670.  
  671.     mov    cx,10            ;radix
  672.                     ;divide the 32 bit value by the radix
  673.                     ;to extract the next digit for the
  674. bin1:                    ;forming string.
  675.     call    divide            ;no, divide by radix
  676.     add    bl,'0'            ;convert the rem to an ascii digit
  677. bin2:
  678.     dec    si            ;backup through string,
  679.     mov    [si],bl            ;store this character into string.
  680.     mov    bx,ax            ;is the value zero yet?
  681.     or    bx,dx
  682.     jnz    bin1            ;no, do it again
  683.     ret
  684.  
  685. xlmputd        endp
  686. ;
  687. ; =================
  688. ;
  689. ;  32 bit by 16 bit unsigned divide
  690. ;
  691. ;  Call with    DX:AX    = 32 bit dividend
  692. ;        CX    = divisor
  693. ;
  694. ;  Returns    DX:AX    = quotient
  695. ;        BX    = remainder
  696. ;        CX    = divisor (unchanged)
  697. ;
  698.     public    divide
  699. divide        proc    near        ;divide dx:ax by cx
  700.  
  701.         jcxz    divl        ;exit if divide by zero
  702.         push    ax        ;0:dividend_upper/divisor
  703.         mov    ax,dx
  704.         xor    dx,dx
  705.         div    cx
  706.         mov    bx,ax        ;bx - quotientl
  707.         pop    ax        ;remainterl:dividend_lower/divisor
  708.         div    cx
  709.         xchg    bx,dx        ;dx:ax = quotientl:quotient2
  710. divl:
  711.         ret            ;bx = remainder2
  712.  
  713. divide        endp
  714. ;
  715. ;--------------
  716. ;
  717.     end    start
  718.