X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Fpandora%2Fplat.c;h=a2e70eb86a2a4da5512116cad99fb8485df5c8a0;hb=93f9619ed819dee07948416c98ca2f1c70a22666;hp=91468a16e7fc304444d23f14ee859af9e7f5c833;hpb=21ebcfd322972ea5579bb5d4bedee9e509b42785;p=picodrive.git diff --git a/platform/pandora/plat.c b/platform/pandora/plat.c index 91468a1..a2e70eb 100644 --- a/platform/pandora/plat.c +++ b/platform/pandora/plat.c @@ -1,7 +1,10 @@ -// (c) Copyright 2006-2009 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. +/* + * PicoDrive + * (C) notaz, 2010,2011 + * + * This work is licensed under the terms of MAME license. + * See COPYING file in the top-level directory. + */ #include #include @@ -12,21 +15,25 @@ #include #include #include +#include #include "../common/emu.h" -#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 "../common/input_pico.h" +#include "../common/version.h" +#include "../libpicofe/input.h" +#include "../libpicofe/menu.h" +#include "../libpicofe/plat.h" +#include "../libpicofe/linux/in_evdev.h" +#include "../libpicofe/linux/sndout_oss.h" +#include "../libpicofe/linux/fbdev.h" +#include "../libpicofe/linux/xenv.h" #include "plat.h" #include "asm_utils.h" -#include "version.h" #include -#include +#define LAYER_MEM_SIZE (320*240*2 * 4) static struct vout_fbdev *main_fb, *layer_fb; // g_layer_* - in use, g_layer_c* - configured custom @@ -35,11 +42,8 @@ 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, 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))) fb_copy[g_screen_width * g_screen_height * 2]; +static unsigned char __attribute__((aligned(4))) fb_copy[320 * 240 * 2]; static void *temp_frame; -unsigned char *PicoDraw2FB; const char *renderer_names[] = { NULL }; const char *renderer_names32x[] = { NULL }; @@ -60,67 +64,76 @@ 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 }, +static struct in_default_bind in_evdev_defbinds[] = +{ + { KEY_UP, IN_BINDTYPE_PLAYER12, GBTN_UP }, + { KEY_DOWN, IN_BINDTYPE_PLAYER12, GBTN_DOWN }, + { KEY_LEFT, IN_BINDTYPE_PLAYER12, GBTN_LEFT }, + { KEY_RIGHT, IN_BINDTYPE_PLAYER12, GBTN_RIGHT }, + { KEY_A, IN_BINDTYPE_PLAYER12, GBTN_A }, + { KEY_S, IN_BINDTYPE_PLAYER12, GBTN_B }, + { KEY_D, IN_BINDTYPE_PLAYER12, GBTN_C }, + { KEY_ENTER, IN_BINDTYPE_PLAYER12, GBTN_START }, + { KEY_R, IN_BINDTYPE_EMU, PEVB_RESET }, + { KEY_F, IN_BINDTYPE_EMU, PEVB_FF }, + { KEY_BACKSPACE,IN_BINDTYPE_EMU, PEVB_FF }, + { 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 }, + { KEY_LEFTCTRL, IN_BINDTYPE_EMU, PEVB_MENU }, + { KEY_HOME, IN_BINDTYPE_PLAYER12, GBTN_A }, + { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, GBTN_B }, + { KEY_END, IN_BINDTYPE_PLAYER12, GBTN_C }, + { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, GBTN_START }, + { KEY_1, IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, + { KEY_2, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, + { KEY_3, IN_BINDTYPE_EMU, PEVB_SSLOT_PREV }, + { KEY_4, IN_BINDTYPE_EMU, PEVB_SSLOT_NEXT }, + { KEY_5, IN_BINDTYPE_EMU, PEVB_PICO_PPREV }, + { KEY_6, IN_BINDTYPE_EMU, PEVB_PICO_PNEXT }, + { KEY_7, IN_BINDTYPE_EMU, PEVB_PICO_SWINP }, { 0, 0, 0 } }; -static int get_cpu_clock(void) +static const struct menu_keymap key_pbtn_map[] = { - FILE *f; - int ret = 0; - f = fopen("/proc/pandora/cpu_mhz_max", "r"); - if (f) { - fscanf(f, "%d", &ret); - fclose(f); - } - return ret; -} + { KEY_UP, PBTN_UP }, + { KEY_DOWN, PBTN_DOWN }, + { KEY_LEFT, PBTN_LEFT }, + { KEY_RIGHT, PBTN_RIGHT }, + /* Pandora */ + { KEY_END, PBTN_MOK }, + { KEY_PAGEDOWN, PBTN_MBACK }, + { KEY_HOME, PBTN_MA2 }, + { KEY_PAGEUP, PBTN_MA3 }, + { KEY_LEFTCTRL, PBTN_MENU }, + { KEY_RIGHTSHIFT, PBTN_L }, + { KEY_RIGHTCTRL, PBTN_R }, + /* "normal" keyboards */ + { KEY_ENTER, PBTN_MOK }, + { KEY_ESC, PBTN_MBACK }, + { KEY_SEMICOLON, PBTN_MA2 }, + { KEY_APOSTROPHE, PBTN_MA3 }, + { KEY_BACKSLASH, PBTN_MENU }, + { KEY_LEFTBRACE, PBTN_L }, + { KEY_RIGHTBRACE, PBTN_R }, +}; + +static const struct in_pdata pandora_evdev_pdata = { + .defbinds = in_evdev_defbinds, + .key_map = key_pbtn_map, + .kmap_size = sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]), +}; void pemu_prep_defconfig(void) { defaultConfig.EmuOpt |= EOPT_VSYNC|EOPT_16BPP; - defaultConfig.s_PicoOpt |= POPT_EN_MCD_GFX|POPT_EN_MCD_PSYNC; + defaultConfig.s_PicoOpt |= POPT_EN_MCD_GFX; defaultConfig.scaling = SCALE_2x2_3x2; } void pemu_validate_config(void) { - currentConfig.CPUclock = get_cpu_clock(); -} - -static void osd_text(int x, int y, const char *text) -{ - int len = strlen(text)*8; - int i, h; - - len++; - for (h = 0; h < 8; h++) { - unsigned short *p; - p = (unsigned short *)g_screen_ptr + x + g_screen_width*(y + h); - for (i = len; i; i--, p++) - *p = (*p>>2) & 0x39e7; - } - emu_text_out16(x, y, text); + currentConfig.CPUclock = plat_target_cpu_clock_get(); } static void draw_cd_leds(void) @@ -149,26 +162,23 @@ static void draw_cd_leds(void) } } -static int emuscan(unsigned int num) -{ - DrawLineDest = (unsigned short *)g_screen_ptr + num * g_screen_width; - - return 0; -} - void pemu_finalize_frame(const char *fps, const char *notice) { if (notice && notice[0]) - osd_text(2, g_osd_y, notice); + emu_osd_text16(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)) + emu_osd_text16(g_osd_fps_x, g_osd_y, fps); + if ((PicoIn.AHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) draw_cd_leds(); } void plat_video_flip(void) { g_screen_ptr = vout_fbdev_flip(layer_fb); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + + // XXX: drain OS event queue here, maybe we'll actually use it someday.. + xenv_update(NULL, NULL, NULL, NULL); } void plat_video_toggle_renderer(int change, int is_menu) @@ -188,6 +198,10 @@ void plat_video_menu_end(void) g_menuscreen_ptr = vout_fbdev_flip(main_fb); } +void plat_video_menu_leave(void) +{ +} + void plat_video_wait_vsync(void) { vout_fbdev_wait_vsync(main_fb); @@ -214,53 +228,6 @@ void plat_status_msg_busy_first(const char *msg) void plat_update_volume(int has_changed, int is_up) { - static int prev_frame = 0, wait_frames = 0; - int vol = currentConfig.volume; - - if (has_changed) - { - if (is_up) { - if (vol < 99) vol++; - } else { - if (vol > 0) vol--; - } - wait_frames = 0; - sndout_oss_setvol(vol, vol); - currentConfig.volume = vol; - emu_status_msg("VOL: %02i", vol); - prev_frame = Pico.m.frame_count; - } -} - -static void make_bg(int no_scale) -{ - unsigned short *s = (void *)fb_copy; - int x, y; - - 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) @@ -270,55 +237,13 @@ void pemu_forced_frame(int no_scale, int 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(no_scale); -} - -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; - - sndout_oss_write_nb(PsndOut, len); + memcpy((void *)fb_copy, g_screen_ptr, sizeof(fb_copy)); + g_menubg_src_ptr = fb_copy; } void pemu_sound_start(void) { - PsndOut = NULL; - - if (currentConfig.EmuOpt & EOPT_EN_SOUND) - { - int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0; - - PsndRerate(Pico.m.frame_count ? 1 : 0); - - /* - * 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 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 = oss_write_nonblocking; - plat_update_volume(0, 0); - memset(sndBuffer, 0, sizeof(sndBuffer)); - PsndOut = sndBuffer; - } -} - -void pemu_sound_stop(void) -{ - sndout_oss_stop(); -} - -void pemu_sound_wait(void) -{ - // don't need to do anything, writes will block by themselves + emu_sound_start(); } void plat_debug_cat(char *str) @@ -329,6 +254,8 @@ static int pnd_setup_layer_(int fd, int enabled, int x, int y, int w, int h) { struct omapfb_plane_info pi; struct omapfb_mem_info mi; + int is_enabled; + int retval = 0; int ret; ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi); @@ -344,18 +271,27 @@ static int pnd_setup_layer_(int fd, int enabled, int x, int y, int w, int h) } /* must disable when changing stuff */ - if (pi.enabled) { + is_enabled = pi.enabled; + if (is_enabled) { pi.enabled = 0; ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi); if (ret != 0) perror("SETUP_PLANE"); + else + is_enabled = 0; } - mi.size = 320*240*2*4; - ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); - if (ret != 0) { - perror("SETUP_MEM"); - return -1; + if (mi.size < LAYER_MEM_SIZE) { + unsigned int size_old = mi.size; + + mi.size = LAYER_MEM_SIZE; + ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); + if (ret != 0) { + perror("SETUP_MEM"); + fprintf(stderr, "(requested %u, had %u)\n", + mi.size, size_old); + return -1; + } } pi.pos_x = x; @@ -365,12 +301,17 @@ static int pnd_setup_layer_(int fd, int enabled, int x, int y, int w, int h) pi.enabled = enabled; ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi); - if (ret != 0) { + if (ret == 0) { + is_enabled = pi.enabled; + } + else { perror("SETUP_PLANE"); - return -1; + retval = -1; } - return 0; + plat_target_switch_layer(1, is_enabled); + + return retval; } int pnd_setup_layer(int enabled, int x, int y, int w, int h) @@ -387,29 +328,10 @@ void pnd_restore_layer_data(void) if ((t[0] | t[5] | t[13]) == 0) memset32((void *)fb_copy, 0x07000700, sizeof(fb_copy) / 4); - memcpy32(g_screen_ptr, (void *)fb_copy, 320*240*2 / 4); + memcpy(g_screen_ptr, (void *)fb_copy, 320*240*2); plat_video_flip(); } -static void apply_filter(int which) -{ - char buf[128]; - int i; - - if (pnd_filter_list == NULL) - return; - - for (i = 0; i < which; i++) - if (pnd_filter_list[i] == NULL) - return; - - if (pnd_filter_list[i] == NULL) - return; - - snprintf(buf, sizeof(buf), "%s/op_videofir.sh %s", pnd_script_base, pnd_filter_list[i]); - system(buf); -} - 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; @@ -417,9 +339,6 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) if (doing_bg_frame) return; - PicoDrawSetOutFormat(PDF_RGB555, 1); - PicoDrawSetCallbacks(emuscan, NULL); - if (is_32cols) { fb_w = 256; fb_left = fb_right = 32; @@ -468,51 +387,32 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) pnd_setup_layer(1, g_layer_x, g_layer_y, g_layer_w, g_layer_h); vout_fbdev_clear(layer_fb); - vout_fbdev_resize(layer_fb, fb_w, fb_h, 16, fb_left, fb_right, fb_top, fb_bottom, 3); + vout_fbdev_resize(layer_fb, fb_w, fb_h, 16, fb_left, fb_right, fb_top, fb_bottom, 4); plat_video_flip(); + + PicoDrawSetOutFormat(PDF_RGB555, 0); } -void pemu_loop_prep(void) +void plat_video_loop_prepare(void) { - static int pal_old = -1; - static int filter_old = -1; - char buf[128]; - - if (currentConfig.CPUclock != get_cpu_clock()) { - snprintf(buf, sizeof(buf), "unset DISPLAY; echo y | %s/op_cpuspeed.sh %d", - pnd_script_base, currentConfig.CPUclock); - system(buf); - } - - if (Pico.m.pal != pal_old) { - snprintf(buf, sizeof(buf), "%s/op_lcdrate.sh %d", - pnd_script_base, Pico.m.pal ? 50 : 60); - system(buf); - pal_old = Pico.m.pal; - } - - if (currentConfig.filter != filter_old) { - apply_filter(currentConfig.filter); - filter_old = currentConfig.filter; - } - // make sure there is no junk left behind the layer - memset32(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2 / 4); + memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); g_menuscreen_ptr = vout_fbdev_flip(main_fb); // emu_video_mode_change will call pnd_setup_layer() +} +void pemu_loop_prep(void) +{ // dirty buffers better go now than during gameplay + fflush(stdout); + fflush(stderr); sync(); sleep(0); - - pemu_sound_start(); } void pemu_loop_end(void) { - pemu_sound_stop(); - /* do one more frame for menu bg */ pemu_forced_frame(0, 1); @@ -542,7 +442,10 @@ void plat_wait_till_us(unsigned int us_to) */ } -#include "../linux/oshide.h" +void *plat_mem_get_for_drc(size_t size) +{ + return NULL; +} void plat_early_init(void) { @@ -576,7 +479,7 @@ void plat_init(void) exit(1); } - oshide_init(); + xenv_init(NULL, "PicoDrive " VERSION); w = h = 0; main_fb = vout_fbdev_init(main_fb_name, &w, &h, 16, 2); @@ -590,7 +493,7 @@ void plat_init(void) g_menuscreen_ptr = vout_fbdev_flip(main_fb); w = 320; h = 240; - layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 3); + layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 16, 4); if (layer_fb == NULL) { fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name); goto fail0; @@ -609,13 +512,18 @@ void plat_init(void) } 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)); + // default ROM path + strcpy(rom_fname_loaded, "/media"); + + in_evdev_init(&pandora_evdev_pdata); + in_probe(); + plat_target_setup_input(); + + sndout_oss_frag_frames = 2; + return; fail1: @@ -627,9 +535,8 @@ fail0: void plat_finish(void) { - sndout_oss_exit(); vout_fbdev_finish(main_fb); - oshide_finish(); + xenv_finish(); printf("all done\n"); }