From e223fa15d18a141a26d73683d036d130cc5c6e8d Mon Sep 17 00:00:00 2001 From: notaz Date: Wed, 1 Nov 2023 18:56:36 +0200 Subject: [PATCH] gpu_unai: sync with libretro --- Makefile | 2 +- plugins/gpu_unai/Makefile | 2 +- plugins/gpu_unai/gpu.cpp | 418 ++++++++-------- plugins/gpu_unai/gpu.h | 10 +- plugins/gpu_unai/gpu_arm.h | 2 +- plugins/gpu_unai/gpu_command.h | 302 ++++++------ plugins/gpu_unai/gpu_inner.h | 177 +++---- plugins/gpu_unai/gpu_inner_light.h | 14 +- plugins/gpu_unai/gpu_inner_light_arm.h | 4 +- plugins/gpu_unai/gpu_inner_quantization.h | 8 +- plugins/gpu_unai/gpu_raster_image.h | 94 ++-- plugins/gpu_unai/gpu_raster_line.h | 58 +-- plugins/gpu_unai/gpu_raster_polygon.h | 122 ++--- plugins/gpu_unai/gpu_raster_sprite.h | 68 +-- .../gpu_unai/{gpu_senquack.h => gpu_unai.h} | 105 ++-- plugins/gpu_unai/gpulib_if.cpp | 465 ++++++++++++------ plugins/gpulib/gpu.h | 4 + 17 files changed, 1054 insertions(+), 801 deletions(-) rename plugins/gpu_unai/{gpu_senquack.h => gpu_unai.h} (84%) diff --git a/Makefile b/Makefile index 8cbf5c66..af3e1ab6 100644 --- a/Makefile +++ b/Makefile @@ -156,7 +156,7 @@ OBJS += plugins/gpu_unai/gpulib_if.o ifeq "$(ARCH)" "arm" OBJS += plugins/gpu_unai/gpu_arm.o endif -plugins/gpu_unai/gpulib_if.o: CFLAGS += -DREARMED -O3 +plugins/gpu_unai/gpulib_if.o: CFLAGS += -DREARMED -DUSE_GPULIB=1 -O3 CC_LINK = $(CXX) endif diff --git a/plugins/gpu_unai/Makefile b/plugins/gpu_unai/Makefile index 12c688e9..756d19aa 100644 --- a/plugins/gpu_unai/Makefile +++ b/plugins/gpu_unai/Makefile @@ -3,7 +3,7 @@ CFLAGS += -DREARMED CFLAGS += -I../../include #CFLAGS += -DINLINE="static __inline__" #CFLAGS += -Dasm="__asm__ __volatile__" -#CFLAGS += -DUSE_GPULIB=1 +CFLAGS += -DUSE_GPULIB=1 include ../../config.mak diff --git a/plugins/gpu_unai/gpu.cpp b/plugins/gpu_unai/gpu.cpp index 5f2929fc..c3f70954 100644 --- a/plugins/gpu_unai/gpu.cpp +++ b/plugins/gpu_unai/gpu.cpp @@ -23,7 +23,7 @@ #include "plugins.h" #include "psxcommon.h" //#include "port.h" -#include "gpu_senquack.h" +#include "gpu_unai.h" #define VIDEO_WIDTH 320 @@ -33,7 +33,7 @@ #define TPS 1000000 #endif -#define IS_PAL (gpu_senquack.GPU_GP1&(0x08<<17)) +#define IS_PAL (gpu_unai.GPU_GP1&(0x08<<17)) //senquack - Original 512KB of guard space seems not to be enough, as Xenogears // accesses outside this range and crashes in town intro fight sequence. @@ -78,28 +78,28 @@ static u16 GPU_FrameBuffer[(FRAME_BUFFER_SIZE*2 + 4096)/2] __attribute__((aligne /////////////////////////////////////////////////////////////////////////////// static void gpuReset(void) { - memset((void*)&gpu_senquack, 0, sizeof(gpu_senquack)); - gpu_senquack.vram = (u16*)GPU_FrameBuffer + (4096/2); //4kb guard room in front - gpu_senquack.GPU_GP1 = 0x14802000; - gpu_senquack.DrawingArea[2] = 256; - gpu_senquack.DrawingArea[3] = 240; - gpu_senquack.DisplayArea[2] = 256; - gpu_senquack.DisplayArea[3] = 240; - gpu_senquack.DisplayArea[5] = 240; - gpu_senquack.TextureWindow[0] = 0; - gpu_senquack.TextureWindow[1] = 0; - gpu_senquack.TextureWindow[2] = 255; - gpu_senquack.TextureWindow[3] = 255; + memset((void*)&gpu_unai, 0, sizeof(gpu_unai)); + gpu_unai.vram = (u16*)GPU_FrameBuffer + (4096/2); //4kb guard room in front + gpu_unai.GPU_GP1 = 0x14802000; + gpu_unai.DrawingArea[2] = 256; + gpu_unai.DrawingArea[3] = 240; + gpu_unai.DisplayArea[2] = 256; + gpu_unai.DisplayArea[3] = 240; + gpu_unai.DisplayArea[5] = 240; + gpu_unai.TextureWindow[0] = 0; + gpu_unai.TextureWindow[1] = 0; + gpu_unai.TextureWindow[2] = 255; + gpu_unai.TextureWindow[3] = 255; //senquack - new vars must be updated whenever texture window is changed: // (used for polygon-drawing in gpu_inner.h, gpu_raster_polygon.h) const u32 fb = FIXED_BITS; // # of fractional fixed-pt bits of u4/v4 - gpu_senquack.u_msk = (((u32)gpu_senquack.TextureWindow[2]) << fb) | ((1 << fb) - 1); - gpu_senquack.v_msk = (((u32)gpu_senquack.TextureWindow[3]) << fb) | ((1 << fb) - 1); + gpu_unai.u_msk = (((u32)gpu_unai.TextureWindow[2]) << fb) | ((1 << fb) - 1); + gpu_unai.v_msk = (((u32)gpu_unai.TextureWindow[3]) << fb) | ((1 << fb) - 1); // Configuration options - gpu_senquack.config = gpu_senquack_config_ext; - gpu_senquack.ilace_mask = gpu_senquack.config.ilace_force; - gpu_senquack.frameskip.skipCount = gpu_senquack.config.frameskip_count; + gpu_unai.config = gpu_unai_config_ext; + gpu_unai.ilace_mask = gpu_unai.config.ilace_force; + gpu_unai.frameskip.skipCount = gpu_unai.config.frameskip_count; SetupLightLUT(); SetupDitheringConstants(); @@ -118,8 +118,8 @@ long GPU_init(void) } #endif - gpu_senquack.fb_dirty = true; - gpu_senquack.dma.last_dma = NULL; + gpu_unai.fb_dirty = true; + gpu_unai.dma.last_dma = NULL; return (0); } @@ -137,27 +137,27 @@ long GPU_freeze(u32 bWrite, GPUFreeze_t* p2) if (bWrite) { - p2->ulStatus = gpu_senquack.GPU_GP1; + p2->ulStatus = gpu_unai.GPU_GP1; memset(p2->ulControl, 0, sizeof(p2->ulControl)); // save resolution and registers for P.E.Op.S. compatibility - p2->ulControl[3] = (3 << 24) | ((gpu_senquack.GPU_GP1 >> 23) & 1); - p2->ulControl[4] = (4 << 24) | ((gpu_senquack.GPU_GP1 >> 29) & 3); - p2->ulControl[5] = (5 << 24) | (gpu_senquack.DisplayArea[0] | (gpu_senquack.DisplayArea[1] << 10)); + p2->ulControl[3] = (3 << 24) | ((gpu_unai.GPU_GP1 >> 23) & 1); + p2->ulControl[4] = (4 << 24) | ((gpu_unai.GPU_GP1 >> 29) & 3); + p2->ulControl[5] = (5 << 24) | (gpu_unai.DisplayArea[0] | (gpu_unai.DisplayArea[1] << 10)); p2->ulControl[6] = (6 << 24) | (2560 << 12); - p2->ulControl[7] = (7 << 24) | (gpu_senquack.DisplayArea[4] | (gpu_senquack.DisplayArea[5] << 10)); - p2->ulControl[8] = (8 << 24) | ((gpu_senquack.GPU_GP1 >> 17) & 0x3f) | ((gpu_senquack.GPU_GP1 >> 10) & 0x40); - memcpy((void*)p2->psxVRam, (void*)gpu_senquack.vram, FRAME_BUFFER_SIZE); + p2->ulControl[7] = (7 << 24) | (gpu_unai.DisplayArea[4] | (gpu_unai.DisplayArea[5] << 10)); + p2->ulControl[8] = (8 << 24) | ((gpu_unai.GPU_GP1 >> 17) & 0x3f) | ((gpu_unai.GPU_GP1 >> 10) & 0x40); + memcpy((void*)p2->psxVRam, (void*)gpu_unai.vram, FRAME_BUFFER_SIZE); return (1); } else { extern void GPU_writeStatus(u32 data); - gpu_senquack.GPU_GP1 = p2->ulStatus; - memcpy((void*)gpu_senquack.vram, (void*)p2->psxVRam, FRAME_BUFFER_SIZE); + gpu_unai.GPU_GP1 = p2->ulStatus; + memcpy((void*)gpu_unai.vram, (void*)p2->psxVRam, FRAME_BUFFER_SIZE); GPU_writeStatus((5 << 24) | p2->ulControl[5]); GPU_writeStatus((7 << 24) | p2->ulControl[7]); GPU_writeStatus((8 << 24) | p2->ulControl[8]); - gpuSetTexture(gpu_senquack.GPU_GP1); + gpuSetTexture(gpu_unai.GPU_GP1); return (1); } return (0); @@ -190,24 +190,24 @@ u8 PacketSize[256] = /////////////////////////////////////////////////////////////////////////////// INLINE void gpuSendPacket() { - gpuSendPacketFunction(gpu_senquack.PacketBuffer.U4[0]>>24); + gpuSendPacketFunction(gpu_unai.PacketBuffer.U4[0]>>24); } /////////////////////////////////////////////////////////////////////////////// INLINE void gpuCheckPacket(u32 uData) { - if (gpu_senquack.PacketCount) + if (gpu_unai.PacketCount) { - gpu_senquack.PacketBuffer.U4[gpu_senquack.PacketIndex++] = uData; - --gpu_senquack.PacketCount; + gpu_unai.PacketBuffer.U4[gpu_unai.PacketIndex++] = uData; + --gpu_unai.PacketCount; } else { - gpu_senquack.PacketBuffer.U4[0] = uData; - gpu_senquack.PacketCount = PacketSize[uData >> 24]; - gpu_senquack.PacketIndex = 1; + gpu_unai.PacketBuffer.U4[0] = uData; + gpu_unai.PacketCount = PacketSize[uData >> 24]; + gpu_unai.PacketIndex = 1; } - if (!gpu_senquack.PacketCount) gpuSendPacket(); + if (!gpu_unai.PacketCount) gpuSendPacket(); } /////////////////////////////////////////////////////////////////////////////// @@ -217,42 +217,42 @@ void GPU_writeDataMem(u32* dmaAddress, int dmaCount) fprintf(stdout,"GPU_writeDataMem(%d)\n",dmaCount); #endif u32 data; - const u16 *VIDEO_END = (u16*)gpu_senquack.vram+(FRAME_BUFFER_SIZE/2)-1; - gpu_senquack.GPU_GP1 &= ~0x14000000; + const u16 *VIDEO_END = (u16*)gpu_unai.vram+(FRAME_BUFFER_SIZE/2)-1; + gpu_unai.GPU_GP1 &= ~0x14000000; while (dmaCount) { - if (gpu_senquack.dma.FrameToWrite) + if (gpu_unai.dma.FrameToWrite) { while (dmaCount) { dmaCount--; data = *dmaAddress++; - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; - gpu_senquack.dma.pvram[gpu_senquack.dma.px] = data; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; + gpu_unai.dma.pvram[gpu_unai.dma.px] = data; + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; - if (++gpu_senquack.dma.py >= gpu_senquack.dma.y_end) + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; + if (++gpu_unai.dma.py >= gpu_unai.dma.y_end) { - gpu_senquack.dma.FrameToWrite = false; - gpu_senquack.GPU_GP1 &= ~0x08000000; - gpu_senquack.fb_dirty = true; + gpu_unai.dma.FrameToWrite = false; + gpu_unai.GPU_GP1 &= ~0x08000000; + gpu_unai.fb_dirty = true; break; } } - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; - gpu_senquack.dma.pvram[gpu_senquack.dma.px] = data>>16; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; + gpu_unai.dma.pvram[gpu_unai.dma.px] = data>>16; + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; - if (++gpu_senquack.dma.py >= gpu_senquack.dma.y_end) + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; + if (++gpu_unai.dma.py >= gpu_unai.dma.y_end) { - gpu_senquack.dma.FrameToWrite = false; - gpu_senquack.GPU_GP1 &= ~0x08000000; - gpu_senquack.fb_dirty = true; + gpu_unai.dma.FrameToWrite = false; + gpu_unai.GPU_GP1 &= ~0x08000000; + gpu_unai.fb_dirty = true; break; } } @@ -266,7 +266,7 @@ void GPU_writeDataMem(u32* dmaAddress, int dmaCount) } } - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 | 0x14000000) & ~0x60000000; + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 | 0x14000000) & ~0x60000000; } long GPU_dmaChain(u32 *rambase, u32 start_addr) @@ -279,9 +279,9 @@ long GPU_dmaChain(u32 *rambase, u32 start_addr) u32 len, count; long dma_words = 0; - if (gpu_senquack.dma.last_dma) *gpu_senquack.dma.last_dma |= 0x800000; + if (gpu_unai.dma.last_dma) *gpu_unai.dma.last_dma |= 0x800000; - gpu_senquack.GPU_GP1 &= ~0x14000000; + gpu_unai.GPU_GP1 &= ~0x14000000; addr = start_addr & 0xffffff; for (count = 0; addr != 0xffffff; count++) @@ -315,10 +315,10 @@ long GPU_dmaChain(u32 *rambase, u32 start_addr) list[0] &= ~0x800000; } - if (gpu_senquack.dma.last_dma) *gpu_senquack.dma.last_dma &= ~0x800000; - gpu_senquack.dma.last_dma = rambase + (start_addr & 0x1fffff) / 4; + if (gpu_unai.dma.last_dma) *gpu_unai.dma.last_dma &= ~0x800000; + gpu_unai.dma.last_dma = rambase + (start_addr & 0x1fffff) / 4; - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 | 0x14000000) & ~0x60000000; + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 | 0x14000000) & ~0x60000000; return dma_words; } @@ -326,40 +326,40 @@ long GPU_dmaChain(u32 *rambase, u32 start_addr) /////////////////////////////////////////////////////////////////////////////// void GPU_writeData(u32 data) { - const u16 *VIDEO_END = (u16*)gpu_senquack.vram+(FRAME_BUFFER_SIZE/2)-1; + const u16 *VIDEO_END = (u16*)gpu_unai.vram+(FRAME_BUFFER_SIZE/2)-1; #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"GPU_writeData()\n"); #endif - gpu_senquack.GPU_GP1 &= ~0x14000000; + gpu_unai.GPU_GP1 &= ~0x14000000; - if (gpu_senquack.dma.FrameToWrite) + if (gpu_unai.dma.FrameToWrite) { - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; - gpu_senquack.dma.pvram[gpu_senquack.dma.px]=(u16)data; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; + gpu_unai.dma.pvram[gpu_unai.dma.px]=(u16)data; + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; - if (++gpu_senquack.dma.py >= gpu_senquack.dma.y_end) + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; + if (++gpu_unai.dma.py >= gpu_unai.dma.y_end) { - gpu_senquack.dma.FrameToWrite = false; - gpu_senquack.GPU_GP1 &= ~0x08000000; - gpu_senquack.fb_dirty = true; + gpu_unai.dma.FrameToWrite = false; + gpu_unai.GPU_GP1 &= ~0x08000000; + gpu_unai.fb_dirty = true; } } - if (gpu_senquack.dma.FrameToWrite) + if (gpu_unai.dma.FrameToWrite) { - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; - gpu_senquack.dma.pvram[gpu_senquack.dma.px]=data>>16; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; + gpu_unai.dma.pvram[gpu_unai.dma.px]=data>>16; + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; - if (++gpu_senquack.dma.py >= gpu_senquack.dma.y_end) + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; + if (++gpu_unai.dma.py >= gpu_unai.dma.y_end) { - gpu_senquack.dma.FrameToWrite = false; - gpu_senquack.GPU_GP1 &= ~0x08000000; - gpu_senquack.fb_dirty = true; + gpu_unai.dma.FrameToWrite = false; + gpu_unai.GPU_GP1 &= ~0x08000000; + gpu_unai.fb_dirty = true; } } } @@ -368,56 +368,56 @@ void GPU_writeData(u32 data) { gpuCheckPacket(data); } - gpu_senquack.GPU_GP1 |= 0x14000000; + gpu_unai.GPU_GP1 |= 0x14000000; } /////////////////////////////////////////////////////////////////////////////// void GPU_readDataMem(u32* dmaAddress, int dmaCount) { - const u16 *VIDEO_END = (u16*)gpu_senquack.vram+(FRAME_BUFFER_SIZE/2)-1; + const u16 *VIDEO_END = (u16*)gpu_unai.vram+(FRAME_BUFFER_SIZE/2)-1; #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"GPU_readDataMem(%d)\n",dmaCount); #endif - if(!gpu_senquack.dma.FrameToRead) return; + if(!gpu_unai.dma.FrameToRead) return; - gpu_senquack.GPU_GP1 &= ~0x14000000; + gpu_unai.GPU_GP1 &= ~0x14000000; do { - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; // lower 16 bit //senquack - 64-bit fix (from notaz) - //u32 data = (unsigned long)gpu_senquack.dma.pvram[gpu_senquack.dma.px]; - u32 data = (u32)gpu_senquack.dma.pvram[gpu_senquack.dma.px]; + //u32 data = (unsigned long)gpu_unai.dma.pvram[gpu_unai.dma.px]; + u32 data = (u32)gpu_unai.dma.pvram[gpu_unai.dma.px]; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; } - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; // higher 16 bit (always, even if it's an odd width) //senquack - 64-bit fix (from notaz) - //data |= (unsigned long)(gpu_senquack.dma.pvram[gpu_senquack.dma.px])<<16; - data |= (u32)(gpu_senquack.dma.pvram[gpu_senquack.dma.px])<<16; + //data |= (unsigned long)(gpu_unai.dma.pvram[gpu_unai.dma.px])<<16; + data |= (u32)(gpu_unai.dma.pvram[gpu_unai.dma.px])<<16; *dmaAddress++ = data; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; - if (++gpu_senquack.dma.py >= gpu_senquack.dma.y_end) + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; + if (++gpu_unai.dma.py >= gpu_unai.dma.y_end) { - gpu_senquack.dma.FrameToRead = false; - gpu_senquack.GPU_GP1 &= ~0x08000000; + gpu_unai.dma.FrameToRead = false; + gpu_unai.GPU_GP1 &= ~0x08000000; break; } } } while (--dmaCount); - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 | 0x14000000) & ~0x60000000; + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 | 0x14000000) & ~0x60000000; } @@ -425,48 +425,48 @@ void GPU_readDataMem(u32* dmaAddress, int dmaCount) /////////////////////////////////////////////////////////////////////////////// u32 GPU_readData(void) { - const u16 *VIDEO_END = (u16*)gpu_senquack.vram+(FRAME_BUFFER_SIZE/2)-1; + const u16 *VIDEO_END = (u16*)gpu_unai.vram+(FRAME_BUFFER_SIZE/2)-1; #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"GPU_readData()\n"); #endif - gpu_senquack.GPU_GP1 &= ~0x14000000; - if (gpu_senquack.dma.FrameToRead) + gpu_unai.GPU_GP1 &= ~0x14000000; + if (gpu_unai.dma.FrameToRead) { - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; - gpu_senquack.GPU_GP0 = gpu_senquack.dma.pvram[gpu_senquack.dma.px]; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; + gpu_unai.GPU_GP0 = gpu_unai.dma.pvram[gpu_unai.dma.px]; + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; - if (++gpu_senquack.dma.py >= gpu_senquack.dma.y_end) + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; + if (++gpu_unai.dma.py >= gpu_unai.dma.y_end) { - gpu_senquack.dma.FrameToRead = false; - gpu_senquack.GPU_GP1 &= ~0x08000000; + gpu_unai.dma.FrameToRead = false; + gpu_unai.GPU_GP1 &= ~0x08000000; } } - if ((&gpu_senquack.dma.pvram[gpu_senquack.dma.px])>(VIDEO_END)) gpu_senquack.dma.pvram-=512*1024; - gpu_senquack.GPU_GP0 |= gpu_senquack.dma.pvram[gpu_senquack.dma.px]<<16; - if (++gpu_senquack.dma.px >= gpu_senquack.dma.x_end) + if ((&gpu_unai.dma.pvram[gpu_unai.dma.px])>(VIDEO_END)) gpu_unai.dma.pvram-=512*1024; + gpu_unai.GPU_GP0 |= gpu_unai.dma.pvram[gpu_unai.dma.px]<<16; + if (++gpu_unai.dma.px >= gpu_unai.dma.x_end) { - gpu_senquack.dma.px = 0; - gpu_senquack.dma.pvram += 1024; - if (++gpu_senquack.dma.py >= gpu_senquack.dma.y_end) + gpu_unai.dma.px = 0; + gpu_unai.dma.pvram += 1024; + if (++gpu_unai.dma.py >= gpu_unai.dma.y_end) { - gpu_senquack.dma.FrameToRead = false; - gpu_senquack.GPU_GP1 &= ~0x08000000; + gpu_unai.dma.FrameToRead = false; + gpu_unai.GPU_GP1 &= ~0x08000000; } } } - gpu_senquack.GPU_GP1 |= 0x14000000; + gpu_unai.GPU_GP1 |= 0x14000000; - return (gpu_senquack.GPU_GP0); + return (gpu_unai.GPU_GP0); } /////////////////////////////////////////////////////////////////////////////// u32 GPU_readStatus(void) { - return gpu_senquack.GPU_GP1; + return gpu_unai.GPU_GP1; } INLINE void GPU_NoSkip(void) @@ -474,16 +474,16 @@ INLINE void GPU_NoSkip(void) #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"GPU_NoSkip()\n"); #endif - gpu_senquack.frameskip.wasSkip = gpu_senquack.frameskip.isSkip; - if (gpu_senquack.frameskip.isSkip) + gpu_unai.frameskip.wasSkip = gpu_unai.frameskip.isSkip; + if (gpu_unai.frameskip.isSkip) { - gpu_senquack.frameskip.isSkip = false; - gpu_senquack.frameskip.skipGPU = false; + gpu_unai.frameskip.isSkip = false; + gpu_unai.frameskip.skipGPU = false; } else { - gpu_senquack.frameskip.isSkip = gpu_senquack.frameskip.skipFrame; - gpu_senquack.frameskip.skipGPU = gpu_senquack.frameskip.skipFrame; + gpu_unai.frameskip.isSkip = gpu_unai.frameskip.skipFrame; + gpu_unai.frameskip.skipGPU = gpu_unai.frameskip.skipFrame; } } @@ -498,26 +498,26 @@ void GPU_writeStatus(u32 data) gpuReset(); break; case 0x01: - gpu_senquack.GPU_GP1 &= ~0x08000000; - gpu_senquack.PacketCount = 0; - gpu_senquack.dma.FrameToRead = gpu_senquack.dma.FrameToWrite = false; + gpu_unai.GPU_GP1 &= ~0x08000000; + gpu_unai.PacketCount = 0; + gpu_unai.dma.FrameToRead = gpu_unai.dma.FrameToWrite = false; break; case 0x02: - gpu_senquack.GPU_GP1 &= ~0x08000000; - gpu_senquack.PacketCount = 0; - gpu_senquack.dma.FrameToRead = gpu_senquack.dma.FrameToWrite = false; + gpu_unai.GPU_GP1 &= ~0x08000000; + gpu_unai.PacketCount = 0; + gpu_unai.dma.FrameToRead = gpu_unai.dma.FrameToWrite = false; break; case 0x03: - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 & ~0x00800000) | ((data & 1) << 23); + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 & ~0x00800000) | ((data & 1) << 23); break; case 0x04: - if (data == 0x04000000) gpu_senquack.PacketCount = 0; - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 & ~0x60000000) | ((data & 3) << 29); + if (data == 0x04000000) gpu_unai.PacketCount = 0; + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 & ~0x60000000) | ((data & 3) << 29); break; case 0x05: // Start of Display Area in VRAM - gpu_senquack.DisplayArea[0] = data & 0x3ff; // X (0..1023) - gpu_senquack.DisplayArea[1] = (data >> 10) & 0x1ff; // Y (0..511) + gpu_unai.DisplayArea[0] = data & 0x3ff; // X (0..1023) + gpu_unai.DisplayArea[1] = (data >> 10) & 0x1ff; // Y (0..511) GPU_NoSkip(); break; case 0x06: @@ -525,7 +525,7 @@ void GPU_writeStatus(u32 data) // 0-11 X1 (260h+0) ;12bit ;\counted in 53.222400MHz units, // 12-23 X2 (260h+320*8) ;12bit ;/relative to HSYNC - // senquack - gpu_senquack completely ignores GP1(0x06) command and + // senquack - gpu_unai completely ignores GP1(0x06) command and // lacks even a place in DisplayArea[] array to store the values. // It seems to have been concerned only with vertical display range // and centering top/bottom. I will not add support here, and @@ -540,10 +540,10 @@ void GPU_writeStatus(u32 data) { u32 v1=data & 0x000003FF; //(short)(data & 0x3ff); u32 v2=(data & 0x000FFC00) >> 10; //(short)((data>>10) & 0x3ff); - if ((gpu_senquack.DisplayArea[4]!=v1)||(gpu_senquack.DisplayArea[5]!=v2)) + if ((gpu_unai.DisplayArea[4]!=v1)||(gpu_unai.DisplayArea[5]!=v2)) { - gpu_senquack.DisplayArea[4] = v1; - gpu_senquack.DisplayArea[5] = v2; + gpu_unai.DisplayArea[4] = v1; + gpu_unai.DisplayArea[5] = v2; #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"video_clear(CHANGE_Y)\n"); #endif @@ -555,53 +555,53 @@ void GPU_writeStatus(u32 data) { static const u32 HorizontalResolution[8] = { 256, 368, 320, 384, 512, 512, 640, 640 }; static const u32 VerticalResolution[4] = { 240, 480, 256, 480 }; - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 & ~0x007F0000) | ((data & 0x3F) << 17) | ((data & 0x40) << 10); + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 & ~0x007F0000) | ((data & 0x3F) << 17) | ((data & 0x40) << 10); #ifdef ENABLE_GPU_LOG_SUPPORT - fprintf(stdout,"GPU_writeStatus(RES=%dx%d,BITS=%d,PAL=%d)\n",HorizontalResolution[(gpu_senquack.GPU_GP1 >> 16) & 7], - VerticalResolution[(gpu_senquack.GPU_GP1 >> 19) & 3],(gpu_senquack.GPU_GP1&0x00200000?24:15),(IS_PAL?1:0)); + fprintf(stdout,"GPU_writeStatus(RES=%dx%d,BITS=%d,PAL=%d)\n",HorizontalResolution[(gpu_unai.GPU_GP1 >> 16) & 7], + VerticalResolution[(gpu_unai.GPU_GP1 >> 19) & 3],(gpu_unai.GPU_GP1&0x00200000?24:15),(IS_PAL?1:0)); #endif // Video mode change - u32 new_width = HorizontalResolution[(gpu_senquack.GPU_GP1 >> 16) & 7]; - u32 new_height = VerticalResolution[(gpu_senquack.GPU_GP1 >> 19) & 3]; + u32 new_width = HorizontalResolution[(gpu_unai.GPU_GP1 >> 16) & 7]; + u32 new_height = VerticalResolution[(gpu_unai.GPU_GP1 >> 19) & 3]; - if (gpu_senquack.DisplayArea[2] != new_width || gpu_senquack.DisplayArea[3] != new_height) + if (gpu_unai.DisplayArea[2] != new_width || gpu_unai.DisplayArea[3] != new_height) { // Update width - gpu_senquack.DisplayArea[2] = new_width; + gpu_unai.DisplayArea[2] = new_width; if (PixelSkipEnabled()) { // Set blit_mask for high horizontal resolutions. This allows skipping // rendering pixels that would never get displayed on low-resolution // platforms that use simple pixel-dropping scaler. - switch (gpu_senquack.DisplayArea[2]) + switch (gpu_unai.DisplayArea[2]) { - case 512: gpu_senquack.blit_mask = 0xa4; break; // GPU_BlitWWSWWSWS - case 640: gpu_senquack.blit_mask = 0xaa; break; // GPU_BlitWS - default: gpu_senquack.blit_mask = 0; break; + case 512: gpu_unai.blit_mask = 0xa4; break; // GPU_BlitWWSWWSWS + case 640: gpu_unai.blit_mask = 0xaa; break; // GPU_BlitWS + default: gpu_unai.blit_mask = 0; break; } } else { - gpu_senquack.blit_mask = 0; + gpu_unai.blit_mask = 0; } // Update height - gpu_senquack.DisplayArea[3] = new_height; + gpu_unai.DisplayArea[3] = new_height; if (LineSkipEnabled()) { // Set rendering line-skip (only render every other line in high-res // 480 vertical mode, or, optionally, force it for all video modes) - if (gpu_senquack.DisplayArea[3] == 480) { - if (gpu_senquack.config.ilace_force) { - gpu_senquack.ilace_mask = 3; // Only need 1/4 of lines + if (gpu_unai.DisplayArea[3] == 480) { + if (gpu_unai.config.ilace_force) { + gpu_unai.ilace_mask = 3; // Only need 1/4 of lines } else { - gpu_senquack.ilace_mask = 1; // Only need 1/2 of lines + gpu_unai.ilace_mask = 1; // Only need 1/2 of lines } } else { // Vert resolution changed from 480 to lower one - gpu_senquack.ilace_mask = gpu_senquack.config.ilace_force; + gpu_unai.ilace_mask = gpu_unai.config.ilace_force; } } else { - gpu_senquack.ilace_mask = 0; + gpu_unai.ilace_mask = 0; } #ifdef ENABLE_GPU_LOG_SUPPORT @@ -614,12 +614,12 @@ void GPU_writeStatus(u32 data) break; case 0x10: switch (data & 0xff) { - case 2: gpu_senquack.GPU_GP0 = gpu_senquack.tex_window; break; - case 3: gpu_senquack.GPU_GP0 = (gpu_senquack.DrawingArea[1] << 10) | gpu_senquack.DrawingArea[0]; break; - case 4: gpu_senquack.GPU_GP0 = ((gpu_senquack.DrawingArea[3]-1) << 10) | (gpu_senquack.DrawingArea[2]-1); break; - case 5: case 6: gpu_senquack.GPU_GP0 = (((u32)gpu_senquack.DrawingOffset[1] & 0x7ff) << 11) | ((u32)gpu_senquack.DrawingOffset[0] & 0x7ff); break; - case 7: gpu_senquack.GPU_GP0 = 2; break; - case 8: case 15: gpu_senquack.GPU_GP0 = 0xBFC03720; break; + case 2: gpu_unai.GPU_GP0 = gpu_unai.tex_window; break; + case 3: gpu_unai.GPU_GP0 = (gpu_unai.DrawingArea[1] << 10) | gpu_unai.DrawingArea[0]; break; + case 4: gpu_unai.GPU_GP0 = ((gpu_unai.DrawingArea[3]-1) << 10) | (gpu_unai.DrawingArea[2]-1); break; + case 5: case 6: gpu_unai.GPU_GP0 = (((u32)gpu_unai.DrawingOffset[1] & 0x7ff) << 11) | ((u32)gpu_unai.DrawingOffset[0] & 0x7ff); break; + case 7: gpu_unai.GPU_GP0 = 2; break; + case 8: case 15: gpu_unai.GPU_GP0 = 0xBFC03720; break; } break; } @@ -632,18 +632,18 @@ static void gpuVideoOutput(void) { int h0, x0, y0, w0, h1; - x0 = gpu_senquack.DisplayArea[0]; - y0 = gpu_senquack.DisplayArea[1]; + x0 = gpu_unai.DisplayArea[0]; + y0 = gpu_unai.DisplayArea[1]; - w0 = gpu_senquack.DisplayArea[2]; - h0 = gpu_senquack.DisplayArea[3]; // video mode + w0 = gpu_unai.DisplayArea[2]; + h0 = gpu_unai.DisplayArea[3]; // video mode - h1 = gpu_senquack.DisplayArea[5] - gpu_senquack.DisplayArea[4]; // display needed + h1 = gpu_unai.DisplayArea[5] - gpu_unai.DisplayArea[4]; // display needed if (h0 == 480) h1 = Min2(h1*2,480); - bool isRGB24 = (gpu_senquack.GPU_GP1 & 0x00200000 ? true : false); + bool isRGB24 = (gpu_unai.GPU_GP1 & 0x00200000 ? true : false); u16* dst16 = SCREEN; - u16* src16 = (u16*)gpu_senquack.vram; + u16* src16 = (u16*)gpu_unai.vram; // PS1 fb read wraps around (fixes black screen in 'Tobal no. 1') unsigned int src16_offs_msk = 1024*512-1; @@ -669,9 +669,9 @@ static void gpuVideoOutput(void) h0=(h0==480 ? 2048 : 1024); { - const int li=gpu_senquack.ilace_mask; + const int li=gpu_unai.ilace_mask; bool pi = ProgressiveInterlaceEnabled(); - bool pif = gpu_senquack.prog_ilace_flag; + bool pif = gpu_unai.prog_ilace_flag; switch ( w0 ) { case 256: @@ -731,7 +731,7 @@ static void gpuVideoOutput(void) } break; } - gpu_senquack.prog_ilace_flag = !gpu_senquack.prog_ilace_flag; + gpu_unai.prog_ilace_flag = !gpu_unai.prog_ilace_flag; } video_flip(); } @@ -744,9 +744,9 @@ static void GPU_frameskip (bool show) u32 now=get_ticks(); // current frame // Update frameskip - if (gpu_senquack.frameskip.skipCount==0) gpu_senquack.frameskip.skipFrame=false; // frameskip off - else if (gpu_senquack.frameskip.skipCount==7) { if (show) gpu_senquack.frameskip.skipFrame=!gpu_senquack.frameskip.skipFrame; } // frameskip medium - else if (gpu_senquack.frameskip.skipCount==8) gpu_senquack.frameskip.skipFrame=true; // frameskip maximum + if (gpu_unai.frameskip.skipCount==0) gpu_unai.frameskip.skipFrame=false; // frameskip off + else if (gpu_unai.frameskip.skipCount==7) { if (show) gpu_unai.frameskip.skipFrame=!gpu_unai.frameskip.skipFrame; } // frameskip medium + else if (gpu_unai.frameskip.skipCount==8) gpu_unai.frameskip.skipFrame=true; // frameskip maximum else { static u32 spd=100; // speed % @@ -761,13 +761,13 @@ static void GPU_frameskip (bool show) frames=0; prev=now; } - switch(gpu_senquack.frameskip.skipCount) + switch(gpu_unai.frameskip.skipCount) { - case 1: if (spd<50) gpu_senquack.frameskip.skipFrame=true; else gpu_senquack.frameskip.skipFrame=false; break; // frameskip on (spd<50%) - case 2: if (spd<60) gpu_senquack.frameskip.skipFrame=true; else gpu_senquack.frameskip.skipFrame=false; break; // frameskip on (spd<60%) - case 3: if (spd<70) gpu_senquack.frameskip.skipFrame=true; else gpu_senquack.frameskip.skipFrame=false; break; // frameskip on (spd<70%) - case 4: if (spd<80) gpu_senquack.frameskip.skipFrame=true; else gpu_senquack.frameskip.skipFrame=false; break; // frameskip on (spd<80%) - case 5: if (spd<90) gpu_senquack.frameskip.skipFrame=true; else gpu_senquack.frameskip.skipFrame=false; break; // frameskip on (spd<90%) + case 1: if (spd<50) gpu_unai.frameskip.skipFrame=true; else gpu_unai.frameskip.skipFrame=false; break; // frameskip on (spd<50%) + case 2: if (spd<60) gpu_unai.frameskip.skipFrame=true; else gpu_unai.frameskip.skipFrame=false; break; // frameskip on (spd<60%) + case 3: if (spd<70) gpu_unai.frameskip.skipFrame=true; else gpu_unai.frameskip.skipFrame=false; break; // frameskip on (spd<70%) + case 4: if (spd<80) gpu_unai.frameskip.skipFrame=true; else gpu_unai.frameskip.skipFrame=false; break; // frameskip on (spd<80%) + case 5: if (spd<90) gpu_unai.frameskip.skipFrame=true; else gpu_unai.frameskip.skipFrame=false; break; // frameskip on (spd<90%) } } } @@ -776,10 +776,10 @@ static void GPU_frameskip (bool show) void GPU_updateLace(void) { // Interlace bit toggle - gpu_senquack.GPU_GP1 ^= 0x80000000; + gpu_unai.GPU_GP1 ^= 0x80000000; // Update display? - if ((gpu_senquack.fb_dirty) && (!gpu_senquack.frameskip.wasSkip) && (!(gpu_senquack.GPU_GP1&0x00800000))) + if ((gpu_unai.fb_dirty) && (!gpu_unai.frameskip.wasSkip) && (!(gpu_unai.GPU_GP1&0x00800000))) { // Display updated gpuVideoOutput(); @@ -794,33 +794,33 @@ void GPU_updateLace(void) #endif } - if ((!gpu_senquack.frameskip.skipCount) && (gpu_senquack.DisplayArea[3] == 480)) gpu_senquack.frameskip.skipGPU=true; // Tekken 3 hack + if ((!gpu_unai.frameskip.skipCount) && (gpu_unai.DisplayArea[3] == 480)) gpu_unai.frameskip.skipGPU=true; // Tekken 3 hack - gpu_senquack.fb_dirty=false; - gpu_senquack.dma.last_dma = NULL; + gpu_unai.fb_dirty=false; + gpu_unai.dma.last_dma = NULL; } // Allows frontend to signal plugin to redraw screen after returning to emu void GPU_requestScreenRedraw() { - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; } void GPU_getScreenInfo(GPUScreenInfo_t *sinfo) { - bool depth24 = (gpu_senquack.GPU_GP1 & 0x00200000 ? true : false); - int16_t hres = (uint16_t)gpu_senquack.DisplayArea[2]; - int16_t vres = (uint16_t)gpu_senquack.DisplayArea[3]; - int16_t w = hres; // Original gpu_senquack doesn't support width < 100% - int16_t h = gpu_senquack.DisplayArea[5] - gpu_senquack.DisplayArea[4]; + bool depth24 = (gpu_unai.GPU_GP1 & 0x00200000 ? true : false); + int16_t hres = (uint16_t)gpu_unai.DisplayArea[2]; + int16_t vres = (uint16_t)gpu_unai.DisplayArea[3]; + int16_t w = hres; // Original gpu_unai doesn't support width < 100% + int16_t h = gpu_unai.DisplayArea[5] - gpu_unai.DisplayArea[4]; if (vres == 480) h *= 2; if (h <= 0 || h > vres) h = vres; - sinfo->vram = (uint8_t*)gpu_senquack.vram; - sinfo->x = (uint16_t)gpu_senquack.DisplayArea[0]; - sinfo->y = (uint16_t)gpu_senquack.DisplayArea[1]; + sinfo->vram = (uint8_t*)gpu_unai.vram; + sinfo->x = (uint16_t)gpu_unai.DisplayArea[0]; + sinfo->y = (uint16_t)gpu_unai.DisplayArea[1]; sinfo->w = w; sinfo->h = h; sinfo->hres = hres; diff --git a/plugins/gpu_unai/gpu.h b/plugins/gpu_unai/gpu.h index 7a467511..f5eb69b4 100644 --- a/plugins/gpu_unai/gpu.h +++ b/plugins/gpu_unai/gpu.h @@ -22,7 +22,7 @@ #ifndef GPU_UNAI_GPU_H #define GPU_UNAI_GPU_H -struct gpu_senquack_config_t { +struct gpu_unai_config_t { uint8_t pixel_skip:1; // If 1, allows skipping rendering pixels that // would not be visible when a high horizontal // resolution PS1 video mode is set. @@ -34,7 +34,7 @@ struct gpu_senquack_config_t { uint8_t ilace_force:3; // Option to force skipping rendering of lines, // for very slow platforms. Value will be - // assigned to 'ilace_mask' in gpu_senquack struct. + // assigned to 'ilace_mask' in gpu_unai struct. // Normally 0. Value '1' will skip rendering // odd lines. @@ -47,13 +47,13 @@ struct gpu_senquack_config_t { uint8_t blending:1; uint8_t dithering:1; - //senquack Only PCSX Rearmed's version of gpu_senquack had this, and I + //senquack Only PCSX Rearmed's version of gpu_unai had this, and I // don't think it's necessary. It would require adding 'AH' flag to // gpuSpriteSpanFn() increasing size of sprite span function array. //uint8_t enableAbbeyHack:1; // Abe's Odyssey hack //////////////////////////////////////////////////////////////////////////// - // Variables used only by older standalone version of gpu_senquack (gpu.cpp) + // Variables used only by older standalone version of gpu_unai (gpu.cpp) #ifndef USE_GPULIB uint8_t prog_ilace:1; // Progressive interlace option (old option) // This option was somewhat oddly named: @@ -66,7 +66,7 @@ struct gpu_senquack_config_t { #endif }; -extern gpu_senquack_config_t gpu_senquack_config_ext; +extern gpu_unai_config_t gpu_unai_config_ext; // TODO: clean up show_fps frontend option extern bool show_fps; diff --git a/plugins/gpu_unai/gpu_arm.h b/plugins/gpu_unai/gpu_arm.h index b9f8f97c..0f8ed6b5 100644 --- a/plugins/gpu_unai/gpu_arm.h +++ b/plugins/gpu_unai/gpu_arm.h @@ -5,7 +5,7 @@ extern "C" { #endif -void draw_spr16_full(u16 *d, void *s, u16 *pal, int lines); +void draw_spr16_full(void *d, void *s, void *pal, int lines); #ifdef __cplusplus } diff --git a/plugins/gpu_unai/gpu_command.h b/plugins/gpu_unai/gpu_command.h index d052ae8c..cf6b62b4 100644 --- a/plugins/gpu_unai/gpu_command.h +++ b/plugins/gpu_unai/gpu_command.h @@ -26,9 +26,9 @@ void gpuSetTexture(u16 tpage) { u32 tmode, tx, ty; - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 & ~0x1FF) | (tpage & 0x1FF); - gpu_senquack.TextureWindow[0]&= ~gpu_senquack.TextureWindow[2]; - gpu_senquack.TextureWindow[1]&= ~gpu_senquack.TextureWindow[3]; + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 & ~0x1FF) | (tpage & 0x1FF); + gpu_unai.TextureWindow[0]&= ~gpu_unai.TextureWindow[2]; + gpu_unai.TextureWindow[1]&= ~gpu_unai.TextureWindow[3]; tmode = (tpage >> 7) & 3; // 16bpp, 8bpp, or 4bpp texture colors? // 0: 4bpp 1: 8bpp 2/3: 16bpp @@ -40,18 +40,18 @@ void gpuSetTexture(u16 tpage) tx = (tpage & 0x0F) << 6; ty = (tpage & 0x10) << 4; - tx += (gpu_senquack.TextureWindow[0] >> (2 - tmode)); - ty += gpu_senquack.TextureWindow[1]; + tx += (gpu_unai.TextureWindow[0] >> (2 - tmode)); + ty += gpu_unai.TextureWindow[1]; - gpu_senquack.BLEND_MODE = ((tpage>>5) & 3) << 3; - gpu_senquack.TEXT_MODE = (tmode + 1) << 5; // gpu_senquack.TEXT_MODE should be values 1..3, so add one - gpu_senquack.TBA = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(tx, ty)]; + gpu_unai.BLEND_MODE = ((tpage>>5) & 3) << 3; + gpu_unai.TEXT_MODE = (tmode + 1) << 5; // gpu_unai.TEXT_MODE should be values 1..3, so add one + gpu_unai.TBA = &gpu_unai.vram[FRAME_OFFSET(tx, ty)]; } /////////////////////////////////////////////////////////////////////////////// INLINE void gpuSetCLUT(u16 clut) { - gpu_senquack.CBA = &((u16*)gpu_senquack.vram)[(clut & 0x7FFF) << 4]; + gpu_unai.CBA = &gpu_unai.vram[(clut & 0x7FFF) << 4]; } #ifdef ENABLE_GPU_NULL_SUPPORT @@ -67,20 +67,20 @@ INLINE void gpuSetCLUT(u16 clut) #endif #define Blending (((PRIM&0x2) && BlendingEnabled()) ? (PRIM&0x2) : 0) -#define Blending_Mode (((PRIM&0x2) && BlendingEnabled()) ? gpu_senquack.BLEND_MODE : 0) +#define Blending_Mode (((PRIM&0x2) && BlendingEnabled()) ? gpu_unai.BLEND_MODE : 0) #define Lighting (((~PRIM)&0x1) && LightingEnabled()) // Dithering applies only to Gouraud-shaded polys or texture-blended polys: #define Dithering (((((~PRIM)&0x1) || (PRIM&0x10)) && DitheringEnabled()) ? \ - (ForcedDitheringEnabled() ? (1<<9) : (gpu_senquack.GPU_GP1 & (1 << 9))) \ + (ForcedDitheringEnabled() ? (1<<9) : (gpu_unai.GPU_GP1 & (1 << 9))) \ : 0) /////////////////////////////////////////////////////////////////////////////// -//Now handled by Rearmed's gpulib and gpu_senquack/gpulib_if.cpp: +//Now handled by Rearmed's gpulib and gpu_unai/gpulib_if.cpp: /////////////////////////////////////////////////////////////////////////////// #ifndef USE_GPULIB // Handles GP0 draw settings commands 0xE1...0xE6 -static void gpuGP0Cmd_0xEx(gpu_senquack_t &gpu_senquack, u32 cmd_word) +static void gpuGP0Cmd_0xEx(gpu_unai_t &gpu_unai, u32 cmd_word) { // Assume incoming GP0 command is 0xE1..0xE6, convert to 1..6 u8 num = (cmd_word >> 24) & 7; @@ -88,65 +88,65 @@ static void gpuGP0Cmd_0xEx(gpu_senquack_t &gpu_senquack, u32 cmd_word) case 1: { // GP0(E1h) - Draw Mode setting (aka "Texpage") DO_LOG(("GP0(0xE1) DrawMode TexPage(0x%x)\n", cmd_word)); - u32 cur_texpage = gpu_senquack.GPU_GP1 & 0x7FF; + u32 cur_texpage = gpu_unai.GPU_GP1 & 0x7FF; u32 new_texpage = cmd_word & 0x7FF; if (cur_texpage != new_texpage) { - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 & ~0x7FF) | new_texpage; - gpuSetTexture(gpu_senquack.GPU_GP1); + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 & ~0x7FF) | new_texpage; + gpuSetTexture(gpu_unai.GPU_GP1); } } break; case 2: { // GP0(E2h) - Texture Window setting DO_LOG(("GP0(0xE2) TextureWindow(0x%x)\n", cmd_word)); - if (cmd_word != gpu_senquack.TextureWindowCur) { + if (cmd_word != gpu_unai.TextureWindowCur) { static const u8 TextureMask[32] = { 255, 7, 15, 7, 31, 7, 15, 7, 63, 7, 15, 7, 31, 7, 15, 7, 127, 7, 15, 7, 31, 7, 15, 7, 63, 7, 15, 7, 31, 7, 15, 7 }; - gpu_senquack.TextureWindowCur = cmd_word; - gpu_senquack.TextureWindow[0] = ((cmd_word >> 10) & 0x1F) << 3; - gpu_senquack.TextureWindow[1] = ((cmd_word >> 15) & 0x1F) << 3; - gpu_senquack.TextureWindow[2] = TextureMask[(cmd_word >> 0) & 0x1F]; - gpu_senquack.TextureWindow[3] = TextureMask[(cmd_word >> 5) & 0x1F]; - gpu_senquack.TextureWindow[0] &= ~gpu_senquack.TextureWindow[2]; - gpu_senquack.TextureWindow[1] &= ~gpu_senquack.TextureWindow[3]; + gpu_unai.TextureWindowCur = cmd_word; + gpu_unai.TextureWindow[0] = ((cmd_word >> 10) & 0x1F) << 3; + gpu_unai.TextureWindow[1] = ((cmd_word >> 15) & 0x1F) << 3; + gpu_unai.TextureWindow[2] = TextureMask[(cmd_word >> 0) & 0x1F]; + gpu_unai.TextureWindow[3] = TextureMask[(cmd_word >> 5) & 0x1F]; + gpu_unai.TextureWindow[0] &= ~gpu_unai.TextureWindow[2]; + gpu_unai.TextureWindow[1] &= ~gpu_unai.TextureWindow[3]; // Inner loop vars must be updated whenever texture window is changed: const u32 fb = FIXED_BITS; // # of fractional fixed-pt bits of u4/v4 - gpu_senquack.u_msk = (((u32)gpu_senquack.TextureWindow[2]) << fb) | ((1 << fb) - 1); - gpu_senquack.v_msk = (((u32)gpu_senquack.TextureWindow[3]) << fb) | ((1 << fb) - 1); + gpu_unai.u_msk = (((u32)gpu_unai.TextureWindow[2]) << fb) | ((1 << fb) - 1); + gpu_unai.v_msk = (((u32)gpu_unai.TextureWindow[3]) << fb) | ((1 << fb) - 1); - gpuSetTexture(gpu_senquack.GPU_GP1); + gpuSetTexture(gpu_unai.GPU_GP1); } } break; case 3: { // GP0(E3h) - Set Drawing Area top left (X1,Y1) DO_LOG(("GP0(0xE3) DrawingArea Pos(0x%x)\n", cmd_word)); - gpu_senquack.DrawingArea[0] = cmd_word & 0x3FF; - gpu_senquack.DrawingArea[1] = (cmd_word >> 10) & 0x3FF; + gpu_unai.DrawingArea[0] = cmd_word & 0x3FF; + gpu_unai.DrawingArea[1] = (cmd_word >> 10) & 0x3FF; } break; case 4: { // GP0(E4h) - Set Drawing Area bottom right (X2,Y2) DO_LOG(("GP0(0xE4) DrawingArea Size(0x%x)\n", cmd_word)); - gpu_senquack.DrawingArea[2] = (cmd_word & 0x3FF) + 1; - gpu_senquack.DrawingArea[3] = ((cmd_word >> 10) & 0x3FF) + 1; + gpu_unai.DrawingArea[2] = (cmd_word & 0x3FF) + 1; + gpu_unai.DrawingArea[3] = ((cmd_word >> 10) & 0x3FF) + 1; } break; case 5: { // GP0(E5h) - Set Drawing Offset (X,Y) DO_LOG(("GP0(0xE5) DrawingOffset(0x%x)\n", cmd_word)); - gpu_senquack.DrawingOffset[0] = ((s32)cmd_word<<(32-11))>>(32-11); - gpu_senquack.DrawingOffset[1] = ((s32)cmd_word<<(32-22))>>(32-11); + gpu_unai.DrawingOffset[0] = ((s32)cmd_word<<(32-11))>>(32-11); + gpu_unai.DrawingOffset[1] = ((s32)cmd_word<<(32-22))>>(32-11); } break; case 6: { // GP0(E6h) - Mask Bit Setting DO_LOG(("GP0(0xE6) SetMask(0x%x)\n", cmd_word)); - gpu_senquack.Masking = (cmd_word & 0x2) << 1; - gpu_senquack.PixelMSB = (cmd_word & 0x1) << 8; + gpu_unai.Masking = (cmd_word & 0x2) << 1; + gpu_unai.PixelMSB = (cmd_word & 0x1) << 8; } break; } } @@ -157,14 +157,14 @@ void gpuSendPacketFunction(const int PRIM) //senquack - TODO: optimize this (packet pointer union as prim draw parameter // introduced as optimization for gpulib command-list processing) - PtrUnion packet = { .ptr = (void*)&gpu_senquack.PacketBuffer }; + PtrUnion packet = { .ptr = (void*)&gpu_unai.PacketBuffer }; switch (PRIM) { case 0x02: { NULL_GPU(); gpuClearImage(packet); // prim handles updateLace && skip - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuClearImage(0x%x)\n",PRIM)); } break; @@ -172,16 +172,16 @@ void gpuSendPacketFunction(const int PRIM) case 0x21: case 0x22: case 0x23: { // Monochrome 3-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Blending_Mode | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | gpu_unai.PixelMSB ]; gpuDrawPolyF(packet, driver, false); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyF(0x%x)\n",PRIM)); } } break; @@ -190,28 +190,28 @@ void gpuSendPacketFunction(const int PRIM) case 0x25: case 0x26: case 0x27: { // Textured 3-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture (gpu_senquack.PacketBuffer.U4[4] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[4]) >> 16); u32 driver_idx = - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB; + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | gpu_unai.PixelMSB; if (!FastLightingEnabled()) { driver_idx |= Lighting; } else { - if (!((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F))) + if (!((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F))) driver_idx |= Lighting; } PP driver = gpuPolySpanDrivers[driver_idx]; gpuDrawPolyFT(packet, driver, false); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyFT(0x%x)\n",PRIM)); } } break; @@ -220,16 +220,16 @@ void gpuSendPacketFunction(const int PRIM) case 0x29: case 0x2A: case 0x2B: { // Monochrome 4-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Blending_Mode | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | gpu_unai.PixelMSB ]; gpuDrawPolyF(packet, driver, true); // is_quad = true - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyF(0x%x) (4-pt QUAD)\n",PRIM)); } } break; @@ -238,28 +238,28 @@ void gpuSendPacketFunction(const int PRIM) case 0x2D: case 0x2E: case 0x2F: { // Textured 4-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture (gpu_senquack.PacketBuffer.U4[4] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[4]) >> 16); u32 driver_idx = - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB; + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | gpu_unai.PixelMSB; if (!FastLightingEnabled()) { driver_idx |= Lighting; } else { - if (!((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F))) + if (!((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F))) driver_idx |= Lighting; } PP driver = gpuPolySpanDrivers[driver_idx]; gpuDrawPolyFT(packet, driver, true); // is_quad = true - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyFT(0x%x) (4-pt QUAD)\n",PRIM)); } } break; @@ -268,7 +268,7 @@ void gpuSendPacketFunction(const int PRIM) case 0x31: case 0x32: case 0x33: { // Gouraud-shaded 3-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); //NOTE: The '129' here is CF_GOURAUD | CF_LIGHT, however @@ -276,13 +276,13 @@ void gpuSendPacketFunction(const int PRIM) // shouldn't apply. Until the original array of template // instantiation ptrs is fixed, we're stuck with this. (TODO) PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | Blending_Mode | - gpu_senquack.Masking | Blending | 129 | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | 129 | gpu_unai.PixelMSB ]; gpuDrawPolyG(packet, driver, false); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyG(0x%x)\n",PRIM)); } } break; @@ -291,19 +291,19 @@ void gpuSendPacketFunction(const int PRIM) case 0x35: case 0x36: case 0x37: { // Gouraud-shaded, textured 3-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture (gpu_senquack.PacketBuffer.U4[5] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16); PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | ((Lighting)?129:0) | gpu_senquack.PixelMSB + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | ((Lighting)?129:0) | gpu_unai.PixelMSB ]; gpuDrawPolyGT(packet, driver, false); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyGT(0x%x)\n",PRIM)); } } break; @@ -312,18 +312,18 @@ void gpuSendPacketFunction(const int PRIM) case 0x39: case 0x3A: case 0x3B: { // Gouraud-shaded 4-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); // See notes regarding '129' for 0x30..0x33 further above -senquack PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | Blending_Mode | - gpu_senquack.Masking | Blending | 129 | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | 129 | gpu_unai.PixelMSB ]; gpuDrawPolyG(packet, driver, true); // is_quad = true - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyG(0x%x) (4-pt QUAD)\n",PRIM)); } } break; @@ -332,19 +332,19 @@ void gpuSendPacketFunction(const int PRIM) case 0x3D: case 0x3E: case 0x3F: { // Gouraud-shaded, textured 4-pt poly - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture (gpu_senquack.PacketBuffer.U4[5] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16); PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | ((Lighting)?129:0) | gpu_senquack.PixelMSB + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | ((Lighting)?129:0) | gpu_unai.PixelMSB ]; gpuDrawPolyGT(packet, driver, true); // is_quad = true - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawPolyGT(0x%x) (4-pt QUAD)\n",PRIM)); } } break; @@ -353,14 +353,14 @@ void gpuSendPacketFunction(const int PRIM) case 0x41: case 0x42: case 0x43: { // Monochrome line - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; PSD driver = gpuPixelSpanDrivers[driver_idx]; gpuDrawLineF(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawLineF(0x%x)\n",PRIM)); } } break; @@ -373,22 +373,22 @@ void gpuSendPacketFunction(const int PRIM) case 0x4D: case 0x4E: case 0x4F: { // Monochrome line strip - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; PSD driver = gpuPixelSpanDrivers[driver_idx]; gpuDrawLineF(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawLineF(0x%x)\n",PRIM)); } - if ((gpu_senquack.PacketBuffer.U4[3] & 0xF000F000) != 0x50005000) + if ((le32_raw(gpu_unai.PacketBuffer.U4[3]) & HTOLE32(0xF000F000)) != HTOLE32(0x50005000)) { - gpu_senquack.PacketBuffer.U4[1] = gpu_senquack.PacketBuffer.U4[2]; - gpu_senquack.PacketBuffer.U4[2] = gpu_senquack.PacketBuffer.U4[3]; - gpu_senquack.PacketCount = 1; - gpu_senquack.PacketIndex = 3; + gpu_unai.PacketBuffer.U4[1] = gpu_unai.PacketBuffer.U4[2]; + gpu_unai.PacketBuffer.U4[2] = gpu_unai.PacketBuffer.U4[3]; + gpu_unai.PacketCount = 1; + gpu_unai.PacketIndex = 3; } } break; @@ -396,16 +396,16 @@ void gpuSendPacketFunction(const int PRIM) case 0x51: case 0x52: case 0x53: { // Gouraud-shaded line - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; // Index MSB selects Gouraud-shaded PixelSpanDriver: driver_idx |= (1 << 5); PSD driver = gpuPixelSpanDrivers[driver_idx]; gpuDrawLineG(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawLineG(0x%x)\n",PRIM)); } } break; @@ -418,26 +418,26 @@ void gpuSendPacketFunction(const int PRIM) case 0x5D: case 0x5E: case 0x5F: { // Gouraud-shaded line strip - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; // Index MSB selects Gouraud-shaded PixelSpanDriver: driver_idx |= (1 << 5); PSD driver = gpuPixelSpanDrivers[driver_idx]; gpuDrawLineG(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawLineG(0x%x)\n",PRIM)); } - if ((gpu_senquack.PacketBuffer.U4[4] & 0xF000F000) != 0x50005000) + if ((le32_raw(gpu_unai.PacketBuffer.U4[4]) & HTOLE32(0xF000F000)) != HTOLE32(0x50005000)) { - gpu_senquack.PacketBuffer.U1[3 + (2 * 4)] = gpu_senquack.PacketBuffer.U1[3 + (0 * 4)]; - gpu_senquack.PacketBuffer.U4[0] = gpu_senquack.PacketBuffer.U4[2]; - gpu_senquack.PacketBuffer.U4[1] = gpu_senquack.PacketBuffer.U4[3]; - gpu_senquack.PacketBuffer.U4[2] = gpu_senquack.PacketBuffer.U4[4]; - gpu_senquack.PacketCount = 2; - gpu_senquack.PacketIndex = 3; + gpu_unai.PacketBuffer.U1[3 + (2 * 4)] = gpu_unai.PacketBuffer.U1[3 + (0 * 4)]; + gpu_unai.PacketBuffer.U4[0] = gpu_unai.PacketBuffer.U4[2]; + gpu_unai.PacketBuffer.U4[1] = gpu_unai.PacketBuffer.U4[3]; + gpu_unai.PacketBuffer.U4[2] = gpu_unai.PacketBuffer.U4[4]; + gpu_unai.PacketCount = 2; + gpu_unai.PacketIndex = 3; } } break; @@ -445,12 +445,12 @@ void gpuSendPacketFunction(const int PRIM) case 0x61: case 0x62: case 0x63: { // Monochrome rectangle (variable size) - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawT(0x%x)\n",PRIM)); } } break; @@ -459,30 +459,30 @@ void gpuSendPacketFunction(const int PRIM) case 0x65: case 0x66: case 0x67: { // Textured rectangle (variable size) - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - u32 driver_idx = Blending_Mode | gpu_senquack.TEXT_MODE | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>1); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1); // This fixes Silent Hill running animation on loading screens: // (On PSX, color values 0x00-0x7F darken the source texture's color, // 0x81-FF lighten textures (ultimately clamped to 0x1F), // 0x80 leaves source texture color unchanged, HOWEVER, - // gpu_senquack uses a simple lighting LUT whereby only the upper + // gpu_unai uses a simple lighting LUT whereby only the upper // 5 bits of an 8-bit color are used, so 0x80-0x87 all behave as // 0x80. // // NOTE: I've changed all textured sprite draw commands here and // elsewhere to use proper behavior, but left poly commands // alone, I don't want to slow rendering down too much. (TODO) - //if ((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F)) + //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F)) // Strip lower 3 bits of each color and determine if lighting should be used: - if ((gpu_senquack.PacketBuffer.U4[0] & 0xF8F8F8) != 0x808080) + if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080)) driver_idx |= Lighting; PS driver = gpuSpriteSpanDrivers[driver_idx]; gpuDrawS(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawS(0x%x)\n",PRIM)); } } break; @@ -491,13 +491,13 @@ void gpuSendPacketFunction(const int PRIM) case 0x69: case 0x6A: case 0x6B: { // Monochrome rectangle (1x1 dot) - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpu_senquack.PacketBuffer.U4[2] = 0x00010001; - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00010001); + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawT(0x%x)\n",PRIM)); } } break; @@ -506,13 +506,13 @@ void gpuSendPacketFunction(const int PRIM) case 0x71: case 0x72: case 0x73: { // Monochrome rectangle (8x8) - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpu_senquack.PacketBuffer.U4[2] = 0x00080008; - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00080008); + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawT(0x%x)\n",PRIM)); } } break; @@ -521,21 +521,21 @@ void gpuSendPacketFunction(const int PRIM) case 0x75: case 0x76: case 0x77: { // Textured rectangle (8x8) - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpu_senquack.PacketBuffer.U4[3] = 0x00080008; - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - u32 driver_idx = Blending_Mode | gpu_senquack.TEXT_MODE | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>1); + gpu_unai.PacketBuffer.U4[3] = u32_to_le32(0x00080008); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1); //senquack - Only color 808080h-878787h allows skipping lighting calculation: - //if ((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F)) + //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F)) // Strip lower 3 bits of each color and determine if lighting should be used: - if ((gpu_senquack.PacketBuffer.U4[0] & 0xF8F8F8) != 0x808080) + if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080)) driver_idx |= Lighting; PS driver = gpuSpriteSpanDrivers[driver_idx]; gpuDrawS(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawS(0x%x)\n",PRIM)); } } break; @@ -544,13 +544,13 @@ void gpuSendPacketFunction(const int PRIM) case 0x79: case 0x7A: case 0x7B: { // Monochrome rectangle (16x16) - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpu_senquack.PacketBuffer.U4[2] = 0x00100010; - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00100010); + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawT(0x%x)\n",PRIM)); } } break; @@ -559,44 +559,44 @@ void gpuSendPacketFunction(const int PRIM) case 0x7D: #ifdef __arm__ /* Notaz 4bit sprites optimization */ - if ((!gpu_senquack.frameskip.skipGPU) && (!(gpu_senquack.GPU_GP1&0x180)) && (!(gpu_senquack.Masking|gpu_senquack.PixelMSB))) + if ((!gpu_unai.frameskip.skipGPU) && (!(gpu_unai.GPU_GP1&0x180)) && (!(gpu_unai.Masking|gpu_unai.PixelMSB))) { - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); gpuDrawS16(packet); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; break; } #endif case 0x7E: case 0x7F: { // Textured rectangle (16x16) - if (!gpu_senquack.frameskip.skipGPU) + if (!gpu_unai.frameskip.skipGPU) { NULL_GPU(); - gpu_senquack.PacketBuffer.U4[3] = 0x00100010; - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - u32 driver_idx = Blending_Mode | gpu_senquack.TEXT_MODE | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>1); + gpu_unai.PacketBuffer.U4[3] = u32_to_le32(0x00100010); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1); //senquack - Only color 808080h-878787h allows skipping lighting calculation: - //if ((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F)) + //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F)) // Strip lower 3 bits of each color and determine if lighting should be used: - if ((gpu_senquack.PacketBuffer.U4[0] & 0xF8F8F8) != 0x808080) + if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080)) driver_idx |= Lighting; PS driver = gpuSpriteSpanDrivers[driver_idx]; gpuDrawS(packet, driver); - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; DO_LOG(("gpuDrawS(0x%x)\n",PRIM)); } } break; case 0x80: // vid -> vid gpuMoveImage(packet); // prim handles updateLace && skip - if ((!gpu_senquack.frameskip.skipCount) && (gpu_senquack.DisplayArea[3] == 480)) // Tekken 3 hack + if ((!gpu_unai.frameskip.skipCount) && (gpu_unai.DisplayArea[3] == 480)) // Tekken 3 hack { - if (!gpu_senquack.frameskip.skipGPU) gpu_senquack.fb_dirty = true; + if (!gpu_unai.frameskip.skipGPU) gpu_unai.fb_dirty = true; } else { - gpu_senquack.fb_dirty = true; + gpu_unai.fb_dirty = true; } DO_LOG(("gpuMoveImage(0x%x)\n",PRIM)); break; @@ -609,13 +609,13 @@ void gpuSendPacketFunction(const int PRIM) DO_LOG(("gpuStoreImage(0x%x)\n",PRIM)); break; case 0xE1 ... 0xE6: { // Draw settings - gpuGP0Cmd_0xEx(gpu_senquack, gpu_senquack.PacketBuffer.U4[0]); + gpuGP0Cmd_0xEx(gpu_unai, le32_to_u32(gpu_unai.PacketBuffer.U4[0])); } break; } } #endif //!USE_GPULIB /////////////////////////////////////////////////////////////////////////////// -// End of code specific to non-gpulib standalone version of gpu_senquack +// End of code specific to non-gpulib standalone version of gpu_unai /////////////////////////////////////////////////////////////////////////////// #endif /* __GPU_UNAI_GPU_COMMAND_H__ */ diff --git a/plugins/gpu_unai/gpu_inner.h b/plugins/gpu_unai/gpu_inner.h index 8cb4bd53..eb209ef4 100644 --- a/plugins/gpu_unai/gpu_inner.h +++ b/plugins/gpu_unai/gpu_inner.h @@ -123,12 +123,8 @@ static inline u16 gpuGouraudColor15bpp(u32 r, u32 g, u32 b) // rectangles) to use the same set of functions. Since tiles are always // monochrome, they simply wouldn't use the extra set of 32 gouraud-shaded // gpuPixelSpanFn functions (TODO?). -// -// NOTE: While the PS1 framebuffer is 16 bit, we use 8-bit pointers here, -// so that pDst can be incremented directly by 'incr' parameter -// without having to shift it before use. template -static u8* gpuPixelSpanFn(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) +static le16_t* gpuPixelSpanFn(le16_t* pDst, uintptr_t data, ptrdiff_t incr, size_t len) { // Blend func can save an operation if it knows uSrc MSB is // unset. For untextured prims, this is always true. @@ -139,6 +135,9 @@ static u8* gpuPixelSpanFn(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) u32 r, g, b; s32 r_incr, g_incr, b_incr; + // Caller counts in bytes, we count in pixels + incr /= 2; + if (CF_GOURAUD) { gcPtr = (GouraudColor*)data; r = gcPtr->r; r_incr = gcPtr->r_incr; @@ -152,15 +151,15 @@ static u8* gpuPixelSpanFn(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) if (!CF_GOURAUD) { // NO GOURAUD if (!CF_MASKCHECK && !CF_BLEND) { - if (CF_MASKSET) { *(u16*)pDst = col | 0x8000; } - else { *(u16*)pDst = col; } + if (CF_MASKSET) { *pDst = u16_to_le16(col | 0x8000); } + else { *pDst = u16_to_le16(col); } } else if (CF_MASKCHECK && !CF_BLEND) { - if (!(*(u16*)pDst & 0x8000)) { - if (CF_MASKSET) { *(u16*)pDst = col | 0x8000; } - else { *(u16*)pDst = col; } + if (!(le16_raw(*pDst) & HTOLE16(0x8000))) { + if (CF_MASKSET) { *pDst = u16_to_le16(col | 0x8000); } + else { *pDst = u16_to_le16(col); } } } else { - uint_fast16_t uDst = *(u16*)pDst; + uint_fast16_t uDst = le16_to_u16(*pDst); if (CF_MASKCHECK) { if (uDst & 0x8000) goto endpixel; } uint_fast16_t uSrc = col; @@ -168,8 +167,8 @@ static u8* gpuPixelSpanFn(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) if (CF_BLEND) uSrc = gpuBlending(uSrc, uDst); - if (CF_MASKSET) { *(u16*)pDst = uSrc | 0x8000; } - else { *(u16*)pDst = uSrc; } + if (CF_MASKSET) { *pDst = u16_to_le16(uSrc | 0x8000); } + else { *pDst = u16_to_le16(uSrc); } } } else @@ -177,16 +176,16 @@ static u8* gpuPixelSpanFn(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) if (!CF_MASKCHECK && !CF_BLEND) { col = gpuGouraudColor15bpp(r, g, b); - if (CF_MASKSET) { *(u16*)pDst = col | 0x8000; } - else { *(u16*)pDst = col; } + if (CF_MASKSET) { *pDst = u16_to_le16(col | 0x8000); } + else { *pDst = u16_to_le16(col); } } else if (CF_MASKCHECK && !CF_BLEND) { col = gpuGouraudColor15bpp(r, g, b); - if (!(*(u16*)pDst & 0x8000)) { - if (CF_MASKSET) { *(u16*)pDst = col | 0x8000; } - else { *(u16*)pDst = col; } + if (!(le16_raw(*pDst) & HTOLE16(0x8000))) { + if (CF_MASKSET) { *pDst = u16_to_le16(col | 0x8000); } + else { *pDst = u16_to_le16(col); } } } else { - uint_fast16_t uDst = *(u16*)pDst; + uint_fast16_t uDst = le16_to_u16(*pDst); if (CF_MASKCHECK) { if (uDst & 0x8000) goto endpixel; } col = gpuGouraudColor15bpp(r, g, b); @@ -199,8 +198,8 @@ static u8* gpuPixelSpanFn(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) if (CF_BLEND) uSrc = gpuBlending(uSrc, uDst); - if (CF_MASKSET) { *(u16*)pDst = uSrc | 0x8000; } - else { *(u16*)pDst = uSrc; } + if (CF_MASKSET) { *pDst = u16_to_le16(uSrc | 0x8000); } + else { *pDst = u16_to_le16(uSrc); } } } @@ -228,7 +227,7 @@ endpixel: return pDst; } -static u8* PixelSpanNULL(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) +static le16_t* PixelSpanNULL(le16_t* pDst, uintptr_t data, ptrdiff_t incr, size_t len) { #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"PixelSpanNULL()\n"); @@ -238,7 +237,7 @@ static u8* PixelSpanNULL(u8* pDst, uintptr_t data, ptrdiff_t incr, size_t len) /////////////////////////////////////////////////////////////////////////////// // PixelSpan (lines) innerloops driver -typedef u8* (*PSD)(u8* dst, uintptr_t data, ptrdiff_t incr, size_t len); +typedef le16_t* (*PSD)(le16_t* dst, uintptr_t data, ptrdiff_t incr, size_t len); const PSD gpuPixelSpanDrivers[64] = { @@ -282,14 +281,26 @@ const PSD gpuPixelSpanDrivers[64] = // GPU Tiles innerloops generator template -static void gpuTileSpanFn(u16 *pDst, u32 count, u16 data) +static void gpuTileSpanFn(le16_t *pDst, u32 count, u16 data) { + le16_t ldata; + if (!CF_MASKCHECK && !CF_BLEND) { - if (CF_MASKSET) { data = data | 0x8000; } - do { *pDst++ = data; } while (--count); + if (CF_MASKSET) + ldata = u16_to_le16(data | 0x8000); + else + ldata = u16_to_le16(data); + do { *pDst++ = ldata; } while (--count); } else if (CF_MASKCHECK && !CF_BLEND) { - if (CF_MASKSET) { data = data | 0x8000; } - do { if (!(*pDst&0x8000)) { *pDst = data; } pDst++; } while (--count); + if (CF_MASKSET) + ldata = u16_to_le16(data | 0x8000); + else + ldata = u16_to_le16(data); + do { + if (!(le16_raw(*pDst) & HTOLE16(0x8000))) + *pDst = ldata; + pDst++; + } while (--count); } else { // Blend func can save an operation if it knows uSrc MSB is @@ -299,16 +310,16 @@ static void gpuTileSpanFn(u16 *pDst, u32 count, u16 data) uint_fast16_t uSrc, uDst; do { - if (CF_MASKCHECK || CF_BLEND) { uDst = *pDst; } - if (CF_MASKCHECK) { if (uDst&0x8000) goto endtile; } + if (CF_MASKCHECK || CF_BLEND) { uDst = le16_to_u16(*pDst); } + if (CF_MASKCHECK) if (uDst&0x8000) { goto endtile; } uSrc = data; if (CF_BLEND) uSrc = gpuBlending(uSrc, uDst); - if (CF_MASKSET) { *pDst = uSrc | 0x8000; } - else { *pDst = uSrc; } + if (CF_MASKSET) { *pDst = u16_to_le16(uSrc | 0x8000); } + else { *pDst = u16_to_le16(uSrc); } //senquack - Did not apply "Silent Hill" mask-bit fix to here. // It is hard to tell from scarce documentation available and @@ -322,7 +333,7 @@ endtile: } } -static void TileNULL(u16 *pDst, u32 count, u16 data) +static void TileNULL(le16_t *pDst, u32 count, u16 data) { #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"TileNULL()\n"); @@ -331,7 +342,7 @@ static void TileNULL(u16 *pDst, u32 count, u16 data) /////////////////////////////////////////////////////////////////////////////// // Tiles innerloops driver -typedef void (*PT)(u16 *pDst, u32 count, u16 data); +typedef void (*PT)(le16_t *pDst, u32 count, u16 data); // Template instantiation helper macros #define TI(cf) gpuTileSpanFn<(cf)> @@ -355,7 +366,7 @@ const PT gpuTileSpanDrivers[32] = { // GPU Sprites innerloops generator template -static void gpuSpriteSpanFn(u16 *pDst, u32 count, u8* pTxt, u32 u0) +static void gpuSpriteSpanFn(le16_t *pDst, u32 count, u8* pTxt, u32 u0) { // Blend func can save an operation if it knows uSrc MSB is unset. // Untextured prims can always skip (source color always comes with MSB=0). @@ -364,13 +375,13 @@ static void gpuSpriteSpanFn(u16 *pDst, u32 count, u8* pTxt, u32 u0) uint_fast16_t uSrc, uDst, srcMSB; bool should_blend; - u32 u0_mask = gpu_senquack.TextureWindow[2]; + u32 u0_mask = gpu_unai.TextureWindow[2]; u8 r5, g5, b5; if (CF_LIGHT) { - r5 = gpu_senquack.r5; - g5 = gpu_senquack.g5; - b5 = gpu_senquack.b5; + r5 = gpu_unai.r5; + g5 = gpu_unai.g5; + b5 = gpu_unai.b5; } if (CF_TEXTMODE==3) { @@ -378,22 +389,22 @@ static void gpuSpriteSpanFn(u16 *pDst, u32 count, u8* pTxt, u32 u0) u0_mask <<= 1; } - const u16 *CBA_; if (CF_TEXTMODE!=3) CBA_ = gpu_senquack.CBA; + const le16_t *CBA_; if (CF_TEXTMODE!=3) CBA_ = gpu_unai.CBA; do { - if (CF_MASKCHECK || CF_BLEND) { uDst = *pDst; } + if (CF_MASKCHECK || CF_BLEND) { uDst = le16_to_u16(*pDst); } if (CF_MASKCHECK) if (uDst&0x8000) { goto endsprite; } if (CF_TEXTMODE==1) { // 4bpp (CLUT) u8 rgb = pTxt[(u0 & u0_mask)>>1]; - uSrc = CBA_[(rgb>>((u0&1)<<2))&0xf]; + uSrc = le16_to_u16(CBA_[(rgb>>((u0&1)<<2))&0xf]); } if (CF_TEXTMODE==2) { // 8bpp (CLUT) - uSrc = CBA_[pTxt[u0 & u0_mask]]; + uSrc = le16_to_u16(CBA_[pTxt[u0 & u0_mask]]); } if (CF_TEXTMODE==3) { // 16bpp - uSrc = *(u16*)(&pTxt[u0 & u0_mask]); + uSrc = le16_to_u16(*(le16_t*)(&pTxt[u0 & u0_mask])); } if (!uSrc) goto endsprite; @@ -410,9 +421,9 @@ static void gpuSpriteSpanFn(u16 *pDst, u32 count, u8* pTxt, u32 u0) if (CF_BLEND && should_blend) uSrc = gpuBlending(uSrc, uDst); - if (CF_MASKSET) { *pDst = uSrc | 0x8000; } - else if (!MSB_PRESERVED && (CF_BLEND || CF_LIGHT)) { *pDst = uSrc | srcMSB; } - else { *pDst = uSrc; } + if (CF_MASKSET) { *pDst = u16_to_le16(uSrc | 0x8000); } + else if (!MSB_PRESERVED && (CF_BLEND || CF_LIGHT)) { *pDst = u16_to_le16(uSrc | srcMSB); } + else { *pDst = u16_to_le16(uSrc); } endsprite: u0 += (CF_TEXTMODE==3) ? 2 : 1; @@ -421,7 +432,7 @@ endsprite: while (--count); } -static void SpriteNULL(u16 *pDst, u32 count, u8* pTxt, u32 u0) +static void SpriteNULL(le16_t *pDst, u32 count, u8* pTxt, u32 u0) { #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"SpriteNULL()\n"); @@ -432,7 +443,7 @@ static void SpriteNULL(u16 *pDst, u32 count, u8* pTxt, u32 u0) /////////////////////////////////////////////////////////////////////////////// // Sprite innerloops driver -typedef void (*PS)(u16 *pDst, u32 count, u8* pTxt, u32 u0); +typedef void (*PS)(le16_t *pDst, u32 count, u8* pTxt, u32 u0); // Template instantiation helper macros #define TI(cf) gpuSpriteSpanFn<(cf)> @@ -485,7 +496,7 @@ const PS gpuSpriteSpanDrivers[256] = { // relevant blend/light headers. // (see README_senquack.txt) template -static void gpuPolySpanFn(const gpu_senquack_t &gpu_senquack, u16 *pDst, u32 count) +static void gpuPolySpanFn(const gpu_unai_t &gpu_unai, le16_t *pDst, u32 count) { // Blend func can save an operation if it knows uSrc MSB is unset. // Untextured prims can always skip this (src color MSB is always 0). @@ -493,14 +504,14 @@ static void gpuPolySpanFn(const gpu_senquack_t &gpu_senquack, u16 *pDst, u32 cou const bool skip_uSrc_mask = MSB_PRESERVED ? (!CF_TEXTMODE) : (!CF_TEXTMODE) || CF_LIGHT; bool should_blend; - u32 bMsk; if (CF_BLITMASK) bMsk = gpu_senquack.blit_mask; + u32 bMsk; if (CF_BLITMASK) bMsk = gpu_unai.blit_mask; if (!CF_TEXTMODE) { if (!CF_GOURAUD) { // UNTEXTURED, NO GOURAUD - const u16 pix15 = gpu_senquack.PixelData; + const u16 pix15 = gpu_unai.PixelData; do { uint_fast16_t uSrc, uDst; @@ -509,7 +520,7 @@ static void gpuPolySpanFn(const gpu_senquack_t &gpu_senquack, u16 *pDst, u32 cou // gravestone text at end of Medieval intro sequence. -senquack //if (CF_BLITMASK) { if ((bMsk>>((((uintptr_t)pDst)>>1)&7))&1) { goto endpolynotextnogou; } } - if (CF_BLEND || CF_MASKCHECK) uDst = *pDst; + if (CF_BLEND || CF_MASKCHECK) uDst = le16_to_u16(*pDst); if (CF_MASKCHECK) { if (uDst&0x8000) { goto endpolynotextnogou; } } uSrc = pix15; @@ -517,8 +528,8 @@ static void gpuPolySpanFn(const gpu_senquack_t &gpu_senquack, u16 *pDst, u32 cou if (CF_BLEND) uSrc = gpuBlending(uSrc, uDst); - if (CF_MASKSET) { *pDst = uSrc | 0x8000; } - else { *pDst = uSrc; } + if (CF_MASKSET) { *pDst = u16_to_le16(uSrc | 0x8000); } + else { *pDst = u16_to_le16(uSrc); } endpolynotextnogou: pDst++; @@ -527,8 +538,8 @@ endpolynotextnogou: else { // UNTEXTURED, GOURAUD - u32 l_gCol = gpu_senquack.gCol; - u32 l_gInc = gpu_senquack.gInc; + u32 l_gCol = gpu_unai.gCol; + u32 l_gInc = gpu_unai.gInc; do { uint_fast16_t uDst, uSrc; @@ -536,7 +547,7 @@ endpolynotextnogou: // See note in above loop regarding CF_BLITMASK //if (CF_BLITMASK) { if ((bMsk>>((((uintptr_t)pDst)>>1)&7))&1) goto endpolynotextgou; } - if (CF_BLEND || CF_MASKCHECK) uDst = *pDst; + if (CF_BLEND || CF_MASKCHECK) uDst = le16_to_u16(*pDst); if (CF_MASKCHECK) { if (uDst&0x8000) goto endpolynotextgou; } if (CF_DITHER) { @@ -555,8 +566,8 @@ endpolynotextnogou: uSrc = gpuBlending(uSrc, uDst); } - if (CF_MASKSET) { *pDst = uSrc | 0x8000; } - else { *pDst = uSrc; } + if (CF_MASKSET) { *pDst = u16_to_le16(uSrc | 0x8000); } + else { *pDst = u16_to_le16(uSrc); } endpolynotextgou: pDst++; @@ -571,15 +582,15 @@ endpolynotextgou: uint_fast16_t uDst, uSrc, srcMSB; - //senquack - note: original UNAI code had gpu_senquack.{u4/v4} packed into + //senquack - note: original UNAI code had gpu_unai.{u4/v4} packed into // one 32-bit unsigned int, but this proved to lose too much accuracy // (pixel drouputs noticeable in NFS3 sky), so now are separate vars. - u32 l_u_msk = gpu_senquack.u_msk; u32 l_v_msk = gpu_senquack.v_msk; - u32 l_u = gpu_senquack.u & l_u_msk; u32 l_v = gpu_senquack.v & l_v_msk; - s32 l_u_inc = gpu_senquack.u_inc; s32 l_v_inc = gpu_senquack.v_inc; + u32 l_u_msk = gpu_unai.u_msk; u32 l_v_msk = gpu_unai.v_msk; + u32 l_u = gpu_unai.u & l_u_msk; u32 l_v = gpu_unai.v & l_v_msk; + s32 l_u_inc = gpu_unai.u_inc; s32 l_v_inc = gpu_unai.v_inc; - const u16* TBA_ = gpu_senquack.TBA; - const u16* CBA_; if (CF_TEXTMODE!=3) CBA_ = gpu_senquack.CBA; + const le16_t* TBA_ = gpu_unai.TBA; + const le16_t* CBA_; if (CF_TEXTMODE!=3) CBA_ = gpu_unai.CBA; u8 r5, g5, b5; u8 r8, g8, b8; @@ -588,17 +599,17 @@ endpolynotextgou: if (CF_LIGHT) { if (CF_GOURAUD) { - l_gInc = gpu_senquack.gInc; - l_gCol = gpu_senquack.gCol; + l_gInc = gpu_unai.gInc; + l_gCol = gpu_unai.gCol; } else { if (CF_DITHER) { - r8 = gpu_senquack.r8; - g8 = gpu_senquack.g8; - b8 = gpu_senquack.b8; + r8 = gpu_unai.r8; + g8 = gpu_unai.g8; + b8 = gpu_unai.b8; } else { - r5 = gpu_senquack.r5; - g5 = gpu_senquack.g5; - b5 = gpu_senquack.b5; + r5 = gpu_unai.r5; + g5 = gpu_unai.g5; + b5 = gpu_unai.b5; } } } @@ -606,7 +617,7 @@ endpolynotextgou: do { if (CF_BLITMASK) { if ((bMsk>>((((uintptr_t)pDst)>>1)&7))&1) goto endpolytext; } - if (CF_MASKCHECK || CF_BLEND) { uDst = *pDst; } + if (CF_MASKCHECK || CF_BLEND) { uDst = le16_to_u16(*pDst); } if (CF_MASKCHECK) if (uDst&0x8000) { goto endpolytext; } //senquack - adapted to work with new 22.10 fixed point routines: @@ -615,15 +626,15 @@ endpolynotextgou: u32 tu=(l_u>>10); u32 tv=(l_v<<1)&(0xff<<11); u8 rgb=((u8*)TBA_)[tv+(tu>>1)]; - uSrc=CBA_[(rgb>>((tu&1)<<2))&0xf]; + uSrc=le16_to_u16(CBA_[(rgb>>((tu&1)<<2))&0xf]); if (!uSrc) goto endpolytext; } if (CF_TEXTMODE==2) { // 8bpp (CLUT) - uSrc = CBA_[(((u8*)TBA_)[(l_u>>10)+((l_v<<1)&(0xff<<11))])]; + uSrc = le16_to_u16(CBA_[(((u8*)TBA_)[(l_u>>10)+((l_v<<1)&(0xff<<11))])]); if (!uSrc) goto endpolytext; } if (CF_TEXTMODE==3) { // 16bpp - uSrc = TBA_[(l_u>>10)+((l_v)&(0xff<<10))]; + uSrc = le16_to_u16(TBA_[(l_u>>10)+((l_v)&(0xff<<10))]); if (!uSrc) goto endpolytext; } @@ -661,9 +672,9 @@ endpolynotextgou: uSrc = gpuBlending(uSrc, uDst); } - if (CF_MASKSET) { *pDst = uSrc | 0x8000; } - else if (!MSB_PRESERVED && (CF_BLEND || CF_LIGHT)) { *pDst = uSrc | srcMSB; } - else { *pDst = uSrc; } + if (CF_MASKSET) { *pDst = u16_to_le16(uSrc | 0x8000); } + else if (!MSB_PRESERVED && (CF_BLEND || CF_LIGHT)) { *pDst = u16_to_le16(uSrc | srcMSB); } + else { *pDst = u16_to_le16(uSrc); } endpolytext: pDst++; l_u = (l_u + l_u_inc) & l_u_msk; @@ -674,7 +685,7 @@ endpolytext: } } -static void PolyNULL(const gpu_senquack_t &gpu_senquack, u16 *pDst, u32 count) +static void PolyNULL(const gpu_unai_t &gpu_unai, le16_t *pDst, u32 count) { #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"PolyNULL()\n"); @@ -683,7 +694,7 @@ static void PolyNULL(const gpu_senquack_t &gpu_senquack, u16 *pDst, u32 count) /////////////////////////////////////////////////////////////////////////////// // Polygon innerloops driver -typedef void (*PP)(const gpu_senquack_t &gpu_senquack, u16 *pDst, u32 count); +typedef void (*PP)(const gpu_unai_t &gpu_unai, le16_t *pDst, u32 count); // Template instantiation helper macros #define TI(cf) gpuPolySpanFn<(cf)> diff --git a/plugins/gpu_unai/gpu_inner_light.h b/plugins/gpu_unai/gpu_inner_light.h index b5d89338..f90e8ec1 100644 --- a/plugins/gpu_unai/gpu_inner_light.h +++ b/plugins/gpu_unai/gpu_inner_light.h @@ -65,7 +65,7 @@ static void SetupLightLUT() for (int i=0; i < 32; ++i) { int val = i * j / 16; if (val > 31) val = 31; - gpu_senquack.LightLUT[(j*32) + i] = val; + gpu_unai.LightLUT[(j*32) + i] = val; } } } @@ -170,9 +170,9 @@ GPU_INLINE u32 gpuLightingRGB24(u32 gCol) //////////////////////////////////////////////////////////////////////////////// GPU_INLINE uint_fast16_t gpuLightingTXTGeneric(uint_fast16_t uSrc, u8 r5, u8 g5, u8 b5) { - return (gpu_senquack.LightLUT[((uSrc&0x7C00)>>5) | b5] << 10) | - (gpu_senquack.LightLUT[ (uSrc&0x03E0) | g5] << 5) | - (gpu_senquack.LightLUT[((uSrc&0x001F)<<5) | r5] ); + return (gpu_unai.LightLUT[((uSrc&0x7C00)>>5) | b5] << 10) | + (gpu_unai.LightLUT[ (uSrc&0x03E0) | g5] << 5) | + (gpu_unai.LightLUT[((uSrc&0x001F)<<5) | r5] ); } @@ -192,9 +192,9 @@ GPU_INLINE uint_fast16_t gpuLightingTXTGeneric(uint_fast16_t uSrc, u8 r5, u8 g5, //////////////////////////////////////////////////////////////////////////////// GPU_INLINE uint_fast16_t gpuLightingTXTGouraudGeneric(uint_fast16_t uSrc, u32 gCol) { - return (gpu_senquack.LightLUT[((uSrc&0x7C00)>>5) | ((gCol>> 5)&0x1F)]<<10) | - (gpu_senquack.LightLUT[ (uSrc&0x03E0) | ((gCol>>16)&0x1F)]<< 5) | - (gpu_senquack.LightLUT[((uSrc&0x001F)<<5) | (gCol>>27) ] ); + return (gpu_unai.LightLUT[((uSrc&0x7C00)>>5) | ((gCol>> 5)&0x1F)]<<10) | + (gpu_unai.LightLUT[ (uSrc&0x03E0) | ((gCol>>16)&0x1F)]<< 5) | + (gpu_unai.LightLUT[((uSrc&0x001F)<<5) | (gCol>>27) ] ); } diff --git a/plugins/gpu_unai/gpu_inner_light_arm.h b/plugins/gpu_unai/gpu_inner_light_arm.h index 550f6b1e..7bd58908 100644 --- a/plugins/gpu_unai/gpu_inner_light_arm.h +++ b/plugins/gpu_unai/gpu_inner_light_arm.h @@ -61,7 +61,7 @@ GPU_INLINE uint_fast16_t gpuLightingTXTARM(uint_fast16_t uSrc, u8 r5, u8 g5, u8 "orr %[out], %[out], %[db], lsl #0x0A \n\t" // out holds 0xmbbbbbgggggrrrrr : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg) : [r5] "r" (r5), [g5] "r" (g5), [b5] "r" (b5), - [lut] "r" (gpu_senquack.LightLUT), [src] "r" (uSrc), "0" (out) + [lut] "r" (gpu_unai.LightLUT), [src] "r" (uSrc), "0" (out) : "cc"); return out; } @@ -103,7 +103,7 @@ GPU_INLINE uint_fast16_t gpuLightingTXTGouraudARM(uint_fast16_t uSrc, u32 gCol) "orr %[out], %[out], %[db], lsl #0x0A \n\t" // out holds 0xmbbbbbgggggrrrrr : [out] "=&r" (out), [db] "=&r" (db), [dg] "=&r" (dg), [gtmp] "=&r" (gtmp) \ - : [gCol] "r" (gCol), [lut] "r" (gpu_senquack.LightLUT), "0" (out), [src] "r" (uSrc) + : [gCol] "r" (gCol), [lut] "r" (gpu_unai.LightLUT), "0" (out), [src] "r" (uSrc) : "cc"); return out; diff --git a/plugins/gpu_unai/gpu_inner_quantization.h b/plugins/gpu_unai/gpu_inner_quantization.h index 6432d031..8a4e9354 100644 --- a/plugins/gpu_unai/gpu_inner_quantization.h +++ b/plugins/gpu_unai/gpu_inner_quantization.h @@ -63,7 +63,7 @@ static void SetupDitheringConstants() // Is 8x8 matrix overkill as a result, can we use 4x4? component &= ~1; - gpu_senquack.DitherMatrix[offset] = (component) + gpu_unai.DitherMatrix[offset] = (component) | (component << 10) | (component << 20); } @@ -85,15 +85,15 @@ static void SetupDitheringConstants() // Where 'X' are fixed-pt bits, '0' is zero-padding, and '-' is don't care //////////////////////////////////////////////////////////////////////////////// template -GPU_INLINE u16 gpuColorQuantization24(u32 uSrc24, const u16 *pDst) +GPU_INLINE u16 gpuColorQuantization24(u32 uSrc24, const le16_t *pDst) { if (DITHER) { - u16 fbpos = (u32)(pDst - gpu_senquack.vram); + uintptr_t fbpos = pDst - gpu_unai.vram; u16 offset = ((fbpos & (0x7 << 10)) >> 7) | (fbpos & 0x7); //clean overflow flags and add - uSrc24 = (uSrc24 & 0x1FF7FDFF) + gpu_senquack.DitherMatrix[offset]; + uSrc24 = (uSrc24 & 0x1FF7FDFF) + gpu_unai.DitherMatrix[offset]; if (uSrc24 & (1<< 9)) uSrc24 |= (0x1FF ); if (uSrc24 & (1<<19)) uSrc24 |= (0x1FF<<10); diff --git a/plugins/gpu_unai/gpu_raster_image.h b/plugins/gpu_unai/gpu_raster_image.h index 8e8064c4..909ca390 100644 --- a/plugins/gpu_unai/gpu_raster_image.h +++ b/plugins/gpu_unai/gpu_raster_image.h @@ -26,25 +26,25 @@ void gpuLoadImage(PtrUnion packet) { u16 x0, y0, w0, h0; - x0 = packet.U2[2] & 1023; - y0 = packet.U2[3] & 511; - w0 = packet.U2[4]; - h0 = packet.U2[5]; + x0 = le16_to_u16(packet.U2[2]) & 1023; + y0 = le16_to_u16(packet.U2[3]) & 511; + w0 = le16_to_u16(packet.U2[4]); + h0 = le16_to_u16(packet.U2[5]); if ((y0 + h0) > FRAME_HEIGHT) { h0 = FRAME_HEIGHT - y0; } - gpu_senquack.dma.FrameToWrite = ((w0)&&(h0)); + gpu_unai.dma.FrameToWrite = ((w0)&&(h0)); - gpu_senquack.dma.px = 0; - gpu_senquack.dma.py = 0; - gpu_senquack.dma.x_end = w0; - gpu_senquack.dma.y_end = h0; - gpu_senquack.dma.pvram = &((u16*)gpu_senquack.vram)[x0+(y0*1024)]; + gpu_unai.dma.px = 0; + gpu_unai.dma.py = 0; + gpu_unai.dma.x_end = w0; + gpu_unai.dma.y_end = h0; + gpu_unai.dma.pvram = &gpu_unai.vram[x0+(y0*1024)]; - gpu_senquack.GPU_GP1 |= 0x08000000; + gpu_unai.GPU_GP1 |= 0x08000000; } #endif // !USE_GPULIB @@ -53,24 +53,24 @@ void gpuLoadImage(PtrUnion packet) void gpuStoreImage(PtrUnion packet) { u16 x0, y0, w0, h0; - x0 = packet.U2[2] & 1023; - y0 = packet.U2[3] & 511; - w0 = packet.U2[4]; - h0 = packet.U2[5]; + x0 = le16_to_u16(packet.U2[2]) & 1023; + y0 = le16_to_u16(packet.U2[3]) & 511; + w0 = le16_to_u16(packet.U2[4]); + h0 = le16_to_u16(packet.U2[5]); if ((y0 + h0) > FRAME_HEIGHT) { h0 = FRAME_HEIGHT - y0; } - gpu_senquack.dma.FrameToRead = ((w0)&&(h0)); + gpu_unai.dma.FrameToRead = ((w0)&&(h0)); - gpu_senquack.dma.px = 0; - gpu_senquack.dma.py = 0; - gpu_senquack.dma.x_end = w0; - gpu_senquack.dma.y_end = h0; - gpu_senquack.dma.pvram = &((u16*)gpu_senquack.vram)[x0+(y0*1024)]; + gpu_unai.dma.px = 0; + gpu_unai.dma.py = 0; + gpu_unai.dma.x_end = w0; + gpu_unai.dma.y_end = h0; + gpu_unai.dma.pvram = &gpu_unai.vram[x0+(y0*1024)]; - gpu_senquack.GPU_GP1 |= 0x08000000; + gpu_unai.GPU_GP1 |= 0x08000000; } #endif // !USE_GPULIB @@ -78,12 +78,12 @@ void gpuMoveImage(PtrUnion packet) { u32 x0, y0, x1, y1; s32 w0, h0; - x0 = packet.U2[2] & 1023; - y0 = packet.U2[3] & 511; - x1 = packet.U2[4] & 1023; - y1 = packet.U2[5] & 511; - w0 = packet.U2[6]; - h0 = packet.U2[7]; + x0 = le16_to_u16(packet.U2[2]) & 1023; + y0 = le16_to_u16(packet.U2[3]) & 511; + x1 = le16_to_u16(packet.U2[4]) & 1023; + y1 = le16_to_u16(packet.U2[5]) & 511; + w0 = le16_to_u16(packet.U2[6]); + h0 = le16_to_u16(packet.U2[7]); if( (x0==x1) && (y0==y1) ) return; if ((w0<=0) || (h0<=0)) return; @@ -94,7 +94,7 @@ void gpuMoveImage(PtrUnion packet) if (((y0+h0)>512)||((x0+w0)>1024)||((y1+h0)>512)||((x1+w0)>1024)) { - u16 *psxVuw=gpu_senquack.vram; + le16_t *psxVuw=gpu_unai.vram; s32 i,j; for(j=0;j>1); lpDst += ((FRAME_OFFSET(x1, y1))>>1); if (w0&1) @@ -127,7 +127,7 @@ void gpuMoveImage(PtrUnion packet) w0>>=1; if (!w0) { do { - *((u16*)lpDst) = *((u16*)lpSrc); + *((le16_t*)lpDst) = *((le16_t*)lpSrc); lpDst += x1; lpSrc += x1; } while (--h0); @@ -135,7 +135,7 @@ void gpuMoveImage(PtrUnion packet) do { x0=w0; do { *lpDst++ = *lpSrc++; } while (--x0); - *((u16*)lpDst) = *((u16*)lpSrc); + *((le16_t*)lpDst) = *((le16_t*)lpSrc); lpDst += x1; lpSrc += x1; } while (--h0); @@ -157,11 +157,11 @@ void gpuMoveImage(PtrUnion packet) void gpuClearImage(PtrUnion packet) { s32 x0, y0, w0, h0; - x0 = packet.S2[2]; - y0 = packet.S2[3]; - w0 = packet.S2[4] & 0x3ff; - h0 = packet.S2[5] & 0x3ff; - + x0 = le16_to_s16(packet.U2[2]); + y0 = le16_to_s16(packet.U2[3]); + w0 = le16_to_s16(packet.U2[4]) & 0x3ff; + h0 = le16_to_s16(packet.U2[5]) & 0x3ff; + w0 += x0; if (x0 < 0) x0 = 0; if (w0 > FRAME_WIDTH) w0 = FRAME_WIDTH; @@ -176,11 +176,11 @@ void gpuClearImage(PtrUnion packet) #ifdef ENABLE_GPU_LOG_SUPPORT fprintf(stdout,"gpuClearImage(x0=%d,y0=%d,w0=%d,h0=%d)\n",x0,y0,w0,h0); #endif - + if (x0&1) { - u16* pixel = (u16*)gpu_senquack.vram + FRAME_OFFSET(x0, y0); - u16 rgb = GPU_RGB16(packet.U4[0]); + le16_t* pixel = gpu_unai.vram + FRAME_OFFSET(x0, y0); + le16_t rgb = u16_to_le16(GPU_RGB16(le32_to_u32(packet.U4[0]))); y0 = FRAME_WIDTH - w0; do { x0=w0; @@ -190,9 +190,9 @@ void gpuClearImage(PtrUnion packet) } else { - u32* pixel = (u32*)gpu_senquack.vram + ((FRAME_OFFSET(x0, y0))>>1); - u32 rgb = GPU_RGB16(packet.U4[0]); - rgb |= (rgb<<16); + le32_t* pixel = (le32_t*)gpu_unai.vram + ((FRAME_OFFSET(x0, y0))>>1); + u32 _rgb = GPU_RGB16(le32_to_u32(packet.U4[0])); + le32_t rgb = u32_to_le32(_rgb | (_rgb << 16)); if (w0&1) { y0 = (FRAME_WIDTH - w0 +1)>>1; @@ -200,7 +200,7 @@ void gpuClearImage(PtrUnion packet) do { x0=w0; do { *pixel++ = rgb; } while (--x0); - *((u16*)pixel) = (u16)rgb; + *((u16*)pixel) = (u16)le32_raw(rgb); pixel += y0; } while (--h0); } diff --git a/plugins/gpu_unai/gpu_raster_line.h b/plugins/gpu_unai/gpu_raster_line.h index 4dd99a6d..a338f974 100644 --- a/plugins/gpu_unai/gpu_raster_line.h +++ b/plugins/gpu_unai/gpu_raster_line.h @@ -69,15 +69,15 @@ void gpuDrawLineF(PtrUnion packet, const PSD gpuPixelSpanDriver) // Clip region: xmax/ymax seem to normally be one *past* the rightmost/ // bottommost pixels of the draw area. Since we render every pixel between // and including both line endpoints, subtract one from xmax/ymax. - const int xmin = gpu_senquack.DrawingArea[0]; - const int ymin = gpu_senquack.DrawingArea[1]; - const int xmax = gpu_senquack.DrawingArea[2] - 1; - const int ymax = gpu_senquack.DrawingArea[3] - 1; + const int xmin = gpu_unai.DrawingArea[0]; + const int ymin = gpu_unai.DrawingArea[1]; + const int xmax = gpu_unai.DrawingArea[2] - 1; + const int ymax = gpu_unai.DrawingArea[3] - 1; - x0 = GPU_EXPANDSIGN(packet.S2[2]) + gpu_senquack.DrawingOffset[0]; - y0 = GPU_EXPANDSIGN(packet.S2[3]) + gpu_senquack.DrawingOffset[1]; - x1 = GPU_EXPANDSIGN(packet.S2[4]) + gpu_senquack.DrawingOffset[0]; - y1 = GPU_EXPANDSIGN(packet.S2[5]) + gpu_senquack.DrawingOffset[1]; + x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2])) + gpu_unai.DrawingOffset[0]; + y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3])) + gpu_unai.DrawingOffset[1]; + x1 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[4])) + gpu_unai.DrawingOffset[0]; + y1 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[5])) + gpu_unai.DrawingOffset[1]; // Always draw top to bottom, so ensure y0 <= y1 if (y0 > y1) { @@ -177,12 +177,9 @@ void gpuDrawLineF(PtrUnion packet, const PSD gpuPixelSpanDriver) err_adjdown; // Subract this from err_term after drawing longer run // Color to draw with (16 bits, highest of which is unset mask bit) - uintptr_t col16 = GPU_RGB16(packet.U4[0]); + uintptr_t col16 = GPU_RGB16(le32_to_u32(packet.U4[0])); - // We use u8 pointers even though PS1 has u16 framebuffer. - // This allows pixel-drawing functions to increment dst pointer - // directly by the passed 'incr' value, not having to shift it first. - u8 *dst = (u8*)gpu_senquack.vram + y0 * dst_stride + x0 * dst_depth; + le16_t *dst = gpu_unai.vram + (y0 * dst_stride + x0 * dst_depth) / FRAME_BYTES_PER_PIXEL; // SPECIAL CASE: Vertical line if (dx == 0) { @@ -278,7 +275,7 @@ void gpuDrawLineF(PtrUnion packet, const PSD gpuPixelSpanDriver) // First run of pixels dst = gpuPixelSpanDriver(dst, col16, incr_major, start_length); - dst += incr_minor; + dst += incr_minor / 2; // Middle runs of pixels while (--minor > 0) { @@ -292,7 +289,7 @@ void gpuDrawLineF(PtrUnion packet, const PSD gpuPixelSpanDriver) } dst = gpuPixelSpanDriver(dst, col16, incr_major, run_length); - dst += incr_minor; + dst += incr_minor / 2; } // Final run of pixels @@ -316,18 +313,18 @@ void gpuDrawLineG(PtrUnion packet, const PSD gpuPixelSpanDriver) // Clip region: xmax/ymax seem to normally be one *past* the rightmost/ // bottommost pixels of the draw area. We'll render every pixel between // and including both line endpoints, so subtract one from xmax/ymax. - const int xmin = gpu_senquack.DrawingArea[0]; - const int ymin = gpu_senquack.DrawingArea[1]; - const int xmax = gpu_senquack.DrawingArea[2] - 1; - const int ymax = gpu_senquack.DrawingArea[3] - 1; + const int xmin = gpu_unai.DrawingArea[0]; + const int ymin = gpu_unai.DrawingArea[1]; + const int xmax = gpu_unai.DrawingArea[2] - 1; + const int ymax = gpu_unai.DrawingArea[3] - 1; - x0 = GPU_EXPANDSIGN(packet.S2[2]) + gpu_senquack.DrawingOffset[0]; - y0 = GPU_EXPANDSIGN(packet.S2[3]) + gpu_senquack.DrawingOffset[1]; - x1 = GPU_EXPANDSIGN(packet.S2[6]) + gpu_senquack.DrawingOffset[0]; - y1 = GPU_EXPANDSIGN(packet.S2[7]) + gpu_senquack.DrawingOffset[1]; + x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2])) + gpu_unai.DrawingOffset[0]; + y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3])) + gpu_unai.DrawingOffset[1]; + x1 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[6])) + gpu_unai.DrawingOffset[0]; + y1 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[7])) + gpu_unai.DrawingOffset[1]; - u32 col0 = packet.U4[0]; - u32 col1 = packet.U4[2]; + u32 col0 = le32_to_u32(packet.U4[0]); + u32 col1 = le32_to_u32(packet.U4[2]); // Always draw top to bottom, so ensure y0 <= y1 if (y0 > y1) { @@ -519,10 +516,7 @@ void gpuDrawLineG(PtrUnion packet, const PSD gpuPixelSpanDriver) gcol.g = g0 << GPU_GOURAUD_FIXED_BITS; gcol.b = b0 << GPU_GOURAUD_FIXED_BITS; - // We use u8 pointers even though PS1 has u16 framebuffer. - // This allows pixel-drawing functions to increment dst pointer - // directly by the passed 'incr' value, not having to shift it first. - u8 *dst = (u8*)gpu_senquack.vram + y0 * dst_stride + x0 * dst_depth; + le16_t *dst = gpu_unai.vram + (y0 * dst_stride + x0 * dst_depth) / FRAME_BYTES_PER_PIXEL; // SPECIAL CASE: Vertical line if (dx == 0) { @@ -547,7 +541,7 @@ void gpuDrawLineG(PtrUnion packet, const PSD gpuPixelSpanDriver) if (db) gcol.b_incr /= dy; } #endif - + gpuPixelSpanDriver(dst, (uintptr_t)&gcol, dst_stride, dy+1); return; } @@ -696,7 +690,7 @@ void gpuDrawLineG(PtrUnion packet, const PSD gpuPixelSpanDriver) // First run of pixels dst = gpuPixelSpanDriver(dst, (uintptr_t)&gcol, incr_major, start_length); - dst += incr_minor; + dst += incr_minor / 2; // Middle runs of pixels while (--minor > 0) { @@ -710,7 +704,7 @@ void gpuDrawLineG(PtrUnion packet, const PSD gpuPixelSpanDriver) } dst = gpuPixelSpanDriver(dst, (uintptr_t)&gcol, incr_major, run_length); - dst += incr_minor; + dst += incr_minor / 2; } // Final run of pixels diff --git a/plugins/gpu_unai/gpu_raster_polygon.h b/plugins/gpu_unai/gpu_raster_polygon.h index 8638ac42..ff6dc00d 100644 --- a/plugins/gpu_unai/gpu_raster_polygon.h +++ b/plugins/gpu_unai/gpu_raster_polygon.h @@ -31,11 +31,19 @@ struct PolyVertex { s32 x, y; // Sign-extended 11-bit X,Y coords union { +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + struct { u8 pad[2], v, u; } tex; // Texture coords (if used) +#else struct { u8 u, v, pad[2]; } tex; // Texture coords (if used) +#endif u32 tex_word; }; union { +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + struct { u8 pad, b, g, r; } col; // 24-bit RGB color (if used) +#else struct { u8 r, g, b, pad; } col; // 24-bit RGB color (if used) +#endif u32 col_word; }; }; @@ -68,30 +76,30 @@ static void polyInitVertexBuffer(PolyVertex *vbuf, const PtrUnion packet, PolyTy vert_stride++; int num_verts = (is_quad) ? 4 : 3; - u32 *ptr; + le32_t *ptr; // X,Y coords, adjusted by draw offsets - s32 x_off = gpu_senquack.DrawingOffset[0]; - s32 y_off = gpu_senquack.DrawingOffset[1]; + s32 x_off = gpu_unai.DrawingOffset[0]; + s32 y_off = gpu_unai.DrawingOffset[1]; ptr = &packet.U4[1]; for (int i=0; i < num_verts; ++i, ptr += vert_stride) { - s16* coord_ptr = (s16*)ptr; - vbuf[i].x = GPU_EXPANDSIGN(coord_ptr[0]) + x_off; - vbuf[i].y = GPU_EXPANDSIGN(coord_ptr[1]) + y_off; + u32 coords = le32_to_u32(*ptr); + vbuf[i].x = GPU_EXPANDSIGN((s16)coords) + x_off; + vbuf[i].y = GPU_EXPANDSIGN((s16)(coords >> 16)) + y_off; } // U,V texture coords (if applicable) if (texturing) { ptr = &packet.U4[2]; for (int i=0; i < num_verts; ++i, ptr += vert_stride) - vbuf[i].tex_word = *ptr; + vbuf[i].tex_word = le32_to_u32(*ptr); } // Colors (if applicable) if (gouraud) { ptr = &packet.U4[0]; for (int i=0; i < num_verts; ++i, ptr += vert_stride) - vbuf[i].col_word = *ptr; + vbuf[i].col_word = le32_to_u32(*ptr); } } @@ -189,8 +197,8 @@ static bool polyUseTriangle(const PolyVertex *vbuf, int tri_num, const PolyVerte // Determine if triangle is completely outside clipping range int xmin, xmax, ymin, ymax; - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; int clipped_lowest_x = Max2(xmin,lowest_x); int clipped_lowest_y = Max2(ymin,lowest_y); int clipped_highest_x = Min2(xmax,highest_x); @@ -218,7 +226,7 @@ gpuDrawPolyF - Flat-shaded, untextured poly void gpuDrawPolyF(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad) { // Set up bgr555 color to be used across calls in inner driver - gpu_senquack.PixelData = GPU_RGB16(packet.U4[0]); + gpu_unai.PixelData = GPU_RGB16(le32_to_u32(packet.U4[0])); PolyVertex vbuf[4]; polyInitVertexBuffer(vbuf, packet, POLYTYPE_F, is_quad); @@ -327,8 +335,8 @@ void gpuDrawPolyF(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad } s32 xmin, xmax, ymin, ymax; - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; if ((ymin - ya) > 0) { x3 += (dx3 * (ymin - ya)); @@ -342,10 +350,10 @@ void gpuDrawPolyF(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad if (loop1 <= 0) continue; - u16* PixelBase = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(0, ya)]; - int li=gpu_senquack.ilace_mask; - int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0); - int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1); + le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)]; + int li=gpu_unai.ilace_mask; + int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); + int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); for (; loop1; --loop1, ya++, PixelBase += FRAME_WIDTH, x3 += dx3, x4 += dx4 ) @@ -357,7 +365,7 @@ void gpuDrawPolyF(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad if ((xmin - xa) > 0) xa = xmin; if (xb > xmax) xb = xmax; if ((xb - xa) > 0) - gpuPolySpanDriver(gpu_senquack, PixelBase + xa, (xb - xa)); + gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa)); } } } while (++cur_pass < total_passes); @@ -369,13 +377,13 @@ gpuDrawPolyFT - Flat-shaded, textured poly void gpuDrawPolyFT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad) { // r8/g8/b8 used if texture-blending & dithering is applied (24-bit light) - gpu_senquack.r8 = packet.U1[0]; - gpu_senquack.g8 = packet.U1[1]; - gpu_senquack.b8 = packet.U1[2]; + gpu_unai.r8 = packet.U1[0]; + gpu_unai.g8 = packet.U1[1]; + gpu_unai.b8 = packet.U1[2]; // r5/g5/b5 used if just texture-blending is applied (15-bit light) - gpu_senquack.r5 = packet.U1[0] >> 3; - gpu_senquack.g5 = packet.U1[1] >> 3; - gpu_senquack.b5 = packet.U1[2] >> 3; + gpu_unai.r5 = packet.U1[0] >> 3; + gpu_unai.g5 = packet.U1[1] >> 3; + gpu_unai.b5 = packet.U1[2] >> 3; PolyVertex vbuf[4]; polyInitVertexBuffer(vbuf, packet, POLYTYPE_FT, is_quad); @@ -452,8 +460,8 @@ void gpuDrawPolyFT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua #endif #endif // Set u,v increments for inner driver - gpu_senquack.u_inc = du4; - gpu_senquack.v_inc = dv4; + gpu_unai.u_inc = du4; + gpu_unai.v_inc = dv4; //senquack - TODO: why is it always going through 2 iterations when sometimes one would suffice here? // (SAME ISSUE ELSEWHERE) @@ -635,8 +643,8 @@ void gpuDrawPolyFT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua } s32 xmin, xmax, ymin, ymax; - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; if ((ymin - ya) > 0) { x3 += dx3 * (ymin - ya); @@ -652,10 +660,10 @@ void gpuDrawPolyFT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua if (loop1 <= 0) continue; - u16* PixelBase = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(0, ya)]; - int li=gpu_senquack.ilace_mask; - int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0); - int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1); + le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)]; + int li=gpu_unai.ilace_mask; + int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); + int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); for (; loop1; --loop1, ++ya, PixelBase += FRAME_WIDTH, x3 += dx3, x4 += dx4, @@ -685,12 +693,12 @@ void gpuDrawPolyFT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua } // Set u,v coords for inner driver - gpu_senquack.u = u4; - gpu_senquack.v = v4; + gpu_unai.u = u4; + gpu_unai.v = v4; if (xb > xmax) xb = xmax; if ((xb - xa) > 0) - gpuPolySpanDriver(gpu_senquack, PixelBase + xa, (xb - xa)); + gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa)); } } } while (++cur_pass < total_passes); @@ -782,7 +790,7 @@ void gpuDrawPolyG(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad #endif #endif // Setup packed Gouraud increment for inner driver - gpu_senquack.gInc = gpuPackGouraudColInc(dr4, dg4, db4); + gpu_unai.gInc = gpuPackGouraudColInc(dr4, dg4, db4); for (s32 loop0 = 2; loop0; loop0--) { if (loop0 == 2) { @@ -979,8 +987,8 @@ void gpuDrawPolyG(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad } s32 xmin, xmax, ymin, ymax; - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; if ((ymin - ya) > 0) { x3 += (dx3 * (ymin - ya)); @@ -997,10 +1005,10 @@ void gpuDrawPolyG(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad if (loop1 <= 0) continue; - u16* PixelBase = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(0, ya)]; - int li=gpu_senquack.ilace_mask; - int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0); - int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1); + le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)]; + int li=gpu_unai.ilace_mask; + int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); + int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); for (; loop1; --loop1, ++ya, PixelBase += FRAME_WIDTH, x3 += dx3, x4 += dx4, @@ -1034,11 +1042,11 @@ void gpuDrawPolyG(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_quad } // Setup packed Gouraud color for inner driver - gpu_senquack.gCol = gpuPackGouraudCol(r4, g4, b4); + gpu_unai.gCol = gpuPackGouraudCol(r4, g4, b4); if (xb > xmax) xb = xmax; if ((xb - xa) > 0) - gpuPolySpanDriver(gpu_senquack, PixelBase + xa, (xb - xa)); + gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa)); } } } while (++cur_pass < total_passes); @@ -1148,9 +1156,9 @@ void gpuDrawPolyGT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua #endif #endif // Set u,v increments and packed Gouraud increment for inner driver - gpu_senquack.u_inc = du4; - gpu_senquack.v_inc = dv4; - gpu_senquack.gInc = gpuPackGouraudColInc(dr4, dg4, db4); + gpu_unai.u_inc = du4; + gpu_unai.v_inc = dv4; + gpu_unai.gInc = gpuPackGouraudColInc(dr4, dg4, db4); for (s32 loop0 = 2; loop0; loop0--) { if (loop0 == 2) { @@ -1372,8 +1380,8 @@ void gpuDrawPolyGT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua } s32 xmin, xmax, ymin, ymax; - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; if ((ymin - ya) > 0) { x3 += (dx3 * (ymin - ya)); @@ -1392,10 +1400,10 @@ void gpuDrawPolyGT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua if (loop1 <= 0) continue; - u16* PixelBase = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(0, ya)]; - int li=gpu_senquack.ilace_mask; - int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0); - int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1); + le16_t* PixelBase = &gpu_unai.vram[FRAME_OFFSET(0, ya)]; + int li=gpu_unai.ilace_mask; + int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); + int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); for (; loop1; --loop1, ++ya, PixelBase += FRAME_WIDTH, x3 += dx3, x4 += dx4, @@ -1438,13 +1446,13 @@ void gpuDrawPolyGT(const PtrUnion packet, const PP gpuPolySpanDriver, u32 is_qua } // Set packed Gouraud color and u,v coords for inner driver - gpu_senquack.u = u4; - gpu_senquack.v = v4; - gpu_senquack.gCol = gpuPackGouraudCol(r4, g4, b4); + gpu_unai.u = u4; + gpu_unai.v = v4; + gpu_unai.gCol = gpuPackGouraudCol(r4, g4, b4); if (xb > xmax) xb = xmax; if ((xb - xa) > 0) - gpuPolySpanDriver(gpu_senquack, PixelBase + xa, (xb - xa)); + gpuPolySpanDriver(gpu_unai, PixelBase + xa, (xb - xa)); } } } while (++cur_pass < total_passes); diff --git a/plugins/gpu_unai/gpu_raster_sprite.h b/plugins/gpu_unai/gpu_raster_sprite.h index ddbad67b..ea4e82f2 100644 --- a/plugins/gpu_unai/gpu_raster_sprite.h +++ b/plugins/gpu_unai/gpu_raster_sprite.h @@ -32,17 +32,17 @@ void gpuDrawS(PtrUnion packet, const PS gpuSpriteSpanDriver) //NOTE: Must 11-bit sign-extend the whole sum here, not just packet X/Y, // or sprites in 1st level of SkullMonkeys disappear when walking right. // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon: - x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_senquack.DrawingOffset[0]); - y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_senquack.DrawingOffset[1]); + x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2]) + gpu_unai.DrawingOffset[0]); + y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3]) + gpu_unai.DrawingOffset[1]); - u32 w = packet.U2[6] & 0x3ff; // Max width is 1023 - u32 h = packet.U2[7] & 0x1ff; // Max height is 511 + u32 w = le16_to_u16(packet.U2[6]) & 0x3ff; // Max width is 1023 + u32 h = le16_to_u16(packet.U2[7]) & 0x1ff; // Max height is 511 x1 = x0 + w; y1 = y0 + h; s32 xmin, xmax, ymin, ymax; - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; u0 = packet.U1[8]; v0 = packet.U1[9]; @@ -59,17 +59,17 @@ void gpuDrawS(PtrUnion packet, const PS gpuSpriteSpanDriver) x1 -= x0; if (x1 <= 0) return; - gpu_senquack.r5 = packet.U1[0] >> 3; - gpu_senquack.g5 = packet.U1[1] >> 3; - gpu_senquack.b5 = packet.U1[2] >> 3; + gpu_unai.r5 = packet.U1[0] >> 3; + gpu_unai.g5 = packet.U1[1] >> 3; + gpu_unai.b5 = packet.U1[2] >> 3; - u16 *Pixel = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(x0, y0)]; - const int li=gpu_senquack.ilace_mask; - const int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0); - const int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1); - unsigned int tmode = gpu_senquack.TEXT_MODE >> 5; - const u32 v0_mask = gpu_senquack.TextureWindow[3]; - u8* pTxt_base = (u8*)gpu_senquack.TBA; + le16_t *Pixel = &gpu_unai.vram[FRAME_OFFSET(x0, y0)]; + const int li=gpu_unai.ilace_mask; + const int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); + const int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); + unsigned int tmode = gpu_unai.TEXT_MODE >> 5; + const u32 v0_mask = gpu_unai.TextureWindow[3]; + u8* pTxt_base = (u8*)gpu_unai.TBA; // Texture is accessed byte-wise, so adjust idx if 16bpp if (tmode == 3) u0 <<= 1; @@ -98,18 +98,18 @@ void gpuDrawS16(PtrUnion packet) //NOTE: Must 11-bit sign-extend the whole sum here, not just packet X/Y, // or sprites in 1st level of SkullMonkeys disappear when walking right. // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon: - x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_senquack.DrawingOffset[0]); - y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_senquack.DrawingOffset[1]); + x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2]) + gpu_unai.DrawingOffset[0]); + y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3]) + gpu_unai.DrawingOffset[1]); - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; u0 = packet.U1[8]; v0 = packet.U1[9]; if (x0 > xmax - 16 || x0 < xmin || - ((u0 | v0) & 15) || !(gpu_senquack.TextureWindow[2] & gpu_senquack.TextureWindow[3] & 8)) { + ((u0 | v0) & 15) || !(gpu_unai.TextureWindow[2] & gpu_unai.TextureWindow[3] & 8)) { // send corner cases to general handler - packet.U4[3] = 0x00100010; + packet.U4[3] = u32_to_le32(0x00100010); gpuDrawS(packet, gpuSpriteSpanFn<0x20>); return; } @@ -124,7 +124,7 @@ void gpuDrawS16(PtrUnion packet) else if (ymax - y0 < 16) h = ymax - y0; - draw_spr16_full(&gpu_senquack.vram[FRAME_OFFSET(x0, y0)], &gpu_senquack.TBA[FRAME_OFFSET(u0/4, v0)], gpu_senquack.CBA, h); + draw_spr16_full(&gpu_unai.vram[FRAME_OFFSET(x0, y0)], &gpu_unai.TBA[FRAME_OFFSET(u0/4, v0)], gpu_unai.CBA, h); } #endif // __arm__ @@ -133,17 +133,17 @@ void gpuDrawT(PtrUnion packet, const PT gpuTileSpanDriver) s32 x0, x1, y0, y1; // This now matches behavior of Mednafen and PCSX Rearmed's gpu_neon: - x0 = GPU_EXPANDSIGN(packet.S2[2] + gpu_senquack.DrawingOffset[0]); - y0 = GPU_EXPANDSIGN(packet.S2[3] + gpu_senquack.DrawingOffset[1]); + x0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[2]) + gpu_unai.DrawingOffset[0]); + y0 = GPU_EXPANDSIGN(le16_to_s16(packet.U2[3]) + gpu_unai.DrawingOffset[1]); - u32 w = packet.U2[4] & 0x3ff; // Max width is 1023 - u32 h = packet.U2[5] & 0x1ff; // Max height is 511 + u32 w = le16_to_u16(packet.U2[4]) & 0x3ff; // Max width is 1023 + u32 h = le16_to_u16(packet.U2[5]) & 0x1ff; // Max height is 511 x1 = x0 + w; y1 = y0 + h; s32 xmin, xmax, ymin, ymax; - xmin = gpu_senquack.DrawingArea[0]; xmax = gpu_senquack.DrawingArea[2]; - ymin = gpu_senquack.DrawingArea[1]; ymax = gpu_senquack.DrawingArea[3]; + xmin = gpu_unai.DrawingArea[0]; xmax = gpu_unai.DrawingArea[2]; + ymin = gpu_unai.DrawingArea[1]; ymax = gpu_unai.DrawingArea[3]; if (y0 < ymin) y0 = ymin; if (y1 > ymax) y1 = ymax; @@ -154,11 +154,11 @@ void gpuDrawT(PtrUnion packet, const PT gpuTileSpanDriver) x1 -= x0; if (x1 <= 0) return; - const u16 Data = GPU_RGB16(packet.U4[0]); - u16 *Pixel = &((u16*)gpu_senquack.vram)[FRAME_OFFSET(x0, y0)]; - const int li=gpu_senquack.ilace_mask; - const int pi=(ProgressiveInterlaceEnabled()?(gpu_senquack.ilace_mask+1):0); - const int pif=(ProgressiveInterlaceEnabled()?(gpu_senquack.prog_ilace_flag?(gpu_senquack.ilace_mask+1):0):1); + const u16 Data = GPU_RGB16(le32_to_u32(packet.U4[0])); + le16_t *Pixel = &gpu_unai.vram[FRAME_OFFSET(x0, y0)]; + const int li=gpu_unai.ilace_mask; + const int pi=(ProgressiveInterlaceEnabled()?(gpu_unai.ilace_mask+1):0); + const int pif=(ProgressiveInterlaceEnabled()?(gpu_unai.prog_ilace_flag?(gpu_unai.ilace_mask+1):0):1); for (; y0 Anything here should be for gpu_senquack's private use. <- +// Header shared between both standalone gpu_unai (gpu.cpp) and new +// gpulib-compatible gpu_unai (gpulib_if.cpp) +// -> Anything here should be for gpu_unai's private use. <- /////////////////////////////////////////////////////////////////////////////// // Compile Options @@ -54,25 +54,67 @@ #define s32 int32_t #define s64 int64_t +typedef struct { + u32 v; +} le32_t; + +typedef struct { + u16 v; +} le16_t; + +static inline u32 le32_to_u32(le32_t le) +{ + return LE32TOH(le.v); +} + +static inline s32 le32_to_s32(le32_t le) +{ + return (int32_t) LE32TOH(le.v); +} + +static inline u32 le32_raw(le32_t le) +{ + return le.v; +} + +static inline le32_t u32_to_le32(u32 u) +{ + return (le32_t){ .v = HTOLE32(u) }; +} + +static inline u16 le16_to_u16(le16_t le) +{ + return LE16TOH(le.v); +} + +static inline s16 le16_to_s16(le16_t le) +{ + return (int16_t) LE16TOH(le.v); +} + +static inline u16 le16_raw(le16_t le) +{ + return le.v; +} + +static inline le16_t u16_to_le16(u16 u) +{ + return (le16_t){ .v = HTOLE16(u) }; +} + union PtrUnion { - u32 *U4; - s32 *S4; - u16 *U2; - s16 *S2; + le32_t *U4; + le16_t *U2; u8 *U1; - s8 *S1; void *ptr; }; union GPUPacket { - u32 U4[16]; - s32 S4[16]; - u16 U2[32]; - s16 S2[32]; + le32_t U4[16]; + le16_t U2[32]; u8 U1[64]; - s8 S1[64]; }; template static inline void SwapValues(T &x, T &y) @@ -133,11 +175,16 @@ static inline s32 GPU_DIV(s32 rs, s32 rt) // 'Unsafe' version of above that doesn't check for div-by-zero #define GPU_FAST_DIV(rs, rt) ((signed)(rs) / (signed)(rt)) -struct gpu_senquack_t { +struct gpu_unai_t { u32 GPU_GP1; GPUPacket PacketBuffer; - u16 *vram; + le16_t *vram; +#ifdef USE_GPULIB + le16_t *downscale_vram; +#endif + //////////////////////////////////////////////////////////////////////////// + // Variables used only by older standalone version of gpu_unai (gpu.cpp) #ifndef USE_GPULIB u32 GPU_GP0; u32 tex_window; // Current texture window vals (set by GP0(E2h) cmd) @@ -146,7 +193,7 @@ struct gpu_senquack_t { bool fb_dirty; // Framebuffer is dirty (according to GPU) // Display status - // NOTE: Standalone older gpu_senquack didn't care about horiz display range + // NOTE: Standalone older gpu_unai didn't care about horiz display range u16 DisplayArea[6]; // [0] : Start of display area (in VRAM) X // [1] : Start of display area (in VRAM) Y // [2] : Display mode resolution HORIZONTAL @@ -159,7 +206,7 @@ struct gpu_senquack_t { struct { s32 px,py; s32 x_end,y_end; - u16* pvram; + le16_t* pvram; u32 *last_dma; // Last dma pointer bool FrameToRead; // Load image in progress bool FrameToWrite; // Store image in progress @@ -175,7 +222,7 @@ struct gpu_senquack_t { bool skipGPU; // Skip GPU primitives } frameskip; #endif - // END of standalone gpu_senquack variables + // END of standalone gpu_unai variables //////////////////////////////////////////////////////////////////////////// u32 TextureWindowCur; // Current setting from last GP0(0xE2) cmd (raw form) @@ -192,8 +239,8 @@ struct gpu_senquack_t { s16 DrawingOffset[2]; // [0] : Drawing offset X (signed) // [1] : Drawing offset Y (signed) - u16* TBA; // Ptr to current texture in VRAM - u16* CBA; // Ptr to current CLUT in VRAM + le16_t* TBA; // Ptr to current texture in VRAM + le16_t* CBA; // Ptr to current CLUT in VRAM //////////////////////////////////////////////////////////////////////////// // Inner Loop parameters @@ -244,39 +291,39 @@ struct gpu_senquack_t { u16 PixelMSB; - gpu_senquack_config_t config; + gpu_unai_config_t config; u8 LightLUT[32*32]; // 5-bit lighting LUT (gpu_inner_light.h) u32 DitherMatrix[64]; // Matrix of dither coefficients }; -static gpu_senquack_t gpu_senquack; +static gpu_unai_t gpu_unai; // Global config that frontend can alter.. Values are read in GPU_init(). // TODO: if frontend menu modifies a setting, add a function that can notify // GPU plugin to use new setting. -gpu_senquack_config_t gpu_senquack_config_ext; +gpu_unai_config_t gpu_unai_config_ext; /////////////////////////////////////////////////////////////////////////////// // Internal inline funcs to get option status: (Allows flexibility) static inline bool LightingEnabled() { - return gpu_senquack.config.lighting; + return gpu_unai.config.lighting; } static inline bool FastLightingEnabled() { - return gpu_senquack.config.fast_lighting; + return gpu_unai.config.fast_lighting; } static inline bool BlendingEnabled() { - return gpu_senquack.config.blending; + return gpu_unai.config.blending; } static inline bool DitheringEnabled() { - return gpu_senquack.config.dithering; + return gpu_unai.config.dithering; } // For now, this is just for development/experimentation purposes.. @@ -295,7 +342,7 @@ static inline bool ProgressiveInterlaceEnabled() // for now when using new gpulib, since it also adds more work in loops. return false; #else - return gpu_senquack.config.prog_ilace; + return gpu_unai.config.prog_ilace; #endif } @@ -305,7 +352,7 @@ static inline bool ProgressiveInterlaceEnabled() // running on higher-res device or a resampling downscaler is enabled. static inline bool PixelSkipEnabled() { - return gpu_senquack.config.pixel_skip || gpu_senquack.config.scale_hires; + return gpu_unai.config.pixel_skip || gpu_unai.config.scale_hires; } static inline bool LineSkipEnabled() diff --git a/plugins/gpu_unai/gpulib_if.cpp b/plugins/gpu_unai/gpulib_if.cpp index 7b148d4f..20794316 100644 --- a/plugins/gpu_unai/gpulib_if.cpp +++ b/plugins/gpu_unai/gpulib_if.cpp @@ -26,8 +26,24 @@ #include #include "../gpulib/gpu.h" +#ifdef THREAD_RENDERING +#include "../gpulib/gpulib_thread_if.h" +#define do_cmd_list real_do_cmd_list +#define renderer_init real_renderer_init +#define renderer_finish real_renderer_finish +#define renderer_sync_ecmds real_renderer_sync_ecmds +#define renderer_update_caches real_renderer_update_caches +#define renderer_flush_queues real_renderer_flush_queues +#define renderer_set_interlace real_renderer_set_interlace +#define renderer_set_config real_renderer_set_config +#define renderer_notify_res_change real_renderer_notify_res_change +#define renderer_notify_update_lace real_renderer_notify_update_lace +#define renderer_sync real_renderer_sync +#define ex_regs scratch_ex_regs +#endif + //#include "port.h" -#include "gpu_senquack.h" +#include "gpu_unai.h" // GPU fixed point math #include "gpu_fixedpoint.h" @@ -52,31 +68,183 @@ ///////////////////////////////////////////////////////////////////////////// +#define DOWNSCALE_VRAM_SIZE (1024 * 512 * 2 * 2 + 4096) + +INLINE void scale_640_to_320(le16_t *dest, const le16_t *src, bool isRGB24) { + size_t uCount = 320; + + if(isRGB24) { + const uint8_t* src8 = (const uint8_t *)src; + uint8_t* dst8 = (uint8_t *)dest; + + do { + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8; + src8 += 4; + } while(--uCount); + } else { + const le16_t* src16 = src; + le16_t* dst16 = dest; + + do { + *dst16++ = *src16; + src16 += 2; + } while(--uCount); + } +} + +INLINE void scale_512_to_320(le16_t *dest, const le16_t *src, bool isRGB24) { + size_t uCount = 64; + + if(isRGB24) { + const uint8_t* src8 = (const uint8_t *)src; + uint8_t* dst8 = (uint8_t *)dest; + + do { + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8; + src8 += 4; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8; + src8 += 4; + *dst8++ = *src8++; + *dst8++ = *src8++; + *dst8++ = *src8; + src8 += 4; + } while(--uCount); + } else { + const le16_t* src16 = src; + le16_t* dst16 = dest; + + do { + *dst16++ = *src16++; + *dst16++ = *src16; + src16 += 2; + *dst16++ = *src16++; + *dst16++ = *src16; + src16 += 2; + *dst16++ = *src16; + src16 += 2; + } while(--uCount); + } +} + +static uint16_t *get_downscale_buffer(int *x, int *y, int *w, int *h, int *vram_h) +{ + le16_t *dest = gpu_unai.downscale_vram; + const le16_t *src = gpu_unai.vram; + bool isRGB24 = (gpu_unai.GPU_GP1 & 0x00200000 ? true : false); + int stride = 1024, dstride = 1024, lines = *h, orig_w = *w; + + // PS1 fb read wraps around (fixes black screen in 'Tobal no. 1') + unsigned int fb_mask = 1024 * 512 - 1; + + if (*h > 240) { + *h /= 2; + stride *= 2; + lines = *h; + + // Ensure start at a non-skipped line + while (*y & gpu_unai.ilace_mask) ++*y; + } + + unsigned int fb_offset_src = (*y * dstride + *x) & fb_mask; + unsigned int fb_offset_dest = fb_offset_src; + + if (*w == 512 || *w == 640) { + *w = 320; + } + + switch(orig_w) { + case 640: + do { + scale_640_to_320(dest + fb_offset_dest, src + fb_offset_src, isRGB24); + fb_offset_src = (fb_offset_src + stride) & fb_mask; + fb_offset_dest = (fb_offset_dest + dstride) & fb_mask; + } while(--lines); + + break; + case 512: + do { + scale_512_to_320(dest + fb_offset_dest, src + fb_offset_src, isRGB24); + fb_offset_src = (fb_offset_src + stride) & fb_mask; + fb_offset_dest = (fb_offset_dest + dstride) & fb_mask; + } while(--lines); + break; + default: + size_t size = isRGB24 ? *w * 3 : *w * 2; + + do { + memcpy(dest + fb_offset_dest, src + fb_offset_src, size); + fb_offset_src = (fb_offset_src + stride) & fb_mask; + fb_offset_dest = (fb_offset_dest + dstride) & fb_mask; + } while(--lines); + break; + } + + return (uint16_t *)gpu_unai.downscale_vram; +} + +static void map_downscale_buffer(void) +{ + if (gpu_unai.downscale_vram) + return; + + gpu_unai.downscale_vram = (le16_t*)gpu.mmap(DOWNSCALE_VRAM_SIZE); + + if (gpu_unai.downscale_vram == NULL) { + fprintf(stderr, "failed to map downscale buffer\n"); + gpu.get_downscale_buffer = NULL; + } + else { + gpu.get_downscale_buffer = get_downscale_buffer; + } +} + +static void unmap_downscale_buffer(void) +{ + if (gpu_unai.downscale_vram == NULL) + return; + + gpu.munmap(gpu_unai.downscale_vram, DOWNSCALE_VRAM_SIZE); + gpu_unai.downscale_vram = NULL; + gpu.get_downscale_buffer = NULL; +} + int renderer_init(void) { - memset((void*)&gpu_senquack, 0, sizeof(gpu_senquack)); - gpu_senquack.vram = (u16*)gpu.vram; + memset((void*)&gpu_unai, 0, sizeof(gpu_unai)); + gpu_unai.vram = (le16_t *)gpu.vram; - // Original standalone gpu_senquack initialized TextureWindow[]. I added the + // Original standalone gpu_unai initialized TextureWindow[]. I added the // same behavior here, since it seems unsafe to leave [2],[3] unset when // using HLE and Rearmed gpu_neon sets this similarly on init. -senquack - gpu_senquack.TextureWindow[0] = 0; - gpu_senquack.TextureWindow[1] = 0; - gpu_senquack.TextureWindow[2] = 255; - gpu_senquack.TextureWindow[3] = 255; + gpu_unai.TextureWindow[0] = 0; + gpu_unai.TextureWindow[1] = 0; + gpu_unai.TextureWindow[2] = 255; + gpu_unai.TextureWindow[3] = 255; //senquack - new vars must be updated whenever texture window is changed: // (used for polygon-drawing in gpu_inner.h, gpu_raster_polygon.h) const u32 fb = FIXED_BITS; // # of fractional fixed-pt bits of u4/v4 - gpu_senquack.u_msk = (((u32)gpu_senquack.TextureWindow[2]) << fb) | ((1 << fb) - 1); - gpu_senquack.v_msk = (((u32)gpu_senquack.TextureWindow[3]) << fb) | ((1 << fb) - 1); + gpu_unai.u_msk = (((u32)gpu_unai.TextureWindow[2]) << fb) | ((1 << fb) - 1); + gpu_unai.v_msk = (((u32)gpu_unai.TextureWindow[3]) << fb) | ((1 << fb) - 1); // Configuration options - gpu_senquack.config = gpu_senquack_config_ext; + gpu_unai.config = gpu_unai_config_ext; //senquack - disabled, not sure this is needed and would require modifying // sprite-span functions, perhaps unnecessarily. No Abe Oddysey hack was // present in latest PCSX4ALL sources we were using. - //gpu_senquack.config.enableAbbeyHack = gpu_senquack_config_ext.abe_hack; - gpu_senquack.ilace_mask = gpu_senquack.config.ilace_force; + //gpu_unai.config.enableAbbeyHack = gpu_unai_config_ext.abe_hack; + gpu_unai.ilace_mask = gpu_unai.config.ilace_force; #ifdef GPU_UNAI_USE_INT_DIV_MULTINV // s_invTable @@ -95,11 +263,16 @@ int renderer_init(void) SetupLightLUT(); SetupDitheringConstants(); + if (gpu_unai.config.scale_hires) { + map_downscale_buffer(); + } + return 0; } void renderer_finish(void) { + unmap_downscale_buffer(); } void renderer_notify_res_change(void) @@ -111,12 +284,12 @@ void renderer_notify_res_change(void) switch (gpu.screen.hres) { - case 512: gpu_senquack.blit_mask = 0xa4; break; // GPU_BlitWWSWWSWS - case 640: gpu_senquack.blit_mask = 0xaa; break; // GPU_BlitWS - default: gpu_senquack.blit_mask = 0; break; + case 512: gpu_unai.blit_mask = 0xa4; break; // GPU_BlitWWSWWSWS + case 640: gpu_unai.blit_mask = 0xaa; break; // GPU_BlitWS + default: gpu_unai.blit_mask = 0; break; } } else { - gpu_senquack.blit_mask = 0; + gpu_unai.blit_mask = 0; } if (LineSkipEnabled()) { @@ -124,23 +297,23 @@ void renderer_notify_res_change(void) // 480 vertical mode, or, optionally, force it for all video modes) if (gpu.screen.vres == 480) { - if (gpu_senquack.config.ilace_force) { - gpu_senquack.ilace_mask = 3; // Only need 1/4 of lines + if (gpu_unai.config.ilace_force) { + gpu_unai.ilace_mask = 3; // Only need 1/4 of lines } else { - gpu_senquack.ilace_mask = 1; // Only need 1/2 of lines + gpu_unai.ilace_mask = 1; // Only need 1/2 of lines } } else { // Vert resolution changed from 480 to lower one - gpu_senquack.ilace_mask = gpu_senquack.config.ilace_force; + gpu_unai.ilace_mask = gpu_unai.config.ilace_force; } } else { - gpu_senquack.ilace_mask = 0; + gpu_unai.ilace_mask = 0; } /* printf("res change hres: %d vres: %d depth: %d ilace_mask: %d\n", - gpu.screen.hres, gpu.screen.vres, gpu.status.rgb24 ? 24 : 15, - gpu_senquack.ilace_mask); + gpu.screen.hres, gpu.screen.vres, (gpu.status & PSX_GPU_STATUS_RGB24) ? 24 : 15, + gpu_unai.ilace_mask); */ } @@ -150,7 +323,7 @@ void renderer_notify_scanout_change(int x, int y) #ifdef USE_GPULIB // Handles GP0 draw settings commands 0xE1...0xE6 -static void gpuGP0Cmd_0xEx(gpu_senquack_t &gpu_senquack, u32 cmd_word) +static void gpuGP0Cmd_0xEx(gpu_unai_t &gpu_unai, u32 cmd_word) { // Assume incoming GP0 command is 0xE1..0xE6, convert to 1..6 u8 num = (cmd_word >> 24) & 7; @@ -158,60 +331,60 @@ static void gpuGP0Cmd_0xEx(gpu_senquack_t &gpu_senquack, u32 cmd_word) switch (num) { case 1: { // GP0(E1h) - Draw Mode setting (aka "Texpage") - u32 cur_texpage = gpu_senquack.GPU_GP1 & 0x7FF; + u32 cur_texpage = gpu_unai.GPU_GP1 & 0x7FF; u32 new_texpage = cmd_word & 0x7FF; if (cur_texpage != new_texpage) { - gpu_senquack.GPU_GP1 = (gpu_senquack.GPU_GP1 & ~0x7FF) | new_texpage; - gpuSetTexture(gpu_senquack.GPU_GP1); + gpu_unai.GPU_GP1 = (gpu_unai.GPU_GP1 & ~0x7FF) | new_texpage; + gpuSetTexture(gpu_unai.GPU_GP1); } } break; case 2: { // GP0(E2h) - Texture Window setting - if (cmd_word != gpu_senquack.TextureWindowCur) { + if (cmd_word != gpu_unai.TextureWindowCur) { static const u8 TextureMask[32] = { 255, 7, 15, 7, 31, 7, 15, 7, 63, 7, 15, 7, 31, 7, 15, 7, 127, 7, 15, 7, 31, 7, 15, 7, 63, 7, 15, 7, 31, 7, 15, 7 }; - gpu_senquack.TextureWindowCur = cmd_word; - gpu_senquack.TextureWindow[0] = ((cmd_word >> 10) & 0x1F) << 3; - gpu_senquack.TextureWindow[1] = ((cmd_word >> 15) & 0x1F) << 3; - gpu_senquack.TextureWindow[2] = TextureMask[(cmd_word >> 0) & 0x1F]; - gpu_senquack.TextureWindow[3] = TextureMask[(cmd_word >> 5) & 0x1F]; - gpu_senquack.TextureWindow[0] &= ~gpu_senquack.TextureWindow[2]; - gpu_senquack.TextureWindow[1] &= ~gpu_senquack.TextureWindow[3]; + gpu_unai.TextureWindowCur = cmd_word; + gpu_unai.TextureWindow[0] = ((cmd_word >> 10) & 0x1F) << 3; + gpu_unai.TextureWindow[1] = ((cmd_word >> 15) & 0x1F) << 3; + gpu_unai.TextureWindow[2] = TextureMask[(cmd_word >> 0) & 0x1F]; + gpu_unai.TextureWindow[3] = TextureMask[(cmd_word >> 5) & 0x1F]; + gpu_unai.TextureWindow[0] &= ~gpu_unai.TextureWindow[2]; + gpu_unai.TextureWindow[1] &= ~gpu_unai.TextureWindow[3]; // Inner loop vars must be updated whenever texture window is changed: const u32 fb = FIXED_BITS; // # of fractional fixed-pt bits of u4/v4 - gpu_senquack.u_msk = (((u32)gpu_senquack.TextureWindow[2]) << fb) | ((1 << fb) - 1); - gpu_senquack.v_msk = (((u32)gpu_senquack.TextureWindow[3]) << fb) | ((1 << fb) - 1); + gpu_unai.u_msk = (((u32)gpu_unai.TextureWindow[2]) << fb) | ((1 << fb) - 1); + gpu_unai.v_msk = (((u32)gpu_unai.TextureWindow[3]) << fb) | ((1 << fb) - 1); - gpuSetTexture(gpu_senquack.GPU_GP1); + gpuSetTexture(gpu_unai.GPU_GP1); } } break; case 3: { // GP0(E3h) - Set Drawing Area top left (X1,Y1) - gpu_senquack.DrawingArea[0] = cmd_word & 0x3FF; - gpu_senquack.DrawingArea[1] = (cmd_word >> 10) & 0x3FF; + gpu_unai.DrawingArea[0] = cmd_word & 0x3FF; + gpu_unai.DrawingArea[1] = (cmd_word >> 10) & 0x3FF; } break; case 4: { // GP0(E4h) - Set Drawing Area bottom right (X2,Y2) - gpu_senquack.DrawingArea[2] = (cmd_word & 0x3FF) + 1; - gpu_senquack.DrawingArea[3] = ((cmd_word >> 10) & 0x3FF) + 1; + gpu_unai.DrawingArea[2] = (cmd_word & 0x3FF) + 1; + gpu_unai.DrawingArea[3] = ((cmd_word >> 10) & 0x3FF) + 1; } break; case 5: { // GP0(E5h) - Set Drawing Offset (X,Y) - gpu_senquack.DrawingOffset[0] = ((s32)cmd_word<<(32-11))>>(32-11); - gpu_senquack.DrawingOffset[1] = ((s32)cmd_word<<(32-22))>>(32-11); + gpu_unai.DrawingOffset[0] = ((s32)cmd_word<<(32-11))>>(32-11); + gpu_unai.DrawingOffset[1] = ((s32)cmd_word<<(32-22))>>(32-11); } break; case 6: { // GP0(E6h) - Mask Bit Setting - gpu_senquack.Masking = (cmd_word & 0x2) << 1; - gpu_senquack.PixelMSB = (cmd_word & 0x1) << 8; + gpu_unai.Masking = (cmd_word & 0x2) << 1; + gpu_unai.PixelMSB = (cmd_word & 0x1) << 8; } break; } } @@ -219,26 +392,27 @@ static void gpuGP0Cmd_0xEx(gpu_senquack_t &gpu_senquack, u32 cmd_word) extern const unsigned char cmd_lengths[256]; -int do_cmd_list(u32 *list, int list_len, int *last_cmd) +int do_cmd_list(u32 *_list, int list_len, int *last_cmd) { u32 cmd = 0, len, i; - u32 *list_start = list; - u32 *list_end = list + list_len; + le32_t *list = (le32_t *)_list; + le32_t *list_start = list; + le32_t *list_end = list + list_len; //TODO: set ilace_mask when resolution changes instead of every time, // eliminate #ifdef below. - gpu_senquack.ilace_mask = gpu_senquack.config.ilace_force; + gpu_unai.ilace_mask = gpu_unai.config.ilace_force; #ifdef HAVE_PRE_ARMV7 /* XXX */ - gpu_senquack.ilace_mask |= !!(gpu.status & PSX_GPU_STATUS_INTERLACE); + gpu_unai.ilace_mask |= !!(gpu.status & PSX_GPU_STATUS_INTERLACE); #endif - if (gpu_senquack.config.scale_hires) { - gpu_senquack.ilace_mask |= !!(gpu.status & PSX_GPU_STATUS_INTERLACE); + if (gpu_unai.config.scale_hires) { + gpu_unai.ilace_mask |= !!(gpu.status & PSX_GPU_STATUS_INTERLACE); } for (; list < list_end; list += 1 + len) { - cmd = *list >> 24; + cmd = le32_to_u32(*list) >> 24; len = cmd_lengths[cmd]; if (list + 1 + len > list_end) { cmd = -1; @@ -246,11 +420,11 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) } #define PRIM cmd - gpu_senquack.PacketBuffer.U4[0] = list[0]; + gpu_unai.PacketBuffer.U4[0] = list[0]; for (i = 1; i <= len; i++) - gpu_senquack.PacketBuffer.U4[i] = list[i]; + gpu_unai.PacketBuffer.U4[i] = list[i]; - PtrUnion packet = { .ptr = (void*)&gpu_senquack.PacketBuffer }; + PtrUnion packet = { .ptr = (void*)&gpu_unai.PacketBuffer }; switch (cmd) { @@ -263,9 +437,9 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x22: case 0x23: { // Monochrome 3-pt poly PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Blending_Mode | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | gpu_unai.PixelMSB ]; gpuDrawPolyF(packet, driver, false); } break; @@ -274,19 +448,19 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x25: case 0x26: case 0x27: { // Textured 3-pt poly - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture(gpu_senquack.PacketBuffer.U4[4] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture(le32_to_u32(gpu_unai.PacketBuffer.U4[4]) >> 16); u32 driver_idx = - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB; + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | gpu_unai.PixelMSB; if (!FastLightingEnabled()) { driver_idx |= Lighting; } else { - if (!((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F))) + if (!((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F))) driver_idx |= Lighting; } @@ -299,9 +473,9 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x2A: case 0x2B: { // Monochrome 4-pt poly PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Blending_Mode | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | gpu_unai.PixelMSB ]; gpuDrawPolyF(packet, driver, true); // is_quad = true } break; @@ -310,19 +484,19 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x2D: case 0x2E: case 0x2F: { // Textured 4-pt poly - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture(gpu_senquack.PacketBuffer.U4[4] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture(le32_to_u32(gpu_unai.PacketBuffer.U4[4]) >> 16); u32 driver_idx = - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | gpu_senquack.PixelMSB; + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | gpu_unai.PixelMSB; if (!FastLightingEnabled()) { driver_idx |= Lighting; } else { - if (!((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F))) + if (!((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F))) driver_idx |= Lighting; } @@ -339,10 +513,10 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) // shouldn't apply. Until the original array of template // instantiation ptrs is fixed, we're stuck with this. (TODO) PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | Blending_Mode | - gpu_senquack.Masking | Blending | 129 | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | 129 | gpu_unai.PixelMSB ]; gpuDrawPolyG(packet, driver, false); } break; @@ -351,13 +525,13 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x35: case 0x36: case 0x37: { // Gouraud-shaded, textured 3-pt poly - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture (gpu_senquack.PacketBuffer.U4[5] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16); PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | ((Lighting)?129:0) | gpu_senquack.PixelMSB + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | ((Lighting)?129:0) | gpu_unai.PixelMSB ]; gpuDrawPolyGT(packet, driver, false); } break; @@ -368,10 +542,10 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x3B: { // Gouraud-shaded 4-pt poly // See notes regarding '129' for 0x30..0x33 further above -senquack PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | Blending_Mode | - gpu_senquack.Masking | Blending | 129 | gpu_senquack.PixelMSB + gpu_unai.Masking | Blending | 129 | gpu_unai.PixelMSB ]; gpuDrawPolyG(packet, driver, true); // is_quad = true } break; @@ -380,13 +554,13 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x3D: case 0x3E: case 0x3F: { // Gouraud-shaded, textured 4-pt poly - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - gpuSetTexture (gpu_senquack.PacketBuffer.U4[5] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + gpuSetTexture (le32_to_u32(gpu_unai.PacketBuffer.U4[5]) >> 16); PP driver = gpuPolySpanDrivers[ - (gpu_senquack.blit_mask?1024:0) | + (gpu_unai.blit_mask?1024:0) | Dithering | - Blending_Mode | gpu_senquack.TEXT_MODE | - gpu_senquack.Masking | Blending | ((Lighting)?129:0) | gpu_senquack.PixelMSB + Blending_Mode | gpu_unai.TEXT_MODE | + gpu_unai.Masking | Blending | ((Lighting)?129:0) | gpu_unai.PixelMSB ]; gpuDrawPolyGT(packet, driver, true); // is_quad = true } break; @@ -396,24 +570,24 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x42: case 0x43: { // Monochrome line // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; PSD driver = gpuPixelSpanDrivers[driver_idx]; gpuDrawLineF(packet, driver); } break; case 0x48 ... 0x4F: { // Monochrome line strip u32 num_vertexes = 1; - u32 *list_position = &(list[2]); + le32_t *list_position = &list[2]; // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; PSD driver = gpuPixelSpanDrivers[driver_idx]; gpuDrawLineF(packet, driver); while(1) { - gpu_senquack.PacketBuffer.U4[1] = gpu_senquack.PacketBuffer.U4[2]; - gpu_senquack.PacketBuffer.U4[2] = *list_position++; + gpu_unai.PacketBuffer.U4[1] = gpu_unai.PacketBuffer.U4[2]; + gpu_unai.PacketBuffer.U4[2] = *list_position++; gpuDrawLineF(packet, driver); num_vertexes++; @@ -421,7 +595,7 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) cmd = -1; goto breakloop; } - if((*list_position & 0xf000f000) == 0x50005000) + if((le32_raw(*list_position) & HTOLE32(0xf000f000)) == HTOLE32(0x50005000)) break; } @@ -433,7 +607,7 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x52: case 0x53: { // Gouraud-shaded line // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; // Index MSB selects Gouraud-shaded PixelSpanDriver: driver_idx |= (1 << 5); PSD driver = gpuPixelSpanDrivers[driver_idx]; @@ -442,10 +616,10 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x58 ... 0x5F: { // Gouraud-shaded line strip u32 num_vertexes = 1; - u32 *list_position = &(list[2]); + le32_t *list_position = &list[2]; // Shift index right by one, as untextured prims don't use lighting - u32 driver_idx = (Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1; + u32 driver_idx = (Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1; // Index MSB selects Gouraud-shaded PixelSpanDriver: driver_idx |= (1 << 5); PSD driver = gpuPixelSpanDrivers[driver_idx]; @@ -453,10 +627,10 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) while(1) { - gpu_senquack.PacketBuffer.U4[0] = gpu_senquack.PacketBuffer.U4[2]; - gpu_senquack.PacketBuffer.U4[1] = gpu_senquack.PacketBuffer.U4[3]; - gpu_senquack.PacketBuffer.U4[2] = *list_position++; - gpu_senquack.PacketBuffer.U4[3] = *list_position++; + gpu_unai.PacketBuffer.U4[0] = gpu_unai.PacketBuffer.U4[2]; + gpu_unai.PacketBuffer.U4[1] = gpu_unai.PacketBuffer.U4[3]; + gpu_unai.PacketBuffer.U4[2] = *list_position++; + gpu_unai.PacketBuffer.U4[3] = *list_position++; gpuDrawLineG(packet, driver); num_vertexes++; @@ -464,7 +638,7 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) cmd = -1; goto breakloop; } - if((*list_position & 0xf000f000) == 0x50005000) + if((le32_raw(*list_position) & HTOLE32(0xf000f000)) == HTOLE32(0x50005000)) break; } @@ -475,7 +649,7 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x61: case 0x62: case 0x63: { // Monochrome rectangle (variable size) - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); } break; @@ -483,24 +657,24 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x65: case 0x66: case 0x67: { // Textured rectangle (variable size) - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - u32 driver_idx = Blending_Mode | gpu_senquack.TEXT_MODE | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>1); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1); //senquack - Only color 808080h-878787h allows skipping lighting calculation: // This fixes Silent Hill running animation on loading screens: // (On PSX, color values 0x00-0x7F darken the source texture's color, // 0x81-FF lighten textures (ultimately clamped to 0x1F), // 0x80 leaves source texture color unchanged, HOWEVER, - // gpu_senquack uses a simple lighting LUT whereby only the upper + // gpu_unai uses a simple lighting LUT whereby only the upper // 5 bits of an 8-bit color are used, so 0x80-0x87 all behave as // 0x80. // // NOTE: I've changed all textured sprite draw commands here and // elsewhere to use proper behavior, but left poly commands // alone, I don't want to slow rendering down too much. (TODO) - //if ((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F)) + //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F)) // Strip lower 3 bits of each color and determine if lighting should be used: - if ((gpu_senquack.PacketBuffer.U4[0] & 0xF8F8F8) != 0x808080) + if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080)) driver_idx |= Lighting; PS driver = gpuSpriteSpanDrivers[driver_idx]; gpuDrawS(packet, driver); @@ -510,8 +684,8 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x69: case 0x6A: case 0x6B: { // Monochrome rectangle (1x1 dot) - gpu_senquack.PacketBuffer.U4[2] = 0x00010001; - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00010001); + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); } break; @@ -519,8 +693,8 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x71: case 0x72: case 0x73: { // Monochrome rectangle (8x8) - gpu_senquack.PacketBuffer.U4[2] = 0x00080008; - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00080008); + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); } break; @@ -528,14 +702,14 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x75: case 0x76: case 0x77: { // Textured rectangle (8x8) - gpu_senquack.PacketBuffer.U4[3] = 0x00080008; - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - u32 driver_idx = Blending_Mode | gpu_senquack.TEXT_MODE | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>1); + gpu_unai.PacketBuffer.U4[3] = u32_to_le32(0x00080008); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1); //senquack - Only color 808080h-878787h allows skipping lighting calculation: - //if ((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F)) + //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F)) // Strip lower 3 bits of each color and determine if lighting should be used: - if ((gpu_senquack.PacketBuffer.U4[0] & 0xF8F8F8) != 0x808080) + if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080)) driver_idx |= Lighting; PS driver = gpuSpriteSpanDrivers[driver_idx]; gpuDrawS(packet, driver); @@ -545,17 +719,17 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) case 0x79: case 0x7A: case 0x7B: { // Monochrome rectangle (16x16) - gpu_senquack.PacketBuffer.U4[2] = 0x00100010; - PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>3)) >> 1]; + gpu_unai.PacketBuffer.U4[2] = u32_to_le32(0x00100010); + PT driver = gpuTileSpanDrivers[(Blending_Mode | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>3)) >> 1]; gpuDrawT(packet, driver); } break; case 0x7C: case 0x7D: #ifdef __arm__ - if ((gpu_senquack.GPU_GP1 & 0x180) == 0 && (gpu_senquack.Masking | gpu_senquack.PixelMSB) == 0) + if ((gpu_unai.GPU_GP1 & 0x180) == 0 && (gpu_unai.Masking | gpu_unai.PixelMSB) == 0) { - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); gpuDrawS16(packet); break; } @@ -563,13 +737,13 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) #endif case 0x7E: case 0x7F: { // Textured rectangle (16x16) - gpu_senquack.PacketBuffer.U4[3] = 0x00100010; - gpuSetCLUT (gpu_senquack.PacketBuffer.U4[2] >> 16); - u32 driver_idx = Blending_Mode | gpu_senquack.TEXT_MODE | gpu_senquack.Masking | Blending | (gpu_senquack.PixelMSB>>1); + gpu_unai.PacketBuffer.U4[3] = u32_to_le32(0x00100010); + gpuSetCLUT (le32_to_u32(gpu_unai.PacketBuffer.U4[2]) >> 16); + u32 driver_idx = Blending_Mode | gpu_unai.TEXT_MODE | gpu_unai.Masking | Blending | (gpu_unai.PixelMSB>>1); //senquack - Only color 808080h-878787h allows skipping lighting calculation: - //if ((gpu_senquack.PacketBuffer.U1[0]>0x5F) && (gpu_senquack.PacketBuffer.U1[1]>0x5F) && (gpu_senquack.PacketBuffer.U1[2]>0x5F)) + //if ((gpu_unai.PacketBuffer.U1[0]>0x5F) && (gpu_unai.PacketBuffer.U1[1]>0x5F) && (gpu_unai.PacketBuffer.U1[2]>0x5F)) // Strip lower 3 bits of each color and determine if lighting should be used: - if ((gpu_senquack.PacketBuffer.U4[0] & 0xF8F8F8) != 0x808080) + if ((le32_raw(gpu_unai.PacketBuffer.U4[0]) & HTOLE32(0xF8F8F8)) != HTOLE32(0x808080)) driver_idx |= Lighting; PS driver = gpuSpriteSpanDrivers[driver_idx]; gpuDrawS(packet, driver); @@ -599,20 +773,20 @@ int do_cmd_list(u32 *list, int list_len, int *last_cmd) goto breakloop; #endif case 0xE1 ... 0xE6: { // Draw settings - gpuGP0Cmd_0xEx(gpu_senquack, gpu_senquack.PacketBuffer.U4[0]); + gpuGP0Cmd_0xEx(gpu_unai, le32_to_u32(gpu_unai.PacketBuffer.U4[0])); } break; } } breakloop: gpu.ex_regs[1] &= ~0x1ff; - gpu.ex_regs[1] |= gpu_senquack.GPU_GP1 & 0x1ff; + gpu.ex_regs[1] |= gpu_unai.GPU_GP1 & 0x1ff; *last_cmd = cmd; return list - list_start; } -void renderer_sync_ecmds(uint32_t *ecmds) +void renderer_sync_ecmds(u32 *ecmds) { int dummy; do_cmd_list(&ecmds[1], 6, &dummy); @@ -631,17 +805,32 @@ void renderer_set_interlace(int enable, int is_odd) } #include "../../frontend/plugin_lib.h" -// Handle any gpulib settings applicable to gpu_senquack: +// Handle any gpulib settings applicable to gpu_unai: void renderer_set_config(const struct rearmed_cbs *cbs) { - gpu_senquack.vram = (u16*)gpu.vram; - gpu_senquack.config.ilace_force = cbs->gpu_unai.ilace_force; - gpu_senquack.config.pixel_skip = cbs->gpu_unai.pixel_skip; - gpu_senquack.config.lighting = cbs->gpu_unai.lighting; - gpu_senquack.config.fast_lighting = cbs->gpu_unai.fast_lighting; - gpu_senquack.config.blending = cbs->gpu_unai.blending; - gpu_senquack.config.dithering = cbs->gpu_unai.dithering; - gpu_senquack.config.scale_hires = cbs->gpu_unai.scale_hires; + gpu_unai.vram = (le16_t *)gpu.vram; + gpu_unai.config.ilace_force = cbs->gpu_unai.ilace_force; + gpu_unai.config.pixel_skip = cbs->gpu_unai.pixel_skip; + gpu_unai.config.lighting = cbs->gpu_unai.lighting; + gpu_unai.config.fast_lighting = cbs->gpu_unai.fast_lighting; + gpu_unai.config.blending = cbs->gpu_unai.blending; + gpu_unai.config.dithering = cbs->gpu_unai.dithering; + gpu_unai.config.scale_hires = cbs->gpu_unai.scale_hires; + + gpu.state.downscale_enable = gpu_unai.config.scale_hires; + if (gpu_unai.config.scale_hires) { + map_downscale_buffer(); + } else { + unmap_downscale_buffer(); + } +} + +void renderer_sync(void) +{ +} + +void renderer_notify_update_lace(int updated) +{ } // vim:shiftwidth=2:expandtab diff --git a/plugins/gpulib/gpu.h b/plugins/gpulib/gpu.h index ab1d23a7..886bb1f5 100644 --- a/plugins/gpulib/gpu.h +++ b/plugins/gpulib/gpu.h @@ -78,6 +78,8 @@ struct psx_gpu { uint32_t enhancement_enable:1; uint32_t enhancement_active:1; uint32_t enhancement_was_active:1; + uint32_t downscale_enable:1; + uint32_t downscale_active:1; uint32_t dims_changed:1; uint32_t *frame_count; uint32_t *hcnt; /* hsync count */ @@ -106,6 +108,8 @@ struct psx_gpu { } frameskip; void *(*get_enhancement_bufer) (int *x, int *y, int *w, int *h, int *vram_h); + uint16_t *(*get_downscale_buffer) + (int *x, int *y, int *w, int *h, int *vram_h); void *(*mmap)(unsigned int size); void (*munmap)(void *ptr, unsigned int size); void (*gpu_state_change)(int what); // psx_gpu_state -- 2.39.5