--- uae/src/debug.c 2018/04/24 16:39:56 1.1.1.3 +++ uae/src/debug.c 2018/04/24 16:42:04 1.1.1.4 @@ -31,7 +31,7 @@ static uaecptr skipaddr; static int do_skip; int debugging = 0; -void activate_debugger(void) +void activate_debugger (void) { do_skip = 0; if (debugger_active) @@ -51,19 +51,19 @@ union flagu historyf[MAX_HIST]; uaecptr history[MAX_HIST]; #endif -static void ignore_ws(char **c) +static void ignore_ws (char **c) { while (**c && isspace(**c)) (*c)++; } -static uae_u32 readhex(char **c) +static uae_u32 readhex (char **c) { uae_u32 val = 0; char nc; - ignore_ws(c); + ignore_ws (c); - while (isxdigit(nc = **c)){ + while (isxdigit(nc = **c)) { (*c)++; val *= 16; nc = toupper(nc); @@ -76,28 +76,28 @@ static uae_u32 readhex(char **c) return val; } -static char next_char(char **c) +static char next_char( char **c) { - ignore_ws(c); + ignore_ws (c); return *(*c)++; } -static int more_params(char **c) +static int more_params (char **c) { - ignore_ws(c); + ignore_ws (c); return (**c) != 0; } -static void dumpmem(uaecptr addr, uaecptr *nxmem, int lines) +static void dumpmem (uaecptr addr, uaecptr *nxmem, int lines) { broken_in = 0; - for (;lines-- && !broken_in;){ + for (;lines-- && !broken_in;) { int i; - printf("%08lx ", addr); - for(i=0; i< 16; i++) { - printf("%04x ", get_word(addr)); addr += 2; + printf ("%08lx ", addr); + for (i = 0; i < 16; i++) { + printf ("%04x ", get_word(addr)); addr += 2; } - printf("\n"); + printf ("\n"); } *nxmem = addr; } @@ -122,18 +122,18 @@ static void foundmod (uae_u32 ptr, char /* Add sample lengths */ ptr2 += 0x2A; - for(i = 0; i < 31; i++, ptr2 += 30) + for (i = 0; i < 31; i++, ptr2 += 30) length += 2*((ptr2[0]<<8)+ptr2[1]); - printf("Name \"%s\", Length 0x%lx bytes.\n", name, length); + printf ("Name \"%s\", Length 0x%lx bytes.\n", name, length); } -static void modulesearch(void) +static void modulesearch (void) { uae_u8 *p = get_real_address (0); uae_u32 ptr; - for (ptr = 0; ptr < chipmem_size - 40; ptr += 2, p += 2) { + for (ptr = 0; ptr < allocated_chipmem - 40; ptr += 2, p += 2) { /* Check for Mahoney & Kaktus */ /* Anyone got the format of old 15 Sample (SoundTracker)modules? */ if (ptr >= 0x438 && p[0] == 'M' && p[1] == '.' && p[2] == 'K' && p[3] == '.') @@ -172,9 +172,110 @@ static void modulesearch(void) } } -void debug(void) +/* cheat-search by Holger Jakob */ +static void cheatsearch (char **c) +{ + uae_u8 *p = get_real_address (0); + static uae_u32 *vlist = NULL; + uae_u32 ptr; + uae_u32 val = 0; + uae_u32 type = 0; /* not yet */ + uae_u32 count = 0; + uae_u32 fcount = 0; + uae_u32 full = 0; + char nc; + + ignore_ws (c); + + while (isxdigit (nc = **c)) { + (*c)++; + val *= 10; + nc = toupper (nc); + if (isdigit (nc)) { + val += nc - '0'; + } + } + if (vlist == NULL) { + vlist = malloc (256*4); + if (vlist != 0) { + for (count = 0; count<255; count++) + vlist[count] = 0; + count = 0; + for (ptr = 0; ptr < allocated_chipmem - 40; ptr += 2, p += 2) { + if (ptr >= 0x438 && p[3] == (val & 0xff) + && p[2] == (val >> 8 & 0xff) + && p[1] == (val >> 16 & 0xff) + && p[0] == (val >> 24 & 0xff)) + { + if (count < 255) { + vlist[count++]=ptr; + printf ("%08x: %x%x%x%x\n",ptr,p[0],p[1],p[2],p[3]); + } else + full = 1; + } + } + printf ("Found %d possible addresses with %d\n",count,val); + printf ("Now continue with 'g' and use 'C' with a different value\n"); + } + } else { + for (count = 0; count<255; count++) { + if (p[vlist[count]+3] == (val & 0xff) + && p[vlist[count]+2] == (val>>8 & 0xff) + && p[vlist[count]+1] == (val>>16 & 0xff) + && p[vlist[count]] == (val>>24 & 0xff)) + { + fcount++; + printf ("%08x: %x%x%x%x\n", vlist[count], p[vlist[count]], + p[vlist[count]+1], p[vlist[count]+2], p[vlist[count]+3]); + } + } + printf ("%d hits of %d found\n",fcount,val); + free (vlist); + vlist = NULL; + } +} + +static void writeintomem (char **c) +{ + uae_u8 *p = get_real_address (0); + uae_u32 addr = 0; + uae_u32 val = 0; + char nc; + + ignore_ws(c); + while (isxdigit(nc = **c)) { + (*c)++; + addr *= 16; + nc = toupper(nc); + if (isdigit(nc)) { + addr += nc - '0'; + } else { + addr += nc - 'A' + 10; + } + } + ignore_ws(c); + while (isxdigit(nc = **c)) { + (*c)++; + val *= 10; + nc = toupper(nc); + if (isdigit(nc)) { + val += nc - '0'; + } + } + + if (addr < allocated_chipmem) { + p[addr] = val>>24 & 0xff; + p[addr+1] = val>>16 & 0xff; + p[addr+2] = val>>8 & 0xff; + p[addr+3] = val & 0xff; + printf("Wrote %d at %08x\n",val,addr); + } else + printf("Invalid address %08x\n",addr); +} + +void debug (void) { - char input[80],c; + char input[80]; uaecptr nextpc,nxdis,nxmem; bogusframe = 1; @@ -196,22 +297,24 @@ void debug(void) if (++firsthist == MAX_HIST) firsthist = 0; } - m68k_dumpstate(&nextpc); + m68k_dumpstate (&nextpc); nxdis = nextpc; nxmem = 0; - for(;;){ - char cmd,*inptr; + for (;;) { + char cmd, *inptr; - printf(">"); + printf (">"); fflush (stdout); - if (fgets(input, 80, stdin) == 0) + if (fgets (input, 80, stdin) == 0) return; inptr = input; - cmd = next_char(&inptr); - switch(cmd){ - case 'c': dumpcia(); dumpcustom(); break; - case 'r': m68k_dumpstate(&nextpc); break; - case 'M': modulesearch(); break; + cmd = next_char (&inptr); + switch (cmd) { + case 'c': dumpcia (); dumpcustom (); break; + case 'r': m68k_dumpstate (&nextpc); break; + case 'M': modulesearch (); break; + case 'C': cheatsearch (&inptr); break; + case 'W': writeintomem (&inptr); break; case 'S': { uae_u8 *memp; @@ -362,6 +465,8 @@ void debug(void) printf (" f
: Step forward until PC ==
\n"); printf (" H : Show PC history instructions\n"); printf (" M: Search for *Tracker sound modules\n"); + printf (" C : Search for values like energy or lifes in games\n"); + printf (" W
: Write into Amiga memory\n"); printf (" S : Save a block of Amiga memory\n"); printf (" h,?: Show this help page\n"); printf (" q: Quit the emulator. You don't want to use this command.\n\n");