annotate vidix/drivers/mach64_vid.c @ 22086:8bf15e2ca61e

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