Subversion Repositories pentevo

Rev

Rev 796 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #include "std.h"
  2.  
  3. #include "emul.h"
  4. #include "vars.h"
  5. #include "debug.h"
  6. #include "dbgtrace.h"
  7. #include "dbglabls.h"
  8. #include "dbgpaint.h"
  9. #include "dbgcmd.h"
  10. #include "memory.h"
  11. #include "z80asm.h"
  12. #include "z80/op_system.h"
  13. #include "util.h"
  14.  
  15. int disasm_line(unsigned addr, char *line)
  16. {
  17.    Z80 &cpu = CpuMgr.Cpu();
  18.    unsigned char dbuf[16+129/*Alone Code 0.36.7*/];
  19.    ptrdiff_t i; //Alone Coder 0.36.7
  20.    for (/*int*/ i = 0; i < 16; i++) dbuf[i] = cpu.DirectRm(addr+unsigned(i));
  21.    sprintf(line, "%04X ", addr); int ptr = 5;
  22.    ptrdiff_t len = disasm(dbuf, addr, char(trace_labels)) - dbuf;
  23.    //8000 ..DDCB0106 rr (ix+1)
  24.    if (trace_labels)
  25.    {
  26.       char *lbl = mon_labels.find(am_r(addr));
  27. //      if (lbl) for (int k = 0; k < 10 && lbl[k]; line[ptr++] = lbl[k++]); //Alone Coder
  28.       if (lbl) for (int k = 0; (k < 10) && lbl[k]; )line[ptr++] = lbl[k++]; //Alone Coder
  29.    }
  30.    else
  31.    {
  32.       ptrdiff_t len1 = len;
  33.       if(len > 4)
  34.       {
  35.           len1 = 4;
  36.           *(short*)(line + ptr) = WORD2('.', '.');
  37.           ptr += 2;
  38.       }
  39.       for(i = len - len1; i < len; i++)
  40.       {
  41.           sprintf(line + ptr, "%02X", dbuf[i]);
  42.           ptr += 2;
  43.       }
  44.    }
  45.  
  46.    while (ptr < 16) line[ptr++] = ' ';
  47.    strcpy(line+ptr, asmbuf);
  48.    return int(len);
  49. }
  50.  
  51. #define TWF_BRANCH  0x010000U
  52. #define TWF_BRADDR  0x020000U
  53. #define TWF_LOOPCMD 0x040000U
  54. #define TWF_CALLCMD 0x080000U
  55. #define TWF_BLKCMD  0x100000U
  56. #define TWF_HALTCMD 0x200000U
  57. // ╠ырф°шх 16сшЄ - рфЁхё z80
  58. // ёЄрЁ°шх 16сшЄ - Їыруш TWF_xxxx
  59. static unsigned tracewndflags()
  60. {
  61.    Z80 &cpu = CpuMgr.Cpu();
  62.    unsigned readptr = cpu.pc, base = cpu.hl;
  63.    unsigned char opcode = 0; unsigned char ed = 0;
  64.    for (;;)
  65.    {
  66.       opcode = cpu.DirectRm(readptr++);
  67.       if (opcode == 0xDD)
  68.           base = cpu.ix;
  69.       else if (opcode == 0xFD)
  70.           base = cpu.iy;
  71.       else if (opcode == 0xED)
  72.           ed = 1;
  73.       else
  74.           break;
  75.    }
  76.  
  77.    unsigned fl = 0;
  78.    if(opcode == 0x76) // halt
  79.    {
  80.        u32 addr;
  81.        if(cpu.im < 2)
  82.        {
  83.            addr = 0x38;
  84.        }
  85.        else // im2
  86.        {
  87.            unsigned vec = unsigned(cpu.i << 8U) | cpu.IntVec();
  88.            addr = u32((cpu.DirectRm(vec+1) << 8U) | cpu.DirectRm(vec));
  89.        }
  90.        return TWF_HALTCMD | addr;
  91.    }
  92.  
  93.    if (ed)
  94.    {
  95.       if((opcode & 0xF4) == 0xB0) // ldir/lddr | cpir/cpdr | inir/indr | otir/otdr
  96.           return TWF_BLKCMD;
  97.  
  98.       if ((opcode & 0xC7) != 0x45)
  99.           return 0; // reti/retn
  100.  
  101.  ret:
  102.       return (cpu.DirectRm(cpu.sp) | unsigned(cpu.DirectRm(cpu.sp+1) << 8U)) | TWF_BRANCH | TWF_BRADDR;
  103.    }
  104.  
  105.    if (opcode == 0xC9) // ret
  106.        goto ret;
  107.    if (opcode == 0xC3) // jp
  108.    {
  109.        jp: return (cpu.DirectRm(readptr) | unsigned(cpu.DirectRm(readptr+1) << 8U)) | TWF_BRANCH | fl;
  110.    }
  111.    if (opcode == 0xCD) // call
  112.    {
  113.        fl = TWF_CALLCMD;
  114.        goto jp;
  115.    }
  116.  
  117.    static const unsigned char flags[] = { ZF,CF,PV,SF };
  118.  
  119.    if ((opcode & 0xC1) == 0xC0)
  120.    {
  121.       unsigned char flag = flags[(opcode >> 4) & 3];
  122.       unsigned char res = cpu.f & flag;
  123.       if (!(opcode & 0x08))
  124.           res ^= flag;
  125.       if (!res)
  126.           return 0;
  127.       if ((opcode & 0xC7) == 0xC0) // ret cc
  128.           goto ret;
  129.       if ((opcode & 0xC7) == 0xC4) // call cc
  130.       {
  131.           fl = TWF_CALLCMD;
  132.           goto jp;
  133.       }
  134.       if ((opcode & 0xC7) == 0xC2) // jp cc
  135.       {
  136.           fl = TWF_LOOPCMD;
  137.           goto jp;
  138.       }
  139.    }
  140.  
  141.    if (opcode == 0xE9)
  142.        return base | TWF_BRANCH | TWF_BRADDR; // jp (hl/ix/iy)
  143.  
  144.    if ((opcode & 0xC7) == 0xC7)
  145.        return (opcode & 0x38) | TWF_CALLCMD | TWF_BRANCH; // rst #xx
  146.  
  147.    if ((opcode & 0xC7) == 0x00)
  148.    {
  149.       if (!opcode || opcode == 0x08)
  150.           return 0;
  151.       int offs = (signed char)cpu.DirectRm(readptr++);
  152.       unsigned addr = unsigned(offs + int(readptr)) | TWF_BRANCH;
  153.       if (opcode == 0x18)
  154.           return addr; // jr
  155.       if (opcode == 0x10)
  156.           return (cpu.b==1)? 0 : addr | TWF_LOOPCMD; // djnz
  157.  
  158.       unsigned char flag = flags[(opcode >> 4) & 1]; // jr cc
  159.       unsigned char res = cpu.f & flag;
  160.       if (!(opcode & 0x08))
  161.           res ^= flag;
  162.       return res? addr | TWF_LOOPCMD : 0;
  163.    }
  164.    return 0;
  165. }
  166.  
  167. static unsigned trcurs_y;
  168. unsigned asmii;
  169. static char asmpc[64], dumppc[12];
  170. const unsigned cs[3][2] = { {0,4}, {5,10}, {16,16} };
  171.  
  172. void showtrace()
  173. {
  174.    Z80 &cpu = CpuMgr.Cpu();
  175. //   char line[40]; //Alone Coder 0.36.7
  176.    char line[16+129]; //Alone Coder 0.36.7
  177.  
  178.    cpu.trace_curs &= 0xFFFF;
  179.    cpu.trace_top &= 0xFFFF;
  180.    cpu.pc &= 0xFFFF;
  181.    cpu.trace_mode = (cpu.trace_mode+3) % 3;
  182.  
  183.    cpu.pc_trflags = tracewndflags();
  184.    cpu.nextpc = (cpu.pc_trflags & TWF_HALTCMD) ? (cpu.pc_trflags & 0xFFFF): ((cpu.pc + unsigned(disasm_line(cpu.pc, line))) & 0xFFFF);
  185.    unsigned pc = cpu.trace_top;
  186.    asmii = -1U;
  187.    unsigned char atr0 = (activedbg == WNDTRACE) ? W_SEL : W_NORM;
  188.    unsigned ii; //Alone Coder 0.36.7
  189.    for (/*unsigned*/ ii = 0; ii < trace_size; ii++)
  190.    {
  191.       pc &= 0xFFFF; cpu.trpc[ii] = pc;
  192.       int len = disasm_line(pc, line);
  193.       char *ptr = line+strlen(line);
  194.       while (ptr < line+32) *ptr++ = ' '; line[32] = 0;
  195.  
  196.       unsigned char atr = (pc == cpu.pc)? W_TRACEPOS : atr0;
  197.       if (cpu.membits[pc] & MEMBITS_BPX) atr = (atr&~7)|2;
  198.       tprint(trace_x, trace_y+ii, line, atr);
  199.  
  200.       if (pc == cpu.trace_curs)
  201.       {
  202.          asmii = ii;
  203.          if (activedbg == WNDTRACE)
  204.             for (unsigned q = 0; q < cs[cpu.trace_mode][1]; q++)
  205.                txtscr[80*30 + (trace_y+ii)*80 + trace_x + cs[cpu.trace_mode][0] + q] = W_CURS;
  206.       }
  207.  
  208.       if (cpu.pc_trflags & TWF_BRANCH)
  209.       {
  210.          if (pc == cpu.pc)
  211.          {
  212.             unsigned addr = cpu.pc_trflags & 0xFFFF;
  213.             unsigned arr = (addr <= cpu.pc)? 0x18 : 0x19; // up/down arrow
  214.             unsigned char color = (pc == cpu.trace_curs && activedbg == WNDTRACE && cpu.trace_mode == 2)? W_TRACE_JINFO_CURS_FG : W_TRACE_JINFO_NOCURS_FG;
  215.             if(cpu.pc_trflags & TWF_BRADDR)
  216.             {
  217.                 sprintf(line, "%04X%c", addr, int(arr));
  218.                 tprint_fg(trace_x + 32 - 5, trace_y + ii, line, color);
  219.             }
  220.             else tprint_fg(trace_x+32-1, trace_y+ii, (char*)&arr, color);
  221.          }
  222.  
  223.          if (pc == (cpu.pc_trflags & 0xFFFF))
  224.          {
  225.             unsigned arr = 0x11; // left arrow
  226.             tprint_fg(trace_x+32-1, trace_y+ii, (char*)&arr, W_TRACE_JARROW_FOREGR);
  227.          }
  228.       }
  229.  
  230.       pc += unsigned(len);
  231.    }
  232.    cpu.trpc[ii] = pc;
  233.  
  234.    unsigned char dbuf[16];
  235.    unsigned i; //Alone Coder
  236.    for (/*int*/ i = 0; i < 16; i++) dbuf[i] = cpu.DirectRm(cpu.trace_curs+i);
  237.    ptrdiff_t len = disasm(dbuf, cpu.trace_curs, 0) - dbuf; strcpy(asmpc, asmbuf);
  238.    for (/*int*/ i = 0; i < len && i < 5; i++)
  239.       sprintf(dumppc + i*2, "%02X", cpu.DirectRm(cpu.trace_curs+i));
  240.  
  241.    char cpu_num[10];
  242.    _snprintf(cpu_num, sizeof(cpu_num), "Z80(%u)", CpuMgr.GetCurrentCpu());
  243.    tprint(trace_x, trace_y-1, cpu_num, W_TITLE);
  244.  
  245.    char lbr[5];
  246.    _snprintf(lbr, sizeof(lbr), "%04hX", cpu.last_branch);
  247.    tprint(trace_x+8, trace_y-1, lbr,  W_TITLE);
  248.    frame(trace_x,trace_y,32,trace_size,FRAME);
  249. }
  250.  
  251. void c_lbl_import()
  252. {
  253.    mon_labels.import_menu();
  254. }
  255.  
  256.       /* ------------------------------------------------------------- */
  257. static unsigned save_pos[8] = { -1U,-1U,-1U,-1U,-1U,-1U,-1U,-1U };
  258. static unsigned save_cur[8] = { -1U,-1U,-1U,-1U,-1U,-1U,-1U,-1U };
  259. static unsigned stack_pos[32] = { -1U }, stack_cur[32] = { -1U };
  260.  
  261. void push_pos();
  262.  
  263. void push_pos()
  264. {
  265.    Z80 &cpu = CpuMgr.Cpu();
  266.    memmove(&stack_pos[1], &stack_pos[0], sizeof stack_pos - sizeof *stack_pos);
  267.    memmove(&stack_cur[1], &stack_cur[0], sizeof stack_cur - sizeof *stack_cur);
  268.    stack_pos[0] = cpu.trace_top; stack_cur[0] = cpu.trace_curs;
  269. }
  270.  
  271. static unsigned cpu_up(unsigned ip)
  272. {
  273.    Z80 &cpu = CpuMgr.Cpu();
  274.    unsigned char buf1[0x10];
  275.    unsigned p1 = (ip > sizeof buf1) ? ip - sizeof buf1 : 0;
  276.    for (unsigned i = 0; i < sizeof buf1; i++) buf1[i] = cpu.DirectRm(p1+i);
  277.    const unsigned char *dispos = buf1, *prev;
  278.    do {
  279.       prev = dispos;
  280.       dispos = disasm(dispos, 0, 0);
  281.    } while ((unsigned)(dispos-buf1+p1) < ip);
  282.    return unsigned(prev-buf1+p1);
  283. }
  284.  
  285. void cgoto()
  286. {
  287.    Z80 &cpu = CpuMgr.Cpu();
  288.    int v = input4(trace_x, trace_y, cpu.trace_top);
  289.    if (v != -1)
  290.        cpu.trace_top = cpu.trace_curs = unsigned(v);
  291. }
  292.  
  293. void csetpc()
  294. {
  295.     Z80 &cpu = CpuMgr.Cpu();
  296.     cpu.pc = cpu.trace_curs;
  297. }
  298.  
  299. void center()
  300. {
  301.    Z80 &cpu = CpuMgr.Cpu();
  302.    if (!cpu.trace_mode)
  303.        sprintf(str, "%04X", cpu.trace_curs);
  304.    else if (cpu.trace_mode == 1)
  305.        strcpy(str, dumppc);
  306.    else
  307.        strcpy(str, asmpc);
  308.  
  309.    if (input.lastkey != VK_RETURN)
  310.    {
  311.        *str = 0;
  312.         PostThreadMessage(GetCurrentThreadId(), WM_KEYDOWN, input.lastkey, 1);
  313.    }
  314.  
  315.    for (;;)
  316.    {
  317.       if (!inputhex(trace_x+cs[cpu.trace_mode][0], trace_y + trcurs_y + asmii, cs[cpu.trace_mode][1], cpu.trace_mode < 2))
  318.           break;
  319.       if (!cpu.trace_mode)
  320.       {
  321.          push_pos();
  322.          sscanf(str, "%X", &cpu.trace_top);
  323.          cpu.trace_curs = cpu.trace_top;
  324.          for (unsigned i = 0; i < asmii; i++)
  325.              cpu.trace_top = cpu_up(cpu.trace_top);
  326.          break;
  327.       }
  328.       else if (cpu.trace_mode == 1)
  329.       {
  330.          char *p; //Alone Coder 0.36.7
  331.          for (/*char * */p = str+strlen(str)-1; p >= str && *p == ' '; *p-- = 0);
  332.          unsigned char dump[8]; unsigned i;
  333.          for (p = str, i = 0; ishex(*p) && ishex(p[1]); p+=2)
  334.             dump[i++] = hex(p);
  335.          if (*p) continue;
  336.          for (unsigned j = 0; j < i; j++)
  337.             cpu.DirectWm(cpu.trace_curs+j, dump[j]);
  338.          break;
  339.       }
  340.       else
  341.       {
  342.          unsigned sz = assemble_cmd((unsigned char*)str, cpu.trace_curs);
  343.          if (sz)
  344.          {
  345.             for (unsigned i = 0; i < sz; i++)
  346.                 cpu.DirectWm(cpu.trace_curs+i, asmresult[i]);
  347.             showtrace();
  348.             void cdown();
  349.             cdown();
  350.             break;
  351.          }
  352.       }
  353.    }
  354. }
  355.  
  356. char dispatch_trace()
  357. {
  358.    if (input.lastkey >= 'A' && input.lastkey < 'Z')
  359.    {
  360.        center();
  361.        return 1;
  362.    }
  363.    return 0;
  364. }
  365.  
  366. void cfindtext()
  367. {
  368.    Z80 &cpu = CpuMgr.Cpu();
  369.    unsigned char oldmode = editor; editor = ED_MEM;
  370.    int rs = find1dlg(cpu.trace_curs);
  371.    editor = oldmode;
  372.    if (rs != -1)
  373.        cpu.trace_top = cpu.trace_curs = unsigned(rs);
  374. }
  375. void cfindcode()
  376. {
  377.    Z80 &cpu = CpuMgr.Cpu();
  378.    unsigned char oldmode = editor; editor = ED_MEM;
  379.    int rs = find2dlg(cpu.trace_curs);
  380.    editor = oldmode;
  381.    if (rs != -1)
  382.        cpu.trace_top = cpu.trace_curs = unsigned(rs);
  383. }
  384.  
  385. void cbpx()
  386. {
  387.    Z80 &cpu = CpuMgr.Cpu();
  388.    cpu.membits[cpu.trace_curs] ^= MEMBITS_BPX;
  389. }
  390.  
  391. void cfindpc()
  392. {
  393.     Z80 &cpu = CpuMgr.Cpu();
  394.     cpu.trace_top = cpu.trace_curs = cpu.pc;
  395. }
  396.  
  397. void cup()
  398. {
  399.    Z80 &cpu = CpuMgr.Cpu();
  400.    if (cpu.trace_curs > cpu.trace_top)
  401.    {
  402.       for (unsigned i = 1; i < trace_size; i++)
  403.          if (cpu.trpc[i] == cpu.trace_curs)
  404.              cpu.trace_curs = cpu.trpc[i-1];
  405.    }
  406.    else
  407.        cpu.trace_top = cpu.trace_curs = cpu_up(cpu.trace_curs);
  408. }
  409.  
  410. void cdown()
  411. {
  412.    Z80 &cpu = CpuMgr.Cpu();
  413.    for (unsigned i = 0; i < trace_size; i++)
  414.       if (cpu.trpc[i] == cpu.trace_curs)
  415.       {
  416.          cpu.trace_curs = cpu.trpc[i+1];
  417.          if (i+1 == trace_size)
  418.              cpu.trace_top = cpu.trpc[1];
  419.          break;
  420.       }
  421. }
  422. void cleft()  { CpuMgr.Cpu().trace_mode--; }
  423. void cright() { CpuMgr.Cpu().trace_mode++; }
  424. void chere()
  425. {
  426.     Z80 &cpu = CpuMgr.Cpu();
  427.     cpu.dbgbreak = 0;
  428.     dbgbreak = 0;
  429.     cpu.dbgchk = 1;
  430.  
  431.     cpu.dbg_stophere = cpu.trace_curs;
  432. }
  433.  
  434. void cpgdn()
  435. {
  436.    Z80 &cpu = CpuMgr.Cpu();
  437.    unsigned curs = 0;
  438.    for (unsigned i = 0; i < trace_size; i++)
  439.       if (cpu.trace_curs == cpu.trpc[i]) curs = i;
  440.    cpu.trace_top = cpu.trpc[trace_size];
  441.    showtrace();
  442.    cpu.trace_curs = cpu.trpc[curs];
  443. }
  444.  
  445. void cpgup()
  446. {
  447.    Z80 &cpu = CpuMgr.Cpu();
  448.    unsigned curs = 0;
  449.    unsigned i; //Alone Coder 0.36.7
  450.    for (/*unsigned*/ i = 0; i < trace_size; i++)
  451.       if (cpu.trace_curs == cpu.trpc[i]) curs = i;
  452.    for (i = 0; i < trace_size; i++)
  453.        cpu.trace_top = cpu_up(cpu.trace_top);
  454.    showtrace();
  455.    cpu.trace_curs = cpu.trpc[curs];
  456. }
  457.  
  458. void pop_pos()
  459. {
  460.    Z80 &cpu = CpuMgr.Cpu();
  461.    if (stack_pos[0] == -1U)
  462.        return;
  463.    cpu.trace_curs = stack_cur[0];
  464.    cpu.trace_top = stack_pos[0];
  465.    memcpy(&stack_pos[0], &stack_pos[1], sizeof stack_pos - sizeof *stack_pos);
  466.    memcpy(&stack_cur[0], &stack_cur[1], sizeof stack_cur - sizeof *stack_cur);
  467.    stack_pos[(sizeof stack_pos / sizeof *stack_pos)-1] = -1U;
  468. }
  469.  
  470. void cjump()
  471. {
  472.    Z80 &cpu = CpuMgr.Cpu();
  473.    char *ptr = nullptr;
  474.    for (char *p = asmpc; *p; p++)
  475.       if (ishex(p[0]) & ishex(p[1]) & ishex(p[2]) & ishex(p[3])) ptr = p;
  476.    if (!ptr) return;
  477.    push_pos();
  478.    unsigned addr;
  479.    sscanf(ptr, "%04X", &addr);
  480.    cpu.trace_curs = cpu.trace_top = addr;
  481. }
  482.  
  483. void cdjump()
  484. {
  485.    char *ptr = nullptr;
  486.    for (char *p = asmpc; *p; p++)
  487.       if (ishex(p[0]) & ishex(p[1]) & ishex(p[2]) & ishex(p[3])) ptr = p;
  488.    if (!ptr) return;
  489.    unsigned addr; sscanf(ptr, "%04X", &addr);
  490.    Z80 &cpu = CpuMgr.Cpu();
  491.    cpu.mem_curs = addr; activedbg = WNDMEM; editor = ED_MEM;
  492. }
  493.  
  494. void cfliplabels()
  495. {
  496.    trace_labels = !trace_labels; showtrace();
  497. }
  498. static void csave(unsigned n)
  499. {
  500.    Z80 &cpu = CpuMgr.Cpu();
  501.    save_pos[n] = cpu.trace_top;
  502.    save_cur[n] = cpu.trace_curs;
  503. }
  504. static void crest(unsigned n)
  505. {
  506.    Z80 &cpu = CpuMgr.Cpu();
  507.    if (save_pos[n] == -1U)
  508.        return;
  509.    push_pos();
  510.    cpu.trace_top = save_pos[n];
  511.    cpu.trace_curs = save_cur[n];
  512. }
  513. void csave1() { csave(0); }
  514. void csave2() { csave(1); }
  515. void csave3() { csave(2); }
  516. void csave4() { csave(3); }
  517. void csave5() { csave(4); }
  518. void csave6() { csave(5); }
  519. void csave7() { csave(6); }
  520. void csave8() { csave(7); }
  521. void crest1() { crest(0); }
  522. void crest2() { crest(1); }
  523. void crest3() { crest(2); }
  524. void crest4() { crest(3); }
  525. void crest5() { crest(4); }
  526. void crest6() { crest(5); }
  527. void crest7() { crest(6); }
  528. void crest8() { crest(7); }
  529.  
  530. namespace z80dbg
  531. {
  532. void __cdecl SetLastT()
  533. {
  534.    cpu.debug_last_t = comp.t_states + cpu.t;
  535. }
  536. }
  537.  
  538. void mon_step()
  539. {
  540.    Z80 &cpu = CpuMgr.Cpu();
  541.    TZ80State &prevcpu = CpuMgr.PrevCpu();
  542.    
  543.    cpu.SetLastT();
  544.    prevcpu = cpu;
  545. //   CpuMgr.CopyToPrev();
  546.    if(cpu.t >= conf.intlen)
  547.        cpu.int_pend = false;
  548.    cpu.Step();
  549.    if (cpu.int_pend && cpu.iff1 && cpu.t != cpu.eipos && // int enabled in CPU not issued after EI
  550.        cpu.int_gate) // int enabled by ATM hardware
  551.    {
  552.       handle_int(&cpu, cpu.IntVec());
  553.    }
  554.  
  555.    cpu.CheckNextFrame();
  556.    cpu.trace_curs = cpu.pc;
  557. }
  558.  
  559. void mon_stepover()
  560. {
  561.    Z80 &cpu = CpuMgr.Cpu();
  562.    unsigned char trace = 1;
  563.  
  564.    // call,rst
  565.    if (cpu.pc_trflags & TWF_CALLCMD)
  566.    {
  567.        cpu.dbg_stopsp = cpu.sp & 0xFFFF;
  568.        cpu.dbg_stophere = cpu.nextpc;
  569.        trace = 0;
  570.    }
  571.    else if (cpu.pc_trflags & (TWF_BLKCMD | TWF_HALTCMD)) // ldir/lddr|cpir/cpdr|otir/otdr|inir/indr|halt
  572.    {
  573.        trace = 0;
  574.        cpu.dbg_stophere = cpu.nextpc;
  575.    }
  576.  
  577. /* [vv]
  578.    // jr cc,$-xx, jp cc,$-xx
  579.    else if ((cpu.pc_trflags & TWF_LOOPCMD) && (cpu.pc_trflags & 0xFFFF) < (cpu.pc & 0xFFFF))
  580.    {
  581.       cpu.dbg_stopsp = cpu.sp & 0xFFFF;
  582.       cpu.dbg_stophere = cpu.nextpc,
  583.       cpu.dbg_loop_r1 = cpu.pc_trflags & 0xFFFF;
  584.       cpu.dbg_loop_r2 = cpu.pc & 0xFFFF;
  585.       trace = 0;
  586.    }
  587. */
  588.  
  589. /* [vv]
  590.    else if (cpu.pc_trflags & TWF_BRANCH)
  591.        trace = 1;
  592.    else
  593.    {
  594.        trace = 1;
  595.        cpu.dbg_stophere = cpu.nextpc;
  596.    }
  597. */
  598.  
  599.    if (trace)
  600.    {
  601.        mon_step();
  602.    }
  603.    else
  604.    {
  605.        cpu.dbgbreak = 0;
  606.        dbgbreak = 0;
  607.        cpu.dbgchk = 1;
  608.    }
  609. }
  610.