From 522b72732791a6129a73a8d0cfb0f99817bdef10 Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Sun, 4 Oct 2026 17:09:59 +1000
Subject: [PATCH] atari:video:xbios: allow CTPCI TOS and FireTOS share the same
video api
Verified on real hardware: FireBee with FireTOS can show double-buffered
fullscreen animations without any problem.
---
src/video/xbios/SDL_xbios.h | 1 +
src/video/xbios/SDL_xbios_ctpci.c | 67 +++++++++++++++++++++++++++++++
src/video/xbios/SDL_xbios_f30.c | 34 ++++++++++++++++
3 files changed, 102 insertions(+)
diff --git a/src/video/xbios/SDL_xbios.h b/src/video/xbios/SDL_xbios.h
index 213e668d0..bc904d1a4 100644
--- a/src/video/xbios/SDL_xbios.h
+++ b/src/video/xbios/SDL_xbios.h
@@ -168,6 +168,7 @@ void SDL_XBIOS_VideoInit_Milan(_THIS);
/* SDL_xbios_ctpci.c */
void SDL_XBIOS_VideoInit_Ctpci(_THIS);
+void SDL_XBIOS_VideoInit_Firebee(_THIS);
/* SDL_xbios_nova.c */
void SDL_XBIOS_VideoInit_Nova(_THIS, void *cookie_nova);
diff --git a/src/video/xbios/SDL_xbios_ctpci.c b/src/video/xbios/SDL_xbios_ctpci.c
index 906853634..4eee17d28 100644
--- a/src/video/xbios/SDL_xbios_ctpci.c
+++ b/src/video/xbios/SDL_xbios_ctpci.c
@@ -28,8 +28,11 @@
Patrice Mandin
*/
+#include <stdio.h>
+
#include <mint/cookie.h>
#include <mint/falcon.h>
+#include <mint/osbind.h>
#include "SDL_xbios.h"
#include "SDL_xbios_milan.h"
@@ -75,6 +78,17 @@ static void swapVbuffers(_THIS);
static int allocVbuffers(_THIS, const xbiosmode_t *new_video_mode, int num_buffers, int bufsize);
static void freeVbuffers(_THIS);
+static void setMode_Firebee(_THIS, const xbiosmode_t *new_video_mode);
+static void swapVbuffers_Firebee(_THIS);
+static int allocVbuffers_Firebee(_THIS, const xbiosmode_t *new_video_mode, int num_buffers, int bufsize);
+static void freeVbuffers_Firebee(_THIS);
+
+/*
+ * FireTOS places the frame buffer of every mode set via CMD_SETMODE at
+ * the start of the ACP video RAM.
+ */
+#define FIREBEE_VIDEO_RAM 0x60000000UL
+
void SDL_XBIOS_VideoInit_Ctpci(_THIS)
{
XBIOS_listModes = listModes;
@@ -87,6 +101,22 @@ void SDL_XBIOS_VideoInit_Ctpci(_THIS)
XBIOS_freeVbuffers = freeVbuffers;
}
+/*
+ * FireBee using the Videl (ACP) output. FireTOS implements the same
+ * Vsetscreen() extension as the CTPCI but its CMD_FLIPPAGE works only with
+ * a Radeon or Lynx card. Double buffering therefore maps both buffers to the
+ * visible screen.
+ */
+void SDL_XBIOS_VideoInit_Firebee(_THIS)
+{
+ SDL_XBIOS_VideoInit_Ctpci(this);
+
+ XBIOS_setMode = setMode_Firebee;
+ XBIOS_swapVbuffers = swapVbuffers_Firebee;
+ XBIOS_allocVbuffers = allocVbuffers_Firebee;
+ XBIOS_freeVbuffers = freeVbuffers_Firebee;
+}
+
#ifndef CTPCI_USE_TABLE
static unsigned long /*cdecl*/ enumfunc(SCREENINFO *inf, unsigned long flag)
{
@@ -236,3 +266,40 @@ static void freeVbuffers(_THIS)
}
}
}
+
+static void setMode_Firebee(_THIS, const xbiosmode_t *new_video_mode)
+{
+ long modecode = 0;
+
+ VsetScreen(-1, new_video_mode->number, VN_MAGIC, CMD_SETMODE);
+
+ /* FireTOS falls back to 640x480x16 if the monitor can't show the mode */
+ VsetScreen(-1, &modecode, VN_MAGIC, CMD_GETMODE);
+ if ((modecode & 0xFFFF) != new_video_mode->number
+ || (unsigned long)Physbase() != (unsigned long)XBIOS_screens[0]) {
+ fprintf(stderr, "Warning: requested mode 0x%04x, got 0x%04lx at %p\n",
+ new_video_mode->number, modecode & 0xFFFF, Physbase());
+ }
+}
+
+static void swapVbuffers_Firebee(_THIS)
+{
+}
+
+static int allocVbuffers_Firebee(_THIS, const xbiosmode_t *new_video_mode, int num_buffers, int bufsize)
+{
+ int i;
+
+ for (i=0; i<num_buffers; i++) {
+ XBIOS_screensmem[i] = (void *)FIREBEE_VIDEO_RAM;
+ XBIOS_screens[i] = XBIOS_screensmem[i];
+ }
+ SDL_memset(XBIOS_screens[0], 0, bufsize);
+
+ return (1);
+}
+
+static void freeVbuffers_Firebee(_THIS)
+{
+ XBIOS_screensmem[0] = XBIOS_screensmem[1] = NULL;
+}
diff --git a/src/video/xbios/SDL_xbios_f30.c b/src/video/xbios/SDL_xbios_f30.c
index d61c1be00..8253e9eef 100644
--- a/src/video/xbios/SDL_xbios_f30.c
+++ b/src/video/xbios/SDL_xbios_f30.c
@@ -30,6 +30,7 @@
#include <mint/cookie.h>
#include <mint/osbind.h>
#include <mint/falcon.h>
+#include <mint/sysvars.h>
#include "../ataricommon/SDL_atarimch.h"
#include "../ataricommon/SDL_atarimxalloc_c.h"
@@ -124,6 +125,28 @@ static int setColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
static int allocVbuffers_SV(_THIS, const xbiosmode_t *new_video_mode, int num_buffers, int bufsize);
+static long is_emutos;
+
+static long checkEmuTOS(void)
+{
+ OSHEADER *tos_header = *((OSHEADER **)_sysbase);
+
+ /* EmuTOS stores 'ETOS' at offset 0x2C of its OS header */
+ is_emutos = ((long)tos_header->os_beg->p_rsv2 == 0x45544F53L);
+ return 0;
+}
+
+/* FireTOS and EmuTOS both set _CF_ but only FireTOS has the CTPCI-like XBIOS */
+static int isFireTOS(void)
+{
+ if (Getcookie(C__CF_, NULL) != C_FOUND) {
+ return 0;
+ }
+
+ Supexec(checkEmuTOS);
+ return !is_emutos;
+}
+
void SDL_XBIOS_VideoInit_F30(_THIS)
{
long cookie_cnts, cookie_scpn, cookie_dummy;
@@ -152,6 +175,17 @@ void SDL_XBIOS_VideoInit_F30(_THIS)
XBIOS_allocVbuffers = allocVbuffers_SV;
has_supervidel = 1;
} else
+ /* FireBee running FireTOS ? */
+ if (isFireTOS()) {
+ unsigned long physbase = (unsigned long)Physbase();
+
+ /* Radeon frame buffer lives in the PCI memory window */
+ if (physbase >= 0x80000000UL && physbase < 0xC0000000UL) {
+ SDL_XBIOS_VideoInit_Ctpci(this);
+ } else {
+ SDL_XBIOS_VideoInit_Firebee(this);
+ }
+ } else
/* CTPCI ? */
if ((Getcookie(C_CT60, &cookie_dummy) == C_FOUND)
&& (Getcookie(C__PCI, &cookie_dummy) == C_FOUND)