Mercurial > sdl-ios-xcode
comparison src/video/xbios/SDL_xbios.c @ 281:c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 17 Feb 2002 19:54:28 +0000 |
parents | |
children | e4bd0cf95506 |
comparison
equal
deleted
inserted
replaced
280:0ddcea45d829 | 281:c5010ab8ba35 |
---|---|
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@libsdl.org | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* | |
29 * Xbios SDL video driver | |
30 * | |
31 * Patrice Mandin | |
32 */ | |
33 | |
34 #include <stdio.h> | |
35 #include <stdlib.h> | |
36 #include <string.h> | |
37 #include <sys/stat.h> | |
38 #include <unistd.h> | |
39 | |
40 /* Mint includes */ | |
41 #include <sys/cookie.h> | |
42 #include <mint/osbind.h> | |
43 #include <mint/falcon.h> | |
44 | |
45 #include "SDL.h" | |
46 #include "SDL_error.h" | |
47 #include "SDL_video.h" | |
48 #include "SDL_mouse.h" | |
49 #include "SDL_sysvideo.h" | |
50 #include "SDL_pixels_c.h" | |
51 #include "SDL_events_c.h" | |
52 | |
53 #include "SDL_ataric2p_s.h" | |
54 #include "SDL_ataric2p060_c.h" | |
55 #include "SDL_atarievents_c.h" | |
56 #include "SDL_atarimxalloc_c.h" | |
57 #include "SDL_xbios.h" | |
58 | |
59 #define XBIOS_VID_DRIVER_NAME "xbios" | |
60 | |
61 /* Initialization/Query functions */ | |
62 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
63 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
64 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
65 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
66 static void XBIOS_VideoQuit(_THIS); | |
67 | |
68 /* Hardware surface functions */ | |
69 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface); | |
70 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface); | |
71 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface); | |
72 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
73 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface); | |
74 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects); | |
75 | |
76 /* List of video modes */ | |
77 | |
78 /* ST modes */ | |
79 static int xbiosnummodes_st=1; | |
80 static xbiosmode_t xbiosmodelist_st[]={ | |
81 {ST_LOW>>8,320,200,4,SDL_FALSE} | |
82 }; | |
83 | |
84 /* TT modes */ | |
85 static int xbiosnummodes_tt=2; | |
86 static xbiosmode_t xbiosmodelist_tt[]={ | |
87 {TT_LOW,320,480,8,SDL_FALSE}, | |
88 {TT_LOW,320,240,8,SDL_TRUE} /* Software double-lined mode */ | |
89 }; | |
90 | |
91 /* Falcon RVB modes */ | |
92 static int xbiosnummodes_f30rvb=16; | |
93 static xbiosmode_t xbiosmodelist_f30rvb[]={ | |
94 {BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,SDL_FALSE}, | |
95 {BPS16|COL80|OVERSCAN,768,240,16,SDL_FALSE}, | |
96 {BPS16|COL80|VERTFLAG,640,400,16,SDL_FALSE}, | |
97 {BPS16|COL80,640,200,16,SDL_FALSE}, | |
98 {BPS16|OVERSCAN|VERTFLAG,384,480,16,SDL_FALSE}, | |
99 {BPS16|OVERSCAN,384,240,16,SDL_FALSE}, | |
100 {BPS16|VERTFLAG,320,400,16,SDL_FALSE}, | |
101 {BPS16,320,200,16,SDL_FALSE}, | |
102 | |
103 {BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,SDL_FALSE}, | |
104 {BPS8|COL80|OVERSCAN,768,240,8,SDL_FALSE}, | |
105 {BPS8|COL80|VERTFLAG,640,400,8,SDL_FALSE}, | |
106 {BPS8|COL80,640,200,8,SDL_FALSE}, | |
107 {BPS8|OVERSCAN|VERTFLAG,384,480,8,SDL_FALSE}, | |
108 {BPS8|OVERSCAN,384,240,8,SDL_FALSE}, | |
109 {BPS8|VERTFLAG,320,400,8,SDL_FALSE}, | |
110 {BPS8,320,200,8,SDL_FALSE} | |
111 }; | |
112 | |
113 /* Falcon VGA modes */ | |
114 static int xbiosnummodes_f30vga=6; | |
115 static xbiosmode_t xbiosmodelist_f30vga[]={ | |
116 {BPS16,320,480,16,SDL_FALSE}, | |
117 {BPS16|VERTFLAG,320,240,16,SDL_FALSE}, | |
118 | |
119 {BPS8|COL80,640,480,8,SDL_FALSE}, | |
120 {BPS8|COL80|VERTFLAG,640,240,8,SDL_FALSE}, | |
121 {BPS8,320,480,8,SDL_FALSE}, | |
122 {BPS8|VERTFLAG,320,240,8,SDL_FALSE} | |
123 }; | |
124 | |
125 /* To setup palette */ | |
126 | |
127 static unsigned short TT_palette[256]; | |
128 static unsigned long F30_palette[256]; | |
129 | |
130 /* Xbios driver bootstrap functions */ | |
131 | |
132 static int XBIOS_Available(void) | |
133 { | |
134 const char *envr = getenv("SDL_VIDEODRIVER"); | |
135 unsigned long cookie_vdo; | |
136 | |
137 /* Check if user asked a different video driver */ | |
138 if ((envr) && (strcmp(envr, XBIOS_VID_DRIVER_NAME)!=0)) { | |
139 return 0; | |
140 } | |
141 | |
142 /* Cookie _VDO present ? if not, assume ST machine */ | |
143 if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) { | |
144 cookie_vdo = VDO_ST << 16; | |
145 } | |
146 | |
147 /* Test if we have a monochrome monitor plugged in */ | |
148 switch( cookie_vdo >>16) { | |
149 case VDO_ST: | |
150 case VDO_STE: | |
151 if ( Getrez() == (ST_HIGH>>8) ) | |
152 return 0; | |
153 break; | |
154 case VDO_TT: | |
155 if ( (EgetShift() & ES_MODE) == TT_HIGH) | |
156 return 0; | |
157 break; | |
158 case VDO_F30: | |
159 if ( Montype() == MONITOR_MONO) | |
160 return 0; | |
161 break; | |
162 default: | |
163 return 0; | |
164 } | |
165 | |
166 return 1; | |
167 } | |
168 | |
169 static void XBIOS_DeleteDevice(SDL_VideoDevice *device) | |
170 { | |
171 free(device->hidden); | |
172 free(device); | |
173 } | |
174 | |
175 static SDL_VideoDevice *XBIOS_CreateDevice(int devindex) | |
176 { | |
177 SDL_VideoDevice *device; | |
178 | |
179 /* Initialize all variables that we clean on shutdown */ | |
180 device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
181 if ( device ) { | |
182 memset(device, 0, (sizeof *device)); | |
183 device->hidden = (struct SDL_PrivateVideoData *) | |
184 malloc((sizeof *device->hidden)); | |
185 } | |
186 if ( (device == NULL) || (device->hidden == NULL) ) { | |
187 SDL_OutOfMemory(); | |
188 if ( device ) { | |
189 free(device); | |
190 } | |
191 return(0); | |
192 } | |
193 memset(device->hidden, 0, (sizeof *device->hidden)); | |
194 | |
195 atari_test_cpu060_present(); | |
196 | |
197 /* Video functions */ | |
198 device->VideoInit = XBIOS_VideoInit; | |
199 device->ListModes = XBIOS_ListModes; | |
200 device->SetVideoMode = XBIOS_SetVideoMode; | |
201 device->SetColors = XBIOS_SetColors; | |
202 device->UpdateRects = NULL; | |
203 device->VideoQuit = XBIOS_VideoQuit; | |
204 device->AllocHWSurface = XBIOS_AllocHWSurface; | |
205 device->LockHWSurface = XBIOS_LockHWSurface; | |
206 device->UnlockHWSurface = XBIOS_UnlockHWSurface; | |
207 device->FlipHWSurface = XBIOS_FlipHWSurface; | |
208 device->FreeHWSurface = XBIOS_FreeHWSurface; | |
209 | |
210 /* Events */ | |
211 device->InitOSKeymap = Atari_InitOSKeymap; | |
212 device->PumpEvents = Atari_PumpEvents; | |
213 | |
214 device->free = XBIOS_DeleteDevice; | |
215 | |
216 return device; | |
217 } | |
218 | |
219 VideoBootStrap XBIOS_bootstrap = { | |
220 XBIOS_VID_DRIVER_NAME, "Atari Xbios driver", | |
221 XBIOS_Available, XBIOS_CreateDevice | |
222 }; | |
223 | |
224 static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
225 { | |
226 int i,j8,j16; | |
227 xbiosmode_t *current_mode; | |
228 | |
229 /* Initialize all variables that we clean on shutdown */ | |
230 memset (SDL_modelist, 0, sizeof(SDL_modelist)); | |
231 | |
232 /* Cookie _VDO present ? if not, assume ST machine */ | |
233 if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) { | |
234 XBIOS_cvdo = VDO_ST << 16; | |
235 } | |
236 | |
237 /* Allocate memory for old palette */ | |
238 XBIOS_oldpalette = (void *)malloc(256*sizeof(long)); | |
239 if ( !XBIOS_oldpalette ) { | |
240 SDL_SetError("Unable to allocate memory for old palette\n"); | |
241 return(-1); | |
242 } | |
243 | |
244 /* Initialize video mode list */ | |
245 /* and save current screen status (palette, screen address, video mode) */ | |
246 | |
247 switch (XBIOS_cvdo >>16) { | |
248 case VDO_ST: | |
249 case VDO_STE: | |
250 { | |
251 short *oldpalette; | |
252 | |
253 XBIOS_nummodes=xbiosnummodes_st; | |
254 XBIOS_modelist=xbiosmodelist_st; | |
255 | |
256 XBIOS_oldvbase=Physbase(); | |
257 XBIOS_oldvmode=Getrez(); | |
258 switch(XBIOS_oldvmode << 8) { | |
259 case ST_LOW: | |
260 XBIOS_oldnumcol=16; | |
261 break; | |
262 case ST_MED: | |
263 XBIOS_oldnumcol=4; | |
264 break; | |
265 case ST_HIGH: | |
266 XBIOS_oldnumcol=2; | |
267 break; | |
268 default: | |
269 XBIOS_oldnumcol=0; | |
270 break; | |
271 } | |
272 | |
273 oldpalette= (short *) XBIOS_oldpalette; | |
274 for (i=0;i<XBIOS_oldnumcol;i++) { | |
275 *oldpalette++=Setcolor(i,-1); | |
276 } | |
277 | |
278 vformat->BitsPerPixel = 8; | |
279 } | |
280 break; | |
281 case VDO_TT: | |
282 XBIOS_nummodes=xbiosnummodes_tt; | |
283 XBIOS_modelist=xbiosmodelist_tt; | |
284 | |
285 XBIOS_oldvbase=Logbase(); | |
286 XBIOS_oldvmode=EgetShift(); | |
287 | |
288 switch(XBIOS_oldvmode & ES_MODE) { | |
289 case TT_LOW: | |
290 XBIOS_oldnumcol=256; | |
291 break; | |
292 case ST_LOW: | |
293 case TT_MED: | |
294 XBIOS_oldnumcol=16; | |
295 break; | |
296 case ST_MED: | |
297 XBIOS_oldnumcol=4; | |
298 break; | |
299 case ST_HIGH: | |
300 case TT_HIGH: | |
301 XBIOS_oldnumcol=2; | |
302 break; | |
303 default: | |
304 XBIOS_oldnumcol=0; | |
305 break; | |
306 } | |
307 if (XBIOS_oldnumcol) { | |
308 EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
309 } | |
310 | |
311 vformat->BitsPerPixel = 8; | |
312 break; | |
313 case VDO_F30: | |
314 switch (Montype()) | |
315 { | |
316 case MONITOR_MONO: | |
317 /* Not usable */ | |
318 break; | |
319 case MONITOR_RGB: | |
320 case MONITOR_TV: | |
321 XBIOS_nummodes = xbiosnummodes_f30rvb; | |
322 XBIOS_modelist = xbiosmodelist_f30rvb; | |
323 break; | |
324 case MONITOR_VGA: | |
325 XBIOS_nummodes = xbiosnummodes_f30vga; | |
326 XBIOS_modelist = xbiosmodelist_f30vga; | |
327 break; | |
328 } | |
329 XBIOS_oldvbase=Logbase(); | |
330 XBIOS_oldvmode=Vsetmode(-1); | |
331 | |
332 XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS)); | |
333 if (XBIOS_oldnumcol > 256) { | |
334 XBIOS_oldnumcol = 0; | |
335 } | |
336 if (XBIOS_oldnumcol) { | |
337 VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
338 } | |
339 | |
340 vformat->BitsPerPixel = 16; | |
341 | |
342 /* Keep vga/rvb, and pal/ntsc bits */ | |
343 current_mode = XBIOS_modelist; | |
344 for (i=0;i<XBIOS_nummodes;i++) { | |
345 Uint16 newvmode; | |
346 | |
347 newvmode = current_mode->number; | |
348 newvmode &= ~(VGA|PAL); | |
349 newvmode |= XBIOS_oldvmode & (VGA|PAL); | |
350 current_mode->number = newvmode; | |
351 | |
352 current_mode++; | |
353 } | |
354 | |
355 break; | |
356 } | |
357 | |
358 current_mode = XBIOS_modelist; | |
359 j8 = j16 = 0; | |
360 for (i=0;i<XBIOS_nummodes;i++) { | |
361 switch (current_mode->depth) { | |
362 case 4: | |
363 case 8: | |
364 SDL_modelist[0][j8] = malloc(sizeof(SDL_Rect)); | |
365 SDL_modelist[0][j8]->x = SDL_modelist[0][j8]->y = 0; | |
366 SDL_modelist[0][j8]->w = current_mode->width; | |
367 SDL_modelist[0][j8]->h = current_mode->height; | |
368 XBIOS_videomodes[0][j8]=current_mode; | |
369 current_mode++; | |
370 j8++; | |
371 break; | |
372 case 16: | |
373 SDL_modelist[1][j16] = malloc(sizeof(SDL_Rect)); | |
374 SDL_modelist[1][j16]->x = SDL_modelist[1][j16]->y = 0; | |
375 SDL_modelist[1][j16]->w = current_mode->width; | |
376 SDL_modelist[1][j16]->h = current_mode->height; | |
377 XBIOS_videomodes[1][j16]=current_mode; | |
378 current_mode++; | |
379 j16++; | |
380 break; | |
381 } | |
382 } | |
383 SDL_modelist[0][j8] = NULL; | |
384 SDL_modelist[1][j16] = NULL; | |
385 | |
386 XBIOS_screens[0]=NULL; | |
387 XBIOS_screens[1]=NULL; | |
388 XBIOS_shadowscreen=NULL; | |
389 | |
390 /* Update hardware info */ | |
391 this->info.hw_available = 1; | |
392 this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM); | |
393 | |
394 /* Init chunky to planar routine */ | |
395 Atari_C2pInit = Atari_C2pInit8; | |
396 if (atari_cpu060_avail) { | |
397 Atari_C2pConvert = Atari_C2pConvert8_060; | |
398 } else { | |
399 Atari_C2pConvert = Atari_C2pConvert8; | |
400 } | |
401 Atari_C2pInit(); | |
402 | |
403 /* We're done! */ | |
404 return(0); | |
405 } | |
406 | |
407 static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
408 { | |
409 /* 8 bits -> list 0 */ | |
410 /* 16 bits -> list 1 */ | |
411 return(SDL_modelist[(format->BitsPerPixel)>>4]); | |
412 } | |
413 | |
414 static void XBIOS_FreeBuffers(_THIS) | |
415 { | |
416 int i; | |
417 | |
418 for (i=0;i<2;i++) { | |
419 if (XBIOS_screensmem[i]!=NULL) { | |
420 Mfree(XBIOS_screensmem[i]); | |
421 XBIOS_screensmem[i]=NULL; | |
422 } | |
423 } | |
424 | |
425 if (XBIOS_shadowscreen!=NULL) { | |
426 Mfree(XBIOS_shadowscreen); | |
427 XBIOS_shadowscreen=NULL; | |
428 } | |
429 } | |
430 | |
431 static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, | |
432 int width, int height, int bpp, Uint32 flags) | |
433 { | |
434 int mode, new_depth; | |
435 int i; | |
436 xbiosmode_t *new_video_mode; | |
437 Uint32 new_screen_size; | |
438 Uint32 modeflags; | |
439 | |
440 /* Free current buffers */ | |
441 XBIOS_FreeBuffers(this); | |
442 | |
443 /* Search if the mode exists (width, height, bpp) */ | |
444 bpp >>= 4; | |
445 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { | |
446 if ( (SDL_modelist[bpp][mode]->w == width) && | |
447 (SDL_modelist[bpp][mode]->h == height) ) { | |
448 | |
449 break; | |
450 } | |
451 } | |
452 if ( SDL_modelist[bpp][mode] == NULL ) { | |
453 SDL_SetError("Couldn't find requested mode in list"); | |
454 return(NULL); | |
455 } | |
456 | |
457 modeflags = (SDL_FULLSCREEN|SDL_HWPALETTE); | |
458 | |
459 /* Allocate needed buffers: simple/double buffer and shadow surface */ | |
460 new_video_mode = XBIOS_videomodes[bpp][mode]; | |
461 new_depth = new_video_mode->depth; | |
462 if (new_depth == 4) { | |
463 Atari_C2pInit = Atari_C2pInit4; | |
464 if (atari_cpu060_avail) { | |
465 Atari_C2pConvert = Atari_C2pConvert4_060; | |
466 } else { | |
467 Atari_C2pConvert = Atari_C2pConvert4; | |
468 } | |
469 new_depth=8; | |
470 modeflags |= SDL_SWSURFACE; | |
471 } else if (new_depth == 8) { | |
472 Atari_C2pInit = Atari_C2pInit8; | |
473 if (atari_cpu060_avail) { | |
474 Atari_C2pConvert = Atari_C2pConvert8_060; | |
475 } else { | |
476 Atari_C2pConvert = Atari_C2pConvert8; | |
477 } | |
478 modeflags |= SDL_SWSURFACE; | |
479 } else { | |
480 modeflags |= SDL_HWSURFACE; | |
481 } | |
482 | |
483 new_screen_size = width * height * ((new_depth)>>3); | |
484 new_screen_size += 256; /* To align on a 256 byte adress */ | |
485 | |
486 if (new_depth == 8) { | |
487 XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM); | |
488 | |
489 if (XBIOS_shadowscreen == NULL) { | |
490 SDL_SetError("XBIOS_SetVideoMode: Not enough memory for shadow surface"); | |
491 return (NULL); | |
492 } | |
493 } | |
494 | |
495 /* Output buffer needs to be twice in size for the software double-line mode */ | |
496 XBIOS_doubleline = SDL_FALSE; | |
497 if (new_video_mode->doubleline) { | |
498 new_screen_size <<= 1; | |
499 XBIOS_doubleline = SDL_TRUE; | |
500 } | |
501 | |
502 XBIOS_screensmem[0] = Atari_SysMalloc(new_screen_size, MX_STRAM); | |
503 | |
504 if (XBIOS_screensmem[0]==NULL) { | |
505 XBIOS_FreeBuffers(this); | |
506 SDL_SetError("XBIOS_SetVideoMode: Not enough memory for video buffer"); | |
507 return (NULL); | |
508 } | |
509 | |
510 XBIOS_screens[0]=(void *) (( (long) XBIOS_screensmem[0]+256) & 0xFFFFFF00UL); | |
511 | |
512 /* Double buffer ? */ | |
513 if (flags & SDL_DOUBLEBUF) { | |
514 XBIOS_screensmem[1] = Atari_SysMalloc(new_screen_size, MX_STRAM); | |
515 | |
516 if (XBIOS_screensmem[1]==NULL) { | |
517 XBIOS_FreeBuffers(this); | |
518 SDL_SetError("XBIOS_SetVideoMode: Not enough memory for double buffer"); | |
519 return (NULL); | |
520 } | |
521 | |
522 XBIOS_screens[1]=(void *) (( (long) XBIOS_screensmem[1]+256) & 0xFFFFFF00UL); | |
523 modeflags |= SDL_DOUBLEBUF; | |
524 } | |
525 | |
526 /* Allocate the new pixel format for the screen */ | |
527 if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) { | |
528 XBIOS_FreeBuffers(this); | |
529 SDL_SetError("Couldn't allocate new pixel format for requested mode"); | |
530 return(NULL); | |
531 } | |
532 | |
533 current->flags = modeflags; | |
534 current->w = XBIOS_width = width; | |
535 current->h = XBIOS_height = height; | |
536 current->pitch = (width * new_depth)>>3; | |
537 | |
538 /* this is for C2P conversion */ | |
539 XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3; | |
540 | |
541 if (new_depth == 8) | |
542 current->pixels = XBIOS_shadowscreen; | |
543 else | |
544 current->pixels = XBIOS_screens[0]; | |
545 | |
546 XBIOS_fbnum = 0; | |
547 | |
548 /* Now set the video mode */ | |
549 Setscreen(-1,XBIOS_screens[0],-1); | |
550 | |
551 switch(XBIOS_cvdo >> 16) { | |
552 case VDO_ST: | |
553 Setscreen(-1,-1,new_video_mode->number); | |
554 /* Reset palette */ | |
555 for (i=0;i<16;i++) { | |
556 int c; | |
557 | |
558 c = ((i>>1)<<8) | ((i>>1)<<4) | (i>>1); | |
559 if ((i & 1) && (i<15)) | |
560 c += (1<<4); | |
561 if (i==14) | |
562 c -= 1<<8; | |
563 | |
564 TT_palette[i]= c; | |
565 } | |
566 Setpalette(TT_palette); | |
567 break; | |
568 case VDO_STE: | |
569 Setscreen(-1,-1,new_video_mode->number); | |
570 /* Reset palette */ | |
571 for (i=0;i<16;i++) | |
572 { | |
573 int c; | |
574 | |
575 c=((i&1)<<3)|((i>>1)&7); | |
576 TT_palette[i]=(c<<8)|(c<<4)|c; | |
577 } | |
578 Setpalette(TT_palette); | |
579 break; | |
580 case VDO_TT: | |
581 EsetShift(new_video_mode->number); | |
582 break; | |
583 case VDO_F30: | |
584 Vsetmode(new_video_mode->number); | |
585 break; | |
586 } | |
587 | |
588 Vsync(); | |
589 | |
590 this->UpdateRects = XBIOS_UpdateRects; | |
591 | |
592 return (current); | |
593 } | |
594 | |
595 /* We don't actually allow hardware surfaces other than the main one */ | |
596 static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface) | |
597 { | |
598 return(-1); | |
599 } | |
600 | |
601 static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface) | |
602 { | |
603 return; | |
604 } | |
605 | |
606 static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface) | |
607 { | |
608 return(0); | |
609 } | |
610 | |
611 static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
612 { | |
613 return; | |
614 } | |
615 | |
616 static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | |
617 { | |
618 SDL_Surface *surface; | |
619 | |
620 surface = this->screen; | |
621 | |
622 XBIOS_FlipHWSurface(this, surface); | |
623 } | |
624 | |
625 static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface) | |
626 { | |
627 if ((surface->format->BitsPerPixel) == 8) { | |
628 void *destscr; | |
629 int destx; | |
630 | |
631 /* Center on destination screen */ | |
632 destscr = XBIOS_screens[XBIOS_fbnum]; | |
633 destscr += XBIOS_pitch * ((XBIOS_height - surface->h) >> 1); | |
634 destx = (XBIOS_width - surface->w) >> 1; | |
635 destx &= ~15; | |
636 destscr += destx; | |
637 | |
638 /* Convert chunky to planar screen */ | |
639 Atari_C2pConvert( | |
640 surface->pixels, | |
641 destscr, | |
642 surface->w, | |
643 surface->h, | |
644 XBIOS_doubleline, | |
645 surface->pitch, | |
646 XBIOS_pitch | |
647 ); | |
648 } | |
649 | |
650 Setscreen(-1,XBIOS_screens[XBIOS_fbnum],-1); | |
651 Vsync(); | |
652 | |
653 if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { | |
654 XBIOS_fbnum ^= 1; | |
655 } | |
656 | |
657 return(0); | |
658 } | |
659 | |
660 static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
661 { | |
662 int i; | |
663 int r,v,b; | |
664 | |
665 switch( XBIOS_cvdo >> 16) { | |
666 case VDO_ST: | |
667 case VDO_STE: | |
668 for (i=0;i<ncolors;i++) | |
669 { | |
670 r = colors[i].r; | |
671 v = colors[i].g; | |
672 b = colors[i].b; | |
673 | |
674 TT_palette[firstcolor+i]=((r*30)+(v*59)+(b*11))/100; | |
675 } | |
676 Atari_C2pConvert4_pal(TT_palette); /* convert the lighting */ | |
677 break; | |
678 case VDO_TT: | |
679 for(i = 0; i < ncolors; i++) | |
680 { | |
681 r = colors[i].r; | |
682 v = colors[i].g; | |
683 b = colors[i].b; | |
684 | |
685 TT_palette[i]=((r>>4)<<8)|((v>>4)<<4)|(b>>4); | |
686 } | |
687 EsetPalette(firstcolor,ncolors,TT_palette); | |
688 break; | |
689 case VDO_F30: | |
690 for(i = 0; i < ncolors; i++) | |
691 { | |
692 r = colors[i].r; | |
693 v = colors[i].g; | |
694 b = colors[i].b; | |
695 | |
696 F30_palette[i]=(r<<16)|(v<<8)|b; | |
697 } | |
698 VsetRGB(firstcolor,ncolors,F30_palette); | |
699 break; | |
700 } | |
701 | |
702 return(1); | |
703 } | |
704 | |
705 /* Note: If we are terminated, this could be called in the middle of | |
706 another SDL video routine -- notably UpdateRects. | |
707 */ | |
708 static void XBIOS_VideoQuit(_THIS) | |
709 { | |
710 int i,j; | |
711 | |
712 Atari_ShutdownEvents(); | |
713 | |
714 /* Restore video mode and palette */ | |
715 switch(XBIOS_cvdo >> 16) { | |
716 case VDO_ST: | |
717 case VDO_STE: | |
718 Setscreen(-1,XBIOS_oldvbase,XBIOS_oldvmode); | |
719 if (XBIOS_oldnumcol) { | |
720 Setpalette(XBIOS_oldpalette); | |
721 } | |
722 break; | |
723 case VDO_TT: | |
724 Setscreen(-1,XBIOS_oldvbase,-1); | |
725 EsetShift(XBIOS_oldvmode); | |
726 if (XBIOS_oldnumcol) { | |
727 EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
728 } | |
729 break; | |
730 case VDO_F30: | |
731 Setscreen(-1, XBIOS_oldvbase, -1); | |
732 Vsetmode(XBIOS_oldvmode); | |
733 if (XBIOS_oldnumcol) { | |
734 VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette); | |
735 } | |
736 break; | |
737 } | |
738 Vsync(); | |
739 | |
740 if (XBIOS_oldpalette) { | |
741 free(XBIOS_oldpalette); | |
742 XBIOS_oldpalette=NULL; | |
743 } | |
744 XBIOS_FreeBuffers(this); | |
745 | |
746 /* Free mode list */ | |
747 for (j=0;j<NUM_MODELISTS;j++) { | |
748 for (i=0;i<SDL_NUMMODES;i++) { | |
749 if (SDL_modelist[j][i]!=NULL) { | |
750 free(SDL_modelist[j][i]); | |
751 SDL_modelist[j][i]=NULL; | |
752 } | |
753 } | |
754 } | |
755 | |
756 this->screen->pixels = NULL; | |
757 } |