This repository has been archived by the owner on Feb 11, 2021. It is now read-only.
/
SDL_dcvideo.c
478 lines (420 loc) · 11.5 KB
1
2
/*
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 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
#include "SDL_video.h"
#include "SDL_mouse.h"
26
27
28
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
29
30
31
32
33
34
35
36
37
38
#include "SDL_dcvideo.h"
#include "SDL_dcevents_c.h"
#include "SDL_dcmouse_c.h"
#include <dc/video.h>
#include <dc/pvr.h>
/* Initialization/Query functions */
39
40
41
42
43
44
45
46
static int DC_VideoInit (_THIS, SDL_PixelFormat * vformat);
static SDL_Rect **DC_ListModes (_THIS, SDL_PixelFormat * format,
Uint32 flags);
static SDL_Surface *DC_SetVideoMode (_THIS, SDL_Surface * current, int width,
int height, int bpp, Uint32 flags);
static int DC_SetColors (_THIS, int firstcolor, int ncolors,
SDL_Color * colors);
static void DC_VideoQuit (_THIS);
47
48
/* Hardware surface functions */
49
50
51
52
53
static int DC_AllocHWSurface (_THIS, SDL_Surface * surface);
static int DC_LockHWSurface (_THIS, SDL_Surface * surface);
static void DC_UnlockHWSurface (_THIS, SDL_Surface * surface);
static void DC_FreeHWSurface (_THIS, SDL_Surface * surface);
static int DC_FlipHWSurface (_THIS, SDL_Surface * surface);
54
55
/* etc. */
56
static void DC_UpdateRects (_THIS, int numrects, SDL_Rect * rects);
57
58
/* OpenGL */
59
#if SDL_VIDEO_OPENGL
60
61
62
63
static void *DC_GL_GetProcAddress (_THIS, const char *proc);
static int DC_GL_LoadLibrary (_THIS, const char *path);
static int DC_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value);
static void DC_GL_SwapBuffers (_THIS);
64
#endif
65
66
67
/* DC driver bootstrap functions */
68
69
static int
DC_Available (void)
70
{
71
return 1;
72
73
}
74
75
static void
DC_DeleteDevice (SDL_VideoDevice * device)
76
{
77
78
SDL_free (device->hidden);
SDL_free (device);
79
80
}
81
82
static SDL_VideoDevice *
DC_CreateDevice (int devindex)
83
{
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
device = (SDL_VideoDevice *) SDL_malloc (sizeof (SDL_VideoDevice));
if (device) {
SDL_memset (device, 0, (sizeof *device));
device->hidden = (struct SDL_PrivateVideoData *)
SDL_malloc ((sizeof *device->hidden));
}
if ((device == NULL) || (device->hidden == NULL)) {
SDL_OutOfMemory ();
if (device) {
SDL_free (device);
}
return (0);
}
SDL_memset (device->hidden, 0, (sizeof *device->hidden));
/* Set the function pointers */
device->VideoInit = DC_VideoInit;
device->ListModes = DC_ListModes;
device->SetVideoMode = DC_SetVideoMode;
device->CreateYUVOverlay = NULL;
device->SetColors = DC_SetColors;
device->UpdateRects = DC_UpdateRects;
device->VideoQuit = DC_VideoQuit;
device->AllocHWSurface = DC_AllocHWSurface;
device->CheckHWBlit = NULL;
device->FillHWRect = NULL;
device->SetHWColorKey = NULL;
device->SetHWAlpha = NULL;
device->LockHWSurface = DC_LockHWSurface;
device->UnlockHWSurface = DC_UnlockHWSurface;
device->FlipHWSurface = DC_FlipHWSurface;
device->FreeHWSurface = DC_FreeHWSurface;
119
#if SDL_VIDEO_OPENGL
120
121
122
123
124
device->GL_LoadLibrary = DC_GL_LoadLibrary;
device->GL_GetProcAddress = DC_GL_GetProcAddress;
device->GL_GetAttribute = DC_GL_GetAttribute;
device->GL_MakeCurrent = NULL;
device->GL_SwapBuffers = DC_GL_SwapBuffers;
125
#endif
126
127
128
129
130
131
132
device->SetCaption = NULL;
device->SetIcon = NULL;
device->IconifyWindow = NULL;
device->GrabInput = NULL;
device->GetWMInfo = NULL;
device->InitOSKeymap = DC_InitOSKeymap;
device->PumpEvents = DC_PumpEvents;
133
134
device->free = DC_DeleteDevice;
135
136
return device;
137
138
139
}
VideoBootStrap DC_bootstrap = {
140
141
"dcvideo", "Dreamcast Video",
DC_Available, DC_CreateDevice
142
143
144
};
145
146
int
DC_VideoInit (_THIS, SDL_PixelFormat * vformat)
147
{
148
149
150
151
152
153
154
155
156
/* Determine the screen depth (use default 16-bit depth) */
/* we change this during the SDL_SetVideoMode implementation... */
vformat->BitsPerPixel = 16;
vformat->Rmask = 0x0000f800;
vformat->Gmask = 0x000007e0;
vformat->Bmask = 0x0000001f;
/* We're done! */
return (0);
157
158
}
159
160
161
const static SDL_Rect RECT_800x600 = { 0, 0, 800, 600 }, RECT_640x480 = {
0, 0, 640, 480}, RECT_320x240 = {
0, 0, 320, 240};
162
const static SDL_Rect *vid_modes[] = {
163
164
165
166
&RECT_800x600,
&RECT_640x480,
&RECT_320x240,
NULL
167
168
};
169
170
SDL_Rect **
DC_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
171
{
172
173
174
175
176
177
178
179
180
181
182
switch (format->BitsPerPixel) {
case 15:
case 16:
return &vid_modes;
case 32:
if (!(flags & SDL_INTERNALOPENGL))
return &vid_modes;
default:
return NULL;
}
// return (SDL_Rect **) -1;
183
184
185
}
pvr_init_params_t params = {
186
187
188
189
/* Enable opaque and translucent polygons with size 16 */
{PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0,
PVR_BINSIZE_16}
,
190
191
192
/* Vertex buffer size */
512 * 1024
193
194
};
195
#if SDL_VIDEO_OPENGL
196
197
198
static int pvr_inited;
#endif
199
200
201
SDL_Surface *
DC_SetVideoMode (_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
202
{
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
int disp_mode, pixel_mode, pitch;
Uint32 Rmask, Gmask, Bmask;
if (width == 320 && height == 240)
disp_mode = DM_320x240;
else if (width == 640 && height == 480)
disp_mode = DM_640x480;
else if (width == 800 && height == 600)
disp_mode = DM_800x608;
else {
SDL_SetError ("Couldn't find requested mode in list");
return (NULL);
}
switch (bpp) {
case 15:
pixel_mode = PM_RGB555;
pitch = width * 2;
/* 5-5-5 */
Rmask = 0x00007c00;
Gmask = 0x000003e0;
Bmask = 0x0000001f;
break;
case 16:
pixel_mode = PM_RGB565;
pitch = width * 2;
/* 5-6-5 */
Rmask = 0x0000f800;
Gmask = 0x000007e0;
Bmask = 0x0000001f;
break;
case 24:
bpp = 32;
case 32:
pixel_mode = PM_RGB888;
pitch = width * 4;
Rmask = 0x00ff0000;
Gmask = 0x0000ff00;
Bmask = 0x000000ff;
242
#if SDL_VIDEO_OPENGL
243
if (!(flags & SDL_INTERNALOPENGL))
244
#endif
245
246
247
248
249
break;
default:
SDL_SetError ("Couldn't find requested mode in list");
return (NULL);
}
250
251
// if ( bpp != current->format->BitsPerPixel ) {
252
253
254
if (!SDL_ReallocFormat (current, bpp, Rmask, Gmask, Bmask, 0)) {
return (NULL);
}
255
256
// }
257
258
259
260
261
/* Set up the new mode framebuffer */
current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE);
current->w = width;
current->h = height;
current->pitch = pitch;
262
263
#if SDL_VIDEO_OPENGL
264
265
266
267
if (pvr_inited) {
pvr_inited = 0;
pvr_shutdown ();
}
268
269
#endif
270
vid_set_mode (disp_mode, pixel_mode);
271
272
current->pixels = vram_s;
273
274
#if SDL_VIDEO_OPENGL
275
276
277
278
279
280
281
282
283
if (flags & SDL_INTERNALOPENGL) {
this->gl_config.driver_loaded = 1;
current->flags = SDL_FULLSCREEN | SDL_INTERNALOPENGL;
current->pixels = NULL;
pvr_inited = 1;
pvr_init (¶ms);
glKosInit ();
glKosBeginFrame ();
} else
284
#endif
285
286
287
288
if (flags | SDL_DOUBLEBUF) {
current->flags |= SDL_DOUBLEBUF;
current->pixels = (void *) ((int) current->pixels | 0x400000);
}
289
290
291
/* We're done */
return (current);
292
293
294
}
/* We don't actually allow hardware surfaces other than the main one */
295
296
static int
DC_AllocHWSurface (_THIS, SDL_Surface * surface)
297
{
298
return (-1);
299
}
300
301
static void
DC_FreeHWSurface (_THIS, SDL_Surface * surface)
302
{
303
return;
304
305
306
}
/* We need to wait for vertical retrace on page flipped displays */
307
308
static int
DC_LockHWSurface (_THIS, SDL_Surface * surface)
309
{
310
return (0);
311
312
}
313
314
static void
DC_UnlockHWSurface (_THIS, SDL_Surface * surface)
315
{
316
return;
317
318
}
319
320
static int
DC_FlipHWSurface (_THIS, SDL_Surface * surface)
321
{
322
323
324
325
326
if (surface->flags & SDL_DOUBLEBUF) {
vid_set_start ((int) surface->pixels & 0xffffff);
surface->pixels = (void *) ((int) surface->pixels ^ 0x400000);
}
return (0);
327
328
}
329
330
static void
DC_UpdateRects (_THIS, int numrects, SDL_Rect * rects)
331
{
332
/* do nothing. */
333
334
}
335
336
static int
DC_SetColors (_THIS, int firstcolor, int ncolors, SDL_Color * colors)
337
{
338
339
/* do nothing of note. */
return (1);
340
341
342
343
344
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
345
346
static void
DC_VideoQuit (_THIS)
347
{
348
#if SDL_VIDEO_OPENGL
349
350
351
352
if (pvr_inited) {
pvr_inited = 0;
pvr_shutdown ();
}
353
354
355
#endif
}
356
#if SDL_VIDEO_OPENGL
357
358
359
360
361
void
dmyfunc (void)
{
}
362
363
364
365
366
367
typedef void (*funcptr) ();
const static struct
{
char *name;
funcptr addr;
368
369
} glfuncs[] = {
#define DEF(func) {#func,&func}
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
DEF (glBegin), DEF (glBindTexture), DEF (glBlendFunc), DEF (glColor4f),
// DEF(glCopyImageID),
DEF (glDisable),
DEF (glEnable),
DEF (glEnd),
DEF (glFlush),
DEF (glGenTextures),
DEF (glGetString),
DEF (glLoadIdentity),
DEF (glMatrixMode), DEF (glOrtho), DEF (glPixelStorei),
// DEF(glPopAttrib),
// DEF(glPopClientAttrib),
{
"glPopAttrib", &dmyfunc}, {
"glPopClientAttrib", &dmyfunc}, DEF (glPopMatrix),
// DEF(glPushAttrib),
// DEF(glPushClientAttrib),
{
"glPushAttrib", &dmyfunc}, {
"glPushClientAttrib", &dmyfunc},
DEF (glPushMatrix),
DEF (glTexCoord2f),
DEF (glTexEnvf),
DEF (glTexImage2D),
DEF (glTexParameteri),
DEF (glTexSubImage2D), DEF (glVertex2i), DEF (glViewport),
396
397
398
#undef DEF
};
399
400
static void *
DC_GL_GetProcAddress (_THIS, const char *proc)
401
{
402
403
void *ret;
int i;
404
405
406
407
ret = glKosGetProcAddress (proc);
if (ret)
return ret;
408
409
410
411
412
for (i = 0; i < sizeof (glfuncs) / sizeof (glfuncs[0]); i++) {
if (SDL_strcmp (proc, glfuncs[i].name) == 0)
return glfuncs[i].addr;
}
413
414
return NULL;
415
416
}
417
418
static int
DC_GL_LoadLibrary (_THIS, const char *path)
419
{
420
this->gl_config.driver_loaded = 1;
421
422
return 0;
423
424
}
425
426
static int
DC_GL_GetAttribute (_THIS, SDL_GLattr attrib, int *value)
427
{
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
GLenum mesa_attrib;
int val;
switch (attrib) {
case SDL_GL_RED_SIZE:
val = 5;
break;
case SDL_GL_GREEN_SIZE:
val = 6;
break;
case SDL_GL_BLUE_SIZE:
val = 5;
break;
case SDL_GL_ALPHA_SIZE:
val = 0;
break;
case SDL_GL_DOUBLEBUFFER:
val = 1;
break;
case SDL_GL_DEPTH_SIZE:
val = 16; /* or 32? */
break;
case SDL_GL_STENCIL_SIZE:
val = 0;
break;
case SDL_GL_ACCUM_RED_SIZE:
val = 0;
break;
case SDL_GL_ACCUM_GREEN_SIZE:
val = 0;
case SDL_GL_ACCUM_BLUE_SIZE:
val = 0;
break;
case SDL_GL_ACCUM_ALPHA_SIZE:
val = 0;
break;
default:
return -1;
}
*value = val;
return 0;
469
470
}
471
472
static void
DC_GL_SwapBuffers (_THIS)
473
{
474
475
glKosFinishFrame ();
glKosBeginFrame ();
476
477
}
#endif
478
/* vi: set ts=4 sw=4 expandtab: */