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 "dbgmem.h"
  10. #include "dbgrwdlg.h"
  11. #include "dbgcmd.h"
  12. #include "memory.h"
  13. #include "gui.h"
  14. #include "util.h"
  15.  
  16. void out(unsigned port, unsigned char val);
  17.  
  18. int find1dlg(unsigned start)
  19. {
  20.    static char ftext[12] = "";
  21.    strcpy(str, ftext);
  22.    filledframe(10,10,16,4);
  23.    tprint(10,10,"  find string   ", FRM_HEADER);
  24.    tprint(11,12,"text:", FFRAME_INSIDE);
  25.    if (!inputhex(17,12,8,false)) return -1;
  26.    strcpy(ftext, str);
  27.    size_t len = strlen(ftext);
  28.    unsigned i; //Alone Coder 0.36.7
  29.    for (unsigned ptr = memadr(start+1); ptr != start; ptr = memadr(ptr+1)) {
  30.       for (/*unsigned*/ i = 0; i < len; i++)
  31.          if (editrm(memadr(ptr+i)) != ftext[i]) break;
  32.       if (i == len) return int(ptr);
  33.    }
  34.    tprint(11,12,"  not found   ", FFRAME_ERROR);
  35.    debugflip();
  36.    while (!process_msgs());
  37.    return -1;
  38. }
  39.  
  40. int find2dlg(unsigned start)
  41. {
  42.    static unsigned code = 0xF3, mask = 0xFF; char ln[64];
  43.    filledframe(10,10,16,5);
  44.    tprint(10,10,"   find data    ", FRM_HEADER);
  45.    sprintf(ln, "code: %08lX", _byteswap_ulong(code)); tprint(11,12,ln, FFRAME_INSIDE);
  46.    sprintf(ln, "mask: %08lX", _byteswap_ulong(mask)); tprint(11,13,ln, FFRAME_INSIDE);
  47.    sprintf(str, "%08lX", _byteswap_ulong(code));
  48.    if (!inputhex(17,12,8,true)) return -1;
  49.    sscanf(str, "%x", &code); code = _byteswap_ulong(code);
  50.    tprint(17,12,str, FFRAME_INSIDE);
  51.    sprintf(str, "%08lX", _byteswap_ulong(mask));
  52.    if (!inputhex(17,13,8,true)) return -1;
  53.    sscanf(str, "%x", &mask); mask = _byteswap_ulong(mask);
  54.    unsigned i; //Alone Coder 0.36.7
  55.    for (unsigned ptr = memadr(start+1); ptr != start; ptr = memadr(ptr+1)) {
  56.       unsigned char *cd = (unsigned char*)&code, *ms = (unsigned char*)&mask;
  57.       for (/*unsigned*/ i = 0; i < 4; i++)
  58.          if ((editrm(memadr(ptr+i)) & ms[i]) != (cd[i] & ms[i])) break;
  59.       if (i == 4) return int(ptr);
  60.    }
  61.    tprint(11,12,"  not found   ", FFRAME_ERROR);
  62.    tprint(11,13,"              ", FFRAME_ERROR);
  63.    debugflip();
  64.    while (!process_msgs());
  65.    return -1;
  66. }
  67.  
  68. void mon_fill()
  69. {
  70.    filledframe(6,10,26,5);
  71.    char ln[64]; sprintf(ln, "start: %04X end: %04X", addr, end);
  72.    tprint(6,10, "    fill memory block     ", FRM_HEADER);
  73.    tprint(7,12, "pattern (hex):", FFRAME_INSIDE);
  74.    tprint(7,13, ln, FFRAME_INSIDE);
  75.  
  76.    static char fillpattern[10] = "00";
  77.  
  78.    unsigned char pattern[4];
  79.    unsigned fillsize = 0;
  80.  
  81.    strcpy(str, fillpattern);
  82.    if (!inputhex(22,12,8,true)) return;
  83.    strcpy(fillpattern, str);
  84.  
  85.    if (!fillpattern[0])
  86.        strcpy(fillpattern, "00");
  87.  
  88.    for (fillsize = 0; fillpattern[2*fillsize]; fillsize++) {
  89.        if(!fillpattern[2 * fillsize + 1])
  90.        {
  91.            fillpattern[2 * fillsize + 1] = '0';
  92.            fillpattern[2 * fillsize + 2] = 0;
  93.        }
  94.       pattern[fillsize] = hex(fillpattern + 2*fillsize);
  95.    }
  96.    tprint(22,12,"        ", FFRAME_INSIDE);
  97.    tprint(22,12,fillpattern, FFRAME_INSIDE);
  98.  
  99.    int a1 = input4(14,13,addr); if (a1 == -1) return;
  100.    addr = unsigned(a1); tprint(14,13,str,FFRAME_INSIDE);
  101.    a1 = input4(24,13,end); if (a1 == -1) return;
  102.    end = unsigned(a1);
  103.  
  104.    unsigned pos = 0;
  105.    for (a1 = int(addr); a1 <= int(end); a1++) {
  106.       cpu.DirectWm(unsigned(a1), pattern[pos]);
  107.       if (++pos == fillsize) pos = 0;
  108.    }
  109. }
  110.  
  111. // ┬√їюф шч ьюэшЄюЁр
  112. void mon_emul()
  113. {
  114.    for(unsigned i = 0; i < CpuMgr.GetCount(); i++)
  115.    {
  116.        Z80 &cpu = CpuMgr.Cpu(i);
  117.        cpu.dbgchk = isbrk(cpu);
  118.        cpu.dbgbreak = 0;
  119.    }
  120.    dbgbreak = 0;
  121. }
  122.  
  123. static void mon_scr(char alt)
  124. {
  125.    temp.scale = temp.mon_scale;
  126.    apply_video();
  127.  
  128.    memcpy(save_buf, rbuf, rb2_offs);
  129.    paint_scr(alt);
  130.    flip(); if (conf.noflic) flip();
  131.    memcpy(rbuf, save_buf, rb2_offs);
  132.  
  133.    while (!process_msgs()) Sleep(20);
  134.    temp.rflags = RF_MONITOR;
  135.    temp.mon_scale = temp.scale;
  136.    temp.scale = 1;
  137.    set_video();
  138. }
  139.  
  140. void mon_scr0() { mon_scr(0); }
  141. void mon_scr1() { mon_scr(1); }
  142. void mon_scray() { mon_scr(2); }
  143.  
  144. void mon_exitsub()
  145. {
  146.    Z80 &cpu = CpuMgr.Cpu();
  147.    cpu.dbgchk = 1;
  148.    cpu.dbgbreak = 0;
  149.    dbgbreak = 0;
  150.    cpu.dbg_stophere = cpu.DirectRm(cpu.sp)+0x100*cpu.DirectRm(cpu.sp+1);
  151. }
  152.  
  153. void editbank()
  154. {
  155.    int x = input2(ports_x+5, ports_y+1, comp.p7FFD);
  156.    if (x != -1)
  157.    {
  158.        comp.p7FFD = u8(x);
  159.        set_banks();
  160.    }
  161. }
  162.  
  163. void editextbank()
  164. {
  165.    if(dbg_extport == -1U)
  166.        return;
  167.    int x = input2(ports_x+5, ports_y+2, dbg_extval);
  168.    if (x != -1)
  169.        out(dbg_extport, (unsigned char)x);
  170. }
  171.  
  172. void mon_nxt()
  173. {
  174.    if (activedbg == WNDREGS) activedbg = WNDTRACE;
  175.    else if (activedbg == WNDTRACE) activedbg = WNDMEM;
  176.    else if (activedbg == WNDMEM) activedbg = WNDREGS;
  177. }
  178.  
  179. void mon_prv() { mon_nxt(); mon_nxt(); }
  180. void mon_dump() { mem_dump ^= 1; mem_sz = mem_dump ? 32:8; }
  181.  
  182. void mon_switch_dump()
  183. {
  184.     static const u8 DumpModes[] = { ED_MEM, ED_PHYS, ED_LOG, ED_CMOS, ED_NVRAM, ED_COMP_PAL };
  185.     static unsigned Idx = 0;
  186.     ++Idx;
  187.     Idx %= ED_MAX;
  188.     editor = DumpModes[Idx];
  189. }
  190.  
  191. #define tool_x 18
  192. #define tool_y 12
  193.  
  194. void mon_tool()
  195. {
  196.    Z80 &cpu = CpuMgr.Cpu();
  197.    static unsigned char unref = 0xCF;
  198.    if (ripper) {
  199.       OPENFILENAME ofn = {  };
  200.       char savename[0x200]; *savename = 0;
  201.       ofn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : sizeof(OPENFILENAME);
  202.       ofn.lpstrFilter = "Memory dump\0*.bin\0";
  203.       ofn.lpstrFile = savename; ofn.nMaxFile = sizeof savename;
  204.       ofn.lpstrTitle = "Save ripped data";
  205.       ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
  206.       ofn.hwndOwner = wnd;
  207.       ofn.lpstrDefExt = "bin";
  208.       ofn.nFilterIndex = 1;
  209.       if (GetSaveFileName(&ofn)) {
  210.          for (unsigned i = 0; i < 0x10000; i++)
  211.             snbuf[i] = (cpu.membits[i] & ripper) ? cpu.DirectRm(i) : unref;
  212.          FILE *ff = fopen(savename, "wb");
  213.          if(ff)
  214.          {
  215.              fwrite(snbuf, 1, 0x10000, ff);
  216.              fclose(ff);
  217.          }
  218.       }
  219.       ripper = 0;
  220.    } else {
  221.       filledframe(tool_x, tool_y, 17, 6);
  222.       tprint(tool_x, tool_y, "  ripper's tool  ", FRM_HEADER);
  223.       tprint(tool_x+1,tool_y+2, "trace reads:", FFRAME_INSIDE);
  224.       *(unsigned*)str = 'Y';
  225.       if (!inputhex(tool_x+15,tool_y+2,1,false)) return;
  226.       tprint(tool_x+15,tool_y+2,str,FFRAME_INSIDE);
  227.       if (*str == 'Y' || *str == 'y' || *str == '1') ripper |= MEMBITS_R;
  228.       *(unsigned*)str = 'N';
  229.       tprint(tool_x+1,tool_y+3, "trace writes:", FFRAME_INSIDE);
  230.       if (!inputhex(tool_x+15,tool_y+3,1,false)) { ripper = 0; return; }
  231.       tprint(tool_x+15,tool_y+3,str,FFRAME_INSIDE);
  232.       if (*str == 'Y' || *str == 'y' || *str == '1') ripper |= MEMBITS_W;
  233.       tprint(tool_x+1,tool_y+4, "unref. byte:", FFRAME_INSIDE);
  234.       int ub;
  235.       if ((ub = input2(tool_x+14,tool_y+4,unref)) == -1) { ripper = 0; return; }
  236.       unref = (unsigned char)ub;
  237.       if (ripper)
  238.           for (unsigned i = 0; i < 0x10000; i++)
  239.               cpu.membits[i] &= ~(MEMBITS_R | MEMBITS_W);
  240.    }
  241. }
  242.  
  243. void mon_setup_dlg()
  244. {
  245. #ifdef MOD_SETTINGS
  246.    setup_dlg();
  247.    temp.rflags = RF_MONITOR;
  248.    set_video();
  249. #endif
  250. }
  251.  
  252. void mon_scrshot() { show_scrshot++; if (show_scrshot == 3) show_scrshot = 0; }
  253.  
  254. void mon_switch_cpu()
  255. {
  256. //    CpuMgr.CopyToPrev();
  257.     Z80 &cpu0 = CpuMgr.Cpu();
  258.     cpu0.dbgbreak = 0;
  259.     CpuMgr.SwitchCpu();
  260.     Z80 &cpu1 = CpuMgr.Cpu();
  261.  
  262.     if(cpu1.trace_curs == -1U)
  263.         cpu1.trace_curs = cpu1.pc;
  264.     if(cpu1.trace_top == -1U)
  265.         cpu1.trace_top = cpu1.pc;
  266.     if(cpu1.trace_mode == -1U)
  267.         cpu1.trace_mode = 0;
  268.  
  269.     debugscr();
  270.     debugflip();
  271. }
  272.