From 494b59bcd2afa152bdae363053247009dac3dd78 Mon Sep 17 00:00:00 2001 From: Turingon Date: Thu, 5 Sep 2024 13:01:03 +0200 Subject: [PATCH] Skeleto de la operandlegilo preta --- disassembler.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/disassembler.c b/disassembler.c index 0e57314..ab72504 100644 --- a/disassembler.c +++ b/disassembler.c @@ -112,7 +112,7 @@ int disassemble8080(buffer* b, int pc, cJSON* json) { printf("\n"); - return opbytes; + return opbytes+1; } @@ -140,6 +140,28 @@ int disassemble8080(buffer* b, int pc, cJSON* json) { printf("Mnemnoic: %s\t", mnemonic); + // Extract and print operands + int operand_count = 0; + cJSON *operands = cJSON_GetObjectItem(command, "operands"); + + if (operands != NULL && cJSON_IsArray(operands)) { + + operand_count = cJSON_GetArraySize(operands); + printf("Number of operands: %d\n", operand_count); + for (int i = 0; i < operand_count; i++) { + cJSON *operand = cJSON_GetArrayItem(operands, i); + cJSON *name = cJSON_GetObjectItem(operand, "name"); + cJSON *bytes = cJSON_GetObjectItem(operand, "bytes"); + if (name != NULL && cJSON_IsString(name)) { + printf("Operand %d: %s", i + 1, name->valuestring); + } + if (bytes != NULL && cJSON_IsNumber(bytes)) { + printf(", Bytes: %d", bytes->valueint); + } + printf("\n"); + } + } + printf("\n"); return opbytes; @@ -162,7 +184,7 @@ void print_keys(cJSON *json) { int main (int argc, char** argv) { - int pc = 0x150; //Program Counter + int pc = 0x150; //Program Counter, note GB roms typically start at 0x100 buffer* buff = read_file(argv); if (buff == NULL) {