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> |
13 | #include "common/input.h" |
14 | #include "common/in_sdl.h" |
15 | #include "common/menu.h" |
b07c18e8 |
16 | #include "plugin_lib.h" |
17 | #include "main.h" |
7badc935 |
18 | #include "plat.h" |
19 | #include "revision.h" |
20 | |
b07c18e8 |
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 }, |
7badc935 |
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 | |
b07c18e8 |
81 | in_sdl_init(in_sdl_defbinds); |
7badc935 |
82 | in_probe(); |
83 | return; |
84 | |
85 | fail: |
86 | SDL_Quit(); |
87 | exit(1); |
88 | } |
89 | |
90 | void plat_finish(void) |
91 | { |
92 | SDL_Quit(); |
93 | } |
94 | |
95 | void plat_gvideo_open(void) |
96 | { |
97 | } |
98 | |
99 | void *plat_gvideo_set_mode(int *w, int *h, int *bpp) |
100 | { |
101 | change_video_mode(*w, *h); |
102 | return screen->pixels; |
103 | } |
104 | |
105 | void *plat_gvideo_flip(void) |
106 | { |
107 | SDL_Flip(screen); |
108 | return screen->pixels; |
109 | } |
110 | |
111 | void plat_gvideo_close(void) |
112 | { |
113 | } |
114 | |
115 | void plat_video_menu_enter(int is_rom_loaded) |
116 | { |
117 | change_video_mode(g_menuscreen_w, g_menuscreen_h); |
118 | } |
119 | |
120 | void plat_video_menu_begin(void) |
121 | { |
122 | SDL_LockSurface(screen); |
123 | g_menuscreen_ptr = screen->pixels; |
124 | } |
125 | |
126 | void plat_video_menu_end(void) |
127 | { |
128 | SDL_UnlockSurface(screen); |
129 | SDL_Flip(screen); |
130 | g_menuscreen_ptr = NULL; |
131 | } |
132 | |
133 | void plat_video_menu_leave(void) |
134 | { |
135 | } |
136 | |
137 | /* unused stuff */ |
138 | void *plat_prepare_screenshot(int *w, int *h, int *bpp) |
139 | { |
140 | return 0; |
141 | } |
142 | |
143 | int plat_cpu_clock_get(void) |
144 | { |
145 | return -1; |
146 | } |
147 | |
148 | int plat_cpu_clock_apply(int cpu_clock) |
149 | { |
150 | return -1; |
151 | } |
152 | |
153 | int plat_get_bat_capacity(void) |
154 | { |
155 | return -1; |
156 | } |
157 | |
158 | void plat_step_volume(int is_up) |
159 | { |
160 | } |
161 | |
162 | void plat_trigger_vibrate(int is_strong) |
163 | { |
164 | } |
165 | |
166 | void plat_minimize(void) |
167 | { |
168 | } |
169 | |
170 | // vim:shiftwidth=2:expandtab |