home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / cpm / terms / qt43src.lbr / BAUD.ZY / BAUD.ZY
Text File  |  1993-01-13  |  7KB  |  271 lines

  1. ; baud.z - alter baud rate, and data word format
  2.  
  3. .var    cmdlin    0x80
  4.  
  5. .macro    baudtb    speed
  6.     dw    speed
  7.     dw    b`speed
  8. .endm
  9.  
  10. .extern    baud
  11. baud:
  12.     call    prompt
  13.     db    'Baud rate? \0'    ; see what is wanted
  14.     ld    hl,cmdlin - 1
  15. scanp:    inc    hl        ; first look for +ch
  16.     ld    a,(hl)
  17.     or    a
  18.     jr    z,noplus    ; didn't find one, on to the next bit
  19.     xor    '+'
  20.     jr    nz,scanp    ; not this char, on to the next
  21.     ld    (hl),a        ; replace the '+' so we have a revised end
  22.     inc    hl
  23.     ld    bc,0x0200    ; b = 2: 2 chars, c = 0 for delimiter
  24.     ld    de,cschr    ; save them in cschr and cqchr
  25.     call    parst        ; crunch up the string
  26. noplus:    ld    hl,cmdlin - 1
  27. scansl:    inc    hl        ; then look for a -del
  28.     ld    a,(hl)
  29.     or    a
  30.     jr    z,nodel        ; no '-' found: process normally
  31.     xor    '-'
  32.     jr    nz,scansl    ; this was not a '-', on to the next
  33.     ld    (hl),a        ; put a null in to make the '-' vanish
  34.     call    incbyp        ; skip leading space
  35.     or    a        ; anything there?
  36.     jr    z,nodel        ; no - go crunch the rest
  37.     cp    '*'        ; '*' as a place holder?
  38.     jr    z,nocsdl    ; skip if no ^S delay
  39.     ld    de,1
  40.     call    scanm        ; get a number, but default if none given
  41.     ld    a,e
  42.     ld    (csdely),a    ; save in ^S delay
  43. nocsdl:    call    incbyp
  44.     or    a
  45.     jr    z,nodel        ; exit now if nothing left
  46.     cp    '*'
  47.     jr    z,nochdl    ; skip if no character delay
  48.     sub    '0'
  49.     cp    10        ; check for a number
  50.     ld    de,ecflg
  51.     ld    (de),a        ; set echo check flag
  52.     jr    nc,lcnum    ; jump if not a number - this sets flag
  53.     dec    hl        ; hl down to account for coming inx
  54.     xor    a        ; clear acc
  55.     ld    (de),a        ; and thus the echo check flag
  56. lcnum:    inc    hl
  57.     ld    de,0
  58.     call    scanm        ; get another
  59.     ld    a,e
  60.     ld    (chd),a        ; and save a character delay
  61. nochdl:    call    incbyp
  62.     or    a
  63.     jr    z,nodel        ; exit now if nothing left
  64.     cp    '*'
  65.     jr    z,nodel        ; and exit if a star
  66.     ld    de,lfecho
  67.     ld    (de),a        ; set linefeed echo flag
  68.     sub    '0'
  69.     cp    10        ; first char a digit
  70.     jr    nc,lfnum    ; jump if not
  71.     dec    hl        ; otherwise backstep hl
  72.     xor    a
  73.     ld    (de),a        ; and clear linefeed echo flag
  74. lfnum:    inc    hl
  75.     ld    de,300
  76.     call    scanm
  77.     ld    (nld),de    ; finally a newline delay
  78. nodel:    ld    hl,cmdlin
  79.     call    byp
  80.     ld    b,h
  81.     ld    c,l        ; point bc at first non-white-space in line
  82.     ld    a,(bc)
  83.     or    a
  84.     ret    z        ; end of line so do nothing
  85.     cp    '*'        ; was a '*' skip over baud rate set
  86.     jp    z,bmode
  87.     dec    bc
  88. scan:    inc    bc        ; now bypass leading zeros
  89.     ld    a,(bc)
  90.     cp    '0'
  91.     jr    z,scan
  92.     ld    hl,0        ; hl gets numeric value of rate
  93.     ld    ix,rate        ; ix points to where string will live
  94. loop:    ld    a,(bc)
  95.     sub    '0'
  96.     cp    10        ; get the next character & check it's a digit
  97.     ld    e,l
  98.     ld    d,h
  99.     jr    nc,gotit    ; nope - we've finished
  100.     add    hl,hl        ; * 2
  101.     add    hl,hl        ; * 4
  102.     add    hl,de        ; * 5
  103.     add    hl,hl        ; * 10
  104.     ld    e,a
  105.     ld    d,0        ; new digit to de
  106.     add    hl,de        ; add it in
  107.     ld    a,(bc)        ; get the character again
  108.     ld    (ix),a        ; save in string
  109.     inc    ix
  110.     inc    bc        ; move both pointers
  111.     jr    loop        ; and do it again
  112. gotit:    ld    a,d
  113.     or    e
  114.     jr    z,usage        ; zero baud rate means we should complain
  115.     ld    a,' '
  116.     push    ix
  117.     pop    hl        ; copy string save pointer to hl
  118.     ld    (hl),a
  119.     inc    hl
  120.     ld    (hl),a
  121.     inc    hl
  122.     ld    (hl),a        ; add three spaces
  123.     ld    a,(bc)        ; look at input char following rate
  124.     or    a
  125.     jr    z,cmdok        ; zero byte is ok
  126.     cp    ' '
  127.     jr    z,cmdok        ; and so is a space
  128. usage:    call    ilprt        ; but we complain about anything else
  129.     db    'Specify <rate> <mode>\r\n\0'
  130.     ret
  131. cmdok:    ld    hl,table    ; point at the table
  132. .dseg
  133. table:    baudtb    38400
  134.     baudtb    19200
  135.     baudtb    9600
  136.     baudtb    4800
  137.     baudtb    2400
  138.     baudtb    1200
  139.     baudtb    600
  140.     baudtb    300
  141. endtbl:
  142.  
  143. .cseg
  144.     push    bc        ; save address in input string
  145.     ld    b,{endtbl - table} / 4
  146. scntbl:    ld    a,(hl)
  147.     cp    e
  148.     inc    hl        ; check low byte of baud rate
  149.     jr    nz,bad2        ; skip if no match
  150.     ld    a,(hl)
  151.     cp    d        ; check high byte
  152.     jr    z,gottbl    ; match! - we got it
  153. bad2:    inc    hl        ; this entry no good
  154.     inc    hl
  155.     inc    hl        ; skip over it
  156.     djnz    scntbl        ; and loop till we run out
  157. badbau:    call    ilprt        ; go complain
  158.     db    'Error: invalid baud rate\r\n\0'
  159.     pop    hl        ; clean up the stack
  160.     ret            ; and exit
  161. gottbl:    inc    hl
  162.     ld    e,(hl)
  163.     inc    hl        ; get address of baud value entry in
  164.     ld    d,(hl)        ; configuration area
  165.     ld    a,(de)        ; get the baud byte itself
  166.     inc    de
  167.     ld    b,a        ; save in b
  168.     ld    a,(de)        ; get the flag byte
  169.     or    a        ; is it zero?
  170.     jr    z,badbau    ; yes - go complain
  171.     ld    a,b
  172.     call    setbd        ; go set the baud rate
  173.     call    ilprt        ; and say what we did
  174.     db    'Baud rate set to '
  175.  
  176. .extern    rate
  177. rate:    db    '         \r\n\0'
  178.     pop    bc        ; get the string address back to bc
  179.     dec    bc
  180. bmode:    inc    bc
  181.     ld    a,(bc)
  182.     cp    ' '
  183.     jr    z,bmode        ; do a byp on bc
  184.     or    a
  185.     ret    z        ; return now on end of string
  186.     ld    e,0        ; set e zero for mode selection
  187.     ld    ix,modsav    ; point ix at save area
  188.     ld    (ix + 0),a    ; save first byte in data bit count
  189.     cp    '7'
  190.     jr    z,seven        ; better be '7'
  191.     cp    '8'
  192.     jr    z,eight        ; or '8'
  193. badmod:    call    ilprt        ; complain if it's wrong
  194.     db    'Modes are [87][EON][12]\r\n\0'
  195.     ret
  196. eight:    inc    e        ; set bit 0 in e for 8 bit options
  197. seven:    inc    bc
  198.     ld    a,(bc)        ; get the next character
  199.     and    0x5f        ; force upper case
  200.     ld    (ix + 2),a    ; save it away
  201.     cp    'N'
  202.     jr    z,nopty        ; 'N' => no parity
  203.     cp    'O'
  204.     jr    z,odd        ; 'O' => odd parity
  205.     cp    'E'
  206.     jr    nz,badmod    ; 'E' => even parity: complain if no match
  207.     set    2,e
  208.     jr    nopty        ; set bit 2 to select even parity options
  209. odd:    set    3,e        ; set bit 3 to select odd parity options
  210. nopty:    inc    bc
  211.     ld    a,(bc)        ; look at the last character
  212.     ld    (ix + 4),a    ; and save it away
  213.     cp    '1'
  214.     jr    z,one        ; better be '1'
  215.     cp    '2'
  216.     jr    nz,badmod    ; or '2' - complain if it's neither
  217.     set    1,e        ; set bit 1 for 2 data bit options
  218. one:    inc    bc
  219.     ld    a,(bc)
  220.     cp    ' '
  221.     jr    z,one        ; skip any trailing spaces
  222.     or    a
  223.     jp    nz,usage    ; but complain if there was more junk
  224.     ld    d,0        ; extend index in e to 16 bits
  225.     ld    hl,modtab
  226.     add    hl,de        ; index into table in configuration area
  227.     ld    a,(hl)        ; get the byte
  228.     call    setmod        ; go set the modes
  229.     call    ilprt
  230.     db    'Mode set to '
  231.  
  232. .extern    modsav
  233. modsav:    db    ' , , \r\n\0'    ; and say what we did
  234.     ret
  235.  
  236. scanm:    ld    a,(hl)
  237.     sub    '0'
  238.     cp    10        ; did we get a digit?
  239.     jr    nc,donenm    ; no - use default in de
  240.     ld    de,0        ; set de zero for answer
  241. scanlp:    ld    a,(hl)
  242.     sub    '0'
  243.     cp    10        ; another digit?
  244. donenm:    jp    nc,unbyp    ; exit if not - answer in de
  245.     push    hl        ; save pointer
  246.     ld    h,d
  247.     ld    l,e
  248.     add    hl,hl
  249.     add    hl,hl
  250.     add    hl,de
  251.     add    hl,hl        ; hl = de * 10
  252.     ld    e,a
  253.     ld    d,0
  254.     add    hl,de        ; + new digit
  255.     ex    de,hl        ; back to de
  256.     pop    hl
  257.     inc    hl        ; look at next character
  258.     jr    scanlp
  259.  
  260. .dseg
  261. .extern    csdely
  262. csdely:    db    1
  263. .extern    nld
  264. nld:    dw    300
  265. .extern    chd
  266. chd:    db    0
  267. .extern cschr
  268. cschr:    db    's' & 0x1f
  269. .extern    cqchr
  270. cqchr:    db    'q' & 0x1f
  271.