Masiva progreso

This commit is contained in:
Turingon 2024-08-28 19:48:32 +02:00
parent 70255ed9ef
commit 454519105a
2 changed files with 22 additions and 3 deletions

Binary file not shown.

View file

@ -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;
}