UINT32 debug_comment_get_opcode_crc32(offs_t address) { int i; UINT32 crc; UINT8 opbuf[64], argbuf[64]; char buff[256]; offs_t numbytes; int maxbytes = activecpu_max_instruction_bytes(); UINT32 addrmask = (debug_get_cpu_info(cpu_getactivecpu()))->space[ADDRESS_SPACE_PROGRAM].logaddrmask; int use_new_dasm = (activecpu_get_info_fct(CPUINFO_PTR_DISASSEMBLE_NEW) != NULL); memset(opbuf, 0x00, sizeof(opbuf)); memset(argbuf, 0x00, sizeof(argbuf)); // fetch the bytes up to the maximum for (i = 0; i < maxbytes; i++) { opbuf[i] = debug_read_opcode(address + i, 1, FALSE); argbuf[i] = debug_read_opcode(address + i, 1, TRUE); } if (use_new_dasm) { numbytes = cpunum_dasm_new(cpu_getactivecpu(), buff, address & addrmask, opbuf, argbuf, maxbytes) & DASMFLAG_LENGTHMASK; } else { numbytes = cpunum_dasm(cpu_getactivecpu(), buff, address & addrmask) & DASMFLAG_LENGTHMASK; } crc = crc32(0, argbuf, numbytes); return crc; }
offs_t activecpu_dasm(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram) { unsigned result; VERIFY_ACTIVECPU(activecpu_dasm); /* check for disassembler override */ if (cpu_dasm_override[activecpu]) { result = (*cpu_dasm_override[activecpu])(buffer, pc, oprom, opram); if (result != 0) return result; } if (cpu[activecpu].intf.disassemble != NULL) { result = (*cpu[activecpu].intf.disassemble)(buffer, pc, oprom, opram); } else { /* if no disassembler present, dump vanilla bytes */ switch (activecpu_min_instruction_bytes()) { case 1: default: sprintf(buffer, "$%02X", (unsigned) *((UINT8 *) oprom)); result = 1; break; case 2: sprintf(buffer, "$%04X", (unsigned) *((UINT16 *) oprom)); result = 2; break; case 4: sprintf(buffer, "$%08X", (unsigned) *((UINT32 *) oprom)); result = 4; break; } } /* make sure we get good results */ assert((result & DASMFLAG_LENGTHMASK) != 0); #ifdef MAME_DEBUG { int shift = activecpu_addrbus_shift(ADDRESS_SPACE_PROGRAM); int bytes = (shift < 0) ? ((result & DASMFLAG_LENGTHMASK) << -shift) : ((result & DASMFLAG_LENGTHMASK) >> shift); assert(bytes >= activecpu_min_instruction_bytes()); assert(bytes <= activecpu_max_instruction_bytes()); (void) bytes; /* appease compiler */ } #endif return result; }
offs_t activecpu_dasm(char *buffer, offs_t pc) { VERIFY_ACTIVECPU(activecpu_dasm); /* allow overrides */ if (cpu_dasm_override) { offs_t result = cpu_dasm_override(activecpu, buffer, pc); if (result) return result; } /* if there's no old-style assembler, do some work to make this call work with the new one */ if (!cpu[activecpu].intf.disassemble) { int dbwidth = activecpu_databus_width(ADDRESS_SPACE_PROGRAM); int maxbytes = activecpu_max_instruction_bytes(); int endianness = activecpu_endianness(); UINT8 opbuf[64], argbuf[64]; int xorval = 0; int numbytes; /* determine the XOR to get the bytes in order */ switch (dbwidth) { case 8: xorval = 0; break; case 16: xorval = (endianness == CPU_IS_LE) ? BYTE_XOR_LE(0) : BYTE_XOR_BE(0); break; case 32: xorval = (endianness == CPU_IS_LE) ? BYTE4_XOR_LE(0) : BYTE4_XOR_BE(0); break; case 64: xorval = (endianness == CPU_IS_LE) ? BYTE8_XOR_LE(0) : BYTE8_XOR_BE(0); break; } /* fetch the bytes up to the maximum */ memset(opbuf, 0xff, sizeof(opbuf)); memset(argbuf, 0xff, sizeof(argbuf)); for (numbytes = 0; numbytes < maxbytes; numbytes++) { offs_t physpc = pc + numbytes; const UINT8 *ptr; /* translate the address, set the opcode base, and apply the byte xor */ if (!cpu[activecpu].intf.translate || (*cpu[activecpu].intf.translate)(ADDRESS_SPACE_PROGRAM, &physpc)) { memory_set_opbase(physpc); physpc ^= xorval; /* get pointer to data */ ptr = memory_get_op_ptr(cpu_getactivecpu(), physpc, 0); if (ptr) { opbuf[numbytes] = *ptr; ptr = memory_get_op_ptr(cpu_getactivecpu(), physpc, 1); if (ptr) argbuf[numbytes] = *ptr; else argbuf[numbytes] = opbuf[numbytes]; } } } return activecpu_dasm_new(buffer, pc, opbuf, argbuf, maxbytes); } return (*cpu[activecpu].intf.disassemble)(buffer, pc); }