1 // license:BSD-3-Clause
2 // copyright-holders:Olivier Galibert
3 
4 // Buffering interface for the disassembly windows
5 
6 #ifndef MAME_EMU_DEBUG_DEBUGBUF_H
7 #define MAME_EMU_DEBUG_DEBUGBUF_H
8 
9 #pragma once
10 
11 class debug_disasm_buffer
12 {
13 public:
14 	debug_disasm_buffer(device_t &device);
15 
16 	void disassemble(offs_t pc, std::string &instruction, offs_t &next_pc, offs_t &size, u32 &info) const;
17 	u32 disassemble_info(offs_t pc) const;
18 	std::string pc_to_string(offs_t pc) const;
19 	std::string data_to_string(offs_t pc, offs_t size, bool opcode) const;
20 	void data_get(offs_t pc, offs_t size, bool opcode, std::vector<u8> &data) const;
21 
22 	offs_t next_pc(offs_t pc, offs_t step) const;
23 	offs_t next_pc_wrap(offs_t pc, offs_t step) const;
24 
25 private:
26 	class debug_data_buffer : public util::disasm_interface::data_buffer
27 	{
28 	public:
29 		debug_data_buffer(util::disasm_interface const &intf);
30 		~debug_data_buffer() = default;
31 
32 		virtual u8  r8 (offs_t pc) const override;
33 		virtual u16 r16(offs_t pc) const override;
34 		virtual u32 r32(offs_t pc) const override;
35 		virtual u64 r64(offs_t pc) const override;
36 
37 		void set_source(address_space &space);
38 		void set_source(debug_data_buffer &back, bool opcode);
39 
40 		bool active() const;
41 
42 		address_space *get_underlying_space() const;
43 		std::string data_to_string(offs_t pc, offs_t size) const;
44 		void data_get(offs_t pc, offs_t size, std::vector<u8> &data) const;
45 
46 	private:
47 		util::disasm_interface const &m_intf;
48 
49 		std::function<offs_t (offs_t)> m_pc_delta_to_bytes;
50 		std::function<void (offs_t, offs_t)> m_do_fill;
51 		std::function<u8  (offs_t)> m_do_r8;
52 		std::function<u16 (offs_t)> m_do_r16;
53 		std::function<u32 (offs_t)> m_do_r32;
54 		std::function<u64 (offs_t)> m_do_r64;
55 		std::function<std::string (offs_t, offs_t)> m_data_to_string;
56 		std::function<void (offs_t, offs_t, std::vector<u8> &)> m_data_get;
57 		std::function<offs_t (offs_t, offs_t)> m_next_pc_wrap;
58 
59 		address_space *m_space;
60 		debug_data_buffer *m_back;
61 		bool m_opcode;
62 		offs_t m_page_mask, m_pc_mask;
63 		mutable offs_t m_lstart, m_lend;
64 		mutable bool m_wrapped;
65 		mutable std::vector<u8> m_buffer;
66 
get_ptr(offs_t lpc)67 		template<typename T> T *get_ptr(offs_t lpc) {
68 			return reinterpret_cast<T *>(&m_buffer[0]) + ((lpc - m_lstart) & m_pc_mask);
69 		}
70 
get(offs_t lpc)71 		template<typename T> T get(offs_t lpc) const {
72 			return reinterpret_cast<const T *>(&m_buffer[0])[(lpc - m_lstart) & m_pc_mask];
73 		}
74 
75 		void setup_methods();
76 		void fill(offs_t lstart, offs_t size) const;
77 
78 	};
79 
80 	util::disasm_interface &m_dintf;
81 	device_memory_interface *const m_mintf;
82 
83 	std::function<offs_t (offs_t, offs_t)> m_next_pc;
84 	std::function<offs_t (offs_t, offs_t)> m_next_pc_wrap;
85 	std::function<std::string (offs_t)> m_pc_to_string;
86 
87 	debug_data_buffer m_buf_raw, m_buf_opcodes, m_buf_params;
88 	u32 const m_flags;
89 	offs_t m_page_mask, m_pc_mask;
90 };
91 
92 #endif
93 
94