home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / a / ddtf.lbr / DDTF.AZM / DDTF.ASM
Encoding:
Assembly Source File  |  1993-10-26  |  20.6 KB  |  969 lines

  1. *    ddtf.asm    Module for finding strings during ddt.
  2. *    version 1    october 27, 1981    (uses lasm.com)
  3. *
  4. *    (C) 1981, by Roy Lipscomb, Logic Associates, Chicago
  5. *    Copying permitted only for non-profit distribution.
  6. *    Original distributor:  HP/RCPM, (312) 955-4493
  7. *
  8. *
  9. *    This module relocates itself under the ccp, prints a signon
  10. *    message, then invokes ddt.  To have ddt automatically
  11. *    load filename.com, type "ddtf filename.com".
  12. *
  13. *    ddt may be on either the default drive, or the same drive
  14. *    as ddtf.
  15. *
  16. *
  17. *    Instructions on use are provided in DDTF.DOC.
  18. *
  19. * >>>>> Essential:  Read the directions given in DDTF.DOC
  20. *    before attempting to assemble this source code.
  21. *
  22. ********************************************************************
  23.  
  24. *********************************************************
  25. *        service/loader routines            *
  26. *********************************************************
  27.  
  28.     if    copy1        ;service routines
  29.     org     100h
  30.     jmp    begin
  31.  
  32. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  33. ;        initial variables            ;
  34. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  35.  
  36. ; change these if necessary
  37. reboot    equ    0
  38. starts    equ    0        ;start of block to search
  39. lengths    equ    0e000h        ;length of block to search
  40. linelen    equ    16        ;number of chars dumpable on a line
  41.                 ;(16 fits 80-col crt).
  42. restart    equ    1        ;first of two consecutive rst
  43.                 ; locations not otherwise used
  44.  
  45. ; there is normally no need to change these
  46. templat    equ    5dh
  47. bdos    equ    5
  48. conin    equ    1
  49. conout    equ    2
  50. constat    equ    11
  51. searchf    equ    17
  52. rst7    equ    56
  53. deffcb    equ    5ch
  54. tbuff    equ    80h
  55. bufflen    equ    60        ;expected maximum length of command
  56.                 ;line (for inserting " DDT ")
  57.                 ;(short length protects debug stack
  58.                 ;while testing under ddt)
  59. ctls    equ    19
  60. cr    equ    13
  61. lf    equ    10
  62. blank    equ    ' '
  63.  
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  65. ;values used in manipulating the ccp
  66.  
  67. doslen1    equ    0d00h        ;length of cpm 1.x bdos
  68. doslen2    equ    0e00h        ;length of cpm 2.x bdos
  69.  
  70. ccplen    equ    800h        ;length of ccp
  71. ccpbmax    equ    6        ;offset to ccp buff maxlength value
  72. ccpcoml    equ    ccpbmax+1    ;offset to ccp command-length byte
  73. ccpbuff    equ    ccpcoml+1    ;offset to start of ccp command line
  74. ccp    dw    0        ;ccp entry point
  75.  
  76. curdrv    equ    4        ;current drive in pg zero
  77. ccpstrt    dw    0        ;pointer to first char in ccp buff
  78.  
  79.  
  80.  
  81. ;variables used in creating DDT-invoking command
  82. ddt    db    '  DDT '    ;first 2 blanks are space for "x:"
  83. ddtlen    equ    $-ddt
  84.  
  85. ddtfcb    db    0,'DDT     COM',0,0,0,0
  86.     dw    0,0,0,0,0,0,0,0
  87.  
  88.  
  89. ;variables used in tests, moves, and message printing
  90.  
  91. protadr    dw    0        ;current start of RAM to be protected
  92. loadpnt    dw    0
  93.  
  94. eom    equ    '$'
  95.  
  96. ccpmess    db    'Abort:  unable to locate CCP',eom
  97.  
  98. rstmess    db    'Abort:  assembled with bad restart location',eom
  99.  
  100. mismess    db    'Abort:  DDT not found',eom
  101.  
  102. helpmes    db    cr,lf
  103.     db    '  DDTF   (C) 1981 by Roy Lipscomb, Logic Associates'
  104.     db    cr,lf
  105.     db    '           Version 1      October, 1981'
  106.     db    cr,lf
  107.     db    cr,lf
  108.     db    '         A "find string" command for DDT.'
  109.     db    cr,lf
  110.     db    '     DDT must be on default disk or DDTF disk.'
  111.     db    cr,lf
  112.     db    '      For condensed instructions, type D'
  113.     db    eom
  114.  
  115.  
  116. ; compute rst address for instruction display
  117. ; f1,f2 is address of jump to find; s2,s2 is start search address
  118.  
  119. rstadr    equ    restart*8
  120. find    equ    rstadr+3
  121. blkhead    equ    rstadr+6
  122. blklen    equ    rstadr+9
  123.  
  124. f1    set    find/16+'0'    ;convert nibbles to ascii
  125. f2    set    (find and 0fh)+'0'
  126. s1    set    blkhead/16+'0'
  127. s2    set    (blkhead and 0fh)+'0'
  128.  
  129. f1    set    f1+('9'+1-f1)/2000h    ;add 7 if greater than "9"
  130. f2    set    f2+('9'+1-f2)/2000h
  131. s1    set    s1+('9'+1-s1)/2000h
  132. s2    set    s2+('9'+1-s2)/2000h
  133.  
  134.  
  135. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  136. ;        mainline                ;
  137. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  138.  
  139. ;initialize and print message
  140. begin    call    getbase        ;compute load address: just below CCP
  141.     push    psw        ;save ccp-located flag
  142.     call    signon        ;print signon message
  143.     pop    psw        ;restore ccp-located flag
  144.     jz    ccperr        ;ccp not found
  145.  
  146. ;insure good environment
  147.     call    testrst
  148.     jz    rsterr        ;0 = bad rst address
  149.  
  150.     call    testddt        ;insure ddt present
  151.     jz    ddtmiss
  152.  
  153. ;do it
  154.     call    chgaddr        ;convert to true addresses
  155.     call    movemod        ;move module to load address
  156.     call    fillrst        ;set up restart location
  157.  
  158.     jmp    getddt        ;link to ddt ("jmp" directly to ccp)
  159.  
  160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  161. ;        find load point for ddtf        ;
  162. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  163. ;if ccp not found, return with zero set
  164. ;(uses all registers)
  165.  
  166. ;address length of command in CCP buffer
  167. getbase    lhld    6
  168.     shld    protadr        ;protect-address if ccp already
  169.                 ;  protected
  170.     lxi    d,0
  171.     call    tstccp
  172.     jz    ccpnopr        ;ccp found, not protected
  173.  
  174. ;second try:  via cbios entry point of cpm 2.x
  175.     lhld    1
  176.     lxi    d,-doslen2
  177.     call    tstccp
  178.     jz    ccpprot        ;ccp found, protected
  179.  
  180. ;last try:  via cbios entry point of cpm 1.x
  181.     lhld    1
  182.     lxi    d,-doslen1
  183.     call    tstccp
  184.     jz    ccpprot        ;ccp found, protected
  185.  
  186. ;ccp not found
  187.     xra    a
  188.     ret            ;set zero flag ("not found")
  189.  
  190. ;ccp found, but not protected
  191. ccpnopr    lhld    ccp        ;ccp not yet protected...
  192.     lxi    d,-ccplen
  193.     dad    d
  194.     shld    protadr        ;set to protect ccp
  195.  
  196. ;ccp found, and already protected
  197. ccpprot    lxi    d,-length
  198.     lhld    protadr
  199.     dad    d
  200.     mvi    l,0        ;place on page boundary (unnecessary?)
  201.     shld    loadpnt
  202.  
  203. ;exit with flag set to "ccp found"
  204.     ori    1
  205.     ret
  206.  
  207.  
  208. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  209. ;test if this location has ccp
  210.  
  211. ;compute tentative ccpbase
  212. tstccp    mvi    l,0
  213.     dad    d        ;compute tentative bdos entry point
  214.     lxi    d,-ccplen
  215.     dad    d        ;tentative bdos entry minus ccp length
  216.     shld    ccp        ; ...gives tentative ccp entry
  217.     xchg            ; ...move it to de for safe keeping
  218.  
  219. ;compute relevant addresses
  220.     lxi    h,ccpbmax    ;compute address of ccp buff ptr:
  221.     dad    d        ;(non-standard ccps might not have 88h)
  222.     mvi    a,ccpbuff+1    ; ccpbuff + 1 + maxbufflen
  223.     add    m
  224.  
  225.     mov    l,a        ;address of ccp buffer pointer...
  226.     push    h
  227.     pop    b        ;... to bc
  228.  
  229.     lxi    h,ccpcoml    ;address of ccp command-line length
  230.     dad    d        ;... to hl
  231.  
  232. ;address command end + 1
  233.     mov    e,m
  234.     mvi    d,0
  235.     dad    d
  236.     inx    h
  237.  
  238. ;if null not at command end +1, ccp absent
  239.     mov    a,m
  240.     ora    a
  241.     rnz            ;not present, so return non-zero
  242.  
  243. ;test if ccp character pointer points to same null, or to value
  244. ; that appears after that null
  245.     mov    a,l        ;get displacement of command endmark
  246.     push    b        ;ccp current-char pointer to hl
  247.     pop    h
  248.     sub    m        ;compare to length displacement
  249.     rz            ;if equal, found
  250.     rc            ;if greater, not found
  251.  
  252. ;does ccp character pointer indicate byte preceding command line?
  253.     mvi    a,ccpbuff
  254.     sub    m
  255.     rnc            ;can't precede command-line
  256.  
  257. ;does ccp character pointer point to inter-parameter blank?
  258.     mvi    a,blank
  259.     mov    l,m        ;address byte pointed to by chr pointer
  260.     cmp    m
  261.  
  262.     ret            ;if zero, ccp found; else not found
  263.  
  264. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  265. ;        test for good RST location        ;
  266. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  267.  
  268. ;test for good rst address:  return "0" if not
  269. testrst    lxi    h,rstadr
  270.     mov    a,l
  271.     ora    h
  272.     rz            ;can't be rst 0...
  273.  
  274.     lxi    d,-48
  275.     dad    d
  276.     mov    a,h
  277.     ora    a
  278.     rm            ;if less than 48 (rst 6),
  279.                 ; it's ok.
  280. badrst    xra    a
  281.     ret
  282.  
  283. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  284. ;    test if ddt present, update messages with drive    ;
  285. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  286.  
  287. ;find first character of lastest ccp command
  288. testddt    lhld    ccp
  289.     lxi    d,ccpbuff
  290.     dad    d    
  291.     shld    ccpstrt        ;save pointer to ccp buff start
  292.  
  293.     mvi    a,' '        ;skip blanks
  294. skipbl    cmp    m
  295.     inx    h
  296.     jz    skipbl
  297.  
  298. ;test for drive prefix on latest ccp command (viz, "B:DDTF")
  299.     mov    a,m
  300.     cpi    ':'
  301.     jnz    builddt        ;if not ":", don't insert drive name
  302.  
  303.     dcx    h
  304.     mov    a,m        ;save drive name for ddt search
  305.     sui    40h
  306.     sta    ddtfcb
  307.  
  308.     lxi    d,ddt        ;set "  DDT" to "x:DDT"
  309.     lxi    b,2
  310.     call    move
  311.  
  312. ;create complete command, move it to ccp buffer
  313. builddt    call    build
  314.  
  315. ;insure ddt is present (do only after command moved from tbuff)
  316.     call    ddtpres
  317.  
  318.     ret            ;zero set if ddt not found
  319.  
  320. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  321. ; insure ddt present on selected or default drive    ;
  322. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  323.  
  324. ;if not found either place, set zero flag = error
  325.  
  326. ;try to find ddt on selected drive
  327. ddtpres    lxi    d,ddtfcb
  328.     mvi    c,searchf
  329.     call    bdos
  330.     inr    a        ;if not 255, found:  return
  331.     rnz
  332.  
  333. ;if above drive was default, set error flag and return
  334.     lxi    d,ddtfcb
  335.     ldax    d
  336.     ora    a
  337.     rz            ;set error flag
  338.  
  339. ;set up to search for ddt on default drive
  340.     xra    a
  341.     stax    d        ;set ddt fcb to default drive
  342.  
  343.     lhld    ccpstrt        ;clear "x:DDT" back to "  DDT" in ccp
  344.     mvi    m,' '
  345.     inx    h
  346.     mvi    m,' '
  347.  
  348. ;search default drive for ddt
  349.     mvi    c,searchf    ;see if ddt on directory
  350.     call    bdos
  351.  
  352.     inr    a        ;if not present, set zero flag
  353.     ret
  354.  
  355. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  356. ;        convert module1 to true addresses    ;
  357. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  358.  
  359. * change pseudo addresses to true addresses
  360. chgaddr    lxi    b,length
  361.     lxi    d,module1
  362.     lxi    h,module2
  363. truloop    ldax    d
  364.     cmp    m
  365.     cnz    convert
  366.  
  367.     inx    h
  368.     inx    d
  369.     dcx    b
  370.  
  371.     mov    a,b
  372.     ora    c
  373.     jnz    truloop
  374.  
  375.     ret
  376.  
  377.  
  378. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  379. ;    convert displacement into address        ;
  380. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  381.  
  382. convert    push    b        ;length of module not yet processed
  383.     push    h        ;module2 character position
  384.  
  385. ; get displacement from instruction, put into bc.
  386.     ldax    d
  387.     mov    b,a
  388.     dcx    d
  389.     ldax    d
  390.     mov    c,a
  391.  
  392.     lxi    h,-module1    ;normalize displacement to zero
  393.     dad    b
  394.     push    h
  395.     pop    b
  396.  
  397.     lhld    loadpnt        ;add load point for true addr
  398.     dad    b
  399.  
  400. ; move true address to instruction
  401.     mov    a,l
  402.     stax    d
  403.     inx    d
  404.     mov    a,h
  405.     stax    d
  406.  
  407.     pop    h
  408.     pop    b
  409.  
  410.     ret
  411.  
  412. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  413. ;        move module into place            ;
  414. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  415.  
  416. movemod    lhld    loadpnt
  417.     xchg                ;de=destination
  418.     lxi    h,module1        ;hl=source 
  419.     lxi    b,length 
  420.  
  421.     call    move
  422.  
  423. ; protect the module (removed by wboot)
  424. protect    lhld    6
  425.     xchg
  426.     lhld    loadpnt
  427.  
  428.     dcx    h
  429.     mov    m,d
  430.     dcx    h
  431.     mov    m,e
  432.     dcx    h
  433.     mvi    m,jmp
  434.  
  435.     shld    6
  436.  
  437.     ret
  438.  
  439. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  440. ;    initialize restart location            ;
  441. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  442.  
  443. ;install rst 7 instruction
  444. fillrst    lxi    h,rstadr
  445.     mvi    m,call
  446.     inx    h
  447.     mvi    m,rst7
  448.     inx    h
  449.     mvi    m,0
  450.     inx    h
  451.  
  452. ;install "jmp findmod"
  453.     mvi    m,jmp
  454.     inx    h
  455.     xchg
  456.     lhld    loadpnt
  457.     xchg
  458.     mov    m,e
  459.     inx    h
  460.     mov    m,d
  461.     inx    h
  462.  
  463. ;install default start-search address
  464.     mvi    m,jpo
  465.     inx    h
  466.     lxi    d,starts
  467.     mov    m,e
  468.     inx    h
  469.     mov    m,d
  470.     inx    h
  471.  
  472. ;install default search length
  473.     mvi    m,jnz
  474.     inx    h
  475.     lxi    d,lengths
  476.     mov    m,e
  477.     inx    h
  478.     mov    m,d
  479.  
  480.     ret
  481.  
  482. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  483. ;        print error messages            ;
  484. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  485. ddtmiss    lxi    h,mismess
  486.     jmp    domess
  487.  
  488. ccperr    lxi    h,ccpmess
  489.     jmp    domess
  490.  
  491. rsterr    lxi    h,rstmess
  492.  
  493. domess    call    display+module2
  494.     call    newline+module2
  495.     jmp    reboot        ;return to cpm
  496.  
  497.  
  498. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  499. ;        print signon mess            ;
  500. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  501.  
  502. ;take advantage of the fact that several of the needed
  503. ;routines are present in the relocatable module
  504.  
  505. signon    lxi    h,helpmes
  506.     call    display+module2
  507.  
  508.     lhld    loadpnt        ;display load address
  509.     call    dispadr+module2
  510.     call    newline+module2
  511.  
  512.     call    newline+module2
  513.     call    newline+module2
  514.     ret
  515.  
  516. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  517. ;        invoke ddt                ;
  518. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  519.  
  520. ;set ccp command-buffer pointer
  521. getddt    lhld    ccp
  522.     lxi    d,ccpbmax    ;offset of ccp char ptr
  523.     dad    d
  524.     mvi    a,ccpbuff+1
  525.     add    m
  526.     mov    l,a
  527.     mvi    m,ccpbuff    ;store char pointer
  528.  
  529. ;select drive
  530.     lda    curdrv
  531.     mov    c,a        ;select current drive
  532.  
  533. ; execute
  534.     lhld    ccp
  535.     pchl
  536.  
  537.  
  538. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  539. ;    build new command in CCP buffer            ;
  540. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  541.  
  542. build    lda    deffcb+1    ;parmeter passed?
  543.     ora    a
  544.     jz    deflgth
  545.  
  546.     cpi    blank        ; if yes, tbuff is empty
  547.     cnz    elbow        ;if no, make room for "DDT" string
  548. deflgth    cz    emptbuf        ;if yes, set default:  "DDT" only
  549.  
  550. ;move (prefix+) "DDT" into command-line workarea
  551. movcom    lxi    h,ddt
  552.     lxi    d,tbuff+1
  553.     lxi    b,ddtlen
  554.     call    move
  555.  
  556. ;move new command to ccp buffer
  557.     lhld    ccp
  558.     lxi    d,ccpcoml
  559.     dad    d    
  560.     xchg            ;destination to de (ccp buffer)
  561.  
  562.     lxi    h,tbuff        ;source to hl (tbuff)
  563.  
  564.     mvi    b,0
  565.     mov    c,m        ;length of command
  566.     inr    c        ;  + 1 (for length byte itself) to bc
  567.     call    move
  568.  
  569. ;install end-of-command marker
  570.     xchg
  571.     mvi    m,0
  572.  
  573.     ret
  574.  
  575. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  576. ;    make room in command line for "DDT" string    ;
  577. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  578.  
  579. ;command line not empty; make room for "DDT "
  580. elbow    lxi    d,tbuff+bufflen        ;destination
  581.     lxi    h,tbuff+bufflen-ddtlen    ;source
  582.     mvi    b,bufflen-ddtlen    ;length (all but length byte)
  583. elloop    mov    a,m
  584.     stax    d
  585.     dcx    d
  586.     dcx    h
  587.     dcr    b
  588.     jnz    elloop
  589.  
  590. ; update buffer length byte
  591.     mov    a,m
  592.     adi    ddtlen
  593.     mov    m,a
  594.  
  595.     ori    1        ;set to skip call (after return)
  596.     ret
  597.  
  598. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  599. ;command line empty; "DDT " will be alone
  600. emptbuf    mvi    a,ddtlen
  601.     sta    tbuff
  602.  
  603.     ret
  604.  
  605. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  606. ;        move block of data            ;
  607. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  608.  
  609. ;source in hl, destination in de, length in bc.
  610.  
  611. move    mov    a,b
  612.     ora    c
  613.     rz
  614.     mov    a,m
  615.     stax    d
  616.     inx    d
  617.     inx    h
  618.     dcx    b
  619.     jmp    move
  620.  
  621. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  622. ;        end of service routines            ;
  623. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  624.  
  625.     endif
  626.  
  627.  
  628.  
  629.  
  630. *********************************************************
  631. *********************************************************
  632. *    beginning of relocatable module            *
  633. *********************************************************
  634. *********************************************************
  635.  
  636.  
  637. ;must org on page boundary, though final copy
  638. ;is loadable anywhere.
  639.     org    ($/100h+1)*100h
  640. cbase    set    $
  641.  
  642.     if    copy1
  643. module1    equ    $
  644.     endif
  645.  
  646.     if    not copy1
  647. module2    equ    $
  648.     endif
  649.  
  650.  
  651. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  652. ; jump to start
  653.     jmp    start+cbase
  654.  
  655. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  656. ;        instructions                ;
  657. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  658.  
  659.     db       'place xvaluex'
  660.     db    'at 5dh; x is any'
  661.     db    'single char not '
  662.     db    'used in value.  '
  663.     db    '                '
  664.  
  665.     db    'To execute, type'
  666.  
  667.         if    (f1-'1') shr 15        ;if f1 = 0
  668.         db    ' G'
  669.         endif
  670.  
  671.         if    (not f1-'1') shr 15    ;if f1 <> 0
  672.         db    'G',f1
  673.         endif
  674.  
  675.     db    f2,'.  To repeat,'
  676.     db    'type G.         '
  677.     db    '                '
  678.  
  679.         if    (s1-'1') shr 15        ;if s1 = 0
  680.         db    ' L'
  681.         endif
  682.  
  683.         if    (not s1-'1') shr 15    ;if s1 <> 0
  684.         db    'L',s1    
  685.         endif
  686.  
  687.     db    s2,' will show   '
  688.     db    'the start (jpo) '
  689.     db    'and length (jnz)'
  690.     db    'of search:  use '
  691.  
  692.         if    (s1-'1') shr 15        ;if s1 = 0
  693.         db    ' A'
  694.         endif
  695.  
  696.         if    (not s1-'1') shr 15    ;if s1 <> 0
  697.         db    'A',s1    
  698.         endif
  699.  
  700.     db    s2,' to change.  '
  701.     db    '                '
  702.  
  703. crlf    equ    $-cbase
  704.     db    cr,lf,eom
  705.  
  706. version    equ    $-cbase
  707.     db    0        ;cpm version.  if 2.X,
  708.                 ;  keyboard can interrupt display
  709.  
  710. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  711. ;        vestibule processing            ;
  712. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  713.  
  714. start    equ    $-cbase
  715.     push    psw
  716.     push    b
  717.     push    d
  718.     push    h
  719.  
  720. ;initialize variables
  721.     lhld    blkhead+1    ;start of search-block to bc
  722.     mov    b,h
  723.     mov    c,l
  724.  
  725.     lhld    blklen+1    ;length of search to de
  726.     xchg
  727.  
  728. ;perform search
  729.     call    search+cbase
  730.  
  731. ;return to ddt
  732.     pop    h
  733.     pop    d
  734.     pop    b
  735.     pop    psw
  736.     jmp    rstadr    ;go to rst7 instruction at rstadr
  737.  
  738. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  739. ;        mainline: find substring        ;
  740. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  741.  
  742. search    equ    $-cbase        ;begin comparison anew
  743.     mov    a,d
  744.     ora    e        ;at end of search block?
  745.     rz            ;  yes, return
  746.  
  747.     push    d        ;save count of chars left
  748.     push    b        ;save current lead-off char ptr
  749.     lxi    h,templat+1    ;address the template
  750. oksofar    equ    $-cbase
  751.     lda    templat        ;address initial terminator
  752.     cmp    m        ;is this the end terminator?
  753.     jz    dumplin+cbase    ; yes, full match: do dump, and
  754.                 ;  jump to reset
  755.     ldax    b        ;not template end, so get block char
  756.     cmp    m        ;does it match template char?
  757.     inx    b        ;(address next char in block)
  758.     inx    h        ;(address next char in template)
  759.     jnz    reset+cbase    ;  no match; reinitialize
  760.  
  761.     dcx    d
  762.     mov    a,d
  763.     ora    e        ;a match, but is it end of block?
  764.     jnz    oksofar+cbase    ;  no, looks good; keep going...
  765.  
  766. reset    equ    $-cbase        ;reinitialize at next block char
  767.     pop    b        ;get old lead-off position for block
  768.     pop    d        ;get char count at lead-off position
  769.     dcx    d        ;count down chars left in block
  770.     inx    b        ;bump to next lead-off position
  771.     jmp    search+cbase    ;restart the comparison
  772.  
  773. *********************************************************
  774. *        dump routines                *
  775. *********************************************************
  776.  
  777. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  778. ;dump line
  779.  
  780. dumplin    equ    $-cbase
  781.     pop    b        ;restore lead-off character
  782.     push    b        ;...and resave
  783.  
  784. ;begin dump half-a-line back from target string
  785.     lxi    h,-linelen/2
  786.     dad    b
  787.  
  788. ;output sections of the line
  789.     call    dispadr+cbase
  790.     call    dumphex+cbase
  791.     call    dumpasc+cbase
  792.  
  793.     call    newline+cbase
  794.  
  795. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  796. ;check for interrupt
  797.  
  798. ;key pressed?
  799.     mvi    c,constat    ;key pressed?
  800.     call    bdos
  801.     ora    a        ;if zero, no key pressed,
  802.     jz    reset+cbase    ; continue processing
  803.  
  804. ;get char  (if ctl-s, continue listing)
  805.     mvi    c,conin        ;get character
  806.     call    bdos
  807.     ani    7fh
  808.     cpi    ctls
  809.     jz    reset+cbase    ; continue processing
  810.  
  811. ;interrupt requested:  stop dump, and return to ddt
  812.     pop    b
  813.     pop    d
  814.     ret
  815.  
  816. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  817. ;display address in hl
  818. dispadr    equ    $-cbase
  819.     push    h        ;display high byte
  820.     mov    a,h
  821.     call    disphex+cbase
  822.     pop    h
  823.  
  824.     push    h        ;display low byte
  825.     mov    a,l
  826.     call    disphex+cbase
  827.  
  828.     mvi    b,1        ;output a blank
  829.     call    blanks+cbase
  830.  
  831.     pop    h
  832.  
  833.     ret
  834.  
  835. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  836. ;dump line in hex
  837. dumphex    equ    $-cbase
  838.     push    h        ;save start dump-address
  839.     mvi    b,linelen    ;set line length
  840.  
  841. dhloop    equ    $-cbase
  842.     push    h        ;save current dump-address
  843.     push    b        ;save current char position
  844.     mov    a,m        ;get character
  845.     call    disphex+cbase        ;output
  846.  
  847.     mvi    b,1        ;output blank
  848.     call    blanks+cbase
  849.  
  850.     pop    b        ;restore char count
  851.     pop    h        ;restore curr dump-address
  852.     inx    h
  853.     dcr    b        ;done?
  854.     jnz    dhloop+cbase    ; no, do next char
  855.  
  856.     pop    h        ;restore start dump-address
  857.     ret
  858.  
  859. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  860. ;dump line in ascii
  861. dumpasc    equ    $-cbase
  862.     push    h        ;save start dump-address
  863.     mvi    b,linelen    ;set line length
  864.  
  865. daloop    equ    $-cbase
  866.     push    h        ;save current-char address
  867.     push    b        ;save char count
  868.  
  869.     mov    a,m        ;get current char
  870.     inr    a        ;wrap around for "del" (127h)
  871.     jm    period+cbase        ;if > 127, change to "."
  872.     cpi    ' '+1        ;if < " ", change to "."
  873.     mov    a,m        ;(reget original char)
  874.     jp    charok+cbase        ;display char as is
  875. period    equ    $-cbase
  876.     mvi    a,'.'
  877. charok    equ    $-cbase
  878.     call    charout+cbase
  879.  
  880.     pop    b
  881.     pop    h
  882.     inx    h
  883.     dcr    b
  884.     jnz    daloop+cbase    ;do again if more chars left
  885.  
  886.     pop    h        ;restore start dump-address
  887.     ret
  888.  
  889. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  890. ;display hex character in ascii format
  891. disphex    equ    $-cbase
  892.     push    psw
  893.     rar
  894.     rar
  895.     rar
  896.     rar
  897.     call    dhex2+cbase
  898.     pop    psw
  899.  
  900. dhex2    equ    $-cbase
  901.     ani    0fh
  902.     cpi    10
  903.     jm    under10+cbase
  904.     adi    7
  905. under10    equ    $-cbase
  906.     adi    '0'
  907.     jmp    charout+cbase
  908.  
  909. *********************************************************
  910. *        display routines            *
  911. *********************************************************
  912.  
  913. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  914. ;skip to new line
  915. newline    equ    $-cbase
  916.     lxi    h,crlf+cbase
  917.     jmp    display+cbase
  918.  
  919. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  920. ;output blanks (number from b)
  921. blanks    equ    $-cbase
  922.     mvi    a,blank
  923. blanks2    equ    $-cbase
  924.     push    b
  925.     call    charout+cbase
  926.     pop    b
  927.     dcr    b
  928.     jnz    blanks2+cbase
  929.     ret
  930.  
  931. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  932. ;display string
  933. display    equ    $-cbase
  934.     mov    a,m
  935.     cpi    eom
  936.     rz
  937.  
  938.     push    h
  939.     call    charout+cbase
  940.     pop    h
  941.     inx    h
  942.     jmp    display+cbase
  943.  
  944.  
  945. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  946. ; display char on console
  947. charout    equ    $-cbase
  948.     push    psw
  949.     mvi    c,conout
  950.     mov    e,a
  951.     call    bdos
  952.     pop    psw
  953.     ret
  954.  
  955. *********************************************************
  956. *        end of relocatable routines        *
  957. *********************************************************
  958.  
  959. ;get length of relocatable routines
  960. length    equ    $-cbase
  961.  
  962. ;flip the copy1/copy2 toggle
  963. copy1    set    not copy1
  964.  
  965. ;link a second copy, if this was the first copy
  966.     if    not copy1
  967.     link    ddtf
  968.     endif
  969.