summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/video/fixfreq.h
blob: 68dc829c650bfcc8d8c19a5f4745562b5982d96a (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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// license:BSD-3-Clause
// copyright-holders:Couriersud
/***************************************************************************

    fixfreq.h

    Fixed frequency monochrome monitor emulation

    The driver is intended for drivers which provide an analog video signal.
    VSYNC and HSYNC levels are used to create the bitmap.

***************************************************************************/

#ifndef MAME_VIDEO_FIXFREQ_H
#define MAME_VIDEO_FIXFREQ_H

#include "machine/netlist.h"
#include "screen.h"


// ======================> fixedfreq_device

class fixedfreq_device : public device_t, public device_video_interface
{
public:
	// construction/destruction
	fixedfreq_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 0);

	// inline configuration helpers
	void set_monitor_clock(uint32_t clock) { m_monitor_clock = clock; }
	void set_fieldcount(int count) { m_fieldcount = count; }
	void set_threshold(double threshold) { m_sync_threshold = threshold; }
	void set_gain(double gain) { m_gain = gain; }
	void set_horz_params(int visible, int frontporch, int sync, int backporch)
	{
		m_hvisible = visible;
		m_hfrontporch = frontporch;
		m_hsync = sync;
		m_hbackporch = backporch;
	}
	void set_vert_params(int visible, int frontporch, int sync, int backporch)
	{
		m_vvisible = visible;
		m_vfrontporch = frontporch;
		m_vsync = sync;
		m_vbackporch = backporch;
	}

	// pre-defined configurations
	void set_mode_ntsc720() //ModeLine "720x480@30i" 13.5 720 736 799 858 480 486 492 525 interlace -hsync -vsync
	{
		set_monitor_clock(13500000);
		set_horz_params(720, 736, 799, 858);
		set_vert_params(480, 486, 492, 525);
		set_fieldcount(2);
		set_threshold(0.3);
	}
	void set_mode_ntsc704() //ModeLine "704x480@30i" 13.5 704 728 791 858 480 486 492 525
	{
		set_monitor_clock(13500000);
		set_horz_params(704, 728, 791, 858);
		set_vert_params(480, 486, 492, 525);
		set_fieldcount(2);
		set_threshold(0.3);
	}

	virtual uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);

	NETDEV_ANALOG_CALLBACK_MEMBER(update_composite_monochrome);
	NETDEV_ANALOG_CALLBACK_MEMBER(update_red);
	NETDEV_ANALOG_CALLBACK_MEMBER(update_green);
	NETDEV_ANALOG_CALLBACK_MEMBER(update_blue);
	NETDEV_ANALOG_CALLBACK_MEMBER(update_sync);


protected:

	typedef double time_type;

	fixedfreq_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock);

	// device-level overrides
	virtual void device_config_complete() override;
	virtual void device_start() override;
	virtual void device_reset() override;
	virtual void device_post_load() override;
	//virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);

	void update_screen_parameters(const time_type &refresh);

private:

	void update_sync_channel(const time_type &time, const double newval);
	void update_bm(const time_type &time);
	void recompute_parameters();

	int m_htotal;
	int m_vtotal;
	int m_hscale;

	double m_sync_signal;
	rgb_t m_col;
	int m_last_x;
	int m_last_y;
	time_type m_last_sync_time;
	time_type m_line_time;
	time_type m_last_hsync_time;
	time_type m_last_vsync_time;
	time_type m_refresh_period;
	time_type m_clock_period;
	std::unique_ptr<bitmap_rgb32> m_bitmap[2];
	int m_cur_bm;

	/* adjustable by drivers */
	uint32_t m_monitor_clock;
	int m_hvisible;
	int m_hfrontporch;
	int m_hsync;
	int m_hbackporch;
	int m_vvisible;
	int m_vfrontporch;
	int m_vsync;
	int m_vbackporch;
	int m_fieldcount;
	double m_sync_threshold;
	double m_gain;

	/* sync separator */
	double m_vsync_filter;
	double m_vsync_threshold;
	double m_vsync_filter_timeconst;

	int m_sig_vsync;
	int m_sig_composite;
	int m_sig_field;
};


// device type definition
DECLARE_DEVICE_TYPE(FIXFREQ, fixedfreq_device)

#endif // MAME_VIDEO_FIXFREQ_H