summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/debug/debugbuf.h
blob: 46ec8286417d34f8be2663d23f986ea79e86d3c9 (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
93
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert

// Buffering interface for the disassembly windows

#ifndef MAME_EMU_DEBUG_DEBUGBUF_H
#define MAME_EMU_DEBUG_DEBUGBUF_H

#pragma once

class debug_disasm_buffer
{
public:
	debug_disasm_buffer(device_t &device);

	void disassemble(offs_t pc, std::string &instruction, offs_t &next_pc, offs_t &size, u32 &info) const;
	u32 disassemble_info(offs_t pc) const;
	std::string pc_to_string(offs_t pc) const;
	std::string data_to_string(offs_t pc, offs_t size, bool opcode) const;
	void data_get(offs_t pc, offs_t size, bool opcode, std::vector<u8> &data) const;

	offs_t next_pc(offs_t pc, offs_t step) const;
	offs_t next_pc_wrap(offs_t pc, offs_t step) const;

private:
	class debug_data_buffer : public util::disasm_interface::data_buffer
	{
	public:
		debug_data_buffer(util::disasm_interface *intf);
		~debug_data_buffer() = default;

		virtual u8  r8 (offs_t pc) const override;
		virtual u16 r16(offs_t pc) const override;
		virtual u32 r32(offs_t pc) const override;
		virtual u64 r64(offs_t pc) const override;

		void set_source(address_space &space);
		void set_source(debug_data_buffer &back, bool opcode);

		bool active() const;

		address_space *get_underlying_space() const;
		std::string data_to_string(offs_t pc, offs_t size) const;
		void data_get(offs_t pc, offs_t size, std::vector<u8> &data) const;

	private:
		util::disasm_interface *m_intf;

		std::function<offs_t (offs_t)> m_pc_delta_to_bytes;
		std::function<void (offs_t, offs_t)> m_do_fill;
		std::function<u8  (offs_t)> m_do_r8;
		std::function<u16 (offs_t)> m_do_r16;
		std::function<u32 (offs_t)> m_do_r32;
		std::function<u64 (offs_t)> m_do_r64;
		std::function<std::string (offs_t, offs_t)> m_data_to_string;
		std::function<void (offs_t, offs_t, std::vector<u8> &)> m_data_get;
		std::function<offs_t (offs_t, offs_t)> m_next_pc_wrap;

		address_space *m_space;
		debug_data_buffer *m_back;
		bool m_opcode;
		offs_t m_page_mask, m_pc_mask;
		mutable offs_t m_lstart, m_lend;
		mutable bool m_wrapped;
		mutable std::vector<u8> m_buffer;

		template<typename T> T *get_ptr(offs_t lpc) {
			return reinterpret_cast<T *>(&m_buffer[0]) + ((lpc - m_lstart) & m_pc_mask);
		}

		template<typename T> T get(offs_t lpc) const {
			return reinterpret_cast<const T *>(&m_buffer[0])[(lpc - m_lstart) & m_pc_mask];
		}

		void setup_methods();
		void fill(offs_t lstart, offs_t size) const;

	};

	util::disasm_interface *m_dintf;
	device_memory_interface *m_mintf;

	std::function<offs_t (offs_t, offs_t)> m_next_pc;
	std::function<offs_t (offs_t, offs_t)> m_next_pc_wrap;
	std::function<std::string (offs_t)> m_pc_to_string;

	debug_data_buffer m_buf_raw, m_buf_opcodes, m_buf_params;
	u32 m_flags;
	offs_t m_page_mask, m_pc_mask;
};

#endif