comparison src/video/fbcon/SDL_fb3dfx.c @ 0:74212992fb08

Initial revision
author Sam Lantinga <slouken@lokigames.com>
date Thu, 26 Apr 2001 16:45:43 +0000
parents
children 63ec24e0575f
comparison
equal deleted inserted replaced
-1:000000000000 0:74212992fb08
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@devolution.com
21 */
22
23 #ifdef SAVE_RCSID
24 static char rcsid =
25 "@(#) $Id$";
26 #endif
27
28 #include "SDL_types.h"
29 #include "SDL_video.h"
30 #include "SDL_blit.h"
31 #include "SDL_fb3dfx.h"
32 #include "3dfx_mmio.h"
33
34
35 static int LockHWSurface(_THIS, SDL_Surface *surface)
36 {
37 if ( surface == SDL_VideoSurface ) {
38 tdfx_waitidle();
39 }
40 return(0);
41 }
42 static void UnlockHWSurface(_THIS, SDL_Surface *surface)
43 {
44 return;
45 }
46
47 /* Wait for vertical retrace */
48 static void WaitVBL(_THIS)
49 {
50 /* find start of retrace */
51 tdfx_waitidle();
52 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == STATUS_RETRACE )
53 ;
54 /* wait until we're past the start */
55 while( (tdfx_in32(TDFX_STATUS) & STATUS_RETRACE) == 0 )
56 ;
57 }
58
59 /* Sets video mem colorkey and accelerated blit function */
60 static int SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key)
61 {
62 return(0);
63 }
64
65 static int FillHWRect(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color)
66 {
67 int bpp;
68 char *dst_base;
69 Uint32 format;
70 int dstX, dstY;
71
72 /* Set the destination pixel format */
73 dst_base = (char *)((char *)dst->pixels - mapped_mem);
74 bpp = dst->format->BitsPerPixel;
75 format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13);
76
77 /* Calculate source and destination base coordinates */
78 dstX = rect->x;
79 dstY = rect->y;
80
81 /* Execute the fill command */
82 tdfx_wait(6);
83 tdfx_out32(DSTBASE, (Uint32)dst_base);
84 tdfx_out32(DSTFORMAT, format);
85 tdfx_out32(COLORFORE, color);
86 tdfx_out32(COMMAND_2D, COMMAND_2D_FILLRECT);
87 tdfx_out32(DSTSIZE, rect->w | (rect->h << 16));
88 tdfx_out32(LAUNCH_2D, dstX | (dstY << 16));
89 return(0);
90 }
91
92 static int HWAccelBlit(SDL_Surface *src, SDL_Rect *srcrect,
93 SDL_Surface *dst, SDL_Rect *dstrect)
94 {
95 SDL_VideoDevice *this;
96 int bpp;
97 Uint32 src_format;
98 Uint32 dst_format;
99 char *src_base;
100 char *dst_base;
101 int srcX, srcY;
102 int dstX, dstY;
103 Uint32 blitop;
104 Uint32 use_colorkey;
105
106 /* Set the source and destination pixel format */
107 this = current_video;
108 src_base = (char *)((char *)src->pixels - mapped_mem);
109 bpp = src->format->BitsPerPixel;
110 src_format = src->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13);
111 dst_base = (char *)((char *)dst->pixels - mapped_mem);
112 bpp = dst->format->BitsPerPixel;
113 dst_format = dst->pitch | ((bpp+((bpp==8) ? 0 : 8)) << 13);
114
115 srcX = srcrect->x;
116 srcY = srcrect->y;
117 dstX = dstrect->x;
118 dstY = dstrect->y;
119
120 /* Assemble the blit operation */
121 blitop = COMMAND_2D_BITBLT | (0xCC << 24);
122 if ( srcX <= dstX ) {
123 blitop |= BIT(14);
124 srcX += (dstrect->w - 1);
125 dstX += (dstrect->w - 1);
126 }
127 if ( srcY <= dstY ) {
128 blitop |= BIT(15);
129 srcY += (dstrect->h - 1);
130 dstY += (dstrect->h - 1);
131 }
132
133 /* Perform the blit! */
134 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
135 tdfx_wait(3);
136 tdfx_out32(SRCCOLORKEYMIN, src->format->colorkey);
137 tdfx_out32(SRCCOLORKEYMAX, src->format->colorkey);
138 tdfx_out32(ROP_2D, 0xAA00);
139 use_colorkey = 1;
140 } else {
141 use_colorkey = 0;
142 }
143 tdfx_wait(9);
144 tdfx_out32(SRCBASE, (Uint32)src_base);
145 tdfx_out32(SRCFORMAT, src_format);
146 tdfx_out32(DSTBASE, (Uint32)dst_base);
147 tdfx_out32(DSTFORMAT, src_format);
148 tdfx_out32(COMMAND_2D, blitop);
149 tdfx_out32(COMMANDEXTRA_2D, use_colorkey);
150 tdfx_out32(DSTSIZE, dstrect->w | (dstrect->h << 16));
151 tdfx_out32(DSTXY, dstX | (dstY << 16));
152 tdfx_out32(LAUNCH_2D, srcX | (srcY << 16));
153
154 return(0);
155 }
156
157 static int CheckHWBlit(_THIS, SDL_Surface *src, SDL_Surface *dst)
158 {
159 int accelerated;
160
161 /* Set initial acceleration on */
162 src->flags |= SDL_HWACCEL;
163
164 /* Set the surface attributes */
165 if ( (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {
166 if ( ! this->info.blit_hw_A ) {
167 src->flags &= ~SDL_HWACCEL;
168 }
169 }
170 if ( (src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY ) {
171 if ( ! this->info.blit_hw_CC ) {
172 src->flags &= ~SDL_HWACCEL;
173 }
174 }
175
176 /* Check to see if final surface blit is accelerated */
177 accelerated = !!(src->flags & SDL_HWACCEL);
178 if ( accelerated ) {
179 src->map->hw_blit = HWAccelBlit;
180 }
181 return(accelerated);
182 }
183
184 void FB_3DfxAccel(_THIS, __u32 card)
185 {
186 /* We have hardware accelerated surface functions */
187 this->CheckHWBlit = CheckHWBlit;
188 this->LockHWSurface = LockHWSurface;
189 this->UnlockHWSurface = UnlockHWSurface;
190 wait_vbl = WaitVBL;
191
192 /* Reset the 3Dfx controller */
193 tdfx_out32(BRESERROR0, 0);
194 tdfx_out32(BRESERROR1, 0);
195
196 /* The 3Dfx has an accelerated color fill */
197 this->info.blit_fill = 1;
198 this->FillHWRect = FillHWRect;
199
200 /* The 3Dfx has accelerated normal and colorkey blits */
201 this->info.blit_hw = 1;
202 this->info.blit_hw_CC = 1;
203 this->SetHWColorKey = SetHWColorKey;
204 }