diff options
author | Franklin Wei <git@fwei.tk> | 2017-01-21 15:18:31 -0500 |
---|---|---|
committer | Franklin Wei <git@fwei.tk> | 2017-12-23 21:01:26 -0500 |
commit | a855d6202536ff28e5aae4f22a0f31d8f5b325d0 (patch) | |
tree | 8c75f224dd64ed360505afa8843d016b0d75000b /apps/plugins/sdl/src/video/dc | |
parent | 01c6dcf6c7b9bb1ad2fa0450f99bacc5f3d3e04b (diff) | |
download | rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.tar.gz rockbox-a855d6202536ff28e5aae4f22a0f31d8f5b325d0.zip |
Port of Duke Nukem 3D
This ports Fabien Sanglard's Chocolate Duke to run on a version of SDL
for Rockbox.
Change-Id: I8f2c4c78af19de10c1633ed7bb7a997b43256dd9
Diffstat (limited to 'apps/plugins/sdl/src/video/dc')
-rw-r--r-- | apps/plugins/sdl/src/video/dc/SDL_dcevents.c | 152 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/dc/SDL_dcevents_c.h | 33 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/dc/SDL_dcmouse.c | 35 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/dc/SDL_dcmouse_c.h | 26 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/dc/SDL_dcvideo.c | 445 | ||||
-rw-r--r-- | apps/plugins/sdl/src/video/dc/SDL_dcvideo.h | 42 |
6 files changed, 733 insertions, 0 deletions
diff --git a/apps/plugins/sdl/src/video/dc/SDL_dcevents.c b/apps/plugins/sdl/src/video/dc/SDL_dcevents.c new file mode 100644 index 0000000000..38dcca4e5b --- /dev/null +++ b/apps/plugins/sdl/src/video/dc/SDL_dcevents.c | |||
@@ -0,0 +1,152 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | 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. | ||
14 | |||
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 | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #include "SDL.h" | ||
25 | #include "../../events/SDL_sysevents.h" | ||
26 | #include "../../events/SDL_events_c.h" | ||
27 | #include "SDL_dcvideo.h" | ||
28 | #include "SDL_dcevents_c.h" | ||
29 | |||
30 | #include <dc/maple.h> | ||
31 | #include <dc/maple/mouse.h> | ||
32 | #include <dc/maple/keyboard.h> | ||
33 | |||
34 | const static unsigned short sdl_key[]= { | ||
35 | /*0*/ 0, 0, 0, 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', | ||
36 | 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', | ||
37 | 'u', 'v', 'w', 'x', 'y', 'z', | ||
38 | /*1e*/ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', | ||
39 | /*28*/ SDLK_RETURN, SDLK_ESCAPE, SDLK_BACKSPACE, SDLK_TAB, SDLK_SPACE, SDLK_MINUS, SDLK_PLUS, SDLK_LEFTBRACKET, | ||
40 | SDLK_RIGHTBRACKET, SDLK_BACKSLASH , 0, SDLK_SEMICOLON, SDLK_QUOTE, | ||
41 | /*35*/ '~', SDLK_COMMA, SDLK_PERIOD, SDLK_SLASH, SDLK_CAPSLOCK, | ||
42 | SDLK_F1, SDLK_F2, SDLK_F3, SDLK_F4, SDLK_F5, SDLK_F6, SDLK_F7, SDLK_F8, SDLK_F9, SDLK_F10, SDLK_F11, SDLK_F12, | ||
43 | /*46*/ SDLK_PRINT, SDLK_SCROLLOCK, SDLK_PAUSE, SDLK_INSERT, SDLK_HOME, SDLK_PAGEUP, SDLK_DELETE, SDLK_END, SDLK_PAGEDOWN, SDLK_RIGHT, SDLK_LEFT, SDLK_DOWN, SDLK_UP, | ||
44 | /*53*/ SDLK_NUMLOCK, SDLK_KP_DIVIDE, SDLK_KP_MULTIPLY, SDLK_KP_MINUS, SDLK_KP_PLUS, SDLK_KP_ENTER, | ||
45 | SDLK_KP1, SDLK_KP2, SDLK_KP3, SDLK_KP4, SDLK_KP5, SDLK_KP6, | ||
46 | /*5f*/ SDLK_KP7, SDLK_KP8, SDLK_KP9, SDLK_KP0, SDLK_KP_PERIOD, 0 /* S3 */ | ||
47 | }; | ||
48 | |||
49 | const static unsigned short sdl_shift[] = { | ||
50 | SDLK_LCTRL,SDLK_LSHIFT,SDLK_LALT,0 /* S1 */, | ||
51 | SDLK_RCTRL,SDLK_RSHIFT,SDLK_RALT,0 /* S2 */, | ||
52 | }; | ||
53 | |||
54 | #define MOUSE_WHEELUP (1<<4) | ||
55 | #define MOUSE_WHEELDOWN (1<<5) | ||
56 | |||
57 | static void mouse_update(void) | ||
58 | { | ||
59 | const static char sdl_mousebtn[] = { | ||
60 | MOUSE_LEFTBUTTON, | ||
61 | MOUSE_RIGHTBUTTON, | ||
62 | MOUSE_SIDEBUTTON, | ||
63 | MOUSE_WHEELUP, | ||
64 | MOUSE_WHEELDOWN | ||
65 | }; | ||
66 | |||
67 | uint8 addr; | ||
68 | mouse_cond_t cond; | ||
69 | |||
70 | static int prev_buttons; | ||
71 | int buttons,changed; | ||
72 | int i; | ||
73 | |||
74 | if ((addr = maple_first_mouse())==0 || mouse_get_cond(addr, &cond)<0) return; | ||
75 | |||
76 | buttons = cond.buttons^0xff; | ||
77 | if (cond.dz<0) buttons|=MOUSE_WHEELUP; | ||
78 | if (cond.dz>0) buttons|=MOUSE_WHEELDOWN; | ||
79 | |||
80 | if (cond.dx||cond.dy) SDL_PrivateMouseMotion(0,1,cond.dx,cond.dy); | ||
81 | |||
82 | changed = buttons^prev_buttons; | ||
83 | for(i=0;i<sizeof(sdl_mousebtn);i++) { | ||
84 | if (changed & sdl_mousebtn[i]) { | ||
85 | SDL_PrivateMouseButton((buttons & sdl_mousebtn[i])?SDL_PRESSED:SDL_RELEASED,i,0,0); | ||
86 | } | ||
87 | } | ||
88 | prev_buttons = buttons; | ||
89 | } | ||
90 | |||
91 | static void keyboard_update(void) | ||
92 | { | ||
93 | static kbd_state_t old_state; | ||
94 | static uint8 old_addr; | ||
95 | |||
96 | kbd_state_t *state; | ||
97 | uint8 addr; | ||
98 | int port,unit; | ||
99 | |||
100 | int shiftkeys; | ||
101 | SDL_keysym keysym; | ||
102 | |||
103 | int i; | ||
104 | |||
105 | addr = maple_first_kb(); | ||
106 | |||
107 | if (addr==0) return; | ||
108 | |||
109 | if (addr!=old_addr) { | ||
110 | old_addr = addr; | ||
111 | SDL_memset(&old_state,0,sizeof(old_state)); | ||
112 | } | ||
113 | |||
114 | maple_raddr(addr,&port,&unit); | ||
115 | |||
116 | state = maple_dev_state(port,unit); | ||
117 | if (!state) return; | ||
118 | |||
119 | shiftkeys = state->shift_keys ^ old_state.shift_keys; | ||
120 | for(i=0;i<sizeof(sdl_shift);i++) { | ||
121 | if ((shiftkeys>>i)&1) { | ||
122 | keysym.sym = sdl_shift[i]; | ||
123 | SDL_PrivateKeyboard(((state->shift_keys>>i)&1)?SDL_PRESSED:SDL_RELEASED,&keysym); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | for(i=0;i<sizeof(sdl_key);i++) { | ||
128 | if (state->matrix[i]!=old_state.matrix[i]) { | ||
129 | int key = sdl_key[i]; | ||
130 | if (key) { | ||
131 | keysym.sym = key; | ||
132 | SDL_PrivateKeyboard(state->matrix[i]?SDL_PRESSED:SDL_RELEASED,&keysym); | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | |||
137 | old_state = *state; | ||
138 | } | ||
139 | |||
140 | void DC_PumpEvents(_THIS) | ||
141 | { | ||
142 | keyboard_update(); | ||
143 | mouse_update(); | ||
144 | } | ||
145 | |||
146 | void DC_InitOSKeymap(_THIS) | ||
147 | { | ||
148 | /* do nothing. */ | ||
149 | } | ||
150 | |||
151 | /* end of SDL_dcevents.c ... */ | ||
152 | |||
diff --git a/apps/plugins/sdl/src/video/dc/SDL_dcevents_c.h b/apps/plugins/sdl/src/video/dc/SDL_dcevents_c.h new file mode 100644 index 0000000000..3196eae47d --- /dev/null +++ b/apps/plugins/sdl/src/video/dc/SDL_dcevents_c.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | 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. | ||
14 | |||
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 | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #include "SDL_dcvideo.h" | ||
25 | |||
26 | /* Variables and functions exported by SDL_sysevents.c to other parts | ||
27 | of the native video subsystem (SDL_sysvideo.c) | ||
28 | */ | ||
29 | extern void DC_InitOSKeymap(_THIS); | ||
30 | extern void DC_PumpEvents(_THIS); | ||
31 | |||
32 | /* end of SDL_dcevents_c.h ... */ | ||
33 | |||
diff --git a/apps/plugins/sdl/src/video/dc/SDL_dcmouse.c b/apps/plugins/sdl/src/video/dc/SDL_dcmouse.c new file mode 100644 index 0000000000..61a0ba028c --- /dev/null +++ b/apps/plugins/sdl/src/video/dc/SDL_dcmouse.c | |||
@@ -0,0 +1,35 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | 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. | ||
14 | |||
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 | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #include <stdio.h> | ||
25 | |||
26 | #include "SDL_mouse.h" | ||
27 | #include "../../events/SDL_events_c.h" | ||
28 | |||
29 | #include "SDL_dcmouse_c.h" | ||
30 | |||
31 | |||
32 | /* The implementation dependent data for the window manager cursor */ | ||
33 | struct WMcursor { | ||
34 | int unused; | ||
35 | }; | ||
diff --git a/apps/plugins/sdl/src/video/dc/SDL_dcmouse_c.h b/apps/plugins/sdl/src/video/dc/SDL_dcmouse_c.h new file mode 100644 index 0000000000..dc018bb164 --- /dev/null +++ b/apps/plugins/sdl/src/video/dc/SDL_dcmouse_c.h | |||
@@ -0,0 +1,26 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | 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. | ||
14 | |||
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 | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #include "SDL_dcvideo.h" | ||
25 | |||
26 | /* Functions to be exported */ | ||
diff --git a/apps/plugins/sdl/src/video/dc/SDL_dcvideo.c b/apps/plugins/sdl/src/video/dc/SDL_dcvideo.c new file mode 100644 index 0000000000..5838a49a32 --- /dev/null +++ b/apps/plugins/sdl/src/video/dc/SDL_dcvideo.c | |||
@@ -0,0 +1,445 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | 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. | ||
14 | |||
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 | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
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" | ||
29 | |||
30 | #include "SDL_dcvideo.h" | ||
31 | #include "SDL_dcevents_c.h" | ||
32 | #include "SDL_dcmouse_c.h" | ||
33 | |||
34 | #include <dc/video.h> | ||
35 | #include <dc/pvr.h> | ||
36 | |||
37 | |||
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); | ||
44 | |||
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); | ||
51 | |||
52 | /* etc. */ | ||
53 | static void DC_UpdateRects(_THIS, int numrects, SDL_Rect *rects); | ||
54 | |||
55 | /* OpenGL */ | ||
56 | #if SDL_VIDEO_OPENGL | ||
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); | ||
61 | #endif | ||
62 | |||
63 | /* DC driver bootstrap functions */ | ||
64 | |||
65 | static int DC_Available(void) | ||
66 | { | ||
67 | return 1; | ||
68 | } | ||
69 | |||
70 | static void DC_DeleteDevice(SDL_VideoDevice *device) | ||
71 | { | ||
72 | SDL_free(device->hidden); | ||
73 | SDL_free(device); | ||
74 | } | ||
75 | |||
76 | static SDL_VideoDevice *DC_CreateDevice(int devindex) | ||
77 | { | ||
78 | SDL_VideoDevice *device; | ||
79 | |||
80 | /* Initialize all variables that we clean on shutdown */ | ||
81 | device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); | ||
82 | if ( device ) { | ||
83 | SDL_memset(device, 0, (sizeof *device)); | ||
84 | device->hidden = (struct SDL_PrivateVideoData *) | ||
85 | SDL_malloc((sizeof *device->hidden)); | ||
86 | } | ||
87 | if ( (device == NULL) || (device->hidden == NULL) ) { | ||
88 | SDL_OutOfMemory(); | ||
89 | if ( device ) { | ||
90 | SDL_free(device); | ||
91 | } | ||
92 | return(0); | ||
93 | } | ||
94 | SDL_memset(device->hidden, 0, (sizeof *device->hidden)); | ||
95 | |||
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; | ||
113 | #if SDL_VIDEO_OPENGL | ||
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; | ||
119 | #endif | ||
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; | ||
127 | |||
128 | device->free = DC_DeleteDevice; | ||
129 | |||
130 | return device; | ||
131 | } | ||
132 | |||
133 | VideoBootStrap DC_bootstrap = { | ||
134 | "dcvideo", "Dreamcast Video", | ||
135 | DC_Available, DC_CreateDevice | ||
136 | }; | ||
137 | |||
138 | |||
139 | int DC_VideoInit(_THIS, SDL_PixelFormat *vformat) | ||
140 | { | ||
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; | ||
147 | |||
148 | /* We're done! */ | ||
149 | return(0); | ||
150 | } | ||
151 | |||
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[] = { | ||
157 | &RECT_800x600, | ||
158 | &RECT_640x480, | ||
159 | &RECT_320x240, | ||
160 | NULL | ||
161 | }; | ||
162 | |||
163 | SDL_Rect **DC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | ||
164 | { | ||
165 | switch(format->BitsPerPixel) { | ||
166 | case 15: | ||
167 | case 16: | ||
168 | return &vid_modes; | ||
169 | case 32: | ||
170 | if (!(flags & SDL_OPENGL)) | ||
171 | return &vid_modes; | ||
172 | default: | ||
173 | return NULL; | ||
174 | } | ||
175 | // return (SDL_Rect **) -1; | ||
176 | } | ||
177 | |||
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 }, | ||
181 | |||
182 | /* Vertex buffer size */ | ||
183 | 512*1024 | ||
184 | }; | ||
185 | |||
186 | #if SDL_VIDEO_OPENGL | ||
187 | static int pvr_inited; | ||
188 | #endif | ||
189 | |||
190 | SDL_Surface *DC_SetVideoMode(_THIS, SDL_Surface *current, | ||
191 | int width, int height, int bpp, Uint32 flags) | ||
192 | { | ||
193 | int disp_mode,pixel_mode,pitch; | ||
194 | Uint32 Rmask, Gmask, Bmask; | ||
195 | |||
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; | ||
199 | else { | ||
200 | SDL_SetError("Couldn't find requested mode in list"); | ||
201 | return(NULL); | ||
202 | } | ||
203 | |||
204 | switch(bpp) { | ||
205 | case 15: pixel_mode = PM_RGB555; pitch = width*2; | ||
206 | /* 5-5-5 */ | ||
207 | Rmask = 0x00007c00; | ||
208 | Gmask = 0x000003e0; | ||
209 | Bmask = 0x0000001f; | ||
210 | break; | ||
211 | case 16: pixel_mode = PM_RGB565; pitch = width*2; | ||
212 | /* 5-6-5 */ | ||
213 | Rmask = 0x0000f800; | ||
214 | Gmask = 0x000007e0; | ||
215 | Bmask = 0x0000001f; | ||
216 | break; | ||
217 | case 24: bpp = 32; | ||
218 | case 32: pixel_mode = PM_RGB888; pitch = width*4; | ||
219 | Rmask = 0x00ff0000; | ||
220 | Gmask = 0x0000ff00; | ||
221 | Bmask = 0x000000ff; | ||
222 | #if SDL_VIDEO_OPENGL | ||
223 | if (!(flags & SDL_OPENGL)) | ||
224 | #endif | ||
225 | break; | ||
226 | default: | ||
227 | SDL_SetError("Couldn't find requested mode in list"); | ||
228 | return(NULL); | ||
229 | } | ||
230 | |||
231 | // if ( bpp != current->format->BitsPerPixel ) { | ||
232 | if ( ! SDL_ReallocFormat(current, bpp, Rmask, Gmask, Bmask, 0) ) { | ||
233 | return(NULL); | ||
234 | } | ||
235 | // } | ||
236 | |||
237 | /* Set up the new mode framebuffer */ | ||
238 | current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); | ||
239 | current->w = width; | ||
240 | current->h = height; | ||
241 | current->pitch = pitch; | ||
242 | |||
243 | #if SDL_VIDEO_OPENGL | ||
244 | if (pvr_inited) { | ||
245 | pvr_inited = 0; | ||
246 | pvr_shutdown(); | ||
247 | } | ||
248 | #endif | ||
249 | |||
250 | vid_set_mode(disp_mode,pixel_mode); | ||
251 | |||
252 | current->pixels = vram_s; | ||
253 | |||
254 | #if SDL_VIDEO_OPENGL | ||
255 | if (flags & SDL_OPENGL) { | ||
256 | this->gl_config.driver_loaded = 1; | ||
257 | current->flags = SDL_FULLSCREEN | SDL_OPENGL; | ||
258 | current->pixels = NULL; | ||
259 | pvr_inited = 1; | ||
260 | pvr_init(¶ms); | ||
261 | glKosInit(); | ||
262 | glKosBeginFrame(); | ||
263 | } else | ||
264 | #endif | ||
265 | if (flags | SDL_DOUBLEBUF) { | ||
266 | current->flags |= SDL_DOUBLEBUF; | ||
267 | current->pixels = (void*)((int)current->pixels | 0x400000); | ||
268 | } | ||
269 | |||
270 | /* We're done */ | ||
271 | return(current); | ||
272 | } | ||
273 | |||
274 | /* We don't actually allow hardware surfaces other than the main one */ | ||
275 | static int DC_AllocHWSurface(_THIS, SDL_Surface *surface) | ||
276 | { | ||
277 | return(-1); | ||
278 | } | ||
279 | static void DC_FreeHWSurface(_THIS, SDL_Surface *surface) | ||
280 | { | ||
281 | return; | ||
282 | } | ||
283 | |||
284 | /* We need to wait for vertical retrace on page flipped displays */ | ||
285 | static int DC_LockHWSurface(_THIS, SDL_Surface *surface) | ||
286 | { | ||
287 | return(0); | ||
288 | } | ||
289 | |||
290 | static void DC_UnlockHWSurface(_THIS, SDL_Surface *surface) | ||
291 | { | ||
292 | return; | ||
293 | } | ||
294 | |||
295 | static int DC_FlipHWSurface(_THIS, SDL_Surface *surface) | ||
296 | { | ||
297 | if (surface->flags & SDL_DOUBLEBUF) { | ||
298 | vid_set_start((int)surface->pixels & 0xffffff); | ||
299 | surface->pixels = (void*)((int)surface->pixels ^ 0x400000); | ||
300 | } | ||
301 | return(0); | ||
302 | } | ||
303 | |||
304 | static void DC_UpdateRects(_THIS, int numrects, SDL_Rect *rects) | ||
305 | { | ||
306 | /* do nothing. */ | ||
307 | } | ||
308 | |||
309 | static int DC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | ||
310 | { | ||
311 | /* do nothing of note. */ | ||
312 | return(1); | ||
313 | } | ||
314 | |||
315 | /* Note: If we are terminated, this could be called in the middle of | ||
316 | another SDL video routine -- notably UpdateRects. | ||
317 | */ | ||
318 | static void DC_VideoQuit(_THIS) | ||
319 | { | ||
320 | #if SDL_VIDEO_OPENGL | ||
321 | if (pvr_inited) { | ||
322 | pvr_inited = 0; | ||
323 | pvr_shutdown(); | ||
324 | } | ||
325 | #endif | ||
326 | } | ||
327 | |||
328 | #if SDL_VIDEO_OPENGL | ||
329 | |||
330 | void dmyfunc(void) {} | ||
331 | |||
332 | typedef void (*funcptr)(); | ||
333 | const static struct { | ||
334 | char *name; | ||
335 | funcptr addr; | ||
336 | } glfuncs[] = { | ||
337 | #define DEF(func) {#func,&func} | ||
338 | DEF(glBegin), | ||
339 | DEF(glBindTexture), | ||
340 | DEF(glBlendFunc), | ||
341 | DEF(glColor4f), | ||
342 | // DEF(glCopyImageID), | ||
343 | DEF(glDisable), | ||
344 | DEF(glEnable), | ||
345 | DEF(glEnd), | ||
346 | DEF(glFlush), | ||
347 | DEF(glGenTextures), | ||
348 | DEF(glGetString), | ||
349 | DEF(glLoadIdentity), | ||
350 | DEF(glMatrixMode), | ||
351 | DEF(glOrtho), | ||
352 | DEF(glPixelStorei), | ||
353 | // DEF(glPopAttrib), | ||
354 | // DEF(glPopClientAttrib), | ||
355 | {"glPopAttrib",&dmyfunc}, | ||
356 | {"glPopClientAttrib",&dmyfunc}, | ||
357 | DEF(glPopMatrix), | ||
358 | // DEF(glPushAttrib), | ||
359 | // DEF(glPushClientAttrib), | ||
360 | {"glPushAttrib",&dmyfunc}, | ||
361 | {"glPushClientAttrib",&dmyfunc}, | ||
362 | DEF(glPushMatrix), | ||
363 | DEF(glTexCoord2f), | ||
364 | DEF(glTexEnvf), | ||
365 | DEF(glTexImage2D), | ||
366 | DEF(glTexParameteri), | ||
367 | DEF(glTexSubImage2D), | ||
368 | DEF(glVertex2i), | ||
369 | DEF(glViewport), | ||
370 | #undef DEF | ||
371 | }; | ||
372 | |||
373 | static void *DC_GL_GetProcAddress(_THIS, const char *proc) | ||
374 | { | ||
375 | void *ret; | ||
376 | int i; | ||
377 | |||
378 | ret = glKosGetProcAddress(proc); | ||
379 | if (ret) return ret; | ||
380 | |||
381 | for(i=0;i<sizeof(glfuncs)/sizeof(glfuncs[0]);i++) { | ||
382 | if (SDL_strcmp(proc,glfuncs[i].name)==0) return glfuncs[i].addr; | ||
383 | } | ||
384 | |||
385 | return NULL; | ||
386 | } | ||
387 | |||
388 | static int DC_GL_LoadLibrary(_THIS, const char *path) | ||
389 | { | ||
390 | this->gl_config.driver_loaded = 1; | ||
391 | |||
392 | return 0; | ||
393 | } | ||
394 | |||
395 | static int DC_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value) | ||
396 | { | ||
397 | GLenum mesa_attrib; | ||
398 | int val; | ||
399 | |||
400 | switch(attrib) { | ||
401 | case SDL_GL_RED_SIZE: | ||
402 | val = 5; | ||
403 | break; | ||
404 | case SDL_GL_GREEN_SIZE: | ||
405 | val = 6; | ||
406 | break; | ||
407 | case SDL_GL_BLUE_SIZE: | ||
408 | val = 5; | ||
409 | break; | ||
410 | case SDL_GL_ALPHA_SIZE: | ||
411 | val = 0; | ||
412 | break; | ||
413 | case SDL_GL_DOUBLEBUFFER: | ||
414 | val = 1; | ||
415 | break; | ||
416 | case SDL_GL_DEPTH_SIZE: | ||
417 | val = 16; /* or 32? */ | ||
418 | break; | ||
419 | case SDL_GL_STENCIL_SIZE: | ||
420 | val = 0; | ||
421 | break; | ||
422 | case SDL_GL_ACCUM_RED_SIZE: | ||
423 | val = 0; | ||
424 | break; | ||
425 | case SDL_GL_ACCUM_GREEN_SIZE: | ||
426 | val = 0; | ||
427 | case SDL_GL_ACCUM_BLUE_SIZE: | ||
428 | val = 0; | ||
429 | break; | ||
430 | case SDL_GL_ACCUM_ALPHA_SIZE: | ||
431 | val = 0; | ||
432 | break; | ||
433 | default : | ||
434 | return -1; | ||
435 | } | ||
436 | *value = val; | ||
437 | return 0; | ||
438 | } | ||
439 | |||
440 | static void DC_GL_SwapBuffers(_THIS) | ||
441 | { | ||
442 | glKosFinishFrame(); | ||
443 | glKosBeginFrame(); | ||
444 | } | ||
445 | #endif | ||
diff --git a/apps/plugins/sdl/src/video/dc/SDL_dcvideo.h b/apps/plugins/sdl/src/video/dc/SDL_dcvideo.h new file mode 100644 index 0000000000..837f028dbb --- /dev/null +++ b/apps/plugins/sdl/src/video/dc/SDL_dcvideo.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /* | ||
2 | SDL - Simple DirectMedia Layer | ||
3 | Copyright (C) 1997-2012 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 | 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. | ||
14 | |||
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 | ||
18 | |||
19 | Sam Lantinga | ||
20 | slouken@libsdl.org | ||
21 | */ | ||
22 | #include "SDL_config.h" | ||
23 | |||
24 | #ifndef _SDL_dcvideo_h | ||
25 | #define _SDL_dcvideo_h | ||
26 | |||
27 | #include "SDL_mouse.h" | ||
28 | #include "SDL_mutex.h" | ||
29 | #include "../SDL_sysvideo.h" | ||
30 | |||
31 | /* Hidden "this" pointer for the video functions */ | ||
32 | #define _THIS SDL_VideoDevice *this | ||
33 | |||
34 | |||
35 | /* Private display data */ | ||
36 | |||
37 | struct SDL_PrivateVideoData { | ||
38 | int w, h; | ||
39 | void *buffer; | ||
40 | }; | ||
41 | |||
42 | #endif /* _SDL_dcvideo_h */ | ||