7badc935 |
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> |
cc56203b |
13 | |
14 | #include "libpicofe/input.h" |
15 | #include "libpicofe/in_sdl.h" |
16 | #include "libpicofe/menu.h" |
b07c18e8 |
17 | #include "plugin_lib.h" |
18 | #include "main.h" |
7badc935 |
19 | #include "plat.h" |
20 | #include "revision.h" |
21 | |
b07c18e8 |
22 | static const struct in_default_bind in_sdl_defbinds[] = { |
2e6189bc |
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 }, |
456f1b86 |
38 | { SDLK_F1, IN_BINDTYPE_EMU, SACTION_SAVE_STATE }, |
39 | { SDLK_F2, IN_BINDTYPE_EMU, SACTION_LOAD_STATE }, |
40 | { SDLK_F3, IN_BINDTYPE_EMU, SACTION_PREV_SSLOT }, |
41 | { SDLK_F4, IN_BINDTYPE_EMU, SACTION_NEXT_SSLOT }, |
42 | { SDLK_F5, IN_BINDTYPE_EMU, SACTION_TOGGLE_FSKIP }, |
43 | { SDLK_F6, IN_BINDTYPE_EMU, SACTION_SCREENSHOT }, |
44 | { SDLK_F7, IN_BINDTYPE_EMU, SACTION_FAST_FORWARD }, |
45 | { SDLK_F8, IN_BINDTYPE_EMU, SACTION_SWITCH_DISPMODE }, |
2e6189bc |
46 | { 0, 0, 0 } |
7badc935 |
47 | }; |
48 | |
49 | static SDL_Surface *screen; |
2e6189bc |
50 | static void *menubg_img; |
7badc935 |
51 | |
52 | static int change_video_mode(int w, int h) |
53 | { |
54 | screen = SDL_SetVideoMode(w, h, 16, 0); |
55 | if (screen == NULL) { |
56 | fprintf(stderr, "SDL_SetVideoMode failed: %s\n", SDL_GetError()); |
57 | return -1; |
58 | } |
59 | |
60 | return 0; |
61 | } |
62 | |
63 | void plat_init(void) |
64 | { |
65 | int ret; |
66 | |
67 | ret = SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE); |
68 | if (ret != 0) { |
69 | fprintf(stderr, "SDL_Init failed: %s\n", SDL_GetError()); |
70 | exit(1); |
71 | } |
72 | |
73 | g_menuscreen_w = 640; |
74 | g_menuscreen_h = 480; |
75 | ret = change_video_mode(g_menuscreen_w, g_menuscreen_h); |
76 | if (ret != 0) { |
77 | ret = change_video_mode(0, 0); |
78 | if (ret != 0) |
79 | goto fail; |
80 | |
81 | if (screen->w < 320 || screen->h < 240) { |
82 | fprintf(stderr, "resolution %dx%d is too small, sorry.\n", |
83 | screen->w, screen->h); |
84 | goto fail; |
85 | } |
86 | g_menuscreen_w = screen->w; |
87 | g_menuscreen_h = screen->h; |
88 | } |
89 | SDL_WM_SetCaption("PCSX-ReARMed " REV, NULL); |
90 | |
2e6189bc |
91 | menubg_img = malloc(640 * 512 * 2); |
92 | if (menubg_img == NULL) |
93 | goto fail; |
94 | |
b07c18e8 |
95 | in_sdl_init(in_sdl_defbinds); |
7badc935 |
96 | in_probe(); |
4ea7de6a |
97 | pl_rearmed_cbs.only_16bpp = 1; |
7badc935 |
98 | return; |
99 | |
100 | fail: |
101 | SDL_Quit(); |
102 | exit(1); |
103 | } |
104 | |
105 | void plat_finish(void) |
106 | { |
2e6189bc |
107 | free(menubg_img); |
108 | menubg_img = NULL; |
7badc935 |
109 | SDL_Quit(); |
110 | } |
111 | |
ab423939 |
112 | void plat_gvideo_open(int is_pal) |
7badc935 |
113 | { |
114 | } |
115 | |
116 | void *plat_gvideo_set_mode(int *w, int *h, int *bpp) |
117 | { |
118 | change_video_mode(*w, *h); |
119 | return screen->pixels; |
120 | } |
121 | |
2e6189bc |
122 | /* XXX: missing SDL_LockSurface() */ |
7badc935 |
123 | void *plat_gvideo_flip(void) |
124 | { |
125 | SDL_Flip(screen); |
126 | return screen->pixels; |
127 | } |
128 | |
129 | void plat_gvideo_close(void) |
130 | { |
131 | } |
132 | |
133 | void plat_video_menu_enter(int is_rom_loaded) |
134 | { |
2e6189bc |
135 | /* surface will be lost, must adjust pl_vout_buf for menu bg */ |
136 | memcpy(menubg_img, screen->pixels, screen->w * screen->h * 2); |
137 | pl_vout_buf = menubg_img; |
138 | |
7badc935 |
139 | change_video_mode(g_menuscreen_w, g_menuscreen_h); |
140 | } |
141 | |
142 | void plat_video_menu_begin(void) |
143 | { |
144 | SDL_LockSurface(screen); |
145 | g_menuscreen_ptr = screen->pixels; |
146 | } |
147 | |
148 | void plat_video_menu_end(void) |
149 | { |
150 | SDL_UnlockSurface(screen); |
151 | SDL_Flip(screen); |
152 | g_menuscreen_ptr = NULL; |
153 | } |
154 | |
155 | void plat_video_menu_leave(void) |
156 | { |
157 | } |
158 | |
159 | /* unused stuff */ |
160 | void *plat_prepare_screenshot(int *w, int *h, int *bpp) |
161 | { |
162 | return 0; |
163 | } |
164 | |
165 | int plat_cpu_clock_get(void) |
166 | { |
167 | return -1; |
168 | } |
169 | |
170 | int plat_cpu_clock_apply(int cpu_clock) |
171 | { |
172 | return -1; |
173 | } |
174 | |
175 | int plat_get_bat_capacity(void) |
176 | { |
177 | return -1; |
178 | } |
179 | |
180 | void plat_step_volume(int is_up) |
181 | { |
182 | } |
183 | |
184 | void plat_trigger_vibrate(int is_strong) |
185 | { |
186 | } |
187 | |
188 | void plat_minimize(void) |
189 | { |
190 | } |
191 | |
192 | // vim:shiftwidth=2:expandtab |