home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / debug / back2ddt.asm < prev    next >
Encoding:
Assembly Source File  |  1994-07-13  |  5.6 KB  |  251 lines

  1. *    back2ddt.asm    Version 1    September 5, 1981
  2. *
  3. *    Enables exiting from DDT via "G18" and returning via control-B.
  4. *
  5. *    (C) 1981 by Roy Lipscomb, Logic Associates, Chicago
  6. *    Copying for non-profit distribution is permitted.
  7. *
  8. *
  9. ***********************************************************************
  10. *
  11. *    This module is useful when debugging a program for which you
  12. *    have a .PRN file on disk.  You can exit from DDT; display the
  13. *    .PRN listing; then return to DDT and the program being tested.
  14. *
  15. *    Notes:
  16. *
  17. *    1)  As supplied, BACK2DDT uses restart locations 3-6 (18h-37h).
  18. *
  19. *    2)  The CCP must be protected from being overlaid.  (This
  20. *    requirement is met if DDT is loaded via DDTX, a public-
  21. *    domain program by Ken Barbier available on many RCPM
  22. *    systems.)
  23. *
  24. *    3)  The program being debugged will be preserved during
  25. *    CCP resident commands--ERA, DIR, TYPE, REN, or SAVE.  Any
  26. *    other (transient) commands will overlay the program.
  27. *
  28. *    4)  The CCP resets the dma to 80h, and alters 80h-ffh. Thus,
  29. *
  30. *        a)  Be sure you have nothing critical in this area
  31. *        (such as the program stack) when exiting with "G18".
  32. *
  33. *        b)  If your program uses a different dma, be sure to
  34. *        reset the dma after typing control-B.
  35. *
  36. *    5)  Registers A, PSW, and PC are not restored by control-B.
  37. *
  38. ********************************************************************
  39.  
  40.     org     100h
  41.     jmp    begin
  42.  
  43. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  44. ;        initial variables            ;
  45. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  46.  
  47. ; change trap char, if so desired
  48. trapchr    equ    2        ;control-b means "back to ddt"
  49.  
  50.  
  51. ;do not change these
  52. trubase    equ    18h        ;actual load point of trap
  53. bdos    equ    5
  54. cindisp    equ    10        ;displacement of conin addr in jmptable
  55. display    equ    2
  56.  
  57. cr    equ    13
  58. lf    equ    10
  59.  
  60. poph    equ    0e1h        ;one of the test instructions
  61.  
  62.  
  63.  
  64. ; "done" message
  65. eom    equ    '$'
  66.  
  67. done    db    cr,lf,'Back2ddt   version 1, Sept 81'
  68.     db    cr,lf
  69.     db    cr,lf,'After protecting the CCP and loading DDT,'
  70.     db    cr,lf,'exit DDT via "G18" and return via control-B.'
  71.     db    cr,lf,eom
  72.  
  73. notdone    db    cr,lf,'Back2ddt already loaded:  no action',cr,lf,eom
  74.  
  75.  
  76. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  77. ;        mainline                ;
  78. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  79.  
  80. begin    push    h
  81.     push    d
  82.     push    b
  83.  
  84. ;test if already loaded
  85.     call    testit
  86.     jz    return        ;yes, already loaded
  87.  
  88. ;move module into place
  89. loadit    lxi    h,module
  90.     lxi    d,trubase
  91.     lxi    b,length
  92.     call    move
  93.  
  94. ;divert cp/m jmp-addresses to trap
  95.     call    patchit    
  96.  
  97. ;exit to cpm
  98. return    pop    b
  99.     pop    d
  100.     pop    h
  101.     ret
  102.  
  103. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  104. ;        patch bios to trap conin        ;
  105. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  106.  
  107. ;address conin entry in bios jump-table
  108. patchit    lhld    1
  109.     mvi    l,cindisp        ;insert offset for conin
  110.  
  111. ;remove true conin jmp-address
  112.     mov    e,m
  113.     inx    h
  114.     mov    d,m
  115.  
  116. ;insert trap address into jmp table
  117.     lxi    b,trpentr-adjust
  118.     mov    m,b
  119.     dcx    h
  120.     mov    m,c
  121.  
  122. ;insert true conin address into trap
  123.     xchg
  124.     shld    trpentr-adjust+1
  125.  
  126. ;print "done" message
  127.     lxi    h,done
  128.     call    message
  129.  
  130.     ret
  131.  
  132. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  133. ;        test if already loaded            ;
  134. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  135.  
  136. ;test if bios jump table already points to trap
  137.  
  138. ;address conin table entry
  139. testit    lhld    1
  140.     mvi    l,cindisp
  141.     mov    c,m
  142.     inx    h
  143.     mov    b,m
  144.  
  145. ;compare jump-table entry with trap entry
  146.     lxi    d,trpentr-adjust
  147.  
  148.     mov    a,c
  149.     sub    e
  150.  
  151.     mov    a,b
  152.     sbb    d
  153.  
  154.     rnz        ;if not equal, assume not already loaded
  155.  
  156. ;already loaded, so output message
  157.     lxi    h,notdone
  158.     call    message
  159.  
  160. ;turn on zero flag
  161.     xra    a
  162.  
  163.     ret
  164.  
  165.  
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167. ;        move block of data            ;
  168. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  169.  
  170. ;source in hl, destination in de, length in bc.
  171.  
  172. move    mov    a,b
  173.     ora    c
  174.     rz
  175.     mov    a,m
  176.     stax    d
  177.     inx    d
  178.     inx    h
  179.     dcx    b
  180.     jmp    move
  181.  
  182. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  183. ;        print signoff mess            ;
  184. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  185. message    mov    a,m
  186.     inx    h
  187.     cpi    eom
  188.     rz        ;return if message completed
  189.  
  190.     mov    e,a
  191.     mvi    c,display
  192.     push    h
  193.     call    bdos
  194.     pop    h
  195.     jmp    message
  196.  
  197.  
  198. *********************************************************
  199. *********************************************************
  200. *        conin-trap module            *
  201. *********************************************************
  202. *********************************************************
  203.  
  204.  
  205. module    equ    $
  206. adjust    equ    module-trubase        ;fudge factor, to compute
  207.                     ;true address
  208.  
  209.  
  210. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  211. ; exit from ddt (save important values)  (takes 15 bytes)
  212. ddtexit    push    b        ;save registers
  213.     push    d
  214.     push    h
  215.  
  216.     lhld    6        ;save ddt trap address
  217.     push    h
  218.  
  219.     lxi    h,0        ;save stack pointer
  220.     dad    sp
  221.     shld    stksav-adjust
  222.  
  223.     rst    0        ;reboot
  224.  
  225. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  226. ; if trapchr found, jmp to ddt; else return (takes 17 bytes)
  227.  
  228. trpentr    call    0        ;perform conin (0 changed at run time)
  229.     cpi    trapchr        ;go to ddt?
  230.     rnz            ;no, back to CCP
  231.  
  232.     lxi    sp,0        ;restore stack address
  233. stksav    equ    $-2        ;(filled at ddt-exit time)
  234.  
  235. ;next two instructions are used to test for already-loaded module
  236. testlod    pop    h        ;restore ddt trap address
  237.     shld    6
  238.  
  239.     pop    h        ;restore registers
  240.     pop    d
  241.     pop    b
  242.  
  243. ;must use actual RST 7 instruction, to preserve stack pointer.
  244.     rst    7
  245.  
  246. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  247. ;get length of relocatable routines
  248. length    equ    $-module    ;must equal 38h, in orig version.
  249.  
  250.     end
  251.