Re: [hatari-devel] TT palette bankswitching should be supported |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
Hi,
Ok, attached is version of patch that updates SDL palette
whenever TT shifter is written.
Roger, your test program says this is fine. Could you
quickly check that the colors used by Hatari also look
similar as what you got on your TT?
- Eero
On 03/01/2016 08:55 PM, Thomas Huth wrote:
On 01.03.2016 18:55, Eero Tamminen wrote:
Main thing I'd like a comment on, is my addition of
TTPaletteSTBank variable which needs to be saved into
memory snapshots, making them incompatible with earlier
versions.
It's not strictly necessary to know current/previous bank
setting, but then SDL palette would need to be synched
every time something is written TT shifter register.
Which one you consider better?
Please try to avoid introducing duplicated state (i.e. an additional
variable) for things that are not really performance critical. For
something that is written so seldomly like the TT shifter, it's ok to
read the value everytime from IO memory when you need it.
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 Wed Mar 02 00:36:36 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 Wed Mar 02 00:36:36 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 Wed Mar 02 00:36:36 2016 +0200
@@ -604,8 +604,6 @@
static void Video_ColorReg_WriteWord(void);
static void Video_ColorReg_ReadWord(void);
-static void Video_TTColorReg_Sync_ST2TT(Uint32 addr, Uint16 stcolor);
-
/*-----------------------------------------------------------------------*/
/**
@@ -3032,6 +3030,14 @@
}
/**
+ * Which 256-color TT palette 16-color "bank" is mapped to ST(e) palette
+ */
+static int TTPaletteSTBank(void)
+{
+ return IoMem_ReadByte(0xff8263) & 0x0f;
+}
+
+/**
* Convert TT palette to SDL palette
*/
static void Video_UpdateTTPalette(int bpp)
@@ -3054,6 +3060,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 +3675,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 +4125,34 @@
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)
{
+ Uint32 stpalette = 0xff8240;
+ Uint32 ttpalette = 0xff8400;
+ int i;
+
TTRes = IoMem_ReadByte(0xff8262) & 7;
TTSpecialVideoMode = IoMem_ReadByte(0xff8262) & 0x90;
@@ -4137,8 +4165,23 @@
Video_ShifterMode_WriteByte();
IoMem_WriteByte(0xff8262, TTRes | TTSpecialVideoMode);
}
+
+ /* ST palette needs to be updated in case there was a bank switch */
+ ttpalette += TTPaletteSTBank() * 16*SIZE_WORD;
+#if 0
+ fprintf(stderr, "TT ST Palette bank: %d\n", TTPaletteSTBank());
+#endif
+ for (i = 0; i < 16*SIZE_WORD; i += SIZE_WORD)
+ {
+ TT2STColor(ttpalette, stpalette);
+ ttpalette += SIZE_WORD;
+ stpalette += SIZE_WORD;
+ }
+ /* in case bank was switched and there are <= 16 colors */
+ bTTColorsSync = false;
}
+
/*-----------------------------------------------------------------------*/
/**
* Write to TT color register area (at 0xff8400)
@@ -4153,31 +4196,21 @@
{
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)
{
- /* outside ST->TT color reg mapping "page"? */
+ /* outside ST->TT color reg mapping bank? */
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 +4219,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;
}