From: Paul Cercueil Date: Sat, 21 May 2022 16:52:47 +0000 (+0100) Subject: dfxvideo: Restore support for big-endian arch X-Git-Tag: r24l~454^2~1 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=495d603c20ec58689bd7f73348d16e17f5491f5b;p=pcsx_rearmed.git dfxvideo: Restore support for big-endian arch The hardware registers, emulated RAM or emulated VRAM are all in little-endian format. Therefore, each access must be done with one of the byte-swap macros, for the plugin to work on big-endian systems. Signed-off-by: Paul Cercueil --- diff --git a/plugins/dfxvideo/gpu.c b/plugins/dfxvideo/gpu.c index 3d20dfa4..60dcaa47 100644 --- a/plugins/dfxvideo/gpu.c +++ b/plugins/dfxvideo/gpu.c @@ -985,7 +985,7 @@ ENDVRAM: if((gpuDataC==254 && gpuDataP>=3) || (gpuDataC==255 && gpuDataP>=4 && !(gpuDataP&1))) { - if((gpuDataM[gpuDataP] & 0xF000F000) == 0x50005000) + if((gpuDataM[gpuDataP] & HOST2LE32(0xF000F000)) == HOST2LE32(0x50005000)) gpuDataP=gpuDataC-1; } } diff --git a/plugins/dfxvideo/gpu.h b/plugins/dfxvideo/gpu.h index 25fcc3ce..7b5aaef0 100644 --- a/plugins/dfxvideo/gpu.h +++ b/plugins/dfxvideo/gpu.h @@ -69,8 +69,8 @@ // byteswappings -#define SWAP16(x) ({ uint16_t y=(x); (((y)>>8 & 0xff) | ((y)<<8 & 0xff00)); }) -#define SWAP32(x) ({ uint32_t y=(x); (((y)>>24 & 0xfful) | ((y)>>8 & 0xff00ul) | ((y)<<8 & 0xff0000ul) | ((y)<<24 & 0xff000000ul)); }) +#define SWAP16(x) __builtin_bswap16(x) +#define SWAP32(x) __builtin_bswap32(x) #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -107,7 +107,7 @@ #define GETLE32_(X) LE2HOST32(*(uint32_t *)X) #define GETLE16D(X) ({uint32_t val = GETLE32(X); (val<<16 | val >> 16);}) #define PUTLE16(X, Y) do{*((uint16_t *)X)=HOST2LE16((uint16_t)Y);}while(0) -#define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE16((uint32_t)Y);}while(0) +#define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE32((uint32_t)Y);}while(0) #ifdef __arm__ #define GETLE32(X) (*(uint16_t *)(X)|(((uint16_t *)(X))[1]<<16)) #define PUTLE32(X, Y) do{uint16_t *p_=(uint16_t *)(X);uint32_t y_=Y;p_[0]=y_;p_[1]=y_>>16;}while(0) diff --git a/plugins/dfxvideo/gpulib_if.c b/plugins/dfxvideo/gpulib_if.c index c1466ed8..c0066b5a 100644 --- a/plugins/dfxvideo/gpulib_if.c +++ b/plugins/dfxvideo/gpulib_if.c @@ -53,8 +53,8 @@ // byteswappings -#define SWAP16(x) ({ uint16_t y=(x); (((y)>>8 & 0xff) | ((y)<<8 & 0xff00)); }) -#define SWAP32(x) ({ uint32_t y=(x); (((y)>>24 & 0xfful) | ((y)>>8 & 0xff00ul) | ((y)<<8 & 0xff0000ul) | ((y)<<24 & 0xff000000ul)); }) +#define SWAP16(x) __builtin_bswap16(x) +#define SWAP32(x) __builtin_bswap32(x) #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ @@ -91,7 +91,7 @@ #define GETLE32_(X) LE2HOST32(*(uint32_t *)X) #define GETLE16D(X) ({uint32_t val = GETLE32(X); (val<<16 | val >> 16);}) #define PUTLE16(X, Y) do{*((uint16_t *)X)=HOST2LE16((uint16_t)Y);}while(0) -#define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE16((uint32_t)Y);}while(0) +#define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE32((uint32_t)Y);}while(0) #ifdef __arm__ #define GETLE32(X) (*(uint16_t *)(X)|(((uint16_t *)(X))[1]<<16)) #define PUTLE32(X, Y) do{uint16_t *p_=(uint16_t *)(X);uint32_t y_=Y;p_[0]=y_;p_[1]=y_>>16;}while(0) @@ -327,7 +327,7 @@ int do_cmd_list(uint32_t *list, int list_len, int *last_cmd) for (; list < list_end; list += 1 + len) { - cmd = *list >> 24; + cmd = GETLE32(list) >> 24; len = cmd_lengths[cmd]; if (list + 1 + len > list_end) { cmd = -1; @@ -338,7 +338,7 @@ int do_cmd_list(uint32_t *list, int list_len, int *last_cmd) if (cmd == 0xa0 || cmd == 0xc0) break; // image i/o, forward to upper layer else if ((cmd & 0xf8) == 0xe0) - gpu.ex_regs[cmd & 7] = list[0]; + gpu.ex_regs[cmd & 7] = GETLE32(list); #endif primTableJ[cmd]((void *)list); @@ -357,7 +357,7 @@ int do_cmd_list(uint32_t *list, int list_len, int *last_cmd) goto breakloop; } - if((*list_position & 0xf000f000) == 0x50005000) + if((*list_position & HOST2LE32(0xf000f000)) == HOST2LE32(0x50005000)) break; list_position++; @@ -380,7 +380,7 @@ int do_cmd_list(uint32_t *list, int list_len, int *last_cmd) goto breakloop; } - if((*list_position & 0xf000f000) == 0x50005000) + if((*list_position & HOST2LE32(0xf000f000)) == HOST2LE32(0x50005000)) break; list_position += 2; @@ -395,8 +395,8 @@ int do_cmd_list(uint32_t *list, int list_len, int *last_cmd) case 0xA0: // sys -> vid { short *slist = (void *)list; - u32 load_width = slist[4]; - u32 load_height = slist[5]; + u32 load_width = LE2HOST32(slist[4]); + u32 load_height = LE2HOST32(slist[5]); u32 load_size = load_width * load_height; len += load_size / 2; diff --git a/plugins/dfxvideo/prim.c b/plugins/dfxvideo/prim.c index 7a71d4c8..c872c284 100644 --- a/plugins/dfxvideo/prim.c +++ b/plugins/dfxvideo/prim.c @@ -1240,7 +1240,7 @@ static void primLineGEx(unsigned char *baseAddr) sly1=(short)(((int)sly1<>SIGNSHIFT); } - lc1 = gpuData[0] & 0xffffff; + lc1 = GETLE32(&gpuData[0]) & 0xffffff; DrawSemiTrans = (SEMITRANSBIT(GETLE32(&gpuData[0]))) ? TRUE : FALSE; diff --git a/plugins/dfxvideo/soft.c b/plugins/dfxvideo/soft.c index 1b22ed50..285500ea 100644 --- a/plugins/dfxvideo/soft.c +++ b/plugins/dfxvideo/soft.c @@ -292,7 +292,7 @@ static inline void GetShadeTransCol32(uint32_t * pdest,uint32_t color) { int32_t sr,sb,sg,src,sbc,sgc,c; src=XCOL1(color);sbc=XCOL2(color);sgc=XCOL3(color); - c=GETLE32(pdest)>>16; + c=HIWORD(GETLE32(pdest)); sr=(XCOL1(c))-src; if(sr&0x8000) sr=0; sb=(XCOL2(c))-sbc; if(sb&0x8000) sb=0; sg=(XCOL3(c))-sgc; if(sg&0x8000) sg=0; @@ -327,8 +327,8 @@ static inline void GetShadeTransCol32(uint32_t * pdest,uint32_t color) { uint32_t ma=GETLE32(pdest); PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask);//0x80008000; - if(ma&0x80000000) PUTLE32(pdest, (ma&0xFFFF0000)|(*pdest&0xFFFF)); - if(ma&0x00008000) PUTLE32(pdest, (ma&0xFFFF) |(*pdest&0xFFFF0000)); + if(ma&0x80000000) PUTLE32(pdest, (ma&0xFFFF0000)|(GETLE32(pdest)&0xFFFF)); + if(ma&0x00008000) PUTLE32(pdest, (ma&0xFFFF) |(GETLE32(pdest)&0xFFFF0000)); return; } PUTLE32(pdest, (X32PSXCOL(r,g,b))|lSetMask);//0x80008000; @@ -950,7 +950,7 @@ static void FillSoftwareAreaTrans(short x0,short y0,short x1, // FILL AREA TRANS { static int iCheat=0; col+=iCheat; - if(iCheat==1) iCheat=0; else iCheat=1; + iCheat ^= 1; } @@ -971,7 +971,7 @@ static void FillSoftwareAreaTrans(short x0,short y0,short x1, // FILL AREA TRANS { uint32_t *DSTPtr; unsigned short LineOffset; - uint32_t lcol=lSetMask|(((uint32_t)(col))<<16)|col; + uint32_t lcol = HOST2LE32(lSetMask | (((uint32_t)(col)) << 16) | col); dx>>=1; DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0); LineOffset = 512 - dx; @@ -980,7 +980,7 @@ static void FillSoftwareAreaTrans(short x0,short y0,short x1, // FILL AREA TRANS { for(i=0;i>=1; DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0); LineOffset = 512 - dx; for(i=0;i