tweak and refactor frontends, menu and config
[picodrive.git] / platform / pandora / plat.c
1 // (c) Copyright 2006-2009 notaz, All rights reserved.\r
2 // Free for non-commercial use.\r
3 \r
4 // For commercial use, separate licencing terms must be obtained.\r
5 \r
6 #include <stdio.h>\r
7 #include <unistd.h>\r
8 #include <stdarg.h>\r
9 #include <sys/types.h>\r
10 #include <sys/stat.h>\r
11 #include <fcntl.h>\r
12 #include <sys/ioctl.h>\r
13 #include <unistd.h>\r
14 #include <linux/fb.h>\r
15 #include <linux/omapfb.h>\r
16 \r
17 #include "../common/emu.h"\r
18 #include "../common/menu.h"\r
19 #include "../common/plat.h"\r
20 #include "../common/arm_utils.h"\r
21 #include "../common/input.h"\r
22 #include "../linux/sndout_oss.h"\r
23 #include "../linux/fbdev.h"\r
24 #include "plat.h"\r
25 #include "asm_utils.h"\r
26 #include "version.h"\r
27 \r
28 #include <pico/pico_int.h>\r
29 \r
30 #include <linux/input.h>\r
31 \r
32 static struct vout_fbdev *main_fb, *layer_fb;\r
33 static int g_layer_x, g_layer_y;\r
34 static int g_layer_w = 320, g_layer_h = 240;\r
35 static int g_osd_fps_x, g_osd_y;\r
36 \r
37 static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts";\r
38 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
39 static unsigned char __attribute__((aligned(4))) temp_frame[g_menuscreen_w * g_menuscreen_h * 2];\r
40 static unsigned char __attribute__((aligned(4))) fb_copy[g_screen_width * g_screen_height * 2];\r
41 unsigned char *PicoDraw2FB = temp_frame;\r
42 const char *renderer_names[] = { NULL };\r
43 const char *renderer_names32x[] = { NULL };\r
44 \r
45 static const char * const pandora_gpio_keys[KEY_MAX + 1] = {\r
46         [0 ... KEY_MAX] = NULL,\r
47         [KEY_UP]        = "Up",\r
48         [KEY_LEFT]      = "Left",\r
49         [KEY_RIGHT]     = "Right",\r
50         [KEY_DOWN]      = "Down",\r
51         [KEY_HOME]      = "A",\r
52         [KEY_PAGEDOWN]  = "X",\r
53         [KEY_END]       = "B",\r
54         [KEY_PAGEUP]    = "Y",\r
55         [KEY_RIGHTSHIFT]= "L",\r
56         [KEY_RIGHTCTRL] = "R",\r
57         [KEY_LEFTALT]   = "Start",\r
58         [KEY_LEFTCTRL]  = "Select",\r
59         [KEY_MENU]      = "Pandora",\r
60 };\r
61 \r
62 static int get_cpu_clock(void)\r
63 {\r
64         FILE *f;\r
65         int ret = 0;\r
66         f = fopen("/proc/pandora/cpu_mhz_max", "r");\r
67         if (f) {\r
68                 fscanf(f, "%d", &ret);\r
69                 fclose(f);\r
70         }\r
71         return ret;\r
72 }\r
73 \r
74 void pemu_prep_defconfig(void)\r
75 {\r
76         defaultConfig.EmuOpt |= EOPT_VSYNC|EOPT_16BPP;\r
77         defaultConfig.s_PicoOpt |= POPT_EN_MCD_GFX|POPT_EN_MCD_PSYNC;\r
78         defaultConfig.scaling = SCALE_2x2_3x2;\r
79 }\r
80 \r
81 void pemu_validate_config(void)\r
82 {\r
83         currentConfig.CPUclock = get_cpu_clock();\r
84 }\r
85 \r
86 static void osd_text(int x, int y, const char *text)\r
87 {\r
88         int len = strlen(text)*8;\r
89         int i, h;\r
90 \r
91         len++;\r
92         for (h = 0; h < 8; h++) {\r
93                 unsigned short *p;\r
94                 p = (unsigned short *)g_screen_ptr + x + g_screen_width*(y + h);\r
95                 for (i = len; i; i--, p++)\r
96                         *p = (*p>>2) & 0x39e7;\r
97         }\r
98         emu_text_out16(x, y, text);\r
99 }\r
100 \r
101 static void draw_cd_leds(void)\r
102 {\r
103         int old_reg;\r
104         old_reg = Pico_mcd->s68k_regs[0];\r
105 \r
106         if (0) {\r
107                 // 8-bit modes\r
108                 unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
109                 unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
110                 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) =\r
111                 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) =\r
112                 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g;\r
113                 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) =\r
114                 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) =\r
115                 *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r;\r
116         } else {\r
117                 // 16-bit modes\r
118                 unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4);\r
119                 unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;\r
120                 unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;\r
121                 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;\r
122                 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2;\r
123                 *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r;\r
124         }\r
125 }\r
126 \r
127 static int emuscan(unsigned int num)\r
128 {\r
129         DrawLineDest = (unsigned short *)g_screen_ptr + num * g_screen_width;\r
130 \r
131         return 0;\r
132 }\r
133 \r
134 void pemu_finalize_frame(const char *fps, const char *notice)\r
135 {\r
136         if (notice && notice[0])\r
137                 osd_text(2, g_osd_y, notice);\r
138         if (fps && fps[0] && (currentConfig.EmuOpt & EOPT_SHOW_FPS))\r
139                 osd_text(g_osd_fps_x, g_osd_y, fps);\r
140         if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS))\r
141                 draw_cd_leds();\r
142 }\r
143 \r
144 void plat_video_flip(void)\r
145 {\r
146         g_screen_ptr = vout_fbdev_flip(layer_fb);\r
147 }\r
148 \r
149 void plat_video_toggle_renderer(int change, int is_menu)\r
150 {\r
151 }\r
152 \r
153 void plat_video_menu_enter(int is_rom_loaded)\r
154 {\r
155 }\r
156 \r
157 void plat_video_menu_begin(void)\r
158 {\r
159 }\r
160 \r
161 void plat_video_menu_end(void)\r
162 {\r
163         g_menuscreen_ptr = vout_fbdev_flip(main_fb);\r
164 }\r
165 \r
166 void plat_video_wait_vsync(void)\r
167 {\r
168         vout_fbdev_wait_vsync(main_fb);\r
169 }\r
170 \r
171 void plat_status_msg_clear(void)\r
172 {\r
173         vout_fbdev_clear_lines(layer_fb, g_osd_y, 8);\r
174 }\r
175 \r
176 void plat_status_msg_busy_next(const char *msg)\r
177 {\r
178         plat_status_msg_clear();\r
179         pemu_finalize_frame("", msg);\r
180         plat_video_flip();\r
181         emu_status_msg("");\r
182         reset_timing = 1;\r
183 }\r
184 \r
185 void plat_status_msg_busy_first(const char *msg)\r
186 {\r
187         plat_status_msg_busy_next(msg);\r
188 }\r
189 \r
190 void plat_update_volume(int has_changed, int is_up)\r
191 {\r
192         static int prev_frame = 0, wait_frames = 0;\r
193         int vol = currentConfig.volume;\r
194 \r
195         if (has_changed)\r
196         {\r
197                 if (is_up) {\r
198                         if (vol < 99) vol++;\r
199                 } else {\r
200                         if (vol >  0) vol--;\r
201                 }\r
202                 wait_frames = 0;\r
203                 sndout_oss_setvol(vol, vol);\r
204                 currentConfig.volume = vol;\r
205                 emu_status_msg("VOL: %02i", vol);\r
206                 prev_frame = Pico.m.frame_count;\r
207         }\r
208 }\r
209 \r
210 static void make_bg(void)\r
211 {\r
212         unsigned short *s = (void *)fb_copy;\r
213         unsigned int t, *d = (unsigned int *)g_menubg_src_ptr + 80 / 2;\r
214         int x, y;\r
215 \r
216         memset32(g_menubg_src_ptr, 0, 800 * 480 * 2 / 4);\r
217 \r
218         for (y = 0; y < 240; y++, s += 320, d += 800*2/2) {\r
219                 for (x = 0; x < 320; x++) {\r
220                         t = s[x];\r
221                         t |= t << 16;\r
222                         d[x] = d[x + 800 / 2] = t;\r
223                 }\r
224         }\r
225 }\r
226 \r
227 void pemu_forced_frame(int no_scale, int do_emu)\r
228 {\r
229         int po_old = PicoOpt;\r
230 \r
231         memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4);\r
232 \r
233         PicoOpt |= POPT_ACC_SPRITES;\r
234         if (!no_scale)\r
235                 PicoOpt |= POPT_EN_SOFTSCALE;\r
236 \r
237         PicoDrawSetOutFormat(PDF_RGB555, 1);\r
238         Pico.m.dirtyPal = 1;\r
239         if (do_emu)\r
240                 PicoFrame();\r
241         else\r
242                 PicoFrameDrawOnly();\r
243 \r
244         // making a copy because enabling the layer clears it's mem\r
245         memcpy32((void *)fb_copy, g_screen_ptr, sizeof(fb_copy) / 4);\r
246         make_bg(); // FIXME: honour no_scale\r
247 \r
248         PicoOpt = po_old;\r
249 }\r
250 \r
251 static void updateSound(int len)\r
252 {\r
253         unsigned int t;\r
254 \r
255         len <<= 1;\r
256         if (PicoOpt & POPT_EN_STEREO)\r
257                 len <<= 1;\r
258 \r
259         // sndout_oss_can_write() not reliable..\r
260         if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len))\r
261                 return;\r
262 \r
263         /* avoid writing audio when lagging behind to prevent audio lag */\r
264         if (PicoSkipFrame == 2)\r
265                 return;\r
266 \r
267         t = plat_get_ticks_ms();\r
268         sndout_oss_write(PsndOut, len);\r
269         t = plat_get_ticks_ms() - t;\r
270         if (t > 1)\r
271                 printf("audio lag %u\n", t);\r
272 }\r
273 \r
274 void pemu_sound_start(void)\r
275 {\r
276         int target_fps = Pico.m.pal ? 50 : 60;\r
277 \r
278         PsndOut = NULL;\r
279 \r
280         if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
281         {\r
282                 int snd_excess_add, frame_samples;\r
283                 int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
284 \r
285                 PsndRerate(Pico.m.frame_count ? 1 : 0);\r
286 \r
287                 frame_samples = PsndLen;\r
288                 snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps;\r
289                 if (snd_excess_add != 0)\r
290                         frame_samples++;\r
291 \r
292                 /*\r
293                  * for 44k stereo, we do 1470 samples/frame\r
294                  * OMAP driver does power of 2 buffers, so we need at least 4K buffer.\r
295                  * The most we can lag is 1K samples, size of OMAP's McBSP FIFO,\r
296                  * with 2K sample buffer we might sometimes lag more than that,\r
297                  * thus causing underflows.\r
298                  */\r
299                 printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
300                         PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);\r
301                 sndout_oss_start(PsndRate, frame_samples * 2, is_stereo);\r
302                 //sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
303                 PicoWriteSound = updateSound;\r
304                 plat_update_volume(0, 0);\r
305                 memset(sndBuffer, 0, sizeof(sndBuffer));\r
306                 PsndOut = sndBuffer;\r
307         }\r
308 }\r
309 \r
310 void pemu_sound_stop(void)\r
311 {\r
312         sndout_oss_stop();\r
313 }\r
314 \r
315 void pemu_sound_wait(void)\r
316 {\r
317         // don't need to do anything, writes will block by themselves\r
318 }\r
319 \r
320 void plat_debug_cat(char *str)\r
321 {\r
322 }\r
323 \r
324 static int pnd_setup_layer_(int fd, int enabled, int x, int y, int w, int h)\r
325 {\r
326         struct omapfb_plane_info pi;\r
327         struct omapfb_mem_info mi;\r
328         int ret;\r
329 \r
330         ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi);\r
331         if (ret != 0) {\r
332                 perror("QUERY_PLANE");\r
333                 return -1;\r
334         }\r
335 \r
336         ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi);\r
337         if (ret != 0) {\r
338                 perror("QUERY_MEM");\r
339                 return -1;\r
340         }\r
341 \r
342         /* must disable when changing stuff */\r
343         if (pi.enabled) {\r
344                 pi.enabled = 0;\r
345                 ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);\r
346                 if (ret != 0)\r
347                         perror("SETUP_PLANE");\r
348         }\r
349 \r
350         mi.size = 320*240*2*4;\r
351         ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi);\r
352         if (ret != 0) {\r
353                 perror("SETUP_MEM");\r
354                 return -1;\r
355         }\r
356 \r
357         pi.pos_x = x;\r
358         pi.pos_y = y;\r
359         pi.out_width = w;\r
360         pi.out_height = h;\r
361         pi.enabled = enabled;\r
362 \r
363         ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi);\r
364         if (ret != 0) {\r
365                 perror("SETUP_PLANE");\r
366                 return -1;\r
367         }\r
368 \r
369         return 0;\r
370 }\r
371 \r
372 int pnd_setup_layer(int enabled, int x, int y, int w, int h)\r
373 {\r
374         return pnd_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled, x, y, w, h);\r
375 }\r
376 \r
377 void pnd_restore_layer_data(void)\r
378 {\r
379         short *t = (short *)fb_copy + 320*240 / 2 + 160;\r
380 \r
381         // right now this is used by menu, which wants to preview something\r
382         // so try to get something on the layer.\r
383         if ((t[0] | t[5] | t[13]) == 0)\r
384                 memset32((void *)fb_copy, 0x07000700, sizeof(fb_copy) / 4);\r
385 \r
386         memcpy32(g_screen_ptr, (void *)fb_copy, 320*240*2 / 4);\r
387         plat_video_flip();\r
388 }\r
389 \r
390 static void apply_filter(int which)\r
391 {\r
392         char buf[128];\r
393         int i;\r
394 \r
395         if (pnd_filter_list == NULL)\r
396                 return;\r
397 \r
398         for (i = 0; i < which; i++)\r
399                 if (pnd_filter_list[i] == NULL)\r
400                         return;\r
401 \r
402         if (pnd_filter_list[i] == NULL)\r
403                 return;\r
404 \r
405         snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]);\r
406         system(buf);\r
407 }\r
408 \r
409 void emu_video_mode_change(int start_line, int line_count, int is_32cols)\r
410 {\r
411         int fb_w = 320, fb_h = 240, fb_left = 0, fb_right = 0, fb_top = 0, fb_bottom = 0;\r
412 \r
413         PicoDrawSetOutFormat(PDF_RGB555, 1);\r
414         PicoDrawSetCallbacks(emuscan, NULL);\r
415 \r
416         if (is_32cols) {\r
417                 fb_w = 256;\r
418                 fb_left = fb_right = 32;\r
419         }\r
420 \r
421         switch (currentConfig.scaling) {\r
422         case SCALE_1x1:\r
423                 g_layer_w = fb_w;\r
424                 g_layer_h = fb_h;\r
425                 break;\r
426         case SCALE_2x2_3x2:\r
427                 g_layer_w = fb_w * (is_32cols ? 3 : 2);\r
428                 g_layer_h = fb_h * 2;\r
429                 break;\r
430         case SCALE_2x2_2x2:\r
431                 g_layer_w = fb_w * 2;\r
432                 g_layer_h = fb_h * 2;\r
433                 break;\r
434         case SCALE_FULLSCREEN:\r
435                 g_layer_w = 800;\r
436                 g_layer_h = 480;\r
437                 break;\r
438         case SCALE_CUSTOM:\r
439                 g_layer_x = g_layer_cx;\r
440                 g_layer_y = g_layer_cy;\r
441                 g_layer_w = g_layer_cw;\r
442                 g_layer_h = g_layer_ch;\r
443                 break;\r
444         }\r
445 \r
446         if (currentConfig.scaling != SCALE_CUSTOM) {\r
447                 // center the layer\r
448                 g_layer_x = 800 / 2 - g_layer_w / 2;\r
449                 g_layer_y = 480 / 2 - g_layer_h / 2;\r
450         }\r
451 \r
452         switch (currentConfig.scaling) {\r
453         case SCALE_FULLSCREEN:\r
454         case SCALE_CUSTOM:\r
455                 fb_top = start_line;\r
456                 fb_h = line_count;\r
457                 break;\r
458         }\r
459         g_osd_fps_x = is_32cols ? 232 : 264;\r
460         g_osd_y = fb_top + fb_h - 8;\r
461 \r
462         pnd_setup_layer(1, g_layer_x, g_layer_y, g_layer_w, g_layer_h);\r
463         vout_fbdev_resize(layer_fb, fb_w, fb_h, fb_left, fb_right, fb_top, fb_bottom, 0);\r
464         vout_fbdev_clear(layer_fb);\r
465         plat_video_flip();\r
466 }\r
467 \r
468 void pemu_loop_prep(void)\r
469 {\r
470         static int pal_old = -1;\r
471         static int filter_old = -1;\r
472         char buf[128];\r
473 \r
474         if (currentConfig.CPUclock != get_cpu_clock()) {\r
475                 snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d",\r
476                          pnd_script_base, currentConfig.CPUclock);\r
477                 system(buf);\r
478         }\r
479 \r
480         if (Pico.m.pal != pal_old) {\r
481                 snprintf(buf, sizeof(buf), "%s/op_lcdrate.sh %d",\r
482                          pnd_script_base, Pico.m.pal ? 50 : 60);\r
483                 system(buf);\r
484                 pal_old = Pico.m.pal;\r
485         }\r
486 \r
487         if (currentConfig.filter != filter_old) {\r
488                 apply_filter(currentConfig.filter);\r
489                 filter_old = currentConfig.filter;\r
490         }\r
491 \r
492         // make sure there is no junk left behind the layer\r
493         memset32(g_menuscreen_ptr, 0, 800 * 480 * 2 / 4);\r
494         g_menuscreen_ptr = vout_fbdev_flip(main_fb);\r
495 \r
496         // emu_video_mode_change will call pnd_setup_layer()\r
497 \r
498         // dirty buffers better go now than during gameplay\r
499         sync();\r
500         sleep(0);\r
501 \r
502         pemu_sound_start();\r
503 }\r
504 \r
505 void pemu_loop_end(void)\r
506 {\r
507         pemu_sound_stop();\r
508 \r
509         /* do one more frame for menu bg */\r
510         pemu_forced_frame(0, 1);\r
511 \r
512         pnd_setup_layer(0, g_layer_x, g_layer_y, g_layer_w, g_layer_h);\r
513 }\r
514 \r
515 void plat_wait_till_us(unsigned int us_to)\r
516 {\r
517         unsigned int now;\r
518         signed int diff;\r
519 \r
520         now = plat_get_ticks_us();\r
521 \r
522         // XXX: need to check NOHZ\r
523         diff = (signed int)(us_to - now);\r
524         if (diff > 10000) {\r
525                 //printf("sleep %d\n", us_to - now);\r
526                 usleep(diff * 15 / 16);\r
527                 now = plat_get_ticks_us();\r
528                 //printf(" wake %d\n", (signed)(us_to - now));\r
529         }\r
530 /*\r
531         while ((signed int)(us_to - now) > 512) {\r
532                 spend_cycles(1024);\r
533                 now = plat_get_ticks_us();\r
534         }\r
535 */\r
536 }\r
537 \r
538 const char *plat_get_credits(void)\r
539 {\r
540         return "PicoDrive v" VERSION " (c) notaz, 2006-2010\n\n\n"\r
541                 "Credits:\n"\r
542                 "fDave: Cyclone 68000 core,\n"\r
543                 "      base code of PicoDrive\n"\r
544                 "Reesy & FluBBa: DrZ80 core\n"\r
545                 "MAME devs: YM2612 and SN76496 cores\n"\r
546                 "Pandora team: Pandora\n"\r
547                 "Inder, ketchupgun: graphics\n"\r
548                 "\n"\r
549                 "special thanks (for docs, ideas):\n"\r
550                 " Charles MacDonald, Haze,\n"\r
551                 " Stephane Dallongeville,\n"\r
552                 " Lordus, Exophase, Rokas,\n"\r
553                 " Nemesis, Tasco Deluxe";\r
554 }\r
555 \r
556 #include "../linux/oshide.h"\r
557 \r
558 void plat_early_init(void)\r
559 {\r
560 }\r
561 \r
562 void plat_init(void)\r
563 {\r
564         const char *main_fb_name, *layer_fb_name;\r
565         int fd, ret, w, h;\r
566 \r
567         main_fb_name = getenv("FBDEV_MAIN");\r
568         if (main_fb_name == NULL)\r
569                 main_fb_name = "/dev/fb0";\r
570 \r
571         layer_fb_name = getenv("FBDEV_LAYER");\r
572         if (layer_fb_name == NULL)\r
573                 layer_fb_name = "/dev/fb1";\r
574 \r
575         // must set the layer up first to be able to use it\r
576         fd = open(layer_fb_name, O_RDWR);\r
577         if (fd == -1) {\r
578                 fprintf(stderr, "%s: ", layer_fb_name);\r
579                 perror("open");\r
580                 exit(1);\r
581         }\r
582 \r
583         ret = pnd_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h);\r
584         close(fd);\r
585         if (ret != 0) {\r
586                 fprintf(stderr, "failed to set up layer, exiting.\n");\r
587                 exit(1);\r
588         }\r
589 \r
590         oshide_init();\r
591 \r
592         w = h = 0;\r
593         main_fb = vout_fbdev_init(main_fb_name, &w, &h, 0);\r
594         if (main_fb == NULL) {\r
595                 fprintf(stderr, "couldn't init fb: %s\n", main_fb_name);\r
596                 exit(1);\r
597         }\r
598 \r
599         if (w != g_menuscreen_w || h != g_menuscreen_h) {\r
600                 fprintf(stderr, "%dx%d not supported on %s\n", w, h, main_fb_name);\r
601                 goto fail0;\r
602         }\r
603         g_menuscreen_ptr = vout_fbdev_flip(main_fb);\r
604 \r
605         w = 320; h = 240;\r
606         layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 0);\r
607         if (layer_fb == NULL) {\r
608                 fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name);\r
609                 goto fail0;\r
610         }\r
611 \r
612         if (w != g_screen_width || h != g_screen_height) {\r
613                 fprintf(stderr, "%dx%d not supported on %s\n", w, h, layer_fb_name);\r
614                 goto fail1;\r
615         }\r
616         g_screen_ptr = vout_fbdev_flip(layer_fb);\r
617 \r
618         g_menubg_ptr = temp_frame;\r
619         g_menubg_src_ptr = temp_frame;\r
620 \r
621         sndout_oss_init();\r
622         pnd_menu_init();\r
623 \r
624         in_set_config(in_name_to_id("evdev:gpio-keys"), IN_CFG_KEY_NAMES,\r
625                       pandora_gpio_keys, sizeof(pandora_gpio_keys));\r
626         return;\r
627 \r
628 fail1:\r
629         vout_fbdev_finish(layer_fb);\r
630 fail0:\r
631         vout_fbdev_finish(main_fb);\r
632         exit(1);\r
633 }\r
634 \r
635 void plat_finish(void)\r
636 {\r
637         sndout_oss_exit();\r
638         vout_fbdev_finish(main_fb);\r
639         oshide_finish();\r
640 \r
641         printf("all done\n");\r
642 }\r
643 \r
644 /* lprintf */\r
645 void lprintf(const char *fmt, ...)\r
646 {\r
647         va_list vl;\r
648 \r
649         va_start(vl, fmt);\r
650         vprintf(fmt, vl);\r
651         va_end(vl);\r
652 }\r
653 \r