summaryrefslogtreecommitdiff
path: root/plugins/peopsxgl
diff options
context:
space:
mode:
authorSND\dario86_cp <SND\dario86_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-03-12 18:54:28 +0000
committerSND\dario86_cp <SND\dario86_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97>2011-03-12 18:54:28 +0000
commita58cfdac407bc1d8fedc11acd924b275ba28cc51 (patch)
treeb4c2e08c34ef1bfe0ba947ef8eed931c9a43fc0e /plugins/peopsxgl
parent9bdd06684bcc627c06ddcf4c406f6b48f0dfe389 (diff)
downloadpcsxr-a58cfdac407bc1d8fedc11acd924b275ba28cc51.tar.gz
Commited patch in issue #8171 (by darktjm).
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@64524 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins/peopsxgl')
-rw-r--r--plugins/peopsxgl/draw.c3316
-rw-r--r--plugins/peopsxgl/fps.c795
-rw-r--r--plugins/peopsxgl/gpu.c7056
-rw-r--r--plugins/peopsxgl/gpu.h83
-rw-r--r--plugins/peopsxgl/gpucfg/main.c14
-rw-r--r--plugins/peopsxgl/key.c356
-rw-r--r--plugins/peopsxgl/prim.c1869
-rw-r--r--plugins/peopsxgl/soft.c16816
-rw-r--r--plugins/peopsxgl/texture.c1366
-rw-r--r--plugins/peopsxgl/texture.h137
10 files changed, 15913 insertions, 15895 deletions
diff --git a/plugins/peopsxgl/draw.c b/plugins/peopsxgl/draw.c
index 748824a1..36bcf360 100644
--- a/plugins/peopsxgl/draw.c
+++ b/plugins/peopsxgl/draw.c
@@ -1,1658 +1,1658 @@
-/***************************************************************************
- draw.c - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
-#include "stdafx.h"
-
-#define _IN_DRAW
-
-#include "externals.h"
-#include "gpu.h"
-#include "draw.h"
-#include "prim.h"
-#include "texture.h"
-#include "menu.h"
-
-#if defined(_MACGL)
-// if you use it, you must include it
-#include <OpenGL/gl.h>
-#include <OpenGL/glext.h>
-#endif
-////////////////////////////////////////////////////////////////////////////////////
-// defines
-
-#define SIGNBIT 0x800
-#define S_MASK 0xf000
-#define L_MASK 0xfffff000
-
-// ownscale: some ogl drivers have buggy texture matrix funcs, so it
-// is safer to calc sow/tow ourselves
-
-#ifdef OWNSCALE
-
-#define ST_FACSPRITE 255.99f
-#define ST_BFFACSPRITE 0.5f/256.0f
-#define ST_BFFACSPRITESORT 0.333f/256.0f
-
-#define ST_OFFSET 0.5f/256.0f;
-
-#define ST_FAC 255.99f
-#define ST_BFFAC 0.5f/256.0f
-#define ST_BFFACSORT 0.333f/256.0f
-
-#define ST_FACTRI 255.99f
-#define ST_BFFACTRI 0.5f/256.0f
-#define ST_BFFACTRISORT 0.333f/256.0f
-
-#define ST_FACVRAMX 255.0f
-#define ST_FACVRAM 256.0f
-
-///////////////////////////////////////////////////////////////
-
-#else
-
-#define ST_BFFACSPRITE 0.5f
-#define ST_BFFACSPRITESORT 0.333f
-
-#define ST_BFFAC 0.5f
-#define ST_BFFACSORT 0.333f
-
-#define ST_BFFACTRI 0.5f
-#define ST_BFFACTRISORT 0.333f
-
-#define ST_OFFSET 0.5f;
-
-#endif
-
-////////////////////////////////////////////////////////////////////////////////////
-// draw globals; most will be initialized again later (by config or checks)
-
-#ifdef _WINDOWS
-HDC dcGlobal = NULL;
-HWND hWWindow;
-#endif
-
-BOOL bIsFirstFrame = TRUE;
-
-// resolution/ratio vars
-
-int iResX;
-int iResY;
-BOOL bKeepRatio = FALSE;
-RECT rRatioRect;
-
-// psx mask related vars
-
-BOOL bCheckMask = FALSE;
-int iUseMask = 0;
-int iSetMask = 0;
-unsigned short sSetMask = 0;
-uint32_t lSetMask = 0;
-
-// drawing/coord vars
-
-OGLVertex vertex[4];
-GLubyte gl_ux[8];
-GLubyte gl_vy[8];
-short sprtY,sprtX,sprtH,sprtW;
-
-// drawing options
-
-BOOL bOpaquePass;
-BOOL bAdvancedBlend;
-BOOL bUseLines;
-BOOL bUseAntiAlias;
-int iTexQuality;
-int iUsePalTextures=1;
-BOOL bSnapShot=FALSE;
-BOOL bSmallAlpha=FALSE;
-int iShowFPS=0;
-
-// OGL extension support
-
-int iForceVSync=-1;
-int iUseExts=0;
-BOOL bGLExt;
-BOOL bGLFastMovie=FALSE;
-BOOL bGLSoft;
-BOOL bGLBlend;
-#if defined (_MACGL) // always supported on OSX > 10.4.3
-#define glBlendEquationEXTEx glBlendEquationEXT
-#define glColorTableEXTEx glColorTableEXT
-#else
-PFNGLBLENDEQU glBlendEquationEXTEx=NULL;
-PFNGLCOLORTABLEEXT glColorTableEXTEx=NULL;
-#endif
-// gfx card buffer infos
-
-int iDepthFunc=0;
-int iZBufferDepth=0;
-GLbitfield uiBufferBits=GL_COLOR_BUFFER_BIT;
-
-////////////////////////////////////////////////////////////////////////
-// Set OGL pixel format
-////////////////////////////////////////////////////////////////////////
-
-#ifdef _WINDOWS
-BOOL bSetupPixelFormat(HDC hDC)
-{
- int pixelformat;
- static PIXELFORMATDESCRIPTOR pfd =
- {
- sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
- 1, // version number
- PFD_DRAW_TO_WINDOW | // support window
- PFD_SUPPORT_OPENGL | // support OpenGL
- PFD_DOUBLEBUFFER, // double buffered
- PFD_TYPE_RGBA, // RGBA type
- 16, // 16-bit color depth (adjusted later)
- 0, 0, 0, 0, 0, 0, // color bits ignored
- 0, // no alpha buffer
- 0, // shift bit ignored
- 0, // no accumulation buffer
- 0, 0, 0, 0, // accum bits ignored
- 0, // z-buffer
- 0,
- 0, // no auxiliary buffer
- PFD_MAIN_PLANE, // main layer
- 0, // reserved
- 0, 0, 0 // layer masks ignored
- };
-
- pfd.cColorBits=iColDepth; // set user color depth
- pfd.cDepthBits=iZBufferDepth; // set user zbuffer (by psx mask)
-
- if((pixelformat=ChoosePixelFormat(hDC,&pfd))==0)
- {
- MessageBox(NULL,"ChoosePixelFormat failed","Error",MB_OK);
- return FALSE;
- }
-
- if(SetPixelFormat(hDC,pixelformat, &pfd)==FALSE)
- {
- MessageBox(NULL,"SetPixelFormat failed","Error",MB_OK);
- return FALSE;
- }
-
- return TRUE;
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////
-// Get extension infos (f.e. pal textures / packed pixels)
-////////////////////////////////////////////////////////////////////////
-
-void GetExtInfos(void)
-{
- BOOL bPacked=FALSE; // default: no packed pixel support
-
- bGLExt=FALSE; // default: no extensions
- bGLFastMovie=FALSE;
-
- if(strstr((char *)glGetString(GL_EXTENSIONS), // packed pixels available?
- "GL_EXT_packed_pixels"))
- bPacked=TRUE; // -> ok
-
- if(bPacked && bUse15bitMdec) // packed available and 15bit mdec wanted?
- bGLFastMovie=TRUE; // -> ok
-
- if(bPacked && (iTexQuality==1 || iTexQuality==2)) // packed available and 16 bit texture format?
- {
- bGLFastMovie=TRUE; // -> ok
- bGLExt=TRUE;
- }
-
- if(iUseExts && // extension support wanted?
- (strstr((char *)glGetString(GL_EXTENSIONS),
- "GL_EXT_texture_edge_clamp") ||
- strstr((char *)glGetString(GL_EXTENSIONS), // -> check clamp support, if yes: use it
- "GL_SGIS_texture_edge_clamp")))
- iClampType=GL_TO_EDGE_CLAMP;
- else iClampType=GL_CLAMP;
-
-#if !defined (_MACGL) // OSX > 10.4.3 defines this
- glColorTableEXTEx=(PFNGLCOLORTABLEEXT)NULL; // init ogl palette func pointer
-#endif
-
-#ifndef __sun
- if(iGPUHeight!=1024 && // no pal textures in ZN mode (height=1024)!
- strstr((char *)glGetString(GL_EXTENSIONS), // otherwise: check ogl support
- "GL_EXT_paletted_texture"))
- {
- iUsePalTextures=1; // -> wow, supported, get func pointer
-
-#ifdef _WINDOWS
- glColorTableEXTEx=(PFNGLCOLORTABLEEXT)wglGetProcAddress("glColorTableEXT");
-#elif defined (_MACGL)
- // no prob, done already in OSX > 10.4.3
-#else
- glColorTableEXTEx=(PFNGLCOLORTABLEEXT)glXGetProcAddress("glColorTableEXT");
-#endif
-
- if(glColorTableEXTEx==NULL) iUsePalTextures=0; // -> ha, cheater... no func, no support
-
- }
- else iUsePalTextures=0;
-#else
- iUsePalTextures=0;
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////
-// Setup some stuff depending on user settings or in-game toggle
-////////////////////////////////////////////////////////////////////////
-
-void SetExtGLFuncs(void)
-{
- //----------------------------------------------------//
-
- SetFixes(); // update fix infos
-
- //----------------------------------------------------//
-
-#ifdef _WINDOWS
- if((iForceVSync>=0) && // force vsync?
- strstr((char *)glGetString(GL_EXTENSIONS), // and extension available?
- "WGL_EXT_swap_control"))
- {
- PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT=
- (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT");
-
- if(wglSwapIntervalEXT) wglSwapIntervalEXT(iForceVSync);
- }
-#endif
-#ifdef _MACGL
- SetVSync(iForceVSync);
-#endif
- if(iUseExts && !(dwActFixes&1024) && // extensions wanted? and not turned off by game fix?
- strstr((char *)glGetString(GL_EXTENSIONS), // and blend_subtract available?
- "GL_EXT_blend_subtract"))
- { // -> get ogl blend function pointer
-#ifdef _WINDOWS
- glBlendEquationEXTEx=(PFNGLBLENDEQU)wglGetProcAddress("glBlendEquationEXT");
-#elif defined(_MACGL)
- // no prob, OSX > 10.4.3 has this
-#else
- glBlendEquationEXTEx=(PFNGLBLENDEQU)glXGetProcAddress("glBlendEquationEXT");
-#endif
- }
- else // no subtract blending?
- {
- if(glBlendEquationEXTEx) // -> change to additive blending (if subract was active)
- glBlendEquationEXTEx(FUNC_ADD_EXT);
-#if !defined(_MACGL) // BTW, why set to null? strange...
- glBlendEquationEXTEx=(PFNGLBLENDEQU)NULL; // -> no more blend function pointer
-#endif
- }
-
- //----------------------------------------------------//
-
- if(iUseExts && bAdvancedBlend && // advanced blending wanted ?
- strstr((char *)glGetString(GL_EXTENSIONS), // and extension avail?
- "GL_EXT_texture_env_combine"))
- {
- bUseMultiPass=FALSE;bGLBlend=TRUE; // -> no need for 2 passes, perfect
-
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
- glTexEnvf(GL_TEXTURE_ENV, COMBINE_RGB_EXT, GL_MODULATE);
- glTexEnvf(GL_TEXTURE_ENV, COMBINE_ALPHA_EXT, GL_MODULATE);
- glTexEnvf(GL_TEXTURE_ENV, RGB_SCALE_EXT, 2.0f);
- }
- else // no advanced blending wanted/available:
- {
- if(bAdvancedBlend) bUseMultiPass=TRUE; // -> pseudo-advanced with 2 passes
- else bUseMultiPass=FALSE; // -> or simple 'bright color' mode
- bGLBlend=FALSE; // -> no ext blending!
-
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- }
-
- //----------------------------------------------------//
- // init standard tex quality 0-2, and big alpha mode 3
-
- if(!(dwActFixes&0x4000) && iFilterType && iTexQuality>=3)
- bSmallAlpha=TRUE;
- else bSmallAlpha=FALSE;
-
- if(bOpaquePass) // opaque mode?
- {
- if(dwActFixes&32)
- {
- TCF[0]=CP8RGBA_0;
- PalTexturedColourFn=CP8RGBA; // -> init col func
- }
- else
- {
- TCF[0]=XP8RGBA_0;
- PalTexturedColourFn=XP8RGBA; // -> init col func
- }
-
- TCF[1]=XP8RGBA_1;
- glAlphaFunc(GL_GREATER,0.49f);
- }
- else // no opaque mode?
- {
- TCF[0]=TCF[1]=P8RGBA;
- PalTexturedColourFn=P8RGBA; // -> init col func
- glAlphaFunc(GL_NOTEQUAL,0); // --> set alpha func
- }
-
- //----------------------------------------------------//
-
- LoadSubTexFn=LoadSubTexturePageSort; // init load tex ptr
-
- giWantedFMT=GL_RGBA; // init ogl tex format
-
- switch(iTexQuality) // -> quality:
- {
- //--------------------------------------------------//
- case 0: // -> don't care
- giWantedRGBA=4;
- giWantedTYPE=GL_UNSIGNED_BYTE;
- break;
- //--------------------------------------------------//
- case 1: // -> R4G4B4A4
- if(bGLExt)
- {
- giWantedRGBA=GL_RGBA4;
- giWantedTYPE=GL_UNSIGNED_SHORT_4_4_4_4_EXT;
- LoadSubTexFn=LoadPackedSubTexturePageSort;
- if(bOpaquePass)
- {
- if(dwActFixes&32) PTCF[0]=CP4RGBA_0;
- else PTCF[0]=XP4RGBA_0;
- PTCF[1]=XP4RGBA_1;
- }
- else
- {
- PTCF[0]=PTCF[1]=P4RGBA;
- }
- }
- else
- {
- giWantedRGBA=GL_RGBA4;
- giWantedTYPE=GL_UNSIGNED_BYTE;
- }
- break;
- //--------------------------------------------------//
- case 2: // -> R5B5G5A1
- if(bGLExt)
- {
- giWantedRGBA=GL_RGB5_A1;
- giWantedTYPE=GL_UNSIGNED_SHORT_5_5_5_1_EXT;
- LoadSubTexFn=LoadPackedSubTexturePageSort;
- if(bOpaquePass)
- {
- if(dwActFixes&32) PTCF[0]=CP5RGBA_0;
- else PTCF[0]=XP5RGBA_0;
- PTCF[1]=XP5RGBA_1;
- }
- else
- {
- PTCF[0]=PTCF[1]=P5RGBA;
- }
- }
- else
- {
- giWantedRGBA=GL_RGB5_A1;giWantedTYPE=GL_UNSIGNED_BYTE;
- }
- break;
- //--------------------------------------------------//
- case 3: // -> R8G8B8A8
- giWantedRGBA=GL_RGBA8;
- giWantedTYPE=GL_UNSIGNED_BYTE;
-
- if(bSmallAlpha)
- {
- if(bOpaquePass) // opaque mode?
- {
- if(dwActFixes&32) {TCF[0]=CP8RGBAEx_0;PalTexturedColourFn=CP8RGBAEx;}
- else {TCF[0]=XP8RGBAEx_0;PalTexturedColourFn=XP8RGBAEx;}
- TCF[1]=XP8RGBAEx_1;
- }
- }
-
- break;
- //--------------------------------------------------//
- case 4: // -> R8G8B8A8
- giWantedRGBA = GL_RGBA8;
- giWantedTYPE = GL_UNSIGNED_BYTE;
-
- if(strstr((char *)glGetString(GL_EXTENSIONS), // and extension avail?
- "GL_EXT_bgra"))
- {
- giWantedFMT = GL_BGRA_EXT;
-
- if(bOpaquePass) // opaque mode?
- {
- if(bSmallAlpha)
- {
- if(dwActFixes&32) {TCF[0]=CP8BGRAEx_0;PalTexturedColourFn=CP8RGBAEx;}
- else {TCF[0]=XP8BGRAEx_0;PalTexturedColourFn=XP8RGBAEx;}
- TCF[1]=XP8BGRAEx_1;
- }
- else
- {
- if(dwActFixes&32) {TCF[0]=CP8BGRA_0;PalTexturedColourFn=CP8RGBA;}
- else {TCF[0]=XP8BGRA_0;PalTexturedColourFn=XP8RGBA;}
- TCF[1]=XP8BGRA_1;
- }
- }
- else // no opaque mode?
- {
- TCF[0]=TCF[1]=P8BGRA; // -> init col func
- }
- }
- else
- {
- iTexQuality=3;
- if(bSmallAlpha)
- {
- if(bOpaquePass) // opaque mode?
- {
- if(dwActFixes&32) {TCF[0]=CP8RGBAEx_0;PalTexturedColourFn=CP8RGBAEx;}
- else {TCF[0]=XP8RGBAEx_0;PalTexturedColourFn=XP8RGBAEx;}
- TCF[1]=XP8RGBAEx_1;
- }
- }
- }
-
- break;
- //--------------------------------------------------//
- }
-
- bBlendEnable=FALSE; // init blending: off
- glDisable(GL_BLEND);
-
- SetScanTrans(); // init scan lines (if wanted)
-}
-
-////////////////////////////////////////////////////////////////////////
-// setup scan lines
-////////////////////////////////////////////////////////////////////////
-
-#define R_TSP 0x00,0x45,0x00,0xff
-#define G_TSP 0x00,0x00,0x45,0xff
-#define B_TSP 0x45,0x00,0x00,0xff
-#define O_TSP 0x45,0x45,0x45,0xff
-#define N_TSP 0x00,0x00,0x00,0xff
-
-GLuint gTexScanName=0;
-
-GLubyte texscan[4][16]=
-{
-{R_TSP, G_TSP, B_TSP, N_TSP},
-{O_TSP, N_TSP, O_TSP, N_TSP},
-{B_TSP, N_TSP, R_TSP, G_TSP},
-{O_TSP, N_TSP, O_TSP, N_TSP}
-};
-
-void CreateScanLines(void)
-{
- if(iUseScanLines)
- {
- int y;
- if(iScanBlend<0) // special scan mask mode
- {
- glGenTextures(1, &gTexScanName);
- glBindTexture(GL_TEXTURE_2D, gTexScanName);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, 4, 4, 4, 0,GL_RGBA, GL_UNSIGNED_BYTE, texscan);
- }
- else // otherwise simple lines in a display list
- {
- uiScanLine=glGenLists(1);
- glNewList(uiScanLine,GL_COMPILE);
- #ifdef _MACGL
- // not mac specific, just commenting out to be friendly
- // use it if you like
- // this draws anti-aliased lines with user-chosen color
- glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);
- glEnable(GL_BLEND | GL_LINE_SMOOTH);
- glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
- glColor4f(iScanlineColor[0],iScanlineColor[1],iScanlineColor[2],iScanlineColor[3]);
- glBegin(GL_LINES);
- for(y=0;y<iResY;y+=2)
- {
- glVertex2f(0,y);
- glVertex2f(iResX,y);
- }
- glEnd();
- glPopAttrib();
- #else
- for(y=0;y<iResY;y+=2)
- {
- glBegin(GL_QUADS);
- glVertex2f(0,y);
- glVertex2f(iResX,y);
- glVertex2f(iResX,y+1);
- glVertex2f(0,y+1);
- glEnd();
- }
-
- #endif
- glEndList();
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// Initialize OGL
-////////////////////////////////////////////////////////////////////////
-
-#ifdef _WINDOWS
-HGLRC GLCONTEXT=NULL;
-#endif
-
-int GLinitialize()
-{
-#ifdef _WINDOWS
- HGLRC objectRC;
- // init
- dcGlobal = GetDC(hWWindow); // FIRST: dc/rc stuff
- objectRC = wglCreateContext(dcGlobal);
- GLCONTEXT=objectRC;
- wglMakeCurrent(dcGlobal, objectRC);
- // CheckWGLExtensions(dcGlobal);
- if(bWindowMode) ReleaseDC(hWWindow,dcGlobal); // win mode: release dc again
-#endif
-#if defined (_MACGL)
- BringContextForward();
-#endif
- glViewport(rRatioRect.left, // init viewport by ratio rect
- iResY-(rRatioRect.top+rRatioRect.bottom),
- rRatioRect.right,
- rRatioRect.bottom);
-
- glScissor(0, 0, iResX, iResY); // init clipping (fullscreen)
- glEnable(GL_SCISSOR_TEST);
-
-#ifndef OWNSCALE
- glMatrixMode(GL_TEXTURE); // init psx tex sow and tow if not "ownscale"
- glLoadIdentity();
- glScalef(1.0f/255.99f,1.0f/255.99f,1.0f); // geforce precision hack
-#endif
-
- glMatrixMode(GL_PROJECTION); // init projection with psx resolution
- glLoadIdentity();
- glOrtho(0,PSXDisplay.DisplayMode.x,
- PSXDisplay.DisplayMode.y, 0, -1, 1);
-
- if(iZBufferDepth) // zbuffer?
- {
- uiBufferBits=GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT;
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_ALWAYS);
- iDepthFunc=1;
- }
- else // no zbuffer?
- {
- uiBufferBits=GL_COLOR_BUFFER_BIT;
- glDisable(GL_DEPTH_TEST);
- }
-
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // first buffer clear
- glClear(uiBufferBits);
-
- if(bUseLines) // funny lines
- {
- glPolygonMode(GL_FRONT, GL_LINE);
- glPolygonMode(GL_BACK, GL_LINE);
- }
- else // or the real filled thing
- {
- glPolygonMode(GL_FRONT, GL_FILL);
- glPolygonMode(GL_BACK, GL_FILL);
- }
-
- MakeDisplayLists(); // lists for menu/opaque
- GetExtInfos(); // get ext infos
- SetExtGLFuncs(); // init all kind of stuff (tex function pointers)
-
- glEnable(GL_ALPHA_TEST); // wanna alpha test
-
- if(!bUseAntiAlias) // no anti-alias (default)
- {
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_POLYGON_SMOOTH);
- glDisable(GL_POINT_SMOOTH);
- }
- else // wanna try it? glitches galore...
- {
- glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_POLYGON_SMOOTH);
- glEnable(GL_POINT_SMOOTH);
- glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
- glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
- glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
- }
-
- ubGloAlpha=127; // init some drawing vars
- ubGloColAlpha=127;
- TWin.UScaleFactor = 1;
- TWin.VScaleFactor = 1;
- bDrawMultiPass=FALSE;
- bTexEnabled=FALSE;
- bUsingTWin=FALSE;
-
- if(bDrawDither) glEnable(GL_DITHER); // dither mode
- else glDisable(GL_DITHER);
-
- glDisable(GL_FOG); // turn all (currently) unused modes off
- glDisable(GL_LIGHTING);
- glDisable(GL_LOGIC_OP);
- glDisable(GL_STENCIL_TEST);
- glDisable(GL_TEXTURE_1D);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_CULL_FACE);
-
- glPixelTransferi(GL_RED_SCALE, 1); // to be sure:
- glPixelTransferi(GL_RED_BIAS, 0); // init more OGL vals
- glPixelTransferi(GL_GREEN_SCALE, 1);
- glPixelTransferi(GL_GREEN_BIAS, 0);
- glPixelTransferi(GL_BLUE_SCALE, 1);
- glPixelTransferi(GL_BLUE_BIAS, 0);
- glPixelTransferi(GL_ALPHA_SCALE, 1);
- glPixelTransferi(GL_ALPHA_BIAS, 0);
-
-#ifdef _WINDOWS
- // detect Windows hw/sw mode (just for info)
- if(!strcmp("Microsoft Corporation",(LPTSTR)glGetString(GL_VENDOR)) &&
- !strcmp("GDI Generic", (LPTSTR)glGetString(GL_RENDERER)))
- bGLSoft=TRUE;
- else bGLSoft=FALSE;
-#endif
-
- glFlush(); // we are done...
- glFinish();
-
- CreateScanLines(); // setup scanline stuff (if wanted)
-
- CheckTextureMemory(); // check available tex memory
-
- if(bKeepRatio) SetAspectRatio(); // set ratio
-
- if(iShowFPS) // user wants FPS display on startup?
- {
- ulKeybits|=KEY_SHOWFPS; // -> ok, turn display on
- szDispBuf[0]=0;
- BuildDispMenu(0);
- }
-
- bIsFirstFrame = FALSE; // we have survived the first frame :)
-
- return 0;
-}
-
-////////////////////////////////////////////////////////////////////////
-// clean up OGL stuff
-////////////////////////////////////////////////////////////////////////
-
-void GLcleanup()
-{
- KillDisplayLists(); // bye display lists
-
- if(iUseScanLines) // scanlines used?
- {
- if(iScanBlend<0)
- {
- if(gTexScanName!=0) // some scanline tex?
- glDeleteTextures(1, &gTexScanName); // -> delete it
- gTexScanName=0;
- }
- else glDeleteLists(uiScanLine,1); // otherwise del scanline display list
- }
-
- CleanupTextureStore(); // bye textures
-
-#ifdef _WINDOWS
- wglMakeCurrent(NULL, NULL); // bye context
- if(GLCONTEXT) wglDeleteContext(GLCONTEXT);
- if(!bWindowMode && dcGlobal)
- ReleaseDC(hWWindow,dcGlobal);
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////
-// Offset stuff
-////////////////////////////////////////////////////////////////////////
-
-// please note: it is hardly do-able in a hw/accel plugin to get the
-// real psx polygon coord mapping right... the following
-// works not to bad with many games, though
-
-__inline BOOL CheckCoord4()
-{
- if(lx0<0)
- {
- if(((lx1-lx0)>CHKMAX_X) ||
- ((lx2-lx0)>CHKMAX_X))
- {
- if(lx3<0)
- {
- if((lx1-lx3)>CHKMAX_X) return TRUE;
- if((lx2-lx3)>CHKMAX_X) return TRUE;
- }
- }
- }
- if(lx1<0)
- {
- if((lx0-lx1)>CHKMAX_X) return TRUE;
- if((lx2-lx1)>CHKMAX_X) return TRUE;
- if((lx3-lx1)>CHKMAX_X) return TRUE;
- }
- if(lx2<0)
- {
- if((lx0-lx2)>CHKMAX_X) return TRUE;
- if((lx1-lx2)>CHKMAX_X) return TRUE;
- if((lx3-lx2)>CHKMAX_X) return TRUE;
- }
- if(lx3<0)
- {
- if(((lx1-lx3)>CHKMAX_X) ||
- ((lx2-lx3)>CHKMAX_X))
- {
- if(lx0<0)
- {
- if((lx1-lx0)>CHKMAX_X) return TRUE;
- if((lx2-lx0)>CHKMAX_X) return TRUE;
- }
- }
- }
-
-
- if(ly0<0)
- {
- if((ly1-ly0)>CHKMAX_Y) return TRUE;
- if((ly2-ly0)>CHKMAX_Y) return TRUE;
- }
- if(ly1<0)
- {
- if((ly0-ly1)>CHKMAX_Y) return TRUE;
- if((ly2-ly1)>CHKMAX_Y) return TRUE;
- if((ly3-ly1)>CHKMAX_Y) return TRUE;
- }
- if(ly2<0)
- {
- if((ly0-ly2)>CHKMAX_Y) return TRUE;
- if((ly1-ly2)>CHKMAX_Y) return TRUE;
- if((ly3-ly2)>CHKMAX_Y) return TRUE;
- }
- if(ly3<0)
- {
- if((ly1-ly3)>CHKMAX_Y) return TRUE;
- if((ly2-ly3)>CHKMAX_Y) return TRUE;
- }
-
- return FALSE;
-}
-
-__inline BOOL CheckCoord3()
-{
- if(lx0<0)
- {
- if((lx1-lx0)>CHKMAX_X) return TRUE;
- if((lx2-lx0)>CHKMAX_X) return TRUE;
- }
- if(lx1<0)
- {
- if((lx0-lx1)>CHKMAX_X) return TRUE;
- if((lx2-lx1)>CHKMAX_X) return TRUE;
- }
- if(lx2<0)
- {
- if((lx0-lx2)>CHKMAX_X) return TRUE;
- if((lx1-lx2)>CHKMAX_X) return TRUE;
- }
- if(ly0<0)
- {
- if((ly1-ly0)>CHKMAX_Y) return TRUE;
- if((ly2-ly0)>CHKMAX_Y) return TRUE;
- }
- if(ly1<0)
- {
- if((ly0-ly1)>CHKMAX_Y) return TRUE;
- if((ly2-ly1)>CHKMAX_Y) return TRUE;
- }
- if(ly2<0)
- {
- if((ly0-ly2)>CHKMAX_Y) return TRUE;
- if((ly1-ly2)>CHKMAX_Y) return TRUE;
- }
-
- return FALSE;
-}
-
-
-__inline BOOL CheckCoord2()
-{
- if(lx0<0)
- {
- if((lx1-lx0)>CHKMAX_X) return TRUE;
- }
- if(lx1<0)
- {
- if((lx0-lx1)>CHKMAX_X) return TRUE;
- }
- if(ly0<0)
- {
- if((ly1-ly0)>CHKMAX_Y) return TRUE;
- }
- if(ly1<0)
- {
- if((ly0-ly1)>CHKMAX_Y) return TRUE;
- }
-
- return FALSE;
-}
-
-/*
-//Lewpys "offsetline" func:
-
-void offsetline(void)
-{
- float x0, x1, y0, y1, oolength, xl, yl;
-
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- if(!(dwActFixes&16))
- {
- if((lx0 & SIGNBIT)) lx0|=S_MASK;
- else lx0&=~S_MASK;
- if((lx1 & SIGNBIT)) lx1|=S_MASK;
- else lx1&=~S_MASK;
- if((ly0 & SIGNBIT)) ly0|=S_MASK;
- else ly0&=~S_MASK;
- if((ly1 & SIGNBIT)) ly1|=S_MASK;
- else ly1&=~S_MASK;
- }
-
- x0 = (float)(lx0 + PSXDisplay.CumulOffset.x);
- x1 = (float)(lx1 + PSXDisplay.CumulOffset.x);
- y0 = (float)(ly0 + PSXDisplay.CumulOffset.y);
- y1 = (float)(ly1 + PSXDisplay.CumulOffset.y);
-
- oolength = (float)1/((float)sqrt((y1 - y0)*(y1 - y0) + (x1 - x0)*(x1 - x0)) * (float)2);
-// oolength = (float)1/((float)sqrt(((y1 - y0)*(y1 - y0) + (x1 - x0)*(x1 - x0)) * (float)2));
-
- xl = (x1 - x0) * oolength;
- yl = (y1 - y0) * oolength;
-
- x0 += 0.5f;
- x1 += 0.5f;
-
- x0 -= xl - yl;
- x1 += xl + yl;
- y0 -= yl + xl;
- y1 += yl - xl;
-
- vertex[0].x=x0;
- vertex[1].x=x1;
- vertex[0].y=y0;
- vertex[1].y=y1;
-
- x0 -= yl * 2;
- x1 -= yl * 2;
- y0 += xl * 2;
- y1 += xl * 2;
-
- vertex[2].x=x1;
- vertex[3].x=x0;
- vertex[2].y=y1;
- vertex[3].y=y0;
-}
-*/
-
-
-// Pete's way: a very easy (and hopefully fast) approach for lines
-// without sqrt... using a small float -> short cast trick :)
-
-#define VERTEX_OFFX 0.2f
-#define VERTEX_OFFY 0.2f
-
-BOOL offsetline(void)
-{
- short x0,x1,y0,y1,dx,dy;float px,py;
-
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- if(!(dwActFixes&16))
- {
- lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
- lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
- ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
- ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
-
- if(CheckCoord2()) return TRUE;
- }
-
- x0 = (lx0 + PSXDisplay.CumulOffset.x)+1;
- x1 = (lx1 + PSXDisplay.CumulOffset.x)+1;
- y0 = (ly0 + PSXDisplay.CumulOffset.y)+1;
- y1 = (ly1 + PSXDisplay.CumulOffset.y)+1;
-
- dx=x1-x0;
- dy=y1-y0;
-
- if(dx>=0)
- {
- if(dy>=0)
- {
- px=0.5f;
- if(dx>dy) py=-0.5f;
- else if(dx<dy) py= 0.5f;
- else py= 0.0f;
- }
- else
- {
- py=-0.5f;
- dy=-dy;
- if(dx>dy) px= 0.5f;
- else if(dx<dy) px=-0.5f;
- else px= 0.0f;
- }
- }
- else
- {
- if(dy>=0)
- {
- py=0.5f;
- dx=-dx;
- if(dx>dy) px=-0.5f;
- else if(dx<dy) px= 0.5f;
- else px= 0.0f;
- }
- else
- {
- px=-0.5f;
- if(dx>dy) py=-0.5f;
- else if(dx<dy) py= 0.5f;
- else py= 0.0f;
- }
- }
-
- vertex[0].x=(short)((float)x0-px);
- vertex[3].x=(short)((float)x0+py);
-
- vertex[0].y=(short)((float)y0-py);
- vertex[3].y=(short)((float)y0-px);
-
- vertex[1].x=(short)((float)x1-py);
- vertex[2].x=(short)((float)x1+px);
-
- vertex[1].y=(short)((float)y1+px);
- vertex[2].y=(short)((float)y1+py);
-
- if(vertex[0].x==vertex[3].x && // ortho rect? done
- vertex[1].x==vertex[2].x &&
- vertex[0].y==vertex[1].y &&
- vertex[2].y==vertex[3].y) return FALSE;
- if(vertex[0].x==vertex[1].x &&
- vertex[2].x==vertex[3].x &&
- vertex[0].y==vertex[3].y &&
- vertex[1].y==vertex[2].y) return FALSE;
-
- vertex[0].x-=VERTEX_OFFX; // otherwise a small offset
- vertex[0].y-=VERTEX_OFFY; // to get better accuracy
- vertex[1].x-=VERTEX_OFFX;
- vertex[1].y-=VERTEX_OFFY;
- vertex[2].x-=VERTEX_OFFX;
- vertex[2].y-=VERTEX_OFFY;
- vertex[3].x-=VERTEX_OFFX;
- vertex[3].y-=VERTEX_OFFY;
-
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////
-
-BOOL offset2(void)
-{
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- if(!(dwActFixes&16))
- {
- lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
- lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
- ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
- ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
-
- if(CheckCoord2()) return TRUE;
- }
-
- vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
- vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
- vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
- vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
-
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////
-
-BOOL offset3(void)
-{
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- if(!(dwActFixes&16))
- {
- lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
- lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
- lx2=(short)(((int)lx2<<SIGNSHIFT)>>SIGNSHIFT);
- ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
- ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
- ly2=(short)(((int)ly2<<SIGNSHIFT)>>SIGNSHIFT);
-
- if(CheckCoord3()) return TRUE;
- }
-
- vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
- vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
- vertex[2].x=lx2+PSXDisplay.CumulOffset.x;
- vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
- vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
- vertex[2].y=ly2+PSXDisplay.CumulOffset.y;
-
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////
-
-BOOL offset4(void)
-{
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- if(!(dwActFixes&16))
- {
- lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
- lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
- lx2=(short)(((int)lx2<<SIGNSHIFT)>>SIGNSHIFT);
- lx3=(short)(((int)lx3<<SIGNSHIFT)>>SIGNSHIFT);
- ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
- ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
- ly2=(short)(((int)ly2<<SIGNSHIFT)>>SIGNSHIFT);
- ly3=(short)(((int)ly3<<SIGNSHIFT)>>SIGNSHIFT);
-
- if(CheckCoord4()) return TRUE;
- }
-
- vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
- vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
- vertex[2].x=lx2+PSXDisplay.CumulOffset.x;
- vertex[3].x=lx3+PSXDisplay.CumulOffset.x;
- vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
- vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
- vertex[2].y=ly2+PSXDisplay.CumulOffset.y;
- vertex[3].y=ly3+PSXDisplay.CumulOffset.y;
-
- return FALSE;
-}
-
-/////////////////////////////////////////////////////////
-
-void offsetST(void)
-{
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- if(!(dwActFixes&16))
- {
- lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
- ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
-
- if(lx0<-512 && PSXDisplay.DrawOffset.x<=-512)
- lx0+=2048;
-
- if(ly0<-512 && PSXDisplay.DrawOffset.y<=-512)
- ly0+=2048;
- }
-
- ly1 = ly0;
- ly2 = ly3 = ly0+sprtH;
- lx3 = lx0;
- lx1 = lx2 = lx0+sprtW;
-
- vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
- vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
- vertex[2].x=lx2+PSXDisplay.CumulOffset.x;
- vertex[3].x=lx3+PSXDisplay.CumulOffset.x;
- vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
- vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
- vertex[2].y=ly2+PSXDisplay.CumulOffset.y;
- vertex[3].y=ly3+PSXDisplay.CumulOffset.y;
-}
-
-/////////////////////////////////////////////////////////
-
-void offsetScreenUpload(int Position)
-{
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- if(Position==-1)
- {
- int lmdx,lmdy;
-
- lmdx=xrUploadArea.x0;
- lmdy=xrUploadArea.y0;
-
- lx0-=lmdx;
- ly0-=lmdy;
- lx1-=lmdx;
- ly1-=lmdy;
- lx2-=lmdx;
- ly2-=lmdy;
- lx3-=lmdx;
- ly3-=lmdy;
- }
- else
- if(Position)
- {
- lx0-=PSXDisplay.DisplayPosition.x;
- ly0-=PSXDisplay.DisplayPosition.y;
- lx1-=PSXDisplay.DisplayPosition.x;
- ly1-=PSXDisplay.DisplayPosition.y;
- lx2-=PSXDisplay.DisplayPosition.x;
- ly2-=PSXDisplay.DisplayPosition.y;
- lx3-=PSXDisplay.DisplayPosition.x;
- ly3-=PSXDisplay.DisplayPosition.y;
- }
- else
- {
- lx0-=PreviousPSXDisplay.DisplayPosition.x;
- ly0-=PreviousPSXDisplay.DisplayPosition.y;
- lx1-=PreviousPSXDisplay.DisplayPosition.x;
- ly1-=PreviousPSXDisplay.DisplayPosition.y;
- lx2-=PreviousPSXDisplay.DisplayPosition.x;
- ly2-=PreviousPSXDisplay.DisplayPosition.y;
- lx3-=PreviousPSXDisplay.DisplayPosition.x;
- ly3-=PreviousPSXDisplay.DisplayPosition.y;
- }
-
- vertex[0].x=lx0 + PreviousPSXDisplay.Range.x0;
- vertex[1].x=lx1 + PreviousPSXDisplay.Range.x0;
- vertex[2].x=lx2 + PreviousPSXDisplay.Range.x0;
- vertex[3].x=lx3 + PreviousPSXDisplay.Range.x0;
- vertex[0].y=ly0 + PreviousPSXDisplay.Range.y0;
- vertex[1].y=ly1 + PreviousPSXDisplay.Range.y0;
- vertex[2].y=ly2 + PreviousPSXDisplay.Range.y0;
- vertex[3].y=ly3 + PreviousPSXDisplay.Range.y0;
-
- if(iUseMask)
- {
- vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
- gl_z+=0.00004f;
- }
-}
-
-/////////////////////////////////////////////////////////
-
-void offsetBlk(void)
-{
- if(bDisplayNotSet)
- SetOGLDisplaySettings(1);
-
- vertex[0].x=lx0-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
- vertex[1].x=lx1-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
- vertex[2].x=lx2-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
- vertex[3].x=lx3-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
- vertex[0].y=ly0-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
- vertex[1].y=ly1-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
- vertex[2].y=ly2-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
- vertex[3].y=ly3-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
-
- if(iUseMask)
- {
- vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
- gl_z+=0.00004f;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// texture sow/tow calculations
-////////////////////////////////////////////////////////////////////////
-
-void assignTextureVRAMWrite(void)
-{
-#ifdef OWNSCALE
-
- vertex[0].sow=0.5f/ ST_FACVRAMX;
- vertex[0].tow=0.5f/ ST_FACVRAM;
-
- vertex[1].sow=(float)gl_ux[1]/ ST_FACVRAMX;
- vertex[1].tow=0.5f/ ST_FACVRAM;
-
- vertex[2].sow=(float)gl_ux[2]/ ST_FACVRAMX;
- vertex[2].tow=(float)gl_vy[2]/ ST_FACVRAM;
-
- vertex[3].sow=0.5f/ ST_FACVRAMX;
- vertex[3].tow=(float)gl_vy[3]/ ST_FACVRAM;
-
-#else
-
- if(gl_ux[1]==255)
- {
- vertex[0].sow=(gl_ux[0]*255.99f)/255.0f;
- vertex[1].sow=(gl_ux[1]*255.99f)/255.0f;
- vertex[2].sow=(gl_ux[2]*255.99f)/255.0f;
- vertex[3].sow=(gl_ux[3]*255.99f)/255.0f;
- }
- else
- {
- vertex[0].sow=gl_ux[0];
- vertex[1].sow=gl_ux[1];
- vertex[2].sow=gl_ux[2];
- vertex[3].sow=gl_ux[3];
- }
-
- vertex[0].tow=gl_vy[0];
- vertex[1].tow=gl_vy[1];
- vertex[2].tow=gl_vy[2];
- vertex[3].tow=gl_vy[3];
-
-#endif
-}
-
-GLuint gLastTex=0;
-GLuint gLastFMode=(GLuint)-1;
-
-/////////////////////////////////////////////////////////
-
-void assignTextureSprite(void)
-{
- if(bUsingTWin)
- {
- vertex[0].sow=vertex[3].sow=(float)gl_ux[0]/TWin.UScaleFactor;
- vertex[1].sow=vertex[2].sow=(float)sSprite_ux2/TWin.UScaleFactor;
- vertex[0].tow=vertex[1].tow=(float)gl_vy[0]/TWin.VScaleFactor;
- vertex[2].tow=vertex[3].tow=(float)sSprite_vy2/TWin.VScaleFactor;
- gLastTex=gTexName;
-
- if(iFilterType>0 && iFilterType<3 && iHiResTextures!=2)
- {
- float fxmin=65536.0f,fxmax=0.0f,fymin=65536.0f,fymax=0.0f;int i;
-
- for(i=0;i<4;i++)
- {
- if(vertex[i].sow<fxmin) fxmin=vertex[i].sow;
- if(vertex[i].tow<fymin) fymin=vertex[i].tow;
- if(vertex[i].sow>fxmax) fxmax=vertex[i].sow;
- if(vertex[i].tow>fymax) fymax=vertex[i].tow;
- }
-
- for(i=0;i<4;i++)
- {
-#ifdef OWNSCALE
- if(vertex[i].sow==fxmin) vertex[i].sow+=0.375f/(float)TWin.Position.x1;
- if(vertex[i].sow==fxmax) vertex[i].sow-=0.375f/(float)TWin.Position.x1;
- if(vertex[i].tow==fymin) vertex[i].tow+=0.375f/(float)TWin.Position.y1;
- if(vertex[i].tow==fymax) vertex[i].tow-=0.375f/(float)TWin.Position.y1;
-#else
- if(vertex[i].sow==fxmin) vertex[i].sow+=96.0f/(float)TWin.Position.x1;
- if(vertex[i].sow==fxmax) vertex[i].sow-=96.0f/(float)TWin.Position.x1;
- if(vertex[i].tow==fymin) vertex[i].tow+=96.0f/(float)TWin.Position.y1;
- if(vertex[i].tow==fymax) vertex[i].tow-=96.0f/(float)TWin.Position.y1;
-#endif
- }
- }
-
- }
- else
- {
-#ifdef OWNSCALE
-
- vertex[0].sow=vertex[3].sow=(float)gl_ux[0] / ST_FACSPRITE;
- vertex[1].sow=vertex[2].sow=(float)sSprite_ux2 / ST_FACSPRITE;
- vertex[0].tow=vertex[1].tow=(float)gl_vy[0] / ST_FACSPRITE;
- vertex[2].tow=vertex[3].tow=(float)sSprite_vy2 / ST_FACSPRITE;
-
-#else
-
- vertex[0].sow=vertex[3].sow=gl_ux[0];
- vertex[1].sow=vertex[2].sow=sSprite_ux2;
- vertex[0].tow=vertex[1].tow=gl_vy[0];
- vertex[2].tow=vertex[3].tow=sSprite_vy2;
-
-#endif
-
- if(iFilterType>2)
- {
- if(gLastTex!=gTexName || gLastFMode!=0)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- gLastTex=gTexName;gLastFMode=0;
- }
- }
- }
-
- if(usMirror & 0x1000)
- {
- vertex[0].sow=vertex[1].sow;
- vertex[1].sow=vertex[2].sow=vertex[3].sow;
- vertex[3].sow=vertex[0].sow;
- }
-
- if(usMirror & 0x2000)
- {
- vertex[0].tow=vertex[3].tow;
- vertex[2].tow=vertex[3].tow=vertex[1].tow;
- vertex[1].tow=vertex[0].tow;
- }
-
-}
-
-/////////////////////////////////////////////////////////
-
-void assignTexture3(void)
-{
- if(bUsingTWin)
- {
- vertex[0].sow=(float)gl_ux[0]/TWin.UScaleFactor;
- vertex[0].tow=(float)gl_vy[0]/TWin.VScaleFactor;
- vertex[1].sow=(float)gl_ux[1]/TWin.UScaleFactor;
- vertex[1].tow=(float)gl_vy[1]/TWin.VScaleFactor;
- vertex[2].sow=(float)gl_ux[2]/TWin.UScaleFactor;
- vertex[2].tow=(float)gl_vy[2]/TWin.VScaleFactor;
- gLastTex=gTexName;
- }
- else
- {
-#ifdef OWNSCALE
- vertex[0].sow=(float)gl_ux[0] / ST_FACTRI;
- vertex[0].tow=(float)gl_vy[0] / ST_FACTRI;
- vertex[1].sow=(float)gl_ux[1] / ST_FACTRI;
-
- vertex[1].tow=(float)gl_vy[1] / ST_FACTRI;
- vertex[2].sow=(float)gl_ux[2] / ST_FACTRI;
- vertex[2].tow=(float)gl_vy[2] / ST_FACTRI;
-#else
- vertex[0].sow=gl_ux[0];
- vertex[0].tow=gl_vy[0];
- vertex[1].sow=gl_ux[1];
- vertex[1].tow=gl_vy[1];
- vertex[2].sow=gl_ux[2];
- vertex[2].tow=gl_vy[2];
-#endif
-
- if(iFilterType>2)
- {
- if(gLastTex!=gTexName || gLastFMode!=1)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- gLastTex=gTexName;gLastFMode=1;
- }
- }
-
- if(iFilterType)
- {
- float fxmin=256.0f,fxmax=0.0f,fymin=256.0f,fymax=0.0f;int i;
- for(i=0;i<3;i++)
- {
- if(vertex[i].sow<fxmin) fxmin=vertex[i].sow;
- if(vertex[i].tow<fymin) fymin=vertex[i].tow;
- if(vertex[i].sow>fxmax) fxmax=vertex[i].sow;
- if(vertex[i].tow>fymax) fymax=vertex[i].tow;
- }
-
- for(i=0;i<3;i++)
- {
- if(vertex[i].sow==fxmin) vertex[i].sow+=ST_BFFACSORT;
- if(vertex[i].sow==fxmax) vertex[i].sow-=ST_BFFACSORT;
- if(vertex[i].tow==fymin) vertex[i].tow+=ST_BFFACSORT;
- if(vertex[i].tow==fymax) vertex[i].tow-=ST_BFFACSORT;
- }
- }
- }
-}
-
-/////////////////////////////////////////////////////////
-
-void assignTexture4(void)
-{
- if(bUsingTWin)
- {
- vertex[0].sow=(float)gl_ux[0]/TWin.UScaleFactor;
- vertex[0].tow=(float)gl_vy[0]/TWin.VScaleFactor;
- vertex[1].sow=(float)gl_ux[1]/TWin.UScaleFactor;
- vertex[1].tow=(float)gl_vy[1]/TWin.VScaleFactor;
- vertex[2].sow=(float)gl_ux[2]/TWin.UScaleFactor;
- vertex[2].tow=(float)gl_vy[2]/TWin.VScaleFactor;
- vertex[3].sow=(float)gl_ux[3]/TWin.UScaleFactor;
- vertex[3].tow=(float)gl_vy[3]/TWin.VScaleFactor;
- gLastTex=gTexName;
- }
- else
- {
-#ifdef OWNSCALE
- vertex[0].sow=(float)gl_ux[0] / ST_FAC;
- vertex[0].tow=(float)gl_vy[0] / ST_FAC;
- vertex[1].sow=(float)gl_ux[1] / ST_FAC;
- vertex[1].tow=(float)gl_vy[1] / ST_FAC;
- vertex[2].sow=(float)gl_ux[2] / ST_FAC;
- vertex[2].tow=(float)gl_vy[2] / ST_FAC;
- vertex[3].sow=(float)gl_ux[3] / ST_FAC;
- vertex[3].tow=(float)gl_vy[3] / ST_FAC;
-#else
- vertex[0].sow=gl_ux[0];
- vertex[0].tow=gl_vy[0];
- vertex[1].sow=gl_ux[1];
- vertex[1].tow=gl_vy[1];
- vertex[2].sow=gl_ux[2];
- vertex[2].tow=gl_vy[2];
- vertex[3].sow=gl_ux[3];
- vertex[3].tow=gl_vy[3];
-#endif
-
- if(iFilterType>2)
- {
- if(gLastTex!=gTexName || gLastFMode!=1)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- gLastTex=gTexName;gLastFMode=1;
- }
- }
-
- if(iFilterType)
- {
- float fxmin=256.0f,fxmax=0.0f,fymin=256.0f,fymax=0.0f;int i;
- for(i=0;i<4;i++)
- {
- if(vertex[i].sow<fxmin) fxmin=vertex[i].sow;
- if(vertex[i].tow<fymin) fymin=vertex[i].tow;
- if(vertex[i].sow>fxmax) fxmax=vertex[i].sow;
- if(vertex[i].tow>fymax) fymax=vertex[i].tow;
- }
-
- for(i=0;i<4;i++)
- {
- if(vertex[i].sow==fxmin) vertex[i].sow+=ST_BFFACSORT;
- if(vertex[i].sow==fxmax) vertex[i].sow-=ST_BFFACSORT;
- if(vertex[i].tow==fymin) vertex[i].tow+=ST_BFFACSORT;
- if(vertex[i].tow==fymax) vertex[i].tow-=ST_BFFACSORT;
- }
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////
-// render pos / buffers
-////////////////////////////////////////////////////////////////////////
-
-#ifndef _WINDOWS
-#define EqualRect(pr1,pr2) ((pr1)->left==(pr2)->left && (pr1)->top==(pr2)->top && (pr1)->right==(pr2)->right && (pr1)->bottom==(pr2)->bottom)
-#endif
-
-////////////////////////////////////////////////////////////////////////
-// SetDisplaySettings: "simply" calcs the new drawing area and updates
-// the ogl clipping (scissor)
-
-BOOL bSetClip=FALSE;
-
-void SetOGLDisplaySettings(BOOL DisplaySet)
-{
- static RECT rprev={0,0,0,0};
- static RECT rC ={0,0,0,0};
- static int iOldX=0;
- static int iOldY=0;
- RECT r;float XS,YS;
-
- bDisplayNotSet = FALSE;
-
- //----------------------------------------------------// that's a whole screen upload
- if(!DisplaySet)
- {
- RECT rX;
- PSXDisplay.GDrawOffset.x=0;
- PSXDisplay.GDrawOffset.y=0;
-
- PSXDisplay.CumulOffset.x = PSXDisplay.DrawOffset.x+PreviousPSXDisplay.Range.x0;
- PSXDisplay.CumulOffset.y = PSXDisplay.DrawOffset.y+PreviousPSXDisplay.Range.y0;
-
- rprev.left=rprev.left+1;
-
- rX=rRatioRect;
- rX.top=iResY-(rRatioRect.top+rRatioRect.bottom);
-
- if(bSetClip || !EqualRect(&rC,&rX))
- {
- rC=rX;
- glScissor(rC.left,rC.top,rC.right,rC.bottom);
- bSetClip=FALSE;
- }
- return;
- }
- //----------------------------------------------------//
-
- PSXDisplay.GDrawOffset.y = PreviousPSXDisplay.DisplayPosition.y;
- PSXDisplay.GDrawOffset.x = PreviousPSXDisplay.DisplayPosition.x;
- PSXDisplay.CumulOffset.x = PSXDisplay.DrawOffset.x - PSXDisplay.GDrawOffset.x+PreviousPSXDisplay.Range.x0;
- PSXDisplay.CumulOffset.y = PSXDisplay.DrawOffset.y - PSXDisplay.GDrawOffset.y+PreviousPSXDisplay.Range.y0;
-
- r.top =PSXDisplay.DrawArea.y0 - PreviousPSXDisplay.DisplayPosition.y;
- r.bottom=PSXDisplay.DrawArea.y1 - PreviousPSXDisplay.DisplayPosition.y;
-
- if(r.bottom<0 || r.top>=PSXDisplay.DisplayMode.y)
- {
- r.top =PSXDisplay.DrawArea.y0 - PSXDisplay.DisplayPosition.y;
- r.bottom=PSXDisplay.DrawArea.y1 - PSXDisplay.DisplayPosition.y;
- }
-
- r.left =PSXDisplay.DrawArea.x0 - PreviousPSXDisplay.DisplayPosition.x;
- r.right =PSXDisplay.DrawArea.x1 - PreviousPSXDisplay.DisplayPosition.x;
-
- if(r.right<0 || r.left>=PSXDisplay.DisplayMode.x)
- {
- r.left =PSXDisplay.DrawArea.x0 - PSXDisplay.DisplayPosition.x;
- r.right =PSXDisplay.DrawArea.x1 - PSXDisplay.DisplayPosition.x;
- }
-
- if(!bSetClip && EqualRect(&r,&rprev) &&
- iOldX == PSXDisplay.DisplayMode.x &&
- iOldY == PSXDisplay.DisplayMode.y)
- return;
-
- rprev = r;
- iOldX = PSXDisplay.DisplayMode.x;
- iOldY = PSXDisplay.DisplayMode.y;
-
- XS=(float)rRatioRect.right/(float)PSXDisplay.DisplayMode.x;
- YS=(float)rRatioRect.bottom/(float)PSXDisplay.DisplayMode.y;
-
- if(PreviousPSXDisplay.Range.x0)
- {
- short s=PreviousPSXDisplay.Range.x0+PreviousPSXDisplay.Range.x1;
-
- r.left+=PreviousPSXDisplay.Range.x0+1;
-
- r.right+=PreviousPSXDisplay.Range.x0;
-
- if(r.left>s) r.left=s;
- if(r.right>s) r.right=s;
- }
-
- if(PreviousPSXDisplay.Range.y0)
- {
- short s=PreviousPSXDisplay.Range.y0+PreviousPSXDisplay.Range.y1;
-
- r.top+=PreviousPSXDisplay.Range.y0+1;
- r.bottom+=PreviousPSXDisplay.Range.y0;
-
- if(r.top>s) r.top=s;
- if(r.bottom>s) r.bottom=s;
- }
-
- // Set the ClipArea variables to reflect the new screen,
- // offset from zero (since it is a new display buffer)
- r.left = (int)(((float)(r.left)) *XS);
- r.top = (int)(((float)(r.top)) *YS);
- r.right = (int)(((float)(r.right + 1))*XS);
- r.bottom = (int)(((float)(r.bottom + 1))*YS);
-
- // Limit clip area to the screen size
- if (r.left > iResX) r.left = iResX;
- if (r.left < 0) r.left = 0;
- if (r.top > iResY) r.top = iResY;
- if (r.top < 0) r.top = 0;
- if (r.right > iResX) r.right = iResX;
- if (r.right < 0) r.right = 0;
- if (r.bottom > iResY) r.bottom = iResY;
- if (r.bottom < 0) r.bottom = 0;
-
- r.right -=r.left;
- r.bottom-=r.top;
- r.top=iResY-(r.top+r.bottom);
-
- r.left+=rRatioRect.left;
- r.top -=rRatioRect.top;
-
- if(bSetClip || !EqualRect(&r,&rC))
- {
- glScissor(r.left,r.top,r.right,r.bottom);
- rC=r;
- bSetClip=FALSE;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
+/***************************************************************************
+ draw.c - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#include "stdafx.h"
+
+#define _IN_DRAW
+
+#include "externals.h"
+#include "gpu.h"
+#include "draw.h"
+#include "prim.h"
+#include "texture.h"
+#include "menu.h"
+
+#if defined(_MACGL)
+// if you use it, you must include it
+#include <OpenGL/gl.h>
+#include <OpenGL/glext.h>
+#endif
+////////////////////////////////////////////////////////////////////////////////////
+// defines
+
+#define SIGNBIT 0x800
+#define S_MASK 0xf000
+#define L_MASK 0xfffff000
+
+// ownscale: some ogl drivers have buggy texture matrix funcs, so it
+// is safer to calc sow/tow ourselves
+
+#ifdef OWNSCALE
+
+#define ST_FACSPRITE 255.99f
+#define ST_BFFACSPRITE 0.5f/256.0f
+#define ST_BFFACSPRITESORT 0.333f/256.0f
+
+#define ST_OFFSET 0.5f/256.0f;
+
+#define ST_FAC 255.99f
+#define ST_BFFAC 0.5f/256.0f
+#define ST_BFFACSORT 0.333f/256.0f
+
+#define ST_FACTRI 255.99f
+#define ST_BFFACTRI 0.5f/256.0f
+#define ST_BFFACTRISORT 0.333f/256.0f
+
+#define ST_FACVRAMX 255.0f
+#define ST_FACVRAM 256.0f
+
+///////////////////////////////////////////////////////////////
+
+#else
+
+#define ST_BFFACSPRITE 0.5f
+#define ST_BFFACSPRITESORT 0.333f
+
+#define ST_BFFAC 0.5f
+#define ST_BFFACSORT 0.333f
+
+#define ST_BFFACTRI 0.5f
+#define ST_BFFACTRISORT 0.333f
+
+#define ST_OFFSET 0.5f;
+
+#endif
+
+////////////////////////////////////////////////////////////////////////////////////
+// draw globals; most will be initialized again later (by config or checks)
+
+#ifdef _WINDOWS
+HDC dcGlobal = NULL;
+HWND hWWindow;
+#endif
+
+BOOL bIsFirstFrame = TRUE;
+
+// resolution/ratio vars
+
+int iResX;
+int iResY;
+BOOL bKeepRatio = FALSE;
+RECT rRatioRect;
+
+// psx mask related vars
+
+BOOL bCheckMask = FALSE;
+int iUseMask = 0;
+int iSetMask = 0;
+unsigned short sSetMask = 0;
+uint32_t lSetMask = 0;
+
+// drawing/coord vars
+
+OGLVertex vertex[4];
+GLubyte gl_ux[8];
+GLubyte gl_vy[8];
+short sprtY,sprtX,sprtH,sprtW;
+
+// drawing options
+
+BOOL bOpaquePass;
+BOOL bAdvancedBlend;
+BOOL bUseLines;
+BOOL bUseAntiAlias;
+int iTexQuality;
+int iUsePalTextures=1;
+BOOL bSnapShot=FALSE;
+BOOL bSmallAlpha=FALSE;
+int iShowFPS=0;
+
+// OGL extension support
+
+int iForceVSync=-1;
+int iUseExts=0;
+BOOL bGLExt;
+BOOL bGLFastMovie=FALSE;
+BOOL bGLSoft;
+BOOL bGLBlend;
+#if defined (_MACGL) // always supported on OSX > 10.4.3
+#define glBlendEquationEXTEx glBlendEquationEXT
+#define glColorTableEXTEx glColorTableEXT
+#else
+PFNGLBLENDEQU glBlendEquationEXTEx=NULL;
+PFNGLCOLORTABLEEXT glColorTableEXTEx=NULL;
+#endif
+// gfx card buffer infos
+
+int iDepthFunc=0;
+int iZBufferDepth=0;
+GLbitfield uiBufferBits=GL_COLOR_BUFFER_BIT;
+
+////////////////////////////////////////////////////////////////////////
+// Set OGL pixel format
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+BOOL bSetupPixelFormat(HDC hDC)
+{
+ int pixelformat;
+ static PIXELFORMATDESCRIPTOR pfd =
+ {
+ sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
+ 1, // version number
+ PFD_DRAW_TO_WINDOW | // support window
+ PFD_SUPPORT_OPENGL | // support OpenGL
+ PFD_DOUBLEBUFFER, // double buffered
+ PFD_TYPE_RGBA, // RGBA type
+ 16, // 16-bit color depth (adjusted later)
+ 0, 0, 0, 0, 0, 0, // color bits ignored
+ 0, // no alpha buffer
+ 0, // shift bit ignored
+ 0, // no accumulation buffer
+ 0, 0, 0, 0, // accum bits ignored
+ 0, // z-buffer
+ 0,
+ 0, // no auxiliary buffer
+ PFD_MAIN_PLANE, // main layer
+ 0, // reserved
+ 0, 0, 0 // layer masks ignored
+ };
+
+ pfd.cColorBits=iColDepth; // set user color depth
+ pfd.cDepthBits=iZBufferDepth; // set user zbuffer (by psx mask)
+
+ if((pixelformat=ChoosePixelFormat(hDC,&pfd))==0)
+ {
+ MessageBox(NULL,"ChoosePixelFormat failed","Error",MB_OK);
+ return FALSE;
+ }
+
+ if(SetPixelFormat(hDC,pixelformat, &pfd)==FALSE)
+ {
+ MessageBox(NULL,"SetPixelFormat failed","Error",MB_OK);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////
+// Get extension infos (f.e. pal textures / packed pixels)
+////////////////////////////////////////////////////////////////////////
+
+static void GetExtInfos(void)
+{
+ BOOL bPacked=FALSE; // default: no packed pixel support
+
+ bGLExt=FALSE; // default: no extensions
+ bGLFastMovie=FALSE;
+
+ if(strstr((char *)glGetString(GL_EXTENSIONS), // packed pixels available?
+ "GL_EXT_packed_pixels"))
+ bPacked=TRUE; // -> ok
+
+ if(bPacked && bUse15bitMdec) // packed available and 15bit mdec wanted?
+ bGLFastMovie=TRUE; // -> ok
+
+ if(bPacked && (iTexQuality==1 || iTexQuality==2)) // packed available and 16 bit texture format?
+ {
+ bGLFastMovie=TRUE; // -> ok
+ bGLExt=TRUE;
+ }
+
+ if(iUseExts && // extension support wanted?
+ (strstr((char *)glGetString(GL_EXTENSIONS),
+ "GL_EXT_texture_edge_clamp") ||
+ strstr((char *)glGetString(GL_EXTENSIONS), // -> check clamp support, if yes: use it
+ "GL_SGIS_texture_edge_clamp")))
+ iClampType=GL_TO_EDGE_CLAMP;
+ else iClampType=GL_CLAMP;
+
+#if !defined (_MACGL) // OSX > 10.4.3 defines this
+ glColorTableEXTEx=(PFNGLCOLORTABLEEXT)NULL; // init ogl palette func pointer
+#endif
+
+#ifndef __sun
+ if(iGPUHeight!=1024 && // no pal textures in ZN mode (height=1024)!
+ strstr((char *)glGetString(GL_EXTENSIONS), // otherwise: check ogl support
+ "GL_EXT_paletted_texture"))
+ {
+ iUsePalTextures=1; // -> wow, supported, get func pointer
+
+#ifdef _WINDOWS
+ glColorTableEXTEx=(PFNGLCOLORTABLEEXT)wglGetProcAddress("glColorTableEXT");
+#elif defined (_MACGL)
+ // no prob, done already in OSX > 10.4.3
+#else
+ glColorTableEXTEx=(PFNGLCOLORTABLEEXT)glXGetProcAddress((GLubyte *)"glColorTableEXT");
+#endif
+
+ if(glColorTableEXTEx==NULL) iUsePalTextures=0; // -> ha, cheater... no func, no support
+
+ }
+ else iUsePalTextures=0;
+#else
+ iUsePalTextures=0;
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////
+// Setup some stuff depending on user settings or in-game toggle
+////////////////////////////////////////////////////////////////////////
+
+void SetExtGLFuncs(void)
+{
+ //----------------------------------------------------//
+
+ SetFixes(); // update fix infos
+
+ //----------------------------------------------------//
+
+#ifdef _WINDOWS
+ if((iForceVSync>=0) && // force vsync?
+ strstr((char *)glGetString(GL_EXTENSIONS), // and extension available?
+ "WGL_EXT_swap_control"))
+ {
+ PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT=
+ (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT");
+
+ if(wglSwapIntervalEXT) wglSwapIntervalEXT(iForceVSync);
+ }
+#endif
+#ifdef _MACGL
+ SetVSync(iForceVSync);
+#endif
+ if(iUseExts && !(dwActFixes&1024) && // extensions wanted? and not turned off by game fix?
+ strstr((char *)glGetString(GL_EXTENSIONS), // and blend_subtract available?
+ "GL_EXT_blend_subtract"))
+ { // -> get ogl blend function pointer
+#ifdef _WINDOWS
+ glBlendEquationEXTEx=(PFNGLBLENDEQU)wglGetProcAddress("glBlendEquationEXT");
+#elif defined(_MACGL)
+ // no prob, OSX > 10.4.3 has this
+#else
+ glBlendEquationEXTEx=(PFNGLBLENDEQU)glXGetProcAddress((GLubyte *)"glBlendEquationEXT");
+#endif
+ }
+ else // no subtract blending?
+ {
+ if(glBlendEquationEXTEx) // -> change to additive blending (if subract was active)
+ glBlendEquationEXTEx(FUNC_ADD_EXT);
+#if !defined(_MACGL) // BTW, why set to null? strange...
+ glBlendEquationEXTEx=(PFNGLBLENDEQU)NULL; // -> no more blend function pointer
+#endif
+ }
+
+ //----------------------------------------------------//
+
+ if(iUseExts && bAdvancedBlend && // advanced blending wanted ?
+ strstr((char *)glGetString(GL_EXTENSIONS), // and extension avail?
+ "GL_EXT_texture_env_combine"))
+ {
+ bUseMultiPass=FALSE;bGLBlend=TRUE; // -> no need for 2 passes, perfect
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
+ glTexEnvf(GL_TEXTURE_ENV, COMBINE_RGB_EXT, GL_MODULATE);
+ glTexEnvf(GL_TEXTURE_ENV, COMBINE_ALPHA_EXT, GL_MODULATE);
+ glTexEnvf(GL_TEXTURE_ENV, RGB_SCALE_EXT, 2.0f);
+ }
+ else // no advanced blending wanted/available:
+ {
+ if(bAdvancedBlend) bUseMultiPass=TRUE; // -> pseudo-advanced with 2 passes
+ else bUseMultiPass=FALSE; // -> or simple 'bright color' mode
+ bGLBlend=FALSE; // -> no ext blending!
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ }
+
+ //----------------------------------------------------//
+ // init standard tex quality 0-2, and big alpha mode 3
+
+ if(!(dwActFixes&0x4000) && iFilterType && iTexQuality>=3)
+ bSmallAlpha=TRUE;
+ else bSmallAlpha=FALSE;
+
+ if(bOpaquePass) // opaque mode?
+ {
+ if(dwActFixes&32)
+ {
+ TCF[0]=CP8RGBA_0;
+ PalTexturedColourFn=CP8RGBA; // -> init col func
+ }
+ else
+ {
+ TCF[0]=XP8RGBA_0;
+ PalTexturedColourFn=XP8RGBA; // -> init col func
+ }
+
+ TCF[1]=XP8RGBA_1;
+ glAlphaFunc(GL_GREATER,0.49f);
+ }
+ else // no opaque mode?
+ {
+ TCF[0]=TCF[1]=P8RGBA;
+ PalTexturedColourFn=P8RGBA; // -> init col func
+ glAlphaFunc(GL_NOTEQUAL,0); // --> set alpha func
+ }
+
+ //----------------------------------------------------//
+
+ LoadSubTexFn=LoadSubTexturePageSort; // init load tex ptr
+
+ giWantedFMT=GL_RGBA; // init ogl tex format
+
+ switch(iTexQuality) // -> quality:
+ {
+ //--------------------------------------------------//
+ case 0: // -> don't care
+ giWantedRGBA=4;
+ giWantedTYPE=GL_UNSIGNED_BYTE;
+ break;
+ //--------------------------------------------------//
+ case 1: // -> R4G4B4A4
+ if(bGLExt)
+ {
+ giWantedRGBA=GL_RGBA4;
+ giWantedTYPE=GL_UNSIGNED_SHORT_4_4_4_4_EXT;
+ LoadSubTexFn=LoadPackedSubTexturePageSort;
+ if(bOpaquePass)
+ {
+ if(dwActFixes&32) PTCF[0]=CP4RGBA_0;
+ else PTCF[0]=XP4RGBA_0;
+ PTCF[1]=XP4RGBA_1;
+ }
+ else
+ {
+ PTCF[0]=PTCF[1]=P4RGBA;
+ }
+ }
+ else
+ {
+ giWantedRGBA=GL_RGBA4;
+ giWantedTYPE=GL_UNSIGNED_BYTE;
+ }
+ break;
+ //--------------------------------------------------//
+ case 2: // -> R5B5G5A1
+ if(bGLExt)
+ {
+ giWantedRGBA=GL_RGB5_A1;
+ giWantedTYPE=GL_UNSIGNED_SHORT_5_5_5_1_EXT;
+ LoadSubTexFn=LoadPackedSubTexturePageSort;
+ if(bOpaquePass)
+ {
+ if(dwActFixes&32) PTCF[0]=CP5RGBA_0;
+ else PTCF[0]=XP5RGBA_0;
+ PTCF[1]=XP5RGBA_1;
+ }
+ else
+ {
+ PTCF[0]=PTCF[1]=P5RGBA;
+ }
+ }
+ else
+ {
+ giWantedRGBA=GL_RGB5_A1;giWantedTYPE=GL_UNSIGNED_BYTE;
+ }
+ break;
+ //--------------------------------------------------//
+ case 3: // -> R8G8B8A8
+ giWantedRGBA=GL_RGBA8;
+ giWantedTYPE=GL_UNSIGNED_BYTE;
+
+ if(bSmallAlpha)
+ {
+ if(bOpaquePass) // opaque mode?
+ {
+ if(dwActFixes&32) {TCF[0]=CP8RGBAEx_0;PalTexturedColourFn=CP8RGBAEx;}
+ else {TCF[0]=XP8RGBAEx_0;PalTexturedColourFn=XP8RGBAEx;}
+ TCF[1]=XP8RGBAEx_1;
+ }
+ }
+
+ break;
+ //--------------------------------------------------//
+ case 4: // -> R8G8B8A8
+ giWantedRGBA = GL_RGBA8;
+ giWantedTYPE = GL_UNSIGNED_BYTE;
+
+ if(strstr((char *)glGetString(GL_EXTENSIONS), // and extension avail?
+ "GL_EXT_bgra"))
+ {
+ giWantedFMT = GL_BGRA_EXT;
+
+ if(bOpaquePass) // opaque mode?
+ {
+ if(bSmallAlpha)
+ {
+ if(dwActFixes&32) {TCF[0]=CP8BGRAEx_0;PalTexturedColourFn=CP8RGBAEx;}
+ else {TCF[0]=XP8BGRAEx_0;PalTexturedColourFn=XP8RGBAEx;}
+ TCF[1]=XP8BGRAEx_1;
+ }
+ else
+ {
+ if(dwActFixes&32) {TCF[0]=CP8BGRA_0;PalTexturedColourFn=CP8RGBA;}
+ else {TCF[0]=XP8BGRA_0;PalTexturedColourFn=XP8RGBA;}
+ TCF[1]=XP8BGRA_1;
+ }
+ }
+ else // no opaque mode?
+ {
+ TCF[0]=TCF[1]=P8BGRA; // -> init col func
+ }
+ }
+ else
+ {
+ iTexQuality=3;
+ if(bSmallAlpha)
+ {
+ if(bOpaquePass) // opaque mode?
+ {
+ if(dwActFixes&32) {TCF[0]=CP8RGBAEx_0;PalTexturedColourFn=CP8RGBAEx;}
+ else {TCF[0]=XP8RGBAEx_0;PalTexturedColourFn=XP8RGBAEx;}
+ TCF[1]=XP8RGBAEx_1;
+ }
+ }
+ }
+
+ break;
+ //--------------------------------------------------//
+ }
+
+ bBlendEnable=FALSE; // init blending: off
+ glDisable(GL_BLEND);
+
+ SetScanTrans(); // init scan lines (if wanted)
+}
+
+////////////////////////////////////////////////////////////////////////
+// setup scan lines
+////////////////////////////////////////////////////////////////////////
+
+#define R_TSP 0x00,0x45,0x00,0xff
+#define G_TSP 0x00,0x00,0x45,0xff
+#define B_TSP 0x45,0x00,0x00,0xff
+#define O_TSP 0x45,0x45,0x45,0xff
+#define N_TSP 0x00,0x00,0x00,0xff
+
+GLuint gTexScanName=0;
+
+GLubyte texscan[4][16]=
+{
+{R_TSP, G_TSP, B_TSP, N_TSP},
+{O_TSP, N_TSP, O_TSP, N_TSP},
+{B_TSP, N_TSP, R_TSP, G_TSP},
+{O_TSP, N_TSP, O_TSP, N_TSP}
+};
+
+static void CreateScanLines(void)
+{
+ if(iUseScanLines)
+ {
+ int y;
+ if(iScanBlend<0) // special scan mask mode
+ {
+ glGenTextures(1, &gTexScanName);
+ glBindTexture(GL_TEXTURE_2D, gTexScanName);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexImage2D(GL_TEXTURE_2D, 0, 4, 4, 4, 0,GL_RGBA, GL_UNSIGNED_BYTE, texscan);
+ }
+ else // otherwise simple lines in a display list
+ {
+ uiScanLine=glGenLists(1);
+ glNewList(uiScanLine,GL_COMPILE);
+ #ifdef _MACGL
+ // not mac specific, just commenting out to be friendly
+ // use it if you like
+ // this draws anti-aliased lines with user-chosen color
+ glPushAttrib(GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);
+ glEnable(GL_BLEND | GL_LINE_SMOOTH);
+ glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
+ glColor4f(iScanlineColor[0],iScanlineColor[1],iScanlineColor[2],iScanlineColor[3]);
+ glBegin(GL_LINES);
+ for(y=0;y<iResY;y+=2)
+ {
+ glVertex2f(0,y);
+ glVertex2f(iResX,y);
+ }
+ glEnd();
+ glPopAttrib();
+ #else
+ for(y=0;y<iResY;y+=2)
+ {
+ glBegin(GL_QUADS);
+ glVertex2f(0,y);
+ glVertex2f(iResX,y);
+ glVertex2f(iResX,y+1);
+ glVertex2f(0,y+1);
+ glEnd();
+ }
+
+ #endif
+ glEndList();
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// Initialize OGL
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+HGLRC GLCONTEXT=NULL;
+#endif
+
+int GLinitialize()
+{
+#ifdef _WINDOWS
+ HGLRC objectRC;
+ // init
+ dcGlobal = GetDC(hWWindow); // FIRST: dc/rc stuff
+ objectRC = wglCreateContext(dcGlobal);
+ GLCONTEXT=objectRC;
+ wglMakeCurrent(dcGlobal, objectRC);
+ // CheckWGLExtensions(dcGlobal);
+ if(bWindowMode) ReleaseDC(hWWindow,dcGlobal); // win mode: release dc again
+#endif
+#if defined (_MACGL)
+ BringContextForward();
+#endif
+ glViewport(rRatioRect.left, // init viewport by ratio rect
+ iResY-(rRatioRect.top+rRatioRect.bottom),
+ rRatioRect.right,
+ rRatioRect.bottom);
+
+ glScissor(0, 0, iResX, iResY); // init clipping (fullscreen)
+ glEnable(GL_SCISSOR_TEST);
+
+#ifndef OWNSCALE
+ glMatrixMode(GL_TEXTURE); // init psx tex sow and tow if not "ownscale"
+ glLoadIdentity();
+ glScalef(1.0f/255.99f,1.0f/255.99f,1.0f); // geforce precision hack
+#endif
+
+ glMatrixMode(GL_PROJECTION); // init projection with psx resolution
+ glLoadIdentity();
+ glOrtho(0,PSXDisplay.DisplayMode.x,
+ PSXDisplay.DisplayMode.y, 0, -1, 1);
+
+ if(iZBufferDepth) // zbuffer?
+ {
+ uiBufferBits=GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT;
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_ALWAYS);
+ iDepthFunc=1;
+ }
+ else // no zbuffer?
+ {
+ uiBufferBits=GL_COLOR_BUFFER_BIT;
+ glDisable(GL_DEPTH_TEST);
+ }
+
+ glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // first buffer clear
+ glClear(uiBufferBits);
+
+ if(bUseLines) // funny lines
+ {
+ glPolygonMode(GL_FRONT, GL_LINE);
+ glPolygonMode(GL_BACK, GL_LINE);
+ }
+ else // or the real filled thing
+ {
+ glPolygonMode(GL_FRONT, GL_FILL);
+ glPolygonMode(GL_BACK, GL_FILL);
+ }
+
+ MakeDisplayLists(); // lists for menu/opaque
+ GetExtInfos(); // get ext infos
+ SetExtGLFuncs(); // init all kind of stuff (tex function pointers)
+
+ glEnable(GL_ALPHA_TEST); // wanna alpha test
+
+ if(!bUseAntiAlias) // no anti-alias (default)
+ {
+ glDisable(GL_LINE_SMOOTH);
+ glDisable(GL_POLYGON_SMOOTH);
+ glDisable(GL_POINT_SMOOTH);
+ }
+ else // wanna try it? glitches galore...
+ {
+ glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_POLYGON_SMOOTH);
+ glEnable(GL_POINT_SMOOTH);
+ glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
+ glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
+ glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
+ }
+
+ ubGloAlpha=127; // init some drawing vars
+ ubGloColAlpha=127;
+ TWin.UScaleFactor = 1;
+ TWin.VScaleFactor = 1;
+ bDrawMultiPass=FALSE;
+ bTexEnabled=FALSE;
+ bUsingTWin=FALSE;
+
+ if(bDrawDither) glEnable(GL_DITHER); // dither mode
+ else glDisable(GL_DITHER);
+
+ glDisable(GL_FOG); // turn all (currently) unused modes off
+ glDisable(GL_LIGHTING);
+ glDisable(GL_LOGIC_OP);
+ glDisable(GL_STENCIL_TEST);
+ glDisable(GL_TEXTURE_1D);
+ glDisable(GL_TEXTURE_2D);
+ glDisable(GL_CULL_FACE);
+
+ glPixelTransferi(GL_RED_SCALE, 1); // to be sure:
+ glPixelTransferi(GL_RED_BIAS, 0); // init more OGL vals
+ glPixelTransferi(GL_GREEN_SCALE, 1);
+ glPixelTransferi(GL_GREEN_BIAS, 0);
+ glPixelTransferi(GL_BLUE_SCALE, 1);
+ glPixelTransferi(GL_BLUE_BIAS, 0);
+ glPixelTransferi(GL_ALPHA_SCALE, 1);
+ glPixelTransferi(GL_ALPHA_BIAS, 0);
+
+#ifdef _WINDOWS
+ // detect Windows hw/sw mode (just for info)
+ if(!strcmp("Microsoft Corporation",(LPTSTR)glGetString(GL_VENDOR)) &&
+ !strcmp("GDI Generic", (LPTSTR)glGetString(GL_RENDERER)))
+ bGLSoft=TRUE;
+ else bGLSoft=FALSE;
+#endif
+
+ glFlush(); // we are done...
+ glFinish();
+
+ CreateScanLines(); // setup scanline stuff (if wanted)
+
+ CheckTextureMemory(); // check available tex memory
+
+ if(bKeepRatio) SetAspectRatio(); // set ratio
+
+ if(iShowFPS) // user wants FPS display on startup?
+ {
+ ulKeybits|=KEY_SHOWFPS; // -> ok, turn display on
+ szDispBuf[0]=0;
+ BuildDispMenu(0);
+ }
+
+ bIsFirstFrame = FALSE; // we have survived the first frame :)
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////
+// clean up OGL stuff
+////////////////////////////////////////////////////////////////////////
+
+void GLcleanup()
+{
+ KillDisplayLists(); // bye display lists
+
+ if(iUseScanLines) // scanlines used?
+ {
+ if(iScanBlend<0)
+ {
+ if(gTexScanName!=0) // some scanline tex?
+ glDeleteTextures(1, &gTexScanName); // -> delete it
+ gTexScanName=0;
+ }
+ else glDeleteLists(uiScanLine,1); // otherwise del scanline display list
+ }
+
+ CleanupTextureStore(); // bye textures
+
+#ifdef _WINDOWS
+ wglMakeCurrent(NULL, NULL); // bye context
+ if(GLCONTEXT) wglDeleteContext(GLCONTEXT);
+ if(!bWindowMode && dcGlobal)
+ ReleaseDC(hWWindow,dcGlobal);
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+// Offset stuff
+////////////////////////////////////////////////////////////////////////
+
+// please note: it is hardly do-able in a hw/accel plugin to get the
+// real psx polygon coord mapping right... the following
+// works not to bad with many games, though
+
+static __inline BOOL CheckCoord4()
+{
+ if(lx0<0)
+ {
+ if(((lx1-lx0)>CHKMAX_X) ||
+ ((lx2-lx0)>CHKMAX_X))
+ {
+ if(lx3<0)
+ {
+ if((lx1-lx3)>CHKMAX_X) return TRUE;
+ if((lx2-lx3)>CHKMAX_X) return TRUE;
+ }
+ }
+ }
+ if(lx1<0)
+ {
+ if((lx0-lx1)>CHKMAX_X) return TRUE;
+ if((lx2-lx1)>CHKMAX_X) return TRUE;
+ if((lx3-lx1)>CHKMAX_X) return TRUE;
+ }
+ if(lx2<0)
+ {
+ if((lx0-lx2)>CHKMAX_X) return TRUE;
+ if((lx1-lx2)>CHKMAX_X) return TRUE;
+ if((lx3-lx2)>CHKMAX_X) return TRUE;
+ }
+ if(lx3<0)
+ {
+ if(((lx1-lx3)>CHKMAX_X) ||
+ ((lx2-lx3)>CHKMAX_X))
+ {
+ if(lx0<0)
+ {
+ if((lx1-lx0)>CHKMAX_X) return TRUE;
+ if((lx2-lx0)>CHKMAX_X) return TRUE;
+ }
+ }
+ }
+
+
+ if(ly0<0)
+ {
+ if((ly1-ly0)>CHKMAX_Y) return TRUE;
+ if((ly2-ly0)>CHKMAX_Y) return TRUE;
+ }
+ if(ly1<0)
+ {
+ if((ly0-ly1)>CHKMAX_Y) return TRUE;
+ if((ly2-ly1)>CHKMAX_Y) return TRUE;
+ if((ly3-ly1)>CHKMAX_Y) return TRUE;
+ }
+ if(ly2<0)
+ {
+ if((ly0-ly2)>CHKMAX_Y) return TRUE;
+ if((ly1-ly2)>CHKMAX_Y) return TRUE;
+ if((ly3-ly2)>CHKMAX_Y) return TRUE;
+ }
+ if(ly3<0)
+ {
+ if((ly1-ly3)>CHKMAX_Y) return TRUE;
+ if((ly2-ly3)>CHKMAX_Y) return TRUE;
+ }
+
+ return FALSE;
+}
+
+static __inline BOOL CheckCoord3()
+{
+ if(lx0<0)
+ {
+ if((lx1-lx0)>CHKMAX_X) return TRUE;
+ if((lx2-lx0)>CHKMAX_X) return TRUE;
+ }
+ if(lx1<0)
+ {
+ if((lx0-lx1)>CHKMAX_X) return TRUE;
+ if((lx2-lx1)>CHKMAX_X) return TRUE;
+ }
+ if(lx2<0)
+ {
+ if((lx0-lx2)>CHKMAX_X) return TRUE;
+ if((lx1-lx2)>CHKMAX_X) return TRUE;
+ }
+ if(ly0<0)
+ {
+ if((ly1-ly0)>CHKMAX_Y) return TRUE;
+ if((ly2-ly0)>CHKMAX_Y) return TRUE;
+ }
+ if(ly1<0)
+ {
+ if((ly0-ly1)>CHKMAX_Y) return TRUE;
+ if((ly2-ly1)>CHKMAX_Y) return TRUE;
+ }
+ if(ly2<0)
+ {
+ if((ly0-ly2)>CHKMAX_Y) return TRUE;
+ if((ly1-ly2)>CHKMAX_Y) return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+static __inline BOOL CheckCoord2()
+{
+ if(lx0<0)
+ {
+ if((lx1-lx0)>CHKMAX_X) return TRUE;
+ }
+ if(lx1<0)
+ {
+ if((lx0-lx1)>CHKMAX_X) return TRUE;
+ }
+ if(ly0<0)
+ {
+ if((ly1-ly0)>CHKMAX_Y) return TRUE;
+ }
+ if(ly1<0)
+ {
+ if((ly0-ly1)>CHKMAX_Y) return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*
+//Lewpys "offsetline" func:
+
+void offsetline(void)
+{
+ float x0, x1, y0, y1, oolength, xl, yl;
+
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ if(!(dwActFixes&16))
+ {
+ if((lx0 & SIGNBIT)) lx0|=S_MASK;
+ else lx0&=~S_MASK;
+ if((lx1 & SIGNBIT)) lx1|=S_MASK;
+ else lx1&=~S_MASK;
+ if((ly0 & SIGNBIT)) ly0|=S_MASK;
+ else ly0&=~S_MASK;
+ if((ly1 & SIGNBIT)) ly1|=S_MASK;
+ else ly1&=~S_MASK;
+ }
+
+ x0 = (float)(lx0 + PSXDisplay.CumulOffset.x);
+ x1 = (float)(lx1 + PSXDisplay.CumulOffset.x);
+ y0 = (float)(ly0 + PSXDisplay.CumulOffset.y);
+ y1 = (float)(ly1 + PSXDisplay.CumulOffset.y);
+
+ oolength = (float)1/((float)sqrt((y1 - y0)*(y1 - y0) + (x1 - x0)*(x1 - x0)) * (float)2);
+// oolength = (float)1/((float)sqrt(((y1 - y0)*(y1 - y0) + (x1 - x0)*(x1 - x0)) * (float)2));
+
+ xl = (x1 - x0) * oolength;
+ yl = (y1 - y0) * oolength;
+
+ x0 += 0.5f;
+ x1 += 0.5f;
+
+ x0 -= xl - yl;
+ x1 += xl + yl;
+ y0 -= yl + xl;
+ y1 += yl - xl;
+
+ vertex[0].x=x0;
+ vertex[1].x=x1;
+ vertex[0].y=y0;
+ vertex[1].y=y1;
+
+ x0 -= yl * 2;
+ x1 -= yl * 2;
+ y0 += xl * 2;
+ y1 += xl * 2;
+
+ vertex[2].x=x1;
+ vertex[3].x=x0;
+ vertex[2].y=y1;
+ vertex[3].y=y0;
+}
+*/
+
+
+// Pete's way: a very easy (and hopefully fast) approach for lines
+// without sqrt... using a small float -> short cast trick :)
+
+#define VERTEX_OFFX 0.2f
+#define VERTEX_OFFY 0.2f
+
+BOOL offsetline(void)
+{
+ short x0,x1,y0,y1,dx,dy;float px,py;
+
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ if(!(dwActFixes&16))
+ {
+ lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
+ lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
+ ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
+ ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
+
+ if(CheckCoord2()) return TRUE;
+ }
+
+ x0 = (lx0 + PSXDisplay.CumulOffset.x)+1;
+ x1 = (lx1 + PSXDisplay.CumulOffset.x)+1;
+ y0 = (ly0 + PSXDisplay.CumulOffset.y)+1;
+ y1 = (ly1 + PSXDisplay.CumulOffset.y)+1;
+
+ dx=x1-x0;
+ dy=y1-y0;
+
+ if(dx>=0)
+ {
+ if(dy>=0)
+ {
+ px=0.5f;
+ if(dx>dy) py=-0.5f;
+ else if(dx<dy) py= 0.5f;
+ else py= 0.0f;
+ }
+ else
+ {
+ py=-0.5f;
+ dy=-dy;
+ if(dx>dy) px= 0.5f;
+ else if(dx<dy) px=-0.5f;
+ else px= 0.0f;
+ }
+ }
+ else
+ {
+ if(dy>=0)
+ {
+ py=0.5f;
+ dx=-dx;
+ if(dx>dy) px=-0.5f;
+ else if(dx<dy) px= 0.5f;
+ else px= 0.0f;
+ }
+ else
+ {
+ px=-0.5f;
+ if(dx>dy) py=-0.5f;
+ else if(dx<dy) py= 0.5f;
+ else py= 0.0f;
+ }
+ }
+
+ vertex[0].x=(short)((float)x0-px);
+ vertex[3].x=(short)((float)x0+py);
+
+ vertex[0].y=(short)((float)y0-py);
+ vertex[3].y=(short)((float)y0-px);
+
+ vertex[1].x=(short)((float)x1-py);
+ vertex[2].x=(short)((float)x1+px);
+
+ vertex[1].y=(short)((float)y1+px);
+ vertex[2].y=(short)((float)y1+py);
+
+ if(vertex[0].x==vertex[3].x && // ortho rect? done
+ vertex[1].x==vertex[2].x &&
+ vertex[0].y==vertex[1].y &&
+ vertex[2].y==vertex[3].y) return FALSE;
+ if(vertex[0].x==vertex[1].x &&
+ vertex[2].x==vertex[3].x &&
+ vertex[0].y==vertex[3].y &&
+ vertex[1].y==vertex[2].y) return FALSE;
+
+ vertex[0].x-=VERTEX_OFFX; // otherwise a small offset
+ vertex[0].y-=VERTEX_OFFY; // to get better accuracy
+ vertex[1].x-=VERTEX_OFFX;
+ vertex[1].y-=VERTEX_OFFY;
+ vertex[2].x-=VERTEX_OFFX;
+ vertex[2].y-=VERTEX_OFFY;
+ vertex[3].x-=VERTEX_OFFX;
+ vertex[3].y-=VERTEX_OFFY;
+
+ return FALSE;
+}
+
+/////////////////////////////////////////////////////////
+
+BOOL offset2(void)
+{
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ if(!(dwActFixes&16))
+ {
+ lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
+ lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
+ ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
+ ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
+
+ if(CheckCoord2()) return TRUE;
+ }
+
+ vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
+ vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
+ vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
+ vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
+
+ return FALSE;
+}
+
+/////////////////////////////////////////////////////////
+
+BOOL offset3(void)
+{
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ if(!(dwActFixes&16))
+ {
+ lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
+ lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
+ lx2=(short)(((int)lx2<<SIGNSHIFT)>>SIGNSHIFT);
+ ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
+ ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
+ ly2=(short)(((int)ly2<<SIGNSHIFT)>>SIGNSHIFT);
+
+ if(CheckCoord3()) return TRUE;
+ }
+
+ vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
+ vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
+ vertex[2].x=lx2+PSXDisplay.CumulOffset.x;
+ vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
+ vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
+ vertex[2].y=ly2+PSXDisplay.CumulOffset.y;
+
+ return FALSE;
+}
+
+/////////////////////////////////////////////////////////
+
+BOOL offset4(void)
+{
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ if(!(dwActFixes&16))
+ {
+ lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
+ lx1=(short)(((int)lx1<<SIGNSHIFT)>>SIGNSHIFT);
+ lx2=(short)(((int)lx2<<SIGNSHIFT)>>SIGNSHIFT);
+ lx3=(short)(((int)lx3<<SIGNSHIFT)>>SIGNSHIFT);
+ ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
+ ly1=(short)(((int)ly1<<SIGNSHIFT)>>SIGNSHIFT);
+ ly2=(short)(((int)ly2<<SIGNSHIFT)>>SIGNSHIFT);
+ ly3=(short)(((int)ly3<<SIGNSHIFT)>>SIGNSHIFT);
+
+ if(CheckCoord4()) return TRUE;
+ }
+
+ vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
+ vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
+ vertex[2].x=lx2+PSXDisplay.CumulOffset.x;
+ vertex[3].x=lx3+PSXDisplay.CumulOffset.x;
+ vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
+ vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
+ vertex[2].y=ly2+PSXDisplay.CumulOffset.y;
+ vertex[3].y=ly3+PSXDisplay.CumulOffset.y;
+
+ return FALSE;
+}
+
+/////////////////////////////////////////////////////////
+
+void offsetST(void)
+{
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ if(!(dwActFixes&16))
+ {
+ lx0=(short)(((int)lx0<<SIGNSHIFT)>>SIGNSHIFT);
+ ly0=(short)(((int)ly0<<SIGNSHIFT)>>SIGNSHIFT);
+
+ if(lx0<-512 && PSXDisplay.DrawOffset.x<=-512)
+ lx0+=2048;
+
+ if(ly0<-512 && PSXDisplay.DrawOffset.y<=-512)
+ ly0+=2048;
+ }
+
+ ly1 = ly0;
+ ly2 = ly3 = ly0+sprtH;
+ lx3 = lx0;
+ lx1 = lx2 = lx0+sprtW;
+
+ vertex[0].x=lx0+PSXDisplay.CumulOffset.x;
+ vertex[1].x=lx1+PSXDisplay.CumulOffset.x;
+ vertex[2].x=lx2+PSXDisplay.CumulOffset.x;
+ vertex[3].x=lx3+PSXDisplay.CumulOffset.x;
+ vertex[0].y=ly0+PSXDisplay.CumulOffset.y;
+ vertex[1].y=ly1+PSXDisplay.CumulOffset.y;
+ vertex[2].y=ly2+PSXDisplay.CumulOffset.y;
+ vertex[3].y=ly3+PSXDisplay.CumulOffset.y;
+}
+
+/////////////////////////////////////////////////////////
+
+void offsetScreenUpload(int Position)
+{
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ if(Position==-1)
+ {
+ int lmdx,lmdy;
+
+ lmdx=xrUploadArea.x0;
+ lmdy=xrUploadArea.y0;
+
+ lx0-=lmdx;
+ ly0-=lmdy;
+ lx1-=lmdx;
+ ly1-=lmdy;
+ lx2-=lmdx;
+ ly2-=lmdy;
+ lx3-=lmdx;
+ ly3-=lmdy;
+ }
+ else
+ if(Position)
+ {
+ lx0-=PSXDisplay.DisplayPosition.x;
+ ly0-=PSXDisplay.DisplayPosition.y;
+ lx1-=PSXDisplay.DisplayPosition.x;
+ ly1-=PSXDisplay.DisplayPosition.y;
+ lx2-=PSXDisplay.DisplayPosition.x;
+ ly2-=PSXDisplay.DisplayPosition.y;
+ lx3-=PSXDisplay.DisplayPosition.x;
+ ly3-=PSXDisplay.DisplayPosition.y;
+ }
+ else
+ {
+ lx0-=PreviousPSXDisplay.DisplayPosition.x;
+ ly0-=PreviousPSXDisplay.DisplayPosition.y;
+ lx1-=PreviousPSXDisplay.DisplayPosition.x;
+ ly1-=PreviousPSXDisplay.DisplayPosition.y;
+ lx2-=PreviousPSXDisplay.DisplayPosition.x;
+ ly2-=PreviousPSXDisplay.DisplayPosition.y;
+ lx3-=PreviousPSXDisplay.DisplayPosition.x;
+ ly3-=PreviousPSXDisplay.DisplayPosition.y;
+ }
+
+ vertex[0].x=lx0 + PreviousPSXDisplay.Range.x0;
+ vertex[1].x=lx1 + PreviousPSXDisplay.Range.x0;
+ vertex[2].x=lx2 + PreviousPSXDisplay.Range.x0;
+ vertex[3].x=lx3 + PreviousPSXDisplay.Range.x0;
+ vertex[0].y=ly0 + PreviousPSXDisplay.Range.y0;
+ vertex[1].y=ly1 + PreviousPSXDisplay.Range.y0;
+ vertex[2].y=ly2 + PreviousPSXDisplay.Range.y0;
+ vertex[3].y=ly3 + PreviousPSXDisplay.Range.y0;
+
+ if(iUseMask)
+ {
+ vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
+ gl_z+=0.00004f;
+ }
+}
+
+/////////////////////////////////////////////////////////
+
+void offsetBlk(void)
+{
+ if(bDisplayNotSet)
+ SetOGLDisplaySettings(1);
+
+ vertex[0].x=lx0-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
+ vertex[1].x=lx1-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
+ vertex[2].x=lx2-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
+ vertex[3].x=lx3-PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
+ vertex[0].y=ly0-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
+ vertex[1].y=ly1-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
+ vertex[2].y=ly2-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
+ vertex[3].y=ly3-PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
+
+ if(iUseMask)
+ {
+ vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
+ gl_z+=0.00004f;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// texture sow/tow calculations
+////////////////////////////////////////////////////////////////////////
+
+void assignTextureVRAMWrite(void)
+{
+#ifdef OWNSCALE
+
+ vertex[0].sow=0.5f/ ST_FACVRAMX;
+ vertex[0].tow=0.5f/ ST_FACVRAM;
+
+ vertex[1].sow=(float)gl_ux[1]/ ST_FACVRAMX;
+ vertex[1].tow=0.5f/ ST_FACVRAM;
+
+ vertex[2].sow=(float)gl_ux[2]/ ST_FACVRAMX;
+ vertex[2].tow=(float)gl_vy[2]/ ST_FACVRAM;
+
+ vertex[3].sow=0.5f/ ST_FACVRAMX;
+ vertex[3].tow=(float)gl_vy[3]/ ST_FACVRAM;
+
+#else
+
+ if(gl_ux[1]==255)
+ {
+ vertex[0].sow=(gl_ux[0]*255.99f)/255.0f;
+ vertex[1].sow=(gl_ux[1]*255.99f)/255.0f;
+ vertex[2].sow=(gl_ux[2]*255.99f)/255.0f;
+ vertex[3].sow=(gl_ux[3]*255.99f)/255.0f;
+ }
+ else
+ {
+ vertex[0].sow=gl_ux[0];
+ vertex[1].sow=gl_ux[1];
+ vertex[2].sow=gl_ux[2];
+ vertex[3].sow=gl_ux[3];
+ }
+
+ vertex[0].tow=gl_vy[0];
+ vertex[1].tow=gl_vy[1];
+ vertex[2].tow=gl_vy[2];
+ vertex[3].tow=gl_vy[3];
+
+#endif
+}
+
+GLuint gLastTex=0;
+GLuint gLastFMode=(GLuint)-1;
+
+/////////////////////////////////////////////////////////
+
+void assignTextureSprite(void)
+{
+ if(bUsingTWin)
+ {
+ vertex[0].sow=vertex[3].sow=(float)gl_ux[0]/TWin.UScaleFactor;
+ vertex[1].sow=vertex[2].sow=(float)sSprite_ux2/TWin.UScaleFactor;
+ vertex[0].tow=vertex[1].tow=(float)gl_vy[0]/TWin.VScaleFactor;
+ vertex[2].tow=vertex[3].tow=(float)sSprite_vy2/TWin.VScaleFactor;
+ gLastTex=gTexName;
+
+ if(iFilterType>0 && iFilterType<3 && iHiResTextures!=2)
+ {
+ float fxmin=65536.0f,fxmax=0.0f,fymin=65536.0f,fymax=0.0f;int i;
+
+ for(i=0;i<4;i++)
+ {
+ if(vertex[i].sow<fxmin) fxmin=vertex[i].sow;
+ if(vertex[i].tow<fymin) fymin=vertex[i].tow;
+ if(vertex[i].sow>fxmax) fxmax=vertex[i].sow;
+ if(vertex[i].tow>fymax) fymax=vertex[i].tow;
+ }
+
+ for(i=0;i<4;i++)
+ {
+#ifdef OWNSCALE
+ if(vertex[i].sow==fxmin) vertex[i].sow+=0.375f/(float)TWin.Position.x1;
+ if(vertex[i].sow==fxmax) vertex[i].sow-=0.375f/(float)TWin.Position.x1;
+ if(vertex[i].tow==fymin) vertex[i].tow+=0.375f/(float)TWin.Position.y1;
+ if(vertex[i].tow==fymax) vertex[i].tow-=0.375f/(float)TWin.Position.y1;
+#else
+ if(vertex[i].sow==fxmin) vertex[i].sow+=96.0f/(float)TWin.Position.x1;
+ if(vertex[i].sow==fxmax) vertex[i].sow-=96.0f/(float)TWin.Position.x1;
+ if(vertex[i].tow==fymin) vertex[i].tow+=96.0f/(float)TWin.Position.y1;
+ if(vertex[i].tow==fymax) vertex[i].tow-=96.0f/(float)TWin.Position.y1;
+#endif
+ }
+ }
+
+ }
+ else
+ {
+#ifdef OWNSCALE
+
+ vertex[0].sow=vertex[3].sow=(float)gl_ux[0] / ST_FACSPRITE;
+ vertex[1].sow=vertex[2].sow=(float)sSprite_ux2 / ST_FACSPRITE;
+ vertex[0].tow=vertex[1].tow=(float)gl_vy[0] / ST_FACSPRITE;
+ vertex[2].tow=vertex[3].tow=(float)sSprite_vy2 / ST_FACSPRITE;
+
+#else
+
+ vertex[0].sow=vertex[3].sow=gl_ux[0];
+ vertex[1].sow=vertex[2].sow=sSprite_ux2;
+ vertex[0].tow=vertex[1].tow=gl_vy[0];
+ vertex[2].tow=vertex[3].tow=sSprite_vy2;
+
+#endif
+
+ if(iFilterType>2)
+ {
+ if(gLastTex!=gTexName || gLastFMode!=0)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ gLastTex=gTexName;gLastFMode=0;
+ }
+ }
+ }
+
+ if(usMirror & 0x1000)
+ {
+ vertex[0].sow=vertex[1].sow;
+ vertex[1].sow=vertex[2].sow=vertex[3].sow;
+ vertex[3].sow=vertex[0].sow;
+ }
+
+ if(usMirror & 0x2000)
+ {
+ vertex[0].tow=vertex[3].tow;
+ vertex[2].tow=vertex[3].tow=vertex[1].tow;
+ vertex[1].tow=vertex[0].tow;
+ }
+
+}
+
+/////////////////////////////////////////////////////////
+
+void assignTexture3(void)
+{
+ if(bUsingTWin)
+ {
+ vertex[0].sow=(float)gl_ux[0]/TWin.UScaleFactor;
+ vertex[0].tow=(float)gl_vy[0]/TWin.VScaleFactor;
+ vertex[1].sow=(float)gl_ux[1]/TWin.UScaleFactor;
+ vertex[1].tow=(float)gl_vy[1]/TWin.VScaleFactor;
+ vertex[2].sow=(float)gl_ux[2]/TWin.UScaleFactor;
+ vertex[2].tow=(float)gl_vy[2]/TWin.VScaleFactor;
+ gLastTex=gTexName;
+ }
+ else
+ {
+#ifdef OWNSCALE
+ vertex[0].sow=(float)gl_ux[0] / ST_FACTRI;
+ vertex[0].tow=(float)gl_vy[0] / ST_FACTRI;
+ vertex[1].sow=(float)gl_ux[1] / ST_FACTRI;
+
+ vertex[1].tow=(float)gl_vy[1] / ST_FACTRI;
+ vertex[2].sow=(float)gl_ux[2] / ST_FACTRI;
+ vertex[2].tow=(float)gl_vy[2] / ST_FACTRI;
+#else
+ vertex[0].sow=gl_ux[0];
+ vertex[0].tow=gl_vy[0];
+ vertex[1].sow=gl_ux[1];
+ vertex[1].tow=gl_vy[1];
+ vertex[2].sow=gl_ux[2];
+ vertex[2].tow=gl_vy[2];
+#endif
+
+ if(iFilterType>2)
+ {
+ if(gLastTex!=gTexName || gLastFMode!=1)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ gLastTex=gTexName;gLastFMode=1;
+ }
+ }
+
+ if(iFilterType)
+ {
+ float fxmin=256.0f,fxmax=0.0f,fymin=256.0f,fymax=0.0f;int i;
+ for(i=0;i<3;i++)
+ {
+ if(vertex[i].sow<fxmin) fxmin=vertex[i].sow;
+ if(vertex[i].tow<fymin) fymin=vertex[i].tow;
+ if(vertex[i].sow>fxmax) fxmax=vertex[i].sow;
+ if(vertex[i].tow>fymax) fymax=vertex[i].tow;
+ }
+
+ for(i=0;i<3;i++)
+ {
+ if(vertex[i].sow==fxmin) vertex[i].sow+=ST_BFFACSORT;
+ if(vertex[i].sow==fxmax) vertex[i].sow-=ST_BFFACSORT;
+ if(vertex[i].tow==fymin) vertex[i].tow+=ST_BFFACSORT;
+ if(vertex[i].tow==fymax) vertex[i].tow-=ST_BFFACSORT;
+ }
+ }
+ }
+}
+
+/////////////////////////////////////////////////////////
+
+void assignTexture4(void)
+{
+ if(bUsingTWin)
+ {
+ vertex[0].sow=(float)gl_ux[0]/TWin.UScaleFactor;
+ vertex[0].tow=(float)gl_vy[0]/TWin.VScaleFactor;
+ vertex[1].sow=(float)gl_ux[1]/TWin.UScaleFactor;
+ vertex[1].tow=(float)gl_vy[1]/TWin.VScaleFactor;
+ vertex[2].sow=(float)gl_ux[2]/TWin.UScaleFactor;
+ vertex[2].tow=(float)gl_vy[2]/TWin.VScaleFactor;
+ vertex[3].sow=(float)gl_ux[3]/TWin.UScaleFactor;
+ vertex[3].tow=(float)gl_vy[3]/TWin.VScaleFactor;
+ gLastTex=gTexName;
+ }
+ else
+ {
+#ifdef OWNSCALE
+ vertex[0].sow=(float)gl_ux[0] / ST_FAC;
+ vertex[0].tow=(float)gl_vy[0] / ST_FAC;
+ vertex[1].sow=(float)gl_ux[1] / ST_FAC;
+ vertex[1].tow=(float)gl_vy[1] / ST_FAC;
+ vertex[2].sow=(float)gl_ux[2] / ST_FAC;
+ vertex[2].tow=(float)gl_vy[2] / ST_FAC;
+ vertex[3].sow=(float)gl_ux[3] / ST_FAC;
+ vertex[3].tow=(float)gl_vy[3] / ST_FAC;
+#else
+ vertex[0].sow=gl_ux[0];
+ vertex[0].tow=gl_vy[0];
+ vertex[1].sow=gl_ux[1];
+ vertex[1].tow=gl_vy[1];
+ vertex[2].sow=gl_ux[2];
+ vertex[2].tow=gl_vy[2];
+ vertex[3].sow=gl_ux[3];
+ vertex[3].tow=gl_vy[3];
+#endif
+
+ if(iFilterType>2)
+ {
+ if(gLastTex!=gTexName || gLastFMode!=1)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ gLastTex=gTexName;gLastFMode=1;
+ }
+ }
+
+ if(iFilterType)
+ {
+ float fxmin=256.0f,fxmax=0.0f,fymin=256.0f,fymax=0.0f;int i;
+ for(i=0;i<4;i++)
+ {
+ if(vertex[i].sow<fxmin) fxmin=vertex[i].sow;
+ if(vertex[i].tow<fymin) fymin=vertex[i].tow;
+ if(vertex[i].sow>fxmax) fxmax=vertex[i].sow;
+ if(vertex[i].tow>fymax) fymax=vertex[i].tow;
+ }
+
+ for(i=0;i<4;i++)
+ {
+ if(vertex[i].sow==fxmin) vertex[i].sow+=ST_BFFACSORT;
+ if(vertex[i].sow==fxmax) vertex[i].sow-=ST_BFFACSORT;
+ if(vertex[i].tow==fymin) vertex[i].tow+=ST_BFFACSORT;
+ if(vertex[i].tow==fymax) vertex[i].tow-=ST_BFFACSORT;
+ }
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+// render pos / buffers
+////////////////////////////////////////////////////////////////////////
+
+#ifndef _WINDOWS
+#define EqualRect(pr1,pr2) ((pr1)->left==(pr2)->left && (pr1)->top==(pr2)->top && (pr1)->right==(pr2)->right && (pr1)->bottom==(pr2)->bottom)
+#endif
+
+////////////////////////////////////////////////////////////////////////
+// SetDisplaySettings: "simply" calcs the new drawing area and updates
+// the ogl clipping (scissor)
+
+BOOL bSetClip=FALSE;
+
+void SetOGLDisplaySettings(BOOL DisplaySet)
+{
+ static RECT rprev={0,0,0,0};
+ static RECT rC ={0,0,0,0};
+ static int iOldX=0;
+ static int iOldY=0;
+ RECT r;float XS,YS;
+
+ bDisplayNotSet = FALSE;
+
+ //----------------------------------------------------// that's a whole screen upload
+ if(!DisplaySet)
+ {
+ RECT rX;
+ PSXDisplay.GDrawOffset.x=0;
+ PSXDisplay.GDrawOffset.y=0;
+
+ PSXDisplay.CumulOffset.x = PSXDisplay.DrawOffset.x+PreviousPSXDisplay.Range.x0;
+ PSXDisplay.CumulOffset.y = PSXDisplay.DrawOffset.y+PreviousPSXDisplay.Range.y0;
+
+ rprev.left=rprev.left+1;
+
+ rX=rRatioRect;
+ rX.top=iResY-(rRatioRect.top+rRatioRect.bottom);
+
+ if(bSetClip || !EqualRect(&rC,&rX))
+ {
+ rC=rX;
+ glScissor(rC.left,rC.top,rC.right,rC.bottom);
+ bSetClip=FALSE;
+ }
+ return;
+ }
+ //----------------------------------------------------//
+
+ PSXDisplay.GDrawOffset.y = PreviousPSXDisplay.DisplayPosition.y;
+ PSXDisplay.GDrawOffset.x = PreviousPSXDisplay.DisplayPosition.x;
+ PSXDisplay.CumulOffset.x = PSXDisplay.DrawOffset.x - PSXDisplay.GDrawOffset.x+PreviousPSXDisplay.Range.x0;
+ PSXDisplay.CumulOffset.y = PSXDisplay.DrawOffset.y - PSXDisplay.GDrawOffset.y+PreviousPSXDisplay.Range.y0;
+
+ r.top =PSXDisplay.DrawArea.y0 - PreviousPSXDisplay.DisplayPosition.y;
+ r.bottom=PSXDisplay.DrawArea.y1 - PreviousPSXDisplay.DisplayPosition.y;
+
+ if(r.bottom<0 || r.top>=PSXDisplay.DisplayMode.y)
+ {
+ r.top =PSXDisplay.DrawArea.y0 - PSXDisplay.DisplayPosition.y;
+ r.bottom=PSXDisplay.DrawArea.y1 - PSXDisplay.DisplayPosition.y;
+ }
+
+ r.left =PSXDisplay.DrawArea.x0 - PreviousPSXDisplay.DisplayPosition.x;
+ r.right =PSXDisplay.DrawArea.x1 - PreviousPSXDisplay.DisplayPosition.x;
+
+ if(r.right<0 || r.left>=PSXDisplay.DisplayMode.x)
+ {
+ r.left =PSXDisplay.DrawArea.x0 - PSXDisplay.DisplayPosition.x;
+ r.right =PSXDisplay.DrawArea.x1 - PSXDisplay.DisplayPosition.x;
+ }
+
+ if(!bSetClip && EqualRect(&r,&rprev) &&
+ iOldX == PSXDisplay.DisplayMode.x &&
+ iOldY == PSXDisplay.DisplayMode.y)
+ return;
+
+ rprev = r;
+ iOldX = PSXDisplay.DisplayMode.x;
+ iOldY = PSXDisplay.DisplayMode.y;
+
+ XS=(float)rRatioRect.right/(float)PSXDisplay.DisplayMode.x;
+ YS=(float)rRatioRect.bottom/(float)PSXDisplay.DisplayMode.y;
+
+ if(PreviousPSXDisplay.Range.x0)
+ {
+ short s=PreviousPSXDisplay.Range.x0+PreviousPSXDisplay.Range.x1;
+
+ r.left+=PreviousPSXDisplay.Range.x0+1;
+
+ r.right+=PreviousPSXDisplay.Range.x0;
+
+ if(r.left>s) r.left=s;
+ if(r.right>s) r.right=s;
+ }
+
+ if(PreviousPSXDisplay.Range.y0)
+ {
+ short s=PreviousPSXDisplay.Range.y0+PreviousPSXDisplay.Range.y1;
+
+ r.top+=PreviousPSXDisplay.Range.y0+1;
+ r.bottom+=PreviousPSXDisplay.Range.y0;
+
+ if(r.top>s) r.top=s;
+ if(r.bottom>s) r.bottom=s;
+ }
+
+ // Set the ClipArea variables to reflect the new screen,
+ // offset from zero (since it is a new display buffer)
+ r.left = (int)(((float)(r.left)) *XS);
+ r.top = (int)(((float)(r.top)) *YS);
+ r.right = (int)(((float)(r.right + 1))*XS);
+ r.bottom = (int)(((float)(r.bottom + 1))*YS);
+
+ // Limit clip area to the screen size
+ if (r.left > iResX) r.left = iResX;
+ if (r.left < 0) r.left = 0;
+ if (r.top > iResY) r.top = iResY;
+ if (r.top < 0) r.top = 0;
+ if (r.right > iResX) r.right = iResX;
+ if (r.right < 0) r.right = 0;
+ if (r.bottom > iResY) r.bottom = iResY;
+ if (r.bottom < 0) r.bottom = 0;
+
+ r.right -=r.left;
+ r.bottom-=r.top;
+ r.top=iResY-(r.top+r.bottom);
+
+ r.left+=rRatioRect.left;
+ r.top -=rRatioRect.top;
+
+ if(bSetClip || !EqualRect(&r,&rC))
+ {
+ glScissor(r.left,r.top,r.right,r.bottom);
+ rC=r;
+ bSetClip=FALSE;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+
diff --git a/plugins/peopsxgl/fps.c b/plugins/peopsxgl/fps.c
index dc89600f..e7e0b3fe 100644
--- a/plugins/peopsxgl/fps.c
+++ b/plugins/peopsxgl/fps.c
@@ -1,396 +1,399 @@
-/***************************************************************************
- fps.c - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
-//*************************************************************************//
-// History of changes:
-//
-// 2009/03/08 - Pete
-// - generic cleanup for the Peops release
-//
-//*************************************************************************//
-
-#include "stdafx.h"
-
-#define _IN_FPS
-
-#include "externals.h"
-
-////////////////////////////////////////////////////////////////////////
-// FPS stuff
-////////////////////////////////////////////////////////////////////////
-
-BOOL bIsPerformanceCounter=FALSE;
-float fFrameRateHz=0;
-DWORD dwFrameRateTicks=16;
-float fFrameRate;
-int iFrameLimit;
-BOOL bUseFrameLimit=FALSE;
-BOOL bUseFrameSkip=0;
-DWORD dwLaceCnt=0;
-
-////////////////////////////////////////////////////////////////////////
-// FPS skipping / limit
-////////////////////////////////////////////////////////////////////////
-
-BOOL bInitCap = TRUE;
-float fps_skip = 0;
-float fps_cur = 0;
-
-#define TIMEBASE 100000
-
-unsigned long timeGetTime()
-{
- struct timeval tv;
- gettimeofday(&tv, 0); // well, maybe there are better ways
- return tv.tv_sec * 100000 + tv.tv_usec/10; // to do that in linux, but at least it works
-}
-
-void FrameCap(void)
-{
- static unsigned long curticks, lastticks, _ticks_since_last_update;
- static unsigned long TicksToWait = 0;
- bool Waiting = TRUE;
-
- {
- curticks = timeGetTime();
- _ticks_since_last_update = curticks - lastticks;
-
- if((_ticks_since_last_update > TicksToWait) ||
- (curticks <lastticks))
- {
- lastticks = curticks;
-
- if((_ticks_since_last_update-TicksToWait) > dwFrameRateTicks)
- TicksToWait=0;
- else TicksToWait=dwFrameRateTicks-(_ticks_since_last_update-TicksToWait);
- }
- else
- {
- while (Waiting)
- {
- curticks = timeGetTime();
- _ticks_since_last_update = curticks - lastticks;
- if ((_ticks_since_last_update > TicksToWait) ||
- (curticks < lastticks))
- {
- Waiting = FALSE;
- lastticks = curticks;
- TicksToWait = dwFrameRateTicks;
- }
- }
- }
- }
-}
-
-#define MAXSKIP 120
-#define MAXLACE 16
-
-void FrameSkip(void)
-{
- static int iNumSkips=0,iAdditionalSkip=0; // number of additional frames to skip
- static DWORD dwLastLace=0; // helper var for frame limitation
- static DWORD curticks, lastticks, _ticks_since_last_update;
-
- if(!dwLaceCnt) return; // important: if no updatelace happened, we ignore it completely
-
- if(iNumSkips) // we are in skipping mode?
- {
- dwLastLace+=dwLaceCnt; // -> calc frame limit helper (number of laces)
- bSkipNextFrame = TRUE; // -> we skip next frame
- iNumSkips--; // -> ok, one done
- }
- else // ok, no additional skipping has to be done...
- { // we check now, if some limitation is needed, or a new skipping has to get started
- DWORD dwWaitTime;
-
- if(bInitCap || bSkipNextFrame) // first time or we skipped before?
- {
- if(bUseFrameLimit && !bInitCap) // frame limit wanted and not first time called?
- {
- DWORD dwT=_ticks_since_last_update; // -> that's the time of the last drawn frame
- dwLastLace+=dwLaceCnt; // -> and that's the number of updatelace since the start of the last drawn frame
-
- curticks = timeGetTime();
- _ticks_since_last_update= dwT+curticks - lastticks;
-
- dwWaitTime=dwLastLace*dwFrameRateTicks; // -> and now we calc the time the real psx would have needed
-
- if(_ticks_since_last_update<dwWaitTime) // -> we were too fast?
- {
- if((dwWaitTime-_ticks_since_last_update)> // -> some more security, to prevent
- (60*dwFrameRateTicks)) // wrong waiting times
- _ticks_since_last_update=dwWaitTime;
-
- while(_ticks_since_last_update<dwWaitTime) // -> loop until we have reached the real psx time
- { // (that's the additional limitation, yup)
- curticks = timeGetTime();
- _ticks_since_last_update = dwT+curticks - lastticks;
- }
- }
- else // we were still too slow ?!!?
- {
- if(iAdditionalSkip<MAXSKIP) // -> well, somewhen we really have to stop skipping on very slow systems
- {
- iAdditionalSkip++; // -> inc our watchdog var
- dwLaceCnt=0; // -> reset lace count
- lastticks = timeGetTime();
- return; // -> done, we will skip next frame to get more speed
- }
- }
- }
-
- bInitCap=FALSE; // -> ok, we have inited the frameskip func
- iAdditionalSkip=0; // -> init additional skip
- bSkipNextFrame=FALSE; // -> we don't skip the next frame
- lastticks = timeGetTime();
- dwLaceCnt=0; // -> and we start to count the laces
- dwLastLace=0;
- _ticks_since_last_update=0;
- return; // -> done, the next frame will get drawn
- }
-
- bSkipNextFrame=FALSE; // init the frame skip signal to 'no skipping' first
-
- curticks = timeGetTime();
- _ticks_since_last_update = curticks - lastticks;
-
- dwLastLace=dwLaceCnt; // store curr count (frame limitation helper)
- dwWaitTime=dwLaceCnt*dwFrameRateTicks; // calc the 'real psx lace time'
-
- if(_ticks_since_last_update>dwWaitTime) // hey, we needed way too long for that frame...
- {
- if(bUseFrameLimit) // if limitation, we skip just next frame,
- { // and decide after, if we need to do more
- iNumSkips=0;
- }
- else
- {
- iNumSkips=_ticks_since_last_update/dwWaitTime; // -> calc number of frames to skip to catch up
- iNumSkips--; // -> since we already skip next frame, one down
- if(iNumSkips>MAXSKIP) iNumSkips=MAXSKIP; // -> well, somewhere we have to draw a line
- }
- bSkipNextFrame = TRUE; // -> signal for skipping the next frame
- }
- else // we were faster than real psx? fine :)
- if(bUseFrameLimit) // frame limit used? so we wait til the 'real psx time' has been reached
- {
- if(dwLaceCnt>MAXLACE) // -> security check
- _ticks_since_last_update=dwWaitTime;
-
- while(_ticks_since_last_update<dwWaitTime) // just do a waiting loop...
- {
- curticks = timeGetTime();
- _ticks_since_last_update = curticks - lastticks;
- }
- }
-
- lastticks = timeGetTime();
- }
-
- dwLaceCnt=0; // init lace counter
-}
-
-void calcfps(void)
-{
- static unsigned long curticks,_ticks_since_last_update,lastticks;
- static long fps_cnt = 0;
- static unsigned long fps_tck = 1;
- static long fpsskip_cnt = 0;
- static unsigned long fpsskip_tck = 1;
-
- {
- curticks = timeGetTime();
- _ticks_since_last_update=curticks-lastticks;
-
- if(bUseFrameSkip && !bUseFrameLimit && _ticks_since_last_update)
- fps_skip=min(fps_skip,((float)TIMEBASE/(float)_ticks_since_last_update+1.0f));
-
- lastticks = curticks;
- }
-
- if(bUseFrameSkip && bUseFrameLimit)
- {
- fpsskip_tck += _ticks_since_last_update;
-
- if(++fpsskip_cnt==2)
- {
- fps_skip = (float)2000/(float)fpsskip_tck;
-
- fps_skip +=6.0f;
-
- fpsskip_cnt = 0;
- fpsskip_tck = 1;
- }
- }
-
- fps_tck += _ticks_since_last_update;
-
- if(++fps_cnt==10)
- {
- fps_cur = (float)(TIMEBASE*10)/(float)fps_tck;
-
- fps_cnt = 0;
- fps_tck = 1;
-
- if(bUseFrameLimit && fps_cur>fFrameRateHz) // optical adjust ;) avoids flickering fps display
- fps_cur=fFrameRateHz;
- }
-}
-
-void PCFrameCap (void)
-{
- static unsigned long curticks, lastticks, _ticks_since_last_update;
- static unsigned long TicksToWait = 0;
- bool Waiting = TRUE;
-
- while (Waiting)
- {
- curticks = timeGetTime();
- _ticks_since_last_update = curticks - lastticks;
- if ((_ticks_since_last_update > TicksToWait) ||
- (curticks < lastticks))
- {
- Waiting = FALSE;
- lastticks = curticks;
- TicksToWait = (TIMEBASE / (unsigned long)fFrameRateHz);
- }
- }
-}
-
-void PCcalcfps(void)
-{
- static unsigned long curticks,_ticks_since_last_update,lastticks;
- static long fps_cnt = 0;
- static float fps_acc = 0;
- float CurrentFPS=0;
-
- curticks = timeGetTime();
- _ticks_since_last_update=curticks-lastticks;
- if(_ticks_since_last_update)
- CurrentFPS=(float)TIMEBASE/(float)_ticks_since_last_update;
- else CurrentFPS = 0;
- lastticks = curticks;
-
- fps_acc += CurrentFPS;
-
- if(++fps_cnt==10)
- {
- fps_cur = fps_acc / 10;
- fps_acc = 0;
- fps_cnt = 0;
- }
-
- fps_skip=CurrentFPS+1.0f;
-}
-
-void SetAutoFrameCap(void)
-{
- if(iFrameLimit==1)
- {
- fFrameRateHz = fFrameRate;
- dwFrameRateTicks=(TIMEBASE / (unsigned long)fFrameRateHz);
- return;
- }
-
- if(dwActFixes&128)
- {
- if (PSXDisplay.Interlaced)
- fFrameRateHz = PSXDisplay.PAL?50.0f:60.0f;
- else fFrameRateHz = PSXDisplay.PAL?25.0f:30.0f;
- }
- else
- {
- //fFrameRateHz = PSXDisplay.PAL?50.0f:59.94f;
-
- if(PSXDisplay.PAL)
- {
- if (STATUSREG&GPUSTATUS_INTERLACED)
- fFrameRateHz=33868800.0f/677343.75f; // 50.00238
- else fFrameRateHz=33868800.0f/680595.00f; // 49.76351
- }
- else
- {
- if (STATUSREG&GPUSTATUS_INTERLACED)
- fFrameRateHz=33868800.0f/565031.25f; // 59.94146
- else fFrameRateHz=33868800.0f/566107.50f; // 59.82750
- }
-
- dwFrameRateTicks=(TIMEBASE / (unsigned long)fFrameRateHz);
- }
-}
-
-void SetFrameRateConfig(void)
-{
- if(!fFrameRate) fFrameRate=200.0f;
-
- if(fFrameRateHz==0)
- {
- if(iFrameLimit==2) fFrameRateHz=59.94f; // auto framerate? set some init val (no pal/ntsc known yet)
- else fFrameRateHz=fFrameRate; // else set user framerate
- }
-
- dwFrameRateTicks=(TIMEBASE / (unsigned long)fFrameRateHz);
-
- if(iFrameLimit==2) SetAutoFrameCap();
-}
-
-void InitFrameCap(void)
-{
-}
-
-void ReInitFrameCap(void)
-{
-}
-
-void CheckFrameRate(void) // called in updatelace (on every emulated psx vsync)
-{
- if(bUseFrameSkip)
- {
- if(!(dwActFixes&0x100))
- {
- dwLaceCnt++; // -> and store cnt of vsync between frames
- if(dwLaceCnt>=MAXLACE && bUseFrameLimit)
- {
- if(dwLaceCnt==MAXLACE) bInitCap=TRUE;
- FrameCap();
- }
- }
- else if(bUseFrameLimit) FrameCap();
- calcfps(); // -> calc fps display in skipping mode
- }
- else // -> non-skipping mode:
- {
- if(bUseFrameLimit) FrameCap();
- if(ulKeybits&KEY_SHOWFPS) calcfps();
- }
-}
-
-void CALLBACK GPUsetframelimit(unsigned long option) // new EPSXE interface func: main emu can enable/disable fps limitation this way
-{
- bInitCap = TRUE;
-
- if(option==1) // emu says: limit
- {
- bUseFrameLimit=TRUE;bUseFrameSkip=FALSE;iFrameLimit=2;
- SetAutoFrameCap();
- }
- else // emu says: no limit
- {
- bUseFrameLimit=FALSE;
- }
-}
+/***************************************************************************
+ fps.c - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+//*************************************************************************//
+// History of changes:
+//
+// 2009/03/08 - Pete
+// - generic cleanup for the Peops release
+//
+//*************************************************************************//
+
+#include "stdafx.h"
+
+#define _IN_FPS
+
+#include "externals.h"
+#include "fps.h"
+
+////////////////////////////////////////////////////////////////////////
+// FPS stuff
+////////////////////////////////////////////////////////////////////////
+
+BOOL bIsPerformanceCounter=FALSE;
+float fFrameRateHz=0;
+DWORD dwFrameRateTicks=16;
+float fFrameRate;
+int iFrameLimit;
+BOOL bUseFrameLimit=FALSE;
+BOOL bUseFrameSkip=0;
+DWORD dwLaceCnt=0;
+
+////////////////////////////////////////////////////////////////////////
+// FPS skipping / limit
+////////////////////////////////////////////////////////////////////////
+
+BOOL bInitCap = TRUE;
+float fps_skip = 0;
+float fps_cur = 0;
+
+#define TIMEBASE 100000
+
+unsigned long timeGetTime()
+{
+ struct timeval tv;
+ gettimeofday(&tv, 0); // well, maybe there are better ways
+ return tv.tv_sec * 100000 + tv.tv_usec/10; // to do that in linux, but at least it works
+}
+
+static void FrameCap(void)
+{
+ static unsigned long curticks, lastticks, _ticks_since_last_update;
+ static unsigned long TicksToWait = 0;
+ bool Waiting = TRUE;
+
+ {
+ curticks = timeGetTime();
+ _ticks_since_last_update = curticks - lastticks;
+
+ if((_ticks_since_last_update > TicksToWait) ||
+ (curticks <lastticks))
+ {
+ lastticks = curticks;
+
+ if((_ticks_since_last_update-TicksToWait) > dwFrameRateTicks)
+ TicksToWait=0;
+ else TicksToWait=dwFrameRateTicks-(_ticks_since_last_update-TicksToWait);
+ }
+ else
+ {
+ while (Waiting)
+ {
+ curticks = timeGetTime();
+ _ticks_since_last_update = curticks - lastticks;
+ if ((_ticks_since_last_update > TicksToWait) ||
+ (curticks < lastticks))
+ {
+ Waiting = FALSE;
+ lastticks = curticks;
+ TicksToWait = dwFrameRateTicks;
+ }
+ }
+ }
+ }
+}
+
+#define MAXSKIP 120
+#define MAXLACE 16
+
+void FrameSkip(void)
+{
+ static int iNumSkips=0,iAdditionalSkip=0; // number of additional frames to skip
+ static DWORD dwLastLace=0; // helper var for frame limitation
+ static DWORD curticks, lastticks, _ticks_since_last_update;
+
+ if(!dwLaceCnt) return; // important: if no updatelace happened, we ignore it completely
+
+ if(iNumSkips) // we are in skipping mode?
+ {
+ dwLastLace+=dwLaceCnt; // -> calc frame limit helper (number of laces)
+ bSkipNextFrame = TRUE; // -> we skip next frame
+ iNumSkips--; // -> ok, one done
+ }
+ else // ok, no additional skipping has to be done...
+ { // we check now, if some limitation is needed, or a new skipping has to get started
+ DWORD dwWaitTime;
+
+ if(bInitCap || bSkipNextFrame) // first time or we skipped before?
+ {
+ if(bUseFrameLimit && !bInitCap) // frame limit wanted and not first time called?
+ {
+ DWORD dwT=_ticks_since_last_update; // -> that's the time of the last drawn frame
+ dwLastLace+=dwLaceCnt; // -> and that's the number of updatelace since the start of the last drawn frame
+
+ curticks = timeGetTime();
+ _ticks_since_last_update= dwT+curticks - lastticks;
+
+ dwWaitTime=dwLastLace*dwFrameRateTicks; // -> and now we calc the time the real psx would have needed
+
+ if(_ticks_since_last_update<dwWaitTime) // -> we were too fast?
+ {
+ if((dwWaitTime-_ticks_since_last_update)> // -> some more security, to prevent
+ (60*dwFrameRateTicks)) // wrong waiting times
+ _ticks_since_last_update=dwWaitTime;
+
+ while(_ticks_since_last_update<dwWaitTime) // -> loop until we have reached the real psx time
+ { // (that's the additional limitation, yup)
+ curticks = timeGetTime();
+ _ticks_since_last_update = dwT+curticks - lastticks;
+ }
+ }
+ else // we were still too slow ?!!?
+ {
+ if(iAdditionalSkip<MAXSKIP) // -> well, somewhen we really have to stop skipping on very slow systems
+ {
+ iAdditionalSkip++; // -> inc our watchdog var
+ dwLaceCnt=0; // -> reset lace count
+ lastticks = timeGetTime();
+ return; // -> done, we will skip next frame to get more speed
+ }
+ }
+ }
+
+ bInitCap=FALSE; // -> ok, we have inited the frameskip func
+ iAdditionalSkip=0; // -> init additional skip
+ bSkipNextFrame=FALSE; // -> we don't skip the next frame
+ lastticks = timeGetTime();
+ dwLaceCnt=0; // -> and we start to count the laces
+ dwLastLace=0;
+ _ticks_since_last_update=0;
+ return; // -> done, the next frame will get drawn
+ }
+
+ bSkipNextFrame=FALSE; // init the frame skip signal to 'no skipping' first
+
+ curticks = timeGetTime();
+ _ticks_since_last_update = curticks - lastticks;
+
+ dwLastLace=dwLaceCnt; // store curr count (frame limitation helper)
+ dwWaitTime=dwLaceCnt*dwFrameRateTicks; // calc the 'real psx lace time'
+
+ if(_ticks_since_last_update>dwWaitTime) // hey, we needed way too long for that frame...
+ {
+ if(bUseFrameLimit) // if limitation, we skip just next frame,
+ { // and decide after, if we need to do more
+ iNumSkips=0;
+ }
+ else
+ {
+ iNumSkips=_ticks_since_last_update/dwWaitTime; // -> calc number of frames to skip to catch up
+ iNumSkips--; // -> since we already skip next frame, one down
+ if(iNumSkips>MAXSKIP) iNumSkips=MAXSKIP; // -> well, somewhere we have to draw a line
+ }
+ bSkipNextFrame = TRUE; // -> signal for skipping the next frame
+ }
+ else // we were faster than real psx? fine :)
+ if(bUseFrameLimit) // frame limit used? so we wait til the 'real psx time' has been reached
+ {
+ if(dwLaceCnt>MAXLACE) // -> security check
+ _ticks_since_last_update=dwWaitTime;
+
+ while(_ticks_since_last_update<dwWaitTime) // just do a waiting loop...
+ {
+ curticks = timeGetTime();
+ _ticks_since_last_update = curticks - lastticks;
+ }
+ }
+
+ lastticks = timeGetTime();
+ }
+
+ dwLaceCnt=0; // init lace counter
+}
+
+static void calcfps(void)
+{
+ static unsigned long curticks,_ticks_since_last_update,lastticks;
+ static long fps_cnt = 0;
+ static unsigned long fps_tck = 1;
+ static long fpsskip_cnt = 0;
+ static unsigned long fpsskip_tck = 1;
+
+ {
+ curticks = timeGetTime();
+ _ticks_since_last_update=curticks-lastticks;
+
+ if(bUseFrameSkip && !bUseFrameLimit && _ticks_since_last_update)
+ fps_skip=min(fps_skip,((float)TIMEBASE/(float)_ticks_since_last_update+1.0f));
+
+ lastticks = curticks;
+ }
+
+ if(bUseFrameSkip && bUseFrameLimit)
+ {
+ fpsskip_tck += _ticks_since_last_update;
+
+ if(++fpsskip_cnt==2)
+ {
+ fps_skip = (float)2000/(float)fpsskip_tck;
+
+ fps_skip +=6.0f;
+
+ fpsskip_cnt = 0;
+ fpsskip_tck = 1;
+ }
+ }
+
+ fps_tck += _ticks_since_last_update;
+
+ if(++fps_cnt==10)
+ {
+ fps_cur = (float)(TIMEBASE*10)/(float)fps_tck;
+
+ fps_cnt = 0;
+ fps_tck = 1;
+
+ if(bUseFrameLimit && fps_cur>fFrameRateHz) // optical adjust ;) avoids flickering fps display
+ fps_cur=fFrameRateHz;
+ }
+}
+
+void PCFrameCap (void)
+{
+ static unsigned long curticks, lastticks, _ticks_since_last_update;
+ static unsigned long TicksToWait = 0;
+ bool Waiting = TRUE;
+
+ while (Waiting)
+ {
+ curticks = timeGetTime();
+ _ticks_since_last_update = curticks - lastticks;
+ if ((_ticks_since_last_update > TicksToWait) ||
+ (curticks < lastticks))
+ {
+ Waiting = FALSE;
+ lastticks = curticks;
+ TicksToWait = (TIMEBASE / (unsigned long)fFrameRateHz);
+ }
+ }
+}
+
+void PCcalcfps(void)
+{
+ static unsigned long curticks,_ticks_since_last_update,lastticks;
+ static long fps_cnt = 0;
+ static float fps_acc = 0;
+ float CurrentFPS=0;
+
+ curticks = timeGetTime();
+ _ticks_since_last_update=curticks-lastticks;
+ if(_ticks_since_last_update)
+ CurrentFPS=(float)TIMEBASE/(float)_ticks_since_last_update;
+ else CurrentFPS = 0;
+ lastticks = curticks;
+
+ fps_acc += CurrentFPS;
+
+ if(++fps_cnt==10)
+ {
+ fps_cur = fps_acc / 10;
+ fps_acc = 0;
+ fps_cnt = 0;
+ }
+
+ fps_skip=CurrentFPS+1.0f;
+}
+
+void SetAutoFrameCap(void)
+{
+ if(iFrameLimit==1)
+ {
+ fFrameRateHz = fFrameRate;
+ dwFrameRateTicks=(TIMEBASE / (unsigned long)fFrameRateHz);
+ return;
+ }
+
+ if(dwActFixes&128)
+ {
+ if (PSXDisplay.Interlaced)
+ fFrameRateHz = PSXDisplay.PAL?50.0f:60.0f;
+ else fFrameRateHz = PSXDisplay.PAL?25.0f:30.0f;
+ }
+ else
+ {
+ //fFrameRateHz = PSXDisplay.PAL?50.0f:59.94f;
+
+ if(PSXDisplay.PAL)
+ {
+ if (STATUSREG&GPUSTATUS_INTERLACED)
+ fFrameRateHz=33868800.0f/677343.75f; // 50.00238
+ else fFrameRateHz=33868800.0f/680595.00f; // 49.76351
+ }
+ else
+ {
+ if (STATUSREG&GPUSTATUS_INTERLACED)
+ fFrameRateHz=33868800.0f/565031.25f; // 59.94146
+ else fFrameRateHz=33868800.0f/566107.50f; // 59.82750
+ }
+
+ dwFrameRateTicks=(TIMEBASE / (unsigned long)fFrameRateHz);
+ }
+}
+
+void SetFrameRateConfig(void)
+{
+ if(!fFrameRate) fFrameRate=200.0f;
+
+ if(fFrameRateHz==0)
+ {
+ if(iFrameLimit==2) fFrameRateHz=59.94f; // auto framerate? set some init val (no pal/ntsc known yet)
+ else fFrameRateHz=fFrameRate; // else set user framerate
+ }
+
+ dwFrameRateTicks=(TIMEBASE / (unsigned long)fFrameRateHz);
+
+ if(iFrameLimit==2) SetAutoFrameCap();
+}
+
+void InitFrameCap(void)
+{
+}
+
+void ReInitFrameCap(void)
+{
+}
+
+void CheckFrameRate(void) // called in updatelace (on every emulated psx vsync)
+{
+ if(bUseFrameSkip)
+ {
+ if(!(dwActFixes&0x100))
+ {
+ dwLaceCnt++; // -> and store cnt of vsync between frames
+ if(dwLaceCnt>=MAXLACE && bUseFrameLimit)
+ {
+ if(dwLaceCnt==MAXLACE) bInitCap=TRUE;
+ FrameCap();
+ }
+ }
+ else if(bUseFrameLimit) FrameCap();
+ calcfps(); // -> calc fps display in skipping mode
+ }
+ else // -> non-skipping mode:
+ {
+ if(bUseFrameLimit) FrameCap();
+ if(ulKeybits&KEY_SHOWFPS) calcfps();
+ }
+}
+
+#if 0 /* unused by pcsx */
+void CALLBACK GPUsetframelimit(unsigned long option) // new EPSXE interface func: main emu can enable/disable fps limitation this way
+{
+ bInitCap = TRUE;
+
+ if(option==1) // emu says: limit
+ {
+ bUseFrameLimit=TRUE;bUseFrameSkip=FALSE;iFrameLimit=2;
+ SetAutoFrameCap();
+ }
+ else // emu says: no limit
+ {
+ bUseFrameLimit=FALSE;
+ }
+}
+#endif
diff --git a/plugins/peopsxgl/gpu.c b/plugins/peopsxgl/gpu.c
index f379372b..092d32a5 100644
--- a/plugins/peopsxgl/gpu.c
+++ b/plugins/peopsxgl/gpu.c
@@ -1,3529 +1,3527 @@
-/***************************************************************************
- gpu.c - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- email : BlackDove@addcom.de
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
-// !!! enable this, if Linux XF86VidMode is not supported:
-//#define NOVMODE
-
-#include "stdafx.h"
-
-#if !defined(_MACGL) && !defined(_WINDOWS)
-
-#include "config.h"
-
-#ifndef NOVMODE
-#include <X11/extensions/xf86vmode.h>
-static XF86VidModeModeInfo **modes=0;
-static int iOldMode=0;
-#endif
-
-#endif
-
-#define _IN_GPU
-
-#include "externals.h"
-#include "gpu.h"
-#include "draw.h"
-#include "cfg.h"
-#include "prim.h"
-#include "psemu_plugin_defs.h"
-#include "texture.h"
-#include "menu.h"
-#include "fps.h"
-#include "key.h"
-#ifdef _WINDOWS
-#include "resource.h"
-#include "ssave.h"
-#endif
-#ifdef ENABLE_NLS
-#include <libintl.h>
-#include <locale.h>
-#define _(x) gettext(x)
-#define N_(x) (x)
-#else
-#define _(x) (x)
-#define N_(x) (x)
-#endif
-
-////////////////////////////////////////////////////////////////////////
-// PPDK developer must change libraryName field and can change revision and build
-////////////////////////////////////////////////////////////////////////
-
-const unsigned char version = 1; // do not touch - library for PSEmu 1.x
-const unsigned char revision = 1;
-const unsigned char build = 78;
-
-static char *libraryName = N_("OpenGL Driver");
-
-static char *PluginAuthor = N_("Pete Bernert");
-static char *libraryInfo = N_("Based on P.E.Op.S. MesaGL Driver V1.78\nCoded by Pete Bernert\n");
-
-////////////////////////////////////////////////////////////////////////
-// memory image of the PSX vram
-////////////////////////////////////////////////////////////////////////
-
-unsigned char *psxVSecure;
-unsigned char *psxVub;
-signed char *psxVsb;
-unsigned short *psxVuw;
-unsigned short *psxVuw_eom;
-signed short *psxVsw;
-uint32_t *psxVul;
-signed int *psxVsl;
-
-// macro for easy access to packet information
-#define GPUCOMMAND(x) ((x>>24) & 0xff)
-
-GLfloat gl_z=0.0f;
-BOOL bNeedInterlaceUpdate=FALSE;
-BOOL bNeedRGB24Update=FALSE;
-BOOL bChangeWinMode=FALSE;
-
-#ifdef _WINDOWS
-extern HGLRC GLCONTEXT;
-#endif
-
-uint32_t ulStatusControl[256];
-
-////////////////////////////////////////////////////////////////////////
-// global GPU vars
-////////////////////////////////////////////////////////////////////////
-
-static int GPUdataRet;
-int lGPUstatusRet;
-char szDispBuf[64];
-
-uint32_t dwGPUVersion = 0;
-int iGPUHeight = 512;
-int iGPUHeightMask = 511;
-int GlobalTextIL = 0;
-int iTileCheat = 0;
-
-static uint32_t gpuDataM[256];
-static unsigned char gpuCommand = 0;
-static int gpuDataC = 0;
-static int gpuDataP = 0;
-
-VRAMLoad_t VRAMWrite;
-VRAMLoad_t VRAMRead;
-int iDataWriteMode;
-int iDataReadMode;
-
-int lClearOnSwap;
-int lClearOnSwapColor;
-BOOL bSkipNextFrame = FALSE;
-int iColDepth;
-BOOL bChangeRes;
-BOOL bWindowMode;
-int iWinSize;
-
-// possible psx display widths
-short dispWidths[8] = {256,320,512,640,368,384,512,640};
-
-PSXDisplay_t PSXDisplay;
-PSXDisplay_t PreviousPSXDisplay;
-TWin_t TWin;
-short imageX0,imageX1;
-short imageY0,imageY1;
-BOOL bDisplayNotSet = TRUE;
-GLuint uiScanLine=0;
-int iUseScanLines=0;
-float iScanlineColor[] = {0,0,0, 0.3}; // easy on the eyes.
-int lSelectedSlot=0;
-unsigned char * pGfxCardScreen=0;
-int iBlurBuffer=0;
-int iScanBlend=0;
-int iRenderFVR=0;
-int iNoScreenSaver=0;
-uint32_t ulGPUInfoVals[16];
-int iFakePrimBusy = 0;
-int iRumbleVal = 0;
-int iRumbleTime = 0;
-uint32_t vBlank=0;
-
-////////////////////////////////////////////////////////////////////////
-// stuff to make this a true PDK module
-////////////////////////////////////////////////////////////////////////
-
-char * CALLBACK PSEgetLibName(void)
-{
- return _(libraryName);
-}
-
-unsigned long CALLBACK PSEgetLibType(void)
-{
- return PSE_LT_GPU;
-}
-
-unsigned long CALLBACK PSEgetLibVersion(void)
-{
- return version<<16|revision<<8|build;
-}
-
-char * GPUgetLibInfos(void)
-{
- return _(libraryInfo);
-}
-
-////////////////////////////////////////////////////////////////////////
-// snapshot funcs (saves screen to bitmap / text infos into file)
-////////////////////////////////////////////////////////////////////////
-
-#ifdef _WINDOWS
-char * GetConfigInfos(HWND hW)
-#else
-char * GetConfigInfos(int hW)
-#endif
-{
-#ifdef _WINDOWS
- HDC hdc;HGLRC hglrc;
-#endif
- char szO[2][4]={"off","on "};
- char szTxt[256];
- char * pB=(char *)malloc(32767);
-
- if(!pB) return NULL;
- *pB=0;
- //----------------------------------------------------//
- sprintf(szTxt,"Plugin: %s %d.%d.%d (mod)\r\n",libraryName,version,revision,build);
- strcat(pB,szTxt);
- sprintf(szTxt,"Author: %s\r\n",PluginAuthor);
- strcat(pB,szTxt);
-
-#ifdef _WINDOWS
- if(hW)
- {
- hdc = GetDC(hW);
- bSetupPixelFormat(hdc);
- hglrc = wglCreateContext(hdc);
- wglMakeCurrent(hdc, hglrc);
- }
-#endif
-
- sprintf(szTxt,"Card vendor: %s\r\n",(char *)glGetString(GL_VENDOR));
- strcat(pB,szTxt);
- sprintf(szTxt,"GFX card: %s\r\n",(char *)glGetString(GL_RENDERER));
- strcat(pB,szTxt);
- sprintf(szTxt,"OGL version: %s\r\n\r\n",(char *)glGetString(GL_VERSION));
- strcat(pB,szTxt);
- //strcat(pB,(char *)glGetString(GL_EXTENSIONS));
- //strcat(pB,"\r\n\r\n");
-
-#ifdef _WINDOWS
- if(hW)
- {
- wglMakeCurrent(NULL, NULL);
- wglDeleteContext(hglrc);
- ReleaseDC(hW,hdc);
- }
- //----------------------------------------------------//
-#endif
-
- if(hW && bWindowMode)
- sprintf(szTxt,"Resolution/Color:\r\n- %dx%d ",LOWORD(iWinSize),HIWORD(iWinSize));
- else
- sprintf(szTxt,"Resolution/Color:\r\n- %dx%d ",iResX,iResY);
- strcat(pB,szTxt);
- if(bWindowMode) sprintf(szTxt,"Window mode\r\n");
- else
- {
- sprintf(szTxt,"Fullscreen ");
- strcat(pB,szTxt);
- if(bChangeRes) sprintf(szTxt,"- Desktop changing [%d Bit]\r\n",iColDepth);
- else sprintf(szTxt,"- NO desktop changing\r\n");
- }
- strcat(pB,szTxt);
-
- if(iForceVSync>=0) sprintf(szTxt,"- V-Sync: %s\r\n",szO[iForceVSync]);
- else strcpy(szTxt,"- V-Sync: Driver\r\n");
- strcat(pB,szTxt);
- sprintf(szTxt,"- Keep psx aspect ratio: %s\r\n\r\n",szO[bKeepRatio]);
- strcat(pB,szTxt);
- //----------------------------------------------------//
- strcpy(szTxt,"Textures:\r\n- ");
- if(iTexQuality==0) strcat(szTxt,"Default");
- else if(iTexQuality==1) strcat(szTxt,"R4G4B4A4");
- else if(iTexQuality==2) strcat(szTxt,"R5G5B5A1");
- else if(iTexQuality==3) strcat(szTxt,"R8G8A8A8");
- else if(iTexQuality==4) strcat(szTxt,"B8G8R8A8");
- if(!hW && bGLExt) strcat(szTxt," (packed pixels)\r\n");
- else strcat(szTxt,"\r\n");
- strcat(pB,szTxt);
- if(!hW)
- {
- sprintf(szTxt,"- Filtering: %d - edge clamping ",iFilterType);
- if(iClampType==GL_TO_EDGE_CLAMP) strcat(szTxt,"supported\r\n");
- else strcat(szTxt,"NOT supported\r\n");
- }
- else sprintf(szTxt,"- iFiltering: %d\r\n",iFilterType);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Hi-Res textures: %d\r\n",iHiResTextures);
- strcat(pB,szTxt);
- if(!hW)
- {
- sprintf(szTxt,"- Palettized tex windows: %s\r\n",szO[iUsePalTextures]);
- strcat(pB,szTxt);
- }
- sprintf(szTxt,"- VRam size: %d MBytes",iVRamSize);
- if(!hW)
- sprintf(szTxt+strlen(szTxt)," - %d textures usable\r\n\r\n",iSortTexCnt);
- else strcat(szTxt,"\r\n\r\n");
- strcat(pB,szTxt);
- //----------------------------------------------------//
- sprintf(szTxt,"Framerate:\r\n- FPS limitation: %s\r\n",szO[bUseFrameLimit]);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Frame skipping: %s\r\n",szO[bUseFrameSkip]);
- strcat(pB,szTxt);
- if(iFrameLimit==2)
- strcpy(szTxt,"- FPS limit: Auto\r\n\r\n");
- else sprintf(szTxt,"- FPS limit: %.1f\r\n\r\n",fFrameRate);
- strcat(pB,szTxt);
- //----------------------------------------------------//
- sprintf(szTxt,"Compatibility:\r\n- Offscreen drawing: %d\r\n",iOffscreenDrawing);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Framebuffer texture: %d",iFrameTexType);
- if(!hW && iFrameTexType==2)
- {
- if(gTexFrameName) strcat(szTxt," - texture created\r\n");
- else strcat(szTxt," - not used yet\r\n");
- }
- else strcat(szTxt,"\r\n");
- strcat(pB,szTxt);
- sprintf(szTxt,"- Framebuffer access: %d\r\n",iFrameReadType);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Alpha multipass: %s\r\n",szO[bOpaquePass]);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Mask bit: %s\r\n",szO[iUseMask]);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Advanced blending: %s",szO[bAdvancedBlend]);
- if(!hW && bAdvancedBlend)
- {
- if(bGLBlend) strcat(szTxt," (hardware)\r\n");
- else strcat(szTxt," (software)\r\n");
- }
- else strcat(szTxt,"\r\n");
- strcat(pB,szTxt);
-
- if(!hW)
- {
- strcpy(szTxt,"- Subtractive blending: ");
- if(glBlendEquationEXTEx)
- {
- if(bUseMultiPass) strcat(szTxt,"supported, but not used!");
- else strcat(szTxt,"activated");
- }
- else strcat(szTxt," NOT supported!");
- strcat(szTxt,"\r\n\r\n");
- }
- else strcpy(szTxt,"\r\n");
-
- strcat(pB,szTxt);
- //----------------------------------------------------//
- sprintf(szTxt,"Misc:\r\n- Scanlines: %s",szO[iUseScanLines]);
- strcat(pB,szTxt);
- if(iUseScanLines) sprintf(szTxt," [%d]\r\n",iScanBlend);
- else strcpy(szTxt,"\r\n");
- strcat(pB,szTxt);
- sprintf(szTxt,"- Line mode: %s\r\n",szO[bUseLines]);
- strcat(pB,szTxt);
-// sprintf(szTxt,"- Line AA: %s\r\n",szO[bUseAntiAlias]);
-// fwrite(szTxt,lstrlen(szTxt),1,txtfile);
- sprintf(szTxt,"- Unfiltered FB: %s\r\n",szO[bUseFastMdec]);
- strcat(pB,szTxt);
- sprintf(szTxt,"- 15 bit FB: %s\r\n",szO[bUse15bitMdec]);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Dithering: %s\r\n",szO[bDrawDither]);
- strcat(pB,szTxt);
- sprintf(szTxt,"- Screen smoothing: %s",szO[iBlurBuffer]);
- strcat(pB,szTxt);
- if(!hW && iBlurBuffer)
- {
- if(gTexBlurName) strcat(pB," - supported\r\n");
- else strcat(pB," - not supported\r\n");
- }
- else strcat(pB,"\r\n");
- sprintf(szTxt,"- Game fixes: %s [%08x]\r\n",szO[bUseFixes],dwCfgFixes);
- strcat(pB,szTxt);
- //----------------------------------------------------//
- return pB;
-}
-
-////////////////////////////////////////////////////////////////////////
-// save text infos to file
-////////////////////////////////////////////////////////////////////////
-
-void DoTextSnapShot(int iNum)
-{
- FILE *txtfile;char szTxt[256];char * pB;
-
-#ifdef _WINDOWS
- sprintf(szTxt,"snap\\pcsx%04d.txt",iNum);
-#else
- sprintf(szTxt,"%s/pcsx%04d.txt",getenv("HOME"),iNum);
-#endif
-
- if((txtfile=fopen(szTxt,"wb"))==NULL)
- return;
-
- pB=GetConfigInfos(0);
- if(pB)
- {
- fwrite(pB,strlen(pB),1,txtfile);
- free(pB);
- }
- fclose(txtfile);
-}
-
-////////////////////////////////////////////////////////////////////////
-// saves screen bitmap to file
-////////////////////////////////////////////////////////////////////////
-
-void DoSnapShot(void)
-{
- unsigned char * snapshotdumpmem=NULL,* p,c;
- FILE *bmpfile;char filename[256];
- unsigned char header[0x36];int size;
- unsigned char empty[2]={0,0};int i;
- unsigned int snapshotnr = 0;
- short SnapWidth;
- short SnapHeigth;
-
- bSnapShot=FALSE;
-
- SnapWidth = iResX;
- SnapHeigth = iResY;
-
- size=SnapWidth * SnapHeigth * 3 + 0x38;
-
- if((snapshotdumpmem=(unsigned char *)
- malloc(SnapWidth*SnapHeigth*3))==NULL)
- return;
-
- // fill in proper values for BMP
- for(i=0;i<0x36;i++) header[i]=0;
- header[0]='B';
- header[1]='M';
- header[2]=(unsigned char)(size&0xff);
- header[3]=(unsigned char)((size>>8)&0xff);
- header[4]=(unsigned char)((size>>16)&0xff);
- header[5]=(unsigned char)((size>>24)&0xff);
- header[0x0a]=0x36;
- header[0x0e]=0x28;
- header[0x12]=(unsigned char)(SnapWidth%256);
- header[0x13]=(unsigned char)(SnapWidth/256);
- header[0x16]=(unsigned char)(SnapHeigth%256);
- header[0x17]=(unsigned char)(SnapHeigth/256);
- header[0x1a]=0x01;
- header[0x1c]=0x18;
- header[0x26]=0x12;
- header[0x27]=0x0B;
- header[0x2A]=0x12;
- header[0x2B]=0x0B;
-
- // increment snapshot value
- // get filename
- do
- {
- snapshotnr++;
-#ifdef _WINDOWS
- sprintf(filename,"snap/pcsx%04d.bmp",snapshotnr);
-#else
- sprintf(filename,"%s/pcsx%04d.bmp",getenv("HOME"),snapshotnr);
-#endif
- bmpfile=fopen(filename,"rb");
- if(bmpfile==NULL)break;
- fclose(bmpfile);
- if(snapshotnr==9999) break;
- }
- while(TRUE);
-
- // try opening new snapshot file
- if((bmpfile=fopen(filename,"wb"))==NULL)
- {free(snapshotdumpmem);return;}
-
- fwrite(header,0x36,1,bmpfile);
-
- glReadPixels(0,0,SnapWidth,SnapHeigth,GL_RGB,
- GL_UNSIGNED_BYTE,snapshotdumpmem);
- p=snapshotdumpmem;
- size=SnapWidth * SnapHeigth;
-
- for(i=0;i<size;i++,p+=3)
- {c=*p;*p=*(p+2);*(p+2)=c;}
-
- fwrite(snapshotdumpmem,size*3,1,bmpfile);
- fwrite(empty,0x2,1,bmpfile);
- fclose(bmpfile);
- free(snapshotdumpmem);
-
- DoTextSnapShot(snapshotnr);
-#ifdef _WINDOWS
- MessageBeep((UINT)-1);
-#endif
-}
-
-void CALLBACK GPUmakeSnapshot(void)
-{
- bSnapShot = TRUE;
-}
-
-////////////////////////////////////////////////////////////////////////
-// GPU INIT... here starts it all (first func called by emu)
-////////////////////////////////////////////////////////////////////////
-
-long CALLBACK GPUinit()
-{
- memset(ulStatusControl,0,256*sizeof(uint32_t));
-
- // different ways of accessing PSX VRAM
-
- psxVSecure=(unsigned char *)malloc((iGPUHeight*2)*1024 + (1024*1024)); // always alloc one extra MB for soft drawing funcs security
- if(!psxVSecure) return -1;
-
- psxVub=psxVSecure+512*1024; // security offset into double sized psx vram!
- psxVsb=(signed char *)psxVub;
- psxVsw=(signed short *)psxVub;
- psxVsl=(signed int *)psxVub;
- psxVuw=(unsigned short *)psxVub;
- psxVul=(uint32_t *)psxVub;
-
- psxVuw_eom=psxVuw+1024*iGPUHeight; // pre-calc of end of vram
-
- memset(psxVSecure,0x00,(iGPUHeight*2)*1024 + (1024*1024));
- memset(ulGPUInfoVals,0x00,16*sizeof(uint32_t));
-
- InitFrameCap(); // init frame rate stuff
-
- PSXDisplay.RGB24 = 0; // init vars
- PreviousPSXDisplay.RGB24= 0;
- PSXDisplay.Interlaced = 0;
- PSXDisplay.InterlacedTest=0;
- PSXDisplay.DrawOffset.x = 0;
- PSXDisplay.DrawOffset.y = 0;
- PSXDisplay.DrawArea.x0 = 0;
- PSXDisplay.DrawArea.y0 = 0;
- PSXDisplay.DrawArea.x1 = 320;
- PSXDisplay.DrawArea.y1 = 240;
- PSXDisplay.DisplayMode.x= 320;
- PSXDisplay.DisplayMode.y= 240;
- PSXDisplay.Disabled = FALSE;
- PreviousPSXDisplay.Range.x0 =0;
- PreviousPSXDisplay.Range.x1 =0;
- PreviousPSXDisplay.Range.y0 =0;
- PreviousPSXDisplay.Range.y1 =0;
- PSXDisplay.Range.x0=0;
- PSXDisplay.Range.x1=0;
- PSXDisplay.Range.y0=0;
- PSXDisplay.Range.y1=0;
- PreviousPSXDisplay.DisplayPosition.x = 1;
- PreviousPSXDisplay.DisplayPosition.y = 1;
- PSXDisplay.DisplayPosition.x = 1;
- PSXDisplay.DisplayPosition.y = 1;
- PreviousPSXDisplay.DisplayModeNew.y=0;
- PSXDisplay.Double=1;
- GPUdataRet=0x400;
-
- PSXDisplay.DisplayModeNew.x=0;
- PSXDisplay.DisplayModeNew.y=0;
-
- //PreviousPSXDisplay.Height = PSXDisplay.Height = 239;
-
- iDataWriteMode = DR_NORMAL;
-
- // Reset transfer values, to prevent mis-transfer of data
- memset(&VRAMWrite,0,sizeof(VRAMLoad_t));
- memset(&VRAMRead,0,sizeof(VRAMLoad_t));
-
- // device initialised already !
- //lGPUstatusRet = 0x74000000;
- vBlank = 0;
-
- STATUSREG = 0x14802000;
- GPUIsIdle;
- GPUIsReadyForCommands;
-
- return 0;
-}
-
-////////////////////////////////////////////////////////////////////////
-// GPU OPEN: funcs to open up the gpu display (Windows)
-////////////////////////////////////////////////////////////////////////
-
-#ifdef _WINDOWS
-
-void ChangeDesktop() // change destop resolution
-{
- DEVMODE dv;long lRes,iTry=0;
-
- while(iTry<10) // keep on hammering...
- {
- memset(&dv,0,sizeof(DEVMODE));
- dv.dmSize=sizeof(DEVMODE);
- dv.dmBitsPerPel=iColDepth;
- dv.dmPelsWidth=iResX;
- dv.dmPelsHeight=iResY;
-
- dv.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
-
- lRes=ChangeDisplaySettings(&dv,0); // ...hammering the anvil
-
- if(lRes==DISP_CHANGE_SUCCESSFUL) return;
- iTry++;Sleep(10);
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// OPEN interface func: attention!
-// some emus are calling this func in their main Window thread,
-// but all other interface funcs (to draw stuff) in a different thread!
-// that's a problem, since OGL is thread safe! Therefore we cannot
-// initialize the OGL stuff right here, we simply set a "bIsFirstFrame = TRUE"
-// flag, to initialize OGL on the first real draw call.
-// btw, we also call this open func ourselfes, each time when the user
-// is changing between fullscreen/window mode (ENTER key)
-// btw part 2: in windows the plugin gets the window handle from the
-// main emu, and doesn't create it's own window (if it would do it,
-// some PAD or SPU plugins would not work anymore)
-////////////////////////////////////////////////////////////////////////
-
-HMENU hPSEMenu=NULL;
-
-long CALLBACK GPUopen(HWND hwndGPU)
-{
- HDC hdc;RECT r;DEVMODE dv;
-
- hWWindow = hwndGPU; // store hwnd globally
-
- InitKeyHandler(); // init key handler (subclass window)
-
- if(bChangeWinMode) // user wants to change fullscreen/window mode?
- {
- ReadWinSizeConfig(); // -> get sizes again
- }
- else // first real startup
- {
- ReadConfig(); // -> read config from registry
-
- SetFrameRateConfig(); // -> setup frame rate stuff
- }
-
- if(iNoScreenSaver) EnableScreenSaver(FALSE); // at least we can try
-
-
- memset(&dv,0,sizeof(DEVMODE));
- dv.dmSize=sizeof(DEVMODE);
- EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dv);
-
- bIsFirstFrame = TRUE; // flag: we have to init OGL later in windows!
-
- if(bWindowMode) // win mode?
- {
- DWORD dw=GetWindowLong(hWWindow, GWL_STYLE); // -> adjust wnd style (owndc needed by some stupid ogl drivers)
- dw&=~WS_THICKFRAME;
- dw|=WS_BORDER|WS_CAPTION|CS_OWNDC;
- SetWindowLong(hWWindow, GWL_STYLE, dw);
-
- hPSEMenu=GetMenu(hWWindow); // -> hide emu menu (if any)
- if(hPSEMenu!=NULL) SetMenu(hWWindow,NULL);
-
- iResX=LOWORD(iWinSize);iResY=HIWORD(iWinSize);
- ShowWindow(hWWindow,SW_SHOWNORMAL);
-
- MoveWindow(hWWindow, // -> center wnd
- GetSystemMetrics(SM_CXFULLSCREEN)/2-iResX/2,
- GetSystemMetrics(SM_CYFULLSCREEN)/2-iResY/2,
- iResX+GetSystemMetrics(SM_CXFIXEDFRAME)+3,
- iResY+GetSystemMetrics(SM_CYFIXEDFRAME)+GetSystemMetrics(SM_CYCAPTION)+3,
- TRUE);
- UpdateWindow(hWWindow); // -> let windows do some update
-
- if(dv.dmBitsPerPel==16 || dv.dmBitsPerPel==32) // -> overwrite user color info with desktop color info
- iColDepth=dv.dmBitsPerPel;
- }
- else // fullscreen mode:
- {
- if(dv.dmBitsPerPel!=(unsigned int)iColDepth || // -> check, if we have to change resolution
- dv.dmPelsWidth !=(unsigned int)iResX ||
- dv.dmPelsHeight!=(unsigned int)iResY)
- bChangeRes=TRUE; else bChangeRes=FALSE;
-
- if(bChangeRes) ChangeDesktop(); // -> change the res (had to do an own func because of some MS 'optimizations')
-
- SetWindowLong(hWWindow, GWL_STYLE, CS_OWNDC); // -> adjust wnd style as well (to be sure)
-
- hPSEMenu=GetMenu(hWWindow); // -> hide menu
- if(hPSEMenu!=NULL) SetMenu(hWWindow,NULL);
- ShowWindow(hWWindow,SW_SHOWMAXIMIZED); // -> max mode
- }
-
- rRatioRect.left = rRatioRect.top=0;
- rRatioRect.right = iResX;
- rRatioRect.bottom = iResY;
-
- r.left=r.top=0;r.right=iResX;r.bottom=iResY; // hack for getting a clean black window until OGL gets initialized
- hdc = GetDC(hWWindow);
- FillRect(hdc,&r,(HBRUSH)GetStockObject(BLACK_BRUSH));
- bSetupPixelFormat(hdc);
- ReleaseDC(hWWindow,hdc);
-
- bDisplayNotSet = TRUE;
- bSetClip=TRUE;
-
- SetFixes(); // setup game fixes
-
- InitializeTextureStore(); // init texture mem
-
-// lGPUstatusRet = 0x74000000;
-
-// with some emus, we could do the OGL init right here... oh my
-// if(bIsFirstFrame) GLinitialize();
-
- return 0;
-}
-
-#elif !defined (_MACGL)
-
-////////////////////////////////////////////////////////////////////////
-// LINUX GPU OPEN: func to open up the gpu display (X stuff)
-// please note: in linux we are creating our own display, and we return
-// the display ID to the main emu... that's cleaner
-////////////////////////////////////////////////////////////////////////
-
-char * pCaptionText=0;
-int bFullScreen=0;
-Display *display;
-
-static Cursor cursor;
-static XVisualInfo *myvisual;
-static Colormap colormap;
-static Window window;
-
-static int bModeChanged=0;
-
-typedef struct
-{
-#define MWM_HINTS_DECORATIONS 2
- long flags;
- long functions;
- long decorations;
- long input_mode;
-} MotifWmHints;
-
-static int dbdepat[]={GLX_RGBA,GLX_DOUBLEBUFFER,GLX_DEPTH_SIZE,16,None};
-static int dbnodepat[]={GLX_RGBA,GLX_DOUBLEBUFFER,None};
-static GLXContext cx;
-
-static int fx=0;
-
-////////////////////////////////////////////////////////////////////////
-
-void osd_close_display (void) // close display
-{
- if(display) // display exists?
- {
- glXDestroyContext(display,cx); // -> kill context
- XFreeColormap(display, colormap); // -> kill colormap
- XSync(display,False); // -> sync events
-
-#ifndef NOVMODE
- if(bModeChanged) // -> repair screen mode
- {
- int myscreen=DefaultScreen(display);
- XF86VidModeSwitchToMode(display,myscreen, // --> switch mode back
- modes[iOldMode]);
- XF86VidModeSetViewPort(display,myscreen,0,0); // --> set viewport upperleft
- free(modes); // --> finally kill mode infos
- bModeChanged=0; // --> done
- }
-#endif
-
- XCloseDisplay(display); // -> close display
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void sysdep_create_display(void) // create display
-{
- XSetWindowAttributes winattr;float fxgamma=2;
- int myscreen;char gammastr[14];
- Screen * screen;XEvent event;
- XSizeHints hints;XWMHints wm_hints;
- MotifWmHints mwmhints;Atom mwmatom;Atom delwindow;
- char *glxfx;
-
- glxfx=getenv("MESA_GLX_FX"); // 3dfx mesa fullscreen flag
- if(glxfx)
- {
- if(glxfx[0]=='f') // -> yup, fullscreen needed
- {
- fx=1; // -> raise flag
- putenv("FX_GLIDE_NO_SPLASH=");
- sprintf(gammastr,"SST_GAMMA=%2.1f",fxgamma); // -> set gamma
- putenv(gammastr);
- }
- }
-
- display=XOpenDisplay(NULL); // open display
- if(!display) // no display?
- {
- fprintf (stderr,"Failed to open display!!!\n");
- osd_close_display();
- return; // -> bye
- }
-
- myscreen=DefaultScreen(display); // get screen id
-
-#ifdef NOVMODE
- if(bFullScreen) {fx=1;bModeChanged=0;}
-#else
- if(bFullScreen)
- {
- XF86VidModeModeLine mode;
- int nmodes,iC;
- fx=1; // raise flag
- XF86VidModeGetModeLine(display,myscreen,&iC,&mode); // get actual mode info
- if(mode.privsize) XFree(mode.private); // no need for private stuff
- bModeChanged=0; // init mode change flag
- if(iResX!=mode.hdisplay || iResY!=mode.vdisplay) // wanted mode is different?
- {
- XF86VidModeGetAllModeLines(display,myscreen, // -> enum all mode infos
- &nmodes,&modes);
- if(modes) // -> infos got?
- {
- for(iC=0;iC<nmodes;++iC) // -> loop modes
- {
- if(mode.hdisplay==modes[iC]->hdisplay && // -> act mode found?
- mode.vdisplay==modes[iC]->vdisplay) // if yes: store mode id
- iOldMode=iC;
-
- if(iResX==modes[iC]->hdisplay && // -> wanted mode found?
- iResY==modes[iC]->vdisplay)
- {
- XF86VidModeSwitchToMode(display,myscreen, // --> switch to mode
- modes[iC]);
- XF86VidModeSetViewPort(display,myscreen,0,0);
- bModeChanged=1; // --> raise flag for repairing mode on close
- }
- }
-
- if(bModeChanged==0) // -> no mode found?
- {
- free(modes); // --> free infos
- printf("No proper fullscreen mode found!\n"); // --> some info output
- }
- }
- }
- }
-#endif
-
- screen=DefaultScreenOfDisplay(display);
-
- if(iZBufferDepth) // visual (with or without zbuffer)
- myvisual=glXChooseVisual(display,myscreen,dbdepat);
- else myvisual=glXChooseVisual(display,myscreen,dbnodepat);
-
- if(!myvisual) // no visual?
- {
- fprintf(stderr,"Failed to obtain visual!!!\n"); // -> bye
- osd_close_display();
- return;
- }
-
- cx=glXCreateContext(display,myvisual,0,GL_TRUE); // create rendering context
-
- if(!cx) // no context?
- {
- fprintf(stderr,"Failed to create OpenGL context!!!\n");
- osd_close_display(); // -> bxe
- return;
- }
-
- // pffff... much work for a simple blank cursor... oh, well...
- if(!bFullScreen) cursor=XCreateFontCursor(display,XC_trek);
- else
- {
- Pixmap p1,p2;XImage * img;
- XColor b,w;unsigned char * idata;
- XGCValues GCv;
- GC GCc;
-
- memset(&b,0,sizeof(XColor));
- memset(&w,0,sizeof(XColor));
- idata=(unsigned char *)malloc(8);
- memset(idata,0,8);
-
- p1=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
- p2=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
-
- img = XCreateImage(display,myvisual->visual,
- 1,XYBitmap,0,idata,8,8,8,1);
-
- GCv.function = GXcopy;
- GCv.foreground = ~0;
- GCv.background = 0;
- GCv.plane_mask = AllPlanes;
- GCc = XCreateGC(display,p1,
- (GCFunction|GCForeground|GCBackground|GCPlaneMask),&GCv);
-
- XPutImage(display, p1,GCc,img,0,0,0,0,8,8);
- XPutImage(display, p2,GCc,img,0,0,0,0,8,8);
- XFreeGC(display, GCc);
-
- cursor = XCreatePixmapCursor(display,p1,p2,&b,&w,0,0);
-
- XFreePixmap(display,p1);
- XFreePixmap(display,p2);
- XDestroyImage(img); // will free idata as well
- }
-
- colormap=XCreateColormap(display, // create colormap
- RootWindow(display,myvisual->screen),
- myvisual->visual,AllocNone);
-
- winattr.background_pixel=0;
- winattr.border_pixel=WhitePixelOfScreen(screen);
- winattr.bit_gravity=ForgetGravity;
- winattr.win_gravity=NorthWestGravity;
- winattr.backing_store=NotUseful;
- winattr.override_redirect=False;
- winattr.save_under=False;
- winattr.event_mask=0;
- winattr.do_not_propagate_mask=0;
- winattr.colormap=colormap;
- winattr.cursor=None;
-
- window=XCreateWindow(display, // create own window
- RootWindow(display,DefaultScreen(display)),
- 0,0,iResX,iResY,
- 0,myvisual->depth,
- InputOutput,myvisual->visual,
- CWBorderPixel | CWBackPixel |
- CWEventMask | CWDontPropagate |
- CWColormap | CWCursor,
- &winattr);
-
- if(!window) // no window?
- {
- fprintf(stderr,"Failed in XCreateWindow()!!!\n");
- osd_close_display(); // -> bye
- return;
- }
-
- delwindow = XInternAtom(display,"WM_DELETE_WINDOW",0);
- XSetWMProtocols(display, window, &delwindow, 1);
-
- hints.flags=PMinSize|PMaxSize; // hints
- if(fx) hints.flags|=USPosition|USSize;
- else hints.flags|=PSize;
-
- hints.min_width = hints.max_width = hints.base_width = iResX;
- hints.min_height = hints.max_height = hints.base_height = iResY;
-
- wm_hints.input=1;
- wm_hints.flags=InputHint;
-
- XSetWMHints(display,window,&wm_hints);
- XSetWMNormalHints(display,window,&hints);
- if(pCaptionText) // caption
- XStoreName(display,window,pCaptionText);
- else XStoreName(display,window,"Pete MesaGL PSX Gpu");
-
- XDefineCursor(display,window,cursor); // cursor
-
- if(fx) // window title bar hack
- {
- mwmhints.flags=MWM_HINTS_DECORATIONS;
- mwmhints.decorations=0;
- mwmatom=XInternAtom(display,"_MOTIF_WM_HINTS",0);
- XChangeProperty(display,window,mwmatom,mwmatom,32,
- PropModeReplace,(unsigned char *)&mwmhints,4);
- }
-
- XSelectInput(display,window, // input setup
- FocusChangeMask | ExposureMask |
- KeyPressMask | KeyReleaseMask);
-
- XMapRaised(display,window);
- XClearWindow(display,window);
- XWindowEvent(display,window,ExposureMask,&event);
- glXMakeCurrent(display,window,cx);
-
-/*
- printf(glGetString(GL_VENDOR));
- printf("\n");
- printf(glGetString(GL_RENDERER));
- printf("\n");
-*/
-
- if (fx) // after make current: fullscreen resize
- {
- XResizeWindow(display,window,screen->width,screen->height);
- hints.min_width = hints.max_width = hints.base_width = screen->width;
- hints.min_height= hints.max_height = hints.base_height = screen->height;
- XSetWMNormalHints(display,window,&hints);
-
- // set the window layer for GNOME
- {
- XEvent xev;
-
- memset(&xev, 0, sizeof(xev));
- xev.xclient.type = ClientMessage;
- xev.xclient.serial = 0;
- xev.xclient.send_event = 1;
- xev.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", 0);
- xev.xclient.window = window;
- xev.xclient.format = 32;
- xev.xclient.data.l[0] = 1;
- xev.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", 0);
- xev.xclient.data.l[2] = 0;
- xev.xclient.data.l[3] = 0;
- xev.xclient.data.l[4] = 0;
-
- XSendEvent(display, RootWindow(display, DefaultScreen(display)), 0,
- SubstructureRedirectMask | SubstructureNotifyMask, &xev);
- }
- }
-}
-
-#endif // !defined(_MACGL)
-
-#ifndef _WINDOWS
-
-#if defined(_MACGL)
-extern char * pCaptionText;
-#endif
-
-////////////////////////////////////////////////////////////////////////
-
-long GPUopen(unsigned long * disp,char * CapText,char * CfgFile)
-{
- pCaptionText=CapText;
- pConfigFile=CfgFile;
-
- ReadConfig(); // read text file for config
-
- SetFrameRateConfig(); // setup frame rate stuff
-
- bIsFirstFrame = TRUE; // we have to init later (well, no really... in Linux we do all in GPUopen)
-
- #if defined (_MACGL)
- unsigned long display = ulInitDisplay();
- #else
- sysdep_create_display(); // create display
- #endif
-
- InitializeTextureStore(); // init texture mem
-
- rRatioRect.left = rRatioRect.top=0;
- rRatioRect.right = iResX;
- rRatioRect.bottom = iResY;
-
- GLinitialize(); // init opengl
-
- if(disp)
- {
- #if defined (_MACGL)
- *disp = display;
- #else
- *disp=(unsigned long *)display; // return display ID to main emu
- #endif
- }
-
- if(display) return 0;
- return -1;
-}
-
-#endif // ndef _WINDOWS
-
-
-
-////////////////////////////////////////////////////////////////////////
-// close
-////////////////////////////////////////////////////////////////////////
-
-#ifdef _WINDOWS
-
-long CALLBACK GPUclose() // WINDOWS CLOSE
-{
- ExitKeyHandler();
-
- GLcleanup(); // close OGL
-
- if(bChangeRes) // change res back
- ChangeDisplaySettings(NULL,0);
-
- if(hPSEMenu) // set menu again
- SetMenu(hWWindow,hPSEMenu);
-
- if(pGfxCardScreen) free(pGfxCardScreen); // free helper memory
- pGfxCardScreen=0;
-
- if(iNoScreenSaver) EnableScreenSaver(TRUE); // enable screen saver again
-
- return 0;
-}
-
-#else
-
-long GPUclose() // LINUX CLOSE
-{
- GLcleanup(); // close OGL
-
- if(pGfxCardScreen) free(pGfxCardScreen); // free helper memory
- pGfxCardScreen=0;
- #if defined (_MACGL)
- CloseDisplay();
- #else
- osd_close_display(); // destroy display
- #endif
- return 0;
-}
-
-#endif
-
-////////////////////////////////////////////////////////////////////////
-// I shot the sheriff... last function called from emu
-////////////////////////////////////////////////////////////////////////
-
-long CALLBACK GPUshutdown()
-{
- if(psxVSecure) free(psxVSecure); // kill emulated vram memory
- psxVSecure=0;
-
- return 0;
-}
-
-////////////////////////////////////////////////////////////////////////
-// paint it black: simple func to clean up optical border garbage
-////////////////////////////////////////////////////////////////////////
-
-void PaintBlackBorders(void)
-{
- short s;
-
- glDisable(GL_SCISSOR_TEST);
- if(bTexEnabled) {glDisable(GL_TEXTURE_2D);bTexEnabled=FALSE;}
- if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}
- if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
- glDisable(GL_ALPHA_TEST);
-
- glBegin(GL_QUADS);
-
- vertex[0].c.lcol=0xff000000;
- SETCOL(vertex[0]);
-
- if(PreviousPSXDisplay.Range.x0)
- {
- s=PreviousPSXDisplay.Range.x0+1;
- glVertex3f(0,0,0.99996f);
- glVertex3f(0,PSXDisplay.DisplayMode.y,0.99996f);
- glVertex3f(s,PSXDisplay.DisplayMode.y,0.99996f);
- glVertex3f(s,0,0.99996f);
-
- s+=PreviousPSXDisplay.Range.x1-2;
-
- glVertex3f(s,0,0.99996f);
- glVertex3f(s,PSXDisplay.DisplayMode.y,0.99996f);
- glVertex3f(PSXDisplay.DisplayMode.x,PSXDisplay.DisplayMode.y,0.99996f);
- glVertex3f(PSXDisplay.DisplayMode.x,0,0.99996f);
- }
-
- if(PreviousPSXDisplay.Range.y0)
- {
- s=PreviousPSXDisplay.Range.y0+1;
- glVertex3f(0,0,0.99996f);
- glVertex3f(0,s,0.99996f);
- glVertex3f(PSXDisplay.DisplayMode.x,s,0.99996f);
- glVertex3f(PSXDisplay.DisplayMode.x,0,0.99996f);
- }
-
- glEnd();
-
- glEnable(GL_ALPHA_TEST);
- glEnable(GL_SCISSOR_TEST);
-}
-
-////////////////////////////////////////////////////////////////////////
-// helper to draw scanlines
-////////////////////////////////////////////////////////////////////////
-
-__inline void XPRIMdrawTexturedQuad(OGLVertex* vertex1, OGLVertex* vertex2,
- OGLVertex* vertex3, OGLVertex* vertex4)
-{
-
- glBegin(GL_QUAD_STRIP);
- glTexCoord2fv(&vertex1->sow);
- glVertex3fv(&vertex1->x);
-
- glTexCoord2fv(&vertex2->sow);
- glVertex3fv(&vertex2->x);
-
- glTexCoord2fv(&vertex4->sow);
- glVertex3fv(&vertex4->x);
-
- glTexCoord2fv(&vertex3->sow);
- glVertex3fv(&vertex3->x);
- glEnd();
-}
-
-////////////////////////////////////////////////////////////////////////
-// scanlines
-////////////////////////////////////////////////////////////////////////
-
-void SetScanLines(void)
-{
- glLoadIdentity();
- glOrtho(0,iResX,iResY, 0, -1, 1);
-
- if(bKeepRatio)
- glViewport(0,0,iResX,iResY);
-
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_ALPHA_TEST);
- if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}
-
- if(iScanBlend<0) // special texture mask scanline mode
- {
- if(!bTexEnabled) {glEnable(GL_TEXTURE_2D);bTexEnabled=TRUE;}
- gTexName=gTexScanName;
- glBindTexture(GL_TEXTURE_2D, gTexName);
- if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- if(!bBlendEnable) {glEnable(GL_BLEND);bBlendEnable=TRUE;}
- SetScanTexTrans();
-
- vertex[0].x=0;
- vertex[0].y=iResY;
- vertex[0].z=0.99996f;
-
- vertex[1].x=iResX;
- vertex[1].y=iResY;
- vertex[1].z=0.99996f;
-
- vertex[2].x=iResX;
- vertex[2].y=0;
- vertex[2].z=0.99996f;
-
- vertex[3].x=0;
- vertex[3].y=0;
- vertex[3].z=0.99996f;
-
- vertex[0].sow=0;
- vertex[0].tow=0;
- vertex[1].sow=(float)iResX/4.0f;
- vertex[1].tow=0;
- vertex[2].sow=vertex[1].sow;
- vertex[2].tow=(float)iResY/4.0f;
- vertex[3].sow=0;
- vertex[3].tow=vertex[2].tow;
-
- vertex[0].c.lcol=0xffffffff;
- SETCOL(vertex[0]);
-
- XPRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
-
- if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
- }
- else // typical line mode
- {
- if(bTexEnabled) {glDisable(GL_TEXTURE_2D);bTexEnabled=FALSE;}
-
- if(iScanBlend==0)
- {
- if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
- vertex[0].c.lcol=0xff000000;
- }
- else
- {
- if(!bBlendEnable) {glEnable(GL_BLEND);bBlendEnable=TRUE;}
- SetScanTrans();
- vertex[0].c.lcol=iScanBlend<<24;
- }
-
- SETCOL(vertex[0]);
-
- glCallList(uiScanLine);
- }
-
- glLoadIdentity();
- glOrtho(0,PSXDisplay.DisplayMode.x,
- PSXDisplay.DisplayMode.y, 0, -1, 1);
-
- if(bKeepRatio)
- glViewport(rRatioRect.left,
- iResY-(rRatioRect.top+rRatioRect.bottom),
- rRatioRect.right,
- rRatioRect.bottom); // init viewport
-
- glEnable(GL_ALPHA_TEST);
- glEnable(GL_SCISSOR_TEST);
-}
-
-////////////////////////////////////////////////////////////////////////
-// blur, babe, blur (heavy performance hit for a so-so fullscreen effect)
-////////////////////////////////////////////////////////////////////////
-
-void BlurBackBuffer(void)
-{
- if(!gTexBlurName) return;
-
- if(bKeepRatio) glViewport(0,0,iResX,iResY);
-
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_ALPHA_TEST);
- if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}
- if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
- if(!bTexEnabled) {glEnable(GL_TEXTURE_2D);bTexEnabled=TRUE;}
- if(iZBufferDepth) glDisable(GL_DEPTH_TEST);
- if(bDrawDither) glDisable(GL_DITHER);
-
- gTexName=gTexBlurName;
- glBindTexture(GL_TEXTURE_2D, gTexName);
-
- glCopyTexSubImage2D( GL_TEXTURE_2D, 0, // get back buffer in texture
- 0,
- 0,
- 0,
- 0,
- iResX,iResY);
-
- vertex[0].x=0;
- vertex[0].y=PSXDisplay.DisplayMode.y;
- vertex[1].x=PSXDisplay.DisplayMode.x;
- vertex[1].y=PSXDisplay.DisplayMode.y;
- vertex[2].x=PSXDisplay.DisplayMode.x;
- vertex[2].y=0;
- vertex[3].x=0;
- vertex[3].y=0;
- vertex[0].sow=0;
- vertex[0].tow=0;
-
-#ifdef OWNSCALE
- vertex[1].sow=((GLfloat)iFTexA)/256.0f;
- vertex[2].tow=((GLfloat)iFTexB)/256.0f;
-#else
- vertex[1].sow=iFTexA;
- vertex[2].tow=iFTexB;
-#endif
- vertex[1].tow=0;
- vertex[2].sow=vertex[1].sow;
- vertex[3].sow=0;
- vertex[3].tow=vertex[2].tow;
-
- if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- vertex[0].c.lcol=0x7fffffff;
- SETCOL(vertex[0]);
-
- DrawMultiBlur(); // draw the backbuffer texture to create blur effect
-
- glEnable(GL_ALPHA_TEST);
- glEnable(GL_SCISSOR_TEST);
- if(iZBufferDepth) glEnable(GL_DEPTH_TEST);
- if(bDrawDither) glEnable(GL_DITHER);
- if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
-
- if(bKeepRatio)
- glViewport(rRatioRect.left, // re-init viewport
- iResY-(rRatioRect.top+rRatioRect.bottom),
- rRatioRect.right,
- rRatioRect.bottom);
-}
-
-////////////////////////////////////////////////////////////////////////
-// "unblur" repairs the backbuffer after a blur
-
-void UnBlurBackBuffer(void)
-{
- if(!gTexBlurName) return;
-
- if(bKeepRatio) glViewport(0,0,iResX,iResY);
-
- glDisable(GL_SCISSOR_TEST);
- glDisable(GL_ALPHA_TEST);
- if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
- if(!bTexEnabled) {glEnable(GL_TEXTURE_2D);bTexEnabled=TRUE;}
- if(iZBufferDepth) glDisable(GL_DEPTH_TEST);
- if(bDrawDither) glDisable(GL_DITHER);
-
- gTexName=gTexBlurName;
- glBindTexture(GL_TEXTURE_2D, gTexName);
-
- vertex[0].x=0;
- vertex[0].y=PSXDisplay.DisplayMode.y;
- vertex[1].x=PSXDisplay.DisplayMode.x;
- vertex[1].y=PSXDisplay.DisplayMode.y;
- vertex[2].x=PSXDisplay.DisplayMode.x;
- vertex[2].y=0;
- vertex[3].x=0;
- vertex[3].y=0;
- vertex[0].sow=0;
- vertex[0].tow=0;
-#ifdef OWNSCALE
- vertex[1].sow=((GLfloat)iFTexA)/256.0f;
- vertex[2].tow=((GLfloat)iFTexB)/256.0f;
-#else
- vertex[1].sow=iFTexA;
- vertex[2].tow=iFTexB;
-#endif
- vertex[1].tow=0;
- vertex[2].sow=vertex[1].sow;
- vertex[3].sow=0;
- vertex[3].tow=vertex[2].tow;
- if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- vertex[0].c.lcol=0xffffffff;
- SETCOL(vertex[0]);
-
- // simply draw the backbuffer texture (without blur)
- XPRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
-
- glEnable(GL_ALPHA_TEST);
- glEnable(GL_SCISSOR_TEST);
- if(iZBufferDepth) glEnable(GL_DEPTH_TEST);
- if(bDrawDither) glEnable(GL_DITHER); // dither mode
- if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
-
- if(bKeepRatio)
- glViewport(rRatioRect.left,
- iResY-(rRatioRect.top+rRatioRect.bottom),
- rRatioRect.right,
- rRatioRect.bottom); // init viewport
-}
-
-////////////////////////////////////////////////////////////////////////
-// Update display (swap buffers)... called in interlaced mode on
-// every emulated vsync, otherwise whenever the displayed screen region
-// has been changed
-////////////////////////////////////////////////////////////////////////
-
-int iLastRGB24=0; // special vars for checking when to skip two display updates
-int iSkipTwo=0;
-
-void updateDisplay(void) // UPDATE DISPLAY
-{
- BOOL bBlur=FALSE;
-
-#ifdef _WINDOWS
- HDC hdc=GetDC(hWWindow); // windows:
- wglMakeCurrent(hdc,GLCONTEXT); // -> make context current again
-#endif
-#if defined (_MACGL)
- BringContextForward();
-#endif
- bFakeFrontBuffer=FALSE;
- bRenderFrontBuffer=FALSE;
-
- if(iRenderFVR) // frame buffer read fix mode still active?
- {
- iRenderFVR--; // -> if some frames in a row without read access: turn off mode
- if(!iRenderFVR) bFullVRam=FALSE;
- }
-
- if(iLastRGB24 && iLastRGB24!=PSXDisplay.RGB24+1) // (mdec) garbage check
- {
- iSkipTwo=2; // -> skip two frames to avoid garbage if color mode changes
- }
- iLastRGB24=0;
-
- if(PSXDisplay.RGB24)// && !bNeedUploadAfter) // (mdec) upload wanted?
- {
- PrepareFullScreenUpload(-1);
- UploadScreen(PSXDisplay.Interlaced); // -> upload whole screen from psx vram
- bNeedUploadTest=FALSE;
- bNeedInterlaceUpdate=FALSE;
- bNeedUploadAfter=FALSE;
- bNeedRGB24Update=FALSE;
- }
- else
- if(bNeedInterlaceUpdate) // smaller upload?
- {
- bNeedInterlaceUpdate=FALSE;
- xrUploadArea=xrUploadAreaIL; // -> upload this rect
- UploadScreen(TRUE);
- }
-
- if(dwActFixes&512) bCheckFF9G4(NULL); // special game fix for FF9
-
- if(PreviousPSXDisplay.Range.x0|| // paint black borders around display area, if needed
- PreviousPSXDisplay.Range.y0)
- PaintBlackBorders();
-
- if(PSXDisplay.Disabled) // display disabled?
- {
- // moved here
- glDisable(GL_SCISSOR_TEST);
- glClearColor(0,0,0,128); // -> clear whole backbuffer
- glClear(uiBufferBits);
- glEnable(GL_SCISSOR_TEST);
- gl_z=0.0f;
- bDisplayNotSet = TRUE;
- }
-
- if(iSkipTwo) // we are in skipping mood?
- {
- iSkipTwo--;
- iDrawnSomething=0; // -> simply lie about something drawn
- }
-
- if(iBlurBuffer && !bSkipNextFrame) // "blur display" activated?
- {BlurBackBuffer();bBlur=TRUE;} // -> blur it
-
- if(iUseScanLines) SetScanLines(); // "scan lines" activated? do it
-
- if(usCursorActive) ShowGunCursor(); // "gun cursor" wanted? show 'em
-
- if(dwActFixes&128) // special FPS limitation mode?
- {
- if(bUseFrameLimit) PCFrameCap(); // -> ok, do it
- if(bUseFrameSkip || ulKeybits&KEY_SHOWFPS)
- PCcalcfps();
- }
-
- if(gTexPicName) DisplayPic(); // some gpu info picture active? display it
-
- if(bSnapShot) DoSnapShot(); // snapshot key pressed? cheeeese :)
-
- if(ulKeybits&KEY_SHOWFPS) // wanna see FPS?
- {
- sprintf(szDispBuf,"%06.1f",fps_cur);
- DisplayText(); // -> show it
- }
-
- //----------------------------------------------------//
- // main buffer swapping (well, or skip it)
-
- if(bUseFrameSkip) // frame skipping active ?
- {
- if(!bSkipNextFrame)
- {
- if(iDrawnSomething)
-#ifdef _WINDOWS
- SwapBuffers(wglGetCurrentDC()); // -> to skip or not to skip
-#elif defined(_MACGL)
- DoBufferSwap();
-#else
- glXSwapBuffers(display,window);
-#endif
- }
- if(dwActFixes&0x180) // -> special old frame skipping: skip max one in a row
- {
- if((fps_skip < fFrameRateHz) && !(bSkipNextFrame))
- {bSkipNextFrame = TRUE; fps_skip=fFrameRateHz;}
- else bSkipNextFrame = FALSE;
- }
- else FrameSkip();
- }
- else // no skip ?
- {
- if(iDrawnSomething)
-#ifdef _WINDOWS
- SwapBuffers(wglGetCurrentDC()); // -> swap
-#elif defined(_MACGL)
- DoBufferSwap();
-#else
- glXSwapBuffers(display,window);
-#endif
- }
-
- iDrawnSomething=0;
-
- //----------------------------------------------------//
-
- if(lClearOnSwap) // clear buffer after swap?
- {
- GLclampf g,b,r;
-
- if(bDisplayNotSet) // -> set new vals
- SetOGLDisplaySettings(1);
-
- g=((GLclampf)GREEN(lClearOnSwapColor))/255.0f; // -> get col
- b=((GLclampf)BLUE(lClearOnSwapColor))/255.0f;
- r=((GLclampf)RED(lClearOnSwapColor))/255.0f;
-
- glDisable(GL_SCISSOR_TEST);
- glClearColor(r,g,b,128); // -> clear
- glClear(uiBufferBits);
- glEnable(GL_SCISSOR_TEST);
- lClearOnSwap=0; // -> done
- }
- else
- {
- if(bBlur) UnBlurBackBuffer(); // unblur buff, if blurred before
-
- if(iZBufferDepth) // clear zbuffer as well (if activated)
- {
- glDisable(GL_SCISSOR_TEST);
- glClear(GL_DEPTH_BUFFER_BIT);
- glEnable(GL_SCISSOR_TEST);
- }
- }
- gl_z=0.0f;
-
- //----------------------------------------------------//
- // additional uploads immediatly after swapping
-
- if(bNeedUploadAfter) // upload wanted?
- {
- bNeedUploadAfter=FALSE;
- bNeedUploadTest=FALSE;
- UploadScreen(-1); // -> upload
- }
-
- if(bNeedUploadTest)
- {
- bNeedUploadTest=FALSE;
- if(PSXDisplay.InterlacedTest &&
- //iOffscreenDrawing>2 &&
- PreviousPSXDisplay.DisplayPosition.x==PSXDisplay.DisplayPosition.x &&
- PreviousPSXDisplay.DisplayEnd.x==PSXDisplay.DisplayEnd.x &&
- PreviousPSXDisplay.DisplayPosition.y==PSXDisplay.DisplayPosition.y &&
- PreviousPSXDisplay.DisplayEnd.y==PSXDisplay.DisplayEnd.y)
- {
- PrepareFullScreenUpload(TRUE);
- UploadScreen(TRUE);
- }
- }
-
- //----------------------------------------------------//
- // rumbling (main emu pad effect)
-
- if(iRumbleTime) // shake screen by modifying view port
- {
- int i1=0,i2=0,i3=0,i4=0;
-
- iRumbleTime--;
- if(iRumbleTime)
- {
- i1=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
- i2=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
- i3=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
- i4=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
- }
-
- glViewport(rRatioRect.left+i1,
- iResY-(rRatioRect.top+rRatioRect.bottom)+i2,
- rRatioRect.right+i3,
- rRatioRect.bottom+i4);
- }
-
-#ifdef _WINDOWS
- ReleaseDC(hWWindow,hdc); // ! important !
-#endif
-
- if(ulKeybits&KEY_RESETTEXSTORE) ResetStuff(); // reset on gpu mode changes? do it before next frame is filled
-}
-
-////////////////////////////////////////////////////////////////////////
-// update front display: smaller update func, if something has changed
-// in the frontbuffer... dirty, but hey... real men know no pain
-////////////////////////////////////////////////////////////////////////
-
-void updateFrontDisplay(void)
-{
- if(PreviousPSXDisplay.Range.x0||
- PreviousPSXDisplay.Range.y0)
- PaintBlackBorders();
-
- if(iBlurBuffer) BlurBackBuffer();
-
- if(iUseScanLines) SetScanLines();
-
- if(usCursorActive) ShowGunCursor();
-
- bFakeFrontBuffer=FALSE;
- bRenderFrontBuffer=FALSE;
-
- if(gTexPicName) DisplayPic();
- if(ulKeybits&KEY_SHOWFPS) DisplayText();
-
-#ifdef _WINDOWS
- { // windows:
- HDC hdc=GetDC(hWWindow);
- wglMakeCurrent(hdc,GLCONTEXT); // -> make current again
- if(iDrawnSomething)
- SwapBuffers(wglGetCurrentDC()); // -> swap
- ReleaseDC(hWWindow,hdc); // -> ! important !
- }
-#elif defined (_MACGL)
-if (iDrawnSomething){
- DoBufferSwap();
- }
-#else
- if(iDrawnSomething) // linux:
- glXSwapBuffers(display,window);
-#endif
-
- if(iBlurBuffer) UnBlurBackBuffer();
-}
-
-////////////////////////////////////////////////////////////////////////
-// check if update needed
-////////////////////////////////////////////////////////////////////////
-
-void ChangeDispOffsetsX(void) // CENTER X
-{
- int lx,l;short sO;
-
- if(!PSXDisplay.Range.x1) return; // some range given?
-
- l=PSXDisplay.DisplayMode.x;
-
- l*=(int)PSXDisplay.Range.x1; // some funky calculation
- l/=2560;lx=l;l&=0xfffffff8;
-
- if(l==PreviousPSXDisplay.Range.x1) return; // some change?
-
- sO=PreviousPSXDisplay.Range.x0; // store old
-
- if(lx>=PSXDisplay.DisplayMode.x) // range bigger?
- {
- PreviousPSXDisplay.Range.x1= // -> take display width
- PSXDisplay.DisplayMode.x;
- PreviousPSXDisplay.Range.x0=0; // -> start pos is 0
- }
- else // range smaller? center it
- {
- PreviousPSXDisplay.Range.x1=l; // -> store width (8 pixel aligned)
- PreviousPSXDisplay.Range.x0= // -> calc start pos
- (PSXDisplay.Range.x0-500)/8;
- if(PreviousPSXDisplay.Range.x0<0) // -> we don't support neg. values yet
- PreviousPSXDisplay.Range.x0=0;
-
- if((PreviousPSXDisplay.Range.x0+lx)> // -> uhuu... that's too much
- PSXDisplay.DisplayMode.x)
- {
- PreviousPSXDisplay.Range.x0= // -> adjust start
- PSXDisplay.DisplayMode.x-lx;
- PreviousPSXDisplay.Range.x1+=lx-l; // -> adjust width
- }
- }
-
- if(sO!=PreviousPSXDisplay.Range.x0) // something changed?
- {
- bDisplayNotSet=TRUE; // -> recalc display stuff
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void ChangeDispOffsetsY(void) // CENTER Y
-{
- int iT;short sO; // store previous y size
-
- if(PSXDisplay.PAL) iT=48; else iT=28; // different offsets on PAL/NTSC
-
- if(PSXDisplay.Range.y0>=iT) // crossed the security line? :)
- {
- PreviousPSXDisplay.Range.y1= // -> store width
- PSXDisplay.DisplayModeNew.y;
-
- sO=(PSXDisplay.Range.y0-iT-4)*PSXDisplay.Double; // -> calc offset
- if(sO<0) sO=0;
-
- PSXDisplay.DisplayModeNew.y+=sO; // -> add offset to y size, too
- }
- else sO=0; // else no offset
-
- if(sO!=PreviousPSXDisplay.Range.y0) // something changed?
- {
- PreviousPSXDisplay.Range.y0=sO;
- bDisplayNotSet=TRUE; // -> recalc display stuff
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// Aspect ratio of ogl screen: simply adjusting ogl view port
-////////////////////////////////////////////////////////////////////////
-
-void SetAspectRatio(void)
-{
- float xs,ys,s;RECT r;
-
- if(!PSXDisplay.DisplayModeNew.x) return;
- if(!PSXDisplay.DisplayModeNew.y) return;
-
- xs=(float)iResX/(float)PSXDisplay.DisplayModeNew.x;
- ys=(float)iResY/(float)PSXDisplay.DisplayModeNew.y;
-
- s=min(xs,ys);
- r.right =(int)((float)PSXDisplay.DisplayModeNew.x*s);
- r.bottom=(int)((float)PSXDisplay.DisplayModeNew.y*s);
- if(r.right > iResX) r.right = iResX;
- if(r.bottom > iResY) r.bottom = iResY;
- if(r.right < 1) r.right = 1;
- if(r.bottom < 1) r.bottom = 1;
-
- r.left = (iResX-r.right)/2;
- r.top = (iResY-r.bottom)/2;
-
- if(r.bottom<rRatioRect.bottom ||
- r.right <rRatioRect.right)
- {
- RECT rC;
- glClearColor(0,0,0,128);
-
- if(r.right <rRatioRect.right)
- {
- rC.left=0;
- rC.top=0;
- rC.right=r.left;
- rC.bottom=iResY;
- glScissor(rC.left,rC.top,rC.right,rC.bottom);
- glClear(uiBufferBits);
- rC.left=iResX-rC.right;
- glScissor(rC.left,rC.top,rC.right,rC.bottom);
- glClear(uiBufferBits);
- }
-
- if(r.bottom <rRatioRect.bottom)
- {
- rC.left=0;
- rC.top=0;
- rC.right=iResX;
- rC.bottom=r.top;
- glScissor(rC.left,rC.top,rC.right,rC.bottom);
- glClear(uiBufferBits);
- rC.top=iResY-rC.bottom;
- glScissor(rC.left,rC.top,rC.right,rC.bottom);
- glClear(uiBufferBits);
- }
-
- bSetClip=TRUE;
- bDisplayNotSet=TRUE;
- }
-
- rRatioRect=r;
-
-
- glViewport(rRatioRect.left,
- iResY-(rRatioRect.top+rRatioRect.bottom),
- rRatioRect.right,
- rRatioRect.bottom); // init viewport
-}
-
-////////////////////////////////////////////////////////////////////////
-// big ass check, if an ogl swap buffer is needed
-////////////////////////////////////////////////////////////////////////
-
-void updateDisplayIfChanged(void)
-{
- BOOL bUp;
-
- if ((PSXDisplay.DisplayMode.y == PSXDisplay.DisplayModeNew.y) &&
- (PSXDisplay.DisplayMode.x == PSXDisplay.DisplayModeNew.x))
- {
- if((PSXDisplay.RGB24 == PSXDisplay.RGB24New) &&
- (PSXDisplay.Interlaced == PSXDisplay.InterlacedNew))
- return; // nothing has changed? fine, no swap buffer needed
- }
- else // some res change?
- {
- glLoadIdentity();
- glOrtho(0,PSXDisplay.DisplayModeNew.x, // -> new psx resolution
- PSXDisplay.DisplayModeNew.y, 0, -1, 1);
- if(bKeepRatio) SetAspectRatio();
- }
-
- bDisplayNotSet = TRUE; // re-calc offsets/display area
-
- bUp=FALSE;
- if(PSXDisplay.RGB24!=PSXDisplay.RGB24New) // clean up textures, if rgb mode change (usually mdec on/off)
- {
- PreviousPSXDisplay.RGB24=0; // no full 24 frame uploaded yet
- ResetTextureArea(FALSE);
- bUp=TRUE;
- }
-
- PSXDisplay.RGB24 = PSXDisplay.RGB24New; // get new infos
- PSXDisplay.DisplayMode.y = PSXDisplay.DisplayModeNew.y;
- PSXDisplay.DisplayMode.x = PSXDisplay.DisplayModeNew.x;
- PSXDisplay.Interlaced = PSXDisplay.InterlacedNew;
-
- PSXDisplay.DisplayEnd.x= // calc new ends
- PSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
- PSXDisplay.DisplayEnd.y=
- PSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
- PreviousPSXDisplay.DisplayEnd.x=
- PreviousPSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
- PreviousPSXDisplay.DisplayEnd.y=
- PreviousPSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
-
- ChangeDispOffsetsX();
-
- if(iFrameLimit==2) SetAutoFrameCap(); // set new fps limit vals (depends on interlace)
-
- if(bUp) updateDisplay(); // yeah, real update (swap buffer)
-}
-
-////////////////////////////////////////////////////////////////////////
-// window mode <-> fullscreen mode (windows)
-////////////////////////////////////////////////////////////////////////
-
-#ifdef _WINDOWS
-void ChangeWindowMode(void)
- {
- GPUclose();
- bWindowMode=!bWindowMode;
- GPUopen(hWWindow);
- bChangeWinMode=FALSE;
- }
-#endif
-
-////////////////////////////////////////////////////////////////////////
-// swap update check (called by psx vsync function)
-////////////////////////////////////////////////////////////////////////
-
-BOOL bSwapCheck(void)
-{
- static int iPosCheck=0;
- static PSXPoint_t pO;
- static PSXPoint_t pD;
- static int iDoAgain=0;
-
- if(PSXDisplay.DisplayPosition.x==pO.x &&
- PSXDisplay.DisplayPosition.y==pO.y &&
- PSXDisplay.DisplayEnd.x==pD.x &&
- PSXDisplay.DisplayEnd.y==pD.y)
- iPosCheck++;
- else iPosCheck=0;
-
- pO=PSXDisplay.DisplayPosition;
- pD=PSXDisplay.DisplayEnd;
-
- if(iPosCheck<=4) return FALSE;
-
- iPosCheck=4;
-
- if(PSXDisplay.Interlaced) return FALSE;
-
- if (bNeedInterlaceUpdate||
- bNeedRGB24Update ||
- bNeedUploadAfter||
- bNeedUploadTest ||
- iDoAgain
- )
- {
- iDoAgain=0;
- if(bNeedUploadAfter)
- iDoAgain=1;
- if(bNeedUploadTest && PSXDisplay.InterlacedTest)
- iDoAgain=1;
-
- bDisplayNotSet = TRUE;
- updateDisplay();
-
- PreviousPSXDisplay.DisplayPosition.x=PSXDisplay.DisplayPosition.x;
- PreviousPSXDisplay.DisplayPosition.y=PSXDisplay.DisplayPosition.y;
- PreviousPSXDisplay.DisplayEnd.x=PSXDisplay.DisplayEnd.x;
- PreviousPSXDisplay.DisplayEnd.y=PSXDisplay.DisplayEnd.y;
- pO=PSXDisplay.DisplayPosition;
- pD=PSXDisplay.DisplayEnd;
-
- return TRUE;
- }
-
- return FALSE;
-}
-
-////////////////////////////////////////////////////////////////////////
-// gun cursor func: player=0-7, x=0-511, y=0-255
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUcursor(int iPlayer,int x,int y)
-{
- if(iPlayer<0) return;
- if(iPlayer>7) return;
-
- usCursorActive|=(1<<iPlayer);
-
- if(x<0) x=0;
- if(x>iGPUHeightMask) x=iGPUHeightMask;
- if(y<0) y=0;
- if(y>255) y=255;
-
- ptCursorPoint[iPlayer].x=x;
- ptCursorPoint[iPlayer].y=y;
-}
-
-////////////////////////////////////////////////////////////////////////
-// update lace is called every VSync. Basically we limit frame rate
-// here, and in interlaced mode we swap ogl display buffers.
-////////////////////////////////////////////////////////////////////////
-
-static unsigned short usFirstPos=2;
-
-void CALLBACK GPUupdateLace(void)
-{
- //if(!(dwActFixes&0x1000))
- // STATUSREG^=0x80000000; // interlaced bit toggle, if the CC game fix is not active (see gpuReadStatus)
-
- if(!(dwActFixes&128)) // normal frame limit func
- CheckFrameRate();
-
- if(iOffscreenDrawing==4) // special check if high offscreen drawing is on
- {
- if(bSwapCheck()) return;
- }
-
- if(PSXDisplay.Interlaced) // interlaced mode?
- {
- STATUSREG^=0x80000000;
- if(PSXDisplay.DisplayMode.x>0 && PSXDisplay.DisplayMode.y>0)
- {
- updateDisplay(); // -> swap buffers (new frame)
- }
- }
- else if(bRenderFrontBuffer) // no interlace mode? and some stuff in front has changed?
- {
- updateFrontDisplay(); // -> update front buffer
- }
- else if(usFirstPos==1) // initial updates (after startup)
- {
- updateDisplay();
- }
-
-#if defined(_WINDOWS) || defined(_MACGL)
- if(bChangeWinMode) ChangeWindowMode();
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////
-// process read request from GPU status register
-////////////////////////////////////////////////////////////////////////
-
-uint32_t CALLBACK GPUreadStatus(void)
-{
- if(dwActFixes&0x1000) // CC game fix
- {
- static int iNumRead=0;
- if((iNumRead++)==2)
- {
- iNumRead=0;
- STATUSREG^=0x80000000; // interlaced bit toggle... we do it on every second read status... needed by some games (like ChronoCross)
- }
- }
-
- if(iFakePrimBusy) // 27.10.2007 - emulating some 'busy' while drawing... pfff... not perfect, but since our emulated dma is not done in an extra thread...
- {
- iFakePrimBusy--;
-
- if(iFakePrimBusy&1) // we do a busy-idle-busy-idle sequence after/while drawing prims
- {
- GPUIsBusy;
- GPUIsNotReadyForCommands;
- }
- else
- {
- GPUIsIdle;
- GPUIsReadyForCommands;
- }
- }
-
- return STATUSREG | (vBlank ? 0x80000000 : 0 );;
-}
-
-////////////////////////////////////////////////////////////////////////
-// processes data send to GPU status register
-// these are always single packet commands.
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUwriteStatus(uint32_t gdata)
-{
- uint32_t lCommand=(gdata>>24)&0xff;
-
-#ifdef _WINDOWS
- if(bIsFirstFrame) GLinitialize(); // real ogl startup (needed by some emus)
-#endif
-
- ulStatusControl[lCommand]=gdata;
-
- switch(lCommand)
- {
- //--------------------------------------------------//
- // reset gpu
- case 0x00:
- memset(ulGPUInfoVals, 0x00, 16 * sizeof(uint32_t));
- lGPUstatusRet = 0x14802000;
- PSXDisplay.Disabled=1;
- iDataWriteMode=iDataReadMode=DR_NORMAL;
- PSXDisplay.DrawOffset.x=PSXDisplay.DrawOffset.y=0;
- drawX=drawY=0;drawW=drawH=0;
- sSetMask=0;lSetMask=0;bCheckMask=FALSE;iSetMask=0;
- usMirror=0;
- GlobalTextAddrX=0;GlobalTextAddrY=0;
- GlobalTextTP=0;GlobalTextABR=0;
- PSXDisplay.RGB24=FALSE;
- PSXDisplay.Interlaced=FALSE;
- bUsingTWin = FALSE;
- return;
-
- // dis/enable display
- case 0x03:
- PreviousPSXDisplay.Disabled = PSXDisplay.Disabled;
- PSXDisplay.Disabled = (gdata & 1);
-
- if(PSXDisplay.Disabled)
- STATUSREG|=GPUSTATUS_DISPLAYDISABLED;
- else STATUSREG&=~GPUSTATUS_DISPLAYDISABLED;
-
- if (iOffscreenDrawing==4 &&
- PreviousPSXDisplay.Disabled &&
- !(PSXDisplay.Disabled))
- {
-
- if(!PSXDisplay.RGB24)
- {
- PrepareFullScreenUpload(TRUE);
- UploadScreen(TRUE);
- updateDisplay();
- }
- }
-
- return;
-
- // setting transfer mode
- case 0x04:
- gdata &= 0x03; // only want the lower two bits
-
- iDataWriteMode=iDataReadMode=DR_NORMAL;
- if(gdata==0x02) iDataWriteMode=DR_VRAMTRANSFER;
- if(gdata==0x03) iDataReadMode =DR_VRAMTRANSFER;
-
- STATUSREG&=~GPUSTATUS_DMABITS; // clear the current settings of the DMA bits
- STATUSREG|=(gdata << 29); // set the DMA bits according to the received data
-
- return;
-
- // setting display position
- case 0x05:
- {
- short sx=(short)(gdata & 0x3ff);
- short sy;
-
- if(iGPUHeight==1024)
- {
- if(dwGPUVersion==2)
- sy = (short)((gdata>>12)&0x3ff);
- else sy = (short)((gdata>>10)&0x3ff);
- }
- else sy = (short)((gdata>>10)&0x3ff); // really: 0x1ff, but we adjust it later
-
- if (sy & 0x200)
- {
- sy|=0xfc00;
- PreviousPSXDisplay.DisplayModeNew.y=sy/PSXDisplay.Double;
- sy=0;
- }
- else PreviousPSXDisplay.DisplayModeNew.y=0;
-
- if(sx>1000) sx=0;
-
- if(usFirstPos)
- {
- usFirstPos--;
- if(usFirstPos)
- {
- PreviousPSXDisplay.DisplayPosition.x = sx;
- PreviousPSXDisplay.DisplayPosition.y = sy;
- PSXDisplay.DisplayPosition.x = sx;
- PSXDisplay.DisplayPosition.y = sy;
- }
- }
-
- if(dwActFixes&8)
- {
- if((!PSXDisplay.Interlaced) &&
- PreviousPSXDisplay.DisplayPosition.x == sx &&
- PreviousPSXDisplay.DisplayPosition.y == sy)
- return;
-
- PSXDisplay.DisplayPosition.x = PreviousPSXDisplay.DisplayPosition.x;
- PSXDisplay.DisplayPosition.y = PreviousPSXDisplay.DisplayPosition.y;
- PreviousPSXDisplay.DisplayPosition.x = sx;
- PreviousPSXDisplay.DisplayPosition.y = sy;
- }
- else
- {
- if((!PSXDisplay.Interlaced) &&
- PSXDisplay.DisplayPosition.x == sx &&
- PSXDisplay.DisplayPosition.y == sy)
- return;
- PreviousPSXDisplay.DisplayPosition.x = PSXDisplay.DisplayPosition.x;
- PreviousPSXDisplay.DisplayPosition.y = PSXDisplay.DisplayPosition.y;
- PSXDisplay.DisplayPosition.x = sx;
- PSXDisplay.DisplayPosition.y = sy;
- }
-
- PSXDisplay.DisplayEnd.x=
- PSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
- PSXDisplay.DisplayEnd.y=
- PSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
-
- PreviousPSXDisplay.DisplayEnd.x=
- PreviousPSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
- PreviousPSXDisplay.DisplayEnd.y=
- PreviousPSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
-
- bDisplayNotSet = TRUE;
-
- if (!(PSXDisplay.Interlaced))
- {
- updateDisplay();
- }
- else
- if(PSXDisplay.InterlacedTest &&
- ((PreviousPSXDisplay.DisplayPosition.x != PSXDisplay.DisplayPosition.x)||
- (PreviousPSXDisplay.DisplayPosition.y != PSXDisplay.DisplayPosition.y)))
- PSXDisplay.InterlacedTest--;
-
- return;
- }
-
- // setting width
- case 0x06:
-
- PSXDisplay.Range.x0=gdata & 0x7ff; //0x3ff;
- PSXDisplay.Range.x1=(gdata>>12) & 0xfff;//0x7ff;
-
- PSXDisplay.Range.x1-=PSXDisplay.Range.x0;
-
- ChangeDispOffsetsX();
-
- return;
-
- // setting height
- case 0x07:
-
- PreviousPSXDisplay.Height = PSXDisplay.Height;
-
- PSXDisplay.Range.y0=gdata & 0x3ff;
- PSXDisplay.Range.y1=(gdata>>10) & 0x3ff;
-
- PSXDisplay.Height = PSXDisplay.Range.y1 -
- PSXDisplay.Range.y0 +
- PreviousPSXDisplay.DisplayModeNew.y;
-
- if (PreviousPSXDisplay.Height != PSXDisplay.Height)
- {
- PSXDisplay.DisplayModeNew.y=PSXDisplay.Height*PSXDisplay.Double;
- ChangeDispOffsetsY();
- updateDisplayIfChanged();
- }
- return;
-
- // setting display infos
- case 0x08:
-
- PSXDisplay.DisplayModeNew.x = dispWidths[(gdata & 0x03) | ((gdata & 0x40) >> 4)];
-
- if (gdata&0x04) PSXDisplay.Double=2;
- else PSXDisplay.Double=1;
- PSXDisplay.DisplayModeNew.y = PSXDisplay.Height*PSXDisplay.Double;
-
- ChangeDispOffsetsY();
-
- PSXDisplay.PAL = (gdata & 0x08)?TRUE:FALSE; // if 1 - PAL mode, else NTSC
- PSXDisplay.RGB24New = (gdata & 0x10)?TRUE:FALSE; // if 1 - TrueColor
- PSXDisplay.InterlacedNew = (gdata & 0x20)?TRUE:FALSE; // if 1 - Interlace
-
- STATUSREG&=~GPUSTATUS_WIDTHBITS; // clear the width bits
-
- STATUSREG|=
- (((gdata & 0x03) << 17) |
- ((gdata & 0x40) << 10)); // set the width bits
-
- PreviousPSXDisplay.InterlacedNew=FALSE;
- if (PSXDisplay.InterlacedNew)
- {
- if(!PSXDisplay.Interlaced)
- {
- PSXDisplay.InterlacedTest=2;
- PreviousPSXDisplay.DisplayPosition.x = PSXDisplay.DisplayPosition.x;
- PreviousPSXDisplay.DisplayPosition.y = PSXDisplay.DisplayPosition.y;
- PreviousPSXDisplay.InterlacedNew=TRUE;
- }
-
- STATUSREG|=GPUSTATUS_INTERLACED;
- }
- else
- {
- PSXDisplay.InterlacedTest=0;
- STATUSREG&=~GPUSTATUS_INTERLACED;
- }
-
- if (PSXDisplay.PAL)
- STATUSREG|=GPUSTATUS_PAL;
- else STATUSREG&=~GPUSTATUS_PAL;
-
- if (PSXDisplay.Double==2)
- STATUSREG|=GPUSTATUS_DOUBLEHEIGHT;
- else STATUSREG&=~GPUSTATUS_DOUBLEHEIGHT;
-
- if (PSXDisplay.RGB24New)
- STATUSREG|=GPUSTATUS_RGB24;
- else STATUSREG&=~GPUSTATUS_RGB24;
-
- updateDisplayIfChanged();
-
- return;
-
- //--------------------------------------------------//
- // ask about GPU version and other stuff
- case 0x10:
-
- gdata&=0xff;
-
- switch(gdata)
- {
- case 0x02:
- GPUdataRet=ulGPUInfoVals[INFO_TW]; // tw infos
- return;
- case 0x03:
- GPUdataRet=ulGPUInfoVals[INFO_DRAWSTART]; // draw start
- return;
- case 0x04:
- GPUdataRet=ulGPUInfoVals[INFO_DRAWEND]; // draw end
- return;
- case 0x05:
- case 0x06:
- GPUdataRet=ulGPUInfoVals[INFO_DRAWOFF]; // draw offset
- return;
- case 0x07:
- if(dwGPUVersion==2)
- GPUdataRet=0x01;
- else GPUdataRet=0x02; // gpu type
- return;
- case 0x08:
- case 0x0F: // some bios addr?
- GPUdataRet=0xBFC03720;
- return;
- }
- return;
- //--------------------------------------------------//
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// vram read/write helpers
-////////////////////////////////////////////////////////////////////////
-
-BOOL bNeedWriteUpload=FALSE;
-
-__inline void FinishedVRAMWrite(void)
-{
- if(bNeedWriteUpload)
- {
- bNeedWriteUpload=FALSE;
- CheckWriteUpdate();
- }
-
- // set register to NORMAL operation
- iDataWriteMode = DR_NORMAL;
-
- // reset transfer values, to prevent mis-transfer of data
- VRAMWrite.ColsRemaining = 0;
- VRAMWrite.RowsRemaining = 0;
-}
-
-__inline void FinishedVRAMRead(void)
-{
- // set register to NORMAL operation
- iDataReadMode = DR_NORMAL;
- // reset transfer values, to prevent mis-transfer of data
- VRAMRead.x = 0;
- VRAMRead.y = 0;
- VRAMRead.Width = 0;
- VRAMRead.Height = 0;
- VRAMRead.ColsRemaining = 0;
- VRAMRead.RowsRemaining = 0;
-
- // indicate GPU is no longer ready for VRAM data in the STATUS REGISTER
- STATUSREG&=~GPUSTATUS_READYFORVRAM;
-}
-
-////////////////////////////////////////////////////////////////////////
-// vram read check ex (reading from card's back/frontbuffer if needed...
-// slow!)
-////////////////////////////////////////////////////////////////////////
-
-void CheckVRamReadEx(int x, int y, int dx, int dy)
-{
- unsigned short sArea;
- int ux,uy,udx,udy,wx,wy;
- unsigned short * p1, *p2;
- float XS,YS;
- unsigned char * ps;
- unsigned char * px;
- unsigned short s,sx;
-
- if(STATUSREG&GPUSTATUS_RGB24) return;
-
- if(((dx > PSXDisplay.DisplayPosition.x) &&
- (x < PSXDisplay.DisplayEnd.x) &&
- (dy > PSXDisplay.DisplayPosition.y) &&
- (y < PSXDisplay.DisplayEnd.y)))
- sArea=0;
- else
- if((!(PSXDisplay.InterlacedTest) &&
- (dx > PreviousPSXDisplay.DisplayPosition.x) &&
- (x < PreviousPSXDisplay.DisplayEnd.x) &&
- (dy > PreviousPSXDisplay.DisplayPosition.y) &&
- (y < PreviousPSXDisplay.DisplayEnd.y)))
- sArea=1;
- else
- {
- return;
- }
-
- //////////////
-
- if(iRenderFVR)
- {
- bFullVRam=TRUE;iRenderFVR=2;return;
- }
- bFullVRam=TRUE;iRenderFVR=2;
-
- //////////////
-
- p2=0;
-
- if(sArea==0)
- {
- ux=PSXDisplay.DisplayPosition.x;
- uy=PSXDisplay.DisplayPosition.y;
- udx=PSXDisplay.DisplayEnd.x-ux;
- udy=PSXDisplay.DisplayEnd.y-uy;
- if((PreviousPSXDisplay.DisplayEnd.x-
- PreviousPSXDisplay.DisplayPosition.x)==udx &&
- (PreviousPSXDisplay.DisplayEnd.y-
- PreviousPSXDisplay.DisplayPosition.y)==udy)
- p2=(psxVuw + (1024*PreviousPSXDisplay.DisplayPosition.y) +
- PreviousPSXDisplay.DisplayPosition.x);
- }
- else
- {
- ux=PreviousPSXDisplay.DisplayPosition.x;
- uy=PreviousPSXDisplay.DisplayPosition.y;
- udx=PreviousPSXDisplay.DisplayEnd.x-ux;
- udy=PreviousPSXDisplay.DisplayEnd.y-uy;
- if((PSXDisplay.DisplayEnd.x-
- PSXDisplay.DisplayPosition.x)==udx &&
- (PSXDisplay.DisplayEnd.y-
- PSXDisplay.DisplayPosition.y)==udy)
- p2=(psxVuw + (1024*PSXDisplay.DisplayPosition.y) +
- PSXDisplay.DisplayPosition.x);
- }
-
- p1=(psxVuw + (1024*uy) + ux);
- if(p1==p2) p2=0;
-
- x=0;y=0;
- wx=dx=udx;wy=dy=udy;
-
- if(udx<=0) return;
- if(udy<=0) return;
- if(dx<=0) return;
- if(dy<=0) return;
- if(wx<=0) return;
- if(wy<=0) return;
-
- XS=(float)rRatioRect.right/(float)wx;
- YS=(float)rRatioRect.bottom/(float)wy;
-
- dx=(int)((float)(dx)*XS);
- dy=(int)((float)(dy)*YS);
-
- if(dx>iResX) dx=iResX;
- if(dy>iResY) dy=iResY;
-
- if(dx<=0) return;
- if(dy<=0) return;
-
- // ogl y adjust
- y=iResY-y-dy;
-
- x+=rRatioRect.left;
- y-=rRatioRect.top;
-
- if(y<0) y=0; if((y+dy)>iResY) dy=iResY-y;
-
- if(!pGfxCardScreen)
- {
- glPixelStorei(GL_PACK_ALIGNMENT,1);
- pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);
- }
-
- ps=pGfxCardScreen;
-
- if(!sArea) glReadBuffer(GL_FRONT);
-
- glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps);
-
- if(!sArea) glReadBuffer(GL_BACK);
-
- s=0;
-
- XS=(float)dx/(float)(udx);
- YS=(float)dy/(float)(udy+1);
-
- for(y=udy;y>0;y--)
- {
- for(x=0;x<udx;x++)
- {
- if(p1>=psxVuw && p1<psxVuw_eom)
- {
- px=ps+(3*((int)((float)x * XS))+
- (3*dx)*((int)((float)y*YS)));
- sx=(*px)>>3;px++;
- s=sx;
- sx=(*px)>>3;px++;
- s|=sx<<5;
- sx=(*px)>>3;
- s|=sx<<10;
- s&=~0x8000;
- *p1=s;
- }
- if(p2>=psxVuw && p2<psxVuw_eom) *p2=s;
-
- p1++;
- if(p2) p2++;
- }
-
- p1 += 1024 - udx;
- if(p2) p2 += 1024 - udx;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// vram read check (reading from card's back/frontbuffer if needed...
-// slow!)
-////////////////////////////////////////////////////////////////////////
-
-void CheckVRamRead(int x, int y, int dx, int dy,BOOL bFront)
-{
- unsigned short sArea;unsigned short * p;
- int ux,uy,udx,udy,wx,wy;float XS,YS;
- unsigned char * ps, * px;
- unsigned short s=0,sx;
-
- if(STATUSREG&GPUSTATUS_RGB24) return;
-
- if(((dx > PSXDisplay.DisplayPosition.x) &&
- (x < PSXDisplay.DisplayEnd.x) &&
- (dy > PSXDisplay.DisplayPosition.y) &&
- (y < PSXDisplay.DisplayEnd.y)))
- sArea=0;
- else
- if((!(PSXDisplay.InterlacedTest) &&
- (dx > PreviousPSXDisplay.DisplayPosition.x) &&
- (x < PreviousPSXDisplay.DisplayEnd.x) &&
- (dy > PreviousPSXDisplay.DisplayPosition.y) &&
- (y < PreviousPSXDisplay.DisplayEnd.y)))
- sArea=1;
- else
- {
- return;
- }
-
- if(dwActFixes&0x40)
- {
- if(iRenderFVR)
- {
- bFullVRam=TRUE;iRenderFVR=2;return;
- }
- bFullVRam=TRUE;iRenderFVR=2;
- }
-
- ux=x;uy=y;udx=dx;udy=dy;
-
- if(sArea==0)
- {
- x -=PSXDisplay.DisplayPosition.x;
- dx-=PSXDisplay.DisplayPosition.x;
- y -=PSXDisplay.DisplayPosition.y;
- dy-=PSXDisplay.DisplayPosition.y;
- wx=PSXDisplay.DisplayEnd.x-PSXDisplay.DisplayPosition.x;
- wy=PSXDisplay.DisplayEnd.y-PSXDisplay.DisplayPosition.y;
- }
- else
- {
- x -=PreviousPSXDisplay.DisplayPosition.x;
- dx-=PreviousPSXDisplay.DisplayPosition.x;
- y -=PreviousPSXDisplay.DisplayPosition.y;
- dy-=PreviousPSXDisplay.DisplayPosition.y;
- wx=PreviousPSXDisplay.DisplayEnd.x-PreviousPSXDisplay.DisplayPosition.x;
- wy=PreviousPSXDisplay.DisplayEnd.y-PreviousPSXDisplay.DisplayPosition.y;
- }
- if(x<0) {ux-=x;x=0;}
- if(y<0) {uy-=y;y=0;}
- if(dx>wx) {udx-=(dx-wx);dx=wx;}
- if(dy>wy) {udy-=(dy-wy);dy=wy;}
- udx-=ux;
- udy-=uy;
-
- p=(psxVuw + (1024*uy) + ux);
-
- if(udx<=0) return;
- if(udy<=0) return;
- if(dx<=0) return;
- if(dy<=0) return;
- if(wx<=0) return;
- if(wy<=0) return;
-
- XS=(float)rRatioRect.right/(float)wx;
- YS=(float)rRatioRect.bottom/(float)wy;
-
- dx=(int)((float)(dx)*XS);
- dy=(int)((float)(dy)*YS);
- x=(int)((float)x*XS);
- y=(int)((float)y*YS);
-
- dx-=x;
- dy-=y;
-
- if(dx>iResX) dx=iResX;
- if(dy>iResY) dy=iResY;
-
- if(dx<=0) return;
- if(dy<=0) return;
-
- // ogl y adjust
- y=iResY-y-dy;
-
- x+=rRatioRect.left;
- y-=rRatioRect.top;
-
- if(y<0) y=0; if((y+dy)>iResY) dy=iResY-y;
-
- if(!pGfxCardScreen)
- {
- glPixelStorei(GL_PACK_ALIGNMENT,1);
- pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);
- }
-
- ps=pGfxCardScreen;
-
- if(bFront) glReadBuffer(GL_FRONT);
-
- glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps);
-
- if(bFront) glReadBuffer(GL_BACK);
-
- XS=(float)dx/(float)(udx);
- YS=(float)dy/(float)(udy+1);
-
- for(y=udy;y>0;y--)
- {
- for(x=0;x<udx;x++)
- {
- if(p>=psxVuw && p<psxVuw_eom)
- {
- px=ps+(3*((int)((float)x * XS))+
- (3*dx)*((int)((float)y*YS)));
- sx=(*px)>>3;px++;
- s=sx;
- sx=(*px)>>3;px++;
- s|=sx<<5;
- sx=(*px)>>3;
- s|=sx<<10;
- s&=~0x8000;
- *p=s;
- }
- p++;
- }
- p += 1024 - udx;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// core read from vram
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUreadDataMem(uint32_t *pMem, int iSize)
-{
- int i;
-
- if(iDataReadMode!=DR_VRAMTRANSFER) return;
-
- GPUIsBusy;
-
- // adjust read ptr, if necessary
- while(VRAMRead.ImagePtr>=psxVuw_eom)
- VRAMRead.ImagePtr-=iGPUHeight*1024;
- while(VRAMRead.ImagePtr<psxVuw)
- VRAMRead.ImagePtr+=iGPUHeight*1024;
-
- if((iFrameReadType&1 && iSize>1) &&
- !(iDrawnSomething==2 &&
- VRAMRead.x == VRAMWrite.x &&
- VRAMRead.y == VRAMWrite.y &&
- VRAMRead.Width == VRAMWrite.Width &&
- VRAMRead.Height == VRAMWrite.Height))
- CheckVRamRead(VRAMRead.x,VRAMRead.y,
- VRAMRead.x+VRAMRead.RowsRemaining,
- VRAMRead.y+VRAMRead.ColsRemaining,
- TRUE);
-
- for(i=0;i<iSize;i++)
- {
- // do 2 seperate 16bit reads for compatibility (wrap issues)
- if ((VRAMRead.ColsRemaining > 0) && (VRAMRead.RowsRemaining > 0))
- {
- // lower 16 bit
- GPUdataRet=(uint32_t)*VRAMRead.ImagePtr;
-
- VRAMRead.ImagePtr++;
- if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
- VRAMRead.RowsRemaining --;
-
- if(VRAMRead.RowsRemaining<=0)
- {
- VRAMRead.RowsRemaining = VRAMRead.Width;
- VRAMRead.ColsRemaining--;
- VRAMRead.ImagePtr += 1024 - VRAMRead.Width;
- if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
- }
-
- // higher 16 bit (always, even if it's an odd width)
- GPUdataRet|=(uint32_t)(*VRAMRead.ImagePtr)<<16;
- *pMem++=GPUdataRet;
-
- if(VRAMRead.ColsRemaining <= 0)
- {FinishedVRAMRead();goto ENDREAD;}
-
- VRAMRead.ImagePtr++;
- if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
- VRAMRead.RowsRemaining--;
- if(VRAMRead.RowsRemaining<=0)
- {
- VRAMRead.RowsRemaining = VRAMRead.Width;
- VRAMRead.ColsRemaining--;
- VRAMRead.ImagePtr += 1024 - VRAMRead.Width;
- if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
- }
- if(VRAMRead.ColsRemaining <= 0)
- {FinishedVRAMRead();goto ENDREAD;}
- }
- else {FinishedVRAMRead();goto ENDREAD;}
- }
-
-ENDREAD:
- GPUIsIdle;
-}
-
-uint32_t CALLBACK GPUreadData(void)
-{
- uint32_t l;
- GPUreadDataMem(&l,1);
- return GPUdataRet;
-}
-
-////////////////////////////////////////////////////////////////////////
-// helper table to know how much data is used by drawing commands
-////////////////////////////////////////////////////////////////////////
-
-const unsigned char primTableCX[256] =
-{
- // 00
- 0,0,3,0,0,0,0,0,
- // 08
- 0,0,0,0,0,0,0,0,
- // 10
- 0,0,0,0,0,0,0,0,
- // 18
- 0,0,0,0,0,0,0,0,
- // 20
- 4,4,4,4,7,7,7,7,
- // 28
- 5,5,5,5,9,9,9,9,
- // 30
- 6,6,6,6,9,9,9,9,
- // 38
- 8,8,8,8,12,12,12,12,
- // 40
- 3,3,3,3,0,0,0,0,
- // 48
-// 5,5,5,5,6,6,6,6, //FLINE
- 254,254,254,254,254,254,254,254,
- // 50
- 4,4,4,4,0,0,0,0,
- // 58
-// 7,7,7,7,9,9,9,9, // LINEG3 LINEG4
- 255,255,255,255,255,255,255,255,
- // 60
- 3,3,3,3,4,4,4,4, // TILE SPRT
- // 68
- 2,2,2,2,3,3,3,3, // TILE1
- // 70
- 2,2,2,2,3,3,3,3,
- // 78
- 2,2,2,2,3,3,3,3,
- // 80
- 4,0,0,0,0,0,0,0,
- // 88
- 0,0,0,0,0,0,0,0,
- // 90
- 0,0,0,0,0,0,0,0,
- // 98
- 0,0,0,0,0,0,0,0,
- // a0
- 3,0,0,0,0,0,0,0,
- // a8
- 0,0,0,0,0,0,0,0,
- // b0
- 0,0,0,0,0,0,0,0,
- // b8
- 0,0,0,0,0,0,0,0,
- // c0
- 3,0,0,0,0,0,0,0,
- // c8
- 0,0,0,0,0,0,0,0,
- // d0
- 0,0,0,0,0,0,0,0,
- // d8
- 0,0,0,0,0,0,0,0,
- // e0
- 0,1,1,1,1,1,1,0,
- // e8
- 0,0,0,0,0,0,0,0,
- // f0
- 0,0,0,0,0,0,0,0,
- // f8
- 0,0,0,0,0,0,0,0
-};
-
-////////////////////////////////////////////////////////////////////////
-// processes data send to GPU data register
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUwriteDataMem(uint32_t *pMem, int iSize)
-{
- unsigned char command;
- uint32_t gdata=0;
- int i=0;
- GPUIsBusy;
- GPUIsNotReadyForCommands;
-
-STARTVRAM:
-
- if(iDataWriteMode==DR_VRAMTRANSFER)
- {
- // make sure we are in vram
- while(VRAMWrite.ImagePtr>=psxVuw_eom)
- VRAMWrite.ImagePtr-=iGPUHeight*1024;
- while(VRAMWrite.ImagePtr<psxVuw)
- VRAMWrite.ImagePtr+=iGPUHeight*1024;
-
- // now do the loop
- while(VRAMWrite.ColsRemaining>0)
- {
- while(VRAMWrite.RowsRemaining>0)
- {
- if(i>=iSize) {goto ENDVRAM;}
- i++;
-
- gdata=*pMem++;
-
- *VRAMWrite.ImagePtr++ = (unsigned short)gdata;
- if(VRAMWrite.ImagePtr>=psxVuw_eom) VRAMWrite.ImagePtr-=iGPUHeight*1024;
- VRAMWrite.RowsRemaining --;
-
- if(VRAMWrite.RowsRemaining <= 0)
- {
- VRAMWrite.ColsRemaining--;
- if (VRAMWrite.ColsRemaining <= 0) // last pixel is odd width
- {
- gdata=(gdata&0xFFFF)|(((uint32_t)(*VRAMWrite.ImagePtr))<<16);
- FinishedVRAMWrite();
- goto ENDVRAM;
- }
- VRAMWrite.RowsRemaining = VRAMWrite.Width;
- VRAMWrite.ImagePtr += 1024 - VRAMWrite.Width;
- }
-
- *VRAMWrite.ImagePtr++ = (unsigned short)(gdata>>16);
- if(VRAMWrite.ImagePtr>=psxVuw_eom) VRAMWrite.ImagePtr-=iGPUHeight*1024;
- VRAMWrite.RowsRemaining --;
- }
-
- VRAMWrite.RowsRemaining = VRAMWrite.Width;
- VRAMWrite.ColsRemaining--;
- VRAMWrite.ImagePtr += 1024 - VRAMWrite.Width;
- }
-
- FinishedVRAMWrite();
- }
-
-ENDVRAM:
-
- if(iDataWriteMode==DR_NORMAL)
- {
- void (* *primFunc)(unsigned char *);
- if(bSkipNextFrame) primFunc=primTableSkip;
- else primFunc=primTableJ;
-
- for(;i<iSize;)
- {
- if(iDataWriteMode==DR_VRAMTRANSFER) goto STARTVRAM;
-
- gdata=*pMem++;i++;
-
- if(gpuDataC == 0)
- {
- command = (unsigned char)((gdata>>24) & 0xff);
-
- if(primTableCX[command])
- {
- gpuDataC = primTableCX[command];
- gpuCommand = command;
- gpuDataM[0] = gdata;
- gpuDataP = 1;
- }
- else continue;
- }
- else
- {
- gpuDataM[gpuDataP] = gdata;
- if(gpuDataC>128)
- {
- if((gpuDataC==254 && gpuDataP>=3) ||
- (gpuDataC==255 && gpuDataP>=4 && !(gpuDataP&1)))
- {
- if((gpuDataM[gpuDataP] & 0xF000F000) == 0x50005000)
- gpuDataP=gpuDataC-1;
- }
- }
- gpuDataP++;
- }
-
- if(gpuDataP == gpuDataC)
- {
- gpuDataC=gpuDataP=0;
- primFunc[gpuCommand]((unsigned char *)gpuDataM);
-
- if(dwEmuFixes&0x0001 || dwActFixes&0x20000) // hack for emulating "gpu busy" in some games
- iFakePrimBusy=4;
- }
- }
- }
-
- GPUdataRet=gdata;
-
- GPUIsReadyForCommands;
- GPUIsIdle;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUwriteData(uint32_t gdata)
-{
- GPUwriteDataMem(&gdata,1);
-}
-
-////////////////////////////////////////////////////////////////////////
-// call config dlg
-////////////////////////////////////////////////////////////////////////
-
-#ifdef _WINDOWS
-
-long CALLBACK GPUconfigure(void)
-{
- HWND hWP=GetActiveWindow();
- DialogBox(hInst,MAKEINTRESOURCE(IDD_CFGDLG),
- hWP,(DLGPROC)CfgDlgProc);
-
- return 0;
-}
-
-#elif defined(_MACGL)
-long CALLBACK GPUconfigure(void)
-{
- DlgProc();
- return 0;
-}
-#else
-
-void StartCfgTool(char *arg) // linux: start external cfg tool
-{
- char cfg[256];
- struct stat buf;
-
- strcpy(cfg, "./cfgpeopsxgl");
- if (stat(cfg, &buf) != -1) {
- if (fork() == 0) {
- execl(cfg, "cfgpeopsxgl", arg, NULL);
- exit(0);
- }
- return;
- }
-
- strcpy(cfg, "./cfg/cfgpeopsxgl");
- if (stat(cfg, &buf) != -1) {
- if (fork() == 0) {
- execl(cfg, "cfgpeopsxgl", arg, NULL);
- exit(0);
- }
- return;
- }
-
- sprintf(cfg, "%s/.pcsx/plugins/cfg/cfgpeopsxgl", getenv("HOME"));
- if (stat(cfg, &buf) != -1) {
- if (fork() == 0) {
- execl(cfg, "cfgpeopsxgl", arg, NULL);
- exit(0);
- }
- return;
- }
-
- printf("ERROR: cfgpeopsxgl file not found!\n");
-}
-
-long CALLBACK GPUconfigure(void)
-{
- StartCfgTool("CFG");
- return 0;
-}
-
-#endif // def _WINDOWS / _MACGL
-
-////////////////////////////////////////////////////////////////////////
-// sets all kind of act fixes
-////////////////////////////////////////////////////////////////////////
-
-void SetFixes(void)
-{
- ReInitFrameCap();
-
- if(dwActFixes & 0x2000)
- dispWidths[4]=384;
- else dispWidths[4]=368;
-}
-
-////////////////////////////////////////////////////////////////////////
-// Pete Special: make an 'intelligent' dma chain check (<-Tekken3)
-////////////////////////////////////////////////////////////////////////
-
-uint32_t lUsedAddr[3];
-
-__inline BOOL CheckForEndlessLoop(uint32_t laddr)
-{
- if(laddr==lUsedAddr[1]) return TRUE;
- if(laddr==lUsedAddr[2]) return TRUE;
-
- if(laddr<lUsedAddr[0]) lUsedAddr[1]=laddr;
- else lUsedAddr[2]=laddr;
- lUsedAddr[0]=laddr;
- return FALSE;
-}
-
-////////////////////////////////////////////////////////////////////////
-// core gives a dma chain to gpu: same as the gpuwrite interface funcs
-////////////////////////////////////////////////////////////////////////
-
-long CALLBACK GPUdmaChain(uint32_t *baseAddrL, uint32_t addr)
-{
- uint32_t dmaMem;
- unsigned char * baseAddrB;
- short count;unsigned int DMACommandCounter = 0;
-
- if(bIsFirstFrame) GLinitialize();
-
- GPUIsBusy;
-
- lUsedAddr[0]=lUsedAddr[1]=lUsedAddr[2]=0xffffff;
-
- baseAddrB = (unsigned char*) baseAddrL;
-
- do
- {
- if(iGPUHeight==512) addr&=0x1FFFFC;
-
- if(DMACommandCounter++ > 2000000) break;
- if(CheckForEndlessLoop(addr)) break;
-
- count = baseAddrB[addr+3];
-
- dmaMem=addr+4;
-
- if(count>0) GPUwriteDataMem(&baseAddrL[dmaMem>>2],count);
-
- addr = baseAddrL[addr>>2]&0xffffff;
- }
- while (addr != 0xffffff);
-
- GPUIsIdle;
-
- return 0;
-}
-
-////////////////////////////////////////////////////////////////////////
-// show about dlg
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUabout(void)
-{
-#ifdef _WINDOWS
- HWND hWP=GetActiveWindow(); // to be sure
- DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
- hWP,(DLGPROC)AboutDlgProc);
-#elif defined(_MACGL)
-
- AboutDlgProc();
-#else
-
- StartCfgTool("ABOUT");
-
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////
-// We are ever fine ;)
-////////////////////////////////////////////////////////////////////////
-
-long CALLBACK GPUtest(void)
-{
- // if test fails this function should return negative value for error (unable to continue)
- // and positive value for warning (can continue but output might be crappy)
-
- return 0;
-}
-
-////////////////////////////////////////////////////////////////////////
-// save state funcs
-////////////////////////////////////////////////////////////////////////
-
-typedef struct GPUFREEZETAG
-{
- uint32_t ulFreezeVersion; // should be always 1 for now (set by main emu)
- uint32_t ulStatus; // current gpu status
- uint32_t ulControl[256]; // latest control register values
- unsigned char psxVRam[1024*1024*2]; // current VRam image (full 2 MB for ZN)
-} GPUFreeze_t;
-
-////////////////////////////////////////////////////////////////////////
-
-long CALLBACK GPUfreeze(uint32_t ulGetFreezeData,GPUFreeze_t * pF)
-{
- if(ulGetFreezeData==2)
- {
- int lSlotNum=*((int *)pF);
- if(lSlotNum<0) return 0;
- if(lSlotNum>8) return 0;
- lSelectedSlot=lSlotNum+1;
- return 1;
- }
-
- if(!pF) return 0;
- if(pF->ulFreezeVersion!=1) return 0;
-
- if(ulGetFreezeData==1)
- {
- pF->ulStatus=STATUSREG;
- memcpy(pF->ulControl,ulStatusControl,256*sizeof(uint32_t));
- memcpy(pF->psxVRam, psxVub, 1024*iGPUHeight*2);
-
- return 1;
- }
-
- if(ulGetFreezeData!=0) return 0;
-
- STATUSREG=pF->ulStatus;
- memcpy(ulStatusControl,pF->ulControl,256*sizeof(uint32_t));
- memcpy(psxVub, pF->psxVRam, 1024*iGPUHeight*2);
-
- ResetTextureArea(TRUE);
-
- GPUwriteStatus(ulStatusControl[0]);
- GPUwriteStatus(ulStatusControl[1]);
- GPUwriteStatus(ulStatusControl[2]);
- GPUwriteStatus(ulStatusControl[3]);
- GPUwriteStatus(ulStatusControl[8]);
- GPUwriteStatus(ulStatusControl[6]);
- GPUwriteStatus(ulStatusControl[7]);
- GPUwriteStatus(ulStatusControl[5]);
- GPUwriteStatus(ulStatusControl[4]);
-
- return 1;
-}
-
-////////////////////////////////////////////////////////////////////////
-// special "emu infos" / "emu effects" functions
-////////////////////////////////////////////////////////////////////////
-
-//00 = black
-//01 = white
-//10 = red
-//11 = transparent
-
-unsigned char cFont[10][120]=
-{
-// 0
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 1
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x05,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x05,0x55,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 2
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x14,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x01,0x40,0x00,0x00,
- 0x80,0x00,0x05,0x00,0x00,0x00,
- 0x80,0x00,0x14,0x00,0x00,0x00,
- 0x80,0x00,0x15,0x55,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 3
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x01,0x54,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 4
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x14,0x00,0x00,
- 0x80,0x00,0x00,0x54,0x00,0x00,
- 0x80,0x00,0x01,0x54,0x00,0x00,
- 0x80,0x00,0x01,0x54,0x00,0x00,
- 0x80,0x00,0x05,0x14,0x00,0x00,
- 0x80,0x00,0x14,0x14,0x00,0x00,
- 0x80,0x00,0x15,0x55,0x00,0x00,
- 0x80,0x00,0x00,0x14,0x00,0x00,
- 0x80,0x00,0x00,0x14,0x00,0x00,
- 0x80,0x00,0x00,0x55,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 5
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x15,0x55,0x00,0x00,
- 0x80,0x00,0x14,0x00,0x00,0x00,
- 0x80,0x00,0x14,0x00,0x00,0x00,
- 0x80,0x00,0x14,0x00,0x00,0x00,
- 0x80,0x00,0x15,0x54,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 6
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x01,0x54,0x00,0x00,
- 0x80,0x00,0x05,0x00,0x00,0x00,
- 0x80,0x00,0x14,0x00,0x00,0x00,
- 0x80,0x00,0x14,0x00,0x00,0x00,
- 0x80,0x00,0x15,0x54,0x00,0x00,
- 0x80,0x00,0x15,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 7
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x15,0x55,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x14,0x00,0x00,
- 0x80,0x00,0x00,0x14,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x50,0x00,0x00,
- 0x80,0x00,0x01,0x40,0x00,0x00,
- 0x80,0x00,0x01,0x40,0x00,0x00,
- 0x80,0x00,0x05,0x00,0x00,0x00,
- 0x80,0x00,0x05,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 8
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-},
-// 9
-{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x05,0x54,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x05,0x00,0x00,
- 0x80,0x00,0x14,0x15,0x00,0x00,
- 0x80,0x00,0x05,0x55,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x05,0x00,0x00,
- 0x80,0x00,0x00,0x14,0x00,0x00,
- 0x80,0x00,0x05,0x50,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0x80,0x00,0x00,0x00,0x00,0x00,
- 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
-}
-};
-
-////////////////////////////////////////////////////////////////////////
-
-void PaintPicDot(unsigned char * p,unsigned char c)
-{
- if(c==0) {*p++=0x00;*p++=0x00;*p=0x00;return;}
- if(c==1) {*p++=0xff;*p++=0xff;*p=0xff;return;}
- if(c==2) {*p++=0x00;*p++=0x00;*p=0xff;return;}
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUgetScreenPic(unsigned char * pMem)
-{
- float XS,YS;int x,y,v;
- unsigned char * ps, * px, * pf;
- unsigned char c;
-
- if(!pGfxCardScreen)
- {
- glPixelStorei(GL_PACK_ALIGNMENT,1);
- pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);
- }
-
- ps=pGfxCardScreen;
-
- glReadBuffer(GL_FRONT);
-
- glReadPixels(0,0,iResX,iResY,GL_RGB,GL_UNSIGNED_BYTE,ps);
-
- glReadBuffer(GL_BACK);
-
- XS=(float)iResX/128;
- YS=(float)iResY/96;
- pf=pMem;
-
- for(y=96;y>0;y--)
- {
- for(x=0;x<128;x++)
- {
- px=ps+(3*((int)((float)x * XS))+
- (3*iResX)*((int)((float)y*YS)));
- *(pf+0)=*(px+2);
- *(pf+1)=*(px+1);
- *(pf+2)=*(px+0);
- pf+=3;
- }
- }
-
- /////////////////////////////////////////////////////////////////////
- // generic number/border painter
-
- pf=pMem+(103*3);
-
- for(y=0;y<20;y++)
- {
- for(x=0;x<6;x++)
- {
- c=cFont[lSelectedSlot][x+y*6];
- v=(c&0xc0)>>6;
- PaintPicDot(pf,(unsigned char)v);pf+=3; // paint the dots into the rect
- v=(c&0x30)>>4;
- PaintPicDot(pf,(unsigned char)v);pf+=3;
- v=(c&0x0c)>>2;
- PaintPicDot(pf,(unsigned char)v);pf+=3;
- v=c&0x03;
- PaintPicDot(pf,(unsigned char)v);pf+=3;
- }
- pf+=104*3;
- }
-
- pf=pMem;
- for(x=0;x<128;x++)
- {
- *(pf+(95*128*3))=0x00;*pf++=0x00;
- *(pf+(95*128*3))=0x00;*pf++=0x00;
- *(pf+(95*128*3))=0xff;*pf++=0xff;
- }
- pf=pMem;
- for(y=0;y<96;y++)
- {
- *(pf+(127*3))=0x00;*pf++=0x00;
- *(pf+(127*3))=0x00;*pf++=0x00;
- *(pf+(127*3))=0xff;*pf++=0xff;
- pf+=127*3;
- }
-
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUshowScreenPic(unsigned char * pMem)
-{
- DestroyPic();
- if(pMem==0) return;
- CreatePic(pMem);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUsetfix(uint32_t dwFixBits)
-{
- dwEmuFixes=dwFixBits;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUvisualVibration(uint32_t iSmall, uint32_t iBig)
-{
- int iVibVal;
-
- if(PSXDisplay.DisplayModeNew.x) // calc min "shake pixel" from screen width
- iVibVal=max(1,iResX/PSXDisplay.DisplayModeNew.x);
- else iVibVal=1;
- // big rumble: 4...15 sp ; small rumble 1...3 sp
- if(iBig) iRumbleVal=max(4*iVibVal,min(15*iVibVal,((int)iBig *iVibVal)/10));
- else iRumbleVal=max(1*iVibVal,min( 3*iVibVal,((int)iSmall*iVibVal)/10));
-
- srand(timeGetTime()); // init rand (will be used in BufferSwap)
-
- iRumbleTime=15; // let the rumble last 16 buffer swaps
-}
-
-////////////////////////////////////////////////////////////////////////
-// main emu can set display infos (A/M/G/D)
-////////////////////////////////////////////////////////////////////////
-
-void CALLBACK GPUdisplayFlags(uint32_t dwFlags)
-{
- dwCoreFlags=dwFlags;
-}
-
-void CALLBACK GPUvBlank( int val )
-{
- vBlank = val;
-}
+/***************************************************************************
+ gpu.c - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ email : BlackDove@addcom.de
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+// !!! enable this, if Linux XF86VidMode is not supported:
+//#define NOVMODE
+
+#include "stdafx.h"
+
+#if !defined(_MACGL) && !defined(_WINDOWS)
+
+#include "config.h"
+
+#ifndef NOVMODE
+#include <X11/extensions/xf86vmode.h>
+static XF86VidModeModeInfo **modes=0;
+static int iOldMode=0;
+#endif
+
+#endif
+
+#define _IN_GPU
+
+#include "externals.h"
+#include "psemu_plugin_defs.h"
+#include "gpu.h"
+#include "draw.h"
+#include "cfg.h"
+#include "prim.h"
+#include "psemu_plugin_defs.h"
+#include "texture.h"
+#include "menu.h"
+#include "fps.h"
+#include "key.h"
+#ifdef _WINDOWS
+#include "resource.h"
+#include "ssave.h"
+#endif
+
+////////////////////////////////////////////////////////////////////////
+// PPDK developer must change libraryName field and can change revision and build
+////////////////////////////////////////////////////////////////////////
+
+const unsigned char version = 1; // do not touch - library for PSEmu 1.x
+const unsigned char revision = 1;
+const unsigned char build = 78;
+
+static char *libraryName = N_("OpenGL Driver");
+
+static char *PluginAuthor = N_("Pete Bernert");
+#if 0
+static char *libraryInfo = N_("Based on P.E.Op.S. MesaGL Driver V1.78\nCoded by Pete Bernert\n");
+#endif
+
+////////////////////////////////////////////////////////////////////////
+// memory image of the PSX vram
+////////////////////////////////////////////////////////////////////////
+
+unsigned char *psxVSecure;
+unsigned char *psxVub;
+signed char *psxVsb;
+unsigned short *psxVuw;
+unsigned short *psxVuw_eom;
+signed short *psxVsw;
+uint32_t *psxVul;
+signed int *psxVsl;
+
+// macro for easy access to packet information
+#define GPUCOMMAND(x) ((x>>24) & 0xff)
+
+GLfloat gl_z=0.0f;
+BOOL bNeedInterlaceUpdate=FALSE;
+BOOL bNeedRGB24Update=FALSE;
+BOOL bChangeWinMode=FALSE;
+
+uint32_t ulStatusControl[256];
+
+////////////////////////////////////////////////////////////////////////
+// global GPU vars
+////////////////////////////////////////////////////////////////////////
+
+static int GPUdataRet;
+int lGPUstatusRet;
+char szDispBuf[64];
+
+uint32_t dwGPUVersion = 0;
+int iGPUHeight = 512;
+int iGPUHeightMask = 511;
+int GlobalTextIL = 0;
+int iTileCheat = 0;
+
+static uint32_t gpuDataM[256];
+static unsigned char gpuCommand = 0;
+static int gpuDataC = 0;
+static int gpuDataP = 0;
+
+VRAMLoad_t VRAMWrite;
+VRAMLoad_t VRAMRead;
+int iDataWriteMode;
+int iDataReadMode;
+
+int lClearOnSwap;
+int lClearOnSwapColor;
+BOOL bSkipNextFrame = FALSE;
+int iColDepth;
+BOOL bChangeRes;
+BOOL bWindowMode;
+int iWinSize;
+
+// possible psx display widths
+short dispWidths[8] = {256,320,512,640,368,384,512,640};
+
+PSXDisplay_t PSXDisplay;
+PSXDisplay_t PreviousPSXDisplay;
+TWin_t TWin;
+short imageX0,imageX1;
+short imageY0,imageY1;
+BOOL bDisplayNotSet = TRUE;
+GLuint uiScanLine=0;
+int iUseScanLines=0;
+float iScanlineColor[] = {0,0,0, 0.3}; // easy on the eyes.
+int lSelectedSlot=0;
+unsigned char * pGfxCardScreen=0;
+int iBlurBuffer=0;
+int iScanBlend=0;
+int iRenderFVR=0;
+int iNoScreenSaver=0;
+uint32_t ulGPUInfoVals[16];
+int iFakePrimBusy = 0;
+int iRumbleVal = 0;
+int iRumbleTime = 0;
+uint32_t vBlank=0;
+
+////////////////////////////////////////////////////////////////////////
+// stuff to make this a true PDK module
+////////////////////////////////////////////////////////////////////////
+
+char * CALLBACK PSEgetLibName(void)
+{
+ return _(libraryName);
+}
+
+unsigned long CALLBACK PSEgetLibType(void)
+{
+ return PSE_LT_GPU;
+}
+
+unsigned long CALLBACK PSEgetLibVersion(void)
+{
+ return version<<16|revision<<8|build;
+}
+
+#if 0
+char * GPUgetLibInfos(void)
+{
+ return _(libraryInfo);
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////
+// snapshot funcs (saves screen to bitmap / text infos into file)
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+static char * GetConfigInfos(HWND hW)
+#else
+static char * GetConfigInfos(int hW)
+#endif
+{
+#ifdef _WINDOWS
+ HDC hdc;HGLRC hglrc;
+#endif
+ char szO[2][4]={"off","on "};
+ char szTxt[256];
+ char * pB=(char *)malloc(32767);
+
+ if(!pB) return NULL;
+ *pB=0;
+ //----------------------------------------------------//
+ sprintf(szTxt,"Plugin: %s %d.%d.%d (mod)\r\n",libraryName,version,revision,build);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"Author: %s\r\n",PluginAuthor);
+ strcat(pB,szTxt);
+
+#ifdef _WINDOWS
+ if(hW)
+ {
+ hdc = GetDC(hW);
+ bSetupPixelFormat(hdc);
+ hglrc = wglCreateContext(hdc);
+ wglMakeCurrent(hdc, hglrc);
+ }
+#endif
+
+ sprintf(szTxt,"Card vendor: %s\r\n",(char *)glGetString(GL_VENDOR));
+ strcat(pB,szTxt);
+ sprintf(szTxt,"GFX card: %s\r\n",(char *)glGetString(GL_RENDERER));
+ strcat(pB,szTxt);
+ sprintf(szTxt,"OGL version: %s\r\n\r\n",(char *)glGetString(GL_VERSION));
+ strcat(pB,szTxt);
+ //strcat(pB,(char *)glGetString(GL_EXTENSIONS));
+ //strcat(pB,"\r\n\r\n");
+
+#ifdef _WINDOWS
+ if(hW)
+ {
+ wglMakeCurrent(NULL, NULL);
+ wglDeleteContext(hglrc);
+ ReleaseDC(hW,hdc);
+ }
+ //----------------------------------------------------//
+#endif
+
+ if(hW && bWindowMode)
+ sprintf(szTxt,"Resolution/Color:\r\n- %dx%d ",LOWORD(iWinSize),HIWORD(iWinSize));
+ else
+ sprintf(szTxt,"Resolution/Color:\r\n- %dx%d ",iResX,iResY);
+ strcat(pB,szTxt);
+ if(bWindowMode) sprintf(szTxt,"Window mode\r\n");
+ else
+ {
+ sprintf(szTxt,"Fullscreen ");
+ strcat(pB,szTxt);
+ if(bChangeRes) sprintf(szTxt,"- Desktop changing [%d Bit]\r\n",iColDepth);
+ else sprintf(szTxt,"- NO desktop changing\r\n");
+ }
+ strcat(pB,szTxt);
+
+ if(iForceVSync>=0) sprintf(szTxt,"- V-Sync: %s\r\n",szO[iForceVSync]);
+ else strcpy(szTxt,"- V-Sync: Driver\r\n");
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Keep psx aspect ratio: %s\r\n\r\n",szO[bKeepRatio]);
+ strcat(pB,szTxt);
+ //----------------------------------------------------//
+ strcpy(szTxt,"Textures:\r\n- ");
+ if(iTexQuality==0) strcat(szTxt,"Default");
+ else if(iTexQuality==1) strcat(szTxt,"R4G4B4A4");
+ else if(iTexQuality==2) strcat(szTxt,"R5G5B5A1");
+ else if(iTexQuality==3) strcat(szTxt,"R8G8A8A8");
+ else if(iTexQuality==4) strcat(szTxt,"B8G8R8A8");
+ if(!hW && bGLExt) strcat(szTxt," (packed pixels)\r\n");
+ else strcat(szTxt,"\r\n");
+ strcat(pB,szTxt);
+ if(!hW)
+ {
+ sprintf(szTxt,"- Filtering: %d - edge clamping ",iFilterType);
+ if(iClampType==GL_TO_EDGE_CLAMP) strcat(szTxt,"supported\r\n");
+ else strcat(szTxt,"NOT supported\r\n");
+ }
+ else sprintf(szTxt,"- iFiltering: %d\r\n",iFilterType);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Hi-Res textures: %d\r\n",iHiResTextures);
+ strcat(pB,szTxt);
+ if(!hW)
+ {
+ sprintf(szTxt,"- Palettized tex windows: %s\r\n",szO[iUsePalTextures]);
+ strcat(pB,szTxt);
+ }
+ sprintf(szTxt,"- VRam size: %d MBytes",iVRamSize);
+ if(!hW)
+ sprintf(szTxt+strlen(szTxt)," - %d textures usable\r\n\r\n",iSortTexCnt);
+ else strcat(szTxt,"\r\n\r\n");
+ strcat(pB,szTxt);
+ //----------------------------------------------------//
+ sprintf(szTxt,"Framerate:\r\n- FPS limitation: %s\r\n",szO[bUseFrameLimit]);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Frame skipping: %s\r\n",szO[bUseFrameSkip]);
+ strcat(pB,szTxt);
+ if(iFrameLimit==2)
+ strcpy(szTxt,"- FPS limit: Auto\r\n\r\n");
+ else sprintf(szTxt,"- FPS limit: %.1f\r\n\r\n",fFrameRate);
+ strcat(pB,szTxt);
+ //----------------------------------------------------//
+ sprintf(szTxt,"Compatibility:\r\n- Offscreen drawing: %d\r\n",iOffscreenDrawing);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Framebuffer texture: %d",iFrameTexType);
+ if(!hW && iFrameTexType==2)
+ {
+ if(gTexFrameName) strcat(szTxt," - texture created\r\n");
+ else strcat(szTxt," - not used yet\r\n");
+ }
+ else strcat(szTxt,"\r\n");
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Framebuffer access: %d\r\n",iFrameReadType);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Alpha multipass: %s\r\n",szO[bOpaquePass]);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Mask bit: %s\r\n",szO[iUseMask]);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Advanced blending: %s",szO[bAdvancedBlend]);
+ if(!hW && bAdvancedBlend)
+ {
+ if(bGLBlend) strcat(szTxt," (hardware)\r\n");
+ else strcat(szTxt," (software)\r\n");
+ }
+ else strcat(szTxt,"\r\n");
+ strcat(pB,szTxt);
+
+ if(!hW)
+ {
+ strcpy(szTxt,"- Subtractive blending: ");
+ if(glBlendEquationEXTEx)
+ {
+ if(bUseMultiPass) strcat(szTxt,"supported, but not used!");
+ else strcat(szTxt,"activated");
+ }
+ else strcat(szTxt," NOT supported!");
+ strcat(szTxt,"\r\n\r\n");
+ }
+ else strcpy(szTxt,"\r\n");
+
+ strcat(pB,szTxt);
+ //----------------------------------------------------//
+ sprintf(szTxt,"Misc:\r\n- Scanlines: %s",szO[iUseScanLines]);
+ strcat(pB,szTxt);
+ if(iUseScanLines) sprintf(szTxt," [%d]\r\n",iScanBlend);
+ else strcpy(szTxt,"\r\n");
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Line mode: %s\r\n",szO[bUseLines]);
+ strcat(pB,szTxt);
+// sprintf(szTxt,"- Line AA: %s\r\n",szO[bUseAntiAlias]);
+// fwrite(szTxt,lstrlen(szTxt),1,txtfile);
+ sprintf(szTxt,"- Unfiltered FB: %s\r\n",szO[bUseFastMdec]);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- 15 bit FB: %s\r\n",szO[bUse15bitMdec]);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Dithering: %s\r\n",szO[bDrawDither]);
+ strcat(pB,szTxt);
+ sprintf(szTxt,"- Screen smoothing: %s",szO[iBlurBuffer]);
+ strcat(pB,szTxt);
+ if(!hW && iBlurBuffer)
+ {
+ if(gTexBlurName) strcat(pB," - supported\r\n");
+ else strcat(pB," - not supported\r\n");
+ }
+ else strcat(pB,"\r\n");
+ sprintf(szTxt,"- Game fixes: %s [%08x]\r\n",szO[bUseFixes],dwCfgFixes);
+ strcat(pB,szTxt);
+ //----------------------------------------------------//
+ return pB;
+}
+
+////////////////////////////////////////////////////////////////////////
+// save text infos to file
+////////////////////////////////////////////////////////////////////////
+
+static void DoTextSnapShot(int iNum)
+{
+ FILE *txtfile;char szTxt[256];char * pB;
+
+#ifdef _WINDOWS
+ sprintf(szTxt,"snap\\pcsx%04d.txt",iNum);
+#else
+ sprintf(szTxt,"%s/pcsx%04d.txt",getenv("HOME"),iNum);
+#endif
+
+ if((txtfile=fopen(szTxt,"wb"))==NULL)
+ return;
+
+ pB=GetConfigInfos(0);
+ if(pB)
+ {
+ if(fwrite(pB,strlen(pB),1,txtfile) != 1) {
+ free(pB);
+ fclose(txtfile);
+ remove(szTxt);
+ return;
+ }
+ free(pB);
+ }
+ fclose(txtfile);
+}
+
+////////////////////////////////////////////////////////////////////////
+// saves screen bitmap to file
+////////////////////////////////////////////////////////////////////////
+
+void DoSnapShot(void)
+{
+ unsigned char * snapshotdumpmem=NULL,* p,c;
+ FILE *bmpfile;char filename[256];
+ unsigned char header[0x36];int size;
+ unsigned char empty[2]={0,0};int i;
+ unsigned int snapshotnr = 0;
+ short SnapWidth;
+ short SnapHeigth;
+
+ bSnapShot=FALSE;
+
+ SnapWidth = iResX;
+ SnapHeigth = iResY;
+
+ size=SnapWidth * SnapHeigth * 3 + 0x38;
+
+ if((snapshotdumpmem=(unsigned char *)
+ malloc(SnapWidth*SnapHeigth*3))==NULL)
+ return;
+
+ // fill in proper values for BMP
+ for(i=0;i<0x36;i++) header[i]=0;
+ header[0]='B';
+ header[1]='M';
+ header[2]=(unsigned char)(size&0xff);
+ header[3]=(unsigned char)((size>>8)&0xff);
+ header[4]=(unsigned char)((size>>16)&0xff);
+ header[5]=(unsigned char)((size>>24)&0xff);
+ header[0x0a]=0x36;
+ header[0x0e]=0x28;
+ header[0x12]=(unsigned char)(SnapWidth%256);
+ header[0x13]=(unsigned char)(SnapWidth/256);
+ header[0x16]=(unsigned char)(SnapHeigth%256);
+ header[0x17]=(unsigned char)(SnapHeigth/256);
+ header[0x1a]=0x01;
+ header[0x1c]=0x18;
+ header[0x26]=0x12;
+ header[0x27]=0x0B;
+ header[0x2A]=0x12;
+ header[0x2B]=0x0B;
+
+ // increment snapshot value
+ // get filename
+ do
+ {
+ snapshotnr++;
+#ifdef _WINDOWS
+ sprintf(filename,"snap/pcsx%04d.bmp",snapshotnr);
+#else
+ sprintf(filename,"%s/pcsx%04d.bmp",getenv("HOME"),snapshotnr);
+#endif
+ bmpfile=fopen(filename,"rb");
+ if(bmpfile==NULL)break;
+ fclose(bmpfile);
+ if(snapshotnr==9999) break;
+ }
+ while(TRUE);
+
+ // try opening new snapshot file
+ if((bmpfile=fopen(filename,"wb"))==NULL)
+ {free(snapshotdumpmem);return;}
+
+ if(fwrite(header,0x36,1,bmpfile) != 1) {
+ free(snapshotdumpmem);
+ fclose(bmpfile);
+ remove(filename);
+ return;
+ }
+
+ glReadPixels(0,0,SnapWidth,SnapHeigth,GL_RGB,
+ GL_UNSIGNED_BYTE,snapshotdumpmem);
+ p=snapshotdumpmem;
+ size=SnapWidth * SnapHeigth;
+
+ for(i=0;i<size;i++,p+=3)
+ {c=*p;*p=*(p+2);*(p+2)=c;}
+
+ if(fwrite(snapshotdumpmem,size*3,1,bmpfile) != 1 ||
+ fwrite(empty,0x2,1,bmpfile) != 1) {
+ free(snapshotdumpmem);
+ fclose(bmpfile);
+ remove(filename);
+ return;
+ }
+ fclose(bmpfile);
+ free(snapshotdumpmem);
+
+ DoTextSnapShot(snapshotnr);
+#ifdef _WINDOWS
+ MessageBeep((UINT)-1);
+#endif
+}
+
+void CALLBACK GPUmakeSnapshot(void)
+{
+ bSnapShot = TRUE;
+}
+
+////////////////////////////////////////////////////////////////////////
+// GPU INIT... here starts it all (first func called by emu)
+////////////////////////////////////////////////////////////////////////
+
+long CALLBACK GPUinit()
+{
+ memset(ulStatusControl,0,256*sizeof(uint32_t));
+
+ // different ways of accessing PSX VRAM
+
+ psxVSecure=(unsigned char *)malloc((iGPUHeight*2)*1024 + (1024*1024)); // always alloc one extra MB for soft drawing funcs security
+ if(!psxVSecure) return -1;
+
+ psxVub=psxVSecure+512*1024; // security offset into double sized psx vram!
+ psxVsb=(signed char *)psxVub;
+ psxVsw=(signed short *)psxVub;
+ psxVsl=(signed int *)psxVub;
+ psxVuw=(unsigned short *)psxVub;
+ psxVul=(uint32_t *)psxVub;
+
+ psxVuw_eom=psxVuw+1024*iGPUHeight; // pre-calc of end of vram
+
+ memset(psxVSecure,0x00,(iGPUHeight*2)*1024 + (1024*1024));
+ memset(ulGPUInfoVals,0x00,16*sizeof(uint32_t));
+
+ InitFrameCap(); // init frame rate stuff
+
+ PSXDisplay.RGB24 = 0; // init vars
+ PreviousPSXDisplay.RGB24= 0;
+ PSXDisplay.Interlaced = 0;
+ PSXDisplay.InterlacedTest=0;
+ PSXDisplay.DrawOffset.x = 0;
+ PSXDisplay.DrawOffset.y = 0;
+ PSXDisplay.DrawArea.x0 = 0;
+ PSXDisplay.DrawArea.y0 = 0;
+ PSXDisplay.DrawArea.x1 = 320;
+ PSXDisplay.DrawArea.y1 = 240;
+ PSXDisplay.DisplayMode.x= 320;
+ PSXDisplay.DisplayMode.y= 240;
+ PSXDisplay.Disabled = FALSE;
+ PreviousPSXDisplay.Range.x0 =0;
+ PreviousPSXDisplay.Range.x1 =0;
+ PreviousPSXDisplay.Range.y0 =0;
+ PreviousPSXDisplay.Range.y1 =0;
+ PSXDisplay.Range.x0=0;
+ PSXDisplay.Range.x1=0;
+ PSXDisplay.Range.y0=0;
+ PSXDisplay.Range.y1=0;
+ PreviousPSXDisplay.DisplayPosition.x = 1;
+ PreviousPSXDisplay.DisplayPosition.y = 1;
+ PSXDisplay.DisplayPosition.x = 1;
+ PSXDisplay.DisplayPosition.y = 1;
+ PreviousPSXDisplay.DisplayModeNew.y=0;
+ PSXDisplay.Double=1;
+ GPUdataRet=0x400;
+
+ PSXDisplay.DisplayModeNew.x=0;
+ PSXDisplay.DisplayModeNew.y=0;
+
+ //PreviousPSXDisplay.Height = PSXDisplay.Height = 239;
+
+ iDataWriteMode = DR_NORMAL;
+
+ // Reset transfer values, to prevent mis-transfer of data
+ memset(&VRAMWrite,0,sizeof(VRAMLoad_t));
+ memset(&VRAMRead,0,sizeof(VRAMLoad_t));
+
+ // device initialised already !
+ //lGPUstatusRet = 0x74000000;
+ vBlank = 0;
+
+ STATUSREG = 0x14802000;
+ GPUIsIdle;
+ GPUIsReadyForCommands;
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////
+// GPU OPEN: funcs to open up the gpu display (Windows)
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+
+void ChangeDesktop() // change destop resolution
+{
+ DEVMODE dv;long lRes,iTry=0;
+
+ while(iTry<10) // keep on hammering...
+ {
+ memset(&dv,0,sizeof(DEVMODE));
+ dv.dmSize=sizeof(DEVMODE);
+ dv.dmBitsPerPel=iColDepth;
+ dv.dmPelsWidth=iResX;
+ dv.dmPelsHeight=iResY;
+
+ dv.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
+
+ lRes=ChangeDisplaySettings(&dv,0); // ...hammering the anvil
+
+ if(lRes==DISP_CHANGE_SUCCESSFUL) return;
+ iTry++;Sleep(10);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// OPEN interface func: attention!
+// some emus are calling this func in their main Window thread,
+// but all other interface funcs (to draw stuff) in a different thread!
+// that's a problem, since OGL is thread safe! Therefore we cannot
+// initialize the OGL stuff right here, we simply set a "bIsFirstFrame = TRUE"
+// flag, to initialize OGL on the first real draw call.
+// btw, we also call this open func ourselfes, each time when the user
+// is changing between fullscreen/window mode (ENTER key)
+// btw part 2: in windows the plugin gets the window handle from the
+// main emu, and doesn't create it's own window (if it would do it,
+// some PAD or SPU plugins would not work anymore)
+////////////////////////////////////////////////////////////////////////
+
+HMENU hPSEMenu=NULL;
+
+long CALLBACK GPUopen(HWND hwndGPU)
+{
+ HDC hdc;RECT r;DEVMODE dv;
+
+ hWWindow = hwndGPU; // store hwnd globally
+
+ InitKeyHandler(); // init key handler (subclass window)
+
+ if(bChangeWinMode) // user wants to change fullscreen/window mode?
+ {
+ ReadWinSizeConfig(); // -> get sizes again
+ }
+ else // first real startup
+ {
+ ReadConfig(); // -> read config from registry
+
+ SetFrameRateConfig(); // -> setup frame rate stuff
+ }
+
+ if(iNoScreenSaver) EnableScreenSaver(FALSE); // at least we can try
+
+
+ memset(&dv,0,sizeof(DEVMODE));
+ dv.dmSize=sizeof(DEVMODE);
+ EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dv);
+
+ bIsFirstFrame = TRUE; // flag: we have to init OGL later in windows!
+
+ if(bWindowMode) // win mode?
+ {
+ DWORD dw=GetWindowLong(hWWindow, GWL_STYLE); // -> adjust wnd style (owndc needed by some stupid ogl drivers)
+ dw&=~WS_THICKFRAME;
+ dw|=WS_BORDER|WS_CAPTION|CS_OWNDC;
+ SetWindowLong(hWWindow, GWL_STYLE, dw);
+
+ hPSEMenu=GetMenu(hWWindow); // -> hide emu menu (if any)
+ if(hPSEMenu!=NULL) SetMenu(hWWindow,NULL);
+
+ iResX=LOWORD(iWinSize);iResY=HIWORD(iWinSize);
+ ShowWindow(hWWindow,SW_SHOWNORMAL);
+
+ MoveWindow(hWWindow, // -> center wnd
+ GetSystemMetrics(SM_CXFULLSCREEN)/2-iResX/2,
+ GetSystemMetrics(SM_CYFULLSCREEN)/2-iResY/2,
+ iResX+GetSystemMetrics(SM_CXFIXEDFRAME)+3,
+ iResY+GetSystemMetrics(SM_CYFIXEDFRAME)+GetSystemMetrics(SM_CYCAPTION)+3,
+ TRUE);
+ UpdateWindow(hWWindow); // -> let windows do some update
+
+ if(dv.dmBitsPerPel==16 || dv.dmBitsPerPel==32) // -> overwrite user color info with desktop color info
+ iColDepth=dv.dmBitsPerPel;
+ }
+ else // fullscreen mode:
+ {
+ if(dv.dmBitsPerPel!=(unsigned int)iColDepth || // -> check, if we have to change resolution
+ dv.dmPelsWidth !=(unsigned int)iResX ||
+ dv.dmPelsHeight!=(unsigned int)iResY)
+ bChangeRes=TRUE; else bChangeRes=FALSE;
+
+ if(bChangeRes) ChangeDesktop(); // -> change the res (had to do an own func because of some MS 'optimizations')
+
+ SetWindowLong(hWWindow, GWL_STYLE, CS_OWNDC); // -> adjust wnd style as well (to be sure)
+
+ hPSEMenu=GetMenu(hWWindow); // -> hide menu
+ if(hPSEMenu!=NULL) SetMenu(hWWindow,NULL);
+ ShowWindow(hWWindow,SW_SHOWMAXIMIZED); // -> max mode
+ }
+
+ rRatioRect.left = rRatioRect.top=0;
+ rRatioRect.right = iResX;
+ rRatioRect.bottom = iResY;
+
+ r.left=r.top=0;r.right=iResX;r.bottom=iResY; // hack for getting a clean black window until OGL gets initialized
+ hdc = GetDC(hWWindow);
+ FillRect(hdc,&r,(HBRUSH)GetStockObject(BLACK_BRUSH));
+ bSetupPixelFormat(hdc);
+ ReleaseDC(hWWindow,hdc);
+
+ bDisplayNotSet = TRUE;
+ bSetClip=TRUE;
+
+ SetFixes(); // setup game fixes
+
+ InitializeTextureStore(); // init texture mem
+
+// lGPUstatusRet = 0x74000000;
+
+// with some emus, we could do the OGL init right here... oh my
+// if(bIsFirstFrame) GLinitialize();
+
+ return 0;
+}
+
+#elif !defined (_MACGL)
+
+////////////////////////////////////////////////////////////////////////
+// LINUX GPU OPEN: func to open up the gpu display (X stuff)
+// please note: in linux we are creating our own display, and we return
+// the display ID to the main emu... that's cleaner
+////////////////////////////////////////////////////////////////////////
+
+char * pCaptionText=0;
+int bFullScreen=0;
+Display *display;
+
+static Cursor cursor;
+static XVisualInfo *myvisual;
+static Colormap colormap;
+static Window window;
+
+static int bModeChanged=0;
+
+typedef struct
+{
+#define MWM_HINTS_DECORATIONS 2
+ long flags;
+ long functions;
+ long decorations;
+ long input_mode;
+} MotifWmHints;
+
+static int dbdepat[]={GLX_RGBA,GLX_DOUBLEBUFFER,GLX_DEPTH_SIZE,16,None};
+static int dbnodepat[]={GLX_RGBA,GLX_DOUBLEBUFFER,None};
+static GLXContext cx;
+
+static int fx=0;
+
+////////////////////////////////////////////////////////////////////////
+
+static void osd_close_display (void) // close display
+{
+ if(display) // display exists?
+ {
+ glXDestroyContext(display,cx); // -> kill context
+ XFreeColormap(display, colormap); // -> kill colormap
+ XSync(display,False); // -> sync events
+
+#ifndef NOVMODE
+ if(bModeChanged) // -> repair screen mode
+ {
+ int myscreen=DefaultScreen(display);
+ XF86VidModeSwitchToMode(display,myscreen, // --> switch mode back
+ modes[iOldMode]);
+ XF86VidModeSetViewPort(display,myscreen,0,0); // --> set viewport upperleft
+ free(modes); // --> finally kill mode infos
+ bModeChanged=0; // --> done
+ }
+#endif
+
+ XCloseDisplay(display); // -> close display
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void sysdep_create_display(void) // create display
+{
+ XSetWindowAttributes winattr;float fxgamma=2;
+ int myscreen;char gammastr[14];
+ Screen * screen;XEvent event;
+ XSizeHints hints;XWMHints wm_hints;
+ MotifWmHints mwmhints;Atom mwmatom;Atom delwindow;
+ char *glxfx;
+
+ glxfx=getenv("MESA_GLX_FX"); // 3dfx mesa fullscreen flag
+ if(glxfx)
+ {
+ if(glxfx[0]=='f') // -> yup, fullscreen needed
+ {
+ fx=1; // -> raise flag
+ putenv("FX_GLIDE_NO_SPLASH=");
+ sprintf(gammastr,"SST_GAMMA=%2.1f",fxgamma); // -> set gamma
+ putenv(gammastr);
+ }
+ }
+
+ display=XOpenDisplay(NULL); // open display
+ if(!display) // no display?
+ {
+ fprintf (stderr,"Failed to open display!!!\n");
+ osd_close_display();
+ return; // -> bye
+ }
+
+ myscreen=DefaultScreen(display); // get screen id
+
+#ifdef NOVMODE
+ if(bFullScreen) {fx=1;bModeChanged=0;}
+#else
+ if(bFullScreen)
+ {
+ XF86VidModeModeLine mode;
+ int nmodes,iC;
+ fx=1; // raise flag
+ XF86VidModeGetModeLine(display,myscreen,&iC,&mode); // get actual mode info
+ if(mode.privsize) XFree(mode.private); // no need for private stuff
+ bModeChanged=0; // init mode change flag
+ if(iResX!=mode.hdisplay || iResY!=mode.vdisplay) // wanted mode is different?
+ {
+ XF86VidModeGetAllModeLines(display,myscreen, // -> enum all mode infos
+ &nmodes,&modes);
+ if(modes) // -> infos got?
+ {
+ for(iC=0;iC<nmodes;++iC) // -> loop modes
+ {
+ if(mode.hdisplay==modes[iC]->hdisplay && // -> act mode found?
+ mode.vdisplay==modes[iC]->vdisplay) // if yes: store mode id
+ iOldMode=iC;
+
+ if(iResX==modes[iC]->hdisplay && // -> wanted mode found?
+ iResY==modes[iC]->vdisplay)
+ {
+ XF86VidModeSwitchToMode(display,myscreen, // --> switch to mode
+ modes[iC]);
+ XF86VidModeSetViewPort(display,myscreen,0,0);
+ bModeChanged=1; // --> raise flag for repairing mode on close
+ }
+ }
+
+ if(bModeChanged==0) // -> no mode found?
+ {
+ free(modes); // --> free infos
+ printf("No proper fullscreen mode found!\n"); // --> some info output
+ }
+ }
+ }
+ }
+#endif
+
+ screen=DefaultScreenOfDisplay(display);
+
+ if(iZBufferDepth) // visual (with or without zbuffer)
+ myvisual=glXChooseVisual(display,myscreen,dbdepat);
+ else myvisual=glXChooseVisual(display,myscreen,dbnodepat);
+
+ if(!myvisual) // no visual?
+ {
+ fprintf(stderr,"Failed to obtain visual!!!\n"); // -> bye
+ osd_close_display();
+ return;
+ }
+
+ cx=glXCreateContext(display,myvisual,0,GL_TRUE); // create rendering context
+
+ if(!cx) // no context?
+ {
+ fprintf(stderr,"Failed to create OpenGL context!!!\n");
+ osd_close_display(); // -> bxe
+ return;
+ }
+
+ // pffff... much work for a simple blank cursor... oh, well...
+ if(!bFullScreen) cursor=XCreateFontCursor(display,XC_trek);
+ else
+ {
+ Pixmap p1,p2;XImage * img;
+ XColor b,w;unsigned char * idata;
+ XGCValues GCv;
+ GC GCc;
+
+ memset(&b,0,sizeof(XColor));
+ memset(&w,0,sizeof(XColor));
+ idata=(unsigned char *)malloc(8);
+ memset(idata,0,8);
+
+ p1=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
+ p2=XCreatePixmap(display,RootWindow(display,myvisual->screen),8,8,1);
+
+ img = XCreateImage(display,myvisual->visual,
+ 1,XYBitmap,0,(char *)idata,8,8,8,1);
+
+ GCv.function = GXcopy;
+ GCv.foreground = ~0;
+ GCv.background = 0;
+ GCv.plane_mask = AllPlanes;
+ GCc = XCreateGC(display,p1,
+ (GCFunction|GCForeground|GCBackground|GCPlaneMask),&GCv);
+
+ XPutImage(display, p1,GCc,img,0,0,0,0,8,8);
+ XPutImage(display, p2,GCc,img,0,0,0,0,8,8);
+ XFreeGC(display, GCc);
+
+ cursor = XCreatePixmapCursor(display,p1,p2,&b,&w,0,0);
+
+ XFreePixmap(display,p1);
+ XFreePixmap(display,p2);
+ XDestroyImage(img); // will free idata as well
+ }
+
+ colormap=XCreateColormap(display, // create colormap
+ RootWindow(display,myvisual->screen),
+ myvisual->visual,AllocNone);
+
+ winattr.background_pixel=0;
+ winattr.border_pixel=WhitePixelOfScreen(screen);
+ winattr.bit_gravity=ForgetGravity;
+ winattr.win_gravity=NorthWestGravity;
+ winattr.backing_store=NotUseful;
+ winattr.override_redirect=False;
+ winattr.save_under=False;
+ winattr.event_mask=0;
+ winattr.do_not_propagate_mask=0;
+ winattr.colormap=colormap;
+ winattr.cursor=None;
+
+ window=XCreateWindow(display, // create own window
+ RootWindow(display,DefaultScreen(display)),
+ 0,0,iResX,iResY,
+ 0,myvisual->depth,
+ InputOutput,myvisual->visual,
+ CWBorderPixel | CWBackPixel |
+ CWEventMask | CWDontPropagate |
+ CWColormap | CWCursor,
+ &winattr);
+
+ if(!window) // no window?
+ {
+ fprintf(stderr,"Failed in XCreateWindow()!!!\n");
+ osd_close_display(); // -> bye
+ return;
+ }
+
+ delwindow = XInternAtom(display,"WM_DELETE_WINDOW",0);
+ XSetWMProtocols(display, window, &delwindow, 1);
+
+ hints.flags=PMinSize|PMaxSize; // hints
+ if(fx) hints.flags|=USPosition|USSize;
+ else hints.flags|=PSize;
+
+ hints.min_width = hints.max_width = hints.base_width = iResX;
+ hints.min_height = hints.max_height = hints.base_height = iResY;
+
+ wm_hints.input=1;
+ wm_hints.flags=InputHint;
+
+ XSetWMHints(display,window,&wm_hints);
+ XSetWMNormalHints(display,window,&hints);
+ if(pCaptionText) // caption
+ XStoreName(display,window,pCaptionText);
+ else XStoreName(display,window,"Pete MesaGL PSX Gpu");
+
+ XDefineCursor(display,window,cursor); // cursor
+
+ if(fx) // window title bar hack
+ {
+ mwmhints.flags=MWM_HINTS_DECORATIONS;
+ mwmhints.decorations=0;
+ mwmatom=XInternAtom(display,"_MOTIF_WM_HINTS",0);
+ XChangeProperty(display,window,mwmatom,mwmatom,32,
+ PropModeReplace,(unsigned char *)&mwmhints,4);
+ }
+
+ XSelectInput(display,window, // input setup
+ FocusChangeMask | ExposureMask |
+ KeyPressMask | KeyReleaseMask);
+
+ XMapRaised(display,window);
+ XClearWindow(display,window);
+ XWindowEvent(display,window,ExposureMask,&event);
+ glXMakeCurrent(display,window,cx);
+
+/*
+ printf(glGetString(GL_VENDOR));
+ printf("\n");
+ printf(glGetString(GL_RENDERER));
+ printf("\n");
+*/
+
+ if (fx) // after make current: fullscreen resize
+ {
+ XResizeWindow(display,window,screen->width,screen->height);
+ hints.min_width = hints.max_width = hints.base_width = screen->width;
+ hints.min_height= hints.max_height = hints.base_height = screen->height;
+ XSetWMNormalHints(display,window,&hints);
+
+ // set the window layer for GNOME
+ {
+ XEvent xev;
+
+ memset(&xev, 0, sizeof(xev));
+ xev.xclient.type = ClientMessage;
+ xev.xclient.serial = 0;
+ xev.xclient.send_event = 1;
+ xev.xclient.message_type = XInternAtom(display, "_NET_WM_STATE", 0);
+ xev.xclient.window = window;
+ xev.xclient.format = 32;
+ xev.xclient.data.l[0] = 1;
+ xev.xclient.data.l[1] = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", 0);
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ XSendEvent(display, RootWindow(display, DefaultScreen(display)), 0,
+ SubstructureRedirectMask | SubstructureNotifyMask, &xev);
+ }
+ }
+}
+
+#endif // !defined(_MACGL)
+
+#ifndef _WINDOWS
+
+#if defined(_MACGL)
+extern char * pCaptionText;
+#endif
+
+////////////////////////////////////////////////////////////////////////
+
+long GPUopen(unsigned long * disp,char * CapText,char * CfgFile)
+{
+ pCaptionText=CapText;
+ pConfigFile=CfgFile;
+
+ ReadConfig(); // read text file for config
+
+ SetFrameRateConfig(); // setup frame rate stuff
+
+ bIsFirstFrame = TRUE; // we have to init later (well, no really... in Linux we do all in GPUopen)
+
+ #if defined (_MACGL)
+ unsigned long display = ulInitDisplay();
+ #else
+ sysdep_create_display(); // create display
+ #endif
+
+ InitializeTextureStore(); // init texture mem
+
+ rRatioRect.left = rRatioRect.top=0;
+ rRatioRect.right = iResX;
+ rRatioRect.bottom = iResY;
+
+ GLinitialize(); // init opengl
+
+ if(disp)
+ {
+ *disp = display;
+ }
+
+ if(display) return 0;
+ return -1;
+}
+
+#endif // ndef _WINDOWS
+
+
+
+////////////////////////////////////////////////////////////////////////
+// close
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+
+long CALLBACK GPUclose() // WINDOWS CLOSE
+{
+ ExitKeyHandler();
+
+ GLcleanup(); // close OGL
+
+ if(bChangeRes) // change res back
+ ChangeDisplaySettings(NULL,0);
+
+ if(hPSEMenu) // set menu again
+ SetMenu(hWWindow,hPSEMenu);
+
+ if(pGfxCardScreen) free(pGfxCardScreen); // free helper memory
+ pGfxCardScreen=0;
+
+ if(iNoScreenSaver) EnableScreenSaver(TRUE); // enable screen saver again
+
+ return 0;
+}
+
+#else
+
+long GPUclose() // LINUX CLOSE
+{
+ GLcleanup(); // close OGL
+
+ if(pGfxCardScreen) free(pGfxCardScreen); // free helper memory
+ pGfxCardScreen=0;
+ #if defined (_MACGL)
+ CloseDisplay();
+ #else
+ osd_close_display(); // destroy display
+ #endif
+ return 0;
+}
+
+#endif
+
+////////////////////////////////////////////////////////////////////////
+// I shot the sheriff... last function called from emu
+////////////////////////////////////////////////////////////////////////
+
+long CALLBACK GPUshutdown()
+{
+ if(psxVSecure) free(psxVSecure); // kill emulated vram memory
+ psxVSecure=0;
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////
+// paint it black: simple func to clean up optical border garbage
+////////////////////////////////////////////////////////////////////////
+
+static void PaintBlackBorders(void)
+{
+ short s;
+
+ glDisable(GL_SCISSOR_TEST);
+ if(bTexEnabled) {glDisable(GL_TEXTURE_2D);bTexEnabled=FALSE;}
+ if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}
+ if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
+ glDisable(GL_ALPHA_TEST);
+
+ glBegin(GL_QUADS);
+
+ vertex[0].c.lcol=0xff000000;
+ SETCOL(vertex[0]);
+
+ if(PreviousPSXDisplay.Range.x0)
+ {
+ s=PreviousPSXDisplay.Range.x0+1;
+ glVertex3f(0,0,0.99996f);
+ glVertex3f(0,PSXDisplay.DisplayMode.y,0.99996f);
+ glVertex3f(s,PSXDisplay.DisplayMode.y,0.99996f);
+ glVertex3f(s,0,0.99996f);
+
+ s+=PreviousPSXDisplay.Range.x1-2;
+
+ glVertex3f(s,0,0.99996f);
+ glVertex3f(s,PSXDisplay.DisplayMode.y,0.99996f);
+ glVertex3f(PSXDisplay.DisplayMode.x,PSXDisplay.DisplayMode.y,0.99996f);
+ glVertex3f(PSXDisplay.DisplayMode.x,0,0.99996f);
+ }
+
+ if(PreviousPSXDisplay.Range.y0)
+ {
+ s=PreviousPSXDisplay.Range.y0+1;
+ glVertex3f(0,0,0.99996f);
+ glVertex3f(0,s,0.99996f);
+ glVertex3f(PSXDisplay.DisplayMode.x,s,0.99996f);
+ glVertex3f(PSXDisplay.DisplayMode.x,0,0.99996f);
+ }
+
+ glEnd();
+
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_SCISSOR_TEST);
+}
+
+////////////////////////////////////////////////////////////////////////
+// helper to draw scanlines
+////////////////////////////////////////////////////////////////////////
+
+static __inline void XPRIMdrawTexturedQuad(OGLVertex* vertex1, OGLVertex* vertex2,
+ OGLVertex* vertex3, OGLVertex* vertex4)
+{
+
+ glBegin(GL_QUAD_STRIP);
+ glTexCoord2fv(&vertex1->sow);
+ glVertex3fv(&vertex1->x);
+
+ glTexCoord2fv(&vertex2->sow);
+ glVertex3fv(&vertex2->x);
+
+ glTexCoord2fv(&vertex4->sow);
+ glVertex3fv(&vertex4->x);
+
+ glTexCoord2fv(&vertex3->sow);
+ glVertex3fv(&vertex3->x);
+ glEnd();
+}
+
+////////////////////////////////////////////////////////////////////////
+// scanlines
+////////////////////////////////////////////////////////////////////////
+
+static void SetScanLines(void)
+{
+ glLoadIdentity();
+ glOrtho(0,iResX,iResY, 0, -1, 1);
+
+ if(bKeepRatio)
+ glViewport(0,0,iResX,iResY);
+
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_ALPHA_TEST);
+ if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}
+
+ if(iScanBlend<0) // special texture mask scanline mode
+ {
+ if(!bTexEnabled) {glEnable(GL_TEXTURE_2D);bTexEnabled=TRUE;}
+ gTexName=gTexScanName;
+ glBindTexture(GL_TEXTURE_2D, gTexName);
+ if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ if(!bBlendEnable) {glEnable(GL_BLEND);bBlendEnable=TRUE;}
+ SetScanTexTrans();
+
+ vertex[0].x=0;
+ vertex[0].y=iResY;
+ vertex[0].z=0.99996f;
+
+ vertex[1].x=iResX;
+ vertex[1].y=iResY;
+ vertex[1].z=0.99996f;
+
+ vertex[2].x=iResX;
+ vertex[2].y=0;
+ vertex[2].z=0.99996f;
+
+ vertex[3].x=0;
+ vertex[3].y=0;
+ vertex[3].z=0.99996f;
+
+ vertex[0].sow=0;
+ vertex[0].tow=0;
+ vertex[1].sow=(float)iResX/4.0f;
+ vertex[1].tow=0;
+ vertex[2].sow=vertex[1].sow;
+ vertex[2].tow=(float)iResY/4.0f;
+ vertex[3].sow=0;
+ vertex[3].tow=vertex[2].tow;
+
+ vertex[0].c.lcol=0xffffffff;
+ SETCOL(vertex[0]);
+
+ XPRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
+
+ if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
+ }
+ else // typical line mode
+ {
+ if(bTexEnabled) {glDisable(GL_TEXTURE_2D);bTexEnabled=FALSE;}
+
+ if(iScanBlend==0)
+ {
+ if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
+ vertex[0].c.lcol=0xff000000;
+ }
+ else
+ {
+ if(!bBlendEnable) {glEnable(GL_BLEND);bBlendEnable=TRUE;}
+ SetScanTrans();
+ vertex[0].c.lcol=iScanBlend<<24;
+ }
+
+ SETCOL(vertex[0]);
+
+ glCallList(uiScanLine);
+ }
+
+ glLoadIdentity();
+ glOrtho(0,PSXDisplay.DisplayMode.x,
+ PSXDisplay.DisplayMode.y, 0, -1, 1);
+
+ if(bKeepRatio)
+ glViewport(rRatioRect.left,
+ iResY-(rRatioRect.top+rRatioRect.bottom),
+ rRatioRect.right,
+ rRatioRect.bottom); // init viewport
+
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_SCISSOR_TEST);
+}
+
+////////////////////////////////////////////////////////////////////////
+// blur, babe, blur (heavy performance hit for a so-so fullscreen effect)
+////////////////////////////////////////////////////////////////////////
+
+static void BlurBackBuffer(void)
+{
+ if(!gTexBlurName) return;
+
+ if(bKeepRatio) glViewport(0,0,iResX,iResY);
+
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_ALPHA_TEST);
+ if(bOldSmoothShaded) {glShadeModel(GL_FLAT);bOldSmoothShaded=FALSE;}
+ if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
+ if(!bTexEnabled) {glEnable(GL_TEXTURE_2D);bTexEnabled=TRUE;}
+ if(iZBufferDepth) glDisable(GL_DEPTH_TEST);
+ if(bDrawDither) glDisable(GL_DITHER);
+
+ gTexName=gTexBlurName;
+ glBindTexture(GL_TEXTURE_2D, gTexName);
+
+ glCopyTexSubImage2D( GL_TEXTURE_2D, 0, // get back buffer in texture
+ 0,
+ 0,
+ 0,
+ 0,
+ iResX,iResY);
+
+ vertex[0].x=0;
+ vertex[0].y=PSXDisplay.DisplayMode.y;
+ vertex[1].x=PSXDisplay.DisplayMode.x;
+ vertex[1].y=PSXDisplay.DisplayMode.y;
+ vertex[2].x=PSXDisplay.DisplayMode.x;
+ vertex[2].y=0;
+ vertex[3].x=0;
+ vertex[3].y=0;
+ vertex[0].sow=0;
+ vertex[0].tow=0;
+
+#ifdef OWNSCALE
+ vertex[1].sow=((GLfloat)iFTexA)/256.0f;
+ vertex[2].tow=((GLfloat)iFTexB)/256.0f;
+#else
+ vertex[1].sow=iFTexA;
+ vertex[2].tow=iFTexB;
+#endif
+ vertex[1].tow=0;
+ vertex[2].sow=vertex[1].sow;
+ vertex[3].sow=0;
+ vertex[3].tow=vertex[2].tow;
+
+ if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ vertex[0].c.lcol=0x7fffffff;
+ SETCOL(vertex[0]);
+
+ DrawMultiBlur(); // draw the backbuffer texture to create blur effect
+
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_SCISSOR_TEST);
+ if(iZBufferDepth) glEnable(GL_DEPTH_TEST);
+ if(bDrawDither) glEnable(GL_DITHER);
+ if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
+
+ if(bKeepRatio)
+ glViewport(rRatioRect.left, // re-init viewport
+ iResY-(rRatioRect.top+rRatioRect.bottom),
+ rRatioRect.right,
+ rRatioRect.bottom);
+}
+
+////////////////////////////////////////////////////////////////////////
+// "unblur" repairs the backbuffer after a blur
+
+static void UnBlurBackBuffer(void)
+{
+ if(!gTexBlurName) return;
+
+ if(bKeepRatio) glViewport(0,0,iResX,iResY);
+
+ glDisable(GL_SCISSOR_TEST);
+ glDisable(GL_ALPHA_TEST);
+ if(bBlendEnable) {glDisable(GL_BLEND);bBlendEnable=FALSE;}
+ if(!bTexEnabled) {glEnable(GL_TEXTURE_2D);bTexEnabled=TRUE;}
+ if(iZBufferDepth) glDisable(GL_DEPTH_TEST);
+ if(bDrawDither) glDisable(GL_DITHER);
+
+ gTexName=gTexBlurName;
+ glBindTexture(GL_TEXTURE_2D, gTexName);
+
+ vertex[0].x=0;
+ vertex[0].y=PSXDisplay.DisplayMode.y;
+ vertex[1].x=PSXDisplay.DisplayMode.x;
+ vertex[1].y=PSXDisplay.DisplayMode.y;
+ vertex[2].x=PSXDisplay.DisplayMode.x;
+ vertex[2].y=0;
+ vertex[3].x=0;
+ vertex[3].y=0;
+ vertex[0].sow=0;
+ vertex[0].tow=0;
+#ifdef OWNSCALE
+ vertex[1].sow=((GLfloat)iFTexA)/256.0f;
+ vertex[2].tow=((GLfloat)iFTexB)/256.0f;
+#else
+ vertex[1].sow=iFTexA;
+ vertex[2].tow=iFTexB;
+#endif
+ vertex[1].tow=0;
+ vertex[2].sow=vertex[1].sow;
+ vertex[3].sow=0;
+ vertex[3].tow=vertex[2].tow;
+ if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ vertex[0].c.lcol=0xffffffff;
+ SETCOL(vertex[0]);
+
+ // simply draw the backbuffer texture (without blur)
+ XPRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
+
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_SCISSOR_TEST);
+ if(iZBufferDepth) glEnable(GL_DEPTH_TEST);
+ if(bDrawDither) glEnable(GL_DITHER); // dither mode
+ if(bGLBlend) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, COMBINE_EXT);
+
+ if(bKeepRatio)
+ glViewport(rRatioRect.left,
+ iResY-(rRatioRect.top+rRatioRect.bottom),
+ rRatioRect.right,
+ rRatioRect.bottom); // init viewport
+}
+
+////////////////////////////////////////////////////////////////////////
+// Update display (swap buffers)... called in interlaced mode on
+// every emulated vsync, otherwise whenever the displayed screen region
+// has been changed
+////////////////////////////////////////////////////////////////////////
+
+int iLastRGB24=0; // special vars for checking when to skip two display updates
+int iSkipTwo=0;
+
+void updateDisplay(void) // UPDATE DISPLAY
+{
+ BOOL bBlur=FALSE;
+
+#ifdef _WINDOWS
+ HDC hdc=GetDC(hWWindow); // windows:
+ wglMakeCurrent(hdc,GLCONTEXT); // -> make context current again
+#endif
+#if defined (_MACGL)
+ BringContextForward();
+#endif
+ bFakeFrontBuffer=FALSE;
+ bRenderFrontBuffer=FALSE;
+
+ if(iRenderFVR) // frame buffer read fix mode still active?
+ {
+ iRenderFVR--; // -> if some frames in a row without read access: turn off mode
+ if(!iRenderFVR) bFullVRam=FALSE;
+ }
+
+ if(iLastRGB24 && iLastRGB24!=PSXDisplay.RGB24+1) // (mdec) garbage check
+ {
+ iSkipTwo=2; // -> skip two frames to avoid garbage if color mode changes
+ }
+ iLastRGB24=0;
+
+ if(PSXDisplay.RGB24)// && !bNeedUploadAfter) // (mdec) upload wanted?
+ {
+ PrepareFullScreenUpload(-1);
+ UploadScreen(PSXDisplay.Interlaced); // -> upload whole screen from psx vram
+ bNeedUploadTest=FALSE;
+ bNeedInterlaceUpdate=FALSE;
+ bNeedUploadAfter=FALSE;
+ bNeedRGB24Update=FALSE;
+ }
+ else
+ if(bNeedInterlaceUpdate) // smaller upload?
+ {
+ bNeedInterlaceUpdate=FALSE;
+ xrUploadArea=xrUploadAreaIL; // -> upload this rect
+ UploadScreen(TRUE);
+ }
+
+ if(dwActFixes&512) bCheckFF9G4(NULL); // special game fix for FF9
+
+ if(PreviousPSXDisplay.Range.x0|| // paint black borders around display area, if needed
+ PreviousPSXDisplay.Range.y0)
+ PaintBlackBorders();
+
+ if(PSXDisplay.Disabled) // display disabled?
+ {
+ // moved here
+ glDisable(GL_SCISSOR_TEST);
+ glClearColor(0,0,0,128); // -> clear whole backbuffer
+ glClear(uiBufferBits);
+ glEnable(GL_SCISSOR_TEST);
+ gl_z=0.0f;
+ bDisplayNotSet = TRUE;
+ }
+
+ if(iSkipTwo) // we are in skipping mood?
+ {
+ iSkipTwo--;
+ iDrawnSomething=0; // -> simply lie about something drawn
+ }
+
+ if(iBlurBuffer && !bSkipNextFrame) // "blur display" activated?
+ {BlurBackBuffer();bBlur=TRUE;} // -> blur it
+
+ if(iUseScanLines) SetScanLines(); // "scan lines" activated? do it
+
+ if(usCursorActive) ShowGunCursor(); // "gun cursor" wanted? show 'em
+
+ if(dwActFixes&128) // special FPS limitation mode?
+ {
+ if(bUseFrameLimit) PCFrameCap(); // -> ok, do it
+ if(bUseFrameSkip || ulKeybits&KEY_SHOWFPS)
+ PCcalcfps();
+ }
+
+ if(gTexPicName) DisplayPic(); // some gpu info picture active? display it
+
+ if(bSnapShot) DoSnapShot(); // snapshot key pressed? cheeeese :)
+
+ if(ulKeybits&KEY_SHOWFPS) // wanna see FPS?
+ {
+ sprintf(szDispBuf,"%06.1f",fps_cur);
+ DisplayText(); // -> show it
+ }
+
+ //----------------------------------------------------//
+ // main buffer swapping (well, or skip it)
+
+ if(bUseFrameSkip) // frame skipping active ?
+ {
+ if(!bSkipNextFrame)
+ {
+ if(iDrawnSomething)
+#ifdef _WINDOWS
+ SwapBuffers(wglGetCurrentDC()); // -> to skip or not to skip
+#elif defined(_MACGL)
+ DoBufferSwap();
+#else
+ glXSwapBuffers(display,window);
+#endif
+ }
+ if(dwActFixes&0x180) // -> special old frame skipping: skip max one in a row
+ {
+ if((fps_skip < fFrameRateHz) && !(bSkipNextFrame))
+ {bSkipNextFrame = TRUE; fps_skip=fFrameRateHz;}
+ else bSkipNextFrame = FALSE;
+ }
+ else FrameSkip();
+ }
+ else // no skip ?
+ {
+ if(iDrawnSomething)
+#ifdef _WINDOWS
+ SwapBuffers(wglGetCurrentDC()); // -> swap
+#elif defined(_MACGL)
+ DoBufferSwap();
+#else
+ glXSwapBuffers(display,window);
+#endif
+ }
+
+ iDrawnSomething=0;
+
+ //----------------------------------------------------//
+
+ if(lClearOnSwap) // clear buffer after swap?
+ {
+ GLclampf g,b,r;
+
+ if(bDisplayNotSet) // -> set new vals
+ SetOGLDisplaySettings(1);
+
+ g=((GLclampf)GREEN(lClearOnSwapColor))/255.0f; // -> get col
+ b=((GLclampf)BLUE(lClearOnSwapColor))/255.0f;
+ r=((GLclampf)RED(lClearOnSwapColor))/255.0f;
+
+ glDisable(GL_SCISSOR_TEST);
+ glClearColor(r,g,b,128); // -> clear
+ glClear(uiBufferBits);
+ glEnable(GL_SCISSOR_TEST);
+ lClearOnSwap=0; // -> done
+ }
+ else
+ {
+ if(bBlur) UnBlurBackBuffer(); // unblur buff, if blurred before
+
+ if(iZBufferDepth) // clear zbuffer as well (if activated)
+ {
+ glDisable(GL_SCISSOR_TEST);
+ glClear(GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_SCISSOR_TEST);
+ }
+ }
+ gl_z=0.0f;
+
+ //----------------------------------------------------//
+ // additional uploads immediatly after swapping
+
+ if(bNeedUploadAfter) // upload wanted?
+ {
+ bNeedUploadAfter=FALSE;
+ bNeedUploadTest=FALSE;
+ UploadScreen(-1); // -> upload
+ }
+
+ if(bNeedUploadTest)
+ {
+ bNeedUploadTest=FALSE;
+ if(PSXDisplay.InterlacedTest &&
+ //iOffscreenDrawing>2 &&
+ PreviousPSXDisplay.DisplayPosition.x==PSXDisplay.DisplayPosition.x &&
+ PreviousPSXDisplay.DisplayEnd.x==PSXDisplay.DisplayEnd.x &&
+ PreviousPSXDisplay.DisplayPosition.y==PSXDisplay.DisplayPosition.y &&
+ PreviousPSXDisplay.DisplayEnd.y==PSXDisplay.DisplayEnd.y)
+ {
+ PrepareFullScreenUpload(TRUE);
+ UploadScreen(TRUE);
+ }
+ }
+
+ //----------------------------------------------------//
+ // rumbling (main emu pad effect)
+
+ if(iRumbleTime) // shake screen by modifying view port
+ {
+ int i1=0,i2=0,i3=0,i4=0;
+
+ iRumbleTime--;
+ if(iRumbleTime)
+ {
+ i1=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
+ i2=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
+ i3=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
+ i4=((rand()*iRumbleVal)/RAND_MAX)-(iRumbleVal/2);
+ }
+
+ glViewport(rRatioRect.left+i1,
+ iResY-(rRatioRect.top+rRatioRect.bottom)+i2,
+ rRatioRect.right+i3,
+ rRatioRect.bottom+i4);
+ }
+
+#ifdef _WINDOWS
+ ReleaseDC(hWWindow,hdc); // ! important !
+#endif
+
+ if(ulKeybits&KEY_RESETTEXSTORE) ResetStuff(); // reset on gpu mode changes? do it before next frame is filled
+}
+
+////////////////////////////////////////////////////////////////////////
+// update front display: smaller update func, if something has changed
+// in the frontbuffer... dirty, but hey... real men know no pain
+////////////////////////////////////////////////////////////////////////
+
+void updateFrontDisplay(void)
+{
+ if(PreviousPSXDisplay.Range.x0||
+ PreviousPSXDisplay.Range.y0)
+ PaintBlackBorders();
+
+ if(iBlurBuffer) BlurBackBuffer();
+
+ if(iUseScanLines) SetScanLines();
+
+ if(usCursorActive) ShowGunCursor();
+
+ bFakeFrontBuffer=FALSE;
+ bRenderFrontBuffer=FALSE;
+
+ if(gTexPicName) DisplayPic();
+ if(ulKeybits&KEY_SHOWFPS) DisplayText();
+
+#ifdef _WINDOWS
+ { // windows:
+ HDC hdc=GetDC(hWWindow);
+ wglMakeCurrent(hdc,GLCONTEXT); // -> make current again
+ if(iDrawnSomething)
+ SwapBuffers(wglGetCurrentDC()); // -> swap
+ ReleaseDC(hWWindow,hdc); // -> ! important !
+ }
+#elif defined (_MACGL)
+if (iDrawnSomething){
+ DoBufferSwap();
+ }
+#else
+ if(iDrawnSomething) // linux:
+ glXSwapBuffers(display,window);
+#endif
+
+ if(iBlurBuffer) UnBlurBackBuffer();
+}
+
+////////////////////////////////////////////////////////////////////////
+// check if update needed
+////////////////////////////////////////////////////////////////////////
+
+static void ChangeDispOffsetsX(void) // CENTER X
+{
+ int lx,l;short sO;
+
+ if(!PSXDisplay.Range.x1) return; // some range given?
+
+ l=PSXDisplay.DisplayMode.x;
+
+ l*=(int)PSXDisplay.Range.x1; // some funky calculation
+ l/=2560;lx=l;l&=0xfffffff8;
+
+ if(l==PreviousPSXDisplay.Range.x1) return; // some change?
+
+ sO=PreviousPSXDisplay.Range.x0; // store old
+
+ if(lx>=PSXDisplay.DisplayMode.x) // range bigger?
+ {
+ PreviousPSXDisplay.Range.x1= // -> take display width
+ PSXDisplay.DisplayMode.x;
+ PreviousPSXDisplay.Range.x0=0; // -> start pos is 0
+ }
+ else // range smaller? center it
+ {
+ PreviousPSXDisplay.Range.x1=l; // -> store width (8 pixel aligned)
+ PreviousPSXDisplay.Range.x0= // -> calc start pos
+ (PSXDisplay.Range.x0-500)/8;
+ if(PreviousPSXDisplay.Range.x0<0) // -> we don't support neg. values yet
+ PreviousPSXDisplay.Range.x0=0;
+
+ if((PreviousPSXDisplay.Range.x0+lx)> // -> uhuu... that's too much
+ PSXDisplay.DisplayMode.x)
+ {
+ PreviousPSXDisplay.Range.x0= // -> adjust start
+ PSXDisplay.DisplayMode.x-lx;
+ PreviousPSXDisplay.Range.x1+=lx-l; // -> adjust width
+ }
+ }
+
+ if(sO!=PreviousPSXDisplay.Range.x0) // something changed?
+ {
+ bDisplayNotSet=TRUE; // -> recalc display stuff
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void ChangeDispOffsetsY(void) // CENTER Y
+{
+ int iT;short sO; // store previous y size
+
+ if(PSXDisplay.PAL) iT=48; else iT=28; // different offsets on PAL/NTSC
+
+ if(PSXDisplay.Range.y0>=iT) // crossed the security line? :)
+ {
+ PreviousPSXDisplay.Range.y1= // -> store width
+ PSXDisplay.DisplayModeNew.y;
+
+ sO=(PSXDisplay.Range.y0-iT-4)*PSXDisplay.Double; // -> calc offset
+ if(sO<0) sO=0;
+
+ PSXDisplay.DisplayModeNew.y+=sO; // -> add offset to y size, too
+ }
+ else sO=0; // else no offset
+
+ if(sO!=PreviousPSXDisplay.Range.y0) // something changed?
+ {
+ PreviousPSXDisplay.Range.y0=sO;
+ bDisplayNotSet=TRUE; // -> recalc display stuff
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// Aspect ratio of ogl screen: simply adjusting ogl view port
+////////////////////////////////////////////////////////////////////////
+
+void SetAspectRatio(void)
+{
+ float xs,ys,s;RECT r;
+
+ if(!PSXDisplay.DisplayModeNew.x) return;
+ if(!PSXDisplay.DisplayModeNew.y) return;
+
+ xs=(float)iResX/(float)PSXDisplay.DisplayModeNew.x;
+ ys=(float)iResY/(float)PSXDisplay.DisplayModeNew.y;
+
+ s=min(xs,ys);
+ r.right =(int)((float)PSXDisplay.DisplayModeNew.x*s);
+ r.bottom=(int)((float)PSXDisplay.DisplayModeNew.y*s);
+ if(r.right > iResX) r.right = iResX;
+ if(r.bottom > iResY) r.bottom = iResY;
+ if(r.right < 1) r.right = 1;
+ if(r.bottom < 1) r.bottom = 1;
+
+ r.left = (iResX-r.right)/2;
+ r.top = (iResY-r.bottom)/2;
+
+ if(r.bottom<rRatioRect.bottom ||
+ r.right <rRatioRect.right)
+ {
+ RECT rC;
+ glClearColor(0,0,0,128);
+
+ if(r.right <rRatioRect.right)
+ {
+ rC.left=0;
+ rC.top=0;
+ rC.right=r.left;
+ rC.bottom=iResY;
+ glScissor(rC.left,rC.top,rC.right,rC.bottom);
+ glClear(uiBufferBits);
+ rC.left=iResX-rC.right;
+ glScissor(rC.left,rC.top,rC.right,rC.bottom);
+ glClear(uiBufferBits);
+ }
+
+ if(r.bottom <rRatioRect.bottom)
+ {
+ rC.left=0;
+ rC.top=0;
+ rC.right=iResX;
+ rC.bottom=r.top;
+ glScissor(rC.left,rC.top,rC.right,rC.bottom);
+ glClear(uiBufferBits);
+ rC.top=iResY-rC.bottom;
+ glScissor(rC.left,rC.top,rC.right,rC.bottom);
+ glClear(uiBufferBits);
+ }
+
+ bSetClip=TRUE;
+ bDisplayNotSet=TRUE;
+ }
+
+ rRatioRect=r;
+
+
+ glViewport(rRatioRect.left,
+ iResY-(rRatioRect.top+rRatioRect.bottom),
+ rRatioRect.right,
+ rRatioRect.bottom); // init viewport
+}
+
+////////////////////////////////////////////////////////////////////////
+// big ass check, if an ogl swap buffer is needed
+////////////////////////////////////////////////////////////////////////
+
+static void updateDisplayIfChanged(void)
+{
+ BOOL bUp;
+
+ if ((PSXDisplay.DisplayMode.y == PSXDisplay.DisplayModeNew.y) &&
+ (PSXDisplay.DisplayMode.x == PSXDisplay.DisplayModeNew.x))
+ {
+ if((PSXDisplay.RGB24 == PSXDisplay.RGB24New) &&
+ (PSXDisplay.Interlaced == PSXDisplay.InterlacedNew))
+ return; // nothing has changed? fine, no swap buffer needed
+ }
+ else // some res change?
+ {
+ glLoadIdentity();
+ glOrtho(0,PSXDisplay.DisplayModeNew.x, // -> new psx resolution
+ PSXDisplay.DisplayModeNew.y, 0, -1, 1);
+ if(bKeepRatio) SetAspectRatio();
+ }
+
+ bDisplayNotSet = TRUE; // re-calc offsets/display area
+
+ bUp=FALSE;
+ if(PSXDisplay.RGB24!=PSXDisplay.RGB24New) // clean up textures, if rgb mode change (usually mdec on/off)
+ {
+ PreviousPSXDisplay.RGB24=0; // no full 24 frame uploaded yet
+ ResetTextureArea(FALSE);
+ bUp=TRUE;
+ }
+
+ PSXDisplay.RGB24 = PSXDisplay.RGB24New; // get new infos
+ PSXDisplay.DisplayMode.y = PSXDisplay.DisplayModeNew.y;
+ PSXDisplay.DisplayMode.x = PSXDisplay.DisplayModeNew.x;
+ PSXDisplay.Interlaced = PSXDisplay.InterlacedNew;
+
+ PSXDisplay.DisplayEnd.x= // calc new ends
+ PSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
+ PSXDisplay.DisplayEnd.y=
+ PSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
+ PreviousPSXDisplay.DisplayEnd.x=
+ PreviousPSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
+ PreviousPSXDisplay.DisplayEnd.y=
+ PreviousPSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
+
+ ChangeDispOffsetsX();
+
+ if(iFrameLimit==2) SetAutoFrameCap(); // set new fps limit vals (depends on interlace)
+
+ if(bUp) updateDisplay(); // yeah, real update (swap buffer)
+}
+
+////////////////////////////////////////////////////////////////////////
+// window mode <-> fullscreen mode (windows)
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+void ChangeWindowMode(void)
+ {
+ GPUclose();
+ bWindowMode=!bWindowMode;
+ GPUopen(hWWindow);
+ bChangeWinMode=FALSE;
+ }
+#endif
+
+////////////////////////////////////////////////////////////////////////
+// swap update check (called by psx vsync function)
+////////////////////////////////////////////////////////////////////////
+
+static BOOL bSwapCheck(void)
+{
+ static int iPosCheck=0;
+ static PSXPoint_t pO;
+ static PSXPoint_t pD;
+ static int iDoAgain=0;
+
+ if(PSXDisplay.DisplayPosition.x==pO.x &&
+ PSXDisplay.DisplayPosition.y==pO.y &&
+ PSXDisplay.DisplayEnd.x==pD.x &&
+ PSXDisplay.DisplayEnd.y==pD.y)
+ iPosCheck++;
+ else iPosCheck=0;
+
+ pO=PSXDisplay.DisplayPosition;
+ pD=PSXDisplay.DisplayEnd;
+
+ if(iPosCheck<=4) return FALSE;
+
+ iPosCheck=4;
+
+ if(PSXDisplay.Interlaced) return FALSE;
+
+ if (bNeedInterlaceUpdate||
+ bNeedRGB24Update ||
+ bNeedUploadAfter||
+ bNeedUploadTest ||
+ iDoAgain
+ )
+ {
+ iDoAgain=0;
+ if(bNeedUploadAfter)
+ iDoAgain=1;
+ if(bNeedUploadTest && PSXDisplay.InterlacedTest)
+ iDoAgain=1;
+
+ bDisplayNotSet = TRUE;
+ updateDisplay();
+
+ PreviousPSXDisplay.DisplayPosition.x=PSXDisplay.DisplayPosition.x;
+ PreviousPSXDisplay.DisplayPosition.y=PSXDisplay.DisplayPosition.y;
+ PreviousPSXDisplay.DisplayEnd.x=PSXDisplay.DisplayEnd.x;
+ PreviousPSXDisplay.DisplayEnd.y=PSXDisplay.DisplayEnd.y;
+ pO=PSXDisplay.DisplayPosition;
+ pD=PSXDisplay.DisplayEnd;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+////////////////////////////////////////////////////////////////////////
+// gun cursor func: player=0-7, x=0-511, y=0-255
+////////////////////////////////////////////////////////////////////////
+
+void CALLBACK GPUcursor(int iPlayer,int x,int y)
+{
+ if(iPlayer<0) return;
+ if(iPlayer>7) return;
+
+ usCursorActive|=(1<<iPlayer);
+
+ if(x<0) x=0;
+ if(x>iGPUHeightMask) x=iGPUHeightMask;
+ if(y<0) y=0;
+ if(y>255) y=255;
+
+ ptCursorPoint[iPlayer].x=x;
+ ptCursorPoint[iPlayer].y=y;
+}
+
+////////////////////////////////////////////////////////////////////////
+// update lace is called every VSync. Basically we limit frame rate
+// here, and in interlaced mode we swap ogl display buffers.
+////////////////////////////////////////////////////////////////////////
+
+static unsigned short usFirstPos=2;
+
+void CALLBACK GPUupdateLace(void)
+{
+ //if(!(dwActFixes&0x1000))
+ // STATUSREG^=0x80000000; // interlaced bit toggle, if the CC game fix is not active (see gpuReadStatus)
+
+ if(!(dwActFixes&128)) // normal frame limit func
+ CheckFrameRate();
+
+ if(iOffscreenDrawing==4) // special check if high offscreen drawing is on
+ {
+ if(bSwapCheck()) return;
+ }
+
+ if(PSXDisplay.Interlaced) // interlaced mode?
+ {
+ STATUSREG^=0x80000000;
+ if(PSXDisplay.DisplayMode.x>0 && PSXDisplay.DisplayMode.y>0)
+ {
+ updateDisplay(); // -> swap buffers (new frame)
+ }
+ }
+ else if(bRenderFrontBuffer) // no interlace mode? and some stuff in front has changed?
+ {
+ updateFrontDisplay(); // -> update front buffer
+ }
+ else if(usFirstPos==1) // initial updates (after startup)
+ {
+ updateDisplay();
+ }
+
+#if defined(_WINDOWS) || defined(_MACGL)
+ if(bChangeWinMode) ChangeWindowMode();
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////
+// process read request from GPU status register
+////////////////////////////////////////////////////////////////////////
+
+uint32_t CALLBACK GPUreadStatus(void)
+{
+ if(dwActFixes&0x1000) // CC game fix
+ {
+ static int iNumRead=0;
+ if((iNumRead++)==2)
+ {
+ iNumRead=0;
+ STATUSREG^=0x80000000; // interlaced bit toggle... we do it on every second read status... needed by some games (like ChronoCross)
+ }
+ }
+
+ if(iFakePrimBusy) // 27.10.2007 - emulating some 'busy' while drawing... pfff... not perfect, but since our emulated dma is not done in an extra thread...
+ {
+ iFakePrimBusy--;
+
+ if(iFakePrimBusy&1) // we do a busy-idle-busy-idle sequence after/while drawing prims
+ {
+ GPUIsBusy;
+ GPUIsNotReadyForCommands;
+ }
+ else
+ {
+ GPUIsIdle;
+ GPUIsReadyForCommands;
+ }
+ }
+
+ return STATUSREG | (vBlank ? 0x80000000 : 0 );;
+}
+
+////////////////////////////////////////////////////////////////////////
+// processes data send to GPU status register
+// these are always single packet commands.
+////////////////////////////////////////////////////////////////////////
+
+void CALLBACK GPUwriteStatus(uint32_t gdata)
+{
+ uint32_t lCommand=(gdata>>24)&0xff;
+
+#ifdef _WINDOWS
+ if(bIsFirstFrame) GLinitialize(); // real ogl startup (needed by some emus)
+#endif
+
+ ulStatusControl[lCommand]=gdata;
+
+ switch(lCommand)
+ {
+ //--------------------------------------------------//
+ // reset gpu
+ case 0x00:
+ memset(ulGPUInfoVals, 0x00, 16 * sizeof(uint32_t));
+ lGPUstatusRet = 0x14802000;
+ PSXDisplay.Disabled=1;
+ iDataWriteMode=iDataReadMode=DR_NORMAL;
+ PSXDisplay.DrawOffset.x=PSXDisplay.DrawOffset.y=0;
+ drawX=drawY=0;drawW=drawH=0;
+ sSetMask=0;lSetMask=0;bCheckMask=FALSE;iSetMask=0;
+ usMirror=0;
+ GlobalTextAddrX=0;GlobalTextAddrY=0;
+ GlobalTextTP=0;GlobalTextABR=0;
+ PSXDisplay.RGB24=FALSE;
+ PSXDisplay.Interlaced=FALSE;
+ bUsingTWin = FALSE;
+ return;
+
+ // dis/enable display
+ case 0x03:
+ PreviousPSXDisplay.Disabled = PSXDisplay.Disabled;
+ PSXDisplay.Disabled = (gdata & 1);
+
+ if(PSXDisplay.Disabled)
+ STATUSREG|=GPUSTATUS_DISPLAYDISABLED;
+ else STATUSREG&=~GPUSTATUS_DISPLAYDISABLED;
+
+ if (iOffscreenDrawing==4 &&
+ PreviousPSXDisplay.Disabled &&
+ !(PSXDisplay.Disabled))
+ {
+
+ if(!PSXDisplay.RGB24)
+ {
+ PrepareFullScreenUpload(TRUE);
+ UploadScreen(TRUE);
+ updateDisplay();
+ }
+ }
+
+ return;
+
+ // setting transfer mode
+ case 0x04:
+ gdata &= 0x03; // only want the lower two bits
+
+ iDataWriteMode=iDataReadMode=DR_NORMAL;
+ if(gdata==0x02) iDataWriteMode=DR_VRAMTRANSFER;
+ if(gdata==0x03) iDataReadMode =DR_VRAMTRANSFER;
+
+ STATUSREG&=~GPUSTATUS_DMABITS; // clear the current settings of the DMA bits
+ STATUSREG|=(gdata << 29); // set the DMA bits according to the received data
+
+ return;
+
+ // setting display position
+ case 0x05:
+ {
+ short sx=(short)(gdata & 0x3ff);
+ short sy;
+
+ if(iGPUHeight==1024)
+ {
+ if(dwGPUVersion==2)
+ sy = (short)((gdata>>12)&0x3ff);
+ else sy = (short)((gdata>>10)&0x3ff);
+ }
+ else sy = (short)((gdata>>10)&0x3ff); // really: 0x1ff, but we adjust it later
+
+ if (sy & 0x200)
+ {
+ sy|=0xfc00;
+ PreviousPSXDisplay.DisplayModeNew.y=sy/PSXDisplay.Double;
+ sy=0;
+ }
+ else PreviousPSXDisplay.DisplayModeNew.y=0;
+
+ if(sx>1000) sx=0;
+
+ if(usFirstPos)
+ {
+ usFirstPos--;
+ if(usFirstPos)
+ {
+ PreviousPSXDisplay.DisplayPosition.x = sx;
+ PreviousPSXDisplay.DisplayPosition.y = sy;
+ PSXDisplay.DisplayPosition.x = sx;
+ PSXDisplay.DisplayPosition.y = sy;
+ }
+ }
+
+ if(dwActFixes&8)
+ {
+ if((!PSXDisplay.Interlaced) &&
+ PreviousPSXDisplay.DisplayPosition.x == sx &&
+ PreviousPSXDisplay.DisplayPosition.y == sy)
+ return;
+
+ PSXDisplay.DisplayPosition.x = PreviousPSXDisplay.DisplayPosition.x;
+ PSXDisplay.DisplayPosition.y = PreviousPSXDisplay.DisplayPosition.y;
+ PreviousPSXDisplay.DisplayPosition.x = sx;
+ PreviousPSXDisplay.DisplayPosition.y = sy;
+ }
+ else
+ {
+ if((!PSXDisplay.Interlaced) &&
+ PSXDisplay.DisplayPosition.x == sx &&
+ PSXDisplay.DisplayPosition.y == sy)
+ return;
+ PreviousPSXDisplay.DisplayPosition.x = PSXDisplay.DisplayPosition.x;
+ PreviousPSXDisplay.DisplayPosition.y = PSXDisplay.DisplayPosition.y;
+ PSXDisplay.DisplayPosition.x = sx;
+ PSXDisplay.DisplayPosition.y = sy;
+ }
+
+ PSXDisplay.DisplayEnd.x=
+ PSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
+ PSXDisplay.DisplayEnd.y=
+ PSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
+
+ PreviousPSXDisplay.DisplayEnd.x=
+ PreviousPSXDisplay.DisplayPosition.x+ PSXDisplay.DisplayMode.x;
+ PreviousPSXDisplay.DisplayEnd.y=
+ PreviousPSXDisplay.DisplayPosition.y+ PSXDisplay.DisplayMode.y+PreviousPSXDisplay.DisplayModeNew.y;
+
+ bDisplayNotSet = TRUE;
+
+ if (!(PSXDisplay.Interlaced))
+ {
+ updateDisplay();
+ }
+ else
+ if(PSXDisplay.InterlacedTest &&
+ ((PreviousPSXDisplay.DisplayPosition.x != PSXDisplay.DisplayPosition.x)||
+ (PreviousPSXDisplay.DisplayPosition.y != PSXDisplay.DisplayPosition.y)))
+ PSXDisplay.InterlacedTest--;
+
+ return;
+ }
+
+ // setting width
+ case 0x06:
+
+ PSXDisplay.Range.x0=gdata & 0x7ff; //0x3ff;
+ PSXDisplay.Range.x1=(gdata>>12) & 0xfff;//0x7ff;
+
+ PSXDisplay.Range.x1-=PSXDisplay.Range.x0;
+
+ ChangeDispOffsetsX();
+
+ return;
+
+ // setting height
+ case 0x07:
+
+ PreviousPSXDisplay.Height = PSXDisplay.Height;
+
+ PSXDisplay.Range.y0=gdata & 0x3ff;
+ PSXDisplay.Range.y1=(gdata>>10) & 0x3ff;
+
+ PSXDisplay.Height = PSXDisplay.Range.y1 -
+ PSXDisplay.Range.y0 +
+ PreviousPSXDisplay.DisplayModeNew.y;
+
+ if (PreviousPSXDisplay.Height != PSXDisplay.Height)
+ {
+ PSXDisplay.DisplayModeNew.y=PSXDisplay.Height*PSXDisplay.Double;
+ ChangeDispOffsetsY();
+ updateDisplayIfChanged();
+ }
+ return;
+
+ // setting display infos
+ case 0x08:
+
+ PSXDisplay.DisplayModeNew.x = dispWidths[(gdata & 0x03) | ((gdata & 0x40) >> 4)];
+
+ if (gdata&0x04) PSXDisplay.Double=2;
+ else PSXDisplay.Double=1;
+ PSXDisplay.DisplayModeNew.y = PSXDisplay.Height*PSXDisplay.Double;
+
+ ChangeDispOffsetsY();
+
+ PSXDisplay.PAL = (gdata & 0x08)?TRUE:FALSE; // if 1 - PAL mode, else NTSC
+ PSXDisplay.RGB24New = (gdata & 0x10)?TRUE:FALSE; // if 1 - TrueColor
+ PSXDisplay.InterlacedNew = (gdata & 0x20)?TRUE:FALSE; // if 1 - Interlace
+
+ STATUSREG&=~GPUSTATUS_WIDTHBITS; // clear the width bits
+
+ STATUSREG|=
+ (((gdata & 0x03) << 17) |
+ ((gdata & 0x40) << 10)); // set the width bits
+
+ PreviousPSXDisplay.InterlacedNew=FALSE;
+ if (PSXDisplay.InterlacedNew)
+ {
+ if(!PSXDisplay.Interlaced)
+ {
+ PSXDisplay.InterlacedTest=2;
+ PreviousPSXDisplay.DisplayPosition.x = PSXDisplay.DisplayPosition.x;
+ PreviousPSXDisplay.DisplayPosition.y = PSXDisplay.DisplayPosition.y;
+ PreviousPSXDisplay.InterlacedNew=TRUE;
+ }
+
+ STATUSREG|=GPUSTATUS_INTERLACED;
+ }
+ else
+ {
+ PSXDisplay.InterlacedTest=0;
+ STATUSREG&=~GPUSTATUS_INTERLACED;
+ }
+
+ if (PSXDisplay.PAL)
+ STATUSREG|=GPUSTATUS_PAL;
+ else STATUSREG&=~GPUSTATUS_PAL;
+
+ if (PSXDisplay.Double==2)
+ STATUSREG|=GPUSTATUS_DOUBLEHEIGHT;
+ else STATUSREG&=~GPUSTATUS_DOUBLEHEIGHT;
+
+ if (PSXDisplay.RGB24New)
+ STATUSREG|=GPUSTATUS_RGB24;
+ else STATUSREG&=~GPUSTATUS_RGB24;
+
+ updateDisplayIfChanged();
+
+ return;
+
+ //--------------------------------------------------//
+ // ask about GPU version and other stuff
+ case 0x10:
+
+ gdata&=0xff;
+
+ switch(gdata)
+ {
+ case 0x02:
+ GPUdataRet=ulGPUInfoVals[INFO_TW]; // tw infos
+ return;
+ case 0x03:
+ GPUdataRet=ulGPUInfoVals[INFO_DRAWSTART]; // draw start
+ return;
+ case 0x04:
+ GPUdataRet=ulGPUInfoVals[INFO_DRAWEND]; // draw end
+ return;
+ case 0x05:
+ case 0x06:
+ GPUdataRet=ulGPUInfoVals[INFO_DRAWOFF]; // draw offset
+ return;
+ case 0x07:
+ if(dwGPUVersion==2)
+ GPUdataRet=0x01;
+ else GPUdataRet=0x02; // gpu type
+ return;
+ case 0x08:
+ case 0x0F: // some bios addr?
+ GPUdataRet=0xBFC03720;
+ return;
+ }
+ return;
+ //--------------------------------------------------//
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// vram read/write helpers
+////////////////////////////////////////////////////////////////////////
+
+BOOL bNeedWriteUpload=FALSE;
+
+static __inline void FinishedVRAMWrite(void)
+{
+ if(bNeedWriteUpload)
+ {
+ bNeedWriteUpload=FALSE;
+ CheckWriteUpdate();
+ }
+
+ // set register to NORMAL operation
+ iDataWriteMode = DR_NORMAL;
+
+ // reset transfer values, to prevent mis-transfer of data
+ VRAMWrite.ColsRemaining = 0;
+ VRAMWrite.RowsRemaining = 0;
+}
+
+static __inline void FinishedVRAMRead(void)
+{
+ // set register to NORMAL operation
+ iDataReadMode = DR_NORMAL;
+ // reset transfer values, to prevent mis-transfer of data
+ VRAMRead.x = 0;
+ VRAMRead.y = 0;
+ VRAMRead.Width = 0;
+ VRAMRead.Height = 0;
+ VRAMRead.ColsRemaining = 0;
+ VRAMRead.RowsRemaining = 0;
+
+ // indicate GPU is no longer ready for VRAM data in the STATUS REGISTER
+ STATUSREG&=~GPUSTATUS_READYFORVRAM;
+}
+
+////////////////////////////////////////////////////////////////////////
+// vram read check ex (reading from card's back/frontbuffer if needed...
+// slow!)
+////////////////////////////////////////////////////////////////////////
+
+void CheckVRamReadEx(int x, int y, int dx, int dy)
+{
+ unsigned short sArea;
+ int ux,uy,udx,udy,wx,wy;
+ unsigned short * p1, *p2;
+ float XS,YS;
+ unsigned char * ps;
+ unsigned char * px;
+ unsigned short s,sx;
+
+ if(STATUSREG&GPUSTATUS_RGB24) return;
+
+ if(((dx > PSXDisplay.DisplayPosition.x) &&
+ (x < PSXDisplay.DisplayEnd.x) &&
+ (dy > PSXDisplay.DisplayPosition.y) &&
+ (y < PSXDisplay.DisplayEnd.y)))
+ sArea=0;
+ else
+ if((!(PSXDisplay.InterlacedTest) &&
+ (dx > PreviousPSXDisplay.DisplayPosition.x) &&
+ (x < PreviousPSXDisplay.DisplayEnd.x) &&
+ (dy > PreviousPSXDisplay.DisplayPosition.y) &&
+ (y < PreviousPSXDisplay.DisplayEnd.y)))
+ sArea=1;
+ else
+ {
+ return;
+ }
+
+ //////////////
+
+ if(iRenderFVR)
+ {
+ bFullVRam=TRUE;iRenderFVR=2;return;
+ }
+ bFullVRam=TRUE;iRenderFVR=2;
+
+ //////////////
+
+ p2=0;
+
+ if(sArea==0)
+ {
+ ux=PSXDisplay.DisplayPosition.x;
+ uy=PSXDisplay.DisplayPosition.y;
+ udx=PSXDisplay.DisplayEnd.x-ux;
+ udy=PSXDisplay.DisplayEnd.y-uy;
+ if((PreviousPSXDisplay.DisplayEnd.x-
+ PreviousPSXDisplay.DisplayPosition.x)==udx &&
+ (PreviousPSXDisplay.DisplayEnd.y-
+ PreviousPSXDisplay.DisplayPosition.y)==udy)
+ p2=(psxVuw + (1024*PreviousPSXDisplay.DisplayPosition.y) +
+ PreviousPSXDisplay.DisplayPosition.x);
+ }
+ else
+ {
+ ux=PreviousPSXDisplay.DisplayPosition.x;
+ uy=PreviousPSXDisplay.DisplayPosition.y;
+ udx=PreviousPSXDisplay.DisplayEnd.x-ux;
+ udy=PreviousPSXDisplay.DisplayEnd.y-uy;
+ if((PSXDisplay.DisplayEnd.x-
+ PSXDisplay.DisplayPosition.x)==udx &&
+ (PSXDisplay.DisplayEnd.y-
+ PSXDisplay.DisplayPosition.y)==udy)
+ p2=(psxVuw + (1024*PSXDisplay.DisplayPosition.y) +
+ PSXDisplay.DisplayPosition.x);
+ }
+
+ p1=(psxVuw + (1024*uy) + ux);
+ if(p1==p2) p2=0;
+
+ x=0;y=0;
+ wx=dx=udx;wy=dy=udy;
+
+ if(udx<=0) return;
+ if(udy<=0) return;
+ if(dx<=0) return;
+ if(dy<=0) return;
+ if(wx<=0) return;
+ if(wy<=0) return;
+
+ XS=(float)rRatioRect.right/(float)wx;
+ YS=(float)rRatioRect.bottom/(float)wy;
+
+ dx=(int)((float)(dx)*XS);
+ dy=(int)((float)(dy)*YS);
+
+ if(dx>iResX) dx=iResX;
+ if(dy>iResY) dy=iResY;
+
+ if(dx<=0) return;
+ if(dy<=0) return;
+
+ // ogl y adjust
+ y=iResY-y-dy;
+
+ x+=rRatioRect.left;
+ y-=rRatioRect.top;
+
+ if(y<0) y=0; if((y+dy)>iResY) dy=iResY-y;
+
+ if(!pGfxCardScreen)
+ {
+ glPixelStorei(GL_PACK_ALIGNMENT,1);
+ pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);
+ }
+
+ ps=pGfxCardScreen;
+
+ if(!sArea) glReadBuffer(GL_FRONT);
+
+ glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps);
+
+ if(!sArea) glReadBuffer(GL_BACK);
+
+ s=0;
+
+ XS=(float)dx/(float)(udx);
+ YS=(float)dy/(float)(udy+1);
+
+ for(y=udy;y>0;y--)
+ {
+ for(x=0;x<udx;x++)
+ {
+ if(p1>=psxVuw && p1<psxVuw_eom)
+ {
+ px=ps+(3*((int)((float)x * XS))+
+ (3*dx)*((int)((float)y*YS)));
+ sx=(*px)>>3;px++;
+ s=sx;
+ sx=(*px)>>3;px++;
+ s|=sx<<5;
+ sx=(*px)>>3;
+ s|=sx<<10;
+ s&=~0x8000;
+ *p1=s;
+ }
+ if(p2>=psxVuw && p2<psxVuw_eom) *p2=s;
+
+ p1++;
+ if(p2) p2++;
+ }
+
+ p1 += 1024 - udx;
+ if(p2) p2 += 1024 - udx;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// vram read check (reading from card's back/frontbuffer if needed...
+// slow!)
+////////////////////////////////////////////////////////////////////////
+
+void CheckVRamRead(int x, int y, int dx, int dy,BOOL bFront)
+{
+ unsigned short sArea;unsigned short * p;
+ int ux,uy,udx,udy,wx,wy;float XS,YS;
+ unsigned char * ps, * px;
+ unsigned short s=0,sx;
+
+ if(STATUSREG&GPUSTATUS_RGB24) return;
+
+ if(((dx > PSXDisplay.DisplayPosition.x) &&
+ (x < PSXDisplay.DisplayEnd.x) &&
+ (dy > PSXDisplay.DisplayPosition.y) &&
+ (y < PSXDisplay.DisplayEnd.y)))
+ sArea=0;
+ else
+ if((!(PSXDisplay.InterlacedTest) &&
+ (dx > PreviousPSXDisplay.DisplayPosition.x) &&
+ (x < PreviousPSXDisplay.DisplayEnd.x) &&
+ (dy > PreviousPSXDisplay.DisplayPosition.y) &&
+ (y < PreviousPSXDisplay.DisplayEnd.y)))
+ sArea=1;
+ else
+ {
+ return;
+ }
+
+ if(dwActFixes&0x40)
+ {
+ if(iRenderFVR)
+ {
+ bFullVRam=TRUE;iRenderFVR=2;return;
+ }
+ bFullVRam=TRUE;iRenderFVR=2;
+ }
+
+ ux=x;uy=y;udx=dx;udy=dy;
+
+ if(sArea==0)
+ {
+ x -=PSXDisplay.DisplayPosition.x;
+ dx-=PSXDisplay.DisplayPosition.x;
+ y -=PSXDisplay.DisplayPosition.y;
+ dy-=PSXDisplay.DisplayPosition.y;
+ wx=PSXDisplay.DisplayEnd.x-PSXDisplay.DisplayPosition.x;
+ wy=PSXDisplay.DisplayEnd.y-PSXDisplay.DisplayPosition.y;
+ }
+ else
+ {
+ x -=PreviousPSXDisplay.DisplayPosition.x;
+ dx-=PreviousPSXDisplay.DisplayPosition.x;
+ y -=PreviousPSXDisplay.DisplayPosition.y;
+ dy-=PreviousPSXDisplay.DisplayPosition.y;
+ wx=PreviousPSXDisplay.DisplayEnd.x-PreviousPSXDisplay.DisplayPosition.x;
+ wy=PreviousPSXDisplay.DisplayEnd.y-PreviousPSXDisplay.DisplayPosition.y;
+ }
+ if(x<0) {ux-=x;x=0;}
+ if(y<0) {uy-=y;y=0;}
+ if(dx>wx) {udx-=(dx-wx);dx=wx;}
+ if(dy>wy) {udy-=(dy-wy);dy=wy;}
+ udx-=ux;
+ udy-=uy;
+
+ p=(psxVuw + (1024*uy) + ux);
+
+ if(udx<=0) return;
+ if(udy<=0) return;
+ if(dx<=0) return;
+ if(dy<=0) return;
+ if(wx<=0) return;
+ if(wy<=0) return;
+
+ XS=(float)rRatioRect.right/(float)wx;
+ YS=(float)rRatioRect.bottom/(float)wy;
+
+ dx=(int)((float)(dx)*XS);
+ dy=(int)((float)(dy)*YS);
+ x=(int)((float)x*XS);
+ y=(int)((float)y*YS);
+
+ dx-=x;
+ dy-=y;
+
+ if(dx>iResX) dx=iResX;
+ if(dy>iResY) dy=iResY;
+
+ if(dx<=0) return;
+ if(dy<=0) return;
+
+ // ogl y adjust
+ y=iResY-y-dy;
+
+ x+=rRatioRect.left;
+ y-=rRatioRect.top;
+
+ if(y<0) y=0; if((y+dy)>iResY) dy=iResY-y;
+
+ if(!pGfxCardScreen)
+ {
+ glPixelStorei(GL_PACK_ALIGNMENT,1);
+ pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);
+ }
+
+ ps=pGfxCardScreen;
+
+ if(bFront) glReadBuffer(GL_FRONT);
+
+ glReadPixels(x,y,dx,dy,GL_RGB,GL_UNSIGNED_BYTE,ps);
+
+ if(bFront) glReadBuffer(GL_BACK);
+
+ XS=(float)dx/(float)(udx);
+ YS=(float)dy/(float)(udy+1);
+
+ for(y=udy;y>0;y--)
+ {
+ for(x=0;x<udx;x++)
+ {
+ if(p>=psxVuw && p<psxVuw_eom)
+ {
+ px=ps+(3*((int)((float)x * XS))+
+ (3*dx)*((int)((float)y*YS)));
+ sx=(*px)>>3;px++;
+ s=sx;
+ sx=(*px)>>3;px++;
+ s|=sx<<5;
+ sx=(*px)>>3;
+ s|=sx<<10;
+ s&=~0x8000;
+ *p=s;
+ }
+ p++;
+ }
+ p += 1024 - udx;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// core read from vram
+////////////////////////////////////////////////////////////////////////
+
+void CALLBACK GPUreadDataMem(uint32_t *pMem, int iSize)
+{
+ int i;
+
+ if(iDataReadMode!=DR_VRAMTRANSFER) return;
+
+ GPUIsBusy;
+
+ // adjust read ptr, if necessary
+ while(VRAMRead.ImagePtr>=psxVuw_eom)
+ VRAMRead.ImagePtr-=iGPUHeight*1024;
+ while(VRAMRead.ImagePtr<psxVuw)
+ VRAMRead.ImagePtr+=iGPUHeight*1024;
+
+ if((iFrameReadType&1 && iSize>1) &&
+ !(iDrawnSomething==2 &&
+ VRAMRead.x == VRAMWrite.x &&
+ VRAMRead.y == VRAMWrite.y &&
+ VRAMRead.Width == VRAMWrite.Width &&
+ VRAMRead.Height == VRAMWrite.Height))
+ CheckVRamRead(VRAMRead.x,VRAMRead.y,
+ VRAMRead.x+VRAMRead.RowsRemaining,
+ VRAMRead.y+VRAMRead.ColsRemaining,
+ TRUE);
+
+ for(i=0;i<iSize;i++)
+ {
+ // do 2 seperate 16bit reads for compatibility (wrap issues)
+ if ((VRAMRead.ColsRemaining > 0) && (VRAMRead.RowsRemaining > 0))
+ {
+ // lower 16 bit
+ GPUdataRet=(uint32_t)*VRAMRead.ImagePtr;
+
+ VRAMRead.ImagePtr++;
+ if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
+ VRAMRead.RowsRemaining --;
+
+ if(VRAMRead.RowsRemaining<=0)
+ {
+ VRAMRead.RowsRemaining = VRAMRead.Width;
+ VRAMRead.ColsRemaining--;
+ VRAMRead.ImagePtr += 1024 - VRAMRead.Width;
+ if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
+ }
+
+ // higher 16 bit (always, even if it's an odd width)
+ GPUdataRet|=(uint32_t)(*VRAMRead.ImagePtr)<<16;
+ *pMem++=GPUdataRet;
+
+ if(VRAMRead.ColsRemaining <= 0)
+ {FinishedVRAMRead();goto ENDREAD;}
+
+ VRAMRead.ImagePtr++;
+ if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
+ VRAMRead.RowsRemaining--;
+ if(VRAMRead.RowsRemaining<=0)
+ {
+ VRAMRead.RowsRemaining = VRAMRead.Width;
+ VRAMRead.ColsRemaining--;
+ VRAMRead.ImagePtr += 1024 - VRAMRead.Width;
+ if(VRAMRead.ImagePtr>=psxVuw_eom) VRAMRead.ImagePtr-=iGPUHeight*1024;
+ }
+ if(VRAMRead.ColsRemaining <= 0)
+ {FinishedVRAMRead();goto ENDREAD;}
+ }
+ else {FinishedVRAMRead();goto ENDREAD;}
+ }
+
+ENDREAD:
+ GPUIsIdle;
+}
+
+uint32_t CALLBACK GPUreadData(void)
+{
+ uint32_t l;
+ GPUreadDataMem(&l,1);
+ return GPUdataRet;
+}
+
+////////////////////////////////////////////////////////////////////////
+// helper table to know how much data is used by drawing commands
+////////////////////////////////////////////////////////////////////////
+
+const unsigned char primTableCX[256] =
+{
+ // 00
+ 0,0,3,0,0,0,0,0,
+ // 08
+ 0,0,0,0,0,0,0,0,
+ // 10
+ 0,0,0,0,0,0,0,0,
+ // 18
+ 0,0,0,0,0,0,0,0,
+ // 20
+ 4,4,4,4,7,7,7,7,
+ // 28
+ 5,5,5,5,9,9,9,9,
+ // 30
+ 6,6,6,6,9,9,9,9,
+ // 38
+ 8,8,8,8,12,12,12,12,
+ // 40
+ 3,3,3,3,0,0,0,0,
+ // 48
+// 5,5,5,5,6,6,6,6, //FLINE
+ 254,254,254,254,254,254,254,254,
+ // 50
+ 4,4,4,4,0,0,0,0,
+ // 58
+// 7,7,7,7,9,9,9,9, // LINEG3 LINEG4
+ 255,255,255,255,255,255,255,255,
+ // 60
+ 3,3,3,3,4,4,4,4, // TILE SPRT
+ // 68
+ 2,2,2,2,3,3,3,3, // TILE1
+ // 70
+ 2,2,2,2,3,3,3,3,
+ // 78
+ 2,2,2,2,3,3,3,3,
+ // 80
+ 4,0,0,0,0,0,0,0,
+ // 88
+ 0,0,0,0,0,0,0,0,
+ // 90
+ 0,0,0,0,0,0,0,0,
+ // 98
+ 0,0,0,0,0,0,0,0,
+ // a0
+ 3,0,0,0,0,0,0,0,
+ // a8
+ 0,0,0,0,0,0,0,0,
+ // b0
+ 0,0,0,0,0,0,0,0,
+ // b8
+ 0,0,0,0,0,0,0,0,
+ // c0
+ 3,0,0,0,0,0,0,0,
+ // c8
+ 0,0,0,0,0,0,0,0,
+ // d0
+ 0,0,0,0,0,0,0,0,
+ // d8
+ 0,0,0,0,0,0,0,0,
+ // e0
+ 0,1,1,1,1,1,1,0,
+ // e8
+ 0,0,0,0,0,0,0,0,
+ // f0
+ 0,0,0,0,0,0,0,0,
+ // f8
+ 0,0,0,0,0,0,0,0
+};
+
+////////////////////////////////////////////////////////////////////////
+// processes data send to GPU data register
+////////////////////////////////////////////////////////////////////////
+
+void CALLBACK GPUwriteDataMem(uint32_t *pMem, int iSize)
+{
+ unsigned char command;
+ uint32_t gdata=0;
+ int i=0;
+ GPUIsBusy;
+ GPUIsNotReadyForCommands;
+
+STARTVRAM:
+
+ if(iDataWriteMode==DR_VRAMTRANSFER)
+ {
+ // make sure we are in vram
+ while(VRAMWrite.ImagePtr>=psxVuw_eom)
+ VRAMWrite.ImagePtr-=iGPUHeight*1024;
+ while(VRAMWrite.ImagePtr<psxVuw)
+ VRAMWrite.ImagePtr+=iGPUHeight*1024;
+
+ // now do the loop
+ while(VRAMWrite.ColsRemaining>0)
+ {
+ while(VRAMWrite.RowsRemaining>0)
+ {
+ if(i>=iSize) {goto ENDVRAM;}
+ i++;
+
+ gdata=*pMem++;
+
+ *VRAMWrite.ImagePtr++ = (unsigned short)gdata;
+ if(VRAMWrite.ImagePtr>=psxVuw_eom) VRAMWrite.ImagePtr-=iGPUHeight*1024;
+ VRAMWrite.RowsRemaining --;
+
+ if(VRAMWrite.RowsRemaining <= 0)
+ {
+ VRAMWrite.ColsRemaining--;
+ if (VRAMWrite.ColsRemaining <= 0) // last pixel is odd width
+ {
+ gdata=(gdata&0xFFFF)|(((uint32_t)(*VRAMWrite.ImagePtr))<<16);
+ FinishedVRAMWrite();
+ goto ENDVRAM;
+ }
+ VRAMWrite.RowsRemaining = VRAMWrite.Width;
+ VRAMWrite.ImagePtr += 1024 - VRAMWrite.Width;
+ }
+
+ *VRAMWrite.ImagePtr++ = (unsigned short)(gdata>>16);
+ if(VRAMWrite.ImagePtr>=psxVuw_eom) VRAMWrite.ImagePtr-=iGPUHeight*1024;
+ VRAMWrite.RowsRemaining --;
+ }
+
+ VRAMWrite.RowsRemaining = VRAMWrite.Width;
+ VRAMWrite.ColsRemaining--;
+ VRAMWrite.ImagePtr += 1024 - VRAMWrite.Width;
+ }
+
+ FinishedVRAMWrite();
+ }
+
+ENDVRAM:
+
+ if(iDataWriteMode==DR_NORMAL)
+ {
+ void (* *primFunc)(unsigned char *);
+ if(bSkipNextFrame) primFunc=primTableSkip;
+ else primFunc=primTableJ;
+
+ for(;i<iSize;)
+ {
+ if(iDataWriteMode==DR_VRAMTRANSFER) goto STARTVRAM;
+
+ gdata=*pMem++;i++;
+
+ if(gpuDataC == 0)
+ {
+ command = (unsigned char)((gdata>>24) & 0xff);
+
+ if(primTableCX[command])
+ {
+ gpuDataC = primTableCX[command];
+ gpuCommand = command;
+ gpuDataM[0] = gdata;
+ gpuDataP = 1;
+ }
+ else continue;
+ }
+ else
+ {
+ gpuDataM[gpuDataP] = gdata;
+ if(gpuDataC>128)
+ {
+ if((gpuDataC==254 && gpuDataP>=3) ||
+ (gpuDataC==255 && gpuDataP>=4 && !(gpuDataP&1)))
+ {
+ if((gpuDataM[gpuDataP] & 0xF000F000) == 0x50005000)
+ gpuDataP=gpuDataC-1;
+ }
+ }
+ gpuDataP++;
+ }
+
+ if(gpuDataP == gpuDataC)
+ {
+ gpuDataC=gpuDataP=0;
+ primFunc[gpuCommand]((unsigned char *)gpuDataM);
+
+ if(dwEmuFixes&0x0001 || dwActFixes&0x20000) // hack for emulating "gpu busy" in some games
+ iFakePrimBusy=4;
+ }
+ }
+ }
+
+ GPUdataRet=gdata;
+
+ GPUIsReadyForCommands;
+ GPUIsIdle;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void CALLBACK GPUwriteData(uint32_t gdata)
+{
+ GPUwriteDataMem(&gdata,1);
+}
+
+////////////////////////////////////////////////////////////////////////
+// call config dlg
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+
+long CALLBACK GPUconfigure(void)
+{
+ HWND hWP=GetActiveWindow();
+ DialogBox(hInst,MAKEINTRESOURCE(IDD_CFGDLG),
+ hWP,(DLGPROC)CfgDlgProc);
+
+ return 0;
+}
+
+#elif defined(_MACGL)
+long CALLBACK GPUconfigure(void)
+{
+ DlgProc();
+ return 0;
+}
+#else
+
+static void StartCfgTool(char *arg) // linux: start external cfg tool
+{
+ char cfg[256];
+ struct stat buf;
+
+ strcpy(cfg, "./cfgpeopsxgl");
+ if (stat(cfg, &buf) != -1) {
+ if (fork() == 0) {
+ execl(cfg, "cfgpeopsxgl", arg, NULL);
+ exit(0);
+ }
+ return;
+ }
+
+ strcpy(cfg, "./cfg/cfgpeopsxgl");
+ if (stat(cfg, &buf) != -1) {
+ if (fork() == 0) {
+ execl(cfg, "cfgpeopsxgl", arg, NULL);
+ exit(0);
+ }
+ return;
+ }
+
+ sprintf(cfg, "%s/.pcsx/plugins/cfg/cfgpeopsxgl", getenv("HOME"));
+ if (stat(cfg, &buf) != -1) {
+ if (fork() == 0) {
+ execl(cfg, "cfgpeopsxgl", arg, NULL);
+ exit(0);
+ }
+ return;
+ }
+
+ printf("ERROR: cfgpeopsxgl file not found!\n");
+}
+
+long CALLBACK GPUconfigure(void)
+{
+ StartCfgTool("CFG");
+ return 0;
+}
+
+#endif // def _WINDOWS / _MACGL
+
+////////////////////////////////////////////////////////////////////////
+// sets all kind of act fixes
+////////////////////////////////////////////////////////////////////////
+
+void SetFixes(void)
+{
+ ReInitFrameCap();
+
+ if(dwActFixes & 0x2000)
+ dispWidths[4]=384;
+ else dispWidths[4]=368;
+}
+
+////////////////////////////////////////////////////////////////////////
+// Pete Special: make an 'intelligent' dma chain check (<-Tekken3)
+////////////////////////////////////////////////////////////////////////
+
+uint32_t lUsedAddr[3];
+
+static __inline BOOL CheckForEndlessLoop(uint32_t laddr)
+{
+ if(laddr==lUsedAddr[1]) return TRUE;
+ if(laddr==lUsedAddr[2]) return TRUE;
+
+ if(laddr<lUsedAddr[0]) lUsedAddr[1]=laddr;
+ else lUsedAddr[2]=laddr;
+ lUsedAddr[0]=laddr;
+ return FALSE;
+}
+
+////////////////////////////////////////////////////////////////////////
+// core gives a dma chain to gpu: same as the gpuwrite interface funcs
+////////////////////////////////////////////////////////////////////////
+
+long CALLBACK GPUdmaChain(uint32_t *baseAddrL, uint32_t addr)
+{
+ uint32_t dmaMem;
+ unsigned char * baseAddrB;
+ short count;unsigned int DMACommandCounter = 0;
+
+ if(bIsFirstFrame) GLinitialize();
+
+ GPUIsBusy;
+
+ lUsedAddr[0]=lUsedAddr[1]=lUsedAddr[2]=0xffffff;
+
+ baseAddrB = (unsigned char*) baseAddrL;
+
+ do
+ {
+ if(iGPUHeight==512) addr&=0x1FFFFC;
+
+ if(DMACommandCounter++ > 2000000) break;
+ if(CheckForEndlessLoop(addr)) break;
+
+ count = baseAddrB[addr+3];
+
+ dmaMem=addr+4;
+
+ if(count>0) GPUwriteDataMem(&baseAddrL[dmaMem>>2],count);
+
+ addr = baseAddrL[addr>>2]&0xffffff;
+ }
+ while (addr != 0xffffff);
+
+ GPUIsIdle;
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////
+// show about dlg
+////////////////////////////////////////////////////////////////////////
+
+void CALLBACK GPUabout(void)
+{
+#ifdef _WINDOWS
+ HWND hWP=GetActiveWindow(); // to be sure
+ DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
+ hWP,(DLGPROC)AboutDlgProc);
+#elif defined(_MACGL)
+
+ AboutDlgProc();
+#else
+
+ StartCfgTool("ABOUT");
+
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////
+// We are ever fine ;)
+////////////////////////////////////////////////////////////////////////
+
+long CALLBACK GPUtest(void)
+{
+ // if test fails this function should return negative value for error (unable to continue)
+ // and positive value for warning (can continue but output might be crappy)
+
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////
+// save state funcs
+////////////////////////////////////////////////////////////////////////
+
+long CALLBACK GPUfreeze(uint32_t ulGetFreezeData,GPUFreeze_t * pF)
+{
+ if(ulGetFreezeData==2)
+ {
+ int lSlotNum=*((int *)pF);
+ if(lSlotNum<0) return 0;
+ if(lSlotNum>8) return 0;
+ lSelectedSlot=lSlotNum+1;
+ return 1;
+ }
+
+ if(!pF) return 0;
+ if(pF->ulFreezeVersion!=1) return 0;
+
+ if(ulGetFreezeData==1)
+ {
+ pF->ulStatus=STATUSREG;
+ memcpy(pF->ulControl,ulStatusControl,256*sizeof(uint32_t));
+ memcpy(pF->psxVRam, psxVub, 1024*iGPUHeight*2);
+
+ return 1;
+ }
+
+ if(ulGetFreezeData!=0) return 0;
+
+ STATUSREG=pF->ulStatus;
+ memcpy(ulStatusControl,pF->ulControl,256*sizeof(uint32_t));
+ memcpy(psxVub, pF->psxVRam, 1024*iGPUHeight*2);
+
+ ResetTextureArea(TRUE);
+
+ GPUwriteStatus(ulStatusControl[0]);
+ GPUwriteStatus(ulStatusControl[1]);
+ GPUwriteStatus(ulStatusControl[2]);
+ GPUwriteStatus(ulStatusControl[3]);
+ GPUwriteStatus(ulStatusControl[8]);
+ GPUwriteStatus(ulStatusControl[6]);
+ GPUwriteStatus(ulStatusControl[7]);
+ GPUwriteStatus(ulStatusControl[5]);
+ GPUwriteStatus(ulStatusControl[4]);
+
+ return 1;
+}
+
+////////////////////////////////////////////////////////////////////////
+// special "emu infos" / "emu effects" functions
+////////////////////////////////////////////////////////////////////////
+
+//00 = black
+//01 = white
+//10 = red
+//11 = transparent
+
+unsigned char cFont[10][120]=
+{
+// 0
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 1
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x05,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x05,0x55,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 2
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x14,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x01,0x40,0x00,0x00,
+ 0x80,0x00,0x05,0x00,0x00,0x00,
+ 0x80,0x00,0x14,0x00,0x00,0x00,
+ 0x80,0x00,0x15,0x55,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 3
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x01,0x54,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 4
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x14,0x00,0x00,
+ 0x80,0x00,0x00,0x54,0x00,0x00,
+ 0x80,0x00,0x01,0x54,0x00,0x00,
+ 0x80,0x00,0x01,0x54,0x00,0x00,
+ 0x80,0x00,0x05,0x14,0x00,0x00,
+ 0x80,0x00,0x14,0x14,0x00,0x00,
+ 0x80,0x00,0x15,0x55,0x00,0x00,
+ 0x80,0x00,0x00,0x14,0x00,0x00,
+ 0x80,0x00,0x00,0x14,0x00,0x00,
+ 0x80,0x00,0x00,0x55,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 5
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x15,0x55,0x00,0x00,
+ 0x80,0x00,0x14,0x00,0x00,0x00,
+ 0x80,0x00,0x14,0x00,0x00,0x00,
+ 0x80,0x00,0x14,0x00,0x00,0x00,
+ 0x80,0x00,0x15,0x54,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 6
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x01,0x54,0x00,0x00,
+ 0x80,0x00,0x05,0x00,0x00,0x00,
+ 0x80,0x00,0x14,0x00,0x00,0x00,
+ 0x80,0x00,0x14,0x00,0x00,0x00,
+ 0x80,0x00,0x15,0x54,0x00,0x00,
+ 0x80,0x00,0x15,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 7
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x15,0x55,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x14,0x00,0x00,
+ 0x80,0x00,0x00,0x14,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x50,0x00,0x00,
+ 0x80,0x00,0x01,0x40,0x00,0x00,
+ 0x80,0x00,0x01,0x40,0x00,0x00,
+ 0x80,0x00,0x05,0x00,0x00,0x00,
+ 0x80,0x00,0x05,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 8
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+},
+// 9
+{0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x05,0x54,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x05,0x00,0x00,
+ 0x80,0x00,0x14,0x15,0x00,0x00,
+ 0x80,0x00,0x05,0x55,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x05,0x00,0x00,
+ 0x80,0x00,0x00,0x14,0x00,0x00,
+ 0x80,0x00,0x05,0x50,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0x80,0x00,0x00,0x00,0x00,0x00,
+ 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
+}
+};
+
+////////////////////////////////////////////////////////////////////////
+
+static void PaintPicDot(unsigned char * p,unsigned char c)
+{
+ if(c==0) {*p++=0x00;*p++=0x00;*p=0x00;return;}
+ if(c==1) {*p++=0xff;*p++=0xff;*p=0xff;return;}
+ if(c==2) {*p++=0x00;*p++=0x00;*p=0xff;return;}
+}
+
+////////////////////////////////////////////////////////////////////////
+
+long CALLBACK GPUgetScreenPic(unsigned char * pMem)
+{
+ float XS,YS;int x,y,v;
+ unsigned char * ps, * px, * pf;
+ unsigned char c;
+
+ if(!pGfxCardScreen)
+ {
+ glPixelStorei(GL_PACK_ALIGNMENT,1);
+ pGfxCardScreen=(unsigned char *)malloc(iResX*iResY*4);
+ }
+
+ ps=pGfxCardScreen;
+
+ glReadBuffer(GL_FRONT);
+
+ glReadPixels(0,0,iResX,iResY,GL_RGB,GL_UNSIGNED_BYTE,ps);
+
+ glReadBuffer(GL_BACK);
+
+ XS=(float)iResX/128;
+ YS=(float)iResY/96;
+ pf=pMem;
+
+ for(y=96;y>0;y--)
+ {
+ for(x=0;x<128;x++)
+ {
+ px=ps+(3*((int)((float)x * XS))+
+ (3*iResX)*((int)((float)y*YS)));
+ *(pf+0)=*(px+2);
+ *(pf+1)=*(px+1);
+ *(pf+2)=*(px+0);
+ pf+=3;
+ }
+ }
+
+ /////////////////////////////////////////////////////////////////////
+ // generic number/border painter
+
+ pf=pMem+(103*3);
+
+ for(y=0;y<20;y++)
+ {
+ for(x=0;x<6;x++)
+ {
+ c=cFont[lSelectedSlot][x+y*6];
+ v=(c&0xc0)>>6;
+ PaintPicDot(pf,(unsigned char)v);pf+=3; // paint the dots into the rect
+ v=(c&0x30)>>4;
+ PaintPicDot(pf,(unsigned char)v);pf+=3;
+ v=(c&0x0c)>>2;
+ PaintPicDot(pf,(unsigned char)v);pf+=3;
+ v=c&0x03;
+ PaintPicDot(pf,(unsigned char)v);pf+=3;
+ }
+ pf+=104*3;
+ }
+
+ pf=pMem;
+ for(x=0;x<128;x++)
+ {
+ *(pf+(95*128*3))=0x00;*pf++=0x00;
+ *(pf+(95*128*3))=0x00;*pf++=0x00;
+ *(pf+(95*128*3))=0xff;*pf++=0xff;
+ }
+ pf=pMem;
+ for(y=0;y<96;y++)
+ {
+ *(pf+(127*3))=0x00;*pf++=0x00;
+ *(pf+(127*3))=0x00;*pf++=0x00;
+ *(pf+(127*3))=0xff;*pf++=0xff;
+ pf+=127*3;
+ }
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+long CALLBACK GPUshowScreenPic(unsigned char * pMem)
+{
+ DestroyPic();
+ if(pMem==0) return 0;
+ CreatePic(pMem);
+ return 0;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+#if 0
+void CALLBACK GPUsetfix(uint32_t dwFixBits)
+{
+ dwEmuFixes=dwFixBits;
+}
+#endif
+
+////////////////////////////////////////////////////////////////////////
+
+void CALLBACK GPUvisualVibration(uint32_t iSmall, uint32_t iBig)
+{
+ int iVibVal;
+
+ if(PSXDisplay.DisplayModeNew.x) // calc min "shake pixel" from screen width
+ iVibVal=max(1,iResX/PSXDisplay.DisplayModeNew.x);
+ else iVibVal=1;
+ // big rumble: 4...15 sp ; small rumble 1...3 sp
+ if(iBig) iRumbleVal=max(4*iVibVal,min(15*iVibVal,((int)iBig *iVibVal)/10));
+ else iRumbleVal=max(1*iVibVal,min( 3*iVibVal,((int)iSmall*iVibVal)/10));
+
+ srand(timeGetTime()); // init rand (will be used in BufferSwap)
+
+ iRumbleTime=15; // let the rumble last 16 buffer swaps
+}
+
+////////////////////////////////////////////////////////////////////////
+// main emu can set display infos (A/M/G/D)
+////////////////////////////////////////////////////////////////////////
+
+#if 0
+void CALLBACK GPUdisplayFlags(uint32_t dwFlags)
+{
+ dwCoreFlags=dwFlags;
+}
+#endif
+
+void CALLBACK GPUvBlank( int val )
+{
+ vBlank = val;
+}
diff --git a/plugins/peopsxgl/gpu.h b/plugins/peopsxgl/gpu.h
index f21433d9..19276781 100644
--- a/plugins/peopsxgl/gpu.h
+++ b/plugins/peopsxgl/gpu.h
@@ -1,40 +1,43 @@
-/***************************************************************************
- gpu.h - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
-#ifndef _GPU_INTERNALS_H
-#define _GPU_INTERNALS_H
-
-#define PRED(x) ((x << 3) & 0xF8)
-#define PBLUE(x) ((x >> 2) & 0xF8)
-#define PGREEN(x) ((x >> 7) & 0xF8)
-
-#define RED(x) (x & 0xff)
-#define BLUE(x) ((x>>16) & 0xff)
-#define GREEN(x) ((x>>8) & 0xff)
-#define COLOR(x) (x & 0xffffff)
-
-void DoSnapShot(void);
-void updateDisplay(void);
-void updateFrontDisplay(void);
-void SetAutoFrameCap(void);
-void SetAspectRatio(void);
-void CheckVRamRead(int x, int y, int dx, int dy,BOOL bFront);
-void CheckVRamReadEx(int x, int y, int dx, int dy);
-void SetFixes(void);
-
-#endif // _GPU_INTERNALS_H
+/***************************************************************************
+ gpu.h - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#ifndef _GPU_INTERNALS_H
+#define _GPU_INTERNALS_H
+
+#define PRED(x) ((x << 3) & 0xF8)
+#define PBLUE(x) ((x >> 2) & 0xF8)
+#define PGREEN(x) ((x >> 7) & 0xF8)
+
+#define RED(x) (x & 0xff)
+#define BLUE(x) ((x>>16) & 0xff)
+#define GREEN(x) ((x>>8) & 0xff)
+#define COLOR(x) (x & 0xffffff)
+
+void DoSnapShot(void);
+void updateDisplay(void);
+void updateFrontDisplay(void);
+void SetAutoFrameCap(void);
+void SetAspectRatio(void);
+void CheckVRamRead(int x, int y, int dx, int dy,BOOL bFront);
+void CheckVRamReadEx(int x, int y, int dx, int dy);
+void SetFixes(void);
+
+#ifdef _WINDOWS
+extern HGLRC GLCONTEXT;
+#endif
+#endif // _GPU_INTERNALS_H
diff --git a/plugins/peopsxgl/gpucfg/main.c b/plugins/peopsxgl/gpucfg/main.c
index a5d5163b..67258fee 100644
--- a/plugins/peopsxgl/gpucfg/main.c
+++ b/plugins/peopsxgl/gpucfg/main.c
@@ -67,7 +67,7 @@ GtkWidget *window,
*btnBeautiful;
// Save values to the config file
-void on_btnSave_clicked( GtkObject *object, gpointer user_data ) {
+static void on_btnSave_clicked( GtkObject *object, gpointer user_data ) {
FILE *out;
out = fopen( "gpuPeopsMesaGL.cfg", "w+" );
@@ -134,7 +134,7 @@ void on_btnSave_clicked( GtkObject *object, gpointer user_data ) {
// Autoconfiguration callbacks
-void on_btnFast_clicked( GtkObject *object, gpointer user_data ) {
+static void on_btnFast_clicked( GtkObject *object, gpointer user_data ) {
gtk_spin_button_set_value( GTK_SPIN_BUTTON( spinXSize ), 640 );
gtk_spin_button_set_value( GTK_SPIN_BUTTON( spinYSize ), 480 );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( chkKeepRatio ), 0 );
@@ -165,7 +165,7 @@ void on_btnFast_clicked( GtkObject *object, gpointer user_data ) {
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( chkScreenSmoothing ), 0 );
}
-void on_btnBeautiful_clicked( GtkObject *object, gpointer user_data ) {
+static void on_btnBeautiful_clicked( GtkObject *object, gpointer user_data ) {
gtk_spin_button_set_value( GTK_SPIN_BUTTON( spinXSize ), 640 );
gtk_spin_button_set_value( GTK_SPIN_BUTTON( spinYSize ), 480 );
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( chkKeepRatio ), 0 );
@@ -198,19 +198,19 @@ void on_btnBeautiful_clicked( GtkObject *object, gpointer user_data ) {
// Callbacks used to toggle the sensitivity of some parts of the GUI
-void on_chkUseGameFixes_toggled( GtkObject *object, gpointer user_data ) {
+static void on_chkUseGameFixes_toggled( GtkObject *object, gpointer user_data ) {
gtk_widget_set_sensitive( tblGameFixes, gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( chkUseGameFixes ) ) );
}
-void on_chkUseFPSLimit_toggled( GtkObject *object, gpointer user_data ) {
+static void on_chkUseFPSLimit_toggled( GtkObject *object, gpointer user_data ) {
gtk_widget_set_sensitive( vboxFPSLimit, gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( chkUseFPSLimit ) ) );
}
-void on_radFPSLimitManual_toggled( GtkObject *object, gpointer user_data ) {
+static void on_radFPSLimitManual_toggled( GtkObject *object, gpointer user_data ) {
gtk_widget_set_sensitive( spinFPSLimit, gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( radFPSLimitManual ) ) );
}
-void on_chkScanLines_toggled( GtkObject *object, gpointer user_data ) {
+static void on_chkScanLines_toggled( GtkObject *object, gpointer user_data ) {
gtk_widget_set_sensitive( spinScanLinesBlend, gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( chkScanLines ) ) );
}
diff --git a/plugins/peopsxgl/key.c b/plugins/peopsxgl/key.c
index dba1c839..200446a2 100644
--- a/plugins/peopsxgl/key.c
+++ b/plugins/peopsxgl/key.c
@@ -1,177 +1,179 @@
-/***************************************************************************
- key.c - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
-#include "stdafx.h"
-
-#define _IN_KEY
-
-#include "externals.h"
-#include "menu.h"
-#include "texture.h"
-#include "draw.h"
-#include "fps.h"
-
-////////////////////////////////////////////////////////////////////////
-// KeyBoard handler stuff
-////////////////////////////////////////////////////////////////////////
-
-uint32_t ulKeybits = 0;
-
-////////////////////////////////////////////////////////////////////////
-// keyboard handler (LINUX)
-////////////////////////////////////////////////////////////////////////
-
-#define VK_INSERT 65379
-#define VK_HOME 65360
-#define VK_PRIOR 65365
-#define VK_NEXT 65366
-#define VK_END 65367
-#define VK_DEL 65535
-#define VK_F5 65474
-
-void GPUkeypressed(int keycode)
-{
-/* arrives via the input plugin, so who knows what thread you're in */
- switch(keycode)
- {
- case VK_F5:
- bSnapShot=1;
- break;
-
- case VK_INSERT:
- ulKeybits|=KEY_RESETTEXSTORE;
- if(iBlurBuffer) iBlurBuffer=0;
- else iBlurBuffer=1;
- break;
-
- case VK_DEL:
- if(ulKeybits&KEY_SHOWFPS)
- {
- ulKeybits&=~KEY_SHOWFPS;
- HideText();
- DestroyPic();
- }
- else
- {
- ulKeybits|=KEY_SHOWFPS;
- szDispBuf[0]=0;
- BuildDispMenu(0);
-
- }
- break;
-
- case VK_PRIOR: BuildDispMenu(-1); break;
- case VK_NEXT: BuildDispMenu( 1); break;
- case VK_END: SwitchDispMenu( 1); break;
- case VK_HOME: SwitchDispMenu(-1); break;
-#if defined (_MACGL)
- default: { void HandleKey(int keycode); HandleKey(keycode); };
-#endif
- }
-
-}
-
-void InitKeyHandler(void)
-{
-}
-
-void ExitKeyHandler(void)
-{
-}
-
-////////////////////////////////////////////////////////////////////////
-// reset stuff on special keyboard commands
-////////////////////////////////////////////////////////////////////////
-
-void ResetStuff(void)
-{
- ResetTextureArea(TRUE);
- ulKeybits&=~KEY_RESETTEXSTORE;
-
- if(ulKeybits&KEY_BLACKWHITE)
- {
- if(bUseFixes) {bUseFixes=FALSE;dwActFixes=0;}
- else {bUseFixes=TRUE; dwActFixes=dwCfgFixes;}
- SetExtGLFuncs();
- if(iFrameLimit==2) SetAutoFrameCap();
- ulKeybits&=~KEY_BLACKWHITE;
- }
-
- if(ulKeybits&KEY_RESETFILTER)
- {
- if(ulKeybits&KEY_STEPDOWN)
- iFilterType--;
- else iFilterType++;
- if(iFilterType>6) iFilterType=0;
- if(iFilterType<0) iFilterType=6;
- SetExtGLFuncs();
- ulKeybits&=~(KEY_RESETFILTER|KEY_STEPDOWN);
- BuildDispMenu(0);
- }
-
- if(ulKeybits&KEY_RESETOPAQUE)
- {
- bOpaquePass=!bOpaquePass;
- SetExtGLFuncs();
- ulKeybits&=~KEY_RESETOPAQUE;
- BuildDispMenu(0);
- }
-
- if(ulKeybits&KEY_RESETADVBLEND)
- {
- bAdvancedBlend=!bAdvancedBlend;
- SetExtGLFuncs();
- ulKeybits&=~KEY_RESETADVBLEND;
- BuildDispMenu(0);
- }
-
- if(ulKeybits&KEY_RESETDITHER)
- {
- bDrawDither=!bDrawDither;
- if(bDrawDither) glEnable(GL_DITHER);
- else glDisable(GL_DITHER);
- ulKeybits&=~KEY_RESETDITHER;
- BuildDispMenu(0);
- }
-
- if(ulKeybits & KEY_TOGGLEFBTEXTURE)
- {
- if(ulKeybits&KEY_STEPDOWN)
- iFrameTexType--;
- else iFrameTexType++;
- if(iFrameTexType>3) iFrameTexType=0;
- if(iFrameTexType<0) iFrameTexType=3;
- if(gTexFrameName!=0)
- glDeleteTextures(1, &gTexFrameName);
- gTexFrameName=0;
- ulKeybits&=~(KEY_TOGGLEFBTEXTURE|KEY_STEPDOWN);
- }
-
- if(ulKeybits & KEY_TOGGLEFBREAD)
- {
- if(ulKeybits&KEY_STEPDOWN)
- iFrameReadType--;
- else iFrameReadType++;
- if(iFrameReadType>4) iFrameReadType=0;
- if(iFrameReadType<0) iFrameReadType=4;
- if(iFrameReadType==4) bFullVRam=TRUE;
- else bFullVRam=FALSE;
- iRenderFVR=0;
- ulKeybits&=~(KEY_TOGGLEFBREAD|KEY_STEPDOWN);
- }
-}
+/***************************************************************************
+ key.c - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#include "stdafx.h"
+
+#define _IN_KEY
+
+#include "externals.h"
+#include "menu.h"
+#include "texture.h"
+#include "draw.h"
+#include "fps.h"
+#include "key.h"
+#include "psemu_plugin_defs.h"
+
+////////////////////////////////////////////////////////////////////////
+// KeyBoard handler stuff
+////////////////////////////////////////////////////////////////////////
+
+uint32_t ulKeybits = 0;
+
+////////////////////////////////////////////////////////////////////////
+// keyboard handler (LINUX)
+////////////////////////////////////////////////////////////////////////
+
+#define VK_INSERT 65379
+#define VK_HOME 65360
+#define VK_PRIOR 65365
+#define VK_NEXT 65366
+#define VK_END 65367
+#define VK_DEL 65535
+#define VK_F5 65474
+
+void GPUkeypressed(int keycode)
+{
+/* arrives via the input plugin, so who knows what thread you're in */
+ switch(keycode)
+ {
+ case VK_F5:
+ bSnapShot=1;
+ break;
+
+ case VK_INSERT:
+ ulKeybits|=KEY_RESETTEXSTORE;
+ if(iBlurBuffer) iBlurBuffer=0;
+ else iBlurBuffer=1;
+ break;
+
+ case VK_DEL:
+ if(ulKeybits&KEY_SHOWFPS)
+ {
+ ulKeybits&=~KEY_SHOWFPS;
+ HideText();
+ DestroyPic();
+ }
+ else
+ {
+ ulKeybits|=KEY_SHOWFPS;
+ szDispBuf[0]=0;
+ BuildDispMenu(0);
+
+ }
+ break;
+
+ case VK_PRIOR: BuildDispMenu(-1); break;
+ case VK_NEXT: BuildDispMenu( 1); break;
+ case VK_END: SwitchDispMenu( 1); break;
+ case VK_HOME: SwitchDispMenu(-1); break;
+#if defined (_MACGL)
+ default: { void HandleKey(int keycode); HandleKey(keycode); };
+#endif
+ }
+
+}
+
+void InitKeyHandler(void)
+{
+}
+
+void ExitKeyHandler(void)
+{
+}
+
+////////////////////////////////////////////////////////////////////////
+// reset stuff on special keyboard commands
+////////////////////////////////////////////////////////////////////////
+
+void ResetStuff(void)
+{
+ ResetTextureArea(TRUE);
+ ulKeybits&=~KEY_RESETTEXSTORE;
+
+ if(ulKeybits&KEY_BLACKWHITE)
+ {
+ if(bUseFixes) {bUseFixes=FALSE;dwActFixes=0;}
+ else {bUseFixes=TRUE; dwActFixes=dwCfgFixes;}
+ SetExtGLFuncs();
+ if(iFrameLimit==2) SetAutoFrameCap();
+ ulKeybits&=~KEY_BLACKWHITE;
+ }
+
+ if(ulKeybits&KEY_RESETFILTER)
+ {
+ if(ulKeybits&KEY_STEPDOWN)
+ iFilterType--;
+ else iFilterType++;
+ if(iFilterType>6) iFilterType=0;
+ if(iFilterType<0) iFilterType=6;
+ SetExtGLFuncs();
+ ulKeybits&=~(KEY_RESETFILTER|KEY_STEPDOWN);
+ BuildDispMenu(0);
+ }
+
+ if(ulKeybits&KEY_RESETOPAQUE)
+ {
+ bOpaquePass=!bOpaquePass;
+ SetExtGLFuncs();
+ ulKeybits&=~KEY_RESETOPAQUE;
+ BuildDispMenu(0);
+ }
+
+ if(ulKeybits&KEY_RESETADVBLEND)
+ {
+ bAdvancedBlend=!bAdvancedBlend;
+ SetExtGLFuncs();
+ ulKeybits&=~KEY_RESETADVBLEND;
+ BuildDispMenu(0);
+ }
+
+ if(ulKeybits&KEY_RESETDITHER)
+ {
+ bDrawDither=!bDrawDither;
+ if(bDrawDither) glEnable(GL_DITHER);
+ else glDisable(GL_DITHER);
+ ulKeybits&=~KEY_RESETDITHER;
+ BuildDispMenu(0);
+ }
+
+ if(ulKeybits & KEY_TOGGLEFBTEXTURE)
+ {
+ if(ulKeybits&KEY_STEPDOWN)
+ iFrameTexType--;
+ else iFrameTexType++;
+ if(iFrameTexType>3) iFrameTexType=0;
+ if(iFrameTexType<0) iFrameTexType=3;
+ if(gTexFrameName!=0)
+ glDeleteTextures(1, &gTexFrameName);
+ gTexFrameName=0;
+ ulKeybits&=~(KEY_TOGGLEFBTEXTURE|KEY_STEPDOWN);
+ }
+
+ if(ulKeybits & KEY_TOGGLEFBREAD)
+ {
+ if(ulKeybits&KEY_STEPDOWN)
+ iFrameReadType--;
+ else iFrameReadType++;
+ if(iFrameReadType>4) iFrameReadType=0;
+ if(iFrameReadType<0) iFrameReadType=4;
+ if(iFrameReadType==4) bFullVRam=TRUE;
+ else bFullVRam=FALSE;
+ iRenderFVR=0;
+ ulKeybits&=~(KEY_TOGGLEFBREAD|KEY_STEPDOWN);
+ }
+}
diff --git a/plugins/peopsxgl/prim.c b/plugins/peopsxgl/prim.c
index 323b1d81..3ee37c27 100644
--- a/plugins/peopsxgl/prim.c
+++ b/plugins/peopsxgl/prim.c
@@ -1,21 +1,21 @@
-/***************************************************************************
- prim.c - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
+/***************************************************************************
+ prim.c - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
#include "stdafx.h"
#define _IN_PRIMDRAW
@@ -25,6 +25,7 @@
#include "draw.h"
#include "soft.h"
#include "texture.h"
+#include "prim.h"
////////////////////////////////////////////////////////////////////////
// defines
@@ -37,77 +38,77 @@
// globals
////////////////////////////////////////////////////////////////////////
-BOOL bDrawTextured; // current active drawing states
+BOOL bDrawTextured; // current active drawing states
BOOL bDrawSmoothShaded;
BOOL bOldSmoothShaded;
BOOL bDrawNonShaded;
BOOL bDrawMultiPass;
int iOffscreenDrawing;
int iDrawnSomething=0;
-
-BOOL bRenderFrontBuffer=FALSE; // flag for front buffer rendering
-
-GLubyte ubGloAlpha; // texture alpha
-GLubyte ubGloColAlpha; // color alpha
-int iFilterType; // type of filter
-BOOL bFullVRam=FALSE; // sign for tex win
-BOOL bDrawDither; // sign for dither
-BOOL bUseMultiPass; // sign for multi pass
-GLuint gTexName; // binded texture
-BOOL bTexEnabled; // texture enable flag
-BOOL bBlendEnable; // blend enable flag
-PSXRect_t xrUploadArea; // rect to upload
-PSXRect_t xrUploadAreaIL; // rect to upload
-PSXRect_t xrUploadAreaRGB24; // rect to upload rgb24
-int iSpriteTex=0; // flag for "hey, it's a sprite"
-unsigned short usMirror; // mirror, mirror on the wall
-
-BOOL bNeedUploadAfter=FALSE; // sign for uploading in next frame
-BOOL bNeedUploadTest=FALSE; // sign for upload test
-BOOL bUsingTWin=FALSE; // tex win active flag
-BOOL bUsingMovie=FALSE; // movie active flag
-PSXRect_t xrMovieArea; // rect for movie upload
-short sSprite_ux2; // needed for sprire adjust
-short sSprite_vy2; //
-uint32_t ulOLDCOL=0; // active color
-uint32_t ulClutID; // clut
-
-uint32_t dwCfgFixes; // game fixes
-uint32_t dwActFixes=0;
+
+BOOL bRenderFrontBuffer=FALSE; // flag for front buffer rendering
+
+GLubyte ubGloAlpha; // texture alpha
+GLubyte ubGloColAlpha; // color alpha
+int iFilterType; // type of filter
+BOOL bFullVRam=FALSE; // sign for tex win
+BOOL bDrawDither; // sign for dither
+BOOL bUseMultiPass; // sign for multi pass
+GLuint gTexName; // binded texture
+BOOL bTexEnabled; // texture enable flag
+BOOL bBlendEnable; // blend enable flag
+PSXRect_t xrUploadArea; // rect to upload
+PSXRect_t xrUploadAreaIL; // rect to upload
+PSXRect_t xrUploadAreaRGB24; // rect to upload rgb24
+int iSpriteTex=0; // flag for "hey, it's a sprite"
+unsigned short usMirror; // mirror, mirror on the wall
+
+BOOL bNeedUploadAfter=FALSE; // sign for uploading in next frame
+BOOL bNeedUploadTest=FALSE; // sign for upload test
+BOOL bUsingTWin=FALSE; // tex win active flag
+BOOL bUsingMovie=FALSE; // movie active flag
+PSXRect_t xrMovieArea; // rect for movie upload
+short sSprite_ux2; // needed for sprire adjust
+short sSprite_vy2; //
+uint32_t ulOLDCOL=0; // active color
+uint32_t ulClutID; // clut
+
+uint32_t dwCfgFixes; // game fixes
+uint32_t dwActFixes=0;
uint32_t dwEmuFixes=0;
-BOOL bUseFixes;
+BOOL bUseFixes;
-int drawX,drawY,drawW,drawH; // offscreen drawing checkers
+int drawX,drawY,drawW,drawH; // offscreen drawing checkers
short sxmin,sxmax,symin,symax;
////////////////////////////////////////////////////////////////////////
// Update global TP infos
////////////////////////////////////////////////////////////////////////
-void UpdateGlobalTP(unsigned short gdata)
+static void UpdateGlobalTP(unsigned short gdata)
{
GlobalTextAddrX = (gdata << 6) & 0x3c0;
- if(iGPUHeight==1024) // ZN mode
- {
- if(dwGPUVersion==2) // very special zn gpu
- {
- GlobalTextAddrY =((gdata & 0x60 ) << 3);
- GlobalTextIL =(gdata & 0x2000) >> 13;
- GlobalTextABR = (unsigned short)((gdata >> 7) & 0x3);
- GlobalTextTP = (gdata >> 9) & 0x3;
- if(GlobalTextTP==3) GlobalTextTP=2;
- GlobalTexturePage = (GlobalTextAddrX>>6)+(GlobalTextAddrY>>4);
- usMirror =0;
- STATUSREG = (STATUSREG & 0xffffe000 ) | (gdata & 0x1fff );
- return;
- }
- else // "enhanced" psx gpu
- {
- GlobalTextAddrY = (unsigned short)(((gdata << 4) & 0x100) | ((gdata >> 2) & 0x200));
- }
- }
- else GlobalTextAddrY = (gdata << 4) & 0x100; // "normal" psx gpu
+ if(iGPUHeight==1024) // ZN mode
+ {
+ if(dwGPUVersion==2) // very special zn gpu
+ {
+ GlobalTextAddrY =((gdata & 0x60 ) << 3);
+ GlobalTextIL =(gdata & 0x2000) >> 13;
+ GlobalTextABR = (unsigned short)((gdata >> 7) & 0x3);
+ GlobalTextTP = (gdata >> 9) & 0x3;
+ if(GlobalTextTP==3) GlobalTextTP=2;
+ GlobalTexturePage = (GlobalTextAddrX>>6)+(GlobalTextAddrY>>4);
+ usMirror =0;
+ STATUSREG = (STATUSREG & 0xffffe000 ) | (gdata & 0x1fff );
+ return;
+ }
+ else // "enhanced" psx gpu
+ {
+ GlobalTextAddrY = (unsigned short)(((gdata << 4) & 0x100) | ((gdata >> 2) & 0x200));
+ }
+ }
+ else GlobalTextAddrY = (gdata << 4) & 0x100; // "normal" psx gpu
usMirror=gdata&0x3000;
@@ -121,7 +122,7 @@ void UpdateGlobalTP(unsigned short gdata)
STATUSREG|=(gdata & 0x07ff); // set the necessary bits
}
-unsigned int DoubleBGR2RGB (unsigned int BGR)
+static unsigned int DoubleBGR2RGB (unsigned int BGR)
{
unsigned int ebx,eax,edx;
@@ -137,7 +138,7 @@ unsigned int DoubleBGR2RGB (unsigned int BGR)
return (ebx|eax|edx);
}
-unsigned short BGR24to16 (uint32_t BGR)
+static unsigned short BGR24to16 (uint32_t BGR)
{
return ((BGR>>3)&0x1f)|((BGR&0xf80000)>>9)|((BGR&0xf800)>>6);
}
@@ -146,7 +147,7 @@ unsigned short BGR24to16 (uint32_t BGR)
// OpenGL primitive drawing commands
////////////////////////////////////////////////////////////////////////
-__inline void PRIMdrawTexturedQuad(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawTexturedQuad(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3, OGLVertex* vertex4)
{
glBegin(GL_TRIANGLE_STRIP);
@@ -166,7 +167,7 @@ __inline void PRIMdrawTexturedQuad(OGLVertex* vertex1, OGLVertex* vertex2,
/////////////////////////////////////////////////////////
-__inline void PRIMdrawTexturedTri(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawTexturedTri(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3)
{
glBegin(GL_TRIANGLES);
@@ -183,7 +184,7 @@ __inline void PRIMdrawTexturedTri(OGLVertex* vertex1, OGLVertex* vertex2,
/////////////////////////////////////////////////////////
-__inline void PRIMdrawTexGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawTexGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3)
{
glBegin(GL_TRIANGLES);
@@ -204,7 +205,7 @@ __inline void PRIMdrawTexGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
/////////////////////////////////////////////////////////
-__inline void PRIMdrawTexGouraudTriColorQuad(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawTexGouraudTriColorQuad(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3, OGLVertex* vertex4)
{
glBegin(GL_TRIANGLE_STRIP);
@@ -228,7 +229,7 @@ __inline void PRIMdrawTexGouraudTriColorQuad(OGLVertex* vertex1, OGLVertex* vert
/////////////////////////////////////////////////////////
-__inline void PRIMdrawTri(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3)
+static __inline void PRIMdrawTri(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* vertex3)
{
glBegin(GL_TRIANGLES);
glVertex3fv(&vertex1->x);
@@ -239,7 +240,7 @@ __inline void PRIMdrawTri(OGLVertex* vertex1, OGLVertex* vertex2, OGLVertex* ver
/////////////////////////////////////////////////////////
-__inline void PRIMdrawTri2(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawTri2(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3, OGLVertex* vertex4)
{
glBegin(GL_TRIANGLE_STRIP);
@@ -252,7 +253,7 @@ __inline void PRIMdrawTri2(OGLVertex* vertex1, OGLVertex* vertex2,
/////////////////////////////////////////////////////////
-__inline void PRIMdrawGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3)
{
glBegin(GL_TRIANGLES);
@@ -269,7 +270,7 @@ __inline void PRIMdrawGouraudTriColor(OGLVertex* vertex1, OGLVertex* vertex2,
/////////////////////////////////////////////////////////
-__inline void PRIMdrawGouraudTri2Color(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawGouraudTri2Color(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3, OGLVertex* vertex4)
{
glBegin(GL_TRIANGLE_STRIP);
@@ -289,7 +290,7 @@ __inline void PRIMdrawGouraudTri2Color(OGLVertex* vertex1, OGLVertex* vertex2,
/////////////////////////////////////////////////////////
-__inline void PRIMdrawFlatLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVertex* vertex3, OGLVertex* vertex4)
+static __inline void PRIMdrawFlatLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVertex* vertex3, OGLVertex* vertex4)
{
glBegin(GL_QUADS);
@@ -304,7 +305,7 @@ __inline void PRIMdrawFlatLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVertex*
/////////////////////////////////////////////////////////
-__inline void PRIMdrawGouraudLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVertex* vertex3, OGLVertex* vertex4)
+static __inline void PRIMdrawGouraudLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVertex* vertex3, OGLVertex* vertex4)
{
glBegin(GL_QUADS);
@@ -324,7 +325,7 @@ __inline void PRIMdrawGouraudLine(OGLVertex* vertex1, OGLVertex* vertex2,OGLVert
/////////////////////////////////////////////////////////
-__inline void PRIMdrawQuad(OGLVertex* vertex1, OGLVertex* vertex2,
+static __inline void PRIMdrawQuad(OGLVertex* vertex1, OGLVertex* vertex2,
OGLVertex* vertex3, OGLVertex* vertex4)
{
glBegin(GL_QUADS);
@@ -354,12 +355,12 @@ SemiTransParams TransSets[4]=
{GL_SRC_ALPHA,GL_SRC_ALPHA, 127},
{GL_ONE, GL_ONE, 255},
{GL_ZERO, GL_ONE_MINUS_SRC_COLOR,255},
- {GL_ONE_MINUS_SRC_ALPHA,GL_ONE, 192}
+ {GL_ONE_MINUS_SRC_ALPHA,GL_ONE, 192}
};
////////////////////////////////////////////////////////////////////////
-void SetSemiTrans(void)
+static void SetSemiTrans(void)
{
/*
* 0.5 x B + 0.5 x F
@@ -372,7 +373,7 @@ void SetSemiTrans(void)
{
if(bBlendEnable)
{glDisable(GL_BLEND);bBlendEnable=FALSE;} // -> don't wanna blend
- ubGloAlpha=ubGloColAlpha=255; // -> full alpha
+ ubGloAlpha=ubGloColAlpha=255; // -> full alpha
return; // -> and bye
}
@@ -388,7 +389,7 @@ void SetSemiTrans(void)
{
obm1=TransSets[GlobalTextABR].srcFac;
obm2=TransSets[GlobalTextABR].dstFac;
- glBlendFunc(obm1,obm2); // set blend func
+ glBlendFunc(obm1,obm2); // set blend func
}
else
if(TransSets[GlobalTextABR].dstFac !=GL_ONE_MINUS_SRC_COLOR)
@@ -397,19 +398,19 @@ void SetSemiTrans(void)
glBlendEquationEXTEx(FUNC_ADD_EXT);
obm1=TransSets[GlobalTextABR].srcFac;
obm2=TransSets[GlobalTextABR].dstFac;
- glBlendFunc(obm1,obm2); // set blend func
+ glBlendFunc(obm1,obm2); // set blend func
}
else
{
glBlendEquationEXTEx(FUNC_REVERSESUBTRACT_EXT);
obm1=TransSets[GlobalTextABR].srcFac;
obm2=TransSets[GlobalTextABR].dstFac;
- glBlendFunc(GL_ONE,GL_ONE); // set blend func
+ glBlendFunc(GL_ONE,GL_ONE); // set blend func
}
}
}
-void SetScanTrans(void) // blending for scan lines
+void SetScanTrans(void) // blending for scan lines
{
if(glBlendEquationEXTEx!=NULL)
{
@@ -419,10 +420,10 @@ void SetScanTrans(void) // blending for scan line
obm1=TransSets[0].srcFac;
obm2=TransSets[0].dstFac;
- glBlendFunc(obm1,obm2); // set blend func
+ glBlendFunc(obm1,obm2); // set blend func
}
-void SetScanTexTrans(void) // blending for scan mask texture
+void SetScanTexTrans(void) // blending for scan mask texture
{
if(glBlendEquationEXTEx!=NULL)
{
@@ -432,7 +433,7 @@ void SetScanTexTrans(void) // blending for scan mask
obm1=TransSets[2].srcFac;
obm2=TransSets[2].dstFac;
- glBlendFunc(obm1,obm2); // set blend func
+ glBlendFunc(obm1,obm2); // set blend func
}
////////////////////////////////////////////////////////////////////////
@@ -471,7 +472,7 @@ SemiTransParams MultiColTransSets[4]=
////////////////////////////////////////////////////////////////////////
-void SetSemiTransMulti(int Pass)
+static void SetSemiTransMulti(int Pass)
{
static GLenum bm1=GL_ZERO;
static GLenum bm2=GL_ONE;
@@ -512,11 +513,11 @@ void SetSemiTransMulti(int Pass)
}
if(!bBlendEnable)
- {glEnable(GL_BLEND);bBlendEnable=TRUE;} // wanna blend
+ {glEnable(GL_BLEND);bBlendEnable=TRUE;} // wanna blend
if(bm1!=obm1 || bm2!=obm2)
{
- glBlendFunc(bm1,bm2); // set blend func
+ glBlendFunc(bm1,bm2); // set blend func
obm1=bm1;obm2=bm2;
}
}
@@ -525,7 +526,7 @@ void SetSemiTransMulti(int Pass)
// Set several rendering stuff including blending
////////////////////////////////////////////////////////////////////////
-__inline void SetZMask3O(void)
+static __inline void SetZMask3O(void)
{
if(iUseMask && DrawSemiTrans && !iSetMask)
{
@@ -534,7 +535,7 @@ __inline void SetZMask3O(void)
}
}
-__inline void SetZMask3(void)
+static __inline void SetZMask3(void)
{
if(iUseMask)
{
@@ -548,7 +549,7 @@ __inline void SetZMask3(void)
}
}
-__inline void SetZMask3NT(void)
+static __inline void SetZMask3NT(void)
{
if(iUseMask)
{
@@ -564,7 +565,7 @@ __inline void SetZMask3NT(void)
////////////////////////////////////////////////////////////////////////
-__inline void SetZMask4O(void)
+static __inline void SetZMask4O(void)
{
if(iUseMask && DrawSemiTrans && !iSetMask)
{
@@ -573,7 +574,7 @@ __inline void SetZMask4O(void)
}
}
-__inline void SetZMask4(void)
+static __inline void SetZMask4(void)
{
if(iUseMask)
{
@@ -587,7 +588,7 @@ __inline void SetZMask4(void)
}
}
-__inline void SetZMask4NT(void)
+static __inline void SetZMask4NT(void)
{
if(iUseMask)
{
@@ -600,29 +601,29 @@ __inline void SetZMask4NT(void)
}
}
}
-
-__inline void SetZMask4SP(void)
-{
- if(iUseMask)
- {
- if(iSetMask==1)
- {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
- else
- {
- if(bCheckMask)
- {
- vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
- gl_z+=0.00004f;
- }
- else
- {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
- }
- }
-}
-
+
+static __inline void SetZMask4SP(void)
+{
+ if(iUseMask)
+ {
+ if(iSetMask==1)
+ {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
+ else
+ {
+ if(bCheckMask)
+ {
+ vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=gl_z;
+ gl_z+=0.00004f;
+ }
+ else
+ {vertex[0].z=vertex[1].z=vertex[2].z=vertex[3].z=0.95f;}
+ }
+ }
+}
+
////////////////////////////////////////////////////////////////////////
-__inline void SetRenderState(uint32_t DrawAttributes)
+static __inline void SetRenderState(uint32_t DrawAttributes)
{
bDrawNonShaded = (SHADETEXBIT(DrawAttributes)) ? TRUE : FALSE;
DrawSemiTrans = (SEMITRANSBIT(DrawAttributes)) ? TRUE : FALSE;
@@ -630,7 +631,7 @@ __inline void SetRenderState(uint32_t DrawAttributes)
////////////////////////////////////////////////////////////////////////
-__inline void SetRenderColor(uint32_t DrawAttributes)
+static __inline void SetRenderColor(uint32_t DrawAttributes)
{
if(bDrawNonShaded) {g_m1=g_m2=g_m3=128;}
else
@@ -643,7 +644,7 @@ __inline void SetRenderColor(uint32_t DrawAttributes)
////////////////////////////////////////////////////////////////////////
-void SetRenderMode(uint32_t DrawAttributes, BOOL bSCol)
+static void SetRenderMode(uint32_t DrawAttributes, BOOL bSCol)
{
if((bUseMultiPass) && (bDrawTextured) && !(bDrawNonShaded))
{bDrawMultiPass = TRUE; SetSemiTransMulti(0);}
@@ -671,24 +672,24 @@ void SetRenderMode(uint32_t DrawAttributes, BOOL bSCol)
if((dwActFixes&4) && ((DrawAttributes&0x00ffffff)==0))
DrawAttributes|=0x007f7f7f;
- if(bDrawNonShaded) // -> non shaded?
+ if(bDrawNonShaded) // -> non shaded?
{
- if(bGLBlend) vertex[0].c.lcol=0x7f7f7f; // --> solid color...
+ if(bGLBlend) vertex[0].c.lcol=0x7f7f7f; // --> solid color...
else vertex[0].c.lcol=0xffffff;
}
else // -> shaded?
{
- if(!bUseMultiPass && !bGLBlend) // --> given color...
+ if(!bUseMultiPass && !bGLBlend) // --> given color...
vertex[0].c.lcol=DoubleBGR2RGB(DrawAttributes);
else vertex[0].c.lcol=DrawAttributes;
}
- vertex[0].c.col[3]=ubGloAlpha; // -> set color with
+ vertex[0].c.col[3]=ubGloAlpha; // -> set color with
SETCOL(vertex[0]); // texture alpha
}
- if(bDrawSmoothShaded!=bOldSmoothShaded) // shading changed?
+ if(bDrawSmoothShaded!=bOldSmoothShaded) // shading changed?
{
- if(bDrawSmoothShaded) glShadeModel(GL_SMOOTH); // -> set actual shading
+ if(bDrawSmoothShaded) glShadeModel(GL_SMOOTH); // -> set actual shading
else glShadeModel(GL_FLAT);
bOldSmoothShaded=bDrawSmoothShaded;
}
@@ -698,9 +699,9 @@ void SetRenderMode(uint32_t DrawAttributes, BOOL bSCol)
// Set Opaque multipass color
////////////////////////////////////////////////////////////////////////
-void SetOpaqueColor(uint32_t DrawAttributes)
+static void SetOpaqueColor(uint32_t DrawAttributes)
{
- if(bDrawNonShaded) return; // no shading? bye
+ if(bDrawNonShaded) return; // no shading? bye
DrawAttributes=DoubleBGR2RGB(DrawAttributes); // multipass is just half color, so double it on opaque pass
vertex[0].c.lcol=DrawAttributes|0xff000000;
@@ -711,7 +712,7 @@ void SetOpaqueColor(uint32_t DrawAttributes)
// Fucking stupid screen coord checking
////////////////////////////////////////////////////////////////////////
-BOOL ClipVertexListScreen(void)
+static BOOL ClipVertexListScreen(void)
{
if (lx0 >= PSXDisplay.DisplayEnd.x) goto NEXTSCRTEST;
if (ly0 >= PSXDisplay.DisplayEnd.y) goto NEXTSCRTEST;
@@ -733,7 +734,7 @@ NEXTSCRTEST:
////////////////////////////////////////////////////////////////////////
-BOOL bDrawOffscreenFront(void)
+static BOOL bDrawOffscreenFront(void)
{
if(sxmin < PSXDisplay.DisplayPosition.x) return FALSE; // must be complete in front
if(symin < PSXDisplay.DisplayPosition.y) return FALSE;
@@ -742,7 +743,7 @@ BOOL bDrawOffscreenFront(void)
return TRUE;
}
-BOOL bOnePointInFront(void)
+static BOOL bOnePointInFront(void)
{
if(sxmax< PSXDisplay.DisplayPosition.x)
return FALSE;
@@ -760,7 +761,7 @@ BOOL bOnePointInFront(void)
}
-BOOL bOnePointInBack(void)
+static BOOL bOnePointInBack(void)
{
if(sxmax< PreviousPSXDisplay.DisplayPosition.x)
return FALSE;
@@ -777,7 +778,7 @@ BOOL bOnePointInBack(void)
return TRUE;
}
-BOOL bDrawOffscreen4(void)
+static BOOL bDrawOffscreen4(void)
{
BOOL bFront;short sW,sH;
@@ -832,12 +833,12 @@ BOOL bDrawOffscreen4(void)
vertex[2].y=ly2 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
vertex[3].y=ly3 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
- if(iOffscreenDrawing==4 && !(dwActFixes&1)) // -> frontbuffer wanted
+ if(iOffscreenDrawing==4 && !(dwActFixes&1)) // -> frontbuffer wanted
{
bRenderFrontBuffer=TRUE;
//return TRUE;
}
- return bFullVRam; // -> but no od
+ return bFullVRam; // -> but no od
}
return TRUE;
@@ -845,7 +846,7 @@ BOOL bDrawOffscreen4(void)
////////////////////////////////////////////////////////////////////////
-BOOL bDrawOffscreen3(void)
+static BOOL bDrawOffscreen3(void)
{
BOOL bFront;short sW,sH;
@@ -858,7 +859,7 @@ BOOL bDrawOffscreen3(void)
symin=min(ly0,min(ly1,ly2));
if(symin>drawH) return FALSE;
- if(PSXDisplay.Disabled) return TRUE; // disabled? ever
+ if(PSXDisplay.Disabled) return TRUE; // disabled? ever
if(iOffscreenDrawing==1) return bFullVRam;
@@ -876,7 +877,7 @@ BOOL bDrawOffscreen3(void)
if(bFront)
{
- if(PSXDisplay.InterlacedTest) return bFullVRam; // -> ok, no need for adjust
+ if(PSXDisplay.InterlacedTest) return bFullVRam; // -> ok, no need for adjust
vertex[0].x=lx0 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
vertex[1].x=lx1 - PSXDisplay.DisplayPosition.x+PreviousPSXDisplay.Range.x0;
@@ -885,13 +886,13 @@ BOOL bDrawOffscreen3(void)
vertex[1].y=ly1 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
vertex[2].y=ly2 - PSXDisplay.DisplayPosition.y+PreviousPSXDisplay.Range.y0;
- if(iOffscreenDrawing==4) // -> frontbuffer wanted
+ if(iOffscreenDrawing==4) // -> frontbuffer wanted
{
bRenderFrontBuffer=TRUE;
// return TRUE;
}
- return bFullVRam; // -> but no od
+ return bFullVRam; // -> but no od
}
return TRUE;
@@ -947,7 +948,7 @@ BOOL CheckAgainstScreen(short imageX0,short imageY0,short imageX1,short imageY1)
{
imageX1 += imageX0;
imageY1 += imageY0;
-
+
if (imageX0 < PreviousPSXDisplay.DisplayPosition.x)
xrUploadArea.x0 = PreviousPSXDisplay.DisplayPosition.x;
else
@@ -1099,7 +1100,7 @@ void PrepareFullScreenUpload (int Position)
// lClearOnSwap=0;
}
else
- if(PSXDisplay.Interlaced && PreviousPSXDisplay.RGB24<2) // in interlaced mode we upload at least two full frames (GT1 menu)
+ if(PSXDisplay.Interlaced && PreviousPSXDisplay.RGB24<2) // in interlaced mode we upload at least two full frames (GT1 menu)
{
PreviousPSXDisplay.RGB24++;
}
@@ -1152,92 +1153,90 @@ void PrepareFullScreenUpload (int Position)
// Upload screen (MDEC and such)
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-
-unsigned char * LoadDirectMovieFast(void);
-
-void UploadScreenEx(int Position)
-{
- short ya,yb,xa,xb,x, y, YStep, XStep, U, UStep,ux[4],vy[4];
-
- if(!PSXDisplay.DisplayMode.x) return;
- if(!PSXDisplay.DisplayMode.y) return;
-
- glDisable(GL_SCISSOR_TEST);
- glShadeModel(GL_FLAT);
- bOldSmoothShaded=FALSE;
- glDisable(GL_BLEND);
- bBlendEnable=FALSE;
- glDisable(GL_TEXTURE_2D);
- bTexEnabled=FALSE;
- glDisable(GL_ALPHA_TEST);
-
- glPixelZoom(((float)rRatioRect.right)/((float)PSXDisplay.DisplayMode.x),
- -1.0f*(((float)rRatioRect.bottom)/((float)PSXDisplay.DisplayMode.y)));
-
- //----------------------------------------------------//
-
- YStep = 256; // max texture size
- XStep = 256;
- UStep = (PSXDisplay.RGB24 ? 128 : 0);
- ya = xrUploadArea.y0;
- yb = xrUploadArea.y1;
- xa = xrUploadArea.x0;
- xb = xrUploadArea.x1;
-
- for(y=ya;y<=yb;y+=YStep) // loop y
- {
- U = 0;
- for(x=xa;x<=xb;x+=XStep) // loop x
- {
- ly0 = ly1 = y; // -> get y coords
- ly2 = y + YStep;
- if (ly2 > yb) ly2 = yb;
- ly3 = ly2;
-
- lx0 = lx3 = x; // -> get x coords
- lx1 = x + XStep;
- if (lx1 > xb) lx1 = xb;
-
- lx2 = lx1;
-
- ux[0]=ux[3]=(xa - x); // -> set tex x coords
- if (ux[0] < 0) ux[0]=ux[3]=0;
- ux[2]=ux[1]=(xb - x);
- if (ux[2] > 256) ux[2]=ux[1]=256;
-
- vy[0]=vy[1]=(ya - y); // -> set tex y coords
- if (vy[0] < 0) vy[0]=vy[1]=0;
- vy[2]=vy[3]=(yb - y);
- if (vy[2] > 256) vy[2]=vy[3]=256;
-
- if ((ux[0] >= ux[2]) || // -> cheaters never win...
- (vy[0] >= vy[2])) continue; // (but winners always cheat...)
-
- xrMovieArea.x0=lx0+U; xrMovieArea.y0=ly0;
- xrMovieArea.x1=lx2+U; xrMovieArea.y1=ly2;
-
- offsetScreenUpload(Position);
-
- glRasterPos2f(vertex[0].x,vertex[0].y);
-
- glDrawPixels(xrMovieArea.x1-xrMovieArea.x0,
- xrMovieArea.y1-xrMovieArea.y0,
- GL_RGBA,GL_UNSIGNED_BYTE,
- LoadDirectMovieFast());
-
- U+=UStep;
- }
- }
-
- //----------------------------------------------------//
-
- glPixelZoom(1.0F,1.0F);
-
- glEnable(GL_ALPHA_TEST);
- glEnable(GL_SCISSOR_TEST);
-}
-
-////////////////////////////////////////////////////////////////////////
+
+static void UploadScreenEx(int Position)
+{
+ short ya,yb,xa,xb,x, y, YStep, XStep, U, UStep,ux[4],vy[4];
+
+ if(!PSXDisplay.DisplayMode.x) return;
+ if(!PSXDisplay.DisplayMode.y) return;
+
+ glDisable(GL_SCISSOR_TEST);
+ glShadeModel(GL_FLAT);
+ bOldSmoothShaded=FALSE;
+ glDisable(GL_BLEND);
+ bBlendEnable=FALSE;
+ glDisable(GL_TEXTURE_2D);
+ bTexEnabled=FALSE;
+ glDisable(GL_ALPHA_TEST);
+
+ glPixelZoom(((float)rRatioRect.right)/((float)PSXDisplay.DisplayMode.x),
+ -1.0f*(((float)rRatioRect.bottom)/((float)PSXDisplay.DisplayMode.y)));
+
+ //----------------------------------------------------//
+
+ YStep = 256; // max texture size
+ XStep = 256;
+ UStep = (PSXDisplay.RGB24 ? 128 : 0);
+ ya = xrUploadArea.y0;
+ yb = xrUploadArea.y1;
+ xa = xrUploadArea.x0;
+ xb = xrUploadArea.x1;
+
+ for(y=ya;y<=yb;y+=YStep) // loop y
+ {
+ U = 0;
+ for(x=xa;x<=xb;x+=XStep) // loop x
+ {
+ ly0 = ly1 = y; // -> get y coords
+ ly2 = y + YStep;
+ if (ly2 > yb) ly2 = yb;
+ ly3 = ly2;
+
+ lx0 = lx3 = x; // -> get x coords
+ lx1 = x + XStep;
+ if (lx1 > xb) lx1 = xb;
+
+ lx2 = lx1;
+
+ ux[0]=ux[3]=(xa - x); // -> set tex x coords
+ if (ux[0] < 0) ux[0]=ux[3]=0;
+ ux[2]=ux[1]=(xb - x);
+ if (ux[2] > 256) ux[2]=ux[1]=256;
+
+ vy[0]=vy[1]=(ya - y); // -> set tex y coords
+ if (vy[0] < 0) vy[0]=vy[1]=0;
+ vy[2]=vy[3]=(yb - y);
+ if (vy[2] > 256) vy[2]=vy[3]=256;
+
+ if ((ux[0] >= ux[2]) || // -> cheaters never win...
+ (vy[0] >= vy[2])) continue; // (but winners always cheat...)
+
+ xrMovieArea.x0=lx0+U; xrMovieArea.y0=ly0;
+ xrMovieArea.x1=lx2+U; xrMovieArea.y1=ly2;
+
+ offsetScreenUpload(Position);
+
+ glRasterPos2f(vertex[0].x,vertex[0].y);
+
+ glDrawPixels(xrMovieArea.x1-xrMovieArea.x0,
+ xrMovieArea.y1-xrMovieArea.y0,
+ GL_RGBA,GL_UNSIGNED_BYTE,
+ LoadDirectMovieFast());
+
+ U+=UStep;
+ }
+ }
+
+ //----------------------------------------------------//
+
+ glPixelZoom(1.0F,1.0F);
+
+ glEnable(GL_ALPHA_TEST);
+ glEnable(GL_SCISSOR_TEST);
+}
+
+////////////////////////////////////////////////////////////////////////
void UploadScreen(int Position)
{
@@ -1246,26 +1245,26 @@ void UploadScreen(int Position)
if(xrUploadArea.x0>1023) xrUploadArea.x0=1023;
if(xrUploadArea.x1>1024) xrUploadArea.x1=1024;
- if(xrUploadArea.y0>iGPUHeightMask) xrUploadArea.y0=iGPUHeightMask;
- if(xrUploadArea.y1>iGPUHeight) xrUploadArea.y1=iGPUHeight;
+ if(xrUploadArea.y0>iGPUHeightMask) xrUploadArea.y0=iGPUHeightMask;
+ if(xrUploadArea.y1>iGPUHeight) xrUploadArea.y1=iGPUHeight;
if(xrUploadArea.x0==xrUploadArea.x1) return;
if(xrUploadArea.y0==xrUploadArea.y1) return;
if(PSXDisplay.Disabled && iOffscreenDrawing<4) return;
-
- iDrawnSomething = 2;
- iLastRGB24=PSXDisplay.RGB24+1;
-
- if(bSkipNextFrame) return;
-
- if(dwActFixes & 2) {UploadScreenEx(Position);return;}
+
+ iDrawnSomething = 2;
+ iLastRGB24=PSXDisplay.RGB24+1;
+
+ if(bSkipNextFrame) return;
+
+ if(dwActFixes & 2) {UploadScreenEx(Position);return;}
bUsingMovie = TRUE;
- bDrawTextured = TRUE; // just doing textures
+ bDrawTextured = TRUE; // just doing textures
bDrawSmoothShaded = FALSE;
- if(bGLBlend) vertex[0].c.lcol=0xff7f7f7f; // set solid col
+ if(bGLBlend) vertex[0].c.lcol=0xff7f7f7f; // set solid col
else vertex[0].c.lcol=0xffffffff;
SETCOL(vertex[0]);
@@ -1281,10 +1280,10 @@ void UploadScreen(int Position)
xa=xrUploadArea.x0;
xb=xrUploadArea.x1;
- for(y=ya;y<=yb;y+=YStep) // loop y
+ for(y=ya;y<=yb;y+=YStep) // loop y
{
U = 0;
- for(x=xa;x<=xb;x+=XStep) // loop x
+ for(x=xa;x<=xb;x+=XStep) // loop x
{
ly0 = ly1 = y; // -> get y coords
ly2 = y + YStep;
@@ -1297,17 +1296,17 @@ void UploadScreen(int Position)
lx2 = lx1;
- ux[0]=ux[3]=(xa - x); // -> set tex x coords
+ ux[0]=ux[3]=(xa - x); // -> set tex x coords
if (ux[0] < 0) ux[0]=ux[3]=0;
ux[2]=ux[1]=(xb - x);
if (ux[2] > 256) ux[2]=ux[1]=256;
- vy[0]=vy[1]=(ya - y); // -> set tex y coords
+ vy[0]=vy[1]=(ya - y); // -> set tex y coords
if (vy[0] < 0) vy[0]=vy[1]=0;
vy[2]=vy[3]=(yb - y);
if (vy[2] > 256) vy[2]=vy[3]=256;
- if ((ux[0] >= ux[2]) || // -> cheaters never win...
+ if ((ux[0] >= ux[2]) || // -> cheaters never win...
(vy[0] >= vy[2])) continue; // (but winners always cheat...)
xrMovieArea.x0=lx0+U; xrMovieArea.y0=ly0;
@@ -1331,7 +1330,7 @@ void UploadScreen(int Position)
}
}
- bUsingMovie=FALSE; // done...
+ bUsingMovie=FALSE; // done...
bDisplayNotSet = TRUE;
}
@@ -1339,7 +1338,7 @@ void UploadScreen(int Position)
// Detect next screen
////////////////////////////////////////////////////////////////////////
-BOOL IsCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
+static BOOL IsCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
{
if (x > PSXDisplay.DisplayPosition.x+1) return FALSE;
if ((x + xoff) < PSXDisplay.DisplayEnd.x-1) return FALSE;
@@ -1355,7 +1354,7 @@ BOOL IsCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
return TRUE;
}
-BOOL IsPrimCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
+static BOOL IsPrimCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
{
x+=PSXDisplay.DrawOffset.x;
if (x > PSXDisplay.DisplayPosition.x+1) return FALSE;
@@ -1368,7 +1367,8 @@ BOOL IsPrimCompleteInsideNextScreen(short x, short y, short xoff, short yoff)
return TRUE;
}
-BOOL IsInsideNextScreen(short x, short y, short xoff, short yoff)
+#if 0
+static BOOL IsInsideNextScreen(short x, short y, short xoff, short yoff)
{
if (x > PSXDisplay.DisplayEnd.x) return FALSE;
if (y > PSXDisplay.DisplayEnd.y) return FALSE;
@@ -1376,6 +1376,7 @@ BOOL IsInsideNextScreen(short x, short y, short xoff, short yoff)
if ((y + yoff) < PSXDisplay.DisplayPosition.y) return FALSE;
return TRUE;
}
+#endif
////////////////////////////////////////////////////////////////////////
// mask stuff...
@@ -1384,7 +1385,7 @@ BOOL IsInsideNextScreen(short x, short y, short xoff, short yoff)
//Mask1 Set mask bit while drawing. 1 = on
//Mask2 Do not draw to mask areas. 1= on
-void cmdSTP(unsigned char * baseAddr)
+static void cmdSTP(unsigned char * baseAddr)
{
uint32_t gdata = ((uint32_t*)baseAddr)[0];
@@ -1392,32 +1393,32 @@ void cmdSTP(unsigned char * baseAddr)
STATUSREG|=((gdata & 0x03) << 11); // set the current bits
if(!iUseMask) return;
-
- if(gdata&1) {sSetMask=0x8000;lSetMask=0x80008000;iSetMask=1;}
- else {sSetMask=0; lSetMask=0; iSetMask=0;}
-
- if(gdata&2)
- {
- if(!(gdata&1)) iSetMask=2;
- bCheckMask=TRUE;
- if(iDepthFunc==0) return;
- iDepthFunc=0;
- glDepthFunc(GL_LESS);
- }
- else
- {
- bCheckMask=FALSE;
- if(iDepthFunc==1) return;
- glDepthFunc(GL_ALWAYS);
- iDepthFunc=1;
- }
+
+ if(gdata&1) {sSetMask=0x8000;lSetMask=0x80008000;iSetMask=1;}
+ else {sSetMask=0; lSetMask=0; iSetMask=0;}
+
+ if(gdata&2)
+ {
+ if(!(gdata&1)) iSetMask=2;
+ bCheckMask=TRUE;
+ if(iDepthFunc==0) return;
+ iDepthFunc=0;
+ glDepthFunc(GL_LESS);
+ }
+ else
+ {
+ bCheckMask=FALSE;
+ if(iDepthFunc==1) return;
+ glDepthFunc(GL_ALWAYS);
+ iDepthFunc=1;
+ }
}
////////////////////////////////////////////////////////////////////////
// cmd: Set texture page infos
////////////////////////////////////////////////////////////////////////
-void cmdTexturePage(unsigned char * baseAddr)
+static void cmdTexturePage(unsigned char * baseAddr)
{
uint32_t gdata = ((uint32_t *)baseAddr)[0];
UpdateGlobalTP((unsigned short)gdata);
@@ -1428,59 +1429,59 @@ void cmdTexturePage(unsigned char * baseAddr)
// cmd: turn on/off texture window
////////////////////////////////////////////////////////////////////////
-void cmdTextureWindow(unsigned char *baseAddr)
+static void cmdTextureWindow(unsigned char *baseAddr)
{
- uint32_t gdata = ((uint32_t *)baseAddr)[0];
- uint32_t YAlign,XAlign;
-
- ulGPUInfoVals[INFO_TW]=gdata&0xFFFFF;
-
- if(gdata & 0x020)
- TWin.Position.y1 = 8; // xxxx1
- else if (gdata & 0x040)
- TWin.Position.y1 = 16; // xxx10
- else if (gdata & 0x080)
- TWin.Position.y1 = 32; // xx100
- else if (gdata & 0x100)
- TWin.Position.y1 = 64; // x1000
- else if (gdata & 0x200)
- TWin.Position.y1 = 128; // 10000
- else
- TWin.Position.y1 = 256; // 00000
-
- // Texture window size is determined by the least bit set of the relevant 5 bits
-
- if (gdata & 0x001)
- TWin.Position.x1 = 8; // xxxx1
- else if (gdata & 0x002)
- TWin.Position.x1 = 16; // xxx10
- else if (gdata & 0x004)
- TWin.Position.x1 = 32; // xx100
- else if (gdata & 0x008)
- TWin.Position.x1 = 64; // x1000
- else if (gdata & 0x010)
- TWin.Position.x1 = 128; // 10000
- else
- TWin.Position.x1 = 256; // 00000
-
- // Re-calculate the bit field, because we can't trust what is passed in the data
-
- YAlign = (uint32_t)(32 - (TWin.Position.y1 >> 3));
- XAlign = (uint32_t)(32 - (TWin.Position.x1 >> 3));
-
- // Absolute position of the start of the texture window
-
- TWin.Position.y0 = (short)(((gdata >> 15) & YAlign) << 3);
- TWin.Position.x0 = (short)(((gdata >> 10) & XAlign) << 3);
-
- if((TWin.Position.x0 == 0 && // tw turned off
+ uint32_t gdata = ((uint32_t *)baseAddr)[0];
+ uint32_t YAlign,XAlign;
+
+ ulGPUInfoVals[INFO_TW]=gdata&0xFFFFF;
+
+ if(gdata & 0x020)
+ TWin.Position.y1 = 8; // xxxx1
+ else if (gdata & 0x040)
+ TWin.Position.y1 = 16; // xxx10
+ else if (gdata & 0x080)
+ TWin.Position.y1 = 32; // xx100
+ else if (gdata & 0x100)
+ TWin.Position.y1 = 64; // x1000
+ else if (gdata & 0x200)
+ TWin.Position.y1 = 128; // 10000
+ else
+ TWin.Position.y1 = 256; // 00000
+
+ // Texture window size is determined by the least bit set of the relevant 5 bits
+
+ if (gdata & 0x001)
+ TWin.Position.x1 = 8; // xxxx1
+ else if (gdata & 0x002)
+ TWin.Position.x1 = 16; // xxx10
+ else if (gdata & 0x004)
+ TWin.Position.x1 = 32; // xx100
+ else if (gdata & 0x008)
+ TWin.Position.x1 = 64; // x1000
+ else if (gdata & 0x010)
+ TWin.Position.x1 = 128; // 10000
+ else
+ TWin.Position.x1 = 256; // 00000
+
+ // Re-calculate the bit field, because we can't trust what is passed in the data
+
+ YAlign = (uint32_t)(32 - (TWin.Position.y1 >> 3));
+ XAlign = (uint32_t)(32 - (TWin.Position.x1 >> 3));
+
+ // Absolute position of the start of the texture window
+
+ TWin.Position.y0 = (short)(((gdata >> 15) & YAlign) << 3);
+ TWin.Position.x0 = (short)(((gdata >> 10) & XAlign) << 3);
+
+ if((TWin.Position.x0 == 0 && // tw turned off
TWin.Position.y0 == 0 &&
TWin.Position.x1 == 0 &&
TWin.Position.y1 == 0) ||
(TWin.Position.x1 == 256 &&
TWin.Position.y1 == 256))
{
- bUsingTWin = FALSE; // -> just do it
+ bUsingTWin = FALSE; // -> just do it
#ifdef OWNSCALE
TWin.UScaleFactor = 1.0f;
@@ -1533,7 +1534,7 @@ void cmdTextureWindow(unsigned char *baseAddr)
TWin.UScaleFactor = (float)TWin.Position.x1;
TWin.VScaleFactor = (float)TWin.Position.y1;
#else
- TWin.UScaleFactor = ((float)TWin.Position.x1)/256.0f; // -> set scale factor
+ TWin.UScaleFactor = ((float)TWin.Position.x1)/256.0f; // -> set scale factor
TWin.VScaleFactor = ((float)TWin.Position.y1)/256.0f;
#endif
}
@@ -1542,7 +1543,7 @@ void cmdTextureWindow(unsigned char *baseAddr)
////////////////////////////////////////////////////////////////////////
// mmm, Lewpy uses that in TileS ... I don't ;)
////////////////////////////////////////////////////////////////////////
-
+
/*
void ClampToPSXDrawAreaOffset(short *x0, short *y0, short *x1, short *y1)
{
@@ -1580,13 +1581,13 @@ void ClampToPSXDrawAreaOffset(short *x0, short *y0, short *x1, short *y1)
if ((*y1 + *y0) > PSXDisplay.DrawArea.y1)
*y1 = (PSXDisplay.DrawArea.y1 - *y0 + 1);
}
-*/
+*/
////////////////////////////////////////////////////////////////////////
// Check draw area dimensions
////////////////////////////////////////////////////////////////////////
-void ClampToPSXScreen(short *x0, short *y0, short *x1, short *y1)
+static void ClampToPSXScreen(short *x0, short *y0, short *x1, short *y1)
{
if (*x0 < 0) *x0 = 0;
else
@@ -1598,18 +1599,18 @@ void ClampToPSXScreen(short *x0, short *y0, short *x1, short *y1)
if (*y0 < 0) *y0 = 0;
else
- if (*y0 > iGPUHeightMask) *y0 = iGPUHeightMask;
+ if (*y0 > iGPUHeightMask) *y0 = iGPUHeightMask;
if (*y1 < 0) *y1 = 0;
else
- if (*y1 > iGPUHeightMask) *y1 = iGPUHeightMask;
+ if (*y1 > iGPUHeightMask) *y1 = iGPUHeightMask;
}
////////////////////////////////////////////////////////////////////////
// Used in Load Image and Blk Fill
////////////////////////////////////////////////////////////////////////
-void ClampToPSXScreenOffset(short *x0, short *y0, short *x1, short *y1)
+static void ClampToPSXScreenOffset(short *x0, short *y0, short *x1, short *y1)
{
if (*x0 < 0)
{ *x1 += *x0; *x0 = 0; }
@@ -1620,8 +1621,8 @@ void ClampToPSXScreenOffset(short *x0, short *y0, short *x1, short *y1)
if (*y0 < 0)
{ *y1 += *y0; *y0 = 0; }
else
- if (*y0 > iGPUHeightMask)
- { *y0 = iGPUHeightMask; *y1 = 0; }
+ if (*y0 > iGPUHeightMask)
+ { *y0 = iGPUHeightMask; *y1 = 0; }
if (*x1 < 0) *x1 = 0;
@@ -1629,37 +1630,37 @@ void ClampToPSXScreenOffset(short *x0, short *y0, short *x1, short *y1)
if (*y1 < 0) *y1 = 0;
- if ((*y1 + *y0) > iGPUHeight) *y1 = (iGPUHeight - *y0);
+ if ((*y1 + *y0) > iGPUHeight) *y1 = (iGPUHeight - *y0);
}
////////////////////////////////////////////////////////////////////////
// cmd: start of drawing area... primitives will be clipped inside
////////////////////////////////////////////////////////////////////////
-void cmdDrawAreaStart(unsigned char * baseAddr)
+static void cmdDrawAreaStart(unsigned char * baseAddr)
{
uint32_t gdata = ((uint32_t *)baseAddr)[0];
-
- drawX = gdata & 0x3ff; // for soft drawing
- if(drawX>=1024) drawX=1023;
-
- if(dwGPUVersion==2)
- {
- ulGPUInfoVals[INFO_DRAWSTART]=gdata&0x3FFFFF;
- drawY = (gdata>>12)&0x3ff;
- }
- else
- {
- ulGPUInfoVals[INFO_DRAWSTART]=gdata&0xFFFFF;
- drawY = (gdata>>10)&0x3ff;
- }
-
- if(drawY>=iGPUHeight) drawY=iGPUHeightMask;
+
+ drawX = gdata & 0x3ff; // for soft drawing
+ if(drawX>=1024) drawX=1023;
+
+ if(dwGPUVersion==2)
+ {
+ ulGPUInfoVals[INFO_DRAWSTART]=gdata&0x3FFFFF;
+ drawY = (gdata>>12)&0x3ff;
+ }
+ else
+ {
+ ulGPUInfoVals[INFO_DRAWSTART]=gdata&0xFFFFF;
+ drawY = (gdata>>10)&0x3ff;
+ }
+
+ if(drawY>=iGPUHeight) drawY=iGPUHeightMask;
PreviousPSXDisplay.DrawArea.y0=PSXDisplay.DrawArea.y0;
PreviousPSXDisplay.DrawArea.x0=PSXDisplay.DrawArea.x0;
- PSXDisplay.DrawArea.y0 = (short)drawY; // for OGL drawing
+ PSXDisplay.DrawArea.y0 = (short)drawY; // for OGL drawing
PSXDisplay.DrawArea.x0 = (short)drawX;
}
@@ -1667,27 +1668,27 @@ void cmdDrawAreaStart(unsigned char * baseAddr)
// cmd: end of drawing area... primitives will be clipped inside
////////////////////////////////////////////////////////////////////////
-void cmdDrawAreaEnd(unsigned char * baseAddr)
+static void cmdDrawAreaEnd(unsigned char * baseAddr)
{
uint32_t gdata = ((uint32_t *)baseAddr)[0];
-
+
drawW = gdata & 0x3ff; // for soft drawing
if(drawW>=1024) drawW=1023;
-
- if(dwGPUVersion==2)
- {
- ulGPUInfoVals[INFO_DRAWEND]=gdata&0x3FFFFF;
- drawH = (gdata>>12)&0x3ff;
- }
- else
- {
- ulGPUInfoVals[INFO_DRAWEND]=gdata&0xFFFFF;
- drawH = (gdata>>10)&0x3ff;
- }
-
- if(drawH>=iGPUHeight) drawH=iGPUHeightMask;
-
- PSXDisplay.DrawArea.y1 = (short)drawH; // for OGL drawing
+
+ if(dwGPUVersion==2)
+ {
+ ulGPUInfoVals[INFO_DRAWEND]=gdata&0x3FFFFF;
+ drawH = (gdata>>12)&0x3ff;
+ }
+ else
+ {
+ ulGPUInfoVals[INFO_DRAWEND]=gdata&0xFFFFF;
+ drawH = (gdata>>10)&0x3ff;
+ }
+
+ if(drawH>=iGPUHeight) drawH=iGPUHeightMask;
+
+ PSXDisplay.DrawArea.y1 = (short)drawH; // for OGL drawing
PSXDisplay.DrawArea.x1 = (short)drawW;
ClampToPSXScreen(&PSXDisplay.DrawArea.x0, // clamp
@@ -1702,28 +1703,28 @@ void cmdDrawAreaEnd(unsigned char * baseAddr)
// cmd: draw offset... will be added to prim coords
////////////////////////////////////////////////////////////////////////
-void cmdDrawOffset(unsigned char * baseAddr)
+static void cmdDrawOffset(unsigned char * baseAddr)
{
uint32_t gdata = ((uint32_t *)baseAddr)[0];
-
+
PreviousPSXDisplay.DrawOffset.x =
- PSXDisplay.DrawOffset.x = (short)(gdata & 0x7ff);
-
- if (dwGPUVersion == 2)
- {
- ulGPUInfoVals[INFO_DRAWOFF] = gdata&0x7FFFFF;
- PSXDisplay.DrawOffset.y = (short)((gdata>>12) & 0x7ff);
- }
- else
- {
- ulGPUInfoVals[INFO_DRAWOFF]=gdata&0x3FFFFF;
- PSXDisplay.DrawOffset.y = (short)((gdata>>11) & 0x7ff);
- }
+ PSXDisplay.DrawOffset.x = (short)(gdata & 0x7ff);
+
+ if (dwGPUVersion == 2)
+ {
+ ulGPUInfoVals[INFO_DRAWOFF] = gdata&0x7FFFFF;
+ PSXDisplay.DrawOffset.y = (short)((gdata>>12) & 0x7ff);
+ }
+ else
+ {
+ ulGPUInfoVals[INFO_DRAWOFF]=gdata&0x3FFFFF;
+ PSXDisplay.DrawOffset.y = (short)((gdata>>11) & 0x7ff);
+ }
PSXDisplay.DrawOffset.x=(short)(((int)PSXDisplay.DrawOffset.x<<21)>>21);
PSXDisplay.DrawOffset.y=(short)(((int)PSXDisplay.DrawOffset.y<<21)>>21);
- PSXDisplay.CumulOffset.x = // new OGL prim offsets
+ PSXDisplay.CumulOffset.x = // new OGL prim offsets
PSXDisplay.DrawOffset.x - PSXDisplay.GDrawOffset.x + PreviousPSXDisplay.Range.x0;
PSXDisplay.CumulOffset.y =
PSXDisplay.DrawOffset.y - PSXDisplay.GDrawOffset.y + PreviousPSXDisplay.Range.y0;
@@ -1733,7 +1734,7 @@ void cmdDrawOffset(unsigned char * baseAddr)
// cmd: load image to vram
////////////////////////////////////////////////////////////////////////
-void primLoadImage(unsigned char * baseAddr)
+static void primLoadImage(unsigned char * baseAddr)
{
unsigned short *sgpuData = ((unsigned short *) baseAddr);
@@ -1752,7 +1753,7 @@ void primLoadImage(unsigned char * baseAddr)
////////////////////////////////////////////////////////////////////////
-void PrepareRGB24Upload(void)
+static void PrepareRGB24Upload(void)
{
VRAMWrite.x=(VRAMWrite.x*2)/3;
VRAMWrite.Width=(VRAMWrite.Width*2)/3;
@@ -1856,7 +1857,7 @@ void CheckWriteUpdate()
}
return;
}
-
+
if(!bNeedUploadAfter)
{
bNeedUploadAfter = TRUE;
@@ -1872,16 +1873,16 @@ void CheckWriteUpdate()
xrUploadArea.y0=min(xrUploadArea.y0,VRAMWrite.y);
xrUploadArea.y1=max(xrUploadArea.y1,VRAMWrite.y+VRAMWrite.Height);
}
-
- if(dwActFixes&0x8000)
- {
- if((xrUploadArea.x1-xrUploadArea.x0)>=(PSXDisplay.DisplayMode.x-32) &&
- (xrUploadArea.y1-xrUploadArea.y0)>=(PSXDisplay.DisplayMode.y-32))
- {
- UploadScreen(-1);
- updateFrontDisplay();
- }
- }
+
+ if(dwActFixes&0x8000)
+ {
+ if((xrUploadArea.x1-xrUploadArea.x0)>=(PSXDisplay.DisplayMode.x-32) &&
+ (xrUploadArea.y1-xrUploadArea.y0)>=(PSXDisplay.DisplayMode.y-32))
+ {
+ UploadScreen(-1);
+ updateFrontDisplay();
+ }
+ }
}
}
}
@@ -1890,7 +1891,7 @@ void CheckWriteUpdate()
// cmd: vram -> psx mem
////////////////////////////////////////////////////////////////////////
-void primStoreImage(unsigned char * baseAddr)
+static void primStoreImage(unsigned char * baseAddr)
{
unsigned short *sgpuData = ((unsigned short *) baseAddr);
@@ -1902,7 +1903,7 @@ void primStoreImage(unsigned char * baseAddr)
VRAMRead.ImagePtr = psxVuw + (VRAMRead.y<<10) + VRAMRead.x;
VRAMRead.RowsRemaining = VRAMRead.Width;
VRAMRead.ColsRemaining = VRAMRead.Height;
-
+
iDataReadMode = DR_VRAMTRANSFER;
STATUSREG |= GPUSTATUS_READYFORVRAM;
@@ -1912,7 +1913,7 @@ void primStoreImage(unsigned char * baseAddr)
// cmd: blkfill - NO primitive! Doesn't care about draw areas...
////////////////////////////////////////////////////////////////////////
-void primBlkFill(unsigned char * baseAddr)
+static void primBlkFill(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -1922,9 +1923,9 @@ void primBlkFill(unsigned char * baseAddr)
sprtX = sgpuData[2];
sprtY = sgpuData[3];
sprtW = sgpuData[4] & 0x3ff;
- sprtH = sgpuData[5] & iGPUHeightMask;
-
- sprtW = (sprtW + 15) & ~15;
+ sprtH = sgpuData[5] & iGPUHeightMask;
+
+ sprtW = (sprtW + 15) & ~15;
// Increase H & W if they are one short of full values, because they never can be full values
if (sprtH == iGPUHeightMask) sprtH=iGPUHeight;
@@ -1938,7 +1939,7 @@ void primBlkFill(unsigned char * baseAddr)
offsetBlk();
- if(ClipVertexListScreen())
+ if(ClipVertexListScreen())
{
PSXDisplay_t * pd;
if(PSXDisplay.InterlacedTest) pd=&PSXDisplay;
@@ -1979,7 +1980,7 @@ void primBlkFill(unsigned char * baseAddr)
}
if(ly2<pd->DisplayEnd.y)
{
- vertex[0].x=0;vertex[0].y=(pd->DisplayEnd.y-pd->DisplayPosition.y)-(pd->DisplayEnd.y-ly2);
+ vertex[0].x=0;vertex[0].y=(pd->DisplayEnd.y-pd->DisplayPosition.y)-(pd->DisplayEnd.y-ly2);
vertex[1].x=pd->DisplayEnd.x-pd->DisplayPosition.x;vertex[1].y=vertex[0].y;
vertex[2].x=vertex[1].x;vertex[2].y=pd->DisplayEnd.y;
vertex[3].x=0;vertex[3].y=vertex[2].y;
@@ -2029,7 +2030,7 @@ void primBlkFill(unsigned char * baseAddr)
// cmd: move image vram -> vram
////////////////////////////////////////////////////////////////////////
-void MoveImageWrapped(short imageX0,short imageY0,
+static void MoveImageWrapped(short imageX0,short imageY0,
short imageX1,short imageY1,
short imageSX,short imageSY)
{
@@ -2109,7 +2110,7 @@ void MoveImageWrapped(short imageX0,short imageY0,
////////////////////////////////////////////////////////////////////////
-void primMoveImage(unsigned char * baseAddr)
+static void primMoveImage(unsigned char * baseAddr)
{
short *sgpuData = ((short *) baseAddr);
short imageY0,imageX0,imageY1,imageX1,imageSX,imageSY,i,j;
@@ -2124,8 +2125,8 @@ void primMoveImage(unsigned char * baseAddr)
if((imageX0 == imageX1) && (imageY0 == imageY1)) return;
if(imageSX<=0) return;
if(imageSY<=0) return;
-
- if(iGPUHeight==1024 && sgpuData[7]>1024) return;
+
+ if(iGPUHeight==1024 && sgpuData[7]>1024) return;
if((imageY0+imageSY)>iGPUHeight ||
(imageX0+imageSX)>1024 ||
@@ -2268,7 +2269,7 @@ void primMoveImage(unsigned char * baseAddr)
// cmd: draw free-size Tile
////////////////////////////////////////////////////////////////////////
-void primTileS(unsigned char * baseAddr)
+static void primTileS(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -2285,8 +2286,8 @@ void primTileS(unsigned char * baseAddr)
offsetST();
- if((dwActFixes&1) && // FF7 special game gix (battle cursor)
- sprtX==0 && sprtY==0 && sprtW==24 && sprtH==16)
+ if((dwActFixes&1) && // FF7 special game gix (battle cursor)
+ sprtX==0 && sprtY==0 && sprtW==24 && sprtH==16)
return;
bDrawTextured = FALSE;
@@ -2297,7 +2298,7 @@ void primTileS(unsigned char * baseAddr)
if(iOffscreenDrawing)
{
if(IsPrimCompleteInsideNextScreen(lx0,ly0,lx2,ly2) ||
- (ly0==-6 && ly2==10)) // OH MY GOD... I DIDN'T WANT TO DO IT... BUT I'VE FOUND NO OTHER WAY... HACK FOR GRADIUS SHOOTER :(
+ (ly0==-6 && ly2==10)) // OH MY GOD... I DIDN'T WANT TO DO IT... BUT I'VE FOUND NO OTHER WAY... HACK FOR GRADIUS SHOOTER :(
{
lClearOnSwapColor = COLOR(gpuData[0]);
lClearOnSwap = 1;
@@ -2305,12 +2306,12 @@ void primTileS(unsigned char * baseAddr)
offsetPSX4();
if(bDrawOffscreen4())
- {
- if(!(iTileCheat && sprtH==32 && gpuData[0]==0x60ffffff)) // special cheat for certain ZiNc games
+ {
+ if(!(iTileCheat && sprtH==32 && gpuData[0]==0x60ffffff)) // special cheat for certain ZiNc games
{
InvalidateTextureAreaEx();
FillSoftwareAreaTrans(lx0,ly0,lx2,ly2,
- BGR24to16(gpuData[0]));
+ BGR24to16(gpuData[0]));
}
}
}
@@ -2333,7 +2334,7 @@ void primTileS(unsigned char * baseAddr)
// cmd: draw 1 dot Tile (point)
////////////////////////////////////////////////////////////////////////
-void primTile1(unsigned char * baseAddr)
+static void primTile1(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *)baseAddr);
@@ -2380,7 +2381,7 @@ void primTile1(unsigned char * baseAddr)
// cmd: draw 8 dot Tile (small rect)
////////////////////////////////////////////////////////////////////////
-void primTile8(unsigned char * baseAddr)
+static void primTile8(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -2427,7 +2428,7 @@ void primTile8(unsigned char * baseAddr)
// cmd: draw 16 dot Tile (medium rect)
////////////////////////////////////////////////////////////////////////
-void primTile16(unsigned char * baseAddr)
+static void primTile16(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *)baseAddr);
@@ -2508,7 +2509,7 @@ void DrawMultiBlur(void)
#define POFF 0.375f
-void DrawMultiFilterSprite(void)
+static void DrawMultiFilterSprite(void)
{
int lABR,lDST;
@@ -2520,8 +2521,8 @@ void DrawMultiFilterSprite(void)
lABR=GlobalTextABR;
lDST=DrawSemiTrans;
- vertex[0].c.col[3]=ubGloAlpha/2; // -> set color with
- SETCOL(vertex[0]); // texture alpha
+ vertex[0].c.col[3]=ubGloAlpha/2; // -> set color with
+ SETCOL(vertex[0]); // texture alpha
PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
vertex[0].x+=POFF;vertex[1].x+=POFF;
vertex[2].x+=POFF;vertex[3].x+=POFF;
@@ -2539,7 +2540,7 @@ void DrawMultiFilterSprite(void)
// cmd: small sprite (textured rect)
////////////////////////////////////////////////////////////////////////
-void primSprt8(unsigned char * baseAddr)
+static void primSprt8(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -2558,30 +2559,30 @@ void primSprt8(unsigned char * baseAddr)
offsetST();
// do texture stuff
- gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
-
- if(usMirror & 0x1000)
- {
- s=gl_ux[0];
- s-=sprtW-1;
- if(s<0) {s=0;}
- gl_ux[0]=gl_ux[3]=s;
- }
+ gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
+
+ if(usMirror & 0x1000)
+ {
+ s=gl_ux[0];
+ s-=sprtW-1;
+ if(s<0) {s=0;}
+ gl_ux[0]=gl_ux[3]=s;
+ }
sSprite_ux2=s=gl_ux[0]+sprtW;
if(s) s--;
if(s>255) s=255;
gl_ux[1]=gl_ux[2]=s;
// Y coords
- gl_vy[0]=gl_vy[1]=baseAddr[9];//(gpuData[2]>>8)&0xff;
-
- if(usMirror & 0x2000)
- {
- s=gl_vy[0];
- s-=sprtH-1;
- if(s<0) {s=0;}
- gl_vy[0]=gl_vy[1]=s;
- }
+ gl_vy[0]=gl_vy[1]=baseAddr[9];//(gpuData[2]>>8)&0xff;
+
+ if(usMirror & 0x2000)
+ {
+ s=gl_vy[0];
+ s-=sprtH-1;
+ if(s<0) {s=0;}
+ gl_vy[0]=gl_vy[1]=s;
+ }
sSprite_vy2=s=gl_vy[0]+sprtH;
if(s) s--;
@@ -2604,12 +2605,12 @@ void primSprt8(unsigned char * baseAddr)
SetRenderColor(gpuData[0]);
lx0-=PSXDisplay.DrawOffset.x;
ly0-=PSXDisplay.DrawOffset.y;
-
+
if(bUsingTWin) DrawSoftwareSpriteTWin(baseAddr,8,8);
else
if(usMirror) DrawSoftwareSpriteMirror(baseAddr,8,8);
else
- DrawSoftwareSprite(baseAddr,8,8,baseAddr[8],baseAddr[9]);
+ DrawSoftwareSprite(baseAddr,8,8,baseAddr[8],baseAddr[9]);
}
}
@@ -2636,17 +2637,17 @@ void primSprt8(unsigned char * baseAddr)
{
SetZMask4O();
if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
- DEFOPAQUEON
-
- if(bSmallAlpha && iFilterType<=2)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- SetZMask4O();
- }
+ DEFOPAQUEON
+
+ if(bSmallAlpha && iFilterType<=2)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ SetZMask4O();
+ }
PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
DEFOPAQUEOFF
@@ -2660,7 +2661,7 @@ void primSprt8(unsigned char * baseAddr)
// cmd: medium sprite (textured rect)
////////////////////////////////////////////////////////////////////////
-void primSprt16(unsigned char * baseAddr)
+static void primSprt16(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -2679,30 +2680,30 @@ void primSprt16(unsigned char * baseAddr)
offsetST();
// do texture stuff
- gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
-
- if(usMirror & 0x1000)
- {
- s=gl_ux[0];
- s-=sprtW-1;
- if(s<0) {s=0;}
- gl_ux[0]=gl_ux[3]=s;
- }
+ gl_ux[0]=gl_ux[3]=baseAddr[8];//gpuData[2]&0xff;
+
+ if(usMirror & 0x1000)
+ {
+ s=gl_ux[0];
+ s-=sprtW-1;
+ if(s<0) {s=0;}
+ gl_ux[0]=gl_ux[3]=s;
+ }
sSprite_ux2=s=gl_ux[0]+sprtW;
if(s) s--;
if(s>255) s=255;
gl_ux[1]=gl_ux[2]=s;
// Y coords
- gl_vy[0]=gl_vy[1]=baseAddr[9];//(gpuData[2]>>8)&0xff;
-
- if(usMirror & 0x2000)
- {
- s=gl_vy[0];
- s-=sprtH-1;
- if(s<0) {s=0;}
- gl_vy[0]=gl_vy[1]=s;
- }
+ gl_vy[0]=gl_vy[1]=baseAddr[9];//(gpuData[2]>>8)&0xff;
+
+ if(usMirror & 0x2000)
+ {
+ s=gl_vy[0];
+ s-=sprtH-1;
+ if(s<0) {s=0;}
+ gl_vy[0]=gl_vy[1]=s;
+ }
sSprite_vy2=s=gl_vy[0]+sprtH;
if(s) s--;
@@ -2729,7 +2730,7 @@ void primSprt16(unsigned char * baseAddr)
else
if(usMirror) DrawSoftwareSpriteMirror(baseAddr,16,16);
else
- DrawSoftwareSprite(baseAddr,16,16,baseAddr[8],baseAddr[9]);
+ DrawSoftwareSprite(baseAddr,16,16,baseAddr[8],baseAddr[9]);
}
}
@@ -2757,16 +2758,16 @@ void primSprt16(unsigned char * baseAddr)
SetZMask4O();
if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
DEFOPAQUEON
-
- if(bSmallAlpha && iFilterType<=2)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- SetZMask4O();
- }
+
+ if(bSmallAlpha && iFilterType<=2)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ SetZMask4O();
+ }
PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
DEFOPAQUEOFF
@@ -2780,7 +2781,7 @@ void primSprt16(unsigned char * baseAddr)
// cmd: free-size sprite (textured rect)
////////////////////////////////////////////////////////////////////////
-void primSprtSRest(unsigned char * baseAddr,unsigned short type)
+static void primSprtSRest(unsigned char * baseAddr,unsigned short type)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -2853,12 +2854,12 @@ void primSprtSRest(unsigned char * baseAddr,unsigned short type)
s-=sprtW-1;if(s<0) s=0;
gl_ux[0]=gl_ux[3]=s;
}
- if(usMirror & 0x2000)
- {
- s=gl_vy[0];
- s-=sprtH-1;if(s<0) {s=0;}
- gl_vy[0]=gl_vy[1]=s;
- }
+ if(usMirror & 0x2000)
+ {
+ s=gl_vy[0];
+ s-=sprtH-1;if(s<0) {s=0;}
+ gl_vy[0]=gl_vy[1]=s;
+ }
sSprite_ux2=s=gl_ux[0]+sprtW;
if(s>255) s=255;
@@ -2900,7 +2901,7 @@ void primSprtSRest(unsigned char * baseAddr,unsigned short type)
else
if(usMirror) DrawSoftwareSpriteMirror(baseAddr,sprtW,sprtH);
else
- DrawSoftwareSprite(baseAddr,sprtW,sprtH,baseAddr[8],baseAddr[9]);
+ DrawSoftwareSprite(baseAddr,sprtW,sprtH,baseAddr[8],baseAddr[9]);
}
}
@@ -2927,17 +2928,17 @@ void primSprtSRest(unsigned char * baseAddr,unsigned short type)
{
SetZMask4O();
if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
- DEFOPAQUEON
-
- if(bSmallAlpha && iFilterType<=2)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- SetZMask4O();
- }
+ DEFOPAQUEON
+
+ if(bSmallAlpha && iFilterType<=2)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ SetZMask4O();
+ }
PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
DEFOPAQUEOFF
@@ -2951,7 +2952,7 @@ void primSprtSRest(unsigned char * baseAddr,unsigned short type)
}
}
-void primSprtS(unsigned char * baseAddr)
+static void primSprtS(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -2980,13 +2981,13 @@ void primSprtS(unsigned char * baseAddr)
if(s<0) {s=0;}
gl_ux[0]=gl_ux[3]=s;
}
- if(usMirror & 0x2000)
- {
- s=gl_vy[0];
- s-=sprtH-1;
- if(s<0) {s=0;}
- gl_vy[0]=gl_vy[1]=s;
- }
+ if(usMirror & 0x2000)
+ {
+ s=gl_vy[0];
+ s-=sprtH-1;
+ if(s<0) {s=0;}
+ gl_vy[0]=gl_vy[1]=s;
+ }
sSprite_ux2=s=gl_ux[0]+sprtW;
if(s) s--;
@@ -3030,7 +3031,7 @@ void primSprtS(unsigned char * baseAddr)
else
if(usMirror) DrawSoftwareSpriteMirror(baseAddr,sprtW,sprtH);
else
- DrawSoftwareSprite(baseAddr,sprtW,sprtH,baseAddr[8],baseAddr[9]);
+ DrawSoftwareSprite(baseAddr,sprtW,sprtH,baseAddr[8],baseAddr[9]);
}
}
@@ -3060,17 +3061,17 @@ void primSprtS(unsigned char * baseAddr)
{
SetZMask4O();
if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
- DEFOPAQUEON
-
- if(bSmallAlpha && iFilterType<=2)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- SetZMask4O();
- }
+ DEFOPAQUEON
+
+ if(bSmallAlpha && iFilterType<=2)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ SetZMask4O();
+ }
PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
DEFOPAQUEOFF
@@ -3091,7 +3092,7 @@ void primSprtS(unsigned char * baseAddr)
// cmd: flat shaded Poly4
////////////////////////////////////////////////////////////////////////
-void primPolyF4(unsigned char *baseAddr)
+static void primPolyF4(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -3138,7 +3139,7 @@ void primPolyF4(unsigned char *baseAddr)
void primPolyG4(unsigned char * baseAddr);
-BOOL bDrawOffscreenFrontFF9G4(void)
+static BOOL bDrawOffscreenFrontFF9G4(void)
{
if(lx0< PSXDisplay.DisplayPosition.x) return FALSE; // must be complete in front
if(lx0> PSXDisplay.DisplayEnd.x) return FALSE;
@@ -3169,16 +3170,16 @@ BOOL bCheckFF9G4(unsigned char * baseAddr)
if(iFF9Fix==0)
{
if(bDrawOffscreenFrontFF9G4())
- {
- short *sgpuData = ((short *) pFF9G4Cache);
- iFF9Fix=2;
- memcpy(pFF9G4Cache,baseAddr,32);
-
- if(sgpuData[2]==142)
- {
- sgpuData[2] +=65;
- sgpuData[10]+=65;
- }
+ {
+ short *sgpuData = ((short *) pFF9G4Cache);
+ iFF9Fix=2;
+ memcpy(pFF9G4Cache,baseAddr,32);
+
+ if(sgpuData[2]==142)
+ {
+ sgpuData[2] +=65;
+ sgpuData[10]+=65;
+ }
return TRUE;
}
else iFF9Fix=1;
@@ -3253,7 +3254,7 @@ void primPolyG4(unsigned char * baseAddr)
// cmd: flat shaded Texture3
////////////////////////////////////////////////////////////////////////
-BOOL DoLineCheck(uint32_t *gpuData)
+static BOOL DoLineCheck(uint32_t *gpuData)
{
BOOL bQuad=FALSE;short dx,dy;
@@ -3418,7 +3419,7 @@ BOOL DoLineCheck(uint32_t *gpuData)
////////////////////////////////////////////////////////////////////////
-void primPolyFT3(unsigned char * baseAddr)
+static void primPolyFT3(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -3491,370 +3492,370 @@ void primPolyFT3(unsigned char * baseAddr)
////////////////////////////////////////////////////////////////////////
// cmd: flat shaded Texture4
////////////////////////////////////////////////////////////////////////
-
-#define ST_FAC 255.99f
-
-void RectTexAlign(void)
-{
- int UFlipped = FALSE;
- int VFlipped = FALSE;
-
- if(gTexName==gTexFrameName) return;
-
- if(ly0==ly1)
- {
- if(!((lx1==lx3 && ly3==ly2 && lx2==lx0) ||
- (lx1==lx2 && ly2==ly3 && lx3==lx0)))
- return;
-
- if(ly0<ly2)
- {
- if (vertex[0].tow > vertex[2].tow)
- VFlipped = 1;
- }
- else
- {
- if (vertex[0].tow < vertex[2].tow)
- VFlipped = 2;
- }
- }
- else
- if(ly0==ly2)
- {
- if(!((lx2==lx3 && ly3==ly1 && lx1==lx0) ||
- (lx2==lx1 && ly1==ly3 && lx3==lx0)))
- return;
-
- if(ly0<ly1)
- {
- if (vertex[0].tow > vertex[1].tow)
- VFlipped = 3;
- }
- else
- {
- if (vertex[0].tow < vertex[1].tow)
- VFlipped = 4;
- }
- }
- else
- if(ly0==ly3)
- {
- if(!((lx3==lx2 && ly2==ly1 && lx1==lx0) ||
- (lx3==lx1 && ly1==ly2 && lx2==lx0)))
- return;
-
- if(ly0<ly1)
- {
- if (vertex[0].tow > vertex[1].tow)
- VFlipped = 5;
- }
- else
- {
- if (vertex[0].tow < vertex[1].tow)
- VFlipped = 6;
- }
- }
- else return;
-
- if(lx0==lx1)
- {
- if(lx0<lx2)
- {
- if (vertex[0].sow > vertex[2].sow)
- UFlipped = 1;
- }
- else
- {
- if (vertex[0].sow < vertex[2].sow)
- UFlipped = 2;
- }
- }
- else
- if(lx0==lx2)
- {
- if(lx0<lx1)
- {
- if (vertex[0].sow > vertex[1].sow)
- UFlipped = 3;
- }
- else
- {
- if (vertex[0].sow < vertex[1].sow)
- UFlipped = 4;
- }
- }
- else
- if(lx0==lx3)
- {
- if(lx0<lx1)
- {
- if (vertex[0].sow > vertex[1].sow)
- UFlipped = 5;
- }
- else
- {
- if (vertex[0].sow < vertex[1].sow)
- UFlipped = 6;
- }
- }
-
- if (UFlipped)
- {
-#ifdef OWNSCALE
- if(bUsingTWin)
- {
- switch(UFlipped)
- {
- case 1:
- vertex[2].sow+=0.95f/TWin.UScaleFactor;
- vertex[3].sow+=0.95f/TWin.UScaleFactor;
- break;
- case 2:
- vertex[0].sow+=0.95f/TWin.UScaleFactor;
- vertex[1].sow+=0.95f/TWin.UScaleFactor;
- break;
- case 3:
- vertex[1].sow+=0.95f/TWin.UScaleFactor;
- vertex[3].sow+=0.95f/TWin.UScaleFactor;
- break;
- case 4:
- vertex[0].sow+=0.95f/TWin.UScaleFactor;
- vertex[2].sow+=0.95f/TWin.UScaleFactor;
- break;
- case 5:
- vertex[1].sow+=0.95f/TWin.UScaleFactor;
- vertex[2].sow+=0.95f/TWin.UScaleFactor;
- break;
- case 6:
- vertex[0].sow+=0.95f/TWin.UScaleFactor;
- vertex[3].sow+=0.95f/TWin.UScaleFactor;
- break;
- }
- }
- else
- {
- switch(UFlipped)
- {
- case 1:
- vertex[2].sow+=1.0f/ST_FAC;
- vertex[3].sow+=1.0f/ST_FAC;
- break;
- case 2:
- vertex[0].sow+=1.0f/ST_FAC;
- vertex[1].sow+=1.0f/ST_FAC;
- break;
- case 3:
- vertex[1].sow+=1.0f/ST_FAC;
- vertex[3].sow+=1.0f/ST_FAC;
- break;
- case 4:
- vertex[0].sow+=1.0f/ST_FAC;
- vertex[2].sow+=1.0f/ST_FAC;
- break;
- case 5:
- vertex[1].sow+=1.0f/ST_FAC;
- vertex[2].sow+=1.0f/ST_FAC;
- break;
- case 6:
- vertex[0].sow+=1.0f/ST_FAC;
- vertex[3].sow+=1.0f/ST_FAC;
- break;
- }
- }
-#else
- if(bUsingTWin)
- {
- switch(UFlipped)
- {
- case 1:
- vertex[2].sow+=1.0f/TWin.UScaleFactor;
- vertex[3].sow+=1.0f/TWin.UScaleFactor;
- break;
- case 2:
- vertex[0].sow+=1.0f/TWin.UScaleFactor;
- vertex[1].sow+=1.0f/TWin.UScaleFactor;
- break;
- case 3:
- vertex[1].sow+=1.0f/TWin.UScaleFactor;
- vertex[3].sow+=1.0f/TWin.UScaleFactor;
- break;
- case 4:
- vertex[0].sow+=1.0f/TWin.UScaleFactor;
- vertex[2].sow+=1.0f/TWin.UScaleFactor;
- break;
- case 5:
- vertex[1].sow+=1.0f/TWin.UScaleFactor;
- vertex[2].sow+=1.0f/TWin.UScaleFactor;
- break;
- case 6:
- vertex[0].sow+=1.0f/TWin.UScaleFactor;
- vertex[3].sow+=1.0f/TWin.UScaleFactor;
- break;
- }
- }
- else
- {
- switch(UFlipped)
- {
- case 1:
- vertex[2].sow+=1.0f;
- vertex[3].sow+=1.0f;
- break;
- case 2:
- vertex[0].sow+=1.0f;
- vertex[1].sow+=1.0f;
- break;
- case 3:
- vertex[1].sow+=1.0f;
- vertex[3].sow+=1.0f;
- break;
- case 4:
- vertex[0].sow+=1.0f;
- vertex[2].sow+=1.0f;
- break;
- case 5:
- vertex[1].sow+=1.0f;
- vertex[2].sow+=1.0f;
- break;
- case 6:
- vertex[0].sow+=1.0f;
- vertex[3].sow+=1.0f;
- break;
- }
- }
-#endif
- }
-
- if (VFlipped)
- {
-#ifdef OWNSCALE
- if(bUsingTWin)
- {
- switch(VFlipped)
- {
- case 1:
- vertex[2].tow+=0.95f/TWin.VScaleFactor;
- vertex[3].tow+=0.95f/TWin.VScaleFactor;
- break;
- case 2:
- vertex[0].tow+=0.95f/TWin.VScaleFactor;
- vertex[1].tow+=0.95f/TWin.VScaleFactor;
- break;
- case 3:
- vertex[1].tow+=0.95f/TWin.VScaleFactor;
- vertex[3].tow+=0.95f/TWin.VScaleFactor;
- break;
- case 4:
- vertex[0].tow+=0.95f/TWin.VScaleFactor;
- vertex[2].tow+=0.95f/TWin.VScaleFactor;
- break;
- case 5:
- vertex[1].tow+=0.95f/TWin.VScaleFactor;
- vertex[2].tow+=0.95f/TWin.VScaleFactor;
- break;
- case 6:
- vertex[0].tow+=0.95f/TWin.VScaleFactor;
- vertex[3].tow+=0.95f/TWin.VScaleFactor;
- break;
- }
- }
- else
- {
- switch(VFlipped)
- {
- case 1:
- vertex[2].tow+=1.0f/ST_FAC;
- vertex[3].tow+=1.0f/ST_FAC;
- break;
- case 2:
- vertex[0].tow+=1.0f/ST_FAC;
- vertex[1].tow+=1.0f/ST_FAC;
- break;
- case 3:
- vertex[1].tow+=1.0f/ST_FAC;
- vertex[3].tow+=1.0f/ST_FAC;
- break;
- case 4:
- vertex[0].tow+=1.0f/ST_FAC;
- vertex[2].tow+=1.0f/ST_FAC;
- break;
- case 5:
- vertex[1].tow+=1.0f/ST_FAC;
- vertex[2].tow+=1.0f/ST_FAC;
- break;
- case 6:
- vertex[0].tow+=1.0f/ST_FAC;
- vertex[3].tow+=1.0f/ST_FAC;
- break;
- }
- }
-#else
- if(bUsingTWin)
- {
- switch(VFlipped)
- {
- case 1:
- vertex[2].tow+=1.0f/TWin.VScaleFactor;
- vertex[3].tow+=1.0f/TWin.VScaleFactor;
- break;
- case 2:
- vertex[0].tow+=1.0f/TWin.VScaleFactor;
- vertex[1].tow+=1.0f/TWin.VScaleFactor;
- break;
- case 3:
- vertex[1].tow+=1.0f/TWin.VScaleFactor;
- vertex[3].tow+=1.0f/TWin.VScaleFactor;
- break;
- case 4:
- vertex[0].tow+=1.0f/TWin.VScaleFactor;
- vertex[2].tow+=1.0f/TWin.VScaleFactor;
- break;
- case 5:
- vertex[1].tow+=1.0f/TWin.VScaleFactor;
- vertex[2].tow+=1.0f/TWin.VScaleFactor;
- break;
- case 6:
- vertex[0].tow+=1.0f/TWin.VScaleFactor;
- vertex[3].tow+=1.0f/TWin.VScaleFactor;
- break;
- }
- }
- else
- {
- switch(VFlipped)
- {
- case 1:
- vertex[2].tow+=1.0f;
- vertex[3].tow+=1.0f;
- break;
- case 2:
- vertex[0].tow+=1.0f;
- vertex[1].tow+=1.0f;
- break;
- case 3:
- vertex[1].tow+=1.0f;
- vertex[3].tow+=1.0f;
- break;
- case 4:
- vertex[0].tow+=1.0f;
- vertex[2].tow+=1.0f;
- break;
- case 5:
- vertex[1].tow+=1.0f;
- vertex[2].tow+=1.0f;
- break;
- case 6:
- vertex[0].tow+=1.0f;
- vertex[3].tow+=1.0f;
- break;
- }
- }
-#endif
- }
-
-}
-
-void primPolyFT4(unsigned char * baseAddr)
+
+#define ST_FAC 255.99f
+
+static void RectTexAlign(void)
+{
+ int UFlipped = FALSE;
+ int VFlipped = FALSE;
+
+ if(gTexName==gTexFrameName) return;
+
+ if(ly0==ly1)
+ {
+ if(!((lx1==lx3 && ly3==ly2 && lx2==lx0) ||
+ (lx1==lx2 && ly2==ly3 && lx3==lx0)))
+ return;
+
+ if(ly0<ly2)
+ {
+ if (vertex[0].tow > vertex[2].tow)
+ VFlipped = 1;
+ }
+ else
+ {
+ if (vertex[0].tow < vertex[2].tow)
+ VFlipped = 2;
+ }
+ }
+ else
+ if(ly0==ly2)
+ {
+ if(!((lx2==lx3 && ly3==ly1 && lx1==lx0) ||
+ (lx2==lx1 && ly1==ly3 && lx3==lx0)))
+ return;
+
+ if(ly0<ly1)
+ {
+ if (vertex[0].tow > vertex[1].tow)
+ VFlipped = 3;
+ }
+ else
+ {
+ if (vertex[0].tow < vertex[1].tow)
+ VFlipped = 4;
+ }
+ }
+ else
+ if(ly0==ly3)
+ {
+ if(!((lx3==lx2 && ly2==ly1 && lx1==lx0) ||
+ (lx3==lx1 && ly1==ly2 && lx2==lx0)))
+ return;
+
+ if(ly0<ly1)
+ {
+ if (vertex[0].tow > vertex[1].tow)
+ VFlipped = 5;
+ }
+ else
+ {
+ if (vertex[0].tow < vertex[1].tow)
+ VFlipped = 6;
+ }
+ }
+ else return;
+
+ if(lx0==lx1)
+ {
+ if(lx0<lx2)
+ {
+ if (vertex[0].sow > vertex[2].sow)
+ UFlipped = 1;
+ }
+ else
+ {
+ if (vertex[0].sow < vertex[2].sow)
+ UFlipped = 2;
+ }
+ }
+ else
+ if(lx0==lx2)
+ {
+ if(lx0<lx1)
+ {
+ if (vertex[0].sow > vertex[1].sow)
+ UFlipped = 3;
+ }
+ else
+ {
+ if (vertex[0].sow < vertex[1].sow)
+ UFlipped = 4;
+ }
+ }
+ else
+ if(lx0==lx3)
+ {
+ if(lx0<lx1)
+ {
+ if (vertex[0].sow > vertex[1].sow)
+ UFlipped = 5;
+ }
+ else
+ {
+ if (vertex[0].sow < vertex[1].sow)
+ UFlipped = 6;
+ }
+ }
+
+ if (UFlipped)
+ {
+#ifdef OWNSCALE
+ if(bUsingTWin)
+ {
+ switch(UFlipped)
+ {
+ case 1:
+ vertex[2].sow+=0.95f/TWin.UScaleFactor;
+ vertex[3].sow+=0.95f/TWin.UScaleFactor;
+ break;
+ case 2:
+ vertex[0].sow+=0.95f/TWin.UScaleFactor;
+ vertex[1].sow+=0.95f/TWin.UScaleFactor;
+ break;
+ case 3:
+ vertex[1].sow+=0.95f/TWin.UScaleFactor;
+ vertex[3].sow+=0.95f/TWin.UScaleFactor;
+ break;
+ case 4:
+ vertex[0].sow+=0.95f/TWin.UScaleFactor;
+ vertex[2].sow+=0.95f/TWin.UScaleFactor;
+ break;
+ case 5:
+ vertex[1].sow+=0.95f/TWin.UScaleFactor;
+ vertex[2].sow+=0.95f/TWin.UScaleFactor;
+ break;
+ case 6:
+ vertex[0].sow+=0.95f/TWin.UScaleFactor;
+ vertex[3].sow+=0.95f/TWin.UScaleFactor;
+ break;
+ }
+ }
+ else
+ {
+ switch(UFlipped)
+ {
+ case 1:
+ vertex[2].sow+=1.0f/ST_FAC;
+ vertex[3].sow+=1.0f/ST_FAC;
+ break;
+ case 2:
+ vertex[0].sow+=1.0f/ST_FAC;
+ vertex[1].sow+=1.0f/ST_FAC;
+ break;
+ case 3:
+ vertex[1].sow+=1.0f/ST_FAC;
+ vertex[3].sow+=1.0f/ST_FAC;
+ break;
+ case 4:
+ vertex[0].sow+=1.0f/ST_FAC;
+ vertex[2].sow+=1.0f/ST_FAC;
+ break;
+ case 5:
+ vertex[1].sow+=1.0f/ST_FAC;
+ vertex[2].sow+=1.0f/ST_FAC;
+ break;
+ case 6:
+ vertex[0].sow+=1.0f/ST_FAC;
+ vertex[3].sow+=1.0f/ST_FAC;
+ break;
+ }
+ }
+#else
+ if(bUsingTWin)
+ {
+ switch(UFlipped)
+ {
+ case 1:
+ vertex[2].sow+=1.0f/TWin.UScaleFactor;
+ vertex[3].sow+=1.0f/TWin.UScaleFactor;
+ break;
+ case 2:
+ vertex[0].sow+=1.0f/TWin.UScaleFactor;
+ vertex[1].sow+=1.0f/TWin.UScaleFactor;
+ break;
+ case 3:
+ vertex[1].sow+=1.0f/TWin.UScaleFactor;
+ vertex[3].sow+=1.0f/TWin.UScaleFactor;
+ break;
+ case 4:
+ vertex[0].sow+=1.0f/TWin.UScaleFactor;
+ vertex[2].sow+=1.0f/TWin.UScaleFactor;
+ break;
+ case 5:
+ vertex[1].sow+=1.0f/TWin.UScaleFactor;
+ vertex[2].sow+=1.0f/TWin.UScaleFactor;
+ break;
+ case 6:
+ vertex[0].sow+=1.0f/TWin.UScaleFactor;
+ vertex[3].sow+=1.0f/TWin.UScaleFactor;
+ break;
+ }
+ }
+ else
+ {
+ switch(UFlipped)
+ {
+ case 1:
+ vertex[2].sow+=1.0f;
+ vertex[3].sow+=1.0f;
+ break;
+ case 2:
+ vertex[0].sow+=1.0f;
+ vertex[1].sow+=1.0f;
+ break;
+ case 3:
+ vertex[1].sow+=1.0f;
+ vertex[3].sow+=1.0f;
+ break;
+ case 4:
+ vertex[0].sow+=1.0f;
+ vertex[2].sow+=1.0f;
+ break;
+ case 5:
+ vertex[1].sow+=1.0f;
+ vertex[2].sow+=1.0f;
+ break;
+ case 6:
+ vertex[0].sow+=1.0f;
+ vertex[3].sow+=1.0f;
+ break;
+ }
+ }
+#endif
+ }
+
+ if (VFlipped)
+ {
+#ifdef OWNSCALE
+ if(bUsingTWin)
+ {
+ switch(VFlipped)
+ {
+ case 1:
+ vertex[2].tow+=0.95f/TWin.VScaleFactor;
+ vertex[3].tow+=0.95f/TWin.VScaleFactor;
+ break;
+ case 2:
+ vertex[0].tow+=0.95f/TWin.VScaleFactor;
+ vertex[1].tow+=0.95f/TWin.VScaleFactor;
+ break;
+ case 3:
+ vertex[1].tow+=0.95f/TWin.VScaleFactor;
+ vertex[3].tow+=0.95f/TWin.VScaleFactor;
+ break;
+ case 4:
+ vertex[0].tow+=0.95f/TWin.VScaleFactor;
+ vertex[2].tow+=0.95f/TWin.VScaleFactor;
+ break;
+ case 5:
+ vertex[1].tow+=0.95f/TWin.VScaleFactor;
+ vertex[2].tow+=0.95f/TWin.VScaleFactor;
+ break;
+ case 6:
+ vertex[0].tow+=0.95f/TWin.VScaleFactor;
+ vertex[3].tow+=0.95f/TWin.VScaleFactor;
+ break;
+ }
+ }
+ else
+ {
+ switch(VFlipped)
+ {
+ case 1:
+ vertex[2].tow+=1.0f/ST_FAC;
+ vertex[3].tow+=1.0f/ST_FAC;
+ break;
+ case 2:
+ vertex[0].tow+=1.0f/ST_FAC;
+ vertex[1].tow+=1.0f/ST_FAC;
+ break;
+ case 3:
+ vertex[1].tow+=1.0f/ST_FAC;
+ vertex[3].tow+=1.0f/ST_FAC;
+ break;
+ case 4:
+ vertex[0].tow+=1.0f/ST_FAC;
+ vertex[2].tow+=1.0f/ST_FAC;
+ break;
+ case 5:
+ vertex[1].tow+=1.0f/ST_FAC;
+ vertex[2].tow+=1.0f/ST_FAC;
+ break;
+ case 6:
+ vertex[0].tow+=1.0f/ST_FAC;
+ vertex[3].tow+=1.0f/ST_FAC;
+ break;
+ }
+ }
+#else
+ if(bUsingTWin)
+ {
+ switch(VFlipped)
+ {
+ case 1:
+ vertex[2].tow+=1.0f/TWin.VScaleFactor;
+ vertex[3].tow+=1.0f/TWin.VScaleFactor;
+ break;
+ case 2:
+ vertex[0].tow+=1.0f/TWin.VScaleFactor;
+ vertex[1].tow+=1.0f/TWin.VScaleFactor;
+ break;
+ case 3:
+ vertex[1].tow+=1.0f/TWin.VScaleFactor;
+ vertex[3].tow+=1.0f/TWin.VScaleFactor;
+ break;
+ case 4:
+ vertex[0].tow+=1.0f/TWin.VScaleFactor;
+ vertex[2].tow+=1.0f/TWin.VScaleFactor;
+ break;
+ case 5:
+ vertex[1].tow+=1.0f/TWin.VScaleFactor;
+ vertex[2].tow+=1.0f/TWin.VScaleFactor;
+ break;
+ case 6:
+ vertex[0].tow+=1.0f/TWin.VScaleFactor;
+ vertex[3].tow+=1.0f/TWin.VScaleFactor;
+ break;
+ }
+ }
+ else
+ {
+ switch(VFlipped)
+ {
+ case 1:
+ vertex[2].tow+=1.0f;
+ vertex[3].tow+=1.0f;
+ break;
+ case 2:
+ vertex[0].tow+=1.0f;
+ vertex[1].tow+=1.0f;
+ break;
+ case 3:
+ vertex[1].tow+=1.0f;
+ vertex[3].tow+=1.0f;
+ break;
+ case 4:
+ vertex[0].tow+=1.0f;
+ vertex[2].tow+=1.0f;
+ break;
+ case 5:
+ vertex[1].tow+=1.0f;
+ vertex[2].tow+=1.0f;
+ break;
+ case 6:
+ vertex[0].tow+=1.0f;
+ vertex[3].tow+=1.0f;
+ break;
+ }
+ }
+#endif
+ }
+
+}
+
+static void primPolyFT4(unsigned char * baseAddr)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -3918,17 +3919,17 @@ void primPolyFT4(unsigned char * baseAddr)
{
SetZMask4O();
if(bUseMultiPass) SetOpaqueColor(gpuData[0]);
- DEFOPAQUEON
-
- if(bSmallAlpha && iFilterType<=2)
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- SetZMask4O();
- }
+ DEFOPAQUEON
+
+ if(bSmallAlpha && iFilterType<=2)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ SetZMask4O();
+ }
PRIMdrawTexturedQuad(&vertex[0], &vertex[1], &vertex[3], &vertex[2]);
DEFOPAQUEOFF
@@ -3941,7 +3942,7 @@ void primPolyFT4(unsigned char * baseAddr)
// cmd: smooth shaded Texture3
////////////////////////////////////////////////////////////////////////
-void primPolyGT3(unsigned char *baseAddr)
+static void primPolyGT3(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -4050,7 +4051,7 @@ void primPolyGT3(unsigned char *baseAddr)
// cmd: smooth shaded Poly3
////////////////////////////////////////////////////////////////////////
-void primPolyG3(unsigned char *baseAddr)
+static void primPolyG3(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -4095,7 +4096,7 @@ void primPolyG3(unsigned char *baseAddr)
// cmd: smooth shaded Texture4
////////////////////////////////////////////////////////////////////////
-void primPolyGT4(unsigned char *baseAddr)
+static void primPolyGT4(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *)baseAddr);
short *sgpuData = ((short *)baseAddr);
@@ -4215,7 +4216,7 @@ void primPolyGT4(unsigned char *baseAddr)
// cmd: smooth shaded Poly3
////////////////////////////////////////////////////////////////////////
-void primPolyF3(unsigned char *baseAddr)
+static void primPolyF3(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -4259,7 +4260,7 @@ void primPolyF3(unsigned char *baseAddr)
// cmd: skipping shaded polylines
////////////////////////////////////////////////////////////////////////
-void primLineGSkip(unsigned char *baseAddr)
+static void primLineGSkip(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -4268,8 +4269,8 @@ void primLineGSkip(unsigned char *baseAddr)
lx1 = sgpuData[2];
ly1 = sgpuData[3];
-
- while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=4))
+
+ while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=4))
{
i++;
@@ -4284,7 +4285,7 @@ void primLineGSkip(unsigned char *baseAddr)
// cmd: shaded polylines
////////////////////////////////////////////////////////////////////////
-void primLineGEx(unsigned char *baseAddr)
+static void primLineGEx(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
int iMax=255;
@@ -4302,11 +4303,11 @@ void primLineGEx(unsigned char *baseAddr)
lx1 = (short)(gpuData[1] & 0xffff);
i=2;
-
+
//while((gpuData[i]>>24)!=0x55)
- //while((gpuData[i]&0x50000000)!=0x50000000)
- // currently best way to check for poly line end:
- while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=4))
+ //while((gpuData[i]&0x50000000)!=0x50000000)
+ // currently best way to check for poly line end:
+ while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=4))
{
ly0 = ly1;lx0=lx1;
vertex[1].c.lcol=vertex[2].c.lcol=vertex[0].c.lcol;
@@ -4317,8 +4318,8 @@ void primLineGEx(unsigned char *baseAddr)
ly1 = (short)((gpuData[i]>>16) & 0xffff);
lx1 = (short)(gpuData[i] & 0xffff);
-
- if(offsetline()) bDraw=FALSE; else bDraw=TRUE;
+
+ if(offsetline()) bDraw=FALSE; else bDraw=TRUE;
if (bDraw && ((lx0 != lx1) || (ly0 != ly1)))
{
@@ -4348,7 +4349,7 @@ void primLineGEx(unsigned char *baseAddr)
// cmd: shaded polyline2
////////////////////////////////////////////////////////////////////////
-void primLineG2(unsigned char *baseAddr)
+static void primLineG2(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -4393,7 +4394,7 @@ void primLineG2(unsigned char *baseAddr)
// cmd: skipping flat polylines
////////////////////////////////////////////////////////////////////////
-void primLineFSkip(unsigned char *baseAddr)
+static void primLineFSkip(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
int i=2,iMax=255;
@@ -4401,7 +4402,7 @@ void primLineFSkip(unsigned char *baseAddr)
ly1 = (short)((gpuData[1]>>16) & 0xffff);
lx1 = (short)(gpuData[1] & 0xffff);
- while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=3))
+ while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=3))
{
ly1 = (short)((gpuData[i]>>16) & 0xffff);
lx1 = (short)(gpuData[i] & 0xffff);
@@ -4413,7 +4414,7 @@ void primLineFSkip(unsigned char *baseAddr)
// cmd: drawing flat polylines
////////////////////////////////////////////////////////////////////////
-void primLineFEx(unsigned char *baseAddr)
+static void primLineFEx(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
int iMax;
@@ -4439,13 +4440,13 @@ void primLineFEx(unsigned char *baseAddr)
// while((gpuData[i]>>24)!=0x55)
// while((gpuData[i]&0x50000000)!=0x50000000)
// currently best way to check for poly line end:
- while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=3))
+ while(!(((gpuData[i] & 0xF000F000) == 0x50005000) && i>=3))
{
ly0 = ly1;lx0=lx1;
ly1 = (short)((gpuData[i]>>16) & 0xffff);
lx1 = (short)(gpuData[i] & 0xffff);
-
- if(!offsetline())
+
+ if(!offsetline())
{
if(iOffscreenDrawing)
{
@@ -4459,7 +4460,7 @@ void primLineFEx(unsigned char *baseAddr)
lx0=cx0;lx1=cx1;ly0=cy0;ly1=cy1;
}
PRIMdrawFlatLine(&vertex[0], &vertex[1], &vertex[2], &vertex[3]);
- }
+ }
i++;if(i>iMax) break;
}
@@ -4471,7 +4472,7 @@ void primLineFEx(unsigned char *baseAddr)
// cmd: drawing flat polyline2
////////////////////////////////////////////////////////////////////////
-void primLineF2(unsigned char *baseAddr)
+static void primLineF2(unsigned char *baseAddr)
{
uint32_t *gpuData = ((uint32_t *) baseAddr);
short *sgpuData = ((short *) baseAddr);
@@ -4512,7 +4513,7 @@ void primLineF2(unsigned char *baseAddr)
// cmd: well, easiest command... not implemented
////////////////////////////////////////////////////////////////////////
-void primNI(unsigned char *bA)
+static void primNI(unsigned char *bA)
{
}
diff --git a/plugins/peopsxgl/soft.c b/plugins/peopsxgl/soft.c
index 9f10a2a0..1ab93f07 100644
--- a/plugins/peopsxgl/soft.c
+++ b/plugins/peopsxgl/soft.c
@@ -1,8407 +1,8409 @@
-/***************************************************************************
- soft.c - description
- -------------------
- begin : Sun Oct 28 2001
- copyright : (C) 2001 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
-#include "stdafx.h"
-
-#define _IN_SOFT
-
-#include "externals.h"
-#include "soft.h"
-
-int iDither = 0;
-
-////////////////////////////////////////////////////////////////////////////////////
-// "NO EDGE BUFFER" POLY VERSION... FUNCS BASED ON FATMAP.TXT FROM MRI / Doomsday
-////////////////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////////////////
-// defines
-////////////////////////////////////////////////////////////////////////////////////
-
-// switches for painting textured quads as 2 triangles (small glitches, but better shading!)
-// can be toggled by game fix 0x200 in version 1.17 anyway, so let the defines enabled!
-
-#define POLYQUAD3
-#define POLYQUAD3GT
-
-// fast solid loops... a bit more additional code, of course
-
-#define FASTSOLID
-
-// psx blending mode 3 with 25% incoming color (instead 50% without the define)
-
-#define HALFBRIGHTMODE3
-
-// color decode defines
-
-#define XCOL1(x) (x & 0x1f)
-#define XCOL2(x) (x & 0x3e0)
-#define XCOL3(x) (x & 0x7c00)
-
-#define XCOL1D(x) (x & 0x1f)
-#define XCOL2D(x) ((x>>5) & 0x1f)
-#define XCOL3D(x) ((x>>10) & 0x1f)
-
-#define X32TCOL1(x) ((x & 0x001f001f)<<7)
-#define X32TCOL2(x) ((x & 0x03e003e0)<<2)
-#define X32TCOL3(x) ((x & 0x7c007c00)>>3)
-
-#define X32COL1(x) (x & 0x001f001f)
-#define X32COL2(x) ((x>>5) & 0x001f001f)
-#define X32COL3(x) ((x>>10) & 0x001f001f)
-
-#define X32ACOL1(x) (x & 0x001e001e)
-#define X32ACOL2(x) ((x>>5) & 0x001e001e)
-#define X32ACOL3(x) ((x>>10) & 0x001e001e)
-
-#define X32BCOL1(x) (x & 0x001c001c)
-#define X32BCOL2(x) ((x>>5) & 0x001c001c)
-#define X32BCOL3(x) ((x>>10) & 0x001c001c)
-
-#define X32PSXCOL(r,g,b) ((g<<10)|(b<<5)|r)
-
-#define XPSXCOL(r,g,b) ((g&0x7c00)|(b&0x3e0)|(r&0x1f))
-
-////////////////////////////////////////////////////////////////////////////////////
-// soft globals
-////////////////////////////////////////////////////////////////////////////////////
-
-short g_m1 = 255, g_m2 = 255, g_m3 = 255;
-short DrawSemiTrans = FALSE;
-short Ymin;
-short Ymax;
-
-short ly0, lx0, ly1, lx1, ly2, lx2, ly3, lx3; // global psx vertex coords
-int GlobalTextAddrX, GlobalTextAddrY, GlobalTextTP;
-int GlobalTextREST, GlobalTextABR, GlobalTextPAGE;
-
-////////////////////////////////////////////////////////////////////////
-// POLYGON OFFSET FUNCS
-////////////////////////////////////////////////////////////////////////
-
-void offsetPSXLine(void)
-{
- short x0,x1,y0,y1,dx,dy;float px,py;
-
- x0 = lx0+1+PSXDisplay.DrawOffset.x;
- x1 = lx1+1+PSXDisplay.DrawOffset.x;
- y0 = ly0+1+PSXDisplay.DrawOffset.y;
- y1 = ly1+1+PSXDisplay.DrawOffset.y;
-
- dx=x1-x0;
- dy=y1-y0;
-
- // tricky line width without sqrt
-
- if(dx>=0)
- {
- if(dy>=0)
- {
- px=0.5f;
- if(dx>dy) py=-0.5f;
- else if(dx<dy) py= 0.5f;
- else py= 0.0f;
- }
- else
- {
- py=-0.5f;
- dy=-dy;
- if(dx>dy) px= 0.5f;
- else if(dx<dy) px=-0.5f;
- else px= 0.0f;
- }
- }
- else
- {
- if(dy>=0)
- {
- py=0.5f;
- dx=-dx;
- if(dx>dy) px=-0.5f;
- else if(dx<dy) px= 0.5f;
- else px= 0.0f;
- }
- else
- {
- px=-0.5f;
- if(dx>dy) py=-0.5f;
- else if(dx<dy) py= 0.5f;
- else py= 0.0f;
- }
- }
-
- lx0=(short)((float)x0-px);
- lx3=(short)((float)x0+py);
-
- ly0=(short)((float)y0-py);
- ly3=(short)((float)y0-px);
-
- lx1=(short)((float)x1-py);
- lx2=(short)((float)x1+px);
-
- ly1=(short)((float)y1+px);
- ly2=(short)((float)y1+py);
-}
-
-void offsetPSX2(void)
-{
- lx0 += PSXDisplay.DrawOffset.x;
- ly0 += PSXDisplay.DrawOffset.y;
- lx1 += PSXDisplay.DrawOffset.x;
- ly1 += PSXDisplay.DrawOffset.y;
-}
-
-void offsetPSX3(void)
-{
- lx0 += PSXDisplay.DrawOffset.x;
- ly0 += PSXDisplay.DrawOffset.y;
- lx1 += PSXDisplay.DrawOffset.x;
- ly1 += PSXDisplay.DrawOffset.y;
- lx2 += PSXDisplay.DrawOffset.x;
- ly2 += PSXDisplay.DrawOffset.y;
-}
-
-void offsetPSX4(void)
-{
- lx0 += PSXDisplay.DrawOffset.x;
- ly0 += PSXDisplay.DrawOffset.y;
- lx1 += PSXDisplay.DrawOffset.x;
- ly1 += PSXDisplay.DrawOffset.y;
- lx2 += PSXDisplay.DrawOffset.x;
- ly2 += PSXDisplay.DrawOffset.y;
- lx3 += PSXDisplay.DrawOffset.x;
- ly3 += PSXDisplay.DrawOffset.y;
-}
-
-/////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-// PER PIXEL FUNCS
-////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-
-
-unsigned char dithertable[16] =
-{
- 7, 0, 6, 1,
- 2, 5, 3, 4,
- 1, 6, 0, 7,
- 4, 3, 5, 2
-};
-
-void Dither16(unsigned short *pdest, uint32_t r, uint32_t g, uint32_t b, unsigned short sM)
-{
- unsigned char coeff;
- unsigned char rlow, glow, blow;
- int x, y;
-
- x = pdest - psxVuw;
- y = x >> 10;
- x -= (y << 10);
-
- coeff = dithertable[(y&3)*4+(x&3)];
-
- rlow = r&7; glow = g&7; blow = b&7;
-
- r>>=3; g>>=3; b>>=3;
-
- if ((r < 0x1F) && rlow > coeff) r++;
- if ((g < 0x1F) && glow > coeff) g++;
- if ((b < 0x1F) && blow > coeff) b++;
-
- *pdest=((unsigned short)b<<10) |
- ((unsigned short)g<<5) |
- (unsigned short)r | sM;
-}
-
-/////////////////////////////////////////////////////////////////
-
-__inline void GetShadeTransCol_Dither(unsigned short *pdest, int m1, int m2, int m3)
-{
- int r,g,b;
-
- if (bCheckMask && *pdest & 0x8000) return;
-
- if (DrawSemiTrans)
- {
- r=((XCOL1D(*pdest))<<3);
- b=((XCOL2D(*pdest))<<3);
- g=((XCOL3D(*pdest))<<3);
-
- if(GlobalTextABR==0)
- {
- r=(r>>1)+(m1>>1);
- b=(b>>1)+(m2>>1);
- g=(g>>1)+(m3>>1);
- }
- else
- if(GlobalTextABR==1)
- {
- r+=m1;
- b+=m2;
- g+=m3;
- }
- else
- if(GlobalTextABR==2)
- {
- r-=m1;
- b-=m2;
- g-=m3;
- if(r&0x80000000) r=0;
- if(b&0x80000000) b=0;
- if(g&0x80000000) g=0;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r+=(m1>>2);
- b+=(m2>>2);
- g+=(m3>>2);
-#else
- r+=(m1>>1);
- b+=(m2>>1);
- g+=(m3>>1);
-#endif
- }
- }
- else
- {
- r=m1;
- b=m2;
- g=m3;
- }
-
- if(r&0x7FFFFF00) r=0xff;
- if(b&0x7FFFFF00) b=0xff;
- if(g&0x7FFFFF00) g=0xff;
-
- Dither16(pdest,r,b,g,sSetMask);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetShadeTransCol(unsigned short * pdest,unsigned short color)
-{
- if(bCheckMask && *pdest&0x8000) return;
-
- if(DrawSemiTrans)
- {
- int r,g,b;
-
- if(GlobalTextABR==0)
- {
- *pdest=((((*pdest)&0x7bde)>>1)+(((color)&0x7bde)>>1))|sSetMask;//0x8000;
- return;
-/*
- r=(XCOL1(*pdest)>>1)+((XCOL1(color))>>1);
- b=(XCOL2(*pdest)>>1)+((XCOL2(color))>>1);
- g=(XCOL3(*pdest)>>1)+((XCOL3(color))>>1);
-*/
- }
- else
- if(GlobalTextABR==1)
- {
- r=(XCOL1(*pdest))+((XCOL1(color)));
- b=(XCOL2(*pdest))+((XCOL2(color)));
- g=(XCOL3(*pdest))+((XCOL3(color)));
- }
- else
- if(GlobalTextABR==2)
- {
- r=(XCOL1(*pdest))-((XCOL1(color)));
- b=(XCOL2(*pdest))-((XCOL2(color)));
- g=(XCOL3(*pdest))-((XCOL3(color)));
- if(r&0x80000000) r=0;
- if(b&0x80000000) b=0;
- if(g&0x80000000) g=0;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r=(XCOL1(*pdest))+((XCOL1(color))>>2);
- b=(XCOL2(*pdest))+((XCOL2(color))>>2);
- g=(XCOL3(*pdest))+((XCOL3(color))>>2);
-#else
- r=(XCOL1(*pdest))+((XCOL1(color))>>1);
- b=(XCOL2(*pdest))+((XCOL2(color))>>1);
- g=(XCOL3(*pdest))+((XCOL3(color))>>1);
-#endif
- }
-
- if(r&0x7FFFFFE0) r=0x1f;
- if(b&0x7FFFFC00) b=0x3e0;
- if(g&0x7FFF8000) g=0x7c00;
-
- *pdest=(XPSXCOL(r,g,b))|sSetMask;//0x8000;
- }
- else *pdest=color|sSetMask;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetShadeTransCol32(uint32_t *pdest, uint32_t color)
-{
- if (DrawSemiTrans)
- {
- int r,g,b;
-
- if(GlobalTextABR==0)
- {
- if(!bCheckMask)
- {
- *pdest=((((*pdest)&0x7bde7bde)>>1)+(((color)&0x7bde7bde)>>1))|lSetMask;//0x80008000;
- return;
- }
- r=(X32ACOL1(*pdest)>>1)+((X32ACOL1(color))>>1);
- b=(X32ACOL2(*pdest)>>1)+((X32ACOL2(color))>>1);
- g=(X32ACOL3(*pdest)>>1)+((X32ACOL3(color))>>1);
- }
- else
- if(GlobalTextABR==1)
- {
- r=(X32COL1(*pdest))+((X32COL1(color)));
- b=(X32COL2(*pdest))+((X32COL2(color)));
- g=(X32COL3(*pdest))+((X32COL3(color)));
- }
- else
- if(GlobalTextABR==2)
- {
- int sr,sb,sg,src,sbc,sgc,c;
- src=XCOL1(color);sbc=XCOL2(color);sgc=XCOL3(color);
- c=(*pdest)>>16;
- sr=(XCOL1(c))-src; if(sr&0x8000) sr=0;
- sb=(XCOL2(c))-sbc; if(sb&0x8000) sb=0;
- sg=(XCOL3(c))-sgc; if(sg&0x8000) sg=0;
- r=((int)sr)<<16;b=((int)sb)<<11;g=((int)sg)<<6;
- c=LOWORD(*pdest);
- sr=(XCOL1(c))-src; if(sr&0x8000) sr=0;
- sb=(XCOL2(c))-sbc; if(sb&0x8000) sb=0;
- sg=(XCOL3(c))-sgc; if(sg&0x8000) sg=0;
- r|=sr;b|=sb>>5;g|=sg>>10;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r=(X32COL1(*pdest))+((X32BCOL1(color))>>2);
- b=(X32COL2(*pdest))+((X32BCOL2(color))>>2);
- g=(X32COL3(*pdest))+((X32BCOL3(color))>>2);
-#else
- r=(X32COL1(*pdest))+((X32ACOL1(color))>>1);
- b=(X32COL2(*pdest))+((X32ACOL2(color))>>1);
- g=(X32COL3(*pdest))+((X32ACOL3(color))>>1);
-#endif
- }
-
- if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
- if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
- if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
- if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
- if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
- if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
-
- if(bCheckMask)
- {
- uint32_t ma=*pdest;
- *pdest=(X32PSXCOL(r,g,b))|lSetMask;//0x80008000;
- if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
- if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
- return;
- }
- *pdest=(X32PSXCOL(r,g,b))|lSetMask;//0x80008000;
- }
- else
- {
- if(bCheckMask)
- {
- uint32_t ma=*pdest;
- *pdest=color|lSetMask;//0x80008000;
- if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
- if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
- return;
- }
-
- *pdest=color|lSetMask;//0x80008000;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColG(unsigned short * pdest,unsigned short color)
-{
- int r,g,b;unsigned short l;
-
- if(color==0) return;
-
- if(bCheckMask && *pdest&0x8000) return;
-
- l=sSetMask|(color&0x8000);
-
- if(DrawSemiTrans && (color&0x8000))
- {
- if(GlobalTextABR==0)
- {
- unsigned short d;
- d =((*pdest)&0x7bde)>>1;
- color =((color) &0x7bde)>>1;
- r=(XCOL1(d))+((((XCOL1(color)))* g_m1)>>7);
- b=(XCOL2(d))+((((XCOL2(color)))* g_m2)>>7);
- g=(XCOL3(d))+((((XCOL3(color)))* g_m3)>>7);
-
-/*
- r=(XCOL1(*pdest)>>1)+((((XCOL1(color))>>1)* g_m1)>>7);
- b=(XCOL2(*pdest)>>1)+((((XCOL2(color))>>1)* g_m2)>>7);
- g=(XCOL3(*pdest)>>1)+((((XCOL3(color))>>1)* g_m3)>>7);
-*/
- }
- else
- if(GlobalTextABR==1)
- {
- r=(XCOL1(*pdest))+((((XCOL1(color)))* g_m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color)))* g_m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color)))* g_m3)>>7);
- }
- else
- if(GlobalTextABR==2)
- {
- r=(XCOL1(*pdest))-((((XCOL1(color)))* g_m1)>>7);
- b=(XCOL2(*pdest))-((((XCOL2(color)))* g_m2)>>7);
- g=(XCOL3(*pdest))-((((XCOL3(color)))* g_m3)>>7);
- if(r&0x80000000) r=0;
- if(b&0x80000000) b=0;
- if(g&0x80000000) g=0;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r=(XCOL1(*pdest))+((((XCOL1(color))>>2)* g_m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color))>>2)* g_m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color))>>2)* g_m3)>>7);
-#else
- r=(XCOL1(*pdest))+((((XCOL1(color))>>1)* g_m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color))>>1)* g_m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color))>>1)* g_m3)>>7);
-#endif
- }
- }
- else
- {
- r=((XCOL1(color))* g_m1)>>7;
- b=((XCOL2(color))* g_m2)>>7;
- g=((XCOL3(color))* g_m3)>>7;
- }
-
- if(r&0x7FFFFFE0) r=0x1f;
- if(b&0x7FFFFC00) b=0x3e0;
- if(g&0x7FFF8000) g=0x7c00;
-
- *pdest=(XPSXCOL(r,g,b))|l;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColG_S(unsigned short * pdest,unsigned short color)
-{
- int r,g,b;unsigned short l;
-
- if(color==0) return;
-
- l=sSetMask|(color&0x8000);
-
- r=((XCOL1(color))* g_m1)>>7;
- b=((XCOL2(color))* g_m2)>>7;
- g=((XCOL3(color))* g_m3)>>7;
-
- if(r&0x7FFFFFE0) r=0x1f;
- if(b&0x7FFFFC00) b=0x3e0;
- if(g&0x7FFF8000) g=0x7c00;
-
- *pdest=(XPSXCOL(r,g,b))|l;
-}
-
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColG_SPR(unsigned short * pdest,unsigned short color)
-{
- int r,g,b;unsigned short l;
-
- if(color==0) return;
-
- if(bCheckMask && *pdest&0x8000) return;
-
- l=sSetMask|(color&0x8000);
-
- if(DrawSemiTrans && (color&0x8000))
- {
- if(GlobalTextABR==0)
- {
- unsigned short d;
- d =((*pdest)&0x7bde)>>1;
- color =((color) &0x7bde)>>1;
- r=(XCOL1(d))+((((XCOL1(color)))* g_m1)>>7);
- b=(XCOL2(d))+((((XCOL2(color)))* g_m2)>>7);
- g=(XCOL3(d))+((((XCOL3(color)))* g_m3)>>7);
-
-/*
- r=(XCOL1(*pdest)>>1)+((((XCOL1(color))>>1)* g_m1)>>7);
- b=(XCOL2(*pdest)>>1)+((((XCOL2(color))>>1)* g_m2)>>7);
- g=(XCOL3(*pdest)>>1)+((((XCOL3(color))>>1)* g_m3)>>7);
-*/
- }
- else
- if(GlobalTextABR==1)
- {
- r=(XCOL1(*pdest))+((((XCOL1(color)))* g_m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color)))* g_m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color)))* g_m3)>>7);
- }
- else
- if(GlobalTextABR==2)
- {
- r=(XCOL1(*pdest))-((((XCOL1(color)))* g_m1)>>7);
- b=(XCOL2(*pdest))-((((XCOL2(color)))* g_m2)>>7);
- g=(XCOL3(*pdest))-((((XCOL3(color)))* g_m3)>>7);
- if(r&0x80000000) r=0;
- if(b&0x80000000) b=0;
- if(g&0x80000000) g=0;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r=(XCOL1(*pdest))+((((XCOL1(color))>>2)* g_m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color))>>2)* g_m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color))>>2)* g_m3)>>7);
-#else
- r=(XCOL1(*pdest))+((((XCOL1(color))>>1)* g_m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color))>>1)* g_m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color))>>1)* g_m3)>>7);
-#endif
- }
- }
- else
- {
- r=((XCOL1(color))* g_m1)>>7;
- b=((XCOL2(color))* g_m2)>>7;
- g=((XCOL3(color))* g_m3)>>7;
- }
-
- if(r&0x7FFFFFE0) r=0x1f;
- if(b&0x7FFFFC00) b=0x3e0;
- if(g&0x7FFF8000) g=0x7c00;
-
- *pdest=(XPSXCOL(r,g,b))|l;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColG32(uint32_t *pdest, uint32_t color)
-{
- int r,g,b,l;
-
- if(color==0) return;
-
- l=lSetMask|(color&0x80008000);
-
- if(DrawSemiTrans && (color&0x80008000))
- {
- if(GlobalTextABR==0)
- {
- r=((((X32TCOL1(*pdest))+((X32COL1(color)) * g_m1))&0xFF00FF00)>>8);
- b=((((X32TCOL2(*pdest))+((X32COL2(color)) * g_m2))&0xFF00FF00)>>8);
- g=((((X32TCOL3(*pdest))+((X32COL3(color)) * g_m3))&0xFF00FF00)>>8);
- }
- else
- if(GlobalTextABR==1)
- {
- r=(X32COL1(*pdest))+(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
- b=(X32COL2(*pdest))+(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
- g=(X32COL3(*pdest))+(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
- }
- else
- if(GlobalTextABR==2)
- {
- int t;
- r=(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
- t=(*pdest&0x001f0000)-(r&0x003f0000); if(t&0x80000000) t=0;
- r=(*pdest&0x0000001f)-(r&0x0000003f); if(r&0x80000000) r=0;
- r|=t;
-
- b=(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
- t=((*pdest>>5)&0x001f0000)-(b&0x003f0000); if(t&0x80000000) t=0;
- b=((*pdest>>5)&0x0000001f)-(b&0x0000003f); if(b&0x80000000) b=0;
- b|=t;
-
- g=(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
- t=((*pdest>>10)&0x001f0000)-(g&0x003f0000); if(t&0x80000000) t=0;
- g=((*pdest>>10)&0x0000001f)-(g&0x0000003f); if(g&0x80000000) g=0;
- g|=t;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r=(X32COL1(*pdest))+(((((X32BCOL1(color))>>2)* g_m1)&0xFF80FF80)>>7);
- b=(X32COL2(*pdest))+(((((X32BCOL2(color))>>2)* g_m2)&0xFF80FF80)>>7);
- g=(X32COL3(*pdest))+(((((X32BCOL3(color))>>2)* g_m3)&0xFF80FF80)>>7);
-#else
- r=(X32COL1(*pdest))+(((((X32ACOL1(color))>>1)* g_m1)&0xFF80FF80)>>7);
- b=(X32COL2(*pdest))+(((((X32ACOL2(color))>>1)* g_m2)&0xFF80FF80)>>7);
- g=(X32COL3(*pdest))+(((((X32ACOL3(color))>>1)* g_m3)&0xFF80FF80)>>7);
-#endif
- }
-
- if(!(color&0x8000))
- {
- r=(r&0xffff0000)|((((X32COL1(color))* g_m1)&0x0000FF80)>>7);
- b=(b&0xffff0000)|((((X32COL2(color))* g_m2)&0x0000FF80)>>7);
- g=(g&0xffff0000)|((((X32COL3(color))* g_m3)&0x0000FF80)>>7);
- }
- if(!(color&0x80000000))
- {
- r=(r&0xffff)|((((X32COL1(color))* g_m1)&0xFF800000)>>7);
- b=(b&0xffff)|((((X32COL2(color))* g_m2)&0xFF800000)>>7);
- g=(g&0xffff)|((((X32COL3(color))* g_m3)&0xFF800000)>>7);
- }
-
- }
- else
- {
- r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
- b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
- g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
- }
-
- if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
- if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
- if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
- if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
- if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
- if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
-
- if(bCheckMask)
- {
- uint32_t ma=*pdest;
-
- *pdest=(X32PSXCOL(r,g,b))|l;
-
- if((color&0xffff)==0 ) *pdest=(ma&0xffff)|(*pdest&0xffff0000);
- if((color&0xffff0000)==0) *pdest=(ma&0xffff0000)|(*pdest&0xffff);
- if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
- if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
-
- return;
- }
- if((color&0xffff)==0 ) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|l)&0xffff0000);return;}
- if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|l)&0xffff);return;}
-
- *pdest=(X32PSXCOL(r,g,b))|l;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColG32_S(uint32_t *pdest, uint32_t color)
-{
- int r,g,b;
-
- if(color==0) return;
-
- r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
- b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
- g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
-
- if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
- if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
- if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
- if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
- if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
- if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
-
- if((color&0xffff)==0) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000);return;}
- if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff);return;}
-
- *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColG32_SPR(uint32_t *pdest, uint32_t color)
-{
- int r,g,b;
-
- if(color==0) return;
-
- if(DrawSemiTrans && (color&0x80008000))
- {
- if(GlobalTextABR==0)
- {
- r=((((X32TCOL1(*pdest))+((X32COL1(color)) * g_m1))&0xFF00FF00)>>8);
- b=((((X32TCOL2(*pdest))+((X32COL2(color)) * g_m2))&0xFF00FF00)>>8);
- g=((((X32TCOL3(*pdest))+((X32COL3(color)) * g_m3))&0xFF00FF00)>>8);
- }
- else
- if(GlobalTextABR==1)
- {
- r=(X32COL1(*pdest))+(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
- b=(X32COL2(*pdest))+(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
- g=(X32COL3(*pdest))+(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
- }
- else
- if(GlobalTextABR==2)
- {
- int t;
- r=(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
- t=(*pdest&0x001f0000)-(r&0x003f0000); if(t&0x80000000) t=0;
- r=(*pdest&0x0000001f)-(r&0x0000003f); if(r&0x80000000) r=0;
- r|=t;
-
- b=(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
- t=((*pdest>>5)&0x001f0000)-(b&0x003f0000); if(t&0x80000000) t=0;
- b=((*pdest>>5)&0x0000001f)-(b&0x0000003f); if(b&0x80000000) b=0;
- b|=t;
-
- g=(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
- t=((*pdest>>10)&0x001f0000)-(g&0x003f0000); if(t&0x80000000) t=0;
- g=((*pdest>>10)&0x0000001f)-(g&0x0000003f); if(g&0x80000000) g=0;
- g|=t;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r=(X32COL1(*pdest))+(((((X32BCOL1(color))>>2)* g_m1)&0xFF80FF80)>>7);
- b=(X32COL2(*pdest))+(((((X32BCOL2(color))>>2)* g_m2)&0xFF80FF80)>>7);
- g=(X32COL3(*pdest))+(((((X32BCOL3(color))>>2)* g_m3)&0xFF80FF80)>>7);
-#else
- r=(X32COL1(*pdest))+(((((X32ACOL1(color))>>1)* g_m1)&0xFF80FF80)>>7);
- b=(X32COL2(*pdest))+(((((X32ACOL2(color))>>1)* g_m2)&0xFF80FF80)>>7);
- g=(X32COL3(*pdest))+(((((X32ACOL3(color))>>1)* g_m3)&0xFF80FF80)>>7);
-#endif
- }
-
- if(!(color&0x8000))
- {
- r=(r&0xffff0000)|((((X32COL1(color))* g_m1)&0x0000FF80)>>7);
- b=(b&0xffff0000)|((((X32COL2(color))* g_m2)&0x0000FF80)>>7);
- g=(g&0xffff0000)|((((X32COL3(color))* g_m3)&0x0000FF80)>>7);
- }
- if(!(color&0x80000000))
- {
- r=(r&0xffff)|((((X32COL1(color))* g_m1)&0xFF800000)>>7);
- b=(b&0xffff)|((((X32COL2(color))* g_m2)&0xFF800000)>>7);
- g=(g&0xffff)|((((X32COL3(color))* g_m3)&0xFF800000)>>7);
- }
-
- }
- else
- {
- r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
- b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
- g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
- }
-
- if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
- if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
- if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
- if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
- if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
- if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
-
- if(bCheckMask)
- {
- uint32_t ma=*pdest;
-
- *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
-
- if((color&0xffff)==0 ) *pdest=(ma&0xffff)|(*pdest&0xffff0000);
- if((color&0xffff0000)==0) *pdest=(ma&0xffff0000)|(*pdest&0xffff);
- if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
- if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
-
- return;
- }
- if((color&0xffff)==0 ) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000);return;}
- if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff);return;}
-
- *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColGX_Dither(unsigned short * pdest, unsigned short color, int m1, int m2, int m3)
-{
- int r,g,b;
-
- if(color==0) return;
-
- if(bCheckMask && *pdest&0x8000) return;
-
- m1=(((XCOL1D(color)))*m1)>>4;
- m2=(((XCOL2D(color)))*m2)>>4;
- m3=(((XCOL3D(color)))*m3)>>4;
-
- if(DrawSemiTrans && (color&0x8000))
- {
- r=((XCOL1D(*pdest))<<3);
- b=((XCOL2D(*pdest))<<3);
- g=((XCOL3D(*pdest))<<3);
-
- if(GlobalTextABR==0)
- {
- r=(r>>1)+(m1>>1);
- b=(b>>1)+(m2>>1);
- g=(g>>1)+(m3>>1);
- }
- else
- if(GlobalTextABR==1)
- {
- r+=m1;
- b+=m2;
- g+=m3;
- }
- else
- if(GlobalTextABR==2)
- {
- r-=m1;
- b-=m2;
- g-=m3;
- if(r&0x80000000) r=0;
- if(b&0x80000000) b=0;
- if(g&0x80000000) g=0;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r+=(m1>>2);
- b+=(m2>>2);
- g+=(m3>>2);
-#else
- r+=(m1>>1);
- b+=(m2>>1);
- g+=(m3>>1);
-#endif
- }
- }
- else
- {
- r=m1;
- b=m2;
- g=m3;
- }
-
- if(r&0x7FFFFF00) r=0xff;
- if(b&0x7FFFFF00) b=0xff;
- if(g&0x7FFFFF00) g=0xff;
-
- Dither16(pdest,r,b,g,sSetMask|(color&0x8000));
-
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColGX(unsigned short * pdest,unsigned short color,short m1,short m2,short m3)
-{
- int r,g,b;unsigned short l;
-
- if(color==0) return;
-
- if(bCheckMask && *pdest&0x8000) return;
-
- l=sSetMask|(color&0x8000);
-
- if(DrawSemiTrans && (color&0x8000))
- {
- if(GlobalTextABR==0)
- {
- unsigned short d;
- d =((*pdest)&0x7bde)>>1;
- color =((color) &0x7bde)>>1;
- r=(XCOL1(d))+((((XCOL1(color)))* m1)>>7);
- b=(XCOL2(d))+((((XCOL2(color)))* m2)>>7);
- g=(XCOL3(d))+((((XCOL3(color)))* m3)>>7);
-/*
- r=(XCOL1(*pdest)>>1)+((((XCOL1(color))>>1)* m1)>>7);
- b=(XCOL2(*pdest)>>1)+((((XCOL2(color))>>1)* m2)>>7);
- g=(XCOL3(*pdest)>>1)+((((XCOL3(color))>>1)* m3)>>7);
-*/
- }
- else
- if(GlobalTextABR==1)
- {
- r=(XCOL1(*pdest))+((((XCOL1(color)))* m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color)))* m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color)))* m3)>>7);
- }
- else
- if(GlobalTextABR==2)
- {
- r=(XCOL1(*pdest))-((((XCOL1(color)))* m1)>>7);
- b=(XCOL2(*pdest))-((((XCOL2(color)))* m2)>>7);
- g=(XCOL3(*pdest))-((((XCOL3(color)))* m3)>>7);
- if(r&0x80000000) r=0;
- if(b&0x80000000) b=0;
- if(g&0x80000000) g=0;
- }
- else
- {
-#ifdef HALFBRIGHTMODE3
- r=(XCOL1(*pdest))+((((XCOL1(color))>>2)* m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color))>>2)* m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color))>>2)* m3)>>7);
-#else
- r=(XCOL1(*pdest))+((((XCOL1(color))>>1)* m1)>>7);
- b=(XCOL2(*pdest))+((((XCOL2(color))>>1)* m2)>>7);
- g=(XCOL3(*pdest))+((((XCOL3(color))>>1)* m3)>>7);
-#endif
- }
- }
- else
- {
- r=((XCOL1(color))* m1)>>7;
- b=((XCOL2(color))* m2)>>7;
- g=((XCOL3(color))* m3)>>7;
- }
-
- if(r&0x7FFFFFE0) r=0x1f;
- if(b&0x7FFFFC00) b=0x3e0;
- if(g&0x7FFF8000) g=0x7c00;
-
- *pdest=(XPSXCOL(r,g,b))|l;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColGX_S(unsigned short * pdest,unsigned short color,short m1,short m2,short m3)
-{
- int r,g,b;
-
- if(color==0) return;
-
- r=((XCOL1(color))* m1)>>7;
- b=((XCOL2(color))* m2)>>7;
- g=((XCOL3(color))* m3)>>7;
-
- if(r&0x7FFFFFE0) r=0x1f;
- if(b&0x7FFFFC00) b=0x3e0;
- if(g&0x7FFF8000) g=0x7c00;
-
- *pdest=(XPSXCOL(r,g,b))|sSetMask|(color&0x8000);
-}
-
-////////////////////////////////////////////////////////////////////////
-
-__inline void GetTextureTransColGX32_S(uint32_t *pdest, uint32_t color, short m1, short m2, short m3)
-{
- int r,g,b;
-
- if(color==0) return;
-
- r=(((X32COL1(color))* m1)&0xFF80FF80)>>7;
- b=(((X32COL2(color))* m2)&0xFF80FF80)>>7;
- g=(((X32COL3(color))* m3)&0xFF80FF80)>>7;
-
- if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
- if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
- if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
- if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
- if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
- if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
-
- if((color&0xffff)==0) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000);return;}
- if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff);return;}
-
- *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
-}
-
-////////////////////////////////////////////////////////////////////////
-// FILL FUNCS
-////////////////////////////////////////////////////////////////////////
-
-void FillSoftwareAreaTrans(short x0,short y0,short x1, // FILL AREA TRANS
- short y1,unsigned short col)
-{
- short j,i,dx,dy;
-
- if(y0>y1) return;
- if(x0>x1) return;
-
- if(x1<drawX) return;
- if(y1<drawY) return;
- if(x0>drawW) return;
- if(y0>drawH) return;
-
- x1=min(x1,drawW+1);
- y1=min(y1,drawH+1);
- x0=max(x0,drawX);
- y0=max(y0,drawY);
-
- if(y0>=iGPUHeight) return;
- if(x0>1023) return;
-
- if(y1>iGPUHeight) y1=iGPUHeight;
- if(x1>1024) x1=1024;
-
- dx=x1-x0;dy=y1-y0;
-
- if(dx==1 && dy==1 && x0==1020 && y0==511) // special fix for pinball game... emu protection???
- {
-/*
-m->v 1020 511 1 1
-writedatamem 0x00000000 1
-tile1 newcol 7fff (orgcol 0xffffff), oldvram 0
-v->m 1020 511 1 1
-readdatamem 0x00007fff 1
-m->v 1020 511 1 1
-writedatamem 0x00000000 1
-tile1 newcol 8000 (orgcol 0xffffff), oldvram 0
-v->m 1020 511 1 1
-readdatamem 0x00008000 1
-*/
-
- static int iCheat=0;
- col+=iCheat;
- if(iCheat==1) iCheat=0; else iCheat=1;
- }
-
- if(dx&1) // slow fill
- {
- unsigned short *DSTPtr;
- unsigned short LineOffset;
- DSTPtr = psxVuw + (1024*y0) + x0;
- LineOffset = 1024 - dx;
- for(i=0;i<dy;i++)
- {
- for(j=0;j<dx;j++)
- GetShadeTransCol(DSTPtr++,col);
- DSTPtr += LineOffset;
- }
- }
- else // fast fill
- {
- uint32_t *DSTPtr;
- unsigned short LineOffset;
- uint32_t lcol=lSetMask|(((uint32_t)(col))<<16)|col;
- dx>>=1;
- DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0);
- LineOffset = 512 - dx;
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for(i=0;i<dy;i++)
- {
- for(j=0;j<dx;j++) *DSTPtr++=lcol;
- DSTPtr += LineOffset;
- }
- }
- else
- {
- for(i=0;i<dy;i++)
- {
- for(j=0;j<dx;j++)
- GetShadeTransCol32(DSTPtr++,lcol);
- DSTPtr += LineOffset;
- }
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void FillSoftwareArea(short x0,short y0,short x1, // FILL AREA (BLK FILL)
- short y1,unsigned short col) // no draw area check here!
-{
- short j,i,dx,dy;
-
- if(y0>y1) return;
- if(x0>x1) return;
-
- if(y0>=iGPUHeight) return;
- if(x0>1023) return;
-
- if(y1>iGPUHeight) y1=iGPUHeight;
- if(x1>1024) x1=1024;
-
- dx=x1-x0;dy=y1-y0;
- if(dx&1)
- {
- unsigned short *DSTPtr;
- unsigned short LineOffset;
-
- DSTPtr = psxVuw + (1024*y0) + x0;
- LineOffset = 1024 - dx;
-
- for(i=0;i<dy;i++)
- {
- for(j=0;j<dx;j++) *DSTPtr++=col;
- DSTPtr += LineOffset;
- }
- }
- else
- {
- uint32_t *DSTPtr;
- unsigned short LineOffset;
- uint32_t lcol=(((int)col)<<16)|col;
- dx>>=1;
- DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0);
- LineOffset = 512 - dx;
-
- for(i=0;i<dy;i++)
- {
- for(j=0;j<dx;j++) *DSTPtr++=lcol;
- DSTPtr += LineOffset;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// EDGE INTERPOLATION
-////////////////////////////////////////////////////////////////////////
-
-typedef struct SOFTVTAG
-{
- int x,y;
- int u,v;
- int R,G,B;
-} soft_vertex;
-
-static soft_vertex vtx[4];
-static soft_vertex * left_array[4], * right_array[4];
-static int left_section, right_section;
-static int left_section_height, right_section_height;
-static int left_x, delta_left_x, right_x, delta_right_x;
-static int left_u, delta_left_u, left_v, delta_left_v;
-static int right_u, delta_right_u, right_v, delta_right_v;
-static int left_R, delta_left_R, right_R, delta_right_R;
-static int left_G, delta_left_G, right_G, delta_right_G;
-static int left_B, delta_left_B, right_B, delta_right_B;
-
-#ifdef _MSC_VER
-
-#pragma warning (disable : 4035)
-
-__inline int shl10idiv(int x, int y)
-{
- __asm
- {
- mov eax,x
- mov ebx,y
- mov edx, eax
- shl eax, 10
- sar edx, 22
- idiv ebx
- // return result in eax
- }
-}
-
-#else
-
-__inline int shl10idiv(int x, int y)
-{
- long long int bi=x;
- bi<<=10;
- return bi/y;
-}
-
-#endif
-
-__inline int RightSection_F(void)
-{
- soft_vertex * v1 = right_array[ right_section ];
- soft_vertex * v2 = right_array[ right_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_right_x = (v2->x - v1->x) / height;
- right_x = v1->x;
-
- right_section_height = height;
- return height;
-}
-
-__inline int LeftSection_F(void)
-{
- soft_vertex * v1 = left_array[ left_section ];
- soft_vertex * v2 = left_array[ left_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_left_x = (v2->x - v1->x) / height;
- left_x = v1->x;
-
- left_section_height = height;
- return height;
-}
-
-__inline BOOL NextRow_F(void)
-{
- if(--left_section_height<=0)
- {
- if(--left_section <= 0) {return TRUE;}
- if(LeftSection_F() <= 0) {return TRUE;}
- }
- else
- {
- left_x += delta_left_x;
- }
-
- if(--right_section_height<=0)
- {
- if(--right_section<=0) {return TRUE;}
- if(RightSection_F() <=0) {return TRUE;}
- }
- else
- {
- right_x += delta_right_x;
- }
- return FALSE;
-}
-
-__inline BOOL SetupSections_F(short x1, short y1, short x2, short y2, short x3, short y3)
-{
- soft_vertex * v1, * v2, * v3;
- int height,longest;
-
- v1 = vtx; v1->x=x1<<16;v1->y=y1;
- v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
- v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
-
- if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
- if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
- if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
-
- height = v3->y - v1->y;
- if(height == 0) {return FALSE;}
- longest = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest == 0) {return FALSE;}
-
- if(longest < 0)
- {
- right_array[0] = v3;
- right_array[1] = v2;
- right_array[2] = v1;
- right_section = 2;
- left_array[0] = v3;
- left_array[1] = v1;
- left_section = 1;
-
- if(LeftSection_F() <= 0) return FALSE;
- if(RightSection_F() <= 0)
- {
- right_section--;
- if(RightSection_F() <= 0) return FALSE;
- }
- }
- else
- {
- left_array[0] = v3;
- left_array[1] = v2;
- left_array[2] = v1;
- left_section = 2;
- right_array[0] = v3;
- right_array[1] = v1;
- right_section = 1;
-
- if(RightSection_F() <= 0) return FALSE;
- if(LeftSection_F() <= 0)
- {
- left_section--;
- if(LeftSection_F() <= 0) return FALSE;
- }
- }
-
- Ymin=v1->y;
- Ymax=min(v3->y-1,drawH);
-
- return TRUE;
-}
-
-__inline int RightSection_G(void)
-{
- soft_vertex * v1 = right_array[ right_section ];
- soft_vertex * v2 = right_array[ right_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_right_x = (v2->x - v1->x) / height;
- right_x = v1->x;
-
- right_section_height = height;
- return height;
-}
-
-__inline int LeftSection_G(void)
-{
- soft_vertex * v1 = left_array[ left_section ];
- soft_vertex * v2 = left_array[ left_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_left_x = (v2->x - v1->x) / height;
- left_x = v1->x;
-
- delta_left_R = ((v2->R - v1->R)) / height;
- left_R = v1->R;
- delta_left_G = ((v2->G - v1->G)) / height;
- left_G = v1->G;
- delta_left_B = ((v2->B - v1->B)) / height;
- left_B = v1->B;
-
- left_section_height = height;
- return height;
-}
-
-__inline BOOL NextRow_G(void)
-{
- if(--left_section_height<=0)
- {
- if(--left_section <= 0) {return TRUE;}
- if(LeftSection_G() <= 0) {return TRUE;}
- }
- else
- {
- left_x += delta_left_x;
- left_R += delta_left_R;
- left_G += delta_left_G;
- left_B += delta_left_B;
- }
-
- if(--right_section_height<=0)
- {
- if(--right_section<=0) {return TRUE;}
- if(RightSection_G() <=0) {return TRUE;}
- }
- else
- {
- right_x += delta_right_x;
- }
- return FALSE;
-}
-
-__inline BOOL SetupSections_G(short x1,short y1,short x2,short y2,short x3,short y3, int rgb1, int rgb2, int rgb3){
- soft_vertex *v1, *v2, *v3;
- int height, longest, temp;
-
- v1 = vtx; v1->x=x1<<16;v1->y=y1;
- v1->R=(rgb1) & 0x00ff0000;
- v1->G=(rgb1<<8) & 0x00ff0000;
- v1->B=(rgb1<<16) & 0x00ff0000;
- v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
- v2->R=(rgb2) & 0x00ff0000;
- v2->G=(rgb2<<8) & 0x00ff0000;
- v2->B=(rgb2<<16) & 0x00ff0000;
- v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
- v3->R=(rgb3) & 0x00ff0000;
- v3->G=(rgb3<<8) & 0x00ff0000;
- v3->B=(rgb3<<16) & 0x00ff0000;
-
- if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
- if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
- if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
-
- height = v3->y - v1->y;
- if(height == 0) {return FALSE;}
- temp=(((v2->y - v1->y) << 16) / height);
- longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest == 0) {return FALSE;}
-
- if(longest < 0)
- {
- right_array[0] = v3;
- right_array[1] = v2;
- right_array[2] = v1;
- right_section = 2;
- left_array[0] = v3;
- left_array[1] = v1;
- left_section = 1;
-
- if(LeftSection_G() <= 0) return FALSE;
- if(RightSection_G() <= 0)
- {
- right_section--;
- if(RightSection_G() <= 0) return FALSE;
- }
- if(longest > -0x1000) longest = -0x1000;
- }
- else
- {
- left_array[0] = v3;
- left_array[1] = v2;
- left_array[2] = v1;
- left_section = 2;
- right_array[0] = v3;
- right_array[1] = v1;
- right_section = 1;
-
- if(RightSection_G() <= 0) return FALSE;
- if(LeftSection_G() <= 0)
- {
- left_section--;
- if(LeftSection_G() <= 0) return FALSE;
- }
- if(longest < 0x1000) longest = 0x1000;
- }
-
- Ymin=v1->y;
- Ymax=min(v3->y-1,drawH);
-
- delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
- delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
- delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
-
- return TRUE;
-}
-
-__inline int RightSection_FT(void)
-{
- soft_vertex * v1 = right_array[ right_section ];
- soft_vertex * v2 = right_array[ right_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_right_x = (v2->x - v1->x) / height;
- right_x = v1->x;
-
- right_section_height = height;
- return height;
-}
-
-__inline int LeftSection_FT(void)
-{
- soft_vertex * v1 = left_array[ left_section ];
- soft_vertex * v2 = left_array[ left_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_left_x = (v2->x - v1->x) / height;
- left_x = v1->x;
-
- delta_left_u = ((v2->u - v1->u)) / height;
- left_u = v1->u;
- delta_left_v = ((v2->v - v1->v)) / height;
- left_v = v1->v;
-
- left_section_height = height;
- return height;
-}
-
-__inline BOOL NextRow_FT(void)
-{
- if(--left_section_height<=0)
- {
- if(--left_section <= 0) {return TRUE;}
- if(LeftSection_FT() <= 0) {return TRUE;}
- }
- else
- {
- left_x += delta_left_x;
- left_u += delta_left_u;
- left_v += delta_left_v;
- }
-
- if(--right_section_height<=0)
- {
- if(--right_section<=0) {return TRUE;}
- if(RightSection_FT() <=0) {return TRUE;}
- }
- else
- {
- right_x += delta_right_x;
- }
- return FALSE;
-}
-
-__inline BOOL SetupSections_FT(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
-{
- soft_vertex * v1, * v2, * v3;
- int height,longest,temp;
-
- v1 = vtx; v1->x=x1<<16;v1->y=y1;
- v1->u=tx1<<16;v1->v=ty1<<16;
- v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
- v2->u=tx2<<16;v2->v=ty2<<16;
- v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
- v3->u=tx3<<16;v3->v=ty3<<16;
-
- if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
- if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
- if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
-
- height = v3->y - v1->y;
- if(height == 0) {return FALSE;}
-
- temp=(((v2->y - v1->y) << 16) / height);
- longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
-
- if(longest == 0) {return FALSE;}
-
- if(longest < 0)
- {
- right_array[0] = v3;
- right_array[1] = v2;
- right_array[2] = v1;
- right_section = 2;
- left_array[0] = v3;
- left_array[1] = v1;
- left_section = 1;
-
- if(LeftSection_FT() <= 0) return FALSE;
- if(RightSection_FT() <= 0)
- {
- right_section--;
- if(RightSection_FT() <= 0) return FALSE;
- }
- if(longest > -0x1000) longest = -0x1000;
- }
- else
- {
- left_array[0] = v3;
- left_array[1] = v2;
- left_array[2] = v1;
- left_section = 2;
- right_array[0] = v3;
- right_array[1] = v1;
- right_section = 1;
-
- if(RightSection_FT() <= 0) return FALSE;
- if(LeftSection_FT() <= 0)
- {
- left_section--;
- if(LeftSection_FT() <= 0) return FALSE;
- }
- if(longest < 0x1000) longest = 0x1000;
- }
-
- Ymin=v1->y;
- Ymax=min(v3->y-1,drawH);
-
- delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
- delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
-
-/*
-Mmm... adjust neg tex deltas... will sometimes cause slight
-texture distortions
-
- longest>>=16;
- if(longest)
- {
- if(longest<0) longest=-longest;
- if(delta_right_u<0)
- delta_right_u-=delta_right_u/longest;
- if(delta_right_v<0)
- delta_right_v-=delta_right_v/longest;
- }
-*/
-
- return TRUE;
-}
-
-__inline int RightSection_GT(void)
-{
- soft_vertex * v1 = right_array[ right_section ];
- soft_vertex * v2 = right_array[ right_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_right_x = (v2->x - v1->x) / height;
- right_x = v1->x;
-
- right_section_height = height;
- return height;
-}
-
-__inline int LeftSection_GT(void)
-{
- soft_vertex * v1 = left_array[ left_section ];
- soft_vertex * v2 = left_array[ left_section-1 ];
-
- int height = v2->y - v1->y;
- if(height == 0) return 0;
- delta_left_x = (v2->x - v1->x) / height;
- left_x = v1->x;
-
- delta_left_u = ((v2->u - v1->u)) / height;
- left_u = v1->u;
- delta_left_v = ((v2->v - v1->v)) / height;
- left_v = v1->v;
-
- delta_left_R = ((v2->R - v1->R)) / height;
- left_R = v1->R;
- delta_left_G = ((v2->G - v1->G)) / height;
- left_G = v1->G;
- delta_left_B = ((v2->B - v1->B)) / height;
- left_B = v1->B;
-
- left_section_height = height;
- return height;
-}
-
-__inline BOOL NextRow_GT(void)
-{
- if(--left_section_height<=0)
- {
- if(--left_section <= 0) {return TRUE;}
- if(LeftSection_GT() <= 0) {return TRUE;}
- }
- else
- {
- left_x += delta_left_x;
- left_u += delta_left_u;
- left_v += delta_left_v;
- left_R += delta_left_R;
- left_G += delta_left_G;
- left_B += delta_left_B;
- }
-
- if(--right_section_height<=0)
- {
- if(--right_section<=0) {return TRUE;}
- if(RightSection_GT() <=0) {return TRUE;}
- }
- else
- {
- right_x += delta_right_x;
- }
- return FALSE;
-}
-
-__inline BOOL SetupSections_GT(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, int rgb1, int rgb2, int rgb3)
-{
- soft_vertex * v1, * v2, * v3;
- int height,longest,temp;
-
- v1 = vtx; v1->x=x1<<16;v1->y=y1;
- v1->u=tx1<<16;v1->v=ty1<<16;
- v1->R=(rgb1) & 0x00ff0000;
- v1->G=(rgb1<<8) & 0x00ff0000;
- v1->B=(rgb1<<16) & 0x00ff0000;
-
- v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
- v2->u=tx2<<16;v2->v=ty2<<16;
- v2->R=(rgb2) & 0x00ff0000;
- v2->G=(rgb2<<8) & 0x00ff0000;
- v2->B=(rgb2<<16) & 0x00ff0000;
-
- v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
- v3->u=tx3<<16;v3->v=ty3<<16;
- v3->R=(rgb3) & 0x00ff0000;
- v3->G=(rgb3<<8) & 0x00ff0000;
- v3->B=(rgb3<<16) & 0x00ff0000;
-
- if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
- if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
- if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
-
- height = v3->y - v1->y;
- if(height == 0) {return FALSE;}
-
- temp=(((v2->y - v1->y) << 16) / height);
- longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
-
- if(longest == 0) {return FALSE;}
-
- if(longest < 0)
- {
- right_array[0] = v3;
- right_array[1] = v2;
- right_array[2] = v1;
- right_section = 2;
- left_array[0] = v3;
- left_array[1] = v1;
- left_section = 1;
-
- if(LeftSection_GT() <= 0) return FALSE;
- if(RightSection_GT() <= 0)
- {
- right_section--;
- if(RightSection_GT() <= 0) return FALSE;
- }
-
- if(longest > -0x1000) longest = -0x1000;
- }
- else
- {
- left_array[0] = v3;
- left_array[1] = v2;
- left_array[2] = v1;
- left_section = 2;
- right_array[0] = v3;
- right_array[1] = v1;
- right_section = 1;
-
- if(RightSection_GT() <= 0) return FALSE;
- if(LeftSection_GT() <= 0)
- {
- left_section--;
- if(LeftSection_GT() <= 0) return FALSE;
- }
- if(longest < 0x1000) longest = 0x1000;
- }
-
- Ymin=v1->y;
- Ymax=min(v3->y-1,drawH);
-
- delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
- delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
- delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
-
- delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
- delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
-
-
-/*
-Mmm... adjust neg tex deltas... will sometimes cause slight
-texture distortions
- longest>>=16;
- if(longest)
- {
- if(longest<0) longest=-longest;
- if(delta_right_u<0)
- delta_right_u-=delta_right_u/longest;
- if(delta_right_v<0)
- delta_right_v-=delta_right_v/longest;
- }
-*/
-
-
- return TRUE;
-}
-
-__inline int RightSection_F4(void)
-{
- soft_vertex * v1 = right_array[ right_section ];
- soft_vertex * v2 = right_array[ right_section-1 ];
-
- int height = v2->y - v1->y;
- right_section_height = height;
- right_x = v1->x;
- if(height == 0)
- {
- return 0;
- }
- delta_right_x = (v2->x - v1->x) / height;
-
- return height;
-}
-
-__inline int LeftSection_F4(void)
-{
- soft_vertex * v1 = left_array[ left_section ];
- soft_vertex * v2 = left_array[ left_section-1 ];
-
- int height = v2->y - v1->y;
- left_section_height = height;
- left_x = v1->x;
- if(height == 0)
- {
- return 0;
- }
- delta_left_x = (v2->x - v1->x) / height;
-
- return height;
-}
-
-__inline BOOL NextRow_F4(void)
-{
- if(--left_section_height<=0)
- {
- if(--left_section > 0)
- while(LeftSection_F4()<=0)
- {
- if(--left_section <= 0) break;
- }
- }
- else
- {
- left_x += delta_left_x;
- }
-
- if(--right_section_height<=0)
- {
- if(--right_section > 0)
- while(RightSection_F4()<=0)
- {
- if(--right_section<=0) break;
- }
- }
- else
- {
- right_x += delta_right_x;
- }
- return FALSE;
-}
-
-__inline BOOL SetupSections_F4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4)
-{
- soft_vertex * v1, * v2, * v3, * v4;
- int height,width,longest1,longest2;
-
- v1 = vtx; v1->x=x1<<16;v1->y=y1;
- v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
- v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
- v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
-
- if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
- if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
- if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
- if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
- if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
- if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
-
- height = v4->y - v1->y; if(height == 0) height =1;
- width = (v4->x - v1->x)>>16;
- longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
- longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
-
- if(longest1 < 0) // 2 is right
- {
- if(longest2 < 0) // 3 is right
- {
- left_array[0] = v4;
- left_array[1] = v1;
- left_section = 1;
-
- height = v3->y - v1->y; if(height == 0) height=1;
- longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest1 >= 0)
- {
- right_array[0] = v4; // 1
- right_array[1] = v3; // 3
- right_array[2] = v1; // 4
- right_section = 2;
- }
- else
- {
- height = v4->y - v2->y; if(height == 0) height=1;
- longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
- if(longest1 >= 0)
- {
- right_array[0] = v4; // 1
- right_array[1] = v2; // 2
- right_array[2] = v1; // 4
- right_section = 2;
- }
- else
- {
- right_array[0] = v4; // 1
- right_array[1] = v3; // 2
- right_array[2] = v2; // 3
- right_array[3] = v1; // 4
- right_section = 3;
- }
- }
- }
- else
- {
- left_array[0] = v4;
- left_array[1] = v3; // 1
- left_array[2] = v1; // 2
- left_section = 2; // 3
- right_array[0] = v4; // 4
- right_array[1] = v2;
- right_array[2] = v1;
- right_section = 2;
- }
- }
- else
- {
- if(longest2 < 0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v2; // 2
- left_array[2] = v1; // 3
- left_section = 2; // 4
- right_array[0] = v4;
- right_array[1] = v3;
- right_array[2] = v1;
- right_section = 2;
- }
- else
- {
- right_array[0] = v4;
- right_array[1] = v1;
- right_section = 1;
-
- height = v3->y - v1->y; if(height == 0) height=1;
- longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest1<0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v3; // 3
- left_array[2] = v1; // 4
- left_section = 2;
- }
- else
- {
- height = v4->y - v2->y; if(height == 0) height=1;
- longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
- if(longest1<0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v2; // 2
- left_array[2] = v1; // 4
- left_section = 2;
- }
- else
- {
- left_array[0] = v4; // 1
- left_array[1] = v3; // 2
- left_array[2] = v2; // 3
- left_array[3] = v1; // 4
- left_section = 3;
- }
- }
- }
- }
-
- while(LeftSection_F4()<=0)
- {
- if(--left_section <= 0) break;
- }
-
- while(RightSection_F4()<=0)
- {
- if(--right_section <= 0) break;
- }
-
- Ymin=v1->y;
- Ymax=min(v4->y-1,drawH);
-
- return TRUE;
-}
-
-__inline int RightSection_FT4(void)
-{
- soft_vertex * v1 = right_array[ right_section ];
- soft_vertex * v2 = right_array[ right_section-1 ];
-
- int height = v2->y - v1->y;
- right_section_height = height;
- right_x = v1->x;
- right_u = v1->u;
- right_v = v1->v;
- if(height == 0)
- {
- return 0;
- }
- delta_right_x = (v2->x - v1->x) / height;
- delta_right_u = (v2->u - v1->u) / height;
- delta_right_v = (v2->v - v1->v) / height;
-
- return height;
-}
-
-__inline int LeftSection_FT4(void)
-{
- soft_vertex * v1 = left_array[ left_section ];
- soft_vertex * v2 = left_array[ left_section-1 ];
-
- int height = v2->y - v1->y;
- left_section_height = height;
- left_x = v1->x;
- left_u = v1->u;
- left_v = v1->v;
- if(height == 0)
- {
- return 0;
- }
- delta_left_x = (v2->x - v1->x) / height;
- delta_left_u = (v2->u - v1->u) / height;
- delta_left_v = (v2->v - v1->v) / height;
-
- return height;
-}
-
-__inline BOOL NextRow_FT4(void)
-{
- if(--left_section_height<=0)
- {
- if(--left_section > 0)
- while(LeftSection_FT4()<=0)
- {
- if(--left_section <= 0) break;
- }
- }
- else
- {
- left_x += delta_left_x;
- left_u += delta_left_u;
- left_v += delta_left_v;
- }
-
- if(--right_section_height<=0)
- {
- if(--right_section > 0)
- while(RightSection_FT4()<=0)
- {
- if(--right_section<=0) break;
- }
- }
- else
- {
- right_x += delta_right_x;
- right_u += delta_right_u;
- right_v += delta_right_v;
- }
- return FALSE;
-}
-
-__inline BOOL SetupSections_FT4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
-{
- soft_vertex * v1, * v2, * v3, * v4;
- int height,width,longest1,longest2;
-
- v1 = vtx; v1->x=x1<<16;v1->y=y1;
- v1->u=tx1<<16;v1->v=ty1<<16;
-
- v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
- v2->u=tx2<<16;v2->v=ty2<<16;
-
- v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
- v3->u=tx3<<16;v3->v=ty3<<16;
-
- v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
- v4->u=tx4<<16;v4->v=ty4<<16;
-
- if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
- if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
- if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
- if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
- if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
- if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
-
- height = v4->y - v1->y; if(height == 0) height =1;
- width = (v4->x - v1->x)>>16;
- longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
- longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
-
- if(longest1 < 0) // 2 is right
- {
- if(longest2 < 0) // 3 is right
- {
- left_array[0] = v4;
- left_array[1] = v1;
- left_section = 1;
-
- height = v3->y - v1->y; if(height == 0) height=1;
- longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest1 >= 0)
- {
- right_array[0] = v4; // 1
- right_array[1] = v3; // 3
- right_array[2] = v1; // 4
- right_section = 2;
- }
- else
- {
- height = v4->y - v2->y; if(height == 0) height=1;
- longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
- if(longest1 >= 0)
- {
- right_array[0] = v4; // 1
- right_array[1] = v2; // 2
- right_array[2] = v1; // 4
- right_section = 2;
- }
- else
- {
- right_array[0] = v4; // 1
- right_array[1] = v3; // 2
- right_array[2] = v2; // 3
- right_array[3] = v1; // 4
- right_section = 3;
- }
- }
- }
- else
- {
- left_array[0] = v4;
- left_array[1] = v3; // 1
- left_array[2] = v1; // 2
- left_section = 2; // 3
- right_array[0] = v4; // 4
- right_array[1] = v2;
- right_array[2] = v1;
- right_section = 2;
- }
- }
- else
- {
- if(longest2 < 0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v2; // 2
- left_array[2] = v1; // 3
- left_section = 2; // 4
- right_array[0] = v4;
- right_array[1] = v3;
- right_array[2] = v1;
- right_section = 2;
- }
- else
- {
- right_array[0] = v4;
- right_array[1] = v1;
- right_section = 1;
-
- height = v3->y - v1->y; if(height == 0) height=1;
- longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest1<0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v3; // 3
- left_array[2] = v1; // 4
- left_section = 2;
- }
- else
- {
- height = v4->y - v2->y; if(height == 0) height=1;
- longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
- if(longest1<0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v2; // 2
- left_array[2] = v1; // 4
- left_section = 2;
- }
- else
- {
- left_array[0] = v4; // 1
- left_array[1] = v3; // 2
- left_array[2] = v2; // 3
- left_array[3] = v1; // 4
- left_section = 3;
- }
- }
- }
- }
-
- while(LeftSection_FT4()<=0)
- {
- if(--left_section <= 0) break;
- }
-
- while(RightSection_FT4()<=0)
- {
- if(--right_section <= 0) break;
- }
-
- Ymin=v1->y;
- Ymax=min(v4->y-1,drawH);
-
- return TRUE;
-}
-
-__inline int RightSection_GT4(void)
-{
- soft_vertex * v1 = right_array[ right_section ];
- soft_vertex * v2 = right_array[ right_section-1 ];
-
- int height = v2->y - v1->y;
- right_section_height = height;
- right_x = v1->x;
- right_u = v1->u;
- right_v = v1->v;
- right_R = v1->R;
- right_G = v1->G;
- right_B = v1->B;
-
- if(height == 0)
- {
- return 0;
- }
- delta_right_x = (v2->x - v1->x) / height;
- delta_right_u = (v2->u - v1->u) / height;
- delta_right_v = (v2->v - v1->v) / height;
- delta_right_R = (v2->R - v1->R) / height;
- delta_right_G = (v2->G - v1->G) / height;
- delta_right_B = (v2->B - v1->B) / height;
-
- return height;
-}
-
-__inline int LeftSection_GT4(void)
-{
- soft_vertex * v1 = left_array[ left_section ];
- soft_vertex * v2 = left_array[ left_section-1 ];
-
- int height = v2->y - v1->y;
- left_section_height = height;
- left_x = v1->x;
- left_u = v1->u;
- left_v = v1->v;
- left_R = v1->R;
- left_G = v1->G;
- left_B = v1->B;
-
- if(height == 0)
- {
- return 0;
- }
- delta_left_x = (v2->x - v1->x) / height;
- delta_left_u = (v2->u - v1->u) / height;
- delta_left_v = (v2->v - v1->v) / height;
- delta_left_R = (v2->R - v1->R) / height;
- delta_left_G = (v2->G - v1->G) / height;
- delta_left_B = (v2->B - v1->B) / height;
-
- return height;
-}
-
-__inline BOOL NextRow_GT4(void)
-{
- if(--left_section_height<=0)
- {
- if(--left_section > 0)
- while(LeftSection_GT4()<=0)
- {
- if(--left_section <= 0) break;
- }
- }
- else
- {
- left_x += delta_left_x;
- left_u += delta_left_u;
- left_v += delta_left_v;
- left_R += delta_left_R;
- left_G += delta_left_G;
- left_B += delta_left_B;
- }
-
- if(--right_section_height<=0)
- {
- if(--right_section > 0)
- while(RightSection_GT4()<=0)
- {
- if(--right_section<=0) break;
- }
- }
- else
- {
- right_x += delta_right_x;
- right_u += delta_right_u;
- right_v += delta_right_v;
- right_R += delta_right_R;
- right_G += delta_right_G;
- right_B += delta_right_B;
- }
- return FALSE;
-}
-
-__inline BOOL SetupSections_GT4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int rgb1, int rgb2, int rgb3, int rgb4)
-{
- soft_vertex * v1, * v2, * v3, * v4;
- int height,width,longest1,longest2;
-
- v1 = vtx; v1->x=x1<<16;v1->y=y1;
- v1->u=tx1<<16;v1->v=ty1<<16;
- v1->R=(rgb1) & 0x00ff0000;
- v1->G=(rgb1<<8) & 0x00ff0000;
- v1->B=(rgb1<<16) & 0x00ff0000;
-
- v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
- v2->u=tx2<<16;v2->v=ty2<<16;
- v2->R=(rgb2) & 0x00ff0000;
- v2->G=(rgb2<<8) & 0x00ff0000;
- v2->B=(rgb2<<16) & 0x00ff0000;
-
- v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
- v3->u=tx3<<16;v3->v=ty3<<16;
- v3->R=(rgb3) & 0x00ff0000;
- v3->G=(rgb3<<8) & 0x00ff0000;
- v3->B=(rgb3<<16) & 0x00ff0000;
-
- v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
- v4->u=tx4<<16;v4->v=ty4<<16;
- v4->R=(rgb4) & 0x00ff0000;
- v4->G=(rgb4<<8) & 0x00ff0000;
- v4->B=(rgb4<<16) & 0x00ff0000;
-
- if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
- if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
- if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
- if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
- if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
- if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
-
- height = v4->y - v1->y; if(height == 0) height =1;
- width = (v4->x - v1->x)>>16;
- longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
- longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
-
- if(longest1 < 0) // 2 is right
- {
- if(longest2 < 0) // 3 is right
- {
- left_array[0] = v4;
- left_array[1] = v1;
- left_section = 1;
-
- height = v3->y - v1->y; if(height == 0) height=1;
- longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest1 >= 0)
- {
- right_array[0] = v4; // 1
- right_array[1] = v3; // 3
- right_array[2] = v1; // 4
- right_section = 2;
- }
- else
- {
- height = v4->y - v2->y; if(height == 0) height=1;
- longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
- if(longest1 >= 0)
- {
- right_array[0] = v4; // 1
- right_array[1] = v2; // 2
- right_array[2] = v1; // 4
- right_section = 2;
- }
- else
- {
- right_array[0] = v4; // 1
- right_array[1] = v3; // 2
- right_array[2] = v2; // 3
- right_array[3] = v1; // 4
- right_section = 3;
- }
- }
- }
- else
- {
- left_array[0] = v4;
- left_array[1] = v3; // 1
- left_array[2] = v1; // 2
- left_section = 2; // 3
- right_array[0] = v4; // 4
- right_array[1] = v2;
- right_array[2] = v1;
- right_section = 2;
- }
- }
- else
- {
- if(longest2 < 0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v2; // 2
- left_array[2] = v1; // 3
- left_section = 2; // 4
- right_array[0] = v4;
- right_array[1] = v3;
- right_array[2] = v1;
- right_section = 2;
- }
- else
- {
- right_array[0] = v4;
- right_array[1] = v1;
- right_section = 1;
-
- height = v3->y - v1->y; if(height == 0) height=1;
- longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
- if(longest1<0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v3; // 3
- left_array[2] = v1; // 4
- left_section = 2;
- }
- else
- {
- height = v4->y - v2->y; if(height == 0) height=1;
- longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
- if(longest1<0)
- {
- left_array[0] = v4; // 1
- left_array[1] = v2; // 2
- left_array[2] = v1; // 4
- left_section = 2;
- }
- else
- {
- left_array[0] = v4; // 1
- left_array[1] = v3; // 2
- left_array[2] = v2; // 3
- left_array[3] = v1; // 4
- left_section = 3;
- }
- }
- }
- }
-
- while(LeftSection_GT4()<=0)
- {
- if(--left_section <= 0) break;
- }
-
- while(RightSection_GT4()<=0)
- {
- if(--right_section <= 0) break;
- }
-
- Ymin=v1->y;
- Ymax=min(v4->y-1,drawH);
-
- return TRUE;
-}
-
-////////////////////////////////////////////////////////////////////////
-// POLY FUNCS
-////////////////////////////////////////////////////////////////////////
-
-////////////////////////////////////////////////////////////////////////
-// POLY 3/4 FLAT SHADED
-////////////////////////////////////////////////////////////////////////
-
-__inline void drawPoly3Fi(short x1, short y1, short x2, short y2, short x3, short y3, int rgb)
-{
- int i,j,xmin,xmax,ymin,ymax;
- unsigned short color;
- uint32_t lcolor;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_F(x1,y1,x2,y2,x3,y3)) return;
-
- ymax=Ymax;
-
- color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
- lcolor=lSetMask|(((uint32_t)(color))<<16)|color;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_F()) return;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- color |=sSetMask;
- for (i=ymin;i<=ymax;i++)
- {
- xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
- xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- *((uint32_t *)&psxVuw[(i<<10)+j])=lcolor;
- }
- if(j==xmax) psxVuw[(i<<10)+j]=color;
-
- if(NextRow_F()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
- xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10)+j], lcolor);
- }
- if(j == xmax)
- GetShadeTransCol(&psxVuw[(i << 10) + j],color);
-
- if(NextRow_F()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3F(int rgb)
-{
- drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
-}
-
-#ifdef POLYQUAD3FS
-
-void drawPoly4F_TRI(int rgb)
-{
- drawPoly3Fi(lx1,ly1,lx3,ly3,lx2,ly2,rgb);
- drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
-}
-
-#endif
-
-// more exact:
-
-void drawPoly4F(int rgb)
-{
- int i,j,xmin,xmax,ymin,ymax;
- unsigned short color;unsigned int lcolor;
-
- if(lx0>drawW && lx1>drawW && lx2>drawW && lx3>drawW) return;
- if(ly0>drawH && ly1>drawH && ly2>drawH && ly3>drawH) return;
- if(lx0<drawX && lx1<drawX && lx2<drawX && lx3<drawX) return;
- if(ly0<drawY && ly1<drawY && ly2<drawY && ly3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_F4(lx0,ly0,lx1,ly1,lx2,ly2,lx3,ly3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_F4()) return;
-
- color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
- lcolor= lSetMask|(((uint32_t)(color))<<16)|color;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- color |=sSetMask;
- for (i=ymin;i<=ymax;i++)
- {
- xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
- xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- *((uint32_t *)&psxVuw[(i<<10)+j])=lcolor;
- }
- if(j==xmax) psxVuw[(i<<10)+j]=color;
-
- if(NextRow_F4()) return;
- }
- return;
- }
-
-#endif
-
- for (i = ymin; i <= ymax; i++)
- {
- xmin = left_x >> 16; if(drawX > xmin) xmin = drawX;
- xmax = (right_x >> 16) - 1; if(drawW < xmax) xmax = drawW;
-
- for(j = xmin; j < xmax; j += 2)
- {
- GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10) + j],lcolor);
- }
- if(j == xmax) GetShadeTransCol(&psxVuw[(i<<10) + j],color);
-
- if(NextRow_F4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// POLY 3/4 F-SHADED TEX PAL 4
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TEx4(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,XAdjust;
- int clutP;
- short tC1,tC2;
-
- if (x1 > drawW && x2 > drawW && x3 > drawW) return;
- if (y1 > drawH && y2 > drawH && y3 > drawH) return;
- if (x1 < drawX && x2 < drawX && x3 < drawX) return;
- if (y1 < drawY && y2 < drawY && y3 < drawY) return;
- if (drawY >= drawH) return;
- if (drawX >= drawW) return;
-
- if (!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax = Ymax;
-
- for (ymin = Ymin; ymin < drawY; ymin++)
- if (NextRow_FT()) return;
-
- clutP = (clY << 10) + clX;
-
- YAdjust = ((GlobalTextAddrY) << 11) + (GlobalTextAddrX << 1);
-
- difX = delta_right_u; difX2 = difX << 1;
- difY = delta_right_v; difY2 = difY << 1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16);
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16);
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
-{
- int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,XAdjust;
- int clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1;
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- XAdjust=((posX+difX)>>16);
-
- TXV=(posY+difY)>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- XAdjust=((posX+difX)>>16);
-
- TXV=(posY+difY)>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,XAdjust;
- int clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
- if(xmax>xmin) xmax--;
-
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16)%TWin.Position.x1;
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16)%TWin.Position.x1;
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-#ifdef POLYQUAD3
-
-void drawPoly4TEx4_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- drawPoly3TEx4(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY);
- drawPoly3TEx4(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY);
-}
-
-#endif
-
-// more exact:
-
-void drawPoly4TEx4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP,XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16);
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
-
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16);
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP,XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<10)+GlobalTextAddrX;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- XAdjust=((posX+difX)>>16);
-
- TXV=(posY+difY)>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
-
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
-
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- XAdjust=((posX+difX)>>16);
-
- TXV=(posY+difY)>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP,XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16)%TWin.Position.x1;
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16)%TWin.Position.x1;
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TEx4_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP,XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16)%TWin.Position.x1;
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16)%TWin.Position.x1;
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-////////////////////////////////////////////////////////////////////////
-// POLY 3 F-SHADED TEX PAL 8
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TEx8(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- ((posX+difX)>>16)];
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
-
- if(j==xmax)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- ((posX+difX)>>16)];
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
-
- if(j==xmax)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
-
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
-{
- int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- TXU=(posX+difX)>>16;
- TXV=(posY+difY)>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
-
- if(j==xmax)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- TXU=(posX+difX)>>16;
- TXV=(posY+difY)>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
-
- if(j==xmax)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
-
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
- if(xmax>xmin) xmax--;
-
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
-
- if(j==xmax)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
-
- if(j==xmax)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
-
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-#ifdef POLYQUAD3
-
-void drawPoly4TEx8_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- drawPoly3TEx8(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY);
-
- drawPoly3TEx8(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY);
-}
-
-#endif
-
-// more exact:
-
-void drawPoly4TEx8(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- ((posX+difX)>>16)];
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- ((posX+difX)>>16)];
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- TXU=(posX+difX)>>16;
- TXV=(posY+difY)>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- TXU=(posX+difX)>>16;
- TXV=(posY+difY)>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i, j, xmin, xmax, ymin, ymax;
- int difX, difY, difX2, difY2;
- int posX, posY, YAdjust, clutP;
- short tC1, tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX += difX2;
- posY += difY2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TEx8_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
- GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16);
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
- }
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// POLY 3 F-SHADED TEX 15 BIT
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TD(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY,difX2, difY2;
- int posX,posY;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT()) return;
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY,difX2, difY2;
- int posX,posY;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT()) return;
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
- }
- if(NextRow_FT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
- }
- if(NextRow_FT())
- {
- return;
- }
- }
-}
-
-
-////////////////////////////////////////////////////////////////////////
-
-#ifdef POLYQUAD3
-
-void drawPoly4TD_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
-{
- drawPoly3TD(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4);
- drawPoly3TD(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4);
-}
-
-#endif
-
-// more exact:
-
-void drawPoly4TD(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX,posY;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX,posY;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY)<<10)+TWin.Position.y0+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TD_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int difX, difY, difX2, difY2;
- int posX, posY;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_FT4()) return;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY)<<10)+TWin.Position.y0+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG_S(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
- }
- if(NextRow_FT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
-
- posX+=difX2;
- posY+=difY2;
- }
- if(j==xmax)
- GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
- }
- if(NextRow_FT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// POLY 3/4 G-SHADED
-////////////////////////////////////////////////////////////////////////
-
-__inline void drawPoly3Gi(short x1,short y1,short x2,short y2,short x3,short y3, int rgb1, int rgb2, int rgb3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_G(x1,y1,x2,y2,x3,y3,rgb1,rgb2,rgb3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_G()) return;
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && iDither!=2)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- *((uint32_t *)&psxVuw[(i<<10)+j])=
- ((((cR1+difR) <<7)&0x7c000000)|(((cG1+difG) << 2)&0x03e00000)|(((cB1+difB)>>3)&0x001f0000)|
- (((cR1) >> 9)&0x7c00)|(((cG1) >> 14)&0x03e0)|(((cB1) >> 19)&0x001f))|lSetMask;
-
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- psxVuw[(i<<10)+j]=(((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f))|sSetMask;
- }
- if(NextRow_G()) return;
- }
- return;
- }
-
-#endif
-
- if(iDither==2)
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- GetShadeTransCol_Dither(&psxVuw[(i<<10)+j],(cB1>>16),(cG1>>16),(cR1>>16));
-
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_G()) return;
- }
- else
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- GetShadeTransCol(&psxVuw[(i<<10)+j],((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f));
-
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_G()) return;
- }
-
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3G(int rgb1, int rgb2, int rgb3)
-{
- drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,rgb1,rgb2,rgb3);
-}
-
-// draw two g-shaded tris for right psx shading emulation
-
-void drawPoly4G(int rgb1, int rgb2, int rgb3, int rgb4)
-{
- drawPoly3Gi(lx1,ly1,lx3,ly3,lx2,ly2,
- rgb2,rgb4,rgb3);
- drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,
- rgb1,rgb2,rgb3);
-}
-
-////////////////////////////////////////////////////////////////////////
-// POLY 3/4 G-SHADED TEX PAL4
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGEx4(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int col1, int col2, int col3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP,XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=((left_x) >> 16);
- xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16);
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int col1, int col2, int col3)
-{
- int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP,XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=((left_x) >> 16);
- xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- XAdjust=((posX+difX)>>16);
-
- TXV=(posY+difY)>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- XAdjust=(posX>>16);
-
- TXV=posY>>16;
- n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
-
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
-{
- int i, j, xmin, xmax, ymin, ymax;
- int cR1, cG1, cB1;
- int difR, difB, difG, difR2, difB2, difG2;
- int difX, difY,difX2, difY2;
- int posX, posY, YAdjust, clutP, XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=((left_x) >> 16);
- xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16)%TWin.Position.x1;
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- XAdjust=(posX>>16)%TWin.Position.x1;
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-// note: the psx is doing g-shaded quads as two g-shaded tris,
-// like the following func... sadly texturing is not 100%
-// correct that way, so small texture distortions can
-// happen...
-
-void drawPoly4TGEx4_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col3, int col4)
-{
- drawPoly3TGEx4_IL(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY,
- col2,col4,col3);
- drawPoly3TGEx4_IL(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY,
- col1,col2,col3);
-}
-
-#ifdef POLYQUAD3GT
-
-void drawPoly4TGEx4_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col3, int col4)
-{
- drawPoly3TGEx4(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY,
- col2,col4,col3);
- drawPoly3TGEx4(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY,
- col1,col2,col3);
-}
-
-#endif
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TGEx4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col4, int col3)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP,XAdjust;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
-
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
- difR=(right_R-cR1)/num;
- difG=(right_G-cG1)/num;
- difB=(right_B-cB1)/num;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- XAdjust=((posX+difX)>>16);
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC2=(tC2>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
-
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
- difR=(right_R-cR1)/num;
- difG=(right_G-cG1)/num;
- difB=(right_B-cB1)/num;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<=xmax;j++)
- {
- XAdjust=(posX>>16);
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
- (XAdjust>>1)];
- tC1=(tC1>>((XAdjust&1)<<2))&0xf;
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TGEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col3, int col4)
-{
- drawPoly3TGEx4_TW(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY,
- col2,col4,col3);
-
- drawPoly3TGEx4_TW(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY,
- col1,col2,col3);
-}
-
-////////////////////////////////////////////////////////////////////////
-// POLY 3/4 G-SHADED TEX PAL8
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGEx8(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+((posX>>16))];
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- (((posX+difX)>>16))];
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+((posX>>16))];
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+((posX>>16))];
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
-{
- int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- TXU=(posX+difX)>>16;
- TXV=(posY+difY)>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- TXU=posX>>16;
- TXV=posY>>16;
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
-
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY,difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
- YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
- YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
-
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
- YAdjust+((posX>>16)%TWin.Position.x1)];
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-// note: two g-shaded tris: small texture distortions can happen
-
-void drawPoly4TGEx8_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col3, int col4)
-{
- drawPoly3TGEx8_IL(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY,
- col2,col4,col3);
- drawPoly3TGEx8_IL(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY,
- col1,col2,col3);
-}
-
-#ifdef POLYQUAD3GT
-
-void drawPoly4TGEx8_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col3, int col4)
-{
- drawPoly3TGEx8(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY,
- col2,col4,col3);
- drawPoly3TGEx8(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY,
- col1,col2,col3);
-}
-
-#endif
-
-void drawPoly4TGEx8(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col4, int col3)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY, difX2, difY2;
- int posX,posY,YAdjust,clutP;
- short tC1,tC2;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT4()) return;
-
- clutP=(clY<<10)+clX;
-
- YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
- difR=(right_R-cR1)/num;
- difG=(right_G-cG1)/num;
- difB=(right_B-cB1)/num;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
- ((posX+difX)>>16)];
-
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1]|
- ((int)psxVuw[clutP+tC2])<<16,
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- }
- if(NextRow_GT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
- difR=(right_R-cR1)/num;
- difG=(right_G-cG1)/num;
- difB=(right_B-cB1)/num;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<=xmax;j++)
- {
- tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[clutP+tC1],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TGEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
- short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
- short clX, short clY,
- int col1, int col2, int col3, int col4)
-{
- drawPoly3TGEx8_TW(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- clX,clY,
- col2,col4,col3);
- drawPoly3TGEx8_TW(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- clX,clY,
- col1,col2,col3);
-}
-
-////////////////////////////////////////////////////////////////////////
-// POLY 3 G-SHADED TEX 15 BIT
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGD(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, int col1, int col2, int col3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY,difX2, difY2;
- int posX,posY;
-
- if(x1>drawW && x2>drawW && x3>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax=Ymax;
-
- for(ymin=Ymin;ymin<drawY;ymin++)
- if(NextRow_GT()) return;
-
- difR=delta_right_R;
- difG=delta_right_G;
- difB=delta_right_B;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
- difX=delta_right_u;difX2=difX<<1;
- difY=delta_right_v;difY2=difY<<1;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX],
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3TGD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, int col1, int col2, int col3)
-{
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY,difX2, difY2;
- int posX,posY;
-
- if (x1>drawW && x2>drawW && x3>drawW) return;
- if (y1>drawH && y2>drawH && y3>drawH) return;
- if (x1<drawX && x2<drawX && x3<drawX) return;
- if (y1<drawY && y2<drawY && y3<drawY) return;
- if (drawY >= drawH) return;
- if (drawX >= drawW) return;
-
- if (!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
-
- ymax = Ymax;
-
- for(ymin = Ymin; ymin < drawY; ymin++)
- if(NextRow_GT()) return;
-
- difR = delta_right_R;
- difG = delta_right_G;
- difB = delta_right_B;
- difR2 = difR<<1;
- difG2 = difG<<1;
- difB2 = difB<<1;
- difX = delta_right_u; difX2 = difX<<1;
- difY = delta_right_v; difY2 = difY<<1;
-
-#ifdef FASTSOLID
-
- if (!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i = ymin; i <= ymax; i++)
- {
- xmin = (left_x >> 16);
- xmax = (right_x >> 16) - 1; //!!!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- if(NextRow_GT())
- {
- return;
- }
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
- if(drawW<xmax) xmax=drawW;
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
-
- for(j=xmin;j<=xmax;j++)
- {
- if(iDither)
- GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
- ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT())
- {
- return;
- }
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-// note: two g-shaded tris: small texture distortions can happen
-
-#ifdef POLYQUAD3GT
-
-void drawPoly4TGD_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int col1, int col2, int col3, int col4)
-{
- drawPoly3TGD(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- col2,col4,col3);
- drawPoly3TGD(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- col1,col2,col3);
-}
-
-#endif
-
-void drawPoly4TGD(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int col1, int col2, int col4, int col3)
-{
- int num;
- int i,j,xmin,xmax,ymin,ymax;
- int cR1,cG1,cB1;
- int difR,difB,difG,difR2,difB2,difG2;
- int difX, difY, difX2, difY2;
- int posX,posY;
-
- if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
- if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
- if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
- if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
-
- ymax = Ymax;
-
- for (ymin = Ymin; ymin < drawY; ymin++)
- if (NextRow_GT4()) return;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans && !iDither)
- {
- for (i = ymin; i <= ymax; i++)
- {
- xmin = (left_x >> 16);
- xmax = (right_x >> 16);
-
- if(xmax >= xmin)
- {
- posX = left_u;
- posY = left_v;
-
- num = (xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
- difR=(right_R-cR1)/num;
- difG=(right_G-cG1)/num;
- difB=(right_B-cB1)/num;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<xmax;j+=2)
- {
- GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
- (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX],
- (cB1>>16)|((cB1+difB)&0xff0000),
- (cG1>>16)|((cG1+difG)&0xff0000),
- (cR1>>16)|((cR1+difR)&0xff0000));
- posX+=difX2;
- posY+=difY2;
- cR1+=difR2;
- cG1+=difG2;
- cB1+=difB2;
- }
- if(j==xmax)
- GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
- (cB1>>16),(cG1>>16),(cR1>>16));
- }
- if(NextRow_GT4()) return;
- }
- return;
- }
-
-#endif
-
- for (i=ymin;i<=ymax;i++)
- {
- xmin=(left_x >> 16);
- xmax=(right_x >> 16);
-
- if(xmax>=xmin)
- {
- posX=left_u;
- posY=left_v;
-
- num=(xmax-xmin);
- if(num==0) num=1;
- difX=(right_u-posX)/num;
- difY=(right_v-posY)/num;
- difX2=difX<<1;
- difY2=difY<<1;
-
- cR1=left_R;
- cG1=left_G;
- cB1=left_B;
- difR=(right_R-cR1)/num;
- difG=(right_G-cG1)/num;
- difB=(right_B-cB1)/num;
- difR2=difR<<1;
- difG2=difG<<1;
- difB2=difB<<1;
-
- if(xmin<drawX)
- {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
- xmax--;if(drawW<xmax) xmax=drawW;
-
- for(j=xmin;j<=xmax;j++)
- {
- if(iDither)
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
- (cB1>>16),(cG1>>16),(cR1>>16));
- else
- GetTextureTransColGX(&psxVuw[(i<<10)+j],
- psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
- (cB1>>16),(cG1>>16),(cR1>>16));
- posX+=difX;
- posY+=difY;
- cR1+=difR;
- cG1+=difG;
- cB1+=difB;
- }
- }
- if(NextRow_GT4()) return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4TGD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int col1, int col2, int col3, int col4)
-{
- drawPoly3TGD_TW(x2,y2,x3,y3,x4,y4,
- tx2,ty2,tx3,ty3,tx4,ty4,
- col2,col4,col3);
- drawPoly3TGD_TW(x1,y1,x2,y2,x4,y4,
- tx1,ty1,tx2,ty2,tx4,ty4,
- col1,col2,col3);
-}
-
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////
-
-
-/*
-// no real rect test, but it does its job the way I need it
-__inline BOOL IsNoRect(void)
-{
- if(lx0==lx1 && lx2==lx3) return FALSE;
- if(lx0==lx2 && lx1==lx3) return FALSE;
- if(lx0==lx3 && lx1==lx2) return FALSE;
- return TRUE;
-}
-*/
-
-// real rect test
-__inline BOOL IsNoRect(void)
-{
- //if(!(dwActFixes&0x200)) return FALSE;
-
- if(ly0==ly1)
- {
- if(lx1==lx3 && ly3==ly2 && lx2==lx0) return FALSE;
- if(lx1==lx2 && ly2==ly3 && lx3==lx0) return FALSE;
- return TRUE;
- }
-
- if(ly0==ly2)
- {
- if(lx2==lx3 && ly3==ly1 && lx1==lx0) return FALSE;
- if(lx2==lx1 && ly1==ly3 && lx3==lx0) return FALSE;
- return TRUE;
- }
-
- if(ly0==ly3)
- {
- if(lx3==lx2 && ly2==ly1 && lx1==lx0) return FALSE;
- if(lx3==lx1 && ly1==ly2 && lx2==lx0) return FALSE;
- return TRUE;
- }
- return TRUE;
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3FT(unsigned char *baseAddr)
-{
- uint32_t *gpuData = ((uint32_t *) baseAddr);
-
- if(GlobalTextIL && GlobalTextTP<2)
- {
- if(GlobalTextTP==0)
- drawPoly3TEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- else
- drawPoly3TEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- }
-
- if(!bUsingTWin)// && !(dwActFixes&0x100))
- {
- switch(GlobalTextTP) // depending on texture mode
- {
- case 0:
- drawPoly3TEx4(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 1:
- drawPoly3TEx8(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 2:
- drawPoly3TD(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
- return;
- }
- return;
- }
-
- switch(GlobalTextTP) // depending on texture mode
- {
- case 0:
- drawPoly3TEx4_TW(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 1:
- drawPoly3TEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 2:
- drawPoly3TD_TW(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
- return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4FT(unsigned char *baseAddr)
-{
- uint32_t *gpuData = ((uint32_t *) baseAddr);
-
- if(GlobalTextIL && GlobalTextTP<2)
- {
- if(GlobalTextTP==0)
- drawPoly4TEx4_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- else
- drawPoly4TEx8_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- }
-
- if(!bUsingTWin)
- {
-#ifdef POLYQUAD3GT
- if(IsNoRect())
- {
- switch (GlobalTextTP)
- {
- case 0:
- drawPoly4TEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 1:
- drawPoly4TEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 2:
- drawPoly4TD_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
- return;
- }
- return;
- }
-#endif
-
- switch (GlobalTextTP)
- {
- case 0: // grandia investigations needed
- drawPoly4TEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 1:
- drawPoly4TEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 2:
- drawPoly4TD(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
- return;
- }
- return;
- }
-
- switch (GlobalTextTP)
- {
- case 0:
- drawPoly4TEx4_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 1:
- drawPoly4TEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 2:
- drawPoly4TD_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
- return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly3GT(unsigned char * baseAddr)
-{
- uint32_t *gpuData = ((uint32_t *) baseAddr);
-
- if(GlobalTextIL && GlobalTextTP<2)
- {
- if(GlobalTextTP==0)
- drawPoly3TGEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6]);
- else
- drawPoly3TGEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6]);
- return;
- }
-
- if(!bUsingTWin)
- {
- switch (GlobalTextTP)
- {
- case 0:
- drawPoly3TGEx4(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6]);
- return;
- case 1:
- drawPoly3TGEx8(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6]);
- return;
- case 2:
- drawPoly3TGD(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6]);
- return;
- }
- return;
- }
-
- switch(GlobalTextTP)
- {
- case 0:
- drawPoly3TGEx4_TW(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6]);
- return;
- case 1:
- drawPoly3TGEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6]);
- return;
- case 2:
- drawPoly3TGD_TW(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6]);
- return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void drawPoly4GT(unsigned char *baseAddr)
-{
- uint32_t *gpuData = ((uint32_t *) baseAddr);
-
- if(GlobalTextIL && GlobalTextTP<2)
- {
- if(GlobalTextTP==0)
- drawPoly4TGEx4_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- else
- drawPoly4TGEx8_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- }
-
- if(!bUsingTWin)
- {
-#ifdef POLYQUAD3GT
- if(IsNoRect())
- {
- switch (GlobalTextTP)
- {
- case 0:
- drawPoly4TGEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
-
- return;
- case 1:
- drawPoly4TGEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- case 2:
- drawPoly4TGD_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff),((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- }
- return;
- }
-#endif
-
- switch (GlobalTextTP)
- {
- case 0:
- drawPoly4TGEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
-
- return;
- case 1:
- drawPoly4TGEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- case 2:
- drawPoly4TGD(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff),((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- }
- return;
- }
-
- switch (GlobalTextTP)
- {
- case 0:
- drawPoly4TGEx4_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- case 1:
- drawPoly4TGEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
- (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
- ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
- gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- case 2:
- drawPoly4TGD_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff),((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
- return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-// SPRITE FUNCS
-////////////////////////////////////////////////////////////////////////
-
-void DrawSoftwareSpriteTWin(unsigned char * baseAddr, int w, int h)
-{
- uint32_t *gpuData = (uint32_t *)baseAddr;
- short sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3;
- short tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3;
-
- sx0=lx0;
- sy0=ly0;
-
- sx0=sx3=sx0+PSXDisplay.DrawOffset.x;
- sx1=sx2=sx0+w;
- sy0=sy1=sy0+PSXDisplay.DrawOffset.y;
- sy2=sy3=sy0+h;
-
- tx0=tx3=gpuData[2]&0xff;
- tx1=tx2=tx0+w;
- ty0=ty1=(gpuData[2]>>8)&0xff;
- ty2=ty3=ty0+h;
-
- switch (GlobalTextTP)
- {
- case 0:
- drawPoly4TEx4_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
- tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 1:
- drawPoly4TEx8_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
- tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
- ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
- return;
- case 2:
- drawPoly4TD_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
- tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3);
- return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void DrawSoftwareSpriteMirror(unsigned char * baseAddr, int w, int h)
-{
- int sprtY,sprtX,sprtW,sprtH,lXDir,lYDir;
- int clutY0,clutX0,clutP,textX0,textY0,sprtYa,sprCY,sprCX,sprA;
- short tC;
- uint32_t *gpuData = (uint32_t *)baseAddr;
- sprtY = ly0;
- sprtX = lx0;
- sprtH = h;
- sprtW = w;
- clutY0 = (gpuData[2]>>22) & iGPUHeightMask;
- clutX0 = (gpuData[2]>>12) & 0x3f0;
- clutP = (clutY0<<11) + (clutX0<<1);
- textY0 = ((gpuData[2]>>8) & 0x000000ff) + GlobalTextAddrY;
- textX0 = (gpuData[2] & 0x000000ff);
-
- sprtX+=PSXDisplay.DrawOffset.x;
- sprtY+=PSXDisplay.DrawOffset.y;
-
-// while (sprtX>1023) sprtX-=1024;
-// while (sprtY>MAXYLINESMIN1) sprtY-=MAXYLINES;
-
- if(sprtX>drawW)
- {
-// if((sprtX+sprtW)>1023) sprtX-=1024;
-// else return;
- return;
- }
-
- if(sprtY>drawH)
- {
-// if ((sprtY+sprtH)>MAXYLINESMIN1) sprtY-=MAXYLINES;
-// else return;
- return;
- }
-
- if(sprtY<drawY)
- {
- if((sprtY+sprtH)<drawY) return;
- sprtH-=(drawY-sprtY);
- textY0+=(drawY-sprtY);
- sprtY=drawY;
- }
-
- if(sprtX<drawX)
- {
- if((sprtX+sprtW)<drawX) return;
- sprtW-=(drawX-sprtX);
- textX0+=(drawX-sprtX);
- sprtX=drawX;
- }
-
- if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
- if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
-
- if(usMirror&0x1000) lXDir=-1; else lXDir=1;
- if(usMirror&0x2000) lYDir=-1; else lYDir=1;
-
- switch (GlobalTextTP)
- {
- case 0: // texture is 4-bit
-
- sprtW=sprtW/2;
- textX0=(GlobalTextAddrX<<1)+(textX0>>1);
- sprtYa=(sprtY<<10);
- clutP=(clutY0<<10)+clutX0;
- for (sprCY=0;sprCY<sprtH;sprCY++)
- for (sprCX=0;sprCX<sprtW;sprCX++)
- {
- tC= psxVub[((textY0+(sprCY*lYDir))<<11) + textX0 +(sprCX*lXDir)];
- sprA=sprtYa+(sprCY<<10)+sprtX + (sprCX<<1);
- GetTextureTransColG_SPR(&psxVuw[sprA],psxVuw[clutP+((tC>>4)&0xf)]);
- GetTextureTransColG_SPR(&psxVuw[sprA+1],psxVuw[clutP+(tC&0xf)]);
- }
- return;
-
- case 1:
-
- clutP>>=1;
- for(sprCY=0;sprCY<sprtH;sprCY++)
- for(sprCX=0;sprCX<sprtW;sprCX++)
- {
- tC = psxVub[((textY0+(sprCY*lYDir))<<11)+(GlobalTextAddrX<<1) + textX0 + (sprCX*lXDir)] & 0xff;
- GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX + sprCX],psxVuw[clutP+tC]);
- }
- return;
-
-
- case 2:
-
- for (sprCY=0;sprCY<sprtH;sprCY++)
- for (sprCX=0;sprCX<sprtW;sprCX++)
- {
- GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX+sprCX],
- psxVuw[((textY0+(sprCY*lYDir))<<10)+GlobalTextAddrX + textX0 +(sprCX*lXDir)]);
- }
- return;
- }
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void DrawSoftwareSprite_IL(unsigned char * baseAddr,short w,short h,int tx,int ty)
-{
- int sprtY,sprtX,sprtW,sprtH,tdx,tdy;
- uint32_t *gpuData = (uint32_t *)baseAddr;
-
- sprtY = ly0;
- sprtX = lx0;
- sprtH = h;
- sprtW = w;
-
- sprtX+=PSXDisplay.DrawOffset.x;
- sprtY+=PSXDisplay.DrawOffset.y;
-
- if(sprtX>drawW) return;
- if(sprtY>drawH) return;
-
- tdx=tx+sprtW;
- tdy=ty+sprtH;
-
- sprtW+=sprtX;
- sprtH+=sprtY;
-
- // Pete is too lazy to make a faster version ;)
-
- if(GlobalTextTP==0)
- drawPoly4TEx4_IL(sprtX,sprtY,sprtX,sprtH,sprtW,sprtH,sprtW,sprtY,
- tx,ty, tx,tdy, tdx,tdy, tdx,ty,
- (gpuData[2]>>12) & 0x3f0, ((gpuData[2]>>22) & iGPUHeightMask));
-
-
- else
- drawPoly4TEx8_IL(sprtX,sprtY,sprtX,sprtH,sprtW,sprtH,sprtW,sprtY,
- tx,ty, tx,tdy, tdx,tdy, tdx,ty,
- (gpuData[2]>>12) & 0x3f0, ((gpuData[2]>>22) & iGPUHeightMask));
-}
-
-////////////////////////////////////////////////////////////////////////
-
-void DrawSoftwareSprite(unsigned char *baseAddr, short w, short h, int tx, int ty)
-{
- int sprtY, sprtX, sprtW, sprtH;
- int clutY0, clutX0, clutP, textX0, textY0, sprtYa, sprCY, sprCX, sprA;
- short tC, tC2;
- uint32_t *gpuData = (uint32_t *)baseAddr;
- unsigned char *pV;
- BOOL bWT,bWS;
-
- if(GlobalTextIL && GlobalTextTP<2)
- {DrawSoftwareSprite_IL(baseAddr,w,h,tx,ty);return;}
-
- sprtY = ly0;
- sprtX = lx0;
- sprtH = h;
- sprtW = w;
- clutY0 = (gpuData[2]>>22) & iGPUHeightMask;
- clutX0 = (gpuData[2]>>12) & 0x3f0;
-
- clutP = (clutY0<<11) + (clutX0<<1);
-
- textY0 =ty+ GlobalTextAddrY;
- textX0 =tx;
-
- sprtX+=PSXDisplay.DrawOffset.x;
- sprtY+=PSXDisplay.DrawOffset.y;
-
- //while (sprtX>1023) sprtX-=1024;
- //while (sprtY>MAXYLINESMIN1) sprtY-=MAXYLINES;
-
- if(sprtX>drawW)
- {
-// if((sprtX+sprtW)>1023) sprtX-=1024;
-// else return;
- return;
- }
-
- if(sprtY>drawH)
- {
-// if ((sprtY+sprtH)>MAXYLINESMIN1) sprtY-=MAXYLINES;
-// else return;
- return;
- }
-
- if(sprtY<drawY)
- {
- if((sprtY+sprtH)<drawY) return;
- sprtH-=(drawY-sprtY);
- textY0+=(drawY-sprtY);
- sprtY=drawY;
- }
-
- if(sprtX<drawX)
- {
- if((sprtX+sprtW)<drawX) return;
-
- sprtW-=(drawX-sprtX);
- textX0+=(drawX-sprtX);
- sprtX=drawX;
- }
-
- if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
- if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
-
-
- bWT=FALSE;
- bWS=FALSE;
-
- switch (GlobalTextTP)
- {
- case 0:
-
- if(textX0&1) {bWS=TRUE;sprtW--;}
- if(sprtW&1) bWT=TRUE;
-
- sprtW=sprtW>>1;
- textX0=(GlobalTextAddrX<<1)+(textX0>>1)+(textY0<<11);
- sprtYa=(sprtY<<10)+sprtX;
- clutP=(clutY0<<10)+clutX0;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (sprCY=0;sprCY<sprtH;sprCY++)
- {
- sprA=sprtYa+(sprCY<<10);
- pV=&psxVub[(sprCY<<11)+textX0];
-
- if(bWS)
- {
- tC=*pV++;
- GetTextureTransColG_S(&psxVuw[sprA++],psxVuw[clutP+((tC>>4)&0xf)]);
- }
-
- for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
- {
- tC=*pV++;
-
- GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
- (((int)psxVuw[clutP+((tC>>4)&0xf)])<<16)|
- psxVuw[clutP+(tC&0x0f)]);
- }
-
- if(bWT)
- {
- tC=*pV;
- GetTextureTransColG_S(&psxVuw[sprA],psxVuw[clutP+(tC&0x0f)]);
- }
- }
- return;
- }
-
-#endif
-
- for (sprCY=0;sprCY<sprtH;sprCY++)
- {
- sprA=sprtYa+(sprCY<<10);
- pV=&psxVub[(sprCY<<11)+textX0];
-
- if(bWS)
- {
- tC=*pV++;
- GetTextureTransColG_SPR(&psxVuw[sprA++],psxVuw[clutP+((tC>>4)&0xf)]);
- }
-
- for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
- {
- tC=*pV++;
-
- GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
- (((int)psxVuw[clutP+((tC>>4)&0xf)])<<16)|
- psxVuw[clutP+(tC&0x0f)]);
- }
-
- if(bWT)
- {
- tC=*pV;
- GetTextureTransColG_SPR(&psxVuw[sprA],psxVuw[clutP+(tC&0x0f)]);
- }
- }
- return;
-
- case 1:
- clutP>>=1;sprtW--;
- textX0+=(GlobalTextAddrX<<1) + (textY0<<11);
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for(sprCY=0;sprCY<sprtH;sprCY++)
- {
- sprA=((sprtY+sprCY)<<10)+sprtX;
- pV=&psxVub[(sprCY<<11)+textX0];
- for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
- {
- tC = *pV++;tC2 = *pV++;
- GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
- (((int)psxVuw[clutP+tC2])<<16)|
- psxVuw[clutP+tC]);
- }
- if(sprCX==sprtW)
- GetTextureTransColG_S(&psxVuw[sprA],psxVuw[clutP+(*pV)]);
- }
- return;
- }
-
-#endif
-
- for(sprCY=0;sprCY<sprtH;sprCY++)
- {
- sprA=((sprtY+sprCY)<<10)+sprtX;
- pV=&psxVub[(sprCY<<11)+textX0];
- for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
- {
- tC = *pV++;tC2 = *pV++;
- GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
- (((int)psxVuw[clutP+tC2])<<16)|
- psxVuw[clutP+tC]);
- }
- if(sprCX==sprtW)
- GetTextureTransColG_SPR(&psxVuw[sprA],psxVuw[clutP+(*pV)]);
- }
- return;
-
- case 2:
-
- textX0+=(GlobalTextAddrX) + (textY0<<10);
- sprtW--;
-
-#ifdef FASTSOLID
-
- if(!bCheckMask && !DrawSemiTrans)
- {
- for (sprCY=0;sprCY<sprtH;sprCY++)
- {
- sprA=((sprtY+sprCY)<<10)+sprtX;
-
- for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
- {
- GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
- (((int)psxVuw[(sprCY<<10) + textX0 + sprCX +1])<<16)|
- psxVuw[(sprCY<<10) + textX0 + sprCX]);
- }
- if(sprCX==sprtW)
- GetTextureTransColG_S(&psxVuw[sprA],
- psxVuw[(sprCY<<10) + textX0 + sprCX]);
-
- }
- return;
- }
-
-#endif
-
- for (sprCY=0;sprCY<sprtH;sprCY++)
- {
- sprA=((sprtY+sprCY)<<10)+sprtX;
-
- for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
- {
- GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
- (((int)psxVuw[(sprCY<<10) + textX0 + sprCX +1])<<16)|
- psxVuw[(sprCY<<10) + textX0 + sprCX]);
- }
- if(sprCX==sprtW)
- GetTextureTransColG_SPR(&psxVuw[sprA],
- psxVuw[(sprCY<<10) + textX0 + sprCX]);
-
- }
- return;
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-/////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-// LINE FUNCS
-////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////
-
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_E_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
-{
- int dx, dy, incrE, incrSE, d;
- uint32_t r0, g0, b0, r1, g1, b1;
- int dr, dg, db;
-
- r0 = (rgb0 & 0x00ff0000);
- g0 = (rgb0 & 0x0000ff00) << 8;
- b0 = (rgb0 & 0x000000ff) << 16;
- r1 = (rgb1 & 0x00ff0000);
- g1 = (rgb1 & 0x0000ff00) << 8;
- b1 = (rgb1 & 0x000000ff) << 16;
-
- dx = x1 - x0;
- dy = y1 - y0;
-
- if (dx > 0)
- {
- dr = ((int)r1 - (int)r0) / dx;
- dg = ((int)g1 - (int)g0) / dx;
- db = ((int)b1 - (int)b0) / dx;
- }
- else
- {
- dr = ((int)r1 - (int)r0);
- dg = ((int)g1 - (int)g0);
- db = ((int)b1 - (int)b0);
- }
-
- d = 2*dy - dx; /* Initial value of d */
- incrE = 2*dy; /* incr. used for move to E */
- incrSE = 2*(dy - dx); /* incr. used for move to SE */
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- while(x0 < x1)
- {
- if (d <= 0)
- {
- d = d + incrE; /* Choose E */
- }
- else
- {
- d = d + incrSE; /* Choose SE */
- y0++;
- }
- x0++;
-
- r0+=dr;
- g0+=dg;
- b0+=db;
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_S_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
-{
- int dx, dy, incrS, incrSE, d;
- uint32_t r0, g0, b0, r1, g1, b1;
- int dr, dg, db;
-
- r0 = (rgb0 & 0x00ff0000);
- g0 = (rgb0 & 0x0000ff00) << 8;
- b0 = (rgb0 & 0x000000ff) << 16;
- r1 = (rgb1 & 0x00ff0000);
- g1 = (rgb1 & 0x0000ff00) << 8;
- b1 = (rgb1 & 0x000000ff) << 16;
-
- dx = x1 - x0;
- dy = y1 - y0;
-
- if (dy > 0)
- {
- dr = ((int)r1 - (int)r0) / dy;
- dg = ((int)g1 - (int)g0) / dy;
- db = ((int)b1 - (int)b0) / dy;
- }
- else
- {
- dr = ((int)r1 - (int)r0);
- dg = ((int)g1 - (int)g0);
- db = ((int)b1 - (int)b0);
- }
-
- d = 2*dx - dy; /* Initial value of d */
- incrS = 2*dx; /* incr. used for move to S */
- incrSE = 2*(dx - dy); /* incr. used for move to SE */
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- while(y0 < y1)
- {
- if (d <= 0)
- {
- d = d + incrS; /* Choose S */
- }
- else
- {
- d = d + incrSE; /* Choose SE */
- x0++;
- }
- y0++;
-
- r0+=dr;
- g0+=dg;
- b0+=db;
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_N_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
-{
- int dx, dy, incrN, incrNE, d;
- uint32_t r0, g0, b0, r1, g1, b1;
- int dr, dg, db;
-
- r0 = (rgb0 & 0x00ff0000);
- g0 = (rgb0 & 0x0000ff00) << 8;
- b0 = (rgb0 & 0x000000ff) << 16;
- r1 = (rgb1 & 0x00ff0000);
- g1 = (rgb1 & 0x0000ff00) << 8;
- b1 = (rgb1 & 0x000000ff) << 16;
-
- dx = x1 - x0;
- dy = -(y1 - y0);
-
- if (dy > 0)
- {
- dr = ((uint32_t)r1 - (uint32_t)r0) / dy;
- dg = ((uint32_t)g1 - (uint32_t)g0) / dy;
- db = ((uint32_t)b1 - (uint32_t)b0) / dy;
- }
- else
- {
- dr = ((uint32_t)r1 - (uint32_t)r0);
- dg = ((uint32_t)g1 - (uint32_t)g0);
- db = ((uint32_t)b1 - (uint32_t)b0);
- }
-
- d = 2*dx - dy; /* Initial value of d */
- incrN = 2*dx; /* incr. used for move to N */
- incrNE = 2*(dx - dy); /* incr. used for move to NE */
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- while(y0 > y1)
- {
- if (d <= 0)
- {
- d = d + incrN; /* Choose N */
- }
- else
- {
- d = d + incrNE; /* Choose NE */
- x0++;
- }
- y0--;
-
- r0+=dr;
- g0+=dg;
- b0+=db;
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_E_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
-{
- int dx, dy, incrE, incrNE, d;
- uint32_t r0, g0, b0, r1, g1, b1;
- int dr, dg, db;
-
- r0 = (rgb0 & 0x00ff0000);
- g0 = (rgb0 & 0x0000ff00) << 8;
- b0 = (rgb0 & 0x000000ff) << 16;
- r1 = (rgb1 & 0x00ff0000);
- g1 = (rgb1 & 0x0000ff00) << 8;
- b1 = (rgb1 & 0x000000ff) << 16;
-
- dx = x1 - x0;
- dy = -(y1 - y0);
-
- if (dx > 0)
- {
- dr = ((int)r1 - (int)r0) / dx;
- dg = ((int)g1 - (int)g0) / dx;
- db = ((int)b1 - (int)b0) / dx;
- }
- else
- {
- dr = ((int)r1 - (int)r0);
- dg = ((int)g1 - (int)g0);
- db = ((int)b1 - (int)b0);
- }
-
- d = 2*dy - dx; /* Initial value of d */
- incrE = 2*dy; /* incr. used for move to E */
- incrNE = 2*(dy - dx); /* incr. used for move to NE */
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- while(x0 < x1)
- {
- if (d <= 0)
- {
- d = d + incrE; /* Choose E */
- }
- else
- {
- d = d + incrNE; /* Choose NE */
- y0--;
- }
- x0++;
-
- r0+=dr;
- g0+=dg;
- b0+=db;
-
- if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
- GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void VertLineShade(int x, int y0, int y1, uint32_t rgb0, uint32_t rgb1)
-{
- int y, dy;
- uint32_t r0, g0, b0, r1, g1, b1;
- int dr, dg, db;
-
- r0 = (rgb0 & 0x00ff0000);
- g0 = (rgb0 & 0x0000ff00) << 8;
- b0 = (rgb0 & 0x000000ff) << 16;
- r1 = (rgb1 & 0x00ff0000);
- g1 = (rgb1 & 0x0000ff00) << 8;
- b1 = (rgb1 & 0x000000ff) << 16;
-
- dy = (y1 - y0);
-
- if (dy > 0)
- {
- dr = ((int)r1 - (int)r0) / dy;
- dg = ((int)g1 - (int)g0) / dy;
- db = ((int)b1 - (int)b0) / dy;
- }
- else
- {
- dr = ((int)r1 - (int)r0);
- dg = ((int)g1 - (int)g0);
- db = ((int)b1 - (int)b0);
- }
-
- if (y0 < drawY)
- {
- r0+=dr*(drawY - y0);
- g0+=dg*(drawY - y0);
- b0+=db*(drawY - y0);
- y0 = drawY;
- }
-
- if (y1 > drawH)
- y1 = drawH;
-
- for (y = y0; y <= y1; y++)
- {
- GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- r0+=dr;
- g0+=dg;
- b0+=db;
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void HorzLineShade(int y, int x0, int x1, uint32_t rgb0, uint32_t rgb1)
-{
- int x, dx;
- uint32_t r0, g0, b0, r1, g1, b1;
- int dr, dg, db;
-
- r0 = (rgb0 & 0x00ff0000);
- g0 = (rgb0 & 0x0000ff00) << 8;
- b0 = (rgb0 & 0x000000ff) << 16;
- r1 = (rgb1 & 0x00ff0000);
- g1 = (rgb1 & 0x0000ff00) << 8;
- b1 = (rgb1 & 0x000000ff) << 16;
-
- dx = (x1 - x0);
-
- if (dx > 0)
- {
- dr = ((int)r1 - (int)r0) / dx;
- dg = ((int)g1 - (int)g0) / dx;
- db = ((int)b1 - (int)b0) / dx;
- }
- else
- {
- dr = ((int)r1 - (int)r0);
- dg = ((int)g1 - (int)g0);
- db = ((int)b1 - (int)b0);
- }
-
- if (x0 < drawX)
- {
- r0+=dr*(drawX - x0);
- g0+=dg*(drawX - x0);
- b0+=db*(drawX - x0);
- x0 = drawX;
- }
-
- if (x1 > drawW)
- x1 = drawW;
-
- for (x = x0; x <= x1; x++)
- {
- GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
- r0+=dr;
- g0+=dg;
- b0+=db;
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_E_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
-{
- int dx, dy, incrE, incrSE, d, x, y;
-
- dx = x1 - x0;
- dy = y1 - y0;
- d = 2*dy - dx; /* Initial value of d */
- incrE = 2*dy; /* incr. used for move to E */
- incrSE = 2*(dy - dx); /* incr. used for move to SE */
- x = x0;
- y = y0;
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- while(x < x1)
- {
- if (d <= 0)
- {
- d = d + incrE; /* Choose E */
- x++;
- }
- else
- {
- d = d + incrSE; /* Choose SE */
- x++;
- y++;
- }
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_S_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
-{
- int dx, dy, incrS, incrSE, d, x, y;
-
- dx = x1 - x0;
- dy = y1 - y0;
- d = 2*dx - dy; /* Initial value of d */
- incrS = 2*dx; /* incr. used for move to S */
- incrSE = 2*(dx - dy); /* incr. used for move to SE */
- x = x0;
- y = y0;
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- while(y < y1)
- {
- if (d <= 0)
- {
- d = d + incrS; /* Choose S */
- y++;
- }
- else
- {
- d = d + incrSE; /* Choose SE */
- x++;
- y++;
- }
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_N_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
-{
- int dx, dy, incrN, incrNE, d, x, y;
-
- dx = x1 - x0;
- dy = -(y1 - y0);
- d = 2*dx - dy; /* Initial value of d */
- incrN = 2*dx; /* incr. used for move to N */
- incrNE = 2*(dx - dy); /* incr. used for move to NE */
- x = x0;
- y = y0;
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- while(y > y1)
- {
- if (d <= 0)
- {
- d = d + incrN; /* Choose N */
- y--;
- }
- else
- {
- d = d + incrNE; /* Choose NE */
- x++;
- y--;
- }
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void Line_E_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
-{
- int dx, dy, incrE, incrNE, d, x, y;
-
- dx = x1 - x0;
- dy = -(y1 - y0);
- d = 2*dy - dx; /* Initial value of d */
- incrE = 2*dy; /* incr. used for move to E */
- incrNE = 2*(dy - dx); /* incr. used for move to NE */
- x = x0;
- y = y0;
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- while(x < x1)
- {
- if (d <= 0)
- {
- d = d + incrE; /* Choose E */
- x++;
- }
- else
- {
- d = d + incrNE; /* Choose NE */
- x++;
- y--;
- }
- if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void VertLineFlat(int x, int y0, int y1, unsigned short colour)
-{
- int y;
-
- if (y0 < drawY)
- y0 = drawY;
-
- if (y1 > drawH)
- y1 = drawH;
-
- for (y = y0; y <= y1; y++)
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void HorzLineFlat(int y, int x0, int x1, unsigned short colour)
-{
- int x;
-
- if (x0 < drawX)
- x0 = drawX;
-
- if (x1 > drawW)
- x1 = drawW;
-
- for (x = x0; x <= x1; x++)
- GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
-}
-
-///////////////////////////////////////////////////////////////////////
-
-/* Bresenham Line drawing function */
-void DrawSoftwareLineShade(int rgb0, int rgb1)
-{
- short x0, y0, x1, y1, xt, yt;
- int rgbt;
- double m, dy, dx;
-
- if(lx0>drawW && lx1>drawW) return;
- if(ly0>drawH && ly1>drawH) return;
- if(lx0<drawX && lx1<drawX) return;
- if(ly0<drawY && ly1<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- x0 = lx0;
- y0 = ly0;
- x1 = lx1;
- y1 = ly1;
-
- dx = x1 - x0;
- dy = y1 - y0;
-
- if (dx == 0)
- {
- if (dy > 0)
- VertLineShade(x0, y0, y1, rgb0, rgb1);
- else
- VertLineShade(x0, y1, y0, rgb1, rgb0);
- }
- else
- if (dy == 0)
- {
- if (dx > 0)
- HorzLineShade(y0, x0, x1, rgb0, rgb1);
- else
- HorzLineShade(y0, x1, x0, rgb1, rgb0);
- }
- else
- {
- if (dx < 0)
- {
- xt = x0;
- yt = y0;
- rgbt = rgb0;
- x0 = x1;
- y0 = y1;
- rgb0 = rgb1;
- x1 = xt;
- y1 = yt;
- rgb1 = rgbt;
-
- dx = x1 - x0;
- dy = y1 - y0;
- }
-
- m = dy/dx;
-
- if (m >= 0)
- {
- if (m > 1)
- Line_S_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
- else
- Line_E_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
- }
- else
- if (m < -1)
- Line_N_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
- else
- Line_E_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
- }
-}
-
-///////////////////////////////////////////////////////////////////////
-
-void DrawSoftwareLineFlat(int rgb)
-{
- short x0, y0, x1, y1, xt, yt;
- double m, dy, dx;
- unsigned short colour = 0;
-
- if(lx0>drawW && lx1>drawW) return;
- if(ly0>drawH && ly1>drawH) return;
- if(lx0<drawX && lx1<drawX) return;
- if(ly0<drawY && ly1<drawY) return;
- if(drawY>=drawH) return;
- if(drawX>=drawW) return;
-
- colour = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
-
- x0 = lx0;
- y0 = ly0;
- x1 = lx1;
- y1 = ly1;
-
- dx = x1 - x0;
- dy = y1 - y0;
-
- if (dx == 0)
- {
- if (dy == 0)
- return; // Nothing to draw
- else if (dy > 0)
- VertLineFlat(x0, y0, y1, colour);
- else
- VertLineFlat(x0, y1, y0, colour);
- }
- else
- if (dy == 0)
- {
- if (dx > 0)
- HorzLineFlat(y0, x0, x1, colour);
- else
- HorzLineFlat(y0, x1, x0, colour);
- }
- else
- {
- if (dx < 0)
- {
- xt = x0;
- yt = y0;
- x0 = x1;
- y0 = y1;
- x1 = xt;
- y1 = yt;
-
- dx = x1 - x0;
- dy = y1 - y0;
- }
-
- m = dy/dx;
-
- if (m >= 0)
- {
- if (m > 1)
- Line_S_SE_Flat(x0, y0, x1, y1, colour);
- else
- Line_E_SE_Flat(x0, y0, x1, y1, colour);
- }
- else
- if (m < -1)
- Line_N_NE_Flat(x0, y0, x1, y1, colour);
- else
- Line_E_NE_Flat(x0, y0, x1, y1, colour);
- }
-}
-
-///////////////////////////////////////////////////////////////////////
+/***************************************************************************
+ soft.c - description
+ -------------------
+ begin : Sun Oct 28 2001
+ copyright : (C) 2001 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#include "stdafx.h"
+
+#define _IN_SOFT
+
+#include "externals.h"
+#include "soft.h"
+
+int iDither = 0;
+
+////////////////////////////////////////////////////////////////////////////////////
+// "NO EDGE BUFFER" POLY VERSION... FUNCS BASED ON FATMAP.TXT FROM MRI / Doomsday
+////////////////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////////////////
+// defines
+////////////////////////////////////////////////////////////////////////////////////
+
+// switches for painting textured quads as 2 triangles (small glitches, but better shading!)
+// can be toggled by game fix 0x200 in version 1.17 anyway, so let the defines enabled!
+
+#define POLYQUAD3
+#define POLYQUAD3GT
+
+// fast solid loops... a bit more additional code, of course
+
+#define FASTSOLID
+
+// psx blending mode 3 with 25% incoming color (instead 50% without the define)
+
+#define HALFBRIGHTMODE3
+
+// color decode defines
+
+#define XCOL1(x) (x & 0x1f)
+#define XCOL2(x) (x & 0x3e0)
+#define XCOL3(x) (x & 0x7c00)
+
+#define XCOL1D(x) (x & 0x1f)
+#define XCOL2D(x) ((x>>5) & 0x1f)
+#define XCOL3D(x) ((x>>10) & 0x1f)
+
+#define X32TCOL1(x) ((x & 0x001f001f)<<7)
+#define X32TCOL2(x) ((x & 0x03e003e0)<<2)
+#define X32TCOL3(x) ((x & 0x7c007c00)>>3)
+
+#define X32COL1(x) (x & 0x001f001f)
+#define X32COL2(x) ((x>>5) & 0x001f001f)
+#define X32COL3(x) ((x>>10) & 0x001f001f)
+
+#define X32ACOL1(x) (x & 0x001e001e)
+#define X32ACOL2(x) ((x>>5) & 0x001e001e)
+#define X32ACOL3(x) ((x>>10) & 0x001e001e)
+
+#define X32BCOL1(x) (x & 0x001c001c)
+#define X32BCOL2(x) ((x>>5) & 0x001c001c)
+#define X32BCOL3(x) ((x>>10) & 0x001c001c)
+
+#define X32PSXCOL(r,g,b) ((g<<10)|(b<<5)|r)
+
+#define XPSXCOL(r,g,b) ((g&0x7c00)|(b&0x3e0)|(r&0x1f))
+
+////////////////////////////////////////////////////////////////////////////////////
+// soft globals
+////////////////////////////////////////////////////////////////////////////////////
+
+short g_m1 = 255, g_m2 = 255, g_m3 = 255;
+short DrawSemiTrans = FALSE;
+short Ymin;
+short Ymax;
+
+short ly0, lx0, ly1, lx1, ly2, lx2, ly3, lx3; // global psx vertex coords
+int GlobalTextAddrX, GlobalTextAddrY, GlobalTextTP;
+int GlobalTextREST, GlobalTextABR, GlobalTextPAGE;
+
+////////////////////////////////////////////////////////////////////////
+// POLYGON OFFSET FUNCS
+////////////////////////////////////////////////////////////////////////
+
+void offsetPSXLine(void)
+{
+ short x0,x1,y0,y1,dx,dy;float px,py;
+
+ x0 = lx0+1+PSXDisplay.DrawOffset.x;
+ x1 = lx1+1+PSXDisplay.DrawOffset.x;
+ y0 = ly0+1+PSXDisplay.DrawOffset.y;
+ y1 = ly1+1+PSXDisplay.DrawOffset.y;
+
+ dx=x1-x0;
+ dy=y1-y0;
+
+ // tricky line width without sqrt
+
+ if(dx>=0)
+ {
+ if(dy>=0)
+ {
+ px=0.5f;
+ if(dx>dy) py=-0.5f;
+ else if(dx<dy) py= 0.5f;
+ else py= 0.0f;
+ }
+ else
+ {
+ py=-0.5f;
+ dy=-dy;
+ if(dx>dy) px= 0.5f;
+ else if(dx<dy) px=-0.5f;
+ else px= 0.0f;
+ }
+ }
+ else
+ {
+ if(dy>=0)
+ {
+ py=0.5f;
+ dx=-dx;
+ if(dx>dy) px=-0.5f;
+ else if(dx<dy) px= 0.5f;
+ else px= 0.0f;
+ }
+ else
+ {
+ px=-0.5f;
+ if(dx>dy) py=-0.5f;
+ else if(dx<dy) py= 0.5f;
+ else py= 0.0f;
+ }
+ }
+
+ lx0=(short)((float)x0-px);
+ lx3=(short)((float)x0+py);
+
+ ly0=(short)((float)y0-py);
+ ly3=(short)((float)y0-px);
+
+ lx1=(short)((float)x1-py);
+ lx2=(short)((float)x1+px);
+
+ ly1=(short)((float)y1+px);
+ ly2=(short)((float)y1+py);
+}
+
+void offsetPSX2(void)
+{
+ lx0 += PSXDisplay.DrawOffset.x;
+ ly0 += PSXDisplay.DrawOffset.y;
+ lx1 += PSXDisplay.DrawOffset.x;
+ ly1 += PSXDisplay.DrawOffset.y;
+}
+
+void offsetPSX3(void)
+{
+ lx0 += PSXDisplay.DrawOffset.x;
+ ly0 += PSXDisplay.DrawOffset.y;
+ lx1 += PSXDisplay.DrawOffset.x;
+ ly1 += PSXDisplay.DrawOffset.y;
+ lx2 += PSXDisplay.DrawOffset.x;
+ ly2 += PSXDisplay.DrawOffset.y;
+}
+
+void offsetPSX4(void)
+{
+ lx0 += PSXDisplay.DrawOffset.x;
+ ly0 += PSXDisplay.DrawOffset.y;
+ lx1 += PSXDisplay.DrawOffset.x;
+ ly1 += PSXDisplay.DrawOffset.y;
+ lx2 += PSXDisplay.DrawOffset.x;
+ ly2 += PSXDisplay.DrawOffset.y;
+ lx3 += PSXDisplay.DrawOffset.x;
+ ly3 += PSXDisplay.DrawOffset.y;
+}
+
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+// PER PIXEL FUNCS
+////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+
+
+unsigned char dithertable[16] =
+{
+ 7, 0, 6, 1,
+ 2, 5, 3, 4,
+ 1, 6, 0, 7,
+ 4, 3, 5, 2
+};
+
+static void Dither16(unsigned short *pdest, uint32_t r, uint32_t g, uint32_t b, unsigned short sM)
+{
+ unsigned char coeff;
+ unsigned char rlow, glow, blow;
+ int x, y;
+
+ x = pdest - psxVuw;
+ y = x >> 10;
+ x -= (y << 10);
+
+ coeff = dithertable[(y&3)*4+(x&3)];
+
+ rlow = r&7; glow = g&7; blow = b&7;
+
+ r>>=3; g>>=3; b>>=3;
+
+ if ((r < 0x1F) && rlow > coeff) r++;
+ if ((g < 0x1F) && glow > coeff) g++;
+ if ((b < 0x1F) && blow > coeff) b++;
+
+ *pdest=((unsigned short)b<<10) |
+ ((unsigned short)g<<5) |
+ (unsigned short)r | sM;
+}
+
+/////////////////////////////////////////////////////////////////
+
+static __inline void GetShadeTransCol_Dither(unsigned short *pdest, int m1, int m2, int m3)
+{
+ int r,g,b;
+
+ if (bCheckMask && *pdest & 0x8000) return;
+
+ if (DrawSemiTrans)
+ {
+ r=((XCOL1D(*pdest))<<3);
+ b=((XCOL2D(*pdest))<<3);
+ g=((XCOL3D(*pdest))<<3);
+
+ if(GlobalTextABR==0)
+ {
+ r=(r>>1)+(m1>>1);
+ b=(b>>1)+(m2>>1);
+ g=(g>>1)+(m3>>1);
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r+=m1;
+ b+=m2;
+ g+=m3;
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ r-=m1;
+ b-=m2;
+ g-=m3;
+ if(r&0x80000000) r=0;
+ if(b&0x80000000) b=0;
+ if(g&0x80000000) g=0;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r+=(m1>>2);
+ b+=(m2>>2);
+ g+=(m3>>2);
+#else
+ r+=(m1>>1);
+ b+=(m2>>1);
+ g+=(m3>>1);
+#endif
+ }
+ }
+ else
+ {
+ r=m1;
+ b=m2;
+ g=m3;
+ }
+
+ if(r&0x7FFFFF00) r=0xff;
+ if(b&0x7FFFFF00) b=0xff;
+ if(g&0x7FFFFF00) g=0xff;
+
+ Dither16(pdest,r,b,g,sSetMask);
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetShadeTransCol(unsigned short * pdest,unsigned short color)
+{
+ if(bCheckMask && *pdest&0x8000) return;
+
+ if(DrawSemiTrans)
+ {
+ int r,g,b;
+
+ if(GlobalTextABR==0)
+ {
+ *pdest=((((*pdest)&0x7bde)>>1)+(((color)&0x7bde)>>1))|sSetMask;//0x8000;
+ return;
+/*
+ r=(XCOL1(*pdest)>>1)+((XCOL1(color))>>1);
+ b=(XCOL2(*pdest)>>1)+((XCOL2(color))>>1);
+ g=(XCOL3(*pdest)>>1)+((XCOL3(color))>>1);
+*/
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r=(XCOL1(*pdest))+((XCOL1(color)));
+ b=(XCOL2(*pdest))+((XCOL2(color)));
+ g=(XCOL3(*pdest))+((XCOL3(color)));
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ r=(XCOL1(*pdest))-((XCOL1(color)));
+ b=(XCOL2(*pdest))-((XCOL2(color)));
+ g=(XCOL3(*pdest))-((XCOL3(color)));
+ if(r&0x80000000) r=0;
+ if(b&0x80000000) b=0;
+ if(g&0x80000000) g=0;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r=(XCOL1(*pdest))+((XCOL1(color))>>2);
+ b=(XCOL2(*pdest))+((XCOL2(color))>>2);
+ g=(XCOL3(*pdest))+((XCOL3(color))>>2);
+#else
+ r=(XCOL1(*pdest))+((XCOL1(color))>>1);
+ b=(XCOL2(*pdest))+((XCOL2(color))>>1);
+ g=(XCOL3(*pdest))+((XCOL3(color))>>1);
+#endif
+ }
+
+ if(r&0x7FFFFFE0) r=0x1f;
+ if(b&0x7FFFFC00) b=0x3e0;
+ if(g&0x7FFF8000) g=0x7c00;
+
+ *pdest=(XPSXCOL(r,g,b))|sSetMask;//0x8000;
+ }
+ else *pdest=color|sSetMask;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetShadeTransCol32(uint32_t *pdest, uint32_t color)
+{
+ if (DrawSemiTrans)
+ {
+ int r,g,b;
+
+ if(GlobalTextABR==0)
+ {
+ if(!bCheckMask)
+ {
+ *pdest=((((*pdest)&0x7bde7bde)>>1)+(((color)&0x7bde7bde)>>1))|lSetMask;//0x80008000;
+ return;
+ }
+ r=(X32ACOL1(*pdest)>>1)+((X32ACOL1(color))>>1);
+ b=(X32ACOL2(*pdest)>>1)+((X32ACOL2(color))>>1);
+ g=(X32ACOL3(*pdest)>>1)+((X32ACOL3(color))>>1);
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r=(X32COL1(*pdest))+((X32COL1(color)));
+ b=(X32COL2(*pdest))+((X32COL2(color)));
+ g=(X32COL3(*pdest))+((X32COL3(color)));
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ int sr,sb,sg,src,sbc,sgc,c;
+ src=XCOL1(color);sbc=XCOL2(color);sgc=XCOL3(color);
+ c=(*pdest)>>16;
+ sr=(XCOL1(c))-src; if(sr&0x8000) sr=0;
+ sb=(XCOL2(c))-sbc; if(sb&0x8000) sb=0;
+ sg=(XCOL3(c))-sgc; if(sg&0x8000) sg=0;
+ r=((int)sr)<<16;b=((int)sb)<<11;g=((int)sg)<<6;
+ c=LOWORD(*pdest);
+ sr=(XCOL1(c))-src; if(sr&0x8000) sr=0;
+ sb=(XCOL2(c))-sbc; if(sb&0x8000) sb=0;
+ sg=(XCOL3(c))-sgc; if(sg&0x8000) sg=0;
+ r|=sr;b|=sb>>5;g|=sg>>10;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r=(X32COL1(*pdest))+((X32BCOL1(color))>>2);
+ b=(X32COL2(*pdest))+((X32BCOL2(color))>>2);
+ g=(X32COL3(*pdest))+((X32BCOL3(color))>>2);
+#else
+ r=(X32COL1(*pdest))+((X32ACOL1(color))>>1);
+ b=(X32COL2(*pdest))+((X32ACOL2(color))>>1);
+ g=(X32COL3(*pdest))+((X32ACOL3(color))>>1);
+#endif
+ }
+
+ if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
+ if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
+ if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
+ if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
+ if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
+ if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
+
+ if(bCheckMask)
+ {
+ uint32_t ma=*pdest;
+ *pdest=(X32PSXCOL(r,g,b))|lSetMask;//0x80008000;
+ if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
+ if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
+ return;
+ }
+ *pdest=(X32PSXCOL(r,g,b))|lSetMask;//0x80008000;
+ }
+ else
+ {
+ if(bCheckMask)
+ {
+ uint32_t ma=*pdest;
+ *pdest=color|lSetMask;//0x80008000;
+ if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
+ if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
+ return;
+ }
+
+ *pdest=color|lSetMask;//0x80008000;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColG(unsigned short * pdest,unsigned short color)
+{
+ int r,g,b;unsigned short l;
+
+ if(color==0) return;
+
+ if(bCheckMask && *pdest&0x8000) return;
+
+ l=sSetMask|(color&0x8000);
+
+ if(DrawSemiTrans && (color&0x8000))
+ {
+ if(GlobalTextABR==0)
+ {
+ unsigned short d;
+ d =((*pdest)&0x7bde)>>1;
+ color =((color) &0x7bde)>>1;
+ r=(XCOL1(d))+((((XCOL1(color)))* g_m1)>>7);
+ b=(XCOL2(d))+((((XCOL2(color)))* g_m2)>>7);
+ g=(XCOL3(d))+((((XCOL3(color)))* g_m3)>>7);
+
+/*
+ r=(XCOL1(*pdest)>>1)+((((XCOL1(color))>>1)* g_m1)>>7);
+ b=(XCOL2(*pdest)>>1)+((((XCOL2(color))>>1)* g_m2)>>7);
+ g=(XCOL3(*pdest)>>1)+((((XCOL3(color))>>1)* g_m3)>>7);
+*/
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r=(XCOL1(*pdest))+((((XCOL1(color)))* g_m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color)))* g_m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color)))* g_m3)>>7);
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ r=(XCOL1(*pdest))-((((XCOL1(color)))* g_m1)>>7);
+ b=(XCOL2(*pdest))-((((XCOL2(color)))* g_m2)>>7);
+ g=(XCOL3(*pdest))-((((XCOL3(color)))* g_m3)>>7);
+ if(r&0x80000000) r=0;
+ if(b&0x80000000) b=0;
+ if(g&0x80000000) g=0;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r=(XCOL1(*pdest))+((((XCOL1(color))>>2)* g_m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color))>>2)* g_m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color))>>2)* g_m3)>>7);
+#else
+ r=(XCOL1(*pdest))+((((XCOL1(color))>>1)* g_m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color))>>1)* g_m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color))>>1)* g_m3)>>7);
+#endif
+ }
+ }
+ else
+ {
+ r=((XCOL1(color))* g_m1)>>7;
+ b=((XCOL2(color))* g_m2)>>7;
+ g=((XCOL3(color))* g_m3)>>7;
+ }
+
+ if(r&0x7FFFFFE0) r=0x1f;
+ if(b&0x7FFFFC00) b=0x3e0;
+ if(g&0x7FFF8000) g=0x7c00;
+
+ *pdest=(XPSXCOL(r,g,b))|l;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColG_S(unsigned short * pdest,unsigned short color)
+{
+ int r,g,b;unsigned short l;
+
+ if(color==0) return;
+
+ l=sSetMask|(color&0x8000);
+
+ r=((XCOL1(color))* g_m1)>>7;
+ b=((XCOL2(color))* g_m2)>>7;
+ g=((XCOL3(color))* g_m3)>>7;
+
+ if(r&0x7FFFFFE0) r=0x1f;
+ if(b&0x7FFFFC00) b=0x3e0;
+ if(g&0x7FFF8000) g=0x7c00;
+
+ *pdest=(XPSXCOL(r,g,b))|l;
+}
+
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColG_SPR(unsigned short * pdest,unsigned short color)
+{
+ int r,g,b;unsigned short l;
+
+ if(color==0) return;
+
+ if(bCheckMask && *pdest&0x8000) return;
+
+ l=sSetMask|(color&0x8000);
+
+ if(DrawSemiTrans && (color&0x8000))
+ {
+ if(GlobalTextABR==0)
+ {
+ unsigned short d;
+ d =((*pdest)&0x7bde)>>1;
+ color =((color) &0x7bde)>>1;
+ r=(XCOL1(d))+((((XCOL1(color)))* g_m1)>>7);
+ b=(XCOL2(d))+((((XCOL2(color)))* g_m2)>>7);
+ g=(XCOL3(d))+((((XCOL3(color)))* g_m3)>>7);
+
+/*
+ r=(XCOL1(*pdest)>>1)+((((XCOL1(color))>>1)* g_m1)>>7);
+ b=(XCOL2(*pdest)>>1)+((((XCOL2(color))>>1)* g_m2)>>7);
+ g=(XCOL3(*pdest)>>1)+((((XCOL3(color))>>1)* g_m3)>>7);
+*/
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r=(XCOL1(*pdest))+((((XCOL1(color)))* g_m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color)))* g_m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color)))* g_m3)>>7);
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ r=(XCOL1(*pdest))-((((XCOL1(color)))* g_m1)>>7);
+ b=(XCOL2(*pdest))-((((XCOL2(color)))* g_m2)>>7);
+ g=(XCOL3(*pdest))-((((XCOL3(color)))* g_m3)>>7);
+ if(r&0x80000000) r=0;
+ if(b&0x80000000) b=0;
+ if(g&0x80000000) g=0;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r=(XCOL1(*pdest))+((((XCOL1(color))>>2)* g_m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color))>>2)* g_m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color))>>2)* g_m3)>>7);
+#else
+ r=(XCOL1(*pdest))+((((XCOL1(color))>>1)* g_m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color))>>1)* g_m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color))>>1)* g_m3)>>7);
+#endif
+ }
+ }
+ else
+ {
+ r=((XCOL1(color))* g_m1)>>7;
+ b=((XCOL2(color))* g_m2)>>7;
+ g=((XCOL3(color))* g_m3)>>7;
+ }
+
+ if(r&0x7FFFFFE0) r=0x1f;
+ if(b&0x7FFFFC00) b=0x3e0;
+ if(g&0x7FFF8000) g=0x7c00;
+
+ *pdest=(XPSXCOL(r,g,b))|l;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColG32(uint32_t *pdest, uint32_t color)
+{
+ int r,g,b,l;
+
+ if(color==0) return;
+
+ l=lSetMask|(color&0x80008000);
+
+ if(DrawSemiTrans && (color&0x80008000))
+ {
+ if(GlobalTextABR==0)
+ {
+ r=((((X32TCOL1(*pdest))+((X32COL1(color)) * g_m1))&0xFF00FF00)>>8);
+ b=((((X32TCOL2(*pdest))+((X32COL2(color)) * g_m2))&0xFF00FF00)>>8);
+ g=((((X32TCOL3(*pdest))+((X32COL3(color)) * g_m3))&0xFF00FF00)>>8);
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r=(X32COL1(*pdest))+(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
+ b=(X32COL2(*pdest))+(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
+ g=(X32COL3(*pdest))+(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ int t;
+ r=(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
+ t=(*pdest&0x001f0000)-(r&0x003f0000); if(t&0x80000000) t=0;
+ r=(*pdest&0x0000001f)-(r&0x0000003f); if(r&0x80000000) r=0;
+ r|=t;
+
+ b=(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
+ t=((*pdest>>5)&0x001f0000)-(b&0x003f0000); if(t&0x80000000) t=0;
+ b=((*pdest>>5)&0x0000001f)-(b&0x0000003f); if(b&0x80000000) b=0;
+ b|=t;
+
+ g=(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
+ t=((*pdest>>10)&0x001f0000)-(g&0x003f0000); if(t&0x80000000) t=0;
+ g=((*pdest>>10)&0x0000001f)-(g&0x0000003f); if(g&0x80000000) g=0;
+ g|=t;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r=(X32COL1(*pdest))+(((((X32BCOL1(color))>>2)* g_m1)&0xFF80FF80)>>7);
+ b=(X32COL2(*pdest))+(((((X32BCOL2(color))>>2)* g_m2)&0xFF80FF80)>>7);
+ g=(X32COL3(*pdest))+(((((X32BCOL3(color))>>2)* g_m3)&0xFF80FF80)>>7);
+#else
+ r=(X32COL1(*pdest))+(((((X32ACOL1(color))>>1)* g_m1)&0xFF80FF80)>>7);
+ b=(X32COL2(*pdest))+(((((X32ACOL2(color))>>1)* g_m2)&0xFF80FF80)>>7);
+ g=(X32COL3(*pdest))+(((((X32ACOL3(color))>>1)* g_m3)&0xFF80FF80)>>7);
+#endif
+ }
+
+ if(!(color&0x8000))
+ {
+ r=(r&0xffff0000)|((((X32COL1(color))* g_m1)&0x0000FF80)>>7);
+ b=(b&0xffff0000)|((((X32COL2(color))* g_m2)&0x0000FF80)>>7);
+ g=(g&0xffff0000)|((((X32COL3(color))* g_m3)&0x0000FF80)>>7);
+ }
+ if(!(color&0x80000000))
+ {
+ r=(r&0xffff)|((((X32COL1(color))* g_m1)&0xFF800000)>>7);
+ b=(b&0xffff)|((((X32COL2(color))* g_m2)&0xFF800000)>>7);
+ g=(g&0xffff)|((((X32COL3(color))* g_m3)&0xFF800000)>>7);
+ }
+
+ }
+ else
+ {
+ r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
+ b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
+ g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
+ }
+
+ if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
+ if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
+ if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
+ if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
+ if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
+ if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
+
+ if(bCheckMask)
+ {
+ uint32_t ma=*pdest;
+
+ *pdest=(X32PSXCOL(r,g,b))|l;
+
+ if((color&0xffff)==0 ) *pdest=(ma&0xffff)|(*pdest&0xffff0000);
+ if((color&0xffff0000)==0) *pdest=(ma&0xffff0000)|(*pdest&0xffff);
+ if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
+ if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
+
+ return;
+ }
+ if((color&0xffff)==0 ) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|l)&0xffff0000);return;}
+ if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|l)&0xffff);return;}
+
+ *pdest=(X32PSXCOL(r,g,b))|l;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColG32_S(uint32_t *pdest, uint32_t color)
+{
+ int r,g,b;
+
+ if(color==0) return;
+
+ r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
+ b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
+ g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
+
+ if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
+ if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
+ if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
+ if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
+ if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
+ if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
+
+ if((color&0xffff)==0) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000);return;}
+ if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff);return;}
+
+ *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColG32_SPR(uint32_t *pdest, uint32_t color)
+{
+ int r,g,b;
+
+ if(color==0) return;
+
+ if(DrawSemiTrans && (color&0x80008000))
+ {
+ if(GlobalTextABR==0)
+ {
+ r=((((X32TCOL1(*pdest))+((X32COL1(color)) * g_m1))&0xFF00FF00)>>8);
+ b=((((X32TCOL2(*pdest))+((X32COL2(color)) * g_m2))&0xFF00FF00)>>8);
+ g=((((X32TCOL3(*pdest))+((X32COL3(color)) * g_m3))&0xFF00FF00)>>8);
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r=(X32COL1(*pdest))+(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
+ b=(X32COL2(*pdest))+(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
+ g=(X32COL3(*pdest))+(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ int t;
+ r=(((((X32COL1(color)))* g_m1)&0xFF80FF80)>>7);
+ t=(*pdest&0x001f0000)-(r&0x003f0000); if(t&0x80000000) t=0;
+ r=(*pdest&0x0000001f)-(r&0x0000003f); if(r&0x80000000) r=0;
+ r|=t;
+
+ b=(((((X32COL2(color)))* g_m2)&0xFF80FF80)>>7);
+ t=((*pdest>>5)&0x001f0000)-(b&0x003f0000); if(t&0x80000000) t=0;
+ b=((*pdest>>5)&0x0000001f)-(b&0x0000003f); if(b&0x80000000) b=0;
+ b|=t;
+
+ g=(((((X32COL3(color)))* g_m3)&0xFF80FF80)>>7);
+ t=((*pdest>>10)&0x001f0000)-(g&0x003f0000); if(t&0x80000000) t=0;
+ g=((*pdest>>10)&0x0000001f)-(g&0x0000003f); if(g&0x80000000) g=0;
+ g|=t;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r=(X32COL1(*pdest))+(((((X32BCOL1(color))>>2)* g_m1)&0xFF80FF80)>>7);
+ b=(X32COL2(*pdest))+(((((X32BCOL2(color))>>2)* g_m2)&0xFF80FF80)>>7);
+ g=(X32COL3(*pdest))+(((((X32BCOL3(color))>>2)* g_m3)&0xFF80FF80)>>7);
+#else
+ r=(X32COL1(*pdest))+(((((X32ACOL1(color))>>1)* g_m1)&0xFF80FF80)>>7);
+ b=(X32COL2(*pdest))+(((((X32ACOL2(color))>>1)* g_m2)&0xFF80FF80)>>7);
+ g=(X32COL3(*pdest))+(((((X32ACOL3(color))>>1)* g_m3)&0xFF80FF80)>>7);
+#endif
+ }
+
+ if(!(color&0x8000))
+ {
+ r=(r&0xffff0000)|((((X32COL1(color))* g_m1)&0x0000FF80)>>7);
+ b=(b&0xffff0000)|((((X32COL2(color))* g_m2)&0x0000FF80)>>7);
+ g=(g&0xffff0000)|((((X32COL3(color))* g_m3)&0x0000FF80)>>7);
+ }
+ if(!(color&0x80000000))
+ {
+ r=(r&0xffff)|((((X32COL1(color))* g_m1)&0xFF800000)>>7);
+ b=(b&0xffff)|((((X32COL2(color))* g_m2)&0xFF800000)>>7);
+ g=(g&0xffff)|((((X32COL3(color))* g_m3)&0xFF800000)>>7);
+ }
+
+ }
+ else
+ {
+ r=(((X32COL1(color))* g_m1)&0xFF80FF80)>>7;
+ b=(((X32COL2(color))* g_m2)&0xFF80FF80)>>7;
+ g=(((X32COL3(color))* g_m3)&0xFF80FF80)>>7;
+ }
+
+ if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
+ if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
+ if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
+ if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
+ if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
+ if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
+
+ if(bCheckMask)
+ {
+ uint32_t ma=*pdest;
+
+ *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
+
+ if((color&0xffff)==0 ) *pdest=(ma&0xffff)|(*pdest&0xffff0000);
+ if((color&0xffff0000)==0) *pdest=(ma&0xffff0000)|(*pdest&0xffff);
+ if(ma&0x80000000) *pdest=(ma&0xFFFF0000)|(*pdest&0xFFFF);
+ if(ma&0x00008000) *pdest=(ma&0xFFFF) |(*pdest&0xFFFF0000);
+
+ return;
+ }
+ if((color&0xffff)==0 ) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000);return;}
+ if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff);return;}
+
+ *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColGX_Dither(unsigned short * pdest, unsigned short color, int m1, int m2, int m3)
+{
+ int r,g,b;
+
+ if(color==0) return;
+
+ if(bCheckMask && *pdest&0x8000) return;
+
+ m1=(((XCOL1D(color)))*m1)>>4;
+ m2=(((XCOL2D(color)))*m2)>>4;
+ m3=(((XCOL3D(color)))*m3)>>4;
+
+ if(DrawSemiTrans && (color&0x8000))
+ {
+ r=((XCOL1D(*pdest))<<3);
+ b=((XCOL2D(*pdest))<<3);
+ g=((XCOL3D(*pdest))<<3);
+
+ if(GlobalTextABR==0)
+ {
+ r=(r>>1)+(m1>>1);
+ b=(b>>1)+(m2>>1);
+ g=(g>>1)+(m3>>1);
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r+=m1;
+ b+=m2;
+ g+=m3;
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ r-=m1;
+ b-=m2;
+ g-=m3;
+ if(r&0x80000000) r=0;
+ if(b&0x80000000) b=0;
+ if(g&0x80000000) g=0;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r+=(m1>>2);
+ b+=(m2>>2);
+ g+=(m3>>2);
+#else
+ r+=(m1>>1);
+ b+=(m2>>1);
+ g+=(m3>>1);
+#endif
+ }
+ }
+ else
+ {
+ r=m1;
+ b=m2;
+ g=m3;
+ }
+
+ if(r&0x7FFFFF00) r=0xff;
+ if(b&0x7FFFFF00) b=0xff;
+ if(g&0x7FFFFF00) g=0xff;
+
+ Dither16(pdest,r,b,g,sSetMask|(color&0x8000));
+
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColGX(unsigned short * pdest,unsigned short color,short m1,short m2,short m3)
+{
+ int r,g,b;unsigned short l;
+
+ if(color==0) return;
+
+ if(bCheckMask && *pdest&0x8000) return;
+
+ l=sSetMask|(color&0x8000);
+
+ if(DrawSemiTrans && (color&0x8000))
+ {
+ if(GlobalTextABR==0)
+ {
+ unsigned short d;
+ d =((*pdest)&0x7bde)>>1;
+ color =((color) &0x7bde)>>1;
+ r=(XCOL1(d))+((((XCOL1(color)))* m1)>>7);
+ b=(XCOL2(d))+((((XCOL2(color)))* m2)>>7);
+ g=(XCOL3(d))+((((XCOL3(color)))* m3)>>7);
+/*
+ r=(XCOL1(*pdest)>>1)+((((XCOL1(color))>>1)* m1)>>7);
+ b=(XCOL2(*pdest)>>1)+((((XCOL2(color))>>1)* m2)>>7);
+ g=(XCOL3(*pdest)>>1)+((((XCOL3(color))>>1)* m3)>>7);
+*/
+ }
+ else
+ if(GlobalTextABR==1)
+ {
+ r=(XCOL1(*pdest))+((((XCOL1(color)))* m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color)))* m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color)))* m3)>>7);
+ }
+ else
+ if(GlobalTextABR==2)
+ {
+ r=(XCOL1(*pdest))-((((XCOL1(color)))* m1)>>7);
+ b=(XCOL2(*pdest))-((((XCOL2(color)))* m2)>>7);
+ g=(XCOL3(*pdest))-((((XCOL3(color)))* m3)>>7);
+ if(r&0x80000000) r=0;
+ if(b&0x80000000) b=0;
+ if(g&0x80000000) g=0;
+ }
+ else
+ {
+#ifdef HALFBRIGHTMODE3
+ r=(XCOL1(*pdest))+((((XCOL1(color))>>2)* m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color))>>2)* m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color))>>2)* m3)>>7);
+#else
+ r=(XCOL1(*pdest))+((((XCOL1(color))>>1)* m1)>>7);
+ b=(XCOL2(*pdest))+((((XCOL2(color))>>1)* m2)>>7);
+ g=(XCOL3(*pdest))+((((XCOL3(color))>>1)* m3)>>7);
+#endif
+ }
+ }
+ else
+ {
+ r=((XCOL1(color))* m1)>>7;
+ b=((XCOL2(color))* m2)>>7;
+ g=((XCOL3(color))* m3)>>7;
+ }
+
+ if(r&0x7FFFFFE0) r=0x1f;
+ if(b&0x7FFFFC00) b=0x3e0;
+ if(g&0x7FFF8000) g=0x7c00;
+
+ *pdest=(XPSXCOL(r,g,b))|l;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColGX_S(unsigned short * pdest,unsigned short color,short m1,short m2,short m3)
+{
+ int r,g,b;
+
+ if(color==0) return;
+
+ r=((XCOL1(color))* m1)>>7;
+ b=((XCOL2(color))* m2)>>7;
+ g=((XCOL3(color))* m3)>>7;
+
+ if(r&0x7FFFFFE0) r=0x1f;
+ if(b&0x7FFFFC00) b=0x3e0;
+ if(g&0x7FFF8000) g=0x7c00;
+
+ *pdest=(XPSXCOL(r,g,b))|sSetMask|(color&0x8000);
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static __inline void GetTextureTransColGX32_S(uint32_t *pdest, uint32_t color, short m1, short m2, short m3)
+{
+ int r,g,b;
+
+ if(color==0) return;
+
+ r=(((X32COL1(color))* m1)&0xFF80FF80)>>7;
+ b=(((X32COL2(color))* m2)&0xFF80FF80)>>7;
+ g=(((X32COL3(color))* m3)&0xFF80FF80)>>7;
+
+ if(r&0x7FE00000) r=0x1f0000|(r&0xFFFF);
+ if(r&0x7FE0) r=0x1f |(r&0xFFFF0000);
+ if(b&0x7FE00000) b=0x1f0000|(b&0xFFFF);
+ if(b&0x7FE0) b=0x1f |(b&0xFFFF0000);
+ if(g&0x7FE00000) g=0x1f0000|(g&0xFFFF);
+ if(g&0x7FE0) g=0x1f |(g&0xFFFF0000);
+
+ if((color&0xffff)==0) {*pdest=(*pdest&0xffff)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff0000);return;}
+ if((color&0xffff0000)==0) {*pdest=(*pdest&0xffff0000)|(((X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000))&0xffff);return;}
+
+ *pdest=(X32PSXCOL(r,g,b))|lSetMask|(color&0x80008000);
+}
+
+////////////////////////////////////////////////////////////////////////
+// FILL FUNCS
+////////////////////////////////////////////////////////////////////////
+
+void FillSoftwareAreaTrans(short x0,short y0,short x1, // FILL AREA TRANS
+ short y1,unsigned short col)
+{
+ short j,i,dx,dy;
+
+ if(y0>y1) return;
+ if(x0>x1) return;
+
+ if(x1<drawX) return;
+ if(y1<drawY) return;
+ if(x0>drawW) return;
+ if(y0>drawH) return;
+
+ x1=min(x1,drawW+1);
+ y1=min(y1,drawH+1);
+ x0=max(x0,drawX);
+ y0=max(y0,drawY);
+
+ if(y0>=iGPUHeight) return;
+ if(x0>1023) return;
+
+ if(y1>iGPUHeight) y1=iGPUHeight;
+ if(x1>1024) x1=1024;
+
+ dx=x1-x0;dy=y1-y0;
+
+ if(dx==1 && dy==1 && x0==1020 && y0==511) // special fix for pinball game... emu protection???
+ {
+/*
+m->v 1020 511 1 1
+writedatamem 0x00000000 1
+tile1 newcol 7fff (orgcol 0xffffff), oldvram 0
+v->m 1020 511 1 1
+readdatamem 0x00007fff 1
+m->v 1020 511 1 1
+writedatamem 0x00000000 1
+tile1 newcol 8000 (orgcol 0xffffff), oldvram 0
+v->m 1020 511 1 1
+readdatamem 0x00008000 1
+*/
+
+ static int iCheat=0;
+ col+=iCheat;
+ if(iCheat==1) iCheat=0; else iCheat=1;
+ }
+
+ if(dx&1) // slow fill
+ {
+ unsigned short *DSTPtr;
+ unsigned short LineOffset;
+ DSTPtr = psxVuw + (1024*y0) + x0;
+ LineOffset = 1024 - dx;
+ for(i=0;i<dy;i++)
+ {
+ for(j=0;j<dx;j++)
+ GetShadeTransCol(DSTPtr++,col);
+ DSTPtr += LineOffset;
+ }
+ }
+ else // fast fill
+ {
+ uint32_t *DSTPtr;
+ unsigned short LineOffset;
+ uint32_t lcol=lSetMask|(((uint32_t)(col))<<16)|col;
+ dx>>=1;
+ DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0);
+ LineOffset = 512 - dx;
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for(i=0;i<dy;i++)
+ {
+ for(j=0;j<dx;j++) *DSTPtr++=lcol;
+ DSTPtr += LineOffset;
+ }
+ }
+ else
+ {
+ for(i=0;i<dy;i++)
+ {
+ for(j=0;j<dx;j++)
+ GetShadeTransCol32(DSTPtr++,lcol);
+ DSTPtr += LineOffset;
+ }
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void FillSoftwareArea(short x0,short y0,short x1, // FILL AREA (BLK FILL)
+ short y1,unsigned short col) // no draw area check here!
+{
+ short j,i,dx,dy;
+
+ if(y0>y1) return;
+ if(x0>x1) return;
+
+ if(y0>=iGPUHeight) return;
+ if(x0>1023) return;
+
+ if(y1>iGPUHeight) y1=iGPUHeight;
+ if(x1>1024) x1=1024;
+
+ dx=x1-x0;dy=y1-y0;
+ if(dx&1)
+ {
+ unsigned short *DSTPtr;
+ unsigned short LineOffset;
+
+ DSTPtr = psxVuw + (1024*y0) + x0;
+ LineOffset = 1024 - dx;
+
+ for(i=0;i<dy;i++)
+ {
+ for(j=0;j<dx;j++) *DSTPtr++=col;
+ DSTPtr += LineOffset;
+ }
+ }
+ else
+ {
+ uint32_t *DSTPtr;
+ unsigned short LineOffset;
+ uint32_t lcol=(((int)col)<<16)|col;
+ dx>>=1;
+ DSTPtr = (uint32_t *)(psxVuw + (1024*y0) + x0);
+ LineOffset = 512 - dx;
+
+ for(i=0;i<dy;i++)
+ {
+ for(j=0;j<dx;j++) *DSTPtr++=lcol;
+ DSTPtr += LineOffset;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// EDGE INTERPOLATION
+////////////////////////////////////////////////////////////////////////
+
+typedef struct SOFTVTAG
+{
+ int x,y;
+ int u,v;
+ int R,G,B;
+} soft_vertex;
+
+static soft_vertex vtx[4];
+static soft_vertex * left_array[4], * right_array[4];
+static int left_section, right_section;
+static int left_section_height, right_section_height;
+static int left_x, delta_left_x, right_x, delta_right_x;
+static int left_u, delta_left_u, left_v, delta_left_v;
+static int right_u, delta_right_u, right_v, delta_right_v;
+static int left_R, delta_left_R, right_R, delta_right_R;
+static int left_G, delta_left_G, right_G, delta_right_G;
+static int left_B, delta_left_B, right_B, delta_right_B;
+
+#ifdef _MSC_VER
+
+#pragma warning (disable : 4035)
+
+static __inline int shl10idiv(int x, int y)
+{
+ __asm
+ {
+ mov eax,x
+ mov ebx,y
+ mov edx, eax
+ shl eax, 10
+ sar edx, 22
+ idiv ebx
+ // return result in eax
+ }
+}
+
+#else
+
+static __inline int shl10idiv(int x, int y)
+{
+ long long int bi=x;
+ bi<<=10;
+ return bi/y;
+}
+
+#endif
+
+static __inline int RightSection_F(void)
+{
+ soft_vertex * v1 = right_array[ right_section ];
+ soft_vertex * v2 = right_array[ right_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_right_x = (v2->x - v1->x) / height;
+ right_x = v1->x;
+
+ right_section_height = height;
+ return height;
+}
+
+static __inline int LeftSection_F(void)
+{
+ soft_vertex * v1 = left_array[ left_section ];
+ soft_vertex * v2 = left_array[ left_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_left_x = (v2->x - v1->x) / height;
+ left_x = v1->x;
+
+ left_section_height = height;
+ return height;
+}
+
+static __inline BOOL NextRow_F(void)
+{
+ if(--left_section_height<=0)
+ {
+ if(--left_section <= 0) {return TRUE;}
+ if(LeftSection_F() <= 0) {return TRUE;}
+ }
+ else
+ {
+ left_x += delta_left_x;
+ }
+
+ if(--right_section_height<=0)
+ {
+ if(--right_section<=0) {return TRUE;}
+ if(RightSection_F() <=0) {return TRUE;}
+ }
+ else
+ {
+ right_x += delta_right_x;
+ }
+ return FALSE;
+}
+
+static __inline BOOL SetupSections_F(short x1, short y1, short x2, short y2, short x3, short y3)
+{
+ soft_vertex * v1, * v2, * v3;
+ int height,longest;
+
+ v1 = vtx; v1->x=x1<<16;v1->y=y1;
+ v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
+ v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
+
+ if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
+ if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
+ if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
+
+ height = v3->y - v1->y;
+ if(height == 0) {return FALSE;}
+ longest = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest == 0) {return FALSE;}
+
+ if(longest < 0)
+ {
+ right_array[0] = v3;
+ right_array[1] = v2;
+ right_array[2] = v1;
+ right_section = 2;
+ left_array[0] = v3;
+ left_array[1] = v1;
+ left_section = 1;
+
+ if(LeftSection_F() <= 0) return FALSE;
+ if(RightSection_F() <= 0)
+ {
+ right_section--;
+ if(RightSection_F() <= 0) return FALSE;
+ }
+ }
+ else
+ {
+ left_array[0] = v3;
+ left_array[1] = v2;
+ left_array[2] = v1;
+ left_section = 2;
+ right_array[0] = v3;
+ right_array[1] = v1;
+ right_section = 1;
+
+ if(RightSection_F() <= 0) return FALSE;
+ if(LeftSection_F() <= 0)
+ {
+ left_section--;
+ if(LeftSection_F() <= 0) return FALSE;
+ }
+ }
+
+ Ymin=v1->y;
+ Ymax=min(v3->y-1,drawH);
+
+ return TRUE;
+}
+
+static __inline int RightSection_G(void)
+{
+ soft_vertex * v1 = right_array[ right_section ];
+ soft_vertex * v2 = right_array[ right_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_right_x = (v2->x - v1->x) / height;
+ right_x = v1->x;
+
+ right_section_height = height;
+ return height;
+}
+
+static __inline int LeftSection_G(void)
+{
+ soft_vertex * v1 = left_array[ left_section ];
+ soft_vertex * v2 = left_array[ left_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_left_x = (v2->x - v1->x) / height;
+ left_x = v1->x;
+
+ delta_left_R = ((v2->R - v1->R)) / height;
+ left_R = v1->R;
+ delta_left_G = ((v2->G - v1->G)) / height;
+ left_G = v1->G;
+ delta_left_B = ((v2->B - v1->B)) / height;
+ left_B = v1->B;
+
+ left_section_height = height;
+ return height;
+}
+
+static __inline BOOL NextRow_G(void)
+{
+ if(--left_section_height<=0)
+ {
+ if(--left_section <= 0) {return TRUE;}
+ if(LeftSection_G() <= 0) {return TRUE;}
+ }
+ else
+ {
+ left_x += delta_left_x;
+ left_R += delta_left_R;
+ left_G += delta_left_G;
+ left_B += delta_left_B;
+ }
+
+ if(--right_section_height<=0)
+ {
+ if(--right_section<=0) {return TRUE;}
+ if(RightSection_G() <=0) {return TRUE;}
+ }
+ else
+ {
+ right_x += delta_right_x;
+ }
+ return FALSE;
+}
+
+static __inline BOOL SetupSections_G(short x1,short y1,short x2,short y2,short x3,short y3, int rgb1, int rgb2, int rgb3){
+ soft_vertex *v1, *v2, *v3;
+ int height, longest, temp;
+
+ v1 = vtx; v1->x=x1<<16;v1->y=y1;
+ v1->R=(rgb1) & 0x00ff0000;
+ v1->G=(rgb1<<8) & 0x00ff0000;
+ v1->B=(rgb1<<16) & 0x00ff0000;
+ v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
+ v2->R=(rgb2) & 0x00ff0000;
+ v2->G=(rgb2<<8) & 0x00ff0000;
+ v2->B=(rgb2<<16) & 0x00ff0000;
+ v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
+ v3->R=(rgb3) & 0x00ff0000;
+ v3->G=(rgb3<<8) & 0x00ff0000;
+ v3->B=(rgb3<<16) & 0x00ff0000;
+
+ if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
+ if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
+ if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
+
+ height = v3->y - v1->y;
+ if(height == 0) {return FALSE;}
+ temp=(((v2->y - v1->y) << 16) / height);
+ longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest == 0) {return FALSE;}
+
+ if(longest < 0)
+ {
+ right_array[0] = v3;
+ right_array[1] = v2;
+ right_array[2] = v1;
+ right_section = 2;
+ left_array[0] = v3;
+ left_array[1] = v1;
+ left_section = 1;
+
+ if(LeftSection_G() <= 0) return FALSE;
+ if(RightSection_G() <= 0)
+ {
+ right_section--;
+ if(RightSection_G() <= 0) return FALSE;
+ }
+ if(longest > -0x1000) longest = -0x1000;
+ }
+ else
+ {
+ left_array[0] = v3;
+ left_array[1] = v2;
+ left_array[2] = v1;
+ left_section = 2;
+ right_array[0] = v3;
+ right_array[1] = v1;
+ right_section = 1;
+
+ if(RightSection_G() <= 0) return FALSE;
+ if(LeftSection_G() <= 0)
+ {
+ left_section--;
+ if(LeftSection_G() <= 0) return FALSE;
+ }
+ if(longest < 0x1000) longest = 0x1000;
+ }
+
+ Ymin=v1->y;
+ Ymax=min(v3->y-1,drawH);
+
+ delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
+ delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
+ delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
+
+ return TRUE;
+}
+
+static __inline int RightSection_FT(void)
+{
+ soft_vertex * v1 = right_array[ right_section ];
+ soft_vertex * v2 = right_array[ right_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_right_x = (v2->x - v1->x) / height;
+ right_x = v1->x;
+
+ right_section_height = height;
+ return height;
+}
+
+static __inline int LeftSection_FT(void)
+{
+ soft_vertex * v1 = left_array[ left_section ];
+ soft_vertex * v2 = left_array[ left_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_left_x = (v2->x - v1->x) / height;
+ left_x = v1->x;
+
+ delta_left_u = ((v2->u - v1->u)) / height;
+ left_u = v1->u;
+ delta_left_v = ((v2->v - v1->v)) / height;
+ left_v = v1->v;
+
+ left_section_height = height;
+ return height;
+}
+
+static __inline BOOL NextRow_FT(void)
+{
+ if(--left_section_height<=0)
+ {
+ if(--left_section <= 0) {return TRUE;}
+ if(LeftSection_FT() <= 0) {return TRUE;}
+ }
+ else
+ {
+ left_x += delta_left_x;
+ left_u += delta_left_u;
+ left_v += delta_left_v;
+ }
+
+ if(--right_section_height<=0)
+ {
+ if(--right_section<=0) {return TRUE;}
+ if(RightSection_FT() <=0) {return TRUE;}
+ }
+ else
+ {
+ right_x += delta_right_x;
+ }
+ return FALSE;
+}
+
+static __inline BOOL SetupSections_FT(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
+{
+ soft_vertex * v1, * v2, * v3;
+ int height,longest,temp;
+
+ v1 = vtx; v1->x=x1<<16;v1->y=y1;
+ v1->u=tx1<<16;v1->v=ty1<<16;
+ v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
+ v2->u=tx2<<16;v2->v=ty2<<16;
+ v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
+ v3->u=tx3<<16;v3->v=ty3<<16;
+
+ if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
+ if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
+ if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
+
+ height = v3->y - v1->y;
+ if(height == 0) {return FALSE;}
+
+ temp=(((v2->y - v1->y) << 16) / height);
+ longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+
+ if(longest == 0) {return FALSE;}
+
+ if(longest < 0)
+ {
+ right_array[0] = v3;
+ right_array[1] = v2;
+ right_array[2] = v1;
+ right_section = 2;
+ left_array[0] = v3;
+ left_array[1] = v1;
+ left_section = 1;
+
+ if(LeftSection_FT() <= 0) return FALSE;
+ if(RightSection_FT() <= 0)
+ {
+ right_section--;
+ if(RightSection_FT() <= 0) return FALSE;
+ }
+ if(longest > -0x1000) longest = -0x1000;
+ }
+ else
+ {
+ left_array[0] = v3;
+ left_array[1] = v2;
+ left_array[2] = v1;
+ left_section = 2;
+ right_array[0] = v3;
+ right_array[1] = v1;
+ right_section = 1;
+
+ if(RightSection_FT() <= 0) return FALSE;
+ if(LeftSection_FT() <= 0)
+ {
+ left_section--;
+ if(LeftSection_FT() <= 0) return FALSE;
+ }
+ if(longest < 0x1000) longest = 0x1000;
+ }
+
+ Ymin=v1->y;
+ Ymax=min(v3->y-1,drawH);
+
+ delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
+ delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
+
+/*
+Mmm... adjust neg tex deltas... will sometimes cause slight
+texture distortions
+
+ longest>>=16;
+ if(longest)
+ {
+ if(longest<0) longest=-longest;
+ if(delta_right_u<0)
+ delta_right_u-=delta_right_u/longest;
+ if(delta_right_v<0)
+ delta_right_v-=delta_right_v/longest;
+ }
+*/
+
+ return TRUE;
+}
+
+static __inline int RightSection_GT(void)
+{
+ soft_vertex * v1 = right_array[ right_section ];
+ soft_vertex * v2 = right_array[ right_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_right_x = (v2->x - v1->x) / height;
+ right_x = v1->x;
+
+ right_section_height = height;
+ return height;
+}
+
+static __inline int LeftSection_GT(void)
+{
+ soft_vertex * v1 = left_array[ left_section ];
+ soft_vertex * v2 = left_array[ left_section-1 ];
+
+ int height = v2->y - v1->y;
+ if(height == 0) return 0;
+ delta_left_x = (v2->x - v1->x) / height;
+ left_x = v1->x;
+
+ delta_left_u = ((v2->u - v1->u)) / height;
+ left_u = v1->u;
+ delta_left_v = ((v2->v - v1->v)) / height;
+ left_v = v1->v;
+
+ delta_left_R = ((v2->R - v1->R)) / height;
+ left_R = v1->R;
+ delta_left_G = ((v2->G - v1->G)) / height;
+ left_G = v1->G;
+ delta_left_B = ((v2->B - v1->B)) / height;
+ left_B = v1->B;
+
+ left_section_height = height;
+ return height;
+}
+
+static __inline BOOL NextRow_GT(void)
+{
+ if(--left_section_height<=0)
+ {
+ if(--left_section <= 0) {return TRUE;}
+ if(LeftSection_GT() <= 0) {return TRUE;}
+ }
+ else
+ {
+ left_x += delta_left_x;
+ left_u += delta_left_u;
+ left_v += delta_left_v;
+ left_R += delta_left_R;
+ left_G += delta_left_G;
+ left_B += delta_left_B;
+ }
+
+ if(--right_section_height<=0)
+ {
+ if(--right_section<=0) {return TRUE;}
+ if(RightSection_GT() <=0) {return TRUE;}
+ }
+ else
+ {
+ right_x += delta_right_x;
+ }
+ return FALSE;
+}
+
+static __inline BOOL SetupSections_GT(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, int rgb1, int rgb2, int rgb3)
+{
+ soft_vertex * v1, * v2, * v3;
+ int height,longest,temp;
+
+ v1 = vtx; v1->x=x1<<16;v1->y=y1;
+ v1->u=tx1<<16;v1->v=ty1<<16;
+ v1->R=(rgb1) & 0x00ff0000;
+ v1->G=(rgb1<<8) & 0x00ff0000;
+ v1->B=(rgb1<<16) & 0x00ff0000;
+
+ v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
+ v2->u=tx2<<16;v2->v=ty2<<16;
+ v2->R=(rgb2) & 0x00ff0000;
+ v2->G=(rgb2<<8) & 0x00ff0000;
+ v2->B=(rgb2<<16) & 0x00ff0000;
+
+ v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
+ v3->u=tx3<<16;v3->v=ty3<<16;
+ v3->R=(rgb3) & 0x00ff0000;
+ v3->G=(rgb3<<8) & 0x00ff0000;
+ v3->B=(rgb3<<16) & 0x00ff0000;
+
+ if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
+ if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
+ if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
+
+ height = v3->y - v1->y;
+ if(height == 0) {return FALSE;}
+
+ temp=(((v2->y - v1->y) << 16) / height);
+ longest = temp * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+
+ if(longest == 0) {return FALSE;}
+
+ if(longest < 0)
+ {
+ right_array[0] = v3;
+ right_array[1] = v2;
+ right_array[2] = v1;
+ right_section = 2;
+ left_array[0] = v3;
+ left_array[1] = v1;
+ left_section = 1;
+
+ if(LeftSection_GT() <= 0) return FALSE;
+ if(RightSection_GT() <= 0)
+ {
+ right_section--;
+ if(RightSection_GT() <= 0) return FALSE;
+ }
+
+ if(longest > -0x1000) longest = -0x1000;
+ }
+ else
+ {
+ left_array[0] = v3;
+ left_array[1] = v2;
+ left_array[2] = v1;
+ left_section = 2;
+ right_array[0] = v3;
+ right_array[1] = v1;
+ right_section = 1;
+
+ if(RightSection_GT() <= 0) return FALSE;
+ if(LeftSection_GT() <= 0)
+ {
+ left_section--;
+ if(LeftSection_GT() <= 0) return FALSE;
+ }
+ if(longest < 0x1000) longest = 0x1000;
+ }
+
+ Ymin=v1->y;
+ Ymax=min(v3->y-1,drawH);
+
+ delta_right_R=shl10idiv(temp*((v3->R - v1->R)>>10)+((v1->R - v2->R)<<6),longest);
+ delta_right_G=shl10idiv(temp*((v3->G - v1->G)>>10)+((v1->G - v2->G)<<6),longest);
+ delta_right_B=shl10idiv(temp*((v3->B - v1->B)>>10)+((v1->B - v2->B)<<6),longest);
+
+ delta_right_u=shl10idiv(temp*((v3->u - v1->u)>>10)+((v1->u - v2->u)<<6),longest);
+ delta_right_v=shl10idiv(temp*((v3->v - v1->v)>>10)+((v1->v - v2->v)<<6),longest);
+
+
+/*
+Mmm... adjust neg tex deltas... will sometimes cause slight
+texture distortions
+ longest>>=16;
+ if(longest)
+ {
+ if(longest<0) longest=-longest;
+ if(delta_right_u<0)
+ delta_right_u-=delta_right_u/longest;
+ if(delta_right_v<0)
+ delta_right_v-=delta_right_v/longest;
+ }
+*/
+
+
+ return TRUE;
+}
+
+static __inline int RightSection_F4(void)
+{
+ soft_vertex * v1 = right_array[ right_section ];
+ soft_vertex * v2 = right_array[ right_section-1 ];
+
+ int height = v2->y - v1->y;
+ right_section_height = height;
+ right_x = v1->x;
+ if(height == 0)
+ {
+ return 0;
+ }
+ delta_right_x = (v2->x - v1->x) / height;
+
+ return height;
+}
+
+static __inline int LeftSection_F4(void)
+{
+ soft_vertex * v1 = left_array[ left_section ];
+ soft_vertex * v2 = left_array[ left_section-1 ];
+
+ int height = v2->y - v1->y;
+ left_section_height = height;
+ left_x = v1->x;
+ if(height == 0)
+ {
+ return 0;
+ }
+ delta_left_x = (v2->x - v1->x) / height;
+
+ return height;
+}
+
+static __inline BOOL NextRow_F4(void)
+{
+ if(--left_section_height<=0)
+ {
+ if(--left_section > 0)
+ while(LeftSection_F4()<=0)
+ {
+ if(--left_section <= 0) break;
+ }
+ }
+ else
+ {
+ left_x += delta_left_x;
+ }
+
+ if(--right_section_height<=0)
+ {
+ if(--right_section > 0)
+ while(RightSection_F4()<=0)
+ {
+ if(--right_section<=0) break;
+ }
+ }
+ else
+ {
+ right_x += delta_right_x;
+ }
+ return FALSE;
+}
+
+static __inline BOOL SetupSections_F4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4)
+{
+ soft_vertex * v1, * v2, * v3, * v4;
+ int height,width,longest1,longest2;
+
+ v1 = vtx; v1->x=x1<<16;v1->y=y1;
+ v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
+ v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
+ v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
+
+ if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
+ if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
+ if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
+ if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
+ if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
+ if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
+
+ height = v4->y - v1->y; if(height == 0) height =1;
+ width = (v4->x - v1->x)>>16;
+ longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
+ longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
+
+ if(longest1 < 0) // 2 is right
+ {
+ if(longest2 < 0) // 3 is right
+ {
+ left_array[0] = v4;
+ left_array[1] = v1;
+ left_section = 1;
+
+ height = v3->y - v1->y; if(height == 0) height=1;
+ longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest1 >= 0)
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v3; // 3
+ right_array[2] = v1; // 4
+ right_section = 2;
+ }
+ else
+ {
+ height = v4->y - v2->y; if(height == 0) height=1;
+ longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
+ if(longest1 >= 0)
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v2; // 2
+ right_array[2] = v1; // 4
+ right_section = 2;
+ }
+ else
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v3; // 2
+ right_array[2] = v2; // 3
+ right_array[3] = v1; // 4
+ right_section = 3;
+ }
+ }
+ }
+ else
+ {
+ left_array[0] = v4;
+ left_array[1] = v3; // 1
+ left_array[2] = v1; // 2
+ left_section = 2; // 3
+ right_array[0] = v4; // 4
+ right_array[1] = v2;
+ right_array[2] = v1;
+ right_section = 2;
+ }
+ }
+ else
+ {
+ if(longest2 < 0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v2; // 2
+ left_array[2] = v1; // 3
+ left_section = 2; // 4
+ right_array[0] = v4;
+ right_array[1] = v3;
+ right_array[2] = v1;
+ right_section = 2;
+ }
+ else
+ {
+ right_array[0] = v4;
+ right_array[1] = v1;
+ right_section = 1;
+
+ height = v3->y - v1->y; if(height == 0) height=1;
+ longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest1<0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v3; // 3
+ left_array[2] = v1; // 4
+ left_section = 2;
+ }
+ else
+ {
+ height = v4->y - v2->y; if(height == 0) height=1;
+ longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
+ if(longest1<0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v2; // 2
+ left_array[2] = v1; // 4
+ left_section = 2;
+ }
+ else
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v3; // 2
+ left_array[2] = v2; // 3
+ left_array[3] = v1; // 4
+ left_section = 3;
+ }
+ }
+ }
+ }
+
+ while(LeftSection_F4()<=0)
+ {
+ if(--left_section <= 0) break;
+ }
+
+ while(RightSection_F4()<=0)
+ {
+ if(--right_section <= 0) break;
+ }
+
+ Ymin=v1->y;
+ Ymax=min(v4->y-1,drawH);
+
+ return TRUE;
+}
+
+static __inline int RightSection_FT4(void)
+{
+ soft_vertex * v1 = right_array[ right_section ];
+ soft_vertex * v2 = right_array[ right_section-1 ];
+
+ int height = v2->y - v1->y;
+ right_section_height = height;
+ right_x = v1->x;
+ right_u = v1->u;
+ right_v = v1->v;
+ if(height == 0)
+ {
+ return 0;
+ }
+ delta_right_x = (v2->x - v1->x) / height;
+ delta_right_u = (v2->u - v1->u) / height;
+ delta_right_v = (v2->v - v1->v) / height;
+
+ return height;
+}
+
+static __inline int LeftSection_FT4(void)
+{
+ soft_vertex * v1 = left_array[ left_section ];
+ soft_vertex * v2 = left_array[ left_section-1 ];
+
+ int height = v2->y - v1->y;
+ left_section_height = height;
+ left_x = v1->x;
+ left_u = v1->u;
+ left_v = v1->v;
+ if(height == 0)
+ {
+ return 0;
+ }
+ delta_left_x = (v2->x - v1->x) / height;
+ delta_left_u = (v2->u - v1->u) / height;
+ delta_left_v = (v2->v - v1->v) / height;
+
+ return height;
+}
+
+static __inline BOOL NextRow_FT4(void)
+{
+ if(--left_section_height<=0)
+ {
+ if(--left_section > 0)
+ while(LeftSection_FT4()<=0)
+ {
+ if(--left_section <= 0) break;
+ }
+ }
+ else
+ {
+ left_x += delta_left_x;
+ left_u += delta_left_u;
+ left_v += delta_left_v;
+ }
+
+ if(--right_section_height<=0)
+ {
+ if(--right_section > 0)
+ while(RightSection_FT4()<=0)
+ {
+ if(--right_section<=0) break;
+ }
+ }
+ else
+ {
+ right_x += delta_right_x;
+ right_u += delta_right_u;
+ right_v += delta_right_v;
+ }
+ return FALSE;
+}
+
+static __inline BOOL SetupSections_FT4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
+{
+ soft_vertex * v1, * v2, * v3, * v4;
+ int height,width,longest1,longest2;
+
+ v1 = vtx; v1->x=x1<<16;v1->y=y1;
+ v1->u=tx1<<16;v1->v=ty1<<16;
+
+ v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
+ v2->u=tx2<<16;v2->v=ty2<<16;
+
+ v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
+ v3->u=tx3<<16;v3->v=ty3<<16;
+
+ v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
+ v4->u=tx4<<16;v4->v=ty4<<16;
+
+ if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
+ if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
+ if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
+ if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
+ if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
+ if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
+
+ height = v4->y - v1->y; if(height == 0) height =1;
+ width = (v4->x - v1->x)>>16;
+ longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
+ longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
+
+ if(longest1 < 0) // 2 is right
+ {
+ if(longest2 < 0) // 3 is right
+ {
+ left_array[0] = v4;
+ left_array[1] = v1;
+ left_section = 1;
+
+ height = v3->y - v1->y; if(height == 0) height=1;
+ longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest1 >= 0)
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v3; // 3
+ right_array[2] = v1; // 4
+ right_section = 2;
+ }
+ else
+ {
+ height = v4->y - v2->y; if(height == 0) height=1;
+ longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
+ if(longest1 >= 0)
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v2; // 2
+ right_array[2] = v1; // 4
+ right_section = 2;
+ }
+ else
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v3; // 2
+ right_array[2] = v2; // 3
+ right_array[3] = v1; // 4
+ right_section = 3;
+ }
+ }
+ }
+ else
+ {
+ left_array[0] = v4;
+ left_array[1] = v3; // 1
+ left_array[2] = v1; // 2
+ left_section = 2; // 3
+ right_array[0] = v4; // 4
+ right_array[1] = v2;
+ right_array[2] = v1;
+ right_section = 2;
+ }
+ }
+ else
+ {
+ if(longest2 < 0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v2; // 2
+ left_array[2] = v1; // 3
+ left_section = 2; // 4
+ right_array[0] = v4;
+ right_array[1] = v3;
+ right_array[2] = v1;
+ right_section = 2;
+ }
+ else
+ {
+ right_array[0] = v4;
+ right_array[1] = v1;
+ right_section = 1;
+
+ height = v3->y - v1->y; if(height == 0) height=1;
+ longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest1<0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v3; // 3
+ left_array[2] = v1; // 4
+ left_section = 2;
+ }
+ else
+ {
+ height = v4->y - v2->y; if(height == 0) height=1;
+ longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
+ if(longest1<0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v2; // 2
+ left_array[2] = v1; // 4
+ left_section = 2;
+ }
+ else
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v3; // 2
+ left_array[2] = v2; // 3
+ left_array[3] = v1; // 4
+ left_section = 3;
+ }
+ }
+ }
+ }
+
+ while(LeftSection_FT4()<=0)
+ {
+ if(--left_section <= 0) break;
+ }
+
+ while(RightSection_FT4()<=0)
+ {
+ if(--right_section <= 0) break;
+ }
+
+ Ymin=v1->y;
+ Ymax=min(v4->y-1,drawH);
+
+ return TRUE;
+}
+
+static __inline int RightSection_GT4(void)
+{
+ soft_vertex * v1 = right_array[ right_section ];
+ soft_vertex * v2 = right_array[ right_section-1 ];
+
+ int height = v2->y - v1->y;
+ right_section_height = height;
+ right_x = v1->x;
+ right_u = v1->u;
+ right_v = v1->v;
+ right_R = v1->R;
+ right_G = v1->G;
+ right_B = v1->B;
+
+ if(height == 0)
+ {
+ return 0;
+ }
+ delta_right_x = (v2->x - v1->x) / height;
+ delta_right_u = (v2->u - v1->u) / height;
+ delta_right_v = (v2->v - v1->v) / height;
+ delta_right_R = (v2->R - v1->R) / height;
+ delta_right_G = (v2->G - v1->G) / height;
+ delta_right_B = (v2->B - v1->B) / height;
+
+ return height;
+}
+
+static __inline int LeftSection_GT4(void)
+{
+ soft_vertex * v1 = left_array[ left_section ];
+ soft_vertex * v2 = left_array[ left_section-1 ];
+
+ int height = v2->y - v1->y;
+ left_section_height = height;
+ left_x = v1->x;
+ left_u = v1->u;
+ left_v = v1->v;
+ left_R = v1->R;
+ left_G = v1->G;
+ left_B = v1->B;
+
+ if(height == 0)
+ {
+ return 0;
+ }
+ delta_left_x = (v2->x - v1->x) / height;
+ delta_left_u = (v2->u - v1->u) / height;
+ delta_left_v = (v2->v - v1->v) / height;
+ delta_left_R = (v2->R - v1->R) / height;
+ delta_left_G = (v2->G - v1->G) / height;
+ delta_left_B = (v2->B - v1->B) / height;
+
+ return height;
+}
+
+static __inline BOOL NextRow_GT4(void)
+{
+ if(--left_section_height<=0)
+ {
+ if(--left_section > 0)
+ while(LeftSection_GT4()<=0)
+ {
+ if(--left_section <= 0) break;
+ }
+ }
+ else
+ {
+ left_x += delta_left_x;
+ left_u += delta_left_u;
+ left_v += delta_left_v;
+ left_R += delta_left_R;
+ left_G += delta_left_G;
+ left_B += delta_left_B;
+ }
+
+ if(--right_section_height<=0)
+ {
+ if(--right_section > 0)
+ while(RightSection_GT4()<=0)
+ {
+ if(--right_section<=0) break;
+ }
+ }
+ else
+ {
+ right_x += delta_right_x;
+ right_u += delta_right_u;
+ right_v += delta_right_v;
+ right_R += delta_right_R;
+ right_G += delta_right_G;
+ right_B += delta_right_B;
+ }
+ return FALSE;
+}
+
+static __inline BOOL SetupSections_GT4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int rgb1, int rgb2, int rgb3, int rgb4)
+{
+ soft_vertex * v1, * v2, * v3, * v4;
+ int height,width,longest1,longest2;
+
+ v1 = vtx; v1->x=x1<<16;v1->y=y1;
+ v1->u=tx1<<16;v1->v=ty1<<16;
+ v1->R=(rgb1) & 0x00ff0000;
+ v1->G=(rgb1<<8) & 0x00ff0000;
+ v1->B=(rgb1<<16) & 0x00ff0000;
+
+ v2 = vtx+1; v2->x=x2<<16;v2->y=y2;
+ v2->u=tx2<<16;v2->v=ty2<<16;
+ v2->R=(rgb2) & 0x00ff0000;
+ v2->G=(rgb2<<8) & 0x00ff0000;
+ v2->B=(rgb2<<16) & 0x00ff0000;
+
+ v3 = vtx+2; v3->x=x3<<16;v3->y=y3;
+ v3->u=tx3<<16;v3->v=ty3<<16;
+ v3->R=(rgb3) & 0x00ff0000;
+ v3->G=(rgb3<<8) & 0x00ff0000;
+ v3->B=(rgb3<<16) & 0x00ff0000;
+
+ v4 = vtx+3; v4->x=x4<<16;v4->y=y4;
+ v4->u=tx4<<16;v4->v=ty4<<16;
+ v4->R=(rgb4) & 0x00ff0000;
+ v4->G=(rgb4<<8) & 0x00ff0000;
+ v4->B=(rgb4<<16) & 0x00ff0000;
+
+ if(v1->y > v2->y) { soft_vertex * v = v1; v1 = v2; v2 = v; }
+ if(v1->y > v3->y) { soft_vertex * v = v1; v1 = v3; v3 = v; }
+ if(v1->y > v4->y) { soft_vertex * v = v1; v1 = v4; v4 = v; }
+ if(v2->y > v3->y) { soft_vertex * v = v2; v2 = v3; v3 = v; }
+ if(v2->y > v4->y) { soft_vertex * v = v2; v2 = v4; v4 = v; }
+ if(v3->y > v4->y) { soft_vertex * v = v3; v3 = v4; v4 = v; }
+
+ height = v4->y - v1->y; if(height == 0) height =1;
+ width = (v4->x - v1->x)>>16;
+ longest1 = (((v2->y - v1->y) << 16) / height) * width + (v1->x - v2->x);
+ longest2 = (((v3->y - v1->y) << 16) / height) * width + (v1->x - v3->x);
+
+ if(longest1 < 0) // 2 is right
+ {
+ if(longest2 < 0) // 3 is right
+ {
+ left_array[0] = v4;
+ left_array[1] = v1;
+ left_section = 1;
+
+ height = v3->y - v1->y; if(height == 0) height=1;
+ longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest1 >= 0)
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v3; // 3
+ right_array[2] = v1; // 4
+ right_section = 2;
+ }
+ else
+ {
+ height = v4->y - v2->y; if(height == 0) height=1;
+ longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
+ if(longest1 >= 0)
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v2; // 2
+ right_array[2] = v1; // 4
+ right_section = 2;
+ }
+ else
+ {
+ right_array[0] = v4; // 1
+ right_array[1] = v3; // 2
+ right_array[2] = v2; // 3
+ right_array[3] = v1; // 4
+ right_section = 3;
+ }
+ }
+ }
+ else
+ {
+ left_array[0] = v4;
+ left_array[1] = v3; // 1
+ left_array[2] = v1; // 2
+ left_section = 2; // 3
+ right_array[0] = v4; // 4
+ right_array[1] = v2;
+ right_array[2] = v1;
+ right_section = 2;
+ }
+ }
+ else
+ {
+ if(longest2 < 0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v2; // 2
+ left_array[2] = v1; // 3
+ left_section = 2; // 4
+ right_array[0] = v4;
+ right_array[1] = v3;
+ right_array[2] = v1;
+ right_section = 2;
+ }
+ else
+ {
+ right_array[0] = v4;
+ right_array[1] = v1;
+ right_section = 1;
+
+ height = v3->y - v1->y; if(height == 0) height=1;
+ longest1 = (((v2->y - v1->y) << 16) / height) * ((v3->x - v1->x)>>16) + (v1->x - v2->x);
+ if(longest1<0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v3; // 3
+ left_array[2] = v1; // 4
+ left_section = 2;
+ }
+ else
+ {
+ height = v4->y - v2->y; if(height == 0) height=1;
+ longest1 = (((v3->y - v2->y) << 16) / height) * ((v4->x - v2->x)>>16) + (v2->x - v3->x);
+ if(longest1<0)
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v2; // 2
+ left_array[2] = v1; // 4
+ left_section = 2;
+ }
+ else
+ {
+ left_array[0] = v4; // 1
+ left_array[1] = v3; // 2
+ left_array[2] = v2; // 3
+ left_array[3] = v1; // 4
+ left_section = 3;
+ }
+ }
+ }
+ }
+
+ while(LeftSection_GT4()<=0)
+ {
+ if(--left_section <= 0) break;
+ }
+
+ while(RightSection_GT4()<=0)
+ {
+ if(--right_section <= 0) break;
+ }
+
+ Ymin=v1->y;
+ Ymax=min(v4->y-1,drawH);
+
+ return TRUE;
+}
+
+////////////////////////////////////////////////////////////////////////
+// POLY FUNCS
+////////////////////////////////////////////////////////////////////////
+
+////////////////////////////////////////////////////////////////////////
+// POLY 3/4 FLAT SHADED
+////////////////////////////////////////////////////////////////////////
+
+static __inline void drawPoly3Fi(short x1, short y1, short x2, short y2, short x3, short y3, int rgb)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ unsigned short color;
+ uint32_t lcolor;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_F(x1,y1,x2,y2,x3,y3)) return;
+
+ ymax=Ymax;
+
+ color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
+ lcolor=lSetMask|(((uint32_t)(color))<<16)|color;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_F()) return;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ color |=sSetMask;
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
+ xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ *((uint32_t *)&psxVuw[(i<<10)+j])=lcolor;
+ }
+ if(j==xmax) psxVuw[(i<<10)+j]=color;
+
+ if(NextRow_F()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
+ xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10)+j], lcolor);
+ }
+ if(j == xmax)
+ GetShadeTransCol(&psxVuw[(i << 10) + j],color);
+
+ if(NextRow_F()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void drawPoly3F(int rgb)
+{
+ drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
+}
+
+#ifdef POLYQUAD3FS
+
+void drawPoly4F_TRI(int rgb)
+{
+ drawPoly3Fi(lx1,ly1,lx3,ly3,lx2,ly2,rgb);
+ drawPoly3Fi(lx0,ly0,lx1,ly1,lx2,ly2,rgb);
+}
+
+#endif
+
+// more exact:
+
+void drawPoly4F(int rgb)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ unsigned short color;unsigned int lcolor;
+
+ if(lx0>drawW && lx1>drawW && lx2>drawW && lx3>drawW) return;
+ if(ly0>drawH && ly1>drawH && ly2>drawH && ly3>drawH) return;
+ if(lx0<drawX && lx1<drawX && lx2<drawX && lx3<drawX) return;
+ if(ly0<drawY && ly1<drawY && ly2<drawY && ly3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_F4(lx0,ly0,lx1,ly1,lx2,ly2,lx3,ly3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_F4()) return;
+
+ color = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
+ lcolor= lSetMask|(((uint32_t)(color))<<16)|color;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ color |=sSetMask;
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=left_x >> 16; if(drawX>xmin) xmin=drawX;
+ xmax=(right_x >> 16)-1; if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ *((uint32_t *)&psxVuw[(i<<10)+j])=lcolor;
+ }
+ if(j==xmax) psxVuw[(i<<10)+j]=color;
+
+ if(NextRow_F4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i = ymin; i <= ymax; i++)
+ {
+ xmin = left_x >> 16; if(drawX > xmin) xmin = drawX;
+ xmax = (right_x >> 16) - 1; if(drawW < xmax) xmax = drawW;
+
+ for(j = xmin; j < xmax; j += 2)
+ {
+ GetShadeTransCol32((uint32_t *)&psxVuw[(i<<10) + j],lcolor);
+ }
+ if(j == xmax) GetShadeTransCol(&psxVuw[(i<<10) + j],color);
+
+ if(NextRow_F4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// POLY 3/4 F-SHADED TEX PAL 4
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TEx4(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,XAdjust;
+ int clutP;
+ short tC1,tC2;
+
+ if (x1 > drawW && x2 > drawW && x3 > drawW) return;
+ if (y1 > drawH && y2 > drawH && y3 > drawH) return;
+ if (x1 < drawX && x2 < drawX && x3 < drawX) return;
+ if (y1 < drawY && y2 < drawY && y3 < drawY) return;
+ if (drawY >= drawH) return;
+ if (drawX >= drawW) return;
+
+ if (!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax = Ymax;
+
+ for (ymin = Ymin; ymin < drawY; ymin++)
+ if (NextRow_FT()) return;
+
+ clutP = (clY << 10) + clX;
+
+ YAdjust = ((GlobalTextAddrY) << 11) + (GlobalTextAddrX << 1);
+
+ difX = delta_right_u; difX2 = difX << 1;
+ difY = delta_right_v; difY2 = difY << 1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16);
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16);
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
+{
+ int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,XAdjust;
+ int clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1;
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ XAdjust=((posX+difX)>>16);
+
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ XAdjust=((posX+difX)>>16);
+
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,XAdjust;
+ int clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
+ if(xmax>xmin) xmax--;
+
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16)%TWin.Position.x1;
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16)%TWin.Position.x1;
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+#ifdef POLYQUAD3
+
+static void drawPoly4TEx4_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ drawPoly3TEx4(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY);
+ drawPoly3TEx4(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY);
+}
+
+#endif
+
+// more exact:
+
+static void drawPoly4TEx4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP,XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16);
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16);
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP,XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<10)+GlobalTextAddrX;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ XAdjust=((posX+difX)>>16);
+
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ XAdjust=((posX+difX)>>16);
+
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP,XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16)%TWin.Position.x1;
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16)%TWin.Position.x1;
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TEx4_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP,XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16)%TWin.Position.x1;
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16)%TWin.Position.x1;
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+////////////////////////////////////////////////////////////////////////
+// POLY 3 F-SHADED TEX PAL 8
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TEx8(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ ((posX+difX)>>16)];
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+
+ if(j==xmax)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ ((posX+difX)>>16)];
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+
+ if(j==xmax)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
+{
+ int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ TXU=(posX+difX)>>16;
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+
+ if(j==xmax)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ TXU=(posX+difX)>>16;
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+
+ if(j==xmax)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3,short clX, short clY)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);//-1; //!!!!!!!!!!!!!!!!
+ if(xmax>xmin) xmax--;
+
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+
+ if(j==xmax)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+
+ if(j==xmax)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+#ifdef POLYQUAD3
+
+static void drawPoly4TEx8_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ drawPoly3TEx8(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY);
+
+ drawPoly3TEx8(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY);
+}
+
+#endif
+
+// more exact:
+
+static void drawPoly4TEx8(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ ((posX+difX)>>16)];
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ ((posX+difX)>>16)];
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ TXU=(posX+difX)>>16;
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ TXU=(posX+difX)>>16;
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i, j, xmin, xmax, ymin, ymax;
+ int difX, difY, difX2, difY2;
+ int posX, posY, YAdjust, clutP;
+ short tC1, tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX += difX2;
+ posY += difY2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ GetTextureTransColG(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TEx8_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,short clX, short clY)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
+ GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16);
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],psxVuw[clutP+tC1]);
+ }
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// POLY 3 F-SHADED TEX 15 BIT
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TD(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY,difX2, difY2;
+ int posX,posY;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT()) return;
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY,difX2, difY2;
+ int posX,posY;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT()) return;
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+ }
+ if(NextRow_FT())
+ {
+ return;
+ }
+ }
+}
+
+
+////////////////////////////////////////////////////////////////////////
+
+#ifdef POLYQUAD3
+
+static void drawPoly4TD_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
+{
+ drawPoly3TD(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4);
+ drawPoly3TD(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4);
+}
+
+#endif
+
+// more exact:
+
+static void drawPoly4TD(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX,posY;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX]);
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX,posY;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY)<<10)+TWin.Position.y0+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TD_TW_S(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int difX, difY, difX2, difY2;
+ int posX, posY;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_FT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_FT4()) return;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY)<<10)+TWin.Position.y0+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG_S(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+ }
+ if(NextRow_FT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+
+ posX+=difX2;
+ posY+=difY2;
+ }
+ if(j==xmax)
+ GetTextureTransColG_SPR(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0]);
+ }
+ if(NextRow_FT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// POLY 3/4 G-SHADED
+////////////////////////////////////////////////////////////////////////
+
+static __inline void drawPoly3Gi(short x1,short y1,short x2,short y2,short x3,short y3, int rgb1, int rgb2, int rgb3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_G(x1,y1,x2,y2,x3,y3,rgb1,rgb2,rgb3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_G()) return;
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && iDither!=2)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ *((uint32_t *)&psxVuw[(i<<10)+j])=
+ ((((cR1+difR) <<7)&0x7c000000)|(((cG1+difG) << 2)&0x03e00000)|(((cB1+difB)>>3)&0x001f0000)|
+ (((cR1) >> 9)&0x7c00)|(((cG1) >> 14)&0x03e0)|(((cB1) >> 19)&0x001f))|lSetMask;
+
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ psxVuw[(i<<10)+j]=(((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f))|sSetMask;
+ }
+ if(NextRow_G()) return;
+ }
+ return;
+ }
+
+#endif
+
+ if(iDither==2)
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ GetShadeTransCol_Dither(&psxVuw[(i<<10)+j],(cB1>>16),(cG1>>16),(cR1>>16));
+
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_G()) return;
+ }
+ else
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1;if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ GetShadeTransCol(&psxVuw[(i<<10)+j],((cR1 >> 9)&0x7c00)|((cG1 >> 14)&0x03e0)|((cB1 >> 19)&0x001f));
+
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_G()) return;
+ }
+
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void drawPoly3G(int rgb1, int rgb2, int rgb3)
+{
+ drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,rgb1,rgb2,rgb3);
+}
+
+// draw two g-shaded tris for right psx shading emulation
+
+void drawPoly4G(int rgb1, int rgb2, int rgb3, int rgb4)
+{
+ drawPoly3Gi(lx1,ly1,lx3,ly3,lx2,ly2,
+ rgb2,rgb4,rgb3);
+ drawPoly3Gi(lx0,ly0,lx1,ly1,lx2,ly2,
+ rgb1,rgb2,rgb3);
+}
+
+////////////////////////////////////////////////////////////////////////
+// POLY 3/4 G-SHADED TEX PAL4
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGEx4(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int col1, int col2, int col3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP,XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=((left_x) >> 16);
+ xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16);
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGEx4_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY,int col1, int col2, int col3)
+{
+ int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP,XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=((left_x) >> 16);
+ xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ XAdjust=((posX+difX)>>16);
+
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ XAdjust=(posX>>16);
+
+ TXV=posY>>16;
+ n_xi = ( ( XAdjust >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( XAdjust >> 4 ) & 0xf );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((XAdjust & 0x03)<<2)) & 0x0f ;
+
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
+{
+ int i, j, xmin, xmax, ymin, ymax;
+ int cR1, cG1, cB1;
+ int difR, difB, difG, difR2, difB2, difG2;
+ int difX, difY,difX2, difY2;
+ int posX, posY, YAdjust, clutP, XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0>>1);
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=((left_x) >> 16);
+ xmax=((right_x) >> 16)-1; //!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16)%TWin.Position.x1;
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ XAdjust=(posX>>16)%TWin.Position.x1;
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+// note: the psx is doing g-shaded quads as two g-shaded tris,
+// like the following func... sadly texturing is not 100%
+// correct that way, so small texture distortions can
+// happen...
+
+static void drawPoly4TGEx4_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGEx4_IL(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY,
+ col2,col4,col3);
+ drawPoly3TGEx4_IL(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY,
+ col1,col2,col3);
+}
+
+#ifdef POLYQUAD3GT
+
+static void drawPoly4TGEx4_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGEx4(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY,
+ col2,col4,col3);
+ drawPoly3TGEx4(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY,
+ col1,col2,col3);
+}
+
+#endif
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TGEx4(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col4, int col3)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP,XAdjust;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+ difR=(right_R-cR1)/num;
+ difG=(right_G-cG1)/num;
+ difB=(right_B-cB1)/num;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ XAdjust=((posX+difX)>>16);
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC2=(tC2>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+ difR=(right_R-cR1)/num;
+ difG=(right_G-cG1)/num;
+ difB=(right_B-cB1)/num;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ XAdjust=(posX>>16);
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+
+ (XAdjust>>1)];
+ tC1=(tC1>>((XAdjust&1)<<2))&0xf;
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TGEx4_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGEx4_TW(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY,
+ col2,col4,col3);
+
+ drawPoly3TGEx4_TW(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY,
+ col1,col2,col3);
+}
+
+////////////////////////////////////////////////////////////////////////
+// POLY 3/4 G-SHADED TEX PAL8
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGEx8(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+((posX>>16))];
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ (((posX+difX)>>16))];
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+((posX>>16))];
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+((posX>>16))];
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGEx8_IL(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
+{
+ int i,j,xmin,xmax,ymin,ymax,n_xi,n_yi,TXV,TXU;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=(GlobalTextAddrY<<10)+GlobalTextAddrX;
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ TXU=(posX+difX)>>16;
+ TXV=(posY+difY)>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC2= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ TXU=posX>>16;
+ TXV=posY>>16;
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ tC1= (psxVuw[(n_yi<<10)+YAdjust+n_xi] >> ((TXU & 0x01)<<3)) & 0xff;
+
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short clX, short clY, int col1, int col2, int col3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY,difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+ YAdjust+=(TWin.Position.y0<<11)+(TWin.Position.x0);
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; // !!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ tC2 = psxVub[((((posY+difY)>>16)%TWin.Position.y1)<<11)+
+ YAdjust+(((posX+difX)>>16)%TWin.Position.x1)];
+
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ tC1 = psxVub[(((posY>>16)%TWin.Position.y1)<<11)+
+ YAdjust+((posX>>16)%TWin.Position.x1)];
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+// note: two g-shaded tris: small texture distortions can happen
+
+static void drawPoly4TGEx8_TRI_IL(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGEx8_IL(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY,
+ col2,col4,col3);
+ drawPoly3TGEx8_IL(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY,
+ col1,col2,col3);
+}
+
+#ifdef POLYQUAD3GT
+
+static void drawPoly4TGEx8_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGEx8(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY,
+ col2,col4,col3);
+ drawPoly3TGEx8(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY,
+ col1,col2,col3);
+}
+
+#endif
+
+static void drawPoly4TGEx8(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col4, int col3)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY, difX2, difY2;
+ int posX,posY,YAdjust,clutP;
+ short tC1,tC2;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT4()) return;
+
+ clutP=(clY<<10)+clX;
+
+ YAdjust=((GlobalTextAddrY)<<11)+(GlobalTextAddrX<<1);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+ difR=(right_R-cR1)/num;
+ difG=(right_G-cG1)/num;
+ difB=(right_B-cB1)/num;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ tC2 = psxVub[(((posY+difY)>>5)&(int)0xFFFFF800)+YAdjust+
+ ((posX+difX)>>16)];
+
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1]|
+ ((int)psxVuw[clutP+tC2])<<16,
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ }
+ if(NextRow_GT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+ difR=(right_R-cR1)/num;
+ difG=(right_G-cG1)/num;
+ difB=(right_B-cB1)/num;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ tC1 = psxVub[((posY>>5)&(int)0xFFFFF800)+YAdjust+(posX>>16)];
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[clutP+tC1],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TGEx8_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4,
+ short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4,
+ short clX, short clY,
+ int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGEx8_TW(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ clX,clY,
+ col2,col4,col3);
+ drawPoly3TGEx8_TW(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ clX,clY,
+ col1,col2,col3);
+}
+
+////////////////////////////////////////////////////////////////////////
+// POLY 3 G-SHADED TEX 15 BIT
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGD(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, int col1, int col2, int col3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY,difX2, difY2;
+ int posX,posY;
+
+ if(x1>drawW && x2>drawW && x3>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax=Ymax;
+
+ for(ymin=Ymin;ymin<drawY;ymin++)
+ if(NextRow_GT()) return;
+
+ difR=delta_right_R;
+ difG=delta_right_G;
+ difB=delta_right_B;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+ difX=delta_right_u;difX2=difX<<1;
+ difY=delta_right_v;difY2=difY<<1;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX],
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly3TGD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, int col1, int col2, int col3)
+{
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY,difX2, difY2;
+ int posX,posY;
+
+ if (x1>drawW && x2>drawW && x3>drawW) return;
+ if (y1>drawH && y2>drawH && y3>drawH) return;
+ if (x1<drawX && x2<drawX && x3<drawX) return;
+ if (y1<drawY && y2<drawY && y3<drawY) return;
+ if (drawY >= drawH) return;
+ if (drawX >= drawW) return;
+
+ if (!SetupSections_GT(x1,y1,x2,y2,x3,y3,tx1,ty1,tx2,ty2,tx3,ty3,col1,col2,col3)) return;
+
+ ymax = Ymax;
+
+ for(ymin = Ymin; ymin < drawY; ymin++)
+ if(NextRow_GT()) return;
+
+ difR = delta_right_R;
+ difG = delta_right_G;
+ difB = delta_right_B;
+ difR2 = difR<<1;
+ difG2 = difG<<1;
+ difB2 = difB<<1;
+ difX = delta_right_u; difX2 = difX<<1;
+ difY = delta_right_v; difY2 = difY<<1;
+
+#ifdef FASTSOLID
+
+ if (!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i = ymin; i <= ymax; i++)
+ {
+ xmin = (left_x >> 16);
+ xmax = (right_x >> 16) - 1; //!!!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[(((((posY+difY)>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX+difX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0])<<16)|
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ (((posX)>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16)-1; //!!!!!!!!!!!!!!!!!!
+ if(drawW<xmax) xmax=drawW;
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ if(iDither)
+ GetTextureTransColGX_Dither(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[((((posY>>16)%TWin.Position.y1)+GlobalTextAddrY+TWin.Position.y0)<<10)+
+ ((posX>>16)%TWin.Position.x1)+GlobalTextAddrX+TWin.Position.x0],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT())
+ {
+ return;
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+// note: two g-shaded tris: small texture distortions can happen
+
+#ifdef POLYQUAD3GT
+
+static void drawPoly4TGD_TRI(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGD(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ col2,col4,col3);
+ drawPoly3TGD(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ col1,col2,col3);
+}
+
+#endif
+
+static void drawPoly4TGD(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int col1, int col2, int col4, int col3)
+{
+ int num;
+ int i,j,xmin,xmax,ymin,ymax;
+ int cR1,cG1,cB1;
+ int difR,difB,difG,difR2,difB2,difG2;
+ int difX, difY, difX2, difY2;
+ int posX,posY;
+
+ if(x1>drawW && x2>drawW && x3>drawW && x4>drawW) return;
+ if(y1>drawH && y2>drawH && y3>drawH && y4>drawH) return;
+ if(x1<drawX && x2<drawX && x3<drawX && x4<drawX) return;
+ if(y1<drawY && y2<drawY && y3<drawY && y4<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ if(!SetupSections_GT4(x1,y1,x2,y2,x3,y3,x4,y4,tx1,ty1,tx2,ty2,tx3,ty3,tx4,ty4,col1,col2,col3,col4)) return;
+
+ ymax = Ymax;
+
+ for (ymin = Ymin; ymin < drawY; ymin++)
+ if (NextRow_GT4()) return;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans && !iDither)
+ {
+ for (i = ymin; i <= ymax; i++)
+ {
+ xmin = (left_x >> 16);
+ xmax = (right_x >> 16);
+
+ if(xmax >= xmin)
+ {
+ posX = left_u;
+ posY = left_v;
+
+ num = (xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+ difR=(right_R-cR1)/num;
+ difG=(right_G-cG1)/num;
+ difB=(right_B-cB1)/num;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<xmax;j+=2)
+ {
+ GetTextureTransColGX32_S((uint32_t *)&psxVuw[(i<<10)+j],
+ (((int)psxVuw[((((posY+difY)>>16)+GlobalTextAddrY)<<10)+((posX+difX)>>16)+GlobalTextAddrX])<<16)|
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+((posX)>>16)+GlobalTextAddrX],
+ (cB1>>16)|((cB1+difB)&0xff0000),
+ (cG1>>16)|((cG1+difG)&0xff0000),
+ (cR1>>16)|((cR1+difR)&0xff0000));
+ posX+=difX2;
+ posY+=difY2;
+ cR1+=difR2;
+ cG1+=difG2;
+ cB1+=difB2;
+ }
+ if(j==xmax)
+ GetTextureTransColGX_S(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ }
+ if(NextRow_GT4()) return;
+ }
+ return;
+ }
+
+#endif
+
+ for (i=ymin;i<=ymax;i++)
+ {
+ xmin=(left_x >> 16);
+ xmax=(right_x >> 16);
+
+ if(xmax>=xmin)
+ {
+ posX=left_u;
+ posY=left_v;
+
+ num=(xmax-xmin);
+ if(num==0) num=1;
+ difX=(right_u-posX)/num;
+ difY=(right_v-posY)/num;
+ difX2=difX<<1;
+ difY2=difY<<1;
+
+ cR1=left_R;
+ cG1=left_G;
+ cB1=left_B;
+ difR=(right_R-cR1)/num;
+ difG=(right_G-cG1)/num;
+ difB=(right_B-cB1)/num;
+ difR2=difR<<1;
+ difG2=difG<<1;
+ difB2=difB<<1;
+
+ if(xmin<drawX)
+ {j=drawX-xmin;xmin=drawX;posX+=j*difX;posY+=j*difY;cR1+=j*difR;cG1+=j*difG;cB1+=j*difB;}
+ xmax--;if(drawW<xmax) xmax=drawW;
+
+ for(j=xmin;j<=xmax;j++)
+ {
+ if(iDither)
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ else
+ GetTextureTransColGX(&psxVuw[(i<<10)+j],
+ psxVuw[(((posY>>16)+GlobalTextAddrY)<<10)+(posX>>16)+GlobalTextAddrX],
+ (cB1>>16),(cG1>>16),(cR1>>16));
+ posX+=difX;
+ posY+=difY;
+ cR1+=difR;
+ cG1+=difG;
+ cB1+=difB;
+ }
+ }
+ if(NextRow_GT4()) return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void drawPoly4TGD_TW(short x1, short y1, short x2, short y2, short x3, short y3, short x4, short y4, short tx1, short ty1, short tx2, short ty2, short tx3, short ty3, short tx4, short ty4, int col1, int col2, int col3, int col4)
+{
+ drawPoly3TGD_TW(x2,y2,x3,y3,x4,y4,
+ tx2,ty2,tx3,ty3,tx4,ty4,
+ col2,col4,col3);
+ drawPoly3TGD_TW(x1,y1,x2,y2,x4,y4,
+ tx1,ty1,tx2,ty2,tx4,ty4,
+ col1,col2,col3);
+}
+
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
+
+
+/*
+// no real rect test, but it does its job the way I need it
+__inline BOOL IsNoRect(void)
+{
+ if(lx0==lx1 && lx2==lx3) return FALSE;
+ if(lx0==lx2 && lx1==lx3) return FALSE;
+ if(lx0==lx3 && lx1==lx2) return FALSE;
+ return TRUE;
+}
+*/
+
+// real rect test
+static __inline BOOL IsNoRect(void)
+{
+ //if(!(dwActFixes&0x200)) return FALSE;
+
+ if(ly0==ly1)
+ {
+ if(lx1==lx3 && ly3==ly2 && lx2==lx0) return FALSE;
+ if(lx1==lx2 && ly2==ly3 && lx3==lx0) return FALSE;
+ return TRUE;
+ }
+
+ if(ly0==ly2)
+ {
+ if(lx2==lx3 && ly3==ly1 && lx1==lx0) return FALSE;
+ if(lx2==lx1 && ly1==ly3 && lx3==lx0) return FALSE;
+ return TRUE;
+ }
+
+ if(ly0==ly3)
+ {
+ if(lx3==lx2 && ly2==ly1 && lx1==lx0) return FALSE;
+ if(lx3==lx1 && ly1==ly2 && lx2==lx0) return FALSE;
+ return TRUE;
+ }
+ return TRUE;
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void drawPoly3FT(unsigned char *baseAddr)
+{
+ uint32_t *gpuData = ((uint32_t *) baseAddr);
+
+ if(GlobalTextIL && GlobalTextTP<2)
+ {
+ if(GlobalTextTP==0)
+ drawPoly3TEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ else
+ drawPoly3TEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ }
+
+ if(!bUsingTWin)// && !(dwActFixes&0x100))
+ {
+ switch(GlobalTextTP) // depending on texture mode
+ {
+ case 0:
+ drawPoly3TEx4(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 1:
+ drawPoly3TEx8(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 2:
+ drawPoly3TD(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
+ return;
+ }
+ return;
+ }
+
+ switch(GlobalTextTP) // depending on texture mode
+ {
+ case 0:
+ drawPoly3TEx4_TW(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 1:
+ drawPoly3TEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 2:
+ drawPoly3TD_TW(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void drawPoly4FT(unsigned char *baseAddr)
+{
+ uint32_t *gpuData = ((uint32_t *) baseAddr);
+
+ if(GlobalTextIL && GlobalTextTP<2)
+ {
+ if(GlobalTextTP==0)
+ drawPoly4TEx4_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ else
+ drawPoly4TEx8_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ }
+
+ if(!bUsingTWin)
+ {
+#ifdef POLYQUAD3GT
+ if(IsNoRect())
+ {
+ switch (GlobalTextTP)
+ {
+ case 0:
+ drawPoly4TEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 1:
+ drawPoly4TEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 2:
+ drawPoly4TD_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
+ return;
+ }
+ return;
+ }
+#endif
+
+ switch (GlobalTextTP)
+ {
+ case 0: // grandia investigations needed
+ drawPoly4TEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 1:
+ drawPoly4TEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 2:
+ drawPoly4TD(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
+ return;
+ }
+ return;
+ }
+
+ switch (GlobalTextTP)
+ {
+ case 0:
+ drawPoly4TEx4_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 1:
+ drawPoly4TEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff), ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 2:
+ drawPoly4TD_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[4] & 0x000000ff), ((gpuData[4]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),(gpuData[6] & 0x000000ff), ((gpuData[6]>>8) & 0x000000ff));
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void drawPoly3GT(unsigned char * baseAddr)
+{
+ uint32_t *gpuData = ((uint32_t *) baseAddr);
+
+ if(GlobalTextIL && GlobalTextTP<2)
+ {
+ if(GlobalTextTP==0)
+ drawPoly3TGEx4_IL(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6]);
+ else
+ drawPoly3TGEx8_IL(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6]);
+ return;
+ }
+
+ if(!bUsingTWin)
+ {
+ switch (GlobalTextTP)
+ {
+ case 0:
+ drawPoly3TGEx4(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6]);
+ return;
+ case 1:
+ drawPoly3TGEx8(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6]);
+ return;
+ case 2:
+ drawPoly3TGD(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6]);
+ return;
+ }
+ return;
+ }
+
+ switch(GlobalTextTP)
+ {
+ case 0:
+ drawPoly3TGEx4_TW(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6]);
+ return;
+ case 1:
+ drawPoly3TGEx8_TW(lx0,ly0,lx1,ly1,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6]);
+ return;
+ case 2:
+ drawPoly3TGD_TW(lx0,ly0,lx1,ly1,lx2,ly2,(gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6]);
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void drawPoly4GT(unsigned char *baseAddr)
+{
+ uint32_t *gpuData = ((uint32_t *) baseAddr);
+
+ if(GlobalTextIL && GlobalTextTP<2)
+ {
+ if(GlobalTextTP==0)
+ drawPoly4TGEx4_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ else
+ drawPoly4TGEx8_TRI_IL(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ }
+
+ if(!bUsingTWin)
+ {
+#ifdef POLYQUAD3GT
+ if(IsNoRect())
+ {
+ switch (GlobalTextTP)
+ {
+ case 0:
+ drawPoly4TGEx4_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+
+ return;
+ case 1:
+ drawPoly4TGEx8_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ case 2:
+ drawPoly4TGD_TRI(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff),((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ }
+ return;
+ }
+#endif
+
+ switch (GlobalTextTP)
+ {
+ case 0:
+ drawPoly4TGEx4(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+
+ return;
+ case 1:
+ drawPoly4TGEx8(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ case 2:
+ drawPoly4TGD(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff),((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ }
+ return;
+ }
+
+ switch (GlobalTextTP)
+ {
+ case 0:
+ drawPoly4TGEx4_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ case 1:
+ drawPoly4TGEx8_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,
+ (gpuData[2] & 0x000000ff), ((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),
+ ((gpuData[2]>>12) & 0x3f0),((gpuData[2]>>22) & iGPUHeightMask),
+ gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ case 2:
+ drawPoly4TGD_TW(lx0,ly0,lx1,ly1,lx3,ly3,lx2,ly2,(gpuData[2] & 0x000000ff),((gpuData[2]>>8) & 0x000000ff), (gpuData[5] & 0x000000ff), ((gpuData[5]>>8) & 0x000000ff),(gpuData[11] & 0x000000ff), ((gpuData[11]>>8) & 0x000000ff),(gpuData[8] & 0x000000ff), ((gpuData[8]>>8) & 0x000000ff),gpuData[0],gpuData[3],gpuData[6],gpuData[9]);
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// SPRITE FUNCS
+////////////////////////////////////////////////////////////////////////
+
+void DrawSoftwareSpriteTWin(unsigned char * baseAddr, int w, int h)
+{
+ uint32_t *gpuData = (uint32_t *)baseAddr;
+ short sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3;
+ short tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3;
+
+ sx0=lx0;
+ sy0=ly0;
+
+ sx0=sx3=sx0+PSXDisplay.DrawOffset.x;
+ sx1=sx2=sx0+w;
+ sy0=sy1=sy0+PSXDisplay.DrawOffset.y;
+ sy2=sy3=sy0+h;
+
+ tx0=tx3=gpuData[2]&0xff;
+ tx1=tx2=tx0+w;
+ ty0=ty1=(gpuData[2]>>8)&0xff;
+ ty2=ty3=ty0+h;
+
+ switch (GlobalTextTP)
+ {
+ case 0:
+ drawPoly4TEx4_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
+ tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 1:
+ drawPoly4TEx8_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
+ tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3,
+ ((gpuData[2]>>12) & 0x3f0), ((gpuData[2]>>22) & iGPUHeightMask));
+ return;
+ case 2:
+ drawPoly4TD_TW_S(sx0,sy0,sx1,sy1,sx2,sy2,sx3,sy3,
+ tx0,ty0,tx1,ty1,tx2,ty2,tx3,ty3);
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void DrawSoftwareSpriteMirror(unsigned char * baseAddr, int w, int h)
+{
+ int sprtY,sprtX,sprtW,sprtH,lXDir,lYDir;
+ int clutY0,clutX0,clutP,textX0,textY0,sprtYa,sprCY,sprCX,sprA;
+ short tC;
+ uint32_t *gpuData = (uint32_t *)baseAddr;
+ sprtY = ly0;
+ sprtX = lx0;
+ sprtH = h;
+ sprtW = w;
+ clutY0 = (gpuData[2]>>22) & iGPUHeightMask;
+ clutX0 = (gpuData[2]>>12) & 0x3f0;
+ clutP = (clutY0<<11) + (clutX0<<1);
+ textY0 = ((gpuData[2]>>8) & 0x000000ff) + GlobalTextAddrY;
+ textX0 = (gpuData[2] & 0x000000ff);
+
+ sprtX+=PSXDisplay.DrawOffset.x;
+ sprtY+=PSXDisplay.DrawOffset.y;
+
+// while (sprtX>1023) sprtX-=1024;
+// while (sprtY>MAXYLINESMIN1) sprtY-=MAXYLINES;
+
+ if(sprtX>drawW)
+ {
+// if((sprtX+sprtW)>1023) sprtX-=1024;
+// else return;
+ return;
+ }
+
+ if(sprtY>drawH)
+ {
+// if ((sprtY+sprtH)>MAXYLINESMIN1) sprtY-=MAXYLINES;
+// else return;
+ return;
+ }
+
+ if(sprtY<drawY)
+ {
+ if((sprtY+sprtH)<drawY) return;
+ sprtH-=(drawY-sprtY);
+ textY0+=(drawY-sprtY);
+ sprtY=drawY;
+ }
+
+ if(sprtX<drawX)
+ {
+ if((sprtX+sprtW)<drawX) return;
+ sprtW-=(drawX-sprtX);
+ textX0+=(drawX-sprtX);
+ sprtX=drawX;
+ }
+
+ if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
+ if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
+
+ if(usMirror&0x1000) lXDir=-1; else lXDir=1;
+ if(usMirror&0x2000) lYDir=-1; else lYDir=1;
+
+ switch (GlobalTextTP)
+ {
+ case 0: // texture is 4-bit
+
+ sprtW=sprtW/2;
+ textX0=(GlobalTextAddrX<<1)+(textX0>>1);
+ sprtYa=(sprtY<<10);
+ clutP=(clutY0<<10)+clutX0;
+ for (sprCY=0;sprCY<sprtH;sprCY++)
+ for (sprCX=0;sprCX<sprtW;sprCX++)
+ {
+ tC= psxVub[((textY0+(sprCY*lYDir))<<11) + textX0 +(sprCX*lXDir)];
+ sprA=sprtYa+(sprCY<<10)+sprtX + (sprCX<<1);
+ GetTextureTransColG_SPR(&psxVuw[sprA],psxVuw[clutP+((tC>>4)&0xf)]);
+ GetTextureTransColG_SPR(&psxVuw[sprA+1],psxVuw[clutP+(tC&0xf)]);
+ }
+ return;
+
+ case 1:
+
+ clutP>>=1;
+ for(sprCY=0;sprCY<sprtH;sprCY++)
+ for(sprCX=0;sprCX<sprtW;sprCX++)
+ {
+ tC = psxVub[((textY0+(sprCY*lYDir))<<11)+(GlobalTextAddrX<<1) + textX0 + (sprCX*lXDir)] & 0xff;
+ GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX + sprCX],psxVuw[clutP+tC]);
+ }
+ return;
+
+
+ case 2:
+
+ for (sprCY=0;sprCY<sprtH;sprCY++)
+ for (sprCX=0;sprCX<sprtW;sprCX++)
+ {
+ GetTextureTransColG_SPR(&psxVuw[((sprtY+sprCY)<<10)+sprtX+sprCX],
+ psxVuw[((textY0+(sprCY*lYDir))<<10)+GlobalTextAddrX + textX0 +(sprCX*lXDir)]);
+ }
+ return;
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+
+static void DrawSoftwareSprite_IL(unsigned char * baseAddr,short w,short h,int tx,int ty)
+{
+ int sprtY,sprtX,sprtW,sprtH,tdx,tdy;
+ uint32_t *gpuData = (uint32_t *)baseAddr;
+
+ sprtY = ly0;
+ sprtX = lx0;
+ sprtH = h;
+ sprtW = w;
+
+ sprtX+=PSXDisplay.DrawOffset.x;
+ sprtY+=PSXDisplay.DrawOffset.y;
+
+ if(sprtX>drawW) return;
+ if(sprtY>drawH) return;
+
+ tdx=tx+sprtW;
+ tdy=ty+sprtH;
+
+ sprtW+=sprtX;
+ sprtH+=sprtY;
+
+ // Pete is too lazy to make a faster version ;)
+
+ if(GlobalTextTP==0)
+ drawPoly4TEx4_IL(sprtX,sprtY,sprtX,sprtH,sprtW,sprtH,sprtW,sprtY,
+ tx,ty, tx,tdy, tdx,tdy, tdx,ty,
+ (gpuData[2]>>12) & 0x3f0, ((gpuData[2]>>22) & iGPUHeightMask));
+
+
+ else
+ drawPoly4TEx8_IL(sprtX,sprtY,sprtX,sprtH,sprtW,sprtH,sprtW,sprtY,
+ tx,ty, tx,tdy, tdx,tdy, tdx,ty,
+ (gpuData[2]>>12) & 0x3f0, ((gpuData[2]>>22) & iGPUHeightMask));
+}
+
+////////////////////////////////////////////////////////////////////////
+
+void DrawSoftwareSprite(unsigned char *baseAddr, short w, short h, int tx, int ty)
+{
+ int sprtY, sprtX, sprtW, sprtH;
+ int clutY0, clutX0, clutP, textX0, textY0, sprtYa, sprCY, sprCX, sprA;
+ short tC, tC2;
+ uint32_t *gpuData = (uint32_t *)baseAddr;
+ unsigned char *pV;
+ BOOL bWT,bWS;
+
+ if(GlobalTextIL && GlobalTextTP<2)
+ {DrawSoftwareSprite_IL(baseAddr,w,h,tx,ty);return;}
+
+ sprtY = ly0;
+ sprtX = lx0;
+ sprtH = h;
+ sprtW = w;
+ clutY0 = (gpuData[2]>>22) & iGPUHeightMask;
+ clutX0 = (gpuData[2]>>12) & 0x3f0;
+
+ clutP = (clutY0<<11) + (clutX0<<1);
+
+ textY0 =ty+ GlobalTextAddrY;
+ textX0 =tx;
+
+ sprtX+=PSXDisplay.DrawOffset.x;
+ sprtY+=PSXDisplay.DrawOffset.y;
+
+ //while (sprtX>1023) sprtX-=1024;
+ //while (sprtY>MAXYLINESMIN1) sprtY-=MAXYLINES;
+
+ if(sprtX>drawW)
+ {
+// if((sprtX+sprtW)>1023) sprtX-=1024;
+// else return;
+ return;
+ }
+
+ if(sprtY>drawH)
+ {
+// if ((sprtY+sprtH)>MAXYLINESMIN1) sprtY-=MAXYLINES;
+// else return;
+ return;
+ }
+
+ if(sprtY<drawY)
+ {
+ if((sprtY+sprtH)<drawY) return;
+ sprtH-=(drawY-sprtY);
+ textY0+=(drawY-sprtY);
+ sprtY=drawY;
+ }
+
+ if(sprtX<drawX)
+ {
+ if((sprtX+sprtW)<drawX) return;
+
+ sprtW-=(drawX-sprtX);
+ textX0+=(drawX-sprtX);
+ sprtX=drawX;
+ }
+
+ if((sprtY+sprtH)>drawH) sprtH=drawH-sprtY+1;
+ if((sprtX+sprtW)>drawW) sprtW=drawW-sprtX+1;
+
+
+ bWT=FALSE;
+ bWS=FALSE;
+
+ switch (GlobalTextTP)
+ {
+ case 0:
+
+ if(textX0&1) {bWS=TRUE;sprtW--;}
+ if(sprtW&1) bWT=TRUE;
+
+ sprtW=sprtW>>1;
+ textX0=(GlobalTextAddrX<<1)+(textX0>>1)+(textY0<<11);
+ sprtYa=(sprtY<<10)+sprtX;
+ clutP=(clutY0<<10)+clutX0;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (sprCY=0;sprCY<sprtH;sprCY++)
+ {
+ sprA=sprtYa+(sprCY<<10);
+ pV=&psxVub[(sprCY<<11)+textX0];
+
+ if(bWS)
+ {
+ tC=*pV++;
+ GetTextureTransColG_S(&psxVuw[sprA++],psxVuw[clutP+((tC>>4)&0xf)]);
+ }
+
+ for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
+ {
+ tC=*pV++;
+
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
+ (((int)psxVuw[clutP+((tC>>4)&0xf)])<<16)|
+ psxVuw[clutP+(tC&0x0f)]);
+ }
+
+ if(bWT)
+ {
+ tC=*pV;
+ GetTextureTransColG_S(&psxVuw[sprA],psxVuw[clutP+(tC&0x0f)]);
+ }
+ }
+ return;
+ }
+
+#endif
+
+ for (sprCY=0;sprCY<sprtH;sprCY++)
+ {
+ sprA=sprtYa+(sprCY<<10);
+ pV=&psxVub[(sprCY<<11)+textX0];
+
+ if(bWS)
+ {
+ tC=*pV++;
+ GetTextureTransColG_SPR(&psxVuw[sprA++],psxVuw[clutP+((tC>>4)&0xf)]);
+ }
+
+ for (sprCX=0;sprCX<sprtW;sprCX++,sprA+=2)
+ {
+ tC=*pV++;
+
+ GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
+ (((int)psxVuw[clutP+((tC>>4)&0xf)])<<16)|
+ psxVuw[clutP+(tC&0x0f)]);
+ }
+
+ if(bWT)
+ {
+ tC=*pV;
+ GetTextureTransColG_SPR(&psxVuw[sprA],psxVuw[clutP+(tC&0x0f)]);
+ }
+ }
+ return;
+
+ case 1:
+ clutP>>=1;sprtW--;
+ textX0+=(GlobalTextAddrX<<1) + (textY0<<11);
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for(sprCY=0;sprCY<sprtH;sprCY++)
+ {
+ sprA=((sprtY+sprCY)<<10)+sprtX;
+ pV=&psxVub[(sprCY<<11)+textX0];
+ for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
+ {
+ tC = *pV++;tC2 = *pV++;
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
+ (((int)psxVuw[clutP+tC2])<<16)|
+ psxVuw[clutP+tC]);
+ }
+ if(sprCX==sprtW)
+ GetTextureTransColG_S(&psxVuw[sprA],psxVuw[clutP+(*pV)]);
+ }
+ return;
+ }
+
+#endif
+
+ for(sprCY=0;sprCY<sprtH;sprCY++)
+ {
+ sprA=((sprtY+sprCY)<<10)+sprtX;
+ pV=&psxVub[(sprCY<<11)+textX0];
+ for(sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
+ {
+ tC = *pV++;tC2 = *pV++;
+ GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
+ (((int)psxVuw[clutP+tC2])<<16)|
+ psxVuw[clutP+tC]);
+ }
+ if(sprCX==sprtW)
+ GetTextureTransColG_SPR(&psxVuw[sprA],psxVuw[clutP+(*pV)]);
+ }
+ return;
+
+ case 2:
+
+ textX0+=(GlobalTextAddrX) + (textY0<<10);
+ sprtW--;
+
+#ifdef FASTSOLID
+
+ if(!bCheckMask && !DrawSemiTrans)
+ {
+ for (sprCY=0;sprCY<sprtH;sprCY++)
+ {
+ sprA=((sprtY+sprCY)<<10)+sprtX;
+
+ for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
+ {
+ GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA],
+ (((int)psxVuw[(sprCY<<10) + textX0 + sprCX +1])<<16)|
+ psxVuw[(sprCY<<10) + textX0 + sprCX]);
+ }
+ if(sprCX==sprtW)
+ GetTextureTransColG_S(&psxVuw[sprA],
+ psxVuw[(sprCY<<10) + textX0 + sprCX]);
+
+ }
+ return;
+ }
+
+#endif
+
+ for (sprCY=0;sprCY<sprtH;sprCY++)
+ {
+ sprA=((sprtY+sprCY)<<10)+sprtX;
+
+ for (sprCX=0;sprCX<sprtW;sprCX+=2,sprA+=2)
+ {
+ GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA],
+ (((int)psxVuw[(sprCY<<10) + textX0 + sprCX +1])<<16)|
+ psxVuw[(sprCY<<10) + textX0 + sprCX]);
+ }
+ if(sprCX==sprtW)
+ GetTextureTransColG_SPR(&psxVuw[sprA],
+ psxVuw[(sprCY<<10) + textX0 + sprCX]);
+
+ }
+ return;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+// LINE FUNCS
+////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////
+
+
+///////////////////////////////////////////////////////////////////////
+
+#if 0
+static void Line_E_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
+{
+ int dx, dy, incrE, incrSE, d;
+ uint32_t r0, g0, b0, r1, g1, b1;
+ int dr, dg, db;
+
+ r0 = (rgb0 & 0x00ff0000);
+ g0 = (rgb0 & 0x0000ff00) << 8;
+ b0 = (rgb0 & 0x000000ff) << 16;
+ r1 = (rgb1 & 0x00ff0000);
+ g1 = (rgb1 & 0x0000ff00) << 8;
+ b1 = (rgb1 & 0x000000ff) << 16;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+
+ if (dx > 0)
+ {
+ dr = ((int)r1 - (int)r0) / dx;
+ dg = ((int)g1 - (int)g0) / dx;
+ db = ((int)b1 - (int)b0) / dx;
+ }
+ else
+ {
+ dr = ((int)r1 - (int)r0);
+ dg = ((int)g1 - (int)g0);
+ db = ((int)b1 - (int)b0);
+ }
+
+ d = 2*dy - dx; /* Initial value of d */
+ incrE = 2*dy; /* incr. used for move to E */
+ incrSE = 2*(dy - dx); /* incr. used for move to SE */
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ while(x0 < x1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrE; /* Choose E */
+ }
+ else
+ {
+ d = d + incrSE; /* Choose SE */
+ y0++;
+ }
+ x0++;
+
+ r0+=dr;
+ g0+=dg;
+ b0+=db;
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void Line_S_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
+{
+ int dx, dy, incrS, incrSE, d;
+ uint32_t r0, g0, b0, r1, g1, b1;
+ int dr, dg, db;
+
+ r0 = (rgb0 & 0x00ff0000);
+ g0 = (rgb0 & 0x0000ff00) << 8;
+ b0 = (rgb0 & 0x000000ff) << 16;
+ r1 = (rgb1 & 0x00ff0000);
+ g1 = (rgb1 & 0x0000ff00) << 8;
+ b1 = (rgb1 & 0x000000ff) << 16;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+
+ if (dy > 0)
+ {
+ dr = ((int)r1 - (int)r0) / dy;
+ dg = ((int)g1 - (int)g0) / dy;
+ db = ((int)b1 - (int)b0) / dy;
+ }
+ else
+ {
+ dr = ((int)r1 - (int)r0);
+ dg = ((int)g1 - (int)g0);
+ db = ((int)b1 - (int)b0);
+ }
+
+ d = 2*dx - dy; /* Initial value of d */
+ incrS = 2*dx; /* incr. used for move to S */
+ incrSE = 2*(dx - dy); /* incr. used for move to SE */
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ while(y0 < y1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrS; /* Choose S */
+ }
+ else
+ {
+ d = d + incrSE; /* Choose SE */
+ x0++;
+ }
+ y0++;
+
+ r0+=dr;
+ g0+=dg;
+ b0+=db;
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void Line_N_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
+{
+ int dx, dy, incrN, incrNE, d;
+ uint32_t r0, g0, b0, r1, g1, b1;
+ int dr, dg, db;
+
+ r0 = (rgb0 & 0x00ff0000);
+ g0 = (rgb0 & 0x0000ff00) << 8;
+ b0 = (rgb0 & 0x000000ff) << 16;
+ r1 = (rgb1 & 0x00ff0000);
+ g1 = (rgb1 & 0x0000ff00) << 8;
+ b1 = (rgb1 & 0x000000ff) << 16;
+
+ dx = x1 - x0;
+ dy = -(y1 - y0);
+
+ if (dy > 0)
+ {
+ dr = ((uint32_t)r1 - (uint32_t)r0) / dy;
+ dg = ((uint32_t)g1 - (uint32_t)g0) / dy;
+ db = ((uint32_t)b1 - (uint32_t)b0) / dy;
+ }
+ else
+ {
+ dr = ((uint32_t)r1 - (uint32_t)r0);
+ dg = ((uint32_t)g1 - (uint32_t)g0);
+ db = ((uint32_t)b1 - (uint32_t)b0);
+ }
+
+ d = 2*dx - dy; /* Initial value of d */
+ incrN = 2*dx; /* incr. used for move to N */
+ incrNE = 2*(dx - dy); /* incr. used for move to NE */
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ while(y0 > y1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrN; /* Choose N */
+ }
+ else
+ {
+ d = d + incrNE; /* Choose NE */
+ x0++;
+ }
+ y0--;
+
+ r0+=dr;
+ g0+=dg;
+ b0+=db;
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void Line_E_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1)
+{
+ int dx, dy, incrE, incrNE, d;
+ uint32_t r0, g0, b0, r1, g1, b1;
+ int dr, dg, db;
+
+ r0 = (rgb0 & 0x00ff0000);
+ g0 = (rgb0 & 0x0000ff00) << 8;
+ b0 = (rgb0 & 0x000000ff) << 16;
+ r1 = (rgb1 & 0x00ff0000);
+ g1 = (rgb1 & 0x0000ff00) << 8;
+ b1 = (rgb1 & 0x000000ff) << 16;
+
+ dx = x1 - x0;
+ dy = -(y1 - y0);
+
+ if (dx > 0)
+ {
+ dr = ((int)r1 - (int)r0) / dx;
+ dg = ((int)g1 - (int)g0) / dx;
+ db = ((int)b1 - (int)b0) / dx;
+ }
+ else
+ {
+ dr = ((int)r1 - (int)r0);
+ dg = ((int)g1 - (int)g0);
+ db = ((int)b1 - (int)b0);
+ }
+
+ d = 2*dy - dx; /* Initial value of d */
+ incrE = 2*dy; /* incr. used for move to E */
+ incrNE = 2*(dy - dx); /* incr. used for move to NE */
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ while(x0 < x1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrE; /* Choose E */
+ }
+ else
+ {
+ d = d + incrNE; /* Choose NE */
+ y0--;
+ }
+ x0++;
+
+ r0+=dr;
+ g0+=dg;
+ b0+=db;
+
+ if ((x0>=drawX)&&(x0<drawW)&&(y0>=drawY)&&(y0<drawH))
+ GetShadeTransCol(&psxVuw[(y0<<10)+x0],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void VertLineShade(int x, int y0, int y1, uint32_t rgb0, uint32_t rgb1)
+{
+ int y, dy;
+ uint32_t r0, g0, b0, r1, g1, b1;
+ int dr, dg, db;
+
+ r0 = (rgb0 & 0x00ff0000);
+ g0 = (rgb0 & 0x0000ff00) << 8;
+ b0 = (rgb0 & 0x000000ff) << 16;
+ r1 = (rgb1 & 0x00ff0000);
+ g1 = (rgb1 & 0x0000ff00) << 8;
+ b1 = (rgb1 & 0x000000ff) << 16;
+
+ dy = (y1 - y0);
+
+ if (dy > 0)
+ {
+ dr = ((int)r1 - (int)r0) / dy;
+ dg = ((int)g1 - (int)g0) / dy;
+ db = ((int)b1 - (int)b0) / dy;
+ }
+ else
+ {
+ dr = ((int)r1 - (int)r0);
+ dg = ((int)g1 - (int)g0);
+ db = ((int)b1 - (int)b0);
+ }
+
+ if (y0 < drawY)
+ {
+ r0+=dr*(drawY - y0);
+ g0+=dg*(drawY - y0);
+ b0+=db*(drawY - y0);
+ y0 = drawY;
+ }
+
+ if (y1 > drawH)
+ y1 = drawH;
+
+ for (y = y0; y <= y1; y++)
+ {
+ GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ r0+=dr;
+ g0+=dg;
+ b0+=db;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void HorzLineShade(int y, int x0, int x1, uint32_t rgb0, uint32_t rgb1)
+{
+ int x, dx;
+ uint32_t r0, g0, b0, r1, g1, b1;
+ int dr, dg, db;
+
+ r0 = (rgb0 & 0x00ff0000);
+ g0 = (rgb0 & 0x0000ff00) << 8;
+ b0 = (rgb0 & 0x000000ff) << 16;
+ r1 = (rgb1 & 0x00ff0000);
+ g1 = (rgb1 & 0x0000ff00) << 8;
+ b1 = (rgb1 & 0x000000ff) << 16;
+
+ dx = (x1 - x0);
+
+ if (dx > 0)
+ {
+ dr = ((int)r1 - (int)r0) / dx;
+ dg = ((int)g1 - (int)g0) / dx;
+ db = ((int)b1 - (int)b0) / dx;
+ }
+ else
+ {
+ dr = ((int)r1 - (int)r0);
+ dg = ((int)g1 - (int)g0);
+ db = ((int)b1 - (int)b0);
+ }
+
+ if (x0 < drawX)
+ {
+ r0+=dr*(drawX - x0);
+ g0+=dg*(drawX - x0);
+ b0+=db*(drawX - x0);
+ x0 = drawX;
+ }
+
+ if (x1 > drawW)
+ x1 = drawW;
+
+ for (x = x0; x <= x1; x++)
+ {
+ GetShadeTransCol(&psxVuw[(y<<10)+x],(unsigned short)(((r0 >> 9)&0x7c00)|((g0 >> 14)&0x03e0)|((b0 >> 19)&0x001f)));
+ r0+=dr;
+ g0+=dg;
+ b0+=db;
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void Line_E_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
+{
+ int dx, dy, incrE, incrSE, d, x, y;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+ d = 2*dy - dx; /* Initial value of d */
+ incrE = 2*dy; /* incr. used for move to E */
+ incrSE = 2*(dy - dx); /* incr. used for move to SE */
+ x = x0;
+ y = y0;
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ while(x < x1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrE; /* Choose E */
+ x++;
+ }
+ else
+ {
+ d = d + incrSE; /* Choose SE */
+ x++;
+ y++;
+ }
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void Line_S_SE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
+{
+ int dx, dy, incrS, incrSE, d, x, y;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+ d = 2*dx - dy; /* Initial value of d */
+ incrS = 2*dx; /* incr. used for move to S */
+ incrSE = 2*(dx - dy); /* incr. used for move to SE */
+ x = x0;
+ y = y0;
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ while(y < y1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrS; /* Choose S */
+ y++;
+ }
+ else
+ {
+ d = d + incrSE; /* Choose SE */
+ x++;
+ y++;
+ }
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void Line_N_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
+{
+ int dx, dy, incrN, incrNE, d, x, y;
+
+ dx = x1 - x0;
+ dy = -(y1 - y0);
+ d = 2*dx - dy; /* Initial value of d */
+ incrN = 2*dx; /* incr. used for move to N */
+ incrNE = 2*(dx - dy); /* incr. used for move to NE */
+ x = x0;
+ y = y0;
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ while(y > y1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrN; /* Choose N */
+ y--;
+ }
+ else
+ {
+ d = d + incrNE; /* Choose NE */
+ x++;
+ y--;
+ }
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void Line_E_NE_Flat(int x0, int y0, int x1, int y1, unsigned short colour)
+{
+ int dx, dy, incrE, incrNE, d, x, y;
+
+ dx = x1 - x0;
+ dy = -(y1 - y0);
+ d = 2*dy - dx; /* Initial value of d */
+ incrE = 2*dy; /* incr. used for move to E */
+ incrNE = 2*(dy - dx); /* incr. used for move to NE */
+ x = x0;
+ y = y0;
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ while(x < x1)
+ {
+ if (d <= 0)
+ {
+ d = d + incrE; /* Choose E */
+ x++;
+ }
+ else
+ {
+ d = d + incrNE; /* Choose NE */
+ x++;
+ y--;
+ }
+ if ((x>=drawX)&&(x<drawW)&&(y>=drawY)&&(y<drawH))
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void VertLineFlat(int x, int y0, int y1, unsigned short colour)
+{
+ int y;
+
+ if (y0 < drawY)
+ y0 = drawY;
+
+ if (y1 > drawH)
+ y1 = drawH;
+
+ for (y = y0; y <= y1; y++)
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void HorzLineFlat(int y, int x0, int x1, unsigned short colour)
+{
+ int x;
+
+ if (x0 < drawX)
+ x0 = drawX;
+
+ if (x1 > drawW)
+ x1 = drawW;
+
+ for (x = x0; x <= x1; x++)
+ GetShadeTransCol(&psxVuw[(y<<10)+x], colour);
+}
+
+///////////////////////////////////////////////////////////////////////
+
+/* Bresenham Line drawing function */
+static void DrawSoftwareLineShade(int rgb0, int rgb1)
+{
+ short x0, y0, x1, y1, xt, yt;
+ int rgbt;
+ double m, dy, dx;
+
+ if(lx0>drawW && lx1>drawW) return;
+ if(ly0>drawH && ly1>drawH) return;
+ if(lx0<drawX && lx1<drawX) return;
+ if(ly0<drawY && ly1<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ x0 = lx0;
+ y0 = ly0;
+ x1 = lx1;
+ y1 = ly1;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+
+ if (dx == 0)
+ {
+ if (dy > 0)
+ VertLineShade(x0, y0, y1, rgb0, rgb1);
+ else
+ VertLineShade(x0, y1, y0, rgb1, rgb0);
+ }
+ else
+ if (dy == 0)
+ {
+ if (dx > 0)
+ HorzLineShade(y0, x0, x1, rgb0, rgb1);
+ else
+ HorzLineShade(y0, x1, x0, rgb1, rgb0);
+ }
+ else
+ {
+ if (dx < 0)
+ {
+ xt = x0;
+ yt = y0;
+ rgbt = rgb0;
+ x0 = x1;
+ y0 = y1;
+ rgb0 = rgb1;
+ x1 = xt;
+ y1 = yt;
+ rgb1 = rgbt;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+ }
+
+ m = dy/dx;
+
+ if (m >= 0)
+ {
+ if (m > 1)
+ Line_S_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
+ else
+ Line_E_SE_Shade(x0, y0, x1, y1, rgb0, rgb1);
+ }
+ else
+ if (m < -1)
+ Line_N_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
+ else
+ Line_E_NE_Shade(x0, y0, x1, y1, rgb0, rgb1);
+ }
+}
+
+///////////////////////////////////////////////////////////////////////
+
+static void DrawSoftwareLineFlat(int rgb)
+{
+ short x0, y0, x1, y1, xt, yt;
+ double m, dy, dx;
+ unsigned short colour = 0;
+
+ if(lx0>drawW && lx1>drawW) return;
+ if(ly0>drawH && ly1>drawH) return;
+ if(lx0<drawX && lx1<drawX) return;
+ if(ly0<drawY && ly1<drawY) return;
+ if(drawY>=drawH) return;
+ if(drawX>=drawW) return;
+
+ colour = ((rgb & 0x00f80000)>>9) | ((rgb & 0x0000f800)>>6) | ((rgb & 0x000000f8)>>3);
+
+ x0 = lx0;
+ y0 = ly0;
+ x1 = lx1;
+ y1 = ly1;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+
+ if (dx == 0)
+ {
+ if (dy == 0)
+ return; // Nothing to draw
+ else if (dy > 0)
+ VertLineFlat(x0, y0, y1, colour);
+ else
+ VertLineFlat(x0, y1, y0, colour);
+ }
+ else
+ if (dy == 0)
+ {
+ if (dx > 0)
+ HorzLineFlat(y0, x0, x1, colour);
+ else
+ HorzLineFlat(y0, x1, x0, colour);
+ }
+ else
+ {
+ if (dx < 0)
+ {
+ xt = x0;
+ yt = y0;
+ x0 = x1;
+ y0 = y1;
+ x1 = xt;
+ y1 = yt;
+
+ dx = x1 - x0;
+ dy = y1 - y0;
+ }
+
+ m = dy/dx;
+
+ if (m >= 0)
+ {
+ if (m > 1)
+ Line_S_SE_Flat(x0, y0, x1, y1, colour);
+ else
+ Line_E_SE_Flat(x0, y0, x1, y1, colour);
+ }
+ else
+ if (m < -1)
+ Line_N_NE_Flat(x0, y0, x1, y1, colour);
+ else
+ Line_E_NE_Flat(x0, y0, x1, y1, colour);
+ }
+}
+#endif
+
+///////////////////////////////////////////////////////////////////////
diff --git a/plugins/peopsxgl/texture.c b/plugins/peopsxgl/texture.c
index c287768f..f247175a 100644
--- a/plugins/peopsxgl/texture.c
+++ b/plugins/peopsxgl/texture.c
@@ -1,62 +1,62 @@
-/***************************************************************************
- texture.c - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
+/***************************************************************************
+ texture.c - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
#include "stdafx.h"
////////////////////////////////////////////////////////////////////////////////////
// Texture related functions are here !
-//
-// The texture handling is heart and soul of this gpu. The plugin was developed
-// 1999, by this time no shaders were available. Since the psx gpu is making
-// heavy use of CLUT (="color lookup tables", aka palettized textures), it was
-// an interesting task to get those emulated at good speed on NV TNT cards
-// (which was my major goal when I created the first "gpuPeteTNT"). Later cards
-// (Geforce256) supported texture palettes by an OGL extension, but at some point
-// this support was dropped again by gfx card vendors.
-// Well, at least there is a certain advatage, if no texture palettes extension can
-// be used: it is possible to modify the textures in any way, allowing "hi-res"
-// textures and other tweaks.
-//
-// My main texture caching is kinda complex: the plugin is allocating "n" 256x256 textures,
-// and it places small psx texture parts inside them. The plugin keeps track what
-// part (with what palette) it had placed in which texture, so it can re-use this
-// part again. The more ogl textures it can use, the better (of course the managing/
-// searching will be slower, but everything is faster than uploading textures again
-// and again to a gfx card). My first card (TNT1) had 16 MB Vram, and it worked
-// well with many games, but I recommend nowadays 64 MB Vram to get a good speed.
-//
-// Sadly, there is also a second kind of texture cache needed, for "psx texture windows".
-// Those are "repeated" textures, so a psx "texture window" needs to be put in
-// a whole texture to use the GL_TEXTURE_WRAP_ features. This cache can get full very
-// fast in games which are having an heavy "texture window" usage, like RRT4. As an
-// alternative, this plugin can use the OGL "palette" extension on texture windows,
-// if available. Nowadays also a fragment shader can easily be used to emulate
-// texture wrapping in a texture atlas, so the main cache could hold the texture
-// windows as well (that's what I am doing in the OGL2 plugin). But currently the
-// OGL1 plugin is a "shader-free" zone, so heavy "texture window" games will cause
-// much texture uploads.
-//
-// Some final advice: take care if you change things in here. I've removed my ASM
-// handlers (they didn't cause much speed gain anyway) for readability/portability,
-// but still the functions/data structures used here are easy to mess up. I guess it
-// can be a pain in the ass to port the plugin to another byte order :)
-//
-////////////////////////////////////////////////////////////////////////////////////
+//
+// The texture handling is heart and soul of this gpu. The plugin was developed
+// 1999, by this time no shaders were available. Since the psx gpu is making
+// heavy use of CLUT (="color lookup tables", aka palettized textures), it was
+// an interesting task to get those emulated at good speed on NV TNT cards
+// (which was my major goal when I created the first "gpuPeteTNT"). Later cards
+// (Geforce256) supported texture palettes by an OGL extension, but at some point
+// this support was dropped again by gfx card vendors.
+// Well, at least there is a certain advatage, if no texture palettes extension can
+// be used: it is possible to modify the textures in any way, allowing "hi-res"
+// textures and other tweaks.
+//
+// My main texture caching is kinda complex: the plugin is allocating "n" 256x256 textures,
+// and it places small psx texture parts inside them. The plugin keeps track what
+// part (with what palette) it had placed in which texture, so it can re-use this
+// part again. The more ogl textures it can use, the better (of course the managing/
+// searching will be slower, but everything is faster than uploading textures again
+// and again to a gfx card). My first card (TNT1) had 16 MB Vram, and it worked
+// well with many games, but I recommend nowadays 64 MB Vram to get a good speed.
+//
+// Sadly, there is also a second kind of texture cache needed, for "psx texture windows".
+// Those are "repeated" textures, so a psx "texture window" needs to be put in
+// a whole texture to use the GL_TEXTURE_WRAP_ features. This cache can get full very
+// fast in games which are having an heavy "texture window" usage, like RRT4. As an
+// alternative, this plugin can use the OGL "palette" extension on texture windows,
+// if available. Nowadays also a fragment shader can easily be used to emulate
+// texture wrapping in a texture atlas, so the main cache could hold the texture
+// windows as well (that's what I am doing in the OGL2 plugin). But currently the
+// OGL1 plugin is a "shader-free" zone, so heavy "texture window" games will cause
+// much texture uploads.
+//
+// Some final advice: take care if you change things in here. I've removed my ASM
+// handlers (they didn't cause much speed gain anyway) for readability/portability,
+// but still the functions/data structures used here are easy to mess up. I guess it
+// can be a pain in the ass to port the plugin to another byte order :)
+//
+////////////////////////////////////////////////////////////////////////////////////
#define _IN_TEXTURE
@@ -80,9 +80,9 @@ GLuint gTexFrameName=0;
int iTexGarbageCollection=1;
uint32_t dwTexPageComp=0;
int iVRamSize=0;
-int iClampType=GL_CLAMP;
+int iClampType=GL_CLAMP;
-void (*LoadSubTexFn) (int,int,short,short);
+void (*LoadSubTexFn) (int,int,short,short);
uint32_t (*PalTexturedColourFn) (uint32_t);
////////////////////////////////////////////////////////////////////////
@@ -111,7 +111,7 @@ uint32_t (*PalTexturedColourFn) (uint32_t);
#define SOFFD 3072
#define MAXWNDTEXCACHE 128
-
+
#define XCHECK(pos1,pos2) ((pos1.c[0]>=pos2.c[1])&&(pos1.c[1]<=pos2.c[0])&&(pos1.c[2]>=pos2.c[3])&&(pos1.c[3]<=pos2.c[2]))
#define INCHECK(pos2,pos1) ((pos1.c[0]<=pos2.c[0]) && (pos1.c[1]>=pos2.c[1]) && (pos1.c[2]<=pos2.c[2]) && (pos1.c[3]>=pos2.c[3]))
@@ -145,13 +145,13 @@ unsigned short (*PTCF[2]) (unsigned short);
////////////////////////////////////////////////////////////////////////
// texture cache implementation
-////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////
-#ifdef _WINDOWS
-#pragma pack(1)
-#endif
-
-// "texture window" cache entry
+#ifdef _WINDOWS
+#pragma pack(1)
+#endif
+
+// "texture window" cache entry
typedef struct textureWndCacheEntryTag
{
@@ -163,8 +163,8 @@ typedef struct textureWndCacheEntryTag
EXLong pos;
GLuint texname;
} textureWndCacheEntry;
-
-// "standard texture" cache entry (12 byte per entry, as small as possible... we need lots of them)
+
+// "standard texture" cache entry (12 byte per entry, as small as possible... we need lots of them)
typedef struct textureSubCacheEntryTagS
{
@@ -175,18 +175,18 @@ typedef struct textureSubCacheEntryTagS
unsigned char cTexID;
unsigned char Opaque;
} textureSubCacheEntryS;
-
-#ifdef _WINDOWS
-#pragma pack()
-#endif
-
-//---------------------------------------------
-
-#define MAXTPAGES_MAX 64
-#define MAXSORTTEX_MAX 196
-
-//---------------------------------------------
-
+
+#ifdef _WINDOWS
+#pragma pack()
+#endif
+
+//---------------------------------------------
+
+#define MAXTPAGES_MAX 64
+#define MAXSORTTEX_MAX 196
+
+//---------------------------------------------
+
textureWndCacheEntry wcWndtexStore[MAXWNDTEXCACHE];
textureSubCacheEntryS * pscSubtexStore[3][MAXTPAGES_MAX];
EXLong * pxSsubtexLeft [MAXSORTTEX_MAX];
@@ -202,14 +202,14 @@ GLubyte * texturepart = NULL;
GLubyte * texturebuffer = NULL;
uint32_t g_x1,g_y1,g_x2,g_y2;
unsigned char ubOpaqueDraw = 0;
-
-unsigned short MAXTPAGES = 32;
-unsigned short CLUTMASK = 0x7fff;
-unsigned short CLUTYMASK = 0x1ff;
-unsigned short MAXSORTTEX = 196;
-
+
+unsigned short MAXTPAGES = 32;
+unsigned short CLUTMASK = 0x7fff;
+unsigned short CLUTYMASK = 0x1ff;
+unsigned short MAXSORTTEX = 196;
+
////////////////////////////////////////////////////////////////////////
-// Texture color conversions... all my ASM funcs are removed for easier
+// Texture color conversions... all my ASM funcs are removed for easier
// porting... and honestly: nowadays the speed gain would be pointless
////////////////////////////////////////////////////////////////////////
@@ -526,7 +526,7 @@ void CheckTextureMemory(void)
glBindTexture(GL_TEXTURE_2D,0);
free(p);
-
+
bDetail=malloc(MAXSORTTEX*sizeof(GLboolean));
memset(bDetail,0,MAXSORTTEX*sizeof(GLboolean));
b=glAreTexturesResident(MAXSORTTEX,uiStexturePage,bDetail);
@@ -537,9 +537,9 @@ void CheckTextureMemory(void)
{
if(bDetail[i]) iCnt++;
uiStexturePage[i]=0;
- }
-
- free(bDetail);
+ }
+
+ free(bDetail);
if(b) iSortTexCnt=MAXSORTTEX-min(1,iHiResTextures);
else iSortTexCnt=iCnt-3+min(1,iHiResTextures); // place for menu&texwnd
@@ -552,24 +552,24 @@ void CheckTextureMemory(void)
////////////////////////////////////////////////////////////////////////
void InitializeTextureStore()
-{
- int i,j;
-
- if(iGPUHeight==1024)
- {
- MAXTPAGES = 64;
- CLUTMASK = 0xffff;
- CLUTYMASK = 0x3ff;
- MAXSORTTEX = 128;
- iTexGarbageCollection=0;
- }
- else
- {
- MAXTPAGES = 32;
- CLUTMASK = 0x7fff;
- CLUTYMASK = 0x1ff;
- MAXSORTTEX = 196;
- }
+{
+ int i,j;
+
+ if(iGPUHeight==1024)
+ {
+ MAXTPAGES = 64;
+ CLUTMASK = 0xffff;
+ CLUTYMASK = 0x3ff;
+ MAXSORTTEX = 128;
+ iTexGarbageCollection=0;
+ }
+ else
+ {
+ MAXTPAGES = 32;
+ CLUTMASK = 0x7fff;
+ CLUTYMASK = 0x1ff;
+ MAXSORTTEX = 196;
+ }
memset(vertex,0,4*sizeof(OGLVertex)); // init vertices
@@ -707,7 +707,7 @@ void ResetTextureArea(BOOL bDelTex)
// Invalidate tex windows
////////////////////////////////////////////////////////////////////////
-void InvalidateWndTextureArea(int X, int Y, int W, int H)
+static void InvalidateWndTextureArea(int X, int Y, int W, int H)
{
int i,px1,px2,py1,py2,iYM=1;
textureWndCacheEntry * tsw=wcWndtexStore;
@@ -715,15 +715,15 @@ void InvalidateWndTextureArea(int X, int Y, int W, int H)
W+=X-1;
H+=Y-1;
if(X<0) X=0;if(X>1023) X=1023;
- if(W<0) W=0;if(W>1023) W=1023;
- if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
- if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
+ if(W<0) W=0;if(W>1023) W=1023;
+ if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
+ if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
W++;H++;
-
- if(iGPUHeight==1024) iYM=3;
-
- py1=min(iYM,Y>>8);
- py2=min(iYM,H>>8); // y: 0 or 1
+
+ if(iGPUHeight==1024) iYM=3;
+
+ py1=min(iYM,Y>>8);
+ py2=min(iYM,H>>8); // y: 0 or 1
px1=max(0,(X>>6));
px2=min(15,(W>>6));
@@ -769,7 +769,7 @@ void InvalidateWndTextureArea(int X, int Y, int W, int H)
// same for sort textures
////////////////////////////////////////////////////////////////////////
-void MarkFree(textureSubCacheEntryS * tsx)
+static void MarkFree(textureSubCacheEntryS * tsx)
{
EXLong * ul, * uls;
int j,iMax;unsigned char x1,y1,dx,dy;
@@ -798,7 +798,7 @@ void MarkFree(textureSubCacheEntryS * tsx)
}
}
-void InvalidateSubSTextureArea(int X, int Y, int W, int H)
+static void InvalidateSubSTextureArea(int X, int Y, int W, int H)
{
int i,j,k,iMax,px,py,px1,px2,py1,py2,iYM = 1;
EXLong npos;
@@ -808,16 +808,16 @@ void InvalidateSubSTextureArea(int X, int Y, int W, int H)
W+=X-1;
H+=Y-1;
if(X<0) X=0;if(X>1023) X=1023;
- if(W<0) W=0;if(W>1023) W=1023;
- if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
- if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
+ if(W<0) W=0;if(W>1023) W=1023;
+ if(Y<0) Y=0;if(Y>iGPUHeightMask) Y=iGPUHeightMask;
+ if(H<0) H=0;if(H>iGPUHeightMask) H=iGPUHeightMask;
W++;H++;
-
- if(iGPUHeight==1024) iYM=3;
- py1=min(iYM,Y>>8);
- py2=min(iYM,H>>8); // y: 0 or 1
- px1=max(0,(X>>6)-3);
+ if(iGPUHeight==1024) iYM=3;
+
+ py1=min(iYM,Y>>8);
+ py2=min(iYM,H>>8); // y: 0 or 1
+ px1=max(0,(X>>6)-3);
px2=min(15,(W>>6)+3); // x: 0-15
for(py=py1;py<=py2;py++)
@@ -847,10 +847,10 @@ void InvalidateSubSTextureArea(int X, int Y, int W, int H)
if(X>x1) x1=X;
if(W<x2) x2=W;
if(x2<x1) {sw=x1;x1=x2;x2=sw;}
-
- if (dwGPUVersion == 2)
- npos.l=0x00ff00ff;
- else
+
+ if (dwGPUVersion == 2)
+ npos.l=0x00ff00ff;
+ else
npos.l=((x1-xa)<<(26-k))|((x2-xa)<<(18-k))|y1|y2;
{
@@ -917,7 +917,7 @@ void InvalidateTextureArea(int X, int Y, int W, int H)
// tex window: define
////////////////////////////////////////////////////////////////////////
-void DefineTextureWnd(void)
+static void DefineTextureWnd(void)
{
if (gTexName == 0)
glGenTextures(1, &gTexName);
@@ -948,7 +948,7 @@ void DefineTextureWnd(void)
// tex window: load packed stretch
////////////////////////////////////////////////////////////////////////
-void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
+static void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
{
uint32_t start, row, column, j, sxh, sxm, ldx, ldy, ldxo;
unsigned int palstart;
@@ -975,41 +975,41 @@ void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
{
//--------------------------------------------------//
// 4bit texture load ..
- case 0:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
- for(row=0;row<16;row++)
- *px++=LPTCOL(*wSRCPtr++);
-
- column=g_y2-ldy;
- for(TXV=g_y1;TXV<=column;TXV++)
- {
- ldx=ldxo;
- for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
- {
- n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
-
- s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
- *ta++=s;
-
- if(ldx) {*ta++=s;ldx--;}
- }
-
- if(ldy)
- {ldy--;
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- *ta++=*(ta-(g_x2-g_x1));
- }
- }
-
- DefineTextureWnd();
-
- break;
- }
+ case 0:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+ for(row=0;row<16;row++)
+ *px++=LPTCOL(*wSRCPtr++);
+
+ column=g_y2-ldy;
+ for(TXV=g_y1;TXV<=column;TXV++)
+ {
+ ldx=ldxo;
+ for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
+ {
+ n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
+
+ s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
+ *ta++=s;
+
+ if(ldx) {*ta++=s;ldx--;}
+ }
+
+ if(ldy)
+ {ldy--;
+ for(TXU=g_x1;TXU<=g_x2;TXU++,ta++)
+ *ta=*(ta-(g_x2-g_x1));
+ }
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
start=((pageid-16*pmult)*128)+256*2048*pmult;
@@ -1052,45 +1052,45 @@ void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
- for(row=0;row<256;row++)
- *px++=LPTCOL(*wSRCPtr++);
-
- column=g_y2-ldy;
- for(TXV=g_y1;TXV<=column;TXV++)
- {
- ldx=ldxo;
- for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
- {
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
-
- *ta++=s;
- if(ldx) {*ta++=s;ldx--;}
- }
-
- if(ldy)
- {ldy--;
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- *ta++=*(ta-(g_x2-g_x1));
- }
-
- }
-
- DefineTextureWnd();
-
- break;
- }
-
+ case 1:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+ for(row=0;row<256;row++)
+ *px++=LPTCOL(*wSRCPtr++);
+
+ column=g_y2-ldy;
+ for(TXV=g_y1;TXV<=column;TXV++)
+ {
+ ldx=ldxo;
+ for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
+ {
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
+
+ *ta++=s;
+ if(ldx) {*ta++=s;ldx--;}
+ }
+
+ if(ldy)
+ {ldy--;
+ for(TXU=g_x1;TXU<=g_x2;TXU++,ta++)
+ *ta=*(ta-(g_x2-g_x1));
+ }
+
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
+
start=((pageid-16*pmult)*128)+256*2048*pmult;
-
+
// not using a lookup table here... speeds up smaller texture areas
cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
@@ -1141,7 +1141,7 @@ void LoadStretchPackedWndTexturePage(int pageid, int mode, short cx, short cy)
// tex window: load stretched
////////////////////////////////////////////////////////////////////////
-void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
+static void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
{
uint32_t start,row,column,j,sxh,sxm,ldx,ldy,ldxo,s;
unsigned int palstart;
@@ -1167,53 +1167,53 @@ void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
{
//--------------------------------------------------//
// 4bit texture load ..
- case 0:
- //------------------- ZN STUFF
-
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
-
- row=4;do
- {
- *px =LTCOL(*wSRCPtr);
- *(px+1)=LTCOL(*(wSRCPtr+1));
- *(px+2)=LTCOL(*(wSRCPtr+2));
- *(px+3)=LTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- column=g_y2-ldy;
- for(TXV=g_y1;TXV<=column;TXV++)
- {
- ldx=ldxo;
- for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
- {
- n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
-
- s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
- *ta++=s;
-
- if(ldx) {*ta++=s;ldx--;}
- }
-
- if(ldy)
- {ldy--;
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- *ta++=*(ta-(g_x2-g_x1));
- }
- }
-
- DefineTextureWnd();
-
- break;
- }
-
- //-------------------
+ case 0:
+ //------------------- ZN STUFF
+
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+
+ row=4;do
+ {
+ *px =LTCOL(*wSRCPtr);
+ *(px+1)=LTCOL(*(wSRCPtr+1));
+ *(px+2)=LTCOL(*(wSRCPtr+2));
+ *(px+3)=LTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ column=g_y2-ldy;
+ for(TXV=g_y1;TXV<=column;TXV++)
+ {
+ ldx=ldxo;
+ for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
+ {
+ n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
+
+ s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
+ *ta++=s;
+
+ if(ldx) {*ta++=s;ldx--;}
+ }
+
+ if(ldy)
+ {ldy--;
+ for(TXU=g_x1;TXU<=g_x2;TXU++,ta++)
+ *ta=*(ta-(g_x2-g_x1));
+ }
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
+
+ //-------------------
start=((pageid-16*pmult)*128)+256*2048*pmult;
// convert CLUT to 32bits .. and then use THAT as a lookup table
@@ -1253,51 +1253,51 @@ void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
- //------------ ZN STUFF
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
-
- row=64;do
- {
- *px =LTCOL(*wSRCPtr);
- *(px+1)=LTCOL(*(wSRCPtr+1));
- *(px+2)=LTCOL(*(wSRCPtr+2));
- *(px+3)=LTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- column=g_y2-ldy;
- for(TXV=g_y1;TXV<=column;TXV++)
- {
- ldx=ldxo;
- for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
- {
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
- *ta++=s;
- if(ldx) {*ta++=s;ldx--;}
- }
-
- if(ldy)
- {ldy--;
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- *ta++=*(ta-(g_x2-g_x1));
- }
-
- }
-
- DefineTextureWnd();
-
- break;
- }
- //------------
+ case 1:
+ //------------ ZN STUFF
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+
+ row=64;do
+ {
+ *px =LTCOL(*wSRCPtr);
+ *(px+1)=LTCOL(*(wSRCPtr+1));
+ *(px+2)=LTCOL(*(wSRCPtr+2));
+ *(px+3)=LTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ column=g_y2-ldy;
+ for(TXV=g_y1;TXV<=column;TXV++)
+ {
+ ldx=ldxo;
+ for(TXU=g_x1;TXU<=g_x2-ldxo;TXU++)
+ {
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ s=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
+ *ta++=s;
+ if(ldx) {*ta++=s;ldx--;}
+ }
+
+ if(ldy)
+ {ldy--;
+ for(TXU=g_x1;TXU<=g_x2;TXU++,ta++)
+ *ta=*(ta-(g_x2-g_x1));
+ }
+
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
+ //------------
start=((pageid-16*pmult)*128)+256*2048*pmult;
@@ -1352,7 +1352,7 @@ void LoadStretchWndTexturePage(int pageid, int mode, short cx, short cy)
// tex window: load packed simple
////////////////////////////////////////////////////////////////////////
-void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
+static void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
{
uint32_t start,row,column,j,sxh,sxm;
unsigned int palstart;
@@ -1375,30 +1375,30 @@ void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
{
//--------------------------------------------------//
// 4bit texture load ..
- case 0:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
- for(row=0;row<16;row++)
- *px++=LPTCOL(*wSRCPtr++);
-
- for(TXV=g_y1;TXV<=g_y2;TXV++)
- {
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- {
- n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
- }
- }
-
- DefineTextureWnd();
-
- break;
- }
+ case 0:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+ for(row=0;row<16;row++)
+ *px++=LPTCOL(*wSRCPtr++);
+
+ for(TXV=g_y1;TXV<=g_y2;TXV++)
+ {
+ for(TXU=g_x1;TXU<=g_x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
+ }
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
start=((pageid-16*pmult)*128)+256*2048*pmult;
@@ -1429,30 +1429,30 @@ void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
- for(row=0;row<256;row++)
- *px++=LPTCOL(*wSRCPtr++);
-
- for(TXV=g_y1;TXV<=g_y2;TXV++)
- {
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- {
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
- }
- }
-
- DefineTextureWnd();
-
- break;
- }
+ case 1:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+ for(row=0;row<256;row++)
+ *px++=LPTCOL(*wSRCPtr++);
+
+ for(TXV=g_y1;TXV<=g_y2;TXV++)
+ {
+ for(TXU=g_x1;TXU<=g_x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
+ }
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
start=((pageid-16*pmult)*128)+256*2048*pmult;
@@ -1494,7 +1494,7 @@ void LoadPackedWndTexturePage(int pageid, int mode, short cx, short cy)
// tex window: load simple
////////////////////////////////////////////////////////////////////////
-void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
+static void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
{
uint32_t start,row,column,j,sxh,sxm;
unsigned int palstart;
@@ -1517,39 +1517,39 @@ void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
{
//--------------------------------------------------//
// 4bit texture load ..
- case 0:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
-
- row=4;do
- {
- *px =LTCOL(*wSRCPtr);
- *(px+1)=LTCOL(*(wSRCPtr+1));
- *(px+2)=LTCOL(*(wSRCPtr+2));
- *(px+3)=LTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- for(TXV=g_y1;TXV<=g_y2;TXV++)
- {
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- {
- n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
- }
- }
-
- DefineTextureWnd();
-
- break;
- }
-
+ case 0:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+
+ row=4;do
+ {
+ *px =LTCOL(*wSRCPtr);
+ *(px+1)=LTCOL(*(wSRCPtr+1));
+ *(px+2)=LTCOL(*(wSRCPtr+2));
+ *(px+3)=LTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ for(TXV=g_y1;TXV<=g_y2;TXV++)
+ {
+ for(TXU=g_x1;TXU<=g_x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
+ }
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
+
start=((pageid-16*pmult)*128)+256*2048*pmult;
// convert CLUT to 32bits .. and then use THAT as a lookup table
@@ -1579,39 +1579,39 @@ void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
-
- row=64;do
- {
- *px =LTCOL(*wSRCPtr);
- *(px+1)=LTCOL(*(wSRCPtr+1));
- *(px+2)=LTCOL(*(wSRCPtr+2));
- *(px+3)=LTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- for(TXV=g_y1;TXV<=g_y2;TXV++)
- {
- for(TXU=g_x1;TXU<=g_x2;TXU++)
- {
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
- }
- }
-
- DefineTextureWnd();
-
- break;
- }
-
+ case 1:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+
+ row=64;do
+ {
+ *px =LTCOL(*wSRCPtr);
+ *(px+1)=LTCOL(*(wSRCPtr+1));
+ *(px+2)=LTCOL(*(wSRCPtr+2));
+ *(px+3)=LTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ for(TXV=g_y1;TXV<=g_y2;TXV++)
+ {
+ for(TXU=g_x1;TXU<=g_x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
+ }
+ }
+
+ DefineTextureWnd();
+
+ break;
+ }
+
start=((pageid-16*pmult)*128)+256*2048*pmult;
// not using a lookup table here... speeds up smaller texture areas
@@ -1654,7 +1654,7 @@ void LoadWndTexturePage(int pageid, int mode, short cx, short cy)
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
-void UploadTexWndPal(int mode,short cx,short cy)
+static void UploadTexWndPal(int mode,short cx,short cy)
{
unsigned int i,iSize;
unsigned short *wSrcPtr;
@@ -1681,7 +1681,7 @@ void UploadTexWndPal(int mode,short cx,short cy)
////////////////////////////////////////////////////////////////////////
-void DefinePalTextureWnd(void)
+static void DefinePalTextureWnd(void)
{
if(gTexName==0)
glGenTextures(1, &gTexName);
@@ -1710,12 +1710,12 @@ void DefinePalTextureWnd(void)
///////////////////////////////////////////////////////
-void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
+static void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
{
uint32_t start,row,column,j,sxh,sxm;
unsigned char *ta;
unsigned char *cSRCPtr;
- uint32_t LineOffset;
+ uint32_t LineOffset;
int pmult = pageid / 16;
ta = (unsigned char *)texturepart;
@@ -1724,8 +1724,8 @@ void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
{
//--------------------------------------------------//
// 4bit texture load ..
- case 0:
- start=((pageid-16*pmult)*128)+256*2048*pmult;
+ case 0:
+ start=((pageid-16*pmult)*128)+256*2048*pmult;
sxm=g_x1&1;sxh=g_x1>>1;
if(sxm) j=g_x1+1; else j=g_x1;
@@ -1748,7 +1748,7 @@ void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
+ case 1:
start=((pageid-16*pmult)*128)+256*2048*pmult;
// not using a lookup table here... speeds up smaller texture areas
@@ -1770,13 +1770,13 @@ void LoadPalWndTexturePage(int pageid, int mode, short cx, short cy)
////////////////////////////////////////////////////////////////////////
-void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)
+static void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)
{
uint32_t start,row,column,j,sxh,sxm,ldx,ldy,ldxo;
unsigned char *ta,s;
unsigned char *cSRCPtr,*cOSRCPtr;
uint32_t LineOffset;
- int pmult = pageid / 16;
+ int pmult = pageid / 16;
ldxo = TWin.Position.x1-TWin.OPosition.x1;
ldy = TWin.Position.y1-TWin.OPosition.y1;
@@ -1788,7 +1788,7 @@ void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)
//--------------------------------------------------//
// 4bit texture load ..
case 0:
- start=((pageid-16*pmult)*128)+256*2048*pmult;
+ start=((pageid-16*pmult)*128)+256*2048*pmult;
sxm=g_x1&1;sxh=g_x1>>1;
if(sxm) j=g_x1+1; else j=g_x1;
@@ -1821,8 +1821,8 @@ void LoadStretchPalWndTexturePage(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
- start=((pageid-16*pmult)*128)+256*2048*pmult;
+ case 1:
+ start=((pageid-16*pmult)*128)+256*2048*pmult;
cSRCPtr = psxVub + start + (2048*g_y1) + g_x1;
LineOffset = 2048 - (g_x2-g_x1+1) +ldxo;
@@ -1871,7 +1871,7 @@ GLuint LoadTextureWnd(int pageid, int TextureMode, uint32_t GivenClutId)
cx = ((GivenClutId << 4) & 0x3F0);
cy = ((GivenClutId >> 6) & CLUTYMASK);
GivenClutId = (GivenClutId & CLUTMASK) | (DrawSemiTrans << 30);
-
+
// palette check sum
{
uint32_t l = 0,row;
@@ -1974,7 +1974,7 @@ GLuint LoadTextureWnd(int pageid, int TextureMode, uint32_t GivenClutId)
// movie texture: define
////////////////////////////////////////////////////////////////////////
-void DefinePackedTextureMovie(void)
+static void DefinePackedTextureMovie(void)
{
if(gTexMovieName==0)
{
@@ -2015,7 +2015,7 @@ void DefinePackedTextureMovie(void)
////////////////////////////////////////////////////////////////////////
-void DefineTextureMovie(void)
+static void DefineTextureMovie(void)
{
if(gTexMovieName==0)
{
@@ -2110,7 +2110,7 @@ unsigned char * LoadDirectMovieFast(void)
////////////////////////////////////////////////////////////////////////
-GLuint LoadTextureMovieFast(void)
+static GLuint LoadTextureMovieFast(void)
{
int row,column;
unsigned int start,startxy;
@@ -2130,7 +2130,7 @@ GLuint LoadTextureMovieFast(void)
{
pD=(unsigned char *)&psxVuw[startxy];
startxy+=1024;
-
+
for(row=xrMovieArea.x0;row<sx0;row+=2)
{
lu1=*((uint32_t *)pD);pD+=3;
@@ -2145,7 +2145,7 @@ GLuint LoadTextureMovieFast(void)
{
lu1=*((uint32_t *)pD);
*ta++=XMBLUE(lu1)|XMGREEN(lu1)|XMRED(lu1)|1;
- }
+ }
}
}
else
@@ -2247,14 +2247,16 @@ GLuint LoadTextureMovie(void)
lu=*((uint32_t *)pD);pD+=3;
*ta++=XMBLUE(lu)|XMGREEN(lu)|XMRED(lu)|1;
}
- *ta++=*(ta-1);
+ *ta=*(ta-1);
+ ta++;
}
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0+1;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
- *ta++=*(ta-1);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
+ *ta=*(ta-1);
+ ta++;
}
}
else
@@ -2272,8 +2274,8 @@ GLuint LoadTextureMovie(void)
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
}
}
}
@@ -2296,14 +2298,16 @@ GLuint LoadTextureMovie(void)
*ta++=((c&0x1f)<<11)|((c&0x3e0)<<1)|((c&0x7c00)>>9)|1;
}
- *ta++=*(ta-1);
+ *ta=*(ta-1);
+ ta++;
}
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0+1;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
- *ta++=*(ta-1);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
+ *ta=*(ta-1);
+ ta++;
}
}
else
@@ -2320,8 +2324,8 @@ GLuint LoadTextureMovie(void)
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
}
}
}
@@ -2347,14 +2351,16 @@ GLuint LoadTextureMovie(void)
*ta++=*((uint32_t *)pD)|0xff000000;
pD+=3;
}
- *ta++=*(ta-1);
+ *ta=*(ta-1);
+ ta++;
}
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0+1;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
- *ta++=*(ta-1);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
+ *ta=*(ta-1);
+ ta++;
}
}
else
@@ -2372,8 +2378,8 @@ GLuint LoadTextureMovie(void)
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
}
}
}
@@ -2392,17 +2398,19 @@ GLuint LoadTextureMovie(void)
for(column=xrMovieArea.y0;column<xrMovieArea.y1;column++)
{
startxy=((1024)*column)+xrMovieArea.x0;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=LTCOL(psxVuw[startxy++]|0x8000);
- *ta++=*(ta-1);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=LTCOL(psxVuw[startxy++]|0x8000);
+ *ta=*(ta-1);
+ ta++;
}
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0+1;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
- *ta++=*(ta-1);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
+ *ta=*(ta-1);
+ ta++;
}
}
else
@@ -2417,8 +2425,8 @@ GLuint LoadTextureMovie(void)
if(b_Y)
{
dx=xrMovieArea.x1-xrMovieArea.x0;
- for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++)
- *ta++=*(ta-dx);
+ for(row=xrMovieArea.x0;row<xrMovieArea.x1;row++,ta++)
+ *ta=*(ta-dx);
}
}
}
@@ -2434,7 +2442,7 @@ GLuint LoadTextureMovie(void)
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-GLuint BlackFake15BitTexture(void)
+static GLuint BlackFake15BitTexture(void)
{
int pmult;short x1,x2,y1,y2;
@@ -2511,7 +2519,7 @@ BOOL bIgnoreNextTile =FALSE;
int iFTex=512;
-GLuint Fake15BitTexture(void)
+static GLuint Fake15BitTexture(void)
{
int pmult;short x1,x2,y1,y2;int iYAdjust;
float ScaleX,ScaleY;RECT rSrc;
@@ -2539,7 +2547,7 @@ GLuint Fake15BitTexture(void)
if(bFakeFrontBuffer) bIgnoreNextTile=TRUE;
CheckVRamReadEx(x1,y1,x1+x2,y1+y2);
return 0;
- }
+ }
/////////////////////////
@@ -2731,36 +2739,36 @@ void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)
{
//--------------------------------------------------//
// 4bit texture load ..
- case 0:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
-
- row=4;do
- {
- *px =LTCOL(*wSRCPtr);
- *(px+1)=LTCOL(*(wSRCPtr+1));
- *(px+2)=LTCOL(*(wSRCPtr+2));
- *(px+3)=LTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- for(TXV=y1;TXV<=y2;TXV++)
- {
- for(TXU=x1;TXU<=x2;TXU++)
- {
- n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
- }
- ta+=xalign;
- }
- break;
- }
+ case 0:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+
+ row=4;do
+ {
+ *px =LTCOL(*wSRCPtr);
+ *(px+1)=LTCOL(*(wSRCPtr+1));
+ *(px+2)=LTCOL(*(wSRCPtr+2));
+ *(px+3)=LTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ for(TXV=y1;TXV<=y2;TXV++)
+ {
+ for(TXU=x1;TXU<=x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
+ }
+ ta+=xalign;
+ }
+ break;
+ }
start=((pageid-16*pmult)<<7)+524288*pmult;
// convert CLUT to 32bits .. and then use THAT as a lookup table
@@ -2805,37 +2813,37 @@ void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
-
- row=64;do
- {
- *px =LTCOL(*wSRCPtr);
- *(px+1)=LTCOL(*(wSRCPtr+1));
- *(px+2)=LTCOL(*(wSRCPtr+2));
- *(px+3)=LTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- for(TXV=y1;TXV<=y2;TXV++)
- {
- for(TXU=x1;TXU<=x2;TXU++)
- {
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
- }
- ta+=xalign;
- }
-
- break;
- }
+ case 1:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+
+ row=64;do
+ {
+ *px =LTCOL(*wSRCPtr);
+ *(px+1)=LTCOL(*(wSRCPtr+1));
+ *(px+2)=LTCOL(*(wSRCPtr+2));
+ *(px+3)=LTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ for(TXV=y1;TXV<=y2;TXV++)
+ {
+ for(TXU=x1;TXU<=x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
+ }
+ ta+=xalign;
+ }
+
+ break;
+ }
start=((pageid-16*pmult)<<7)+524288*pmult;
@@ -3057,9 +3065,9 @@ void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy)
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-//
-// load texture part (packed)
-//
+//
+// load texture part (packed)
+//
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
@@ -3099,35 +3107,35 @@ void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)
{
//--------------------------------------------------//
// 4bit texture load ..
- case 0:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
- row=4;do
- {
- *px =LPTCOL(*wSRCPtr);
- *(px+1)=LPTCOL(*(wSRCPtr+1));
- *(px+2)=LPTCOL(*(wSRCPtr+2));
- *(px+3)=LPTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- for(TXV=y1;TXV<=y2;TXV++)
- {
- for(TXU=x1;TXU<=x2;TXU++)
- {
- n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
- n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
- }
- ta+=xalign;
- }
- break;
- }
+ case 0:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+ row=4;do
+ {
+ *px =LPTCOL(*wSRCPtr);
+ *(px+1)=LPTCOL(*(wSRCPtr+1));
+ *(px+2)=LPTCOL(*(wSRCPtr+2));
+ *(px+3)=LPTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ for(TXV=y1;TXV<=y2;TXV++)
+ {
+ for(TXU=x1;TXU<=x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 2 ) & ~0x3c ) + ( ( TXV << 2 ) & 0x3c );
+ n_yi = ( TXV & ~0xf ) + ( ( TXU >> 4 ) & 0xf );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x03 ) << 2 ) ) & 0x0f ));
+ }
+ ta+=xalign;
+ }
+ break;
+ }
start=((pageid-16*pmult)<<7)+524288*pmult;
@@ -3170,37 +3178,37 @@ void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)
break;
//--------------------------------------------------//
// 8bit texture load ..
- case 1:
- if(GlobalTextIL)
- {
- unsigned int TXV,TXU,n_xi,n_yi;
-
- wSRCPtr=psxVuw+palstart;
-
- row=64;do
- {
- *px =LPTCOL(*wSRCPtr);
- *(px+1)=LPTCOL(*(wSRCPtr+1));
- *(px+2)=LPTCOL(*(wSRCPtr+2));
- *(px+3)=LPTCOL(*(wSRCPtr+3));
- row--;px+=4;wSRCPtr+=4;
- }
- while (row);
-
- for(TXV=y1;TXV<=y2;TXV++)
- {
- for(TXU=x1;TXU<=x2;TXU++)
- {
- n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
- n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
-
- *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
- }
- ta+=xalign;
- }
-
- break;
- }
+ case 1:
+ if(GlobalTextIL)
+ {
+ unsigned int TXV,TXU,n_xi,n_yi;
+
+ wSRCPtr=psxVuw+palstart;
+
+ row=64;do
+ {
+ *px =LPTCOL(*wSRCPtr);
+ *(px+1)=LPTCOL(*(wSRCPtr+1));
+ *(px+2)=LPTCOL(*(wSRCPtr+2));
+ *(px+3)=LPTCOL(*(wSRCPtr+3));
+ row--;px+=4;wSRCPtr+=4;
+ }
+ while (row);
+
+ for(TXV=y1;TXV<=y2;TXV++)
+ {
+ for(TXU=x1;TXU<=x2;TXU++)
+ {
+ n_xi = ( ( TXU >> 1 ) & ~0x78 ) + ( ( TXU << 2 ) & 0x40 ) + ( ( TXV << 3 ) & 0x38 );
+ n_yi = ( TXV & ~0x7 ) + ( ( TXU >> 5 ) & 0x7 );
+
+ *ta++=*(pa+((*( psxVuw + ((GlobalTextAddrY + n_yi)*1024) + GlobalTextAddrX + n_xi ) >> ( ( TXU & 0x01 ) << 3 ) ) & 0xff));
+ }
+ ta+=xalign;
+ }
+
+ break;
+ }
start=((pageid-16*pmult)<<7)+524288*pmult;
@@ -3433,17 +3441,17 @@ void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)
}
/////////////////////////////////////////////////////////////////////////////
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-//
-// hires texture funcs
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+//
+// hires texture funcs
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
#define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
@@ -3463,7 +3471,7 @@ void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy)
#define Q_INTERPOLATE8(A, B, C, D) (((((A & qcolorMask8) >> 2) + ((B & qcolorMask8) >> 2) + ((C & qcolorMask8) >> 2) + ((D & qcolorMask8) >> 2) + ((((A & qlowpixelMask8) + (B & qlowpixelMask8) + (C & qlowpixelMask8) + (D & qlowpixelMask8)) >> 2) & qlowpixelMask8))|((((A&0xFF000000)==0x50000000)?0x50000000:(((B&0xFF000000)==0x50000000)?0x50000000:(((C&0xFF000000)==0x50000000)?0x50000000:(((D&0xFF000000)==0x50000000)?0x50000000:(((A&0xFF000000)==0x00000000)?0x00000000:(((B&0xFF000000)==0x00000000)?0x00000000:(((C&0xFF000000)==0x00000000)?0x00000000:(((D&0xFF000000)==0x00000000)?0x00000000:0xFF000000)))))))))))
-void Super2xSaI_ex8_Ex(unsigned char *srcPtr, DWORD srcPitch,
+static void Super2xSaI_ex8_Ex(unsigned char *srcPtr, DWORD srcPitch,
unsigned char *dstBitmap, int width, int height)
{
DWORD dstPitch = srcPitch * 2;
@@ -3608,7 +3616,7 @@ void Super2xSaI_ex8_Ex(unsigned char *srcPtr, DWORD srcPitch,
}
-void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
+static void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
unsigned char *dstBitmap, int width, int height)
{
DWORD dstPitch = srcPitch * 2;
@@ -3762,7 +3770,7 @@ void Super2xSaI_ex8(unsigned char *srcPtr, DWORD srcPitch,
#define Q_INTERPOLATE4(A, B, C, D) ((((A & qcolorMask4) >> 2) + ((B & qcolorMask4) >> 2) + ((C & qcolorMask4) >> 2) + ((D & qcolorMask4) >> 2) + ((((A & qlowpixelMask4) + (B & qlowpixelMask4) + (C & qlowpixelMask4) + (D & qlowpixelMask4)) >> 2) & qlowpixelMask4))| ((((A&0x0000000F)==0x00000006)?0x00000006:(((B&0x0000000F)==0x00000006)?0x00000006:(((C&0x0000000F)==0x00000006)?0x00000006:(((D&0x0000000F)==0x00000006)?0x00000006:(((A&0x0000000F)==0x00000000)?0x00000000:(((B&0x0000000F)==0x00000000)?0x00000000:(((C&0x0000000F)==0x00000000)?0x00000000:(((D&0x0000000F)==0x00000000)?0x00000000:0x0000000F))))))))))
-void Super2xSaI_ex4(unsigned char *srcPtr, DWORD srcPitch,
+static void Super2xSaI_ex4(unsigned char *srcPtr, DWORD srcPitch,
unsigned char *dstBitmap, int width, int height)
{
DWORD dstPitch = srcPitch * 2;
@@ -3917,7 +3925,7 @@ void Super2xSaI_ex4(unsigned char *srcPtr, DWORD srcPitch,
#define Q_INTERPOLATE5(A, B, C, D) ((((A & qcolorMask5) >> 2) + ((B & qcolorMask5) >> 2) + ((C & qcolorMask5) >> 2) + ((D & qcolorMask5) >> 2) + ((((A & qlowpixelMask5) + (B & qlowpixelMask5) + (C & qlowpixelMask5) + (D & qlowpixelMask5)) >> 2) & qlowpixelMask5))| ((((A&0x00000001)==0x00000000)?0x00000000:(((B&0x00000001)==0x00000000)?0x00000000:(((C&0x00000001)==0x00000000)?0x00000000:(((D&0x00000001)==0x00000000)?0x00000000:0x00000001))))))
-void Super2xSaI_ex5(unsigned char *srcPtr, DWORD srcPitch,
+static void Super2xSaI_ex5(unsigned char *srcPtr, DWORD srcPitch,
unsigned char *dstBitmap, int width, int height)
{
DWORD dstPitch = srcPitch * 2;
@@ -4064,14 +4072,14 @@ void Super2xSaI_ex5(unsigned char *srcPtr, DWORD srcPitch,
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
-//
-// ogl texture defines
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-void DefineSubTextureSortHiRes(void)
+//
+// ogl texture defines
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+static void DefineSubTextureSortHiRes(void)
{
int x,y,dx2;
@@ -4201,18 +4209,18 @@ void DefineSubTextureSort(void)
}
/////////////////////////////////////////////////////////////////////////////
-
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-//
-// texture cache garbage collection
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-void DoTexGarbageCollection(void)
+
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+//
+// texture cache garbage collection
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+static void DoTexGarbageCollection(void)
{
static unsigned short LRUCleaned=0;
unsigned short iC,iC1,iC2;
@@ -4248,15 +4256,15 @@ void DoTexGarbageCollection(void)
usLRUTexPage=LRUCleaned;
}
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-//
-// search cache for existing (already used) parts
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+//
+// search cache for existing (already used) parts
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
unsigned char * CheckTextureInSubSCache(int TextureMode, uint32_t GivenClutId, unsigned short * pCache)
{
@@ -4480,7 +4488,7 @@ ENDLOOP:
if(ul)
{
//////////////////////////////////////////////////////
-
+
{
dwTexPageComp=0;
@@ -4556,17 +4564,17 @@ ENDLOOP:
return &tsx->Opaque;
}
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-//
-// search cache for free place (on compress)
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-BOOL GetCompressTexturePlace(textureSubCacheEntryS * tsx)
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+//
+// search cache for free place (on compress)
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+static BOOL GetCompressTexturePlace(textureSubCacheEntryS * tsx)
{
int i,j,k,iMax,iC;uint32_t rx,ry,mx,my;
EXLong * ul=0, * uls, rfree;
@@ -4627,7 +4635,7 @@ BOOL GetCompressTexturePlace(textureSubCacheEntryS * tsx)
rfree=*ul;
mx=ul->c[2]-2;
my=ul->c[0]-2;
-
+
if(rx<mx && ry<my)
{
ul->c[3]+=rx;
@@ -4691,17 +4699,17 @@ TENDLOOP:
return TRUE;
}
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-//
-// compress texture cache (to make place for new texture part, if needed)
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-
-void CompressTextureSpace(void)
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+//
+// compress texture cache (to make place for new texture part, if needed)
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+
+static void CompressTextureSpace(void)
{
textureSubCacheEntryS * tsx, * tsg, * tsb;
int i,j,k,m,n,iMax;EXLong * ul, r,opos;
@@ -4754,14 +4762,14 @@ void CompressTextureSpace(void)
tsb->ClutID=0;
}
}
-
+
// if(r.l!=tsx->pos.l)
{
cx=((tsx->ClutID << 4) & 0x3F0);
cy=((tsx->ClutID >> 6) & CLUTYMASK);
if(j!=2)
- {
+ {
// palette check sum
l=0;lSRCPtr=(uint32_t *)(psxVuw+cx+(cy*1024));
if(j==1) for(row=1;row<129;row++) l+=((*lSRCPtr++)-1)*row;
@@ -4774,9 +4782,9 @@ void CompressTextureSpace(void)
}
tsx->pos.l=r.l;
- if(!GetCompressTexturePlace(tsx)) // no place?
+ if(!GetCompressTexturePlace(tsx)) // no place?
{
- for(i=0;i<3;i++) // -> clean up everything
+ for(i=0;i<3;i++) // -> clean up everything
for(j=0;j<MAXTPAGES;j++)
{
tsb=pscSubtexStore[i][j];
@@ -4826,21 +4834,21 @@ void CompressTextureSpace(void)
DrawSemiTrans=sOldDST;
}
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-//
-// main entry for searching/creating textures, called from prim.c
-//
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
-/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+//
+// main entry for searching/creating textures, called from prim.c
+//
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
GLuint SelectSubTextureS(int TextureMode, uint32_t GivenClutId)
{
unsigned char * OPtr;unsigned short iCache;short cx,cy;
-
- // sort sow/tow infos for fast access
+
+ // sort sow/tow infos for fast access
unsigned char ma1,ma2,mi1,mi2;
if(gl_ux[0]>gl_ux[1]) {mi1=gl_ux[1];ma1=gl_ux[0];}
@@ -4860,10 +4868,10 @@ GLuint SelectSubTextureS(int TextureMode, uint32_t GivenClutId)
else gl_ux[5]=mi1;
if(ma1>ma2) gl_ux[4]=ma1;
else gl_ux[4]=ma2;
-
- // get clut infos in one 32 bit val
- if(TextureMode==2) // no clut here
+ // get clut infos in one 32 bit val
+
+ if(TextureMode==2) // no clut here
{
GivenClutId=CLUTUSED|(DrawSemiTrans<<30);cx=cy=0;
@@ -4875,7 +4883,7 @@ GLuint SelectSubTextureS(int TextureMode, uint32_t GivenClutId)
cx=((GivenClutId << 4) & 0x3F0); // but here
cy=((GivenClutId >> 6) & CLUTYMASK);
GivenClutId=(GivenClutId&CLUTMASK)|(DrawSemiTrans<<30)|CLUTUSED;
-
+
// palette check sum.. removed MMX asm, this easy func works as well
{
uint32_t l=0,row;
@@ -4888,22 +4896,22 @@ GLuint SelectSubTextureS(int TextureMode, uint32_t GivenClutId)
}
}
-
+
// search cache
iCache=0;
- OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
-
+ OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
+
// cache full? compress and try again
if(iCache==0xffff)
{
CompressTextureSpace();
OPtr=CheckTextureInSubSCache(TextureMode,GivenClutId,&iCache);
- }
-
+ }
+
// found? fine
usLRUTexPage=iCache;
- if(!OPtr) return uiStexturePage[iCache];
-
+ if(!OPtr) return uiStexturePage[iCache];
+
// not found? upload texture and store infos in cache
gTexName=uiStexturePage[iCache];
LoadSubTexFn(GlobalTexturePage,TextureMode,cx,cy);
diff --git a/plugins/peopsxgl/texture.h b/plugins/peopsxgl/texture.h
index b646af7c..b4a69049 100644
--- a/plugins/peopsxgl/texture.h
+++ b/plugins/peopsxgl/texture.h
@@ -1,68 +1,69 @@
-/***************************************************************************
- texture.h - description
- -------------------
- begin : Sun Mar 08 2009
- copyright : (C) 1999-2009 by Pete Bernert
- web : www.pbernert.com
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. See also the license.txt file for *
- * additional informations. *
- * *
- ***************************************************************************/
-
-#ifndef _GPU_TEXTURE_H_
-#define _GPU_TEXTURE_H_
-
-#define TEXTUREPAGESIZE 256 * 256
-
-void InitializeTextureStore();
-void CleanupTextureStore();
-GLuint LoadTextureWnd(int pageid, int TextureMode, uint32_t GivenClutId);
-GLuint LoadTextureMovie(void);
-void InvalidateTextureArea(int imageX0, int imageY0, int imageX1, int imageY1);
-void InvalidateTextureAreaEx(void);
-void LoadTexturePage(int pageid, int mode, short cx, short cy);
-void ResetTextureArea(BOOL bDelTex);
-GLuint SelectSubTextureS(int TextureMode, uint32_t GivenClutId);
-void CheckTextureMemory(void);
-
-void LoadSubTexturePage(int pageid, int mode, short cx, short cy);
-void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy);
-void LoadPackedSubTexturePage(int pageid, int mode, short cx, short cy);
-void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy);
-uint32_t XP8RGBA(uint32_t BGR);
-uint32_t XP8RGBAEx(uint32_t BGR);
-uint32_t XP8RGBA_0(uint32_t BGR);
-uint32_t XP8RGBAEx_0(uint32_t BGR);
-uint32_t XP8BGRA_0(uint32_t BGR);
-uint32_t XP8BGRAEx_0(uint32_t BGR);
-uint32_t XP8RGBA_1(uint32_t BGR);
-uint32_t XP8RGBAEx_1(uint32_t BGR);
-uint32_t XP8BGRA_1(uint32_t BGR);
-uint32_t XP8BGRAEx_1(uint32_t BGR);
-uint32_t P8RGBA(uint32_t BGR);
-uint32_t P8BGRA(uint32_t BGR);
-uint32_t CP8RGBA_0(uint32_t BGR);
-uint32_t CP8RGBAEx_0(uint32_t BGR);
-uint32_t CP8BGRA_0(uint32_t BGR);
-uint32_t CP8BGRAEx_0(uint32_t BGR);
-uint32_t CP8RGBA(uint32_t BGR);
-uint32_t CP8RGBAEx(uint32_t BGR);
-unsigned short XP5RGBA (unsigned short BGR);
-unsigned short XP5RGBA_0 (unsigned short BGR);
-unsigned short XP5RGBA_1 (unsigned short BGR);
-unsigned short P5RGBA (unsigned short BGR);
-unsigned short CP5RGBA_0 (unsigned short BGR);
-unsigned short XP4RGBA (unsigned short BGR);
-unsigned short XP4RGBA_0 (unsigned short BGR);
-unsigned short XP4RGBA_1 (unsigned short BGR);
-unsigned short P4RGBA (unsigned short BGR);
-unsigned short CP4RGBA_0 (unsigned short BGR);
-
-#endif // _TEXTURE_H_
+/***************************************************************************
+ texture.h - description
+ -------------------
+ begin : Sun Mar 08 2009
+ copyright : (C) 1999-2009 by Pete Bernert
+ web : www.pbernert.com
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. See also the license.txt file for *
+ * additional informations. *
+ * *
+ ***************************************************************************/
+
+#ifndef _GPU_TEXTURE_H_
+#define _GPU_TEXTURE_H_
+
+#define TEXTUREPAGESIZE 256 * 256
+
+void InitializeTextureStore();
+void CleanupTextureStore();
+GLuint LoadTextureWnd(int pageid, int TextureMode, uint32_t GivenClutId);
+GLuint LoadTextureMovie(void);
+void InvalidateTextureArea(int imageX0, int imageY0, int imageX1, int imageY1);
+void InvalidateTextureAreaEx(void);
+void LoadTexturePage(int pageid, int mode, short cx, short cy);
+void ResetTextureArea(BOOL bDelTex);
+GLuint SelectSubTextureS(int TextureMode, uint32_t GivenClutId);
+void CheckTextureMemory(void);
+
+void LoadSubTexturePage(int pageid, int mode, short cx, short cy);
+void LoadSubTexturePageSort(int pageid, int mode, short cx, short cy);
+void LoadPackedSubTexturePage(int pageid, int mode, short cx, short cy);
+void LoadPackedSubTexturePageSort(int pageid, int mode, short cx, short cy);
+uint32_t XP8RGBA(uint32_t BGR);
+uint32_t XP8RGBAEx(uint32_t BGR);
+uint32_t XP8RGBA_0(uint32_t BGR);
+uint32_t XP8RGBAEx_0(uint32_t BGR);
+uint32_t XP8BGRA_0(uint32_t BGR);
+uint32_t XP8BGRAEx_0(uint32_t BGR);
+uint32_t XP8RGBA_1(uint32_t BGR);
+uint32_t XP8RGBAEx_1(uint32_t BGR);
+uint32_t XP8BGRA_1(uint32_t BGR);
+uint32_t XP8BGRAEx_1(uint32_t BGR);
+uint32_t P8RGBA(uint32_t BGR);
+uint32_t P8BGRA(uint32_t BGR);
+uint32_t CP8RGBA_0(uint32_t BGR);
+uint32_t CP8RGBAEx_0(uint32_t BGR);
+uint32_t CP8BGRA_0(uint32_t BGR);
+uint32_t CP8BGRAEx_0(uint32_t BGR);
+uint32_t CP8RGBA(uint32_t BGR);
+uint32_t CP8RGBAEx(uint32_t BGR);
+unsigned short XP5RGBA (unsigned short BGR);
+unsigned short XP5RGBA_0 (unsigned short BGR);
+unsigned short XP5RGBA_1 (unsigned short BGR);
+unsigned short P5RGBA (unsigned short BGR);
+unsigned short CP5RGBA_0 (unsigned short BGR);
+unsigned short XP4RGBA (unsigned short BGR);
+unsigned short XP4RGBA_0 (unsigned short BGR);
+unsigned short XP4RGBA_1 (unsigned short BGR);
+unsigned short P4RGBA (unsigned short BGR);
+unsigned short CP4RGBA_0 (unsigned short BGR);
+unsigned char * LoadDirectMovieFast(void);
+
+#endif // _TEXTURE_H_