SDL-1.2: atari:video:xbios: properly initialize double buffering

From 3a0c3a483edf8b3acbbea654005515f490be6a60 Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Sun, 7 Jul 2024 01:09:20 +0200
Subject: [PATCH] atari:video:xbios: properly initialize double buffering

---
 src/video/xbios/SDL_xbios.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/video/xbios/SDL_xbios.c b/src/video/xbios/SDL_xbios.c
index 4fcde0f3..70a09b30 100644
--- a/src/video/xbios/SDL_xbios.c
+++ b/src/video/xbios/SDL_xbios.c
@@ -504,6 +504,13 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
 	/* this is for C2P conversion */
 	XBIOS_pitch = (*XBIOS_getLineWidth)(this, new_video_mode, new_video_mode->width, new_video_mode->depth);
 
+	/* XBIOS_setMode() is going to call SetScreen(XBIOS_screens[0])
+	 * and XBIOS_swapVbuffers() is going to call Setscreen(XBIOS_screens[XBIOS_fbnum])
+	 * so these can't be the same buffers if double buffering has been requested.
+	 */
+	XBIOS_fbnum = num_buffers-1;
+	XBIOS_current = new_video_mode;
+
 	current->w = width;
 	current->h = height;
 	current->pitch = lineWidth;
@@ -511,7 +518,7 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
 	if (XBIOS_shadowscreen)
 		current->pixels = XBIOS_shadowscreen;
 	else
-		current->pixels = XBIOS_screens[0];
+		current->pixels = XBIOS_screens[XBIOS_fbnum];
 
 #if SDL_VIDEO_OPENGL
 	if (flags & SDL_OPENGL) {
@@ -534,9 +541,6 @@ static SDL_Surface *XBIOS_SetVideoMode(_THIS, SDL_Surface *current,
 	(*XBIOS_vsync)(this);
 #endif
 
-	XBIOS_fbnum = 0;
-	XBIOS_current = new_video_mode;
-
 	this->UpdateRects = XBIOS_updRects;
 
 	return (current);