2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
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.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "SDL_config.h"
24 #include "SDL_video.h"
25 #include "SDL_mouse.h"
26 #include "../SDL_sysvideo.h"
27 #include "../SDL_pixels_c.h"
28 #include "../../events/SDL_events_c.h"
30 #include "SDL_dcvideo.h"
31 #include "SDL_dcevents_c.h"
32 #include "SDL_dcmouse_c.h"
38 /* Initialization/Query functions */
39 static int DC_VideoInit(_THIS, SDL_PixelFormat *vformat);
40 static SDL_Rect **DC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
41 static SDL_Surface *DC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags);
42 static int DC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
43 static void DC_VideoQuit(_THIS);
45 /* Hardware surface functions */
46 static int DC_AllocHWSurface(_THIS, SDL_Surface *surface);
47 static int DC_LockHWSurface(_THIS, SDL_Surface *surface);
48 static void DC_UnlockHWSurface(_THIS, SDL_Surface *surface);
49 static void DC_FreeHWSurface(_THIS, SDL_Surface *surface);
50 static int DC_FlipHWSurface(_THIS, SDL_Surface *surface);
53 static void DC_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
57 static void *DC_GL_GetProcAddress(_THIS, const char *proc);
58 static int DC_GL_LoadLibrary(_THIS, const char *path);
59 static int DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
60 static void DC_GL_SwapBuffers(_THIS);
63 /* DC driver bootstrap functions */
65 static int DC_Available(void)
70 static void DC_DeleteDevice(SDL_VideoDevice *device)
72 SDL_free(device->hidden);
76 static SDL_VideoDevice *DC_CreateDevice(int devindex)
78 SDL_VideoDevice *device;
80 /* Initialize all variables that we clean on shutdown */
81 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
83 SDL_memset(device, 0, (sizeof *device));
84 device->hidden = (struct SDL_PrivateVideoData *)
85 SDL_malloc((sizeof *device->hidden));
87 if ( (device == NULL) || (device->hidden == NULL) ) {
94 SDL_memset(device->hidden, 0, (sizeof *device->hidden));
96 /* Set the function pointers */
97 device->VideoInit = DC_VideoInit;
98 device->ListModes = DC_ListModes;
99 device->SetVideoMode = DC_SetVideoMode;
100 device->CreateYUVOverlay = NULL;
101 device->SetColors = DC_SetColors;
102 device->UpdateRects = DC_UpdateRects;
103 device->VideoQuit = DC_VideoQuit;
104 device->AllocHWSurface = DC_AllocHWSurface;
105 device->CheckHWBlit = NULL;
106 device->FillHWRect = NULL;
107 device->SetHWColorKey = NULL;
108 device->SetHWAlpha = NULL;
109 device->LockHWSurface = DC_LockHWSurface;
110 device->UnlockHWSurface = DC_UnlockHWSurface;
111 device->FlipHWSurface = DC_FlipHWSurface;
112 device->FreeHWSurface = DC_FreeHWSurface;
114 device->GL_LoadLibrary = DC_GL_LoadLibrary;
115 device->GL_GetProcAddress = DC_GL_GetProcAddress;
116 device->GL_GetAttribute = DC_GL_GetAttribute;
117 device->GL_MakeCurrent = NULL;
118 device->GL_SwapBuffers = DC_GL_SwapBuffers;
120 device->SetCaption = NULL;
121 device->SetIcon = NULL;
122 device->IconifyWindow = NULL;
123 device->GrabInput = NULL;
124 device->GetWMInfo = NULL;
125 device->InitOSKeymap = DC_InitOSKeymap;
126 device->PumpEvents = DC_PumpEvents;
128 device->free = DC_DeleteDevice;
133 VideoBootStrap DC_bootstrap = {
134 "dcvideo", "Dreamcast Video",
135 DC_Available, DC_CreateDevice
139 int DC_VideoInit(_THIS, SDL_PixelFormat *vformat)
141 /* Determine the screen depth (use default 16-bit depth) */
142 /* we change this during the SDL_SetVideoMode implementation... */
143 vformat->BitsPerPixel = 16;
144 vformat->Rmask = 0x0000f800;
145 vformat->Gmask = 0x000007e0;
146 vformat->Bmask = 0x0000001f;
152 const static SDL_Rect
153 RECT_800x600 = {0,0,800,600},
154 RECT_640x480 = {0,0,640,480},
155 RECT_320x240 = {0,0,320,240};
156 const static SDL_Rect *vid_modes[] = {
163 SDL_Rect **DC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags)
165 switch(format->BitsPerPixel) {
170 if (!(flags & SDL_OPENGL))
175 // return (SDL_Rect **) -1;
178 pvr_init_params_t params = {
179 /* Enable opaque and translucent polygons with size 16 */
180 { PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16, PVR_BINSIZE_0, PVR_BINSIZE_16 },
182 /* Vertex buffer size */
187 static int pvr_inited;
190 SDL_Surface *DC_SetVideoMode(_THIS, SDL_Surface *current,
191 int width, int height, int bpp, Uint32 flags)
193 int disp_mode,pixel_mode,pitch;
194 Uint32 Rmask, Gmask, Bmask;
196 if (width==320 && height==240) disp_mode=DM_320x240;
197 else if (width==640 && height==480) disp_mode=DM_640x480;
198 else if (width==800 && height==600) disp_mode=DM_800x608;
200 SDL_SetError("Couldn't find requested mode in list");
205 case 15: pixel_mode = PM_RGB555; pitch = width*2;
211 case 16: pixel_mode = PM_RGB565; pitch = width*2;
218 case 32: pixel_mode = PM_RGB888; pitch = width*4;
223 if (!(flags & SDL_OPENGL))
227 SDL_SetError("Couldn't find requested mode in list");
231 // if ( bpp != current->format->BitsPerPixel ) {
232 if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) {
237 /* Set up the new mode framebuffer */
238 current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
241 current->pitch = pitch;
250 vid_set_mode(disp_mode,pixel_mode);
252 current->pixels = vram_s;
255 if (flags & SDL_OPENGL) {
256 this->gl_config.driver_loaded = 1;
257 current->flags = SDL_FULLSCREEN | SDL_OPENGL;
258 current->pixels = NULL;
265 if (flags | SDL_DOUBLEBUF) {
266 current->flags |= SDL_DOUBLEBUF;
267 current->pixels = (void*)((int)current->pixels | 0x400000);
274 /* We don't actually allow hardware surfaces other than the main one */
275 static int DC_AllocHWSurface(_THIS, SDL_Surface *surface)
279 static void DC_FreeHWSurface(_THIS, SDL_Surface *surface)
284 /* We need to wait for vertical retrace on page flipped displays */
285 static int DC_LockHWSurface(_THIS, SDL_Surface *surface)
290 static void DC_UnlockHWSurface(_THIS, SDL_Surface *surface)
295 static int DC_FlipHWSurface(_THIS, SDL_Surface *surface)
297 if (surface->flags & SDL_DOUBLEBUF) {
298 vid_set_start((int)surface->pixels & 0xffffff);
299 surface->pixels = (void*)((int)surface->pixels ^ 0x400000);
304 static void DC_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
309 static int DC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
311 /* do nothing of note. */
315 /* Note: If we are terminated, this could be called in the middle of
316 another SDL video routine -- notably UpdateRects.
318 static void DC_VideoQuit(_THIS)
330 void dmyfunc(void) {}
332 typedef void (*funcptr)();
333 const static struct {
337 #define DEF(func) {#func,&func}
342 // DEF(glCopyImageID),
354 // DEF(glPopClientAttrib),
355 {"glPopAttrib",&dmyfunc},
356 {"glPopClientAttrib",&dmyfunc},
358 // DEF(glPushAttrib),
359 // DEF(glPushClientAttrib),
360 {"glPushAttrib",&dmyfunc},
361 {"glPushClientAttrib",&dmyfunc},
366 DEF(glTexParameteri),
367 DEF(glTexSubImage2D),
373 static void *DC_GL_GetProcAddress(_THIS, const char *proc)
378 ret = glKosGetProcAddress(proc);
381 for(i=0;i<sizeof(glfuncs)/sizeof(glfuncs[0]);i++) {
382 if (SDL_strcmp(proc,glfuncs[i].name)==0) return glfuncs[i].addr;
388 static int DC_GL_LoadLibrary(_THIS, const char *path)
390 this->gl_config.driver_loaded = 1;
395 static int DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
401 case SDL_GL_RED_SIZE:
404 case SDL_GL_GREEN_SIZE:
407 case SDL_GL_BLUE_SIZE:
410 case SDL_GL_ALPHA_SIZE:
413 case SDL_GL_DOUBLEBUFFER:
416 case SDL_GL_DEPTH_SIZE:
417 val = 16; /* or 32? */
419 case SDL_GL_STENCIL_SIZE:
422 case SDL_GL_ACCUM_RED_SIZE:
425 case SDL_GL_ACCUM_GREEN_SIZE:
427 case SDL_GL_ACCUM_BLUE_SIZE:
430 case SDL_GL_ACCUM_ALPHA_SIZE:
440 static void DC_GL_SwapBuffers(_THIS)