Annotation of hatari/src/tos.c, revision 1.1.1.10

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.10! root       18: char TOS_rcsid[] = "Hatari $Id: tos.c,v 1.29 2005/06/05 14:19:39 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"
                     25: #include "floppy.h"
1.1.1.4   root       26: #include "gemdos.h"
                     27: #include "hdc.h"
1.1.1.10! root       28: #include "ioMem.h"
        !            29: #include "log.h"
1.1       root       30: #include "m68000.h"
                     31: #include "memorySnapShot.h"
                     32: #include "stMemory.h"
                     33: #include "tos.h"
                     34: #include "vdi.h"
                     35: 
                     36: 
1.1.1.10! root       37: Uint16 TosVersion;                      /* eg, 0x0100, 0x0102 */
        !            38: Uint32 TosAddress, TosSize;             /* Address in ST memory and size of TOS image */
        !            39: BOOL bTosImageLoaded = FALSE;           /* Successfully loaded a TOS image? */
        !            40: BOOL bRamTosImage;                      /* TRUE if we loaded a RAM TOS image */
        !            41: unsigned int ConnectedDriveMask = 0x03; /* Bit mask of connected drives, eg 0x7 is A,B,C */
        !            42: 
        !            43: 
        !            44: /* Settings for different memory sizes */
        !            45: static const MEMORY_INFO MemoryInfo[] =
1.1.1.6   root       46: {
                     47:   { 0x80000,  0x01, 0x00080000 },    /* MEMORYSIZE_512 */
                     48:   { 0x100000, 0x05, 0x00100000 },    /* MEMORYSIZE_1024 */
                     49:   { 0x200000, 0x02, 0x00200000 },    /* MEMORYSIZE_2MB */
                     50:   { 0x400000, 0x0A, 0x00400000 }     /* MEMORYSIZE_4MB */
1.1       root       51: };
                     52: 
1.1.1.4   root       53: /* Bit masks of connected drives(we support up to C,D,E,F,G,H) */
1.1.1.10! root       54: static const unsigned int ConnectedDriveMaskList[] =
1.1.1.6   root       55: {
1.1       root       56:   0x03,  /* DRIVELIST_NONE  A,B         */
                     57:   0x07,  /* DRIVELIST_C    A,B,C       */
                     58:   0x0F,  /* DRIVELIST_CD    A,B,C,D     */
                     59:   0x1F,  /* DRIVELIST_CDE  A,B,C,D,E   */
                     60:   0x3F,  /* DRIVELIST_CDEF  A,B,C,D,E,F */
1.1.1.4   root       61:   0x7F,  /* DRIVELIST_CDEFG  A,B,C,D,E,F,G */
                     62:   0xFF,  /* DRIVELIST_CDEFGH  A,B,C,D,E,F,G,H */
1.1       root       63: };
                     64: 
                     65: /* Possible TOS file extensions to scan for */
1.1.1.10! root       66: static const char *pszTosNameExts[] =
1.1.1.6   root       67: {
1.1       root       68:   ".img",
                     69:   ".rom",
                     70:   ".tos",
                     71:   NULL
                     72: };
                     73: 
                     74: 
1.1.1.6   root       75: /* Flags that define if a TOS patch should be applied */
                     76: enum
1.1       root       77: {
1.1.1.6   root       78:   TP_ALWAYS,            /* Patch should alway be applied */
                     79:   TP_HD_ON,             /* Apply patch only if HD emulation is on */
                     80:   TP_HD_OFF             /* Apply patch only if HD emulation is off */
                     81: };
1.1.1.3   root       82: 
1.1.1.6   root       83: /* This structure is used for patching the TOS ROMs */
1.1.1.7   root       84: typedef struct
1.1       root       85: {
1.1.1.6   root       86:   Uint16 Version;       /* TOS version number */
                     87:   Sint16 Country;       /* TOS country code: -1 if it does not matter, 0=US, 1=Germany, 2=France, etc. */
1.1.1.10! root       88:   const char *pszName;  /* Name of the patch */
1.1.1.7   root       89:   int Flags;            /* When should the patch be applied? (see enum above) */
1.1.1.6   root       90:   Uint32 Address;       /* Where the patch should be applied */
                     91:   Uint32 OldData;       /* Expected first 4 old bytes */
                     92:   Uint32 Size;          /* Length of the patch */
1.1.1.10! root       93:   const void *pNewData; /* Pointer to the new bytes */
1.1.1.6   root       94: } TOS_PATCH;
                     95: 
1.1.1.10! root       96: static const char pszDmaBoot[] = "boot from DMA bus";
        !            97: static const char pszMouse[] = "working mouse in big screen resolutions";
        !            98: static const char pszRomCheck[] = "ROM checksum";
        !            99: static const char pszNoSteHw[] = "disable STE hardware access";
1.1.1.6   root      100: 
1.1.1.9   root      101: //static Uint8 pRtsOpcode[] = { 0x4E, 0x75 };  /* 0x4E75 = RTS */
1.1.1.10! root      102: static const Uint8 pNopOpcodes[] = { 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
1.1.1.6   root      103:         0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
                    104:         0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71 };  /* 0x4E71 = NOP */
1.1.1.10! root      105: static const Uint8 pMouseOpcode[] = { 0xD3, 0xC1 };  /* "ADDA.L D1,A1" (instead of "ADDA.W D1,A1") */
        !           106: static const Uint8 pRomCheckOpcode[] = { 0x60, 0x00, 0x00, 0x98 };  /* BRA $e00894 */
        !           107: static const Uint8 pBraOpcode[] = { 0x60 };  /* 0x60XX = BRA */
1.1       root      108: 
1.1.1.6   root      109: /* The patches for the TOS: */
1.1.1.10! root      110: static const TOS_PATCH TosPatches[] =
1.1.1.6   root      111: {
                    112:   { 0x100, -1, pszDmaBoot, TP_HD_OFF, 0xFC03D6, 0x610000D0, 4, pNopOpcodes }, /* BSR $FC04A8 */
                    113: 
                    114:   { 0x102, -1, pszDmaBoot, TP_HD_OFF, 0xFC0472, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC0558 */
                    115:   { 0x102, 0, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
                    116:   { 0x102, 1, pszMouse, TP_ALWAYS, 0xFD008A, 0xD2C147F9, 2, pMouseOpcode },
                    117:   { 0x102, 2, pszMouse, TP_ALWAYS, 0xFD00A8, 0xD2C147F9, 2, pMouseOpcode },
                    118:   { 0x102, 3, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
                    119:   { 0x102, 6, pszMouse, TP_ALWAYS, 0xFCFEF0, 0xD2C147F9, 2, pMouseOpcode },
                    120:   { 0x102, 8, pszMouse, TP_ALWAYS, 0xFCFEFE, 0xD2C147F9, 2, pMouseOpcode },
                    121: 
                    122:   { 0x104, -1, pszDmaBoot, TP_HD_OFF, 0xFC0466, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC054C */
                    123: 
1.1.1.10! root      124:   { 0x106, -1, pszDmaBoot, TP_HD_OFF, 0xE00576, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E0065C */
        !           125: 
        !           126:   { 0x162, -1, pszDmaBoot, TP_HD_OFF, 0xE00576, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E0065C */
        !           127: 
1.1.1.6   root      128:   { 0x205, -1, pszDmaBoot, TP_HD_OFF, 0xE006AE, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E00794 */
                    129:   /* An unpatched TOS 2.05 only works on STEs, so apply some anti-STE patches... */
                    130:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00096, 0x42788900, 4, pNopOpcodes }, /* CLR.W $FFFF8900 */
                    131:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE0009E, 0x31D88924, 4, pNopOpcodes }, /* MOVE.W (A0)+,$FFFF8924 */
                    132:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE000A6, 0x09D10AA9, 28, pNopOpcodes },
                    133:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE003A0, 0x30389200, 4, pNopOpcodes }, /* MOVE.W $ffff9200,D0 */
                    134:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE004EA, 0x61000CBC, 4, pNopOpcodes },
                    135:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00508, 0x61000C9E, 4, pNopOpcodes },
                    136:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE007A0, 0x631E2F3C, 1, pBraOpcode },
                    137:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00928, 0x10388901, 4, pNopOpcodes }, /* MOVE.B $FFFF8901,D0 */
                    138:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00944, 0xB0388901, 4, pNopOpcodes }, /* CMP.B $FFFF8901,D0 */
                    139:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00950, 0x67024601, 1, pBraOpcode },
                    140:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00968, 0x61000722, 4, pNopOpcodes },
                    141:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00CF2, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
                    142:   { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00E00, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
                    143:   { 0x205, 0, pszNoSteHw, TP_ALWAYS, 0xE03038, 0x31C0860E, 4, pNopOpcodes },
                    144:   { 0x205, 0, pszNoSteHw, TP_ALWAYS, 0xE034A8, 0x31C0860E, 4, pNopOpcodes },
                    145:   { 0x205, 0, pszNoSteHw, TP_ALWAYS, 0xE034F6, 0x31E90002, 6, pNopOpcodes },
                    146: 
                    147:   /* E007FA  MOVE.L  #$1FFFE,D7  Run checksums on 2xROMs (skip) */
                    148:   /* Checksum is total of TOS ROM image, but get incorrect results */
                    149:   /* as we've changed bytes in the ROM! So, just skip anyway! */
                    150:   { 0x206, -1, pszRomCheck, TP_ALWAYS, 0xE007FA, 0x2E3C0001, 4, pRomCheckOpcode },
                    151:   { 0x206, -1, pszDmaBoot, TP_HD_OFF, 0xE00898, 0x610000E0, 4, pNopOpcodes }, /* BSR.W $E0097A */
1.1       root      152: 
1.1.1.6   root      153:   { 0, 0, NULL, 0, 0, 0, 0, NULL }
                    154: };
1.1       root      155: 
                    156: 
                    157: 
1.1.1.6   root      158: /*-----------------------------------------------------------------------*/
                    159: /*
                    160:   Save/Restore snapshot of local variables ('MemorySnapShot_Store' handles type)
                    161: */
                    162: void TOS_MemorySnapShot_Capture(BOOL bSave)
                    163: {
                    164:   /* Save/Restore details */
                    165:   MemorySnapShot_Store(&TosVersion, sizeof(TosVersion));
                    166:   MemorySnapShot_Store(&TosAddress, sizeof(TosAddress));
                    167:   MemorySnapShot_Store(&TosSize, sizeof(TosSize));
                    168:   MemorySnapShot_Store(&ConnectedDriveMask, sizeof(ConnectedDriveMask));
1.1       root      169: }
                    170: 
1.1.1.3   root      171: 
                    172: /*-----------------------------------------------------------------------*/
1.1       root      173: /*
1.1.1.4   root      174:   Patch TOS to skip some TOS setup code which we don't support/need.
1.1       root      175: 
                    176:   So, how do we find these addresses when we have no commented source code?
1.1.1.10! root      177:   - For the "Boot from DMA bus" patch:
        !           178:     Scan at start of rom for tst.w $482, boot call will be just above it.
1.1       root      179: */
1.1.1.6   root      180: static void TOS_FixRom(void)
1.1       root      181: {
1.1.1.6   root      182:   int nGoodPatches, nBadPatches;
                    183:   short TosCountry;
                    184:   BOOL bHdIsOn;
1.1.1.10! root      185:   const TOS_PATCH *pPatch;
1.1       root      186: 
1.1.1.6   root      187:   /* Check for EmuTOS first since we can not patch it */
                    188:   if(STMemory_ReadLong(TosAddress+0x2c) == 0x45544F53)      /* 0x45544F53 = 'ETOS' */
                    189:   {
1.1.1.10! root      190:     Log_Printf(LOG_DEBUG, "Detected EmuTOS, skipping TOS patches.\n");
1.1.1.6   root      191:     return;
                    192:   }
1.1       root      193: 
1.1.1.7   root      194:   /* We also can't patch RAM TOS images (yet) */
                    195:   if(bRamTosImage)
                    196:   {
1.1.1.10! root      197:     Log_Printf(LOG_DEBUG, "Detected RAM TOS image, skipping TOS patches.\n");
1.1.1.7   root      198:     return;
                    199:   }
                    200: 
1.1.1.6   root      201:   nGoodPatches = nBadPatches = 0;
                    202:   TosCountry = STMemory_ReadWord(TosAddress+28)>>1;   /* TOS country code */
                    203:   bHdIsOn = (ACSI_EMU_ON || GEMDOS_EMU_ON);
                    204:   pPatch = TosPatches;
1.1       root      205: 
1.1.1.6   root      206:   /* Apply TOS patches: */
                    207:   while(pPatch->Version)
                    208:   {
1.1.1.7   root      209:     /* Only apply patches that suit to the actual TOS  version: */
1.1.1.6   root      210:     if(pPatch->Version == TosVersion
                    211:        && (pPatch->Country == TosCountry || pPatch->Country == -1))
                    212:     {
                    213:       /* Make sure that we really patch the right place by comparing data: */
                    214:       if(STMemory_ReadLong(pPatch->Address) == pPatch->OldData)
1.1.1.5   root      215:       {
1.1.1.6   root      216:         /* Only apply the patch if it is really needed: */
                    217:         if(pPatch->Flags == TP_ALWAYS || (pPatch->Flags == TP_HD_ON && bHdIsOn)
                    218:            || (pPatch->Flags == TP_HD_OFF && !bHdIsOn))
1.1.1.5   root      219:         {
1.1.1.6   root      220:           /* Now we can really apply the patch! */
                    221:           /*fprintf(stderr, "Applying TOS patch '%s'.\n", pPatch->pszName);*/
                    222:           memcpy(&STRam[pPatch->Address], pPatch->pNewData, pPatch->Size);
1.1.1.5   root      223:         }
1.1.1.6   root      224:         else
1.1.1.5   root      225:         {
1.1.1.6   root      226:           /*fprintf(stderr, "Skipped patch '%s'.\n", pPatch->pszName);*/
1.1.1.5   root      227:         }
1.1.1.6   root      228:         nGoodPatches += 1;
1.1.1.5   root      229:       }
                    230:       else
                    231:       {
1.1.1.10! root      232:         Log_Printf(LOG_DEBUG, "Failed to apply TOS patch '%s' at %x (expected %x, found %x).\n",
        !           233:                    pPatch->pszName, pPatch->Address, pPatch->OldData, STMemory_ReadLong(pPatch->Address));
1.1.1.6   root      234:         nBadPatches += 1;
1.1.1.5   root      235:       }
1.1.1.6   root      236:     }
                    237:     pPatch += 1;
                    238:   }
1.1       root      239: 
1.1.1.10! root      240:   Log_Printf(LOG_DEBUG, "Applied %i TOS patches, %i patches failed.\n",
        !           241:              nGoodPatches, nBadPatches);
1.1       root      242: }
                    243: 
1.1.1.3   root      244: 
                    245: /*-----------------------------------------------------------------------*/
1.1       root      246: /*
                    247:   Set default memory configuration, connected floppies and memory size
                    248: */
1.1.1.6   root      249: static void TOS_SetDefaultMemoryConfig(void)
1.1       root      250: {
1.1.1.3   root      251:   /* As TOS checks hardware for memory size + connected devices on boot-up */
                    252:   /* we set these values ourselves and fill in the magic numbers so TOS */
                    253:   /* skips these tests which would crash the emulator as the reference the MMU */
                    254: 
                    255:   /* Fill in magic numbers, so TOS does not try to reference MMU */
1.1.1.6   root      256:   STMemory_WriteLong(0x420, 0x752019f3);        /* memvalid - configuration is valid */
                    257:   STMemory_WriteLong(0x43a, 0x237698aa);        /* another magic # */
                    258:   STMemory_WriteLong(0x51a, 0x5555aaaa);        /* and another */
1.1       root      259: 
1.1.1.3   root      260:   /* Set memory size, adjust for extra VDI screens if needed */
1.1.1.5   root      261:   if (bUseVDIRes)
                    262:   {
1.1.1.3   root      263:     /* This is enough for 1024x768x16colour (0x60000) */
1.1.1.6   root      264:     STMemory_WriteLong(0x436, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop-0x60000);  /* mem top - upper end of user memory (before 32k screen) */
                    265:     STMemory_WriteLong(0x42e, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop-0x58000);  /* phys top */
1.1       root      266:   }
1.1.1.5   root      267:   else
                    268:   {
1.1.1.9   root      269:     STMemory_WriteLong(0x436, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop-0x8000);   /* mem top - upper end of user memory (before 32k screen) */
1.1.1.6   root      270:     STMemory_WriteLong(0x42e, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop);          /* phys top */
1.1       root      271:   }
1.1.1.6   root      272:   STMemory_WriteByte(0x424, MemoryInfo[ConfigureParams.Memory.nMemorySize].MemoryConfig);
                    273:   STMemory_WriteByte(0xff8001, MemoryInfo[ConfigureParams.Memory.nMemorySize].MemoryConfig);
1.1       root      274: 
1.1.1.7   root      275:   /* Set memory range */
1.1.1.3   root      276:   STRamEnd = MemoryInfo[ConfigureParams.Memory.nMemorySize].MemoryEnd;  /* Set end of RAM */
                    277: 
                    278:   /* Set TOS floppies */
1.1.1.6   root      279:   STMemory_WriteWord(0x446, nBootDrive);          /* Boot up on A(0) or C(2) */
1.1.1.9   root      280:   //STMemory_WriteWord(0x4a6, 0x2);                 /* Connected floppies A,B (0 or 2) */
1.1.1.4   root      281: 
1.1.1.3   root      282:   ConnectedDriveMask = ConnectedDriveMaskList[ConfigureParams.HardDisc.nDriveList];
1.1.1.4   root      283: 
1.1.1.6   root      284:   STMemory_WriteLong(0x4c2, ConnectedDriveMask);  /* Drives A,B and C - NOTE some TOS images overwrite value, see 'TOS_ConnectedDrive_OpCode' */
1.1       root      285: 
1.1.1.3   root      286:   /* Mirror ROM boot vectors */
1.1.1.6   root      287:   STMemory_WriteLong(0x00, STMemory_ReadLong(TosAddress));
                    288:   STMemory_WriteLong(0x04, STMemory_ReadLong(TosAddress+4));
1.1.1.7   root      289: 
                    290:   /* Initialize the memory banks: */
                    291:   memory_uninit();
                    292:   memory_init(STRamEnd, 0, TosAddress);
1.1.1.6   root      293: }
                    294: 
                    295: 
                    296: /*-----------------------------------------------------------------------*/
                    297: /*
                    298:   Load TOS Rom image file into ST memory space and fix image so can emulate correctly
                    299:   Pre TOS 1.06 are loaded at 0xFC0000 with later ones at 0xE00000
                    300: */
                    301: int TOS_LoadImage(void)
                    302: {
1.1.1.10! root      303:   Uint8 *pTosFile = NULL;
1.1.1.6   root      304: 
                    305:   bTosImageLoaded = FALSE;
                    306: 
                    307:   /* Load TOS image into memory so we can check it's vesion */
                    308:   TosVersion = 0;
1.1.1.9   root      309:   pTosFile = File_Read(ConfigureParams.Rom.szTosImageFileName, NULL, NULL, pszTosNameExts);
                    310:   TosSize = File_Length(ConfigureParams.Rom.szTosImageFileName);
1.1.1.6   root      311: 
                    312:   if(pTosFile && TosSize>0)
                    313:   {
1.1.1.7   root      314:     /* Check for RAM TOS images first: */
1.1.1.8   root      315:     if(SDL_SwapBE32(*(Uint32 *)pTosFile) == 0x46FC2700)
1.1.1.7   root      316:     {
1.1.1.10! root      317:       Log_Printf(LOG_WARN, "Detected a RAM TOS - this will probably not work very well!\n");
1.1.1.7   root      318:       /* RAM TOS images have a 256 bytes loader function before the real image
                    319:        * starts, so we simply skip the first 256 bytes here: */
                    320:       TosSize -= 0x100;
                    321:       memmove(pTosFile, pTosFile + 0x100, TosSize);
                    322:       bRamTosImage = TRUE;
                    323:     }
                    324:     else
                    325:     {
                    326:       bRamTosImage = FALSE;
                    327:     }
                    328: 
1.1.1.6   root      329:     /* Now, look at start of image to find Version number and address */
1.1.1.10! root      330:     TosVersion = SDL_SwapBE16(*(Uint16 *)&pTosFile[2]);
        !           331:     TosAddress = SDL_SwapBE32(*(Uint32 *)&pTosFile[8]);
1.1.1.6   root      332: 
                    333:     /* Check for reasonable TOS version: */
                    334:     if(TosVersion<0x100 || TosVersion>0x500 || TosSize>1024*1024L
1.1.1.7   root      335:        || (!bRamTosImage && TosAddress!=0xe00000 && TosAddress!=0xfc0000))
1.1.1.6   root      336:     {
1.1.1.10! root      337:       Log_AlertDlg(LOG_FATAL, "Your TOS image seems not to be a valid TOS ROM file!\n"
        !           338:                               "(TOS version %x, address $%x)", TosVersion, TosAddress);
1.1.1.6   root      339:       return -2;
                    340:     }
                    341: 
1.1.1.10! root      342:     /* TOSes 1.06 and 1.62 are for the STE ONLY and so don't run on a real ST. */
1.1.1.6   root      343:     /* They access illegal memory addresses which don't exist on a real machine and cause the OS */
1.1.1.10! root      344:     /* to lock up. So, if user selects one of these, switch to STE mode. */
        !           345:     if ((TosVersion == 0x0106 || TosVersion == 0x0162) && ConfigureParams.System.nMachineType != MACHINE_STE)
1.1.1.6   root      346:     {
1.1.1.10! root      347:       Log_AlertDlg(LOG_INFO, "TOS versions 1.06 and 1.62\nare NOT valid ST ROM images.\n"
        !           348:                              " => Switching to STE mode now.\n");
        !           349:       IoMem_UnInit();
        !           350:       ConfigureParams.System.nMachineType = MACHINE_STE;
        !           351:       IoMem_Init();
1.1.1.6   root      352:     }
                    353: 
                    354:     /* Copy loaded image into ST memory */
1.1.1.10! root      355:     memcpy(STRam+TosAddress, pTosFile, TosSize);
1.1.1.6   root      356:   }
                    357:   else
                    358:   {
1.1.1.10! root      359:     Log_AlertDlg(LOG_FATAL, "Can not load TOS file:\n'%s'", ConfigureParams.Rom.szTosImageFileName);
1.1.1.6   root      360:     return -1;
                    361:   }
                    362: 
1.1.1.10! root      363:   Log_Printf(LOG_DEBUG, "Loaded TOS version %i.%c%c, starting at $%x, "
1.1.1.6   root      364:           "country code = %i, %s\n", TosVersion>>8, '0'+((TosVersion>>4)&0x0f),
                    365:           '0'+(TosVersion&0x0f), TosAddress, STMemory_ReadWord(TosAddress+28)>>1,
                    366:           (STMemory_ReadWord(TosAddress+28)&1)?"PAL":"NTSC");
                    367: 
                    368:   /* Are we allowed VDI under this TOS? */
1.1.1.10! root      369:   if (TosVersion == 0x0100 && bUseVDIRes)
1.1.1.6   root      370:   {
1.1.1.10! root      371:     /* Warn user */
        !           372:     Log_AlertDlg(LOG_WARN, "To use GEM extended resolutions, you must select a TOS >= 1.02.");
1.1.1.6   root      373:     /* And select non VDI */
1.1.1.9   root      374:     bUseVDIRes = ConfigureParams.Screen.bUseExtVdiResolutions = FALSE;
1.1.1.6   root      375:   }
                    376: 
                    377:   /* Fix TOS image, modify code for emulation */
                    378:   TOS_FixRom();
                    379: 
                    380:   /* Set connected devices, memory configuration */
                    381:   TOS_SetDefaultMemoryConfig();
                    382: 
                    383:   /* and free loaded image */
1.1.1.10! root      384:   free(pTosFile);
1.1.1.6   root      385: 
                    386:   bTosImageLoaded = TRUE;
                    387:   return 0;
1.1       root      388: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.