release r1
[fceu.git] / drivers / sdl / sdl.c
CommitLineData
4a2a617a 1#include <SDL.h>
2#include "../common/platform.h"
3#include "../common/args.h"
4#include "../common/settings.h"
5#include "../common/input.h"
87e3eef5 6#include "../common/main.h"
4a2a617a 7#include "../libpicofe/menu.h"
8#include "../libpicofe/input.h"
9#include "../libpicofe/in_sdl.h"
44343b87 10#include "../libpicofe/plat.h"
87e3eef5 11#include "../../video.h"
4a2a617a 12
13static const struct in_default_bind in_sdl_defbinds[] = {
14 { SDLK_UP, IN_BINDTYPE_PLAYER12, NKEYB_UP },
15 { SDLK_DOWN, IN_BINDTYPE_PLAYER12, NKEYB_DOWN },
16 { SDLK_LEFT, IN_BINDTYPE_PLAYER12, NKEYB_LEFT },
17 { SDLK_RIGHT, IN_BINDTYPE_PLAYER12, NKEYB_RIGHT },
18 { SDLK_z, IN_BINDTYPE_PLAYER12, NKEYB_B },
19 { SDLK_x, IN_BINDTYPE_PLAYER12, NKEYB_A },
20 { SDLK_a, IN_BINDTYPE_PLAYER12, NKEYB_B_TURBO },
21 { SDLK_s, IN_BINDTYPE_PLAYER12, NKEYB_A_TURBO },
87e3eef5 22 { SDLK_c, IN_BINDTYPE_PLAYER12, NKEYB_SELECT },
23 { SDLK_v, IN_BINDTYPE_PLAYER12, NKEYB_START },
4a2a617a 24 { SDLK_ESCAPE, IN_BINDTYPE_EMU, EACTB_ENTER_MENU },
25 { 0, 0, 0 }
26};
27
87e3eef5 28static SDL_Surface *screen;
29static char fps_str[32];
30static SDL_Color psdl[256];
31
44343b87 32struct plat_target plat_target;
33
87e3eef5 34static int changemode(int bpp)
35{
36 const SDL_VideoInfo *vinf;
37 int flags = 0;
38
39 vinf = SDL_GetVideoInfo();
40
41 if(vinf->hw_available)
42 flags |= SDL_HWSURFACE;
43
44 if (bpp == 8)
45 flags |= SDL_HWPALETTE;
46
47 screen = SDL_SetVideoMode(320, 240, bpp, flags);
48 if (!screen)
49 {
50 puts(SDL_GetError());
51 return -1;
52 }
53
54 SDL_WM_SetCaption("FCE Ultra", "FCE Ultra");
55 return 0;
56}
4a2a617a 57
58void platform_init(void)
59{
60 memset(&Settings, 0, sizeof(Settings));
61 Settings.frameskip = -1; // auto
62 Settings.sound_rate = 44100;
63 Settings.turbo_rate_add = (8*2 << 24) / 60 + 1; // 8Hz turbofire
64 Settings.gamma = 100;
65 Settings.sstate_confirm = 1;
66
87e3eef5 67 if (SDL_Init(SDL_INIT_NOPARACHUTE | SDL_INIT_VIDEO))
4a2a617a 68 {
87e3eef5 69 printf("Could not initialize SDL: %s.\n", SDL_GetError());
70 exit(1);
4a2a617a 71 }
87e3eef5 72
73 g_menuscreen_w = 320;
74 g_menuscreen_h = 240;
75 if (changemode(8) != 0)
76 exit(1);
4a2a617a 77}
78
79void platform_late_init(void)
80{
81 in_sdl_init(in_sdl_defbinds);
87e3eef5 82 in_probe();
4a2a617a 83}
84
87e3eef5 85// video
86static void flip(void)
4a2a617a 87{
87e3eef5 88 SDL_Flip(screen);
89 XBuf = screen->pixels;
4a2a617a 90}
91
87e3eef5 92void CleanSurface(void)
4a2a617a 93{
87e3eef5 94 memset(screen->pixels, 0, 320 * 240 * screen->format->BytesPerPixel);
95 flip();
4a2a617a 96}
97
87e3eef5 98void KillVideo(void)
99{
100}
101
102int InitVideo(void)
103{
104 fps_str[0] = 0;
105
106 CleanSurface();
107
108 srendline = 0;
109 erendline = 239;
110
111 return 1;
112}
113
114void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b)
115{
116 psdl[index].r = r;
117 psdl[index].g = g;
118 psdl[index].b = b;
119
120 SDL_SetPalette(screen, SDL_PHYSPAL, &psdl[index], index, 1);
121}
122
123void FCEUD_GetPalette(uint8 index, uint8 * r, uint8 * g, uint8 * b)
124{
125 // dummy, will break snapshots
126 *r = *g = *b = 0;
127}
128
129void BlitPrepare(int skip)
130{
131 if (skip) {
132 return;
133 }
134
135 if (eoptions & EO_CLIPSIDES)
136 {
137 int i, *p = (int *) ((char *)screen->pixels + 32);
138 for (i = 240; i; i--, p += 320/4)
139 {
140 p[0] = p[1] = p[62] = p[63] = 0;
141 }
142 }
143
144 if (Settings.accurate_mode && Settings.scaling < 2)
145 {
146 int i, *p = (int *)screen->pixels + 32/4;
147 if (srendline > 0)
148 for (i = srendline; i > 0; i--, p += 320/4)
149 memset(p, 0, 256);
150 if (erendline < 239)
151 {
152 int *p = (int *)screen->pixels + erendline*320/4 + 32/4;
153 for (i = 239-srendline; i > 0; i--, p += 320/4)
154 memset(p, 0, 256);
155 }
156 }
157}
158
159void BlitScreen(int skip)
160{
161 if (!skip)
162 flip();
163}
164
165void platform_apply_config(void)
166{
167}
168
169void platform_set_volume(int val)
4a2a617a 170{
171}
172
173void plat_video_menu_enter(int is_rom_loaded)
174{
87e3eef5 175 changemode(16);
4a2a617a 176}
177
178void plat_video_menu_begin(void)
179{
180 g_menuscreen_ptr = screen->pixels;
181}
182
183void plat_video_menu_end(void)
184{
185 SDL_Flip(screen);
186}
187
188void plat_video_menu_leave(void)
189{
87e3eef5 190 changemode(8);
191 SDL_SetPalette(screen, SDL_PHYSPAL, psdl, 0, 256);
4a2a617a 192}
193
194char *DriverUsage="";
195
196ARGPSTRUCT DriverArgs[]={
197 {0,0,0,0}
198};
199
200void DoDriverArgs(void)
201{
202}
203
204void GetBaseDirectory(char *BaseDirectory)
205{
87e3eef5 206 strcpy(BaseDirectory, "fceultra");
207}
208
158d88ba 209void platform_get_def_rompath(char *buf, int size)
210{
211 buf[0] = 0;
212}
213
87e3eef5 214void platform_finish(void)
215{
216 SDL_Quit();
4a2a617a 217}