From c7eb229a3cfc2848bcc3413185758039f30559aa Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 6 Sep 2010 13:08:23 +0000 Subject: [PATCH] pandora: use hw scaler (resolves 32x+sms), frontend refactoring git-svn-id: file:///home/notaz/opt/svn/PicoDrive@885 be3aeb3a-fb24-0410-a615-afba39da0efa --- pico/mode4.c | 2 +- pico/z80if.c | 1 + platform/common/emu.c | 5 +- platform/common/emu.h | 1 + platform/common/menu.c | 155 ++++---- platform/common/menu.h | 24 +- platform/gp2x/emu.c | 5 + platform/gp2x/plat.c | 1 + platform/gp2x/port_config.h | 2 + platform/linux/emu.c | 1 + platform/linux/io.c | 6 +- platform/linux/port_config.h | 2 + platform/pandora/Makefile | 7 +- platform/pandora/emu.c | 449 ----------------------- platform/pandora/menu.c | 135 ++++++- platform/pandora/pandora.c | 54 --- platform/pandora/picorestore.c | 37 +- platform/pandora/plat.c | 646 +++++++++++++++++++++++++++++++++ platform/pandora/plat.h | 17 + platform/pandora/port_config.h | 6 +- 20 files changed, 960 insertions(+), 596 deletions(-) delete mode 100644 platform/pandora/emu.c delete mode 100644 platform/pandora/pandora.c create mode 100644 platform/pandora/plat.c create mode 100644 platform/pandora/plat.h diff --git a/pico/mode4.c b/pico/mode4.c index 1b337a3..ecfbd75 100644 --- a/pico/mode4.c +++ b/pico/mode4.c @@ -207,9 +207,9 @@ void PicoFrameStartMode4(void) } if (rendstatus != rendstatus_old || lines != rendlines) { + emu_video_mode_change(screen_offset, lines, 1); rendstatus_old = rendstatus; rendlines = lines; - emu_video_mode_change(screen_offset, lines, 1); } DrawLineDest = (char *)DrawLineDestBase + screen_offset * DrawLineDestIncrement; diff --git a/pico/z80if.c b/pico/z80if.c index 10c438a..faeed8e 100644 --- a/pico/z80if.c +++ b/pico/z80if.c @@ -71,6 +71,7 @@ void z80_init(void) void z80_reset(void) { #ifdef _USE_DRZ80 + // FIXME: reset is not correct memset(&drZ80, 0, 0x54); drZ80.Z80F = (1<<2); // set ZFlag drZ80.Z80F2 = (1<<2); // set ZFlag diff --git a/platform/common/emu.c b/platform/common/emu.c index 618eb70..f995c1d 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -1140,8 +1140,11 @@ static void emu_tray_close(void) void emu_32x_startup(void) { - plat_video_toggle_renderer(0, 0); + plat_video_toggle_renderer(0, 0); // HACK system_announce(); + + // force mode change event + rendstatus_old = -1; } void emu_reset_game(void) diff --git a/platform/common/emu.h b/platform/common/emu.h index f51907f..90803a6 100644 --- a/platform/common/emu.h +++ b/platform/common/emu.h @@ -75,6 +75,7 @@ typedef struct _currentConfig_t { int turbo_rate; int renderer; int renderer32x; + int filter; // pandora } currentConfig_t; extern currentConfig_t currentConfig, defaultConfig; diff --git a/platform/common/menu.c b/platform/common/menu.c index 39a71b1..691eda4 100644 --- a/platform/common/menu.c +++ b/platform/common/menu.c @@ -1,4 +1,4 @@ -// (c) Copyright 2006-2009 notaz, All rights reserved. +// (c) Copyright 2006-2010 notaz, All rights reserved. // Free for non-commercial use. // For commercial use, separate licencing terms must be obtained. @@ -25,10 +25,17 @@ static char static_buff[64]; static int menu_error_time = 0; char menu_error_msg[64] = { 0, }; +void *g_menuscreen_ptr; +void *g_menubg_src_ptr; void *g_menubg_ptr; #ifndef UIQ3 +#if !SCREEN_SIZE_FIXED +int g_menuscreen_w = MSCREEN_WIDTH; +int g_menuscreen_h = MSCREEN_HEIGHT; +#endif + static unsigned char *menu_font_data = NULL; static int menu_text_color = 0xffff; // default to white static int menu_sel_color = -1; // disabled @@ -46,7 +53,7 @@ static const int me_sfont_w = 6, me_sfont_h = 10; static void text_out16_(int x, int y, const char *text, int color) { int i, lh, tr, tg, tb, len; - unsigned short *dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width; + unsigned short *dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w; tr = (color & 0xf800) >> 8; tg = (color & 0x07e0) >> 3; tb = (color & 0x001f) << 3; @@ -66,8 +73,8 @@ static void text_out16_(int x, int y, const char *text, int color) } lh = me_mfont_h; - if (y + lh > g_screen_height) - lh = g_screen_height - y; + if (y + lh > g_menuscreen_h) + lh = g_menuscreen_h - y; for (i = 0; i < len; i++) { @@ -75,7 +82,7 @@ static void text_out16_(int x, int y, const char *text, int color) unsigned short *dst = dest; int u, l; - for (l = 0; l < lh; l++, dst += g_screen_width - me_mfont_w) + for (l = 0; l < lh; l++, dst += g_menuscreen_w - me_mfont_w) { for (u = me_mfont_w / 2; u > 0; u--, src++) { @@ -106,7 +113,7 @@ void text_out16(int x, int y, const char *texto, ...) { va_list args; char buffer[256]; - int maxw = (g_screen_width - x) / me_mfont_w; + int maxw = (g_menuscreen_w - x) / me_mfont_w; if (maxw < 0) return; @@ -139,7 +146,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) break; src = fontdata6x8[c]; - dst = (unsigned short *)g_screen_ptr + x + y * g_screen_width; + dst = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w; while (h--) { @@ -154,7 +161,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) dst += multiplier; } - dst += g_screen_width - me_sfont_w; + dst += g_menuscreen_w - me_sfont_w; } src++; } @@ -164,7 +171,7 @@ static void smalltext_out16_(int x, int y, const char *texto, int color) static void smalltext_out16(int x, int y, const char *texto, int color) { char buffer[128]; - int maxw = (g_screen_width - x) / me_sfont_w; + int maxw = (g_menuscreen_w - x) / me_sfont_w; if (maxw < 0) return; @@ -187,13 +194,13 @@ static void menu_draw_selection(int x, int y, int w) if (menu_sel_color < 0) return; // no selection hilight if (y > 0) y--; - dest = (unsigned short *)g_screen_ptr + x + y * g_screen_width + me_mfont_w * 2 - 2; + dest = (unsigned short *)g_menuscreen_ptr + x + y * g_menuscreen_w + me_mfont_w * 2 - 2; for (h = me_mfont_h + 1; h > 0; h--) { dst = dest; for (i = w - (me_mfont_w * 2 - 2); i > 0; i--) *dst++ = menu_sel_color; - dest += g_screen_width; + dest += g_menuscreen_w; } } @@ -335,8 +342,12 @@ static void menu_enter(int is_rom_loaded) { if (is_rom_loaded) { + void *src = g_menubg_src_ptr; + if (src == NULL) + src = g_menuscreen_ptr; + // darken the active framebuffer - menu_darken_bg(g_menubg_ptr, g_screen_ptr, g_screen_width * g_screen_height, 1); + menu_darken_bg(g_menubg_ptr, src, g_menuscreen_w * g_menuscreen_h, 1); } else { @@ -344,8 +355,8 @@ static void menu_enter(int is_rom_loaded) // should really only happen once, on startup.. emu_make_path(buff, "skin/background.png", sizeof(buff)); - if (readpng(g_menubg_ptr, buff, READPNG_BG, g_screen_width, g_screen_height) < 0) - memset(g_menubg_ptr, 0, g_screen_width * g_screen_height * 2); + if (readpng(g_menubg_ptr, buff, READPNG_BG, g_menuscreen_w, g_menuscreen_h) < 0) + memset(g_menubg_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); } plat_video_menu_enter(is_rom_loaded); @@ -442,17 +453,17 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) h = n * me_mfont_h; w += me_mfont_w * 2; /* selector */ - if (w > g_screen_width) { - lprintf("width %d > %d\n", w, g_screen_width); - w = g_screen_width; + if (w > g_menuscreen_w) { + lprintf("width %d > %d\n", w, g_menuscreen_w); + w = g_menuscreen_w; } - if (h > g_screen_height) { - lprintf("height %d > %d\n", w, g_screen_height); - h = g_screen_height; + if (h > g_menuscreen_h) { + lprintf("height %d > %d\n", w, g_menuscreen_h); + h = g_menuscreen_h; } - x = g_screen_width / 2 - w / 2; - y = g_screen_height / 2 - h / 2; + x = g_menuscreen_w / 2 - w / 2; + y = g_menuscreen_h / 2 - h / 2; /* draw */ plat_video_menu_begin(); @@ -513,10 +524,10 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) } /* display help or message if we have one */ - h = (g_screen_height - h) / 2; // bottom area height + h = (g_menuscreen_h - h) / 2; // bottom area height if (menu_error_msg[0] != 0) { if (h >= me_mfont_h + 4) - text_out16(5, g_screen_height - me_mfont_h - 4, menu_error_msg); + text_out16(5, g_menuscreen_h - me_mfont_h - 4, menu_error_msg); else lprintf("menu msg doesn't fit!\n"); @@ -530,7 +541,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void)) tmp = strchr(tmp + 1, '\n'); if (h >= l * me_sfont_h + 4) for (tmp = ent_sel->help; l > 0; l--, tmp = strchr(tmp, '\n') + 1) - smalltext_out16(5, g_screen_height - (l * me_sfont_h + 4), tmp, 0xffff); + smalltext_out16(5, g_menuscreen_h - (l * me_sfont_h + 4), tmp, 0xffff); } if (draw_more != NULL) @@ -671,14 +682,14 @@ static void draw_menu_credits(void) p++; } - x = g_screen_width / 2 - w * me_mfont_w / 2; - y = g_screen_height / 2 - h * me_mfont_h / 2; + x = g_menuscreen_w / 2 - w * me_mfont_w / 2; + y = g_menuscreen_h / 2 - h * me_mfont_h / 2; if (x < 0) x = 0; if (y < 0) y = 0; plat_video_menu_begin(); - for (p = creds; *p != 0 && y <= g_screen_height - me_mfont_h; y += me_mfont_h) { + for (p = creds; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) { text_out16(x, y, p); for (; *p != 0 && *p != '\n'; p++) @@ -696,30 +707,30 @@ static int cdload_called = 0; static void load_progress_cb(int percent) { - int ln, len = percent * g_screen_width / 100; - unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * me_sfont_h * 2; + int ln, len = percent * g_menuscreen_w / 100; + unsigned short *dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2; - if (len > g_screen_width) - len = g_screen_width; - for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_screen_width) + if (len > g_menuscreen_w) + len = g_menuscreen_w; + for (ln = me_sfont_h - 2; ln > 0; ln--, dst += g_menuscreen_w) memset(dst, 0xff, len * 2); plat_video_menu_end(); } static void cdload_progress_cb(const char *fname, int percent) { - int ln, len = percent * g_screen_width / 100; - unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * me_sfont_h * 2; + int ln, len = percent * g_menuscreen_w / 100; + unsigned short *dst = (unsigned short *)g_menuscreen_ptr + g_menuscreen_w * me_sfont_h * 2; - memset(dst, 0xff, g_screen_width * (me_sfont_h - 2) * 2); + memset(dst, 0xff, g_menuscreen_w * (me_sfont_h - 2) * 2); smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff); smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff); - dst += g_screen_width * me_sfont_h * 3; + dst += g_menuscreen_w * me_sfont_h * 3; - if (len > g_screen_width) - len = g_screen_width; - for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_screen_width) + if (len > g_menuscreen_w) + len = g_menuscreen_w; + for (ln = (me_sfont_h - 2); ln > 0; ln--, dst += g_menuscreen_w) memset(dst, 0xff, len * 2); plat_video_menu_end(); @@ -767,13 +778,13 @@ static void do_delete(const char *fpath, const char *fname) plat_video_menu_begin(); if (!rom_loaded) - menu_darken_bg(g_screen_ptr, g_screen_ptr, g_screen_width * g_screen_height, 0); + menu_darken_bg(g_menuscreen_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h, 0); len = strlen(fname); - if (len > g_screen_width / me_sfont_w) - len = g_screen_width / me_sfont_w; + if (len > g_menuscreen_w / me_sfont_w) + len = g_menuscreen_w / me_sfont_w; - mid = g_screen_width / 2; + mid = g_menuscreen_w / 2; text_out16(mid - me_mfont_w * 15 / 2, 8 * me_mfont_h, "About to delete"); smalltext_out16(mid - len * me_sfont_w / 2, 9 * me_mfont_h + 5, fname, 0xbdff); text_out16(mid - me_mfont_w * 13 / 2, 11 * me_mfont_h, "Are you sure?"); @@ -817,7 +828,7 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) int max_cnt, start, i, x, pos; void *darken_ptr; - max_cnt = g_screen_height / me_sfont_h; + max_cnt = g_menuscreen_h / me_sfont_h; start = max_cnt / 2 - sel; n--; // exclude current dir (".") @@ -826,8 +837,8 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) // if (!rom_loaded) // menu_darken_bg(gp2x_screen, 320*240, 0); - darken_ptr = (short *)g_screen_ptr + g_screen_width * max_cnt/2 * me_sfont_h; - menu_darken_bg(darken_ptr, darken_ptr, g_screen_width * me_sfont_h * 8 / 10, 0); + darken_ptr = (short *)g_menuscreen_ptr + g_menuscreen_w * max_cnt/2 * me_sfont_h; + menu_darken_bg(darken_ptr, darken_ptr, g_menuscreen_w * me_sfont_h * 8 / 10, 0); x = 5 + me_mfont_w + 1; if (start - 2 >= 0) @@ -1024,7 +1035,7 @@ static void draw_patchlist(int sel) { int max_cnt, start, i, pos, active; - max_cnt = g_screen_height / me_sfont_h; + max_cnt = g_menuscreen_h / me_sfont_h; start = max_cnt / 2 - sel; plat_video_menu_begin(); @@ -1113,9 +1124,9 @@ static void draw_savestate_menu(int menu_sel, int is_loading) w = (13 + 2) * me_mfont_w; h = (1+2+10+1) * me_mfont_h; - x = g_screen_width / 2 - w / 2; + x = g_menuscreen_w / 2 - w / 2; if (x < 0) x = 0; - y = g_screen_height / 2 - h / 2; + y = g_menuscreen_h / 2 - h / 2; if (y < 0) y = 0; plat_video_menu_begin(); @@ -1257,8 +1268,8 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ int x, y, w, i; w = ((player_idx >= 0) ? 20 : 30) * me_mfont_w; - x = g_screen_width / 2 - w / 2; - y = (g_screen_height - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2; + x = g_menuscreen_w / 2 - w / 2; + y = (g_menuscreen_h - 4 * me_mfont_h) / 2 - (2 + opt_cnt) * me_mfont_h / 2; if (x < me_mfont_w * 2) x = me_mfont_w * 2; @@ -1279,23 +1290,23 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_ w = strlen(dev_name) * me_mfont_w; if (w < 30 * me_mfont_w) w = 30 * me_mfont_w; - if (w > g_screen_width) - w = g_screen_width; + if (w > g_menuscreen_w) + w = g_menuscreen_w; - x = g_screen_width / 2 - w / 2; + x = g_menuscreen_w / 2 - w / 2; if (!is_bind) { snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK)); snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2, in_get_key_name(-1, -PBTN_MA2)); - text_out16(x, g_screen_height - 4 * me_mfont_h, buff); + text_out16(x, g_menuscreen_h - 4 * me_mfont_h, buff); } else - text_out16(x, g_screen_height - 4 * me_mfont_h, "Press a button to bind/unbind"); + text_out16(x, g_menuscreen_h - 4 * me_mfont_h, "Press a button to bind/unbind"); if (dev_count > 1) { - text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name); - text_out16(x, g_screen_height - 2 * me_mfont_h, "Press left/right for other devs"); + text_out16(x, g_menuscreen_h - 3 * me_mfont_h, dev_name); + text_out16(x, g_menuscreen_h - 2 * me_mfont_h, "Press left/right for other devs"); } plat_video_menu_end(); @@ -1881,7 +1892,7 @@ static void draw_text_debug(const char *str, int skip, int from) } str = p; - for (line = from; line < g_screen_height / me_sfont_h; line++) + for (line = from; line < g_menuscreen_h / me_sfont_h; line++) { smalltext_out16(1, line * me_sfont_h, str, 0xffff); while (*p && *p != '\n') @@ -1907,10 +1918,10 @@ static void draw_frame_debug(void) if (PicoDrawMask & PDRAW_SPRITES_HI_ON) memcpy(layer_str + 19, "spr_hi", 6); if (PicoDrawMask & PDRAW_32X_ON) memcpy(layer_str + 26, "32x", 4); - memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); + memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); pemu_forced_frame(0, 0); smalltext_out16(4, 1, "build: r" REVISION " "__DATE__ " " __TIME__ " " COMPILER, 0xffff); - smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff); + smalltext_out16(4, g_menuscreen_h - me_sfont_h, layer_str, 0xffff); } static void debug_menu_loop(void) @@ -1928,23 +1939,23 @@ static void debug_menu_loop(void) plat_debug_cat(tmp); draw_text_debug(tmp, 0, 0); if (dumped) { - smalltext_out16(g_screen_width - 6 * me_sfont_h, - g_screen_height - me_mfont_h, "dumped", 0xffff); + smalltext_out16(g_menuscreen_w - 6 * me_sfont_h, + g_menuscreen_h - me_mfont_h, "dumped", 0xffff); dumped = 0; } break; case 1: draw_frame_debug(); break; - case 2: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); + case 2: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); pemu_forced_frame(0, 1); - menu_darken_bg(g_screen_ptr, g_screen_ptr, g_screen_width * g_screen_height, 0); - PDebugShowSpriteStats((unsigned short *)g_screen_ptr + (g_screen_height/2 - 240/2)*g_screen_width + - g_screen_width/2 - 320/2, g_screen_width); + menu_darken_bg(g_menuscreen_ptr, g_menuscreen_ptr, g_menuscreen_w * g_menuscreen_h, 0); + PDebugShowSpriteStats((unsigned short *)g_menuscreen_ptr + (g_menuscreen_h/2 - 240/2)*g_menuscreen_w + + g_menuscreen_w/2 - 320/2, g_menuscreen_w); break; - case 3: memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2); - PDebugShowPalette(g_screen_ptr, g_screen_width); - PDebugShowSprite((unsigned short *)g_screen_ptr + g_screen_width*120 + g_screen_width/2 + 16, - g_screen_width, spr_offs); + case 3: memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); + PDebugShowPalette(g_menuscreen_ptr, g_menuscreen_w); + PDebugShowSprite((unsigned short *)g_menuscreen_ptr + g_menuscreen_w*120 + g_menuscreen_w/2 + 16, + g_menuscreen_w, spr_offs); draw_text_debug(PDebugSpriteList(), spr_offs, 6); break; case 4: plat_video_menu_begin(); diff --git a/platform/common/menu.h b/platform/common/menu.h index 74bf8e6..64a70a7 100644 --- a/platform/common/menu.h +++ b/platform/common/menu.h @@ -1,5 +1,7 @@ // (c) Copyright 2006-2009 notaz, All rights reserved. +#include "port_config.h" + typedef enum { MB_NONE = 1, /* no auto processing */ @@ -73,6 +75,10 @@ typedef enum MA_OPT3_VSYNC, MA_OPT3_GAMMAA, MA_OPT3_BLACKLVL, + MA_OPT3_LAYER_X, + MA_OPT3_LAYER_Y, + MA_OPT3_LAYER_W, + MA_OPT3_LAYER_H, MA_OPT3_DONE, MA_CDOPT_TESTBIOS_USA, MA_CDOPT_TESTBIOS_EUR, @@ -108,9 +114,9 @@ typedef struct int mask; /* bit to toggle for on/off */ signed short min; /* for ranged integer settings, to be sign-extended */ signed short max; - int enabled:1; - int need_to_save:1; - int selectable:1; + unsigned int enabled:1; + unsigned int need_to_save:1; + unsigned int selectable:1; int (*handler)(menu_id id, int keys); const char * (*generate_name)(menu_id id, int *offs); const void *data; @@ -138,6 +144,9 @@ typedef struct #define mee_range(name, id, var, min, max) \ { name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL, NULL, NULL } +#define mee_range_hide(name, id, var, min, max) \ + { name, MB_OPT_RANGE, id, &(var), 0, min, max, 0, 1, 0, NULL, NULL, NULL, NULL } + #define mee_cust_s_h(name, id, need_save, handler, name_func, help) \ { name, MB_OPT_CUSTOM, id, NULL, 0, 0, 0, 1, need_save, 1, handler, name_func, NULL, help } @@ -174,7 +183,16 @@ typedef struct extern me_bind_action me_ctrl_actions[15]; extern me_bind_action emuctrl_actions[]; // platform code +extern void *g_menubg_src_ptr; extern void *g_menubg_ptr; +extern void *g_menuscreen_ptr; +#if SCREEN_SIZE_FIXED +#define g_menuscreen_w MSCREEN_WIDTH +#define g_menuscreen_h MSCREEN_HEIGHT +#else +extern int g_menuscreen_w; +extern int g_menuscreen_h; +#endif void menu_init(void); void menu_plat_setup(int is_wiz); diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index ad6b59b..b019c3b 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -13,6 +13,7 @@ #include #include +#include #include "plat_gp2x.h" #include "soc.h" @@ -871,6 +872,10 @@ void pemu_loop_prep(void) vidResetMode(); scaling_update(); + // dirty buffers better go now than during gameplay + sync(); + sleep(0); + pemu_sound_start(); } diff --git a/platform/gp2x/plat.c b/platform/gp2x/plat.c index d1e6d80..f0be14e 100644 --- a/platform/gp2x/plat.c +++ b/platform/gp2x/plat.c @@ -85,6 +85,7 @@ void plat_video_menu_enter(int is_rom_loaded) void plat_video_menu_begin(void) { memcpy(g_screen_ptr, gp2x_screens[2], 320*240*2); + g_menuscreen_ptr = g_screen_ptr; } void plat_video_menu_end(void) diff --git a/platform/gp2x/port_config.h b/platform/gp2x/port_config.h index c4c1d0f..2002302 100644 --- a/platform/gp2x/port_config.h +++ b/platform/gp2x/port_config.h @@ -11,6 +11,8 @@ #define SCREEN_SIZE_FIXED 1 #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 +#define MSCREEN_WIDTH SCREEN_WIDTH +#define MSCREEN_HEIGHT SCREEN_HEIGHT // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? diff --git a/platform/linux/emu.c b/platform/linux/emu.c index 1d9c2bb..b582072 100644 --- a/platform/linux/emu.c +++ b/platform/linux/emu.c @@ -179,6 +179,7 @@ void plat_video_menu_enter(int is_rom_loaded) void plat_video_menu_begin(void) { memcpy32(g_screen_ptr, g_menubg_ptr, g_screen_width * g_screen_height * 2 / 4); + g_menubg_ptr = g_screen_ptr; } void plat_video_menu_end(void) diff --git a/platform/linux/io.c b/platform/linux/io.c index 63e3da8..7fff211 100644 --- a/platform/linux/io.c +++ b/platform/linux/io.c @@ -252,8 +252,8 @@ static void xlib_init(void) static void realloc_screen(void) { int size = scr_w * scr_h * 2; - g_screen_width = scr_w; - g_screen_height = scr_h; + g_menuscreen_w = scr_w; + g_menuscreen_h = scr_h; g_screen_ptr = realloc(g_screen_ptr, size); g_menubg_ptr = realloc(g_menubg_ptr, size); memset(g_screen_ptr, 0, size); @@ -322,6 +322,8 @@ void plat_init(void) ret = vout_fbdev_init(&w, &h); if (ret != 0) exit(1); + g_menuscreen_w = w; + g_menuscreen_h = h; g_screen_width = w; g_menubg_ptr = realloc(g_menubg_ptr, w * g_screen_height * 2); PicoDraw2FB = g_menubg_ptr; diff --git a/platform/linux/port_config.h b/platform/linux/port_config.h index d9ccb47..d8fa108 100644 --- a/platform/linux/port_config.h +++ b/platform/linux/port_config.h @@ -12,6 +12,8 @@ #define SCREEN_SIZE_FIXED 0 #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 +#define MSCREEN_WIDTH SCREEN_WIDTH +#define MSCREEN_HEIGHT SCREEN_HEIGHT // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? diff --git a/platform/pandora/Makefile b/platform/pandora/Makefile index 4827a54..20d1b23 100644 --- a/platform/pandora/Makefile +++ b/platform/pandora/Makefile @@ -19,9 +19,6 @@ asm_cdmemory = 1 #profile = 1 #drc_debug = 3 -no_32x = 1 -no_sms = 1 - -include Makefile.local ifeq "$(use_musashi)" "1" @@ -46,7 +43,7 @@ LD = $(CROSS)ld OBJCOPY = $(CROSS)objcopy # frontend -OBJS += pandora.o emu.o asm_utils.o +OBJS += plat.o asm_utils.o # common OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o platform/common/config.o \ @@ -96,6 +93,8 @@ readme.txt: ../../tools/textfilter ../base_readme.txt PicoDrive.pxml: PicoDrive.pxml.template ./make_pxml.sh PicoDrive.pxml.template PicoDrive.pxml +platform/common/menu.o: menu.c + # ----------- release ----------- VER = $(shell head -n 1 version.h | sed 's/.*"\(.*\)\.\(.*\)".*/\1\2/g') diff --git a/platform/pandora/emu.c b/platform/pandora/emu.c deleted file mode 100644 index 7996a79..0000000 --- a/platform/pandora/emu.c +++ /dev/null @@ -1,449 +0,0 @@ -// (c) Copyright 2006-2009 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. - -#include -#include - -#include "../common/emu.h" -#include "../common/menu.h" -#include "../common/plat.h" -#include "../common/arm_utils.h" -#include "../linux/sndout_oss.h" -#include "../linux/fbdev.h" -#include "asm_utils.h" -#include "version.h" - -#include - - -static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; -static unsigned char temp_frame[g_screen_width * g_screen_height * 2]; -unsigned char *PicoDraw2FB = temp_frame; -const char *renderer_names[] = { NULL }; -const char *renderer_names32x[] = { NULL }; -char cpu_clk_name[] = "Max CPU clock"; - -enum { - SCALE_1x1, - SCALE_2x2_3x2, - SCALE_2x2_2x2, -}; - -static int get_cpu_clock(void) -{ - FILE *f; - int ret = 0; - f = fopen("/proc/pandora/cpu_mhz_max", "r"); - if (f) { - fscanf(f, "%d", &ret); - fclose(f); - } - return ret; -} - -void pemu_prep_defconfig(void) -{ - // XXX: move elsewhere - g_menubg_ptr = temp_frame; - - defaultConfig.EmuOpt |= EOPT_VSYNC; - defaultConfig.s_PicoOpt |= POPT_EN_MCD_GFX|POPT_EN_MCD_PSYNC; - defaultConfig.scaling = SCALE_2x2_3x2; -} - -void pemu_validate_config(void) -{ - currentConfig.CPUclock = get_cpu_clock(); -} - -// FIXME: cleanup -static void osd_text(int x, int y, const char *text) -{ - int len = strlen(text)*8; - - if (0) { - int *p, i, h; - x &= ~3; // align x - len = (len+3) >> 2; - for (h = 0; h < 8; h++) { - p = (int *) ((unsigned char *) g_screen_ptr+x+g_screen_width*(y+h)); - for (i = len; i; i--, p++) *p = 0xe0e0e0e0; - } - emu_text_out8(x, y, text); - } else { - int *p, i, h; - x &= ~1; // align x - len++; - for (h = 0; h < 16; h++) { - p = (int *) ((unsigned short *) g_screen_ptr+x+g_screen_width*(y+h)); - for (i = len; i; i--, p++) *p = 0;//(*p>>2)&0x39e7; - } - text_out16(x, y, text); - } -} - -static void draw_cd_leds(void) -{ -// static - int old_reg; -// if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change // mmu hack problems? - old_reg = Pico_mcd->s68k_regs[0]; - - if (0) { - // 8-bit modes - unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; - unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; - *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) = - *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) = - *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g; - *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) = - *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) = - *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r; - } else { - // 16-bit modes - unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4); - unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0; - unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0; - *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2; - *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2; - *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; - } -} - -static int emuscan_1x1(unsigned int num) -{ - DrawLineDest = (unsigned short *)g_screen_ptr + - g_screen_width * g_screen_height / 2 - g_screen_width * 240 / 2 + - num*g_screen_width + g_screen_width/2 - 320/2; - - return 0; -} - -#define MAKE_EMUSCAN(name_, clut_name_, offs_, len_) \ -static int name_(unsigned int num) \ -{ \ - unsigned char *ps = HighCol+8; \ - unsigned short *pd, *pal = HighPal; \ - int sh = Pico.video.reg[0xC] & 8; \ - int mask = 0xff; \ - \ - pd = (unsigned short *)g_screen_ptr + num*800*2 + offs_;\ - \ - if (Pico.m.dirtyPal) \ - PicoDoHighPal555(sh); \ - \ - if (!sh && (rendstatus & PDRAW_SPR_LO_ON_HI)) \ - mask = 0x3f; /* upper bits are priority stuff */\ - \ - clut_line##clut_name_(pd, ps, pal, (mask<<16) | len_); \ - \ - return 0; \ -} - -MAKE_EMUSCAN(emuscan_2x2_40, 2x2, 800/2 - 320*2/2, 320) -MAKE_EMUSCAN(emuscan_2x2_32, 2x2, 800/2 - 256*2/2, 256) -MAKE_EMUSCAN(emuscan_3x2_32, 3x2, 800/2 - 256*3/2, 256) - -#if 0 /* FIXME */ -static int EmuScanEnd16_32x(unsigned int num) -{ - unsigned int *ps; - unsigned int *pd; - int len; - - ps = (unsigned int *)temp_frame; - pd = (unsigned int *)g_screen_ptr + (num*800*2 + 800/2 - 320*2/2) / 2; - - for (len = 320/2; len > 0; len--, ps++) { - unsigned int p, p1; - p1 = *ps; - p = p1 << 16; - p |= p >> 16; - *pd = pd[800/2] = p; - pd++; - - p = p1 >> 16; - p |= p << 16; - *pd = pd[800/2] = p; - pd++; - } - - return 0; -} -#endif - -void pemu_finalize_frame(const char *fps, const char *notice) -{ - if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) { - if (notice) - osd_text(4, 464, notice); - if (currentConfig.EmuOpt & EOPT_SHOW_FPS) - osd_text(640, 464, fps); - } - if ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) - draw_cd_leds(); -} - -void plat_video_toggle_renderer(int change, int is_menu) -{ - // this will auto-select SMS/32X renderers - PicoDrawSetOutFormat(PDF_RGB555, 1); -} - -void plat_video_menu_enter(int is_rom_loaded) -{ -} - -void plat_video_menu_begin(void) -{ - memcpy32(g_screen_ptr, g_menubg_ptr, g_screen_width * g_screen_height * 2 / 4); -} - -void plat_video_menu_end(void) -{ - plat_video_flip(); -} - -void plat_status_msg_clear(void) -{ - int s = g_screen_width * g_screen_height * 2; - int l = g_screen_width * 16 * 2; - int i; - - for (i = 0; i < fbdev_buffer_count; i++) - memset32((int *)((char *)fbdev_buffers[i] + s - l), 0, l / 4); -} - -void plat_status_msg_busy_next(const char *msg) -{ - plat_status_msg_clear(); - pemu_finalize_frame("", msg); - plat_video_flip(); - emu_status_msg(""); - reset_timing = 1; -} - -void plat_status_msg_busy_first(const char *msg) -{ -// memset32(g_screen_ptr, 0, g_screen_width * g_screen_height * 2 / 4); - plat_status_msg_busy_next(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; - } -} - -void pemu_forced_frame(int opts, int no_scale) -{ - int oldscale = currentConfig.scaling; - int po_old = PicoOpt; - - if (no_scale) { - currentConfig.scaling = SCALE_1x1; - emu_video_mode_change(0, 0, 0); - } - - PicoOpt &= ~POPT_ALT_RENDERER; - PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites - - Pico.m.dirtyPal = 1; - PicoFrameDrawOnly(); - - PicoOpt = po_old; - currentConfig.scaling = oldscale; -} - -static void updateSound(int len) -{ - unsigned int t; - - len <<= 1; - if (PicoOpt & POPT_EN_STEREO) - len <<= 1; - - // sndout_oss_can_write() not reliable.. - 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); -} - -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++; - - 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); - //sndout_oss_setvol(currentConfig.volume, currentConfig.volume); - PicoWriteSound = updateSound; - 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 -} - -void plat_debug_cat(char *str) -{ -} - -void emu_video_mode_change(int start_line, int line_count, int is_32cols) -{ - int i; - - // clear whole screen in all buffers - for (i = 0; i < fbdev_buffer_count; i++) - memset32(fbdev_buffers[i], 0, g_screen_width * g_screen_height * 2 / 4); - - PicoScanBegin = NULL; - PicoScanEnd = NULL; - -#if 0 - if (PicoAHW & PAHW_32X) { - /* FIXME */ - DrawLineDest = (unsigned short *)temp_frame; - PicoDrawSetOutFormat(PDF_RGB555, 1); - PicoScanEnd = EmuScanEnd16_32x; - } else -#endif - { - switch (currentConfig.scaling) { - case SCALE_1x1: - PicoDrawSetOutFormat(PDF_RGB555, 1); - PicoScanBegin = emuscan_1x1; - break; - case SCALE_2x2_3x2: - PicoDrawSetOutFormat(PDF_NONE, 0); - PicoScanEnd = is_32cols ? emuscan_3x2_32 : emuscan_2x2_40; - break; - case SCALE_2x2_2x2: - PicoDrawSetOutFormat(PDF_NONE, 0); - PicoScanEnd = is_32cols ? emuscan_2x2_32 : emuscan_2x2_40; - break; - } - } -} - -void pemu_loop_prep(void) -{ - if (currentConfig.CPUclock != get_cpu_clock()) { - char buf[64]; - snprintf(buf, sizeof(buf), "sudo /usr/pandora/scripts/op_cpuspeed.sh %d", - currentConfig.CPUclock); - system(buf); - } - - pemu_sound_start(); -} - -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_ALT_RENDERER; - PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; - currentConfig.EmuOpt |= EOPT_16BPP; - - PicoDrawSetOutFormat(PDF_RGB555, 1); - Pico.m.dirtyPal = 1; - PicoFrame(); - - PicoOpt = po_old; - currentConfig.EmuOpt = eo_old; -} - -void plat_wait_till_us(unsigned int us_to) -{ - unsigned int now; - signed int diff; - - now = plat_get_ticks_us(); - - // XXX: need to check NOHZ - diff = (signed int)(us_to - now); - if (diff > 10000) { - //printf("sleep %d\n", us_to - now); - usleep(diff * 15 / 16); - now = plat_get_ticks_us(); - //printf(" wake %d\n", (signed)(us_to - now)); - } -/* - while ((signed int)(us_to - now) > 512) { - spend_cycles(1024); - now = plat_get_ticks_us(); - } -*/ -} - -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"; -} diff --git a/platform/pandora/menu.c b/platform/pandora/menu.c index a9a54ab..ae2a079 100644 --- a/platform/pandora/menu.c +++ b/platform/pandora/menu.c @@ -1,14 +1,143 @@ -static const char *men_scaler[] = { "1x1, 1x1", "2x2, 3x2", "2x2, 2x2", NULL }; +#include "plat.h" + +static const char *men_scaler[] = { "1x1, 1x1", "2x2, 3x2", "2x2, 2x2", "fullscreen", "custom", NULL }; static const char h_scaler[] = "Scalers for 40 and 32 column modes\n" "(320 and 256 pixel wide horizontal)"; +static const char h_cscaler[] = "Displays the scaler layer, you can resize it\n" + "using d-pad or move it using R+d-pad"; +static const char *men_dummy[] = { NULL }; +char **pnd_filter_list; +int g_layer_cx = 80, g_layer_cy = 0; +int g_layer_cw = 640, g_layer_ch = 480; + +static int menu_loop_cscaler(menu_id id, int keys) +{ + unsigned int inp; + + currentConfig.scaling = SCALE_CUSTOM; + + pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch); + pnd_restore_layer_data(); + + for (;;) + { + plat_video_menu_begin(); + memset(g_menuscreen_ptr, 0, g_menuscreen_w * g_menuscreen_h * 2); + text_out16(2, 480 - 18, "%dx%d | d-pad to resize, R+d-pad to move", g_layer_cw, g_layer_ch); + plat_video_menu_end(); + + inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40); + if (inp & PBTN_UP) g_layer_cy--; + if (inp & PBTN_DOWN) g_layer_cy++; + if (inp & PBTN_LEFT) g_layer_cx--; + if (inp & PBTN_RIGHT) g_layer_cx++; + if (!(inp & PBTN_R)) { + if (inp & PBTN_UP) g_layer_ch += 2; + if (inp & PBTN_DOWN) g_layer_ch -= 2; + if (inp & PBTN_LEFT) g_layer_cw += 2; + if (inp & PBTN_RIGHT) g_layer_cw -= 2; + } + if (inp & (PBTN_MOK|PBTN_MBACK)) + break; + + if (inp & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)) { + if (g_layer_cx < 0) g_layer_cx = 0; + if (g_layer_cx > 640) g_layer_cx = 640; + if (g_layer_cy < 0) g_layer_cy = 0; + if (g_layer_cy > 420) g_layer_cy = 420; + if (g_layer_cw < 160) g_layer_cw = 160; + if (g_layer_ch < 60) g_layer_ch = 60; + if (g_layer_cx + g_layer_cw > 800) + g_layer_cw = 800 - g_layer_cx; + if (g_layer_cy + g_layer_ch > 480) + g_layer_ch = 480 - g_layer_cy; + pnd_setup_layer(1, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch); + } + } + + pnd_setup_layer(0, g_layer_cx, g_layer_cy, g_layer_cw, g_layer_ch); + + return 0; +} #define MENU_OPTIONS_GFX \ - mee_onoff ("Vsync", MA_OPT2_VSYNC, currentConfig.EmuOpt, EOPT_VSYNC), \ mee_enum_h ("Scaler", MA_OPT_SCALING, currentConfig.scaling, \ - men_scaler, h_scaler), + men_scaler, h_scaler), \ + mee_enum ("Filter", MA_OPT3_FILTERING, currentConfig.filter, men_dummy), \ + mee_onoff ("Vsync", MA_OPT2_VSYNC, currentConfig.EmuOpt, EOPT_VSYNC), \ + mee_cust_h ("Setup custom scaler", MA_NONE, menu_loop_cscaler, NULL, h_cscaler), \ + mee_range_hide("layer_x", MA_OPT3_LAYER_X, g_layer_cx, 0, 640), \ + mee_range_hide("layer_y", MA_OPT3_LAYER_Y, g_layer_cy, 0, 420), \ + mee_range_hide("layer_w", MA_OPT3_LAYER_W, g_layer_cw, 160, 800), \ + mee_range_hide("layer_h", MA_OPT3_LAYER_H, g_layer_ch, 60, 480), \ #define MENU_OPTIONS_ADV \ mee_onoff ("SVP dynarec", MA_OPT2_SVP_DYNAREC, PicoOpt, POPT_EN_SVP_DRC), \ mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC), #define menu_main_plat_draw NULL + +#include +#include + +static menu_entry e_menu_gfx_options[]; + +void pnd_menu_init(void) +{ + struct dirent *ent; + int i, count = 0; + char **mfilters; + char buff[64]; + DIR *dir; + + dir = opendir("/etc/pandora/conf/dss_fir"); + if (dir == NULL) { + perror("filter opendir"); + return; + } + + while (1) { + errno = 0; + ent = readdir(dir); + if (ent == NULL) { + if (errno != 0) + perror("readdir"); + break; + } + if (strstr(ent->d_name, "_up_h")) + count++; + } + + if (count == 0) + return; + + mfilters = calloc(count + 1, sizeof(mfilters[0])); + if (mfilters == NULL) + return; + + rewinddir(dir); + for (i = 0; (ent = readdir(dir)); ) { + char *pos; + size_t len; + + pos = strstr(ent->d_name, "_up_h"); + if (pos == NULL) + continue; + + len = pos - ent->d_name; + if (len > sizeof(buff) - 1) + continue; + + strncpy(buff, ent->d_name, len); + buff[len] = 0; + mfilters[i] = strdup(buff); + if (mfilters[i] != NULL) + i++; + } + closedir(dir); + + i = me_id2offset(e_menu_gfx_options, MA_OPT3_FILTERING); + e_menu_gfx_options[i].data = (void *)mfilters; + pnd_filter_list = mfilters; +} + diff --git a/platform/pandora/pandora.c b/platform/pandora/pandora.c deleted file mode 100644 index 5541c2d..0000000 --- a/platform/pandora/pandora.c +++ /dev/null @@ -1,54 +0,0 @@ -#include -#include -#include - -#include "../linux/sndout_oss.h" -#include "../linux/fbdev.h" -#include "../linux/oshide.h" -#include "../common/emu.h" - -void plat_early_init(void) -{ -} - -void plat_init(void) -{ - int ret, w, h; - - oshide_init(); - - ret = vout_fbdev_init(&w, &h); - if (ret != 0) { - fprintf(stderr, "couldn't init framebuffer\n"); - exit(1); - } - - if (w != g_screen_width || h != g_screen_height) { - fprintf(stderr, "%dx%d not supported\n", w, h); - vout_fbdev_finish(); - exit(1); - } - - // snd - sndout_oss_init(); -} - -void plat_finish(void) -{ - sndout_oss_exit(); - vout_fbdev_finish(); - oshide_finish(); - - printf("all done\n"); -} - -/* lprintf */ -void lprintf(const char *fmt, ...) -{ - va_list vl; - - va_start(vl, fmt); - vprintf(fmt, vl); - va_end(vl); -} - diff --git a/platform/pandora/picorestore.c b/platform/pandora/picorestore.c index a278abc..950b98e 100644 --- a/platform/pandora/picorestore.c +++ b/platform/pandora/picorestore.c @@ -5,6 +5,7 @@ #include #include #include +#include #include int main() @@ -14,14 +15,14 @@ int main() fbdev = open("/dev/fb0", O_RDWR); if (fbdev == -1) { - perror("open"); - return 1; + perror("open fb0"); + goto end_fb0; } ret = ioctl(fbdev, FBIOGET_VSCREENINFO, &fbvar); if (ret == -1) { perror("FBIOGET_VSCREENINFO ioctl"); - goto end_fb; + goto end_fb0; } if (fbvar.yoffset != 0) { @@ -34,8 +35,34 @@ int main() printf("ok\n"); } -end_fb: - close(fbdev); +end_fb0: + if (fbdev >= 0) + close(fbdev); + + fbdev = open("/dev/fb1", O_RDWR); + if (fbdev == -1) { + perror("open fb1"); + goto end_fb1; + } + + ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi); + ret |= ioctl(fd, OMAPFB_QUERY_MEM, &mi); + if (ret != 0) + perror("QUERY_*"); + + pi.enabled = 0; + ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi); + if (ret != 0) + perror("SETUP_PLANE"); + + mi.size = 0; + ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); + if (ret != 0) + perror("SETUP_MEM"); + +end_fb1: + if (fbdev >= 0) + close(fbdev); kbdfd = open("/dev/tty", O_RDWR); if (kbdfd == -1) { diff --git a/platform/pandora/plat.c b/platform/pandora/plat.c new file mode 100644 index 0000000..5992f73 --- /dev/null +++ b/platform/pandora/plat.c @@ -0,0 +1,646 @@ +// (c) Copyright 2006-2009 notaz, All rights reserved. +// Free for non-commercial use. + +// For commercial use, separate licencing terms must be obtained. + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../common/emu.h" +#include "../common/menu.h" +#include "../common/plat.h" +#include "../common/arm_utils.h" +#include "../linux/sndout_oss.h" +#include "../linux/fbdev.h" +#include "plat.h" +#include "asm_utils.h" +#include "version.h" + +#include + + +static struct vout_fbdev *main_fb, *layer_fb; +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 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; +const char *renderer_names[] = { NULL }; +const char *renderer_names32x[] = { NULL }; +char cpu_clk_name[] = "Max CPU clock"; + +static int get_cpu_clock(void) +{ + FILE *f; + int ret = 0; + f = fopen("/proc/pandora/cpu_mhz_max", "r"); + if (f) { + fscanf(f, "%d", &ret); + fclose(f); + } + return ret; +} + +void pemu_prep_defconfig(void) +{ + defaultConfig.EmuOpt |= EOPT_VSYNC|EOPT_16BPP; + defaultConfig.s_PicoOpt |= POPT_EN_MCD_GFX|POPT_EN_MCD_PSYNC; + 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); +} + +static void draw_cd_leds(void) +{ + int old_reg; + old_reg = Pico_mcd->s68k_regs[0]; + + if (0) { + // 8-bit modes + unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; + unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+ 4) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+ 4) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+ 4) = col_g; + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*2+12) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*3+12) = + *(unsigned int *)((char *)g_screen_ptr + g_screen_width*4+12) = col_r; + } else { + // 16-bit modes + unsigned int *p = (unsigned int *)((short *)g_screen_ptr + g_screen_width*2+4); + unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0; + unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; p += g_screen_width/2 - 12/2; + *p++ = col_g; *p++ = col_g; p+=2; *p++ = col_r; *p++ = col_r; + } +} + +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 || (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 ((PicoAHW & PAHW_MCD) && (currentConfig.EmuOpt & EOPT_EN_CD_LEDS)) + draw_cd_leds(); +} + +void plat_video_flip(void) +{ + g_screen_ptr = vout_fbdev_flip(layer_fb); +} + +void plat_video_toggle_renderer(int change, int is_menu) +{ +} + +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) +{ + g_menuscreen_ptr = vout_fbdev_flip(main_fb); +} + +void plat_video_wait_vsync(void) +{ + vout_fbdev_wait_vsync(main_fb); +} + +void plat_status_msg_clear(void) +{ + vout_fbdev_clear_lines(layer_fb, g_screen_height - 8, 8); +} + +void plat_status_msg_busy_next(const char *msg) +{ + plat_status_msg_clear(); + pemu_finalize_frame("", msg); + plat_video_flip(); + emu_status_msg(""); + reset_timing = 1; +} + +void plat_status_msg_busy_first(const char *msg) +{ + plat_status_msg_busy_next(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; + } +} + +void pemu_forced_frame(int opts, int no_scale) +{ + int oldscale = currentConfig.scaling; + int po_old = PicoOpt; + + if (no_scale) { + currentConfig.scaling = SCALE_1x1; + emu_video_mode_change(8, 224, 0); + } + + PicoOpt |= opts|POPT_ACC_SPRITES; + + Pico.m.dirtyPal = 1; + PicoFrameDrawOnly(); + + PicoOpt = po_old; + currentConfig.scaling = oldscale; +} + +static void updateSound(int len) +{ + unsigned int t; + + len <<= 1; + if (PicoOpt & POPT_EN_STEREO) + len <<= 1; + + // sndout_oss_can_write() not reliable.. + 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); +} + +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 + * 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); + //sndout_oss_setvol(currentConfig.volume, currentConfig.volume); + PicoWriteSound = updateSound; + 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 +} + +void plat_debug_cat(char *str) +{ +} + +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 ret; + + ret = ioctl(fd, OMAPFB_QUERY_PLANE, &pi); + if (ret != 0) { + perror("QUERY_PLANE"); + return -1; + } + + ret = ioctl(fd, OMAPFB_QUERY_MEM, &mi); + if (ret != 0) { + perror("QUERY_MEM"); + return -1; + } + + /* must disable when changing stuff */ + if (pi.enabled) { + pi.enabled = 0; + ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi); + if (ret != 0) + perror("SETUP_PLANE"); + } + + mi.size = 320*240*2*4; + ret = ioctl(fd, OMAPFB_SETUP_MEM, &mi); + if (ret != 0) { + perror("SETUP_MEM"); + return -1; + } + + pi.pos_x = x; + pi.pos_y = y; + pi.out_width = w; + pi.out_height = h; + pi.enabled = enabled; + + ret = ioctl(fd, OMAPFB_SETUP_PLANE, &pi); + if (ret != 0) { + perror("SETUP_PLANE"); + return -1; + } + + return 0; +} + +int pnd_setup_layer(int enabled, int x, int y, int w, int h) +{ + return pnd_setup_layer_(vout_fbdev_get_fd(layer_fb), enabled, x, y, w, h); +} + +void pnd_restore_layer_data(void) +{ + 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. + 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); + 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; + + PicoScanBegin = emuscan; + PicoScanEnd = NULL; + PicoDrawSetOutFormat(PDF_RGB555, 1); + + if (is_32cols) { + fb_w = 256; + fb_left = fb_right = 32; + } + + switch (currentConfig.scaling) { + case SCALE_1x1: + g_layer_w = fb_w; + g_layer_h = fb_h; + break; + case SCALE_2x2_3x2: + g_layer_w = fb_w * (is_32cols ? 3 : 2); + g_layer_h = fb_h * 2; + break; + case SCALE_2x2_2x2: + g_layer_w = fb_w * 2; + g_layer_h = fb_h * 2; + break; + case SCALE_FULLSCREEN: + g_layer_w = 800; + g_layer_h = 480; + break; + case SCALE_CUSTOM: + g_layer_x = g_layer_cx; + g_layer_y = g_layer_cy; + g_layer_w = g_layer_cw; + g_layer_h = g_layer_ch; + break; + } + + if (currentConfig.scaling != SCALE_CUSTOM) { + // center the layer + g_layer_x = 800 / 2 - g_layer_w / 2; + g_layer_y = 480 / 2 - g_layer_h / 2; + } + + switch (currentConfig.scaling) { + case SCALE_FULLSCREEN: + case SCALE_CUSTOM: + fb_top = start_line; + fb_h = line_count; + break; + } + g_osd_fps_x = is_32cols ? 232 : 264; + 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; + } + } +} + +void pemu_loop_prep(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, 800 * 480 * 2 / 4); + g_menuscreen_ptr = vout_fbdev_flip(main_fb); + + // emu_video_mode_change will call pnd_setup_layer() + + // dirty buffers better go now than during gameplay + sync(); + sleep(0); + + pemu_sound_start(); +} + +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(); + + 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) +{ + unsigned int now; + signed int diff; + + now = plat_get_ticks_us(); + + // XXX: need to check NOHZ + diff = (signed int)(us_to - now); + if (diff > 10000) { + //printf("sleep %d\n", us_to - now); + usleep(diff * 15 / 16); + now = plat_get_ticks_us(); + //printf(" wake %d\n", (signed)(us_to - now)); + } +/* + while ((signed int)(us_to - now) > 512) { + spend_cycles(1024); + now = plat_get_ticks_us(); + } +*/ +} + +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) +{ +} + +void plat_init(void) +{ + const char *main_fb_name, *layer_fb_name; + int fd, ret, w, h; + + main_fb_name = getenv("FBDEV_MAIN"); + if (main_fb_name == NULL) + main_fb_name = "/dev/fb0"; + + layer_fb_name = getenv("FBDEV_LAYER"); + if (layer_fb_name == NULL) + layer_fb_name = "/dev/fb1"; + + // must set the layer up first to be able to use it + fd = open(layer_fb_name, O_RDWR); + if (fd == -1) { + fprintf(stderr, "%s: ", layer_fb_name); + perror("open"); + exit(1); + } + + ret = pnd_setup_layer_(fd, 0, g_layer_x, g_layer_y, g_layer_w, g_layer_h); + close(fd); + if (ret != 0) { + fprintf(stderr, "failed to set up layer, exiting.\n"); + exit(1); + } + + oshide_init(); + + w = h = 0; + main_fb = vout_fbdev_init(main_fb_name, &w, &h, 0); + 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_ptr = vout_fbdev_flip(main_fb); + + w = 320; h = 240; + layer_fb = vout_fbdev_init(layer_fb_name, &w, &h, 0); + if (layer_fb == NULL) { + fprintf(stderr, "couldn't init fb: %s\n", layer_fb_name); + goto fail0; + } + + if (w != g_screen_width || h != g_screen_height) { + fprintf(stderr, "%dx%d not supported on %s\n", w, h, layer_fb_name); + goto fail1; + } + g_screen_ptr = vout_fbdev_flip(layer_fb); + + g_menubg_ptr = temp_frame; + g_menubg_src_ptr = temp_frame; + + sndout_oss_init(); + pnd_menu_init(); + return; + +fail1: + vout_fbdev_finish(layer_fb); +fail0: + vout_fbdev_finish(main_fb); + exit(1); +} + +void plat_finish(void) +{ + sndout_oss_exit(); + vout_fbdev_finish(main_fb); + oshide_finish(); + + printf("all done\n"); +} + +/* lprintf */ +void lprintf(const char *fmt, ...) +{ + va_list vl; + + va_start(vl, fmt); + vprintf(fmt, vl); + va_end(vl); +} + diff --git a/platform/pandora/plat.h b/platform/pandora/plat.h new file mode 100644 index 0000000..6cff3da --- /dev/null +++ b/platform/pandora/plat.h @@ -0,0 +1,17 @@ + +extern char **pnd_filter_list; +extern int g_layer_cx, g_layer_cy; +extern int g_layer_cw, g_layer_ch; + +void pnd_menu_init(void); +int pnd_setup_layer(int enabled, int x, int y, int w, int h); +void pnd_restore_layer_data(void); + +enum { + SCALE_1x1, + SCALE_2x2_3x2, + SCALE_2x2_2x2, + SCALE_FULLSCREEN, + SCALE_CUSTOM, +}; + diff --git a/platform/pandora/port_config.h b/platform/pandora/port_config.h index a670c1c..50bc723 100644 --- a/platform/pandora/port_config.h +++ b/platform/pandora/port_config.h @@ -8,8 +8,10 @@ #define REDUCE_IO_CALLS 0 #define SCREEN_SIZE_FIXED 1 -#define SCREEN_WIDTH 800 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 +#define MSCREEN_WIDTH 800 +#define MSCREEN_HEIGHT 480 // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? -- 2.39.2