Subversion Repositories pentevo

Rev

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