From 7b2868c47b9e31b6fe895a3ec27419dc3ad0d6d9 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Mon, 8 Dec 2008 03:51:18 +0000 Subject: [PATCH] Move various things that should be in Mdec.h there, rework the defines in VUflags.c to functions, put in 64 bit versions of the Interlocked functions I previously #if 0ed, some cleaning, and, not least, make it so Linux compiles after r399. git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@400 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/Linux/GtkGui.cpp | 2 + pcsx2/Mdec.c | 112 ++++------------------------------------- pcsx2/Mdec.h | 79 +++++++++++++++++++++++++++++ pcsx2/Misc.h | 22 ++++++-- pcsx2/PsxInterpreter.c | 4 +- pcsx2/VU0.c | 91 +++++++++++++++++++-------------- pcsx2/VUflags.c | 105 ++++++++++++++++++++++++-------------- pcsx2/VUflags.h | 17 ++++--- pcsx2/VUops.h | 10 ++++ 9 files changed, 250 insertions(+), 192 deletions(-) diff --git a/pcsx2/Linux/GtkGui.cpp b/pcsx2/Linux/GtkGui.cpp index 9dce5eff62..fc8cd457b1 100644 --- a/pcsx2/Linux/GtkGui.cpp +++ b/pcsx2/Linux/GtkGui.cpp @@ -17,6 +17,7 @@ */ #include "GtkGui.h" + void On_Dialog_Cancelled(GtkButton* button, gpointer user_data) { gtk_widget_destroy((GtkWidget*)gtk_widget_get_toplevel ((GtkWidget*)button)); gtk_widget_set_sensitive(MainWindow, TRUE); @@ -95,6 +96,7 @@ void OnDestroy(GtkObject *object, gpointer user_data) {} gboolean OnDelete(GtkWidget *widget, GdkEvent *event, gpointer user_data) { pcsx2_exit(); + return (FALSE); } int Pcsx2Configure() { if (!UseGui) return 0; diff --git a/pcsx2/Mdec.c b/pcsx2/Mdec.c index 4c7e6086d6..32001208ee 100644 --- a/pcsx2/Mdec.c +++ b/pcsx2/Mdec.c @@ -24,31 +24,16 @@ #include "PsxCommon.h" #include "Mdec.h" -#define FIXED - -#define CONST_BITS 8 -#define PASS1_BITS 2 - -#define FIX_1_082392200 (277) -#define FIX_1_414213562 (362) -#define FIX_1_847759065 (473) -#define FIX_2_613125930 (669) - -#define MULTIPLY(var,const) (DESCALE((var) * (const), CONST_BITS)) - -#define DEQUANTIZE(coef,quantval) (coef) - -#define DESCALE(x,n) ((x)>>(n)) -#define RANGE(n) (n) - -#define DCTSIZE 8 -#define DCTSIZE2 64 +int iq_y[DCTSIZE2],iq_uv[DCTSIZE2]; static void idct1(int *block) { - int val = RANGE(DESCALE(block[0], PASS1_BITS+3)); - int i; - for(i=0;i>16)*(bcr&0xffff); - if (cmd==0x60000000) { - } else if (cmd==0x40000001) { u8 *p = (u8*)PSXM(adr); iqtab_init(iq_y,p); iqtab_init(iq_uv,p+64); - } else - if ((cmd&0xf5ff0000)==0x30000000) { + } + else if ((cmd&0xf5ff0000)==0x30000000) { mdec.rl = (u16*)PSXM(adr); } - else { - } HW_DMA0_CHCR &= ~0x01000000; psxDmaInterrupt(0); @@ -260,7 +219,7 @@ void psxDma1(u32 adr, u32 bcr, u32 chcr) { if (chcr!=0x01000200) return; size = (bcr>>16)*(bcr&0xffff); - image = (u16*)PSXM(adr); + image = (u16*)PSXM(adr); if (mdec.command&0x08000000) { for (;size>0;size-=(16*16)/2,image+=(16*16)) { mdec.rl = rl2blk(blk,mdec.rl); @@ -277,10 +236,6 @@ void psxDma1(u32 adr, u32 bcr, u32 chcr) { psxDmaInterrupt(1); } - -#define RUNOF(a) ((a)>>10) -#define VALOF(a) (((int)(a)<<(32-10))>>(32-10)) - static int zscan[DCTSIZE2] = { 0 ,1 ,8 ,16,9 ,2 ,3 ,10, 17,24,32,25,18,11,4 ,5 , @@ -305,8 +260,6 @@ static int aanscales[DCTSIZE2] = { void iqtab_init(int *iqtab,unsigned char *iq_y) { -#define CONST_BITS14 14 -#define IFAST_SCALE_BITS 2 int i; for(i=0;i 63) break; blk[zscan[k]] = (VALOF(rl) * iqtab[k] * q_scale) / 8; // / 16; } -// blk[0] = (blk[0] * iq_t[0] * 8) / 16; -// for(int j=1;j<64;j++) -// blk[j] = blk[j] * iq_t[j] * q_scale; - - // idct + idct(blk,k+1); - blk+=DCTSIZE2; } return mdec_rl; } -#ifdef FIXED -#define MULR(a) ((((int)0x0000059B) * (a)) >> 10) -#define MULG(a) ((((int)0xFFFFFEA1) * (a)) >> 10) -#define MULG2(a) ((((int)0xFFFFFD25) * (a)) >> 10) -#define MULB(a) ((((int)0x00000716) * (a)) >> 10) -#else -#define MULR(a) ((int)((float)1.40200 * (a))) -#define MULG(a) ((int)((float)-0.3437 * (a))) -#define MULG2(a) ((int)((float)-0.7143 * (a))) -#define MULB(a) ((int)((float)1.77200 * (a))) -#endif - -#define MAKERGB15(r,g,b) ( (((r)>>3)<<10)|(((g)>>3)<<5)|((b)>>3) ) -#define ROUND(c) roundtbl[((c)+128+256)]//&0x3ff] -/*#define ROUND(c) round(c+128) -int round(int r) { - if (r<0) return 0; - if (r>255) return 255; - return r; -}*/ - -#define RGB15(n, Y) \ - image[n] = MAKERGB15(ROUND(Y + R),ROUND(Y + G),ROUND(Y + B)); - -#define RGB15BW(n, Y) \ - image[n] = MAKERGB15(ROUND(Y),ROUND(Y),ROUND(Y)); - -#define RGB24(n, Y) \ - image[n+2] = ROUND(Y + R); \ - image[n+1] = ROUND(Y + G); \ - image[n+0] = ROUND(Y + B); - -#define RGB24BW(n, Y) \ - image[n+2] = ROUND(Y); \ - image[n+1] = ROUND(Y); \ - image[n+0] = ROUND(Y); - unsigned char roundtbl[256*3]; void round_init(void) { diff --git a/pcsx2/Mdec.h b/pcsx2/Mdec.h index d2e1002f5a..e54dae3a9e 100644 --- a/pcsx2/Mdec.h +++ b/pcsx2/Mdec.h @@ -19,6 +19,72 @@ #ifndef __MDEC_H__ #define __MDEC_H__ + +// mdec status: +#define MDEC_BUSY 0x20000000 +#define MDEC_DREQ 0x18000000 +#define MDEC_FIFO 0xc0000000 +#define MDEC_RGB24 0x02000000 +#define MDEC_STP 0x00800000 + + +#define CONST_BITS 8 +#define PASS1_BITS 2 +#define CONST_BITS14 14 +#define IFAST_SCALE_BITS 2 + +#define FIX_1_082392200 (277) +#define FIX_1_414213562 (362) +#define FIX_1_847759065 (473) +#define FIX_2_613125930 (669) + +#define MULTIPLY(var,const) (DESCALE((var) * (const), CONST_BITS)) + +#define DEQUANTIZE(coef,quantval) (coef) + +#define DESCALE(x,n) ((x)>>(n)) +#define RANGE(n) (n) + +#define DCTSIZE 8 +#define DCTSIZE2 64 + +#define RUNOF(a) ((a)>>10) +#define VALOF(a) (((int)(a)<<(32-10))>>(32-10)) +#define NOP 0xfe00 + +#define FIXED + +#ifdef FIXED +#define MULR(a) ((((int)0x0000059B) * (a)) >> 10) +#define MULG(a) ((((int)0xFFFFFEA1) * (a)) >> 10) +#define MULG2(a) ((((int)0xFFFFFD25) * (a)) >> 10) +#define MULB(a) ((((int)0x00000716) * (a)) >> 10) +#else +#define MULR(a) ((int)((float)1.40200 * (a))) +#define MULG(a) ((int)((float)-0.3437 * (a))) +#define MULG2(a) ((int)((float)-0.7143 * (a))) +#define MULB(a) ((int)((float)1.77200 * (a))) +#endif + +#define MAKERGB15(r,g,b) ( (((r)>>3)<<10)|(((g)>>3)<<5)|((b)>>3) ) +#define ROUND(c) roundtbl[((c)+128+256)]//&0x3ff] + +#define RGB15(n, Y) \ + image[n] = MAKERGB15(ROUND(Y + R),ROUND(Y + G),ROUND(Y + B)); + +#define RGB15BW(n, Y) \ + image[n] = MAKERGB15(ROUND(Y),ROUND(Y),ROUND(Y)); + +#define RGB24(n, Y) \ + image[n+2] = ROUND(Y + R); \ + image[n+1] = ROUND(Y + G); \ + image[n+0] = ROUND(Y + B); + +#define RGB24BW(n, Y) \ + image[n+2] = ROUND(Y); \ + image[n+1] = ROUND(Y); \ + image[n+0] = ROUND(Y); + void mdecInit(); void mdecWrite0(u32 data); void mdecWrite1(u32 data); @@ -28,4 +94,17 @@ void psxDma0(u32 madr, u32 bcr, u32 chcr); void psxDma1(u32 madr, u32 bcr, u32 chcr); int mdecFreeze(gzFile f, int Mode); +unsigned short* rl2blk(int *blk,unsigned short *mdec_rl); +void iqtab_init(int *iqtab,unsigned char *iq_y); +void round_init(void); +void yuv2rgb24(int *blk,unsigned char *image); +void yuv2rgb15(int *blk,unsigned short *image); + +struct { + unsigned long command; + unsigned long status; + unsigned short *rl; + int rlsize; +} mdec; + #endif /* __MDEC_H__ */ diff --git a/pcsx2/Misc.h b/pcsx2/Misc.h index 8e0878e434..f9e189111a 100644 --- a/pcsx2/Misc.h +++ b/pcsx2/Misc.h @@ -249,7 +249,7 @@ void * memcpy_amd_(void *dest, const void *src, size_t n); //#define memcpy_fast memcpy //Dont use normal memcpy, it has sse in 2k5! #else // for now disable linux fast memcpy -#define memcpy_fast memcpy_pcsx2 +#define memcpy_fast memcpy #endif #endif @@ -345,17 +345,24 @@ static __forceinline long InterlockedDecrement( long* Addend ) return InterlockedExchangeAdd( Addend, -1 ); } -#if 0 // These don't work, but are also never called. static __forceinline long InterlockedCompareExchange(volatile long *dest, long exch, long comp) { long old; +#ifdef __x86_64__ + __asm__ __volatile__ + ( + "lock; cmpxchgq %q2, %1" + : "=a" (old), "=m" (*dest) + : "r" (exch), "m" (*dest), "0" (comp)); +#else __asm__ __volatile__ ( "lock; cmpxchgl %2, %0" : "=m" (*dest), "=a" (old) : "r" (exch), "m" (*dest), "a" (comp) ); +#endif return(old); } @@ -368,17 +375,24 @@ static __forceinline long InterlockedCompareExchangePointer(PVOID volatile *dest // that matches the size of the pointer type, so no need to ifdef it like the std non-compare // exchange. +#ifdef __x86_64__ + __asm__ __volatile__ + ( + "lock; cmpxchgq %q2, %1" + : "=a" (old), "=m" (*dest) + : "r" (exch), "m" (*dest), "0" (comp) + ); +#else __asm__ __volatile__ ( "lock; cmpxchgl %2, %0" : "=m" (*dest), "=a" (old) : "r" (exch), "m" (*dest), "a" (comp) ); - +#endif return(old); } #endif -#endif extern void InitCPUTicks(); extern u64 GetTickFrequency(); diff --git a/pcsx2/PsxInterpreter.c b/pcsx2/PsxInterpreter.c index 4ae4d639c8..9c8f380e75 100644 --- a/pcsx2/PsxInterpreter.c +++ b/pcsx2/PsxInterpreter.c @@ -27,7 +27,7 @@ static int branch = 0; static int branch2 = 0; static u32 branchPC; -static void doBranch(tar); // forward declared prototype +static void doBranch(s32 tar); // forward declared prototype // Subsets extern void (*psxBSC[64])(); @@ -736,7 +736,7 @@ static __forceinline void execI() { } -static void doBranch(tar) { +static void doBranch(s32 tar) { branch2 = branch = 1; branchPC = tar; execI(); diff --git a/pcsx2/VU0.c b/pcsx2/VU0.c index e4ab6aa272..30bec2b8db 100644 --- a/pcsx2/VU0.c +++ b/pcsx2/VU0.c @@ -129,7 +129,7 @@ void QMTC2() { } if (_Fs_ == 0) return; VU0.VF[_Fs_].UD[0] = cpuRegs.GPR.r[_Rt_].UD[0]; - VU0.VF[_Fs_].UD[1] = cpuRegs.GPR.r[_Rt_].UD[1]; + VU0.VF[_Fs_].UD[1] = cpuRegs.GPR.r[_Rt_].UD[1]; } void CFC2() { @@ -175,9 +175,7 @@ void CTC2() { case REG_CMSAR1: // REG_CMSAR1 if (!(VU0.VI[REG_VPU_STAT].UL & 0x100) ) { VU1.VI[REG_TPC].UL = cpuRegs.GPR.r[_Rt_].US[0]; - //FreezeXMMRegs(1); vu1ExecMicro(VU1.VI[REG_TPC].UL); // Execute VU1 Micro SubRoutine - //FreezeXMMRegs(0); } break; default: @@ -189,8 +187,17 @@ void CTC2() { //--------------------------------------------------------------------------------------- -#define SYNCMSFLAGS() VU0.VI[REG_STATUS_FLAG].UL = VU0.statusflag; VU0.VI[REG_MAC_FLAG].UL = VU0.macflag; -#define SYNCFDIV() VU0.VI[REG_Q].UL = VU0.q.UL; VU0.VI[REG_STATUS_FLAG].UL = VU0.statusflag; +__forceinline void SYNCMSFLAGS() +{ + VU0.VI[REG_STATUS_FLAG].UL = VU0.statusflag; + VU0.VI[REG_MAC_FLAG].UL = VU0.macflag; +} + +__forceinline void SYNCFDIV() +{ + VU0.VI[REG_Q].UL = VU0.q.UL; + VU0.VI[REG_STATUS_FLAG].UL = VU0.statusflag; +} void VABS() { VU0.code = cpuRegs.code; _vuABS(&VU0); } void VADD() { VU0.code = cpuRegs.code; _vuADD(&VU0); SYNCMSFLAGS(); } @@ -331,25 +338,49 @@ void VFCSET() { VU0.code = cpuRegs.code; _vuFCSET(&VU0); } void VFCGET() { VU0.code = cpuRegs.code; _vuFCGET(&VU0); } void VXITOP() { VU0.code = cpuRegs.code; _vuXITOP(&VU0); } -#define CP2COND (/*(VU0.VI[REG_VPU_STAT].US[0] & 1) | */((VU0.VI[REG_VPU_STAT].US[0] >> 8) & 1)) +#define CP2COND (((VU0.VI[REG_VPU_STAT].US[0] >> 8) & 1)) -#define BC2(cond) \ - if (CP2COND cond) { \ - SysPrintf("VU0 Macro Branch \n"); \ - intDoBranch(_BranchTarget_); \ +void BC2F() +{ + if (CP2COND == 0) + { + SysPrintf("VU0 Macro Branch \n"); + intDoBranch(_BranchTarget_); } +} +void BC2T() +{ + if (CP2COND == 1) + { + SysPrintf("VU0 Macro Branch \n"); + intDoBranch(_BranchTarget_); + } +} -void BC2F() { BC2(== 0);} -void BC2T() { BC2(== 1);} - -#define BC2L(cond) \ - if (CP2COND cond) { \ - SysPrintf("VU0 Macro Branch \n"); \ - intDoBranch(_BranchTarget_); \ - } else cpuRegs.pc+= 4; - -void BC2FL() { BC2L(== 0);} -void BC2TL() { BC2L(== 1);} +void BC2FL() +{ + if (CP2COND == 0) + { + SysPrintf("VU0 Macro Branch \n"); + intDoBranch(_BranchTarget_); + } + else + { + cpuRegs.pc+= 4; + } +} +void BC2TL() +{ + if (CP2COND == 1) + { + SysPrintf("VU0 Macro Branch \n"); + intDoBranch(_BranchTarget_); + } + else + { + cpuRegs.pc+= 4; + } +} void vu0Finish() { @@ -373,29 +404,11 @@ void vu0Finish() } void VCALLMS() { - //FreezeXMMRegs(1); - vu0Finish(); vu0ExecMicro(((cpuRegs.code >> 6) & 0x7FFF) * 8); - //FreezeXMMRegs(0); } void VCALLMSR() { - //FreezeXMMRegs(1); vu0Finish(); vu0ExecMicro(VU0.VI[REG_CMSAR0].US[0] * 8); - //FreezeXMMRegs(0); } - -#ifndef _MSC_VER - -/*u32* GET_VU_MEM(VURegs* VU, u32 addr) -{ - if( VU == g_pVU1 ) return (u32*)(VU1.Mem+(addr&0x3fff)); - - if( addr >= 0x4200 ) return &VU1.VI[(addr>>2)&0x1f].UL; - - return (u32*)(VU0.Mem+(addr&0x0fff)); -}*/ - -#endif diff --git a/pcsx2/VUflags.c b/pcsx2/VUflags.c index 03fac856d2..8bac9b30f5 100644 --- a/pcsx2/VUflags.c +++ b/pcsx2/VUflags.c @@ -43,47 +43,76 @@ __inline void vuUpdateDI(VURegs * VU) { // VU->statusflag|= (Flag_D | (VU0.VI[REG_STATUS_FLAG].US[0] >> 5)) << 11; } -#define VU_MAC_UPDATE(name, shift) \ -u32 name(VURegs * VU, float f) { \ - u32 v = *(u32*)&f; \ - int exp = (v >> 23) & 0xff; \ - u32 s = v & 0x80000000; \ - \ - if (s) VU->macflag |= 0x0010<macflag &= ~(0x0010<macflag = (VU->macflag & ~(0x1100<macflag = (VU->macflag&~(0x1000<macflag = (VU->macflag&~(0x0100<macflag = (VU->macflag & ~(0x1101<> 23) & 0xff; + u32 s = v & 0x80000000; + + if (s) + VU->macflag |= 0x0010<macflag &= ~(0x0010<macflag = (VU->macflag & ~(0x1100<macflag = (VU->macflag&~(0x1000<macflag = (VU->macflag&~(0x0100<macflag = (VU->macflag & ~(0x1101<macflag&= ~(0x1111<macflag&= ~(0x1111<<3); +} + +__forceinline void VU_MACy_CLEAR(VURegs * VU) +{ + VU->macflag&= ~(0x1111<<2); +} + +__forceinline void VU_MACz_CLEAR(VURegs * VU) +{ + VU->macflag&= ~(0x1111<<1); +} + +__forceinline void VU_MACw_CLEAR(VURegs * VU) +{ + VU->macflag&= ~(0x1111<<0); +} void VU_STAT_UPDATE(VURegs * VU) { int newflag = 0 ; diff --git a/pcsx2/VUflags.h b/pcsx2/VUflags.h index 8a59f1d594..4ecc98d5ab 100644 --- a/pcsx2/VUflags.h +++ b/pcsx2/VUflags.h @@ -22,14 +22,15 @@ #include "VU.h" void vuUpdateDI(VURegs * VU); -u32 VU_MACx_UPDATE(VURegs * VU, float x); -u32 VU_MACy_UPDATE(VURegs * VU, float y); -u32 VU_MACz_UPDATE(VURegs * VU, float z); -u32 VU_MACw_UPDATE(VURegs * VU, float w); -void VU_MACx_CLEAR(VURegs * VU); -void VU_MACy_CLEAR(VURegs * VU); -void VU_MACz_CLEAR(VURegs * VU); -void VU_MACw_CLEAR(VURegs * VU); +__forceinline u32 VU_MAC_UPDATE( int shift, VURegs * VU, float f); +__forceinline u32 VU_MACx_UPDATE(VURegs * VU, float x); +__forceinline u32 VU_MACy_UPDATE(VURegs * VU, float y); +__forceinline u32 VU_MACz_UPDATE(VURegs * VU, float z); +__forceinline u32 VU_MACw_UPDATE(VURegs * VU, float w); +__forceinline void VU_MACx_CLEAR(VURegs * VU); +__forceinline void VU_MACy_CLEAR(VURegs * VU); +__forceinline void VU_MACz_CLEAR(VURegs * VU); +__forceinline void VU_MACw_CLEAR(VURegs * VU); void VU_STAT_UPDATE(VURegs * VU); diff --git a/pcsx2/VUops.h b/pcsx2/VUops.h index ba0a495105..b1f8cc0e55 100644 --- a/pcsx2/VUops.h +++ b/pcsx2/VUops.h @@ -25,6 +25,16 @@ #include "VU.h" +extern __forceinline u32 VU_MAC_UPDATE( int shift, VURegs * VU, float f); +extern __forceinline u32 VU_MACx_UPDATE(VURegs * VU, float x); +extern __forceinline u32 VU_MACy_UPDATE(VURegs * VU, float y); +extern __forceinline u32 VU_MACz_UPDATE(VURegs * VU, float z); +extern __forceinline u32 VU_MACw_UPDATE(VURegs * VU, float w); +extern __forceinline void VU_MACx_CLEAR(VURegs * VU); +extern __forceinline void VU_MACy_CLEAR(VURegs * VU); +extern __forceinline void VU_MACz_CLEAR(VURegs * VU); +extern __forceinline void VU_MACw_CLEAR(VURegs * VU); + #define float_to_int4(x) (s32)((float)x * (1.0f / 0.0625f)) #define float_to_int12(x) (s32)((float)x * (1.0f / 0.000244140625f)) #define float_to_int15(x) (s32)((float)x * (1.0f / 0.000030517578125))