- Comença a vores el depurador

This commit is contained in:
2024-04-10 20:35:36 +02:00
parent 1dec5f7a30
commit 9a65ef3915
5 changed files with 101 additions and 19 deletions

View File

@@ -4,7 +4,7 @@
namespace z80dis
{
//char buffer[256];
char buffer[256];
int opcode_size = 0;
// $%04x
// $%02x
@@ -58,35 +58,47 @@ namespace z80dis
void printOpcode(const uint8_t *memory)
{
for (int i=0; i<4;++i) if (opcode_size>i) printf("%02x ", *(memory+i)); else printf(" ");
char hex[4];
for (int i=0; i<4;++i)
{
if (opcode_size>i)
sprintf(hex, "%02x ", *(memory+i));
else
sprintf(hex, " ");
strcat(buffer, hex);
}
}
void printAsm(const uint8_t *memory)
const char *getAsm(const uint8_t *memory, const bool include_opcode)
{
opcode_size = 0;
buffer[0]=0;
char txt[20];
const char *base = getBase(memory);
if (strstr(base, "4x")) {
opcode_size+=2;
printOpcode(memory);
const uint16_t word = *(uint16_t*)(memory+1);
printf(base, word);
sprintf(txt, base, word);
} else if (strstr(base, "2x")) {
opcode_size+=1;
printOpcode(memory);
printf(base, *(memory+1));
sprintf(txt, base, *(memory+1));
} else if (strstr(base, "hhd")) {
opcode_size+=1;
printOpcode(memory);
if (opcode_size>4) {
opcode_size=4;
printf(base, (int8_t)*(memory+2));
sprintf(txt, base, (int8_t)*(memory+2));
} else {
printf(base, (int8_t)*(memory+1));
sprintf(txt, base, (int8_t)*(memory+1));
}
} else {
printOpcode(memory);
printf(base);
sprintf(txt, base);
}
strcat(buffer, txt);
return buffer;
}
}