|
|
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.9 ! root 18: char TOS_rcsid[] = "Hatari $Id: tos.c,v 1.23 2004/12/09 21:06:37 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 "debug.h"
25: #include "errlog.h"
26: #include "file.h"
27: #include "floppy.h"
1.1.1.4 root 28: #include "gemdos.h"
29: #include "hdc.h"
1.1 root 30: #include "m68000.h"
31: #include "memAlloc.h"
32: #include "memorySnapShot.h"
33: #include "stMemory.h"
34: #include "tos.h"
35: #include "vdi.h"
36:
37:
38: /* Settings for differnt memory sizes */
1.1.1.6 root 39: static MEMORY_INFO MemoryInfo[] =
40: {
41: { 0x80000, 0x01, 0x00080000 }, /* MEMORYSIZE_512 */
42: { 0x100000, 0x05, 0x00100000 }, /* MEMORYSIZE_1024 */
43: { 0x200000, 0x02, 0x00200000 }, /* MEMORYSIZE_2MB */
44: { 0x400000, 0x0A, 0x00400000 } /* MEMORYSIZE_4MB */
1.1 root 45: };
46:
1.1.1.4 root 47: /* Bit masks of connected drives(we support up to C,D,E,F,G,H) */
1.1.1.6 root 48: unsigned int ConnectedDriveMaskList[] =
49: {
1.1 root 50: 0x03, /* DRIVELIST_NONE A,B */
51: 0x07, /* DRIVELIST_C A,B,C */
52: 0x0F, /* DRIVELIST_CD A,B,C,D */
53: 0x1F, /* DRIVELIST_CDE A,B,C,D,E */
54: 0x3F, /* DRIVELIST_CDEF A,B,C,D,E,F */
1.1.1.4 root 55: 0x7F, /* DRIVELIST_CDEFG A,B,C,D,E,F,G */
56: 0xFF, /* DRIVELIST_CDEFGH A,B,C,D,E,F,G,H */
1.1 root 57: };
58:
1.1.1.6 root 59: unsigned short int TosVersion; /* eg, 0x0100, 0x0102 */
60: unsigned long TosAddress, TosSize; /* Address in ST memory and size of TOS image */
61: BOOL bTosImageLoaded = FALSE; /* Successfully loaded a TOS image? */
1.1.1.7 root 62: BOOL bRamTosImage; /* TRUE if we loaded a RAM TOS image */
1.1 root 63: unsigned int ConnectedDriveMask=0x03; /* Bit mask of connected drives, eg 0x7 is A,B,C */
64:
65: /* Possible TOS file extensions to scan for */
1.1.1.6 root 66: char *pszTosNameExts[] =
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. */
88: 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.7 root 93: void *pNewData; /* Pointer to the new bytes */
1.1.1.6 root 94: } TOS_PATCH;
95:
1.1.1.9 ! root 96: //static char pszHdvInit[] = "hdv_init - initialize drives"; // obsolete - will be removed soon
! 97: //static char pszHdvBoot[] = "hdv_boot - load boot sector"; // obsolete - will be removed soon
1.1.1.6 root 98: static char pszDmaBoot[] = "boot from DMA bus";
1.1.1.9 ! root 99: //static char pszSetConDrv[] = "set connected drives mask"; // obsolete - will be removed soon
! 100: //static char pszClrConDrv[] = "clear connected drives mask"; // obsolete - will be removed soon
1.1.1.6 root 101: static char pszMouse[] = "working mouse in big screen resolutions";
102: static char pszRomCheck[] = "ROM checksum";
103: static char pszNoSteHw[] = "disable STE hardware access";
104:
1.1.1.9 ! root 105: //static Uint8 pRtsOpcode[] = { 0x4E, 0x75 }; /* 0x4E75 = RTS */
1.1.1.6 root 106: static Uint8 pNopOpcodes[] = { 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
107: 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
108: 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71 }; /* 0x4E71 = NOP */
109: static Uint8 pMouseOpcode[] = { 0xD3, 0xC1 }; /* "ADDA.L D1,A1" (instead of "ADDA.W D1,A1") */
110: static Uint8 pRomCheckOpcode[] = { 0x60, 0x00, 0x00, 0x98 }; /* BRA $e00894 */
111: static Uint8 pBraOpcode[] = { 0x60 }; /* 0x60XX = BRA */
1.1 root 112:
1.1.1.6 root 113: /* The patches for the TOS: */
114: static TOS_PATCH TosPatches[] =
115: {
1.1.1.9 ! root 116: //{ 0x100, -1, pszHdvInit, TP_ALWAYS, 0xFC0D60, 0x4E56FFF0, 2, pRtsOpcode },
! 117: //{ 0x100, -1, pszHdvBoot, TP_ALWAYS, 0xFC1384, 0x4EB900FC, 6, pNopOpcodes }, /* JSR $FC0AF8 */
1.1.1.6 root 118: { 0x100, -1, pszDmaBoot, TP_HD_OFF, 0xFC03D6, 0x610000D0, 4, pNopOpcodes }, /* BSR $FC04A8 */
119:
1.1.1.9 ! root 120: //{ 0x102, -1, pszHdvInit, TP_ALWAYS, 0xFC0F44, 0x4E56FFF0, 2, pRtsOpcode },
! 121: //{ 0x102, -1, pszHdvBoot, TP_ALWAYS, 0xFC1568, 0x4EB900FC, 6, pNopOpcodes }, /* JSR $FC0C2E */
1.1.1.7 root 122: //{ 0x102, -1, pszClrConDrv, TP_HD_OFF, 0xFC0302, 0x42B90000, 6, pNopOpcodes }, /* CLR.L $4C2 */
1.1.1.6 root 123: { 0x102, -1, pszDmaBoot, TP_HD_OFF, 0xFC0472, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC0558 */
124: { 0x102, 0, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
125: { 0x102, 1, pszMouse, TP_ALWAYS, 0xFD008A, 0xD2C147F9, 2, pMouseOpcode },
126: { 0x102, 2, pszMouse, TP_ALWAYS, 0xFD00A8, 0xD2C147F9, 2, pMouseOpcode },
127: { 0x102, 3, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
128: { 0x102, 6, pszMouse, TP_ALWAYS, 0xFCFEF0, 0xD2C147F9, 2, pMouseOpcode },
129: { 0x102, 8, pszMouse, TP_ALWAYS, 0xFCFEFE, 0xD2C147F9, 2, pMouseOpcode },
130:
1.1.1.9 ! root 131: //{ 0x104, -1, pszHdvInit, TP_ALWAYS, 0xFC16BA, 0x4E56FFF0, 2, pRtsOpcode },
! 132: //{ 0x104, -1, pszHdvBoot, TP_ALWAYS, 0xFC1CCE, 0x4EB900FC, 6, pNopOpcodes }, /* JSR $FC0BD8 */
1.1.1.7 root 133: //{ 0x104, -1, pszClrConDrv, TP_HD_OFF, 0xFC02E6, 0x42AD04C2, 4, pNopOpcodes }, /* CLR.L $4C2(A5) */
1.1.1.6 root 134: { 0x104, -1, pszDmaBoot, TP_HD_OFF, 0xFC0466, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC054C */
135:
1.1.1.7 root 136: //{ 0x205, -1, pszClrConDrv, TP_HD_OFF, 0xE002FC, 0x42B804C2, 4, pNopOpcodes }, /* CLR.L $4C2 */
1.1.1.6 root 137: { 0x205, -1, pszDmaBoot, TP_HD_OFF, 0xE006AE, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E00794 */
1.1.1.9 ! root 138: //{ 0x205, 0, pszHdvInit, TP_ALWAYS, 0xE0468C, 0x4E56FFF0, 2, pRtsOpcode },
! 139: //{ 0x205, 1, pszHdvInit, TP_ALWAYS, 0xE046E6, 0x4E56FFF0, 2, pRtsOpcode },
! 140: //{ 0x205, 2, pszHdvInit, TP_ALWAYS, 0xE04704, 0x4E56FFF0, 2, pRtsOpcode },
! 141: //{ 0x205, 4, pszHdvInit, TP_ALWAYS, 0xE04712, 0x4E56FFF0, 2, pRtsOpcode },
! 142: //{ 0x205, 5, pszHdvInit, TP_ALWAYS, 0xE046F4, 0x4E56FFF0, 2, pRtsOpcode },
! 143: //{ 0x205, 6, pszHdvInit, TP_ALWAYS, 0xE04704, 0x4E56FFF0, 2, pRtsOpcode },
! 144: //{ 0x205, 0, pszHdvBoot, TP_ALWAYS, 0xE04CA0, 0x4EB900E0, 6, pNopOpcodes }, /* JSR $E00E8E */
! 145: //{ 0x205, 1, pszHdvBoot, TP_ALWAYS, 0xE04CFA, 0x4EB900E0, 6, pNopOpcodes },
! 146: //{ 0x205, 2, pszHdvBoot, TP_ALWAYS, 0xE04D18, 0x4EB900E0, 6, pNopOpcodes },
! 147: //{ 0x205, 4, pszHdvBoot, TP_ALWAYS, 0xE04D26, 0x4EB900E0, 6, pNopOpcodes },
! 148: //{ 0x205, 5, pszHdvBoot, TP_ALWAYS, 0xE04D08, 0x4EB900E0, 6, pNopOpcodes },
! 149: //{ 0x205, 6, pszHdvBoot, TP_ALWAYS, 0xE04D18, 0x4EB900E0, 6, pNopOpcodes },
1.1.1.6 root 150: /* An unpatched TOS 2.05 only works on STEs, so apply some anti-STE patches... */
151: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00096, 0x42788900, 4, pNopOpcodes }, /* CLR.W $FFFF8900 */
152: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE0009E, 0x31D88924, 4, pNopOpcodes }, /* MOVE.W (A0)+,$FFFF8924 */
153: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE000A6, 0x09D10AA9, 28, pNopOpcodes },
154: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE003A0, 0x30389200, 4, pNopOpcodes }, /* MOVE.W $ffff9200,D0 */
155: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE004EA, 0x61000CBC, 4, pNopOpcodes },
156: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00508, 0x61000C9E, 4, pNopOpcodes },
157: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE007A0, 0x631E2F3C, 1, pBraOpcode },
158: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00928, 0x10388901, 4, pNopOpcodes }, /* MOVE.B $FFFF8901,D0 */
159: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00944, 0xB0388901, 4, pNopOpcodes }, /* CMP.B $FFFF8901,D0 */
160: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00950, 0x67024601, 1, pBraOpcode },
161: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00968, 0x61000722, 4, pNopOpcodes },
162: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00CF2, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
163: { 0x205, -1, pszNoSteHw, TP_ALWAYS, 0xE00E00, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
164: { 0x205, 0, pszNoSteHw, TP_ALWAYS, 0xE03038, 0x31C0860E, 4, pNopOpcodes },
165: { 0x205, 0, pszNoSteHw, TP_ALWAYS, 0xE034A8, 0x31C0860E, 4, pNopOpcodes },
166: { 0x205, 0, pszNoSteHw, TP_ALWAYS, 0xE034F6, 0x31E90002, 6, pNopOpcodes },
167:
168: /* E007FA MOVE.L #$1FFFE,D7 Run checksums on 2xROMs (skip) */
169: /* Checksum is total of TOS ROM image, but get incorrect results */
170: /* as we've changed bytes in the ROM! So, just skip anyway! */
171: { 0x206, -1, pszRomCheck, TP_ALWAYS, 0xE007FA, 0x2E3C0001, 4, pRomCheckOpcode },
1.1.1.9 ! root 172: //{ 0x206, -1, pszClrConDrv, TP_HD_OFF, 0xE00362, 0x42B804C2, 4, pNopOpcodes }, /* CLR.L $4C2 */
1.1.1.6 root 173: { 0x206, -1, pszDmaBoot, TP_HD_OFF, 0xE00898, 0x610000E0, 4, pNopOpcodes }, /* BSR.W $E0097A */
1.1.1.9 ! root 174: //{ 0x206, 0, pszHdvInit, TP_ALWAYS, 0xE0518E, 0x4E56FFF0, 2, pRtsOpcode },
! 175: //{ 0x206, 1, pszHdvInit, TP_ALWAYS, 0xE051E8, 0x4E56FFF0, 2, pRtsOpcode },
! 176: //{ 0x206, 2, pszHdvInit, TP_ALWAYS, 0xE05206, 0x4E56FFF0, 2, pRtsOpcode },
! 177: //{ 0x206, 3, pszHdvInit, TP_ALWAYS, 0xE0518E, 0x4E56FFF0, 2, pRtsOpcode },
! 178: //{ 0x206, 6, pszHdvInit, TP_ALWAYS, 0xE05206, 0x4E56FFF0, 2, pRtsOpcode },
! 179: //{ 0x206, 8, pszHdvInit, TP_ALWAYS, 0xE05214, 0x4E56FFF0, 2, pRtsOpcode },
! 180: //{ 0x206, 0, pszHdvBoot, TP_ALWAYS, 0xE05944, 0x4EB900E0, 6, pNopOpcodes }, /* JSR $E011DC */
! 181: //{ 0x206, 1, pszHdvBoot, TP_ALWAYS, 0xE0599E, 0x4EB900E0, 6, pNopOpcodes },
! 182: //{ 0x206, 2, pszHdvBoot, TP_ALWAYS, 0xE059BC, 0x4EB900E0, 6, pNopOpcodes },
! 183: //{ 0x206, 3, pszHdvBoot, TP_ALWAYS, 0xE05944, 0x4EB900E0, 6, pNopOpcodes },
! 184: //{ 0x206, 6, pszHdvBoot, TP_ALWAYS, 0xE059BC, 0x4EB900E0, 6, pNopOpcodes },
! 185: //{ 0x206, 8, pszHdvBoot, TP_ALWAYS, 0xE059CA, 0x4EB900E0, 6, pNopOpcodes },
1.1 root 186:
1.1.1.6 root 187: { 0, 0, NULL, 0, 0, 0, 0, NULL }
188: };
1.1 root 189:
190:
191:
1.1.1.6 root 192: /*-----------------------------------------------------------------------*/
193: /*
194: Save/Restore snapshot of local variables ('MemorySnapShot_Store' handles type)
195: */
196: void TOS_MemorySnapShot_Capture(BOOL bSave)
197: {
198: /* Save/Restore details */
199: MemorySnapShot_Store(&TosVersion, sizeof(TosVersion));
200: MemorySnapShot_Store(&TosAddress, sizeof(TosAddress));
201: MemorySnapShot_Store(&TosSize, sizeof(TosSize));
202: MemorySnapShot_Store(&ConnectedDriveMask, sizeof(ConnectedDriveMask));
1.1 root 203: }
204:
1.1.1.3 root 205:
206: /*-----------------------------------------------------------------------*/
1.1 root 207: /*
1.1.1.4 root 208: Patch TOS to skip some TOS setup code which we don't support/need.
1.1 root 209:
210: So, how do we find these addresses when we have no commented source code?
1.1.1.6 root 211: - Hdv_init: Scan start of TOS for table of move.l <addr>,$46A(a5), around 0x224 bytes in
212: and look at the first entry - that's the hdv_init address.
213: - Hdv_boot: Scan start of TOS for table of move.l <addr>,$47A(a5), and look for 5th entry,
214: that's the hdv_boot address. The function starts with link,movem,jsr.
215: - Boot from DMA bus: again scan at start of rom for tst.w $482, boot call will be just above it.
216: - Clear connected drives: search for 'clr.w' and '$4c2' to find, may use (a5) in which case op-code
217: is only 4 bytes and also note this is only do on TOS > 1.00
218:
219: If we use hard disk emulation, we also need to force set condrv ($4c2),
220: because the ACSI driver (if any) will reset it. This is done after the DMA
221: bus boot (when the driver loads), replacing the RTS with our own routine which
222: sets condrv and then RTSes.
1.1 root 223: */
1.1.1.6 root 224: static void TOS_FixRom(void)
1.1 root 225: {
1.1.1.6 root 226: int nGoodPatches, nBadPatches;
227: short TosCountry;
228: BOOL bHdIsOn;
229: TOS_PATCH *pPatch;
1.1 root 230:
1.1.1.6 root 231: /* Check for EmuTOS first since we can not patch it */
232: if(STMemory_ReadLong(TosAddress+0x2c) == 0x45544F53) /* 0x45544F53 = 'ETOS' */
233: {
234: fprintf(stderr, "Detected EmuTOS, skipping TOS patches.\n");
235: return;
236: }
1.1 root 237:
1.1.1.7 root 238: /* We also can't patch RAM TOS images (yet) */
239: if(bRamTosImage)
240: {
241: fprintf(stderr, "RAM TOS image --> skipping TOS patches.\n");
242: return;
243: }
244:
1.1.1.6 root 245: nGoodPatches = nBadPatches = 0;
246: TosCountry = STMemory_ReadWord(TosAddress+28)>>1; /* TOS country code */
247: bHdIsOn = (ACSI_EMU_ON || GEMDOS_EMU_ON);
248: pPatch = TosPatches;
1.1 root 249:
1.1.1.6 root 250: /* Apply TOS patches: */
251: while(pPatch->Version)
252: {
1.1.1.7 root 253: /* Only apply patches that suit to the actual TOS version: */
1.1.1.6 root 254: if(pPatch->Version == TosVersion
255: && (pPatch->Country == TosCountry || pPatch->Country == -1))
256: {
257: /* Make sure that we really patch the right place by comparing data: */
258: if(STMemory_ReadLong(pPatch->Address) == pPatch->OldData)
1.1.1.5 root 259: {
1.1.1.6 root 260: /* Only apply the patch if it is really needed: */
261: if(pPatch->Flags == TP_ALWAYS || (pPatch->Flags == TP_HD_ON && bHdIsOn)
262: || (pPatch->Flags == TP_HD_OFF && !bHdIsOn))
1.1.1.5 root 263: {
1.1.1.6 root 264: /* Now we can really apply the patch! */
265: /*fprintf(stderr, "Applying TOS patch '%s'.\n", pPatch->pszName);*/
266: memcpy(&STRam[pPatch->Address], pPatch->pNewData, pPatch->Size);
1.1.1.5 root 267: }
1.1.1.6 root 268: else
1.1.1.5 root 269: {
1.1.1.6 root 270: /*fprintf(stderr, "Skipped patch '%s'.\n", pPatch->pszName);*/
1.1.1.5 root 271: }
1.1.1.6 root 272: nGoodPatches += 1;
1.1.1.5 root 273: }
274: else
275: {
1.1.1.8 root 276: fprintf(stderr, "Failed to apply TOS patch '%s' at %x (expected %x, found %x).\n",
1.1.1.7 root 277: pPatch->pszName, pPatch->Address, pPatch->OldData, STMemory_ReadLong(pPatch->Address));
1.1.1.6 root 278: nBadPatches += 1;
1.1.1.5 root 279: }
1.1.1.6 root 280: }
281: pPatch += 1;
282: }
1.1 root 283:
1.1.1.6 root 284: fprintf(stderr, "Applied %i TOS patches, %i patches failed.\n",
285: nGoodPatches, nBadPatches);
1.1 root 286: }
287:
1.1.1.3 root 288:
289: /*-----------------------------------------------------------------------*/
1.1 root 290: /*
291: Set default memory configuration, connected floppies and memory size
292: */
1.1.1.6 root 293: static void TOS_SetDefaultMemoryConfig(void)
1.1 root 294: {
1.1.1.3 root 295: /* As TOS checks hardware for memory size + connected devices on boot-up */
296: /* we set these values ourselves and fill in the magic numbers so TOS */
297: /* skips these tests which would crash the emulator as the reference the MMU */
298:
299: /* Fill in magic numbers, so TOS does not try to reference MMU */
1.1.1.6 root 300: STMemory_WriteLong(0x420, 0x752019f3); /* memvalid - configuration is valid */
301: STMemory_WriteLong(0x43a, 0x237698aa); /* another magic # */
302: STMemory_WriteLong(0x51a, 0x5555aaaa); /* and another */
1.1 root 303:
1.1.1.3 root 304: /* Set memory size, adjust for extra VDI screens if needed */
1.1.1.5 root 305: if (bUseVDIRes)
306: {
1.1.1.3 root 307: /* This is enough for 1024x768x16colour (0x60000) */
1.1.1.6 root 308: STMemory_WriteLong(0x436, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop-0x60000); /* mem top - upper end of user memory (before 32k screen) */
309: STMemory_WriteLong(0x42e, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop-0x58000); /* phys top */
1.1 root 310: }
1.1.1.5 root 311: else
312: {
1.1.1.9 ! root 313: STMemory_WriteLong(0x436, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop-0x8000); /* mem top - upper end of user memory (before 32k screen) */
1.1.1.6 root 314: STMemory_WriteLong(0x42e, MemoryInfo[ConfigureParams.Memory.nMemorySize].PhysTop); /* phys top */
1.1 root 315: }
1.1.1.6 root 316: STMemory_WriteByte(0x424, MemoryInfo[ConfigureParams.Memory.nMemorySize].MemoryConfig);
317: STMemory_WriteByte(0xff8001, MemoryInfo[ConfigureParams.Memory.nMemorySize].MemoryConfig);
1.1 root 318:
1.1.1.7 root 319: /* Set memory range */
1.1.1.3 root 320: STRamEnd = MemoryInfo[ConfigureParams.Memory.nMemorySize].MemoryEnd; /* Set end of RAM */
321:
322: /* Set TOS floppies */
1.1.1.6 root 323: STMemory_WriteWord(0x446, nBootDrive); /* Boot up on A(0) or C(2) */
1.1.1.9 ! root 324: //STMemory_WriteWord(0x4a6, 0x2); /* Connected floppies A,B (0 or 2) */
1.1.1.4 root 325:
1.1.1.3 root 326: ConnectedDriveMask = ConnectedDriveMaskList[ConfigureParams.HardDisc.nDriveList];
1.1.1.4 root 327:
1.1.1.6 root 328: STMemory_WriteLong(0x4c2, ConnectedDriveMask); /* Drives A,B and C - NOTE some TOS images overwrite value, see 'TOS_ConnectedDrive_OpCode' */
1.1 root 329:
1.1.1.3 root 330: /* Mirror ROM boot vectors */
1.1.1.6 root 331: STMemory_WriteLong(0x00, STMemory_ReadLong(TosAddress));
332: STMemory_WriteLong(0x04, STMemory_ReadLong(TosAddress+4));
1.1.1.7 root 333:
334: /* Initialize the memory banks: */
335: memory_uninit();
336: memory_init(STRamEnd, 0, TosAddress);
1.1.1.6 root 337: }
338:
339:
340: /*-----------------------------------------------------------------------*/
341: /*
342: Load TOS Rom image file into ST memory space and fix image so can emulate correctly
343: Pre TOS 1.06 are loaded at 0xFC0000 with later ones at 0xE00000
344: */
345: int TOS_LoadImage(void)
346: {
347: void *pTosFile = NULL;
348:
349: bTosImageLoaded = FALSE;
350:
351: /* Load TOS image into memory so we can check it's vesion */
352: TosVersion = 0;
1.1.1.9 ! root 353: pTosFile = File_Read(ConfigureParams.Rom.szTosImageFileName, NULL, NULL, pszTosNameExts);
! 354: TosSize = File_Length(ConfigureParams.Rom.szTosImageFileName);
1.1.1.6 root 355:
356: if(pTosFile && TosSize>0)
357: {
1.1.1.7 root 358: /* Check for RAM TOS images first: */
1.1.1.8 root 359: if(SDL_SwapBE32(*(Uint32 *)pTosFile) == 0x46FC2700)
1.1.1.7 root 360: {
361: fprintf(stderr, "Warning: Detected a RAM TOS - this will probably not work very well!\n");
362: /* RAM TOS images have a 256 bytes loader function before the real image
363: * starts, so we simply skip the first 256 bytes here: */
364: TosSize -= 0x100;
365: memmove(pTosFile, pTosFile + 0x100, TosSize);
366: bRamTosImage = TRUE;
367: }
368: else
369: {
370: bRamTosImage = FALSE;
371: }
372:
1.1.1.6 root 373: /* Now, look at start of image to find Version number and address */
1.1.1.8 root 374: TosVersion = SDL_SwapBE16(*(Uint16 *)((Uint32)pTosFile+2));
375: TosAddress = SDL_SwapBE32(*(Uint32 *)((Uint32)pTosFile+8));
1.1.1.6 root 376:
377: /* Check for reasonable TOS version: */
378: if(TosVersion<0x100 || TosVersion>0x500 || TosSize>1024*1024L
1.1.1.7 root 379: || (!bRamTosImage && TosAddress!=0xe00000 && TosAddress!=0xfc0000))
1.1.1.6 root 380: {
381: Main_Message("Your TOS seems not to be a valid TOS ROM file!\n", PROG_NAME);
1.1.1.7 root 382: fprintf(stderr,"(TOS version %x, address %lx)\n", TosVersion, TosAddress);
1.1.1.6 root 383: return -2;
384: }
385:
386: /* TOSes 1.06 and 1.62 are for the STe ONLY and so don't run on a real STfm. */
387: /* They access illegal memory addresses which don't exist on a real machine and cause the OS */
388: /* to lock up. So, if user selects one of these, show an error */
389: if(TosVersion==0x0106 || TosVersion==0x0162)
390: {
391: Main_Message("TOS versions 1.06 and 1.62 are NOT valid STfm images.\n\n"
392: "These were only designed for use on the STe range of machines.\n", PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
393: return -3;
394: }
395:
396: /* Copy loaded image into ST memory */
397: memcpy((void *)((unsigned long)STRam+TosAddress), pTosFile, TosSize);
398: }
399: else
400: {
401: char err_txt[256];
402: strcpy(err_txt, "Can not load TOS file:\n ");
1.1.1.9 ! root 403: strncat(err_txt, ConfigureParams.Rom.szTosImageFileName, 256-32);
1.1.1.6 root 404: strcat(err_txt, "\n");
405: Main_Message(err_txt, PROG_NAME);
406: return -1;
407: }
408:
409: fprintf(stderr, "Loaded TOS version %i.%c%c, starting at $%lx, "
410: "country code = %i, %s\n", TosVersion>>8, '0'+((TosVersion>>4)&0x0f),
411: '0'+(TosVersion&0x0f), TosAddress, STMemory_ReadWord(TosAddress+28)>>1,
412: (STMemory_ReadWord(TosAddress+28)&1)?"PAL":"NTSC");
413:
414: /* Are we allowed VDI under this TOS? */
415: if(TosVersion == 0x0100 && bUseVDIRes)
416: {
417: /* Warn user (exit if need to) */
418: Main_Message("To use GEM extended resolutions, you must select a TOS >= 1.02.",
419: PROG_NAME /*,MB_OK|MB_ICONINFORMATION*/);
420: /* And select non VDI */
1.1.1.9 ! root 421: bUseVDIRes = ConfigureParams.Screen.bUseExtVdiResolutions = FALSE;
1.1.1.6 root 422: }
423:
424: /* Fix TOS image, modify code for emulation */
425: TOS_FixRom();
426:
427: /* Set connected devices, memory configuration */
428: TOS_SetDefaultMemoryConfig();
429:
430: /* and free loaded image */
431: Memory_Free(pTosFile);
432:
433: bTosImageLoaded = TRUE;
434: return 0;
1.1 root 435: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.