home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / RS232DVR.ZIP / RS232.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-08-13  |  12.1 KB  |  622 lines

  1.     page    60,132
  2. ;***********************************************************
  3. ;**    Configuration Program for Communications           **
  4. ;**    Copyright (C) Texas Instruments, Inc. 1986         **
  5. ;**                                                       **
  6. ;**    Author: Greg Haley                                 **
  7. ;**    Project Start: 09/15/86                            **
  8. ;**    Last Revision: 11/18/86                            **
  9. ;**                               **
  10. ;**    Modifications: Joe McDaniel, Fein-Marquart      **
  11. ;**    August, 1987                      **
  12. ;***********************************************************
  13.  
  14.     name    RS232
  15.     title    Config Program for Serial Communications
  16. cr    equ    0dH
  17. lf    equ    0aH
  18.  
  19. code    segment
  20.     assume    cs:code, ds:code, es:code, ss:code
  21.     org    80h
  22. char_count label byte
  23.     org    81h
  24. command_line label byte
  25.     org    100h
  26. RS232     proc    near
  27.     jmp     start
  28.  
  29. ; variables 
  30. device    db    'AUX',6 dup (0)        ; Device name
  31. handle    dw    0            ; Handle for AUX
  32. DCW    dw    ?            ; Device configuration word
  33. DCB    db    ?            ; Device Configuration Byte
  34. c_line    db    256 dup (?)        ; Copy of command line
  35. count    dw    0            ; Num. of chars in command line
  36.     dw    40 dup (?)        ; New stack
  37. top_stack label word
  38.  
  39. msg:
  40.     db    cr,lf,'RS232 Configuration Copyright (C) '
  41.     db    'Texas Instruments 1986'
  42.     db    cr,lf,'Author: Greg Haley',cr,lf
  43.     db    'Revised: Joe McDaniel, Fein-Marquart Associates - 1987',cr,lf
  44.     db    cr,lf,'Current serial configuration:'
  45.        db    cr,lf,'Port='
  46. port_n    db    ' , Speed='
  47. speed    db    '    , Parity='
  48. parity    db    '    , Data bits='
  49. data    db    ' , Stop bits='
  50. stop    db    ' , Busy='
  51. busy    db    '        ',cr,lf
  52.     db    'RI='
  53. ringind    db    ' , SP='
  54. spind    db    ' , DSR='
  55. dsrind    db    ' , CTS='
  56. ctsind    db    ' , DCD='
  57. dcdind    db    ' ','$'
  58.  
  59. busy_tbl dw    no_busy    
  60.     dw    scf_busy
  61.     dw    dsr_busy
  62.     dw    xon_busy
  63.  
  64. no_busy    db    'NONE    '
  65. scf_busy db    'SCF     '
  66. dsr_busy db    'DSR     '
  67. xon_busy db    'XON-XOFF'
  68.  
  69. p_tbl    dw    par_none
  70.     dw    par_odd
  71.     dw    par_none
  72.     dw    par_even
  73.  
  74. par_none db    'NONE'
  75. par_odd    db    ' ODD'
  76. par_even db    'EVEN'
  77.  
  78. s_tbl    dw    s_110
  79.     dw    s_150
  80.     dw    s_300
  81.     dw    s_600
  82.     dw    s_1200
  83.     dw    s_2400
  84.     dw    s_4800
  85.     dw    s_9600
  86.     dw    s_19200
  87.  
  88. s_110    db    '  110'
  89. s_150    db    '  150'
  90. s_300    db    '  300'
  91. s_600    db    '  600'
  92. s_1200    db    ' 1200'
  93. s_2400    db    ' 2400'
  94. s_4800    db    ' 4800'
  95. s_9600    db    ' 9600'
  96. s_19200    db    '19200'
  97.  
  98. ; Program starts here
  99. start:    
  100. ; set up new stack
  101.     mov    sp,offset top_stack
  102.     mov    ax,cs
  103.     mov    ds,ax
  104.     mov     es,ax
  105.  
  106. ; open handle
  107.     mov    dx,offset device
  108.     mov    ax,3d02h
  109.     int    21h
  110.     jnc    open_1
  111.     jmp    error
  112. open_1:
  113.     mov    handle,ax
  114.     mov    bx,ax
  115.  
  116. ; get command line length
  117.     mov    al,char_count
  118.     or    al,al
  119.     jnz    command_1
  120.     jmp    display_dcw
  121. command_1:
  122.     cbw
  123.     mov    count,ax
  124.  
  125. ; get command line
  126.     mov    cx,ax
  127.     mov    si,offset command_line
  128.     mov    di,offset c_line
  129. copy_string:
  130.     lodsb
  131.     cmp    al,'a'            ; Is it lower case?
  132.     jb    upper_case        ;  No, skip
  133.     and    al,11011111b        ;  Yes, convert to upper case
  134. upper_case:
  135.     stosb                ; Store upper case value
  136.     loop    copy_string        ; Loop 'til done
  137.     
  138. ; get DCW
  139.     call    get_dcw
  140.     jnc    get_dcw_1
  141.     jmp    error
  142. get_dcw_1:
  143.  
  144. ; get DCB
  145.     call    get_dcb
  146.     jnc    get_dcb_1
  147.     jmp    error
  148. get_dcb_1:
  149.  
  150. ; mask out the control line bits in the dcb
  151.     and    dcb,11100000b
  152.  
  153. ; look for word "port" ("po")
  154.     mov    di,offset c_line
  155.     mov    cx,count
  156.  
  157. port_again:
  158.     mov    al,'P'
  159.     repnz    scasb            ; find string
  160.     jcxz    port_done
  161.     mov    si,di
  162.     lodsb                ; next char "O" ?
  163.     cmp    al,'O'
  164.     jne    port_again         ; No, look for others
  165.  
  166.     mov    al,'='            ; Now look for "=" char
  167.     repnz    scasb
  168.     jcxz    port_done
  169.  
  170.     mov    dl,'1'            ; find port number
  171.     mov    dh,'4'
  172.     mov    si,di
  173. get_port:
  174.     lodsb
  175.     cmp    al,dl            ; port 1 <= port <= 4 ?
  176.     jb     loop_port
  177.     cmp    al,dh
  178.     jg    loop_port
  179.     dec    al                  ; convert port to binary
  180.     and    al,00000011b
  181.     jmp    port_dcw        ; go change it
  182. loop_port:
  183.     loop    get_port
  184.  
  185.  
  186. ; modify DCW
  187. port_dcw:
  188.     and    dcw,1110011111111111b    ; reset port bits
  189.     mov    cl,11
  190.     xor    ah,ah
  191.     shl    ax,cl
  192.     or    dcw,ax
  193. port_done:    
  194.  
  195. ; look for word "data" ("da")
  196.     mov    di,offset c_line
  197.     mov    cx,count
  198.     mov    al,'D'
  199.     repnz    scasb            ; find string
  200.     jcxz    data_done
  201.     mov    si,di
  202.     lodsb                ; next char "A" ?
  203.     cmp    al,'A'
  204.     je    found_data        ; Yes, continue
  205.     jmp    data_done        ; No, exit
  206. found_data:
  207.     mov    al,'='            ; Now look for "=" char
  208.     repnz    scasb
  209.     jcxz    data_done
  210.  
  211.     mov    si,di
  212.     lodsb
  213.     cmp    al,'7'            ; 7 data bits?
  214.     jne    check_for_8
  215.     and    dcw,1011111111111111b    ; Store in proper bit
  216.     jmp    data_done        ; we're done
  217. check_for_8:
  218.     cmp    al,'8'                  ; 8 data bits
  219.     jne    data_done        ; 
  220.     or     dcw,0100000000000000b    ; Store in proper bit
  221. data_done:    
  222.  
  223. ; look for word "busy" ("bu")
  224.     mov    di,offset c_line
  225.     mov    cx,count
  226.     mov    al,'B'
  227.     repnz    scasb            ; find string
  228.     jcxz    busy_done
  229.     mov    si,di
  230.     lodsb                ; next char "U" ?
  231.     cmp    al,'U'
  232.     je    found_busy        ; Yes, continue
  233.     jmp    busy_done        ; No, exit
  234. found_busy:
  235.     mov    al,'='            ; Now look for "=" char
  236.     repnz    scasb
  237.     jcxz    busy_done
  238.  
  239.     mov    si,di
  240.     lodsb
  241.     cmp    al,'N'            ; No busy handling?
  242.     jne    busy_scf
  243.     and    dcw,1111110011111111b    ; Store in proper bits
  244.     jmp    busy_done        ; we're done
  245. busy_scf:
  246.     cmp    al,'S'            ; SCF busy handling?
  247.     jne    busy_dsr
  248.     and    dcw,1111110011111111b    ; Store in proper bits
  249.     or     dcw,0000000100000000b    ; Store in proper bits
  250.     jmp    busy_done        ; we're done
  251. busy_dsr:
  252.     cmp    al,'D'            ; No busy handling?
  253.     jne    busy_xon
  254.     and    dcw,1111110011111111b    ; Store in proper bits
  255.     or     dcw,0000001000000000b    ; Store in proper bits
  256.     jmp    busy_done        ; we're done
  257. busy_xon:
  258.     cmp    al,'X'            ; No busy handling?
  259.     jne    busy_done
  260.     or     dcw,0000001100000000b    ; Store in proper bits
  261. busy_done:    
  262.  
  263. ; look for word "speed" ("sp")
  264.     mov    di,offset c_line
  265.     mov    cx,count
  266. find_speed:
  267.     mov    al,'S'
  268.     repnz    scasb            ; find string
  269.     or    cx,cx            ; too far a jump for     jcxnz    speed_A
  270.     jnz    speed_A
  271.     jmp    speed_done
  272.  
  273. speed_A:
  274.     mov    si,di
  275.     lodsb                ; next char "P" ?
  276.     cmp    al,'P'
  277.     jne    find_speed        ; No, look again
  278.     mov    al,'='            ; Now look for "=" char
  279.     repnz    scasb
  280.     or    cx,cx            ; too far a jump for jcxnz    speed_2
  281.     jnz    speed_B
  282.     jmp    speed_done
  283.  
  284. speed_B:
  285.     mov    si,di
  286.     lodsb
  287.     cmp    al,'1'            ; 1 speed bit?
  288.     jne    speed_2
  289.     lodsb
  290.     cmp    al,'1'            ; 110 baud?
  291.     jne    speed_150
  292.     and    dcw,1111111100001111b    ; Store in proper bits
  293.     jmp    speed_done        ; we're done
  294. speed_150:
  295.     cmp    al,'5'            ; 150 baud?
  296.     jne    speed_1200
  297.     and    dcw,1111111100001111b    ; Store in proper bits
  298.     or     dcw,0000000000010000b    ; Store in proper bits
  299.     jmp    speed_done        ; we're done
  300. speed_1200:
  301.     cmp    al,'2'                  ; 1200 baud?
  302.     jne    speed_19200
  303.     and    dcw,1111111100001111b    ; Store in proper bits
  304.     or     dcw,0000000001000000b    ; Store in proper bits
  305.     jmp    speed_done        ; we're done
  306. speed_19200:
  307.     cmp    al,'9'                  ; 19200 baud?
  308.     jne    speed_done
  309.     and    dcw,1111111100001111b    ; Store in proper bits
  310.     or     dcw,0000000010000000b    ; Store in proper bits
  311.     jmp    speed_done        ; we're done
  312. speed_2:
  313.     cmp    al,'2'                  ; 2400 baud?
  314.     jne    speed_3
  315.     and    dcw,1111111100001111b    ; Store in proper bits
  316.     or     dcw,0000000001010000b    ; Store in proper bits
  317.     jmp    speed_done        ; we're done
  318. speed_3:
  319.     cmp    al,'3'                  ; 300 baud?
  320.     jne    speed_4
  321.     and    dcw,1111111100001111b    ; Store in proper bits
  322.     or     dcw,0000000000100000b    ; Store in proper bits
  323.     jmp    speed_done        ; we're done
  324. speed_4:
  325.     cmp    al,'4'                  ; 4800 baud?
  326.     jne    speed_6
  327.     and    dcw,1111111100001111b    ; Store in proper bits
  328.     or     dcw,0000000001100000b    ; Store in proper bits
  329.     jmp    speed_done        ; we're done
  330. speed_6:
  331.     cmp    al,'6'                  ; 600 baud?
  332.     jne    speed_9
  333.     and    dcw,1111111100001111b    ; Store in proper bits
  334.     or     dcw,0000000000110000b    ; Store in proper bits
  335.     jmp    speed_done        ; we're done
  336. speed_9:
  337.     cmp    al,'9'                  ; 9600 baud?
  338.     jne    speed_done
  339.     and    dcw,1111111100001111b    ; Store in proper bits
  340.     or     dcw,0000000001110000b    ; Store in proper bits
  341. speed_done:    
  342.  
  343. ; look for word "stop" ("st")
  344.     mov    di,offset c_line
  345.     mov    cx,count
  346. find_stop:
  347.     mov    al,'S'
  348.     repnz    scasb            ; find string
  349.     jcxz    stop_done
  350.     mov    si,di
  351.     lodsb                ; next char "T" ?
  352.     cmp    al,'T'
  353.     jne    find_stop        ; No, try next
  354.     mov    al,'='            ; Now look for "=" char
  355.     repnz    scasb
  356.     jcxz    stop_done
  357.  
  358.     mov    si,di
  359.     lodsb
  360.     cmp    al,'1'            ; 1 stop bit?
  361.     jne    stop_2
  362.     and    dcw,1111111111110111b    ; Store in proper bit
  363.     jmp    stop_done        ; we're done
  364. stop_2:
  365.     cmp    al,'2'                  ; 2 stop bits
  366.     jne    stop_done        ; 
  367.     or     dcw,0000000000001000b    ; Store in proper bit
  368. stop_done:    
  369.  
  370. ; look for word "parity" ("pa")
  371.     mov    di,offset c_line
  372.     mov    cx,count
  373. find_parity:
  374.     mov    al,'P'
  375.     repnz    scasb            ; find string
  376.     jcxz    parity_done
  377.     mov    si,di
  378.     lodsb                ; next char "A" ?
  379.     cmp    al,'A'
  380.     jne    find_parity        ; No, look again
  381.     mov    al,'='            ; Now look for "=" char
  382.     repnz    scasb
  383.     jcxz    parity_done
  384.  
  385.     mov    si,di
  386.     lodsb
  387.     cmp    al,'N'            ; No parity?
  388.     jne    parity_odd
  389.     and    dcw,1111111111111100b    ; Store in proper bits
  390.     jmp    parity_done        ; we're done
  391. parity_odd:
  392.     cmp    al,'O'            ; ODD parity?
  393.     jne    parity_even
  394.     and    dcw,1111111111111100b    ; Store in proper bits
  395.     or     dcw,0000000000000001b    ; Store in proper bits
  396.     jmp    parity_done        ; we're done
  397. parity_even:
  398.     cmp    al,'E'            ; EVEN parity?
  399.     jne    parity_done
  400.     or     dcw,0000000000000011b    ; Store in proper bits
  401. parity_done:    
  402.  
  403. ; search for the DCB settings, too
  404. ; look for word "FLush"
  405.     mov    di,offset c_line
  406.     mov    cx,count
  407.     mov    al,'F'
  408.     repnz    scasb            ; find string
  409.     jcxz    fl_done
  410.     mov    si,di
  411.     lodsb                ; next char "L" ?
  412.     cmp    al,'L'
  413.     jne    fl_done         ; No, look for others
  414.     mov    al,'='            ; Now look for "=" char
  415.     repnz    scasb
  416.     jcxz    fl_done
  417.  
  418.     mov    si,di
  419.     lodsb
  420.     and    dcb,11111101b        ; assume 0 (off)
  421.     cmp    al,'1'            ; 1 ?
  422.     jne     fl_done
  423.     or    dcb,00000010b        ; set it on
  424. fl_done:    
  425.  
  426. ; look for word "DTr"
  427.     mov    di,offset c_line
  428.     mov    cx,count
  429.     mov    al,'D'
  430.     repnz    scasb            ; find string
  431.     jcxz    dtr_done
  432.     mov    si,di
  433.     lodsb                ; next char "T" ?
  434.     cmp    al,'T'
  435.     jne    dtr_done         ; No, look for others
  436.     mov    al,'='            ; Now look for "=" char
  437.     repnz    scasb
  438.     jcxz    dtr_done
  439.  
  440.     mov    si,di
  441.     lodsb
  442.     or    dcb,00000001b        ; assume 1 (on)
  443.     cmp    al,'0'            ; 0 ?
  444.     jne     dtr_done
  445.     and    dcb,11111110b        ; set it off
  446. dtr_done:    
  447.  
  448.  
  449. ; Turn on Serial bit in DCW
  450.     or     dcw,1000000000000000b
  451.  
  452. ; Set new DCB
  453.      mov    dx,offset DCB
  454.      mov    bx,handle
  455.      mov    cx,1
  456.      mov    ax,4403h
  457.      int    21h
  458.  
  459. ; Set new DCW
  460.     mov    dx,offset DCW
  461.     mov    bx,handle
  462.     mov    cx,2
  463.     mov    ax,4403h
  464.     int    21h
  465.  
  466. ; display current DCW and DCB
  467. display_dcw:
  468.     call    get_dcw
  469.     call    get_dcb
  470.     call    print_dcw
  471.  
  472. ; terminate program
  473. exit: 
  474.     mov    al,0
  475.     jmp     short terminate
  476. error:
  477.     mov    al,1
  478. terminate:
  479.     mov    ah,4ch
  480.     int    21h
  481.  
  482. ; Get Device Config Word
  483. get_dcw    proc    near
  484.     mov    dx,offset DCW
  485.     mov    bx,handle
  486.     mov    cx,2
  487.     mov    ax,4402h
  488.     int    21h
  489.     ret
  490. get_dcw    endp
  491.  
  492. ; Get Device Config Byte
  493. get_dcb    proc    near
  494.     mov    dx,offset DCB
  495.     mov    bx,handle
  496.     mov    cx,1
  497.     mov    ax,4402h
  498.     int    21h
  499.     ret
  500. get_dcb    endp
  501.  
  502. print_dcw proc     near
  503. ; insert port number
  504.     mov    dx,dcw
  505.     mov    cl,11
  506.     shr    dx,cl
  507.     and    dl,00000011b
  508.     or    dl,00110000b
  509.     inc    dl
  510.     mov    port_n,dl
  511.  
  512. ; insert speed
  513.     mov    dx,dcw
  514.     and    dx,0000000011110000b
  515.     mov    cl,3
  516.     shr    dl,cl
  517.     mov    bx,offset s_tbl
  518.     add    bx,dx
  519.     mov    si,[bx]
  520.     mov    di,offset speed
  521.     mov    cx,5
  522.     repz    movsb
  523.  
  524. ; insert parity
  525.     mov    dx,dcw
  526.     and    dx,0000000000000011b
  527.     shl    dx,1
  528.     mov    bx,offset p_tbl
  529.     add    bx,dx
  530.     mov    si,[bx]
  531.     mov    di,offset parity
  532.     mov    cx,4
  533.     repz    movsb
  534.  
  535. ; insert data bits
  536.     mov    dx,dcw
  537.     mov    al,'7'
  538.     and    dx,0100000000000000b
  539.     jz    data_7
  540.     inc    al
  541. data_7:
  542.     mov    data,al
  543.  
  544. ; insert stop bits
  545.     mov    dx,dcw
  546.     mov    al,'1'
  547.     and    dx,0000000000001000b
  548.     jz    stopis2
  549.     inc    al
  550. stopis2:
  551.     mov    stop,al
  552.  
  553. ; insert busy
  554.     mov    dx,dcw
  555.     and    dx,0000001100000000b
  556.     xchg    dl,dh
  557.     shl    dx,1
  558.     mov    bx,offset busy_tbl
  559.     add    bx,dx
  560.     mov    si,[bx]
  561.     mov    di,offset busy
  562.     mov    cx,8
  563.     repz    movsb
  564.  
  565. ; print dcb, too
  566. ; insert ring indicator status
  567.     mov    dl,dcb
  568.     mov    al,'0'
  569.     and    dx,00010000b
  570.     jz    ri2
  571.     inc    al
  572. ri2:
  573.     mov    ringind,al
  574.  
  575. ; insert modem speed indicator status
  576.     mov    dl,dcb
  577.     mov    al,'0'
  578.     and    dx,00001000b
  579.     jz    sp2
  580.     inc    al
  581. sp2:
  582.     mov    spind,al
  583.  
  584. ; insert dsr indicator status
  585.     mov    dl,dcb
  586.     mov    al,'0'
  587.     and    dx,00000100b
  588.     jz    dsri2
  589.     inc    al
  590. dsri2:
  591.     mov    dsrind,al
  592.  
  593. ; insert cts indicator status
  594.     mov    dl,dcb
  595.     mov    al,'0'
  596.     and    dx,00000010b
  597.     jz    cts2
  598.     inc    al
  599. cts2:
  600.     mov    ctsind,al
  601.  
  602. ; insert dcd indicator status
  603.     mov    dl,dcb
  604.     mov    al,'0'
  605.     and    dx,00000001b
  606.     jz    dcd2
  607.     inc    al
  608. dcd2:
  609.     mov    dcdind,al
  610.  
  611. ; print message
  612.     mov    dx,offset msg
  613.     mov    ah,9
  614.     int    21h
  615.  
  616.     ret
  617. print_dcw endp
  618.  
  619. RS232     endp
  620. code    ends
  621.     end    RS232 
  622.