-
Notifications
You must be signed in to change notification settings - Fork 78
/
Composite.cpp
174 lines (152 loc) · 5.63 KB
/
Composite.cpp
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
/*
Author: bitluni 2019
License:
Creative Commons Attribution ShareAlike 4.0
https://creativecommons.org/licenses/by-sa/4.0/
For further details check out:
https://youtube.com/bitlunislab
https://github.com/bitluni
http://bitluni.net
*/
#include "Composite.h"
const ModeComposite Composite::MODE400x300(32, 76, 380, 8, 8, 24, 278, 2, 1, 16, 8000000);
//1136 per line
//920 visible
//84 sync
//132 front
//312 total lines
//856
const ModeComposite Composite::MODEPAL312P(64, 96, 640, 56, 8, 23, 272, 9, 1, 32, 13333333, 70, 38, 4433619);
//const ModeComposite Composite::MODEPAL312P(84, 152, 840, 60, 8, 23, 272, 9, 1, 42, 17734475, 99, 40, 4433619);
//const ModeComposite Composite::MODEPAL312P(44, 76, 420, 28, 8, 23, 272, 9, 1, 20, 8867238, 50, 20, 4433619);
//const ModeComposite Composite::MODENTSC312P(64, 96, 640, 56, 8, 23, 272, 9, 1, 32, 13333333, 70, 38, 4433619);
//4.43361875 * 4
const PinConfigComposite Composite::GameWing(22, 14, 32, 15, 33, 27, 12, 13);
const PinConfigComposite Composite::XPlayer(32, 27, 14, 12, 13, 4, 21, 22);
Composite::Composite(const int i2sIndex)
: I2S(i2sIndex)
{
dmaBufferDescriptors = 0;
}
bool Composite::init(const ModeComposite &mode, const int *pinMap, const int bitCount)
{
this->mode = mode;
int xres = mode.hRes;
int yres = mode.vRes / mode.vDiv;
blankLevel = 72;
burstAmp = 32;
syncLevel = 0;
propagateResolution(xres, yres);
totalLines = mode.linesPerField();
allocateLineBuffers();
currentLine = 0;
vSyncPassed = false;
initParallelOutputMode(pinMap, mode.pixelClock, bitCount);
startTX();
return true;
}
void Composite::getClockSetting(long *sampleRate, int *n, int *a, int *b, int *div)
{
if(sampleRate)
*sampleRate = mode.pixelClock;
if(n)
*n = 2;
if(a)
*a = 1;
if(b)
*b = 0;
if(div)
*div = 6;
}
int Composite::burst(int sampleNumber, bool even)
{
return blankLevel;
}
///complete ringbuffer from frame
void Composite::allocateLineBuffers(void **frameBuffer)
{
//simple buffers
dmaBufferDescriptorCount = totalLines;
dmaBufferDescriptors = DMABufferDescriptor::allocateDescriptors(dmaBufferDescriptorCount);
for (int i = 0; i < dmaBufferDescriptorCount; i++)
dmaBufferDescriptors[i].next(dmaBufferDescriptors[(i + 1) % dmaBufferDescriptorCount]);
for (int i = 0; i < totalLines; i++)
{
dmaBufferDescriptors[i].setBuffer(frameBuffer[i], 856);
}
return;
dmaBufferDescriptorCount = totalLines * 2 + mode.vRes;
int inactiveSamples = mode.hFront + mode.hSync;
int activeSamples = mode.hRes;
int syncSamples = mode.pixelsPerLine() / 2;
shortSyncBuffer = DMABufferDescriptor::allocateBuffer(syncSamples * bytesPerSample(), true);
longSyncBuffer = DMABufferDescriptor::allocateBuffer(syncSamples * bytesPerSample(), true);
lineSyncBuffer[0] = DMABufferDescriptor::allocateBuffer(inactiveSamples * bytesPerSample(), true);
lineSyncBuffer[1] = DMABufferDescriptor::allocateBuffer(inactiveSamples * bytesPerSample(), true);
lineBlankBuffer = DMABufferDescriptor::allocateBuffer(mode.hRes * bytesPerSample() + mode.hBack, true, blankLevel * 0x1010101);
lineBackBlankBuffer = DMABufferDescriptor::allocateBuffer(mode.hBack * bytesPerSample(), true, blankLevel * 0x1010101);
if(bytesPerSample() == 1)
{
int i = 0;
for (int j = 0; j < mode.hSync; j++)
{
((unsigned char *)(lineSyncBuffer[0]))[i ^ 2] = syncLevel;
((unsigned char *)(lineSyncBuffer[1]))[i++ ^ 2] = syncLevel;
}
for (int j = 0; j < mode.hFront; j++)
{
((unsigned char *)(lineSyncBuffer[0]))[i ^ 2] = burst(j + mode.hSync, true);
((unsigned char *)(lineSyncBuffer[1]))[i++ ^ 2] = burst(j + mode.hSync, false);
}
for (int i = 0; i < syncSamples; i++)
{
if(i < mode.shortSync)
((unsigned char *)shortSyncBuffer)[i ^ 2] = blankLevel;
else
((unsigned char *)shortSyncBuffer)[i ^ 2] = syncLevel;
if(i < syncSamples - mode.shortSync)
((unsigned char *)longSyncBuffer)[i ^ 2] = blankLevel;
else
((unsigned char *)longSyncBuffer)[i ^ 2] = syncLevel;
}
for (int i = 0; i < mode.hRes + mode.hBack; i++)
((unsigned char *)lineBlankBuffer)[i ^ 2] = blankLevel;
}
//bytesPerSample() == 2 is not implemented
dmaBufferDescriptors = DMABufferDescriptor::allocateDescriptors(dmaBufferDescriptorCount);
for (int i = 0; i < dmaBufferDescriptorCount; i++)
dmaBufferDescriptors[i].next(dmaBufferDescriptors[(i + 1) % dmaBufferDescriptorCount]);
int d = 0;
for(int i = 0; i < 6; i++)
dmaBufferDescriptors[d++].setBuffer(shortSyncBuffer, syncSamples * bytesPerSample());
for(int i = 0; i < 5; i++)
dmaBufferDescriptors[d++].setBuffer(longSyncBuffer, syncSamples * bytesPerSample());
for(int i = 0; i < 5; i++)
dmaBufferDescriptors[d++].setBuffer(shortSyncBuffer, syncSamples * bytesPerSample());
for (int i = 0; i < mode.vFront; i++)
{
dmaBufferDescriptors[d++].setBuffer(lineSyncBuffer[i & 1], inactiveSamples * bytesPerSample());
dmaBufferDescriptors[d++].setBuffer(lineBlankBuffer, (mode.hRes + mode.hBack) * bytesPerSample());
}
for (int i = 0; i < mode.vRes; i++)
{
dmaBufferDescriptors[d++].setBuffer(lineSyncBuffer[(i + mode.vFront) & 1], inactiveSamples * bytesPerSample());
dmaBufferDescriptors[d++].setBuffer(frameBuffer[i / mode.vDiv], mode.hRes * bytesPerSample());
dmaBufferDescriptors[d++].setBuffer(lineBackBlankBuffer, mode.hBack * bytesPerSample());
}
for (int i = 0; i < mode.vBack; i++)
{
dmaBufferDescriptors[d++].setBuffer(lineSyncBuffer[(i + mode.vFront + mode.vBack) & 1], inactiveSamples * bytesPerSample());
dmaBufferDescriptors[d++].setBuffer(lineBlankBuffer, (mode.hRes + mode.hBack) * bytesPerSample());
}
}
void Composite::vSync()
{
vSyncPassed = true;
}
void Composite::interrupt()
{
}
void Composite::interruptPixelLine(int y, unsigned long *pixels)
{
}