1 // license:LGPL-2.1+
2 // copyright-holders:Angelo Salese
3 /***************************************************************************
4 
5 Nichibutsu 1412M2 device emulation
6 
7 ***************************************************************************/
8 
9 #ifndef MAME_MACHINE_NB1412M2_H
10 #define MAME_MACHINE_NB1412M2_H
11 
12 #pragma once
13 
14 
15 //**************************************************************************
16 //  TYPE DEFINITIONS
17 //**************************************************************************
18 
19 // ======================> nb1412m2_device
20 
21 class nb1412m2_device : public device_t, public device_memory_interface
22 {
23 public:
24 	// construction/destruction
25 	nb1412m2_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
26 
27 	// I/O operations
28 	void command_w(uint8_t data);
29 	void data_w(uint8_t data);
30 	uint8_t data_r();
31 
dac_callback()32 	auto dac_callback() { return m_dac_cb.bind(); }
33 
34 	void nb1412m2_map(address_map &map);
35 
36 protected:
37 	// device-level overrides
38 //  virtual void device_validity_check(validity_checker &valid) const override;
39 //  virtual void device_add_mconfig(machine_config &config) override;
40 	virtual void device_start() override;
41 	virtual void device_reset() override;
42 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
43 	virtual space_config_vector memory_space_config() const override;
44 
45 private:
46 	uint8_t m_command;
47 	uint16_t m_rom_address;
48 	uint16_t m_adj_address;
49 	uint16_t m_dac_start_address, m_dac_current_address;
50 	int m_dac_frequency;
51 	uint8_t m_rom_op;
52 	uint8_t m_const90;
53 	bool m_timer_reg;
54 	bool m_dac_playback;
55 	const address_space_config m_space_config;
56 	emu_timer *m_timer;
57 	emu_timer *m_dac_timer;
58 
59 	required_region_ptr<uint8_t> m_data;
60 	devcb_write8 m_dac_cb;
61 
62 	static const device_timer_id TIMER_MAIN = 1;
63 	static const device_timer_id TIMER_DAC = 2;
64 
65 	void rom_address_w(offs_t offset, uint8_t data);
66 	uint8_t rom_decrypt_r();
67 	void rom_op_w(uint8_t data);
68 	void rom_adjust_w(offs_t offset, uint8_t data);
69 	uint8_t timer_r();
70 	void timer_w(uint8_t data);
71 	void timer_ack_w(uint8_t data);
72 	uint8_t const90_r();
73 	void const90_w(uint8_t data);
74 	void dac_address_w(offs_t offset, uint8_t data);
75 	void dac_timer_w(uint8_t data);
76 };
77 
78 
79 // device type definition
80 DECLARE_DEVICE_TYPE(NB1412M2, nb1412m2_device)
81 
82 
83 
84 //**************************************************************************
85 //  GLOBAL VARIABLES
86 //**************************************************************************
87 
88 
89 #endif // MAME_MACHINE_NB1412M2_H
90