Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
477 lines (419 loc) · 11.4 KB

SDL_dcvideo.c

File metadata and controls

477 lines (419 loc) · 11.4 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
#include "SDL_video.h"
#include "SDL_mouse.h"
Feb 16, 2006
Feb 16, 2006
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 */
May 29, 2006
May 29, 2006
39
40
41
42
43
44
45
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);
46
47
/* Hardware surface functions */
May 29, 2006
May 29, 2006
48
49
50
51
52
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);
53
54
/* etc. */
May 29, 2006
May 29, 2006
55
static void DC_UpdateRects(_THIS, int numrects, SDL_Rect * rects);
56
57
/* OpenGL */
Mar 2, 2006
Mar 2, 2006
58
#if SDL_VIDEO_OPENGL
May 29, 2006
May 29, 2006
59
60
61
62
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);
Mar 2, 2006
Mar 2, 2006
63
#endif
64
65
66
/* DC driver bootstrap functions */
May 28, 2006
May 28, 2006
67
static int
May 29, 2006
May 29, 2006
68
DC_Available(void)
May 28, 2006
May 28, 2006
70
return 1;
May 28, 2006
May 28, 2006
73
static void
May 29, 2006
May 29, 2006
74
DC_DeleteDevice(SDL_VideoDevice * device)
May 29, 2006
May 29, 2006
76
77
SDL_free(device->hidden);
SDL_free(device);
May 28, 2006
May 28, 2006
80
static SDL_VideoDevice *
May 29, 2006
May 29, 2006
81
DC_CreateDevice(int devindex)
May 28, 2006
May 28, 2006
83
84
85
SDL_VideoDevice *device;
/* Initialize all variables that we clean on shutdown */
May 29, 2006
May 29, 2006
86
device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
May 28, 2006
May 28, 2006
87
if (device) {
May 29, 2006
May 29, 2006
88
SDL_memset(device, 0, (sizeof *device));
May 28, 2006
May 28, 2006
89
device->hidden = (struct SDL_PrivateVideoData *)
May 29, 2006
May 29, 2006
90
SDL_malloc((sizeof *device->hidden));
May 28, 2006
May 28, 2006
91
92
}
if ((device == NULL) || (device->hidden == NULL)) {
May 29, 2006
May 29, 2006
93
SDL_OutOfMemory();
May 28, 2006
May 28, 2006
94
if (device) {
May 29, 2006
May 29, 2006
95
SDL_free(device);
May 28, 2006
May 28, 2006
96
97
98
}
return (0);
}
May 29, 2006
May 29, 2006
99
SDL_memset(device->hidden, 0, (sizeof *device->hidden));
May 28, 2006
May 28, 2006
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* 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;
Feb 16, 2006
Feb 16, 2006
118
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
119
120
121
122
123
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;
May 28, 2006
May 28, 2006
125
126
127
128
129
130
131
device->SetCaption = NULL;
device->SetIcon = NULL;
device->IconifyWindow = NULL;
device->GrabInput = NULL;
device->GetWMInfo = NULL;
device->InitOSKeymap = DC_InitOSKeymap;
device->PumpEvents = DC_PumpEvents;
May 28, 2006
May 28, 2006
133
device->free = DC_DeleteDevice;
May 28, 2006
May 28, 2006
135
return device;
136
137
138
}
VideoBootStrap DC_bootstrap = {
May 28, 2006
May 28, 2006
139
140
"dcvideo", "Dreamcast Video",
DC_Available, DC_CreateDevice
141
142
143
};
May 28, 2006
May 28, 2006
144
int
May 29, 2006
May 29, 2006
145
DC_VideoInit(_THIS, SDL_PixelFormat * vformat)
May 28, 2006
May 28, 2006
147
148
149
150
151
152
153
154
155
/* 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);
May 28, 2006
May 28, 2006
158
159
160
const static SDL_Rect RECT_800x600 = { 0, 0, 800, 600 }, RECT_640x480 = {
0, 0, 640, 480}, RECT_320x240 = {
0, 0, 320, 240};
161
const static SDL_Rect *vid_modes[] = {
May 28, 2006
May 28, 2006
162
163
164
165
&RECT_800x600,
&RECT_640x480,
&RECT_320x240,
NULL
May 28, 2006
May 28, 2006
168
SDL_Rect **
May 29, 2006
May 29, 2006
169
DC_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
May 28, 2006
May 28, 2006
171
172
173
174
175
176
177
178
179
180
181
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;
182
183
184
}
pvr_init_params_t params = {
May 28, 2006
May 28, 2006
185
186
187
188
/* Enable opaque and translucent polygons with size 16 */
{PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0,
PVR_BINSIZE_16}
,
May 28, 2006
May 28, 2006
190
191
/* Vertex buffer size */
512 * 1024
Feb 16, 2006
Feb 16, 2006
194
#if SDL_VIDEO_OPENGL
195
196
197
static int pvr_inited;
#endif
May 28, 2006
May 28, 2006
198
SDL_Surface *
May 29, 2006
May 29, 2006
199
200
DC_SetVideoMode(_THIS, SDL_Surface * current,
int width, int height, int bpp, Uint32 flags)
May 28, 2006
May 28, 2006
202
203
204
205
206
207
208
209
210
211
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 {
May 29, 2006
May 29, 2006
212
SDL_SetError("Couldn't find requested mode in list");
May 28, 2006
May 28, 2006
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
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;
Feb 16, 2006
Feb 16, 2006
241
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
242
if (!(flags & SDL_INTERNALOPENGL))
May 28, 2006
May 28, 2006
244
245
break;
default:
May 29, 2006
May 29, 2006
246
SDL_SetError("Couldn't find requested mode in list");
May 28, 2006
May 28, 2006
247
248
return (NULL);
}
249
250
// if ( bpp != current->format->BitsPerPixel ) {
May 29, 2006
May 29, 2006
251
if (!SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0)) {
May 28, 2006
May 28, 2006
252
253
return (NULL);
}
May 28, 2006
May 28, 2006
256
257
258
259
260
/* Set up the new mode framebuffer */
current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE);
current->w = width;
current->h = height;
current->pitch = pitch;
Feb 16, 2006
Feb 16, 2006
262
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
263
264
if (pvr_inited) {
pvr_inited = 0;
May 29, 2006
May 29, 2006
265
pvr_shutdown();
May 28, 2006
May 28, 2006
266
}
267
268
#endif
May 29, 2006
May 29, 2006
269
vid_set_mode(disp_mode, pixel_mode);
May 28, 2006
May 28, 2006
271
current->pixels = vram_s;
Feb 16, 2006
Feb 16, 2006
273
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
274
275
276
277
278
if (flags & SDL_INTERNALOPENGL) {
this->gl_config.driver_loaded = 1;
current->flags = SDL_FULLSCREEN | SDL_INTERNALOPENGL;
current->pixels = NULL;
pvr_inited = 1;
May 29, 2006
May 29, 2006
279
280
281
pvr_init(&params);
glKosInit();
glKosBeginFrame();
May 28, 2006
May 28, 2006
282
} else
May 28, 2006
May 28, 2006
284
285
286
287
if (flags | SDL_DOUBLEBUF) {
current->flags |= SDL_DOUBLEBUF;
current->pixels = (void *) ((int) current->pixels | 0x400000);
}
May 28, 2006
May 28, 2006
289
290
/* We're done */
return (current);
291
292
293
}
/* We don't actually allow hardware surfaces other than the main one */
May 28, 2006
May 28, 2006
294
static int
May 29, 2006
May 29, 2006
295
DC_AllocHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
297
return (-1);
May 28, 2006
May 28, 2006
299
static void
May 29, 2006
May 29, 2006
300
DC_FreeHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
302
return;
303
304
305
}
/* We need to wait for vertical retrace on page flipped displays */
May 28, 2006
May 28, 2006
306
static int
May 29, 2006
May 29, 2006
307
DC_LockHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
309
return (0);
May 28, 2006
May 28, 2006
312
static void
May 29, 2006
May 29, 2006
313
DC_UnlockHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
315
return;
May 28, 2006
May 28, 2006
318
static int
May 29, 2006
May 29, 2006
319
DC_FlipHWSurface(_THIS, SDL_Surface * surface)
May 28, 2006
May 28, 2006
321
if (surface->flags & SDL_DOUBLEBUF) {
May 29, 2006
May 29, 2006
322
vid_set_start((int) surface->pixels & 0xffffff);
May 28, 2006
May 28, 2006
323
324
325
surface->pixels = (void *) ((int) surface->pixels ^ 0x400000);
}
return (0);
May 28, 2006
May 28, 2006
328
static void
May 29, 2006
May 29, 2006
329
DC_UpdateRects(_THIS, int numrects, SDL_Rect * rects)
May 28, 2006
May 28, 2006
331
/* do nothing. */
May 28, 2006
May 28, 2006
334
static int
May 29, 2006
May 29, 2006
335
DC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
May 28, 2006
May 28, 2006
337
338
/* do nothing of note. */
return (1);
339
340
341
342
343
}
/* Note: If we are terminated, this could be called in the middle of
another SDL video routine -- notably UpdateRects.
*/
May 28, 2006
May 28, 2006
344
static void
May 29, 2006
May 29, 2006
345
DC_VideoQuit(_THIS)
Feb 16, 2006
Feb 16, 2006
347
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
348
349
if (pvr_inited) {
pvr_inited = 0;
May 29, 2006
May 29, 2006
350
pvr_shutdown();
May 28, 2006
May 28, 2006
351
}
352
353
354
#endif
}
Feb 16, 2006
Feb 16, 2006
355
#if SDL_VIDEO_OPENGL
May 28, 2006
May 28, 2006
357
void
May 29, 2006
May 29, 2006
358
dmyfunc(void)
May 28, 2006
May 28, 2006
359
360
{
}
May 28, 2006
May 28, 2006
362
363
364
365
366
typedef void (*funcptr) ();
const static struct
{
char *name;
funcptr addr;
367
368
} glfuncs[] = {
#define DEF(func) {#func,&func}
May 29, 2006
May 29, 2006
369
DEF(glBegin), DEF(glBindTexture), DEF(glBlendFunc), DEF(glColor4f),
May 28, 2006
May 28, 2006
370
// DEF(glCopyImageID),
May 29, 2006
May 29, 2006
371
372
373
374
375
376
377
378
DEF(glDisable),
DEF(glEnable),
DEF(glEnd),
DEF(glFlush),
DEF(glGenTextures),
DEF(glGetString),
DEF(glLoadIdentity),
DEF(glMatrixMode), DEF(glOrtho), DEF(glPixelStorei),
May 28, 2006
May 28, 2006
379
380
381
382
// DEF(glPopAttrib),
// DEF(glPopClientAttrib),
{
"glPopAttrib", &dmyfunc}, {
May 29, 2006
May 29, 2006
383
"glPopClientAttrib", &dmyfunc}, DEF(glPopMatrix),
May 28, 2006
May 28, 2006
384
385
386
387
388
// DEF(glPushAttrib),
// DEF(glPushClientAttrib),
{
"glPushAttrib", &dmyfunc}, {
"glPushClientAttrib", &dmyfunc},
May 29, 2006
May 29, 2006
389
390
391
392
393
394
DEF(glPushMatrix),
DEF(glTexCoord2f),
DEF(glTexEnvf),
DEF(glTexImage2D),
DEF(glTexParameteri),
DEF(glTexSubImage2D), DEF(glVertex2i), DEF(glViewport),
395
396
397
#undef DEF
};
May 28, 2006
May 28, 2006
398
static void *
May 29, 2006
May 29, 2006
399
DC_GL_GetProcAddress(_THIS, const char *proc)
May 28, 2006
May 28, 2006
401
402
void *ret;
int i;
May 29, 2006
May 29, 2006
404
ret = glKosGetProcAddress(proc);
May 28, 2006
May 28, 2006
405
406
if (ret)
return ret;
May 29, 2006
May 29, 2006
408
409
for (i = 0; i < sizeof(glfuncs) / sizeof(glfuncs[0]); i++) {
if (SDL_strcmp(proc, glfuncs[i].name) == 0)
May 28, 2006
May 28, 2006
410
411
return glfuncs[i].addr;
}
May 28, 2006
May 28, 2006
413
return NULL;
May 28, 2006
May 28, 2006
416
static int
May 29, 2006
May 29, 2006
417
DC_GL_LoadLibrary(_THIS, const char *path)
May 28, 2006
May 28, 2006
419
this->gl_config.driver_loaded = 1;
May 28, 2006
May 28, 2006
421
return 0;
May 28, 2006
May 28, 2006
424
static int
May 29, 2006
May 29, 2006
425
DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int *value)
May 28, 2006
May 28, 2006
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
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;
May 28, 2006
May 28, 2006
470
static void
May 29, 2006
May 29, 2006
471
DC_GL_SwapBuffers(_THIS)
May 29, 2006
May 29, 2006
473
474
glKosFinishFrame();
glKosBeginFrame();
475
476
}
#endif
May 28, 2006
May 28, 2006
477
/* vi: set ts=4 sw=4 expandtab: */