1 // license:BSD-3-Clause
2 // copyright-holders:Felipe Sanches, Sandro Ronco
3 /***************************************************************************
4 
5         NT7534 LCD controller
6 
7 ***************************************************************************/
8 
9 #ifndef MAME_VIDEO_NT7534_H
10 #define MAME_VIDEO_NT7534_H
11 
12 #pragma once
13 
14 
15 //**************************************************************************
16 //  TYPE DEFINITIONS
17 //**************************************************************************
18 
19 #define NT7534_PIXEL_UPDATE(name) void name(bitmap_ind16 &bitmap, uint8_t line, uint8_t pos, uint8_t y, uint8_t x, int state)
20 
21 
22 // ======================> nt7534_device
23 
24 class nt7534_device : public device_t
25 {
26 public:
27 	typedef device_delegate<void (bitmap_ind16 &bitmap, uint8_t line, uint8_t pos, uint8_t y, uint8_t x, int state)> pixel_update_delegate;
28 
29 	// construction/destruction
30 	nt7534_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);
31 
set_pixel_update_cb(T &&...args)32 	template <typename... T> void set_pixel_update_cb(T &&... args) { m_pixel_update_cb.set(std::forward<T>(args)...); }
33 
34 	// device interface
35 	virtual void write(offs_t offset, uint8_t data);
36 	virtual uint8_t read(offs_t offset);
37 	virtual void control_write(uint8_t data);
38 	virtual uint8_t control_read();
39 	virtual void data_write(uint8_t data);
40 	virtual uint8_t data_read();
41 
42 	const uint8_t *render();
43 	virtual uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
44 
45 protected:
46 	nt7534_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
47 
48 	// device-level overrides
49 	virtual void device_start() override;
50 	virtual void device_reset() override;
51 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
52 private:
53 	// internal helper
54 	void set_busy_flag(uint16_t usec);
55 	void update_nibble(int rs, int rw);
56 
57 	// internal state
58 	static constexpr device_timer_id TIMER_BUSY = 0;
59 
60 	emu_timer * m_busy_timer;
61 
62 	pixel_update_delegate m_pixel_update_cb; // pixel update callback
63 
64 	bool        m_busy_flag;
65 	uint8_t     m_ddram[9*132];        // internal display data RAM
66 	uint8_t     m_page;                // page address
67 	uint16_t    m_column;              // column address
68 	uint16_t    m_backup_column;       // column address
69 	uint8_t     m_display_start_line;
70 	uint8_t     m_dr;                  // data register
71 	uint8_t     m_ir;                  // instruction register
72 	bool        m_display_on;          // display on/off
73 	bool        m_entire_display_on;
74 	bool        m_reverse;             // Reverse display
75 	bool        m_read_modify_write;
76 	bool        m_adc;
77 	int         m_direction;           // auto increment/decrement (-1 or +1)
78 	uint8_t     m_data_len;            // interface data length 4 or 8 bit
79 	int         m_rs_state;
80 	int         m_rw_state;
81 	bool        m_nibble;
82 };
83 
84 // device type definition
85 DECLARE_DEVICE_TYPE(NT7534,    nt7534_device)
86 
87 #endif // MAME_VIDEO_NT7534_H
88