SDL-1.2: atari:video:xbios: align CTPCI and Milan implementations

From 5b002dc405d4b7eea1555338c3109ee95160ad57 Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Tue, 12 Dec 2023 19:35:42 +0100
Subject: [PATCH] atari:video:xbios: align CTPCI and Milan implementations

Also it seems that Milan XBIOS didn't set vformat->BitsPerPixel properly.
---
 src/video/xbios/SDL_xbios_ctpci.c | 10 ++++++----
 src/video/xbios/SDL_xbios_milan.c | 32 ++++++++++++++++---------------
 src/video/xbios/SDL_xbios_st.c    |  2 +-
 src/video/xbios/SDL_xbios_tt.c    |  4 ++--
 4 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/src/video/xbios/SDL_xbios_ctpci.c b/src/video/xbios/SDL_xbios_ctpci.c
index d82eafbb..930b7063 100644
--- a/src/video/xbios/SDL_xbios_ctpci.c
+++ b/src/video/xbios/SDL_xbios_ctpci.c
@@ -39,9 +39,11 @@
 #include "SDL_xbios.h"
 #include "SDL_xbios_milan.h"
 
-/* use predefined, hardcoded table if CTPCI_USE_TABLE == 1
-   else enumerate all non virtual video modes */
-#define CTPCI_USE_TABLE 1
+/*
+ * Use predefined, hardcoded table if CTPCI_USE_TABLE is defined
+ * else enumerate all non virtual video modes
+ */
+#define CTPCI_USE_TABLE
 
 typedef struct {
 	Uint16 modecode, width, height;
@@ -144,7 +146,7 @@ static void listModes(_THIS, int actually_add)
 
 static void saveMode(_THIS, SDL_PixelFormat *vformat)
 {
-	SCREENINFO si;
+	SCREENINFO si = { 0 };
 
 	/* Read infos about current mode */
 	VsetScreen(-1, &XBIOS_oldvmode, VN_MAGIC, CMD_GETMODE);
diff --git a/src/video/xbios/SDL_xbios_milan.c b/src/video/xbios/SDL_xbios_milan.c
index dbf17e4b..75977110 100644
--- a/src/video/xbios/SDL_xbios_milan.c
+++ b/src/video/xbios/SDL_xbios_milan.c
@@ -33,23 +33,22 @@
 #include "SDL_xbios.h"
 #include "SDL_xbios_milan.h"
 
-#define NUM_PREDEFINED_MODES 7
-
 typedef struct {
-	Uint16 width, height;
+	Uint16 modecode, width, height;
 } predefined_mode_t;
 
-static const predefined_mode_t mode_list[NUM_PREDEFINED_MODES]={
-	{640,400},
-	{640,480},
-	{800,608},
-	{1024,768},
-	{1152,864},
-	{1280,1024},
-	{1600,1200}
+
+static const predefined_mode_t mode_list[]={
+	{0x1000+(0<<4),640,400},
+	{0x1000+(1<<4),640,480},
+	{0x1000+(2<<4),800,608},
+	{0x1000+(3<<4),1024,768},
+	{0x1000+(4<<4),1152,864},
+	{0x1000+(5<<4),1280,1024},
+	{0x1000+(6<<4),1600,1200}
 };
 
-static const Uint8 mode_bpp[4]={
+static const Uint8 mode_bpp[]={
 	8, 15, 16, 32
 };
 
@@ -81,6 +80,7 @@ void SDL_XBIOS_VideoInit_Milan(_THIS)
 	XBIOS_allocVbuffers = allocVbuffers;
 	XBIOS_freeVbuffers = freeVbuffers;
 
+	/* CTPCI doesn't need this as it's inherited from xbios_f030 */
 	this->SetColors = setColors;
 }
 
@@ -104,9 +104,9 @@ static void listModes(_THIS, int actually_add)
 	int i;
 
 	/* Read validated predefined modes */
-	for (i=0; i<NUM_PREDEFINED_MODES; i++) {
+	for (i=0; i<sizeof(mode_list)/sizeof(predefined_mode_t); i++) {
 		int j;
-		Uint16 deviceid = 0x1000 + (i<<4);
+		Uint16 deviceid = mode_list[i].modecode;
 
 		for (j=1; j<4; j++) {
 			if (Validmode(deviceid + j)) {
@@ -131,7 +131,7 @@ static void listModes(_THIS, int actually_add)
 
 static void saveMode(_THIS, SDL_PixelFormat *vformat)
 {
-	SCREENINFO si;
+	SCREENINFO si = { 0 };
 
 	/* Read infos about current mode */
 	VsetScreen(-1, &XBIOS_oldvmode, MI_MAGIC, CMD_GETMODE);
@@ -146,6 +146,8 @@ static void saveMode(_THIS, SDL_PixelFormat *vformat)
 
 	XBIOS_oldvbase = (void*)si.frameadr;
 
+	vformat->BitsPerPixel = si.scrPlanes;
+
 	XBIOS_oldnumcol = 0;
 	if (si.scrFlags & SCRINFO_OK) {
 		if (si.scrPlanes <= 8) {
diff --git a/src/video/xbios/SDL_xbios_st.c b/src/video/xbios/SDL_xbios_st.c
index 01e9579d..fed70b87 100644
--- a/src/video/xbios/SDL_xbios_st.c
+++ b/src/video/xbios/SDL_xbios_st.c
@@ -37,7 +37,7 @@
 #include "SDL_xbios.h"
 
 static const xbiosmode_t stmodes[]={
-	{ST_LOW>>8,320,200,4, XBIOSMODE_C2P}
+	{ST_LOW>>8,320,200,4,XBIOSMODE_C2P}
 };
 
 static void listModes(_THIS, int actually_add);
diff --git a/src/video/xbios/SDL_xbios_tt.c b/src/video/xbios/SDL_xbios_tt.c
index 67095b04..550bb984 100644
--- a/src/video/xbios/SDL_xbios_tt.c
+++ b/src/video/xbios/SDL_xbios_tt.c
@@ -36,8 +36,8 @@
 #include "SDL_xbios_nova.h"
 
 static const xbiosmode_t ttmodes[]={
-	{TT_LOW,320,480,8, XBIOSMODE_C2P},
-	{TT_LOW,320,240,8, XBIOSMODE_C2P|XBIOSMODE_DOUBLELINE}
+	{TT_LOW,320,480,8,XBIOSMODE_C2P},
+	{TT_LOW,320,240,8,XBIOSMODE_C2P|XBIOSMODE_DOUBLELINE}
 };
 
 static void listModes(_THIS, int actually_add);