?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ;Debugging routines. These are of two kinds:
  3. ;
  4. ; * Routines to assist in debugging the z-machine itself.
  5. ; * Diagnostic output should a z-program fail.
  6. ;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8. ;
  9. ;Code for debugging the Z-machine.
  10. ;
  11. ;This prints the text immediately following the CALL:
  12. ;
  13. ;       call ilprint
  14. ;       defb 'text'
  15. ;
  16. ilprint:
  17.         ex      (sp),hl ;HL -> inline parameter
  18.         push    af
  19.         push    bc
  20.         push    de
  21.         ld      d,h
  22.         ld      e,l
  23.         push    hl
  24.         ld      c,9
  25.         ld      a,(trace)
  26.         or      a
  27.         call    ZXFDOS
  28.         pop     hl
  29. ilpr1:  ld      a,(hl)
  30.         inc     hl
  31.         cp      '$'
  32.         jr      nz,ilpr1
  33.         pop     de
  34.         pop     bc
  35.         pop     af
  36.         ex      (sp),hl
  37.         ret
  38. ;
  39. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  40. ;
  41. ;This subroutine causes a border colour change and waits for a keypress.
  42. ;It is intended to provide a simple method of tracing where the program has
  43. ;got to.
  44. ;
  45. ;yes_i_live:
  46. ;
  47. ;<< v0.02 >> Spectrum-specific code moved to ZXIO.BIN as ZXILIV.
  48. ;
  49. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  50. ;
  51. ;Print a hex number in A/BC/DE/HL/IX, and wait for a keypress.
  52. ;
  53. hexa:   push    de
  54.         ld      d,0
  55.         ld      e,a
  56.         jr      hexd1
  57. ;
  58. hexix:  push    de
  59.         push    ix
  60.         pop     de
  61.         jr      hexd1
  62.  
  63. hexbc:  push    de
  64.         ld      d,b
  65.         ld      e,c
  66. hexd1:  call    hexde
  67.         pop     de
  68.         ret
  69. ;
  70. hexhl:  ex      de,hl
  71.         call    hexde
  72.         ex      de,hl
  73.         ret
  74. ;
  75. hexde:  push    af
  76.         push    bc
  77.         push    de
  78.         push    hl
  79.         ex      de,hl
  80.         ld      de,hbuf+4
  81.         push    de
  82.         call    sphex4
  83.         pop     de
  84.         ld      c,9
  85.         call    ZXFDOS
  86. popd:   pop     hl      ;<< v0.02 This code was in yes_i_live
  87.         pop     de      ;  but has been moved
  88.         pop     bc
  89.         pop     af
  90.         ret             ;>>
  91. ;
  92. showlcl:
  93.         push    af      ;<< v0.04 Show local variables
  94.         push    bc
  95.         push    de
  96.         push    hl
  97. showl0: push    ix
  98.         ld      b,6
  99. showl3: call    ilprint
  100.         defb    '  Locals $'
  101.         ld      hl,(zsp)
  102.         ld      de,4
  103.         add     hl,de
  104. ;
  105.  
  106. showl1: ld      e,(hl)
  107.         inc     hl
  108.         ld      d,(hl)
  109.         inc     hl
  110.  
  111.         call    hexde
  112.         call    ilprint
  113.         defb    ' $'
  114.         djnz    showl1
  115. showle: call    ilprint
  116.         defb    13,10,'$'
  117.         pop     ix
  118.         jr      popd
  119.  
  120. showpc: push    af
  121.         push    bc
  122.         push    de
  123.         push    hl
  124.         ld      a,(trace)
  125.         or      a
  126.         jr      z,popd
  127.  
  128. spc2:   ld      hl,(zpc)
  129.         ld      bc,(zpc+2)
  130.         ld      de,hbuf+2
  131.         push    de
  132.         call    sphex6
  133.         pop     de
  134.         ld      c,9
  135.         call    ZXFDOS
  136.  
  137.         jr      showl0  ;Show local variables
  138.  
  139.         ld      de,crlf
  140.         ld      c,9
  141.         call    ZXFDOS
  142. ;;      ld      c,1
  143. ;;      call    zxfdos
  144.         jr      popd
  145.  
  146. hbuf:   defb    '00000000$'
  147. crlf:   defb    13,10,'$'
  148. trace:  defb    0
  149. ;
  150. ifpc:   push    hl
  151.         ld      hl,(zpc)
  152.         and     a
  153.         sbc     hl,bc
  154.         jr      nz,ifpc0
  155.         ld      a,(zpc+2)
  156.         cp      d
  157. ifpc0:  pop     hl
  158.         ret
  159.  
  160. ;
  161. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  162. ;
  163. ; Routines for debugging Z-programs.
  164. ;
  165. ; This prints the Z-machine's stack (excluding the artificial 'entry' frame).
  166. ;
  167. showstk:
  168.         ld      de,strace       ;"Stack trace:"
  169.         ld      c,9
  170.         call    ZXFDOS
  171.         ld      ix,(zsp)        ;Bottom of stack
  172. shows1: call    dframe          ;Dump a frame
  173.         ld      de,38
  174.         add     ix,de           ;Reached the top yet?
  175.         push    ix
  176.         pop     hl
  177.         ld      de,(zstop)
  178.         and     a
  179.         sbc     hl,de
  180.         jr      nz,shows1
  181.         ld      de,strend       ;"[End of stack]"
  182.         ld      c,9
  183.         call    ZXFDOS
  184.         ret
  185. ;
  186. dframe: ld      de,sfr1         ;Dump a single stack frame
  187.         ld      l,(ix+0)
  188.         ld      h,(ix+1)
  189.         ld      c,(ix+2)
  190.         call    sphex6          ;PC
  191.         ld      de,sfr2
  192.         ld      a,(ix+34)
  193.         call    sphex2          ;CALL method
  194.         ld      de,sfr3
  195.         ld      l,(ix+36)
  196.         ld      h,(ix+37)
  197.         call    sphex4          ;Routine stack pointer
  198.         ld      de,sfr4
  199.         ld      a,(ix+35)
  200.         call    sphex2          ;No. of parameters
  201.         push    ix
  202.         ld      de,sframe
  203.         ld      c,9
  204.         call    ZXFDOS          ;Print stack frame line
  205.         pop     ix
  206.         ld      b,15
  207.         push    ix
  208. llp:    ld      de,lln
  209.         ld      l,(ix+4)
  210.         ld      h,(ix+5)
  211.         push    bc
  212.         push    ix
  213.         call    sphex4
  214.         ld      de,lln
  215.         ld      c,9
  216.         call    ZXFDOS
  217.         pop     ix
  218.         pop     bc
  219.         inc     ix
  220.         inc     ix
  221.         djnz    llp
  222.         ld      de,crlf_
  223.         ld      c,9
  224.         call    ZXFDOS
  225.         pop     ix
  226.         ret
  227. ;
  228. sframe: defb    'Caller PC='
  229. sfr1:   defb    '000000  Call type='
  230. sfr2:   defb    '00  Routine sp='
  231. sfr3:   defb    '0000  params '
  232. sfr4:   defb    '00'
  233.         defb    13,10,'$'
  234. lln:    defb    '0000$'
  235. strace: defb    'Z-machine stack trace:',13,10,'$'
  236. strend: defb    '[End of stack]'
  237. crlf_:  defb    13,10,'$'
  238. ;
  239. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  240. ;
  241. ;Illegal instruction error
  242. ;
  243. fail2:  pop     de              ;POP the stack twice first
  244. fail1:  pop     de              ;POP the stack once first
  245. fail:   ld      hl,(zipc)
  246.         ld      bc,(zipc+2)
  247.         ld      de,iistr1
  248.         call    sphex6          ;PC
  249.         ld      de,iistr
  250.         ld      a,(inst)
  251.         cp      0BEh            ;EXT:?
  252.         jr      nz,faila
  253.         call    sphex2
  254.         ld      a,(inst+1)
  255.         call    sphex2
  256.         ex      de,hl
  257.         ld      (hl),13
  258.         inc     hl
  259.         ld      (hl),10
  260.         inc     hl
  261.         ld      (hl),'$'
  262.         jr      failb
  263. ;
  264. faila:  call    sphex2          ;Opcode
  265. failb:  ld      de,iistr0
  266.         ld      c,9             ;Print message
  267.         call    ZXFDOS
  268.         ld      hl,iinst
  269.         xor     a
  270.         ret
  271. ;
  272. iinst:  defb    'A Illegal instructio'
  273.         defb    0EEh                    ;'n'+ 80h
  274. iistr0: defb    'Illegal instruction at PC='
  275. iistr1: defb    '000000 : opcode = '
  276. iistr:  defb    '00'
  277.         defb    13,10,36,0,0    ;The 2 zeroes allow the string to grow...
  278. ;
  279. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  280. ;
  281. ;Stack overflow error
  282. ;
  283. spfail2:
  284.         pop     de
  285. spfail1:
  286.         pop     de
  287. spfail: ld      hl,(zpc)
  288.         ld      bc,(zpc+2)
  289.         ld      de,sostr1
  290.         call    sphex6          ;PC
  291.         ld      a,(inst)
  292.         ld      de,sostr
  293.         call    sphex2          ;Opcode
  294.         ld      de,sostr0
  295.         ld      c,9             ;Print message
  296.         call    ZXFDOS
  297.         ld      hl,sover
  298.         xor     a
  299.         ret
  300. ;
  301. sover:  defb    '4 Out of stac'
  302.         defb    0EBh            ;'k'+80h
  303. sostr0: defb    'Illegal instruction at PC='
  304. sostr1: defb    '000000 : opcode = '
  305. sostr:  defb    '00'
  306.         defb    13,10,36
  307. ;
  308. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  309. ;
  310. proper2:
  311.         pop     hl
  312. proper1:
  313.         pop     hl
  314. properr:
  315.         push    de      ;Object no.
  316.         push    bc      ;Property no.
  317.         ld      hl,(zpc)
  318.         ld      bc,(zpc+2)
  319.         ld      de,pestr1
  320.         call    sphex6          ;PC
  321.         pop     bc
  322.         ld      a,c
  323.         ld      de,pestr3
  324.         call    sphex2
  325.         pop     hl
  326.         ld      de,pestr2
  327.         call    sphex4
  328.         ld      de,pestr
  329.         ld      c,9             ;Print message
  330.         call    ZXFDOS
  331.         ld      hl,perr
  332.         xor     a
  333.         ret
  334. ;
  335. perr:   defb    '2 Property not foun'
  336.         defb    0E4h            ;'d'+80h
  337. pestr:  defb    'Invalid property at PC='
  338. pestr1: defb    '000000 Object '
  339. pestr2: defb    '0000 property '
  340. pestr3: defb    '00',13,10,'$'
  341. ;
  342. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  343. ;
  344. ;Division by 0
  345. ;
  346. div0:   ld      hl,(zpc)
  347.         ld      bc,(zpc+2)
  348.         ld      de,d0str1
  349.         call    sphex6
  350.         ld      de,d0str
  351.         ld      c,9
  352.         call    ZXFDOS
  353.         ld      hl,d0err
  354.         xor     a
  355.         ret
  356. ;
  357. d0str:  defb    'Division by zero at PC='
  358. d0str1: defb    '000000',13,10,'$'
  359. d0err:  defb    '6 Division by zer'
  360.         defb    0EFh    ;'o'+80h
  361. ;
  362.