summaryrefslogtreecommitdiff
path: root/Source/DirectFB/gfxdrivers/cyber5k/cyber5k_overlay.c
blob: b4638dfb80b49092a43034a2e1d0b3fecefbd82a (plain)
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
/*
   (c) Copyright 2001-2009  The world wide DirectFB Open Source Community (directfb.org)
   (c) Copyright 2000-2004  Convergence (integrated media) GmbH

   All rights reserved.

   Written by Denis Oliver Kropp <dok@directfb.org>,
              Andreas Hundt <andi@fischlustig.de>,
              Sven Neumann <neo@directfb.org>,
              Ville Syrjälä <syrjala@sci.fi> and
              Claudio Ciccani <klan@users.sf.net>.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#include <directfb.h>

#include <core/coredefs.h>

#include "cyber5k.h"
#include "cyber5k_overlay.h"
#include "regs.h"
#include "mmio.h"

static int overlay_byte_per_pixel = 2;
static int overlay_init = 0;

static unsigned char savedReg74, savedReg75; /*FIFO control registers for 2D Graphics*/
static unsigned char savedRegD9[2], savedRegDA[2], savedRegDD[2]; /*FIFO control registers for Overlay*/
/*Following is our FIFO policy number, should be programmed to
0x3CE/0x74, 0x3CE/0x75, 0x3CE(0x3C4)/0xD9, 0x3CE(0x3C4)/0xDA,
0x3CE(0x3c4)/0xDD respectively in order to get a best memory bandwidth.
Current value is a group of experence value based on 70MHZ EDO/SG RAM.*/
static unsigned char bFIFOPolicyNum[5] = {0x10, 0x10, 0x1C, 0x1C, 0x06};


static void
cyber_videoreg_mask( unsigned char index, unsigned char value, unsigned char mask )
{
     unsigned char tmp;

     cyber_out8( cyber_mmio, GRAINDEX, index );
     tmp = cyber_in8( cyber_mmio, GRADATA );
     tmp &= mask;
     tmp |= value;
     cyber_out8( cyber_mmio, GRADATA, tmp );
}

static void
cyber_seqreg_mask( unsigned char index, unsigned char value, unsigned char mask )
{
     unsigned char tmp;

     cyber_out8( cyber_mmio, SEQINDEX, index );
     tmp = cyber_in8( cyber_mmio, SEQDATA );

     tmp &= mask;
     tmp |= value;
     cyber_out8( cyber_mmio, SEQDATA, tmp );
}

static void
cyber_overlayreg_mask( unsigned char index, unsigned char value, unsigned char mask ) {
     unsigned char tmp;

     cyber_out8( cyber_mmio, GRAINDEX, index );
     tmp = cyber_in8( cyber_mmio, GRADATA );

     tmp &= mask;
     tmp |= value;
     cyber_out8(cyber_mmio, GRADATA, tmp);
}

void cyber_cleanup_overlay(void)
{
     /*restore FIFO control regs*/
     cyber_seqreg_mask(0xA7, 0x0, ~0x5);


     if (!overlay_init)
          return;
     overlay_init = 0;


     cyber_grphw(0x74, savedReg74);
     cyber_grphw(0x75, savedReg75);

     cyber_grphw(0xD9, savedRegD9[0]);
     cyber_grphw(0xDA, savedRegDA[0]);
     cyber_grphw(0xDD, savedRegDD[0]);

     cyber_seqw(0xD9, savedRegD9[1]);
     cyber_seqw(0xDA, savedRegDA[1]);
     cyber_seqw(0xDD, savedRegDD[1]);
}

void cyber_init_overlay(void)
{
     /*Clear Overlay path first*/
     cyber_grphw(DISP_CTL_I, 0x00);

     /* Video Display Vertical Starting Line (may not need initiate here)*/
     cyber_grphw(DEST_RECT_TOP_L, 0x00);
     cyber_grphw(DEST_RECT_TOP_H, 0x00);

     /* Overlay Vertical DDA Increment Value*/
     cyber_grphw(DDA_Y_INC_L, 0x00);
     cyber_grphw(DDA_Y_INC_H, 0x10);

     /* Video Memory Starting Address*/
     cyber_grphw(MEMORY_START_L, 0x00);
     cyber_grphw(MEMORY_START_M, 0x0f);
     cyber_grphw(MEMORY_START_H, 0x03);  /* Temporary fixed to 0x30f00 = 0xc3c00 >> 2*/
     /* 0x3c00 = 0x300*0x14 = 768*20*/

     /* Video Display Horizontal Starting Pixel -- may not need init here*/
     cyber_grphw(DEST_RECT_LEFT_L, 0x20);
     cyber_grphw(DEST_RECT_LEFT_H, 0x00);

     /* Video Display Horizontal Ending Pixel -- may not need init here*/
     cyber_grphw(DEST_RECT_RIGHT_L, 0x60);
     cyber_grphw(DEST_RECT_RIGHT_H, 0x01);

     /* Video Display Vertical Ending Line -- may not need init here*/
     cyber_grphw(DEST_RECT_BOTTOM_L, 0xe0);
     cyber_grphw(DEST_RECT_BOTTOM_H, 0x00);

     /* Video Color Compare Register*/
     cyber_grphw(COLOR_CMP_RED,  0x00);
     cyber_grphw(COLOR_CMP_GREEN,0x00);
     cyber_grphw(COLOR_CMP_BLUE, 0x00);

     /* Video Horizontal DDA Increment Value*/
     cyber_grphw(DDA_X_INC_L, 0x00);
     cyber_grphw(DDA_X_INC_H, 0x10);

     /* Video Format Control*/
     cyber_grphw(VIDEO_FORMAT, 0x00);

     /* Video Misc Control*/
     cyber_grphw(MISC_CTL_I, 0x00);

     cyber_grphw(MISC_CTL_I, 0x01); /* Video Misc Control*/

     /*default to colorkey*/
     cyber_grphw(DISP_CTL_I, 0x04 );

#ifdef NTSCTVOUT /*if your TV output mode is NTSC*/
     cyber_seqreg_mask(0xA6, 0x20, ~0x30);
#else  /*if your TV output mode is PAL*/
     cyber_seqreg_mask(0xA6, 0x30, ~0x30);
#endif


     if (overlay_init)
          return;
     overlay_init = 1;



/* the following code is commented out, since saved values are not clean if */
/* DirectFB crashed while underlay was enabled, hardcoded bootup            */
/* values instead (see below)                                               */

/*
     cyber_out8(cyber_mmio, GRAINDEX, 0x74);
     savedReg74 = cyber_in8(cyber_mmio, GRADATA);
     cyber_out8(cyber_mmio, GRAINDEX, 0x75);
     savedReg75 = cyber_in8(cyber_mmio, GRADATA);

     cyber_out8(cyber_mmio, GRAINDEX, 0xD9);
     savedRegD9[0] = cyber_in8(cyber_mmio, GRADATA);
     cyber_out8(cyber_mmio, GRAINDEX, 0xDA);
     savedRegDA[0] = cyber_in8(cyber_mmio, GRADATA);
     cyber_out8(cyber_mmio, GRAINDEX, 0xDD);
     savedRegDD[0] = cyber_in8(cyber_mmio, GRADATA);

     cyber_out8(cyber_mmio, SEQINDEX, 0xD9);
     savedRegD9[1] = cyber_in8(cyber_mmio, SEQDATA);
     cyber_out8(cyber_mmio, SEQINDEX, 0xDA);
     savedRegDA[1] = cyber_in8(cyber_mmio, SEQDATA);
     cyber_out8(cyber_mmio, SEQINDEX, 0xDD);
     savedRegDD[1] = cyber_in8(cyber_mmio, SEQDATA);
     */


     savedReg74    = 0x1b;
     savedReg74    = 0x1e;

     savedRegD9[0] = 0x0f;
     savedRegDA[0] = 0x1b;
     savedRegDD[0] = 0x00;

     savedRegD9[1] = 0x0f;
     savedRegDA[1] = 0x1b;
     savedRegDD[1] = 0x00;
}

void cyber_change_overlay_fifo(void)
{
     cyber_grphw(0x74, bFIFOPolicyNum[0]);
     cyber_grphw(0x75, bFIFOPolicyNum[1]);
     cyber_grphw(0xD9, bFIFOPolicyNum[2]);
     cyber_grphw(0xDA, bFIFOPolicyNum[3]);

     cyber_videoreg_mask(0xA6, 0x08, ~0x08);
     cyber_videoreg_mask(0xF1, 0x40, (unsigned char)(~0xC0));
     cyber_overlayreg_mask(FIFO_CTL_I, bFIFOPolicyNum[4] & 0x05, ~0x05);
     cyber_overlayreg_mask(FIFO_CTL_I, 0x2, ~0x02);
}

void cyber_set_overlay_format(int format) {
     switch (format) {
          case OVERLAY_YUV422:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x00, 0xF8 );
               overlay_byte_per_pixel = 2;
               break;
          case OVERLAY_RGB555:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x01, 0xF8 );
               overlay_byte_per_pixel = 2;
               break;
          case OVERLAY_RGB565:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x02, 0xF8 );
               overlay_byte_per_pixel = 2;
               break;
          case OVERLAY_RGB888:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x03, 0xF8 );
               overlay_byte_per_pixel = 3;
               break;
          case OVERLAY_RGB8888:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x04, 0xF8 );
               overlay_byte_per_pixel = 4;
               break;
          case OVERLAY_RGB8:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x05, 0xF8 );
               overlay_byte_per_pixel = 1;
               break;
          case OVERLAY_RGB4444:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x06, 0xF8 );
               overlay_byte_per_pixel = 2;
               break;
          case OVERLAY_RGB8T:
               cyber_overlayreg_mask( VIDEO_FORMAT, 0x07, 0xF8 );
               overlay_byte_per_pixel = 1;
               break;
     }
}

void cyber_set_overlay_mode(int mode)
{
     switch (mode) {
          case OVERLAY_COLORKEY:
               cyber_overlayreg_mask( DISP_CTL_I, 0x00, 0xFD );
               break;
          case OVERLAY_WINDOWKEY:
          default:
               cyber_overlayreg_mask( DISP_CTL_I, 0x02, 0xFD );
               break;
     }
}

void cyber_set_overlay_srcaddr(int addr, int x, int y, int width, int pitch)
{
     unsigned char bHigh;
     int wByteFetch;

     addr += y * pitch  +  x * overlay_byte_per_pixel;
     addr >>= 2;

     /*playback start addr*/
     cyber_grphw( MEMORY_START_L, (unsigned char)( addr & 0x0000FF) );
     cyber_grphw( MEMORY_START_M, (unsigned char)((addr & 0x00FF00) >> 8) );
     cyber_grphw( MEMORY_START_H, (unsigned char)((addr & 0xFF0000) >> 16) );

     /* pitch is a multiple of 64 bits*/
     pitch >>= 3; /* 64 bit address field*/
     wByteFetch = (width * overlay_byte_per_pixel + 7) >> 3;

     bHigh = (unsigned char)(pitch >> 8) & 0x0F;
     bHigh = bHigh | (((unsigned char)(wByteFetch >> 8)) << 4 );

     cyber_grphw( MEMORY_PITCH_L, (unsigned char)(pitch) );
     cyber_grphw( MEMORY_PITCH_H, bHigh );

     cyber_grphw( MEMORY_OFFSET_PHASE, (unsigned char)(wByteFetch) );

     if (width > 720)  /*Turn off interpolation*/
          cyber_overlayreg_mask( DISP_CTL_I, 0x20, 0xDF );
     else { /*Turn off interpolation*/
          if (width > 360) { /* Y Only*/
               cyber_seqreg_mask(0xA6, 0x40, ~0x40);
          }
          else {
               cyber_seqreg_mask(0xA6, 0x00, ~0x40);
          }

          cyber_overlayreg_mask( DISP_CTL_I, 0x00, 0xDF );
     }
}

void cyber_set_overlay_window(int left, int top, int right, int bottom)
{
     cyber_grphw( DEST_RECT_LEFT_L,  (unsigned char)(left      ) );
     cyber_grphw( DEST_RECT_LEFT_H,  (unsigned char)(left  >> 8) );
     cyber_grphw( DEST_RECT_RIGHT_L, (unsigned char)(right     ) );
     cyber_grphw( DEST_RECT_RIGHT_H, (unsigned char)(right >> 8) );

     cyber_grphw( DEST_RECT_TOP_L,    (unsigned char)(top        ) );
     cyber_grphw( DEST_RECT_TOP_H,    (unsigned char)(top    >> 8) );
     cyber_grphw( DEST_RECT_BOTTOM_L, (unsigned char)(bottom     ) );
     cyber_grphw( DEST_RECT_BOTTOM_H, (unsigned char)(bottom >> 8) );
}

void cyber_set_overlay_scale( unsigned char bEnableBob, int wSrcXExt, int wDstXExt, int wSrcYExt, int wDstYExt )
{
     int dwScale;

     cyber_grphw( DDA_X_INIT_L, 0x0 );     /* set to 0x800;*/
     cyber_grphw( DDA_X_INIT_H, 0x8 );
     if ( wSrcXExt == wDstXExt )
          dwScale = 0x1000;
     else
          dwScale = ( wSrcXExt * 0x1000 ) / wDstXExt;
     cyber_grphw( DDA_X_INC_L, (unsigned char)( dwScale & 0x00FF) );
     cyber_grphw( DDA_X_INC_H, (unsigned char)((dwScale & 0xFF00) >> 8) );

     cyber_grphw( DDA_Y_INIT_L, 0x0 );     /* set to 0x800;*/
     cyber_grphw( DDA_Y_INIT_H, 0x8 );

     if ( wSrcYExt == wDstYExt )
          dwScale = 0x1000;
     else
          dwScale = ( wSrcYExt * 0x1000 ) / wDstYExt;


     if (bEnableBob == 0) {/*Disable Bob mode*/
          cyber_seqreg_mask(0xA7, 0x0, ~0x5); /*Bob/Weave disable*/
     }
     else {/*Enable Bob mode*/
          wSrcYExt = wSrcYExt / 2;
	     if (wSrcYExt == wDstYExt)
	          dwScale = 0x1000;
	     else
	          dwScale = ( wSrcYExt * 0x1000 ) / wDstYExt;
	     if (dwScale <= 0x815 && dwScale >= 0x7eb) {
	          cyber_seqreg_mask(0xA7, 0x5, ~0x5); /*Bob/Weave enable*/
	     }
	     else {
	          cyber_seqreg_mask(0xA7, 0x4, ~0x5); /*Bob/Weave enable*/
	     }
	}

     cyber_grphw( DDA_Y_INC_L, (unsigned char)( dwScale & 0x00FF) );
     cyber_grphw( DDA_Y_INC_H, (unsigned char)((dwScale & 0xFF00) >> 8) );
}

void cyber_enable_overlay(int enable)
{
     if (enable)
          cyber_overlayreg_mask( DISP_CTL_I, 0x84, (unsigned char)(~0x84) );
     else
          cyber_overlayreg_mask( DISP_CTL_I, 0x00, 0x7F );  /* Disable Vafc !!!*/
}