Re: [hatari-devel] Fix display of Atari logo with extended VDI resolutions

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


On Wednesday 16 November 2016 21:31:21 Thomas Huth wrote:
> I think you could use VDIWidth * VDIPlanes / 8 to calculate the current
> line length in bytes. But that of course only works in VDI mode - that's
> basically also why I suggested the TP_VDIRES below.

Well ok, i already knew about VDIWidth, but i was looking for something that 
just tells me the emulated screen size. Anyway, i have changed the patch now 
to only be applied if using extended VDI modes. I also just realized that the 
new routine fits within the replaced one, so there was no need to move it to 
the end of the ROM, which simplifies it a bit.

>Is that easier? We'd need to calc the CRC in that case, so I guess it's
>rather easier if we skip the CRC check in TOS?

I think yes, because you don't have to figure out where that CRC is calculated 
for different ROM versions. And it will help for programs that copy the ROM 
into RAM in order to modify it itself, like GEMRAM. I have added a patch that 
will just do that, just in case ;)

The third patch is for making the ROM for St-Book work. It is similar to 2.06 
(and even has 2.06 as version in the header), but makes some accesses to 
0xd00000 which i had to patch out (TOS 3.06 also makes an access to 0xd000e0 
very early, dunno why that does not give a buserror on Hatari). When setting 
the machine type to MSTE, this should work now.

Greetings,
Thorsten

PS.: just in case you did not know yet: A complete source version of TOS 
2.06/3.06 can be found at http://www.tho-otto.de/download/tos306de.tar.bz2
diff -r d527521e02dc src/tos.c
--- a/src/tos.c	Mon Nov 14 00:21:09 2016 +0200
+++ b/src/tos.c	Thu Nov 17 07:13:37 2016 +0100
@@ -113,6 +113,7 @@
 	TP_ANTI_STE,          /* Apply patch only if running on plain ST */
 	TP_ANTI_PMMU,         /* Apply patch only if no PMMU is available */
 	TP_FIX_060,           /* Apply patch only if CPU is 68060 */
+	TP_VDIRES,            /* Apply patch only if VDI is used */
 };
 
 /* This structure is used for patching the TOS ROMs */
@@ -135,6 +136,7 @@
 static const char pszNoPmmu[] = "disable PMMU access";
 static const char pszFix060[] = "replace code for 68060";
 static const char pszFalconExtraRAM[] = "enable extra TT RAM on Falcon";
+static const char pszAtariLogo[] = "draw Atari Logo";
 
 //static Uint8 pRtsOpcode[] = { 0x4E, 0x75 };  /* 0x4E75 = RTS */
 static const Uint8 pNopOpcodes[] = { 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
@@ -146,6 +148,45 @@
 static const Uint8 pRomCheckOpcode404[] = { 0x60, 0x00, 0x00, 0x94 };  /* BRA $e00746 */
 static const Uint8 pBraOpcode[] = { 0x60 };  /* 0x60XX = BRA */
 
+/*
+ * Routine for drawing the Atari logo.
+ * When this function is called, A0 contains a pointer to a 96x86x1 image.
+ * We cannot use the vdi yet (the screen workstation has not yet been opened),
+ * but we can take into account extended VDI modes.
+ */
+static const Uint8 pAtariLogo[] = {
+	0x3e, 0x3c, 0x00, 0x01,     /* move.w    #planes, d7; number will be patched below */
+	0x2c, 0x3c, 0, 0, 1, 64,    /* move.l    #linewidth, d6; number will be patched below */
+	0x22, 0x78, 0x04, 0x4e,     /* movea.l   (_v_bas_ad).w,a1 */
+	0xd3, 0xc6,                 /* adda.l    d6,a1 ; start drawing at 5th line */
+	0xd3, 0xc6,                 /* adda.l    d6,a1 */
+	0xd3, 0xc6,                 /* adda.l    d6,a1 */
+	0xd3, 0xc6,                 /* adda.l    d6,a1 */
+	0xd3, 0xc6,                 /* adda.l    d6,a1 */
+	0x30, 0x3c, 0x00, 0x55,     /* move.w    #$0055,d0 ; 86 lines of data */
+/* logocol1: */
+	0x72, 0x05,                 /* moveq.l   #5,d1 ; 6 words of data per line */
+	0x24, 0x49,                 /* movea.l   a1,a2 */
+/* logocol2: */
+	0x34, 0x18,                 /* move.w    (a0)+,d2 */
+	0x36, 0x07,                 /* move.w    d7,d3 */
+	0x53, 0x43,                 /* subq.w    #1,d3 */
+/* logocol3: */
+	0x34, 0xc2,                 /* move.w    d2,(a2)+ */
+	0x51, 0xcb, 0xff, 0xfc,     /* dbf       d3,logocol3 */
+	0x51, 0xc9, 0xff, 0xf2,     /* dbf       d1,logocol2 */
+	0xd3, 0xc6,                 /* adda.l    d6,a1 */
+	0x51, 0xc8, 0xff, 0xe8,     /* dbf       d0,logocol1 */
+	0x4e, 0x71,                 /* nops to end of original routine */
+	0x4e, 0x71,
+	0x4e, 0x71,
+	0x4e, 0x71,
+	0x4e, 0x71,
+	0x4e, 0x71,
+	0x4e, 0x71,
+	0x4e, 0x71
+};
+
 static const Uint8 p060movep1[] = {	/* replace MOVEP */
 	0x70, 0x0c,			/* moveq #12,d0 */
 	0x42, 0x30, 0x08, 0x00,		/* loop: clr.b 0,(d0,a0) */
@@ -235,12 +276,14 @@
   /* as we've changed bytes in the ROM! So, just skip anyway! */
   { 0x206, -1, pszRomCheck, TP_ALWAYS, 0xE007FA, 0x2E3C0001, 4, pRomCheckOpcode206 },
   { 0x206, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00898, 0x610000E0, 4, pNopOpcodes }, /* BSR.W $E0097A */
+  { 0x206, -1, pszAtariLogo, TP_VDIRES, 0xE0076C, 0x1038044c, sizeof( pAtariLogo ), pAtariLogo },
 
   { 0x306, -1, pszRomCheck, TP_ALWAYS, 0xE007D4, 0x2E3C0001, 4, pRomCheckOpcode306 },
   { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE00068, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE01702, 0xF0394C00, 32, pNopOpcodes }, /* pmove : CRP=80000002 00000700 TC=80f04445 TT0=017e8107 TT1=807e8507 -> */
   { 0x306, -1, pszFix060, TP_FIX_060, 0xe024dc, 0x01C80000, 12, p060movep1 },
   { 0x306, -1, pszFix060, TP_FIX_060, 0xe024fa, 0x01C80000, 12, p060movep1 },
+  { 0x306, -1, pszAtariLogo, TP_VDIRES, 0xE00754, 0x1038044c, sizeof( pAtariLogo ), pAtariLogo },
 
   { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE00064, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0148A, 0xF0394C00, 32, pNopOpcodes },
@@ -313,6 +356,7 @@
 	int nGoodPatches, nBadPatches;
 	short TosCountry;
 	const TOS_PATCH *pPatch;
+	Uint32 logopatch_addr = 0;
 
 	/* We can't patch RAM TOS images (yet) */
 	if (bRamTosImage && TosVersion != 0x0492)
@@ -348,6 +392,7 @@
 				        && ConfigureParams.System.bFastBoot)
 				    || (pPatch->Flags == TP_ANTI_STE && Config_IsMachineST())
 				    || (pPatch->Flags == TP_ANTI_PMMU && !use_mmu)
+				    || (pPatch->Flags == TP_VDIRES && bUseVDIRes)
 				    || (pPatch->Flags == TP_FIX_060 && ConfigureParams.System.nCpuLevel > 4)
 				   )
 				{
@@ -355,6 +400,8 @@
 					Log_Printf(LOG_DEBUG, "Applying TOS patch '%s'.\n", pPatch->pszName);
 					memcpy(&RomMem[pPatch->Address], pPatch->pNewData, pPatch->Size);
 					nGoodPatches += 1;
+					if (strcmp(pPatch->pszName, pszAtariLogo) == 0)
+						logopatch_addr = pPatch->Address;
 				}
 				else
 				{
@@ -371,6 +418,13 @@
 		pPatch += 1;
 	}
 
+	/* patch some values into the "Draw logo" patch */
+	if (logopatch_addr != 0)
+	{
+		STMemory_WriteWord(logopatch_addr + 2, VDIPlanes);
+		STMemory_WriteLong(logopatch_addr + 6, VDIWidth * VDIPlanes / 8);
+	}
+
 	Log_Printf(LOG_DEBUG, "Applied %i TOS patches, %i patches failed.\n",
 	           nGoodPatches, nBadPatches);
 }
diff --git a/src/tos.c b/src/tos.c
--- a/src/tos.c
+++ b/src/tos.c
@@ -131,7 +131,6 @@ typedef struct
 
 static const char pszDmaBoot[] = "boot from DMA bus";
 static const char pszMouse[] = "big resolutions mouse driver";
-static const char pszRomCheck[] = "ROM checksum";
 static const char pszNoSteHw[] = "disable STE hardware access";
 static const char pszNoPmmu[] = "disable PMMU access";
 static const char pszFix060[] = "replace code for 68060";
@@ -143,9 +142,6 @@ static const Uint8 pNopOpcodes[] = { 0x4
         0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
         0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71 };  /* 0x4E71 = NOP */
 static const Uint8 pMouseOpcode[] = { 0xD3, 0xC1 };  /* "ADDA.L D1,A1" (instead of "ADDA.W D1,A1") */
-static const Uint8 pRomCheckOpcode206[] = { 0x60, 0x00, 0x00, 0x98 };  /* BRA $e00894 */
-static const Uint8 pRomCheckOpcode306[] = { 0x60, 0x00, 0x00, 0xB0 };  /* BRA $e00886 */
-static const Uint8 pRomCheckOpcode404[] = { 0x60, 0x00, 0x00, 0x94 };  /* BRA $e00746 */
 static const Uint8 pBraOpcode[] = { 0x60 };  /* 0x60XX = BRA */
 
 /*
@@ -274,11 +270,9 @@ static const TOS_PATCH TosPatches[] =
   /* E007FA  MOVE.L  #$1FFFE,D7  Run checksums on 2xROMs (skip) */
   /* Checksum is total of TOS ROM image, but get incorrect results */
   /* as we've changed bytes in the ROM! So, just skip anyway! */
-  { 0x206, -1, pszRomCheck, TP_ALWAYS, 0xE007FA, 0x2E3C0001, 4, pRomCheckOpcode206 },
   { 0x206, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00898, 0x610000E0, 4, pNopOpcodes }, /* BSR.W $E0097A */
   { 0x206, -1, pszAtariLogo, TP_VDIRES, 0xE0076C, 0x1038044c, sizeof( pAtariLogo ), pAtariLogo },
 
-  { 0x306, -1, pszRomCheck, TP_ALWAYS, 0xE007D4, 0x2E3C0001, 4, pRomCheckOpcode306 },
   { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE00068, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE01702, 0xF0394C00, 32, pNopOpcodes }, /* pmove : CRP=80000002 00000700 TC=80f04445 TT0=017e8107 TT1=807e8507 -> */
   { 0x306, -1, pszFix060, TP_FIX_060, 0xe024dc, 0x01C80000, 12, p060movep1 },
@@ -288,28 +282,24 @@ static const TOS_PATCH TosPatches[] =
   { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE00064, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0148A, 0xF0394C00, 32, pNopOpcodes },
   { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE03948, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
-  { 0x400, -1, pszRomCheck, TP_ALWAYS, 0xE00686, 0x2E3C0007, 4, pRomCheckOpcode404 },
   { 0x400, -1, pszFix060, TP_FIX_060, 0xE0258A, 0x01C80000, 12, p060movep1 },
   { 0x400, -1, pszFix060, TP_FIX_060, 0xE025DA, 0x41F8FA01, 20, p060movep2 },
 
   { 0x401, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0006A, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x401, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE014A8, 0xF0394C00, 32, pNopOpcodes },
   { 0x401, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE03946, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
-  { 0x401, -1, pszRomCheck, TP_ALWAYS, 0xE006A6, 0x2E3C0007, 4, pRomCheckOpcode404 },
   { 0x401, -1, pszFix060, TP_FIX_060, 0xE02588, 0x01C80000, 12, p060movep1 },
   { 0x401, -1, pszFix060, TP_FIX_060, 0xE025D8, 0x41F8FA01, 20, p060movep2 },
 
   { 0x402, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0006A, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x402, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE014A8, 0xF0394C00, 32, pNopOpcodes },
   { 0x402, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE03946, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
-  { 0x402, -1, pszRomCheck, TP_ALWAYS, 0xE006A6, 0x2E3C0007, 4, pRomCheckOpcode404 },
   { 0x402, -1, pszFix060, TP_FIX_060, 0xE02588, 0x01C80000, 12, p060movep1 },
   { 0x402, -1, pszFix060, TP_FIX_060, 0xE025D8, 0x41F8FA01, 20, p060movep2 },
 
   { 0x404, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0006A, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x404, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE014E6, 0xF0394C00, 32, pNopOpcodes }, /* pmove : CRP=80000002 00000700 TC=80f04445 TT0=017e8107 TT1=807e8507 -> */
   { 0x404, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE039A0, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
-  { 0x404, -1, pszRomCheck, TP_ALWAYS, 0xE006B0, 0x2E3C0007, 4, pRomCheckOpcode404 },
   { 0x404, -1, pszDmaBoot, TP_ALWAYS, 0xE01C9E, 0x62FC31FC, 2, pNopOpcodes },  /* Just a delay */
   { 0x404, -1, pszDmaBoot, TP_ALWAYS, 0xE01CB2, 0x62FC31FC, 2, pNopOpcodes },  /* Just a delay */
   { 0x404, -1, pszFix060, TP_FIX_060, 0xE025E2, 0x01C80000, 12, p060movep1 },
@@ -344,6 +334,48 @@ void TOS_MemorySnapShot_Capture(bool bSa
 
 
 /*-----------------------------------------------------------------------*/
+
+static unsigned short const crc_tab[256] = {
+	0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
+	0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
+	0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
+	0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
+	0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
+	0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
+	0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
+	0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
+	0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
+	0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
+	0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+	0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
+	0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
+	0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
+	0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
+	0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
+};
+
+
+static unsigned short calc_crc(Uint32 pos, Uint32 size, Uint32 inc)
+{
+	unsigned short sum;
+	unsigned short run;
+	unsigned char *p;
+	
+	p = STMemory_STAddrToPointer(pos);
+	sum = run = 0;
+	do {
+		run = sum;
+		sum <<= 8;
+		run >>= 8;
+		run ^= *p;
+		sum ^= crc_tab[run];
+		p += inc;
+	} while (--size != 0);
+	return sum;
+}
+
+
+/*-----------------------------------------------------------------------*/
 /**
  * Patch TOS to skip some TOS setup code which we don't support/need.
  *
@@ -357,6 +389,11 @@ static void TOS_FixRom(void)
 	short TosCountry;
 	const TOS_PATCH *pPatch;
 	Uint32 logopatch_addr = 0;
+	Uint32 banksize;
+	Uint32 crcpos;
+	Uint16 crc, sum;
+	int i, banks;
+	int chip = 0;
 
 	/* We can't patch RAM TOS images (yet) */
 	if (bRamTosImage && TosVersion != 0x0492)
@@ -365,6 +402,71 @@ static void TOS_FixRom(void)
 		return;
 	}
 
+	/*
+	 * check the current crc.
+	 * not all tos versions perform a CRC check,
+	 * and the file that we loaded might have been patched already,
+	 * so we don't update the crc if it wasn't right before
+	 */
+	if ((TosVersion >= 0x400 && TosVersion < 0x500) && TosSize > 256 * 1024L)
+	{
+		/*
+		 * Falcon TOS 4.x: a single 512KB ROM
+		 */
+		banks = 1;
+		banksize = ((TosSize + 1) & ~1) - 2;
+	} else if ((TosVersion == 0x206 || TosVersion == 0x207 || TosVersion == 0x208) &&
+		TosSize > 256 * 1024L &&
+		!bIsEmuTOS)
+	{
+		/*
+		 * ST-Book TOS 2.x: a single 256KB ROM
+		 * The second half of the image contains a cartridge ROM
+		 */
+		banks = 1;
+		banksize = (((TosSize >> 1) + 1) & ~1) - 2;
+	} else if (TosSize > 256 * 1024L)
+	{
+		/*
+		 * TT TOS 3.x: 4 128KB ROMs
+		 */
+		banks = 4;
+		banksize = (((TosSize + 3) / 4) & ~1) - 2;
+	} else if (TosSize > 192 * 1024L)
+	{
+		/*
+		 * STE TOS 2.x: 2 128KB ROMs
+		 */
+		banks = 2;
+		banksize = (((TosSize + 1) / 2) & ~1) - 2;
+	} else
+	{
+		/*
+		 * TOS 1.x: 6 32KB ROMs, without CRC
+		 */
+		banks = -1;
+		banksize = 0;
+	}
+	if (banks > 0)
+	{
+		for (i = 0; i < banks; i++)
+		{
+			crc = calc_crc(TosAddress + i, banksize, banks);
+			crcpos = TosAddress + banksize * banks + i;
+			sum = (STMemory_ReadByte(crcpos) << 8) |
+			       STMemory_ReadByte(crcpos + banks);
+			if (crc != sum)
+			{
+				banks = 0;
+				chip = i & 1 ? 'O' : 'E';
+				break;
+			}
+		}
+	}
+	
+	if (banks == 0)
+		Log_Printf(LOG_WARN, "TOS: WARNING: BAD ROM CRC IN CHIP %c\n", chip);
+
 	nGoodPatches = nBadPatches = 0;
 	TosCountry = STMemory_ReadWord(TosAddress+28)>>1;   /* TOS country code */
 	pPatch = TosPatches;
@@ -425,6 +527,29 @@ static void TOS_FixRom(void)
 		STMemory_WriteLong(logopatch_addr + 6, VDIWidth * VDIPlanes / 8);
 	}
 
+	/*
+	 * Update the ROM crc if we patched anything,
+	 * the ROM does a crc check
+	 * and the crc was valid before our patches
+	 */
+	if (nGoodPatches != 0)
+	{
+		if (banks > 0)
+		{
+			for (i = 0; i < banks; i++)
+			{
+				crc = calc_crc(TosAddress + i, banksize, banks);
+				crcpos = TosAddress + banksize * banks + i;
+				STMemory_WriteByte(crcpos, crc >> 8);
+				STMemory_WriteByte(crcpos + banks, crc);
+			}
+			Log_Printf(LOG_DEBUG, "ROM checksum updated\n");
+		} else if (banks >= 0)
+		{
+			Log_Printf(LOG_INFO, "ROM checksum not updated\n");
+		}
+	}
+
 	Log_Printf(LOG_DEBUG, "Applied %i TOS patches, %i patches failed.\n",
 	           nGoodPatches, nBadPatches);
 }
diff --git a/src/tos.c b/src/tos.c
--- a/src/tos.c
+++ b/src/tos.c
@@ -136,6 +136,7 @@ static const char pszNoPmmu[] = "disable
 static const char pszFix060[] = "replace code for 68060";
 static const char pszFalconExtraRAM[] = "enable extra TT RAM on Falcon";
 static const char pszAtariLogo[] = "draw Atari Logo";
+static const char pszSTbook[] = "disable MCU access on ST-Book";
 
 //static Uint8 pRtsOpcode[] = { 0x4E, 0x75 };  /* 0x4E75 = RTS */
 static const Uint8 pNopOpcodes[] = { 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
@@ -273,6 +274,12 @@ static const TOS_PATCH TosPatches[] =
   { 0x206, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00898, 0x610000E0, 4, pNopOpcodes }, /* BSR.W $E0097A */
   { 0x206, -1, pszAtariLogo, TP_VDIRES, 0xE0076C, 0x1038044c, sizeof( pAtariLogo ), pAtariLogo },
 
+  { 0x208, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00806, 0x610000E8, 4, pNopOpcodes }, /* BSR.W $E008F0 */
+  { 0x208, -1, pszAtariLogo, TP_VDIRES, 0xE006B4, 0x1038044c, sizeof( pAtariLogo ), pAtariLogo },
+  { 0x208, -1, pszSTbook, TP_ALWAYS, 0xE00066, 0x303900d0, 18, pNopOpcodes },
+  { 0x208, -1, pszSTbook, TP_ALWAYS, 0xE000D6, 0x4a7900d0, 6, pNopOpcodes },
+  { 0x208, -1, pszSTbook, TP_ALWAYS, 0xE009FE, 0x303900d0, 14, pNopOpcodes },
+
   { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE00068, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
   { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE01702, 0xF0394C00, 32, pNopOpcodes }, /* pmove : CRP=80000002 00000700 TC=80f04445 TT0=017e8107 TT1=807e8507 -> */
   { 0x306, -1, pszFix060, TP_FIX_060, 0xe024dc, 0x01C80000, 12, p060movep1 },
@@ -895,7 +902,9 @@ int TOS_LoadImage(void)
 	/* Now, look at start of image to find Version number and address */
 	TosVersion = SDL_SwapBE16(*(Uint16 *)&pTosFile[2]);
 	TosAddress = SDL_SwapBE32(*(Uint32 *)&pTosFile[8]);
-
+	if (TosVersion == 0x206 && SDL_SwapBE16(*(Uint16 *)&pTosFile[30]) == 0x186A)
+		TosVersion = 0x208;
+	
 	/* Check for reasonable TOS version: */
 	if (TosVersion == 0x000 && TosSize == 16384)
 	{


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