Skip to content

Latest commit

 

History

History
941 lines (800 loc) · 22.8 KB

SDL_xbios.c

File metadata and controls

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