1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /**********************************************************************
4 
5     TI TMS9927 and compatible CRT controller emulation
6 
7 **********************************************************************/
8 
9 #ifndef MAME_VIDEO_TMS9927_H
10 #define MAME_VIDEO_TMS9927_H
11 
12 
13 class tms9927_device : public device_t, public device_video_interface
14 {
15 public:
16 	tms9927_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
17 
vsyn_callback()18 	auto vsyn_callback() { return m_write_vsyn.bind(); }
hsyn_callback()19 	auto hsyn_callback() { return m_write_hsyn.bind(); }
20 
set_char_width(int pixels)21 	void set_char_width(int pixels) { m_hpixels_per_column = pixels; }
set_region_tag(const char * tag)22 	void set_region_tag(const char *tag) { m_selfload.set_tag(tag); }
set_overscan(int left,int right,int top,int bottom)23 	void set_overscan(int left, int right, int top, int bottom) {
24 		m_overscan_left = left;
25 		m_overscan_right = right;
26 		m_overscan_top = top;
27 		m_overscan_bottom = bottom;
28 	}
set_visarea(s16 minx,s16 maxx,s16 miny,s16 maxy)29 	void set_visarea(s16 minx, s16 maxx, s16 miny, s16 maxy) { m_custom_visarea.set(minx, maxx, miny, maxy); }
30 
31 	void write(offs_t offset, uint8_t data);
32 	uint8_t read(offs_t offset);
33 
34 	int bl_r();
35 
screen_reset()36 	bool screen_reset() const { return m_reset; }
upscroll_offset()37 	int upscroll_offset() const { return m_start_datarow; }
38 	bool cursor_bounds(rectangle &bounds) const;
39 
40 protected:
41 	tms9927_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);
42 
43 	// device-level overrides
44 	virtual void device_start() override;
45 	virtual void device_stop() override;
46 	virtual void device_reset() override;
47 	virtual void device_clock_changed() override;
48 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
49 	virtual void device_post_load() override;
50 
51 private:
52 	enum
53 	{
54 		TIMER_VSYNC,
55 		TIMER_HSYNC
56 	};
57 
58 	void recompute_parameters(bool postload);
59 	void generic_access(offs_t offset);
60 
61 	devcb_write_line m_write_vsyn;
62 	devcb_write_line m_write_hsyn;
63 
64 	int m_hpixels_per_column;         /* number of pixels per video memory address */
65 	uint16_t  m_overscan_left;
66 	uint16_t  m_overscan_right;
67 	uint16_t  m_overscan_top;
68 	uint16_t  m_overscan_bottom;
69 
70 	// internal state
71 	optional_region_ptr<uint8_t> m_selfload;
72 
73 	/* live state */
74 	uint8_t   m_reg[9];
75 	uint8_t   m_start_datarow;
76 	bool      m_reset;
77 	bool      m_vsyn;
78 	bool      m_hsyn;
79 
80 	/* derived state; no need to save */
81 	bool      m_valid_config;
82 	uint16_t  m_total_hpix, m_total_vpix;
83 	uint16_t  m_visible_hpix, m_visible_vpix;
84 	rectangle m_custom_visarea;
85 	uint16_t  m_vsyn_start, m_vsyn_end;
86 	uint16_t  m_hsyn_start, m_hsyn_end;
87 
88 	emu_timer *m_vsync_timer;
89 	emu_timer *m_hsync_timer;
90 };
91 
92 
93 class crt5027_device : public tms9927_device
94 {
95 public:
96 	crt5027_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
97 };
98 
99 
100 class crt5037_device : public tms9927_device
101 {
102 public:
103 	crt5037_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
104 };
105 
106 
107 class crt5057_device : public tms9927_device
108 {
109 public:
110 	crt5057_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
111 };
112 
113 
114 DECLARE_DEVICE_TYPE(TMS9927, tms9927_device)
115 DECLARE_DEVICE_TYPE(CRT5027, crt5027_device)
116 DECLARE_DEVICE_TYPE(CRT5037, crt5037_device)
117 DECLARE_DEVICE_TYPE(CRT5057, crt5057_device)
118 
119 #endif // MAME_VIDEO_TMS9927_H
120