Пример #1
0
int m7700_disassemble(char* buff, unsigned int pc, unsigned int pb, int m_flag, int x_flag)
{
	unsigned int instruction;
	opcode_struct *opcode;
	char* ptr;
	int var;
	signed char varS;
	int length = 1;
	unsigned int address;

	pb <<= 16;
	address = pc | pb;

	instruction = read_8(address);

	// check for prefixes
	switch (instruction)
	{
		case 0x42:
			address++;
			length++;
			instruction = read_8(address);
			opcode = g_opcodes_prefix42 + instruction;
			break;

		case 0x89:
			address++;
			length++;
			instruction = read_8(address);
			opcode = g_opcodes_prefix89 + instruction;
			break;

		default:
			opcode = g_opcodes + instruction;
			break;
	}

	sprintf(buff, "%s", g_opnames[opcode->name]);
	ptr = buff + strlen(buff);

	switch(opcode->ea)
	{
		case IMP :
			break;
		case ACC :
			sprintf(ptr, " A");
			break;
		case ACCB :
			sprintf(ptr, " B");
			break;
		case RELB:
			varS = read_8(address+1);
			length++;
			sprintf(ptr, " %06x (%s)", pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			break;
		case RELW:
		case PER :
			var = read_16(address+1);
			sprintf(ptr, " %06x (%s)", pb | ((pc + 1 + var)&0xffff), int_16_str(var));
			length += 2;
			break;
		case IMM :
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x", read_16(address+1));
				length += 2;
			}
			else
			{
				sprintf(ptr, " #$%02x", read_8(address+1));
				length++;
			}
			break;
		case BBCD:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				varS = read_8(address+4);
				length += 4;
				sprintf(ptr, " #$%04x, $%02x, %06x (%s)", read_16(address+2), read_8(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			else
			{
				varS = read_8(address+3);
				length += 3;
				sprintf(ptr, " #$%02x, $%02x, %06x (%s)", read_8(address+2), read_8(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			break;
		case BBCA:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				length += 5;
				varS = read_8(address+5);
				sprintf(ptr, " #$%04x, $%04x, %06x (%s)", read_16(address+3), read_16(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			else
			{
				length += 4;
				varS = read_8(address+4);
				sprintf(ptr, " #$%02x, $%04x, %06x (%s)", read_8(address+3), read_16(address+1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			break;
		case LDM4:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%02x", read_16(address+2), read_8(address+1));
				length += 3;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%02x", read_8(address+2), read_8(address+1));
				length += 2;
			}
			break;
		case LDM5:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%04x", read_16(address+3), read_16(address+1));
				length += 4;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%04x", read_8(address+3), read_16(address+1));
				length += 3;
			}
			break;
		case LDM4X:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%02x, X", read_16(address+2), read_8(address+1));
				length += 3;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%02x, X", read_8(address+2), read_8(address+1));
				length += 2;
			}
			break;
		case LDM5X:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%04x, X", read_16(address+3), read_16(address+1));
				length += 4;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%04x, X", read_8(address+3), read_16(address+1));
				length += 3;
			}
			break;
		case A   :
		case PEA :
			sprintf(ptr, " $%04x", read_16(address+1));
			length += 2;
			break;
		case AI  :
			sprintf(ptr, " ($%04x)", read_16(address+1));
			length += 2;
			break;
		case AL  :
			sprintf(ptr, " $%06x", read_24(address+1));
			length += 3;
			break;
		case ALX :
			sprintf(ptr, " $%06x,X", read_24(address+1));
			length += 3;
			break;
		case AX  :
			sprintf(ptr, " $%04x,X", read_16(address+1));
			length += 2;
			break;
		case AXI :
			sprintf(ptr, " ($%04x,X)", read_16(address+1));
			length += 2;
			break;
		case AY  :
			sprintf(ptr, " $%04x,Y", read_16(address+1));
			length += 2;
			break;
		case D   :
			sprintf(ptr, " $%02x", read_8(address+1));
			length++;
			break;
		case DI  :
		case PEI :
			sprintf(ptr, " ($%02x)", read_8(address+1));
			length++;
			break;
		case DIY :
			sprintf(ptr, " ($%02x),Y", read_8(address+1));
			length++;
			break;
		case DLI :
			sprintf(ptr, " [$%02x]", read_8(address+1));
			length++;
			break;
		case DLIY:
			sprintf(ptr, " [$%02x],Y", read_8(address+1));
			length++;
			break;
		case DX  :
			sprintf(ptr, " $%02x,X", read_8(address+1));
			length++;
			break;
		case DXI :
			sprintf(ptr, " ($%02x,X)", read_8(address+1));
			length++;
			break;
		case DY  :
			sprintf(ptr, " $%02x,Y", read_8(address+1));
			length++;
			break;
		case S   :
			sprintf(ptr, " %s,S", int_8_str(read_8(address+1)));
			length++;
			break;
		case SIY :
			sprintf(ptr, " (%s,S),Y", int_8_str(read_8(address+1)));
			length++;
			break;
		case SIG :
			sprintf(ptr, " #$%02x", read_8(address+1));
			length++;
			break;
		case MVN :
		case MVP :
			sprintf(ptr, " $%02x, $%02x", read_8(address+2), read_8(address+1));
			length += 2;
			break;
	}

	return length;
}
Пример #2
0
unsigned g65816_disassemble(char* buff, unsigned int pc, unsigned int pb, const UINT8 *oprom, int m_flag, int x_flag)
{
	unsigned int instruction;
	const opcode_struct* opcode;
	char* ptr;
	int var;
	int length = 1;
	unsigned int address;
	unsigned dasm_flags;

	pb <<= 16;
	address = pc | pb;

	base_oprom = oprom;
	base_pc = address;

	instruction = read_8(address);
	opcode = g_opcodes + instruction;

	strcpy(buff, g_opnames[opcode->name]);
	ptr = buff + strlen(buff);

	switch(opcode->name)
	{
		case JSR:
		case JSL:
			dasm_flags = DASMFLAG_STEP_OVER;
			break;

		case RTI:
		case RTL:
		case RTS:
			dasm_flags = DASMFLAG_STEP_OUT;
			break;

		default:
			dasm_flags = 0;
			break;
	}

	switch(opcode->ea)
	{
		case IMP :
			break;
		case ACC :
			sprintf(ptr, "A");
			break;
		case RELB:
			var = (INT8) read_8(address+1);
			length++;
			sprintf(ptr, " %06x (%s)", pb | ((pc + length + var)&0xffff), int_8_str(var));
			break;
		case RELW:
		case PER :
			var = read_16(address+1);
			sprintf(ptr, " %06x (%s)", pb | ((pc + 1 + var)&0xffff), int_16_str(var));
			length += 2;
			break;
		case IMM :
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x", read_16(address+1));
				length += 2;
			}
			else
			{
				sprintf(ptr, " #$%02x", read_8(address+1));
				length++;
			}
			break;
		case A   :
		case PEA :
			sprintf(ptr, " $%04x", read_16(address+1));
			length += 2;
			break;
		case AI  :
			sprintf(ptr, " ($%04x)", read_16(address+1));
			length += 2;
			break;
		case AL  :
			sprintf(ptr, " $%06x", read_24(address+1));
			length += 3;
			break;
		case ALX :
			sprintf(ptr, " $%06x,X", read_24(address+1));
			length += 3;
			break;
		case AX  :
			sprintf(ptr, " $%04x,X", read_16(address+1));
			length += 2;
			break;
		case AXI :
			sprintf(ptr, " ($%04x,X)", read_16(address+1));
			length += 2;
			break;
		case AY  :
			sprintf(ptr, " $%04x,Y", read_16(address+1));
			length += 2;
			break;
		case D   :
			sprintf(ptr, " $%02x", read_8(address+1));
			length++;
			break;
		case DI  :
		case PEI :
			sprintf(ptr, " ($%02x)", read_8(address+1));
			length++;
			break;
		case DIY :
			sprintf(ptr, " ($%02x),Y", read_8(address+1));
			length++;
			break;
		case DLI :
			sprintf(ptr, " [$%02x]", read_8(address+1));
			length++;
			break;
		case DLIY:
			sprintf(ptr, " [$%02x],Y", read_8(address+1));
			length++;
			break;
		case DX  :
			sprintf(ptr, " $%02x,X", read_8(address+1));
			length++;
			break;
		case DXI :
			sprintf(ptr, " ($%02x,X)", read_8(address+1));
			length++;
			break;
		case DY  :
			sprintf(ptr, " $%02x,Y", read_8(address+1));
			length++;
			break;
		case S   :
			sprintf(ptr, " %s,S", int_8_str(read_8(address+1)));
			length++;
			break;
		case SIY :
			sprintf(ptr, " (%s,S),Y", int_8_str(read_8(address+1)));
			length++;
			break;
		case SIG :
			sprintf(ptr, " #$%02x", read_8(address+1));
			length++;
			break;
		case MVN :
		case MVP :
			sprintf(ptr, " $%02x, $%02x", read_8(address+2), read_8(address+1));
			length += 2;
			break;
	}

	return length | DASMFLAG_SUPPORTED | dasm_flags;
}
Пример #3
0
int m7700_disassemble(char* buff, unsigned int pc, unsigned int pb, const UINT8 *oprom, int m_flag, int x_flag)
{
	unsigned int instruction;
	const m7700_opcode_struct *opcode;
	char* ptr;
	int var;
	signed char varS;
	int length = 1;
	unsigned int address;
	//unsigned int start;
	UINT32 flags = 0;

	pb <<= 16;
	address = pc | pb;
	//start = address;

	instruction = read_8(oprom,0);

	// check for prefixes
	switch (instruction)
	{
	case 0x42:
		address++;
		length++;
		oprom++;
		instruction = read_8(oprom,0);
		opcode = &m7700_opcode_struct::get_prefix42(instruction);
		break;

	case 0x89:
		address++;
		length++;
		oprom++;
		instruction = read_8(oprom,0);
		opcode = &m7700_opcode_struct::get_prefix89(instruction);
		break;

	default:
		opcode = &m7700_opcode_struct::get(instruction);
		break;
	}

	if (opcode->is_call())
		flags = DASMFLAG_STEP_OVER;
	else if (opcode->is_return())
		flags = DASMFLAG_STEP_OUT;

	sprintf(buff, "%s", opcode->name());
	ptr = buff + strlen(buff);

	switch(opcode->ea)
	{
		case IMP :
			break;
		case ACC :
			sprintf(ptr, " A");
			break;
		case ACCB :
			sprintf(ptr, " B");
			break;
		case RELB:
			varS = read_8(oprom,1);
			length++;
			sprintf(ptr, " %06x (%s)", pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			break;
		case RELW:
		case PER :
			var = read_16(oprom,1);
			length += 2;
			sprintf(ptr, " %06x (%s)", pb | ((pc + length + var)&0xffff), int_16_str(var));
			break;
		case IMM :
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x", read_16(oprom,1));
				length += 2;
			}
			else
			{
				sprintf(ptr, " #$%02x", read_8(oprom,1));
				length++;
			}
			break;
		case BBCD:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				varS = read_8(oprom,4);
				length += 4;
				sprintf(ptr, " #$%04x, $%02x, %06x (%s)", read_16(oprom,2), read_8(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			else
			{
				varS = read_8(oprom,3);
				length += 3;
				sprintf(ptr, " #$%02x, $%02x, %06x (%s)", read_8(oprom,2), read_8(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			break;
		case BBCA:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				length += 5;
				varS = read_8(oprom,5);
				sprintf(ptr, " #$%04x, $%04x, %06x (%s)", read_16(oprom,3), read_16(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			else
			{
				length += 4;
				varS = read_8(oprom,4);
				sprintf(ptr, " #$%02x, $%04x, %06x (%s)", read_8(oprom,3), read_16(oprom,1), pb | ((pc + length + varS)&0xffff), int_8_str(varS));
			}
			break;
		case LDM4:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%02x", read_16(oprom,2), read_8(oprom,1));
				length += 3;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%02x", read_8(oprom,2), read_8(oprom,1));
				length += 2;
			}
			break;
		case LDM5:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%04x", read_16(oprom,3), read_16(oprom,1));
				length += 4;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%04x", read_8(oprom,3), read_16(oprom,1));
				length += 3;
			}
			break;
		case LDM4X:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%02x, X", read_16(oprom,2), read_8(oprom,1));
				length += 3;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%02x, X", read_8(oprom,2), read_8(oprom,1));
				length += 2;
			}
			break;
		case LDM5X:
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x, $%04x, X", read_16(oprom,3), read_16(oprom,1));
				length += 4;
			}
			else
			{
				sprintf(ptr, " #$%02x, $%04x, X", read_8(oprom,3), read_16(oprom,1));
				length += 3;
			}
			break;
		case A   :
		case PEA :
			sprintf(ptr, " $%04x", read_16(oprom,1));
			length += 2;
			break;
		case AI  :
			sprintf(ptr, " ($%04x)", read_16(oprom,1));
			length += 2;
			break;
		case AL  :
			sprintf(ptr, " $%06x", read_24(oprom,1));
			length += 3;
			break;
		case ALX :
			sprintf(ptr, " $%06x,X", read_24(oprom,1));
			length += 3;
			break;
		case AX  :
			sprintf(ptr, " $%04x,X", read_16(oprom,1));
			length += 2;
			break;
		case AXI :
			sprintf(ptr, " ($%04x,X)", read_16(oprom,1));
			length += 2;
			break;
		case AY  :
			sprintf(ptr, " $%04x,Y", read_16(oprom,1));
			length += 2;
			break;
		case D   :
			sprintf(ptr, " $%02x", read_8(oprom,1));
			length++;
			break;
		case DI  :
		case PEI :
			sprintf(ptr, " ($%02x)", read_8(oprom,1));
			length++;
			break;
		case DIY :
			sprintf(ptr, " ($%02x),Y", read_8(oprom,1));
			length++;
			break;
		case DLI :
			sprintf(ptr, " [$%02x]", read_8(oprom,1));
			length++;
			break;
		case DLIY:
			sprintf(ptr, " [$%02x],Y", read_8(oprom,1));
			length++;
			break;
		case DX  :
			sprintf(ptr, " $%02x,X", read_8(oprom,1));
			length++;
			break;
		case DXI :
			sprintf(ptr, " ($%02x,X)", read_8(oprom,1));
			length++;
			break;
		case DY  :
			sprintf(ptr, " $%02x,Y", read_8(oprom,1));
			length++;
			break;
		case S   :
			sprintf(ptr, " %s,S", int_8_str(read_8(oprom,1)));
			length++;
			break;
		case SIY :
			sprintf(ptr, " (%s,S),Y", int_8_str(read_8(oprom,1)));
			length++;
			break;
		case SIG :
			sprintf(ptr, " #$%02x", read_8(oprom,1));
			length++;
			break;
		case MVN :
		case MVP :
			sprintf(ptr, " $%02x, $%02x", read_8(oprom,2), read_8(oprom,1));
			length += 2;
			break;
	}

	return length | flags | DASMFLAG_SUPPORTED;
}
Пример #4
0
int g65816_disassemble(char* buff, unsigned int pc, unsigned int pb, int m_flag, int x_flag)
{
	unsigned int instruction;
	opcode_struct* opcode;
	char* ptr;
	int var;
	int length = 1;
	unsigned int address;

	pb <<= 16;
	address = pc | pb;

	instruction = read_8(address);
	opcode = g_opcodes + instruction;

	strcpy(buff, g_opnames[opcode->name]);
	ptr = buff + strlen(buff);

	switch(opcode->ea)
	{
		case IMP :
			break;
		case ACC :
			sprintf(ptr, "A");
			break;
		case RELB:
			var = read_8(address+1);
			length++;
			sprintf(ptr, " %06x (%s)", pb | ((pc + length + var)&0xffff), int_8_str(var));
			break;
		case RELW:
		case PER :
			var = read_16(address+1);
			sprintf(ptr, " %06x (%s)", pb | ((pc + 1 + var)&0xffff), int_16_str(var));
			length += 2;
			break;
		case IMM :
			if((opcode->flag == M && !m_flag) || (opcode->flag == X && !x_flag))
			{
				sprintf(ptr, " #$%04x", read_16(address+1));
				length += 2;
			}
			else
			{
				sprintf(ptr, " #$%02x", read_8(address+1));
				length++;
			}
			break;
		case A   :
		case PEA :
			sprintf(ptr, " $%04x", read_16(address+1));
			length += 2;
			break;
		case AI  :
			sprintf(ptr, " ($%04x)", read_16(address+1));
			length += 2;
			break;
		case AL  :
			sprintf(ptr, " $%06x", read_24(address+1));
			length += 3;
			break;
		case ALX :
			sprintf(ptr, " $%06x,X", read_24(address+1));
			length += 3;
			break;
		case AX  :
			sprintf(ptr, " $%04x,X", read_16(address+1));
			length += 2;
			break;
		case AXI :
			sprintf(ptr, " ($%04x,X)", read_16(address+1));
			length += 2;
			break;
		case AY  :
			sprintf(ptr, " $%04x,Y", read_16(address+1));
			length += 2;
			break;
		case D   :
			sprintf(ptr, " $%02x", read_8(address+1));
			length++;
			break;
		case DI  :
		case PEI :
			sprintf(ptr, " ($%02x)", read_8(address+1));
			length++;
			break;
		case DIY :
			sprintf(ptr, " ($%02x),Y", read_8(address+1));
			length++;
			break;
		case DLI :
			sprintf(ptr, " [$%02x]", read_8(address+1));
			length++;
			break;
		case DLIY:
			sprintf(ptr, " [$%02x],Y", read_8(address+1));
			length++;
			break;
		case DX  :
			sprintf(ptr, " $%02x,X", read_8(address+1));
			length++;
			break;
		case DXI :
			sprintf(ptr, " ($%02x,X)", read_8(address+1));
			length++;
			break;
		case DY  :
			sprintf(ptr, " $%02x,Y", read_8(address+1));
			length++;
			break;
		case S   :
			sprintf(ptr, " %s,S", int_8_str(read_8(address+1)));
			length++;
			break;
		case SIY :
			sprintf(ptr, " (%s,S),Y", int_8_str(read_8(address+1)));
			length++;
			break;
		case SIG :
			sprintf(ptr, " #$%02x", read_8(address+1));
			length++;
			break;
		case MVN :
		case MVP :
			sprintf(ptr, " $%02x, $%02x", read_8(address+2), read_8(address+1));
			length += 2;
			break;
	}

	return length;
}