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