Subversion Repositories pentevo

Rev

Rev 1134 | 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 "draw.h"
  6. #include "dx.h"
  7. #include "debug.h"
  8. #include "dbgpaint.h"
  9. #include "dbgreg.h"
  10. #include "dbgtrace.h"
  11. #include "dbgmem.h"
  12. #include "dbgoth.h"
  13. #include "dbglabls.h"
  14. #include "dbgbpx.h"
  15.  
  16. #include "util.h"
  17.  
  18. #ifdef MOD_MONITOR
  19.  
  20. unsigned char trace_labels;
  21.  
  22. unsigned bkpts_ena;
  23. unsigned user_mon_req = 0;
  24.  
  25. unsigned show_scrshot;
  26. unsigned user_watches[3] = { 0x4000, 0x8000, 0xC000 };
  27.  
  28. unsigned mem_sz = 8;
  29. unsigned mem_disk, mem_track, mem_max;
  30. unsigned char mem_ascii;
  31. unsigned char mem_dump;
  32. unsigned char editor = ED_MEM;
  33.  
  34. unsigned regs_curs;
  35. unsigned dbg_extport;
  36. unsigned char dbg_extval; // extended memory port like 1FFD or DFFD
  37.  
  38. unsigned ripper; // ripper mode (none/read/write)
  39.  
  40. DBGWND activedbg = WNDTRACE;
  41.  
  42. void debugscr();
  43. unsigned find1dlg(unsigned start);
  44. unsigned find2dlg(unsigned start);
  45.  
  46. /*
  47. #include "dbgpaint.cpp"
  48. #include "dbglabls.cpp"
  49. #include "z80asm.cpp"
  50. #include "dbgreg.cpp"
  51. #include "dbgmem.cpp"
  52. #include "dbgtrace.cpp"
  53. #include "dbgrwdlg.cpp"
  54. #include "dbgcmd.cpp"
  55. #include "dbgbpx.cpp"
  56. #include "dbgoth.cpp"
  57. */
  58.  
  59. void debugscr()
  60. {
  61.    memset(txtscr, BACKGR_CH, sizeof txtscr/2);
  62.    memset(txtscr+sizeof txtscr/2, BACKGR, sizeof txtscr/2);
  63.    nfr = 0;
  64.  
  65.    showregs();
  66.    showtrace();
  67.    showmem();
  68.    showwatch();
  69.    showstack();
  70.    show_ay();
  71.    showbanks();
  72.    showports();
  73.    showdos();
  74.  
  75. #if 1
  76.    show_time();
  77. #else
  78.    tprint(copy_x, copy_y, "\x1A", 0x9C);
  79.    tprint(copy_x+1, copy_y, "UnrealSpeccy " VERS_STRING, 0x9E);
  80.    tprint(copy_x+20, copy_y, "by SMT", 0x9D);
  81.    tprint(copy_x+26, copy_y, "\x1B", 0x9C);
  82.    frame(copy_x, copy_y, 27, 1, 0x0A);
  83. #endif
  84. }
  85.  
  86. static void handle_mouse()
  87. {
  88.     Z80 &cpu = CpuMgr.Cpu();
  89.     unsigned mx = ((mousepos & 0xFFFF) - temp.gx) / 8,
  90.         my = (((mousepos >> 16) & 0x7FFF) - temp.gy) / 16;
  91.     if(my >= trace_y && my < trace_y + trace_size && mx >= trace_x && mx < trace_x + 32)
  92.     {
  93.         needclr++; activedbg = WNDTRACE;
  94.         cpu.trace_curs = cpu.trpc[my - trace_y];
  95.         if(mx - trace_x < cs[1][0]) cpu.trace_mode = 0;
  96.         else if(mx - trace_x < cs[2][0]) cpu.trace_mode = 1;
  97.         else cpu.trace_mode = 2;
  98.     }
  99.     if(my >= mem_y && my < mem_y + mem_size && mx >= mem_x && mx < mem_x + 37)
  100.     {
  101.         needclr++; activedbg = WNDMEM;
  102.         unsigned dx = mx - mem_x;
  103.         if(mem_dump)
  104.         {
  105.             if(dx >= 5)
  106.                 cpu.mem_curs = cpu.mem_top + (dx - 5) + (my - mem_y) * 32;
  107.         }
  108.         else
  109.         {
  110.             unsigned mem_se = (dx - 5) % 3;
  111.             if(dx >= 29)
  112.             {
  113.                 cpu.mem_curs = cpu.mem_top + (dx - 29) + (my - mem_y) * 8;
  114.                 mem_ascii = 1;
  115.             }
  116.             if(dx >= 5 && mem_se != 2 && dx < 29)
  117.             {
  118.                 cpu.mem_curs = cpu.mem_top + (dx - 5) / 3 + (my - mem_y) * 8;
  119.                 cpu.mem_second = mem_se;
  120.                 mem_ascii = 0;
  121.             }
  122.         }
  123.     }
  124.     if(mx >= regs_x && my >= regs_y && mx < regs_x + 32 && my < regs_y + 4)
  125.     {
  126.         needclr++; activedbg = WNDREGS;
  127.         for(unsigned i = 0; i < regs_layout_count; i++)
  128.         {
  129.             unsigned delta = 1;
  130.             if(regs_layout[i].width == 16) delta = 4;
  131.             if(regs_layout[i].width == 8) delta = 2;
  132.             if(my - regs_y == regs_layout[i].y && mx - regs_x - regs_layout[i].x < delta) regs_curs = i;
  133.         }
  134.     }
  135.     if(mousepos & 0x80000000)
  136.     { // right-click
  137.         enum { IDM_BPX = 1, IDM_SOME_OTHER };
  138.         HMENU menu = CreatePopupMenu();
  139.         if(activedbg == WNDTRACE)
  140.         {
  141.             AppendMenu(menu, MF_STRING, IDM_BPX, "breakpoint");
  142.         }
  143.         else
  144.         {
  145.             AppendMenu(menu, MF_STRING, 0, "I don't know");
  146.             AppendMenu(menu, MF_STRING, 0, "what to place");
  147.             AppendMenu(menu, MF_STRING, 0, "to menu, so");
  148.             AppendMenu(menu, MF_STRING, 0, "No Stuff Here");
  149.         }
  150.         int cmd = TrackPopupMenu(menu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_LEFTALIGN | TPM_TOPALIGN,
  151.             int(mousepos & 0xFFFF) + temp.client.left,
  152.             int((mousepos >> 16) & 0x7FFF) + temp.client.top, 0, wnd, nullptr);
  153.         DestroyMenu(menu);
  154.         if(cmd == IDM_BPX) cbpx();
  155.         //if (cmd == IDM_SOME_OTHER) some_other();
  156.         //needclr++;
  157.     }
  158.     mousepos = 0;
  159. }
  160.  
  161. void TCpuMgr::CopyToPrev()
  162. {
  163.     for(unsigned i = 0; i < Count; i++)
  164.         PrevCpus[i] = *Cpus[i];
  165. }
  166.  
  167. /* ------------------------------------------------------------- */
  168. static void debug(Z80 *cpu)
  169. {
  170.    OnEnterGui();
  171.    temp.mon_scale = temp.scale;
  172.    temp.scale = 1;
  173.    temp.rflags = RF_MONITOR;
  174.    needclr = 1;
  175.    dbgbreak = 1;
  176.    set_video();
  177.  
  178.    CpuMgr.SetCurrentCpu(cpu->GetIdx());
  179.    TZ80State *prevcpu = &CpuMgr.PrevCpu(cpu->GetIdx());
  180.    cpu->trace_curs = cpu->pc;
  181.    cpu->dbg_stopsp = cpu->dbg_stophere = -1U;
  182.    cpu->dbg_loop_r1 = 0;
  183.    cpu->dbg_loop_r2 = 0xFFFF;
  184.    mousepos = 0;
  185.  
  186.    while(dbgbreak) // debugger event loop
  187.    {
  188.       if (trace_labels)
  189.          mon_labels.notify_user_labels();
  190.  
  191.       cpu = &CpuMgr.Cpu();
  192.       prevcpu = &CpuMgr.PrevCpu(cpu->GetIdx());
  193. repaint_dbg:
  194.       cpu->trace_top &= 0xFFFF;
  195.       cpu->trace_curs &= 0xFFFF;
  196.  
  197.       debugscr();
  198.       if (cpu->trace_curs < cpu->trace_top || cpu->trace_curs >= cpu->trpc[trace_size] || asmii==-1U)
  199.       {
  200.          cpu->trace_top = cpu->trace_curs;
  201.          debugscr();
  202.       }
  203.  
  204.       debugflip();
  205.  
  206. sleep:
  207.       while(!dispatch(nullptr))
  208.       {
  209.          if (mousepos)
  210.              handle_mouse();
  211.          if (needclr)
  212.          {
  213.              needclr--;
  214.              goto repaint_dbg;
  215.          }
  216.          Sleep(20);
  217.       }
  218.       if (activedbg == WNDREGS && dispatch_more(ac_regs)) // ╬сЁрсюЄър уюЁ ўшї ъыртш°
  219.       {
  220.           continue;
  221.       }
  222.       if (activedbg == WNDTRACE && dispatch_more(ac_trace)) // ╬сЁрсюЄър уюЁ ўшї ъыртш°
  223.       {
  224.           continue;
  225.       }
  226.       if (activedbg == WNDMEM && dispatch_more(ac_mem)) // ╬сЁрсюЄър уюЁ ўшї ъыртш°
  227.       {
  228.           continue;
  229.       }
  230.       if (activedbg == WNDREGS && dispatch_regs()) // ╬сЁрсюЄър ттюфр ЄхъёЄр
  231.       {
  232.           continue;
  233.       }
  234.       if (activedbg == WNDTRACE && dispatch_trace()) // ╬сЁрсюЄър ттюфр ЄхъёЄр
  235.       {
  236.           continue;
  237.       }
  238.       if (activedbg == WNDMEM && dispatch_mem()) // ╬сЁрсюЄър ттюфр ЄхъёЄр
  239.       {
  240.           continue;
  241.       }
  242.       if (needclr)
  243.       {
  244.           needclr--;
  245.           continue;
  246.       }
  247.       goto sleep;
  248.    }
  249.  
  250.    *prevcpu = *cpu;
  251. //   CpuMgr.CopyToPrev();
  252.    cpu->SetLastT();
  253.    temp.scale = temp.mon_scale;
  254.    apply_video();
  255.    OnExitGui(false);
  256. }
  257.  
  258. void debug_events(Z80 *cpu)
  259. {
  260.    unsigned pc = cpu->pc & 0xFFFF;
  261.    unsigned char *membit = cpu->membits + pc;
  262.    *membit |= MEMBITS_X;
  263.    cpu->dbgbreak |= (*membit & MEMBITS_BPX);
  264.    dbgbreak |= (*membit & MEMBITS_BPX);
  265.  
  266.    if (pc == cpu->dbg_stophere)
  267.    {
  268.        cpu->dbgbreak = 1;
  269.        dbgbreak = 1;
  270.    }
  271.  
  272.    if ((cpu->sp & 0xFFFF) == cpu->dbg_stopsp)
  273.    {
  274.       if (pc > cpu->dbg_stophere && pc < cpu->dbg_stophere + 0x100)
  275.       {
  276.           cpu->dbgbreak = 1;
  277.           dbgbreak = 1;
  278.       }
  279.       if (pc < cpu->dbg_loop_r1 || pc > cpu->dbg_loop_r2)
  280.       {
  281.           cpu->dbgbreak = 1;
  282.           dbgbreak = 1;
  283.       }
  284.    }
  285.  
  286.    if (cpu->cbpn)
  287.    {
  288.       cpu->r_low = (cpu->r_low & 0x7F) + cpu->r_hi;
  289.       for (unsigned i = 0; i < cpu->cbpn; i++)
  290.       {
  291.          if (calc(cpu, cpu->cbp[i]))
  292.          {
  293.              cpu->dbgbreak = 1;
  294.              dbgbreak = 1;
  295.          }
  296.       }
  297.    }
  298.  
  299.    brk_port_in = brk_port_out = -1U; // reset only when breakpoints active
  300.  
  301.    if (cpu->dbgbreak)
  302.    {
  303.        if(!bkpts_ena && !user_mon_req)
  304.        {
  305.            dbgbreak = 0;
  306.            cpu->dbgbreak = 0;
  307.            return;
  308.        }
  309.        user_mon_req = 0;
  310.        debug(cpu);
  311.    }
  312. }
  313.  
  314. #endif // MOD_MONITOR
  315.  
  316. unsigned char isbrk(const Z80 &cpu) // is there breakpoints active or any other reason to use debug z80 loop?
  317. {
  318. #ifndef MOD_DEBUGCORE
  319.    return 0;
  320. #else
  321.    if(!bkpts_ena) return 0;
  322.  
  323.    #ifdef MOD_MEMBAND_LED
  324.    if (conf.led.memband & 0x80000000)
  325.        return 1;
  326.    #endif
  327.  
  328.    if (conf.mem_model == MM_PROFSCORP)
  329.        return 1; // breakpoint on read ROM switches ROM bank
  330.  
  331.    #ifdef MOD_MONITOR
  332.    if (cpu.cbpn)
  333.        return 1;
  334.    unsigned char res = 0;
  335.    for (int i = 0; i < 0x10000; i++)
  336.        res |= cpu.membits[i];
  337.    return (res & (MEMBITS_BPR | MEMBITS_BPW | MEMBITS_BPX));
  338.    #endif
  339.  
  340. #endif
  341. }
  342.