X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pandora%2Fplat.c;h=1815274b814d1b9ec28fb37df3b37eed47b5cb6c;hb=ca69c3e5a0ecf407c02dc85c6f3282ebb1efc5a2;hp=5992f739f96231f92d0ba0832f9dfb3661a6a814;hpb=c66f49e61a09926e828b2685cc997a6ebee7cdb4;p=libpicofe.git diff --git a/pandora/plat.c b/pandora/plat.c index 5992f73..1815274 100644 --- a/pandora/plat.c +++ b/pandora/plat.c @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -18,28 +17,73 @@ #include "../common/menu.h" #include "../common/plat.h" #include "../common/arm_utils.h" +#include "../common/input.h" #include "../linux/sndout_oss.h" #include "../linux/fbdev.h" +#include "../linux/xenv.h" #include "plat.h" #include "asm_utils.h" #include "version.h" #include +#include static struct vout_fbdev *main_fb, *layer_fb; +// g_layer_* - in use, g_layer_c* - configured custom +int g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch; static int g_layer_x, g_layer_y; static int g_layer_w = 320, g_layer_h = 240; -static int g_osd_fps_x, g_osd_y; +static int g_osd_fps_x, g_osd_y, doing_bg_frame; static const char pnd_script_base[] = "sudo -n /usr/pandora/scripts"; static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; -static unsigned char __attribute__((aligned(4))) temp_frame[g_menuscreen_w * g_menuscreen_h * 2]; static unsigned char __attribute__((aligned(4))) fb_copy[g_screen_width * g_screen_height * 2]; -unsigned char *PicoDraw2FB = temp_frame; +static void *temp_frame; +unsigned char *PicoDraw2FB; const char *renderer_names[] = { NULL }; const char *renderer_names32x[] = { NULL }; -char cpu_clk_name[] = "Max CPU clock"; + +static const char * const pandora_gpio_keys[KEY_MAX + 1] = { + [0 ... KEY_MAX] = NULL, + [KEY_UP] = "Up", + [KEY_LEFT] = "Left", + [KEY_RIGHT] = "Right", + [KEY_DOWN] = "Down", + [KEY_HOME] = "A", + [KEY_PAGEDOWN] = "X", + [KEY_END] = "B", + [KEY_PAGEUP] = "Y", + [KEY_RIGHTSHIFT]= "L", + [KEY_RIGHTCTRL] = "R", + [KEY_LEFTALT] = "Start", + [KEY_LEFTCTRL] = "Select", + [KEY_MENU] = "Pandora", +}; + +struct in_default_bind in_evdev_defbinds[] = +{ + /* MXYZ SACB RLDU */ + { KEY_UP, IN_BINDTYPE_PLAYER12, 0 }, + { KEY_DOWN, IN_BINDTYPE_PLAYER12, 1 }, + { KEY_LEFT, IN_BINDTYPE_PLAYER12, 2 }, + { KEY_RIGHT, IN_BINDTYPE_PLAYER12, 3 }, + { KEY_S, IN_BINDTYPE_PLAYER12, 4 }, /* B */ + { KEY_D, IN_BINDTYPE_PLAYER12, 5 }, /* C */ + { KEY_A, IN_BINDTYPE_PLAYER12, 6 }, /* A */ + { KEY_ENTER, IN_BINDTYPE_PLAYER12, 7 }, + { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU }, + { KEY_SPACE, IN_BINDTYPE_EMU, PEVB_MENU }, + /* Pandora */ + { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, 4 }, + { KEY_END, IN_BINDTYPE_PLAYER12, 5 }, + { KEY_HOME, IN_BINDTYPE_PLAYER12, 6 }, + { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, 7 }, + { KEY_RIGHTSHIFT,IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, + { KEY_RIGHTCTRL, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, + { KEY_LEFTCTRL, IN_BINDTYPE_EMU, PEVB_MENU }, + { 0, 0, 0 } +}; static int get_cpu_clock(void) { @@ -115,12 +159,10 @@ static int emuscan(unsigned int num) void pemu_finalize_frame(const char *fps, const char *notice) { - if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) { - if (notice) - osd_text(2, g_osd_y, notice); - if (currentConfig.EmuOpt & EOPT_SHOW_FPS) - osd_text(g_osd_fps_x, g_osd_y, fps); - } + if (notice && notice[0]) + osd_text(2, g_osd_y, notice); + if (fps && fps[0] && (currentConfig.EmuOpt & EOPT_SHOW_FPS)) + osd_text(g_osd_fps_x, g_osd_y, fps); if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) draw_cd_leds(); } @@ -128,6 +170,10 @@ void pemu_finalize_frame(const char *fps, const char *notice) void plat_video_flip(void) { g_screen_ptr = vout_fbdev_flip(layer_fb); + + // XXX: drain OS event queue here, maybe we'll actually use it someday.. + int dummy; + xenv_update(&dummy); } void plat_video_toggle_renderer(int change, int is_menu) @@ -140,7 +186,6 @@ void plat_video_menu_enter(int is_rom_loaded) void plat_video_menu_begin(void) { - memcpy32(g_menuscreen_ptr, g_menubg_ptr, g_menuscreen_w * g_menuscreen_h * 2 / 4); } void plat_video_menu_end(void) @@ -155,7 +200,7 @@ void plat_video_wait_vsync(void) void plat_status_msg_clear(void) { - vout_fbdev_clear_lines(layer_fb, g_screen_height - 8, 8); + vout_fbdev_clear_lines(layer_fb, g_osd_y, 8); } void plat_status_msg_busy_next(const char *msg) @@ -192,78 +237,79 @@ void plat_update_volume(int has_changed, int is_up) } } -void pemu_forced_frame(int opts, int no_scale) +static void make_bg(int no_scale) { - int oldscale = currentConfig.scaling; - int po_old = PicoOpt; + unsigned short *s = (void *)fb_copy; + int x, y; - if (no_scale) { - currentConfig.scaling = SCALE_1x1; - emu_video_mode_change(8, 224, 0); + memset32(g_menubg_src_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2 / 4); + + if (!no_scale && g_menuscreen_w >= 640 && g_menuscreen_h >= 480) { + unsigned int t, *d = g_menubg_src_ptr; + d += (g_menuscreen_h / 2 - 480 / 2) * g_menuscreen_w / 2; + d += (g_menuscreen_w / 2 - 640 / 2) / 2; + for (y = 0; y < 240; y++, s += 320, d += g_menuscreen_w*2/2) { + for (x = 0; x < 320; x++) { + t = s[x]; + t |= t << 16; + d[x] = d[x + g_menuscreen_w / 2] = t; + } + } + return; } - PicoOpt |= opts|POPT_ACC_SPRITES; - - Pico.m.dirtyPal = 1; - PicoFrameDrawOnly(); - - PicoOpt = po_old; - currentConfig.scaling = oldscale; + if (g_menuscreen_w >= 320 && g_menuscreen_h >= 240) { + unsigned short *d = g_menubg_src_ptr; + d += (g_menuscreen_h / 2 - 240 / 2) * g_menuscreen_w; + d += (g_menuscreen_w / 2 - 320 / 2); + for (y = 0; y < 240; y++, s += 320, d += g_menuscreen_w) + memcpy(d, s, 320*2); + return; + } } -static void updateSound(int len) +void pemu_forced_frame(int no_scale, int do_emu) { - unsigned int t; + doing_bg_frame = 1; + emu_cmn_forced_frame(no_scale, do_emu); + doing_bg_frame = 0; - len <<= 1; - if (PicoOpt & POPT_EN_STEREO) - len <<= 1; + // making a copy because enabling the layer clears it's mem + memcpy32((void *)fb_copy, g_screen_ptr, sizeof(fb_copy) / 4); + make_bg(no_scale); +} - // sndout_oss_can_write() not reliable.. +static void oss_write_nonblocking(int len) +{ + // sndout_oss_can_write() is not reliable, only use with no_frmlimit if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && !sndout_oss_can_write(len)) return; - /* avoid writing audio when lagging behind to prevent audio lag */ - if (PicoSkipFrame == 2) - return; - - t = plat_get_ticks_ms(); - sndout_oss_write(PsndOut, len); - t = plat_get_ticks_ms() - t; - if (t > 1) - printf("audio lag %u\n", t); + sndout_oss_write_nb(PsndOut, len); } void pemu_sound_start(void) { - int target_fps = Pico.m.pal ? 50 : 60; - PsndOut = NULL; if (currentConfig.EmuOpt & EOPT_EN_SOUND) { - int snd_excess_add, frame_samples; int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0; PsndRerate(Pico.m.frame_count ? 1 : 0); - frame_samples = PsndLen; - snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps; - if (snd_excess_add != 0) - frame_samples++; - /* - * for 44k stereo, we do 1470 samples/frame + * for 44k stereo, we do 1470 samples/emu_frame * OMAP driver does power of 2 buffers, so we need at least 4K buffer. * The most we can lag is 1K samples, size of OMAP's McBSP FIFO, * with 2K sample buffer we might sometimes lag more than that, * thus causing underflows. */ - printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n", - PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal); - sndout_oss_start(PsndRate, frame_samples * 2, is_stereo); + printf("starting audio: %i len: %i stereo: %i, pal: %i\n", + PsndRate, PsndLen, is_stereo, Pico.m.pal); + sndout_oss_start(PsndRate, is_stereo, 2); //sndout_oss_setvol(currentConfig.volume, currentConfig.volume); - PicoWriteSound = updateSound; + PicoWriteSound = oss_write_nonblocking; plat_update_volume(0, 0); memset(sndBuffer, 0, sizeof(sndBuffer)); PsndOut = sndBuffer; @@ -339,7 +385,7 @@ int pnd_setup_layer(int enabled, int x, int y, int w, int h) void pnd_restore_layer_data(void) { - short *t = ((short *)fb_copy)[320*240 / 2 + 160]; + short *t = (short *)fb_copy + 320*240 / 2 + 160; // right now this is used by menu, which wants to preview something // so try to get something on the layer. @@ -373,9 +419,11 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) { int fb_w = 320, fb_h = 240, fb_left = 0, fb_right = 0, fb_top = 0, fb_bottom = 0; - PicoScanBegin = emuscan; - PicoScanEnd = NULL; + if (doing_bg_frame) + return; + PicoDrawSetOutFormat(PDF_RGB555, 1); + PicoDrawSetCallbacks(emuscan, NULL); if (is_32cols) { fb_w = 256; @@ -424,25 +472,9 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) g_osd_y = fb_top + fb_h - 8; pnd_setup_layer(1, g_layer_x, g_layer_y, g_layer_w, g_layer_h); - vout_fbdev_resize(layer_fb, fb_w, fb_h, fb_left, fb_right, fb_top, fb_bottom, 0); vout_fbdev_clear(layer_fb); -} - -static void make_bg(void) -{ - unsigned short *s = (void *)fb_copy; - unsigned int t, *d = (unsigned int *)g_menubg_src_ptr + 80 / 2; - int x, y; - - memset32(g_menubg_src_ptr, 0, 800 * 480 * 2 / 4); - - for (y = 0; y < 240; y++, s += 320, d += 800*2/2) { - for (x = 0; x < 320; x++) { - t = s[x]; - t |= t << 16; - d[x] = d[x + 800 / 2] = t; - } - } + vout_fbdev_resize(layer_fb, fb_w, fb_h, 16, fb_left, fb_right, fb_top, fb_bottom, 3); + plat_video_flip(); } void pemu_loop_prep(void) @@ -470,7 +502,7 @@ void pemu_loop_prep(void) } // make sure there is no junk left behind the layer - memset32(g_menuscreen_ptr, 0, 800 * 480 * 2 / 4); + memset32(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2 / 4); g_menuscreen_ptr = vout_fbdev_flip(main_fb); // emu_video_mode_change will call pnd_setup_layer() @@ -484,28 +516,12 @@ void pemu_loop_prep(void) void pemu_loop_end(void) { - int po_old = PicoOpt; - int eo_old = currentConfig.EmuOpt; - pemu_sound_stop(); - memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4); /* do one more frame for menu bg */ - PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; - currentConfig.EmuOpt |= EOPT_16BPP; - - PicoDrawSetOutFormat(PDF_RGB555, 1); - Pico.m.dirtyPal = 1; - PicoFrame(); - - // making a copy because enabling the layer clears it's mem - memcpy32((void *)fb_copy, g_screen_ptr, sizeof(fb_copy) / 4); - make_bg(); + pemu_forced_frame(0, 1); pnd_setup_layer(0, g_layer_x, g_layer_y, g_layer_w, g_layer_h); - - PicoOpt = po_old; - currentConfig.EmuOpt = eo_old; } void plat_wait_till_us(unsigned int us_to) @@ -531,26 +547,6 @@ void plat_wait_till_us(unsigned int us_to) */ } -const char *plat_get_credits(void) -{ - return "PicoDrive v" VERSION " (c) notaz, 2006-2010\n\n\n" - "Credits:\n" - "fDave: Cyclone 68000 core,\n" - " base code of PicoDrive\n" - "Reesy & FluBBa: DrZ80 core\n" - "MAME devs: YM2612 and SN76496 cores\n" - "Pandora team: Pandora\n" - "Inder, ketchupgun: graphics\n" - "\n" - "special thanks (for docs, ideas):\n" - " Charles MacDonald, Haze,\n" - " Stephane Dallongeville,\n" - " Lordus, Exophase, Rokas,\n" - " Nemesis, Tasco Deluxe"; -} - -#include "../linux/oshide.h" - void plat_early_init(void) { } @@ -583,23 +579,21 @@ void plat_init(void) exit(1); } - oshide_init(); + xenv_init(); w = h = 0; - main_fb = vout_fbdev_init(main_fb_name, &w, &h, 0); + main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2); if (main_fb == NULL) { fprintf(stderr, "couldn't init fb: %s\n", main_fb_name); exit(1); } - if (w != g_menuscreen_w || h != g_menuscreen_h) { - fprintf(stderr, "%dx%d not supported on %s\n", w, h, main_fb_name); - goto fail0; - } + g_menuscreen_w = w; + g_menuscreen_h = h; g_menuscreen_ptr = vout_fbdev_flip(main_fb); w = 320; h = 240; - layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 0); + layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3); if (layer_fb == NULL) { fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name); goto fail0; @@ -611,11 +605,20 @@ void plat_init(void) } g_screen_ptr = vout_fbdev_flip(layer_fb); + temp_frame = calloc(g_menuscreen_w * g_menuscreen_h * 2, 1); + if (temp_frame == NULL) { + fprintf(stderr, "OOM\n"); + goto fail1; + } g_menubg_ptr = temp_frame; g_menubg_src_ptr = temp_frame; + PicoDraw2FB = temp_frame; sndout_oss_init(); pnd_menu_init(); + + in_set_config(in_name_to_id("evdev:gpio-keys"), IN_CFG_KEY_NAMES, + pandora_gpio_keys, sizeof(pandora_gpio_keys)); return; fail1: @@ -629,18 +632,8 @@ void plat_finish(void) { sndout_oss_exit(); vout_fbdev_finish(main_fb); - oshide_finish(); + xenv_finish(); printf("all done\n"); } -/* lprintf */ -void lprintf(const char *fmt, ...) -{ - va_list vl; - - va_start(vl, fmt); - vprintf(fmt, vl); - va_end(vl); -} -