home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / enterprs / cpm / utils / a / echo3.ark / ECHO3.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-09-27  |  12.8 KB  |  561 lines

  1. ;ECHO3.ASM          Disables/enables console output.      Assembles
  2. ;1/12/87          (Useful mainly in batch jobs.)      with ASM.COM.
  3. ;Roy Lipscomb
  4. ;
  5. ;            Copyright 1987, Logic Associates, Chicago.
  6. ;          Permission granted for free distribution only.
  7. ;         Cannot be sold without prior written permission.
  8. ;
  9. ;
  10. ;Version 3:    []  Allows pseudo-control codes (e.g., two-char "=Z").
  11. ;        []  Uses "-" to toggle upper/lower case.
  12. ;
  13. ;Version 2:    []  Combines ECHON and ECHOFF into one program, ECHO.
  14. ;        []  Verifies the location of the echo switch.
  15. ;        []  Compatible with XSUB.
  16. ;        []  Employs new syntax, similar to ECHO in PC-DOS.
  17. ;
  18. ;Please address any comments or suggestions to--
  19. ;
  20. ;    Roy Lipscomb
  21. ;    Logic Associates
  22. ;    1433 W. Thome
  23. ;    Chicago, IL 60660
  24. ;
  25. ;----------------------------------------------------------
  26.     org    100h
  27.     jmp    begin
  28.  
  29. ;.........................................................
  30. ;equates.
  31.  
  32. ul    equ    '/'        ;char for "toggle upper/lower case."
  33. ct    equ    '~'        ;char for "convert next char to ctl."
  34. nc    equ    '+'        ;char for "text done, no cr/lf."
  35.  
  36. no    equ    0
  37. yes    equ    255
  38.  
  39. bell    equ    7
  40. cr    equ    0dh
  41. lf    equ    0ah
  42.  
  43. dirio    equ    6        ;direct console i/o function.
  44. bdos    equ    5
  45.  
  46. on    equ    jmp
  47. off    equ    ret
  48.  
  49. warmboot equ    0
  50. bdos    equ    5
  51.  
  52. fcb    equ    5ch    ;default fcbs, containing first word
  53. fcb2    equ    6ch    ;  and second word respectively of the
  54.             ;  command line.
  55. textloc    equ    82h    ;command-line text location.
  56.  
  57. ;options:
  58. noopt    equ    0    ;no further action.
  59. help    equ    1    ;display instructions.
  60. swoff    equ    2    ;disable console output.
  61. swon    equ    3    ;enable console output.
  62. text    equ    4    ;display command-line text.
  63.  
  64. ;.........................................................
  65. ;messages.
  66.  
  67. helpmsg:
  68.  db cr,lf,ul,'ECHO3  E',ul,'nables-disables console output.'
  69.  db cr,lf,ul,'C',ul,'opyright 1987, ',ul,'L',ul,'ogic '
  70.  db       ul,'A',ul,'ssociates, 60660'
  71.  db cr,lf,'      ',ul,'F',ul,'or free distribution only.'
  72. ;db cr,lf
  73.  db cr,lf,'---------------------------------------'
  74.  db cr,lf
  75.  db cr,lf,'  ',ul,'D',ul,'isable output:    ',ul,'ECHO  OFF',ul
  76.  db cr,lf
  77.  db cr,lf,'  ',ul,'E',ul,'nable output:     ',ul,'ECHO  ON',ul
  78.  db cr,lf
  79.  db cr,lf,'  ',ul,'D',ul,'isplay "text,"'
  80.  db cr,lf,'  whether on-off:    ',ul,'ECHO',ul,'  text'
  81.  db cr,lf
  82.  db cr,lf,'  ',ul,'D',ul,'isplay help:      ',ul,'ECHO  HELP',ul
  83.  db cr,lf,'                  or ',ul,'ECHO  H',ul
  84.  db cr,lf,'                  or ',ul,'ECHO  ?',ul
  85.  db cr,lf
  86.  db cr,lf,'* "',ul,ul,'" means "',ul,'T',ul,'oggle upper-lower case":'
  87.  db cr,lf,'      ',ul,'W',ul,'rite "',ul,'',ul,'ram',ul,'',ul,' disk" '
  88.  db       'for "',ul,'RAM',ul,' disk".'
  89.  db cr,lf,'* "',ct,ct,'" means "',ul,'C',ul,'ontrol-".'
  90.  db       '  (',ul,'E',ul,'.g., "',ct,ct,'',ul,'Z',ul,'".)'
  91.  db cr,lf,'* "',nc,nc,'" means "',ul,'I',ul,'gnore carriage return."'
  92.  db cr,lf,'* ',ul,'B',ul,'ypass above by '
  93.  db       '"',ul,ul,ul,ul,'", "'
  94.  db       '"',ct,ct,ct,ct,'", "'
  95.  db     'or ',nc,nc,nc,nc,'".'
  96.  db cr,lf
  97.  db cr,lf,'---------------------------------------'    
  98. endomess:
  99.  db 0
  100.  
  101. errmsg:
  102.  db bell
  103.  db cr,lf,'***> ',ul,'N',ul,'o action.  ',ul,'S',ul,'witch not found. <***'
  104. crlf:
  105.  db cr,lf,0
  106.  
  107. ;.........................................................
  108. ;work locations.
  109.  
  110. tablen    equ    6    ;length of entry in table below.
  111. tsttab:
  112.  db '?    ',help
  113.  db 'H    ',help
  114.  db 'HELP ',help
  115.  db 'OFF  ',swoff
  116.  db 'ON   ',swon
  117.  db 0,text
  118.  
  119. option: db    0    ;option desired by user.
  120.  
  121. echosw:    dw    0    ;location of echo switch (bios jump table).
  122.  
  123. error:    db    no    ;error in locating echo switch?
  124.  
  125. upper:    db    no    ;display this char in upper case?
  126.  
  127. oldchar: db    0    ;latest character displayed by ECHO.
  128.  
  129. ;--------------------------------------------------------
  130. ;            mainline            ;
  131. ;--------------------------------------------------------
  132. begin:
  133.     xra    a        ;initialize old-char area.
  134.     sta    oldchar
  135.  
  136.     call    findsw        ;locate the echo on/off switch.
  137.                 ;if not found, set "error" = yes.
  138.  
  139.     call    findparm    ;analyze parm, return option.
  140.  
  141.     cpi    help        ;asking for help?
  142.     cz    dhelp
  143.  
  144.     cpi    text        ;display text?
  145.     cz    dtext
  146.  
  147.     lda    error        ;echo-switch unlocated?
  148.     cpi    yes
  149.     lda    option
  150.     cz    derror
  151.  
  152.     cpi    swon        ;turn on?
  153.     cz    turnon
  154.  
  155.     cpi    swoff        ;turn off?
  156.     cz    turnoff
  157.  
  158.     ret            ;return to CP/M.
  159.  
  160. ;--------------------------------------------------------
  161. ;        determine option            ;
  162. ;--------------------------------------------------------
  163. ;on exit, a = option code (for help, ON, OFF, or text.)
  164.  
  165. findparm:
  166.     lxi    h,fcb+1        ;address test-table
  167.     xchg            ;  and start of command
  168.     lxi    h,tsttab-tablen ;  line.
  169.  
  170.     push    d
  171.     push    h
  172.  
  173. findpr1:
  174.     pop    h
  175.     pop    d
  176.  
  177.     lxi    b,tablen    ;bump to next table entry.
  178.     dad    b
  179.  
  180.     inr    m        ;end of table?
  181.     dcr    m
  182.     jz    findpr8        ;  yes, assume text: exit.
  183.  
  184.     push    d        ;save for next test.
  185.     push    h
  186.  
  187.     call    chekopt        ;is this the option?
  188.     jnz    findpr1        ; no, test next option.
  189.                 ; yes, a = option code.
  190.  
  191.     pop    d        ;flush stack.
  192.     pop    h
  193.  
  194.     mov    b,a        ;save option code.
  195.  
  196.     cpi    text        ;is it text option?
  197.     jz    findpr9        ;  yes, keep code, exit.
  198.  
  199.     lda    fcb2+1        ;only one word on command line?
  200.     cpi    ' '
  201.     jz    findpr9        ; yes, keep code, exit.
  202.  
  203. findpr8:
  204.     mvi    b,text        ;change code to "text."
  205.  
  206. findpr9:
  207.     mov    a,b        ;get code into a.
  208.     sta    option        ;save the code.
  209.  
  210.     ret            ;return option code in A.
  211.  
  212. ;........................................................
  213. ;        is this the option?            ;
  214. ;........................................................
  215. ;on exit, z = no if no match.
  216. ;   else  z = yes, a = option code.
  217.  
  218. chekopt:
  219.     mvi    b,tablen-1    ;match all chars (skip code).
  220.  
  221. chekop2:
  222.     ldax    d        ;fcb char matches...
  223.     inx    d
  224.  
  225.     cmp    m        ;  ...test char?
  226.     inx    h
  227.     jnz    chekop9        ;  no, test next tab entry.
  228.  
  229.     dcr    b        ;  yes: all 4 chars done?
  230.     jnz    chekop2        ;        no, do next char.
  231.  
  232.     mov    a,m        ;        yes, get opt code.
  233.  
  234. chekop9:
  235.     ret
  236.  
  237. ;--------------------------------------------------------
  238. ;        locate echo switch            ;
  239. ;--------------------------------------------------------
  240. ;on exit, if switch found: store address of switch,
  241. ;               set z = yes.
  242.  
  243. findsw:
  244.     mvi    a,yes        ;initialize error flag.
  245.     sta    error
  246.  
  247.     call    isxsub        ;is xsub active?
  248.     jz    findsw4        ;  yes, use pointer in XSUB.
  249.  
  250.     lhld    warmboot+1    ;  no, use normal pointer.
  251.  
  252. findsw4:
  253.     call    tstsw        ;looks like switch location?
  254.     jnz    findsw9        ;  no, exit.
  255.  
  256.     shld    echosw        ;  yes, save location.
  257.  
  258.     mvi    a,no        ;turn off error flag.
  259.     sta    error
  260.  
  261. findsw9:
  262.     ret
  263.  
  264. ;........................................................
  265. ;           is xsub present?            ;
  266. ;........................................................
  267. ;on exit, if yes, z=yes, hl=pointer to bios jump table.
  268.  
  269. isxsub:
  270.     lhld    bdos+1        ;get pointers that indicate
  271.     xchg            ; whether xsub is present.
  272.     lhld    warmboot+1
  273.  
  274. ;test for presence of xsub.
  275.     mov    a,d
  276.     cmp    h        ;warmboot/bdos same page?
  277.     jnz    isxs9        ;  no, xsub not present.
  278.  
  279.     mov    a,l        ;exactly 29h bytes apart?
  280.     sui    29h
  281.     cmp    e
  282.     jnz    isxs9        ;  no, xsub not present.
  283.  
  284. ;get true warmboot vector into hl
  285.     dcx    h
  286.     mov    d,m
  287.     dcx    h
  288.     mov    e,m
  289.  
  290.     xchg
  291.  
  292. isxs9:
  293.     ret
  294.  
  295. ;........................................................
  296. ;    hl -> possible location of switch?        ;
  297. ;........................................................
  298. ;on entry, h points into possible first page of bios.
  299. ;
  300. ;on exit, if "no,"  z = no.
  301. ;      if "yes," z=yes,
  302. ;            hl=switch location.
  303.  
  304. tstsw:
  305.     mvi    l,0ch        ;adjust to proper offset,
  306.     mov    a,m        ; get content.
  307.  
  308.     cpi    on        ;is content either "on"
  309.     jz    tstws9        ;  or "off"?  if neither,
  310.                 ;  then switch not found.
  311.     cpi    off
  312. tstws9:
  313.     ret            ;if "not switch", z = no.
  314.  
  315. ;--------------------------------------------------------
  316. ;             turn switch ON                 ;
  317. ;--------------------------------------------------------
  318. turnon:
  319.     lhld    echosw
  320.     mov    b,m        ;get old value of switch.
  321.     mvi    m,on        ;set switch to new value.
  322.  
  323.     mvi    a,noopt        ;disable further options.
  324.     ret
  325.  
  326. ;--------------------------------------------------------
  327. ;             turn switch OFF             ;
  328. ;--------------------------------------------------------
  329. turnoff:
  330.     lhld    echosw
  331.     mov    b,m        ;get old value of switch.
  332.     mvi    m,off
  333.  
  334.     mvi    a,noopt        ;disable further options.
  335.     ret
  336.  
  337. ;--------------------------------------------------------
  338. ;        process appropiate message        ;
  339. ;--------------------------------------------------------
  340. dhelp:
  341.     lxi    d,helpmsg
  342.     call    display
  343.     ret
  344.  
  345. ;........................................................
  346. derror:
  347.     lxi    d,errmsg
  348.     call    display
  349.     ret
  350.  
  351. ;........................................................
  352. dtext:
  353.     lda    fcb+1        ;blank line?
  354.     cpi    ' '
  355.     jz    dtext2        ; yes, skip.
  356.  
  357.     lxi    d,textloc    ;point to command line text.
  358.     call    display
  359.  
  360. dtext2:
  361.     lda    oldchar        ;suppress cr/lf?
  362.     cpi    nc
  363.     lxi    d,crlf        ; yes, point to "blank line."
  364.     cnz    display
  365.  
  366.     ret
  367.  
  368. ;--------------------------------------------------------
  369. ;           display a message            ;
  370. ;--------------------------------------------------------
  371. ;on entry, de = msg address.
  372.  
  373. display:
  374.     lda    error        ;is switch unlocated?
  375.     cpi    yes
  376.     push    d        ;(save address of message)
  377.     cnz    turnon        ;  no:  turn it on, and...
  378.     pop    d
  379.  
  380.     push    b        ;       ...save old switch.
  381.     jmp    display6    ;  yes:  try display anyway.
  382.  
  383. display2:
  384.     lhld    oldchar        ;get previous char into l,
  385.     sta    oldchar        ;  save new char.
  386.  
  387.     mov    b,a        ;store new char in b.
  388.  
  389.     call    doul        ;if ul char:  process, and skip
  390.     jz    display5    ;       display if appropriate.
  391.  
  392.     call    docntl        ;if make-ctl:  process, and skip
  393.     jz    display5    ;       display if appropriate.
  394.  
  395.     call    donc        ;if "nc" char:  process, and skip
  396.     jz    display5    ;       display if appropriate.
  397.  
  398. display4:
  399.     mov    a,b        ;reget new char.
  400.  
  401.     push    d
  402.     call    setcase        ;set char to upper or
  403.     call    chario        ; lower case, then output.
  404.     pop    d
  405.  
  406.     lda    oldchar        ;indicate old char was displayed.
  407.     ori    80h
  408.     sta    oldchar
  409.  
  410. display5:
  411.     inx    d
  412.  
  413. display6:
  414.     ldax    d
  415.     ora    a        ;null?
  416.     jnz    display2    ;  no, go process.
  417.  
  418. display8:
  419.     pop    b
  420.  
  421.     lda    error        ;error locating switch?
  422.     cpi    yes
  423.     jz    display9    ; yes, exit.
  424.  
  425.     lhld    echosw        ; no, restore old content
  426.     mov    m,b        ;  of switch.
  427.  
  428. display9:
  429.     mvi    a,noopt        ;disable further actions,
  430.     sta    error        ;  including error msg.
  431.  
  432.     ret
  433.  
  434. ;........................................................
  435. ;        set char to upper/lower case        ;
  436. ;........................................................
  437. ;on entry, a = b = new char, l = old char.
  438. ;on exit, if z = yes, then skip display of char.
  439.  
  440. doul:
  441.     mov    a,b
  442.  
  443.     cpi    ul        ;current char is ul char?
  444.     mvi    a,1        ;(set to display char)
  445.     jnz    doul9        ; no, exit.
  446.  
  447.     lda    upper        ;toggle upper/lower case.
  448.     cma
  449.     sta    upper
  450.  
  451.     mov    a,b
  452.     cmp    l        ;old char undisplayed ul char?
  453.     mvi    a,1        ;(set to display char)
  454.     jz    doul9        ;  yes, display new char (ul char).
  455.     xra    a        ;  no, skip display
  456.  
  457. doul9:
  458.     ora    a        ;set flag.
  459.     ret
  460.  
  461. ;........................................................
  462. ;        build control char            ;
  463. ;........................................................
  464. ;on entry, a = b = new char, l = old char.
  465. ;on exit, if z = yes, then skip display of char.
  466.  
  467. docntl:
  468.     mvi    a,ct        ;old char is undisplayed make-ctl?
  469.     cmp    l
  470.     jz    docntl4        ; yes, skip.
  471.  
  472.     cmp    b        ; no, new char is an make-ctl?
  473.     mvi    a,1        ;(clear a.)
  474.     jmp    docntl9        ; yes/no, exit.  (if yes, skip display)
  475.  
  476. docntl4:
  477.     sub    b        ;new char also = make-ctl?
  478.     jz    docntl8        ;  yes, exit and display.
  479.  
  480.     mov    a,b        ;  no, convert new char into
  481.     ani    1fh        ;      control char, and
  482.     mov    b,a
  483.  
  484. docntl8:
  485.     ori    1        ;      display char.
  486.  
  487. docntl9:
  488.     ret
  489.  
  490. ;........................................................
  491. ;        set to end without cr/lf        ;
  492. ;........................................................
  493. ;on entry, a = b = new char, l = old char.
  494. ;on exit, if z = yes, then skip display of char,
  495. ;               and point to end of message.
  496.  
  497. donc:
  498.     mvi    a,nc        ;old char is undisplayed "nc" char?
  499.     cmp    l        ;(if displayed, was second of prev pair).
  500.     jz    donc4        ; yes, skip.
  501.  
  502.     cmp    b        ;new char is an "nc" char?
  503.     jz    donc8        ;  yes, skip display.
  504.     mvi    a,1        ;(set to display)
  505.     jmp    donc9        ;  no, display the char.
  506.  
  507. donc4:
  508.     cmp    b        ;new char also = "nc" char?
  509.     mvi    a,1        ;(set to display)
  510.     jz    donc9        ;  yes, display new char.
  511.  
  512.     lxi    d,endomess-1    ;  no, end message immediately,
  513.                 ;      without cr/lf.
  514. donc8:
  515.     xra    a        ;      don't display this char.
  516.  
  517. donc9:
  518.     ora    a        ;set flag.
  519.     ret
  520.  
  521. ;........................................................
  522. ;        set char to upper/lower case        ;
  523. ;........................................................
  524. ;on entry and exit, a = character.
  525.  
  526. setcase:
  527.     cpi    'A'        ;alphabetic character?
  528.     jc    setcase9
  529.  
  530.     cpi    'Z'+1
  531.     jnc    setcase9    ;  no, exit.
  532.  
  533. setcase4:
  534.     mov    e,a
  535.  
  536.     lda    upper        ;want upper case?
  537.     cpi    yes
  538.  
  539.     mov    a,e
  540.     jz    setcase9    ;  yes, keep upper case.
  541.  
  542.     ori    20h        ;  no, convert to lower.
  543.  
  544. setcase9:
  545.     ret
  546.  
  547. ;........................................................
  548. ;        output a character.            ;
  549. ;........................................................
  550. ;on entry, a = character to be output.
  551.  
  552. chario:
  553.     mov    e,a
  554.     mvi    c,dirio
  555.     call    bdos
  556.  
  557.     ret
  558.  
  559. ;--------------------------------------------------------
  560.     end
  561.