diff --git a/disassembler b/disassembler index d8c1617..4300dcf 100755 Binary files a/disassembler and b/disassembler differ diff --git a/disassembler.c b/disassembler.c index d02703e..a48d092 100644 --- a/disassembler.c +++ b/disassembler.c @@ -83,6 +83,10 @@ int disassemble8080(buffer* b, int pc, cJSON* json) { printf("%04x ", pc); char mnemonic[10]; + char opcode_str[5]; + sprintf(opcode_str, "0x%02X", *code); + printf("%s\n", opcode_str); + // Here begins the cJSON part cJSON *unprefixed = cJSON_GetObjectItem(json, "unprefixed"); @@ -90,9 +94,9 @@ int disassemble8080(buffer* b, int pc, cJSON* json) { printf("Error: 'unprefixed' not found in JSON.\n"); return 0; // We don't want to continue } - cJSON *command = cJSON_GetObjectItem(unprefixed, code); + cJSON *command = cJSON_GetObjectItem(unprefixed, opcode_str); if (command == NULL) { - printf("Error: Command with opcode %s not found.\n", code); + printf("Error: Command with opcode %s not found.\n", opcode_str); return 0; } cJSON *mnemonic_item = cJSON_GetObjectItem(command, "mnemonic"); @@ -117,6 +121,20 @@ int disassemble8080(buffer* b, int pc, cJSON* json) { return opbytes; } +void print_keys(cJSON *json) { + // Used only for debug purposes + // Lists all the keys + cJSON *unprefixed = cJSON_GetObjectItem(json, "unprefixed"); + if (unprefixed == NULL) { + printf("Error: 'unprefixed' not found in JSON.\n"); + return; + } + + cJSON *item = NULL; + cJSON_ArrayForEach(item, unprefixed) { + printf("Key: %s\n", item->string); + } +} int main (int argc, char** argv) { @@ -135,6 +153,8 @@ int main (int argc, char** argv) { return 1; } + //print_keys(json); + while (pc < 400) {//buff->length) { pc += disassemble8080(buff, pc, json); @@ -142,5 +162,4 @@ int main (int argc, char** argv) { free(buff); cJSON_Delete(json); // basically free(json) return 0; - } \ No newline at end of file