summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/didisasm.cpp
blob: 95353889a6561d9cd597570748e105897ed16854 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************

    didisasm.c

    Device disasm interfaces.

***************************************************************************/

#include "emu.h"


//**************************************************************************
//  DEVICE DISASM INTERFACE
//**************************************************************************

//-------------------------------------------------
//  device_disasm_interface - constructor
//-------------------------------------------------

device_disasm_interface::device_disasm_interface(const machine_config &mconfig, device_t &device)
	: device_interface(device, "disasm")
{
}


//-------------------------------------------------
//  ~device_disasm_interface - destructor
//-------------------------------------------------

device_disasm_interface::~device_disasm_interface()
{
}


//-------------------------------------------------
//  interface_pre_start - work to be done prior to
//  actually starting a device
//-------------------------------------------------

void device_disasm_interface::interface_pre_start()
{
	// bind delegate
	m_dasm_override.bind_relative_to(*device().owner());
}


//-------------------------------------------------
//  static_set_dasm_override - configuration
//  helper to override disassemble function
//-------------------------------------------------

void device_disasm_interface::static_set_dasm_override(device_t &device, dasm_override_delegate dasm_override)
{
	device_disasm_interface *dasm;
	if (!device.interface(dasm))
		throw emu_fatalerror("MCFG_DEVICE_DISASSEMBLE_OVERRIDE called on device '%s' with no disasm interface", device.tag());
	dasm->m_dasm_override = dasm_override;
}


//-------------------------------------------------
//  disassemble - interface for disassembly
//-------------------------------------------------

offs_t device_disasm_interface::disassemble(std::ostream &stream, offs_t pc, const u8 *oprom, const u8 *opram, u32 options)
{
	offs_t result = 0;

	// check for disassembler override
	if (!m_dasm_override.isnull())
		result = m_dasm_override(device(), stream, pc, oprom, opram, options);
	if (result == 0)
		result = disasm_disassemble(stream, pc, oprom, opram, options);

	// make sure we get good results
	assert((result & DASMFLAG_LENGTHMASK) != 0);
#ifdef MAME_DEBUG
	device_memory_interface *memory;
	if (device().interface(memory))
	{
		address_space &space = memory->space(AS_PROGRAM);
		int bytes = space.address_to_byte(result & DASMFLAG_LENGTHMASK);
		assert(bytes >= min_opcode_bytes());
		assert(bytes <= max_opcode_bytes());
		(void) bytes; // appease compiler
	}
#endif

	return result;
}