|
|
1.1 root 1: /*
1.1.1.6 root 2: Hatari - tos.c
1.1 root 3:
1.1.1.6 root 4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
1.1 root 6:
1.1.1.6 root 7: Load TOS image file into ST memory, fix/setup for emulator.
8:
9: The Atari ST TOS needs to be patched to help with emulation. Eg, it references
10: the MMU chip to set memory size. This is patched to the sizes we need without
11: the complicated emulation of hardware which is not needed (as yet). We also
12: patch DMA devices and Hard Drives.
13: NOTE: TOS versions 1.06 and 1.62 were not designed for use on a real STfm.
14: These were for the STe machine ONLY. They access the DMA/Microwire addresses
15: on boot-up which (correctly) cause a bus-error on Hatari as they would in a
16: real STfm. If a user tries to select any of these images we bring up an error.
1.1 root 17: */
1.1.1.13! root 18: const char TOS_rcsid[] = "Hatari $Id: tos.c,v 1.54 2007/12/18 18:56:19 thothy Exp $";
1.1 root 19:
1.1.1.8 root 20: #include <SDL_endian.h>
1.1.1.4 root 21:
1.1 root 22: #include "main.h"
1.1.1.9 root 23: #include "configuration.h"
1.1 root 24: #include "file.h"
1.1.1.4 root 25: #include "gemdos.h"
26: #include "hdc.h"
1.1.1.10 root 27: #include "ioMem.h"
28: #include "log.h"
1.1 root 29: #include "m68000.h"
30: #include "memorySnapShot.h"
31: #include "stMemory.h"
32: #include "tos.h"
33: #include "vdi.h"
34:
35:
1.1.1.10 root 36: Uint16 TosVersion; /* eg, 0x0100, 0x0102 */
37: Uint32 TosAddress, TosSize; /* Address in ST memory and size of TOS image */
38: BOOL bTosImageLoaded = FALSE; /* Successfully loaded a TOS image? */
39: BOOL bRamTosImage; /* TRUE if we loaded a RAM TOS image */
40: unsigned int ConnectedDriveMask = 0x03; /* Bit mask of connected drives, eg 0x7 is A,B,C */
1.1.1.11 root 41: int nNumDrives = 2; /* Number of drives, default is 2 for A: and B: */
1.1.1.10 root 42:
43:
1.1 root 44: /* Possible TOS file extensions to scan for */
1.1.1.12 root 45: static const char * const pszTosNameExts[] =
1.1.1.6 root 46: {
1.1.1.12 root 47: ".img",
48: ".rom",
49: ".tos",
50: NULL
1.1 root 51: };
52:
53:
1.1.1.6 root 54: /* Flags that define if a TOS patch should be applied */
55: enum
1.1 root 56: {
1.1.1.12 root 57: TP_ALWAYS, /* Patch should alway be applied */
1.1.1.13! root 58: TP_HDIMAGE_OFF, /* Apply patch only if HD emulation is off */
1.1.1.12 root 59: TP_ANTI_STE /* Apply patch only if running on plain ST */
1.1.1.6 root 60: };
1.1.1.3 root 61:
1.1.1.6 root 62: /* This structure is used for patching the TOS ROMs */
1.1.1.7 root 63: typedef struct
1.1 root 64: {
1.1.1.12 root 65: Uint16 Version; /* TOS version number */
66: Sint16 Country; /* TOS country code: -1 if it does not matter, 0=US, 1=Germany, 2=France, etc. */
67: const char *pszName; /* Name of the patch */
68: int Flags; /* When should the patch be applied? (see enum above) */
69: Uint32 Address; /* Where the patch should be applied */
70: Uint32 OldData; /* Expected first 4 old bytes */
71: Uint32 Size; /* Length of the patch */
72: const void *pNewData; /* Pointer to the new bytes */
1.1.1.6 root 73: } TOS_PATCH;
74:
1.1.1.10 root 75: static const char pszDmaBoot[] = "boot from DMA bus";
1.1.1.13! root 76: static const char pszMouse[] = "big resolutions mouse driver";
1.1.1.10 root 77: static const char pszRomCheck[] = "ROM checksum";
78: static const char pszNoSteHw[] = "disable STE hardware access";
1.1.1.12 root 79: static const char pszNoPmmu[] = "disable PMMU access";
1.1.1.13! root 80: static const char pszHwDisable[] = "disable hardware access";
1.1.1.6 root 81:
1.1.1.9 root 82: //static Uint8 pRtsOpcode[] = { 0x4E, 0x75 }; /* 0x4E75 = RTS */
1.1.1.10 root 83: static const Uint8 pNopOpcodes[] = { 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
1.1.1.6 root 84: 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
1.1.1.12 root 85: 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71 }; /* 0x4E71 = NOP */
1.1.1.10 root 86: static const Uint8 pMouseOpcode[] = { 0xD3, 0xC1 }; /* "ADDA.L D1,A1" (instead of "ADDA.W D1,A1") */
1.1.1.13! root 87: static const Uint8 pRomCheckOpcode206[] = { 0x60, 0x00, 0x00, 0x98 }; /* BRA $e00894 */
! 88: static const Uint8 pRomCheckOpcode306[] = { 0x60, 0x00, 0x00, 0xB0 }; /* BRA $e00886 */
! 89: static const Uint8 pRomCheckOpcode404[] = { 0x60, 0x00, 0x00, 0x94 }; /* BRA $e00746 */
1.1.1.10 root 90: static const Uint8 pBraOpcode[] = { 0x60 }; /* 0x60XX = BRA */
1.1 root 91:
1.1.1.6 root 92: /* The patches for the TOS: */
1.1.1.10 root 93: static const TOS_PATCH TosPatches[] =
1.1.1.6 root 94: {
1.1.1.13! root 95: { 0x100, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xFC03D6, 0x610000D0, 4, pNopOpcodes }, /* BSR $FC04A8 */
1.1.1.6 root 96:
1.1.1.13! root 97: { 0x102, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xFC0472, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC0558 */
1.1.1.6 root 98: { 0x102, 0, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
99: { 0x102, 1, pszMouse, TP_ALWAYS, 0xFD008A, 0xD2C147F9, 2, pMouseOpcode },
100: { 0x102, 2, pszMouse, TP_ALWAYS, 0xFD00A8, 0xD2C147F9, 2, pMouseOpcode },
101: { 0x102, 3, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
102: { 0x102, 6, pszMouse, TP_ALWAYS, 0xFCFEF0, 0xD2C147F9, 2, pMouseOpcode },
103: { 0x102, 8, pszMouse, TP_ALWAYS, 0xFCFEFE, 0xD2C147F9, 2, pMouseOpcode },
104:
1.1.1.13! root 105: { 0x104, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xFC0466, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC054C */
1.1.1.6 root 106:
1.1.1.13! root 107: { 0x106, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00576, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E0065C */
1.1.1.10 root 108:
1.1.1.13! root 109: { 0x162, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00576, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E0065C */
1.1.1.10 root 110:
1.1.1.13! root 111: { 0x205, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE006AE, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E00794 */
1.1.1.6 root 112: /* An unpatched TOS 2.05 only works on STEs, so apply some anti-STE patches... */
1.1.1.11 root 113: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00096, 0x42788900, 4, pNopOpcodes }, /* CLR.W $FFFF8900 */
114: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE0009E, 0x31D88924, 4, pNopOpcodes }, /* MOVE.W (A0)+,$FFFF8924 */
115: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE000A6, 0x09D10AA9, 28, pNopOpcodes },
116: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE003A0, 0x30389200, 4, pNopOpcodes }, /* MOVE.W $ffff9200,D0 */
117: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE004EA, 0x61000CBC, 4, pNopOpcodes },
118: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00508, 0x61000C9E, 4, pNopOpcodes },
119: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE007A0, 0x631E2F3C, 1, pBraOpcode },
120: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00928, 0x10388901, 4, pNopOpcodes }, /* MOVE.B $FFFF8901,D0 */
121: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00944, 0xB0388901, 4, pNopOpcodes }, /* CMP.B $FFFF8901,D0 */
122: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00950, 0x67024601, 1, pBraOpcode },
123: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00968, 0x61000722, 4, pNopOpcodes },
124: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00CF2, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
125: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00E00, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
126: { 0x205, 0, pszNoSteHw, TP_ANTI_STE, 0xE03038, 0x31C0860E, 4, pNopOpcodes },
127: { 0x205, 0, pszNoSteHw, TP_ANTI_STE, 0xE034A8, 0x31C0860E, 4, pNopOpcodes },
128: { 0x205, 0, pszNoSteHw, TP_ANTI_STE, 0xE034F6, 0x31E90002, 6, pNopOpcodes },
1.1.1.6 root 129:
130: /* E007FA MOVE.L #$1FFFE,D7 Run checksums on 2xROMs (skip) */
131: /* Checksum is total of TOS ROM image, but get incorrect results */
132: /* as we've changed bytes in the ROM! So, just skip anyway! */
1.1.1.13! root 133: { 0x206, -1, pszRomCheck, TP_ALWAYS, 0xE007FA, 0x2E3C0001, 4, pRomCheckOpcode206 },
! 134: { 0x206, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00898, 0x610000E0, 4, pNopOpcodes }, /* BSR.W $E0097A */
1.1 root 135:
1.1.1.13! root 136: { 0x306, -1, pszRomCheck, TP_ALWAYS, 0xE007D4, 0x2E3C0001, 4, pRomCheckOpcode306 },
1.1.1.12 root 137: { 0x306, -1, pszNoPmmu, TP_ALWAYS, 0xE00068, 0xF0394000, 24, pNopOpcodes },
138: { 0x306, -1, pszNoPmmu, TP_ALWAYS, 0xE01702, 0xF0394C00, 32, pNopOpcodes },
139:
1.1.1.13! root 140: { 0x400, -1, pszNoPmmu, TP_ALWAYS, 0xE00064, 0xF0394000, 24, pNopOpcodes },
! 141: { 0x400, -1, pszNoPmmu, TP_ALWAYS, 0xE0148A, 0xF0394C00, 32, pNopOpcodes },
! 142: { 0x400, -1, pszNoPmmu, TP_ALWAYS, 0xE03948, 0xF0394000, 24, pNopOpcodes },
! 143: { 0x400, -1, pszRomCheck, TP_ALWAYS, 0xE00686, 0x2E3C0007, 4, pRomCheckOpcode404 },
! 144:
! 145: { 0x401, -1, pszNoPmmu, TP_ALWAYS, 0xE0006A, 0xF0394000, 24, pNopOpcodes },
! 146: { 0x401, -1, pszNoPmmu, TP_ALWAYS, 0xE014A8, 0xF0394C00, 32, pNopOpcodes },
! 147: { 0x401, -1, pszNoPmmu, TP_ALWAYS, 0xE03946, 0xF0394000, 24, pNopOpcodes },
! 148: { 0x401, -1, pszRomCheck, TP_ALWAYS, 0xE006A6, 0x2E3C0007, 4, pRomCheckOpcode404 },
! 149:
! 150: { 0x402, -1, pszNoPmmu, TP_ALWAYS, 0xE0006A, 0xF0394000, 24, pNopOpcodes },
! 151: { 0x402, -1, pszNoPmmu, TP_ALWAYS, 0xE014A8, 0xF0394C00, 32, pNopOpcodes },
! 152: { 0x402, -1, pszNoPmmu, TP_ALWAYS, 0xE03946, 0xF0394000, 24, pNopOpcodes },
! 153: { 0x402, -1, pszRomCheck, TP_ALWAYS, 0xE006A6, 0x2E3C0007, 4, pRomCheckOpcode404 },
! 154:
! 155: { 0x404, -1, pszNoPmmu, TP_ALWAYS, 0xE0006A, 0xF0394000, 24, pNopOpcodes },
! 156: { 0x404, -1, pszNoPmmu, TP_ALWAYS, 0xE014E6, 0xF0394C00, 32, pNopOpcodes },
! 157: { 0x404, -1, pszNoPmmu, TP_ALWAYS, 0xE039A0, 0xF0394000, 24, pNopOpcodes },
! 158: { 0x404, -1, pszRomCheck, TP_ALWAYS, 0xE006B0, 0x2E3C0007, 4, pRomCheckOpcode404 },
! 159:
! 160: { 0x492, -1, pszNoPmmu, TP_ALWAYS, 0x00F946, 0xF0394000, 24, pNopOpcodes },
! 161: { 0x492, -1, pszNoPmmu, TP_ALWAYS, 0x01097A, 0xF0394C00, 32, pNopOpcodes },
! 162: { 0x492, -1, pszNoPmmu, TP_ALWAYS, 0x012E04, 0xF0394000, 24, pNopOpcodes },
! 163:
1.1.1.6 root 164: { 0, 0, NULL, 0, 0, 0, 0, NULL }
165: };
1.1 root 166:
167:
168:
1.1.1.6 root 169: /*-----------------------------------------------------------------------*/
1.1.1.13! root 170: /**
! 171: * Save/Restore snapshot of local variables ('MemorySnapShot_Store' handles type)
! 172: */
1.1.1.6 root 173: void TOS_MemorySnapShot_Capture(BOOL bSave)
174: {
1.1.1.12 root 175: /* Save/Restore details */
176: MemorySnapShot_Store(&TosVersion, sizeof(TosVersion));
177: MemorySnapShot_Store(&TosAddress, sizeof(TosAddress));
178: MemorySnapShot_Store(&TosSize, sizeof(TosSize));
179: MemorySnapShot_Store(&ConnectedDriveMask, sizeof(ConnectedDriveMask));
180: MemorySnapShot_Store(&nNumDrives, sizeof(nNumDrives));
1.1 root 181: }
182:
1.1.1.3 root 183:
184: /*-----------------------------------------------------------------------*/
1.1.1.13! root 185: /**
! 186: * Patch TOS to skip some TOS setup code which we don't support/need.
! 187: *
! 188: * So, how do we find these addresses when we have no commented source code?
! 189: * - For the "Boot from DMA bus" patch:
! 190: * Scan at start of rom for tst.w $482, boot call will be just above it.
! 191: */
1.1.1.6 root 192: static void TOS_FixRom(void)
1.1 root 193: {
1.1.1.12 root 194: int nGoodPatches, nBadPatches;
195: short TosCountry;
196: const TOS_PATCH *pPatch;
197:
1.1.1.13! root 198: /* We can't patch RAM TOS images (yet) */
! 199: if (bRamTosImage && TosVersion != 0x0492)
1.1.1.12 root 200: {
201: Log_Printf(LOG_DEBUG, "Detected RAM TOS image, skipping TOS patches.\n");
202: return;
203: }
204:
205: nGoodPatches = nBadPatches = 0;
206: TosCountry = STMemory_ReadWord(TosAddress+28)>>1; /* TOS country code */
207: pPatch = TosPatches;
208:
209: /* Apply TOS patches: */
210: while (pPatch->Version)
211: {
212: /* Only apply patches that suit to the actual TOS version: */
213: if (pPatch->Version == TosVersion
214: && (pPatch->Country == TosCountry || pPatch->Country == -1))
215: {
216: /* Make sure that we really patch the right place by comparing data: */
217: if(STMemory_ReadLong(pPatch->Address) == pPatch->OldData)
218: {
219: /* Only apply the patch if it is really needed: */
1.1.1.13! root 220: if (pPatch->Flags == TP_ALWAYS
! 221: || (pPatch->Flags == TP_HDIMAGE_OFF && !ACSI_EMU_ON && !ConfigureParams.HardDisk.bUseIdeHardDiskImage)
1.1.1.12 root 222: || (pPatch->Flags == TP_ANTI_STE && ConfigureParams.System.nMachineType == MACHINE_ST))
223: {
224: /* Now we can really apply the patch! */
1.1.1.13! root 225: Log_Printf(LOG_DEBUG, "Applying TOS patch '%s'.\n", pPatch->pszName);
! 226: memcpy(&RomMem[pPatch->Address], pPatch->pNewData, pPatch->Size);
1.1.1.12 root 227: nGoodPatches += 1;
228: }
229: else
230: {
1.1.1.13! root 231: Log_Printf(LOG_DEBUG, "Skipped patch '%s'.\n", pPatch->pszName);
1.1.1.12 root 232: }
233: }
234: else
235: {
236: Log_Printf(LOG_DEBUG, "Failed to apply TOS patch '%s' at %x (expected %x, found %x).\n",
237: pPatch->pszName, pPatch->Address, pPatch->OldData, STMemory_ReadLong(pPatch->Address));
238: nBadPatches += 1;
239: }
240: }
241: pPatch += 1;
242: }
1.1.1.3 root 243:
1.1.1.12 root 244: Log_Printf(LOG_DEBUG, "Applied %i TOS patches, %i patches failed.\n",
245: nGoodPatches, nBadPatches);
1.1.1.6 root 246: }
247:
248:
249: /*-----------------------------------------------------------------------*/
1.1.1.13! root 250: /**
! 251: * Assert that TOS version matches the machine type and change the system
! 252: * configuration if necessary.
! 253: * For example TOSes 1.06 and 1.62 are for the STE ONLY and so don't run
! 254: * on a real ST, TOS 3.0x is TT only and TOS 4.x is Falcon only.
! 255: * These TOS version access illegal memory addresses on machine they were
! 256: * not designed for and so cause the OS to lock up. So, if user selects one
! 257: * of these, switch to the appropriate machine type.
! 258: */
! 259: static void TOS_CheckSysConfig(void)
! 260: {
! 261: if ((TosVersion == 0x0106 || TosVersion == 0x0162) && ConfigureParams.System.nMachineType != MACHINE_STE)
! 262: {
! 263: Log_AlertDlg(LOG_INFO, "TOS versions 1.06 and 1.62 are for Atari STE only.\n"
! 264: " ==> Switching to STE mode now.\n");
! 265: IoMem_UnInit();
! 266: ConfigureParams.System.nMachineType = MACHINE_STE;
! 267: IoMem_Init();
! 268: }
! 269: else if ((TosVersion & 0x0f00) == 0x0300 && ConfigureParams.System.nMachineType != MACHINE_TT)
! 270: {
! 271: Log_AlertDlg(LOG_INFO, "TOS versions 3.0x are for Atari TT only.\n"
! 272: " ==> Switching to TT mode now.\n");
! 273: IoMem_UnInit();
! 274: ConfigureParams.System.nMachineType = MACHINE_TT;
! 275: IoMem_Init();
! 276: ConfigureParams.System.nCpuLevel = 3;
! 277: M68000_CheckCpuLevel();
! 278: }
! 279: else if ((TosVersion & 0x0f00) == 0x0400 && ConfigureParams.System.nMachineType != MACHINE_FALCON)
! 280: {
! 281: Log_AlertDlg(LOG_INFO, "TOS versions 4.x are for Atari Falcon only.\n"
! 282: " ==> Switching to Falcon mode now.\n");
! 283: IoMem_UnInit();
! 284: ConfigureParams.System.nMachineType = MACHINE_FALCON;
! 285: IoMem_Init();
! 286: ConfigureParams.System.nCpuLevel = 3;
! 287: M68000_CheckCpuLevel();
! 288: }
! 289: else if ((TosVersion < 0x0300 && ConfigureParams.System.nMachineType == MACHINE_FALCON)
! 290: || (TosVersion < 0x0200 && ConfigureParams.System.nMachineType == MACHINE_TT))
! 291: {
! 292: Log_AlertDlg(LOG_INFO, "This TOS versions does not work in TT/Falcon mode.\n"
! 293: " ==> Switching to STE mode now.\n");
! 294: IoMem_UnInit();
! 295: ConfigureParams.System.nMachineType = MACHINE_STE;
! 296: IoMem_Init();
! 297: if (TosVersion <= 0x0104)
! 298: {
! 299: ConfigureParams.System.nCpuLevel = 0;
! 300: M68000_CheckCpuLevel();
! 301: }
! 302: }
! 303: }
! 304:
! 305:
! 306: /*-----------------------------------------------------------------------*/
! 307: /**
! 308: * Load TOS Rom image file into ST memory space and fix image so can emulate correctly
! 309: * Pre TOS 1.06 are loaded at 0xFC0000 with later ones at 0xE00000
! 310: */
1.1.1.6 root 311: int TOS_LoadImage(void)
312: {
1.1.1.12 root 313: Uint8 *pTosFile = NULL;
314: long nFileSize;
1.1.1.13! root 315: BOOL bIsEmuTOS;
1.1.1.6 root 316:
1.1.1.12 root 317: bTosImageLoaded = FALSE;
1.1.1.6 root 318:
1.1.1.12 root 319: /* Load TOS image into memory so we can check it's vesion */
320: TosVersion = 0;
1.1.1.13! root 321: pTosFile = File_Read(ConfigureParams.Rom.szTosImageFileName, &nFileSize, pszTosNameExts);
1.1.1.12 root 322:
323: if (!pTosFile || nFileSize <= 0)
324: {
325: Log_AlertDlg(LOG_FATAL, "Can not load TOS file:\n'%s'", ConfigureParams.Rom.szTosImageFileName);
326: return -1;
327: }
328:
329: TosSize = nFileSize;
330:
331: /* Check for RAM TOS images first: */
332: if (SDL_SwapBE32(*(Uint32 *)pTosFile) == 0x46FC2700)
333: {
1.1.1.13! root 334: int nRamTosLoaderSize;
1.1.1.12 root 335: Log_Printf(LOG_WARN, "Detected a RAM TOS - this will probably not work very well!\n");
336: /* RAM TOS images have a 256 bytes loader function before the real image
1.1.1.13! root 337: * starts (34 bytes for TOS 4.92). Since we directly copy the image to the right
! 338: * location later, we simply skip this additional header here: */
! 339: if (SDL_SwapBE32(*(Uint32 *)(pTosFile+34)) == 0x602E0492)
! 340: nRamTosLoaderSize = 0x22;
! 341: else
! 342: nRamTosLoaderSize = 0x100;
! 343: TosSize -= nRamTosLoaderSize;
! 344: memmove(pTosFile, pTosFile + nRamTosLoaderSize, TosSize);
1.1.1.12 root 345: bRamTosImage = TRUE;
346: }
347: else
348: {
349: bRamTosImage = FALSE;
350: }
351:
1.1.1.13! root 352: /* Check for EmuTOS ... (0x45544F53 = 'ETOS') */
! 353: bIsEmuTOS = (SDL_SwapBE32(*(Uint32 *)&pTosFile[0x2c]) == 0x45544F53);
! 354:
1.1.1.12 root 355: /* Now, look at start of image to find Version number and address */
356: TosVersion = SDL_SwapBE16(*(Uint16 *)&pTosFile[2]);
357: TosAddress = SDL_SwapBE32(*(Uint32 *)&pTosFile[8]);
358:
359: /* Check for reasonable TOS version: */
1.1.1.13! root 360: if (TosVersion<0x100 || TosVersion>=0x500 || TosSize>1024*1024L
1.1.1.12 root 361: || (!bRamTosImage && TosAddress!=0xe00000 && TosAddress!=0xfc0000))
362: {
363: Log_AlertDlg(LOG_FATAL, "Your TOS image seems not to be a valid TOS ROM file!\n"
364: "(TOS version %x, address $%x)", TosVersion, TosAddress);
365: return -2;
366: }
367:
1.1.1.13! root 368: /* Assert that machine type matches the TOS version. Note that EmuTOS can
! 369: * handle all machine types, so we don't do the system check there: */
! 370: if (!bIsEmuTOS)
! 371: TOS_CheckSysConfig();
! 372:
! 373: /* Calculate end of RAM */
! 374: if (ConfigureParams.Memory.nMemorySize > 0
! 375: && ConfigureParams.Memory.nMemorySize <= 14)
! 376: STRamEnd = ConfigureParams.Memory.nMemorySize * 0x100000;
! 377: else
! 378: STRamEnd = 0x80000; /* 512 KiB */
! 379:
! 380: /* (Re-)Initialize the memory banks: */
! 381: memory_uninit();
! 382: memory_init(STRamEnd, 0, TosAddress);
! 383:
! 384: /* Clear Upper memory (ROM and IO memory) */
! 385: memset(&RomMem[0xe00000], 0, 0x200000);
1.1.1.12 root 386:
387: /* Copy loaded image into ST memory */
1.1.1.13! root 388: memcpy(&RomMem[TosAddress], pTosFile, TosSize);
1.1.1.12 root 389:
390: Log_Printf(LOG_DEBUG, "Loaded TOS version %i.%c%c, starting at $%x, "
391: "country code = %i, %s\n", TosVersion>>8, '0'+((TosVersion>>4)&0x0f),
392: '0'+(TosVersion&0x0f), TosAddress, STMemory_ReadWord(TosAddress+28)>>1,
393: (STMemory_ReadWord(TosAddress+28)&1)?"PAL":"NTSC");
394:
395: /* Are we allowed VDI under this TOS? */
396: if (TosVersion == 0x0100 && bUseVDIRes)
397: {
398: /* Warn user */
399: Log_AlertDlg(LOG_WARN, "To use GEM extended resolutions, you must select a TOS >= 1.02.");
400: /* And select non VDI */
401: bUseVDIRes = ConfigureParams.Screen.bUseExtVdiResolutions = FALSE;
402: }
403:
404: /* Fix TOS image, modify code for emulation */
1.1.1.13! root 405: if (!bIsEmuTOS)
! 406: TOS_FixRom();
1.1.1.12 root 407:
408: /* Set connected devices, memory configuration, etc. */
409: STMemory_SetDefaultConfig();
1.1.1.6 root 410:
1.1.1.12 root 411: /* and free loaded image */
412: free(pTosFile);
1.1.1.6 root 413:
1.1.1.12 root 414: bTosImageLoaded = TRUE;
1.1.1.6 root 415:
1.1.1.12 root 416: return 0;
1.1 root 417: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.