Re: [hatari-devel] TT palette bankswitching should be supported

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On 02/26/2016 12:54 AM, Eero Tamminen wrote:
Looking at Roger's test program (which doesn't change
any palette entries, just queries them after changing
bank), it's not enough to map ST palette writes, also
reads need to be mapped.

And as byte sized writes to ST palette entries need
to be blocked, I think I need to re-write the palette
handling so that both ST palette writes AND reads are
directed to suitable TT palette entries.

Instead of that, I decided just to copy suitable
bank of palette entries from TT-palette to ST(e)-palette
on bank switch. I also decided to use separate TT
function for handling ST color regs. The attached
patch adds one more save file variable which means
an ABI break.

The patch works fine with Roger's tester(s).

Comments?

As to byte accesses, this only prevents TT-palette
entries from being modified. As TT values are ones
set to SDL palette, the TT-register values and colors
on screen should be correct on byte accesses, just
the ST-regs are wrong (until they get updated).


	- Eero


CPU core can manipulate ST palette registers directly,
but they're used just on writes, not on reads.


     - Eero

On 02/23/2016 07:55 PM, Thomas Huth wrote:
Am Sun, 21 Feb 2016 22:56:14 +0200
schrieb Eero Tamminen <oak@xxxxxxxxxxxxxx>:

Hi Roger,

On 02/21/2016 07:26 AM, Roger Burrows wrote:
On 21 Feb 2016 at 1:00, Eero Tamminen wrote:
Ah, so this isn't about ST<->TT color palette mapping,
but about e.g. 16/4/2 color modes.   Both TT and ST modes?

It applies when bank-switching is active, so should apply to ST
low, ST medium, and TT medium.  I originally tested just TT medium,
but I've now tested ST medium & ST low and (as per the Atari
documents), it applies to all 3.

Note that this does not apply to any other TT mode (ST
high/duochrome, TT high, TT low).

Thanks for the testing!

Could you send the test program you mentioned?

Attached patch hopefully fixes that.

You might also need to set bTTColorsSync = false in case the
application writes to the TT shifter mode register?



diff -r ced6489e1793 src/includes/video.h
--- a/src/includes/video.h	Fri Feb 26 23:36:01 2016 +0100
+++ b/src/includes/video.h	Mon Feb 29 01:04:54 2016 +0200
@@ -225,6 +225,7 @@
 extern void Video_HorScroll_Write(void);
 extern void Video_TTShiftMode_WriteWord(void);
 extern void Video_TTColorRegs_Write(void);
+extern void Video_TTColorRegs_STRegWrite(void);
 
 extern void Video_Info(FILE *fp, Uint32 dummy);
 
diff -r ced6489e1793 src/ioMemTabTT.c
--- a/src/ioMemTabTT.c	Fri Feb 26 23:36:01 2016 +0100
+++ b/src/ioMemTabTT.c	Mon Feb 29 01:04:54 2016 +0200
@@ -61,22 +61,7 @@
 	{ 0xff820d, SIZE_BYTE, Video_BaseLow_ReadByte, Video_ScreenBaseSTE_WriteByte },
 	{ 0xff820e, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite },                               /* No bus error here */
 	{ 0xff820f, SIZE_BYTE, IoMem_VoidRead, IoMem_VoidWrite },                               /* No bus error here */
-	{ 0xff8240, SIZE_WORD, Video_Color0_ReadWord, Video_Color0_WriteWord },			/* ST palette color 0 */
-	{ 0xff8242, SIZE_WORD, Video_Color1_ReadWord, Video_Color1_WriteWord },			/* ST palette color 1 */
-	{ 0xff8244, SIZE_WORD, Video_Color2_ReadWord, Video_Color2_WriteWord },			/* ST palette color 2 */
-	{ 0xff8246, SIZE_WORD, Video_Color3_ReadWord, Video_Color3_WriteWord },			/* ST palette color 3 */
-	{ 0xff8248, SIZE_WORD, Video_Color4_ReadWord, Video_Color4_WriteWord },			/* ST palette color 4 */
-	{ 0xff824a, SIZE_WORD, Video_Color5_ReadWord, Video_Color5_WriteWord },			/* ST palette color 5 */
-	{ 0xff824c, SIZE_WORD, Video_Color6_ReadWord, Video_Color6_WriteWord },			/* ST palette color 6 */
-	{ 0xff824e, SIZE_WORD, Video_Color7_ReadWord, Video_Color7_WriteWord },			/* ST palette color 7 */
-	{ 0xff8250, SIZE_WORD, Video_Color8_ReadWord, Video_Color8_WriteWord },			/* ST palette color 8 */
-	{ 0xff8252, SIZE_WORD, Video_Color9_ReadWord, Video_Color9_WriteWord },			/* ST palette color 9 */
-	{ 0xff8254, SIZE_WORD, Video_Color10_ReadWord, Video_Color10_WriteWord },		/* ST palette color 10 */
-	{ 0xff8256, SIZE_WORD, Video_Color11_ReadWord, Video_Color11_WriteWord },		/* ST palette color 11 */
-	{ 0xff8258, SIZE_WORD, Video_Color12_ReadWord, Video_Color12_WriteWord },		/* ST palette color 12 */
-	{ 0xff825a, SIZE_WORD, Video_Color13_ReadWord, Video_Color13_WriteWord },		/* ST palette color 13 */
-	{ 0xff825c, SIZE_WORD, Video_Color14_ReadWord, Video_Color14_WriteWord },		/* ST palette color 14 */
-	{ 0xff825e, SIZE_WORD, Video_Color15_ReadWord, Video_Color15_WriteWord },		/* ST palette color 15 */
+	{ 0xff8240, 16*SIZE_WORD, IoMem_ReadWithoutInterception, Video_TTColorRegs_STRegWrite },        /* 16 TT ST-palette entries */
 	{ 0xff8260, SIZE_BYTE, Video_ShifterMode_ReadByte, Video_ShifterMode_WriteByte },
 	{ 0xff8261, SIZE_BYTE, IoMem_VoidRead_00, IoMem_VoidWrite },                            /* No bus errors here : return 0 not ff */
 	{ 0xff8262, SIZE_WORD, IoMem_ReadWithoutInterception, Video_TTShiftMode_WriteWord },    /* TT screen mode */
diff -r ced6489e1793 src/video.c
--- a/src/video.c	Fri Feb 26 23:36:01 2016 +0100
+++ b/src/video.c	Mon Feb 29 01:04:54 2016 +0200
@@ -487,6 +487,7 @@
 
 int TTSpecialVideoMode;				/* TT special video mode */
 static int nPrevTTSpecialVideoMode;		/* TT special video mode */
+static int TTPaletteSTBank;			/* which TT color bank ST palette maps */
 
 static int LastCycleScroll8264;			/* value of Cycles_GetCounterOnWriteAccess last time ff8264 was set for the current VBL */
 static int LastCycleScroll8265;			/* value of Cycles_GetCounterOnWriteAccess last time ff8265 was set for the current VBL */
@@ -604,8 +605,6 @@
 static void	Video_ColorReg_WriteWord(void);
 static void	Video_ColorReg_ReadWord(void);
 
-static void	Video_TTColorReg_Sync_ST2TT(Uint32 addr, Uint16 stcolor);
-
 
 /*-----------------------------------------------------------------------*/
 /**
@@ -646,6 +645,7 @@
 	MemorySnapShot_Store(&VblJitterIndex, sizeof(VblJitterIndex));
 	MemorySnapShot_Store(&ShifterFrame, sizeof(ShifterFrame));
 	MemorySnapShot_Store(&TTSpecialVideoMode, sizeof(TTSpecialVideoMode));
+	MemorySnapShot_Store(&TTPaletteSTBank, sizeof(TTPaletteSTBank));
 }
 
 
@@ -695,6 +695,7 @@
 	VblJitterIndex = 0;
 
 	TTSpecialVideoMode = nPrevTTSpecialVideoMode = 0;
+	TTPaletteSTBank = 0;
 
 	/* Clear framecycles counter */
 	Cycles_SetCounter(CYCLES_COUNTER_VIDEO, 0);
@@ -3054,6 +3055,12 @@
 		Uint32 ttpalette = 0xff8400;
 		int i, colors = 1 << bpp;
 
+		if (colors <= 16)
+		{
+			/* use correct ST palette bank */
+			ttpalette += TTPaletteSTBank * 16*SIZE_WORD;
+		}
+
 		for (i = 0; i < colors; i++)
 		{
 			Video_SetTTPaletteColor(i, ttpalette);
@@ -3663,12 +3670,6 @@
 	addr &= 0xfffffffe;			/* Ensure addr is even to store the 16 bit color */
 	IoMem_WriteWord(addr, col);		/* (some games write 0xFFFF and read back to see if STe) */
 
-	if (machine == MACHINE_TT)
-	{
-		Video_TTColorReg_Sync_ST2TT(addr, col);
-		return;
-	}
-
 	idx = (addr - 0xff8240) / 2;		/* words */
 
 	if (bUseHighRes || (bUseVDIRes && VDIPlanes == 1))
@@ -4119,12 +4120,32 @@
 		FrameCycles, LineCycles, nHBL, HblCounterVideo, M68000_GetPC(), CurrentInstrCycles );
 }
 
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Helper for TT->ST color reg copies
+ */
+static void TT2STColor(Uint32 ttaddr, Uint32 staddr)
+{
+	Uint16 stcolor, ttcolor;
+
+	ttcolor = IoMem_ReadWord(ttaddr);
+	stcolor = ((ttcolor & 0xeee) >> 1) | ((ttcolor&0x111) << 3);
+	IoMem_WriteWord(staddr, stcolor);
+#if 0
+	fprintf(stderr, "0x%x: 0x%03x (TT) -> 0x%x: 0x%03x (ST)\n",
+		ttaddr, ttcolor, staddr, stcolor);
+#endif
+}
+
 /*-----------------------------------------------------------------------*/
 /**
  * Write to TT shifter mode register (0xff8262)
  */
 void Video_TTShiftMode_WriteWord(void)
 {
+	int bank;
+
 	TTRes = IoMem_ReadByte(0xff8262) & 7;
 	TTSpecialVideoMode = IoMem_ReadByte(0xff8262) & 0x90;
 
@@ -4137,6 +4158,30 @@
 		Video_ShifterMode_WriteByte();
 		IoMem_WriteByte(0xff8262, TTRes | TTSpecialVideoMode);
 	}
+
+	/* ST palette needs to be updated on bank switch */
+	bank = IoMem_ReadByte(0xff8263) & 0x0f;
+	if (bank != TTPaletteSTBank)
+	{
+		Uint32 stpalette = 0xff8240;
+		Uint32 ttpalette = 0xff8400;
+		int i;
+#if 0
+		fprintf(stderr, "TT ST Palette bank change: %d -> %d\n",
+			TTPaletteSTBank, bank);
+#endif
+		TTPaletteSTBank = bank;
+		ttpalette += bank * 16*SIZE_WORD;
+
+		for (i = 0; i < 16*SIZE_WORD; i += SIZE_WORD)
+		{
+			TT2STColor(ttpalette, stpalette);
+			ttpalette += SIZE_WORD;
+			stpalette += SIZE_WORD;
+		}
+		/* in case there were <= 16 colors */
+		bTTColorsSync = false;
+	}
 }
 
 /*-----------------------------------------------------------------------*/
@@ -4153,16 +4198,13 @@
 {
 	const Uint32 stpalette = 0xff8240;
 	const Uint32 ttpalette = 0xff8400;
-	Uint16 stcolor, ttcolor;
-	int page, offset, i;
+	int offset, i;
 	Uint32 addr;
 
-	page = (IoMem_ReadWord(0xff8262) & 0x0f);
-
 	/* ensure even address for byte accesses */
 	addr = IoAccessCurrentAddress & 0xfffffffe;
 	
-	offset = addr - (ttpalette + page * 16*SIZE_WORD);
+	offset = addr - (ttpalette + TTPaletteSTBank * 16*SIZE_WORD);
 
 	/* in case it was long access */
 	for (i = 0; i < nIoMemAccessSize; i += 2)
@@ -4170,14 +4212,7 @@
 		/* outside ST->TT color reg mapping "page"? */
 		if (offset < 0 || offset >= 16*SIZE_WORD)
 			continue;
-
-		ttcolor = IoMem_ReadWord(addr);
-		stcolor = ((ttcolor >> 1) & 0x777) | ((ttcolor >> 3) & 0x888);
-		IoMem_WriteWord(stpalette + offset, stcolor);
-#if 0
-		fprintf(stderr, "0x%x: 0x%03x (TT) -> 0x%x: 0x%03x (ST)\n",
-			addr, ttcolor, stpalette + offset, stcolor);
-#endif
+		TT2STColor(addr, stpalette + offset);
 		offset += 2;
 		addr += 2;
 	}
@@ -4186,28 +4221,51 @@
 
 /*-----------------------------------------------------------------------*/
 /**
- * Write to ST color register on TT (starting at 0xff8240)
+ * Write to ST color register area on TT (starting at 0xff8240)
  *
- * Sync single ST color register value to TT register area
+ * ST color register write on TT -> sync to TT color register
+ *
+ * Although registers themselves are word sized, writes to this area
+ * can be of any size. Hatari IO-area handling doesn't feed them here
+ * word sized as that would require 256 different handlers.
  */
-static void Video_TTColorReg_Sync_ST2TT(Uint32 addr, Uint16 stcolor)
+void Video_TTColorRegs_STRegWrite(void)
 {
 	const Uint32 stpalette = 0xff8240;
 	const Uint32 ttpalette = 0xff8400;
-	int page, offset;
 	Uint16 ttcolor;
-
-	page = (IoMem_ReadWord(0xff8262) & 0x0f);
+	Uint16 stcolor;
+	int offset, i;
+	Uint32 addr;
+
+	/* byte writes don't have effect on TT */
+	if (nIoMemAccessSize < 2)
+		return;
+
+	addr = IoAccessCurrentAddress;
+
 	offset = addr - stpalette;
 	assert(offset > 0 && offset < 16*SIZE_WORD);
-	offset += page * 16*SIZE_WORD;
-
-	ttcolor = ((stcolor&0x777) << 1) | ((stcolor&0x888) >> 3);
-	IoMem_WriteWord(ttpalette + offset, ttcolor);
+	offset += TTPaletteSTBank * 16*SIZE_WORD;
+
+	/* in case it was long access */
+	for (i = 0; i < nIoMemAccessSize; i += 2)
+	{
+		/* program may write 0xFFFF and read it back
+		 * to check for STe palette so need to be masked
+		 */
+		stcolor = IoMem_ReadWord(addr) & 0xfff;
+		IoMem_WriteWord(addr, stcolor);
+		/* Sync ST(e) color to TT register */
+		ttcolor = ((stcolor & 0x777) << 1) | ((stcolor & 0x888) >> 3);
+		IoMem_WriteWord(ttpalette + offset, ttcolor);
 #if 0
-	fprintf(stderr, "0x%x: 0x%03x (ST) -> 0x%x: 0x%03x (TT)\n",
-		addr, stcolor, ttpalette + offset, ttcolor);
+		fprintf(stderr, "0x%x: 0x%03x (ST) -> 0x%x: 0x%03x (TT)\n",
+			addr, stcolor, ttpalette + offset, ttcolor);
 #endif
+		offset += 2;
+		addr += 2;
+	}
 	bTTColorsSync = false;
 }
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/