Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1088 | alone | 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 | //============================================================================= |
||
17 | void out(unsigned port, unsigned char val); |
||
18 | //============================================================================= |
||
19 | |||
20 | |||
21 | #define DBG_ATTR_BCKGRND 0x00 //0 0 |
||
22 | #define DBG_ATTR_BCKGRND_ACTIVE 0x10 //blue |
||
23 | |||
24 | |||
25 | #define DBG_ATTR_WINDOW_TITLE 0xF0//0x1F //blue br+WHITE |
||
26 | |||
27 | #define DBG_ATTR_WINDOW_BACK_COLOR 0x70//0x70//white 0 |
||
28 | #define DBG_ATTR_WINDOW_TEXT 0x70 |
||
29 | #define DBG_ATTR_WINDOW_TEXT_ERROR 0x72 //white red |
||
30 | |||
31 | |||
32 | //============================================================================= |
||
33 | int find1dlg(unsigned start) |
||
34 | { |
||
35 | static char ftext[12] = ""; |
||
36 | strcpy( str, |
||
37 | ftext |
||
38 | ); |
||
39 | filledframe( 10, |
||
40 | 10, |
||
41 | 16, |
||
42 | 4, |
||
43 | DBG_ATTR_WINDOW_BACK_COLOR |
||
44 | ); |
||
45 | tprint( 10, |
||
46 | 10, |
||
47 | " find string ", |
||
48 | DBG_ATTR_WINDOW_TITLE //FRM_HEADER |
||
49 | ); |
||
50 | tprint( 11, |
||
51 | 12, |
||
52 | "text:", |
||
53 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
54 | ); |
||
55 | if (!inputhex( 17, 12, 8, false)) return -1; |
||
56 | |||
57 | strcpy( ftext, |
||
58 | str |
||
59 | ); |
||
60 | |||
61 | size_t len = strlen(ftext); |
||
62 | unsigned i; //Alone Coder 0.36.7 |
||
63 | |||
64 | for (unsigned ptr = memadr(start+1); ptr != start; ptr = memadr(ptr+1)) |
||
65 | { |
||
66 | for (/*unsigned*/ i = 0; i < len; i++) |
||
67 | if (editrm(memadr(ptr+i)) != ftext[i]) break; |
||
68 | |||
69 | if (i == len) return int(ptr); |
||
70 | } |
||
71 | tprint( 11, |
||
72 | 12, |
||
73 | " not found ", |
||
74 | DBG_ATTR_WINDOW_TEXT_ERROR //FFRAME_ERROR |
||
75 | ); |
||
76 | debugflip(); |
||
77 | while (!process_msgs()); |
||
78 | return -1; |
||
79 | } |
||
80 | //============================================================================= |
||
81 | |||
82 | |||
83 | //============================================================================= |
||
84 | int find2dlg(unsigned start) |
||
85 | { |
||
86 | static unsigned code = 0xF3, mask = 0xFF; char ln[64]; |
||
87 | //------------------------------------------------------------------------- |
||
88 | filledframe( 10, |
||
89 | 10, |
||
90 | 16, |
||
91 | 5, |
||
92 | DBG_ATTR_WINDOW_BACK_COLOR |
||
93 | ); |
||
94 | //------------------------------------------------------------------------- |
||
95 | tprint( 10, |
||
96 | 10, |
||
97 | " find data ", |
||
98 | DBG_ATTR_WINDOW_TITLE //FRM_HEADER |
||
99 | ); |
||
100 | //------------------------------------------------------------------------- |
||
101 | sprintf( ln, |
||
102 | "code: %08lX", |
||
103 | _byteswap_ulong(code) |
||
104 | ); |
||
105 | tprint( 11, |
||
106 | 12, |
||
107 | ln, |
||
108 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
109 | ); |
||
110 | //------------------------------------------------------------------------- |
||
111 | sprintf( ln, |
||
112 | "mask: %08lX", |
||
113 | _byteswap_ulong(mask) |
||
114 | ); |
||
115 | tprint( 11, |
||
116 | 13, |
||
117 | ln, |
||
118 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
119 | ); |
||
120 | //------------------------------------------------------------------------- |
||
121 | // ���� code: |
||
122 | sprintf( str, |
||
123 | "%08lX", |
||
124 | _byteswap_ulong(code) |
||
125 | ); |
||
126 | if (!inputhex(17,12,8,true)) return -1; |
||
127 | sscanf( str, |
||
128 | "%x", |
||
129 | &code |
||
130 | ); |
||
131 | code = _byteswap_ulong(code); |
||
132 | tprint( 17, //��������� code: xxxxxxxx |
||
133 | 12, |
||
134 | str, |
||
135 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
136 | ); |
||
137 | //------------------------------------------------------------------------- |
||
138 | // ���� mask: |
||
139 | sprintf( str, |
||
140 | "%08lX", |
||
141 | _byteswap_ulong(mask) |
||
142 | ); |
||
143 | if (!inputhex( 17, 13, 8, true )) return -1; |
||
144 | sscanf( str, |
||
145 | "%x", |
||
146 | &mask |
||
147 | ); |
||
148 | mask = _byteswap_ulong(mask); |
||
149 | //------------------------------------------------------------------------- |
||
150 | unsigned i; //Alone Coder 0.36.7 |
||
151 | for (unsigned ptr = memadr( start + 1); ptr != start; ptr = memadr( ptr + 1)) |
||
152 | { |
||
153 | unsigned char *cd = (unsigned char*) &code, *ms = (unsigned char*) &mask; |
||
154 | for (/*unsigned*/ i = 0; i < 4; i++) |
||
155 | if ((editrm(memadr(ptr+i)) & ms[i]) != (cd[i] & ms[i])) |
||
156 | break; |
||
157 | if (i == 4) return int(ptr); |
||
158 | } |
||
159 | tprint( 11, |
||
160 | 12, |
||
161 | " not found ", |
||
162 | DBG_ATTR_WINDOW_TEXT_ERROR //FFRAME_ERROR |
||
163 | ); |
||
164 | tprint( 11, |
||
165 | 13, |
||
166 | " ", |
||
167 | DBG_ATTR_WINDOW_TEXT_ERROR //FFRAME_ERROR |
||
168 | ); |
||
169 | debugflip(); |
||
170 | while (!process_msgs()); |
||
171 | return -1; |
||
172 | } |
||
173 | //============================================================================= |
||
174 | |||
175 | |||
176 | //============================================================================= |
||
177 | // fill memory block with pattern // � WNDMEM ���� |
||
178 | void mon_fill() //� "mon.fillblock" ������ |
||
179 | { |
||
180 | filledframe( 6, |
||
181 | 10, |
||
182 | 26, |
||
183 | 5, |
||
184 | DBG_ATTR_WINDOW_BACK_COLOR |
||
185 | ); |
||
186 | char ln[64]; |
||
187 | sprintf( ln, |
||
188 | "start: %04X end: %04X", |
||
189 | addr, |
||
190 | end |
||
191 | ); |
||
192 | tprint( 6, |
||
193 | 10, |
||
194 | " fill memory block ", |
||
195 | DBG_ATTR_WINDOW_TITLE //FRM_HEADER |
||
196 | ); |
||
197 | tprint( 7, |
||
198 | 12, |
||
199 | "pattern (hex):", |
||
200 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
201 | ); |
||
202 | tprint( 7, |
||
203 | 13, |
||
204 | ln, |
||
205 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
206 | ); |
||
207 | |||
208 | static char fillpattern[10] = "00"; |
||
209 | |||
210 | unsigned char pattern[4]; |
||
211 | unsigned fillsize = 0; |
||
212 | |||
213 | strcpy( str, |
||
214 | fillpattern |
||
215 | ); |
||
216 | if (!inputhex( 22, 12, 8,true)) return; |
||
217 | |||
218 | strcpy( fillpattern, |
||
219 | str |
||
220 | ); |
||
221 | |||
222 | if (!fillpattern[0]) |
||
223 | strcpy( fillpattern, |
||
224 | "00" |
||
225 | ); |
||
226 | |||
227 | for (fillsize = 0; fillpattern[2*fillsize]; fillsize++) |
||
228 | { |
||
229 | if (!fillpattern[2 * fillsize + 1]) |
||
230 | { |
||
231 | fillpattern[2 * fillsize + 1] = '0'; |
||
232 | fillpattern[2 * fillsize + 2] = 0; |
||
233 | } |
||
234 | pattern[fillsize] = hex(fillpattern + 2*fillsize); |
||
235 | } |
||
236 | tprint( 22, |
||
237 | 12, |
||
238 | " ", |
||
239 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
240 | ); |
||
241 | tprint( 22, |
||
242 | 12, |
||
243 | fillpattern, |
||
244 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
245 | ); |
||
246 | |||
247 | int a1 = input4( 14, |
||
248 | 13, |
||
249 | addr |
||
250 | ); |
||
251 | if (a1 == -1) return; |
||
252 | |||
253 | addr = unsigned(a1); |
||
254 | tprint( 14, |
||
255 | 13, |
||
256 | str, |
||
257 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
258 | ); |
||
259 | a1 = input4( 24, |
||
260 | 13, |
||
261 | end |
||
262 | ); |
||
263 | if (a1 == -1) return; |
||
264 | end = unsigned(a1); |
||
265 | |||
266 | unsigned pos = 0; |
||
267 | for (a1 = int(addr); a1 <= int(end); a1++) |
||
268 | { |
||
269 | cpu.DirectWm(unsigned(a1), pattern[pos]); |
||
270 | if (++pos == fillsize) pos = 0; |
||
271 | } |
||
272 | } |
||
273 | //============================================================================= |
||
274 | |||
275 | |||
276 | //============================================================================= |
||
277 | // ����� �� �������� //"mon.emul" ������ |
||
278 | void mon_emul() |
||
279 | { |
||
280 | for (unsigned i = 0; i < CpuMgr.GetCount(); i++) |
||
281 | { |
||
282 | Z80 &cpu = CpuMgr.Cpu( i); |
||
283 | cpu.dbgchk = isbrk( cpu); |
||
284 | cpu.dbgbreak = 0; |
||
285 | } |
||
286 | dbgbreak = 0; |
||
287 | } |
||
288 | //============================================================================= |
||
289 | |||
290 | |||
291 | //============================================================================= |
||
292 | // ���������� ������ �� �������� �� ������ |
||
293 | static void mon_scr(char alt) |
||
294 | { |
||
295 | // printf("mon_scr()\n"); |
||
296 | temp.scale = temp.mon_scale; |
||
297 | apply_video(); |
||
298 | |||
299 | memcpy( save_buf, |
||
300 | rbuf, |
||
301 | rb2_offs |
||
302 | ); |
||
303 | paint_scr(alt); |
||
304 | flip(); |
||
305 | if (conf.noflic) flip(); |
||
306 | memcpy( rbuf, |
||
307 | save_buf, |
||
308 | rb2_offs |
||
309 | ); |
||
310 | |||
311 | while (!process_msgs()) Sleep(20); |
||
312 | |||
313 | temp.rflags = RF_MONITOR; |
||
314 | temp.mon_scale = temp.scale; |
||
315 | temp.scale = 1; |
||
316 | set_video(); |
||
317 | } |
||
318 | //============================================================================= |
||
319 | |||
320 | |||
321 | //============================================================================= |
||
322 | void mon_scr0() { mon_scr(0); } // "mon.screen", mon_scr0 |
||
323 | //============================================================================= |
||
324 | void mon_scr1() { mon_scr(1); } // "mon.altscreen", mon_scr1 |
||
325 | //============================================================================= |
||
326 | void mon_scray() { mon_scr(2); } // "mon.rayscreen", mon_scray |
||
327 | //============================================================================= |
||
328 | |||
329 | |||
330 | //============================================================================= |
||
331 | void mon_exitsub() //trace until (sp) //"mon.exitsub" ������ |
||
332 | { |
||
333 | //printf("mon_exitsub()\n"); |
||
334 | Z80 &cpu = CpuMgr.Cpu(); |
||
335 | cpu.dbgchk = 1; |
||
336 | cpu.dbgbreak = 0; |
||
337 | dbgbreak = 0; |
||
338 | cpu.dbg_stophere = cpu.DirectRm( cpu.sp) + 0x100 * cpu.DirectRm( cpu.sp + 1); |
||
339 | //printf("mon_exitsub\n"); |
||
340 | } |
||
341 | //============================================================================= |
||
342 | |||
343 | |||
344 | //============================================================================= |
||
345 | void editbank() //write to #7FFD //"mon.setbank" ������ |
||
346 | { |
||
347 | //printf("editbank()\n"); |
||
348 | int x = input2( ports_x+5, |
||
349 | ports_y+1, |
||
350 | comp.p7FFD |
||
351 | ); |
||
352 | if (x != -1) |
||
353 | { |
||
354 | comp.p7FFD = u8(x); |
||
355 | set_banks(); |
||
356 | } |
||
357 | } |
||
358 | //============================================================================= |
||
359 | |||
360 | |||
361 | //============================================================================= |
||
362 | // write to model-specific extended memory port |
||
363 | void editextbank() //"mon.sethimem" ������ |
||
364 | { |
||
365 | if (dbg_extport == -1U) |
||
366 | return; |
||
367 | int x = input2(ports_x+5, ports_y+2, dbg_extval); |
||
368 | if (x != -1) |
||
369 | out(dbg_extport, (unsigned char)x); |
||
370 | } |
||
371 | //============================================================================= |
||
372 | |||
373 | |||
374 | //============================================================================= |
||
375 | // next window |
||
376 | void mon_nxt() //"mon.next" ������ |
||
377 | { |
||
378 | if (activedbg == WNDREGS) activedbg = WNDTRACE; |
||
379 | else if (activedbg == WNDTRACE) activedbg = WNDMEM; |
||
380 | else if (activedbg == WNDMEM) activedbg = WNDREGS; |
||
381 | } |
||
382 | //============================================================================= |
||
383 | |||
384 | |||
385 | //============================================================================= |
||
386 | // prev window... //"mon.prev" ������ |
||
387 | void mon_prv() |
||
388 | { |
||
389 | mon_nxt(); |
||
390 | mon_nxt(); |
||
391 | } |
||
392 | //============================================================================= |
||
393 | // toggle dump (HEX/Ascii) //� WNDMEM ���� |
||
394 | void mon_dump() //� "mon.dump" ������ |
||
395 | { |
||
396 | mem_dump ^= 1; |
||
397 | mem_sz = mem_dump ? 32: |
||
398 | 8 ; |
||
399 | } |
||
400 | //============================================================================= |
||
401 | |||
402 | |||
403 | //============================================================================= |
||
404 | // //� WNDMEM ���� |
||
405 | void mon_switch_dump() //� "mon.switchdump" ������ |
||
406 | { |
||
407 | static const u8 DumpModes[] = { ED_MEM, |
||
408 | ED_PHYS, |
||
409 | ED_LOG, |
||
410 | ED_CMOS, |
||
411 | ED_NVRAM, |
||
412 | ED_COMP_PAL |
||
413 | }; |
||
414 | static unsigned Idx = 0; |
||
415 | ++Idx; |
||
416 | Idx %= ED_MAX; |
||
417 | editor = DumpModes[ Idx]; |
||
418 | } |
||
419 | //============================================================================= |
||
420 | |||
421 | #define tool_x 18 |
||
422 | #define tool_y 12 |
||
423 | |||
424 | //============================================================================= |
||
425 | // ripper's tool //� WNDMEM ���� |
||
426 | void mon_tool() //� "mon.rip" ������ |
||
427 | { |
||
428 | Z80 &cpu = CpuMgr.Cpu(); |
||
429 | static unsigned char unref = 0xCF; //RST $8 |
||
430 | |||
431 | //------------------------------------------------------------------------- |
||
432 | // ��� �������? |
||
433 | if (ripper) |
||
434 | { |
||
435 | OPENFILENAME ofn = { }; |
||
436 | char savename[0x200]; *savename = 0; |
||
437 | ofn.lStructSize = (WinVerMajor < 5) ? OPENFILENAME_SIZE_VERSION_400 : |
||
438 | sizeof(OPENFILENAME); |
||
439 | ofn.lpstrFilter = "Memory dump\0*.bin\0"; |
||
440 | ofn.lpstrFile = savename; |
||
441 | ofn.nMaxFile = sizeof savename; |
||
442 | ofn.lpstrTitle = "Save ripped data"; |
||
443 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT; |
||
444 | ofn.hwndOwner = wnd; |
||
445 | ofn.lpstrDefExt = "bin"; |
||
446 | ofn.nFilterIndex = 1; |
||
447 | |||
448 | if (GetSaveFileName(&ofn)) |
||
449 | { |
||
450 | for (unsigned i = 0; i < 0x10000; i++) |
||
451 | snbuf[i] = (cpu.membits[i] & ripper) ? cpu.DirectRm(i) : |
||
452 | unref; |
||
453 | FILE *ff = fopen(savename, "wb"); |
||
454 | if (ff) |
||
455 | { |
||
456 | fwrite( snbuf, |
||
457 | 1, |
||
458 | 0x10000, |
||
459 | ff |
||
460 | ); |
||
461 | fclose(ff); |
||
462 | } |
||
463 | } |
||
464 | ripper = 0; |
||
465 | } |
||
466 | //------------------------------------------------------------------------- |
||
467 | // ������ ������? |
||
468 | else |
||
469 | { |
||
470 | //--------------------------------------------------------------------- |
||
471 | filledframe( tool_x, |
||
472 | tool_y, |
||
473 | 17, |
||
474 | 6, |
||
475 | DBG_ATTR_WINDOW_BACK_COLOR |
||
476 | ); |
||
477 | tprint( tool_x, |
||
478 | tool_y, |
||
479 | " ripper's tool ", |
||
480 | DBG_ATTR_WINDOW_TITLE //FRM_HEADER |
||
481 | ); |
||
482 | //--------------------------------------------------------------------- |
||
483 | // trace reads |
||
484 | tprint( tool_x+1, |
||
485 | tool_y+2, |
||
486 | "trace reads:", |
||
487 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
488 | ); |
||
489 | *(unsigned*)str = 'Y'; |
||
490 | if (!inputhex( tool_x+15, tool_y+2, 1, false )) return; |
||
491 | tprint( tool_x+15, |
||
492 | tool_y+2, |
||
493 | str, |
||
494 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
495 | ); |
||
496 | if (*str == 'Y' || *str == 'y' || *str == '1') ripper |= MEMBITS_R; |
||
497 | //--------------------------------------------------------------------- |
||
498 | // trace writes |
||
499 | *(unsigned*)str = 'N'; |
||
500 | tprint( tool_x+1, |
||
501 | tool_y+3, |
||
502 | "trace writes:", |
||
503 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
504 | ); |
||
505 | if (!inputhex( tool_x+15, tool_y+3, 1, false )) { ripper = 0; return; } |
||
506 | tprint( tool_x+15, |
||
507 | tool_y+3, |
||
508 | str, |
||
509 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
510 | ); |
||
511 | if (*str == 'Y' || *str == 'y' || *str == '1') ripper |= MEMBITS_W; |
||
512 | //--------------------------------------------------------------------- |
||
513 | // unref. byte |
||
514 | tprint( tool_x+1, |
||
515 | tool_y+4, |
||
516 | "unref. byte:", |
||
517 | DBG_ATTR_WINDOW_TEXT //FFRAME_INSIDE |
||
518 | ); |
||
519 | int ub; |
||
520 | if ((ub = input2( tool_x+14, tool_y+4, unref)) == -1) { ripper = 0; return; } |
||
521 | unref = (unsigned char)ub; |
||
522 | //--------------------------------------------------------------------- |
||
523 | if (ripper) |
||
524 | for (unsigned i = 0; i < 0x10000; i++) |
||
525 | cpu.membits[i] &= ~(MEMBITS_R | MEMBITS_W); |
||
526 | } |
||
527 | } |
||
528 | //============================================================================= |
||
529 | |||
530 | |||
531 | //============================================================================= |
||
532 | // emulation settings (GUI) //"mon.settings" ������ |
||
533 | void mon_setup_dlg() |
||
534 | { |
||
535 | #ifdef MOD_SETTINGS // ����� � ��������� |
||
536 | setup_dlg(); // � ���������������� ��������� |
||
537 | temp.rflags = RF_MONITOR; // ��� ����������� �������� � ������� |
||
538 | set_video(); |
||
539 | #endif |
||
540 | } |
||
541 | //============================================================================= |
||
542 | |||
543 | |||
544 | //============================================================================= |
||
545 | // toggle screenshot/scrdump/watches //"mon.scrshot" ������ |
||
546 | void mon_scrshot() |
||
547 | { |
||
548 | show_scrshot++; |
||
549 | show_scrshot %= 4; |
||
550 | } |
||
551 | //============================================================================= |
||
552 | |||
553 | |||
554 | //============================================================================= |
||
555 | // �switch to next cpu // � WNDTRACE ���� |
||
556 | void mon_switch_cpu() // � "mon.cpu" ������ |
||
557 | { |
||
558 | // CpuMgr.CopyToPrev(); |
||
559 | Z80 &cpu0 = CpuMgr.Cpu(); |
||
560 | cpu0.dbgbreak = 0; |
||
561 | CpuMgr.SwitchCpu(); |
||
562 | Z80 &cpu1 = CpuMgr.Cpu(); |
||
563 | |||
564 | //���� �� ����������������? |
||
565 | if (cpu1.trace_curs == -1U) cpu1.trace_curs = cpu1.pc; |
||
566 | if (cpu1.trace_top == -1U) cpu1.trace_top = cpu1.pc; |
||
567 | if (cpu1.trace_mode == -1U) cpu1.trace_mode = 0; |
||
568 | |||
569 | debugscr(); |
||
570 | debugflip(); |
||
571 | } |
||
572 | //============================================================================= |
||
573 |