gpu plugins: always support 16bpp blit
[pcsx_rearmed.git] / frontend / plat_sdl.c
1 /*
2  * (C) GraÅžvydas "notaz" Ignotas, 2011,2012
3  *
4  * This work is licensed under the terms of any of these licenses
5  * (at your option):
6  *  - GNU GPL, version 2 or later.
7  *  - GNU LGPL, version 2.1 or later.
8  * See the COPYING file in the top-level directory.
9  */
10
11 #include <stdio.h>
12 #include <SDL.h>
13 #include "common/input.h"
14 #include "common/in_sdl.h"
15 #include "common/menu.h"
16 #include "plugin_lib.h"
17 #include "main.h"
18 #include "plat.h"
19 #include "revision.h"
20
21 static const struct in_default_bind in_sdl_defbinds[] = {
22         { SDLK_UP,      IN_BINDTYPE_PLAYER12, DKEY_UP },
23         { SDLK_DOWN,    IN_BINDTYPE_PLAYER12, DKEY_DOWN },
24         { SDLK_LEFT,    IN_BINDTYPE_PLAYER12, DKEY_LEFT },
25         { SDLK_RIGHT,   IN_BINDTYPE_PLAYER12, DKEY_RIGHT },
26         { SDLK_d,       IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE },
27         { SDLK_z,       IN_BINDTYPE_PLAYER12, DKEY_CROSS },
28         { SDLK_x,       IN_BINDTYPE_PLAYER12, DKEY_CIRCLE },
29         { SDLK_s,       IN_BINDTYPE_PLAYER12, DKEY_SQUARE },
30         { SDLK_v,       IN_BINDTYPE_PLAYER12, DKEY_START },
31         { SDLK_c,       IN_BINDTYPE_PLAYER12, DKEY_SELECT },
32         { SDLK_w,       IN_BINDTYPE_PLAYER12, DKEY_L1 },
33         { SDLK_r,       IN_BINDTYPE_PLAYER12, DKEY_R1 },
34         { SDLK_e,       IN_BINDTYPE_PLAYER12, DKEY_L2 },
35         { SDLK_t,       IN_BINDTYPE_PLAYER12, DKEY_R2 },
36         { SDLK_ESCAPE,  IN_BINDTYPE_EMU, SACTION_ENTER_MENU },
37         { 0, 0, 0 }
38 };
39
40 static SDL_Surface *screen;
41
42 static int change_video_mode(int w, int h)
43 {
44   screen = SDL_SetVideoMode(w, h, 16, 0);
45   if (screen == NULL) {
46     fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
47     return -1;
48   }
49
50   return 0;
51 }
52
53 void plat_init(void)
54 {
55   int ret;
56
57   ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
58   if (ret != 0) {
59     fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
60     exit(1);
61   }
62
63   g_menuscreen_w = 640;
64   g_menuscreen_h = 480;
65   ret = change_video_mode(g_menuscreen_w, g_menuscreen_h);
66   if (ret != 0) {
67     ret = change_video_mode(0, 0);
68     if (ret != 0)
69       goto fail;
70
71     if (screen->w < 320 || screen->h < 240) {
72       fprintf(stderr, "resolution %dx%d is too small, sorry.\n",
73               screen->w, screen->h);
74       goto fail;
75     }
76     g_menuscreen_w = screen->w;
77     g_menuscreen_h = screen->h;
78   }
79   SDL_WM_SetCaption("PCSX-ReARMed " REV, NULL);
80
81   in_sdl_init(in_sdl_defbinds);
82   in_probe();
83   pl_rearmed_cbs.only_16bpp = 1;
84   return;
85
86 fail:
87   SDL_Quit();
88   exit(1);
89 }
90
91 void plat_finish(void)
92 {
93   SDL_Quit();
94 }
95
96 void plat_gvideo_open(void)
97 {
98 }
99
100 void *plat_gvideo_set_mode(int *w, int *h, int *bpp)
101 {
102   change_video_mode(*w, *h);
103   return screen->pixels;
104 }
105
106 void *plat_gvideo_flip(void)
107 {
108   SDL_Flip(screen);
109   return screen->pixels;
110 }
111
112 void plat_gvideo_close(void)
113 {
114 }
115
116 void plat_video_menu_enter(int is_rom_loaded)
117 {
118   change_video_mode(g_menuscreen_w, g_menuscreen_h);
119 }
120
121 void plat_video_menu_begin(void)
122 {
123   SDL_LockSurface(screen);
124   g_menuscreen_ptr = screen->pixels;
125 }
126
127 void plat_video_menu_end(void)
128 {
129   SDL_UnlockSurface(screen);
130   SDL_Flip(screen);
131   g_menuscreen_ptr = NULL;
132 }
133
134 void plat_video_menu_leave(void)
135 {
136 }
137
138 /* unused stuff */
139 void *plat_prepare_screenshot(int *w, int *h, int *bpp)
140 {
141   return 0;
142 }
143
144 int plat_cpu_clock_get(void)
145 {
146   return -1;
147 }
148
149 int plat_cpu_clock_apply(int cpu_clock)
150 {
151   return -1;
152 }
153
154 int plat_get_bat_capacity(void)
155 {
156   return -1;
157 }
158
159 void plat_step_volume(int is_up)
160 {
161 }
162
163 void plat_trigger_vibrate(int is_strong)
164 {
165 }
166
167 void plat_minimize(void)
168 {
169 }
170
171 // vim:shiftwidth=2:expandtab