From e021a622b4ede131ac41f574cdd38e36f04124d8 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Mon, 20 Aug 2018 13:03:53 -0400 Subject: [PATCH] adds two new WDM debugger commands useful for programmers. WDM $a0 prints a string a: string type (0 = c-string, 1 = pascal string, 2 = gs/os string). set bit 15 ($8000) to add a trailing '\n x/y: pointer to the string WDM $a1 hexdumps memory a: length x/y pointer to memory (in both cases, x is the low word and y is the high word (ie, bank)) --- src/sim65816.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/src/sim65816.c b/src/sim65816.c index f9197e0..8a209c6 100644 --- a/src/sim65816.c +++ b/src/sim65816.c @@ -6,6 +6,8 @@ */ #include +#include + #include "defc.h" #include "printer.h" #include "imagewriter.h" @@ -2517,6 +2519,78 @@ do_mvn(word32 banks) extern void host_fst(void); +static void wdm_print() { + /* x:y is ptr to cstring to print, a is type of string */ + /* 0 = cstring, 1 = pstring, 2 = gsosstring, $8000 is add \n */ + + word32 address = engine.xreg + (engine.yreg << 16); + word16 type = engine.acc; + char c; + int length; + + if (address) switch (type & 0xff){ + case 0: + while ((c = get_memory_c(address++, 0))) { + fputc(c, stdout); + } + break; + + case 1: + length = get_memory_c(address++, 0); + while (length--) { + c = get_memory_c(address++, 0); + fputc(c, stdout); + } + break; + + case 2: + length = get_memory16_c(address, 0); + address += 2; + while (length--) { + c = get_memory_c(address++, 0); + fputc(c, stdout); + } + break; + } + if (type & 0x8000) fputc('\n', stdout); +} + +static void wdm_hexdump() { + /* x:y is ptr to memory, a is length */ + word32 count = engine.acc; + word32 address = engine.xreg + (engine.yreg << 16); + if (address && count) { + + static char hex[] = "0123456789abcdef"; + char buffer1[16*3+1]; + char buffer2[16+1]; + byte b; + int i, j; + while (count) { + + memset(buffer1, ' ', sizeof(buffer1)-1); + memset(buffer2, ' ', sizeof(buffer2)-1); + buffer1[48] = 0; + buffer2[16] = 0; + + int xx = 16; + if (count < 16) xx = count; + for (i = 0, j = 0; i < xx; ++i) { + b = get_memory_c(address + i, 0); + buffer1[j++] = hex[b >> 4]; + buffer1[j++] = hex[b & 0x0f]; + buffer1[j++] = ' '; + b &= 0x7f; /* support high ascii */ + buffer2[i] = isprint(b) ? b : '.'; + + } + printf("%06x %s%s\n", address, buffer1, buffer2); + count -= xx; + address += xx; + } + } +} + void do_wdm(word32 arg) { @@ -2524,6 +2598,23 @@ do_wdm(word32 arg) case 0x8d: /* Bouncin Ferno does WDM 8d */ break; + + /* 0xAx range can be used for debugging, etc */ + + case 0xa0: /* print */ + wdm_print(); + break; + + case 0xa1: /* hexdump */ + wdm_hexdump(); + break; + + + /* 0xFx shouldn't be called unless you know what you're doing */ + + case 0xfe: /* used for ModemWorks branch */ + break; + case 0xff: /* fst */ host_fst(); break;