diff --git a/include/apple2.hires.h b/include/apple2.hires.h index 0042bb8..5a28188 100644 --- a/include/apple2.hires.h +++ b/include/apple2.hires.h @@ -5,5 +5,6 @@ #include "vm_bits.h" extern void apple2_hires_draw(apple2 *, int); +extern void apple2_hires_dump(apple2 *, FILE *); #endif diff --git a/include/vm_debug.h b/include/vm_debug.h index 21cf246..fba4d2f 100644 --- a/include/vm_debug.h +++ b/include/vm_debug.h @@ -82,6 +82,7 @@ extern DEBUG_CMD(dblock); extern DEBUG_CMD(disasm); extern DEBUG_CMD(hdump); extern DEBUG_CMD(help); +extern DEBUG_CMD(hidump); extern DEBUG_CMD(jump); extern DEBUG_CMD(printaddr); extern DEBUG_CMD(printstate); diff --git a/src/apple2.hires.c b/src/apple2.hires.c index 476655b..4d51d4f 100644 --- a/src/apple2.hires.c +++ b/src/apple2.hires.c @@ -705,3 +705,47 @@ apple2_hires_draw(apple2 *mach, int row) prev = curr; } } + +void +apple2_hires_dump(apple2 *mach, FILE *stream) +{ + int row, col, base, bit; + char dotsym; + vm_8bit byte; + + fprintf(stream, "HIRES DUMP\n\nBytes:\n"); + + for (row = 0; row < 192; row++) { + base = addresses[row]; + + fprintf(stream, "%3d [", row); + + for (col = 0; col < 40; col++) { + fprintf(stream, "%02X", mos6502_get(mach->cpu, base + col)); + + if (col < 39) { + fprintf(stream, " "); + } + } + + fprintf(stream, "]\n"); + } + + fprintf(stream, "\nDots:\n"); + + for (row = 0; row < 192; row++) { + base = addresses[row]; + + fprintf(stream, "%3d [", row); + + for (col = 0; col < 40; col++) { + byte = mos6502_get(mach->cpu, base + col); + dotsym = (byte & 0x80) ? '#' : '%'; + for (bit = 0; bit < 7; bit++) { + fprintf(stream, "%c", ((byte >> bit) & 1) ? dotsym : '_'); + } + } + + fprintf(stream, "]\n"); + } +} diff --git a/src/vm_debug.c b/src/vm_debug.c index 5c9d071..2c58f4e 100644 --- a/src/vm_debug.c +++ b/src/vm_debug.c @@ -10,6 +10,7 @@ #include #include "apple2.h" +#include "apple2.hires.h" #include "mos6502.h" #include "mos6502.dis.h" #include "vm_debug.h" @@ -43,6 +44,8 @@ vm_debug_cmd cmdtable[] = { "Print out this list of commands", }, { "hdump", "hd", vm_debug_cmd_hdump, 2, " ", "Hex dump memory in a given region", }, + { "hidump", "hid", vm_debug_cmd_hidump, 1, "", + "Dump hires graphics memory to file", }, { "jump", "j", vm_debug_cmd_jump, 1, "", "Jump to for next execution", }, { "printaddr", "pa", vm_debug_cmd_printaddr, 1, "", @@ -245,13 +248,8 @@ vm_debug_execute(const char *str) break; case 1: - args.addr1 = vm_debug_addr(vm_debug_next_arg(&ebuf)); - - // Oh no - if (args.addr1 == -1) { - free(orig); - return; - } + args.target = vm_debug_next_arg(&ebuf); + args.addr1 = vm_debug_addr(args.target); break; @@ -471,3 +469,18 @@ DEBUG_CMD(hdump) vm_segment_hexdump(cpu->rmem, stream, args->addr1, args->addr2); } + +DEBUG_CMD(hidump) +{ + FILE *stream; + + stream = fopen(args->target, "w"); + if (stream == NULL) { + return; + } + + apple2 *mach = (apple2 *)vm_di_get(VM_MACHINE); + apple2_hires_dump(mach, stream); + + fclose(stream); +}