Mercurial > mplayer.hg
annotate vidix/drivers/cyberblade_vid.c @ 10612:8e678e833591
docs updates
author | diego |
---|---|
date | Fri, 15 Aug 2003 12:05:18 +0000 |
parents | f6d2772efca3 |
children | 972d1998bde9 |
rev | line source |
---|---|
8505 | 1 /* |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
2 Driver for CyberBlade/i1 - Version 0.1.4 |
8505 | 3 |
4 Copyright (C) 2002 by Alastair M. Robinson. | |
8513 | 5 Official homepage: http://www.blackfiveservices.co.uk/EPIAVidix.shtml |
6 | |
8505 | 7 Based on Permedia 3 driver by Måns Rullgård |
8 | |
9 Thanks to Gilles Frattini for bugfixes | |
10 | |
11 This program is free software; you can redistribute it and/or modify | |
12 it under the terms of the GNU General Public License as published by | |
13 the Free Software Foundation; either version 2 of the License, or | |
14 (at your option) any later version. | |
15 | |
16 This program is distributed in the hope that it will be useful, | |
17 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 GNU General Public License for more details. | |
20 | |
21 You should have received a copy of the GNU General Public License | |
22 along with this program; if not, write to the Free Software | |
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
25 Changes: |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
26 18/01/03 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
27 MMIO is no longer used, sidestepping cache issues on EPIA-800 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
28 TV-Out modes are now better supported - this should be the end |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
29 of the magenta stripes :) |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
30 Brightness/Contrast controls disabled for the time being - they were |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
31 seriously degrading picture quality, especially with TV-Out. |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
32 |
8505 | 33 To Do: |
34 Implement Hue/Saturation controls | |
35 Support / Test multiple frames | |
36 Test colour-key code more extensively | |
37 */ | |
38 | |
39 #include <errno.h> | |
40 #include <stdio.h> | |
41 #include <stdlib.h> | |
42 #include <string.h> | |
43 #include <inttypes.h> | |
44 #include <unistd.h> | |
45 | |
46 #include "../vidix.h" | |
47 #include "../fourcc.h" | |
48 #include "../../libdha/libdha.h" | |
49 #include "../../libdha/pci_ids.h" | |
50 #include "../../libdha/pci_names.h" | |
51 #include "../../config.h" | |
52 | |
53 #include "cyberblade_regs.h" | |
54 | |
55 pciinfo_t pci_info; | |
56 | |
57 char save_colourkey[6]; | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
58 char *cyberblade_mem; |
8505 | 59 |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
60 #ifdef DEBUG_LOGFILE |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
61 FILE *logfile=0; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
62 #define LOGWRITE(x) {if(logfile) fprintf(logfile,x);} |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
63 #else |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
64 #define LOGWRITE(x) |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
65 #endif |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
66 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
67 /* Helper functions for reading registers. */ |
8505 | 68 |
69 static int CRINW(int reg) | |
70 { | |
71 int result; | |
72 result=CRINB(reg); | |
73 result|=CRINB(reg+1)<<8; | |
74 return(result); | |
75 } | |
76 | |
77 static void CROUTW(int reg,int val) | |
78 { | |
79 CROUTB(reg,val&255); | |
80 CROUTB(reg+1,(val>>8)&255); | |
81 } | |
82 | |
83 static int SRINW(int reg) | |
84 { | |
85 int result; | |
86 result=SRINB(reg); | |
87 result|=SRINB(reg+1)<<8; | |
88 return(result); | |
89 } | |
90 | |
91 static void SROUTW(int reg,int val) | |
92 { | |
93 SROUTB(reg,val&255); | |
94 SROUTB(reg+1,(val>>8)&255); | |
95 } | |
96 | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
97 void DumpRegisters() |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
98 { |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
99 int reg,val; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
100 #ifdef DEBUG_LOGFILE |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
101 if(logfile) |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
102 { |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
103 LOGWRITE("CRTC Register Dump:\n") |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
104 for(reg=0;reg<256;++reg) |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
105 { |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
106 val=CRINB(reg); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
107 fprintf(logfile,"CR0x%2x: 0x%2x\n",reg,val); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
108 } |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
109 LOGWRITE("SR Register Dump:\n") |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
110 for(reg=0;reg<256;++reg) |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
111 { |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
112 val=SRINB(reg); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
113 fprintf(logfile,"SR0x%2x: 0x%2x\n",reg,val); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
114 } |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
115 } |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
116 #endif |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
117 } |
8505 | 118 /* --- */ |
119 | |
120 static vidix_capability_t cyberblade_cap = | |
121 { | |
122 "Trident CyberBlade i1 driver", | |
123 "Alastair M. Robinson <blackfive@fakenhamweb.co.uk>", | |
124 TYPE_OUTPUT, | |
125 { 0, 0, 0, 0 }, | |
126 1024, | |
127 1024, | |
128 4, | |
129 4, | |
130 -1, | |
131 FLAG_UPSCALER|FLAG_DOWNSCALER, | |
132 VENDOR_TRIDENT, | |
133 -1, | |
134 { 0, 0, 0, 0 } | |
135 }; | |
136 | |
137 | |
138 unsigned int vixGetVersion(void) | |
139 { | |
140 return(VIDIX_VERSION); | |
141 } | |
142 | |
143 | |
144 static unsigned short cyberblade_card_ids[] = | |
145 { | |
146 DEVICE_TRIDENT_CYBERBLADE_I1 | |
147 }; | |
148 | |
149 | |
150 static int find_chip(unsigned chip_id) | |
151 { | |
152 unsigned i; | |
153 for(i = 0;i < sizeof(cyberblade_card_ids)/sizeof(unsigned short);i++) | |
154 { | |
155 if(chip_id == cyberblade_card_ids[i]) return i; | |
156 } | |
157 return -1; | |
158 } | |
159 | |
160 int vixProbe(int verbose, int force) | |
161 { | |
162 pciinfo_t lst[MAX_PCI_DEVICES]; | |
163 unsigned i,num_pci; | |
164 int err; | |
165 err = pci_scan(lst,&num_pci); | |
166 if(err) | |
167 { | |
168 printf("[cyberblade] Error occured during pci scan: %s\n",strerror(err)); | |
169 return err; | |
170 } | |
171 else | |
172 { | |
173 err = ENXIO; | |
174 for(i=0; i < num_pci; i++) | |
175 { | |
176 if(lst[i].vendor == VENDOR_TRIDENT) | |
177 { | |
178 int idx; | |
179 const char *dname; | |
180 idx = find_chip(lst[i].device); | |
181 if(idx == -1) | |
182 continue; | |
183 dname = pci_device_name(VENDOR_TRIDENT, lst[i].device); | |
184 dname = dname ? dname : "Unknown chip"; | |
185 printf("[cyberblade] Found chip: %s\n", dname); | |
9767
f6d2772efca3
Ignore disabled cards. (Jon Burgess <jburgess@uklinux.net>)
ranma
parents:
9023
diff
changeset
|
186 if ((lst[i].command & PCI_COMMAND_IO) == 0) |
f6d2772efca3
Ignore disabled cards. (Jon Burgess <jburgess@uklinux.net>)
ranma
parents:
9023
diff
changeset
|
187 { |
f6d2772efca3
Ignore disabled cards. (Jon Burgess <jburgess@uklinux.net>)
ranma
parents:
9023
diff
changeset
|
188 printf("[cyberblade] Device is disabled, ignoring\n"); |
f6d2772efca3
Ignore disabled cards. (Jon Burgess <jburgess@uklinux.net>)
ranma
parents:
9023
diff
changeset
|
189 continue; |
f6d2772efca3
Ignore disabled cards. (Jon Burgess <jburgess@uklinux.net>)
ranma
parents:
9023
diff
changeset
|
190 } |
8505 | 191 cyberblade_cap.device_id = lst[i].device; |
192 err = 0; | |
193 memcpy(&pci_info, &lst[i], sizeof(pciinfo_t)); | |
194 break; | |
195 } | |
196 } | |
197 } | |
198 | |
199 if(err && verbose) printf("[cyberblade] Can't find chip\n"); | |
200 return err; | |
201 } | |
202 | |
203 | |
204 int vixInit(void) | |
205 { | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
206 cyberblade_mem = map_phys_mem(pci_info.base0, 0x800000); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
207 enable_app_io(); |
8505 | 208 save_colourkey[0]=SRINB(0x50); |
209 save_colourkey[1]=SRINB(0x51); | |
210 save_colourkey[2]=SRINB(0x52); | |
211 save_colourkey[3]=SRINB(0x54); | |
212 save_colourkey[4]=SRINB(0x55); | |
213 save_colourkey[5]=SRINB(0x56); | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
214 #ifdef DEBUG_LOGFILE |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
215 logfile=fopen("/tmp/cyberblade_vidix.log","w"); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
216 #endif |
8505 | 217 return 0; |
218 } | |
219 | |
220 void vixDestroy(void) | |
221 { | |
222 int protect; | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
223 #ifdef DEBUG_LOGFILE |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
224 if(logfile) |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
225 fclose(logfile); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
226 #endif |
8505 | 227 protect=SRINB(0x11); |
228 SROUTB(0x11, 0x92); | |
229 CROUTB(0x8E, 0xc4); /* Disable overlay */ | |
230 SROUTB(0x50,save_colourkey[0]); | |
231 SROUTB(0x51,save_colourkey[1]); | |
232 SROUTB(0x52,save_colourkey[2]); | |
233 SROUTB(0x54,save_colourkey[3]); | |
234 SROUTB(0x55,save_colourkey[4]); | |
235 SROUTB(0x56,save_colourkey[5]); | |
236 SROUTB(0x11, protect); | |
8513 | 237 disable_app_io(); |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
238 unmap_phys_mem(cyberblade_mem, 0x800000); |
8505 | 239 } |
240 | |
241 | |
242 int vixGetCapability(vidix_capability_t *to) | |
243 { | |
244 memcpy(to, &cyberblade_cap, sizeof(vidix_capability_t)); | |
245 return 0; | |
246 } | |
247 | |
248 | |
249 static int is_supported_fourcc(uint32_t fourcc) | |
250 { | |
251 switch(fourcc) | |
252 { | |
253 case IMGFMT_YUY2: | |
254 case IMGFMT_YV12: | |
255 case IMGFMT_YVU9: | |
256 case IMGFMT_BGR16: | |
257 return 1; | |
258 default: | |
259 return 0; | |
260 } | |
261 } | |
262 | |
263 int vixQueryFourcc(vidix_fourcc_t *to) | |
264 { | |
265 if(is_supported_fourcc(to->fourcc)) | |
266 { | |
267 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
268 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
269 VID_DEPTH_12BPP| VID_DEPTH_15BPP| | |
270 VID_DEPTH_16BPP| VID_DEPTH_24BPP| | |
271 VID_DEPTH_32BPP; | |
272 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; | |
273 return 0; | |
274 } | |
275 else | |
276 to->depth = to->flags = 0; | |
277 return ENOSYS; | |
278 } | |
279 | |
280 | |
281 static int frames[VID_PLAY_MAXFRAMES]; | |
282 | |
283 static vidix_grkey_t cyberblade_grkey; | |
284 | |
285 int vixGetGrKeys(vidix_grkey_t *grkey) | |
286 { | |
287 memcpy(grkey, &cyberblade_grkey, sizeof(vidix_grkey_t)); | |
288 return(0); | |
289 } | |
290 | |
291 int vixSetGrKeys(const vidix_grkey_t *grkey) | |
292 { | |
293 int pixfmt=CRINB(0x38); | |
8513 | 294 int protect; |
8505 | 295 memcpy(&cyberblade_grkey, grkey, sizeof(vidix_grkey_t)); |
296 | |
8513 | 297 protect=SRINB(0x11); |
298 SROUTB(0x11, 0x92); | |
299 | |
8505 | 300 if(pixfmt&0x28) /* 32 or 24 bpp */ |
301 { | |
302 SROUTB(0x50, cyberblade_grkey.ckey.blue); /* Colour Key */ | |
303 SROUTB(0x51, cyberblade_grkey.ckey.green); /* Colour Key */ | |
304 SROUTB(0x52, cyberblade_grkey.ckey.red); /* Colour Key */ | |
305 SROUTB(0x54, 0xff); /* Colour Key Mask */ | |
306 SROUTB(0x55, 0xff); /* Colour Key Mask */ | |
307 SROUTB(0x56, 0xff); /* Colour Key Mask */ | |
308 } | |
309 else | |
310 { | |
311 int tmp=((cyberblade_grkey.ckey.blue & 0xF8)>>3) | |
312 | ((cyberblade_grkey.ckey.green & 0xfc)<<3) | |
313 | ((cyberblade_grkey.ckey.red & 0xf8)<<8); | |
314 SROUTB(0x50, tmp&0xff); /* Colour Key */ | |
315 SROUTB(0x51, (tmp>>8)&0xff); /* Colour Key */ | |
316 SROUTB(0x52, 0); /* Colour Key */ | |
317 SROUTB(0x54, 0xff); /* Colour Key Mask */ | |
318 SROUTB(0x55, 0xff); /* Colour Key Mask */ | |
319 SROUTB(0x56, 0x00); /* Colour Key Mask */ | |
320 } | |
8513 | 321 SROUTB(0x11,protect); |
8505 | 322 return(0); |
323 } | |
324 | |
325 | |
326 vidix_video_eq_t equal = | |
327 { | |
328 VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | VEQ_CAP_HUE, | |
329 300, 100, 0, 0, 0, 0, 0, 0 | |
330 }; | |
331 | |
332 int vixPlaybackGetEq( vidix_video_eq_t * eq) | |
333 { | |
334 memcpy(eq,&equal,sizeof(vidix_video_eq_t)); | |
335 return 0; | |
336 } | |
337 | |
338 int vixPlaybackSetEq( const vidix_video_eq_t * eq) | |
339 { | |
340 int br,sat,cr,protect; | |
341 if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness; | |
342 if(eq->cap & VEQ_CAP_CONTRAST) equal.contrast = eq->contrast; | |
343 if(eq->cap & VEQ_CAP_SATURATION) equal.saturation = eq->saturation; | |
344 if(eq->cap & VEQ_CAP_HUE) equal.hue = eq->hue; | |
345 if(eq->cap & VEQ_CAP_RGB_INTENSITY) | |
346 { | |
347 equal.red_intensity = eq->red_intensity; | |
348 equal.green_intensity = eq->green_intensity; | |
349 equal.blue_intensity = eq->blue_intensity; | |
350 } | |
351 equal.flags = eq->flags; | |
352 | |
353 cr = (equal.contrast) * 31 / 2000; cr+=16; | |
354 if (cr < 0) cr = 0; if(cr > 7) cr = 7; | |
355 cr=cr<<4 | cr; | |
356 | |
357 br = (equal.brightness+1000) * 63 / 2000; | |
358 if (br < 0) br = 0; if(br > 63) br = 63; | |
359 if(br>32) br-=32; else br+=32; | |
360 | |
361 sat = (equal.saturation + 1000) * 16 / 2000; | |
362 if (sat < 0) sat = 0; if(sat > 31) sat = 31; | |
363 | |
364 protect=SRINB(0x11); | |
365 SROUTB(0x11, 0x92); | |
366 | |
367 SROUTB(0xBC,cr); | |
368 SROUTW(0xB0,(br<<10)|4); | |
369 | |
370 SROUTB(0x11, protect); | |
371 | |
372 return 0; | |
373 } | |
374 | |
375 | |
376 static int YOffs,UOffs,VOffs; | |
377 | |
378 int vixConfigPlayback(vidix_playback_t *info) | |
379 { | |
380 int shrink, zoom; | |
381 int src_w, drw_w; | |
382 int src_h, drw_h; | |
383 int hscale,vscale; | |
384 long base0; | |
385 int y_pitch, uv_pitch; | |
386 int protect=0; | |
387 int layout=0; | |
388 unsigned int i; | |
389 | |
390 if(!is_supported_fourcc(info->fourcc)) | |
391 return -1; | |
392 | |
393 src_w = info->src.w; | |
394 src_h = info->src.h; | |
395 | |
396 drw_w = info->dest.w; | |
397 drw_h = info->dest.h; | |
398 | |
399 switch(info->fourcc) | |
400 { | |
401 case IMGFMT_YUY2: | |
402 case IMGFMT_BGR16: | |
403 y_pitch = (src_w*2 + 15) & ~15; | |
404 uv_pitch = 0; | |
405 YOffs=VOffs=UOffs=info->offset.y = info->offset.v = info->offset.u = 0; | |
406 info->frame_size = y_pitch*src_h; | |
407 layout=0x0; /* packed */ | |
408 break; | |
409 case IMGFMT_YV12: | |
410 y_pitch = (src_w+15) & ~15; | |
411 uv_pitch = ((src_w/2)+7) & ~7; | |
412 YOffs=info->offset.y = 0; | |
413 VOffs=info->offset.v = y_pitch*src_h; | |
414 UOffs=info->offset.u = info->offset.v+(uv_pitch)*(src_h/2); | |
415 info->frame_size = y_pitch*src_h + 2*uv_pitch*(src_h/2); | |
416 layout=0x1; /* planar, 4:1:1 */ | |
417 break; | |
418 case IMGFMT_YVU9: | |
419 y_pitch = (src_w+15) & ~15; | |
420 uv_pitch = ((src_w/4)+3) & ~3; | |
421 YOffs=info->offset.y = 0; | |
422 VOffs=info->offset.v = y_pitch*src_h; | |
423 UOffs=info->offset.u = info->offset.v+(uv_pitch)*(src_h/4); | |
424 info->frame_size = y_pitch*src_h + 2*uv_pitch*(src_h/4); | |
425 layout=0x51; /* planar, 16:1:1 */ | |
426 break; | |
427 } | |
428 | |
8513 | 429 /* Assume we have 2 MB to play with */ |
430 info->num_frames = 0x200000 / info->frame_size; | |
8505 | 431 if(info->num_frames > VID_PLAY_MAXFRAMES) |
432 info->num_frames = VID_PLAY_MAXFRAMES; | |
433 | |
8513 | 434 /* Start at 6 MB. Let's hope it's not in use. */ |
435 base0 = 0x600000; | |
8505 | 436 info->dga_addr = cyberblade_mem + base0; |
437 | |
438 info->dest.pitch.y = 16; | |
439 info->dest.pitch.u = 16; | |
440 info->dest.pitch.v = 16; | |
441 | |
442 for(i = 0; i < info->num_frames; i++) | |
443 { | |
444 info->offsets[i] = info->frame_size * i; | |
445 frames[i] = base0+info->offsets[i]; | |
446 } | |
447 | |
8513 | 448 OUTPORT8(0x3d4,0x39); |
449 OUTPORT8(0x3d5,INPORT(0x3d5)|1); | |
450 | |
451 SRINB(0x0b); /* Select new mode */ | |
452 | |
8505 | 453 /* Unprotect hardware registers... */ |
454 protect=SRINB(0x11); | |
455 SROUTB(0x11, 0x92); | |
456 | |
457 SROUTB(0x57, 0xc0); /* Playback key function */ | |
458 SROUTB(0x21, 0x34); /* Signature control */ | |
459 SROUTB(0x37, 0x30); /* Video key mode */ | |
460 | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
461 vixSetGrKeys(&cyberblade_grkey); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
462 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
463 /* compute_scale_factor(&src_w, &drw_w, &shrink, &zoom); */ |
8505 | 464 { |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
465 int HTotal,VTotal,HSync,VSync,Overflow,HDisp,VDisp; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
466 int HWinStart,VWinStart; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
467 int tx1,ty1,tx2,ty2; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
468 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
469 HTotal=CRINB(0x00); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
470 HSync=CRINB(0x04); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
471 VTotal=CRINB(0x06); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
472 VSync=CRINB(0x10); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
473 Overflow=CRINB(0x07); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
474 HTotal <<=3; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
475 HSync <<=3; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
476 VTotal |= (Overflow & 1) <<8; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
477 VTotal |= (Overflow & 0x20) <<4; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
478 VTotal +=4; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
479 VSync |= (Overflow & 4) <<6; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
480 VSync |= (Overflow & 0x80) <<2; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
481 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
482 if(CRINB(0xd1)&0x80) |
8505 | 483 { |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
484 int hcorr,vcorr; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
485 int TVHTotal,TVVTotal,TVHSyncStart,TVVSyncStart,TVOverflow; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
486 LOGWRITE("[cyberblade] Using TV-CRTC\n"); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
487 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
488 HDisp=(1+CRINB(0x01))*8; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
489 VDisp=1+CRINB(0x12); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
490 Overflow=CRINB(0x07); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
491 VDisp |= (Overflow & 2) <<7; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
492 VDisp |= (Overflow & 0x40) << 3; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
493 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
494 TVHTotal=CRINB(0xe0)*8; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
495 TVVTotal=CRINB(0xe6); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
496 TVOverflow=CRINB(0xe7); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
497 if(TVOverflow&0x20) TVVTotal|=512; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
498 if(TVOverflow&0x01) TVVTotal|=256; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
499 TVHTotal+=40; TVVTotal+=2; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
500 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
501 TVHSyncStart=CRINB(0xe4)*8; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
502 TVVSyncStart=CRINB(0xf0); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
503 if(TVOverflow&0x80) TVVSyncStart|=512; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
504 if(TVOverflow&0x04) TVVSyncStart|=256; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
505 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
506 HWinStart=(TVHTotal-HDisp)&15; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
507 HWinStart|=(HTotal-HDisp)&15; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
508 HWinStart+=(TVHTotal-TVHSyncStart)-49; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
509 |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
510 VWinStart=(TVVTotal-VDisp)/2-1; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
511 VWinStart-=(1-((TVVTotal-VDisp)&1))+4; |
8505 | 512 } |
513 else | |
514 { | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
515 LOGWRITE("[cyberblade] Using Standard CRTC\n"); |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
516 HWinStart=(HTotal-HSync)+15; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
517 VWinStart=(VTotal-VSync)-8; |
8505 | 518 } |
519 | |
8513 | 520 printf("[cyberblade] HTotal: 0x%x, HSStart: 0x%x\n",HTotal,HSync); |
521 printf(" VTotal: 0x%x, VStart: 0x%x\n",VTotal,VSync); | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
522 tx1=HWinStart+info->dest.x; |
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
523 ty1=VWinStart+info->dest.y; |
8505 | 524 tx2=tx1+info->dest.w; |
525 ty2=ty1+info->dest.h; | |
526 | |
527 CROUTW(0x86,tx1); | |
528 CROUTW(0x88,ty1); | |
529 CROUTW(0x8a,tx2); | |
530 CROUTW(0x8c,ty2+3); | |
531 } | |
532 | |
533 if(src_w==drw_w) | |
534 hscale=0; | |
535 else if(src_w<drw_w) | |
536 { | |
537 hscale=((src_w<<10)/(drw_w-2)) & 0x1fff; | |
538 } | |
539 else | |
540 { | |
541 hscale=0x8000 | ((((src_w/drw_w)-1)&7)<<10) | (((drw_w<<10)/src_w) & 0x3ff); | |
542 } | |
543 | |
544 vscale=(src_h<<10)/(drw_h); | |
545 if(drw_h<src_h) | |
546 vscale=0x8000|((drw_h<<10)/(src_h)); | |
547 | |
548 /* Write scale factors to hardware */ | |
549 | |
550 CROUTW(0x80,hscale); /* Horizontal Scale */ | |
551 CROUTW(0x82,vscale); /* Vertical Scale */ | |
552 | |
553 /* Now set the start address and data layout */ | |
554 { | |
555 int lb = (y_pitch+2) >> 2; | |
556 CROUTB(0x95, ((lb & 0x100)>>1) | 0x08 ); /* Linebuffer level bit 8 & threshold */ | |
557 CROUTB(0x96, (lb & 0xFF)); /* Linebuffer level */ | |
558 | |
559 CROUTB(0x97, 0x00); /* VDE Flags */ | |
560 CROUTB(0xBA, 0x00); /* Chroma key */ | |
561 CROUTB(0xBB, 0x00); /* Chroma key */ | |
562 CROUTB(0xBC, 0xFF); /* Chroma key */ | |
563 CROUTB(0xBD, 0xFF); /* Chroma key */ | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
564 CROUTB(0xBE, 0x04); /* Capture control */ |
8505 | 565 |
566 if(src_w > 384) | |
567 layout|=4; /* 2x line buffers */ | |
568 SROUTB(0x97, layout); | |
569 | |
570 CROUTW(0x90,y_pitch); /* Y Bytes per row */ | |
571 SROUTW(0x9A,uv_pitch); /* UV Bytes per row */ | |
572 | |
573 switch(info->fourcc) | |
574 { | |
575 case IMGFMT_BGR16: | |
576 CROUTB(0x8F, 0x24); /* VDE Flags - Edge Recovery & CSC Bypass */ | |
577 CROUTB(0xBF, 0x02); /* Video format - RGB16 */ | |
578 SROUTB(0xBE, 0x0); /* HSCB disabled */ | |
579 break; | |
580 default: | |
581 CROUTB(0x8F, 0x20); /* VDE Flags - Edge Recovery */ | |
582 CROUTB(0xBF, 0x00); /* Video format - YUV */ | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
583 SROUTB(0xBE, 0x00); /* HSCB disable - was 0x03*/ |
8505 | 584 break; |
585 } | |
586 | |
587 CROUTB(0x92, ((base0+info->offset.y) >> 3) &0xff); /* Lower 8 bits of start address */ | |
588 CROUTB(0x93, ((base0+info->offset.y) >> 11) &0xff); /* Mid 8 bits of start address */ | |
589 CROUTB(0x94, ((base0+info->offset.y) >> 19) &0xf); /* Upper 4 bits of start address */ | |
590 SROUTB(0x80, ((base0+info->offset.v) >> 3) &0xff); /* Lower 8 bits of start address */ | |
591 SROUTB(0x81, ((base0+info->offset.v) >> 11) &0xff); /* Mid 8 bits of start address */ | |
592 SROUTB(0x82, ((base0+info->offset.v) >> 19) &0xf); /* Upper 4 bits of start address */ | |
593 SROUTB(0x83, ((base0+info->offset.u) >> 3) &0xff); /* Lower 8 bits of start address */ | |
594 SROUTB(0x84, ((base0+info->offset.u) >> 11) &0xff); /* Mid 8 bits of start address */ | |
595 SROUTB(0x85, ((base0+info->offset.u) >> 19) &0xf); /* Upper 4 bits of start address */ | |
596 } | |
597 | |
598 vixPlaybackSetEq(&equal); | |
599 | |
600 /* Protect hardware registers again */ | |
601 SROUTB(0x11, protect); | |
602 return 0; | |
603 } | |
604 | |
605 | |
606 int vixPlaybackOn(void) | |
607 { | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
608 LOGWRITE("Enable overlay\n"); |
8505 | 609 CROUTB(0x8E, 0xd4); /* VDE Flags*/ |
610 | |
611 return 0; | |
612 } | |
613 | |
614 | |
615 int vixPlaybackOff(void) | |
616 { | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
617 LOGWRITE("Disable overlay\n"); |
8505 | 618 CROUTB(0x8E, 0xc4); /* VDE Flags*/ |
619 | |
620 return 0; | |
621 } | |
622 | |
623 | |
624 int vixPlaybackFrameSelect(unsigned int frame) | |
625 { | |
626 int protect; | |
9023
e40760677a83
Updated to v0.1.4 by Alastair Robinson <blackfive@fakenhamweb.co.uk>
alex
parents:
8513
diff
changeset
|
627 LOGWRITE("Frame select\n"); |
8505 | 628 protect=SRINB(0x11); |
629 SROUTB(0x11, 0x92); | |
630 /* Set overlay address to that of selected frame */ | |
631 CROUTB(0x92, ((frames[frame]+YOffs) >> 3) &0xff); /* Lower 8 bits of start address */ | |
632 CROUTB(0x93, ((frames[frame]+YOffs) >> 11) &0xff); /* Mid 8 bits of start address */ | |
633 CROUTB(0x94, ((frames[frame]+YOffs) >> 19) &0xf); /* Upper 4 bits of start address */ | |
634 SROUTB(0x80, ((frames[frame]+VOffs) >> 3) &0xff); /* Lower 8 bits of start address */ | |
635 SROUTB(0x81, ((frames[frame]+VOffs) >> 11) &0xff); /* Mid 8 bits of start address */ | |
636 SROUTB(0x82, ((frames[frame]+VOffs) >> 19) &0xf); /* Upper 4 bits of start address */ | |
637 SROUTB(0x83, ((frames[frame]+UOffs) >> 3) &0xff); /* Lower 8 bits of start address */ | |
638 SROUTB(0x84, ((frames[frame]+UOffs) >> 11) &0xff); /* Mid 8 bits of start address */ | |
639 SROUTB(0x85, ((frames[frame]+UOffs) >> 19) &0xf); /* Upper 4 bits of start address */ | |
640 SROUTB(0x11, protect); | |
641 return 0; | |
642 } | |
643 | |
644 |