Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

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