comparison src/video/xbios/SDL_xbios.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 14717b52abc0
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
63 #define DEBUG_PRINT(what) 63 #define DEBUG_PRINT(what)
64 #undef DEBUG_VIDEO_XBIOS 64 #undef DEBUG_VIDEO_XBIOS
65 #endif 65 #endif
66 66
67 /* Initialization/Query functions */ 67 /* Initialization/Query functions */
68 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat); 68 static int XBIOS_VideoInit (_THIS, SDL_PixelFormat * vformat);
69 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); 69 static SDL_Rect **XBIOS_ListModes (_THIS, SDL_PixelFormat * format,
70 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); 70 Uint32 flags);
71 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); 71 static SDL_Surface *XBIOS_SetVideoMode (_THIS, SDL_Surface * current,
72 static void XBIOS_VideoQuit(_THIS); 72 int width, int height, int bpp,
73 Uint32 flags);
74 static int XBIOS_SetColors (_THIS, int firstcolor, int ncolors,
75 SDL_Color * colors);
76 static void XBIOS_VideoQuit (_THIS);
73 77
74 /* Hardware surface functions */ 78 /* Hardware surface functions */
75 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface); 79 static int XBIOS_AllocHWSurface (_THIS, SDL_Surface * surface);
76 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface); 80 static int XBIOS_LockHWSurface (_THIS, SDL_Surface * surface);
77 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface); 81 static int XBIOS_FlipHWSurface (_THIS, SDL_Surface * surface);
78 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface); 82 static void XBIOS_UnlockHWSurface (_THIS, SDL_Surface * surface);
79 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface); 83 static void XBIOS_FreeHWSurface (_THIS, SDL_Surface * surface);
80 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); 84 static void XBIOS_UpdateRects (_THIS, int numrects, SDL_Rect * rects);
81 85
82 #if SDL_VIDEO_OPENGL 86 #if SDL_VIDEO_OPENGL
83 /* OpenGL functions */ 87 /* OpenGL functions */
84 static void XBIOS_GL_SwapBuffers(_THIS); 88 static void XBIOS_GL_SwapBuffers (_THIS);
85 #endif 89 #endif
86 90
87 /* To setup palette */ 91 /* To setup palette */
88 92
89 static unsigned short TT_palette[256]; 93 static unsigned short TT_palette[256];
90 static unsigned long F30_palette[256]; 94 static unsigned long F30_palette[256];
91 95
92 /* Xbios driver bootstrap functions */ 96 /* Xbios driver bootstrap functions */
93 97
94 static int XBIOS_Available(void) 98 static int
95 { 99 XBIOS_Available (void)
96 unsigned long cookie_vdo, cookie_mil, cookie_hade, cookie_scpn; 100 {
97 101 unsigned long cookie_vdo, cookie_mil, cookie_hade, cookie_scpn;
98 /* Milan/Hades Atari clones do not have an Atari video chip */ 102
99 if ( (Getcookie(C__MIL, &cookie_mil) == C_FOUND) || 103 /* Milan/Hades Atari clones do not have an Atari video chip */
100 (Getcookie(C_hade, &cookie_hade) == C_FOUND) ) { 104 if ((Getcookie (C__MIL, &cookie_mil) == C_FOUND) ||
101 return 0; 105 (Getcookie (C_hade, &cookie_hade) == C_FOUND)) {
102 } 106 return 0;
103 107 }
104 /* Cookie _VDO present ? if not, assume ST machine */ 108
105 if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) { 109 /* Cookie _VDO present ? if not, assume ST machine */
106 cookie_vdo = VDO_ST << 16; 110 if (Getcookie (C__VDO, &cookie_vdo) != C_FOUND) {
107 } 111 cookie_vdo = VDO_ST << 16;
108 112 }
109 /* Test if we have a monochrome monitor plugged in */ 113
110 switch( cookie_vdo >>16) { 114 /* Test if we have a monochrome monitor plugged in */
111 case VDO_ST: 115 switch (cookie_vdo >> 16) {
112 case VDO_STE: 116 case VDO_ST:
113 if ( Getrez() == (ST_HIGH>>8) ) 117 case VDO_STE:
114 return 0; 118 if (Getrez () == (ST_HIGH >> 8))
115 break; 119 return 0;
116 case VDO_TT: 120 break;
117 if ( (EgetShift() & ES_MODE) == TT_HIGH) 121 case VDO_TT:
118 return 0; 122 if ((EgetShift () & ES_MODE) == TT_HIGH)
119 break; 123 return 0;
120 case VDO_F30: 124 break;
121 if ( VgetMonitor() == MONITOR_MONO) 125 case VDO_F30:
122 return 0; 126 if (VgetMonitor () == MONITOR_MONO)
123 if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) { 127 return 0;
124 if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *)cookie_scpn)) { 128 if (Getcookie (C_SCPN, &cookie_scpn) == C_FOUND) {
125 return 0; 129 if (!SDL_XBIOS_SB3Usable ((scpn_cookie_t *) cookie_scpn)) {
126 } 130 return 0;
127 } 131 }
128 break; 132 }
129 default: 133 break;
130 return 0; 134 default:
131 } 135 return 0;
132 136 }
133 return 1; 137
134 } 138 return 1;
135 139 }
136 static void XBIOS_DeleteDevice(SDL_VideoDevice *device) 140
137 { 141 static void
138 SDL_free(device->hidden); 142 XBIOS_DeleteDevice (SDL_VideoDevice * device)
139 SDL_free(device); 143 {
140 } 144 SDL_free (device->hidden);
141 145 SDL_free (device);
142 static SDL_VideoDevice *XBIOS_CreateDevice(int devindex) 146 }
143 { 147
144 SDL_VideoDevice *device; 148 static SDL_VideoDevice *
145 149 XBIOS_CreateDevice (int devindex)
146 /* Initialize all variables that we clean on shutdown */ 150 {
147 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); 151 SDL_VideoDevice *device;
148 if ( device ) { 152
149 SDL_memset(device, 0, (sizeof *device)); 153 /* Initialize all variables that we clean on shutdown */
150 device->hidden = (struct SDL_PrivateVideoData *) 154 device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
151 SDL_malloc((sizeof *device->hidden)); 155 if (device) {
152 device->gl_data = (struct SDL_PrivateGLData *) 156 SDL_memset (device, 0, (sizeof *device));
153 SDL_malloc((sizeof *device->gl_data)); 157 device->hidden = (struct SDL_PrivateVideoData *)
154 } 158 SDL_malloc ((sizeof *device->hidden));
155 if ( (device == NULL) || (device->hidden == NULL) ) { 159 device->gl_data = (struct SDL_PrivateGLData *)
156 SDL_OutOfMemory(); 160 SDL_malloc ((sizeof *device->gl_data));
157 if ( device ) { 161 }
158 SDL_free(device); 162 if ((device == NULL) || (device->hidden == NULL)) {
159 } 163 SDL_OutOfMemory ();
160 return(0); 164 if (device) {
161 } 165 SDL_free (device);
162 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); 166 }
163 SDL_memset(device->gl_data, 0, sizeof(*device->gl_data)); 167 return (0);
164 168 }
165 /* Video functions */ 169 SDL_memset (device->hidden, 0, (sizeof *device->hidden));
166 device->VideoInit = XBIOS_VideoInit; 170 SDL_memset (device->gl_data, 0, sizeof (*device->gl_data));
167 device->ListModes = XBIOS_ListModes; 171
168 device->SetVideoMode = XBIOS_SetVideoMode; 172 /* Video functions */
169 device->SetColors = XBIOS_SetColors; 173 device->VideoInit = XBIOS_VideoInit;
170 device->UpdateRects = NULL; 174 device->ListModes = XBIOS_ListModes;
171 device->VideoQuit = XBIOS_VideoQuit; 175 device->SetVideoMode = XBIOS_SetVideoMode;
172 device->AllocHWSurface = XBIOS_AllocHWSurface; 176 device->SetColors = XBIOS_SetColors;
173 device->LockHWSurface = XBIOS_LockHWSurface; 177 device->UpdateRects = NULL;
174 device->UnlockHWSurface = XBIOS_UnlockHWSurface; 178 device->VideoQuit = XBIOS_VideoQuit;
175 device->FlipHWSurface = XBIOS_FlipHWSurface; 179 device->AllocHWSurface = XBIOS_AllocHWSurface;
176 device->FreeHWSurface = XBIOS_FreeHWSurface; 180 device->LockHWSurface = XBIOS_LockHWSurface;
181 device->UnlockHWSurface = XBIOS_UnlockHWSurface;
182 device->FlipHWSurface = XBIOS_FlipHWSurface;
183 device->FreeHWSurface = XBIOS_FreeHWSurface;
177 184
178 #if SDL_VIDEO_OPENGL 185 #if SDL_VIDEO_OPENGL
179 /* OpenGL functions */ 186 /* OpenGL functions */
180 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary; 187 device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
181 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress; 188 device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
182 device->GL_GetAttribute = SDL_AtariGL_GetAttribute; 189 device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
183 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent; 190 device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
184 device->GL_SwapBuffers = XBIOS_GL_SwapBuffers; 191 device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
185 #endif 192 #endif
186 193
187 /* Events */ 194 /* Events */
188 device->InitOSKeymap = Atari_InitOSKeymap; 195 device->InitOSKeymap = Atari_InitOSKeymap;
189 device->PumpEvents = Atari_PumpEvents; 196 device->PumpEvents = Atari_PumpEvents;
190 197
191 device->free = XBIOS_DeleteDevice; 198 device->free = XBIOS_DeleteDevice;
192 199
193 return device; 200 return device;
194 } 201 }
195 202
196 VideoBootStrap XBIOS_bootstrap = { 203 VideoBootStrap XBIOS_bootstrap = {
197 XBIOS_VID_DRIVER_NAME, "Atari Xbios driver", 204 XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
198 XBIOS_Available, XBIOS_CreateDevice 205 XBIOS_Available, XBIOS_CreateDevice
199 }; 206 };
200 207
201 void SDL_XBIOS_AddMode(_THIS, Uint16 modecode, Uint16 width, Uint16 height, 208 void
202 Uint16 depth, SDL_bool flags) 209 SDL_XBIOS_AddMode (_THIS, Uint16 modecode, Uint16 width, Uint16 height,
203 { 210 Uint16 depth, SDL_bool flags)
204 int i, curpos; 211 {
205 xbiosmode_t *current_mode; 212 int i, curpos;
206 213 xbiosmode_t *current_mode;
207 /* Check if mode already exists */ 214
208 if (XBIOS_modelist) { 215 /* Check if mode already exists */
209 current_mode = XBIOS_modelist; 216 if (XBIOS_modelist) {
210 for (i=0;i<XBIOS_nummodes; i++, current_mode++) { 217 current_mode = XBIOS_modelist;
211 if (current_mode->width != width) 218 for (i = 0; i < XBIOS_nummodes; i++, current_mode++) {
212 continue; 219 if (current_mode->width != width)
213 if (current_mode->height != height) 220 continue;
214 continue; 221 if (current_mode->height != height)
215 if (current_mode->depth != depth) 222 continue;
216 continue; 223 if (current_mode->depth != depth)
217 return; 224 continue;
218 } 225 return;
219 } 226 }
220 227 }
221 ++XBIOS_nummodes; 228
222 XBIOS_modelist = (xbiosmode_t *) SDL_realloc(XBIOS_modelist, XBIOS_nummodes * sizeof(xbiosmode_t)); 229 ++XBIOS_nummodes;
223 230 XBIOS_modelist =
224 /* Keep the list sorted: bpp, width, height */ 231 (xbiosmode_t *) SDL_realloc (XBIOS_modelist,
225 curpos=0; 232 XBIOS_nummodes * sizeof (xbiosmode_t));
226 233
227 for(i=0; i<XBIOS_nummodes-1; i++) { 234 /* Keep the list sorted: bpp, width, height */
228 if (XBIOS_modelist[i].depth <= depth) { 235 curpos = 0;
229 if (XBIOS_modelist[i].width < width) { 236
230 break; 237 for (i = 0; i < XBIOS_nummodes - 1; i++) {
231 } else if (XBIOS_modelist[i].width == width) { 238 if (XBIOS_modelist[i].depth <= depth) {
232 if (XBIOS_modelist[i].height <= height) { 239 if (XBIOS_modelist[i].width < width) {
233 break; 240 break;
234 } 241 } else if (XBIOS_modelist[i].width == width) {
235 } 242 if (XBIOS_modelist[i].height <= height) {
236 } 243 break;
237 curpos++; 244 }
238 } 245 }
239 246 }
240 /* Push remaining modes further */ 247 curpos++;
241 for(i=XBIOS_nummodes-1; i>curpos; i--) { 248 }
242 SDL_memcpy(&XBIOS_modelist[i], &XBIOS_modelist[i-1], sizeof(xbiosmode_t)); 249
243 } 250 /* Push remaining modes further */
244 251 for (i = XBIOS_nummodes - 1; i > curpos; i--) {
245 XBIOS_modelist[curpos].number = modecode; 252 SDL_memcpy (&XBIOS_modelist[i], &XBIOS_modelist[i - 1],
246 XBIOS_modelist[curpos].width = width; 253 sizeof (xbiosmode_t));
247 XBIOS_modelist[curpos].height = height; 254 }
248 XBIOS_modelist[curpos].depth = depth; 255
249 XBIOS_modelist[curpos].doubleline = flags; 256 XBIOS_modelist[curpos].number = modecode;
250 } 257 XBIOS_modelist[curpos].width = width;
251 258 XBIOS_modelist[curpos].height = height;
252 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat) 259 XBIOS_modelist[curpos].depth = depth;
253 { 260 XBIOS_modelist[curpos].doubleline = flags;
254 int i,j8,j16; 261 }
255 xbiosmode_t *current_mode; 262
256 unsigned long cookie_blow, cookie_scpn, cookie_cnts; 263 static int
257 264 XBIOS_VideoInit (_THIS, SDL_PixelFormat * vformat)
258 /* Initialize all variables that we clean on shutdown */ 265 {
259 memset (SDL_modelist, 0, sizeof(SDL_modelist)); 266 int i, j8, j16;
260 267 xbiosmode_t *current_mode;
261 /* Cookie _VDO present ? if not, assume ST machine */ 268 unsigned long cookie_blow, cookie_scpn, cookie_cnts;
262 if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) { 269
263 XBIOS_cvdo = VDO_ST << 16; 270 /* Initialize all variables that we clean on shutdown */
264 } 271 memset (SDL_modelist, 0, sizeof (SDL_modelist));
265 272
266 /* Allocate memory for old palette */ 273 /* Cookie _VDO present ? if not, assume ST machine */
267 XBIOS_oldpalette = (void *)SDL_malloc(256*sizeof(long)); 274 if (Getcookie (C__VDO, &XBIOS_cvdo) != C_FOUND) {
268 if ( !XBIOS_oldpalette ) { 275 XBIOS_cvdo = VDO_ST << 16;
269 SDL_SetError("Unable to allocate memory for old palette\n"); 276 }
270 return(-1); 277
271 } 278 /* Allocate memory for old palette */
272 279 XBIOS_oldpalette = (void *) SDL_malloc (256 * sizeof (long));
273 /* Initialize video mode list */ 280 if (!XBIOS_oldpalette) {
274 /* and save current screen status (palette, screen address, video mode) */ 281 SDL_SetError ("Unable to allocate memory for old palette\n");
275 XBIOS_nummodes = 0; 282 return (-1);
276 XBIOS_modelist = NULL; 283 }
277 XBIOS_centscreen = SDL_FALSE; 284
278 285 /* Initialize video mode list */
279 switch (XBIOS_cvdo >>16) { 286 /* and save current screen status (palette, screen address, video mode) */
280 case VDO_ST: 287 XBIOS_nummodes = 0;
281 case VDO_STE: 288 XBIOS_modelist = NULL;
282 { 289 XBIOS_centscreen = SDL_FALSE;
283 short *oldpalette; 290
284 291 switch (XBIOS_cvdo >> 16) {
285 SDL_XBIOS_AddMode(this, ST_LOW>>8,320,200,4,SDL_FALSE); 292 case VDO_ST:
286 293 case VDO_STE:
287 XBIOS_oldvbase=Physbase(); 294 {
288 XBIOS_oldvmode=Getrez(); 295 short *oldpalette;
289 switch(XBIOS_oldvmode << 8) { 296
290 case ST_LOW: 297 SDL_XBIOS_AddMode (this, ST_LOW >> 8, 320, 200, 4, SDL_FALSE);
291 XBIOS_oldnumcol=16; 298
292 break; 299 XBIOS_oldvbase = Physbase ();
293 case ST_MED: 300 XBIOS_oldvmode = Getrez ();
294 XBIOS_oldnumcol=4; 301 switch (XBIOS_oldvmode << 8) {
295 break; 302 case ST_LOW:
296 case ST_HIGH: 303 XBIOS_oldnumcol = 16;
297 XBIOS_oldnumcol=2; 304 break;
298 break; 305 case ST_MED:
299 default: 306 XBIOS_oldnumcol = 4;
300 XBIOS_oldnumcol=0; 307 break;
301 break; 308 case ST_HIGH:
302 } 309 XBIOS_oldnumcol = 2;
303 310 break;
304 oldpalette= (short *) XBIOS_oldpalette; 311 default:
305 for (i=0;i<XBIOS_oldnumcol;i++) { 312 XBIOS_oldnumcol = 0;
306 *oldpalette++=Setcolor(i,-1); 313 break;
307 } 314 }
308 315
309 vformat->BitsPerPixel = 8; 316 oldpalette = (short *) XBIOS_oldpalette;
310 } 317 for (i = 0; i < XBIOS_oldnumcol; i++) {
311 break; 318 *oldpalette++ = Setcolor (i, -1);
312 case VDO_TT: 319 }
313 320
314 SDL_XBIOS_AddMode(this, TT_LOW,320,480,8,SDL_FALSE); 321 vformat->BitsPerPixel = 8;
315 /* Software double-lined mode */ 322 }
316 SDL_XBIOS_AddMode(this, TT_LOW,320,240,8,SDL_TRUE); 323 break;
317 324 case VDO_TT:
318 XBIOS_oldvbase=Logbase(); 325
319 XBIOS_oldvmode=EgetShift(); 326 SDL_XBIOS_AddMode (this, TT_LOW, 320, 480, 8, SDL_FALSE);
320 327 /* Software double-lined mode */
321 switch(XBIOS_oldvmode & ES_MODE) { 328 SDL_XBIOS_AddMode (this, TT_LOW, 320, 240, 8, SDL_TRUE);
322 case TT_LOW: 329
323 XBIOS_oldnumcol=256; 330 XBIOS_oldvbase = Logbase ();
324 break; 331 XBIOS_oldvmode = EgetShift ();
325 case ST_LOW: 332
326 case TT_MED: 333 switch (XBIOS_oldvmode & ES_MODE) {
327 XBIOS_oldnumcol=16; 334 case TT_LOW:
328 break; 335 XBIOS_oldnumcol = 256;
329 case ST_MED: 336 break;
330 XBIOS_oldnumcol=4; 337 case ST_LOW:
331 break; 338 case TT_MED:
332 case ST_HIGH: 339 XBIOS_oldnumcol = 16;
333 case TT_HIGH: 340 break;
334 XBIOS_oldnumcol=2; 341 case ST_MED:
335 break; 342 XBIOS_oldnumcol = 4;
336 default: 343 break;
337 XBIOS_oldnumcol=0; 344 case ST_HIGH:
338 break; 345 case TT_HIGH:
339 } 346 XBIOS_oldnumcol = 2;
340 if (XBIOS_oldnumcol) { 347 break;
341 EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette); 348 default:
342 } 349 XBIOS_oldnumcol = 0;
343 350 break;
344 vformat->BitsPerPixel = 8; 351 }
345 break; 352 if (XBIOS_oldnumcol) {
346 case VDO_F30: 353 EgetPalette (0, XBIOS_oldnumcol, XBIOS_oldpalette);
347 switch (VgetMonitor()) 354 }
348 { 355
349 case MONITOR_MONO: 356 vformat->BitsPerPixel = 8;
350 /* Not usable */ 357 break;
351 break; 358 case VDO_F30:
352 case MONITOR_RGB: 359 switch (VgetMonitor ()) {
353 case MONITOR_TV: 360 case MONITOR_MONO:
354 SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE); 361 /* Not usable */
355 SDL_XBIOS_AddMode(this, BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE); 362 break;
356 SDL_XBIOS_AddMode(this, BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE); 363 case MONITOR_RGB:
357 SDL_XBIOS_AddMode(this, BPS16|COL80,640,200,16,SDL_FALSE); 364 case MONITOR_TV:
358 SDL_XBIOS_AddMode(this, BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE); 365 SDL_XBIOS_AddMode (this, BPS16 | COL80 | OVERSCAN | VERTFLAG,
359 SDL_XBIOS_AddMode(this, BPS16|OVERSCAN,384,240,16,SDL_FALSE); 366 768, 480, 16, SDL_FALSE);
360 SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,400,16,SDL_FALSE); 367 SDL_XBIOS_AddMode (this, BPS16 | COL80 | OVERSCAN, 768, 240,
361 SDL_XBIOS_AddMode(this, BPS16,320,200,16,SDL_FALSE); 368 16, SDL_FALSE);
362 SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE); 369 SDL_XBIOS_AddMode (this, BPS16 | COL80 | VERTFLAG, 640, 400,
363 SDL_XBIOS_AddMode(this, BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE); 370 16, SDL_FALSE);
364 SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE); 371 SDL_XBIOS_AddMode (this, BPS16 | COL80, 640, 200, 16, SDL_FALSE);
365 SDL_XBIOS_AddMode(this, BPS8|COL80,640,200,8,SDL_FALSE); 372 SDL_XBIOS_AddMode (this, BPS16 | OVERSCAN | VERTFLAG, 384,
366 SDL_XBIOS_AddMode(this, BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE); 373 480, 16, SDL_FALSE);
367 SDL_XBIOS_AddMode(this, BPS8|OVERSCAN,384,240,8,SDL_FALSE); 374 SDL_XBIOS_AddMode (this, BPS16 | OVERSCAN, 384, 240, 16,
368 SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,400,8,SDL_FALSE); 375 SDL_FALSE);
369 SDL_XBIOS_AddMode(this, BPS8,320,200,8,SDL_FALSE); 376 SDL_XBIOS_AddMode (this, BPS16 | VERTFLAG, 320, 400, 16,
370 break; 377 SDL_FALSE);
371 case MONITOR_VGA: 378 SDL_XBIOS_AddMode (this, BPS16, 320, 200, 16, SDL_FALSE);
372 SDL_XBIOS_AddMode(this, BPS16,320,480,16,SDL_FALSE); 379 SDL_XBIOS_AddMode (this, BPS8 | COL80 | OVERSCAN | VERTFLAG,
373 SDL_XBIOS_AddMode(this, BPS16|VERTFLAG,320,240,16,SDL_FALSE); 380 768, 480, 8, SDL_FALSE);
374 SDL_XBIOS_AddMode(this, BPS8|COL80,640,480,8,SDL_FALSE); 381 SDL_XBIOS_AddMode (this, BPS8 | COL80 | OVERSCAN, 768, 240, 8,
375 SDL_XBIOS_AddMode(this, BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE); 382 SDL_FALSE);
376 SDL_XBIOS_AddMode(this, BPS8,320,480,8,SDL_FALSE); 383 SDL_XBIOS_AddMode (this, BPS8 | COL80 | VERTFLAG, 640, 400, 8,
377 SDL_XBIOS_AddMode(this, BPS8|VERTFLAG,320,240,8,SDL_FALSE); 384 SDL_FALSE);
378 break; 385 SDL_XBIOS_AddMode (this, BPS8 | COL80, 640, 200, 8, SDL_FALSE);
379 } 386 SDL_XBIOS_AddMode (this, BPS8 | OVERSCAN | VERTFLAG, 384, 480,
380 XBIOS_oldvbase=Logbase(); 387 8, SDL_FALSE);
381 XBIOS_oldvmode=VsetMode(-1); 388 SDL_XBIOS_AddMode (this, BPS8 | OVERSCAN, 384, 240, 8, SDL_FALSE);
382 389 SDL_XBIOS_AddMode (this, BPS8 | VERTFLAG, 320, 400, 8, SDL_FALSE);
383 XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS)); 390 SDL_XBIOS_AddMode (this, BPS8, 320, 200, 8, SDL_FALSE);
384 if (XBIOS_oldnumcol > 256) { 391 break;
385 XBIOS_oldnumcol = 0; 392 case MONITOR_VGA:
386 } 393 SDL_XBIOS_AddMode (this, BPS16, 320, 480, 16, SDL_FALSE);
387 if (XBIOS_oldnumcol) { 394 SDL_XBIOS_AddMode (this, BPS16 | VERTFLAG, 320, 240, 16,
388 VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette); 395 SDL_FALSE);
389 } 396 SDL_XBIOS_AddMode (this, BPS8 | COL80, 640, 480, 8, SDL_FALSE);
390 397 SDL_XBIOS_AddMode (this, BPS8 | COL80 | VERTFLAG, 640, 240, 8,
391 vformat->BitsPerPixel = 16; 398 SDL_FALSE);
392 399 SDL_XBIOS_AddMode (this, BPS8, 320, 480, 8, SDL_FALSE);
393 /* Keep vga/rvb, and pal/ntsc bits */ 400 SDL_XBIOS_AddMode (this, BPS8 | VERTFLAG, 320, 240, 8, SDL_FALSE);
394 current_mode = XBIOS_modelist; 401 break;
395 for (i=0;i<XBIOS_nummodes;i++) { 402 }
396 Uint16 newvmode; 403 XBIOS_oldvbase = Logbase ();
397 404 XBIOS_oldvmode = VsetMode (-1);
398 newvmode = current_mode->number; 405
399 newvmode &= ~(VGA|PAL); 406 XBIOS_oldnumcol = 1 << (1 << (XBIOS_oldvmode & NUMCOLS));
400 newvmode |= XBIOS_oldvmode & (VGA|PAL); 407 if (XBIOS_oldnumcol > 256) {
401 current_mode->number = newvmode; 408 XBIOS_oldnumcol = 0;
402 409 }
403 current_mode++; 410 if (XBIOS_oldnumcol) {
404 } 411 VgetRGB (0, XBIOS_oldnumcol, XBIOS_oldpalette);
405 412 }
406 /* Initialize BlowUp/SB3/Centscreen stuff if present */ 413
407 if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) { 414 vformat->BitsPerPixel = 16;
408 SDL_XBIOS_BlowupInit(this, (blow_cookie_t *)cookie_blow); 415
409 } else if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) { 416 /* Keep vga/rvb, and pal/ntsc bits */
410 SDL_XBIOS_SB3Init(this, (scpn_cookie_t *)cookie_scpn); 417 current_mode = XBIOS_modelist;
411 } else if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) { 418 for (i = 0; i < XBIOS_nummodes; i++) {
412 XBIOS_oldvmode = SDL_XBIOS_CentscreenInit(this); 419 Uint16 newvmode;
413 XBIOS_centscreen = SDL_TRUE; 420
414 } 421 newvmode = current_mode->number;
415 422 newvmode &= ~(VGA | PAL);
416 break; 423 newvmode |= XBIOS_oldvmode & (VGA | PAL);
417 } 424 current_mode->number = newvmode;
418 425
419 /* Determine the current screen size */ 426 current_mode++;
420 if ( XBIOS_nummodes > 0 ) { 427 }
421 /* FIXME: parse video mode list to search for current mode */ 428
422 this->info.current_w = XBIOS_modelist[0].width; 429 /* Initialize BlowUp/SB3/Centscreen stuff if present */
423 this->info.current_h = XBIOS_modelist[0].height; 430 if (Getcookie (C_BLOW, &cookie_blow) == C_FOUND) {
424 } 431 SDL_XBIOS_BlowupInit (this, (blow_cookie_t *) cookie_blow);
425 432 } else if (Getcookie (C_SCPN, &cookie_scpn) == C_FOUND) {
426 current_mode = XBIOS_modelist; 433 SDL_XBIOS_SB3Init (this, (scpn_cookie_t *) cookie_scpn);
427 j8 = j16 = 0; 434 } else if (Getcookie (C_CNTS, &cookie_cnts) == C_FOUND) {
428 for (i=0; i<XBIOS_nummodes; i++, current_mode++) { 435 XBIOS_oldvmode = SDL_XBIOS_CentscreenInit (this);
429 switch (current_mode->depth) { 436 XBIOS_centscreen = SDL_TRUE;
430 case 4: 437 }
431 case 8: 438
432 SDL_modelist[0][j8] = SDL_malloc(sizeof(SDL_Rect)); 439 break;
433 SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0; 440 }
434 SDL_modelist[0][j8]->w = current_mode->width; 441
435 SDL_modelist[0][j8]->h = current_mode->height; 442 /* Determine the current screen size */
436 XBIOS_videomodes[0][j8]=current_mode; 443 if (XBIOS_nummodes > 0) {
437 j8++; 444 /* FIXME: parse video mode list to search for current mode */
438 break; 445 this->info.current_w = XBIOS_modelist[0].width;
439 case 16: 446 this->info.current_h = XBIOS_modelist[0].height;
440 SDL_modelist[1][j16] = SDL_malloc(sizeof(SDL_Rect)); 447 }
441 SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0; 448
442 SDL_modelist[1][j16]->w = current_mode->width; 449 current_mode = XBIOS_modelist;
443 SDL_modelist[1][j16]->h = current_mode->height; 450 j8 = j16 = 0;
444 XBIOS_videomodes[1][j16]=current_mode; 451 for (i = 0; i < XBIOS_nummodes; i++, current_mode++) {
445 j16++; 452 switch (current_mode->depth) {
446 break; 453 case 4:
447 } 454 case 8:
448 } 455 SDL_modelist[0][j8] = SDL_malloc (sizeof (SDL_Rect));
449 SDL_modelist[0][j8] = NULL; 456 SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0;
450 SDL_modelist[1][j16] = NULL; 457 SDL_modelist[0][j8]->w = current_mode->width;
451 458 SDL_modelist[0][j8]->h = current_mode->height;
452 XBIOS_screens[0]=NULL; 459 XBIOS_videomodes[0][j8] = current_mode;
453 XBIOS_screens[1]=NULL; 460 j8++;
454 XBIOS_shadowscreen=NULL; 461 break;
455 462 case 16:
456 /* Update hardware info */ 463 SDL_modelist[1][j16] = SDL_malloc (sizeof (SDL_Rect));
457 this->info.hw_available = 1; 464 SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0;
458 this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM); 465 SDL_modelist[1][j16]->w = current_mode->width;
459 466 SDL_modelist[1][j16]->h = current_mode->height;
460 /* Init chunky to planar routine */ 467 XBIOS_videomodes[1][j16] = current_mode;
461 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; 468 j16++;
469 break;
470 }
471 }
472 SDL_modelist[0][j8] = NULL;
473 SDL_modelist[1][j16] = NULL;
474
475 XBIOS_screens[0] = NULL;
476 XBIOS_screens[1] = NULL;
477 XBIOS_shadowscreen = NULL;
478
479 /* Update hardware info */
480 this->info.hw_available = 1;
481 this->info.video_mem = (Uint32) Atari_SysMalloc (-1L, MX_STRAM);
482
483 /* Init chunky to planar routine */
484 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
462 485
463 #if SDL_VIDEO_OPENGL 486 #if SDL_VIDEO_OPENGL
464 SDL_AtariGL_InitPointers(this); 487 SDL_AtariGL_InitPointers (this);
465 #endif 488 #endif
466 489
467 /* We're done! */ 490 /* We're done! */
468 return(0); 491 return (0);
469 } 492 }
470 493
471 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) 494 static SDL_Rect **
472 { 495 XBIOS_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
473 /* 8 bits -> list 0 */ 496 {
474 /* 16 bits -> list 1 */ 497 /* 8 bits -> list 0 */
475 if ((format->BitsPerPixel != 8) && (format->BitsPerPixel !=16)) { 498 /* 16 bits -> list 1 */
476 return NULL; 499 if ((format->BitsPerPixel != 8) && (format->BitsPerPixel != 16)) {
477 } 500 return NULL;
478 501 }
479 return(SDL_modelist[(format->BitsPerPixel)>>4]); 502
480 } 503 return (SDL_modelist[(format->BitsPerPixel) >> 4]);
481 504 }
482 static void XBIOS_FreeBuffers(_THIS) 505
483 { 506 static void
484 int i; 507 XBIOS_FreeBuffers (_THIS)
485 508 {
486 for (i=0;i<2;i++) { 509 int i;
487 if (XBIOS_screensmem[i]!=NULL) { 510
488 Mfree(XBIOS_screensmem[i]); 511 for (i = 0; i < 2; i++) {
489 XBIOS_screensmem[i]=NULL; 512 if (XBIOS_screensmem[i] != NULL) {
490 } 513 Mfree (XBIOS_screensmem[i]);
491 } 514 XBIOS_screensmem[i] = NULL;
492 515 }
493 if (XBIOS_shadowscreen!=NULL) { 516 }
494 Mfree(XBIOS_shadowscreen); 517
495 XBIOS_shadowscreen=NULL; 518 if (XBIOS_shadowscreen != NULL) {
496 } 519 Mfree (XBIOS_shadowscreen);
497 } 520 XBIOS_shadowscreen = NULL;
498 521 }
499 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, 522 }
500 int width, int height, int bpp, Uint32 flags) 523
501 { 524 static SDL_Surface *
502 int mode, new_depth; 525 XBIOS_SetVideoMode (_THIS, SDL_Surface * current,
503 int i; 526 int width, int height, int bpp, Uint32 flags)
504 xbiosmode_t *new_video_mode; 527 {
505 Uint32 new_screen_size; 528 int mode, new_depth;
506 Uint32 modeflags; 529 int i;
507 530 xbiosmode_t *new_video_mode;
508 /* Free current buffers */ 531 Uint32 new_screen_size;
509 XBIOS_FreeBuffers(this); 532 Uint32 modeflags;
510 533
511 /* Limit bpp */ 534 /* Free current buffers */
512 if (bpp>16) { 535 XBIOS_FreeBuffers (this);
513 bpp = 16; 536
514 } 537 /* Limit bpp */
515 bpp >>= 4; 538 if (bpp > 16) {
516 539 bpp = 16;
517 /* Search if the mode exists (width, height, bpp) */ 540 }
518 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { 541 bpp >>= 4;
519 if ( (SDL_modelist[bpp][mode]->w == width) && 542
520 (SDL_modelist[bpp][mode]->h == height) ) { 543 /* Search if the mode exists (width, height, bpp) */
521 544 for (mode = 0; SDL_modelist[bpp][mode]; ++mode) {
522 break; 545 if ((SDL_modelist[bpp][mode]->w == width) &&
523 } 546 (SDL_modelist[bpp][mode]->h == height)) {
524 } 547
525 if ( SDL_modelist[bpp][mode] == NULL ) { 548 break;
526 SDL_SetError("Couldn't find requested mode in list"); 549 }
527 return(NULL); 550 }
528 } 551 if (SDL_modelist[bpp][mode] == NULL) {
529 552 SDL_SetError ("Couldn't find requested mode in list");
530 modeflags = SDL_FULLSCREEN | SDL_PREALLOC; 553 return (NULL);
531 554 }
532 /* Allocate needed buffers: simple/double buffer and shadow surface */ 555
533 new_video_mode = XBIOS_videomodes[bpp][mode]; 556 modeflags = SDL_FULLSCREEN | SDL_PREALLOC;
534 new_depth = new_video_mode->depth; 557
535 if (new_depth == 4) { 558 /* Allocate needed buffers: simple/double buffer and shadow surface */
536 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4; 559 new_video_mode = XBIOS_videomodes[bpp][mode];
537 new_depth=8; 560 new_depth = new_video_mode->depth;
538 modeflags |= SDL_SWSURFACE|SDL_HWPALETTE; 561 if (new_depth == 4) {
539 } else if (new_depth == 8) { 562 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4;
540 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8; 563 new_depth = 8;
541 modeflags |= SDL_SWSURFACE|SDL_HWPALETTE; 564 modeflags |= SDL_SWSURFACE | SDL_HWPALETTE;
542 } else { 565 } else if (new_depth == 8) {
543 modeflags |= SDL_HWSURFACE; 566 SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
544 } 567 modeflags |= SDL_SWSURFACE | SDL_HWPALETTE;
545 568 } else {
546 new_screen_size = width * height * ((new_depth)>>3); 569 modeflags |= SDL_HWSURFACE;
547 new_screen_size += 256; /* To align on a 256 byte adress */ 570 }
548 571
549 if (new_depth == 8) { 572 new_screen_size = width * height * ((new_depth) >> 3);
550 XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM); 573 new_screen_size += 256; /* To align on a 256 byte adress */
551 574
552 if (XBIOS_shadowscreen == NULL) { 575 if (new_depth == 8) {
553 SDL_SetError("Can not allocate %d KB for shadow buffer", new_screen_size>>10); 576 XBIOS_shadowscreen = Atari_SysMalloc (new_screen_size, MX_PREFTTRAM);
554 return (NULL); 577
555 } 578 if (XBIOS_shadowscreen == NULL) {
556 SDL_memset(XBIOS_shadowscreen, 0, new_screen_size); 579 SDL_SetError ("Can not allocate %d KB for shadow buffer",
557 } 580 new_screen_size >> 10);
558 581 return (NULL);
559 /* Output buffer needs to be twice in size for the software double-line mode */ 582 }
560 XBIOS_doubleline = SDL_FALSE; 583 SDL_memset (XBIOS_shadowscreen, 0, new_screen_size);
561 if (new_video_mode->doubleline) { 584 }
562 new_screen_size <<= 1; 585
563 XBIOS_doubleline = SDL_TRUE; 586 /* Output buffer needs to be twice in size for the software double-line mode */
564 } 587 XBIOS_doubleline = SDL_FALSE;
565 588 if (new_video_mode->doubleline) {
566 XBIOS_screensmem[0] = Atari_SysMalloc(new_screen_size, MX_STRAM); 589 new_screen_size <<= 1;
567 590 XBIOS_doubleline = SDL_TRUE;
568 if (XBIOS_screensmem[0]==NULL) { 591 }
569 XBIOS_FreeBuffers(this); 592
570 SDL_SetError("Can not allocate %d KB for frame buffer", new_screen_size>>10); 593 XBIOS_screensmem[0] = Atari_SysMalloc (new_screen_size, MX_STRAM);
571 return (NULL); 594
572 } 595 if (XBIOS_screensmem[0] == NULL) {
573 SDL_memset(XBIOS_screensmem[0], 0, new_screen_size); 596 XBIOS_FreeBuffers (this);
574 597 SDL_SetError ("Can not allocate %d KB for frame buffer",
575 XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL); 598 new_screen_size >> 10);
599 return (NULL);
600 }
601 SDL_memset (XBIOS_screensmem[0], 0, new_screen_size);
602
603 XBIOS_screens[0] =
604 (void *) (((long) XBIOS_screensmem[0] + 256) & 0xFFFFFF00UL);
576 605
577 #if SDL_VIDEO_OPENGL 606 #if SDL_VIDEO_OPENGL
578 if (flags & SDL_INTERNALOPENGL) { 607 if (flags & SDL_INTERNALOPENGL) {
579 if (this->gl_config.double_buffer) { 608 if (this->gl_config.double_buffer) {
580 flags |= SDL_DOUBLEBUF; 609 flags |= SDL_DOUBLEBUF;
581 } 610 }
582 } 611 }
583 #endif 612 #endif
584 613
585 /* Double buffer ? */ 614 /* Double buffer ? */
586 if (flags & SDL_DOUBLEBUF) { 615 if (flags & SDL_DOUBLEBUF) {
587 XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM); 616 XBIOS_screensmem[1] = Atari_SysMalloc (new_screen_size, MX_STRAM);
588 617
589 if (XBIOS_screensmem[1]==NULL) { 618 if (XBIOS_screensmem[1] == NULL) {
590 XBIOS_FreeBuffers(this); 619 XBIOS_FreeBuffers (this);
591 SDL_SetError("Can not allocate %d KB for double buffer", new_screen_size>>10); 620 SDL_SetError ("Can not allocate %d KB for double buffer",
592 return (NULL); 621 new_screen_size >> 10);
593 } 622 return (NULL);
594 SDL_memset(XBIOS_screensmem[1], 0, new_screen_size); 623 }
595 624 SDL_memset (XBIOS_screensmem[1], 0, new_screen_size);
596 XBIOS_screens[1]=(void *) (( (long) XBIOS_screensmem[1]+256) & 0xFFFFFF00UL); 625
597 modeflags |= SDL_DOUBLEBUF; 626 XBIOS_screens[1] =
598 } 627 (void *) (((long) XBIOS_screensmem[1] + 256) & 0xFFFFFF00UL);
599 628 modeflags |= SDL_DOUBLEBUF;
600 /* Allocate the new pixel format for the screen */ 629 }
601 if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) { 630
602 XBIOS_FreeBuffers(this); 631 /* Allocate the new pixel format for the screen */
603 SDL_SetError("Couldn't allocate new pixel format for requested mode"); 632 if (!SDL_ReallocFormat (current, new_depth, 0, 0, 0, 0)) {
604 return(NULL); 633 XBIOS_FreeBuffers (this);
605 } 634 SDL_SetError
606 635 ("Couldn't allocate new pixel format for requested mode");
607 current->w = XBIOS_width = width; 636 return (NULL);
608 current->h = XBIOS_height = height; 637 }
609 current->pitch = (width * new_depth)>>3; 638
610 639 current->w = XBIOS_width = width;
611 /* this is for C2P conversion */ 640 current->h = XBIOS_height = height;
612 XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3; 641 current->pitch = (width * new_depth) >> 3;
613 642
614 if (new_depth == 8) 643 /* this is for C2P conversion */
615 current->pixels = XBIOS_shadowscreen; 644 XBIOS_pitch = (new_video_mode->width * new_video_mode->depth) >> 3;
616 else 645
617 current->pixels = XBIOS_screens[0]; 646 if (new_depth == 8)
618 647 current->pixels = XBIOS_shadowscreen;
619 XBIOS_fbnum = 0; 648 else
649 current->pixels = XBIOS_screens[0];
650
651 XBIOS_fbnum = 0;
620 652
621 #if SDL_VIDEO_OPENGL 653 #if SDL_VIDEO_OPENGL
622 if (flags & SDL_INTERNALOPENGL) { 654 if (flags & SDL_INTERNALOPENGL) {
623 if (!SDL_AtariGL_Init(this, current)) { 655 if (!SDL_AtariGL_Init (this, current)) {
624 XBIOS_FreeBuffers(this); 656 XBIOS_FreeBuffers (this);
625 SDL_SetError("Can not create OpenGL context"); 657 SDL_SetError ("Can not create OpenGL context");
626 return NULL; 658 return NULL;
627 } 659 }
628 660
629 modeflags |= SDL_INTERNALOPENGL; 661 modeflags |= SDL_INTERNALOPENGL;
630 } 662 }
631 #endif 663 #endif
632 664
633 current->flags = modeflags; 665 current->flags = modeflags;
634 666
635 /* Now set the video mode */ 667 /* Now set the video mode */
636 #ifndef DEBUG_VIDEO_XBIOS 668 #ifndef DEBUG_VIDEO_XBIOS
637 Setscreen(-1,XBIOS_screens[0],-1); 669 Setscreen (-1, XBIOS_screens[0], -1);
638 #endif 670 #endif
639 671
640 switch(XBIOS_cvdo >> 16) { 672 switch (XBIOS_cvdo >> 16) {
641 case VDO_ST: 673 case VDO_ST:
642 #ifndef DEBUG_VIDEO_XBIOS 674 #ifndef DEBUG_VIDEO_XBIOS
643 Setscreen(-1,-1,new_video_mode->number); 675 Setscreen (-1, -1, new_video_mode->number);
644 #endif 676 #endif
645 /* Reset palette */ 677 /* Reset palette */
646 for (i=0;i<16;i++) { 678 for (i = 0; i < 16; i++) {
647 TT_palette[i]= ((i>>1)<<8) | (((i*8)/17)<<4) | (i>>1); 679 TT_palette[i] =
648 } 680 ((i >> 1) << 8) | (((i * 8) / 17) << 4) | (i >> 1);
649 #ifndef DEBUG_VIDEO_XBIOS 681 }
650 Setpalette(TT_palette); 682 #ifndef DEBUG_VIDEO_XBIOS
651 #endif 683 Setpalette (TT_palette);
652 break; 684 #endif
653 case VDO_STE: 685 break;
654 #ifndef DEBUG_VIDEO_XBIOS 686 case VDO_STE:
655 Setscreen(-1,-1,new_video_mode->number); 687 #ifndef DEBUG_VIDEO_XBIOS
656 #endif 688 Setscreen (-1, -1, new_video_mode->number);
657 /* Reset palette */ 689 #endif
658 for (i=0;i<16;i++) 690 /* Reset palette */
659 { 691 for (i = 0; i < 16; i++) {
660 int c; 692 int c;
661 693
662 c=((i&1)<<3)|((i>>1)&7); 694 c = ((i & 1) << 3) | ((i >> 1) & 7);
663 TT_palette[i]=(c<<8)|(c<<4)|c; 695 TT_palette[i] = (c << 8) | (c << 4) | c;
664 } 696 }
665 #ifndef DEBUG_VIDEO_XBIOS 697 #ifndef DEBUG_VIDEO_XBIOS
666 Setpalette(TT_palette); 698 Setpalette (TT_palette);
667 #endif 699 #endif
668 break; 700 break;
669 case VDO_TT: 701 case VDO_TT:
670 #ifndef DEBUG_VIDEO_XBIOS 702 #ifndef DEBUG_VIDEO_XBIOS
671 EsetShift(new_video_mode->number); 703 EsetShift (new_video_mode->number);
672 #endif 704 #endif
673 break; 705 break;
674 case VDO_F30: 706 case VDO_F30:
675 #ifndef DEBUG_VIDEO_XBIOS 707 #ifndef DEBUG_VIDEO_XBIOS
676 if (XBIOS_centscreen) { 708 if (XBIOS_centscreen) {
677 SDL_XBIOS_CentscreenSetmode(this, width, height, new_depth); 709 SDL_XBIOS_CentscreenSetmode (this, width, height, new_depth);
678 } else { 710 } else {
679 VsetMode(new_video_mode->number); 711 VsetMode (new_video_mode->number);
680 } 712 }
681 #endif 713 #endif
682 /* Set hardware palette to black in True Colour */ 714 /* Set hardware palette to black in True Colour */
683 if (new_depth == 16) { 715 if (new_depth == 16) {
684 SDL_memset(F30_palette, 0, sizeof(F30_palette)); 716 SDL_memset (F30_palette, 0, sizeof (F30_palette));
685 VsetRGB(0,256,F30_palette); 717 VsetRGB (0, 256, F30_palette);
686 } 718 }
687 break; 719 break;
688 } 720 }
689 721
690 Vsync(); 722 Vsync ();
691 723
692 this->UpdateRects = XBIOS_UpdateRects; 724 this->UpdateRects = XBIOS_UpdateRects;
693 725
694 return (current); 726 return (current);
695 } 727 }
696 728
697 /* We don't actually allow hardware surfaces other than the main one */ 729 /* We don't actually allow hardware surfaces other than the main one */
698 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface) 730 static int
699 { 731 XBIOS_AllocHWSurface (_THIS, SDL_Surface * surface)
700 return(-1); 732 {
701 } 733 return (-1);
702 734 }
703 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface) 735
704 { 736 static void
705 return; 737 XBIOS_FreeHWSurface (_THIS, SDL_Surface * surface)
706 } 738 {
707 739 return;
708 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface) 740 }
709 { 741
710 return(0); 742 static int
711 } 743 XBIOS_LockHWSurface (_THIS, SDL_Surface * surface)
712 744 {
713 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface) 745 return (0);
714 { 746 }
715 return; 747
716 } 748 static void
717 749 XBIOS_UnlockHWSurface (_THIS, SDL_Surface * surface)
718 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) 750 {
719 { 751 return;
720 SDL_Surface *surface; 752 }
721 753
722 surface = this->screen; 754 static void
723 755 XBIOS_UpdateRects (_THIS, int numrects, SDL_Rect * rects)
724 if ((surface->format->BitsPerPixel) == 8) { 756 {
725 int i; 757 SDL_Surface *surface;
726 758
727 for (i=0;i<numrects;i++) { 759 surface = this->screen;
728 void *source,*destination; 760
729 int x1,x2; 761 if ((surface->format->BitsPerPixel) == 8) {
730 762 int i;
731 x1 = rects[i].x & ~15; 763
732 x2 = rects[i].x+rects[i].w; 764 for (i = 0; i < numrects; i++) {
733 if (x2 & 15) { 765 void *source, *destination;
734 x2 = (x2 | 15) +1; 766 int x1, x2;
735 } 767
736 768 x1 = rects[i].x & ~15;
737 source = surface->pixels; 769 x2 = rects[i].x + rects[i].w;
738 source += surface->pitch * rects[i].y; 770 if (x2 & 15) {
739 source += x1; 771 x2 = (x2 | 15) + 1;
740 772 }
741 destination = XBIOS_screens[XBIOS_fbnum]; 773
742 destination += XBIOS_pitch * rects[i].y; 774 source = surface->pixels;
743 destination += x1; 775 source += surface->pitch * rects[i].y;
744 776 source += x1;
745 /* Convert chunky to planar screen */ 777
746 SDL_Atari_C2pConvert( 778 destination = XBIOS_screens[XBIOS_fbnum];
747 source, 779 destination += XBIOS_pitch * rects[i].y;
748 destination, 780 destination += x1;
749 x2-x1, 781
750 rects[i].h, 782 /* Convert chunky to planar screen */
751 XBIOS_doubleline, 783 SDL_Atari_C2pConvert (source,
752 surface->pitch, 784 destination,
753 XBIOS_pitch 785 x2 - x1,
754 ); 786 rects[i].h,
755 } 787 XBIOS_doubleline,
756 } 788 surface->pitch, XBIOS_pitch);
757 789 }
758 #ifndef DEBUG_VIDEO_XBIOS 790 }
759 Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1); 791 #ifndef DEBUG_VIDEO_XBIOS
760 #endif 792 Setscreen (-1, XBIOS_screens[XBIOS_fbnum], -1);
761 Vsync(); 793 #endif
762 794 Vsync ();
763 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { 795
764 XBIOS_fbnum ^= 1; 796 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
765 if ((surface->format->BitsPerPixel) > 8) { 797 XBIOS_fbnum ^= 1;
766 surface->pixels=XBIOS_screens[XBIOS_fbnum]; 798 if ((surface->format->BitsPerPixel) > 8) {
767 } 799 surface->pixels = XBIOS_screens[XBIOS_fbnum];
768 } 800 }
769 } 801 }
770 802 }
771 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface) 803
772 { 804 static int
773 if ((surface->format->BitsPerPixel) == 8) { 805 XBIOS_FlipHWSurface (_THIS, SDL_Surface * surface)
774 void *destscr; 806 {
775 int destx; 807 if ((surface->format->BitsPerPixel) == 8) {
776 808 void *destscr;
777 /* Center on destination screen */ 809 int destx;
778 destscr = XBIOS_screens[XBIOS_fbnum]; 810
779 destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1); 811 /* Center on destination screen */
780 destx = (XBIOS_width - surface->w) >> 1; 812 destscr = XBIOS_screens[XBIOS_fbnum];
781 destx &= ~15; 813 destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1);
782 destscr += destx; 814 destx = (XBIOS_width - surface->w) >> 1;
783 815 destx &= ~15;
784 /* Convert chunky to planar screen */ 816 destscr += destx;
785 SDL_Atari_C2pConvert( 817
786 surface->pixels, 818 /* Convert chunky to planar screen */
787 destscr, 819 SDL_Atari_C2pConvert (surface->pixels,
788 surface->w, 820 destscr,
789 surface->h, 821 surface->w,
790 XBIOS_doubleline, 822 surface->h,
791 surface->pitch, 823 XBIOS_doubleline, surface->pitch, XBIOS_pitch);
792 XBIOS_pitch 824 }
793 ); 825 #ifndef DEBUG_VIDEO_XBIOS
794 } 826 Setscreen (-1, XBIOS_screens[XBIOS_fbnum], -1);
795 827 #endif
796 #ifndef DEBUG_VIDEO_XBIOS 828 Vsync ();
797 Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1); 829
798 #endif 830 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
799 Vsync(); 831 XBIOS_fbnum ^= 1;
800 832 if ((surface->format->BitsPerPixel) > 8) {
801 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { 833 surface->pixels = XBIOS_screens[XBIOS_fbnum];
802 XBIOS_fbnum ^= 1; 834 }
803 if ((surface->format->BitsPerPixel) > 8) { 835 }
804 surface->pixels=XBIOS_screens[XBIOS_fbnum]; 836
805 } 837 return (0);
806 } 838 }
807 839
808 return(0); 840 static int
809 } 841 XBIOS_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
810 842 {
811 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 843 int i;
812 { 844 int r, v, b;
813 int i; 845
814 int r,v,b; 846 switch (XBIOS_cvdo >> 16) {
815 847 case VDO_ST:
816 switch( XBIOS_cvdo >> 16) { 848 case VDO_STE:
817 case VDO_ST: 849 for (i = 0; i < ncolors; i++) {
818 case VDO_STE: 850 r = colors[i].r;
819 for (i=0;i<ncolors;i++) 851 v = colors[i].g;
820 { 852 b = colors[i].b;
821 r = colors[i].r; 853
822 v = colors[i].g; 854 TT_palette[firstcolor + i] =
823 b = colors[i].b; 855 ((r * 30) + (v * 59) + (b * 11)) / 100;
824 856 }
825 TT_palette[firstcolor+i]=((r*30)+(v*59)+(b*11))/100; 857 SDL_Atari_C2pConvert4_pal (TT_palette); /* convert the lighting */
826 } 858 break;
827 SDL_Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */ 859 case VDO_TT:
828 break; 860 for (i = 0; i < ncolors; i++) {
829 case VDO_TT: 861 r = colors[i].r;
830 for(i = 0; i < ncolors; i++) 862 v = colors[i].g;
831 { 863 b = colors[i].b;
832 r = colors[i].r; 864
833 v = colors[i].g; 865 TT_palette[i] = ((r >> 4) << 8) | ((v >> 4) << 4) | (b >> 4);
834 b = colors[i].b; 866 }
835 867 #ifndef DEBUG_VIDEO_XBIOS
836 TT_palette[i]=((r>>4)<<8)|((v>>4)<<4)|(b>>4); 868 EsetPalette (firstcolor, ncolors, TT_palette);
837 } 869 #endif
838 #ifndef DEBUG_VIDEO_XBIOS 870 break;
839 EsetPalette(firstcolor,ncolors,TT_palette); 871 case VDO_F30:
840 #endif 872 for (i = 0; i < ncolors; i++) {
841 break; 873 r = colors[i].r;
842 case VDO_F30: 874 v = colors[i].g;
843 for(i = 0; i < ncolors; i++) 875 b = colors[i].b;
844 { 876
845 r = colors[i].r; 877 F30_palette[i] = (r << 16) | (v << 8) | b;
846 v = colors[i].g; 878 }
847 b = colors[i].b; 879 #ifndef DEBUG_VIDEO_XBIOS
848 880 VsetRGB (firstcolor, ncolors, F30_palette);
849 F30_palette[i]=(r<<16)|(v<<8)|b; 881 #endif
850 } 882 break;
851 #ifndef DEBUG_VIDEO_XBIOS 883 }
852 VsetRGB(firstcolor,ncolors,F30_palette); 884
853 #endif 885 return (1);
854 break;
855 }
856
857 return(1);
858 } 886 }
859 887
860 /* Note: If we are terminated, this could be called in the middle of 888 /* Note: If we are terminated, this could be called in the middle of
861 another SDL video routine -- notably UpdateRects. 889 another SDL video routine -- notably UpdateRects.
862 */ 890 */
863 static void XBIOS_VideoQuit(_THIS) 891 static void
864 { 892 XBIOS_VideoQuit (_THIS)
865 int i,j; 893 {
866 894 int i, j;
867 Atari_ShutdownEvents(); 895
868 896 Atari_ShutdownEvents ();
869 /* Restore video mode and palette */ 897
870 #ifndef DEBUG_VIDEO_XBIOS 898 /* Restore video mode and palette */
871 switch(XBIOS_cvdo >> 16) { 899 #ifndef DEBUG_VIDEO_XBIOS
872 case VDO_ST: 900 switch (XBIOS_cvdo >> 16) {
873 case VDO_STE: 901 case VDO_ST:
874 Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode); 902 case VDO_STE:
875 if (XBIOS_oldnumcol) { 903 Setscreen (-1, XBIOS_oldvbase, XBIOS_oldvmode);
876 Setpalette(XBIOS_oldpalette); 904 if (XBIOS_oldnumcol) {
877 } 905 Setpalette (XBIOS_oldpalette);
878 break; 906 }
879 case VDO_TT: 907 break;
880 Setscreen(-1,XBIOS_oldvbase,-1); 908 case VDO_TT:
881 EsetShift(XBIOS_oldvmode); 909 Setscreen (-1, XBIOS_oldvbase, -1);
882 if (XBIOS_oldnumcol) { 910 EsetShift (XBIOS_oldvmode);
883 EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette); 911 if (XBIOS_oldnumcol) {
884 } 912 EsetPalette (0, XBIOS_oldnumcol, XBIOS_oldpalette);
885 break; 913 }
886 case VDO_F30: 914 break;
887 Setscreen(-1, XBIOS_oldvbase, -1); 915 case VDO_F30:
888 if (XBIOS_centscreen) { 916 Setscreen (-1, XBIOS_oldvbase, -1);
889 SDL_XBIOS_CentscreenRestore(this, XBIOS_oldvmode); 917 if (XBIOS_centscreen) {
890 } else { 918 SDL_XBIOS_CentscreenRestore (this, XBIOS_oldvmode);
891 VsetMode(XBIOS_oldvmode); 919 } else {
892 } 920 VsetMode (XBIOS_oldvmode);
893 if (XBIOS_oldnumcol) { 921 }
894 VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette); 922 if (XBIOS_oldnumcol) {
895 } 923 VsetRGB (0, XBIOS_oldnumcol, XBIOS_oldpalette);
896 break; 924 }
897 } 925 break;
898 Vsync(); 926 }
927 Vsync ();
899 #endif 928 #endif
900 929
901 930
902 #if SDL_VIDEO_OPENGL 931 #if SDL_VIDEO_OPENGL
903 if (gl_active) { 932 if (gl_active) {
904 SDL_AtariGL_Quit(this, SDL_TRUE); 933 SDL_AtariGL_Quit (this, SDL_TRUE);
905 } 934 }
906 #endif 935 #endif
907 936
908 if (XBIOS_oldpalette) { 937 if (XBIOS_oldpalette) {
909 SDL_free(XBIOS_oldpalette); 938 SDL_free (XBIOS_oldpalette);
910 XBIOS_oldpalette=NULL; 939 XBIOS_oldpalette = NULL;
911 } 940 }
912 XBIOS_FreeBuffers(this); 941 XBIOS_FreeBuffers (this);
913 942
914 /* Free mode list */ 943 /* Free mode list */
915 for (j=0;j<NUM_MODELISTS;j++) { 944 for (j = 0; j < NUM_MODELISTS; j++) {
916 for (i=0;i<SDL_NUMMODES;i++) { 945 for (i = 0; i < SDL_NUMMODES; i++) {
917 if (SDL_modelist[j][i]!=NULL) { 946 if (SDL_modelist[j][i] != NULL) {
918 SDL_free(SDL_modelist[j][i]); 947 SDL_free (SDL_modelist[j][i]);
919 SDL_modelist[j][i]=NULL; 948 SDL_modelist[j][i] = NULL;
920 } 949 }
921 } 950 }
922 } 951 }
923 952
924 if (XBIOS_modelist) { 953 if (XBIOS_modelist) {
925 SDL_free(XBIOS_modelist); 954 SDL_free (XBIOS_modelist);
926 XBIOS_nummodes=0; 955 XBIOS_nummodes = 0;
927 XBIOS_modelist=NULL; 956 XBIOS_modelist = NULL;
928 } 957 }
929 958
930 this->screen->pixels = NULL; 959 this->screen->pixels = NULL;
931 } 960 }
932 961
933 #if SDL_VIDEO_OPENGL 962 #if SDL_VIDEO_OPENGL
934 963
935 static void XBIOS_GL_SwapBuffers(_THIS) 964 static void
936 { 965 XBIOS_GL_SwapBuffers (_THIS)
937 SDL_AtariGL_SwapBuffers(this); 966 {
938 XBIOS_FlipHWSurface(this, this->screen); 967 SDL_AtariGL_SwapBuffers (this);
939 SDL_AtariGL_MakeCurrent(this); 968 XBIOS_FlipHWSurface (this, this->screen);
940 } 969 SDL_AtariGL_MakeCurrent (this);
941 970 }
942 #endif 971
972 #endif
973 /* vi: set ts=4 sw=4 expandtab: */