switch over to libpicofe
[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
14 #include "libpicofe/input.h"
15 #include "libpicofe/in_sdl.h"
16 #include "libpicofe/menu.h"
17 #include "plugin_lib.h"
18 #include "main.h"
19 #include "plat.h"
20 #include "revision.h"
21
22 static const struct in_default_bind in_sdl_defbinds[] = {
23   { SDLK_UP,     IN_BINDTYPE_PLAYER12, DKEY_UP },
24   { SDLK_DOWN,   IN_BINDTYPE_PLAYER12, DKEY_DOWN },
25   { SDLK_LEFT,   IN_BINDTYPE_PLAYER12, DKEY_LEFT },
26   { SDLK_RIGHT,  IN_BINDTYPE_PLAYER12, DKEY_RIGHT },
27   { SDLK_d,      IN_BINDTYPE_PLAYER12, DKEY_TRIANGLE },
28   { SDLK_z,      IN_BINDTYPE_PLAYER12, DKEY_CROSS },
29   { SDLK_x,      IN_BINDTYPE_PLAYER12, DKEY_CIRCLE },
30   { SDLK_s,      IN_BINDTYPE_PLAYER12, DKEY_SQUARE },
31   { SDLK_v,      IN_BINDTYPE_PLAYER12, DKEY_START },
32   { SDLK_c,      IN_BINDTYPE_PLAYER12, DKEY_SELECT },
33   { SDLK_w,      IN_BINDTYPE_PLAYER12, DKEY_L1 },
34   { SDLK_r,      IN_BINDTYPE_PLAYER12, DKEY_R1 },
35   { SDLK_e,      IN_BINDTYPE_PLAYER12, DKEY_L2 },
36   { SDLK_t,      IN_BINDTYPE_PLAYER12, DKEY_R2 },
37   { SDLK_ESCAPE, IN_BINDTYPE_EMU, SACTION_ENTER_MENU },
38   { 0, 0, 0 }
39 };
40
41 static SDL_Surface *screen;
42 static void *menubg_img;
43
44 static int change_video_mode(int w, int h)
45 {
46   screen = SDL_SetVideoMode(w, h, 16, 0);
47   if (screen == NULL) {
48     fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError());
49     return -1;
50   }
51
52   return 0;
53 }
54
55 void plat_init(void)
56 {
57   int ret;
58
59   ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE);
60   if (ret != 0) {
61     fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError());
62     exit(1);
63   }
64
65   g_menuscreen_w = 640;
66   g_menuscreen_h = 480;
67   ret = change_video_mode(g_menuscreen_w, g_menuscreen_h);
68   if (ret != 0) {
69     ret = change_video_mode(0, 0);
70     if (ret != 0)
71       goto fail;
72
73     if (screen->w < 320 || screen->h < 240) {
74       fprintf(stderr, "resolution %dx%d is too small, sorry.\n",
75               screen->w, screen->h);
76       goto fail;
77     }
78     g_menuscreen_w = screen->w;
79     g_menuscreen_h = screen->h;
80   }
81   SDL_WM_SetCaption("PCSX-ReARMed " REV, NULL);
82
83   menubg_img = malloc(640 * 512 * 2);
84   if (menubg_img == NULL)
85     goto fail;
86
87   in_sdl_init(in_sdl_defbinds);
88   in_probe();
89   pl_rearmed_cbs.only_16bpp = 1;
90   return;
91
92 fail:
93   SDL_Quit();
94   exit(1);
95 }
96
97 void plat_finish(void)
98 {
99   free(menubg_img);
100   menubg_img = NULL;
101   SDL_Quit();
102 }
103
104 void plat_gvideo_open(int is_pal)
105 {
106 }
107
108 void *plat_gvideo_set_mode(int *w, int *h, int *bpp)
109 {
110   change_video_mode(*w, *h);
111   return screen->pixels;
112 }
113
114 /* XXX: missing SDL_LockSurface() */
115 void *plat_gvideo_flip(void)
116 {
117   SDL_Flip(screen);
118   return screen->pixels;
119 }
120
121 void plat_gvideo_close(void)
122 {
123 }
124
125 void plat_video_menu_enter(int is_rom_loaded)
126 {
127   /* surface will be lost, must adjust pl_vout_buf for menu bg */
128   memcpy(menubg_img, screen->pixels, screen->w * screen->h * 2);
129   pl_vout_buf = menubg_img;
130
131   change_video_mode(g_menuscreen_w, g_menuscreen_h);
132 }
133
134 void plat_video_menu_begin(void)
135 {
136   SDL_LockSurface(screen);
137   g_menuscreen_ptr = screen->pixels;
138 }
139
140 void plat_video_menu_end(void)
141 {
142   SDL_UnlockSurface(screen);
143   SDL_Flip(screen);
144   g_menuscreen_ptr = NULL;
145 }
146
147 void plat_video_menu_leave(void)
148 {
149 }
150
151 /* unused stuff */
152 void *plat_prepare_screenshot(int *w, int *h, int *bpp)
153 {
154   return 0;
155 }
156
157 int plat_cpu_clock_get(void)
158 {
159   return -1;
160 }
161
162 int plat_cpu_clock_apply(int cpu_clock)
163 {
164   return -1;
165 }
166
167 int plat_get_bat_capacity(void)
168 {
169   return -1;
170 }
171
172 void plat_step_volume(int is_up)
173 {
174 }
175
176 void plat_trigger_vibrate(int is_strong)
177 {
178 }
179
180 void plat_minimize(void)
181 {
182 }
183
184 // vim:shiftwidth=2:expandtab