From 8f459cf958f1aee7b72d7dce3eed999061cd7a77 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 20 Nov 2017 19:15:54 -0500 Subject: [PATCH] Use u32 for gfxGetFramebuffer() width/height. Added gfxGetFramebufferDisplayOffset(). --- nx/include/switch/gfx/gfx.h | 4 +++- nx/source/gfx/gfx.c | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/gfx/gfx.h b/nx/include/switch/gfx/gfx.h index a715edea..ba9ee17f 100644 --- a/nx/include/switch/gfx/gfx.h +++ b/nx/include/switch/gfx/gfx.h @@ -4,5 +4,7 @@ void gfxExit(void); void gfxWaitForVsync(); void gfxSwapBuffers(); -u8* gfxGetFramebuffer(u16* width, u16* height); +u8* gfxGetFramebuffer(u32* width, u32* height); void gfxFlushBuffers(void); + +u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y); diff --git a/nx/source/gfx/gfx.c b/nx/source/gfx/gfx.c index 51fe735f..d2db8c03 100644 --- a/nx/source/gfx/gfx.c +++ b/nx/source/gfx/gfx.c @@ -231,7 +231,7 @@ void gfxSwapBuffers() { if (R_FAILED(rc)) fatalSimple(rc); } -u8* gfxGetFramebuffer(u16* width, u16* height) { +u8* gfxGetFramebuffer(u32* width, u32* height) { if(width) *width = 1280; if(height) *height = 720; @@ -242,3 +242,20 @@ void gfxFlushBuffers(void) { armDCacheFlush(&g_gfxFramebuf[g_gfxCurrentBuffer*g_nvgfx_singleframebuf_size], g_nvgfx_singleframebuf_size); } +//This implements tegra blocklinear, with hard-coded constants etc. +u32 gfxGetFramebufferDisplayOffset(u32 x, u32 y) { + u32 width=0, height=0; + u32 tilepos, tmp_pos; + + gfxGetFramebuffer(&width, &height); + + y = height-1-y; + + tilepos = ((y & 127) / 16) + (x/16*8) + ((y/16/8)*(width/16*8)); + tilepos = tilepos*16*16 * 4; + + tmp_pos = ((y%16)/8)*512 + ((x%16)/8)*256 + ((y%8)/2)*64 + ((x%8)/4)*32 + (y%2)*16 + (x%4)*4;//This line is a modified version of code from the Tegra X1 datasheet. + + return tilepos + tmp_pos; +} +