-Anem a usar ncurses

This commit is contained in:
2024-04-10 14:36:17 +02:00
parent d1982fc8b5
commit 1dec5f7a30
6 changed files with 89 additions and 16 deletions

View File

@@ -4,8 +4,8 @@
namespace z80dis
{
char buffer[256];
//char buffer[256];
int opcode_size = 0;
// $%04x
// $%02x
// %hhd
@@ -29,42 +29,64 @@ namespace z80dis
const char *getBase(const uint8_t *memory)
{
if (*memory == 0xCB) {
opcode_size=2;
return cb_opcodes[*(memory+1)];
} else if (*memory == 0xDD) {
if (*(memory+1) == 0xCB) {
opcode_size=4;
return ix_bit_opcodes[*(memory+3)];
} else {
opcode_size=2;
return ix_opcodes[*(memory+1)];
}
} else if (*memory == 0xED) {
opcode_size=2;
return misc_opcodes[(*(memory+1))-64];
} else if (*memory == 0xFD) {
if (*(memory+1) == 0xCB) {
opcode_size=4;
return iy_bit_opcodes[*(memory+3)];
} else {
opcode_size=2;
return iy_opcodes[*(memory+1)];
}
} else {
opcode_size=1;
return base_opcodes[*memory];
}
}
const char *getAsm(const uint8_t *memory)
void printOpcode(const uint8_t *memory)
{
for (int i=0; i<4;++i) if (opcode_size>i) printf("%02x ", *(memory+i)); else printf(" ");
}
void printAsm(const uint8_t *memory)
{
opcode_size = 0;
const char *base = getBase(memory);
if (strstr(base, "4x")) {
opcode_size+=2;
printOpcode(memory);
const uint16_t word = *(uint16_t*)(memory+1);
sprintf(buffer, base, word);
return buffer;
printf(base, word);
} else if (strstr(base, "2x")) {
sprintf(buffer, base, *(memory+1));
return buffer;
opcode_size+=1;
printOpcode(memory);
printf(base, *(memory+1));
} else if (strstr(base, "hhd")) {
sprintf(buffer, base, (int8_t)*(memory+1));
return buffer;
opcode_size+=1;
printOpcode(memory);
if (opcode_size>4) {
opcode_size=4;
printf(base, (int8_t)*(memory+2));
} else {
printf(base, (int8_t)*(memory+1));
}
} else {
return base;
printOpcode(memory);
printf(base);
}
}
}