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
This commit is contained in:
arcum42 2008-12-08 03:51:18 +00:00 committed by Gregory Hainaut
parent f7fc484e58
commit 7b2868c47b
9 changed files with 250 additions and 192 deletions

View File

@ -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;

View File

@ -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<DCTSIZE2;i++) block[i]=val;
int i, val;
val = RANGE(DESCALE(block[0], PASS1_BITS+3));
for(i=0;i<DCTSIZE2;i++)
block[i]=val;
}
void idct(int *block,int k)
@ -162,21 +147,6 @@ void idct(int *block,int k)
}
}
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;
int iq_y[DCTSIZE2],iq_uv[DCTSIZE2];
void mdecInit(void) {
mdec.rl = (u16*)&psxM[0x100000];
mdec.command = 0;
@ -209,13 +179,6 @@ u32 mdecRead0(void) {
return mdec.command;
}
// mdec status:
#define MDEC_BUSY 0x20000000
#define MDEC_DREQ 0x18000000
#define MDEC_FIFO 0xc0000000
#define MDEC_RGB24 0x02000000
#define MDEC_STP 0x00800000
u32 mdecRead1(void) {
#ifdef CDR_LOG
CDR_LOG("mdec1 read %lx\n", mdec.status);
@ -233,17 +196,13 @@ void psxDma0(u32 adr, u32 bcr, u32 chcr) {
size = (bcr>>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) {
mdec.rl = (u16*)PSXM(adr);
}
else {
else if ((cmd&0xf5ff0000)==0x30000000) {
mdec.rl = (u16*)PSXM(adr);
}
HW_DMA0_CHCR &= ~0x01000000;
@ -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<DCTSIZE2;i++) {
@ -314,7 +267,6 @@ void iqtab_init(int *iqtab,unsigned char *iq_y)
}
}
#define NOP 0xfe00
unsigned short* rl2blk(int *blk,unsigned short *mdec_rl) {
int i,k,q_scale,rl;
int *iqtab;
@ -335,55 +287,13 @@ unsigned short* rl2blk(int *blk,unsigned short *mdec_rl) {
if (k > 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) {

View File

@ -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__ */

View File

@ -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();

View File

@ -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();

View File

@ -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

View File

@ -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<<shift; \
else VU->macflag &= ~(0x0010<<shift); \
\
if( f == 0 ) { \
VU->macflag = (VU->macflag & ~(0x1100<<shift)) | (0x0001<<shift); \
return v; \
} \
\
switch(exp) { \
case 0: \
VU->macflag = (VU->macflag&~(0x1000<<shift)) | (0x0101<<shift); \
return s; \
case 255: \
VU->macflag = (VU->macflag&~(0x0100<<shift)) | (0x1000<<shift); \
return s|0x7f7fffff; /* max allowed */ \
default: \
VU->macflag = (VU->macflag & ~(0x1101<<shift)); \
return v; \
} \
} \
__forceinline u32 VU_MAC_UPDATE( int shift, VURegs * VU, float f)
{
u32 v = *(u32*)&f;
int exp = (v >> 23) & 0xff;
u32 s = v & 0x80000000;
VU_MAC_UPDATE(VU_MACx_UPDATE, 3);
VU_MAC_UPDATE(VU_MACy_UPDATE, 2);
VU_MAC_UPDATE(VU_MACz_UPDATE, 1);
VU_MAC_UPDATE(VU_MACw_UPDATE, 0);
if (s)
VU->macflag |= 0x0010<<shift;
else
VU->macflag &= ~(0x0010<<shift);
#define VU_MAC_CLEAR(name, shift) \
void name(VURegs * VU) { \
VU->macflag&= ~(0x1111<<shift); \
} \
if( f == 0 )
{
VU->macflag = (VU->macflag & ~(0x1100<<shift)) | (0x0001<<shift);
return v;
}
VU_MAC_CLEAR(VU_MACx_CLEAR, 3);
VU_MAC_CLEAR(VU_MACy_CLEAR, 2);
VU_MAC_CLEAR(VU_MACz_CLEAR, 1);
VU_MAC_CLEAR(VU_MACw_CLEAR, 0);
switch(exp)
{
case 0:
VU->macflag = (VU->macflag&~(0x1000<<shift)) | (0x0101<<shift);
return s;
case 255:
VU->macflag = (VU->macflag&~(0x0100<<shift)) | (0x1000<<shift);
return s|0x7f7fffff; /* max allowed */
default:
VU->macflag = (VU->macflag & ~(0x1101<<shift));
return v;
}
}
__forceinline u32 VU_MACx_UPDATE(VURegs * VU, float x)
{
return VU_MAC_UPDATE(3, VU, x);
}
__forceinline u32 VU_MACy_UPDATE(VURegs * VU, float y)
{
return VU_MAC_UPDATE(2, VU, y);
}
__forceinline u32 VU_MACz_UPDATE(VURegs * VU, float z)
{
return VU_MAC_UPDATE(1, VU, z);
}
__forceinline u32 VU_MACw_UPDATE(VURegs * VU, float w)
{
return VU_MAC_UPDATE(0, VU, w);
}
__forceinline void VU_MACx_CLEAR(VURegs * VU)
{
VU->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 ;

View File

@ -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);

View File

@ -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))