diff --git a/.vscode/settings.json b/.vscode/settings.json index bb879da..3e5eb95 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,7 +4,7 @@ "C_Cpp_Runner.debuggerPath": "gdb", "C_Cpp_Runner.cStandard": "", "C_Cpp_Runner.cppStandard": "", - "C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat", + "C_Cpp_Runner.msvcBatchPath": "", "C_Cpp_Runner.useMsvc": false, "C_Cpp_Runner.warnings": [ "-Wall", diff --git a/disassembler b/disassembler index 4300dcf..dd6a179 100755 Binary files a/disassembler and b/disassembler differ diff --git a/disassembler.c b/disassembler.c index a48d092..0e57314 100644 --- a/disassembler.c +++ b/disassembler.c @@ -87,12 +87,39 @@ int disassemble8080(buffer* b, int pc, cJSON* json) { sprintf(opcode_str, "0x%02X", *code); printf("%s\n", opcode_str); - // Here begins the cJSON part + + if (strcmp(opcode_str, "0xCB") == 0) { + printf("We have a prefixed command!\n"); + unsigned char *code = &(b->buffer[pc+1]); + + sprintf(opcode_str, "0x%02X", *code); + printf("%s\n", opcode_str); + + cJSON *prefixed = cJSON_GetObjectItem(json, "cbprefixed"); + if (unprefixed == NULL) { + printf("Error: 'unprefixed' not found in JSON.\n"); + return 0; + } + cJSON *command = cJSON_GetObjectItem(prefixed, opcode_str); + if (command == NULL) { + printf("Error: Command with opcode %s not found.\n", opcode_str); + return 0; + } + cJSON *mnemonic_item = cJSON_GetObjectItem(command, "mnemonic"); + cJSON *bytes_item = cJSON_GetObjectItem(command, "bytes"); + + printf("Mnemnoic: %s\t", mnemonic); + + + printf("\n"); + return opbytes; + + } cJSON *unprefixed = cJSON_GetObjectItem(json, "unprefixed"); if (unprefixed == NULL) { printf("Error: 'unprefixed' not found in JSON.\n"); - return 0; // We don't want to continue + return 0; } cJSON *command = cJSON_GetObjectItem(unprefixed, opcode_str); if (command == NULL) { @@ -110,13 +137,10 @@ int disassemble8080(buffer* b, int pc, cJSON* json) { if (bytes_item != NULL && cJSON_IsNumber(bytes_item)) { opbytes = bytes_item->valueint; } - // Here ends the cJSON part - printf("Number of Opbytes: %d ", opbytes); - printf("Mnemnoic: %s", mnemonic); - if (opbytes > 5 || opbytes < 1) { - opbytes = 1; - } + printf("Mnemnoic: %s\t", mnemonic); + + printf("\n"); return opbytes; } @@ -138,14 +162,14 @@ void print_keys(cJSON *json) { int main (int argc, char** argv) { - int pc = 0; //Program Counter + int pc = 0x150; //Program Counter buffer* buff = read_file(argv); if (buff == NULL) { printf("Fatal error.\n"); return 1; } - print_buffer(buff); + //print_buffer(buff); cJSON *json = read_cjson(); if (json == NULL) { @@ -156,7 +180,7 @@ int main (int argc, char** argv) { //print_keys(json); - while (pc < 400) {//buff->length) { + while (pc < 0x400) {//buff->length) { pc += disassemble8080(buff, pc, json); } free(buff);