Skip to content

Latest commit

 

History

History
733 lines (611 loc) · 17.4 KB

SDL_xbios.c

File metadata and controls

733 lines (611 loc) · 17.4 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 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_sb3.h"
Jan 11, 2007
Jan 11, 2007
50
#include "SDL_xbios_tveille.h"
Sep 19, 2009
Sep 19, 2009
51
#include "SDL_xbios_milan.h"
52
53
54
#define XBIOS_VID_DRIVER_NAME "xbios"
Oct 13, 2008
Oct 13, 2008
55
56
57
58
#ifndef C_fVDI
#define C_fVDI 0x66564449L
#endif
Mar 7, 2005
Mar 7, 2005
59
/* Debug print info */
Mar 7, 2005
Mar 7, 2005
60
#if 0
Mar 7, 2005
Mar 7, 2005
61
62
63
64
#define DEBUG_PRINT(what) \
{ \
printf what; \
}
Mar 7, 2005
Mar 7, 2005
65
#define DEBUG_VIDEO_XBIOS 1
Mar 7, 2005
Mar 7, 2005
66
67
68
69
#else
#define DEBUG_PRINT(what)
#undef DEBUG_VIDEO_XBIOS
#endif
Nov 12, 2003
Nov 12, 2003
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* 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 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
85
#if SDL_VIDEO_OPENGL
Nov 17, 2004
Nov 17, 2004
86
87
88
89
/* OpenGL functions */
static void XBIOS_GL_SwapBuffers(_THIS);
#endif
90
91
92
93
/* Xbios driver bootstrap functions */
static int XBIOS_Available(void)
{
Aug 28, 2011
Aug 28, 2011
94
95
long cookie_vdo, /*cookie_mil,*/ cookie_hade, cookie_scpn;
long cookie_fvdi;
Oct 13, 2008
Oct 13, 2008
96
const char *envr = SDL_getenv("SDL_VIDEODRIVER");
Jan 31, 2004
Jan 31, 2004
97
98
/* Milan/Hades Atari clones do not have an Atari video chip */
Sep 20, 2009
Sep 20, 2009
99
if ( /*(Getcookie(C__MIL, &cookie_mil) == C_FOUND) ||*/
Jan 31, 2004
Jan 31, 2004
100
101
102
(Getcookie(C_hade, &cookie_hade) == C_FOUND) ) {
return 0;
}
Oct 13, 2008
Oct 13, 2008
104
105
106
107
108
109
110
111
112
113
114
/* 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 */
}
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* 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
132
if ( VgetMonitor() == MONITOR_MONO)
133
return 0;
Feb 22, 2005
Feb 22, 2005
134
135
136
137
138
if (Getcookie(C_SCPN, &cookie_scpn) == C_FOUND) {
if (!SDL_XBIOS_SB3Usable((scpn_cookie_t *)cookie_scpn)) {
return 0;
}
}
139
break;
Sep 19, 2009
Sep 19, 2009
140
141
case VDO_MILAN:
break;
142
143
144
145
146
147
148
149
150
default:
return 0;
}
return 1;
}
static void XBIOS_DeleteDevice(SDL_VideoDevice *device)
{
Feb 7, 2006
Feb 7, 2006
151
152
SDL_free(device->hidden);
SDL_free(device);
153
154
155
156
157
}
static SDL_VideoDevice *XBIOS_CreateDevice(int devindex)
{
SDL_VideoDevice *device;
Jul 30, 2014
Jul 30, 2014
158
long cookie_cvdo;
159
160
/* Initialize all variables that we clean on shutdown */
Feb 7, 2006
Feb 7, 2006
161
device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
162
if ( device ) {
Feb 7, 2006
Feb 7, 2006
163
SDL_memset(device, 0, (sizeof *device));
164
device->hidden = (struct SDL_PrivateVideoData *)
Feb 7, 2006
Feb 7, 2006
165
SDL_malloc((sizeof *device->hidden));
Nov 25, 2004
Nov 25, 2004
166
device->gl_data = (struct SDL_PrivateGLData *)
Feb 7, 2006
Feb 7, 2006
167
SDL_malloc((sizeof *device->gl_data));
168
169
170
171
}
if ( (device == NULL) || (device->hidden == NULL) ) {
SDL_OutOfMemory();
if ( device ) {
Feb 7, 2006
Feb 7, 2006
172
SDL_free(device);
173
174
175
}
return(0);
}
Feb 7, 2006
Feb 7, 2006
176
177
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
SDL_memset(device->gl_data, 0, sizeof(*device->gl_data));
178
179
180
181
182
/* Video functions */
device->VideoInit = XBIOS_VideoInit;
device->ListModes = XBIOS_ListModes;
device->SetVideoMode = XBIOS_SetVideoMode;
Jul 30, 2014
Jul 30, 2014
183
device->SetColors = NULL; /* Defined by each device specific backend */
Jul 31, 2014
Jul 31, 2014
184
device->UpdateRects = NULL; /* Defined once video mode set */
185
186
187
188
189
190
191
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
192
#if SDL_VIDEO_OPENGL
Nov 17, 2004
Nov 17, 2004
193
/* OpenGL functions */
Nov 25, 2004
Nov 25, 2004
194
195
196
197
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
198
199
200
device->GL_SwapBuffers = XBIOS_GL_SwapBuffers;
#endif
201
202
203
204
205
206
/* Events */
device->InitOSKeymap = Atari_InitOSKeymap;
device->PumpEvents = Atari_PumpEvents;
device->free = XBIOS_DeleteDevice;
Jul 30, 2014
Jul 30, 2014
207
208
209
210
/* Setup device specific functions, default to ST for everything */
if (Getcookie(C__VDO, &cookie_cvdo) != C_FOUND) {
cookie_cvdo = VDO_ST << 16;
}
Jul 30, 2014
Jul 30, 2014
211
SDL_XBIOS_VideoInit_ST(device, cookie_cvdo);
Jul 31, 2014
Jul 31, 2014
212
device->hidden->updRects = XBIOS_UpdateRects;
Jul 30, 2014
Jul 30, 2014
213
214
switch (cookie_cvdo>>16) {
Jul 30, 2014
Jul 30, 2014
215
216
217
218
case VDO_ST:
case VDO_STE:
/* Already done as default */
break;
Jul 30, 2014
Jul 30, 2014
219
case VDO_TT:
Jul 30, 2014
Jul 30, 2014
220
221
SDL_XBIOS_VideoInit_TT(device);
break;
Jul 30, 2014
Jul 30, 2014
222
case VDO_F30:
Jul 30, 2014
Jul 30, 2014
223
SDL_XBIOS_VideoInit_F30(device);
Jul 30, 2014
Jul 30, 2014
224
break;
Jul 30, 2014
Jul 30, 2014
225
226
227
228
229
case VDO_MILAN:
SDL_XBIOS_VideoInit_Milan(device);
break;
}
230
231
232
233
234
235
236
237
return device;
}
VideoBootStrap XBIOS_bootstrap = {
XBIOS_VID_DRIVER_NAME, "Atari Xbios driver",
XBIOS_Available, XBIOS_CreateDevice
};
Sep 19, 2009
Sep 19, 2009
238
void SDL_XBIOS_AddMode(_THIS, int actually_add, const xbiosmode_t *modeinfo)
Mar 7, 2005
Mar 7, 2005
239
{
Sep 19, 2009
Sep 19, 2009
240
241
242
243
244
245
246
247
248
249
250
251
252
253
int i = 0;
switch(modeinfo->depth) {
case 15:
case 16:
i = 1;
break;
case 24:
i = 2;
break;
case 32:
i = 3;
break;
}
Mar 7, 2005
Mar 7, 2005
254
Sep 19, 2009
Sep 19, 2009
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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) ) {
Mar 7, 2005
Mar 7, 2005
270
271
return;
}
Sep 19, 2009
Sep 19, 2009
272
273
274
275
276
277
278
279
280
281
/* 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];
Jul 28, 2014
Jul 28, 2014
282
SDL_memcpy(&saved_mode[!b], SDL_xbiosmode[i][j], sizeof(xbiosmode_t));
Sep 19, 2009
Sep 19, 2009
283
284
285
286
287
288
289
290
291
*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];
Mar 7, 2005
Mar 7, 2005
292
}
Sep 19, 2009
Sep 19, 2009
293
}
Mar 7, 2005
Mar 7, 2005
294
295
296
static int XBIOS_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
Aug 26, 2011
Aug 26, 2011
297
int i;
298
299
/* Initialize all variables that we clean on shutdown */
Sep 19, 2009
Sep 19, 2009
300
301
302
303
304
for ( i=0; i<NUM_MODELISTS; ++i ) {
SDL_nummodes[i] = 0;
SDL_modelist[i] = NULL;
SDL_xbiosmode[i] = NULL;
}
305
306
/* Allocate memory for old palette */
Feb 7, 2006
Feb 7, 2006
307
XBIOS_oldpalette = (void *)SDL_malloc(256*sizeof(long));
308
309
310
311
312
if ( !XBIOS_oldpalette ) {
SDL_SetError("Unable to allocate memory for old palette\n");
return(-1);
}
Sep 19, 2009
Sep 19, 2009
313
314
315
316
317
318
319
/* 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;
Jul 30, 2014
Jul 30, 2014
320
321
/* Save current mode, may update current screen size or preferred depth */
(*XBIOS_saveMode)(this, vformat);
Sep 19, 2009
Sep 19, 2009
322
Jul 30, 2014
Jul 30, 2014
323
324
/* First allocate room for needed video modes */
(*XBIOS_listModes)(this, 0);
Sep 19, 2009
Sep 19, 2009
326
327
328
for ( i=0; i<NUM_MODELISTS; ++i ) {
int j;
Sep 20, 2009
Sep 20, 2009
329
SDL_xbiosmode[i] = (xbiosmode_t **)
Sep 20, 2009
Sep 20, 2009
330
SDL_malloc((SDL_nummodes[i]+1)*sizeof(xbiosmode_t *));
Sep 19, 2009
Sep 19, 2009
331
332
333
334
if ( SDL_xbiosmode[i] == NULL ) {
SDL_OutOfMemory();
return(-1);
}
Sep 20, 2009
Sep 20, 2009
335
336
337
338
339
340
341
342
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));
}
Sep 20, 2009
Sep 20, 2009
343
SDL_xbiosmode[i][j] = NULL;
Sep 20, 2009
Sep 20, 2009
344
Sep 19, 2009
Sep 19, 2009
345
346
347
348
349
350
351
352
353
354
355
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);
Feb 22, 2005
Feb 22, 2005
356
}
Sep 19, 2009
Sep 19, 2009
357
358
359
360
SDL_memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect));
}
SDL_modelist[i][j] = NULL;
}
May 31, 2005
May 31, 2005
361
Sep 19, 2009
Sep 19, 2009
362
/* Now fill the mode list */
Jul 30, 2014
Jul 30, 2014
363
(*XBIOS_listModes)(this, 1);
364
365
366
367
368
369
370
371
372
373
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
374
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
Feb 16, 2006
Feb 16, 2006
376
#if SDL_VIDEO_OPENGL
Nov 26, 2004
Nov 26, 2004
377
378
379
SDL_AtariGL_InitPointers(this);
#endif
Jan 11, 2007
Jan 11, 2007
380
381
382
383
384
/* Disable screensavers */
if (SDL_XBIOS_TveillePresent(this)) {
SDL_XBIOS_TveilleDisable(this);
}
385
386
387
388
389
390
/* We're done! */
return(0);
}
static SDL_Rect **XBIOS_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
{
Sep 19, 2009
Sep 19, 2009
391
return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]);
392
393
394
395
}
static void XBIOS_FreeBuffers(_THIS)
{
Jul 30, 2014
Jul 30, 2014
396
(*XBIOS_freeVbuffers)(this);
Jul 30, 2014
Jul 30, 2014
398
if (XBIOS_shadowscreen) {
399
400
401
402
403
404
405
406
407
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;
Jul 30, 2014
Jul 30, 2014
408
int num_buffers;
409
410
411
xbiosmode_t *new_video_mode;
Uint32 new_screen_size;
Uint32 modeflags;
Aug 3, 2014
Aug 3, 2014
412
Uint32 lineWidth;
413
414
415
416
/* Free current buffers */
XBIOS_FreeBuffers(this);
Sep 19, 2009
Sep 19, 2009
417
418
/* Try to set the requested linear video mode */
bpp = (bpp+7)/8-1;
419
420
421
422
423
424
425
426
427
428
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);
}
Sep 19, 2009
Sep 19, 2009
429
new_video_mode = SDL_xbiosmode[bpp][mode];
Jul 27, 2005
Jul 27, 2005
431
modeflags = SDL_FULLSCREEN | SDL_PREALLOC;
432
433
434
435
/* Allocate needed buffers: simple/double buffer and shadow surface */
new_depth = new_video_mode->depth;
if (new_depth == 4) {
Nov 12, 2003
Nov 12, 2003
436
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert4;
437
new_depth=8;
Jun 30, 2005
Jun 30, 2005
438
modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
439
} else if (new_depth == 8) {
Nov 12, 2003
Nov 12, 2003
440
SDL_Atari_C2pConvert = SDL_Atari_C2pConvert8;
Oct 5, 2002
Oct 5, 2002
441
modeflags |= SDL_SWSURFACE|SDL_HWPALETTE;
442
443
444
445
} else {
modeflags |= SDL_HWSURFACE;
}
Aug 3, 2014
Aug 3, 2014
446
447
448
lineWidth = (*XBIOS_getLineWidth)(this, new_video_mode, width, new_depth);
new_screen_size = lineWidth * height;
449
450
new_screen_size += 256; /* To align on a 256 byte adress */
Sep 20, 2009
Sep 20, 2009
451
if (new_video_mode->flags & XBIOSMODE_C2P) {
452
453
454
XBIOS_shadowscreen = Atari_SysMalloc(new_screen_size, MX_PREFTTRAM);
if (XBIOS_shadowscreen == NULL) {
Jul 27, 2005
Jul 27, 2005
455
SDL_SetError("Can not allocate %d KB for shadow buffer", new_screen_size>>10);
456
457
return (NULL);
}
Feb 7, 2006
Feb 7, 2006
458
SDL_memset(XBIOS_shadowscreen, 0, new_screen_size);
459
460
461
}
/* Output buffer needs to be twice in size for the software double-line mode */
Sep 20, 2009
Sep 20, 2009
462
if (new_video_mode->flags & XBIOSMODE_DOUBLELINE) {
463
464
465
new_screen_size <<= 1;
}
Sep 19, 2009
Sep 19, 2009
466
467
/* Double buffer ? */
num_buffers = 1;
Feb 16, 2006
Feb 16, 2006
469
#if SDL_VIDEO_OPENGL
Nov 17, 2004
Nov 17, 2004
470
471
472
473
474
475
if (flags & SDL_OPENGL) {
if (this->gl_config.double_buffer) {
flags |= SDL_DOUBLEBUF;
}
}
#endif
Jul 30, 2014
Jul 30, 2014
476
if (flags & SDL_DOUBLEBUF) {
Sep 19, 2009
Sep 19, 2009
477
478
479
480
481
num_buffers = 2;
modeflags |= SDL_DOUBLEBUF;
}
/* Allocate buffers */
Jul 30, 2014
Jul 30, 2014
482
483
484
if (!(*XBIOS_allocVbuffers)(this, num_buffers, new_screen_size)) {
XBIOS_FreeBuffers(this);
return (NULL);
Sep 19, 2009
Sep 19, 2009
486
487
488
489
490
491
492
493
/* 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);
}
Sep 20, 2009
Sep 20, 2009
494
495
496
XBIOS_current = new_video_mode;
current->w = width;
current->h = height;
Aug 3, 2014
Aug 3, 2014
497
current->pitch = lineWidth;
498
499
/* this is for C2P conversion */
Aug 3, 2014
Aug 3, 2014
500
XBIOS_pitch = (*XBIOS_getLineWidth)(this, new_video_mode, new_video_mode->width, new_video_mode->depth);
Jul 30, 2014
Jul 30, 2014
502
if (XBIOS_shadowscreen)
503
504
505
506
507
508
current->pixels = XBIOS_shadowscreen;
else
current->pixels = XBIOS_screens[0];
XBIOS_fbnum = 0;
Feb 16, 2006
Feb 16, 2006
509
#if SDL_VIDEO_OPENGL
Nov 17, 2004
Nov 17, 2004
510
if (flags & SDL_OPENGL) {
Nov 25, 2004
Nov 25, 2004
511
if (!SDL_AtariGL_Init(this, current)) {
Nov 17, 2004
Nov 17, 2004
512
XBIOS_FreeBuffers(this);
Nov 25, 2004
Nov 25, 2004
513
514
SDL_SetError("Can not create OpenGL context");
return NULL;
Nov 17, 2004
Nov 17, 2004
515
516
517
518
519
520
521
522
}
modeflags |= SDL_OPENGL;
}
#endif
current->flags = modeflags;
Nov 12, 2003
Nov 12, 2003
523
#ifndef DEBUG_VIDEO_XBIOS
Sep 19, 2009
Sep 19, 2009
524
/* Now set the video mode */
Jul 30, 2014
Jul 30, 2014
525
(*XBIOS_setMode)(this, new_video_mode);
526
527
Vsync();
Sep 19, 2009
Sep 19, 2009
528
#endif
Jul 31, 2014
Jul 31, 2014
530
this->UpdateRects = XBIOS_updRects;
Aug 22, 2014
Aug 22, 2014
531
532
XBIOS_recoffset = 2;
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
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;
}
Aug 22, 2014
Aug 22, 2014
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
static void recalc_offset(_THIS)
{
int offset_x;
offset_x = (XBIOS_current->width - this->screen->w)>>1;
offset_x &= ~15;
this->offset_x = offset_x;
this->screen->offset = this->offset_y*this->screen->pitch +
this->offset_x*this->screen->format->BytesPerPixel;
--XBIOS_recoffset;
}
572
573
574
static void XBIOS_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
{
SDL_Surface *surface;
Mar 22, 2002
Mar 22, 2002
575
576
577
surface = this->screen;
Sep 20, 2009
Sep 20, 2009
578
if (XBIOS_current->flags & XBIOSMODE_C2P) {
Mar 22, 2002
Mar 22, 2002
579
int i;
Sep 20, 2009
Sep 20, 2009
580
int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
Mar 22, 2002
Mar 22, 2002
581
Aug 22, 2014
Aug 22, 2014
582
583
584
585
if (XBIOS_recoffset>0) {
recalc_offset(this);
}
Mar 22, 2002
Mar 22, 2002
586
for (i=0;i<numrects;i++) {
Aug 22, 2014
Aug 22, 2014
587
Uint8 *source,*destination;
Mar 22, 2002
Mar 22, 2002
588
589
590
int x1,x2;
x1 = rects[i].x & ~15;
Mar 26, 2002
Mar 26, 2002
591
592
593
594
x2 = rects[i].x+rects[i].w;
if (x2 & 15) {
x2 = (x2 | 15) +1;
}
Mar 22, 2002
Mar 22, 2002
595
596
597
598
599
source = surface->pixels;
source += surface->pitch * rects[i].y;
source += x1;
Aug 22, 2014
Aug 22, 2014
600
destination = XBIOS_screens[XBIOS_fbnum];
Mar 22, 2002
Mar 22, 2002
601
602
603
604
destination += XBIOS_pitch * rects[i].y;
destination += x1;
/* Convert chunky to planar screen */
Nov 12, 2003
Nov 12, 2003
605
SDL_Atari_C2pConvert(
Jul 21, 2005
Jul 21, 2005
606
607
608
609
source,
destination,
x2-x1,
rects[i].h,
Sep 20, 2009
Sep 20, 2009
610
doubleline,
Jul 21, 2005
Jul 21, 2005
611
612
surface->pitch,
XBIOS_pitch
Mar 22, 2002
Mar 22, 2002
613
614
615
616
);
}
}
Nov 12, 2003
Nov 12, 2003
617
#ifndef DEBUG_VIDEO_XBIOS
Jul 30, 2014
Jul 30, 2014
618
(*XBIOS_swapVbuffers)(this);
Sep 19, 2009
Sep 19, 2009
619
Mar 22, 2002
Mar 22, 2002
620
Vsync();
Sep 19, 2009
Sep 19, 2009
621
#endif
Mar 22, 2002
Mar 22, 2002
622
623
624
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
XBIOS_fbnum ^= 1;
Aug 22, 2014
Aug 22, 2014
625
626
627
628
629
}
if (XBIOS_shadowscreen) {
surface->pixels=((Uint8 *) XBIOS_shadowscreen) + surface->offset;
} else {
surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
Mar 22, 2002
Mar 22, 2002
630
}
631
632
633
634
}
static int XBIOS_FlipHWSurface(_THIS, SDL_Surface *surface)
{
Sep 20, 2009
Sep 20, 2009
635
636
if (XBIOS_current->flags & XBIOSMODE_C2P) {
int doubleline = (XBIOS_current->flags & XBIOSMODE_DOUBLELINE ? 1 : 0);
Jul 21, 2005
Jul 21, 2005
637
Aug 22, 2014
Aug 22, 2014
638
639
640
if (XBIOS_recoffset>0) {
recalc_offset(this);
}
Jul 21, 2005
Jul 21, 2005
641
642
/* Convert chunky to planar screen */
Nov 12, 2003
Nov 12, 2003
643
SDL_Atari_C2pConvert(
Jul 21, 2005
Jul 21, 2005
644
surface->pixels,
Aug 22, 2014
Aug 22, 2014
645
((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset,
Jul 21, 2005
Jul 21, 2005
646
647
surface->w,
surface->h,
Sep 20, 2009
Sep 20, 2009
648
doubleline,
Jul 21, 2005
Jul 21, 2005
649
650
surface->pitch,
XBIOS_pitch
651
652
653
);
}
Nov 12, 2003
Nov 12, 2003
654
#ifndef DEBUG_VIDEO_XBIOS
Jul 30, 2014
Jul 30, 2014
655
(*XBIOS_swapVbuffers)(this);
Sep 19, 2009
Sep 19, 2009
656
657
Vsync();
Sep 19, 2009
Sep 19, 2009
658
#endif
659
660
if ((surface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) {
Mar 20, 2002
Mar 20, 2002
661
XBIOS_fbnum ^= 1;
Aug 22, 2014
Aug 22, 2014
662
663
664
665
666
}
if (XBIOS_shadowscreen) {
surface->pixels=((Uint8 *) XBIOS_shadowscreen) + surface->offset;
} else {
surface->pixels=((Uint8 *) XBIOS_screens[XBIOS_fbnum]) + surface->offset;
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
}
return(0);
}
/* 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
682
#ifndef DEBUG_VIDEO_XBIOS
Jul 30, 2014
Jul 30, 2014
683
684
(*XBIOS_restoreMode)(this);
685
Vsync();
Feb 7, 2004
Feb 7, 2004
686
#endif
Feb 16, 2006
Feb 16, 2006
688
#if SDL_VIDEO_OPENGL
Nov 26, 2004
Nov 26, 2004
689
690
691
692
693
if (gl_active) {
SDL_AtariGL_Quit(this, SDL_TRUE);
}
#endif
694
if (XBIOS_oldpalette) {
Feb 7, 2006
Feb 7, 2006
695
SDL_free(XBIOS_oldpalette);
696
697
698
699
700
XBIOS_oldpalette=NULL;
}
XBIOS_FreeBuffers(this);
/* Free mode list */
Sep 19, 2009
Sep 19, 2009
701
702
703
704
705
706
707
708
709
710
711
712
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;
Mar 7, 2005
Mar 7, 2005
714
715
}
716
this->screen->pixels = NULL;
Jan 11, 2007
Jan 11, 2007
717
718
719
/* Restore screensavers */
if (SDL_XBIOS_TveillePresent(this)) {
Aug 26, 2011
Aug 26, 2011
720
SDL_XBIOS_TveilleEnable(this);
Jan 11, 2007
Jan 11, 2007
721
}
Nov 17, 2004
Nov 17, 2004
723
Feb 16, 2006
Feb 16, 2006
724
#if SDL_VIDEO_OPENGL
Nov 17, 2004
Nov 17, 2004
725
726
727
static void XBIOS_GL_SwapBuffers(_THIS)
{
Nov 27, 2004
Nov 27, 2004
728
729
730
SDL_AtariGL_SwapBuffers(this);
XBIOS_FlipHWSurface(this, this->screen);
SDL_AtariGL_MakeCurrent(this);
Nov 17, 2004
Nov 17, 2004
731
732
733
}
#endif