From: notaz Date: Sun, 10 Jan 2010 17:07:28 +0000 (+0000) Subject: new 32x renderers, auto fskip change, massive refactoring X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=662e622b59369f975691a70756f80188d8d27ea0;p=libpicofe.git new 32x renderers, auto fskip change, massive refactoring git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@855 be3aeb3a-fb24-0410-a615-afba39da0efa --- diff --git a/common/common_arm.mak b/common/common_arm.mak index ce6d711..c14df93 100644 --- a/common/common_arm.mak +++ b/common/common_arm.mak @@ -24,6 +24,10 @@ ifeq "$(asm_cdmemory)" "1" DEFINES += _ASM_CD_MEMORY_C OBJS += pico/cd/memory_arm.o endif +ifeq "$(asm_32xdraw)" "1" +DEFINES += _ASM_32X_DRAW +OBJS += pico/32x/draw_arm.o +endif DIRS += cpu/Cyclone cpu/Cyclone/proj cpu/Cyclone/tools cpu/DrZ80 diff --git a/common/config.c b/common/config.c index a6d4f1d..4292000 100644 --- a/common/config.c +++ b/common/config.c @@ -10,6 +10,7 @@ #include #endif #include "config.h" +#include "plat.h" #include "input.h" #include "lprintf.h" @@ -197,6 +198,7 @@ static int default_var(const menu_entry *me) case MA_OPT2_GAMMA: return defaultConfig.gamma; case MA_OPT_FRAMESKIP: return defaultConfig.Frameskip; case MA_OPT_CPU_CLOCKS: return defaultConfig.CPUclock; + case MA_OPT_RENDERER: return defaultConfig.renderer; case MA_OPT_SAVE_SLOT: default: @@ -217,9 +219,6 @@ static int is_cust_val_default(const menu_entry *me) case MA_OPT_CONFIRM_STATES: return !((defaultConfig.EmuOpt ^ currentConfig.EmuOpt) & (EOPT_CONFIRM_LOAD|EOPT_CONFIRM_SAVE)) == 0; - case MA_OPT_RENDERER: - return ((defaultConfig.s_PicoOpt ^ PicoOpt) & POPT_ALT_RENDERER) == 0 && - ((defaultConfig.EmuOpt ^ currentConfig.EmuOpt) & EOPT_16BPP) == 0; case MA_CDOPT_READAHEAD: return defaultConfig.s_PicoCDBuffers == PicoCDBuffers; default:break; @@ -468,26 +467,21 @@ int config_readlrom(const char *fname) static int custom_read(menu_entry *me, const char *var, const char *val) { char *tmp; - int tmpi; + int i; switch (me->id) { case MA_OPT_RENDERER: - if (strcasecmp(var, "Renderer") != 0) return 0; - if (strcasecmp(val, "8bit fast") == 0 || strcasecmp(val, "fast") == 0) { - PicoOpt |= POPT_ALT_RENDERER; - } - else if (strcasecmp(val, "16bit accurate") == 0 || strcasecmp(val, "accurate") == 0) { - PicoOpt &= ~POPT_ALT_RENDERER; - currentConfig.EmuOpt |= 0x80; - } - else if (strcasecmp(val, "8bit accurate") == 0) { - PicoOpt &= ~POPT_ALT_RENDERER; - currentConfig.EmuOpt &= ~0x80; - } - else + if (strcasecmp(var, "Renderer") != 0 || renderer_names == NULL) return 0; - return 1; + + for (i = 0; renderer_names[i] != NULL; i++) { + if (strcasecmp(val, renderer_names[i]) == 0) { + currentConfig.renderer = i; + return 1; + } + } + return 0; case MA_OPT_SCALING: #ifdef __GP2X__ @@ -589,9 +583,9 @@ static int custom_read(menu_entry *me, const char *var, const char *val) case MA_OPT2_SQUIDGEHACK: if (strcasecmp(var, "Squidgehack") != 0) return 0; - tmpi = atoi(val); - if (tmpi) *(int *)me->var |= me->mask; - else *(int *)me->var &= ~me->mask; + i = atoi(val); + if (i) *(int *)me->var |= me->mask; + else *(int *)me->var &= ~me->mask; return 1; case MA_CDOPT_READAHEAD: diff --git a/common/emu.c b/common/emu.c index f86526c..786a026 100644 --- a/common/emu.c +++ b/common/emu.c @@ -1116,7 +1116,7 @@ static void emu_tray_close(void) void emu_32x_startup(void) { - plat_video_toggle_renderer(0, 1, 0); + plat_video_toggle_renderer(0, 0); system_announce(); } @@ -1247,9 +1247,9 @@ static void run_events_ui(unsigned int which) PicoStateProgressCB = NULL; } } - if ((which & PEV_SWITCH_RND) && !(PicoAHW & PAHW_32X)) + if (which & PEV_SWITCH_RND) { - plat_video_toggle_renderer(1, 0, 0); + plat_video_toggle_renderer(1, 0); } if (which & (PEV_SSLOT_PREV|PEV_SSLOT_NEXT)) { @@ -1493,17 +1493,15 @@ void emu_loop(void) { if ((currentConfig.EmuOpt & EOPT_NO_FRMLIMIT) && currentConfig.Frameskip >= 0) pframes_done = 0; - else { + else pframes_done -= target_fps; - /* don't allow it to drift during heavy slowdowns */ - if (pframes_done < -5) { - reset_timing = 1; - continue; - } - if (pframes_done < -2) - pframes_done = -2; + if (pframes_done < -2) { + /* don't drag more than 2 frames behind */ + pframes_done = -2; + timestamp_base = timestamp - 2 * target_frametime; } - timestamp_base += ms_to_ticks(1000); + else + timestamp_base += ms_to_ticks(1000); } diff = timestamp - timestamp_base; @@ -1528,15 +1526,13 @@ void emu_loop(void) else if (diff > diff_lim) { /* no time left for this frame - skip */ - if (diff - diff_lim >= ms_to_ticks(200)) { - /* if too much behind, reset instead */ - reset_timing = 1; + /* limit auto frameskip to 8 */ + if (frames_done / 8 <= frames_shown) { + emu_update_input(); + skip_frame(diff < diff_lim + target_frametime * 16); + pframes_done++; frames_done++; continue; } - emu_update_input(); - skip_frame(diff < diff_lim + target_frametime * 2); - pframes_done++; frames_done++; - continue; } emu_update_input(); diff --git a/common/emu.h b/common/emu.h index 1f23742..518d5fd 100644 --- a/common/emu.h +++ b/common/emu.h @@ -28,7 +28,7 @@ extern int g_screen_height; #define EOPT_GZIP_SAVES (1<<3) #define EOPT_MMUHACK (1<<4) #define EOPT_NO_AUTOSVCFG (1<<5) -#define EOPT_16BPP (1<<7) +#define EOPT_16BPP (1<<7) // depreceted for .renderer #define EOPT_RAM_TIMINGS (1<<8) #define EOPT_CONFIRM_SAVE (1<<9) #define EOPT_EN_CD_LEDS (1<<10) @@ -67,6 +67,8 @@ typedef struct _currentConfig_t { float hscale32, hscale40; // psp: horizontal scale int gamma2; // psp: black level int turbo_rate; + int renderer; + int renderer32x; } currentConfig_t; extern currentConfig_t currentConfig, defaultConfig; diff --git a/common/menu.c b/common/menu.c index 8accc25..34d5b49 100644 --- a/common/menu.c +++ b/common/menu.c @@ -603,7 +603,6 @@ static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void)) #else #define MENU_OPTIONS_GFX #define MENU_OPTIONS_ADV -#define mgn_opt_renderer NULL /* TODO */ #define menu_main_plat_draw NULL #endif @@ -1494,16 +1493,47 @@ static int menu_loop_cd_options(menu_id id, int keys) // ------------ 32X options menu ------------ +static const char *get_rname(const char **rn, int val, int *offs) +{ + int i, len, found = -1, maxlen = 0; + + for (i = 0; rn[i] != NULL; i++) { + len = strlen(rn[i]); + if (len > maxlen) + maxlen = len; + if (i == val) + found = i; + } + + *offs = 3 - maxlen; + if (found >= 0) + return rn[found]; + return "???"; +} + +static const char *mgn_opt_renderer32x(menu_id id, int *offs) +{ + return get_rname(renderer_names32x, currentConfig.renderer32x, offs); +} + static menu_entry e_menu_32x_options[] = { - mee_onoff("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X), - mee_onoff("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM), + mee_onoff ("32X enabled", MA_32XOPT_ENABLE_32X, PicoOpt, POPT_EN_32X), + mee_range_cust("32X renderer", MA_32XOPT_RENDERER, currentConfig.renderer32x, 0, 0, mgn_opt_renderer32x), + mee_onoff ("PWM sound", MA_32XOPT_PWM, PicoOpt, POPT_EN_PWM), mee_end, }; static int menu_loop_32x_options(menu_id id, int keys) { static int sel = 0; + int i, c; + + for (c = 0; renderer_names32x != NULL && renderer_names32x[c] != NULL; ) + c++; + i = me_id2offset(e_menu_32x_options, MA_32XOPT_RENDERER); + e_menu_32x_options[i].max = c > 0 ? (c - 1) : 0; + me_loop(e_menu_32x_options, &sel, NULL); return 0; } @@ -1534,15 +1564,14 @@ static int menu_loop_adv_options(menu_id id, int keys) // ------------ gfx options menu ------------ -static int mh_opt_render(menu_id id, int keys) +static const char *mgn_opt_renderer(menu_id id, int *offs) { - plat_video_toggle_renderer((keys & PBTN_RIGHT) ? 1 : 0, 0, 1); - return 0; + return get_rname(renderer_names, currentConfig.renderer, offs); } static menu_entry e_menu_gfx_options[] = { - mee_cust ("Renderer", MA_OPT_RENDERER, mh_opt_render, mgn_opt_renderer), + mee_range_cust("Renderer", MA_OPT_RENDERER, currentConfig.renderer, 0, 0, mgn_opt_renderer), MENU_OPTIONS_GFX mee_end, }; @@ -1550,6 +1579,14 @@ static menu_entry e_menu_gfx_options[] = static int menu_loop_gfx_options(menu_id id, int keys) { static int sel = 0; + int i, c; + + for (c = 0; renderer_names != NULL && renderer_names[c] != NULL; ) + c++; + i = me_id2offset(e_menu_gfx_options, MA_OPT_RENDERER); + e_menu_gfx_options[i].max = c > 0 ? (c - 1) : 0; + me_enable(e_menu_gfx_options, MA_OPT_RENDERER, renderer_names != NULL); + me_loop(e_menu_gfx_options, &sel, NULL); return 0; } diff --git a/common/menu.h b/common/menu.h index c9be9f2..83cb9c2 100644 --- a/common/menu.h +++ b/common/menu.h @@ -86,6 +86,7 @@ typedef enum MA_CDOPT_BETTER_SYNC, MA_CDOPT_DONE, MA_32XOPT_ENABLE_32X, + MA_32XOPT_RENDERER, MA_32XOPT_PWM, MA_CTRL_PLAYER1, MA_CTRL_PLAYER2, diff --git a/common/plat.h b/common/plat.h index 46725bf..4f89b2c 100644 --- a/common/plat.h +++ b/common/plat.h @@ -4,6 +4,8 @@ extern "C" { /* stuff to be implemented by platform code */ extern char cpu_clk_name[]; +extern const char **renderer_names; +extern const char **renderer_names32x; void pemu_prep_defconfig(void); void pemu_validate_config(void); @@ -35,7 +37,7 @@ void plat_video_menu_end(void); void plat_video_flip(void); void plat_video_wait_vsync(void); -void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu); +void plat_video_toggle_renderer(int change, int menu_call); void plat_update_volume(int has_changed, int is_up); diff --git a/gp2x/Makefile b/gp2x/Makefile index 9d8aa6a..431a357 100644 --- a/gp2x/Makefile +++ b/gp2x/Makefile @@ -13,6 +13,7 @@ asm_ym2612 = 1 asm_misc = 1 asm_cdpico = 1 asm_cdmemory = 1 +asm_32xdraw = 1 #profile = 1 #drc_debug = 3 diff --git a/gp2x/emu.c b/gp2x/emu.c index 2994fdb..a15ff89 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -1,7 +1,15 @@ -// (c) Copyright 2006-2009 notaz, All rights reserved. -// Free for non-commercial use. - -// For commercial use, separate licencing terms must be obtained. +/* + * (c) Copyright 2006-2010 notaz, All rights reserved. + * + * For performance reasons 3 renderers are exported for both MD and 32x modes: + * - 16bpp line renderer + * - 8bpp line renderer (slightly faster) + * - 8bpp tile renderer + * In 32x mode: + * - 32x layer is overlayed on top of 16bpp one + * - line internal one done on PicoDraw2FB, then mixed with 32x + * - tile internal one done on PicoDraw2FB, then mixed with 32x + */ #include #include @@ -37,6 +45,11 @@ static short __attribute__((aligned(4))) sndBuffer[2*(44100+100)/50]; static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)]; unsigned char *PicoDraw2FB = PicoDraw2FB_; static int osd_fps_x, osd_y; +const char *renderer_names_[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; +const char *renderer_names32x_[] = { "accurate", "faster ", "fastest ", NULL }; +const char **renderer_names = renderer_names_; +const char **renderer_names32x = renderer_names32x_; +enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; extern void *gp2x_screens[4]; @@ -62,6 +75,7 @@ void pemu_prep_defconfig(void) gp2x_soc_t soc; defaultConfig.CPUclock = default_cpu_clock; + defaultConfig.renderer32x = RT_8BIT_FAST; soc = soc_detect(); if (soc == SOCID_MMSP2) @@ -87,6 +101,31 @@ void pemu_validate_config(void) currentConfig.CPUclock = default_cpu_clock; } +static int get_renderer(void) +{ + if (PicoAHW & PAHW_32X) + return currentConfig.renderer32x; + else + return currentConfig.renderer; +} + +static void change_renderer(int diff) +{ + int *r; + if (PicoAHW & PAHW_32X) + r = ¤tConfig.renderer32x; + else + r = ¤tConfig.renderer; + *r += diff; + if (*r >= RT_COUNT) + *r = 0; + else if (*r < 0) + *r = RT_COUNT - 1; +} + +#define is_16bit_mode() \ + (get_renderer() == RT_16BIT || (PicoAHW & PAHW_32X)) + static void (*osd_text)(int x, int y, const char *text); static void osd_text8(int x, int y, const char *text) @@ -160,7 +199,7 @@ static void draw_cd_leds(void) scr_offs = pitch * 2 + 4; } - if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) { + if (!is_16bit_mode()) { #define p(x) px[(x) >> 2] // 8-bit modes unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs); @@ -187,7 +226,7 @@ static void draw_pico_ptr(void) int x, y, pitch = 320; // only if pen enabled and for 16bit modes - if (pico_inp_mode == 0 || (PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) + if (pico_inp_mode == 0 || currentConfig.EmuOpt != RT_16BIT) return; x = pico_pen_x + PICO_PEN_ADJUST_X; @@ -208,20 +247,6 @@ static void draw_pico_ptr(void) p[pitch*2] ^= 0xffff; } -static int EmuScanBegin16(unsigned int num) -{ - DrawLineDest = (unsigned short *) g_screen_ptr + g_screen_width * num; - - return 0; -} - -static int EmuScanBegin8(unsigned int num) -{ - DrawLineDest = (unsigned char *) g_screen_ptr + g_screen_width * num; - - return 0; -} - /* rot thing for Wiz */ static unsigned char __attribute__((aligned(4))) rot_buff[320*4*2]; @@ -307,7 +332,9 @@ void pemu_finalize_frame(const char *fps, const char *notice) int emu_opt = currentConfig.EmuOpt; int ret; - if (PicoOpt & POPT_ALT_RENDERER) + if (PicoAHW & PAHW_32X) + ; // nothing to do + else if (get_renderer() == RT_8BIT_FAST) { // 8bit fast renderer if (Pico.m.dirtyPal) { @@ -323,7 +350,7 @@ void pemu_finalize_frame(const char *fps, const char *notice) vidcpyM2(g_screen_ptr, PicoDraw2FB+328*8, !(Pico.video.reg[12] & 1), !(PicoOpt & POPT_DIS_32C_BORDER)); } - else if (!(emu_opt & EOPT_16BPP)) + else if (get_renderer() == RT_8BIT_ACC) { // 8bit accurate renderer if (Pico.m.dirtyPal) @@ -348,7 +375,12 @@ void pemu_finalize_frame(const char *fps, const char *notice) void plat_video_flip(void) { + int stride = g_screen_width; gp2x_video_flip(); + + if (is_16bit_mode()) + stride *= 2; + PicoDrawSetOutBuf(g_screen_ptr, stride); } /* XXX */ @@ -385,7 +417,7 @@ void plat_video_wait_vsync(void) void plat_status_msg_clear(void) { - int is_8bit = (PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP); + int is_8bit = !is_16bit_mode(); if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { /* ugh.. */ int i, u, *p; @@ -431,47 +463,78 @@ void plat_status_msg_busy_first(const char *msg) static void vidResetMode(void) { + int gp2x_mode = 16; + int renderer = get_renderer(); + + PicoScanBegin = NULL; PicoScanEnd = NULL; - if (PicoOpt & POPT_ALT_RENDERER) { - if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { - gp2x_video_changemode(-8); - vidcpyM2 = vidcpy_m2_rot; - osd_text = osd_text8_rot; - } else { - gp2x_video_changemode(8); - vidcpyM2 = vidcpy_m2; - osd_text = osd_text8; - } - } - else if (currentConfig.EmuOpt & EOPT_16BPP) { - PicoDrawSetColorFormat(1); + switch (renderer) { + case RT_16BIT: + PicoOpt &= ~POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_RGB555, 0); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { - gp2x_video_changemode(-16); PicoScanBegin = EmuScanBegin16_rot; PicoScanEnd = EmuScanEnd16_rot; - osd_text = osd_text16_rot; - } else { - gp2x_video_changemode(16); - PicoScanBegin = EmuScanBegin16; - osd_text = osd_text16; } - } - else { - PicoDrawSetColorFormat(2); + break; + case RT_8BIT_ACC: + PicoOpt &= ~POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_8BIT, 0); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width); if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { - gp2x_video_changemode(-8); PicoScanBegin = EmuScanBegin8_rot; PicoScanEnd = EmuScanEnd8_rot; - osd_text = osd_text8_rot; - } else { - gp2x_video_changemode(8); - PicoScanBegin = EmuScanBegin8; - osd_text = osd_text8; } + gp2x_mode = 8; + break; + case RT_8BIT_FAST: + PicoOpt |= POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_NONE, 0); + if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) + vidcpyM2 = vidcpy_m2_rot; + else + vidcpyM2 = vidcpy_m2; + gp2x_mode = 8; + break; } - if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) { + if (is_16bit_mode()) + osd_text = (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) ? osd_text16_rot : osd_text16; + else + osd_text = (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) ? osd_text8_rot : osd_text8; + + if (PicoAHW & PAHW_32X) { + // rules change in 32X world + if (renderer != RT_16BIT) { + PicoDrawSetOutFormat(PDF_NONE, 0); + PicoScanBegin = NULL; + PicoScanEnd = NULL; + } + PicoScan32xBegin = NULL; + PicoScan32xEnd = NULL; + if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) { + PicoScan32xBegin = EmuScanBegin16_rot; + PicoScan32xEnd = EmuScanEnd16_rot; + } + // Wiz 16bit is an exception, uses line rendering due to rotation mess + if (renderer == RT_16BIT && (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX)) { + PicoDrawSetOutFormat(PDF_RGB555, 1); + PicoDraw32xSetFrameMode(0, 0); + } + else { + PicoDraw32xSetFrameMode(1, (renderer == RT_16BIT) ? 1 : 0); + } + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + gp2x_mode = 16; + } + + if (currentConfig.EmuOpt & EOPT_WIZ_TEAR_FIX) + gp2x_mode = -gp2x_mode; + gp2x_video_changemode(gp2x_mode); + + if (!is_16bit_mode()) { // setup pal for 8-bit modes localPal[0xc0] = 0x0000c000; // MCD LEDs localPal[0xd0] = 0x00c00000; @@ -492,41 +555,20 @@ static void vidResetMode(void) make_local_pal = (PicoAHW & PAHW_SMS) ? make_local_pal_sms : make_local_pal_md; } -void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu) +void plat_video_toggle_renderer(int change, int is_menu_call) { - if (force_16bpp) { - PicoOpt &= ~POPT_ALT_RENDERER; - currentConfig.EmuOpt |= EOPT_16BPP; - } - /* alt, 16bpp, 8bpp */ - else if (PicoOpt & POPT_ALT_RENDERER) { - PicoOpt &= ~POPT_ALT_RENDERER; - if (is_next) - currentConfig.EmuOpt |= EOPT_16BPP; - } else if (!(currentConfig.EmuOpt & EOPT_16BPP)) { - if (is_next) - PicoOpt |= POPT_ALT_RENDERER; - else - currentConfig.EmuOpt |= EOPT_16BPP; - } else { - currentConfig.EmuOpt &= ~EOPT_16BPP; - if (!is_next) - PicoOpt |= POPT_ALT_RENDERER; - } + change_renderer(change); - if (is_menu) + if (is_menu_call) return; vidResetMode(); rendstatus_old = -1; - if (PicoOpt & POPT_ALT_RENDERER) { - emu_status_msg(" 8bit fast renderer"); - } else if (currentConfig.EmuOpt & EOPT_16BPP) { - emu_status_msg("16bit accurate renderer"); - } else { - emu_status_msg(" 8bit accurate renderer"); - } + if (PicoAHW & PAHW_32X) + emu_status_msg(renderer_names32x[get_renderer()]); + else + emu_status_msg(renderer_names[get_renderer()]); } #if 0 // TODO @@ -695,20 +737,19 @@ void pemu_sound_wait(void) void pemu_forced_frame(int opts) { int po_old = PicoOpt; - int eo_old = currentConfig.EmuOpt; PicoOpt &= ~POPT_ALT_RENDERER; PicoOpt |= opts|POPT_ACC_SPRITES; - currentConfig.EmuOpt |= EOPT_16BPP; - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; + PicoDrawSetOutFormat(PDF_RGB555, 1); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + PicoDraw32xSetFrameMode(0, 0); + PicoScanBegin = NULL; PicoScanEnd = NULL; Pico.m.dirtyPal = 1; PicoFrameDrawOnly(); PicoOpt = po_old; - currentConfig.EmuOpt = eo_old; } void plat_debug_cat(char *str) @@ -733,7 +774,7 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) gp2x_video_RGB_setscaling(0, scalex, 240); // clear whole screen in all buffers - if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) + if (!is_16bit_mode()) gp2x_memset_all_buffers(0, 0xe0, 320*240); else gp2x_memset_all_buffers(0, 0, 320*240*2); @@ -848,11 +889,12 @@ void pemu_loop_end(void) /* do one more frame for menu bg */ PicoOpt &= ~POPT_ALT_RENDERER; PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; - currentConfig.EmuOpt |= EOPT_16BPP; - PicoScanBegin = EmuScanBegin16; + PicoDrawSetOutFormat(PDF_RGB555, 1); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + PicoDraw32xSetFrameMode(0, 0); + PicoScanBegin = NULL; PicoScanEnd = NULL; - PicoDrawSetColorFormat(1); Pico.m.dirtyPal = 1; PicoFrame(); diff --git a/gp2x/menu.c b/gp2x/menu.c index da94d05..fb9d24a 100644 --- a/gp2x/menu.c +++ b/gp2x/menu.c @@ -53,17 +53,6 @@ static void menu_main_plat_draw(void) // ------------ gfx options menu ------------ -static const char *mgn_opt_renderer(menu_id id, int *offs) -{ - *offs = -11; - if (PicoOpt & POPT_ALT_RENDERER) - return " 8bit fast"; - else if (currentConfig.EmuOpt & EOPT_16BPP) - return "16bit accurate"; - else - return " 8bit accurate"; -} - static const char *mgn_opt_scaling(menu_id id, int *offs) { *offs = -13; diff --git a/gp2x/port_config.h b/gp2x/port_config.h index 5480ae8..1f4fdd0 100644 --- a/gp2x/port_config.h +++ b/gp2x/port_config.h @@ -12,9 +12,6 @@ #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 -// draw.c -#define OVERRIDE_HIGHCOL 0 - // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? #define END_ROW 28 // ..end diff --git a/gp2x/port_config.s b/gp2x/port_config.s index 5a41036..10d53ac 100644 --- a/gp2x/port_config.s +++ b/gp2x/port_config.s @@ -6,7 +6,6 @@ .equiv START_ROW, 0 .equiv END_ROW, 28 -.equiv OVERRIDE_HIGHCOL, 0 .equiv UNALIGNED_DRAWLINEDEST, 0 @ this should be set to one only for GP2X port diff --git a/linux/emu.c b/linux/emu.c index 98e2b72..7dc2c14 100644 --- a/linux/emu.c +++ b/linux/emu.c @@ -18,6 +18,11 @@ static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; char cpu_clk_name[] = "unused"; +const char *renderer_names_[] = { "16bit accurate", " 8bit accurate", " 8bit fast", NULL }; +const char *renderer_names32x_[] = { "accurate", "faster ", "fastest ", NULL }; +const char **renderer_names = renderer_names_; +const char **renderer_names32x = renderer_names32x_; +enum renderer_types { RT_16BIT, RT_8BIT_ACC, RT_8BIT_FAST, RT_COUNT }; void pemu_prep_defconfig(void) @@ -75,7 +80,7 @@ static void draw_cd_leds(void) led_offs = 4; scr_offs = pitch * 2 + 4; - if ((PicoOpt & POPT_ALT_RENDERER) || !(currentConfig.EmuOpt & EOPT_16BPP)) { + if (currentConfig.renderer != RT_16BIT) { #define p(x) px[(x) >> 2] // 8-bit modes unsigned int *px = (unsigned int *)((char *)g_screen_ptr + scr_offs); @@ -96,15 +101,20 @@ static void draw_cd_leds(void) } } -static int EmuScanBegin16(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 (currentConfig.renderer != RT_16BIT && !(PicoAHW & PAHW_32X)) { + unsigned short *pd = (unsigned short *)g_screen_ptr + 8 * g_screen_width; + unsigned char *ps = PicoDraw2FB + 328*8 + 8; + unsigned short *pal = HighPal; + int i, x; + if (Pico.m.dirtyPal) + PicoDrawUpdateHighPal(); + for (i = 0; i < 224; i++, ps += 8) + for (x = 0; x < 320; x++) + *pd++ = pal[*ps++]; + } + if (notice || (currentConfig.EmuOpt & EOPT_SHOW_FPS)) { if (notice) osd_text(4, g_screen_height - 8, notice); @@ -115,10 +125,51 @@ void pemu_finalize_frame(const char *fps, const char *notice) draw_cd_leds(); } -void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu) +static void apply_renderer(void) +{ + PicoScanBegin = NULL; + PicoScanEnd = NULL; + + switch (currentConfig.renderer) { + case RT_16BIT: + PicoOpt &= ~POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_RGB555, 0); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + break; + case RT_8BIT_ACC: + PicoOpt &= ~POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_8BIT, 0); + PicoDrawSetOutBuf(PicoDraw2FB + 8, 328); + break; + case RT_8BIT_FAST: + PicoOpt |= POPT_ALT_RENDERER; + PicoDrawSetOutFormat(PDF_NONE, 0); + break; + } + + if (PicoAHW & PAHW_32X) { + int only_32x = 0; + if (currentConfig.renderer == RT_16BIT) + only_32x = 1; + else + PicoDrawSetOutFormat(PDF_NONE, 0); + PicoDraw32xSetFrameMode(1, only_32x); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); + } +} + +void plat_video_toggle_renderer(int change, int is_menu) { - // this will auto-select SMS/32X renderers - PicoDrawSetColorFormat(1); + currentConfig.renderer += change; + if (currentConfig.renderer >= RT_COUNT) + currentConfig.renderer = 0; + else if (currentConfig.renderer < 0) + currentConfig.renderer = RT_COUNT - 1; + + if (!is_menu) + apply_renderer(); + + emu_status_msg(renderer_names[currentConfig.renderer]); } void plat_video_menu_enter(int is_rom_loaded) @@ -168,10 +219,8 @@ void pemu_forced_frame(int opts) PicoOpt &= ~POPT_ALT_RENDERER; PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites - currentConfig.EmuOpt |= EOPT_16BPP; - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; + PicoDrawSetOutFormat(PDF_RGB555, 0); Pico.m.dirtyPal = 1; PicoFrameDrawOnly(); @@ -244,8 +293,7 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) void pemu_loop_prep(void) { - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; + apply_renderer(); osd_text = osd_text16; pemu_sound_start(); @@ -262,9 +310,8 @@ void pemu_loop_end(void) /* do one more frame for menu bg */ PicoOpt &= ~POPT_ALT_RENDERER; PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; - currentConfig.EmuOpt |= EOPT_16BPP; - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 0); Pico.m.dirtyPal = 1; PicoFrame(); diff --git a/linux/port_config.h b/linux/port_config.h index f576048..7e05d7d 100644 --- a/linux/port_config.h +++ b/linux/port_config.h @@ -13,9 +13,6 @@ #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 -// draw.c -#define OVERRIDE_HIGHCOL 0 - // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? #define END_ROW 28 // ..end diff --git a/pandora/emu.c b/pandora/emu.c index f7c2a2e..2bd8be8 100644 --- a/pandora/emu.c +++ b/pandora/emu.c @@ -23,6 +23,8 @@ 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[] = "unused"; @@ -43,7 +45,7 @@ static void osd_text(int x, int y, const char *text) { int len = strlen(text)*8; - if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + if (0) { int *p, i, h; x &= ~3; // align x len = (len+3) >> 2; @@ -71,7 +73,7 @@ static void draw_cd_leds(void) // if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change // mmu hack problems? old_reg = Pico_mcd->s68k_regs[0]; - if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) { + if (0) { // 8-bit modes unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0; unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0; @@ -183,10 +185,10 @@ void pemu_finalize_frame(const char *fps, const char *notice) draw_cd_leds(); } -void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu) +void plat_video_toggle_renderer(int change, int is_menu) { // this will auto-select SMS/32X renderers - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 1); } void plat_video_menu_enter(int is_rom_loaded) @@ -251,17 +253,14 @@ void plat_update_volume(int has_changed, int is_up) void pemu_forced_frame(int opts) { int po_old = PicoOpt; - int eo_old = currentConfig.EmuOpt; PicoOpt &= ~0x10; PicoOpt |= opts|POPT_ACC_SPRITES; // acc_sprites - currentConfig.EmuOpt |= 0x80; Pico.m.dirtyPal = 1; PicoFrameDrawOnly(); PicoOpt = po_old; - currentConfig.EmuOpt = eo_old; } static void updateSound(int len) @@ -339,16 +338,16 @@ void emu_video_mode_change(int start_line, int line_count, int is_32cols) memset32(fbdev_buffers[i], 0, g_screen_width * g_screen_height * 2 / 4); #ifdef USE_320_SCREEN - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 1); PicoScanBegin = EmuScanBegin16; #else if (PicoAHW & PAHW_32X) { DrawLineDest = (unsigned short *)temp_frame; - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 1); PicoScanBegin = NULL; PicoScanEnd = EmuScanEnd16_32x; } else { - PicoDrawSetColorFormat(-1); + PicoDrawSetOutFormat(PDF_NONE, 0); PicoScanBegin = NULL; PicoScanEnd = EmuScanEnd16; } @@ -374,7 +373,7 @@ void pemu_loop_end(void) PicoOpt |= POPT_EN_SOFTSCALE|POPT_ACC_SPRITES; currentConfig.EmuOpt |= EOPT_16BPP; - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 1); Pico.m.dirtyPal = 1; PicoFrame(); diff --git a/pandora/menu.c b/pandora/menu.c index fa33f3d..5b7b9f7 100644 --- a/pandora/menu.c +++ b/pandora/menu.c @@ -6,4 +6,3 @@ mee_onoff ("Status line in main menu", MA_OPT2_STATUS_LINE, currentConfig.EmuOpt, EOPT_SHOW_RTC), #define menu_main_plat_draw NULL -#define mgn_opt_renderer NULL diff --git a/pandora/port_config.h b/pandora/port_config.h index 0c071bd..a670c1c 100644 --- a/pandora/port_config.h +++ b/pandora/port_config.h @@ -11,9 +11,6 @@ #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 480 -// draw.c -#define OVERRIDE_HIGHCOL 0 - // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? #define END_ROW 28 // ..end diff --git a/pandora/port_config.s b/pandora/port_config.s index 5a41036..10d53ac 100644 --- a/pandora/port_config.s +++ b/pandora/port_config.s @@ -6,7 +6,6 @@ .equiv START_ROW, 0 .equiv END_ROW, 28 -.equiv OVERRIDE_HIGHCOL, 0 .equiv UNALIGNED_DRAWLINEDEST, 0 @ this should be set to one only for GP2X port diff --git a/psp/emu.c b/psp/emu.c index 9af4fe5..6169940 100644 --- a/psp/emu.c +++ b/psp/emu.c @@ -465,7 +465,7 @@ static void vidResetMode(void) sceGuTexImage(0,512,512,512,(char *)VRAM_STUFF + 16); // slow rend. - PicoDrawSetColorFormat(-1); + PicoDrawSetOutFormat(PDF_NONE, 0); PicoScanBegin = EmuScanSlowBegin; PicoScanEnd = EmuScanSlowEnd; @@ -682,7 +682,7 @@ void pemu_forced_frame(int opts) memset32((int *)VRAM_CACHED_STUFF + 512*232/4, 0xe0e0e0e0, 512*8/4); memset32_uncached((int *)psp_screen + 512*264*2/4, 0, 512*8*2/4); - PicoDrawSetColorFormat(-1); + PicoDrawSetOutFormat(PDF_NONE, 0); PicoScanBegin = EmuScanSlowBegin; PicoScanEnd = EmuScanSlowEnd; EmuScanPrepare(); diff --git a/psp/port_config.h b/psp/port_config.h index cc42e6c..d07c9f4 100644 --- a/psp/port_config.h +++ b/psp/port_config.h @@ -14,7 +14,6 @@ // draw.c #define USE_BGR555 1 -#define OVERRIDE_HIGHCOL 1 // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? diff --git a/win32/plat.c b/win32/plat.c index e5e2f7e..4173da3 100644 --- a/win32/plat.c +++ b/win32/plat.c @@ -13,6 +13,8 @@ static unsigned short screen_buff[320 * 240]; static unsigned char PicoDraw2FB_[(8+320) * (8+240+8)]; unsigned char *PicoDraw2FB = PicoDraw2FB_; +const char **renderer_names = NULL; +const char **renderer_names32x = NULL; char cpu_clk_name[] = "unused"; @@ -68,17 +70,10 @@ void pemu_validate_config(void) { } -static int EmuScanBegin16(unsigned int num) -{ - DrawLineDest = (unsigned short *) g_screen_ptr + g_screen_width * num; - - return 0; -} - void pemu_loop_prep(void) { - PicoDrawSetColorFormat(1); - PicoScanBegin = EmuScanBegin16; + PicoDrawSetOutFormat(PDF_RGB555, 1); + PicoDrawSetOutBuf(g_screen_ptr, g_screen_width * 2); pemu_sound_start(); } @@ -105,10 +100,10 @@ void plat_video_wait_vsync(void) { } -void plat_video_toggle_renderer(int is_next, int force_16bpp, int is_menu) +void plat_video_toggle_renderer(int change, int is_menu) { // this will auto-select SMS/32X renderers - PicoDrawSetColorFormat(1); + PicoDrawSetOutFormat(PDF_RGB555, 1); } void emu_video_mode_change(int start_line, int line_count, int is_32cols) diff --git a/win32/port_config.h b/win32/port_config.h index 04b4c93..d6a09cc 100644 --- a/win32/port_config.h +++ b/win32/port_config.h @@ -13,9 +13,6 @@ #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 240 -// draw.c -#define OVERRIDE_HIGHCOL 0 - // draw2.c #define START_ROW 0 // which row of tiles to start rendering at? #define END_ROW 28 // ..end