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
|
// license:BSD-3-Clause
// copyright-holders:Dirk Best
/***************************************************************************
TEA1002
PAL colour encoder and video summer
***************************************************************************/
#include "emu.h"
#include "tea1002.h"
namespace {
//**************************************************************************
// CONSTANTS
//**************************************************************************
const int s_tint = -6; // what is this based on?
const float s_luminance[] =
{
0, 22.5, 44, 66.5, 8.5, 31, 52.5, 100, // INV = 0
75, 52.5, 31, 8.5, 66.5, 44, 22.5, 0 // INV = 1
};
const int s_phase[] =
{
0, 103, 241, 167, 347, 61, 283, 0, // INV = 0
0, 283, 61, 347, 167, 241, 103, 0 // INV = 1
};
const int s_amplitude[] =
{
0, 48, 44, 33, 33, 44, 48, 0, // INV = 0
0, 24, 22, 17, 17, 22, 24, 0 // INV = 1
};
} // anonymous namespace
//**************************************************************************
// DEVICE DEFINITIONS
//**************************************************************************
DEFINE_DEVICE_TYPE(TEA1002, tea1002_device, "tea1002", "Mullard TEA1002 PAL colour encoder")
//**************************************************************************
// LIVE DEVICE
//**************************************************************************
//-------------------------------------------------
// tea1002_device - constructor
//-------------------------------------------------
tea1002_device::tea1002_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, TEA1002, tag, owner, clock)
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void tea1002_device::device_start()
{
}
//**************************************************************************
// IMPLEMENTATION
//**************************************************************************
// this could be done in device_start() and cached, but it's only
// accessed once at PALETTE_INIT anyway
rgb_t tea1002_device::color(int index)
{
// calculate yuv
double y = s_luminance[index] / 100;
double u = cos((s_phase[index] + s_tint) * M_PI / 180) * s_amplitude[index] / 100;
double v = sin((s_phase[index] + s_tint) * M_PI / 180) * s_amplitude[index] / 100;
// and convert to rgb
double r = y + v * 1.14;
double g = y - u * 0.395 - v * 0.581;
double b = y + u * 2.032;
return rgb_t(rgb_t::clamp(r * 255), rgb_t::clamp(g * 255), rgb_t::clamp(b * 255));
}
|