Mercurial > mplayer.hg
annotate vidix/drivers/mach64_vid.c @ 5563:71372b7125cf
Sorry, fix vobsub duration the arpi way.
Also added origin parsing, those values are to adjust subtitle placement, they should be added to start_row and end_row and start_col and end_col, but haven't yet found the proper place to hook them in.
author | atmos4 |
---|---|
date | Thu, 11 Apr 2002 16:50:52 +0000 |
parents | 51fcb1e5c96e |
children | bdfd4b72244a |
rev | line source |
---|---|
4691 | 1 /* |
2 mach64_vid - VIDIX based video driver for Mach64 and 3DRage chips | |
3 Copyrights 2002 Nick Kurshev. This file is based on sources from | |
4 GATOS (gatos.sf.net) and X11 (www.xfree86.org) | |
5 Licence: GPL | |
4866 | 6 WARNING: THIS DRIVER IS IN BETTA STAGE |
4691 | 7 */ |
8 #include <errno.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <math.h> | |
13 #include <inttypes.h> | |
14 #include <fcntl.h> | |
15 | |
16 #include "../vidix.h" | |
17 #include "../fourcc.h" | |
18 #include "../../libdha/libdha.h" | |
19 #include "../../libdha/pci_ids.h" | |
20 #include "../../libdha/pci_names.h" | |
21 | |
22 #include "mach64.h" | |
23 | |
24 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */ | |
25 | |
26 static void *mach64_mmio_base = 0; | |
27 static void *mach64_mem_base = 0; | |
4721 | 28 static int32_t mach64_overlay_offset = 0; |
4691 | 29 static uint32_t mach64_ram_size = 0; |
4866 | 30 static uint32_t mach64_buffer_base[10][3]; |
31 static int num_mach64_buffers=-1; | |
4876 | 32 static int supports_planar=0; |
4691 | 33 |
34 pciinfo_t pci_info; | |
35 static int probed = 0; | |
36 static int __verbose = 0; | |
4721 | 37 |
4758 | 38 #define VERBOSE_LEVEL 1 |
39 | |
4721 | 40 typedef struct bes_registers_s |
41 { | |
42 /* base address of yuv framebuffer */ | |
43 uint32_t yuv_base; | |
44 uint32_t fourcc; | |
45 /* YUV BES registers */ | |
46 uint32_t reg_load_cntl; | |
47 uint32_t scale_inc; | |
48 uint32_t y_x_start; | |
49 uint32_t y_x_end; | |
50 uint32_t vid_buf_pitch; | |
51 uint32_t height_width; | |
52 | |
53 uint32_t scale_cntl; | |
54 uint32_t exclusive_horz; | |
55 uint32_t auto_flip_cntl; | |
56 uint32_t filter_cntl; | |
57 uint32_t key_cntl; | |
58 uint32_t test; | |
59 /* Configurable stuff */ | |
60 | |
61 int brightness; | |
62 int saturation; | |
63 | |
64 int ckey_on; | |
65 uint32_t graphics_key_clr; | |
66 uint32_t graphics_key_msk; | |
67 | |
68 int deinterlace_on; | |
69 uint32_t deinterlace_pattern; | |
70 | |
71 } bes_registers_t; | |
72 | |
73 static bes_registers_t besr; | |
74 | |
75 typedef struct video_registers_s | |
76 { | |
77 const char * sname; | |
78 uint32_t name; | |
79 uint32_t value; | |
80 }video_registers_t; | |
81 | |
82 static bes_registers_t besr; | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
83 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
84 /* Graphic keys */ |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
85 static vidix_grkey_t mach64_grkey; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
86 |
4721 | 87 #define DECLARE_VREG(name) { #name, name, 0 } |
88 static video_registers_t vregs[] = | |
89 { | |
90 DECLARE_VREG(OVERLAY_SCALE_INC), | |
91 DECLARE_VREG(OVERLAY_Y_X_START), | |
92 DECLARE_VREG(OVERLAY_Y_X_END), | |
93 DECLARE_VREG(OVERLAY_SCALE_CNTL), | |
94 DECLARE_VREG(OVERLAY_EXCLUSIVE_HORZ), | |
95 DECLARE_VREG(OVERLAY_EXCLUSIVE_VERT), | |
96 DECLARE_VREG(OVERLAY_TEST), | |
97 DECLARE_VREG(SCALER_BUF_PITCH), | |
98 DECLARE_VREG(SCALER_HEIGHT_WIDTH), | |
99 DECLARE_VREG(SCALER_BUF0_OFFSET), | |
100 DECLARE_VREG(SCALER_BUF0_OFFSET_U), | |
101 DECLARE_VREG(SCALER_BUF0_OFFSET_V), | |
102 DECLARE_VREG(SCALER_BUF1_OFFSET), | |
103 DECLARE_VREG(SCALER_BUF1_OFFSET_U), | |
104 DECLARE_VREG(SCALER_BUF1_OFFSET_V), | |
105 DECLARE_VREG(SCALER_H_COEFF0), | |
106 DECLARE_VREG(SCALER_H_COEFF1), | |
107 DECLARE_VREG(SCALER_H_COEFF2), | |
108 DECLARE_VREG(SCALER_H_COEFF3), | |
109 DECLARE_VREG(SCALER_H_COEFF4), | |
110 DECLARE_VREG(SCALER_COLOUR_CNTL), | |
111 DECLARE_VREG(SCALER_THRESHOLD), | |
112 DECLARE_VREG(VIDEO_FORMAT), | |
113 DECLARE_VREG(VIDEO_CONFIG), | |
114 DECLARE_VREG(VIDEO_SYNC_TEST), | |
115 DECLARE_VREG(VIDEO_SYNC_TEST_B) | |
116 }; | |
117 | |
4691 | 118 /* VIDIX exports */ |
119 | |
120 /* MMIO space*/ | |
121 #define GETREG(TYPE,PTR,OFFZ) (*((volatile TYPE*)((PTR)+(OFFZ)))) | |
122 #define SETREG(TYPE,PTR,OFFZ,VAL) (*((volatile TYPE*)((PTR)+(OFFZ))))=VAL | |
123 | |
4721 | 124 #define INREG8(addr) GETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2) |
125 #define OUTREG8(addr,val) SETREG(uint8_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val) | |
126 #define INREG(addr) GETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2) | |
127 #define OUTREG(addr,val) SETREG(uint32_t,(uint32_t)mach64_mmio_base,((addr)^0x100)<<2,val) | |
4691 | 128 |
129 #define OUTREGP(addr,val,mask) \ | |
130 do { \ | |
131 unsigned int _tmp = INREG(addr); \ | |
132 _tmp &= (mask); \ | |
133 _tmp |= (val); \ | |
134 OUTREG(addr, _tmp); \ | |
135 } while (0) | |
136 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
137 static __inline__ int ATIGetMach64LCDReg(int _Index) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
138 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
139 OUTREG8(LCD_INDEX, _Index); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
140 return INREG(LCD_DATA); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
141 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
142 |
4691 | 143 static __inline__ uint32_t INPLL(uint32_t addr) |
144 { | |
4721 | 145 uint32_t res; |
146 | |
147 /* write addr byte */ | |
148 OUTREG8(CLOCK_CNTL + 1, (addr << 2)); | |
149 /* read the register value */ | |
150 res = INREG(CLOCK_CNTL + 2); | |
151 return res; | |
4691 | 152 } |
153 | |
4721 | 154 static __inline__ void OUTPLL(uint32_t addr,uint32_t val) |
155 { | |
156 /* write addr byte */ | |
157 OUTREG8(CLOCK_CNTL + 1, (addr << 2) | PLL_WR_EN); | |
158 /* write the register value */ | |
159 OUTREG(CLOCK_CNTL + 2, val); | |
160 OUTREG8(CLOCK_CNTL + 1, (addr << 2) & ~PLL_WR_EN); | |
161 } | |
162 | |
4691 | 163 #define OUTPLLP(addr,val,mask) \ |
164 do { \ | |
165 unsigned int _tmp = INPLL(addr); \ | |
166 _tmp &= (mask); \ | |
167 _tmp |= (val); \ | |
168 OUTPLL(addr, _tmp); \ | |
169 } while (0) | |
170 | |
4721 | 171 static void mach64_fifo_wait(unsigned n) |
172 { | |
173 while ((INREG(FIFO_STAT) & 0xffff) > ((uint32_t)(0x8000 >> n))); | |
174 } | |
175 | |
176 static void mach64_wait_for_idle( void ) | |
177 { | |
178 mach64_fifo_wait(16); | |
179 while ((INREG(GUI_STAT) & 1)!= 0); | |
180 } | |
181 | |
4876 | 182 static void mach64_wait_vsync( void ) |
183 { | |
184 int i; | |
185 | |
186 for(i=0; i<2000000; i++) | |
187 if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK)==0 ) break; | |
188 for(i=0; i<2000000; i++) | |
189 if( (INREG(CRTC_INT_CNTL)&CRTC_VBLANK) ) break; | |
190 | |
191 } | |
192 | |
4691 | 193 static vidix_capability_t mach64_cap = |
194 { | |
195 "BES driver for Mach64/3DRage cards", | |
4872 | 196 "Nick Kurshev and Michael Niedermayer", |
4691 | 197 TYPE_OUTPUT, |
198 { 0, 0, 0, 0 }, | |
199 2048, | |
200 2048, | |
201 4, | |
202 4, | |
203 -1, | |
204 FLAG_UPSCALER|FLAG_DOWNSCALER, | |
205 VENDOR_ATI, | |
206 -1, | |
207 { 0, 0, 0, 0 } | |
208 }; | |
209 | |
4721 | 210 static uint32_t mach64_vid_get_dbpp( void ) |
211 { | |
212 uint32_t dbpp,retval; | |
213 dbpp = (INREG(CRTC_GEN_CNTL)>>8)& 0x7; | |
214 switch(dbpp) | |
215 { | |
216 case 1: retval = 4; break; | |
217 case 2: retval = 8; break; | |
218 case 3: retval = 15; break; | |
219 case 4: retval = 16; break; | |
220 case 5: retval = 24; break; | |
221 default: retval=32; break; | |
222 } | |
223 return retval; | |
224 } | |
225 | |
226 static int mach64_is_dbl_scan( void ) | |
227 { | |
228 return INREG(CRTC_GEN_CNTL) & CRTC_DBL_SCAN_EN; | |
229 } | |
230 | |
231 static int mach64_is_interlace( void ) | |
232 { | |
233 return INREG(CRTC_GEN_CNTL) & CRTC_INTERLACE_EN; | |
234 } | |
235 | |
236 static uint32_t mach64_get_xres( void ) | |
237 { | |
238 /* FIXME: currently we extract that from CRTC!!!*/ | |
239 uint32_t xres,h_total; | |
240 h_total = INREG(CRTC_H_TOTAL_DISP); | |
241 xres = (h_total >> 16) & 0xffff; | |
242 return (xres + 1)*8; | |
243 } | |
244 | |
245 static uint32_t mach64_get_yres( void ) | |
246 { | |
247 /* FIXME: currently we extract that from CRTC!!!*/ | |
248 uint32_t yres,v_total; | |
249 v_total = INREG(CRTC_V_TOTAL_DISP); | |
250 yres = (v_total >> 16) & 0xffff; | |
251 return yres + 1; | |
252 } | |
253 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
254 // returns the verical stretch factor in 16.16 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
255 static int mach64_get_vert_stretch(void) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
256 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
257 int lcd_index; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
258 int lcd_gen_ctrl; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
259 int vert_stretching; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
260 int ext_vert_stretch; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
261 int ret; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
262 int yres= mach64_get_yres(); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
263 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
264 //FIXME check for mobility & co |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
265 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
266 lcd_index= INREG(LCD_INDEX); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
267 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
268 vert_stretching= ATIGetMach64LCDReg(LCD_VERT_STRETCHING); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
269 if(!(vert_stretching&VERT_STRETCH_EN)) ret= 1<<16; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
270 else |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
271 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
272 int panel_size; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
273 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
274 ext_vert_stretch= ATIGetMach64LCDReg(LCD_EXT_VERT_STRETCH); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
275 panel_size= (ext_vert_stretch&VERT_PANEL_SIZE)>>11; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
276 panel_size++; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
277 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
278 ret= ((yres<<16) + (panel_size>>1))/panel_size; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
279 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
280 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
281 // lcd_gen_ctrl = ATIGetMach64LCDReg(LCD_GEN_CNTL); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
282 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
283 OUTREG(LCD_INDEX, lcd_index); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
284 |
4872 | 285 if(__verbose>VERBOSE_LEVEL) printf("[mach64] vertical stretching factor= %d\n", ret); |
286 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
287 return ret; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
288 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
289 |
4721 | 290 static void mach64_vid_make_default() |
291 { | |
4872 | 292 mach64_fifo_wait(5); |
4761 | 293 OUTREG(SCALER_COLOUR_CNTL,0x00101000); |
4872 | 294 |
295 besr.ckey_on=0; | |
296 besr.graphics_key_msk=0; | |
297 besr.graphics_key_clr=0; | |
298 | |
299 OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk); | |
300 OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr); | |
301 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND); | |
302 | |
4721 | 303 } |
304 | |
305 static void mach64_vid_dump_regs( void ) | |
306 { | |
307 size_t i; | |
308 printf("[mach64] *** Begin of DRIVER variables dump ***\n"); | |
309 printf("[mach64] mach64_mmio_base=%p\n",mach64_mmio_base); | |
310 printf("[mach64] mach64_mem_base=%p\n",mach64_mem_base); | |
311 printf("[mach64] mach64_overlay_off=%08X\n",mach64_overlay_offset); | |
312 printf("[mach64] mach64_ram_size=%08X\n",mach64_ram_size); | |
313 printf("[mach64] video mode: %ux%u@%u\n",mach64_get_xres(),mach64_get_yres(),mach64_vid_get_dbpp()); | |
314 printf("[mach64] *** Begin of OV0 registers dump ***\n"); | |
315 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++) | |
316 { | |
317 mach64_wait_for_idle(); | |
318 printf("[mach64] %s = %08X\n",vregs[i].sname,INREG(vregs[i].name)); | |
319 } | |
320 printf("[mach64] *** End of OV0 registers dump ***\n"); | |
321 } | |
322 | |
323 | |
4691 | 324 unsigned int vixGetVersion(void) |
325 { | |
326 return(VIDIX_VERSION); | |
327 } | |
328 | |
329 static unsigned short ati_card_ids[] = | |
330 { | |
331 DEVICE_ATI_215CT_MACH64_CT, | |
332 DEVICE_ATI_210888CX_MACH64_CX, | |
333 DEVICE_ATI_210888ET_MACH64_ET, | |
334 DEVICE_ATI_MACH64_VT, | |
335 DEVICE_ATI_210888GX_MACH64_GX, | |
336 DEVICE_ATI_264LT_MACH64_LT, | |
337 DEVICE_ATI_264VT_MACH64_VT, | |
338 DEVICE_ATI_264VT3_MACH64_VT3, | |
339 DEVICE_ATI_264VT4_MACH64_VT4, | |
340 /**/ | |
341 DEVICE_ATI_3D_RAGE_PRO, | |
342 DEVICE_ATI_3D_RAGE_PRO2, | |
343 DEVICE_ATI_3D_RAGE_PRO3, | |
344 DEVICE_ATI_3D_RAGE_PRO4, | |
345 DEVICE_ATI_RAGE_XC, | |
346 DEVICE_ATI_RAGE_XL_AGP, | |
347 DEVICE_ATI_RAGE_XC_AGP, | |
348 DEVICE_ATI_RAGE_XL, | |
349 DEVICE_ATI_3D_RAGE_PRO5, | |
350 DEVICE_ATI_3D_RAGE_PRO6, | |
351 DEVICE_ATI_RAGE_XL2, | |
352 DEVICE_ATI_RAGE_XC2, | |
353 DEVICE_ATI_3D_RAGE_I_II, | |
354 DEVICE_ATI_3D_RAGE_II, | |
355 DEVICE_ATI_3D_RAGE_IIC, | |
356 DEVICE_ATI_3D_RAGE_IIC2, | |
357 DEVICE_ATI_3D_RAGE_IIC3, | |
358 DEVICE_ATI_3D_RAGE_IIC4, | |
359 DEVICE_ATI_3D_RAGE_LT, | |
360 DEVICE_ATI_3D_RAGE_LT2, | |
361 DEVICE_ATI_3D_RAGE_LT_G, | |
362 DEVICE_ATI_3D_RAGE_LT3, | |
363 DEVICE_ATI_RAGE_MOBILITY_P_M, | |
364 DEVICE_ATI_RAGE_MOBILITY_L, | |
365 DEVICE_ATI_3D_RAGE_LT4, | |
366 DEVICE_ATI_3D_RAGE_LT5, | |
367 DEVICE_ATI_RAGE_MOBILITY_P_M2, | |
368 DEVICE_ATI_RAGE_MOBILITY_L2 | |
369 }; | |
370 | |
371 static int find_chip(unsigned chip_id) | |
372 { | |
373 unsigned i; | |
374 for(i = 0;i < sizeof(ati_card_ids)/sizeof(unsigned short);i++) | |
375 { | |
376 if(chip_id == ati_card_ids[i]) return i; | |
377 } | |
378 return -1; | |
379 } | |
380 | |
381 int vixProbe(int verbose,int force) | |
382 { | |
383 pciinfo_t lst[MAX_PCI_DEVICES]; | |
384 unsigned i,num_pci; | |
385 int err; | |
386 __verbose = verbose; | |
387 err = pci_scan(lst,&num_pci); | |
388 if(err) | |
389 { | |
390 printf("[mach64] Error occured during pci scan: %s\n",strerror(err)); | |
391 return err; | |
392 } | |
393 else | |
394 { | |
395 err = ENXIO; | |
396 for(i=0;i<num_pci;i++) | |
397 { | |
398 if(lst[i].vendor == VENDOR_ATI) | |
399 { | |
400 int idx; | |
401 const char *dname; | |
402 idx = find_chip(lst[i].device); | |
403 if(idx == -1 && force == PROBE_NORMAL) continue; | |
404 dname = pci_device_name(VENDOR_ATI,lst[i].device); | |
405 dname = dname ? dname : "Unknown chip"; | |
406 printf("[mach64] Found chip: %s\n",dname); | |
407 if(force > PROBE_NORMAL) | |
408 { | |
409 printf("[mach64] Driver was forced. Was found %sknown chip\n",idx == -1 ? "un" : ""); | |
410 if(idx == -1) | |
411 printf("[mach64] Assuming it as Mach64\n"); | |
412 } | |
413 mach64_cap.device_id = lst[i].device; | |
414 err = 0; | |
415 memcpy(&pci_info,&lst[i],sizeof(pciinfo_t)); | |
416 probed=1; | |
417 break; | |
418 } | |
419 } | |
420 } | |
421 if(err && verbose) printf("[mach64] Can't find chip\n"); | |
422 return err; | |
423 } | |
424 | |
4721 | 425 static void reset_regs( void ) |
426 { | |
427 size_t i; | |
428 for(i=0;i<sizeof(vregs)/sizeof(video_registers_t);i++) | |
429 { | |
430 mach64_fifo_wait(2); | |
4758 | 431 OUTREG(vregs[i].name,0); |
4721 | 432 } |
433 } | |
434 | |
435 | |
4691 | 436 int vixInit(void) |
437 { | |
438 int err; | |
439 if(!probed) | |
440 { | |
441 printf("[mach64] Driver was not probed but is being initializing\n"); | |
442 return EINTR; | |
443 } | |
4721 | 444 if((mach64_mmio_base = map_phys_mem(pci_info.base2,0x4000))==(void *)-1) return ENOMEM; |
445 mach64_wait_for_idle(); | |
4691 | 446 mach64_ram_size = INREG(MEM_CNTL) & CTL_MEM_SIZEB; |
447 if (mach64_ram_size < 8) mach64_ram_size = (mach64_ram_size + 1) * 512; | |
448 else if (mach64_ram_size < 12) mach64_ram_size = (mach64_ram_size - 3) * 1024; | |
449 else mach64_ram_size = (mach64_ram_size - 7) * 2048; | |
450 mach64_ram_size *= 0x400; /* KB -> bytes */ | |
451 if((mach64_mem_base = map_phys_mem(pci_info.base0,mach64_ram_size))==(void *)-1) return ENOMEM; | |
4758 | 452 memset(&besr,0,sizeof(bes_registers_t)); |
4691 | 453 printf("[mach64] Video memory = %uMb\n",mach64_ram_size/0x100000); |
454 err = mtrr_set_type(pci_info.base0,mach64_ram_size,MTRR_TYPE_WRCOMB); | |
455 if(!err) printf("[mach64] Set write-combining type of video memory\n"); | |
4876 | 456 |
457 /* check if planar formats are supported */ | |
458 supports_planar=0; | |
459 mach64_wait_for_idle(); | |
460 mach64_fifo_wait(2); | |
461 if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1; | |
462 else | |
463 { | |
464 OUTREG(SCALER_BUF0_OFFSET_U, -1); | |
465 | |
466 mach64_wait_vsync(); | |
467 mach64_wait_for_idle(); | |
468 mach64_fifo_wait(2); | |
469 | |
470 if(INREG(SCALER_BUF0_OFFSET_U)) supports_planar=1; | |
471 } | |
472 if(supports_planar) printf("[mach64] Planar YUV formats are supported :)\n"); | |
473 else printf("[mach64] Planar YUV formats are not supported :(\n"); | |
474 | |
4721 | 475 reset_regs(); |
4761 | 476 mach64_vid_make_default(); |
4876 | 477 |
4758 | 478 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4691 | 479 return 0; |
480 } | |
481 | |
482 void vixDestroy(void) | |
483 { | |
484 unmap_phys_mem(mach64_mem_base,mach64_ram_size); | |
4721 | 485 unmap_phys_mem(mach64_mmio_base,0x4000); |
4691 | 486 } |
487 | |
488 int vixGetCapability(vidix_capability_t *to) | |
489 { | |
490 memcpy(to, &mach64_cap, sizeof(vidix_capability_t)); | |
491 return 0; | |
492 } | |
493 | |
4721 | 494 static unsigned mach64_query_pitch(unsigned fourcc,const vidix_yuv_t *spitch) |
495 { | |
496 unsigned pitch,spy,spv,spu; | |
497 spy = spv = spu = 0; | |
498 switch(spitch->y) | |
499 { | |
500 case 16: | |
501 case 32: | |
502 case 64: | |
503 case 128: | |
504 case 256: spy = spitch->y; break; | |
505 default: break; | |
506 } | |
507 switch(spitch->u) | |
508 { | |
509 case 16: | |
510 case 32: | |
511 case 64: | |
512 case 128: | |
513 case 256: spu = spitch->u; break; | |
514 default: break; | |
515 } | |
516 switch(spitch->v) | |
517 { | |
518 case 16: | |
519 case 32: | |
520 case 64: | |
521 case 128: | |
522 case 256: spv = spitch->v; break; | |
523 default: break; | |
524 } | |
525 switch(fourcc) | |
526 { | |
527 /* 4:2:0 */ | |
528 case IMGFMT_IYUV: | |
529 case IMGFMT_YV12: | |
530 case IMGFMT_I420: | |
531 if(spy > 16 && spu == spy/2 && spv == spy/2) pitch = spy; | |
532 else pitch = 32; | |
533 break; | |
4872 | 534 case IMGFMT_YVU9: |
535 if(spy > 32 && spu == spy/4 && spv == spy/4) pitch = spy; | |
536 else pitch = 64; | |
537 break; | |
4721 | 538 default: |
4722
39f3bfae472c
Direct rendering with dshow codecs support. (Was untested but should work)
nick
parents:
4721
diff
changeset
|
539 if(spy >= 16) pitch = spy; |
39f3bfae472c
Direct rendering with dshow codecs support. (Was untested but should work)
nick
parents:
4721
diff
changeset
|
540 else pitch = 16; |
4721 | 541 break; |
542 } | |
543 return pitch; | |
544 } | |
545 | |
546 static void mach64_compute_framesize(vidix_playback_t *info) | |
547 { | |
548 unsigned pitch,awidth; | |
549 pitch = mach64_query_pitch(info->fourcc,&info->src.pitch); | |
550 switch(info->fourcc) | |
551 { | |
552 case IMGFMT_I420: | |
553 case IMGFMT_YV12: | |
554 case IMGFMT_IYUV: | |
555 awidth = (info->src.w + (pitch-1)) & ~(pitch-1); | |
556 info->frame_size = awidth*(info->src.h+info->src.h/2); | |
557 break; | |
4872 | 558 case IMGFMT_YVU9: |
559 awidth = (info->src.w + (pitch-1)) & ~(pitch-1); | |
560 info->frame_size = awidth*(info->src.h+info->src.h/8); | |
561 break; | |
562 // case IMGFMT_RGB32: | |
4721 | 563 case IMGFMT_BGR32: |
564 awidth = (info->src.w*4 + (pitch-1)) & ~(pitch-1); | |
565 info->frame_size = (awidth*info->src.h); | |
566 break; | |
567 /* YUY2 YVYU, RGB15, RGB16 */ | |
568 default: | |
569 awidth = (info->src.w*2 + (pitch-1)) & ~(pitch-1); | |
570 info->frame_size = (awidth*info->src.h); | |
571 break; | |
572 } | |
4872 | 573 info->frame_size+=256; // so we have some space for alignment & such |
574 info->frame_size&=~16; | |
4721 | 575 } |
576 | |
577 static void mach64_vid_stop_video( void ) | |
578 { | |
579 mach64_fifo_wait(14); | |
580 OUTREG(OVERLAY_SCALE_CNTL, 0x80000000); | |
581 OUTREG(OVERLAY_EXCLUSIVE_HORZ, 0); | |
582 OUTREG(OVERLAY_EXCLUSIVE_VERT, 0); | |
583 OUTREG(SCALER_H_COEFF0, 0x00002000); | |
584 OUTREG(SCALER_H_COEFF1, 0x0D06200D); | |
585 OUTREG(SCALER_H_COEFF2, 0x0D0A1C0D); | |
586 OUTREG(SCALER_H_COEFF3, 0x0C0E1A0C); | |
587 OUTREG(SCALER_H_COEFF4, 0x0C14140C); | |
588 OUTREG(VIDEO_FORMAT, 0xB000B); | |
589 OUTREG(OVERLAY_TEST, 0x0); | |
590 } | |
591 | |
592 static void mach64_vid_display_video( void ) | |
593 { | |
594 uint32_t vf; | |
595 mach64_fifo_wait(14); | |
596 | |
597 OUTREG(OVERLAY_Y_X_START, besr.y_x_start); | |
598 OUTREG(OVERLAY_Y_X_END, besr.y_x_end); | |
599 OUTREG(OVERLAY_SCALE_INC, besr.scale_inc); | |
600 OUTREG(SCALER_BUF_PITCH, besr.vid_buf_pitch); | |
601 OUTREG(SCALER_HEIGHT_WIDTH, besr.height_width); | |
4866 | 602 OUTREG(SCALER_BUF0_OFFSET, mach64_buffer_base[0][0]); |
603 OUTREG(SCALER_BUF0_OFFSET_U, mach64_buffer_base[0][1]); | |
604 OUTREG(SCALER_BUF0_OFFSET_V, mach64_buffer_base[0][2]); | |
605 OUTREG(SCALER_BUF1_OFFSET, mach64_buffer_base[0][0]); | |
606 OUTREG(SCALER_BUF1_OFFSET_U, mach64_buffer_base[0][1]); | |
607 OUTREG(SCALER_BUF1_OFFSET_V, mach64_buffer_base[0][2]); | |
4876 | 608 mach64_wait_vsync(); |
609 | |
610 mach64_fifo_wait(4); | |
4758 | 611 OUTREG(OVERLAY_SCALE_CNTL, 0xC4000003); |
4760 | 612 // OVERLAY_SCALE_CNTL bits & what they seem to affect |
613 // bit 0 no effect | |
614 // bit 1 yuv2rgb coeff related | |
615 // bit 2 horizontal interpolation if 0 | |
616 // bit 3 vertical interpolation if 0 | |
4847 | 617 // bit 4 chroma encoding (0-> 128=neutral / 1-> 0->neutral) |
4760 | 618 // bit 5-6 gamma correction |
619 // bit 7 nothing visible if set | |
620 // bit 8-27 no effect | |
621 // bit 28-31 nothing interresting just crashed my system when i played with them :( | |
4847 | 622 |
4721 | 623 mach64_wait_for_idle(); |
624 vf = INREG(VIDEO_FORMAT); | |
4751 | 625 |
626 // Bits 16-19 seem to select the format | |
4769 | 627 // 0x0 dunno behaves strange |
628 // 0x1 dunno behaves strange | |
629 // 0x2 dunno behaves strange | |
630 // 0x3 BGR15 | |
631 // 0x4 BGR16 | |
632 // 0x5 BGR16 (hmm, that need investigation, 2 BGR16 formats, i guess 1 will have only 5bits for green) | |
633 // 0x6 BGR32 | |
634 // 0x7 BGR32 with somehow mixed even / odd pixels ? | |
635 // 0x8 YYYYUVUV | |
636 // 0x9 YVU9 | |
637 // 0xA YV12 | |
638 // 0xB YUY2 | |
639 // 0xC UYVY | |
4847 | 640 // 0xD UYVY (no difference is visible if i switch between C/D for every even/odd frame) |
4769 | 641 // 0xE dunno behaves strange |
642 // 0xF dunno behaves strange | |
643 // Bit 28 all values are assumed to be 7 bit with chroma=64 for black (tested with YV12 & YUY2) | |
4751 | 644 // the remaining bits seem to have no effect |
645 | |
4769 | 646 |
4721 | 647 switch(besr.fourcc) |
648 { | |
4769 | 649 /* BGR formats */ |
650 case IMGFMT_BGR15: OUTREG(VIDEO_FORMAT, 0x00030000); break; | |
651 case IMGFMT_BGR16: OUTREG(VIDEO_FORMAT, 0x00040000); break; | |
652 case IMGFMT_BGR32: OUTREG(VIDEO_FORMAT, 0x00060000); break; | |
4721 | 653 /* 4:2:0 */ |
654 case IMGFMT_IYUV: | |
655 case IMGFMT_I420: | |
4769 | 656 case IMGFMT_YV12: OUTREG(VIDEO_FORMAT, 0x000A0000); break; |
4872 | 657 |
658 case IMGFMT_YVU9: OUTREG(VIDEO_FORMAT, 0x00090000); break; | |
4721 | 659 /* 4:2:2 */ |
660 case IMGFMT_YVYU: | |
4769 | 661 case IMGFMT_UYVY: OUTREG(VIDEO_FORMAT, 0x000C0000); break; |
4721 | 662 case IMGFMT_YUY2: |
4769 | 663 default: OUTREG(VIDEO_FORMAT, 0x000B0000); break; |
4721 | 664 } |
4758 | 665 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4721 | 666 } |
667 | |
668 static int mach64_vid_init_video( vidix_playback_t *config ) | |
669 { | |
4758 | 670 uint32_t src_w,src_h,dest_w,dest_h,pitch,h_inc,v_inc,left,leftUV,top,ecp,y_pos; |
4721 | 671 int is_420,best_pitch,mpitch; |
4866 | 672 int src_offset_y, src_offset_u, src_offset_v; |
673 unsigned int i; | |
4872 | 674 |
4721 | 675 mach64_vid_stop_video(); |
4866 | 676 /* warning, if left or top are != 0 this will fail, as the framesize is too small then */ |
677 left = config->src.x; | |
678 top = config->src.y; | |
4721 | 679 src_h = config->src.h; |
680 src_w = config->src.w; | |
681 is_420 = 0; | |
682 if(config->fourcc == IMGFMT_YV12 || | |
683 config->fourcc == IMGFMT_I420 || | |
684 config->fourcc == IMGFMT_IYUV) is_420 = 1; | |
685 best_pitch = mach64_query_pitch(config->fourcc,&config->src.pitch); | |
686 mpitch = best_pitch-1; | |
687 switch(config->fourcc) | |
688 { | |
4872 | 689 case IMGFMT_YVU9: |
4721 | 690 /* 4:2:0 */ |
691 case IMGFMT_IYUV: | |
692 case IMGFMT_YV12: | |
693 case IMGFMT_I420: pitch = (src_w + mpitch) & ~mpitch; | |
694 config->dest.pitch.y = | |
695 config->dest.pitch.u = | |
696 config->dest.pitch.v = best_pitch; | |
4769 | 697 besr.vid_buf_pitch= pitch; |
4721 | 698 break; |
699 /* RGB 4:4:4:4 */ | |
700 case IMGFMT_RGB32: | |
701 case IMGFMT_BGR32: pitch = (src_w*4 + mpitch) & ~mpitch; | |
702 config->dest.pitch.y = | |
703 config->dest.pitch.u = | |
704 config->dest.pitch.v = best_pitch; | |
4769 | 705 besr.vid_buf_pitch= pitch>>2; |
4721 | 706 break; |
707 /* 4:2:2 */ | |
708 default: /* RGB15, RGB16, YVYU, UYVY, YUY2 */ | |
709 pitch = ((src_w*2) + mpitch) & ~mpitch; | |
710 config->dest.pitch.y = | |
711 config->dest.pitch.u = | |
712 config->dest.pitch.v = best_pitch; | |
4769 | 713 besr.vid_buf_pitch= pitch>>1; |
4721 | 714 break; |
715 } | |
716 dest_w = config->dest.w; | |
717 dest_h = config->dest.h; | |
718 besr.fourcc = config->fourcc; | |
719 ecp = (INPLL(PLL_VCLK_CNTL) & PLL_ECP_DIV) >> 4; | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
720 v_inc = src_h * mach64_get_vert_stretch(); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
721 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
722 if(mach64_is_interlace()) v_inc<<=1; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
723 if(mach64_is_dbl_scan() ) v_inc>>=1; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
724 v_inc>>=4; // convert 16.16 -> 20.12 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
725 v_inc/= dest_h; |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
726 |
4721 | 727 h_inc = (src_w << (12+ecp)) / dest_w; |
728 /* keep everything in 16.16 */ | |
729 config->offsets[0] = 0; | |
4866 | 730 for(i=1; i<config->num_frames; i++) |
731 config->offsets[i] = config->offsets[i-1] + config->frame_size; | |
732 | |
4872 | 733 /*FIXME the left / top stuff is broken (= zoom a src rectangle from a larger one) |
734 1. the framesize isnt known as the outer src rectangle dimensions arent known | |
735 2. the mach64 needs aligned addresses so it cant work anyway | |
736 -> so we could shift the outer buffer to compensate that but that would mean | |
737 alignment problems for the code which writes into it | |
738 */ | |
739 | |
4721 | 740 if(is_420) |
741 { | |
4866 | 742 config->offset.y= 0; |
4872 | 743 config->offset.u= (pitch*src_h + 15)&~15; |
744 config->offset.v= (config->offset.u + (pitch*src_h>>2) + 15)&~15; | |
745 | |
4866 | 746 src_offset_y= config->offset.y + top*pitch + left; |
747 src_offset_u= config->offset.u + (top*pitch>>2) + (left>>1); | |
748 src_offset_v= config->offset.v + (top*pitch>>2) + (left>>1); | |
4872 | 749 |
4721 | 750 if(besr.fourcc == IMGFMT_I420 || besr.fourcc == IMGFMT_IYUV) |
751 { | |
752 uint32_t tmp; | |
753 tmp = config->offset.u; | |
754 config->offset.u = config->offset.v; | |
755 config->offset.v = tmp; | |
756 } | |
757 } | |
4872 | 758 else if(besr.fourcc == IMGFMT_YVU9) |
759 { | |
760 config->offset.y= 0; | |
761 config->offset.u= (pitch*src_h + 15)&~15; | |
762 config->offset.v= (config->offset.u + (pitch*src_h>>4) + 15)&~15; | |
763 | |
764 src_offset_y= config->offset.y + top*pitch + left; | |
765 src_offset_u= config->offset.u + (top*pitch>>4) + (left>>1); | |
766 src_offset_v= config->offset.v + (top*pitch>>4) + (left>>1); | |
767 } | |
4866 | 768 else if(besr.fourcc == IMGFMT_BGR32) |
769 { | |
770 config->offset.y = config->offset.u = config->offset.v = 0; | |
4872 | 771 src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 2); |
4866 | 772 } |
4721 | 773 else |
774 { | |
4866 | 775 config->offset.y = config->offset.u = config->offset.v = 0; |
4872 | 776 src_offset_y= src_offset_u= src_offset_v= top*pitch + (left << 1); |
4866 | 777 } |
778 | |
779 num_mach64_buffers= config->num_frames; | |
780 for(i=0; i<config->num_frames; i++) | |
781 { | |
782 mach64_buffer_base[i][0]= (mach64_overlay_offset + config->offsets[i] + src_offset_y)&~15; | |
783 mach64_buffer_base[i][1]= (mach64_overlay_offset + config->offsets[i] + src_offset_u)&~15; | |
784 mach64_buffer_base[i][2]= (mach64_overlay_offset + config->offsets[i] + src_offset_v)&~15; | |
4721 | 785 } |
786 | |
787 leftUV = (left >> 17) & 15; | |
788 left = (left >> 16) & 15; | |
789 besr.scale_inc = ( h_inc << 16 ) | v_inc; | |
4758 | 790 y_pos = config->dest.y; |
791 if(mach64_is_dbl_scan()) y_pos*=2; | |
792 else | |
793 if(mach64_is_interlace()) y_pos/=2; | |
794 besr.y_x_start = y_pos | (config->dest.x << 16); | |
795 y_pos =config->dest.y + dest_h; | |
796 if(mach64_is_dbl_scan()) y_pos*=2; | |
797 else | |
798 if(mach64_is_interlace()) y_pos/=2; | |
799 besr.y_x_end = y_pos | ((config->dest.x + dest_w) << 16); | |
4721 | 800 besr.height_width = ((src_w - left)<<16) | (src_h - top); |
4769 | 801 |
4721 | 802 return 0; |
803 } | |
804 | |
4876 | 805 static int is_supported_fourcc(uint32_t fourcc) |
4721 | 806 { |
4876 | 807 switch(fourcc) |
808 { | |
809 case IMGFMT_YV12: | |
810 case IMGFMT_I420: | |
811 case IMGFMT_YVU9: | |
812 case IMGFMT_IYUV: | |
813 return supports_planar; | |
814 case IMGFMT_YUY2: | |
815 case IMGFMT_UYVY: | |
816 case IMGFMT_BGR15: | |
817 case IMGFMT_BGR16: | |
818 case IMGFMT_BGR32: | |
819 return 1; | |
820 default: | |
821 return 0; | |
822 } | |
4721 | 823 } |
824 | |
4691 | 825 int vixQueryFourcc(vidix_fourcc_t *to) |
826 { | |
4721 | 827 if(is_supported_fourcc(to->fourcc)) |
828 { | |
829 to->depth = VID_DEPTH_1BPP | VID_DEPTH_2BPP | | |
830 VID_DEPTH_4BPP | VID_DEPTH_8BPP | | |
831 VID_DEPTH_12BPP| VID_DEPTH_15BPP| | |
832 VID_DEPTH_16BPP| VID_DEPTH_24BPP| | |
833 VID_DEPTH_32BPP; | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
834 to->flags = VID_CAP_EXPAND | VID_CAP_SHRINK | VID_CAP_COLORKEY; |
4721 | 835 return 0; |
836 } | |
837 else to->depth = to->flags = 0; | |
4691 | 838 return ENOSYS; |
839 } | |
840 | |
841 int vixConfigPlayback(vidix_playback_t *info) | |
842 { | |
4721 | 843 if(!is_supported_fourcc(info->fourcc)) return ENOSYS; |
4866 | 844 |
4721 | 845 mach64_compute_framesize(info); |
4894
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
846 |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
847 if(info->num_frames>4) info->num_frames=4; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
848 for(;info->num_frames>0; info->num_frames--) |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
849 { |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
850 mach64_overlay_offset = mach64_ram_size - info->frame_size*info->num_frames; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
851 mach64_overlay_offset &= 0xffff0000; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
852 if(mach64_overlay_offset>0) break; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
853 } |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
854 if(info->num_frames <= 0) return EINVAL; |
abe1a2edb422
use 4 buffers, fallback to fewer buffers if the video ram isnt large enough
michael
parents:
4876
diff
changeset
|
855 |
4721 | 856 info->dga_addr = (char *)mach64_mem_base + mach64_overlay_offset; |
857 mach64_vid_init_video(info); | |
858 return 0; | |
4691 | 859 } |
860 | |
861 int vixPlaybackOn(void) | |
862 { | |
4721 | 863 mach64_vid_display_video(); |
864 return 0; | |
4691 | 865 } |
866 | |
867 int vixPlaybackOff(void) | |
868 { | |
4721 | 869 mach64_vid_stop_video(); |
870 return 0; | |
871 } | |
872 | |
4691 | 873 int vixPlaybackFrameSelect(unsigned int frame) |
874 { | |
4721 | 875 uint32_t off[6]; |
4866 | 876 int i; |
877 int last_frame= (frame-1+num_mach64_buffers) % num_mach64_buffers; | |
878 //printf("Selecting frame %d\n", frame); | |
4721 | 879 /* |
880 buf3-5 always should point onto second buffer for better | |
881 deinterlacing and TV-in | |
882 */ | |
4866 | 883 if(num_mach64_buffers==1) return 0; |
884 | |
885 for(i=0; i<3; i++) | |
4721 | 886 { |
4866 | 887 off[i] = mach64_buffer_base[frame][i]; |
888 off[i+3]= mach64_buffer_base[last_frame][i]; | |
889 } | |
4769 | 890 |
4847 | 891 #if 0 // delay routine so the individual frames can be ssen better |
892 { | |
893 volatile int i=0; | |
894 for(i=0; i<10000000; i++); | |
895 } | |
896 #endif | |
4721 | 897 |
898 mach64_wait_for_idle(); | |
899 mach64_fifo_wait(7); | |
4847 | 900 |
4721 | 901 OUTREG(SCALER_BUF0_OFFSET, off[0]); |
902 OUTREG(SCALER_BUF0_OFFSET_U, off[1]); | |
903 OUTREG(SCALER_BUF0_OFFSET_V, off[2]); | |
904 OUTREG(SCALER_BUF1_OFFSET, off[3]); | |
905 OUTREG(SCALER_BUF1_OFFSET_U, off[4]); | |
906 OUTREG(SCALER_BUF1_OFFSET_V, off[5]); | |
4866 | 907 if(num_mach64_buffers==2) mach64_wait_vsync(); //only wait for vsync if we do double buffering |
908 | |
4758 | 909 if(__verbose > VERBOSE_LEVEL) mach64_vid_dump_regs(); |
4721 | 910 return 0; |
4691 | 911 } |
4721 | 912 |
913 vidix_video_eq_t equal = | |
914 { | |
915 VEQ_CAP_BRIGHTNESS | VEQ_CAP_SATURATION | |
916 , | |
917 0, 0, 0, 0, 0, 0, 0, 0 }; | |
918 | |
919 int vixPlaybackGetEq( vidix_video_eq_t * eq) | |
920 { | |
921 memcpy(eq,&equal,sizeof(vidix_video_eq_t)); | |
922 return 0; | |
923 } | |
924 | |
925 int vixPlaybackSetEq( const vidix_video_eq_t * eq) | |
926 { | |
927 int br,sat; | |
928 if(eq->cap & VEQ_CAP_BRIGHTNESS) equal.brightness = eq->brightness; | |
929 if(eq->cap & VEQ_CAP_CONTRAST) equal.contrast = eq->contrast; | |
930 if(eq->cap & VEQ_CAP_SATURATION) equal.saturation = eq->saturation; | |
931 if(eq->cap & VEQ_CAP_HUE) equal.hue = eq->hue; | |
932 if(eq->cap & VEQ_CAP_RGB_INTENSITY) | |
933 { | |
934 equal.red_intensity = eq->red_intensity; | |
935 equal.green_intensity = eq->green_intensity; | |
936 equal.blue_intensity = eq->blue_intensity; | |
937 } | |
938 equal.flags = eq->flags; | |
939 br = equal.brightness * 64 / 1000; | |
940 if(br < -64) br = -64; if(br > 63) br = 63; | |
941 sat = (equal.saturation + 1000) * 16 / 1000; | |
942 if(sat < 0) sat = 0; if(sat > 31) sat = 31; | |
943 OUTREG(SCALER_COLOUR_CNTL, (br & 0x7f) | (sat << 8) | (sat << 16)); | |
944 return 0; | |
945 } | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
946 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
947 int vixGetGrKeys(vidix_grkey_t *grkey) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
948 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
949 memcpy(grkey, &mach64_grkey, sizeof(vidix_grkey_t)); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
950 return(0); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
951 } |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
952 |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
953 int vixSetGrKeys(const vidix_grkey_t *grkey) |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
954 { |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
955 memcpy(&mach64_grkey, grkey, sizeof(vidix_grkey_t)); |
4872 | 956 |
957 if(mach64_grkey.ckey.op == CKEY_TRUE) | |
958 { | |
959 besr.ckey_on=1; | |
960 | |
961 switch(mach64_vid_get_dbpp()) | |
962 { | |
963 case 15: | |
964 besr.graphics_key_msk=0x7FFF; | |
965 besr.graphics_key_clr= | |
966 ((mach64_grkey.ckey.blue &0xF8)>>3) | |
967 | ((mach64_grkey.ckey.green&0xF8)<<2) | |
968 | ((mach64_grkey.ckey.red &0xF8)<<7); | |
969 break; | |
970 case 16: | |
971 besr.graphics_key_msk=0xFFFF; | |
972 besr.graphics_key_clr= | |
973 ((mach64_grkey.ckey.blue &0xF8)>>3) | |
974 | ((mach64_grkey.ckey.green&0xFC)<<3) | |
975 | ((mach64_grkey.ckey.red &0xF8)<<8); | |
976 break; | |
977 case 24: | |
978 besr.graphics_key_msk=0xFFFFFF; | |
979 besr.graphics_key_clr= | |
980 ((mach64_grkey.ckey.blue &0xFF)) | |
981 | ((mach64_grkey.ckey.green&0xFF)<<8) | |
982 | ((mach64_grkey.ckey.red &0xFF)<<16); | |
983 break; | |
984 case 32: | |
985 besr.graphics_key_msk=0xFFFFFF; | |
986 besr.graphics_key_clr= | |
987 ((mach64_grkey.ckey.blue &0xFF)) | |
988 | ((mach64_grkey.ckey.green&0xFF)<<8) | |
989 | ((mach64_grkey.ckey.red &0xFF)<<16); | |
990 break; | |
991 default: | |
992 besr.ckey_on=0; | |
993 besr.graphics_key_msk=0; | |
994 besr.graphics_key_clr=0; | |
995 } | |
996 } | |
997 else | |
998 { | |
999 besr.ckey_on=0; | |
1000 besr.graphics_key_msk=0; | |
1001 besr.graphics_key_clr=0; | |
1002 } | |
1003 | |
1004 mach64_fifo_wait(4); | |
1005 OUTREG(OVERLAY_GRAPHICS_KEY_MSK, besr.graphics_key_msk); | |
1006 OUTREG(OVERLAY_GRAPHICS_KEY_CLR, besr.graphics_key_clr); | |
1007 // OUTREG(OVERLAY_VIDEO_KEY_MSK, 0); | |
1008 // OUTREG(OVERLAY_VIDEO_KEY_CLR, 0); | |
1009 if(besr.ckey_on) | |
1010 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_EQ|CMP_MIX_AND); | |
1011 else | |
1012 OUTREG(OVERLAY_KEY_CNTL,VIDEO_KEY_FN_TRUE|GRAPHIC_KEY_FN_TRUE|CMP_MIX_AND); | |
1013 | |
4861
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
1014 return(0); |
601e8a796c38
colorkey support fixed (thanks to nick for the mga_vid tip ... i should RTFS more)
michael
parents:
4853
diff
changeset
|
1015 } |