1 |
|
/* |
2 |
< |
* mon_cmd.cpp - mon standard commands |
2 |
> |
* mon_cmd.cpp - cxmon standard commands |
3 |
|
* |
4 |
< |
* mon (C) 1997-1999 Christian Bauer, Marc Hellwig |
4 |
> |
* cxmon (C) 1997-1999 Christian Bauer, Marc Hellwig |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
20 |
|
|
21 |
|
#include "sysdeps.h" |
22 |
|
|
23 |
+ |
#include <stdlib.h> |
24 |
+ |
|
25 |
|
#include "mon.h" |
26 |
|
#include "mon_cmd.h" |
27 |
< |
#include "mon_ppc.h" |
28 |
< |
#include "mon_68k.h" |
29 |
< |
#include "mon_x86.h" |
30 |
< |
#include "mon_6502.h" |
31 |
< |
#include "mon_8080.h" |
30 |
< |
#include "version.h" |
27 |
> |
#include "mon_disass.h" |
28 |
> |
|
29 |
> |
#ifndef VERSION |
30 |
> |
#define VERSION "2" |
31 |
> |
#endif |
32 |
|
|
33 |
|
|
34 |
|
/* |
118 |
|
|
119 |
|
void version(void) |
120 |
|
{ |
121 |
< |
fprintf(monout, "mon V%d.%d\n", VERSION_MAJOR, VERSION_MINOR); |
121 |
> |
fprintf(monout, "mon V" VERSION "\n"); |
122 |
|
} |
123 |
|
|
124 |
|
|
171 |
|
} |
172 |
|
|
173 |
|
if (val > 0x7fffffff) { |
174 |
< |
fprintf(monout, "Hex unsigned: $%08lx\n" |
175 |
< |
"Hex signed : -$%08lx\n" |
176 |
< |
"Dec unsigned: %lu\n" |
177 |
< |
"Dec signed : %ld\n", val, -val, val, val); |
174 |
> |
fprintf(monout, "Hex unsigned: $%08x\n" |
175 |
> |
"Hex signed : -$%08x\n" |
176 |
> |
"Dec unsigned: %u\n" |
177 |
> |
"Dec signed : %d\n", val, -val, val, val); |
178 |
|
fprintf(monout, "Char : '%c%c%c%c'\n", char2print(val >> 24), char2print(val >> 16), char2print(val >> 8), char2print(val)); |
179 |
|
} else { |
180 |
< |
fprintf(monout, "Hex : $%08lx\n" |
181 |
< |
"Dec : %ld\n", val, val); |
180 |
> |
fprintf(monout, "Hex : $%08x\n" |
181 |
> |
"Dec : %d\n", val, val); |
182 |
|
fprintf(monout, "Char: '%c%c%c%c'\n", char2print(val >> 24), char2print(val >> 16), char2print(val >> 8), char2print(val)); |
183 |
|
} |
184 |
|
} |
222 |
|
return; |
223 |
|
|
224 |
|
while (adr <= end_adr && !mon_aborted()) { |
225 |
< |
fprintf(monout, "%08lx:", mon_use_real_mem ? adr: adr % mon_mem_size); |
225 |
> |
fprintf(monout, "%08x:", mon_use_real_mem ? adr: adr % mon_mem_size); |
226 |
|
for (int i=0; i<MEMDUMP_BPL; i++, adr++) { |
227 |
|
if (i % 4 == 0) |
228 |
< |
fprintf(monout, " %08lx", mon_read_word(adr)); |
228 |
> |
fprintf(monout, " %08x", mon_read_word(adr)); |
229 |
|
mem[i] = char2print(mon_read_byte(adr)); |
230 |
|
} |
231 |
|
fprintf(monout, " '%s'\n", mem); |
253 |
|
return; |
254 |
|
|
255 |
|
while (adr <= end_adr && !mon_aborted()) { |
256 |
< |
fprintf(monout, "%08lx:", mon_use_real_mem ? adr : adr % mon_mem_size); |
256 |
> |
fprintf(monout, "%08x:", mon_use_real_mem ? adr : adr % mon_mem_size); |
257 |
|
for (int i=0; i<ASCIIDUMP_BPL; i++, adr++) |
258 |
|
str[i] = char2print(mon_read_byte(adr)); |
259 |
|
fprintf(monout, " '%s'\n", str); |
264 |
|
|
265 |
|
|
266 |
|
/* |
267 |
+ |
* Binary dump |
268 |
+ |
* b [start [end]] |
269 |
+ |
*/ |
270 |
+ |
|
271 |
+ |
void binary_dump(void) |
272 |
+ |
{ |
273 |
+ |
uint32 adr, end_adr; |
274 |
+ |
uint8 str[9]; |
275 |
+ |
|
276 |
+ |
str[8] = 0; |
277 |
+ |
|
278 |
+ |
if (!range_args(&adr, &end_adr, 7)) // 8 lines unless end address specified |
279 |
+ |
return; |
280 |
+ |
|
281 |
+ |
while (adr <= end_adr && !mon_aborted()) { |
282 |
+ |
fprintf(monout, "%08x:", mon_use_real_mem ? adr : adr % mon_mem_size); |
283 |
+ |
uint8 b = mon_read_byte(adr); |
284 |
+ |
for (int m=0x80, i=0; i<8; m>>=1, i++) |
285 |
+ |
str[i] = (b & m) ? '*' : '.'; |
286 |
+ |
fprintf(monout, " '%s'\n", str); |
287 |
+ |
adr++; |
288 |
+ |
} |
289 |
+ |
|
290 |
+ |
mon_dot_address = adr; |
291 |
+ |
} |
292 |
+ |
|
293 |
+ |
|
294 |
+ |
/* |
295 |
|
* Disassemble |
296 |
|
* d [start [end]] |
297 |
|
* d65 [start [end]] |
298 |
|
* d68 [start [end]] |
299 |
|
* d80 [start [end]] |
300 |
|
* d86 [start [end]] |
301 |
+ |
* d8086 [start [end]] |
302 |
|
*/ |
303 |
|
|
304 |
|
enum CPUType { |
305 |
|
CPU_PPC, |
306 |
|
CPU_6502, |
307 |
|
CPU_680x0, |
308 |
< |
CPU_8080, |
309 |
< |
CPU_80x86 |
308 |
> |
CPU_Z80, |
309 |
> |
CPU_80x86_32, |
310 |
> |
CPU_80x86_16 |
311 |
|
}; |
312 |
|
|
313 |
|
static void disassemble(CPUType type) |
321 |
|
case CPU_PPC: |
322 |
|
while (adr <= end_adr && !mon_aborted()) { |
323 |
|
uint32 w = mon_read_word(adr); |
324 |
< |
fprintf(monout, "%08lx: %08lx\t", mon_use_real_mem ? adr : adr % mon_mem_size, w); |
324 |
> |
fprintf(monout, "%08x: %08x\t", mon_use_real_mem ? adr : adr % mon_mem_size, w); |
325 |
|
disass_ppc(monout, mon_use_real_mem ? adr : adr % mon_mem_size, w); |
326 |
|
adr += 4; |
327 |
|
} |
332 |
|
uint8 op = mon_read_byte(adr); |
333 |
|
uint8 lo = mon_read_byte(adr + 1); |
334 |
|
uint8 hi = mon_read_byte(adr + 2); |
335 |
< |
fprintf(monout, "%08lx: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
335 |
> |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
336 |
|
adr += disass_6502(monout, mon_use_real_mem ? adr : adr % mon_mem_size, op, lo, hi); |
337 |
|
} |
338 |
|
break; |
339 |
|
|
340 |
|
case CPU_680x0: |
341 |
|
while (adr <= end_adr && !mon_aborted()) { |
342 |
< |
uint16 buf[8]; |
343 |
< |
buf[0] = mon_read_half(adr); |
313 |
< |
buf[1] = mon_read_half(adr + 2); |
314 |
< |
buf[2] = mon_read_half(adr + 4); |
315 |
< |
buf[3] = mon_read_half(adr + 6); |
316 |
< |
buf[4] = mon_read_half(adr + 8); |
317 |
< |
buf[5] = mon_read_half(adr + 10); |
318 |
< |
buf[6] = mon_read_half(adr + 12); |
319 |
< |
buf[7] = mon_read_half(adr + 14); |
320 |
< |
fprintf(monout, "%08lx: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
321 |
< |
adr += disass_68k(monout, mon_use_real_mem ? adr : adr % mon_mem_size, buf); |
342 |
> |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
343 |
> |
adr += disass_68k(monout, mon_use_real_mem ? adr : adr % mon_mem_size); |
344 |
|
} |
345 |
|
break; |
346 |
|
|
347 |
< |
case CPU_8080: |
347 |
> |
case CPU_Z80: |
348 |
|
while (adr <= end_adr && !mon_aborted()) { |
349 |
< |
uint8 op = mon_read_byte(adr); |
350 |
< |
uint8 lo = mon_read_byte(adr + 1); |
329 |
< |
uint8 hi = mon_read_byte(adr + 2); |
330 |
< |
fprintf(monout, "%08lx: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
331 |
< |
adr += disass_8080(monout, mon_use_real_mem ? adr : adr % mon_mem_size, op, lo, hi); |
349 |
> |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
350 |
> |
adr += disass_z80(monout, mon_use_real_mem ? adr : adr % mon_mem_size); |
351 |
|
} |
352 |
|
break; |
353 |
|
|
354 |
< |
case CPU_80x86: |
354 |
> |
case CPU_80x86_32: |
355 |
|
while (adr <= end_adr && !mon_aborted()) { |
356 |
< |
uint8 buf[16]; |
357 |
< |
for (int i=0; i<16; i++) |
358 |
< |
buf[i] = mon_read_byte(adr + i); |
359 |
< |
fprintf(monout, "%08lx: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
360 |
< |
adr += disass_x86(monout, mon_use_real_mem ? adr : adr % mon_mem_size, buf); |
356 |
> |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
357 |
> |
adr += disass_x86(monout, mon_use_real_mem ? adr : adr % mon_mem_size, false); |
358 |
> |
} |
359 |
> |
break; |
360 |
> |
|
361 |
> |
case CPU_80x86_16: |
362 |
> |
while (adr <= end_adr && !mon_aborted()) { |
363 |
> |
fprintf(monout, "%08x: ", mon_use_real_mem ? adr : adr % mon_mem_size); |
364 |
> |
adr += disass_x86(monout, mon_use_real_mem ? adr : adr % mon_mem_size, true); |
365 |
|
} |
366 |
|
break; |
367 |
|
} |
384 |
|
disassemble(CPU_680x0); |
385 |
|
} |
386 |
|
|
387 |
< |
void disassemble_8080(void) |
387 |
> |
void disassemble_z80(void) |
388 |
> |
{ |
389 |
> |
disassemble(CPU_Z80); |
390 |
> |
} |
391 |
> |
|
392 |
> |
void disassemble_80x86_32(void) |
393 |
|
{ |
394 |
< |
disassemble(CPU_8080); |
394 |
> |
disassemble(CPU_80x86_32); |
395 |
|
} |
396 |
|
|
397 |
< |
void disassemble_80x86(void) |
397 |
> |
void disassemble_80x86_16(void) |
398 |
|
{ |
399 |
< |
disassemble(CPU_80x86); |
399 |
> |
disassemble(CPU_80x86_16); |
400 |
|
} |
401 |
|
|
402 |
|
|
501 |
|
|
502 |
|
while (adr <= end_adr && !mon_aborted()) { |
503 |
|
if (mon_read_byte(adr) != mon_read_byte(dest)) { |
504 |
< |
fprintf(monout, "%08lx ", mon_use_real_mem ? adr : adr % mon_mem_size); |
504 |
> |
fprintf(monout, "%08x ", mon_use_real_mem ? adr : adr % mon_mem_size); |
505 |
|
num++; |
506 |
|
if (!(num & 7)) |
507 |
|
fputc('\n', monout); |
541 |
|
break; |
542 |
|
|
543 |
|
if (i == len) { |
544 |
< |
fprintf(monout, "%08lx ", mon_use_real_mem ? adr : adr % mon_mem_size); |
544 |
> |
fprintf(monout, "%08x ", mon_use_real_mem ? adr : adr % mon_mem_size); |
545 |
|
num++; |
546 |
|
if (num == 1) |
547 |
|
mon_dot_address = adr; |
593 |
|
mon_write_byte(adr++, fc); |
594 |
|
fclose(file); |
595 |
|
|
596 |
< |
fprintf(monerr, "%08lx bytes read from %08lx to %08lx\n", adr - start_adr, mon_use_real_mem ? start_adr : start_adr % mon_mem_size, mon_use_real_mem ? adr-1 : (adr-1) % mon_mem_size); |
596 |
> |
fprintf(monerr, "%08x bytes read from %08x to %08x\n", adr - start_adr, mon_use_real_mem ? start_adr : start_adr % mon_mem_size, mon_use_real_mem ? adr-1 : (adr-1) % mon_mem_size); |
597 |
|
mon_dot_address = adr; |
598 |
|
} |
599 |
|
} |
636 |
|
fputc(mon_read_byte(adr++), file); |
637 |
|
fclose(file); |
638 |
|
|
639 |
< |
fprintf(monerr, "%08lx bytes written from %08lx to %08lx\n", size, mon_use_real_mem ? start_adr : start_adr % mon_mem_size, mon_use_real_mem ? end_adr : end_adr % mon_mem_size); |
639 |
> |
fprintf(monerr, "%08x bytes written from %08x to %08x\n", size, mon_use_real_mem ? start_adr : start_adr % mon_mem_size, mon_use_real_mem ? end_adr : end_adr % mon_mem_size); |
640 |
|
} |
641 |
|
} |