From a2851ab70b42021c49b24f5cb3215a0c8d08c1fd Mon Sep 17 00:00:00 2001 From: netux79 Date: Fri, 12 Feb 2016 16:58:59 -0500 Subject: [PATCH] (GX) Resolution Saving's Video Corruption Fix. Also some cleanups for the RA GX version included. --- audio/drivers/gx_audio.c | 15 +- command_event.c | 5 +- defines/gx_defines.h | 140 ++---- frontend/drivers/platform_gx.c | 3 +- frontend/drivers/platform_wii.c | 2 +- gfx/drivers/gx_gfx.c | 687 +++++++++++++--------------- gfx/drivers/gx_gfx_inl.h | 774 -------------------------------- gfx/drivers/gx_gfx_vi_encoder.c | 1 + gfx/drivers_context/ps3_ctx.c | 3 - gfx/video_driver.c | 10 - memory/wii/mem2_manager.c | 1 - menu/cbs/menu_cbs_get_value.c | 12 +- menu/cbs/menu_cbs_ok.c | 7 +- menu/cbs/menu_cbs_start.c | 10 +- performance.c | 6 +- runloop.h | 2 - string_list_special.c | 2 +- 17 files changed, 389 insertions(+), 1291 deletions(-) delete mode 100644 gfx/drivers/gx_gfx_inl.h diff --git a/audio/drivers/gx_audio.c b/audio/drivers/gx_audio.c index f83c111655..2b19f076a4 100644 --- a/audio/drivers/gx_audio.c +++ b/audio/drivers/gx_audio.c @@ -31,19 +31,6 @@ #include "../../configuration.h" #include "../../defines/gx_defines.h" -#define CHUNK_FRAMES 64 -#define CHUNK_SIZE (CHUNK_FRAMES * sizeof(uint32_t)) -#define BLOCKS 16 - -#ifdef GEKKO -#define AIInit AUDIO_Init -#define AIInitDMA AUDIO_InitDMA -#define AIStartDMA AUDIO_StartDMA -#define AIStopDMA AUDIO_StopDMA -#define AIRegisterDMACallback AUDIO_RegisterDMACallback -#define AISetDSPSampleRate AUDIO_SetDSPSampleRate -#endif - typedef struct { uint32_t data[BLOCKS][CHUNK_FRAMES]; @@ -218,7 +205,7 @@ static void gx_audio_free(void *data) AIRegisterDMACallback(NULL); if (wa->cond) - LWP_CloseQueue(wa->cond); + OSCloseThreadQueue(wa->cond); wa->cond = 0; free(data); diff --git a/command_event.c b/command_event.c index 7f95f98b63..cb74025b68 100644 --- a/command_event.c +++ b/command_event.c @@ -944,7 +944,10 @@ bool event_cmd_ctl(enum event_command cmd, void *data) video_driver_set_video_mode(width, height, true); - snprintf(msg, sizeof(msg),"Resolution: %dx%d",width, height); + if (width == 0 || height == 0) + strlcpy(msg, "Resolution: DEFAULT", sizeof(msg)); + else + snprintf(msg, sizeof(msg),"Resolution: %dx%d",width, height); runloop_msg_queue_push(msg, 1, 100, true); } } diff --git a/defines/gx_defines.h b/defines/gx_defines.h index fb4ac8a7d8..9d095eb117 100644 --- a/defines/gx_defines.h +++ b/defines/gx_defines.h @@ -16,95 +16,12 @@ #ifndef _GX_DEFINES_H #define _GX_DEFINES_H -#define _SHIFTL(v, s, w) ((uint32_t) (((uint32_t)(v) & ((0x01 << (w)) - 1)) << (s))) -#define _SHIFTR(v, s, w) ((uint32_t)(((uint32_t)(v) >> (s)) & ((0x01 << (w)) - 1))) - -#ifndef __lhbrx -#define __lhbrx(base,index) \ -({ register u16 res; \ - __asm__ volatile ("lhbrx %0,%1,%2" : "=r"(res) : "b%"(index), "r"(base) : "memory"); \ - res; }) -#endif - -#ifndef __sthbrx -#define __sthbrx(base,index,value) \ - __asm__ volatile ("sthbrx %0,%1,%2" : : "r"(value), "b%"(index), "r"(base) : "memory") -#endif - -#ifndef __stwbrx -#define __stwbrx(base,index,value) \ - __asm__ volatile ("stwbrx %0,%1,%2" : : "r"(value), "b%"(index), "r"(base) : "memory") -#endif - -#ifndef _sync -#define _sync() asm volatile("sync") -#endif - -#ifndef _nop -#define _nop() asm volatile("nop") -#endif - -#ifndef ppcsync -#define ppcsync() asm volatile("sc") -#endif - -#ifndef ppchalt -#define ppchalt() ({ \ - _sync(); \ - while(1) { \ - _nop(); \ - asm volatile("li 3,0"); \ - _nop(); \ - } \ -}) -#endif - -#ifndef _CPU_ISR_Enable -#define _CPU_ISR_Enable() \ - { register u32 _val = 0; \ - __asm__ __volatile__ ( \ - "mfmsr %0\n" \ - "ori %0,%0,0x8000\n" \ - "mtmsr %0" \ - : "=&r" ((_val)) : "0" ((_val)) \ - ); \ - } -#endif - -#ifndef _CPU_ISR_Disable -#define _CPU_ISR_Disable( _isr_cookie ) \ - { register u32 _disable_mask = 0; \ - _isr_cookie = 0; \ - __asm__ __volatile__ ( \ - "mfmsr %0\n" \ - "rlwinm %1,%0,0,17,15\n" \ - "mtmsr %1\n" \ - "extrwi %0,%0,1,16" \ - : "=&r" ((_isr_cookie)), "=&r" ((_disable_mask)) \ - : "0" ((_isr_cookie)), "1" ((_disable_mask)) \ - ); \ - } -#endif - -#ifndef _CPU_ISR_Restore -#define _CPU_ISR_Restore( _isr_cookie ) \ - { register u32 _enable_mask = 0; \ - __asm__ __volatile__ ( \ - " cmpwi %0,0\n" \ - " beq 1f\n" \ - " mfmsr %1\n" \ - " ori %1,%1,0x8000\n" \ - " mtmsr %1\n" \ - "1:" \ - : "=r"((_isr_cookie)),"=&r" ((_enable_mask)) \ - : "0"((_isr_cookie)),"1" ((_enable_mask)) \ - ); \ - } -#endif - #ifdef GEKKO -extern void __lwp_thread_stopmultitasking(void (*exitfunc)()); +#define SYSMEM1_SIZE 0x01800000 + +#define _SHIFTL(v, s, w) ((uint32_t) (((uint32_t)(v) & ((0x01 << (w)) - 1)) << (s))) +#define _SHIFTR(v, s, w) ((uint32_t)(((uint32_t)(v) >> (s)) & ((0x01 << (w)) - 1))) #define OSThread lwp_t #define OSCond lwpq_t @@ -120,19 +37,52 @@ extern void __lwp_thread_stopmultitasking(void (*exitfunc)()); #define OSWaitCond(cond, mutex) LWP_CondWait(cond, mutex) #define OSInitThreadQueue(queue) LWP_InitQueue(queue) +#define OSCloseThreadQueue(queue) LWP_CloseQueue(queue) #define OSSleepThread(queue) LWP_ThreadSleep(queue) #define OSJoinThread(thread, val) LWP_JoinThread(thread, val) #define OSCreateThread(thread, func, intarg, ptrarg, stackbase, stacksize, priority, attrs) LWP_CreateThread(thread, func, ptrarg, stackbase, stacksize, priority) -#define VISetPostRetraceCallback(cb) VIDEO_SetPostRetraceCallback(cb) -#define VISetBlack(black) VIDEO_SetBlack(black) -#define VIFlush() VIDEO_Flush() -#define VISetNextFrameBuffer(fb) VIDEO_SetNextFramebuffer(fb) -#define VIWaitForRetrace() VIDEO_WaitVSync() -#define VIConfigure(rm) VIDEO_Configure(rm) -#define VIInit() VIDEO_Init() -#define VIPadFrameBufferWidth(width) VIDEO_PadFramebufferWidth(width) +#define BLIT_LINE_16(off) \ +{ \ + const uint32_t *tmp_src = src; \ + uint32_t *tmp_dst = dst; \ + for (unsigned x = 0; x < width2 >> 1; x++, tmp_src += 2, tmp_dst += 8) \ + { \ + tmp_dst[ 0 + off] = BLIT_LINE_16_CONV(tmp_src[0]); \ + tmp_dst[ 1 + off] = BLIT_LINE_16_CONV(tmp_src[1]); \ + } \ + src += tmp_pitch; \ +} + +#define BLIT_LINE_32(off) \ +{ \ + const uint16_t *tmp_src = src; \ + uint16_t *tmp_dst = dst; \ + for (unsigned x = 0; x < width2 >> 3; x++, tmp_src += 8, tmp_dst += 32) \ + { \ + tmp_dst[ 0 + off] = tmp_src[0] | 0xFF00; \ + tmp_dst[ 16 + off] = tmp_src[1]; \ + tmp_dst[ 1 + off] = tmp_src[2] | 0xFF00; \ + tmp_dst[ 17 + off] = tmp_src[3]; \ + tmp_dst[ 2 + off] = tmp_src[4] | 0xFF00; \ + tmp_dst[ 18 + off] = tmp_src[5]; \ + tmp_dst[ 3 + off] = tmp_src[6] | 0xFF00; \ + tmp_dst[ 19 + off] = tmp_src[7]; \ + } \ + src += tmp_pitch; \ +} + +#define CHUNK_FRAMES 64 +#define CHUNK_SIZE (CHUNK_FRAMES * sizeof(uint32_t)) +#define BLOCKS 16 + +#define AIInit AUDIO_Init +#define AIInitDMA AUDIO_InitDMA +#define AIStartDMA AUDIO_StartDMA +#define AIStopDMA AUDIO_StopDMA +#define AIRegisterDMACallback AUDIO_RegisterDMACallback +#define AISetDSPSampleRate AUDIO_SetDSPSampleRate #endif diff --git a/frontend/drivers/platform_gx.c b/frontend/drivers/platform_gx.c index 402a1120a9..d41e41435a 100644 --- a/frontend/drivers/platform_gx.c +++ b/frontend/drivers/platform_gx.c @@ -37,7 +37,6 @@ #include "../frontend_driver.h" #include "../../defaults.h" -#include "../../defines/gx_defines.h" #ifdef HW_RVL #include @@ -53,7 +52,7 @@ extern void system_exec_wii(const char *path, bool should_load_game); #include #endif -#if defined(HW_RVL) +#if defined(HW_RVL) && ! defined(IS_SALAMANDER) static enum frontend_fork gx_fork_mode = FRONTEND_FORK_NONE; #endif diff --git a/frontend/drivers/platform_wii.c b/frontend/drivers/platform_wii.c index 2794792c6b..10f63299d8 100644 --- a/frontend/drivers/platform_wii.c +++ b/frontend/drivers/platform_wii.c @@ -24,12 +24,12 @@ #include #include #include +#include #include #include #include -#include "../../defines/gx_defines.h" #include "../../verbosity.h" #define EXECUTE_ADDR ((uint8_t *) 0x91800000) diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 1bd798d382..c49f01af6c 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -33,7 +33,7 @@ #include "../../memory/wii/mem2_manager.h" #endif -#include "gx_gfx_inl.h" +#include "../../defines/gx_defines.h" struct gx_overlay_data { @@ -62,8 +62,6 @@ typedef struct gx_video void *framebuf[2]; } gx_video_t; -#define SYSMEM1_SIZE 0x01800000 - unsigned g_current_framebuf; bool g_vsync; @@ -92,11 +90,6 @@ size_t display_list_size; GXRModeObj gx_mode; unsigned gx_old_width, gx_old_height; -static u8 _gxtexmode0ids[8] = {0x80,0x81,0x82,0x83,0xA0,0xA1,0xA2,0xA3}; -static u8 _gxtexmode1ids[8] = {0x84,0x85,0x86,0x87,0xA4,0xA5,0xA6,0xA7}; -static u8 _gxteximg0ids[8] = {0x88,0x89,0x8A,0x8B,0xA8,0xA9,0xAA,0xAB}; -static u8 _gxteximg3ids[8] = {0x94,0x95,0x96,0x97,0xB4,0xB5,0xB6,0xB7}; - float verts[16] ATTRIBUTE_ALIGN(32) = { -1, 1, -0.5, 1, 1, -0.5, @@ -120,7 +113,8 @@ u8 color_ptr[16] ATTRIBUTE_ALIGN(32) = { enum { - GX_RESOLUTIONS_512_192 = 0, + GX_RESOLUTIONS_DEFAULT = 0, + GX_RESOLUTIONS_512_192, GX_RESOLUTIONS_598_200, GX_RESOLUTIONS_640_200, GX_RESOLUTIONS_384_224, @@ -159,12 +153,11 @@ enum GX_RESOLUTIONS_530_480, GX_RESOLUTIONS_608_480, GX_RESOLUTIONS_640_480, - GX_RESOLUTIONS_LAST, + GX_RESOLUTIONS_LAST = GX_RESOLUTIONS_640_480, }; -static unsigned menu_current_gx_resolution = GX_RESOLUTIONS_448_448; - -unsigned menu_gx_resolutions[GX_RESOLUTIONS_LAST][2] = { +unsigned menu_gx_resolutions[][2] = { + { 0, 0 }, /* Let the system choose its preferred resolution, for NTSC is 640x480 */ { 512, 192 }, { 598, 200 }, { 640, 200 }, @@ -206,8 +199,6 @@ unsigned menu_gx_resolutions[GX_RESOLUTIONS_LAST][2] = { { 640, 480 }, }; -extern unsigned menu_current_gx_resolution; - static void retrace_callback(u32 retrace_count) { (void)retrace_count; @@ -215,36 +206,31 @@ static void retrace_callback(u32 retrace_count) OSSignalCond(g_video_cond); } -#ifdef HAVE_OVERLAY -static void gx_render_overlay(void *data); -static void gx_free_overlay(gx_video_t *gx) -{ - free(gx->overlay); - gx->overlay = NULL; - gx->overlays = 0; - GX_InvalidateTexAll(); -} -#endif - static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, bool fullscreen) { f32 y_scale; + float refresh_rate; u16 xfbWidth, xfbHeight; bool progressive; - unsigned modetype, level, viHeightMultiplier, viWidth, tvmode, + unsigned modetype, viHeightMultiplier, viWidth, tvmode, max_width, max_height, i; - gx_video_t *gx = (gx_video_t*)data; - settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); + gx_video_t *gx = (gx_video_t*)data; + settings_t *settings = config_get_ptr(); - (void)level; + /* stop vsync callback */ + VIDEO_SetPostRetraceCallback(NULL); + g_draw_done = false; + /* wait for next even field */ + /* this prevents screen artefacts when switching between interlaced & non-interlaced modes */ + do VIDEO_WaitVSync(); + while (!VIDEO_GetNextField()); - _CPU_ISR_Disable(level); - VISetBlack(true); - VIFlush(); + VIDEO_SetBlack(true); + VIDEO_Flush(); viHeightMultiplier = 1; - viWidth = settings->video.viwidth; + viWidth = settings->video.viwidth; + #if defined(HW_RVL) progressive = CONF_GetProgressiveScan() > 0 && VIDEO_HaveComponentCable(); @@ -272,7 +258,7 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, { case VI_PAL: max_width = VI_MAX_WIDTH_PAL; - max_height = /* VI_MAX_HEIGHT_PAL */ 574; + max_height = VI_MAX_HEIGHT_PAL; break; case VI_MPAL: max_width = VI_MAX_WIDTH_MPAL; @@ -304,7 +290,7 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, } else { - modetype = (progressive) ? VI_PROGRESSIVE : VI_INTERLACE; + modetype = progressive ? VI_PROGRESSIVE : VI_INTERLACE; } if (lines > max_height) @@ -362,20 +348,27 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, gx->double_strike = (modetype == VI_NON_INTERLACE); gx->should_resize = true; - VIConfigure(&gx_mode); - VIDEO_ClearFrameBuffer(&gx_mode, gx->framebuf[0], COLOR_BLACK); - VIDEO_ClearFrameBuffer(&gx_mode, gx->framebuf[1], COLOR_BLACK); - VISetNextFrameBuffer(gx->framebuf[0]); - VISetPostRetraceCallback(retrace_callback); - VISetBlack(false); - VIFlush(); + /* calculate menu dimensions */ + size_t new_fb_pitch; + unsigned new_fb_width; + unsigned new_fb_height = (gx_mode.efbHeight / (gx->double_strike ? 1 : 2)) & ~3; + if (new_fb_height > 240) + new_fb_height = 240; + new_fb_width = (gx_mode.fbWidth / (gx_mode.fbWidth < 400 ? 1 : 2)) & ~3; + if (new_fb_width > 400) + new_fb_width = 400; + new_fb_pitch = new_fb_width * 2; + + menu_display_ctl(MENU_DISPLAY_CTL_SET_WIDTH, &new_fb_width); + menu_display_ctl(MENU_DISPLAY_CTL_SET_HEIGHT, &new_fb_height); + menu_display_ctl(MENU_DISPLAY_CTL_SET_FB_PITCH, &new_fb_pitch); GX_SetViewportJitter(0, 0, gx_mode.fbWidth, gx_mode.efbHeight, 0, 1, 1); GX_SetDispCopySrc(0, 0, gx_mode.fbWidth, gx_mode.efbHeight); y_scale = GX_GetYScaleFactor(gx_mode.efbHeight, gx_mode.xfbHeight); - xfbWidth = VIPadFrameBufferWidth(gx_mode.fbWidth); + xfbWidth = VIDEO_PadFramebufferWidth(gx_mode.fbWidth); xfbHeight = GX_SetDispCopyYScale(y_scale); GX_SetDispCopyDst(xfbWidth, xfbHeight); @@ -389,57 +382,37 @@ static void gx_set_video_mode(void *data, unsigned fbWidth, unsigned lines, GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_InvalidateTexAll(); GX_Flush(); - _CPU_ISR_Restore(level); - + + /* Now apply all the configuration to the screen */ + VIDEO_Configure(&gx_mode); + VIDEO_ClearFrameBuffer(&gx_mode, gx->framebuf[0], COLOR_BLACK); + VIDEO_ClearFrameBuffer(&gx_mode, gx->framebuf[1], COLOR_BLACK); + VIDEO_SetNextFramebuffer(gx->framebuf[0]); + g_current_framebuf = 0; + /* re-activate the Vsync callback */ + VIDEO_SetPostRetraceCallback(retrace_callback); + VIDEO_SetBlack(false); + VIDEO_Flush(); + VIDEO_WaitVSync(); + RARCH_LOG("GX Resolution: %dx%d (%s)\n", gx_mode.fbWidth, - gx_mode.efbHeight, (gx_mode.viTVMode & 3) == VI_INTERLACE + gx_mode.efbHeight, (gx_mode.viTVMode & 3) == VI_INTERLACE ? "interlaced" : "progressive"); - { - size_t new_fb_pitch; - unsigned new_fb_width; - unsigned new_fb_height = (gx_mode.efbHeight / (gx->double_strike ? 1 : 2)) & ~3; - if (new_fb_height > 240) - new_fb_height = 240; - new_fb_width = (gx_mode.fbWidth / (gx_mode.fbWidth < 400 ? 1 : 2)) & ~3; - if (new_fb_width > 400) - new_fb_width = 400; - - new_fb_pitch = new_fb_width * 2; - - menu_display_ctl(MENU_DISPLAY_CTL_SET_WIDTH, &new_fb_width); - menu_display_ctl(MENU_DISPLAY_CTL_SET_HEIGHT, &new_fb_height); - menu_display_ctl(MENU_DISPLAY_CTL_SET_FB_PITCH, &new_fb_pitch); - } - if (tvmode == VI_PAL) { - float refresh_rate = 50.0f; + refresh_rate = 50.0f; if (modetype == VI_NON_INTERLACE) refresh_rate = 50.0801f; - driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &refresh_rate); } else { - float refresh_rate = 59.94f; + refresh_rate = 59.94f; if (modetype == VI_NON_INTERLACE) refresh_rate = 59.8261f; - driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &refresh_rate); } - - /* custom viewports for older resolutions will most likely be corrupted, reset them */ - /* TOD/FIXME - is this needed? */ - video_driver_ctl(RARCH_DISPLAY_CTL_RESET_CUSTOM_VIEWPORT, NULL); - - g_current_framebuf = 0; - for(i = 0; i < GX_RESOLUTIONS_LAST; i++) - if(fbWidth == menu_gx_resolutions[i][0] && lines == menu_gx_resolutions[i][1]) - menu_current_gx_resolution = i; - - global->console.screen.resolutions.width = menu_gx_resolutions[menu_current_gx_resolution][0]; - global->console.screen.resolutions.height = menu_gx_resolutions[menu_current_gx_resolution][0]; - - RARCH_LOG("GX Resolution Index: %d\n", menu_current_gx_resolution); + + driver_ctl(RARCH_DRIVER_CTL_SET_REFRESH_RATE, &refresh_rate); } static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) @@ -477,8 +450,24 @@ static void gx_set_aspect_ratio(void *data, unsigned aspect_ratio_idx) gx->should_resize = true; } +static void gx_get_video_output_size(void *data, unsigned *width, unsigned *height) +{ + global_t *global = global_get_ptr(); + + (void)data; + + /* If the current index is out of bound default it to zero */ + if (global->console.screen.resolutions.current.id > GX_RESOLUTIONS_LAST) + global->console.screen.resolutions.current.id = 0; + + *width = menu_gx_resolutions[global->console.screen.resolutions.current.id][0]; + *height = menu_gx_resolutions[global->console.screen.resolutions.current.id][1]; +} + static void setup_video_mode(gx_video_t *gx) { + unsigned width, height; + if (!gx->framebuf[0]) { unsigned i; @@ -487,23 +476,20 @@ static void setup_video_mode(gx_video_t *gx) memalign(32, 640 * 576 * VI_DISPLAY_PIX_SZ)); } - g_current_framebuf = 0; - g_draw_done = true; g_orientation = ORIENTATION_NORMAL; OSInitThreadQueue(&g_video_cond); - VIDEO_GetPreferredMode(&gx_mode); - gx_set_video_mode(gx, 0, 0, true); + gx_get_video_output_size(gx, &width, &height); + gx_set_video_mode(gx, width, height, true); } static void init_texture(void *data, unsigned width, unsigned height) { unsigned g_filter, menu_w, menu_h; - struct __gx_regdef *__gx = (struct __gx_regdef*)__gxregs; - gx_video_t *gx = (gx_video_t*)data; - struct __gx_texobj *fb_ptr = (struct __gx_texobj*)&g_tex.obj; - struct __gx_texobj *menu_ptr = (struct __gx_texobj*)&menu_tex.obj; - settings_t *settings = config_get_ptr(); + gx_video_t *gx = (gx_video_t*)data; + GXTexObj *fb_ptr = (GXTexObj*)&g_tex.obj; + GXTexObj *menu_ptr = (GXTexObj*)&menu_tex.obj; + settings_t *settings = config_get_ptr(); width &= ~3; height &= ~3; @@ -514,15 +500,15 @@ static void init_texture(void *data, unsigned width, unsigned height) menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &menu_w); menu_display_ctl(MENU_DISPLAY_CTL_HEIGHT, &menu_h); - __GX_InitTexObj(fb_ptr, g_tex.data, width, height, - (gx->rgb32) ? GX_TF_RGBA8 : gx->menu_texture_enable ? + GX_InitTexObj(fb_ptr, g_tex.data, width, height, + (gx->rgb32) ? GX_TF_RGBA8 : gx->menu_texture_enable ? GX_TF_RGB5A3 : GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE); - __GX_InitTexObjFilterMode(fb_ptr, g_filter, g_filter); - __GX_InitTexObj(menu_ptr, menu_tex.data, menu_w, menu_h, + GX_InitTexObjFilterMode(fb_ptr, g_filter, g_filter); + GX_InitTexObj(menu_ptr, menu_tex.data, menu_w, menu_h, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP, GX_FALSE); - __GX_InitTexObjFilterMode(menu_ptr, g_filter, g_filter); - __GX_InvalidateTexAll(__gx); + GX_InitTexObjFilterMode(menu_ptr, g_filter, g_filter); + GX_InvalidateTexAll(); } static void init_vtx(void *data, const video_info_t *video) @@ -532,7 +518,6 @@ static void init_vtx(void *data, const video_info_t *video) GX_SetCullMode(GX_CULL_NONE); GX_SetClipMode(GX_CLIP_DISABLE); - GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetZMode(GX_ENABLE, GX_ALWAYS, GX_ENABLE); GX_SetColorUpdate(GX_TRUE); GX_SetAlphaUpdate(GX_FALSE); @@ -659,7 +644,7 @@ static void *gx_init(const video_info_t *video, *input = gxinput ? &input_gx : NULL; *input_data = gxinput; - VIInit(); + VIDEO_Init(); GX_Init(gx_fifo, sizeof(gx_fifo)); g_vsync = video->vsync; @@ -675,14 +660,10 @@ static void *gx_init(const video_info_t *video, return gx; } -#define ASM_BLITTER - -#ifdef ASM_BLITTER - static void update_texture_asm(const uint32_t *src, const uint32_t *dst, unsigned width, unsigned height, unsigned pitch) { - register uint32_t tmp0, tmp1, tmp2, tmp3, line2, line2b, + register uint32_t tmp0, tmp1, tmp2, tmp3, line2, line2b, line3, line3b, line4, line4b, line5; __asm__ volatile ( @@ -748,66 +729,12 @@ static void update_texture_asm(const uint32_t *src, const uint32_t *dst, ); } -#endif - -#define BLIT_LINE_16(off) \ -{ \ - const uint32_t *tmp_src = src; \ - uint32_t *tmp_dst = dst; \ - for (unsigned x = 0; x < width2 >> 1; x++, tmp_src += 2, tmp_dst += 8) \ - { \ - tmp_dst[ 0 + off] = BLIT_LINE_16_CONV(tmp_src[0]); \ - tmp_dst[ 1 + off] = BLIT_LINE_16_CONV(tmp_src[1]); \ - } \ - src += tmp_pitch; \ -} - -#define BLIT_LINE_32(off) \ -{ \ - const uint16_t *tmp_src = src; \ - uint16_t *tmp_dst = dst; \ - for (unsigned x = 0; x < width2 >> 3; x++, tmp_src += 8, tmp_dst += 32) \ - { \ - tmp_dst[ 0 + off] = tmp_src[0] | 0xFF00; \ - tmp_dst[ 16 + off] = tmp_src[1]; \ - tmp_dst[ 1 + off] = tmp_src[2] | 0xFF00; \ - tmp_dst[ 17 + off] = tmp_src[3]; \ - tmp_dst[ 2 + off] = tmp_src[4] | 0xFF00; \ - tmp_dst[ 18 + off] = tmp_src[5]; \ - tmp_dst[ 3 + off] = tmp_src[6] | 0xFF00; \ - tmp_dst[ 19 + off] = tmp_src[7]; \ - } \ - src += tmp_pitch; \ -} - static void convert_texture16(const uint32_t *_src, uint32_t *_dst, unsigned width, unsigned height, unsigned pitch) { -#ifdef ASM_BLITTER width &= ~3; height &= ~3; update_texture_asm(_src, _dst, width, height, pitch); -#else - width &= ~3; - height &= ~3; - unsigned tmp_pitch = pitch >> 2; - unsigned width2 = width >> 1; - - /* Texture data is 4x4 tiled @ 16bpp. - * Use 32-bit to transfer more data per cycle. - */ - const uint32_t *src = _src; - uint32_t *dst = _dst; - for (unsigned i = 0; i < height; i += 4, dst += 4 * width2) - { -#define BLIT_LINE_16_CONV(x) x - BLIT_LINE_16(0) - BLIT_LINE_16(2) - BLIT_LINE_16(4) - BLIT_LINE_16(6) -#undef BLIT_LINE_16_CONV - } -#endif } static void convert_texture16_conv(const uint32_t *_src, uint32_t *_dst, @@ -1053,153 +980,6 @@ static void gx_blit_line(gx_video_t *gx, unsigned x, unsigned y, const char *mes } } -static bool gx_frame(void *data, const void *frame, - unsigned width, unsigned height, - uint64_t frame_count, unsigned pitch, - const char *msg) -{ - static struct retro_perf_counter gx_frame = {0}; - char fps_txt[128] = {0}; - char fps_text_buf[128] = {0}; - gx_video_t *gx = (gx_video_t*)data; - struct __gx_regdef *__gx = (struct __gx_regdef*)__gxregs; - u8 clear_efb = GX_FALSE; - settings_t *settings = config_get_ptr(); - - rarch_perf_init(&gx_frame, "gx_frame"); - retro_perf_start(&gx_frame); - - if(!gx || (!frame && !gx->menu_texture_enable)) - return true; - - if (!frame) - width = height = 4; /* draw a black square in the background */ - - if(gx->should_resize) - { - gx_resize(gx); - clear_efb = GX_TRUE; - } - - while (((g_vsync || gx->menu_texture_enable)) && !g_draw_done) - OSSleepThread(g_video_cond); - - width = min(g_tex.width, width); - height = min(g_tex.height, height); - - if (width != gx_old_width || height != gx_old_height) - { - init_texture(data, width, height); - gx_old_width = width; - gx_old_height = height; - } - - g_draw_done = false; - g_current_framebuf ^= 1; - - - if (frame) - { - static struct retro_perf_counter gx_frame_convert = {0}; - - rarch_perf_init(&gx_frame_convert, "gx_frame_convert"); - retro_perf_start(&gx_frame_convert); - - if (gx->rgb32) - convert_texture32(frame, g_tex.data, width, height, pitch); - else if (gx->menu_texture_enable) - convert_texture16_conv(frame, g_tex.data, width, height, pitch); - else - convert_texture16(frame, g_tex.data, width, height, pitch); - DCFlushRange(g_tex.data, height * (width << (gx->rgb32 ? 2 : 1))); - - retro_perf_stop(&gx_frame_convert); - } - - if (gx->menu_texture_enable && gx->menu_data) - { - size_t fb_pitch; - unsigned fb_width, fb_height; - - menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &fb_width); - menu_display_ctl(MENU_DISPLAY_CTL_HEIGHT, &fb_height); - menu_display_ctl(MENU_DISPLAY_CTL_FB_PITCH, &fb_pitch); - - convert_texture16( - gx->menu_data, - menu_tex.data, - fb_width, - fb_height, - fb_pitch); - DCFlushRange( - menu_tex.data, - fb_width * fb_pitch); - } - - __GX_InvalidateTexAll(__gx); - - __GX_SetCurrentMtx(__gx, GX_PNMTX0); - __GX_LoadTexObj(&g_tex.obj, GX_TEXMAP0); - __GX_CallDispList(__gx, display_list, display_list_size); - - if (gx->menu_texture_enable) - { - __GX_SetCurrentMtx(__gx, GX_PNMTX1); - GX_LoadTexObj(&menu_tex.obj, GX_TEXMAP0); - __GX_CallDispList(__gx, display_list, display_list_size); - } - -#ifdef HAVE_OVERLAY - if (gx->overlay_enable) - gx_render_overlay(gx); -#endif - - GX_DrawDone(); - - video_monitor_get_fps(fps_txt, sizeof(fps_txt), - fps_text_buf, sizeof(fps_text_buf)); - - if (settings->fps_show) - { - char mem1_txt[128] = {0}; - char mem2_txt[128] = {0}; - unsigned x = 15; - unsigned y = 35; - - (void)mem2_txt; - - gx_blit_line(gx, x, y, fps_text_buf); - y += FONT_HEIGHT * (gx->double_strike ? 1 : 2); - snprintf(mem1_txt, sizeof(mem1_txt), "MEM1: %8d / %8d", - SYSMEM1_SIZE - SYS_GetArena1Size(), SYSMEM1_SIZE); - gx_blit_line(gx, x, y, mem1_txt); -#ifdef HW_RVL - y += FONT_HEIGHT * (gx->double_strike ? 1 : 2); - snprintf(mem2_txt, sizeof(mem2_txt), "MEM2: %8d / %8d", - gx_mem2_used(), gx_mem2_total()); - gx_blit_line(gx, x, y, mem2_txt); -#endif - } - - if (msg && !gx->menu_texture_enable) - { - unsigned x = 7 * (gx->double_strike ? 1 : 2); - unsigned y = gx->vp.full_height - (35 * (gx->double_strike ? 1 : 2)); - - gx_blit_line(gx, x, y, msg); - clear_efb = GX_TRUE; - } - - __GX_CopyDisp(__gx, gx->framebuf[g_current_framebuf], clear_efb); - __GX_Flush(__gx); - VISetNextFrameBuffer(gx->framebuf[g_current_framebuf]); - VIFlush(); - - retro_perf_stop(&gx_frame); - - return true; -} - static void gx_set_nonblock_state(void *data, bool state) { (void)data; @@ -1232,24 +1012,6 @@ static bool gx_has_windowed(void *data) return false; } -static void gx_free(void *data) -{ -#ifdef HAVE_OVERLAY - gx_video_t *gx = (gx_video_t*)data; - - gx_free_overlay(gx); -#endif - - GX_DrawDone(); - GX_AbortFrame(); - GX_Flush(); - VISetBlack(true); - VIFlush(); - VIWaitForRetrace(); - - free(data); -} - static void gx_set_rotation(void *data, unsigned orientation) { gx_video_t *gx = (gx_video_t*)data; @@ -1309,32 +1071,30 @@ static bool gx_read_viewport(void *data, uint8_t *buffer) return true; } -static void gx_get_video_output_size(void *data, unsigned *width, unsigned *height) -{ - (void)data; - - *width = menu_gx_resolutions[menu_current_gx_resolution][0]; - *height = menu_gx_resolutions[menu_current_gx_resolution][1]; -} - static void gx_get_video_output_prev(void *data) { - if (menu_current_gx_resolution > 0) - menu_current_gx_resolution--; + global_t *global = global_get_ptr(); + + if (global->console.screen.resolutions.current.id == 0) + { + global->console.screen.resolutions.current.id = GX_RESOLUTIONS_LAST; + return; + } + + global->console.screen.resolutions.current.id--; } static void gx_get_video_output_next(void *data) { - if (menu_current_gx_resolution < GX_RESOLUTIONS_LAST - 1) - { -#ifdef HW_RVL - if ((menu_current_gx_resolution + 1) > GX_RESOLUTIONS_640_480) - if (CONF_GetVideo() != CONF_VIDEO_PAL) - return; -#endif + global_t *global = global_get_ptr(); - menu_current_gx_resolution++; + if (global->console.screen.resolutions.current.id >= GX_RESOLUTIONS_LAST) + { + global->console.screen.resolutions.current.id = 0; + return; } + + global->console.screen.resolutions.current.id++; } static const video_poke_interface_t gx_poke_interface = { @@ -1360,41 +1120,6 @@ static void gx_get_poke_interface(void *data, const video_poke_interface_t **ifa } #ifdef HAVE_OVERLAY -static void gx_overlay_tex_geom(void *data, unsigned image, float x, float y, float w, float h); -static void gx_overlay_vertex_geom(void *data, unsigned image, float x, float y, float w, float h); - -static bool gx_overlay_load(void *data, const void *image_data, unsigned num_images) -{ - unsigned i; - gx_video_t *gx = (gx_video_t*)data; - const struct texture_image *images = (const struct texture_image*)image_data; - - gx_free_overlay(gx); - gx->overlay = (struct gx_overlay_data*)calloc(num_images, sizeof(*gx->overlay)); - if (!gx->overlay) - return false; - - gx->overlays = num_images; - - for (i = 0; i < num_images; i++) - { - struct gx_overlay_data *o = (struct gx_overlay_data*)&gx->overlay[i]; - - GX_InitTexObj(&o->tex, images[i].pixels, images[i].width, - images[i].height, - GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); - GX_InitTexObjFilterMode(&g_tex.obj, GX_LINEAR, GX_LINEAR); - DCFlushRange(images[i].pixels, images[i].width * - images[i].height * sizeof(uint32_t)); - gx_overlay_tex_geom(gx, i, 0, 0, 1, 1); /* Default. Stretch to whole screen. */ - gx_overlay_vertex_geom(gx, i, 0, 0, 1, 1); - gx->overlay[i].alpha_mod = 1.0f; - } - - GX_InvalidateTexAll(); - return true; -} - static void gx_overlay_tex_geom(void *data, unsigned image, float x, float y, float w, float h) { @@ -1449,6 +1174,46 @@ static void gx_overlay_vertex_geom(void *data, unsigned image, o->vertex_coord[7] = y + h; } +static void gx_free_overlay(gx_video_t *gx) +{ + free(gx->overlay); + gx->overlay = NULL; + gx->overlays = 0; + GX_InvalidateTexAll(); +} + +static bool gx_overlay_load(void *data, const void *image_data, unsigned num_images) +{ + unsigned i; + gx_video_t *gx = (gx_video_t*)data; + const struct texture_image *images = (const struct texture_image*)image_data; + + gx_free_overlay(gx); + gx->overlay = (struct gx_overlay_data*)calloc(num_images, sizeof(*gx->overlay)); + if (!gx->overlay) + return false; + + gx->overlays = num_images; + + for (i = 0; i < num_images; i++) + { + struct gx_overlay_data *o = (struct gx_overlay_data*)&gx->overlay[i]; + + GX_InitTexObj(&o->tex, images[i].pixels, images[i].width, + images[i].height, + GX_TF_RGBA8, GX_CLAMP, GX_CLAMP, GX_FALSE); + GX_InitTexObjFilterMode(&g_tex.obj, GX_LINEAR, GX_LINEAR); + DCFlushRange(images[i].pixels, images[i].width * + images[i].height * sizeof(uint32_t)); + gx_overlay_tex_geom(gx, i, 0, 0, 1, 1); /* Default. Stretch to whole screen. */ + gx_overlay_vertex_geom(gx, i, 0, 0, 1, 1); + gx->overlay[i].alpha_mod = 1.0f; + } + + GX_InvalidateTexAll(); + return true; +} + static void gx_overlay_enable(void *data, bool state) { gx_video_t *gx = (gx_video_t*)data; @@ -1531,6 +1296,174 @@ static void gx_get_overlay_interface(void *data, const video_overlay_interface_t } #endif +static void gx_free(void *data) +{ +#ifdef HAVE_OVERLAY + gx_video_t *gx = (gx_video_t*)data; + + gx_free_overlay(gx); +#endif + + GX_DrawDone(); + GX_AbortFrame(); + GX_Flush(); + VIDEO_SetBlack(true); + VIDEO_Flush(); + VIDEO_WaitVSync(); + + if (g_video_cond) + OSCloseThreadQueue(g_video_cond); + g_video_cond = 0; + + free(data); +} + +static bool gx_frame(void *data, const void *frame, + unsigned width, unsigned height, + uint64_t frame_count, unsigned pitch, + const char *msg) +{ + static struct retro_perf_counter gx_frame = {0}; + char fps_txt[128] = {0}; + char fps_text_buf[128] = {0}; + gx_video_t *gx = (gx_video_t*)data; + u8 clear_efb = GX_FALSE; + settings_t *settings = config_get_ptr(); + + rarch_perf_init(&gx_frame, "gx_frame"); + retro_perf_start(&gx_frame); + + if(!gx || (!frame && !gx->menu_texture_enable)) + return true; + + if (!frame) + width = height = 4; /* draw a black square in the background */ + + if(gx->should_resize) + { + gx_resize(gx); + clear_efb = GX_TRUE; + } + + while (((g_vsync || gx->menu_texture_enable)) && !g_draw_done) + OSSleepThread(g_video_cond); + + width = min(g_tex.width, width); + height = min(g_tex.height, height); + + if (width != gx_old_width || height != gx_old_height) + { + init_texture(data, width, height); + gx_old_width = width; + gx_old_height = height; + } + + g_draw_done = false; + g_current_framebuf ^= 1; + + + if (frame) + { + static struct retro_perf_counter gx_frame_convert = {0}; + + rarch_perf_init(&gx_frame_convert, "gx_frame_convert"); + retro_perf_start(&gx_frame_convert); + + if (gx->rgb32) + convert_texture32(frame, g_tex.data, width, height, pitch); + else if (gx->menu_texture_enable) + convert_texture16_conv(frame, g_tex.data, width, height, pitch); + else + convert_texture16(frame, g_tex.data, width, height, pitch); + DCFlushRange(g_tex.data, height * (width << (gx->rgb32 ? 2 : 1))); + + retro_perf_stop(&gx_frame_convert); + } + + if (gx->menu_texture_enable && gx->menu_data) + { + size_t fb_pitch; + unsigned fb_width, fb_height; + + menu_display_ctl(MENU_DISPLAY_CTL_WIDTH, &fb_width); + menu_display_ctl(MENU_DISPLAY_CTL_HEIGHT, &fb_height); + menu_display_ctl(MENU_DISPLAY_CTL_FB_PITCH, &fb_pitch); + + convert_texture16( + gx->menu_data, + menu_tex.data, + fb_width, + fb_height, + fb_pitch); + DCFlushRange( + menu_tex.data, + fb_width * fb_pitch); + } + + GX_InvalidateTexAll(); + + GX_SetCurrentMtx(GX_PNMTX0); + GX_LoadTexObj(&g_tex.obj, GX_TEXMAP0); + GX_CallDispList(display_list, display_list_size); + + if (gx->menu_texture_enable) + { + GX_SetCurrentMtx(GX_PNMTX1); + GX_LoadTexObj(&menu_tex.obj, GX_TEXMAP0); + GX_CallDispList(display_list, display_list_size); + } + +#ifdef HAVE_OVERLAY + if (gx->overlay_enable) + gx_render_overlay(gx); +#endif + + GX_DrawDone(); + + video_monitor_get_fps(fps_txt, sizeof(fps_txt), + fps_text_buf, sizeof(fps_text_buf)); + + if (settings->fps_show) + { + char mem1_txt[128] = {0}; + char mem2_txt[128] = {0}; + unsigned x = 15; + unsigned y = 35; + + (void)mem2_txt; + + gx_blit_line(gx, x, y, fps_text_buf); + y += FONT_HEIGHT * (gx->double_strike ? 1 : 2); + snprintf(mem1_txt, sizeof(mem1_txt), "MEM1: %8d / %8d", + SYSMEM1_SIZE - SYS_GetArena1Size(), SYSMEM1_SIZE); + gx_blit_line(gx, x, y, mem1_txt); +#ifdef HW_RVL + y += FONT_HEIGHT * (gx->double_strike ? 1 : 2); + snprintf(mem2_txt, sizeof(mem2_txt), "MEM2: %8d / %8d", + gx_mem2_used(), gx_mem2_total()); + gx_blit_line(gx, x, y, mem2_txt); +#endif + } + + if (msg && !gx->menu_texture_enable) + { + unsigned x = 7 * (gx->double_strike ? 1 : 2); + unsigned y = gx->vp.full_height - (35 * (gx->double_strike ? 1 : 2)); + + gx_blit_line(gx, x, y, msg); + clear_efb = GX_TRUE; + } + + GX_CopyDisp(gx->framebuf[g_current_framebuf], clear_efb); + GX_Flush(); + VIDEO_SetNextFramebuffer(gx->framebuf[g_current_framebuf]); + VIDEO_Flush(); + + retro_perf_stop(&gx_frame); + + return true; +} + static bool gx_set_shader(void *data, enum rarch_shader_type type, const char *path) { diff --git a/gfx/drivers/gx_gfx_inl.h b/gfx/drivers/gx_gfx_inl.h deleted file mode 100644 index 8c6289813e..0000000000 --- a/gfx/drivers/gx_gfx_inl.h +++ /dev/null @@ -1,774 +0,0 @@ -#include - -#include "../../defines/gx_defines.h" - -#define STRUCT_REGDEF_SIZE 1440 -#define WGPIPE (0xCC008000) - -#define FIFO_PUTU8(x) *(vu8*)WGPIPE = (u8)(x) -#define FIFO_PUTS8(x) *(vs8*)WGPIPE = (s8)(x) -#define FIFO_PUTU16(x) *(vu16*)WGPIPE = (u16)(x) -#define FIFO_PUTS16(x) *(vs16*)WGPIPE = (s16)(x) -#define FIFO_PUTU32(x) *(vu32*)WGPIPE = (u32)(x) -#define FIFO_PUTS32(x) *(vs32*)WGPIPE = (s32)(x) -#define FIFO_PUTF32(x) *(vf32*)WGPIPE = (f32)(x) - -#define XY(x, y) (((y) << 10) | (x)) - -#define GX_LOAD_BP_REG(x) \ - FIFO_PUTU8(0x61); \ - FIFO_PUTU32((x)) - -#define GX_LOAD_CP_REG(x, y) \ - FIFO_PUTU8(0x08); \ - FIFO_PUTU8((x)); \ - FIFO_PUTU32((y)) - -#define GX_LOAD_XF_REG(x, y) \ - FIFO_PUTU8(0x10); \ - FIFO_PUTU32(((x) & 0xffff)); \ - FIFO_PUTU32((y)) - -#define GX_LOAD_XF_REGS(x, n) \ - FIFO_PUTU8(0x10); \ - FIFO_PUTU32((((((n) & 0xffff)-1)<<16)|((x) & 0xffff))) - -extern u8 __gxregs[]; - -struct __gx_regdef -{ - u16 cpSRreg; - u16 cpCRreg; - u16 cpCLreg; - u16 xfFlush; - u16 xfFlushExp; - u16 xfFlushSafe; - u32 gxFifoInited; - u32 vcdClear; - u32 VATTable; - u32 mtxIdxLo; - u32 mtxIdxHi; - u32 texCoordManually; - u32 vcdLo; - u32 vcdHi; - u32 vcdNrms; - u32 dirtyState; - u32 perf0Mode; - u32 perf1Mode; - u32 cpPerfMode; - u32 VAT0reg[8]; - u32 VAT1reg[8]; - u32 VAT2reg[8]; - u32 texMapSize[8]; - u32 texMapWrap[8]; - u32 sciTLcorner; - u32 sciBRcorner; - u32 lpWidth; - u32 genMode; - u32 suSsize[8]; - u32 suTsize[8]; - u32 tevTexMap[16]; - u32 tevColorEnv[16]; - u32 tevAlphaEnv[16]; - u32 tevSwapModeTable[8]; - u32 tevRasOrder[11]; - u32 tevTexCoordEnable; - u32 tevIndMask; - u32 texCoordGen[8]; - u32 texCoordGen2[8]; - u32 dispCopyCntrl; - u32 dispCopyDst; - u32 dispCopyTL; - u32 dispCopyWH; - u32 texCopyCntrl; - u32 texCopyDst; - u32 texCopyTL; - u32 texCopyWH; - u32 peZMode; - u32 peCMode0; - u32 peCMode1; - u32 peCntrl; - u32 chnAmbColor[2]; - u32 chnMatColor[2]; - u32 chnCntrl[4]; - GXTexRegion texRegion[24]; - GXTlutRegion tlutRegion[20]; - u8 saveDLctx; - u8 gxFifoUnlinked; - u8 texCopyZTex; - u8 _pad; -} __attribute__((packed)); - -struct __gx_texobj -{ - u32 tex_filt; - u32 tex_lod; - u32 tex_size; - u32 tex_maddr; - u32 usr_data; - u32 tex_fmt; - u32 tex_tlut; - u16 tex_tile_cnt; - u8 tex_tile_type; - u8 tex_flag; -} __attribute__((packed)); - -#define __GX_FlushTextureState(__gx) GX_LOAD_BP_REG(__gx->tevIndMask) - -#define __GX_SetDispCopySrc(__gx, left, top, wd, ht) \ -__gx->dispCopyTL = (__gx->dispCopyTL & ~0x00ffffff) | XY(left,top); \ -__gx->dispCopyTL = (__gx->dispCopyTL & ~0xff000000) | (_SHIFTL(0x49,24,8)); \ -__gx->dispCopyWH = (__gx->dispCopyWH & ~0x00ffffff) | XY((wd-1),(ht-1)); \ -__gx->dispCopyWH = (__gx->dispCopyWH & ~0xff000000) | (_SHIFTL(0x4a,24,8)) - -#define __GX_SetDispCopyDst(__gx, wd, ht) \ -__gx->dispCopyDst = (__gx->dispCopyDst & ~0x3ff) | (_SHIFTR(wd,4,10)); \ -__gx->dispCopyDst = (__gx->dispCopyDst & ~0xff000000) | (_SHIFTL(0x4d,24,8)) - -#define __GX_SetClipMode(mode) GX_LOAD_XF_REG(0x1005,(mode & 1)) - -#define __GX_CopyDisp(__gx, dest, clear) \ -{ \ - u8 clflag; \ - u32 val; \ - if(clear) \ - { \ - val= (__gx->peZMode & ~0xf) | 0xf; \ - GX_LOAD_BP_REG(val); \ - val = (__gx->peCMode0 & ~0x3); \ - GX_LOAD_BP_REG(val); \ - } \ - clflag = 0; \ - if (clear || (__gx->peCntrl & 0x7) == 0x0003) \ - { \ - if (__gx->peCntrl & 0x40) \ - { \ - clflag = 1; \ - val = (__gx->peCntrl & ~0x40); \ - GX_LOAD_BP_REG(val); \ - } \ - } \ - GX_LOAD_BP_REG(__gx->dispCopyTL); /* set source top */ \ - GX_LOAD_BP_REG(__gx->dispCopyWH); \ - GX_LOAD_BP_REG(__gx->dispCopyDst); \ - val = 0x4b000000 | (_SHIFTR(MEM_VIRTUAL_TO_PHYSICAL(dest),5,24)); \ - GX_LOAD_BP_REG(val); \ - __gx->dispCopyCntrl = (__gx->dispCopyCntrl & ~0x800) | (_SHIFTL(clear,11,1)); \ - __gx->dispCopyCntrl = (__gx->dispCopyCntrl & ~0x4000) | 0x4000; \ - __gx->dispCopyCntrl = (__gx->dispCopyCntrl & ~0xff000000) | (_SHIFTL(0x52,24,8)); \ - GX_LOAD_BP_REG(__gx->dispCopyCntrl); \ - if (clear) \ - { \ - GX_LOAD_BP_REG(__gx->peZMode); \ - GX_LOAD_BP_REG(__gx->peCMode0); \ - } \ - if (clflag) \ - { \ - GX_LOAD_BP_REG(__gx->peCntrl); \ - } \ -} - -#if 0 -static void __SETVCDATTR(struct __gx_regdef *__gx, u8 attr,u8 type) -{ - switch(attr) - { - case GX_VA_PTNMTXIDX: - __gx->vcdLo = (__gx->vcdLo & ~0x1) | (type & 0x1); - break; - case GX_VA_TEX0MTXIDX: - __gx->vcdLo = (__gx->vcdLo & ~0x2) | (_SHIFTL(type,1,1)); - break; - case GX_VA_TEX1MTXIDX: - __gx->vcdLo = (__gx->vcdLo & ~0x4)|(_SHIFTL(type,2,1)); - break; - case GX_VA_TEX2MTXIDX: - __gx->vcdLo = (__gx->vcdLo & ~0x8)|(_SHIFTL(type,3,1)); - break; - case GX_VA_TEX3MTXIDX: - __gx->vcdLo = (__gx->vcdLo&~0x10)|(_SHIFTL(type,4,1)); - break; - case GX_VA_TEX4MTXIDX: - __gx->vcdLo = (__gx->vcdLo&~0x20)|(_SHIFTL(type,5,1)); - break; - case GX_VA_TEX5MTXIDX: - __gx->vcdLo = (__gx->vcdLo&~0x40)|(_SHIFTL(type,6,1)); - break; - case GX_VA_TEX6MTXIDX: - __gx->vcdLo = (__gx->vcdLo&~0x80)|(_SHIFTL(type,7,1)); - break; - case GX_VA_TEX7MTXIDX: - __gx->vcdLo = (__gx->vcdLo&~0x100)|(_SHIFTL(type,8,1)); - break; - case GX_VA_POS: - __gx->vcdLo = (__gx->vcdLo&~0x600)|(_SHIFTL(type,9,2)); - break; - case GX_VA_NRM: - __gx->vcdLo = (__gx->vcdLo&~0x1800)|(_SHIFTL(type,11,2)); - __gx->vcdNrms = 1; - break; - case GX_VA_NBT: - __gx->vcdLo = (__gx->vcdLo&~0x1800)|(_SHIFTL(type,11,2)); - __gx->vcdNrms = 2; - break; - case GX_VA_CLR0: - __gx->vcdLo = (__gx->vcdLo&~0x6000)|(_SHIFTL(type,13,2)); - break; - case GX_VA_CLR1: - __gx->vcdLo = (__gx->vcdLo&~0x18000)|(_SHIFTL(type,15,2)); - break; - case GX_VA_TEX0: - __gx->vcdHi = (__gx->vcdHi&~0x3)|(type&0x3); - break; - case GX_VA_TEX1: - __gx->vcdHi = (__gx->vcdHi&~0xc)|(_SHIFTL(type,2,2)); - break; - case GX_VA_TEX2: - __gx->vcdHi = (__gx->vcdHi&~0x30)|(_SHIFTL(type,4,2)); - break; - case GX_VA_TEX3: - __gx->vcdHi = (__gx->vcdHi&~0xc0)|(_SHIFTL(type,6,2)); - break; - case GX_VA_TEX4: - __gx->vcdHi = (__gx->vcdHi&~0x300)|(_SHIFTL(type,8,2)); - break; - case GX_VA_TEX5: - __gx->vcdHi = (__gx->vcdHi&~0xc00)|(_SHIFTL(type,10,2)); - break; - case GX_VA_TEX6: - __gx->vcdHi = (__gx->vcdHi&~0x3000)|(_SHIFTL(type,12,2)); - break; - case GX_VA_TEX7: - __gx->vcdHi = (__gx->vcdHi&~0xc000)|(_SHIFTL(type,14,2)); - break; - } -} -#endif - -#define XSHIFT 2 -#define YSHIFT 2 - -#define __GX_InitTexObj(ptr, img_ptr, wd, ht, fmt, wrap_s, wrap_t, mipmap) \ - ptr->tex_filt = (ptr->tex_filt & ~0x03)|(wrap_s & 3); \ - ptr->tex_filt = (ptr->tex_filt & ~0x0c)|(_SHIFTL(wrap_t,2,2)); \ - ptr->tex_filt = (ptr->tex_filt & ~0x10)|0x10; \ - /* no mip-mapping */ \ - ptr->tex_filt= (ptr->tex_filt & ~0xE0)|0x0080; \ - ptr->tex_fmt = fmt; \ - ptr->tex_size = (ptr->tex_size & ~0x3ff)|((wd-1) & 0x3ff); \ - ptr->tex_size = (ptr->tex_size & ~0xFFC00)|(_SHIFTL((ht-1),10,10)); \ - ptr->tex_size = (ptr->tex_size & ~0xF00000)|(_SHIFTL(fmt,20,4)); \ - ptr->tex_maddr = (ptr->tex_maddr & ~0x01ffffff)|(_SHIFTR(MEM_VIRTUAL_TO_PHYSICAL(img_ptr),5,24)); \ - ptr->tex_tile_type = 2; \ - ptr->tex_tile_cnt = ((((wd+(1 << XSHIFT))-1) >> XSHIFT) * (((ht+(1 << YSHIFT))-1) >> YSHIFT)) & 0x7fff; \ - ptr->tex_flag |= 0x0002 - - -#define __GX_InvalidateTexAll(__gx) \ - GX_LOAD_BP_REG(__gx->tevIndMask); \ - GX_LOAD_BP_REG(0x66001000); \ - GX_LOAD_BP_REG(0x66001100); \ - GX_LOAD_BP_REG(__gx->tevIndMask) - -#define __GX_SetCurrentMtx(__gx, mtx) \ - __gx->mtxIdxLo = (__gx->mtxIdxLo & ~0x3f)|(mtx & 0x3f); \ - __gx->dirtyState |= 0x04000000 - -#define __GX_SetVAT(__gx, setvtx) \ - for(s32 i = 0; i < 8;i++) \ - { \ - setvtx = (1<VATTable & setvtx) \ - { \ - GX_LOAD_CP_REG((0x70+(i & 7)),__gx->VAT0reg[i]); \ - GX_LOAD_CP_REG((0x80+(i & 7)),__gx->VAT1reg[i]); \ - GX_LOAD_CP_REG((0x90+(i & 7)),__gx->VAT2reg[i]); \ - } \ - } \ - __gx->VATTable = 0 - -#define __GX_XfVtxSpecs(__gx) \ -{ \ - u32 nrms,texs,cols; \ - cols = 0; \ - if(__gx->vcdLo & 0x6000) cols++; \ - if(__gx->vcdLo & 0x18000) cols++; \ - nrms = 0; \ - if(__gx->vcdNrms==1) nrms = 1; \ - else if(__gx->vcdNrms==2) nrms = 2; \ - texs = 0; \ - if(__gx->vcdHi & 0x3) texs++; \ - if(__gx->vcdHi & 0xc) texs++; \ - if(__gx->vcdHi & 0x30) texs++; \ - if(__gx->vcdHi & 0xc0) texs++; \ - if(__gx->vcdHi & 0x300) texs++; \ - if(__gx->vcdHi & 0xc00) texs++; \ - if(__gx->vcdHi & 0x3000) texs++; \ - if(__gx->vcdHi & 0xc000) texs++; \ - GX_LOAD_XF_REG(0x1008, ((_SHIFTL(texs,4,4))|(_SHIFTL(nrms,2,2))|(cols & 0x3))); \ -} - -#define __GX_SetVCD(__gx) \ - GX_LOAD_CP_REG(0x50,__gx->vcdLo); \ - GX_LOAD_CP_REG(0x60,__gx->vcdHi); \ - __GX_XfVtxSpecs(__gx) - - -#define __GX_SetChanCntrl(__gx) \ -{ \ - u32 i,chan,mask; \ - if(__gx->dirtyState & 0x01000000) \ - { \ - GX_LOAD_XF_REG(0x1009,(_SHIFTR(__gx->genMode,4,3))); \ - } \ - i = 0; \ - chan = 0x100e; \ - mask = _SHIFTR(__gx->dirtyState,12,4); \ - while(mask) { \ - if(mask & 0x0001) \ - { \ - GX_LOAD_XF_REG(chan,__gx->chnCntrl[i]); \ - } \ - mask >>= 1; \ - chan++; \ - i++; \ - } \ -} - -#define __GX_SetMatrixIndex(__gx, mtx) \ - if(mtx<5) { \ - GX_LOAD_CP_REG(0x30,__gx->mtxIdxLo); \ - GX_LOAD_XF_REG(0x1018,__gx->mtxIdxLo); \ - } else { \ - GX_LOAD_CP_REG(0x40,__gx->mtxIdxHi); \ - GX_LOAD_XF_REG(0x1019,__gx->mtxIdxHi); \ - } - -#define __GX_SetArray(__gx, attr, ptr, stride) \ - if(attr>=GX_VA_POS && attr<=GX_LIGHTARRAY) \ - { \ - GX_LOAD_CP_REG((0xA0 +((attr) - GX_VA_POS)),(u32)MEM_VIRTUAL_TO_PHYSICAL(ptr)); \ - GX_LOAD_CP_REG((0xB0 +((attr) - GX_VA_POS)),(u32)(stride)); \ - } - -#define __GX_Begin(__vtx, primitive, vtxfmt, vtxcnt) \ - if(__gx->dirtyState) \ - __GX_SetDirtyState(__gx); \ - FIFO_PUTU8(primitive | (vtxfmt & 7)); \ - FIFO_PUTU16(vtxcnt) - -#ifdef HW_DOL -static INLINE void __GX_UpdateBPMask(struct __gx_regdef *__gx) -{ - u32 i; - u8 ntexmap; - u32 nbmp = _SHIFTR(__gx->genMode,16,3); - u32 nres = 0; - - for(i = 0; i < nbmp; i++) - { - switch (i) - { - case GX_INDTEXSTAGE0: - ntexmap = __gx->tevRasOrder[2] & 7; - break; - case GX_INDTEXSTAGE1: - ntexmap = _SHIFTR(__gx->tevRasOrder[2],6,3); - break; - case GX_INDTEXSTAGE2: - ntexmap = _SHIFTR(__gx->tevRasOrder[2],12,3); - break; - case GX_INDTEXSTAGE3: - ntexmap = _SHIFTR(__gx->tevRasOrder[2],18,3); - break; - default: - ntexmap = 0; - break; - } - nres |= (1<tevIndMask & 0xff)!=nres) - { - __gx->tevIndMask = (__gx->tevIndMask & ~0xff)|(nres & 0xff); - GX_LOAD_BP_REG(__gx->tevIndMask); - } -} -#endif - -#define __GX_SetChanColor(__gx) \ - if(__gx->dirtyState & 0x0100) \ - { \ - GX_LOAD_XF_REG(0x100a,__gx->chnAmbColor[0]); \ - } \ - if(__gx->dirtyState & 0x0200) \ - { \ - GX_LOAD_XF_REG(0x100b,__gx->chnAmbColor[1]); \ - } \ - if(__gx->dirtyState & 0x0400) \ - { \ - GX_LOAD_XF_REG(0x100c,__gx->chnMatColor[0]); \ - } \ - if(__gx->dirtyState & 0x0800) \ - { \ - GX_LOAD_XF_REG(0x100d,__gx->chnMatColor[1]); \ - } - -static INLINE void __GX_SetTexCoordGen(struct __gx_regdef *__gx) -{ - u32 i,mask; - u32 texcoord; - - if(__gx->dirtyState&0x02000000) - { - GX_LOAD_XF_REG(0x103f,(__gx->genMode&0xf)); - } - - i = 0; - texcoord = 0x1040; - mask = _SHIFTR(__gx->dirtyState,16,8); - while(mask) - { - if(mask&0x0001) - { - GX_LOAD_XF_REG(texcoord,__gx->texCoordGen[i]); - GX_LOAD_XF_REG((texcoord+0x10),__gx->texCoordGen2[i]); - } - mask >>= 1; - texcoord++; - i++; - } -} - -static void __SetSURegs(struct __gx_regdef *__gx, u8 texmap,u8 texcoord) -{ - u16 wd = __gx->texMapSize[texmap] & 0x3ff; - u16 ht = _SHIFTR(__gx->texMapSize[texmap],10,10); - u8 wrap_s = __gx->texMapWrap[texmap] & 3; - u8 wrap_t = _SHIFTR(__gx->texMapWrap[texmap],2,2); - u32 reg = (texcoord & 0x7); - - __gx->suSsize[reg] = (__gx->suSsize[reg] & ~0x0000ffff)|wd; - __gx->suTsize[reg] = (__gx->suTsize[reg]&~0x0000ffff)|ht; - __gx->suSsize[reg] = (__gx->suSsize[reg]&~0x00010000)|(_SHIFTL(wrap_s,16,1)); - __gx->suTsize[reg] = (__gx->suTsize[reg]&~0x00010000)|(_SHIFTL(wrap_t,16,1)); - - GX_LOAD_BP_REG(__gx->suSsize[reg]); - GX_LOAD_BP_REG(__gx->suTsize[reg]); -} - -static INLINE void __GX_SetSUTexRegs(struct __gx_regdef *__gx) -{ - u32 i, texcm; - u8 texcoord, texmap; - u32 dirtev = (_SHIFTR(__gx->genMode,10,4))+1; - u32 indtev = _SHIFTR(__gx->genMode,16,3); - - /* Indirect texture order */ - for(i = 0; i < indtev; i++) - { - switch(i) - { - case GX_INDTEXSTAGE0: - texmap = __gx->tevRasOrder[2] & 7; - texcoord = _SHIFTR(__gx->tevRasOrder[2],3,3); - break; - case GX_INDTEXSTAGE1: - texmap = _SHIFTR(__gx->tevRasOrder[2],6,3); - texcoord = _SHIFTR(__gx->tevRasOrder[2],9,3); - break; - case GX_INDTEXSTAGE2: - texmap = _SHIFTR(__gx->tevRasOrder[2],12,3); - texcoord = _SHIFTR(__gx->tevRasOrder[2],15,3); - break; - case GX_INDTEXSTAGE3: - texmap = _SHIFTR(__gx->tevRasOrder[2],18,3); - texcoord = _SHIFTR(__gx->tevRasOrder[2],21,3); - break; - default: - texmap = 0; - texcoord = 0; - break; - } - - texcm = _SHIFTL(1,texcoord,1); - - if(!(__gx->texCoordManually & texcm)) - __SetSURegs(__gx, texmap,texcoord); - } - - /* Direct texture order */ - for(i = 0; i < dirtev; i++) - { - u32 tevm; - u32 tevreg = 3+(_SHIFTR(i,1,3)); - texmap = (__gx->tevTexMap[i] & 0xff); - - if(i & 1) - texcoord = _SHIFTR(__gx->tevRasOrder[tevreg],15,3); - else - texcoord = _SHIFTR(__gx->tevRasOrder[tevreg],3,3); - - tevm = _SHIFTL(1,i,1); - texcm = _SHIFTL(1,texcoord,1); - if(texmap!=0xff && (__gx->tevTexCoordEnable & tevm) && !(__gx->texCoordManually & texcm)) - { - __SetSURegs(__gx, texmap,texcoord); - } - } -} - -#define __GX_SetGenMode(__gx) \ - GX_LOAD_BP_REG(__gx->genMode); \ - __gx->xfFlush = 0 - -static void __GX_SetDirtyState(struct __gx_regdef *__gx) -{ - if(__gx->dirtyState & 0x0001) - { - __GX_SetSUTexRegs(__gx); - } -#ifdef HW_DOL - if(__gx->dirtyState & 0x0002) - { - __GX_UpdateBPMask(__gx); - } -#endif - if(__gx->dirtyState & 0x0004) - { - __GX_SetGenMode(__gx); - } - if(__gx->dirtyState & 0x0008) - { - __GX_SetVCD(__gx); - } - if(__gx->dirtyState & 0x0010) - { - u8 setvtx = 0; - __GX_SetVAT(__gx, setvtx); - } - if(__gx->dirtyState & ~0xff) - { - if(__gx->dirtyState & 0x0f00) - { - __GX_SetChanColor(__gx); - } - if(__gx->dirtyState & 0x0100f000) - { - __GX_SetChanCntrl(__gx); - } - if(__gx->dirtyState & 0x02ff0000) - { - __GX_SetTexCoordGen(__gx); - } - if(__gx->dirtyState & 0x04000000) - { - __GX_SetMatrixIndex(__gx, 0); - __GX_SetMatrixIndex(__gx, 5); - } - } - __gx->dirtyState = 0; -} - -static void __GX_SendFlushPrim(struct __gx_regdef *__gx) -{ - u32 tmp2,cnt; - u32 tmp = (__gx->xfFlush*__gx->xfFlushExp); - - FIFO_PUTU8(0x98); - FIFO_PUTU16(__gx->xfFlush); - - tmp2 = (tmp+3)/4; - - if(tmp > 0) - { - cnt = tmp2/8; - while(cnt) - { - FIFO_PUTU32(0); - FIFO_PUTU32(0); - FIFO_PUTU32(0); - FIFO_PUTU32(0); - FIFO_PUTU32(0); - FIFO_PUTU32(0); - FIFO_PUTU32(0); - FIFO_PUTU32(0); - cnt--; - } - tmp2 &= 0x0007; - if(tmp2) - { - while(tmp2) - { - FIFO_PUTU32(0); - tmp2--; - } - } - } - __gx->xfFlush = 1; -} - -#define __GX_InitTexObjFilterMode(ptr, minfilt, magfilt) \ -{ \ - static u8 GX2HWFiltConv[] = {0x00,0x04,0x01,0x05,0x02,0x06,0x00,0x00}; \ - ptr->tex_filt = (ptr->tex_filt & ~0x10)|(_SHIFTL((magfilt==GX_LINEAR?1:0),4,1)); \ - ptr->tex_filt = (ptr->tex_filt & ~0xe0)|(_SHIFTL(GX2HWFiltConv[minfilt],5,3)); \ -} - -#define __GX_SetCullMode(__gx, mode) \ -{ \ - static u8 cm2hw[] = { 0, 2, 1, 3 }; \ - __gx->genMode = (__gx->genMode & ~0xC000)|(_SHIFTL(cm2hw[mode],14,2)); \ - __gx->dirtyState |= 0x0004; \ -} - -#define __GX_CallDispList(__gx, list, nbytes) \ - if(__gx->dirtyState) \ - { \ - __GX_SetDirtyState(__gx); \ - } \ - if(!__gx->vcdClear) \ - { \ - __GX_SendFlushPrim(__gx); \ - } \ - FIFO_PUTU8(0x40); /*call displaylist */ \ - FIFO_PUTU32(MEM_VIRTUAL_TO_PHYSICAL(list)); \ - FIFO_PUTU32(nbytes) - -#define __GX_Flush(__gx) \ - if(__gx->dirtyState) \ - __GX_SetDirtyState(__gx); \ - FIFO_PUTU32(0); \ - FIFO_PUTU32(0); \ - FIFO_PUTU32(0); \ - FIFO_PUTU32(0); \ - FIFO_PUTU32(0); \ - FIFO_PUTU32(0); \ - FIFO_PUTU32(0); \ - FIFO_PUTU32(0); \ - ppcsync() - -#define __GX_ClearVtxDesc(__gx) \ - __gx->vcdNrms = 0; \ - __gx->vcdClear = ((__gx->vcdClear & ~0x0600)|0x0200); \ - __gx->vcdLo = __gx->vcdHi = 0; \ - __gx->dirtyState |= 0x0008 - -#if 0 -#define __GX_SetVtxDesc(__gx, attr, type) \ - __SETVCDATTR(__gx, attr,type); \ - __gx->dirtyState |= 0x0008 -#endif - -#define __GX_SetBlendMode(__gx, type, src_fact, dst_fact, op) \ - __gx->peCMode0 = (__gx->peCMode0 & ~0x1); \ - if(type==GX_BM_BLEND || type==GX_BM_SUBTRACT) __gx->peCMode0 |= 0x1; \ - __gx->peCMode0 = (__gx->peCMode0 & ~0x800); \ - if(type==GX_BM_SUBTRACT) __gx->peCMode0 |= 0x800; \ - __gx->peCMode0 = (__gx->peCMode0 & ~0x2); \ - if(type==GX_BM_LOGIC) __gx->peCMode0 |= 0x2; \ - __gx->peCMode0 = (__gx->peCMode0 & ~0xF000)|(_SHIFTL(op,12,4)); \ - __gx->peCMode0 = (__gx->peCMode0 & ~0xE0)|(_SHIFTL(dst_fact,5,3)); \ - __gx->peCMode0 = (__gx->peCMode0 & ~0x700)|(_SHIFTL(src_fact,8,3)); \ - GX_LOAD_BP_REG(__gx->peCMode0) - -#define __GX_InvVtxCache() FIFO_PUTU8(0x48) - -#define __GX_SetDispCopyGamma(__gx, gamma) __gx->dispCopyCntrl = (__gx->dispCopyCntrl & ~0x180) | (_SHIFTL(gamma,7,2)) - -#define __GX_SetColorUpdate(__gx, enable) \ - __gx->peCMode0 = (__gx->peCMode0 & ~0x8)|(_SHIFTL(enable,3,1)); \ - GX_LOAD_BP_REG(__gx->peCMode0) - -#define __GX_SetAlphaUpdate(__gx, enable) \ - __gx->peCMode0 = (__gx->peCMode0 & ~0x10)|(_SHIFTL(enable,4,1)); \ - GX_LOAD_BP_REG(__gx->peCMode0) - -#define __GX_SetNumChans(__gx, num) \ - __gx->genMode = (__gx->genMode & ~0x70)|(_SHIFTL(num,4,3)); \ - __gx->dirtyState |= 0x01000004 - -#define __GX_SetNumTexGens(__gx, nr) \ - __gx->genMode = (__gx->genMode & ~0xf)|(nr & 0xf); \ - __gx->dirtyState |= 0x02000004 - -#define __GX_PokeARGB(x, y, color) \ -{ \ - u32 regval; \ - regval = 0xc8000000|(_SHIFTL(x,2,10)); \ - regval = (regval & ~0x3FF000)|(_SHIFTL(y,12,10)); \ - *(u32*)regval = _SHIFTL(color.a,24,8)|_SHIFTL(color.r,16,8)|_SHIFTL(color.g,8,8)|(color.b & 0xff); \ -} - -#define __GX_SetFieldMode(__gx, field_mode, half_aspect_ratio) \ - __gx->lpWidth = (__gx->lpWidth & ~0x400000)|(_SHIFTL(half_aspect_ratio,22,1)); \ - GX_LOAD_BP_REG(__gx->lpWidth); \ - __GX_FlushTextureState(__gx); \ - GX_LOAD_BP_REG(0x68000000|(field_mode & 1)); \ - __GX_FlushTextureState(__gx) - -#define __GX_SetCopyClear(color, zvalue) \ -{ \ - u32 val; \ - val = (_SHIFTL(color.a,8,8))|(color.r & 0xff); \ - GX_LOAD_BP_REG(0x4f000000|val); \ - val = (_SHIFTL(color.g,8,8))|(color.b & 0xff); \ - GX_LOAD_BP_REG(0x50000000|val); \ - val = zvalue & 0x00ffffff; \ - GX_LOAD_BP_REG(0x51000000|val); \ -} - -#define __GX_SetZMode(__gx, enable, func, update_enable) \ - __gx->peZMode = (__gx->peZMode&~0x1)|(enable&1); \ - __gx->peZMode = (__gx->peZMode&~0xe)|(_SHIFTL(func,1,3)); \ - __gx->peZMode = (__gx->peZMode&~0x10)|(_SHIFTL(update_enable,4,1)); \ - GX_LOAD_BP_REG(__gx->peZMode) - -#define __GX_LoadTexObj(obj, mapid) \ -{ \ - struct __gx_texobj *ptr = (struct __gx_texobj*)obj; \ - ptr->tex_filt = (ptr->tex_filt&~0xff000000)|(_SHIFTL(_gxtexmode0ids[mapid],24,8)); \ - ptr->tex_lod = (ptr->tex_lod&~0xff000000)|(_SHIFTL(_gxtexmode1ids[mapid],24,8)); \ - ptr->tex_size = (ptr->tex_size&~0xff000000)|(_SHIFTL(_gxteximg0ids[mapid],24,8)); \ - ptr->tex_maddr = (ptr->tex_maddr&~0xff000000)|(_SHIFTL(_gxteximg3ids[mapid],24,8)); \ - GX_LOAD_BP_REG(ptr->tex_filt); \ - GX_LOAD_BP_REG(ptr->tex_lod); \ - GX_LOAD_BP_REG(ptr->tex_size); \ - GX_LOAD_BP_REG(ptr->tex_maddr); \ - __gx->texMapSize[mapid] = ptr->tex_size; \ - __gx->texMapWrap[mapid] = ptr->tex_filt; \ - __gx->dirtyState |= 0x0001; \ -} - -#define X_FACTOR 0.5 -#define Y_FACTOR 342.0 -#define ZFACTOR 16777215.0 - -static INLINE void __GX_SetViewportJitter(f32 xOrig,f32 yOrig,f32 wd,f32 ht,f32 nearZ,f32 farZ,u32 field) -{ - f32 x0,y0,x1,y1,n,f,z; - static f32 Xfactor = 0.5; - static f32 Yfactor = 342.0; - static f32 Zfactor = 16777215.0; - - if(!field) - yOrig -= Xfactor; - x0 = wd*Xfactor; - y0 = (-ht)*Xfactor; - x1 = (xOrig+(wd*Xfactor))+Yfactor; - y1 = (yOrig+(ht*Xfactor))+Yfactor; - n = Zfactor*nearZ; - f = Zfactor*farZ; - z = f-n; - GX_LOAD_XF_REGS(0x101a,6); - FIFO_PUTF32(x0); - FIFO_PUTF32(y0); - FIFO_PUTF32(z); - FIFO_PUTF32(x1); - FIFO_PUTF32(y1); - FIFO_PUTF32(f); -} - -#define __GX_Position1x8(index) FIFO_PUTU8(index) -#define __GX_TexCoord1x8(index) FIFO_PUTU8(index) -#define __GX_Color1x8(index) FIFO_PUTU8(index) diff --git a/gfx/drivers/gx_gfx_vi_encoder.c b/gfx/drivers/gx_gfx_vi_encoder.c index b3580ddd79..f1a0c0fd31 100644 --- a/gfx/drivers/gx_gfx_vi_encoder.c +++ b/gfx/drivers/gx_gfx_vi_encoder.c @@ -41,6 +41,7 @@ #include #include #include +#include #include diff --git a/gfx/drivers_context/ps3_ctx.c b/gfx/drivers_context/ps3_ctx.c index 4fa8ef3efb..1995de4096 100644 --- a/gfx/drivers_context/ps3_ctx.c +++ b/gfx/drivers_context/ps3_ctx.c @@ -303,9 +303,6 @@ static bool gfx_ctx_ps3_set_video_mode(void *data, if (!global) return false; - global->console.screen.resolutions.width = width; - global->console.screen.resolutions.height = height; - return true; } diff --git a/gfx/video_driver.c b/gfx/video_driver.c index 9328378080..12fbb39c79 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -1628,12 +1628,6 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) config_get_bool(conf, "soft_filter_enable", &global->console.softfilter_enable); - CONFIG_GET_INT_BASE(conf, global, - console.screen.resolutions.width, - "console_resolution_width"); - CONFIG_GET_INT_BASE(conf, global, - console.screen.resolutions.height, - "console_resolution_height"); CONFIG_GET_INT_BASE(conf, global, console.screen.soft_filter_index, "soft_filter_index"); @@ -1660,10 +1654,6 @@ bool video_driver_ctl(enum rarch_display_ctl_state state, void *data) config_set_bool(conf, "soft_filter_enable", global->console.softfilter_enable); - config_set_int(conf, "console_resolution_width", - global->console.screen.resolutions.width); - config_set_int(conf, "console_resolution_height", - global->console.screen.resolutions.height); config_set_int(conf, "soft_filter_index", global->console.screen.soft_filter_index); config_set_int(conf, "current_resolution_id", diff --git a/memory/wii/mem2_manager.c b/memory/wii/mem2_manager.c index b2d56b47d3..bb0deaa123 100644 --- a/memory/wii/mem2_manager.c +++ b/memory/wii/mem2_manager.c @@ -9,7 +9,6 @@ #include #include "mem2_manager.h" -#include "../../defines/gx_defines.h" /* Forbid the use of MEM2 through malloc */ uint32_t MALLOC_MEM2 = 0; diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 6454f72b88..9b074ba0d6 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -680,13 +680,17 @@ static void menu_action_setting_disp_set_label_menu_video_resolution( *w = 19; *s = '\0'; - (void)width; - (void)height; - strlcpy(s2, path, len2); if (video_driver_get_video_output_size(&width, &height)) - snprintf(s, len, "%ux%u", width, height); + { +#ifdef GEKKO + if (width == 0 || height == 0) + strlcpy(s, "DEFAULT", len); + else +#endif + snprintf(s, len, "%ux%u", width, height); + } else strlcpy(s, menu_hash_to_str(MENU_VALUE_NOT_AVAILABLE), len); } diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 08b5533fb8..1a01ca8098 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -2139,7 +2139,12 @@ static int action_ok_video_resolution(const char *path, event_cmd_ctl(EVENT_CMD_REINIT, NULL); #endif video_driver_set_video_mode(width, height, true); - snprintf(msg, sizeof(msg),"Applying: %dx%d\n START to reset", +#ifdef GEKKO + if (width == 0 || height == 0) + strlcpy(msg, "Applying: DEFAULT", sizeof(msg)); + else +#endif + snprintf(msg, sizeof(msg),"Applying: %dx%d\n START to reset", width, height); runloop_msg_queue_push(msg, 1, 100, true); } diff --git a/menu/cbs/menu_cbs_start.c b/menu/cbs/menu_cbs_start.c index a3dab0b999..bc6d4e38d7 100644 --- a/menu/cbs/menu_cbs_start.c +++ b/menu/cbs/menu_cbs_start.c @@ -292,14 +292,18 @@ static int action_start_playlist_association(unsigned type, const char *label) static int action_start_video_resolution(unsigned type, const char *label) { unsigned width = 0, height = 0; + global_t *global = global_get_ptr(); - video_driver_set_video_mode(640, 480, true); + /* Reset the resolution id to zero */ + global->console.screen.resolutions.current.id = 0; if (video_driver_get_video_output_size(&width, &height)) { - char msg[PATH_MAX_LENGTH]; + char msg[PATH_MAX_LENGTH] = {0}; - snprintf(msg, sizeof(msg),"Resetting to: %dx%d", width, height); + video_driver_set_video_mode(width, height, true); + + strlcpy(msg, "Resetting to: DEFAULT", sizeof(msg)); runloop_msg_queue_push(msg, 1, 100, true); } diff --git a/performance.c b/performance.c index 79b6b15c44..10ab6a57f9 100644 --- a/performance.c +++ b/performance.c @@ -36,7 +36,7 @@ #include #endif -#if defined(__CELLOS_LV2__) || defined(GEKKO) +#if defined(__CELLOS_LV2__) #ifndef _PPU_INTRINSICS_H #include #endif @@ -221,8 +221,10 @@ retro_perf_tick_t retro_get_perf_counter(void) #elif defined(__ARM_ARCH_6__) __asm__ volatile( "mrc p15, 0, %0, c9, c13, 0" : "=r"(time_ticks) ); -#elif defined(__CELLOS_LV2__) || defined(GEKKO) || defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) +#elif defined(__CELLOS_LV2__) || defined(_XBOX360) || defined(__powerpc__) || defined(__ppc__) || defined(__POWERPC__) time_ticks = __mftb(); +#elif defined(GEKKO) + time_ticks = gettime(); #elif defined(PSP) || defined(VITA) sceRtcGetCurrentTick(&time_ticks); #elif defined(_3DS) diff --git a/runloop.h b/runloop.h index 4d9ada94d4..67bc5b8763 100644 --- a/runloop.h +++ b/runloop.h @@ -271,8 +271,6 @@ typedef struct global uint32_t *list; unsigned count; bool check; - unsigned width; - unsigned height; } resolutions; unsigned gamma_correction; diff --git a/string_list_special.c b/string_list_special.c index 58325a4947..220795dac5 100644 --- a/string_list_special.c +++ b/string_list_special.c @@ -209,7 +209,7 @@ error: const char *char_list_new_special(enum string_list_type type, void *data) { - unsigned len; + unsigned len = 0; size_t list_size; struct string_list *s = string_list_new_special(type, data, &len, &list_size); char *options = (len > 0) ? (char*)calloc(len, sizeof(char)): NULL;