home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / cpmug / cpmug081.ark / BAUDSET.ASM < prev    next >
Encoding:
Assembly Source File  |  1984-04-29  |  6.1 KB  |  343 lines

  1. ;
  2. ; baudset - an extremely system dependant utility to adjust
  3. ;        the baud rate of the various serial device ports.
  4. ;
  5. printf    equ    9    ;cp/m's print string function
  6. tab    equ    9    ;tab character (no relation to the above)
  7. ;
  8. bdos    equ    5    ;to talk to cp/m
  9. cibuf    equ    81h    ;start of console input buffer
  10. tpa    equ    100h    ;program load address
  11. ;
  12.     org    tpa
  13. ;
  14. baudset:
  15.     xra    a
  16.     sta    doflag
  17.     sta    aflag
  18.     sta    bflag
  19.     lxi    d,cibuf
  20. nxtdev:    call    skipbl
  21.     lxi    h,devtab
  22.     call    search
  23.     jc    error
  24.     pchl
  25. ;
  26. tuart:    call    skipbl
  27.     ldax    d    ;get next non-blank
  28.     cpi    'A'    ;which Tuart?
  29.     jnz    isitB
  30.     sta    Aflag    ; 'A'
  31.     lxi    h,Adata
  32.     shld    lasttu
  33.     jmp    getrat
  34. isitB:    cpi    'B'
  35.     jnz    error
  36.     sta    Bflag    ; 'B'
  37.     lxi    h,Bdata
  38.     shld    lasttu
  39. getrat:    inx    d
  40.     call    skipbl    ;get the next non-blank
  41.     cpi    '='
  42.     jnz    error    ;it must be an equal sign
  43.     inx    d
  44.     call    skipbl    ;get the baud rate
  45.     lxi    h,tuatab
  46.     call    search
  47.     jc    error
  48.     push    d
  49.     xchg
  50.     lhld    lasttu    ;let's see now, where does this go?
  51.     mov    m,e
  52.     inx    h
  53.     mov    m,d    ;save the control bytes for later use
  54.     pop    d
  55.     call    skipbl    ;get command terminator character
  56.     ldax    d
  57.     inx    d
  58.     ana    a    ;the line ends with a zero
  59.     jz    gotops    ;if eol, done.
  60.     cpi    ';'
  61.     jz    nxtdev    ;a semicolon starts a device spec
  62.     jmp    error    ;anything else is incorrect
  63. ;
  64. douadr:    mvi    a,4eh    ;defaults:
  65.             ;  8 data bits, 1 stop bit, no parity, 16*rate.
  66.     sta    douops
  67.     sta    doflag
  68. ;
  69. oploop:    call    skipbl
  70.     lxi    h,opstab
  71.     call    search    ;search option table. get addrs of argument table
  72.     jc    error
  73.     call    skipbl
  74.     ldax    d
  75.     cpi    '='    ;skip blanks, then look for an equal sign
  76.     jnz    error
  77.     inx    d    ;skip the equal sign. find the argument.
  78.     call    skipbl
  79.     call    search    ;search the argument table for this value
  80.     jc    error
  81.     lda    douops
  82.     ana    h
  83.     ora    l
  84.     sta    douops    ;adjust the doubler's configuration byte
  85.     call    skipbl
  86.     ldax    d
  87.     inx    d    ;point to the next char.
  88.     ora    a
  89.     jz    gotops    ;a zero marks the end of the line
  90.     cpi    ','
  91.     jz    oploop    ;a comma marks the start of another spec
  92.     cpi    ';'
  93.     jz    nxtdev    ;a semicolon marks the start of a device spec
  94.     jmp    error    ;anything else is a mistake
  95. ;
  96. ; skipbl - skip over leading blanks
  97. ;
  98. skipbl:    ldax    d
  99.     cpi    ' '    ;space?
  100.     jz    skip    ; yes: skip it
  101.     cpi    tab    ;tab?
  102.     rnz        ; if not a space and not a tab, return
  103. skip:    inx    d
  104.     jmp    skipbl    ; yes: check next char
  105. ;
  106. ; search - searches a table.
  107. ;
  108. ;    enter with the table address in hl,
  109. ;    and the address of that which is to be matched in de.
  110. ;
  111. ;    returns carry on failure to match;
  112. ;    returns no carry & routine address in hl on match.
  113. ;
  114. nomat:    pop    d
  115.     dad    b
  116.     inx    h
  117.     inx    h    ;point to next item in table
  118. ;
  119. search:    mov    c,m
  120.     inx    h
  121.     mov    b,m
  122.     inx    h    ;get length of item in bc
  123. ;
  124.     mov    a,c
  125.     ora    b
  126.     jz    nofind    ;reached end of table with no match?
  127.     push    d    ;no: save start of name pointer
  128. ;
  129. nxtch:    call    skipbl    ;ignore spaces
  130.     cmp    m    ;match?
  131.     jnz    nomat
  132.     inx    h
  133.     inx    d
  134.     dcx    b    ;yes, a match...bump pointers, decr counter
  135.     mov    a,c
  136.     ora    b    ;reached end of item yet?
  137.     jnz    nxtch
  138. ;
  139. match:    pop    b    ;get start of item address off stack
  140.     mov    a,m
  141.     inx    h
  142.     mov    h,m
  143.     mov    l,a    ;get service routine address
  144.     xra    a    ;indicate succesful match
  145.     ret
  146. ;
  147. nofind:    stc
  148.     sbb    a    ;indicate failure to match
  149.     ret
  150. ;
  151. ; gotops - sets the devices to their new baud rates.
  152. ;
  153. gotops:    lda    doflag
  154.     ana    a
  155.     jz    goa    ;no: try tuart a
  156.     lxi    h,0fe0ah    ;the Doubler's command address.
  157.     mvi    m,0
  158.     nop!    nop
  159.     mvi    m,0
  160.     nop!    nop
  161.     mvi    m,0
  162.     nop!    nop
  163.     mvi    m,50h    ;internal reset + error reset
  164.     nop!    nop
  165.     lda    douops
  166.     mov    m,a
  167.     nop!    nop
  168.     mvi    m,2eh    ;RTS + DTR + Rx + Tx
  169. goa:    lda    aflag
  170.     ana    a    ;is tuart 'A' to be altered?
  171.     jz    gob    ;  no:  try tuart 'B'
  172.     lda    adata    ;  yes: change it.
  173.     out    0
  174.     lda    adata+1
  175.     out    2
  176. gob:    lda    bflag
  177.     ana    a    ;is tuart 'B' to be altered?
  178.     rz        ;  if not, we're done, so back to cp/m
  179.     lda    bdata
  180.     out    50h
  181.     lda    bdata+1
  182.     out    52h
  183.     ret
  184. ;
  185. ; error - sends an error message to the console
  186. ;
  187. errmsg:    db    '--error--$'
  188. error:    mvi    a,'?'
  189.     stax    d
  190.     lxi    h,80h    ;char count
  191.     mvi    a,81h    ;start of string
  192.     add    m
  193.     mov    l,a
  194.     mvi    m,'$'
  195.     lxi    d,errmsg
  196.     mvi    c,printf
  197.     call    bdos
  198.     lxi    d,81h
  199.     mvi    c,printf
  200.     jmp    bdos    ;returns to cp/m after printing message
  201. ;
  202. ; devtab - table of device name lengths,
  203. ;            device names,
  204. ;            and service routine addresses.
  205. ;
  206. devtab:
  207.     dw    tualen
  208. tuasta    equ    $
  209.     db    'TUART'
  210. tualen    equ    $-tuasta
  211.     dw    tuart
  212. ;
  213.     dw    doulen
  214. dousta    equ    $
  215.     db    'DOUBLER'
  216. doulen    equ    $-dousta
  217.     dw    douadr
  218. ;
  219.     dw    0    ;end of table marker
  220. ;
  221. ; tuatab - a table listing the baud rates avalible for the
  222. ;       5501's on the Cromemco Tuart board.
  223. ;
  224. tuatab:
  225.     dw    5
  226.     db    '19200'
  227.     dw    1090h
  228.     dw    5
  229.     db    '19.2K'
  230.     dw    1090h
  231.     dw    4
  232.     db    '9600'
  233.     dw    00c0h
  234.     dw    4
  235.     db    '4800'
  236.     dw    00a0h
  237.     dw    4
  238.     db    '2400'
  239.     dw    0090h
  240.     dw    4
  241.     db    '1200'
  242.     dw    0088h
  243.     dw    3
  244.     db    '300'
  245.     dw    0084h
  246.     dw    3
  247.     db    '150'
  248.     dw    0082h
  249.     dw    3
  250.     db    '110'
  251.     dw    0001h, 0
  252. ;
  253. ; opstab - a table listing the options which may be specified
  254. ;       to correctly set up the 8251 on the doubler.
  255. ;
  256. opstab:
  257.     dw    rateln-$-2
  258.     db    'RATEFACTOR'
  259. rateln    equ    $
  260.     dw    ratetb
  261.     dw    bitsln-$-2
  262.     db    'DATABITS'
  263. bitsln    equ    $
  264.     dw    bitstb
  265.     dw    stopln-$-2
  266.     db    'STOPBITS'
  267. stopln    equ    $
  268.     dw    stoptb
  269.     dw    pariln-$-2
  270.     db    'PARITY'
  271. pariln    equ    $
  272.     dw    paritb, 0
  273. ;
  274. ; ratetb - a table listing the multiplication factors avalible
  275. ;       for the 8251 on the Micromation Doubler board.
  276. ;
  277. ratetb:
  278.     dw    2
  279.     db    '64'
  280.     dw    0fc03h
  281.     dw    2
  282.     db    '16'
  283.     dw    0fc02h
  284.     dw    1
  285.     db    '1'
  286.     dw    0fc01h, 0
  287. ;
  288. ; bitstb - a table listing the number of data bits avalible
  289. ;       for the 8251 on the Micromation Doubler board.
  290. ;
  291. bitstb:
  292.     dw    1
  293.     db    '5'
  294.     dw    0f300h
  295.     dw    1
  296.     db    '6'
  297.     dw    0f304h
  298.     dw    1
  299.     db    '7'
  300.     dw    0f308h
  301.     dw    1
  302.     db    '8'
  303.     dw    0f30ch, 0
  304. ;
  305. ; paritb - a table listing the parity options avalible
  306. ;       for the 8251 on the Micromation Doubler board.
  307. ;
  308. paritb:
  309.     dw    4
  310.     db    'NONE'
  311.     dw    0cf00h
  312.     dw    3
  313.     db    'ODD'
  314.     dw    0cf10h
  315.     dw    4
  316.     db    'EVEN'
  317.     dw    0cf30h, 0
  318. ;
  319. ; stoptb - a tale listing the stop bit options avalible
  320. ;       for the 8251 on the Micromation Doubler board.
  321. ;
  322. stoptb:
  323.     dw    1
  324.     db    '2'
  325.     dw    03fc0h
  326.     dw    3
  327.     db    '1.5'
  328.     dw    03f80h
  329.     dw    1
  330.     db    '1'
  331.     dw    03f40h, 0
  332. ;
  333. doflag:    ds    1
  334. aflag:    ds    1
  335. bflag:    ds    1
  336. ;
  337. lasttu:    ds    2    ;points to adata or bdata
  338. adata:    ds    2    ;data for tuart 'A'
  339. bdata:    ds    2    ;data for tuart 'B'
  340. douops:    ds    1    ;data for the Doubler
  341. ;
  342.     end    baudset
  343.