X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pandora%2Fplat.c;h=1815274b814d1b9ec28fb37df3b37eed47b5cb6c;hb=ca69c3e5a0ecf407c02dc85c6f3282ebb1efc5a2;hp=7ba6c572953d674f225d562307d810a06209dc14;hpb=902972d1c7f353aebb17a5ab587b2526e1a45d60;p=libpicofe.git diff --git a/pandora/plat.c b/pandora/plat.c index 7ba6c57..1815274 100644 --- a/pandora/plat.c +++ b/pandora/plat.c @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #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" @@ -30,15 +30,17 @@ #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 }; @@ -59,6 +61,30 @@ static const char * const pandora_gpio_keys[KEY_MAX + 1] = { [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) { FILE *f; @@ -144,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) @@ -207,100 +237,79 @@ void plat_update_volume(int has_changed, int is_up) } } -static void make_bg(void) +static void make_bg(int no_scale) { 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; + 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; + } + + 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; } } void pemu_forced_frame(int no_scale, int do_emu) { - int po_old = PicoOpt; - - memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4); - - PicoOpt |= POPT_ACC_SPRITES; - if (!no_scale) - PicoOpt |= POPT_EN_SOFTSCALE; - - PicoDrawSetOutFormat(PDF_RGB555, 1); - Pico.m.dirtyPal = 1; - if (do_emu) - PicoFrame(); - else - PicoFrameDrawOnly(); + doing_bg_frame = 1; + emu_cmn_forced_frame(no_scale, do_emu); + doing_bg_frame = 0; // making a copy because enabling the layer clears it's mem memcpy32((void *)fb_copy, g_screen_ptr, sizeof(fb_copy) / 4); - make_bg(); // FIXME: honour no_scale - - PicoOpt = po_old; + make_bg(no_scale); } -static void updateSound(int len) +static void oss_write_nonblocking(int len) { - unsigned int t; - - len <<= 1; - if (PicoOpt & POPT_EN_STEREO) - len <<= 1; - - // sndout_oss_can_write() not reliable.. + // 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; @@ -410,6 +419,9 @@ 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; + if (doing_bg_frame) + return; + PicoDrawSetOutFormat(PDF_RGB555, 1); PicoDrawSetCallbacks(emuscan, NULL); @@ -460,8 +472,8 @@ 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); + vout_fbdev_resize(layer_fb, fb_w, fb_h, 16, fb_left, fb_right, fb_top, fb_bottom, 3); plat_video_flip(); } @@ -490,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() @@ -535,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) { } @@ -587,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; @@ -615,8 +605,14 @@ 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(); @@ -636,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); -} -