foxygit / fake-08-xbox360 Log in
commit 580d5ec42a2c78920b3f43d2252acaa3d5796fd8
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Wed Apr 29 08:08:39 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Wed Apr 29 08:08:39 2020 -0600

    First pass at allowing stretched screen to flow to bottom FB
---
 source/console.cpp  |  2 +-
 source/graphics.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 source/graphics.h   |  1 +
 source/main.cpp     | 19 +++++++++++++++++++
 4 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/source/console.cpp b/source/console.cpp
index 4d4af11..c941259 100644
--- a/source/console.cpp
+++ b/source/console.cpp
@@ -234,7 +234,7 @@ void Console::FlipBuffer_SAO(
     uint8_t* fb, int width, int height,
     uint8_t* fb_o, int width_o, int height_o,
     std::function<void()> postFlipFunction){
-    _graphics->flipBuffer(fb, width, height);
+    _graphics->flipBuffer_SAO(fb, width, height, fb_o, width_o, height_o);

     if (postFlipFunction) {
         postFlipFunction();
diff --git a/source/graphics.cpp b/source/graphics.cpp
index 0038d15..5b9ef58 100644
--- a/source/graphics.cpp
+++ b/source/graphics.cpp
@@ -861,6 +861,55 @@ void Graphics::flipBuffer_STF(uint8_t* fb, int width, int height) {
     }
 }

+void Graphics::flipBuffer_SAO(
+	uint8_t* fb, int width, int height,
+	uint8_t* fb_o, int width_o, int height_o) {
+	short x, y;
+
+	//assume landscape, hardcoded double for now (3ds)
+	int ratio = 2;
+	int stretchedWidth = PicoScreenWidth * ratio;
+	int stretchedHeight = PicoScreenHeight * ratio;
+
+	short xOffset = width / 2 - stretchedWidth / 2;
+	short yOffset = 0;
+
+    for(x = 0; x < stretchedWidth; x++) {
+    	for(y = 0; y < height; y++) {
+			int picoX = (int)(x / ratio);
+			int picoY = (int)(y / ratio);
+			uint8_t c = _pico8_fb[picoX*128 + picoY];
+			Color col = PaletteColors[_gfxState_screenPaletteMap[c]];
+
+			int pixIdx = (((x + xOffset)*height)+ ((height - 1) - (y + yOffset)))*3;
+
+			fb[pixIdx + 0] = col.Blue;
+			fb[pixIdx + 1] = col.Green;
+			fb[pixIdx + 2] = col.Red;
+    	}
+    }
+
+	int overflowHeight = stretchedHeight - height;
+
+	xOffset = width_o / 2 - stretchedWidth / 2;
+	yOffset = 0;
+
+	for(x = 0; x < stretchedWidth; x++) {
+    	for(y = 0; y < overflowHeight; y++) {
+			int picoX = (int)(x / ratio);
+			int picoY = (int)((y + height) / ratio);
+			uint8_t c = _pico8_fb[picoX*128 + picoY];
+			Color col = PaletteColors[_gfxState_screenPaletteMap[c]];
+
+			int pixIdx = (((x + xOffset)*height)+ ((height - 1) - (y + yOffset)))*3;
+
+			fb_o[pixIdx + 0] = col.Blue;
+			fb_o[pixIdx + 1] = col.Green;
+			fb_o[pixIdx + 2] = col.Red;
+    	}
+    }
+}
+
 void Graphics::cursor() {
 	this->cursor(0, 0);
 }
diff --git a/source/graphics.h b/source/graphics.h
index 144321c..484dcb2 100644
--- a/source/graphics.h
+++ b/source/graphics.h
@@ -196,6 +196,7 @@ class Graphics {
 	void flipBuffer(uint8_t* fb, int width, int height);

 	void flipBuffer_STF(uint8_t* fb, int width, int height);
+	void flipBuffer_SAO(uint8_t* fb, int width, int height, uint8_t* fb_o, int width_o, int height_o);

 };

diff --git a/source/main.cpp b/source/main.cpp
index f426cf8..3263a9e 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -20,6 +20,9 @@
 const int ScreenWidth = 400;
 const int ScreenHeight = 240;

+const int BottomScreenWidth = 320;
+const int BottomScreenHeight = 240;
+
 StretchOption stretch = PixelPerfect;

 void ChangeStretch() {
@@ -27,6 +30,9 @@ void ChangeStretch() {
 		stretch = StretchToFit;
 	}
 	else if (stretch == StretchToFit) {
+		stretch = StretchAndOverflow;
+	}
+	else if (stretch == StretchAndOverflow) {
 		stretch = PixelPerfect;
 	}
 }
@@ -79,6 +85,10 @@ void clear3dsFrameBuffer() {
 	//clear whole top framebuffer
 	memset(fb, bgcolor, ScreenHeight*ScreenWidth*3);

+	//clear top 16 pixels of bottom buffer in case overflow rendering is being used
+	uint8_t* fbb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
+	memset(fbb, bgcolor, 16*BottomScreenWidth*3);
+
 }

 //3ds specific helper function
@@ -137,6 +147,7 @@ int main(int argc, char* argv[])

 		#if _TEST
 		consoleClear();
+		printf("\n"); //make space for overflow if needed
 		printf("svcGetSystemTick(): %lld \n", now_time);
 		printf("frame time (ticks): %lld \n", frame_time);
 		printf("frame time (ms): %f \n", frameTimeMs);
@@ -202,6 +213,14 @@ int main(int argc, char* argv[])
 		else if (stretch == StretchToFit) {
 			console->FlipBuffer_STF(fb, ScreenWidth, ScreenHeight, postFlip);
 		}
+		else if (stretch == StretchAndOverflow) {
+			uint8_t* fbb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, NULL, NULL);
+
+			console->FlipBuffer_SAO(
+				fb, ScreenWidth, ScreenHeight,
+				fbb, BottomScreenWidth, BottomScreenHeight,
+				postFlip);
+		}

 	}