/
SDL_xbios.c
991 lines (848 loc) · 23.5 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2012 Sam Lantinga
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
11
12
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19
20
21
Sam Lantinga
slouken@libsdl.org
*/
22
#include "SDL_config.h"
23
24
25
26
27
28
29
30
31
32
33
/*
* Xbios SDL video driver
*
* Patrice Mandin
*/
#include <sys/stat.h>
#include <unistd.h>
/* Mint includes */
34
#include <mint/cookie.h>
35
36
37
38
39
#include <mint/osbind.h>
#include <mint/falcon.h>
#include "SDL_video.h"
#include "SDL_mouse.h"
40
41
42
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
43
44
45
46
47
#include "../ataricommon/SDL_ataric2p_s.h"
#include "../ataricommon/SDL_atarievents_c.h"
#include "../ataricommon/SDL_atarimxalloc_c.h"
#include "../ataricommon/SDL_atarigl_c.h"
48
#include "SDL_xbios.h"
49
#include "SDL_xbios_blowup.h"
50
#include "SDL_xbios_centscreen.h"
51
#include "SDL_xbios_sb3.h"
52
#include "SDL_xbios_tveille.h"
53
#include "SDL_xbios_milan.h"
54
55
56
#define XBIOS_VID_DRIVER_NAME "xbios"
57
58
59
60
#ifndef C_fVDI
#define C_fVDI 0x66564449L
#endif
61
/* Debug print info */
62
#if 0
63
64
65
66
#define DEBUG_PRINT(what) \
{ \
printf what; \
}
67
#define DEBUG_VIDEO_XBIOS 1
68
69
70
71
#else
#define DEBUG_PRINT(what)
#undef DEBUG_VIDEO_XBIOS
#endif
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Initialization/Query functions */
static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat);
static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static void XBIOS_VideoQuit(_THIS);
/* Hardware surface functions */
static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface);
static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface);
static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface);
static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface);
static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface);
static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
88
#if SDL_VIDEO_OPENGL
89
90
91
92
/* OpenGL functions */
static void XBIOS_GL_SwapBuffers(_THIS);
#endif
93
94
95
/* Default list of video modes */
static const xbiosmode_t ttmodes[2]={
96
97
{TT_LOW,320,480,8, XBIOSMODE_C2P},
{TT_LOW,320,240,8, XBIOSMODE_C2P|XBIOSMODE_DOUBLELINE}
98
99
100
};
static const xbiosmode_t falconrgbmodes[16]={
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
{BPS16|COL80|OVERSCAN|VERTFLAG,768,480,16,0},
{BPS16|COL80|OVERSCAN,768,240,16,0},
{BPS16|COL80|VERTFLAG,640,400,16,0},
{BPS16|COL80,640,200,16,0},
{BPS16|OVERSCAN|VERTFLAG,384,480,16,0},
{BPS16|OVERSCAN,384,240,16,0},
{BPS16|VERTFLAG,320,400,16,0},
{BPS16,320,200,16,0},
{BPS8|COL80|OVERSCAN|VERTFLAG,768,480,8,XBIOSMODE_C2P},
{BPS8|COL80|OVERSCAN,768,240,8,XBIOSMODE_C2P},
{BPS8|COL80|VERTFLAG,640,400,8,XBIOSMODE_C2P},
{BPS8|COL80,640,200,8,XBIOSMODE_C2P},
{BPS8|OVERSCAN|VERTFLAG,384,480,8,XBIOSMODE_C2P},
{BPS8|OVERSCAN,384,240,8,XBIOSMODE_C2P},
{BPS8|VERTFLAG,320,400,8,XBIOSMODE_C2P},
{BPS8,320,200,8,XBIOSMODE_C2P}
117
118
119
};
static const xbiosmode_t falconvgamodes[6]={
120
121
122
123
124
125
{BPS16,320,480,16,0},
{BPS16|VERTFLAG,320,240,16,0},
{BPS8|COL80,640,480,8,XBIOSMODE_C2P},
{BPS8|COL80|VERTFLAG,640,240,8,XBIOSMODE_C2P},
{BPS8,320,480,8,XBIOSMODE_C2P},
{BPS8|VERTFLAG,320,240,8,XBIOSMODE_C2P}
126
127
};
128
129
130
131
/* Xbios driver bootstrap functions */
static int XBIOS_Available(void)
{
132
133
long cookie_vdo, /*cookie_mil,*/ cookie_hade, cookie_scpn;
long cookie_fvdi;
134
const char *envr = SDL_getenv("SDL_VIDEODRIVER");
135
136
/* Milan/Hades Atari clones do not have an Atari video chip */
137
if ( /*(Getcookie(C__MIL, &cookie_mil) == C_FOUND) ||*/
138
139
140
(Getcookie(C_hade, &cookie_hade) == C_FOUND) ) {
return 0;
}
141
142
143
144
145
146
147
148
149
150
151
152
/* fVDI means graphic card, so no Xbios with it */
if (Getcookie(C_fVDI, &cookie_fvdi) == C_FOUND) {
if (!envr) {
return 0;
}
if (SDL_strcmp(envr, XBIOS_VID_DRIVER_NAME)!=0) {
return 0;
}
/* Except if we force Xbios usage, through env var */
}
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* Cookie _VDO present ? if not, assume ST machine */
if (Getcookie(C__VDO, &cookie_vdo) != C_FOUND) {
cookie_vdo = VDO_ST << 16;
}
/* Test if we have a monochrome monitor plugged in */
switch( cookie_vdo >>16) {
case VDO_ST:
case VDO_STE:
if ( Getrez() == (ST_HIGH>>8) )
return 0;
break;
case VDO_TT:
if ( (EgetShift() & ES_MODE) == TT_HIGH)
return 0;
break;
case VDO_F30:
170
if ( VgetMonitor() == MONITOR_MONO)
171
return 0;
172
173
174
175
176
if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *)cookie_scpn)) {
return 0;
}
}
177
break;
178
179
case VDO_MILAN:
break;
180
181
182
183
184
185
186
187
188
default:
return 0;
}
return 1;
}
static void XBIOS_DeleteDevice(SDL_VideoDevice *device)
{
189
190
SDL_free(device->hidden);
SDL_free(device);
191
192
193
194
195
}
static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
196
long cookie_cvdo;
197
198
/* Initialize all variables that we clean on shutdown */
199
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
200
if ( device ) {
201
SDL_memset(device, 0, (sizeof *device));
202
device->hidden = (struct SDL_PrivateVideoData *)
203
SDL_malloc((sizeof *device->hidden));
204
device->gl_data = (struct SDL_PrivateGLData *)
205
SDL_malloc((sizeof *device->gl_data));
206
207
208
209
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
210
SDL_free(device);
211
212
213
}
return(0);
}
214
215
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
216
217
218
219
220
221
222
223
224
225
226
227
228
229
/* Video functions */
device->VideoInit = XBIOS_VideoInit;
device->ListModes = XBIOS_ListModes;
device->SetVideoMode = XBIOS_SetVideoMode;
device->SetColors = XBIOS_SetColors;
device->UpdateRects = NULL;
device->VideoQuit = XBIOS_VideoQuit;
device->AllocHWSurface = XBIOS_AllocHWSurface;
device->LockHWSurface = XBIOS_LockHWSurface;
device->UnlockHWSurface = XBIOS_UnlockHWSurface;
device->FlipHWSurface = XBIOS_FlipHWSurface;
device->FreeHWSurface = XBIOS_FreeHWSurface;
230
#if SDL_VIDEO_OPENGL
231
/* OpenGL functions */
232
233
234
235
device->GL_LoadLibrary = SDL_AtariGL_LoadLibrary;
device->GL_GetProcAddress = SDL_AtariGL_GetProcAddress;
device->GL_GetAttribute = SDL_AtariGL_GetAttribute;
device->GL_MakeCurrent = SDL_AtariGL_MakeCurrent;
236
237
238
device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
#endif
239
240
241
242
243
244
/* Events */
device->InitOSKeymap = Atari_InitOSKeymap;
device->PumpEvents = Atari_PumpEvents;
device->free = XBIOS_DeleteDevice;
245
246
247
248
/* Setup device specific functions, default to ST for everything */
if (Getcookie(C__VDO, &cookie_cvdo) != C_FOUND) {
cookie_cvdo = VDO_ST << 16;
}
249
SDL_XBIOS_VideoInit_ST(device, cookie_cvdo);
250
251
switch (cookie_cvdo>>16) {
252
253
254
255
case VDO_ST:
case VDO_STE:
/* Already done as default */
break;
256
257
258
259
260
case VDO_MILAN:
SDL_XBIOS_VideoInit_Milan(device);
break;
}
261
262
263
264
265
266
267
268
return device;
}
VideoBootStrap XBIOS_bootstrap = {
XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
XBIOS_Available, XBIOS_CreateDevice
};
269
void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo)
270
{
271
272
273
274
275
276
277
278
279
280
281
282
283
284
int i = 0;
switch(modeinfo->depth) {
case 15:
case 16:
i = 1;
break;
case 24:
i = 2;
break;
case 32:
i = 3;
break;
}
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
if ( actually_add ) {
SDL_Rect saved_rect[2];
xbiosmode_t saved_mode[2];
int b, j;
/* Add the mode, sorted largest to smallest */
b = 0;
j = 0;
while ( (SDL_modelist[i][j]->w > modeinfo->width) ||
(SDL_modelist[i][j]->h > modeinfo->height) ) {
++j;
}
/* Skip modes that are already in our list */
if ( (SDL_modelist[i][j]->w == modeinfo->width) &&
(SDL_modelist[i][j]->h == modeinfo->height) ) {
301
302
return;
}
303
304
305
306
307
308
309
310
311
312
/* Insert the new mode */
saved_rect[b] = *SDL_modelist[i][j];
SDL_memcpy(&saved_mode[b], SDL_xbiosmode[i][j], sizeof(xbiosmode_t));
SDL_modelist[i][j]->w = modeinfo->width;
SDL_modelist[i][j]->h = modeinfo->height;
SDL_memcpy(SDL_xbiosmode[i][j], modeinfo, sizeof(xbiosmode_t));
/* Everybody scoot down! */
if ( saved_rect[b].w && saved_rect[b].h ) {
for ( ++j; SDL_modelist[i][j]->w; ++j ) {
saved_rect[!b] = *SDL_modelist[i][j];
313
SDL_memcpy(&saved_mode[!b], SDL_xbiosmode[i][j], sizeof(xbiosmode_t));
314
315
316
317
318
319
320
321
322
*SDL_modelist[i][j] = saved_rect[b];
SDL_memcpy(SDL_xbiosmode[i][j], &saved_mode[b], sizeof(xbiosmode_t));
b = !b;
}
*SDL_modelist[i][j] = saved_rect[b];
SDL_memcpy(SDL_xbiosmode[i][j], &saved_mode[b], sizeof(xbiosmode_t));
}
} else {
++SDL_nummodes[i];
323
}
324
}
325
326
327
328
static void XBIOS_ListTTModes(_THIS, int actually_add)
{
int i;
329
330
331
for (i=0; i<2; i++) {
SDL_XBIOS_AddMode(this, actually_add, &ttmodes[i]);
332
}
333
334
335
336
337
338
339
340
341
342
343
344
}
static void XBIOS_ListFalconRgbModes(_THIS, int actually_add)
{
int i;
for (i=0; i<16; i++) {
xbiosmode_t modeinfo;
SDL_memcpy(&modeinfo, &falconrgbmodes[i], sizeof(xbiosmode_t));
modeinfo.number &= ~(VGA|PAL);
modeinfo.number |= XBIOS_oldvmode & (VGA|PAL);
345
346
SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
347
}
348
349
350
351
352
}
static void XBIOS_ListFalconVgaModes(_THIS, int actually_add)
{
int i;
353
354
355
356
357
358
359
360
361
362
for (i=0; i<6; i++) {
xbiosmode_t modeinfo;
SDL_memcpy(&modeinfo, &falconvgamodes[i], sizeof(xbiosmode_t));
modeinfo.number &= ~(VGA|PAL);
modeinfo.number |= XBIOS_oldvmode & (VGA|PAL);
SDL_XBIOS_AddMode(this, actually_add, &modeinfo);
}
363
364
}
365
366
static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
367
int i;
368
long cookie_blow, cookie_scpn, cookie_cnts;
369
370
/* Initialize all variables that we clean on shutdown */
371
372
373
374
375
for ( i=0; i<NUM_MODELISTS; ++i ) {
SDL_nummodes[i] = 0;
SDL_modelist[i] = NULL;
SDL_xbiosmode[i] = NULL;
}
376
377
378
379
380
381
382
/* Cookie _VDO present ? if not, assume ST machine */
if (Getcookie(C__VDO, &XBIOS_cvdo) != C_FOUND) {
XBIOS_cvdo = VDO_ST << 16;
}
/* Allocate memory for old palette */
383
XBIOS_oldpalette = (void *)SDL_malloc(256*sizeof(long));
384
385
386
387
388
389
390
if ( !XBIOS_oldpalette ) {
SDL_SetError("Unable to allocate memory for old palette\n");
return(-1);
}
/* Initialize video mode list */
/* and save current screen status (palette, screen address, video mode) */
391
XBIOS_centscreen = SDL_FALSE;
392
XBIOS_oldvbase = Physbase();
393
394
395
396
397
398
399
400
401
/* Determine the current screen size */
this->info.current_w = 0;
this->info.current_h = 0;
/* Determine the screen depth (use default 8-bit depth) */
vformat->BitsPerPixel = 8;
/* First allocate room for needed video modes */
402
403
404
switch (XBIOS_cvdo >>16) {
case VDO_ST:
case VDO_STE:
405
406
(*XBIOS_saveMode)(this, vformat);
(*XBIOS_listModes)(this, 0);
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
break;
case VDO_TT:
XBIOS_oldvmode=EgetShift();
switch(XBIOS_oldvmode & ES_MODE) {
case TT_LOW:
XBIOS_oldnumcol=256;
break;
case ST_LOW:
case TT_MED:
XBIOS_oldnumcol=16;
break;
case ST_MED:
XBIOS_oldnumcol=4;
break;
case ST_HIGH:
case TT_HIGH:
XBIOS_oldnumcol=2;
break;
}
if (XBIOS_oldnumcol) {
EgetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
431
XBIOS_ListTTModes(this, 0);
432
433
break;
case VDO_F30:
434
XBIOS_oldvmode=VsetMode(-1);
435
436
437
438
439
440
441
442
443
444
445
XBIOS_oldnumcol= 1<< (1 << (XBIOS_oldvmode & NUMCOLS));
if (XBIOS_oldnumcol > 256) {
XBIOS_oldnumcol = 0;
}
if (XBIOS_oldnumcol) {
VgetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
vformat->BitsPerPixel = 16;
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/* ScreenBlaster 3 ? */
if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
SDL_XBIOS_ListSB3Modes(this, 0, (scpn_cookie_t *)cookie_scpn);
} else
/* Centscreen ? */
if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) {
XBIOS_oldvmode = SDL_XBIOS_ListCentscreenModes(this, 0);
XBIOS_centscreen = SDL_TRUE;
} else
/* Standard, with or without Blowup */
{
switch (VgetMonitor())
{
case MONITOR_RGB:
case MONITOR_TV:
XBIOS_ListFalconRgbModes(this, 0);
break;
case MONITOR_VGA:
XBIOS_ListFalconVgaModes(this, 0);
break;
}
if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) {
SDL_XBIOS_ListBlowupModes(this, 0, (blow_cookie_t *)cookie_blow);
}
471
}
472
break;
473
case VDO_MILAN:
474
475
(*XBIOS_saveMode)(this, vformat);
(*XBIOS_listModes)(this, 0);
476
break;
477
}
478
479
480
481
for ( i=0; i<NUM_MODELISTS; ++i ) {
int j;
482
SDL_xbiosmode[i] = (xbiosmode_t **)
483
SDL_malloc((SDL_nummodes[i]+1)*sizeof(xbiosmode_t *));
484
485
486
487
if ( SDL_xbiosmode[i] == NULL ) {
SDL_OutOfMemory();
return(-1);
}
488
489
490
491
492
493
494
495
for ( j=0; j<SDL_nummodes[i]; ++j ) {
SDL_xbiosmode[i][j]=(xbiosmode_t *)SDL_malloc(sizeof(xbiosmode_t));
if ( SDL_xbiosmode[i][j] == NULL ) {
SDL_OutOfMemory();
return(-1);
}
SDL_memset(SDL_xbiosmode[i][j], 0, sizeof(xbiosmode_t));
}
496
SDL_xbiosmode[i][j] = NULL;
497
498
499
500
501
502
503
504
505
506
507
508
SDL_modelist[i] = (SDL_Rect **)
SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *));
if ( SDL_modelist[i] == NULL ) {
SDL_OutOfMemory();
return(-1);
}
for ( j=0; j<SDL_nummodes[i]; ++j ) {
SDL_modelist[i][j]=(SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
if ( SDL_modelist[i][j] == NULL ) {
SDL_OutOfMemory();
return(-1);
509
}
510
511
512
513
SDL_memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect));
}
SDL_modelist[i][j] = NULL;
}
514
515
516
517
518
/* Now fill the mode list */
switch (XBIOS_cvdo >>16) {
case VDO_ST:
case VDO_STE:
519
(*XBIOS_listModes)(this, 1);
520
break;
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
case VDO_TT:
XBIOS_ListTTModes(this, 1);
break;
case VDO_F30:
/* ScreenBlaster 3 ? */
if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
SDL_XBIOS_ListSB3Modes(this, 1, (scpn_cookie_t *)cookie_scpn);
} else
/* Centscreen ? */
if (Getcookie(C_CNTS, &cookie_cnts) == C_FOUND) {
XBIOS_oldvmode = SDL_XBIOS_ListCentscreenModes(this, 1);
XBIOS_centscreen = SDL_TRUE;
} else
/* Standard, with or without Blowup */
{
switch (VgetMonitor())
{
case MONITOR_RGB:
case MONITOR_TV:
XBIOS_ListFalconRgbModes(this, 1);
break;
case MONITOR_VGA:
XBIOS_ListFalconVgaModes(this, 1);
break;
}
546
547
548
549
550
551
if (Getcookie(C_BLOW, &cookie_blow) == C_FOUND) {
SDL_XBIOS_ListBlowupModes(this, 1, (blow_cookie_t *)cookie_blow);
}
}
break;
552
case VDO_MILAN:
553
(*XBIOS_listModes)(this, 1);
554
break;
555
}
556
557
558
559
560
561
562
563
564
565
XBIOS_screens[0]=NULL;
XBIOS_screens[1]=NULL;
XBIOS_shadowscreen=NULL;
/* Update hardware info */
this->info.hw_available = 1;
this->info.video_mem = (Uint32) Atari_SysMalloc(-1L, MX_STRAM);
/* Init chunky to planar routine */
566
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
567
568
#if SDL_VIDEO_OPENGL
569
570
571
SDL_AtariGL_InitPointers(this);
#endif
572
573
574
575
576
/* Disable screensavers */
if (SDL_XBIOS_TveillePresent(this)) {
SDL_XBIOS_TveilleDisable(this);
}
577
578
579
580
581
582
/* We're done! */
return(0);
}
static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
583
return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
584
585
586
587
}
static void XBIOS_FreeBuffers(_THIS)
{
588
(*XBIOS_freeVbuffers)(this);
589
590
591
592
593
594
595
596
597
598
599
if (XBIOS_shadowscreen!=NULL) {
Mfree(XBIOS_shadowscreen);
XBIOS_shadowscreen=NULL;
}
}
static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags)
{
int mode, new_depth;
600
int num_buffers;
601
602
603
604
605
606
607
xbiosmode_t *new_video_mode;
Uint32 new_screen_size;
Uint32 modeflags;
/* Free current buffers */
XBIOS_FreeBuffers(this);
608
609
/* Try to set the requested linear video mode */
bpp = (bpp+7)/8-1;
610
611
612
613
614
615
616
617
618
619
for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) {
if ( (SDL_modelist[bpp][mode]->w == width) &&
(SDL_modelist[bpp][mode]->h == height) ) {
break;
}
}
if ( SDL_modelist[bpp][mode] == NULL ) {
SDL_SetError("Couldn't find requested mode in list");
return(NULL);
}
620
new_video_mode = SDL_xbiosmode[bpp][mode];
621
622
modeflags = SDL_FULLSCREEN | SDL_PREALLOC;
623
624
625
626
/* Allocate needed buffers: simple/double buffer and shadow surface */
new_depth = new_video_mode->depth;
if (new_depth == 4) {
627
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4;
628
new_depth=8;
629
modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
630
} else if (new_depth == 8) {
631
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
632
modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
633
634
635
636
637
638
639
} else {
modeflags |= SDL_HWSURFACE;
}
new_screen_size = width * height * ((new_depth)>>3);
new_screen_size += 256; /* To align on a 256 byte adress */
640
if (new_video_mode->flags & XBIOSMODE_C2P) {
641
642
643
XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM);
if (XBIOS_shadowscreen == NULL) {
644
SDL_SetError("Can not allocate %d KB for shadow buffer", new_screen_size>>10);
645
646
return (NULL);
}
647
SDL_memset(XBIOS_shadowscreen, 0, new_screen_size);
648
649
650
}
/* Output buffer needs to be twice in size for the software double-line mode */
651
if (new_video_mode->flags & XBIOSMODE_DOUBLELINE) {
652
653
654
new_screen_size <<= 1;
}
655
656
/* Double buffer ? */
num_buffers = 1;
657
658
#if SDL_VIDEO_OPENGL
659
660
661
662
663
664
if (flags & SDL_OPENGL) {
if (this->gl_config.double_buffer) {
flags |= SDL_DOUBLEBUF;
}
}
#endif
665
if ((flags & SDL_DOUBLEBUF) && ((XBIOS_cvdo>>16) != VDO_MILAN)) {
666
667
668
669
670
num_buffers = 2;
modeflags |= SDL_DOUBLEBUF;
}
/* Allocate buffers */
671
672
673
if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) {
XBIOS_FreeBuffers(this);
return (NULL);
674
}
675
676
677
678
679
680
681
682
/* Allocate the new pixel format for the screen */
if ( ! SDL_ReallocFormat(current, new_depth, 0, 0, 0, 0) ) {
XBIOS_FreeBuffers(this);
SDL_SetError("Couldn't allocate new pixel format for requested mode");
return(NULL);
}
683
684
685
XBIOS_current = new_video_mode;
current->w = width;
current->h = height;
686
687
688
689
690
current->pitch = (width * new_depth)>>3;
/* this is for C2P conversion */
XBIOS_pitch = (new_video_mode->width * new_video_mode->depth)>>3;
691
if (new_video_mode->flags & XBIOSMODE_C2P)
692
693
694
695
696
697
current->pixels = XBIOS_shadowscreen;
else
current->pixels = XBIOS_screens[0];
XBIOS_fbnum = 0;
698
#if SDL_VIDEO_OPENGL
699
if (flags & SDL_OPENGL) {
700
if (!SDL_AtariGL_Init(this, current)) {
701
XBIOS_FreeBuffers(this);
702
703
SDL_SetError("Can not create OpenGL context");
return NULL;
704
705
706
707
708
709
710
711
}
modeflags |= SDL_OPENGL;
}
#endif
current->flags = modeflags;
712
#ifndef DEBUG_VIDEO_XBIOS
713
/* Now set the video mode */
714
if ((XBIOS_cvdo>>16) != VDO_MILAN) {
715
716
Setscreen(-1,XBIOS_screens[0],-1);
}
717
718
719
720
switch(XBIOS_cvdo >> 16) {
case VDO_ST:
case VDO_STE:
721
(*XBIOS_setMode)(this, new_video_mode);
722
723
724
725
726
break;
case VDO_TT:
EsetShift(new_video_mode->number);
break;
case VDO_F30:
727
728
729
if (XBIOS_centscreen) {
SDL_XBIOS_CentscreenSetmode(this, width, height, new_depth);
} else {
730
VsetMode(new_video_mode->number);
731
}
732
733
/* Set hardware palette to black in True Colour */
734
735
736
737
738
739
if (new_depth > 8) {
SDL_memset(F30_palette, 0, sizeof(F30_palette));
VsetRGB(0,256,F30_palette);
}
break;
case VDO_MILAN:
740
(*XBIOS_setMode)(this, new_video_mode);
741
742
743
744
break;
}
Vsync();
745
#endif
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
this->UpdateRects = XBIOS_UpdateRects;
return (current);
}
/* We don't actually allow hardware surfaces other than the main one */
static int XBIOS_AllocHWSurface(_THIS, SDL_Surface *surface)
{
return(-1);
}
static void XBIOS_FreeHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static int XBIOS_LockHWSurface(_THIS, SDL_Surface *surface)
{
return(0);
}
static void XBIOS_UnlockHWSurface(_THIS, SDL_Surface *surface)
{
return;
}
static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
776
777
778
surface = this->screen;
779
if (XBIOS_current->flags & XBIOSMODE_C2P) {
780
int i;
781
int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
782
783
784
785
786
787
for (i=0;i<numrects;i++) {
void *source,*destination;
int x1,x2;
x1 = rects[i].x & ~15;
788
789
790
791
x2 = rects[i].x+rects[i].w;
if (x2 & 15) {
x2 = (x2 | 15) +1;
}
792
793
794
795
796
source = surface->pixels;
source += surface->pitch * rects[i].y;
source += x1;
797
destination = XBIOS_screens[XBIOS_fbnum];
798
799
800
801
destination += XBIOS_pitch * rects[i].y;
destination += x1;
/* Convert chunky to planar screen */
802
SDL_Atari_C2pConvert(
803
804
805
806
source,
destination,
x2-x1,
rects[i].h,
807
doubleline,
808
809
surface->pitch,
XBIOS_pitch
810
811
812
813
);
}
}
814
#ifndef DEBUG_VIDEO_XBIOS
815
(*XBIOS_swapVbuffers)(this);
816
817
Vsync();
818
#endif
819
820
821
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
822
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
823
824
825
surface->pixels=XBIOS_screens[XBIOS_fbnum];
}
}
826
827
828
829
}
static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
{
830
if (XBIOS_current->flags & XBIOSMODE_C2P) {
831
832
void *destscr;
int destx;
833
int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
834
835
836
/* Center on destination screen */
destscr = XBIOS_screens[XBIOS_fbnum];
837
838
destscr += XBIOS_pitch * ((XBIOS_current->height - surface->h) >> 1);
destx = (XBIOS_current->width - surface->w) >> 1;
839
840
841
destx &= ~15;
destscr += destx;
842
/* Convert chunky to planar screen */
843
SDL_Atari_C2pConvert(
844
845
846
847
surface->pixels,
destscr,
surface->w,
surface->h,
848
doubleline,
849
850
surface->pitch,
XBIOS_pitch
851
852
853
);
}
854
#ifndef DEBUG_VIDEO_XBIOS
855
(*XBIOS_swapVbuffers)(this);
856
857
Vsync();
858
#endif
859
860
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
861
XBIOS_fbnum ^= 1;
862
if ((XBIOS_current->flags & XBIOSMODE_C2P) == 0) {
863
864
surface->pixels=XBIOS_screens[XBIOS_fbnum];
}
865
866
867
868
869
870
871
}
return(0);
}
static int XBIOS_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
{
872
#ifndef DEBUG_VIDEO_XBIOS
873
874
875
876
877
878
879
880
881
882
883
int i;
int r,v,b;
switch( XBIOS_cvdo >> 16) {
case VDO_TT:
for(i = 0; i < ncolors; i++)
{
r = colors[i].r;
v = colors[i].g;
b = colors[i].b;
884
TT_palette[i]=((r>>4)<<8)|((v>>4)<<4)|(b>>4);
885
886
887
888
889
890
891
892
893
894
}
EsetPalette(firstcolor,ncolors,TT_palette);
break;
case VDO_F30:
for(i = 0; i < ncolors; i++)
{
r = colors[i].r;
v = colors[i].g;
b = colors[i].b;
895
F30_palette[i]=(r<<16)|(v<<8)|b;
896
897
898
899
}
VsetRGB(firstcolor,ncolors,F30_palette);
break;
}
900
#endif
901
902
903
904
905
906
907
908
909
910
911
912
913
914
return(1);
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
static void XBIOS_VideoQuit(_THIS)
{
int i,j;
Atari_ShutdownEvents();
/* Restore video mode and palette */
915
#ifndef DEBUG_VIDEO_XBIOS
916
917
918
switch(XBIOS_cvdo >> 16) {
case VDO_ST:
case VDO_STE:
919
(*XBIOS_restoreMode)(this);
920
921
922
923
924
925
926
927
928
929
break;
case VDO_TT:
Setscreen(-1,XBIOS_oldvbase,-1);
EsetShift(XBIOS_oldvmode);
if (XBIOS_oldnumcol) {
EsetPalette(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
break;
case VDO_F30:
Setscreen(-1, XBIOS_oldvbase, -1);
930
931
932
if (XBIOS_centscreen) {
SDL_XBIOS_CentscreenRestore(this, XBIOS_oldvmode);
} else {
933
VsetMode(XBIOS_oldvmode);
934
}
935
if (XBIOS_oldnumcol) {
936
937
938
939
VsetRGB(0, XBIOS_oldnumcol, XBIOS_oldpalette);
}
break;
case VDO_MILAN:
940
(*XBIOS_restoreMode)(this);
941
942
943
break;
}
Vsync();
944
#endif
945
946
#if SDL_VIDEO_OPENGL
947
948
949
950
951
if (gl_active) {
SDL_AtariGL_Quit(this, SDL_TRUE);
}
#endif
952
if (XBIOS_oldpalette) {
953
SDL_free(XBIOS_oldpalette);
954
955
956
957
958
XBIOS_oldpalette=NULL;
}
XBIOS_FreeBuffers(this);
/* Free mode list */
959
960
961
962
963
964
965
966
967
968
969
970
for ( i=0; i<NUM_MODELISTS; ++i ) {
if ( SDL_modelist[i] != NULL ) {
for ( j=0; SDL_modelist[i][j]; ++j )
SDL_free(SDL_modelist[i][j]);
SDL_free(SDL_modelist[i]);
SDL_modelist[i] = NULL;
}
if ( SDL_xbiosmode[i] != NULL ) {
for ( j=0; SDL_xbiosmode[i][j]; ++j )
SDL_free(SDL_xbiosmode[i][j]);
SDL_free(SDL_xbiosmode[i]);
SDL_xbiosmode[i] = NULL;
971
}
972
973
}
974
this->screen->pixels = NULL;
975
976
977
/* Restore screensavers */
if (SDL_XBIOS_TveillePresent(this)) {
978
SDL_XBIOS_TveilleEnable(this);
979
}
980
}
981
982
#if SDL_VIDEO_OPENGL
983
984
985
static void XBIOS_GL_SwapBuffers(_THIS)
{
986
987
988
SDL_AtariGL_SwapBuffers(this);
XBIOS_FlipHWSurface(this, this->screen);
SDL_AtariGL_MakeCurrent(this);
989
990
991
}
#endif