From 9d98bfbe6b902fa97bd20aedae1653677aa945a6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 18 Nov 2015 12:55:28 +0100 Subject: [PATCH] (GX) Move defines to defines/gx_defines.h --- defines/gx_defines.h | 88 ++++++++++++++++++++++++++++++++ frontend/drivers/platform_wii.c | 2 +- gfx/drivers/gx_gfx.c | 2 - gfx/drivers/gx_gfx_inl.h | 69 ++++++++++++------------- gfx/drivers/gx_gfx_vi_encoder.c | 32 +++++------- gfx/drivers/ppc_asm.h | 89 --------------------------------- gfx/drivers/vg.c | 7 ++- memory/wii/mem2_manager.c | 2 +- 8 files changed, 140 insertions(+), 151 deletions(-) delete mode 100644 gfx/drivers/ppc_asm.h diff --git a/defines/gx_defines.h b/defines/gx_defines.h index 194b315c31..0349c577fd 100644 --- a/defines/gx_defines.h +++ b/defines/gx_defines.h @@ -1,8 +1,96 @@ #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 OSThread lwp_t #define OSCond lwpq_t #define OSThreadQueue lwpq_t diff --git a/frontend/drivers/platform_wii.c b/frontend/drivers/platform_wii.c index b42e5ede96..aeb1fc54c7 100644 --- a/frontend/drivers/platform_wii.c +++ b/frontend/drivers/platform_wii.c @@ -30,7 +30,7 @@ #include #include -#include "../../gfx/drivers/ppc_asm.h" +#include "../../defines/gx_defines.h" #define EXECUTE_ADDR ((uint8_t *) 0x91800000) #define BOOTER_ADDR ((uint8_t *) 0x93000000) diff --git a/gfx/drivers/gx_gfx.c b/gfx/drivers/gx_gfx.c index 7c7e78f05f..2b0a684080 100644 --- a/gfx/drivers/gx_gfx.c +++ b/gfx/drivers/gx_gfx.c @@ -35,9 +35,7 @@ #include "../../memory/wii/mem2_manager.h" #endif -#include "ppc_asm.h" #include "gx_gfx_inl.h" -#include "../../defines/gx_defines.h" struct gx_overlay_data { diff --git a/gfx/drivers/gx_gfx_inl.h b/gfx/drivers/gx_gfx_inl.h index a86f5097a3..8c6289813e 100644 --- a/gfx/drivers/gx_gfx_inl.h +++ b/gfx/drivers/gx_gfx_inl.h @@ -1,5 +1,7 @@ #include +#include "../../defines/gx_defines.h" + #define STRUCT_REGDEF_SIZE 1440 #define WGPIPE (0xCC008000) @@ -31,9 +33,6 @@ FIFO_PUTU8(0x10); \ FIFO_PUTU32((((((n) & 0xffff)-1)<<16)|((x) & 0xffff))) -#define _SHIFTL(v, s, w) ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) -#define _SHIFTR(v, s, w) ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) - extern u8 __gxregs[]; struct __gx_regdef @@ -361,11 +360,10 @@ static void __SETVCDATTR(struct __gx_regdef *__gx, u8 attr,u8 type) #ifdef HW_DOL static INLINE void __GX_UpdateBPMask(struct __gx_regdef *__gx) { - u32 i, nbmp, nres; + u32 i; u8 ntexmap; - - nbmp = _SHIFTR(__gx->genMode,16,3); - nres = 0; + u32 nbmp = _SHIFTR(__gx->genMode,16,3); + u32 nres = 0; for(i = 0; i < nbmp; i++) { @@ -426,11 +424,13 @@ static INLINE void __GX_SetTexCoordGen(struct __gx_regdef *__gx) GX_LOAD_XF_REG(0x103f,(__gx->genMode&0xf)); } - i = 0; + i = 0; texcoord = 0x1040; - mask = _SHIFTR(__gx->dirtyState,16,8); - while(mask) { - if(mask&0x0001) { + 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]); } @@ -442,16 +442,12 @@ static INLINE void __GX_SetTexCoordGen(struct __gx_regdef *__gx) static void __SetSURegs(struct __gx_regdef *__gx, u8 texmap,u8 texcoord) { - u32 reg; - u16 wd, ht; - u8 wrap_s,wrap_t; + 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); - wd = __gx->texMapSize[texmap] & 0x3ff; - ht = _SHIFTR(__gx->texMapSize[texmap],10,10); - wrap_s = __gx->texMapWrap[texmap] & 3; - wrap_t = _SHIFTR(__gx->texMapWrap[texmap],2,2); - - 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)); @@ -463,14 +459,13 @@ static void __SetSURegs(struct __gx_regdef *__gx, u8 texmap,u8 texcoord) static INLINE void __GX_SetSUTexRegs(struct __gx_regdef *__gx) { - u32 i, indtev, dirtev, tevreg, tevm, texcm; + u32 i, texcm; u8 texcoord, texmap; + u32 dirtev = (_SHIFTR(__gx->genMode,10,4))+1; + u32 indtev = _SHIFTR(__gx->genMode,16,3); - dirtev = (_SHIFTR(__gx->genMode,10,4))+1; - indtev = _SHIFTR(__gx->genMode,16,3); - - //indirect texture order - for(i = 0;i < indtev; i++) + /* Indirect texture order */ + for(i = 0; i < indtev; i++) { switch(i) { @@ -502,10 +497,11 @@ static INLINE void __GX_SetSUTexRegs(struct __gx_regdef *__gx) __SetSURegs(__gx, texmap,texcoord); } - //direct texture order + /* Direct texture order */ for(i = 0; i < dirtev; i++) { - tevreg = 3+(_SHIFTR(i,1,3)); + u32 tevm; + u32 tevreg = 3+(_SHIFTR(i,1,3)); texmap = (__gx->tevTexMap[i] & 0xff); if(i & 1) @@ -515,7 +511,7 @@ static INLINE void __GX_SetSUTexRegs(struct __gx_regdef *__gx) tevm = _SHIFTL(1,i,1); texcm = _SHIFTL(1,texcoord,1); - if(texmap!=0xff && (__gx->tevTexCoordEnable&tevm) && !(__gx->texCoordManually & texcm)) + if(texmap!=0xff && (__gx->tevTexCoordEnable & tevm) && !(__gx->texCoordManually & texcm)) { __SetSURegs(__gx, texmap,texcoord); } @@ -576,9 +572,8 @@ static void __GX_SetDirtyState(struct __gx_regdef *__gx) static void __GX_SendFlushPrim(struct __gx_regdef *__gx) { - u32 tmp,tmp2,cnt; - - tmp = (__gx->xfFlush*__gx->xfFlushExp); + u32 tmp2,cnt; + u32 tmp = (__gx->xfFlush*__gx->xfFlushExp); FIFO_PUTU8(0x98); FIFO_PUTU16(__gx->xfFlush); @@ -755,14 +750,16 @@ static INLINE void __GX_SetViewportJitter(f32 xOrig,f32 yOrig,f32 wd,f32 ht,f32 static f32 Xfactor = 0.5; static f32 Yfactor = 342.0; static f32 Zfactor = 16777215.0; - if(!field) yOrig -= Xfactor; + + 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; + n = Zfactor*nearZ; + f = Zfactor*farZ; + z = f-n; GX_LOAD_XF_REGS(0x101a,6); FIFO_PUTF32(x0); FIFO_PUTF32(y0); diff --git a/gfx/drivers/gx_gfx_vi_encoder.c b/gfx/drivers/gx_gfx_vi_encoder.c index 4f5d2968af..b3580ddd79 100644 --- a/gfx/drivers/gx_gfx_vi_encoder.c +++ b/gfx/drivers/gx_gfx_vi_encoder.c @@ -44,19 +44,9 @@ #include -#include "../../gfx/drivers/ppc_asm.h" +#include "../../defines/gx_defines.h" -/**************************************************************************** - * I2C driver by Hector Martin (marcan) - * - ****************************************************************************/ - -#define _SHIFTL(v, s, w) \ - ((u32) (((u32)(v) & ((0x01 << (w)) - 1)) << (s))) -#define _SHIFTR(v, s, w) \ - ((u32)(((u32)(v) >> (s)) & ((0x01 << (w)) - 1))) - -extern void udelay(int us); +void udelay(int us); static u32 i2cIdentFirst = 0; static u32 i2cIdentFlag = 1; @@ -111,7 +101,7 @@ static u32 __sendSlaveAddress(u8 addr) __viSetSCL(1); udelay(2); - if(i2cIdentFlag==1 && __viGetSDA()!=0) + if ((i2cIdentFlag == 1) && __viGetSDA()!=0) return 0; __viSetSDA(i2cIdentFlag^1); @@ -134,12 +124,12 @@ void VIDEO_SetTrapFilter(bool enable) u8 addr = 0xe0; u32 len = 2; - buf[0] = reg; - buf[1] = data; + buf[0] = reg; + buf[1] = data; - val = buf; + val = buf; - if(i2cIdentFirst==0) + if(i2cIdentFirst == 0) { __viOpenI2C(0); udelay(4); @@ -160,7 +150,9 @@ void VIDEO_SetTrapFilter(bool enable) udelay(4); ret = __sendSlaveAddress(addr); - if(ret==0) { + + if(ret == 0) + { _CPU_ISR_Restore(level); goto end; } @@ -172,7 +164,7 @@ void VIDEO_SetTrapFilter(bool enable) for(j=0;j<8;j++) { u32 chan = i2cIdentFlag; - if(c&0x80) {} + if(c & 0x80) {} else chan ^= 1; @@ -190,7 +182,7 @@ void VIDEO_SetTrapFilter(bool enable) __viSetSCL(1); udelay(2); - if(i2cIdentFlag==1 && __viGetSDA()!=0) + if((i2cIdentFlag == 1) && __viGetSDA()!=0) { _CPU_ISR_Restore(level); goto end; diff --git a/gfx/drivers/ppc_asm.h b/gfx/drivers/ppc_asm.h deleted file mode 100644 index 18cd5bf4f3..0000000000 --- a/gfx/drivers/ppc_asm.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef __PPC_ASM_H -#define __PPC_ASM_H - -#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 - -extern void __lwp_thread_stopmultitasking(void (*exitfunc)()); - -#endif diff --git a/gfx/drivers/vg.c b/gfx/drivers/vg.c index 694ac737e3..58a1498d3c 100644 --- a/gfx/drivers/vg.c +++ b/gfx/drivers/vg.c @@ -15,13 +15,16 @@ */ #include + #include #include #include #include -#include "../video_context_driver.h" -#include + #include +#include + +#include "../video_context_driver.h" #include "../../libretro.h" #include "../../general.h" #include "../../retroarch.h" diff --git a/memory/wii/mem2_manager.c b/memory/wii/mem2_manager.c index be8b7d4c84..b2d56b47d3 100644 --- a/memory/wii/mem2_manager.c +++ b/memory/wii/mem2_manager.c @@ -9,7 +9,7 @@ #include #include "mem2_manager.h" -#include "../../gfx/drivers/ppc_asm.h" +#include "../../defines/gx_defines.h" /* Forbid the use of MEM2 through malloc */ uint32_t MALLOC_MEM2 = 0;