s3v_rop.h revision 1d54945d
1/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/s3virge/s3v_rop.h,v 1.2 1998/11/28 10:43:16 dawes Exp $ */
2
3/*
4Copyright (C) 1994-1998 The XFree86 Project, Inc.  All Rights Reserved.
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software and associated documentation files (the "Software"), to deal in
8the Software without restriction, including without limitation the rights to
9use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10of the Software, and to permit persons to whom the Software is furnished to do
11so, subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT-
18NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
19XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23Except as contained in this notice, the name of the XFree86 Project shall not
24be used in advertising or otherwise to promote the sale, use or other dealings
25in this Software without prior written authorization from the XFree86 Project.
26*/
27
28/* This file contains the data structures which map the X ROPs to the
29 * ViRGE ROPs. It also contains other mappings which are used when supporting
30 * planemasks and transparency.
31 *
32 * Created by Sebastien Marineau, 29/03/97.
33 * This file should be included only from s3v_accel.c to avoid
34 * duplicate symbols.
35 *
36 */
37
38#include "regs3v.h"
39
40static int s3vAlu[16] =
41{
42   ROP_0,               /* GXclear */
43   ROP_DSa,             /* GXand */
44   ROP_SDna,            /* GXandReverse */
45   ROP_S,               /* GXcopy */
46   ROP_DSna,            /* GXandInverted */
47   ROP_D,               /* GXnoop */
48   ROP_DSx,             /* GXxor */
49   ROP_DSo,             /* GXor */
50   ROP_DSon,            /* GXnor */
51   ROP_DSxn,            /* GXequiv */
52   ROP_Dn,              /* GXinvert*/
53   ROP_SDno,            /* GXorReverse */
54   ROP_Sn,              /* GXcopyInverted */
55   ROP_DSno,            /* GXorInverted */
56   ROP_DSan,            /* GXnand */
57   ROP_1                /* GXset */
58};
59
60/* S -> P, for solid and pattern fills. */
61static int s3vAlu_sp[16]=
62{
63   ROP_0,
64   ROP_DPa,
65   ROP_PDna,
66   ROP_P,
67   ROP_DPna,
68   ROP_D,
69   ROP_DPx,
70   ROP_DPo,
71   ROP_DPon,
72   ROP_DPxn,
73   ROP_Dn,
74   ROP_PDno,
75   ROP_Pn,
76   ROP_DPno,
77   ROP_DPan,
78   ROP_1
79};
80
81/* ROP  ->  (ROP & P) | (D & ~P) */
82/* These are used to support a planemask for S->D ops */
83static int s3vAlu_pat[16] =
84{
85   ROP_0_PaDPnao,
86   ROP_DSa_PaDPnao,
87   ROP_SDna_PaDPnao,
88   ROP_S_PaDPnao,
89   ROP_DSna_PaDPnao,
90   ROP_D_PaDPnao,
91   ROP_DSx_PaDPnao,
92   ROP_DSo_PaDPnao,
93   ROP_DSon_PaDPnao,
94   ROP_DSxn_PaDPnao,
95   ROP_Dn_PaDPnao,
96   ROP_SDno_PaDPnao,
97   ROP_Sn_PaDPnao,
98   ROP_DSno_PaDPnao,
99   ROP_DSan_PaDPnao,
100   ROP_1_PaDPnao
101};
102
103/* ROP_sp -> (ROP_sp & S) | (D & ~S) */
104/* This is used for our transparent mono pattern fills to support trans/plane*/
105static int s3vAlu_MonoTrans[16] =
106{
107   ROP_0_SaDSnao,
108   ROP_DPa_SaDSnao,
109   ROP_PDna_SaDSnao,
110   ROP_P_SaDSnao,
111   ROP_DPna_SaDSnao,
112   ROP_D_SaDSnao,
113   ROP_DPx_SaDSnao,
114   ROP_DPo_SaDSnao,
115   ROP_DPon_SaDSnao,
116   ROP_DPxn_SaDSnao,
117   ROP_Dn_SaDSnao,
118   ROP_PDno_SaDSnao,
119   ROP_Pn_SaDSnao,
120   ROP_DPno_SaDSnao,
121   ROP_DPan_SaDSnao,
122   ROP_1_SaDSnao
123};
124
125
126
127/* This function was taken from accel/s3v.h. It adjusts the width
128 * of transfers for mono images to works around some bugs.
129 */
130
131static __inline__ int S3VCheckLSPN(S3VPtr ps3v, int w, int dir)
132{
133   int lspn = (w * ps3v->Bpp) & 63;  /* scanline width in bytes modulo 64*/
134
135   if (ps3v->Bpp == 1) {
136      if (lspn <= 8*1)
137	 w += 16;
138      else if (lspn <= 16*1)
139	 w += 8;
140   } else if (ps3v->Bpp == 2) {
141      if (lspn <= 4*2)
142	 w += 8;
143      else if (lspn <= 8*2)
144	 w += 4;
145   } else {  /* ps3v->Bpp == 3 */
146      if (lspn <= 3*3)
147	 w += 6;
148      else if (lspn <= 6*3)
149	 w += 3;
150   }
151   if (dir && w >= ps3v->bltbug_width1 && w <= ps3v->bltbug_width2) {
152      w = ps3v->bltbug_width2 + 1;
153   }
154
155   return w;
156}
157
158/* And this adjusts color bitblts widths to work around GE bugs */
159
160static __inline__ int S3VCheckBltWidth(S3VPtr ps3v, int w)
161{
162   if (w >= ps3v->bltbug_width1 && w <= ps3v->bltbug_width2) {
163      w = ps3v->bltbug_width2 + 1;
164   }
165   return w;
166}
167
168/* This next function determines if the Source operand is present in the
169 * given ROP. The rule is that both the lower and upper nibble of the rop
170 * have to be neither 0x00, 0x05, 0x0a or 0x0f. If a CPU-Screen blit is done
171 * with a ROP which does not contain the source, the virge will hang when
172 * data is written to the image transfer area.
173 */
174
175static __inline__ Bool S3VROPHasSrc(int shifted_rop)
176{
177    int rop = (shifted_rop & (0xff << 17)) >> 17;
178
179    if ((((rop & 0x0f) == 0x0a) | ((rop & 0x0f) == 0x0f)
180        | ((rop & 0x0f) == 0x05) | ((rop & 0x0f) == 0x00)) &
181       (((rop & 0xf0) == 0xa0) | ((rop & 0xf0) == 0xf0)
182        | ((rop & 0xf0) == 0x50) | ((rop & 0xf0) == 0x00)))
183            return FALSE;
184    else
185            return TRUE;
186}
187
188/* This next function determines if the Destination operand is present in the
189 * given ROP. The rule is that both the lower and upper nibble of the rop
190 * have to be neither 0x00, 0x03, 0x0c or 0x0f.
191 */
192
193static __inline__ Bool S3VROPHasDst(int shifted_rop)
194{
195    int rop = (shifted_rop & (0xff << 17)) >> 17;
196
197    if ((((rop & 0x0f) == 0x0c) | ((rop & 0x0f) == 0x0f)
198        | ((rop & 0x0f) == 0x03) | ((rop & 0x0f) == 0x00)) &
199       (((rop & 0xf0) == 0xc0) | ((rop & 0xf0) == 0xf0)
200        | ((rop & 0xf0) == 0x30) | ((rop & 0xf0) == 0x00)))
201            return FALSE;
202    else
203            return TRUE;
204}
205
206
207
208