- Begin refactoring work in order to support combination native/custom rendering sizes.
This commit is contained in:
rogerman 2015-08-24 22:12:18 +00:00
parent bf5b1505c8
commit bccbae0df9
6 changed files with 458 additions and 245 deletions

File diff suppressed because it is too large Load Diff

View File

@ -646,17 +646,35 @@ enum GPULayerType
GPULayerType_OBJ = 2
};
enum NDSDisplayID
{
NDSDisplayID_Main = 0,
NDSDisplayID_Touch = 1
};
typedef struct
{
u8 blockIndexBG[2];
u8 bgLayerUsingVRAM[2];
u8 blockIndexOBJ[2];
u8 blockIndexDisplayVRAM;
bool isBlockUsed[4];
bool is3DEnabled[2];
} VRAM3DUsageProperties;
typedef struct
{
bool isCustomSizeRequested; // true - A custom size was requested; false - Use the native size
size_t customWidth; // The custom buffer width, measured in pixels
size_t customHeight; // The custom buffer height, measured in pixels
u16 *masterCustomBuffer; // Pointer to the head of the master custom buffer.
u16 *masterNativeBuffer; // Pointer to the head of the master native buffer.
u16 *customBuffer[2]; // Pointer to a display's custom size framebuffer
u16 *nativeBuffer[2]; // Pointer to a display's native size framebuffer
bool didPerformCustomRender[2]; // true - The display performed a custom render; false - The display performed a native render
size_t renderedWidth[2]; // The display rendered at this width, measured in pixels
size_t renderedHeight[2]; // The display rendered at this height, measured in pixels
u16 *renderedBuffer[2]; // The display rendered to this buffer
} NDSDisplayInfo;
#define VRAM_NO_3D_USAGE 0xFF
struct GPU
@ -714,11 +732,24 @@ struct GPU
template<size_t WIN_NUM> void setup_windows();
GPUCoreID core;
NDSDisplayID targetDisplayID;
GPUDisplayMode dispMode;
u8 vramBlock;
u16 *VRAMaddr;
u16 *VRAMaddrNonNative;
u16 *VRAMaddrNative;
u16 *VRAMaddrCustom;
bool isCustomRenderingNeeded;
bool is3DEnabled;
u8 vramBlockBGIndex;
u8 vramBGLayer;
u8 vramBlockOBJIndex;
u16 *customBuffer;
u16 *nativeBuffer;
size_t renderedWidth;
size_t renderedHeight;
u16 *renderedBuffer;
//FIFO fifo;
u8 bgPrio[5];
@ -836,11 +867,10 @@ struct GPU
template<bool BACKDROP, int FUNCNUM> void setFinalColorBG(const size_t srcX, const size_t dstX, u16 *dstLine, u8 *bgPixelsLine, u16 src);
template<bool MOSAIC, bool BACKDROP> FORCEINLINE void __setFinalColorBck(u16 color, const size_t srcX, const bool opaque);
template<bool MOSAIC, bool BACKDROP, bool USENONNATIVEVRAM, int FUNCNUM> FORCEINLINE void ___setFinalColorBck(u16 color, const size_t srcX, const bool opaque);
template<bool MOSAIC, bool BACKDROP, bool USECUSTOMVRAM, int FUNCNUM> FORCEINLINE void ___setFinalColorBck(u16 color, const size_t srcX, const bool opaque);
void UpdateVRAM3DUsageProperties_BGLayer(const GPU &gpuEngine, const size_t bankIndex, VRAM3DUsageProperties &outProperty) const;
void UpdateVRAM3DUsageProperties_OBJLayer(const GPU &gpuEngine, const size_t bankIndex, VRAM3DUsageProperties &outProperty) const;
void UpdateVRAM3DUsageProperties(VRAM3DUsageProperties &outProperty) const;
void UpdateVRAM3DUsageProperties_BGLayer(const size_t bankIndex, VRAM3DUsageProperties &outProperty);
void UpdateVRAM3DUsageProperties_OBJLayer(const size_t bankIndex, VRAM3DUsageProperties &outProperty);
void setAffineStart(const size_t layer, int xy, u32 val);
void setAffineStartWord(const size_t layer, int xy, u16 val, int word);
@ -864,6 +894,8 @@ struct GPU
void setBLDALPHA(const u16 val);
void setBLDALPHA_EVA(const u8 val);
void setBLDALPHA_EVB(const u8 val);
void SetDisplayByID(const NDSDisplayID theDisplayID);
};
#if 0
// normally should have same addresses
@ -885,7 +917,7 @@ static void REG_DISPx_pack_test(GPU * gpu)
}
#endif
extern u16 *GPU_screen;
extern u16 *GPU_screen; // TODO: Old pointer - need to eliminate direct reference in frontends
GPU* GPU_Init(const GPUCoreID coreID);
void GPU_Reset(GPU *gpu);
@ -893,7 +925,8 @@ void GPU_DeInit(GPU *gpu);
size_t GPU_GetFramebufferWidth();
size_t GPU_GetFramebufferHeight();
void GPU_SetFramebufferSize(size_t w, size_t h);
bool GPU_IsFramebufferNativeSize();
void GPU_UpdateVRAM3DUsageProperties(VRAM3DUsageProperties &outProperty);
const NDSDisplayInfo& NDS_GetDisplayInfo(); // Frontends need to call this whenever they need to read the video buffers from the emulator core
//these are functions used by debug tools which want to render layers etc outside the context of the emulation
namespace GPU_EXT
@ -905,14 +938,31 @@ namespace GPU_EXT
void sprite1D(GPU *gpu, u16 l, u8 *dst, u8 *dst_alpha, u8 *typeTab, u8 *prioTab);
void sprite2D(GPU *gpu, u16 l, u8 *dst, u8 *dst_alpha, u8 *typeTab, u8 *prioTab);
typedef struct
class NDSDisplay
{
private:
NDSDisplayID _ID;
GPU *_gpu;
public:
NDSDisplay();
NDSDisplay(const NDSDisplayID displayID);
NDSDisplay(const NDSDisplayID displayID, const GPUCoreID coreID);
GPU* GetEngine();
GPUCoreID GetEngineID();
void SetEngineByID(const GPUCoreID theID);
};
struct NDS_Screen
{
GPU *gpu;
u16 offset;
} NDS_Screen;
};
extern NDS_Screen MainScreen;
extern NDS_Screen SubScreen;
extern NDSDisplay MainDisplay;
extern NDSDisplay TouchDisplay;
int Screen_Init();
void Screen_Reset(void);

View File

@ -404,7 +404,7 @@ static void TextualInputDisplay() {
}
}
static void TouchDisplay() {
static void OSD_HandleTouchDisplay() {
// note: calcY should not be used in this function.
aggDraw.hud->lineWidth(1.0);
@ -523,7 +523,7 @@ void DrawHUD()
if (CommonSettings.hud.ShowInputDisplay)
{
TextualInputDisplay();
TouchDisplay();
OSD_HandleTouchDisplay();
}
if (CommonSettings.hud.FpsDisplay)

View File

@ -1011,9 +1011,6 @@ void MMU_Reset()
// Enable the sound speakers
T1WriteWord(MMU.ARM7_REG, 0x304, 0x0001);
MainScreen.offset = 0;
SubScreen.offset = GPU_GetFramebufferHeight();
MMU_VRAM_unmap_all();
MMU.powerMan_CntReg = 0x00;
@ -1851,14 +1848,14 @@ static void writereg_POWCNT1(const int size, const u32 adr, const u32 val) {
if(nds.power1.dispswap)
{
//printf("Main core on top (vcount=%d)\n",nds.VCount);
MainScreen.offset = 0;
SubScreen.offset = GPU_GetFramebufferHeight();
MainDisplay.SetEngineByID(GPUCOREID_MAIN);
TouchDisplay.SetEngineByID(GPUCOREID_SUB);
}
else
{
//printf("Main core on bottom (vcount=%d)\n",nds.VCount);
MainScreen.offset = GPU_GetFramebufferHeight();
SubScreen.offset = 0;
MainDisplay.SetEngineByID(GPUCOREID_SUB);
TouchDisplay.SetEngineByID(GPUCOREID_MAIN);
}
break;
}

View File

@ -587,7 +587,7 @@ u32 GameInfo::readROM(u32 pos)
num++;
}
return LE_TO_LOCAL_32(data) & ~pad | pad;
return (LE_TO_LOCAL_32(data) & ~pad) | pad;
}
bool GameInfo::isDSiEnhanced()
@ -798,7 +798,7 @@ public:
SkipNext2DFrame = false;
nextSkip = false;
}
else if(lastOffset != MainScreen.offset && lastSkip && !skipped)
else if((lastDisplayTarget != MainScreen.gpu->targetDisplayID) && lastSkip && !skipped)
{
// if we're switching from not skipping to skipping
// and the screens are also switching around this frame,
@ -812,8 +812,8 @@ public:
consecutiveNonCaptures = 0;
else if(!(consecutiveNonCaptures > 9000)) // arbitrary cap to avoid eventual wrap
consecutiveNonCaptures++;
lastLastOffset = lastOffset;
lastOffset = MainScreen.offset;
lastDisplayTarget = MainScreen.gpu->targetDisplayID;
lastSkip = skipped;
skipped = nextSkip;
nextSkip = false;
@ -835,7 +835,7 @@ public:
nextSkip = false;
skipped = false;
lastSkip = false;
lastOffset = 0;
lastDisplayTarget = NDSDisplayID_Main;
SkipCur2DFrame = false;
SkipCur3DFrame = false;
SkipNext2DFrame = false;
@ -845,8 +845,7 @@ private:
bool nextSkip;
bool skipped;
bool lastSkip;
int lastOffset;
int lastLastOffset;
NDSDisplayID lastDisplayTarget;
int consecutiveNonCaptures;
bool SkipCur2DFrame;
bool SkipCur3DFrame;
@ -2898,9 +2897,16 @@ void NDS_suspendProcessingInput(bool suspend)
void NDS_swapScreen()
{
u16 tmp = MainScreen.offset;
MainScreen.offset = SubScreen.offset;
SubScreen.offset = tmp;
if (MainDisplay.GetEngineID() == GPUCOREID_MAIN)
{
MainDisplay.SetEngineByID(GPUCOREID_SUB);
TouchDisplay.SetEngineByID(GPUCOREID_MAIN);
}
else
{
MainDisplay.SetEngineByID(GPUCOREID_MAIN);
TouchDisplay.SetEngineByID(GPUCOREID_SUB);
}
}

View File

@ -816,11 +816,13 @@ void ToDSScreenRelativeCoords(s32& x, s32& y, int whichScreen)
}
// finally, make it relative to the correct screen
const bool isMainGPUFirst = (MainDisplay.GetEngineID() == GPUCOREID_MAIN);
if (video.layout == 0 || video.layout == 2)
{
if(whichScreen)
{
bool topOnTop = (video.swap == 0) || (video.swap == 2 && !MainScreen.offset) || (video.swap == 3 && MainScreen.offset);
bool topOnTop = (video.swap == 0) || (video.swap == 2 && isMainGPUFirst) || (video.swap == 3 && !isMainGPUFirst);
bool bottom = (whichScreen > 0);
if(topOnTop)
y += bottom ? -192 : 0;
@ -832,7 +834,7 @@ void ToDSScreenRelativeCoords(s32& x, s32& y, int whichScreen)
{
if(whichScreen)
{
bool topOnTop = (video.swap == 0) || (video.swap == 2 && !MainScreen.offset) || (video.swap == 3 && MainScreen.offset);
bool topOnTop = (video.swap == 0) || (video.swap == 2 && isMainGPUFirst) || (video.swap == 3 && !isMainGPUFirst);
bool bottom = (whichScreen > 0);
if(topOnTop)
x += bottom ? -256 : 0;
@ -1654,6 +1656,7 @@ static void OGL_DoDisplay()
RECT srcRects [2];
const bool isMainGPUFirst = (MainDisplay.GetEngineID() == GPUCOREID_MAIN);
if(video.swap == 0)
{
@ -1669,15 +1672,15 @@ static void OGL_DoDisplay()
}
else if(video.swap == 2)
{
srcRects[0] = (MainScreen.offset) ? SubScreenSrcRect : MainScreenSrcRect;
srcRects[1] = (MainScreen.offset) ? MainScreenSrcRect : SubScreenSrcRect;
if(osd) osd->swapScreens = (MainScreen.offset != 0);
srcRects[0] = (!isMainGPUFirst) ? SubScreenSrcRect : MainScreenSrcRect;
srcRects[1] = (!isMainGPUFirst) ? MainScreenSrcRect : SubScreenSrcRect;
if(osd) osd->swapScreens = !isMainGPUFirst;
}
else if(video.swap == 3)
{
srcRects[0] = (MainScreen.offset) ? MainScreenSrcRect : SubScreenSrcRect;
srcRects[1] = (MainScreen.offset) ? SubScreenSrcRect : MainScreenSrcRect;
if(osd) osd->swapScreens = (SubScreen.offset != 0);
srcRects[0] = (!isMainGPUFirst) ? MainScreenSrcRect : SubScreenSrcRect;
srcRects[1] = (!isMainGPUFirst) ? SubScreenSrcRect : MainScreenSrcRect;
if(osd) osd->swapScreens = isMainGPUFirst;
}
//printf("%d,%d %dx%d -- %d,%d %dx%d\n",
@ -1771,6 +1774,7 @@ static void DD_DoDisplay()
RECT* dstRects [2] = {&MainScreenRect, &SubScreenRect};
RECT* srcRects [2];
const bool isMainGPUFirst = (MainDisplay.GetEngineID() == GPUCOREID_MAIN);
if(video.swap == 0)
{
@ -1786,15 +1790,15 @@ static void DD_DoDisplay()
}
else if(video.swap == 2)
{
srcRects[0] = (MainScreen.offset) ? &SubScreenSrcRect : &MainScreenSrcRect;
srcRects[1] = (MainScreen.offset) ? &MainScreenSrcRect : &SubScreenSrcRect;
if(osd) osd->swapScreens = (MainScreen.offset != 0);
srcRects[0] = (!isMainGPUFirst) ? &SubScreenSrcRect : &MainScreenSrcRect;
srcRects[1] = (!isMainGPUFirst) ? &MainScreenSrcRect : &SubScreenSrcRect;
if(osd) osd->swapScreens = !isMainGPUFirst;
}
else if(video.swap == 3)
{
srcRects[0] = (MainScreen.offset) ? &MainScreenSrcRect : &SubScreenSrcRect;
srcRects[1] = (MainScreen.offset) ? &SubScreenSrcRect : &MainScreenSrcRect;
if(osd) osd->swapScreens = (SubScreen.offset != 0);
srcRects[0] = (!isMainGPUFirst) ? &MainScreenSrcRect : &SubScreenSrcRect;
srcRects[1] = (!isMainGPUFirst) ? &SubScreenSrcRect : &MainScreenSrcRect;
if(osd) osd->swapScreens = isMainGPUFirst;
}
//this code fills in all the undrawn areas if we are in fullscreen mode.
@ -5141,7 +5145,9 @@ DOKEYDOWN:
}
else
{
if ((video.layout == 2) && ((video.swap == 0) || (video.swap == 2 && !MainScreen.offset) || (video.swap == 3 && MainScreen.offset))) return 0;
const bool isMainGPUFirst = (MainDisplay.GetEngineID() == GPUCOREID_MAIN);
if ((video.layout == 2) && ((video.swap == 0) || (video.swap == 2 && isMainGPUFirst) || (video.swap == 3 && !isMainGPUFirst))) return 0;
ToDSScreenRelativeCoords(x,y,1);
if(x<0) x = 0; else if(x>255) x = 255;
if(y<0) y = 0; else if(y>192) y = 192;