Skip to content

Latest commit

 

History

History
1116 lines (955 loc) · 26.3 KB

SDL_xbios.c

File metadata and controls

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