summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/mcd212.h
blob: 1701c36cd94fcb26304df52d9877ea41b12925bb (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
// license:BSD-3-Clause
// copyright-holders:Ryan Holtz
/******************************************************************************


    CD-i MCD212 video emulation
    -------------------

    written by Ryan Holtz


*******************************************************************************

STATUS:

- Just enough for the Mono-I CD-i board to work somewhat properly.

TODO:

- Unknown yet.

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

#ifndef MAME_VIDEO_MCD212_H
#define MAME_VIDEO_MCD212_H

#pragma once


#define MCD212_CURCNT_COLOR         0x00000f    // Cursor color
#define MCD212_CURCNT_CUW           0x008000    // Cursor width
#define MCD212_CURCNT_COF           0x070000    // Cursor off time
#define MCD212_CURCNT_COF_SHIFT     16
#define MCD212_CURCNT_CON           0x280000    // Cursor on time
#define MCD212_CURCNT_CON_SHIFT     19
#define MCD212_CURCNT_BLKC          0x400000    // Blink type
#define MCD212_CURCNT_EN            0x800000    // Cursor enable

#define MCD212_ICM_CS               0x400000    // CLUT select
#define MCD212_ICM_NR               0x080000    // Number of region flags
#define MCD212_ICM_EV               0x040000    // External video
#define MCD212_ICM_MODE2            0x000f00    // Plane 2
#define MCD212_ICM_MODE2_SHIFT      8
#define MCD212_ICM_MODE1            0x00000f    // Plane 1
#define MCD212_ICM_MODE1_SHIFT      0

#define MCD212_TCR_DISABLE_MX       0x800000    // Mix disable
#define MCD212_TCR_TB               0x000f00    // Plane B
#define MCD212_TCR_TB_SHIFT         8
#define MCD212_TCR_TA               0x00000f    // Plane A
#define MCD212_TCR_COND_1           0x0         // Transparent if: Always (Plane Disabled)
#define MCD212_TCR_COND_KEY_1       0x1         // Transparent if: Color Key = True
#define MCD212_TCR_COND_XLU_1       0x2         // Transparent if: Transparency Bit = 1
#define MCD212_TCR_COND_RF0_1       0x3         // Transparent if: Region Flag 0 = True
#define MCD212_TCR_COND_RF1_1       0x4         // Transparent if: Region Flag 1 = True
#define MCD212_TCR_COND_RF0KEY_1    0x5         // Transparent if: Region Flag 0 = True || Color Key = True
#define MCD212_TCR_COND_RF1KEY_1    0x6         // Transparent if: Region Flag 1 = True || Color Key = True
#define MCD212_TCR_COND_UNUSED0     0x7         // Unused
#define MCD212_TCR_COND_0           0x8         // Transparent if: Never (No Transparent Area)
#define MCD212_TCR_COND_KEY_0       0x9         // Transparent if: Color Key = False
#define MCD212_TCR_COND_XLU_0       0xa         // Transparent if: Transparency Bit = 0
#define MCD212_TCR_COND_RF0_0       0xb         // Transparent if: Region Flag 0 = False
#define MCD212_TCR_COND_RF1_0       0xc         // Transparent if: Region Flag 1 = False
#define MCD212_TCR_COND_RF0KEY_0    0xd         // Transparent if: Region Flag 0 = False && Color Key = False
#define MCD212_TCR_COND_RF1KEY_0    0xe         // Transparent if: Region Flag 1 = False && Color Key = False
#define MCD212_TCR_COND_UNUSED1     0xf         // Unused

#define MCD212_POR_AB               0           // Plane A in front of Plane B
#define MCD212_POR_BA               1           // Plane B in front of Plane A

#define MCD212_RC_X                 0x0003ff    // X position
#define MCD212_RC_WF                0x00fc00    // Weight position
#define MCD212_RC_WF_SHIFT          10
#define MCD212_RC_RF                0x010000    // Region flag
#define MCD212_RC_RF_SHIFT          16
#define MCD212_RC_OP                0xf00000    // Operation
#define MCD212_RC_OP_SHIFT          20

#define MCD212_CSR1W_ST             0x0002  // Standard
#define MCD212_CSR1W_BE             0x0001  // Bus Error

#define MCD212_CSR2R_IT1            0x0004  // Interrupt 1
#define MCD212_CSR2R_IT2            0x0002  // Interrupt 2
#define MCD212_CSR2R_BE             0x0001  // Bus Error

#define MCD212_DCR_DE               0x8000  // Display Enable
#define MCD212_DCR_CF               0x4000  // Crystal Frequency
#define MCD212_DCR_FD               0x2000  // Frame Duration
#define MCD212_DCR_SM               0x1000  // Scan Mode
#define MCD212_DCR_CM               0x0800  // Color Mode Ch.1/2
#define MCD212_DCR_ICA              0x0200  // ICA Enable Ch.1/2
#define MCD212_DCR_DCA              0x0100  // DCA Enable Ch.1/2

#define MCD212_DDR_FT               0x0300  // Display File Type
#define MCD212_DDR_FT_BMP           0x0000  // Bitmap
#define MCD212_DDR_FT_BMP2          0x0100  // Bitmap (alt.)
#define MCD212_DDR_FT_RLE           0x0200  // Run-Length Encoded
#define MCD212_DDR_FT_MOSAIC        0x0300  // Mosaic
#define MCD212_DDR_MT               0x0c00  // Mosaic File Type
#define MCD212_DDR_MT_2             0x0000  // 2x1
#define MCD212_DDR_MT_4             0x0400  // 4x1
#define MCD212_DDR_MT_8             0x0800  // 8x1
#define MCD212_DDR_MT_16            0x0c00  // 16x1
#define MCD212_DDR_MT_SHIFT         10

typedef uint8_t BYTE68K;
typedef uint16_t WORD68K;
typedef int16_t SWORD68K;

#define BYTE68K_MAX 255

//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> mcd212_device

class mcd212_device : public device_t,
						public device_video_interface
{
public:
	typedef device_delegate<void (int)> scanline_callback_delegate;

	// construction/destruction
	mcd212_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);

	auto int_callback() { return m_int_callback.bind(); }

	template <typename... T> void set_scanline_callback(T &&... args) { m_scanline_callback.set(std::forward<T>(args)...); }

	// device members
	uint16_t regs_r(offs_t offset, uint16_t mem_mask = ~0);
	void regs_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
	TIMER_CALLBACK_MEMBER( perform_scan );

	bitmap_rgb32& get_bitmap() { return m_bitmap; }

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

	struct channel_t
	{
		uint8_t csrr;
		uint16_t csrw;
		uint16_t dcr;
		uint16_t vsr;
		uint16_t ddr;
		uint16_t dcp;
		uint32_t dca;
		uint8_t clut_r[256];
		uint8_t clut_g[256];
		uint8_t clut_b[256];
		uint32_t image_coding_method;
		uint32_t transparency_control;
		uint32_t plane_order;
		uint32_t clut_bank;
		uint32_t transparent_color_a;
		uint32_t reserved0;
		uint32_t transparent_color_b;
		uint32_t mask_color_a;
		uint32_t reserved1;
		uint32_t mask_color_b;
		uint32_t dyuv_abs_start_a;
		uint32_t dyuv_abs_start_b;
		uint32_t reserved2;
		uint32_t cursor_position;
		uint32_t cursor_control;
		uint32_t cursor_pattern[16];
		uint32_t region_control[8];
		uint32_t backdrop_color;
		uint32_t mosaic_hold_a;
		uint32_t mosaic_hold_b;
		uint8_t weight_factor_a[768];
		uint8_t weight_factor_b[768];
	};

	struct ab_t
	{
		//* Color limit array.
		BYTE68K limit[3 * BYTE68K_MAX];

		//* Color clamp array.
		BYTE68K clamp[3 * BYTE68K_MAX];

		//* U-to-B matrix array.
		SWORD68K matrixUB[BYTE68K_MAX + 1];

		//* U-to-G matrix array.
		SWORD68K matrixUG[BYTE68K_MAX + 1];

		//* V-to-G matrix array.
		SWORD68K matrixVG[BYTE68K_MAX + 1];

		//* V-to-R matrix array.
		SWORD68K matrixVR[BYTE68K_MAX + 1];

		//* Delta-Y decoding array.
		BYTE68K deltaY[BYTE68K_MAX + 1];

		//* Delta-U/V decoding array.
		BYTE68K deltaUV[BYTE68K_MAX + 1];
	};

protected:
	// device-level overrides
	virtual void device_resolve_objects() override;
	virtual void device_start() override;
	virtual void device_reset() override;

private:
	// interrupt callbacks
	devcb_write_line m_int_callback;

	scanline_callback_delegate m_scanline_callback;

	required_shared_ptr<uint16_t> m_planea;
	required_shared_ptr<uint16_t> m_planeb;

	// internal state
	channel_t m_channel[2];
	emu_timer *m_scan_timer;
	uint8_t m_region_flag_0[768];
	uint8_t m_region_flag_1[768];

	bitmap_rgb32 m_bitmap;

	static const uint32_t s_4bpp_color[16];

	ab_t m_ab;

	void update_region_arrays();

	void set_vsr(int channel, uint32_t value);
	uint32_t get_vsr(int channel);

	void set_dcp(int channel, uint32_t value);
	uint32_t get_dcp(int channel);

	void set_display_parameters(int channel, uint8_t value);
	void update_visible_area();
	uint32_t get_screen_width();

	void process_ica(int channel);
	void process_dca(int channel);
	void process_vsr(int channel, uint8_t *pixels_r, uint8_t *pixels_g, uint8_t *pixels_b);

	void set_register(int channel, uint8_t reg, uint32_t value);

	void mix_lines(uint8_t *plane_a_r, uint8_t *plane_a_g, uint8_t *plane_a_b, uint8_t *plane_b_r, uint8_t *plane_b_g, uint8_t *plane_b_b, uint32_t *out);

	void draw_cursor(uint32_t *scanline, int y);
	void draw_scanline(int y);

	void ab_init();
};

// device type definition
DECLARE_DEVICE_TYPE(MCD212, mcd212_device)

#endif // MAME_VIDEO_MCD212_H