|
|
1.1 root 1: /*
1.1.1.6 root 2: Hatari - tos.c
1.1 root 3:
1.1.1.22 root 4: This file is distributed under the GNU General Public License, version 2
5: or at 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:
1.1.1.18 root 9: The Atari ST TOS needs to be patched to help with emulation. Eg, it
10: references the MMU chip to set memory size. This is patched to the
11: sizes we need without the complicated emulation of hardware which
12: is not needed (as yet). We also patch DMA devices and Hard Drives.
13:
14: NOTE: TOS versions 1.06 and 1.62 were not designed for use on a
15: real STfm. These were for the STe machine ONLY. They access the
16: DMA/Microwire addresses on boot-up which (correctly) cause a
17: bus-error on Hatari as they would in a real STfm. If a user tries
18: to select any of these images we bring up an error. */
1.1.1.16 root 19: const char TOS_fileid[] = "Hatari tos.c : " __DATE__ " " __TIME__;
1.1 root 20:
1.1.1.8 root 21: #include <SDL_endian.h>
1.1.1.4 root 22:
1.1 root 23: #include "main.h"
1.1.1.9 root 24: #include "configuration.h"
1.1 root 25: #include "file.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"
1.1.1.18 root 33: #include "str.h"
1.1 root 34: #include "tos.h"
35: #include "vdi.h"
1.1.1.18 root 36: #include "falcon/dsp.h"
37: #include "clocks_timings.h"
1.1.1.25! root 38: #include "screen.h"
! 39: #include "video.h"
1.1 root 40:
1.1.1.14 root 41: bool bIsEmuTOS;
42: Uint16 TosVersion; /* eg. 0x0100, 0x0102 */
1.1.1.10 root 43: Uint32 TosAddress, TosSize; /* Address in ST memory and size of TOS image */
1.1.1.16 root 44: bool bTosImageLoaded = false; /* Successfully loaded a TOS image? */
45: bool bRamTosImage; /* true if we loaded a RAM TOS image */
1.1.1.23 root 46: unsigned int ConnectedDriveMask = 0x00; /* Bit mask of connected drives, eg 0x7 is A,B,C */
1.1.1.16 root 47: int nNumDrives = 2; /* Number of drives, default is 2 for A: and B: - Strictly, this is the highest mapped drive letter, in-between drives may not be allocated */
1.1.1.10 root 48:
1.1 root 49: /* Possible TOS file extensions to scan for */
1.1.1.12 root 50: static const char * const pszTosNameExts[] =
1.1.1.6 root 51: {
1.1.1.12 root 52: ".img",
53: ".rom",
54: ".tos",
55: NULL
1.1 root 56: };
57:
1.1.1.18 root 58: static struct {
59: FILE *file; /* file pointer to contents of INF file */
60: char prgname[16]; /* TOS name of the program to auto start */
61: const char *infname; /* name of the INF file TOS will try to match */
62: int match_count; /* how many times INF was matched after boot */
63: int match_max; /* how many times TOS needs it to be matched */
64: } TosAutoStart;
65:
66: /* autostarted program name will be added after first '\' character */
67: static const char emudesk_inf[] =
68: "#E 9A 07\r\n"
69: "#Z 01 C:\\@\r\n"
70: "#W 00 00 02 06 26 0C 08 C:\\*.*@\r\n"
71: "#W 00 00 02 08 26 0C 00 @\r\n"
72: "#W 00 00 02 0A 26 0C 00 @\r\n"
73: "#W 00 00 02 0D 26 0C 00 @\r\n"
74: "#M 00 00 01 FF A DISK A@ @\r\n"
75: "#M 01 00 01 FF B DISK B@ @\r\n"
76: "#M 02 00 01 FF C DISK C@ @\r\n"
77: "#F FF 28 @ *.*@\r\n"
78: "#D FF 02 @ *.*@\r\n"
79: "#G 08 FF *.APP@ @\r\n"
80: "#G 08 FF *.PRG@ @\r\n"
81: "#P 08 FF *.TTP@ @\r\n"
82: "#F 08 FF *.TOS@ @\r\n"
83: "#T 00 03 03 FF TRASH@ @\r\n";
84:
85: static const char desktop_inf[] =
86: "#a000000\r\n"
87: "#b001000\r\n"
88: "#c7770007000600070055200505552220770557075055507703111302\r\n"
89: "#d\r\n"
90: "#Z 01 C:\\@\r\n"
91: "#E D8 11\r\n"
92: "#W 00 00 10 01 17 17 13 C:\\*.*@\r\n"
93: "#W 00 00 08 0B 1D 0D 00 @\r\n"
94: "#W 00 00 0A 0F 1A 09 00 @\r\n"
95: "#W 00 00 0E 01 1A 09 00 @\r\n"
96: "#M 00 00 05 FF A DISK A@ @\r\n"
97: "#M 00 01 05 FF B DISK B@ @\r\n"
98: "#M 00 02 05 FF C DISK C@ @\r\n"
99: "#T 00 03 02 FF TRASH@ @\r\n"
100: "#F FF 04 @ *.*@\r\n"
101: "#D FF 01 @ *.*@\r\n"
102: "#P 03 04 @ *.*@\r\n"
103: "#G 03 FF *.APP@ @\r\n"
104: "#G 03 FF *.PRG@ @\r\n"
105: "#P 03 FF *.TTP@ @\r\n"
106: "#F 03 04 *.TOS@ @\r\n";
1.1 root 107:
1.1.1.6 root 108: /* Flags that define if a TOS patch should be applied */
109: enum
1.1 root 110: {
1.1.1.12 root 111: TP_ALWAYS, /* Patch should alway be applied */
1.1.1.13 root 112: TP_HDIMAGE_OFF, /* Apply patch only if HD emulation is off */
1.1.1.22 root 113: TP_ANTI_STE, /* Apply patch only if running on plain ST */
1.1.1.24 root 114: TP_ANTI_PMMU, /* Apply patch only if no PMMU is available */
115: TP_FIX_060, /* Apply patch only if CPU is 68060 */
1.1.1.6 root 116: };
1.1.1.3 root 117:
1.1.1.6 root 118: /* This structure is used for patching the TOS ROMs */
1.1.1.7 root 119: typedef struct
1.1 root 120: {
1.1.1.12 root 121: Uint16 Version; /* TOS version number */
122: Sint16 Country; /* TOS country code: -1 if it does not matter, 0=US, 1=Germany, 2=France, etc. */
123: const char *pszName; /* Name of the patch */
124: int Flags; /* When should the patch be applied? (see enum above) */
125: Uint32 Address; /* Where the patch should be applied */
126: Uint32 OldData; /* Expected first 4 old bytes */
127: Uint32 Size; /* Length of the patch */
128: const void *pNewData; /* Pointer to the new bytes */
1.1.1.6 root 129: } TOS_PATCH;
130:
1.1.1.10 root 131: static const char pszDmaBoot[] = "boot from DMA bus";
1.1.1.13 root 132: static const char pszMouse[] = "big resolutions mouse driver";
1.1.1.10 root 133: static const char pszRomCheck[] = "ROM checksum";
134: static const char pszNoSteHw[] = "disable STE hardware access";
1.1.1.12 root 135: static const char pszNoPmmu[] = "disable PMMU access";
1.1.1.24 root 136: static const char pszFix060[] = "replace code for 68060";
137: static const char pszFalconExtraRAM[] = "enable extra TT RAM on Falcon";
1.1.1.6 root 138:
1.1.1.9 root 139: //static Uint8 pRtsOpcode[] = { 0x4E, 0x75 }; /* 0x4E75 = RTS */
1.1.1.10 root 140: static const Uint8 pNopOpcodes[] = { 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
1.1.1.6 root 141: 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71,
1.1.1.12 root 142: 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71, 0x4E, 0x71 }; /* 0x4E71 = NOP */
1.1.1.10 root 143: static const Uint8 pMouseOpcode[] = { 0xD3, 0xC1 }; /* "ADDA.L D1,A1" (instead of "ADDA.W D1,A1") */
1.1.1.13 root 144: static const Uint8 pRomCheckOpcode206[] = { 0x60, 0x00, 0x00, 0x98 }; /* BRA $e00894 */
145: static const Uint8 pRomCheckOpcode306[] = { 0x60, 0x00, 0x00, 0xB0 }; /* BRA $e00886 */
146: static const Uint8 pRomCheckOpcode404[] = { 0x60, 0x00, 0x00, 0x94 }; /* BRA $e00746 */
1.1.1.10 root 147: static const Uint8 pBraOpcode[] = { 0x60 }; /* 0x60XX = BRA */
1.1 root 148:
1.1.1.25! root 149: static const Uint8 p060movep1[] = { /* replace MOVEP */
1.1.1.24 root 150: 0x70, 0x0c, /* moveq #12,d0 */
151: 0x42, 0x30, 0x08, 0x00, /* loop: clr.b 0,(d0,a0) */
152: 0x55, 0x40, /* subq #2,d0 */
153: 0x4a, 0x40, /* tst.w d0 */
154: 0x66, 0xf6, /* bne.s loop */
155: };
1.1.1.25! root 156: static const Uint8 p060movep2[] = { /* replace MOVEP */
1.1.1.24 root 157: 0x41, 0xf8, 0xfa, 0x26, /* lea 0xfffffa26.w,a0 */
158: 0x20, 0xfc, 0x00, 0x00, 0x00, 0x88, /* move.l #$00000088,(a0)+ */
159: 0x20, 0xbc, 0x00, 0x01, 0x00, 0x05, /* move.l #$00010005,(a0) */
160: 0x4a, 0x38, 0x0a, 0x87 /* tst.b $a87.w */
161: };
1.1.1.25! root 162: static const Uint8 p060movep3_1[] = { /* replace MOVEP */
1.1.1.24 root 163: 0x4e, 0xb9, 0x00, 0xe7, 0xf0, 0x00, /* jsr $e7f000 */
164: 0x4e, 0x71 /* nop */
165: };
1.1.1.25! root 166: static const Uint8 p060movep3_2[] = { /* replace MOVEP $28(a2),d7 */
1.1.1.24 root 167:
168: 0x00, 0x7c, 0x07, 0x00, /* ori #$700,sr */
169: 0x1e, 0x2a, 0x00, 0x28, /* move.b $28(a2),d7 */
170: 0xe1, 0x4f, /* lsl.w #8,d7 */
171: 0x1e, 0x2a, 0x00, 0x2a, /* move.b $2a(a2),d7 */
172: 0x48, 0x47, /* swap d7 */
173: 0x1e, 0x2a, 0x00, 0x2c, /* move.b $2c(a2),d7 */
174: 0xe1, 0x4f, /* lsl.w #8,d7 */
175: 0x1e, 0x2a, 0x00, 0x2e, /* move.b $2e(a2),d7 */
176: 0x4e, 0x75 /* rts */
177: };
178:
179: static const Uint8 pFalconExtraRAM_1[] = {
180: 0x4e, 0xb9, 0x00, 0xe7, 0xf1, 0x00 /* jsr $e7f100 */
181: };
182: static const Uint8 pFalconExtraRAM_2[] = { /* call maddalt() to declare the extra RAM */
183: 0x20, 0x38, 0x05, 0xa4, /* move.l $05a4.w,d0 */
184: 0x67, 0x18, /* beq.s $ba2d2 */
185: 0x04, 0x80, 0x01, 0x00, 0x00, 0x00, /* subi.l #$1000000,d0 */
186: 0x2f, 0x00, /* move.l d0,-(sp) */
187: 0x2f, 0x3c, 0x01, 0x00, 0x00, 0x00, /* move.l #$1000000,-(sp) */
188: 0x3f, 0x3c, 0x00, 0x14, /* move.w #$14,-(sp) */
189: 0x4e, 0x41, /* trap #1 */
190: 0x4f, 0xef, 0x00, 0x0a, /* lea $a(sp),sp */
191: 0x70, 0x03, /* moveq #3,d0 */
192: 0x4e, 0xf9, 0x00, 0xe0, 0x0b, 0xd2 /* jmp $e00bd2 */
193: };
194:
1.1.1.6 root 195: /* The patches for the TOS: */
1.1.1.10 root 196: static const TOS_PATCH TosPatches[] =
1.1.1.6 root 197: {
1.1.1.13 root 198: { 0x100, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xFC03D6, 0x610000D0, 4, pNopOpcodes }, /* BSR $FC04A8 */
1.1.1.6 root 199:
1.1.1.13 root 200: { 0x102, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xFC0472, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC0558 */
1.1.1.6 root 201: { 0x102, 0, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
202: { 0x102, 1, pszMouse, TP_ALWAYS, 0xFD008A, 0xD2C147F9, 2, pMouseOpcode },
203: { 0x102, 2, pszMouse, TP_ALWAYS, 0xFD00A8, 0xD2C147F9, 2, pMouseOpcode },
204: { 0x102, 3, pszMouse, TP_ALWAYS, 0xFD0030, 0xD2C147F9, 2, pMouseOpcode },
205: { 0x102, 6, pszMouse, TP_ALWAYS, 0xFCFEF0, 0xD2C147F9, 2, pMouseOpcode },
206: { 0x102, 8, pszMouse, TP_ALWAYS, 0xFCFEFE, 0xD2C147F9, 2, pMouseOpcode },
207:
1.1.1.13 root 208: { 0x104, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xFC0466, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $FC054C */
1.1.1.6 root 209:
1.1.1.13 root 210: { 0x106, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00576, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E0065C */
1.1.1.10 root 211:
1.1.1.13 root 212: { 0x162, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00576, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E0065C */
1.1.1.10 root 213:
1.1.1.13 root 214: { 0x205, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE006AE, 0x610000E4, 4, pNopOpcodes }, /* BSR.W $E00794 */
1.1.1.6 root 215: /* An unpatched TOS 2.05 only works on STEs, so apply some anti-STE patches... */
1.1.1.11 root 216: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00096, 0x42788900, 4, pNopOpcodes }, /* CLR.W $FFFF8900 */
217: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE0009E, 0x31D88924, 4, pNopOpcodes }, /* MOVE.W (A0)+,$FFFF8924 */
218: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE000A6, 0x09D10AA9, 28, pNopOpcodes },
219: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE003A0, 0x30389200, 4, pNopOpcodes }, /* MOVE.W $ffff9200,D0 */
220: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE004EA, 0x61000CBC, 4, pNopOpcodes },
221: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00508, 0x61000C9E, 4, pNopOpcodes },
222: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE007A0, 0x631E2F3C, 1, pBraOpcode },
223: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00928, 0x10388901, 4, pNopOpcodes }, /* MOVE.B $FFFF8901,D0 */
224: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00944, 0xB0388901, 4, pNopOpcodes }, /* CMP.B $FFFF8901,D0 */
225: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00950, 0x67024601, 1, pBraOpcode },
226: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00968, 0x61000722, 4, pNopOpcodes },
227: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00CF2, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
228: { 0x205, -1, pszNoSteHw, TP_ANTI_STE, 0xE00E00, 0x1038820D, 4, pNopOpcodes }, /* MOVE.B $FFFF820D,D0 */
229: { 0x205, 0, pszNoSteHw, TP_ANTI_STE, 0xE03038, 0x31C0860E, 4, pNopOpcodes },
230: { 0x205, 0, pszNoSteHw, TP_ANTI_STE, 0xE034A8, 0x31C0860E, 4, pNopOpcodes },
231: { 0x205, 0, pszNoSteHw, TP_ANTI_STE, 0xE034F6, 0x31E90002, 6, pNopOpcodes },
1.1.1.6 root 232:
233: /* E007FA MOVE.L #$1FFFE,D7 Run checksums on 2xROMs (skip) */
234: /* Checksum is total of TOS ROM image, but get incorrect results */
235: /* as we've changed bytes in the ROM! So, just skip anyway! */
1.1.1.13 root 236: { 0x206, -1, pszRomCheck, TP_ALWAYS, 0xE007FA, 0x2E3C0001, 4, pRomCheckOpcode206 },
237: { 0x206, -1, pszDmaBoot, TP_HDIMAGE_OFF, 0xE00898, 0x610000E0, 4, pNopOpcodes }, /* BSR.W $E0097A */
1.1 root 238:
1.1.1.13 root 239: { 0x306, -1, pszRomCheck, TP_ALWAYS, 0xE007D4, 0x2E3C0001, 4, pRomCheckOpcode306 },
1.1.1.24 root 240: { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE00068, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
241: { 0x306, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE01702, 0xF0394C00, 32, pNopOpcodes }, /* pmove : CRP=80000002 00000700 TC=80f04445 TT0=017e8107 TT1=807e8507 -> */
1.1.1.25! root 242: { 0x306, -1, pszFix060, TP_FIX_060, 0xe024dc, 0x01C80000, 12, p060movep1 },
! 243: { 0x306, -1, pszFix060, TP_FIX_060, 0xe024fa, 0x01C80000, 12, p060movep1 },
1.1.1.12 root 244:
1.1.1.24 root 245: { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE00064, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
1.1.1.22 root 246: { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0148A, 0xF0394C00, 32, pNopOpcodes },
1.1.1.24 root 247: { 0x400, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE03948, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
1.1.1.13 root 248: { 0x400, -1, pszRomCheck, TP_ALWAYS, 0xE00686, 0x2E3C0007, 4, pRomCheckOpcode404 },
1.1.1.25! root 249: { 0x400, -1, pszFix060, TP_FIX_060, 0xE0258A, 0x01C80000, 12, p060movep1 },
! 250: { 0x400, -1, pszFix060, TP_FIX_060, 0xE025DA, 0x41F8FA01, 20, p060movep2 },
1.1.1.13 root 251:
1.1.1.24 root 252: { 0x401, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0006A, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
1.1.1.22 root 253: { 0x401, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE014A8, 0xF0394C00, 32, pNopOpcodes },
1.1.1.24 root 254: { 0x401, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE03946, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
1.1.1.13 root 255: { 0x401, -1, pszRomCheck, TP_ALWAYS, 0xE006A6, 0x2E3C0007, 4, pRomCheckOpcode404 },
1.1.1.25! root 256: { 0x401, -1, pszFix060, TP_FIX_060, 0xE02588, 0x01C80000, 12, p060movep1 },
! 257: { 0x401, -1, pszFix060, TP_FIX_060, 0xE025D8, 0x41F8FA01, 20, p060movep2 },
1.1.1.13 root 258:
1.1.1.24 root 259: { 0x402, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0006A, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
1.1.1.22 root 260: { 0x402, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE014A8, 0xF0394C00, 32, pNopOpcodes },
1.1.1.24 root 261: { 0x402, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE03946, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
1.1.1.13 root 262: { 0x402, -1, pszRomCheck, TP_ALWAYS, 0xE006A6, 0x2E3C0007, 4, pRomCheckOpcode404 },
1.1.1.25! root 263: { 0x402, -1, pszFix060, TP_FIX_060, 0xE02588, 0x01C80000, 12, p060movep1 },
! 264: { 0x402, -1, pszFix060, TP_FIX_060, 0xE025D8, 0x41F8FA01, 20, p060movep2 },
1.1.1.13 root 265:
1.1.1.24 root 266: { 0x404, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE0006A, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
267: { 0x404, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE014E6, 0xF0394C00, 32, pNopOpcodes }, /* pmove : CRP=80000002 00000700 TC=80f04445 TT0=017e8107 TT1=807e8507 -> */
268: { 0x404, -1, pszNoPmmu, TP_ANTI_PMMU, 0xE039A0, 0xF0394000, 24, pNopOpcodes }, /* pmove : TC=0 TT0=0 TT1=0 -> disable MMU */
1.1.1.13 root 269: { 0x404, -1, pszRomCheck, TP_ALWAYS, 0xE006B0, 0x2E3C0007, 4, pRomCheckOpcode404 },
1.1.1.23 root 270: { 0x404, -1, pszDmaBoot, TP_ALWAYS, 0xE01C9E, 0x62FC31FC, 2, pNopOpcodes }, /* Just a delay */
271: { 0x404, -1, pszDmaBoot, TP_ALWAYS, 0xE01CB2, 0x62FC31FC, 2, pNopOpcodes }, /* Just a delay */
1.1.1.25! root 272: { 0x404, -1, pszFix060, TP_FIX_060, 0xE025E2, 0x01C80000, 12, p060movep1 },
! 273: { 0x404, -1, pszFix060, TP_FIX_060, 0xE02632, 0x41F8FA01, 20, p060movep2 },
! 274: { 0x404, -1, pszFix060, TP_FIX_060, 0xE02B1E, 0x007c0700, 8, p060movep3_1 },
! 275: { 0x404, -1, pszFix060, TP_FIX_060, 0xE7F000, 0xFFFFFFFF, sizeof( p060movep3_2 ), p060movep3_2 },
1.1.1.24 root 276: { 0x404, -1, pszFalconExtraRAM, TP_ALWAYS, 0xE0096E, 0x70036100, 6, pFalconExtraRAM_1 },
277: { 0x404, -1, pszFalconExtraRAM, TP_ALWAYS, 0xE7F100, 0xFFFFFFFF, sizeof( pFalconExtraRAM_2 ), pFalconExtraRAM_2 },
1.1.1.13 root 278:
1.1.1.22 root 279: { 0x492, -1, pszNoPmmu, TP_ANTI_PMMU, 0x00F946, 0xF0394000, 24, pNopOpcodes },
280: { 0x492, -1, pszNoPmmu, TP_ANTI_PMMU, 0x01097A, 0xF0394C00, 32, pNopOpcodes },
281: { 0x492, -1, pszNoPmmu, TP_ANTI_PMMU, 0x012E04, 0xF0394000, 24, pNopOpcodes },
1.1.1.13 root 282:
1.1.1.6 root 283: { 0, 0, NULL, 0, 0, 0, 0, NULL }
284: };
1.1 root 285:
286:
287:
1.1.1.6 root 288: /*-----------------------------------------------------------------------*/
1.1.1.13 root 289: /**
290: * Save/Restore snapshot of local variables ('MemorySnapShot_Store' handles type)
291: */
1.1.1.14 root 292: void TOS_MemorySnapShot_Capture(bool bSave)
1.1.1.6 root 293: {
1.1.1.12 root 294: /* Save/Restore details */
295: MemorySnapShot_Store(&TosVersion, sizeof(TosVersion));
296: MemorySnapShot_Store(&TosAddress, sizeof(TosAddress));
297: MemorySnapShot_Store(&TosSize, sizeof(TosSize));
298: MemorySnapShot_Store(&ConnectedDriveMask, sizeof(ConnectedDriveMask));
299: MemorySnapShot_Store(&nNumDrives, sizeof(nNumDrives));
1.1 root 300: }
301:
1.1.1.3 root 302:
303: /*-----------------------------------------------------------------------*/
1.1.1.13 root 304: /**
305: * Patch TOS to skip some TOS setup code which we don't support/need.
306: *
307: * So, how do we find these addresses when we have no commented source code?
308: * - For the "Boot from DMA bus" patch:
309: * Scan at start of rom for tst.w $482, boot call will be just above it.
310: */
1.1.1.6 root 311: static void TOS_FixRom(void)
1.1 root 312: {
1.1.1.12 root 313: int nGoodPatches, nBadPatches;
314: short TosCountry;
315: const TOS_PATCH *pPatch;
316:
1.1.1.13 root 317: /* We can't patch RAM TOS images (yet) */
318: if (bRamTosImage && TosVersion != 0x0492)
1.1.1.12 root 319: {
320: Log_Printf(LOG_DEBUG, "Detected RAM TOS image, skipping TOS patches.\n");
321: return;
322: }
323:
324: nGoodPatches = nBadPatches = 0;
325: TosCountry = STMemory_ReadWord(TosAddress+28)>>1; /* TOS country code */
326: pPatch = TosPatches;
327:
328: /* Apply TOS patches: */
329: while (pPatch->Version)
330: {
331: /* Only apply patches that suit to the actual TOS version: */
332: if (pPatch->Version == TosVersion
333: && (pPatch->Country == TosCountry || pPatch->Country == -1))
334: {
1.1.1.22 root 335: #if ENABLE_WINUAE_CPU
1.1.1.25! root 336: bool use_mmu = ConfigureParams.System.bMMU &&
! 337: ConfigureParams.System.nCpuLevel == 3;
1.1.1.22 root 338: #else
339: bool use_mmu = false;
340: #endif
1.1.1.12 root 341: /* Make sure that we really patch the right place by comparing data: */
342: if(STMemory_ReadLong(pPatch->Address) == pPatch->OldData)
343: {
344: /* Only apply the patch if it is really needed: */
1.1.1.13 root 345: if (pPatch->Flags == TP_ALWAYS
1.1.1.19 root 346: || (pPatch->Flags == TP_HDIMAGE_OFF && !ACSI_EMU_ON
347: && !ConfigureParams.HardDisk.bUseIdeMasterHardDiskImage
348: && ConfigureParams.System.bFastBoot)
1.1.1.25! root 349: || (pPatch->Flags == TP_ANTI_STE && Config_IsMachineST())
1.1.1.22 root 350: || (pPatch->Flags == TP_ANTI_PMMU && !use_mmu)
1.1.1.24 root 351: || (pPatch->Flags == TP_FIX_060 && ConfigureParams.System.nCpuLevel > 4)
1.1.1.22 root 352: )
1.1.1.12 root 353: {
354: /* Now we can really apply the patch! */
1.1.1.13 root 355: Log_Printf(LOG_DEBUG, "Applying TOS patch '%s'.\n", pPatch->pszName);
356: memcpy(&RomMem[pPatch->Address], pPatch->pNewData, pPatch->Size);
1.1.1.12 root 357: nGoodPatches += 1;
358: }
359: else
360: {
1.1.1.13 root 361: Log_Printf(LOG_DEBUG, "Skipped patch '%s'.\n", pPatch->pszName);
1.1.1.12 root 362: }
363: }
364: else
365: {
366: Log_Printf(LOG_DEBUG, "Failed to apply TOS patch '%s' at %x (expected %x, found %x).\n",
367: pPatch->pszName, pPatch->Address, pPatch->OldData, STMemory_ReadLong(pPatch->Address));
368: nBadPatches += 1;
369: }
370: }
371: pPatch += 1;
372: }
1.1.1.3 root 373:
1.1.1.12 root 374: Log_Printf(LOG_DEBUG, "Applied %i TOS patches, %i patches failed.\n",
375: nGoodPatches, nBadPatches);
1.1.1.6 root 376: }
377:
378:
379: /*-----------------------------------------------------------------------*/
1.1.1.13 root 380: /**
1.1.1.18 root 381: * Set name of program that will be auto started after TOS boots.
382: * Supported only from TOS 1.04 forward.
383: */
384: void TOS_AutoStart(const char *prgname)
385: {
386: Str_Filename2TOSname(prgname, TosAutoStart.prgname);
387: }
388:
389: /*-----------------------------------------------------------------------*/
390: /**
391: * Create a temporary desktop.inf file which will start autostart program.
392: * This needs to be re-created on each boot in case user changed TOS version.
393: */
394: static void TOS_CreateAutoInf(void)
395: {
396: const char *contents, *infname, *prgname;
397: int offset, size, max;
398: FILE *fp;
399:
400: /* in case TOS didn't for some reason close it on previous boot */
401: TOS_AutoStartClose(TosAutoStart.file);
402:
403: prgname = TosAutoStart.prgname;
404: /* autostart not enabled? */
405: if (!*prgname)
406: return;
407:
408: /* autostart not supported? */
409: if (TosVersion < 0x0104)
410: {
411: Log_Printf(LOG_WARN, "Only TOS versions >= 1.04 support autostarting!\n");
412: return;
413: }
414:
415: if (bIsEmuTOS)
416: {
417: infname = "C:\\EMUDESK.INF";
418: size = sizeof(emudesk_inf);
419: contents = emudesk_inf;
420: max = 1;
421: } else {
422: /* need to match file TOS searches first */
423: if (TosVersion >= 0x0200)
424: infname = "NEWDESK.INF";
425: else
426: infname = "DESKTOP.INF";
427: size = sizeof(desktop_inf);
428: contents = desktop_inf;
429: max = 1;
430: }
431: /* infname needs to be exactly the same string that given
432: * TOS version gives for GEMDOS to find.
433: */
434: TosAutoStart.infname = infname;
435: TosAutoStart.match_max = max;
436: TosAutoStart.match_count = 0;
437:
438: /* find where to insert the program name */
439: for (offset = 0; offset < size; )
440: {
441: if (contents[offset++] == '\\')
442: break;
443: }
444: assert(offset < size);
445:
446: /* create the autostart file */
447: fp = tmpfile();
448: if (!(fp
449: && fwrite(contents, offset, 1, fp) == 1
450: && fwrite(prgname, strlen(prgname), 1, fp) == 1
451: && fwrite(contents+offset, size-offset-1, 1, fp) == 1
452: && fseek(fp, 0, SEEK_SET) == 0))
453: {
454: if (fp)
455: fclose(fp);
456: Log_Printf(LOG_ERROR, "Failed to create autostart file for '%s'!\n", TosAutoStart.prgname);
457: return;
458: }
459: TosAutoStart.file = fp;
460: Log_Printf(LOG_WARN, "Virtual autostart file '%s' created for '%s'.\n", infname, prgname);
461: }
462:
463: /*-----------------------------------------------------------------------*/
464: /**
465: * If given name matches autostart file, return its handle, NULL otherwise
466: */
467: FILE *TOS_AutoStartOpen(const char *filename)
468: {
469: if (TosAutoStart.file && strcmp(filename, TosAutoStart.infname) == 0)
470: {
1.1.1.23 root 471: /* whether to "autostart" also exception debugging? */
472: if (ConfigureParams.Log.nExceptionDebugMask & EXCEPT_AUTOSTART)
473: {
474: ExceptionDebugMask = ConfigureParams.Log.nExceptionDebugMask & ~EXCEPT_AUTOSTART;
475: fprintf(stderr, "Exception debugging enabled (0x%x).\n", ExceptionDebugMask);
476: }
1.1.1.18 root 477: Log_Printf(LOG_WARN, "Autostart file '%s' for '%s' matched.\n", filename, TosAutoStart.prgname);
478: return TosAutoStart.file;
479: }
480: return NULL;
481: }
482:
483: /*-----------------------------------------------------------------------*/
484: /**
485: * If given handle matches autostart file, close it and return true,
486: * false otherwise.
487: */
488: bool TOS_AutoStartClose(FILE *fp)
489: {
490: if (fp && fp == TosAutoStart.file)
491: {
492: if (++TosAutoStart.match_count >= TosAutoStart.match_max)
493: {
494: /* Remove autostart INF file after TOS has
495: * read it enough times to do autostarting.
496: * Otherwise user may try change desktop settings
497: * and save them, but they would be lost.
498: */
499: fclose(TosAutoStart.file);
500: TosAutoStart.file = NULL;
501: Log_Printf(LOG_WARN, "Autostart file removed.\n");
502: }
503: return true;
504: }
505: return false;
506: }
507:
508:
509: /*-----------------------------------------------------------------------*/
510: /**
1.1.1.13 root 511: * Assert that TOS version matches the machine type and change the system
512: * configuration if necessary.
513: * For example TOSes 1.06 and 1.62 are for the STE ONLY and so don't run
514: * on a real ST, TOS 3.0x is TT only and TOS 4.x is Falcon only.
515: * These TOS version access illegal memory addresses on machine they were
516: * not designed for and so cause the OS to lock up. So, if user selects one
517: * of these, switch to the appropriate machine type.
518: */
519: static void TOS_CheckSysConfig(void)
520: {
1.1.1.22 root 521: int oldCpuLevel = ConfigureParams.System.nCpuLevel;
1.1.1.21 root 522: MACHINETYPE oldMachineType = ConfigureParams.System.nMachineType;
1.1.1.25! root 523: #if ENABLE_WINUAE_CPU
! 524: FPUTYPE oldFpuType = ConfigureParams.System.n_FPUType;
! 525: #endif
! 526:
! 527: if (((TosVersion == 0x0106 || TosVersion == 0x0162) && !Config_IsMachineSTE())
1.1.1.22 root 528: || (TosVersion == 0x0162 && ConfigureParams.System.nCpuLevel != 0))
1.1.1.13 root 529: {
1.1.1.14 root 530: Log_AlertDlg(LOG_ERROR, "TOS versions 1.06 and 1.62 are for Atari STE only.\n"
1.1.1.13 root 531: " ==> Switching to STE mode now.\n");
532: IoMem_UnInit();
533: ConfigureParams.System.nMachineType = MACHINE_STE;
1.1.1.18 root 534: ClocksTimings_InitMachine ( ConfigureParams.System.nMachineType );
1.1.1.25! root 535: Video_SetTimings ( ConfigureParams.System.nMachineType , ConfigureParams.System.VideoTimingMode );
1.1.1.13 root 536: IoMem_Init();
1.1.1.18 root 537: ConfigureParams.System.nCpuFreq = 8;
1.1.1.17 root 538: ConfigureParams.System.nCpuLevel = 0;
1.1.1.13 root 539: }
1.1.1.25! root 540: else if ((TosVersion & 0x0f00) == 0x0300 && !Config_IsMachineTT())
1.1.1.13 root 541: {
1.1.1.14 root 542: Log_AlertDlg(LOG_ERROR, "TOS versions 3.0x are for Atari TT only.\n"
1.1.1.13 root 543: " ==> Switching to TT mode now.\n");
544: IoMem_UnInit();
545: ConfigureParams.System.nMachineType = MACHINE_TT;
1.1.1.18 root 546: ClocksTimings_InitMachine ( ConfigureParams.System.nMachineType );
1.1.1.25! root 547: Video_SetTimings ( ConfigureParams.System.nMachineType , ConfigureParams.System.VideoTimingMode );
1.1.1.13 root 548: IoMem_Init();
1.1.1.18 root 549: ConfigureParams.System.nCpuFreq = 32;
1.1.1.13 root 550: ConfigureParams.System.nCpuLevel = 3;
551: }
1.1.1.25! root 552: else if ((TosVersion & 0x0f00) == 0x0400 && !Config_IsMachineFalcon())
1.1.1.13 root 553: {
1.1.1.14 root 554: Log_AlertDlg(LOG_ERROR, "TOS versions 4.x are for Atari Falcon only.\n"
1.1.1.13 root 555: " ==> Switching to Falcon mode now.\n");
556: IoMem_UnInit();
557: ConfigureParams.System.nMachineType = MACHINE_FALCON;
1.1.1.18 root 558: ClocksTimings_InitMachine ( ConfigureParams.System.nMachineType );
1.1.1.25! root 559: Video_SetTimings ( ConfigureParams.System.nMachineType , ConfigureParams.System.VideoTimingMode );
1.1.1.18 root 560: #if ENABLE_DSP_EMU
561: ConfigureParams.System.nDSPType = DSP_TYPE_EMU;
1.1.1.25! root 562: DSP_Enable();
1.1.1.18 root 563: #endif
1.1.1.13 root 564: IoMem_Init();
1.1.1.18 root 565: ConfigureParams.System.nCpuFreq = 16;
1.1.1.13 root 566: ConfigureParams.System.nCpuLevel = 3;
567: }
1.1.1.19 root 568: else if (TosVersion <= 0x0104 &&
1.1.1.25! root 569: (ConfigureParams.System.nCpuLevel > 0 || !Config_IsMachineST()))
1.1.1.17 root 570: {
1.1.1.19 root 571: Log_AlertDlg(LOG_ERROR, "TOS versions <= 1.4 work only in\n"
572: "ST mode and with a 68000 CPU.\n"
1.1.1.22 root 573: " ==> Switching to ST mode with 68000 now.\n");
1.1.1.17 root 574: IoMem_UnInit();
575: ConfigureParams.System.nMachineType = MACHINE_ST;
1.1.1.18 root 576: ClocksTimings_InitMachine ( ConfigureParams.System.nMachineType );
1.1.1.25! root 577: Video_SetTimings ( ConfigureParams.System.nMachineType , ConfigureParams.System.VideoTimingMode );
1.1.1.17 root 578: IoMem_Init();
1.1.1.18 root 579: ConfigureParams.System.nCpuFreq = 8;
1.1.1.17 root 580: ConfigureParams.System.nCpuLevel = 0;
581: }
1.1.1.25! root 582: else if ((TosVersion < 0x0300 && Config_IsMachineFalcon())
! 583: || (TosVersion < 0x0200 && Config_IsMachineTT()))
1.1.1.13 root 584: {
1.1.1.19 root 585: Log_AlertDlg(LOG_ERROR, "This TOS version does not work in TT/Falcon mode.\n"
1.1.1.13 root 586: " ==> Switching to STE mode now.\n");
587: IoMem_UnInit();
588: ConfigureParams.System.nMachineType = MACHINE_STE;
1.1.1.18 root 589: ClocksTimings_InitMachine ( ConfigureParams.System.nMachineType );
1.1.1.25! root 590: Video_SetTimings ( ConfigureParams.System.nMachineType , ConfigureParams.System.VideoTimingMode );
1.1.1.13 root 591: IoMem_Init();
1.1.1.18 root 592: ConfigureParams.System.nCpuFreq = 8;
1.1.1.17 root 593: ConfigureParams.System.nCpuLevel = 0;
1.1.1.13 root 594: }
1.1.1.22 root 595: else if ((TosVersion & 0x0f00) == 0x0400 && ConfigureParams.System.nCpuLevel < 2)
1.1.1.14 root 596: {
1.1.1.22 root 597: Log_AlertDlg(LOG_ERROR, "TOS versions 4.x require a CPU >= 68020.\n"
1.1.1.14 root 598: " ==> Switching to 68020 mode now.\n");
599: ConfigureParams.System.nCpuLevel = 2;
1.1.1.21 root 600: }
1.1.1.25! root 601: #if ENABLE_WINUAE_CPU
! 602: else if ((TosVersion & 0x0f00) == 0x0300 &&
! 603: (ConfigureParams.System.nCpuLevel < 2 || ConfigureParams.System.n_FPUType == FPU_NONE))
! 604: {
! 605: Log_AlertDlg(LOG_ERROR, "TOS versions 3.0x require a CPU >= 68020 with FPU.\n"
! 606: " ==> Switching to 68030 mode with FPU now.\n");
! 607: ConfigureParams.System.nCpuLevel = 3;
! 608: ConfigureParams.System.n_FPUType = FPU_68882;
! 609: }
! 610: #else
1.1.1.22 root 611: else if ((TosVersion & 0x0f00) == 0x0300 && ConfigureParams.System.nCpuLevel < 3)
612: {
1.1.1.25! root 613: Log_AlertDlg(LOG_ERROR, "TOS versions 3.0x require a CPU >= 68020 with FPU.\n"
! 614: " ==> Switching to 68030 mode with FPU now.\n");
1.1.1.22 root 615: ConfigureParams.System.nCpuLevel = 3;
616: }
1.1.1.25! root 617: #endif
! 618:
1.1.1.21 root 619: /* TOS version triggered changes? */
620: if (ConfigureParams.System.nMachineType != oldMachineType)
621: {
622: #if ENABLE_WINUAE_CPU
1.1.1.25! root 623: if (Config_IsMachineTT())
1.1.1.21 root 624: {
625: ConfigureParams.System.bCompatibleFPU = true;
626: ConfigureParams.System.n_FPUType = FPU_68882;
627: } else {
628: ConfigureParams.System.n_FPUType = FPU_NONE; /* TODO: or leave it as-is? */
629: }
1.1.1.22 root 630: if (TosVersion < 0x200)
631: {
632: ConfigureParams.System.bAddressSpace24 = true;
633: ConfigureParams.System.bMMU = false;
634: }
1.1.1.21 root 635: #endif
1.1.1.18 root 636: M68000_CheckCpuSettings();
1.1.1.14 root 637: }
1.1.1.25! root 638: else if (ConfigureParams.System.nCpuLevel != oldCpuLevel
! 639: #if ENABLE_WINUAE_CPU
! 640: || ConfigureParams.System.n_FPUType != oldFpuType
! 641: #endif
! 642: )
1.1.1.22 root 643: {
644: M68000_CheckCpuSettings();
645: }
1.1.1.19 root 646: if (TosVersion < 0x0104 && ConfigureParams.HardDisk.bUseHardDiskDirectories)
647: {
648: Log_AlertDlg(LOG_ERROR, "Please use at least TOS v1.04 for the HD directory emulation "
649: "(all required GEMDOS functionality isn't completely emulated for this TOS version).");
650: }
1.1.1.25! root 651: if (Config_IsMachineFalcon() && bUseVDIRes && !bIsEmuTOS)
! 652: {
! 653: Log_AlertDlg(LOG_ERROR, "Please use EmuTOS for proper VDI results in Falcon mode "
! 654: "(TOS 4 doesn't fully support VDI).");
! 655: }
1.1.1.13 root 656: }
657:
658:
659: /*-----------------------------------------------------------------------*/
660: /**
1.1.1.20 root 661: * Load TOS Rom image file into ST memory space and fix image so it can be
662: * emulated correctly. Pre TOS 1.06 are loaded at 0xFC0000 and later ones
663: * at 0xE00000.
1.1.1.13 root 664: */
1.1.1.6 root 665: int TOS_LoadImage(void)
666: {
1.1.1.12 root 667: Uint8 *pTosFile = NULL;
668: long nFileSize;
1.1.1.6 root 669:
1.1.1.16 root 670: bTosImageLoaded = false;
1.1.1.6 root 671:
1.1.1.24 root 672: /* Calculate end of RAM */
673: if (ConfigureParams.Memory.nMemorySize > 0
674: && ConfigureParams.Memory.nMemorySize <= 14)
675: STRamEnd = ConfigureParams.Memory.nMemorySize * 0x100000;
676: else
677: STRamEnd = 0x80000; /* 512 KiB */
678:
1.1.1.20 root 679: /* Load TOS image into memory so that we can check its version */
1.1.1.12 root 680: TosVersion = 0;
1.1.1.13 root 681: pTosFile = File_Read(ConfigureParams.Rom.szTosImageFileName, &nFileSize, pszTosNameExts);
1.1.1.12 root 682:
683: if (!pTosFile || nFileSize <= 0)
684: {
685: Log_AlertDlg(LOG_FATAL, "Can not load TOS file:\n'%s'", ConfigureParams.Rom.szTosImageFileName);
1.1.1.24 root 686: free(pTosFile);
1.1.1.12 root 687: return -1;
688: }
689:
690: TosSize = nFileSize;
691:
692: /* Check for RAM TOS images first: */
693: if (SDL_SwapBE32(*(Uint32 *)pTosFile) == 0x46FC2700)
694: {
1.1.1.13 root 695: int nRamTosLoaderSize;
1.1.1.12 root 696: Log_Printf(LOG_WARN, "Detected a RAM TOS - this will probably not work very well!\n");
697: /* RAM TOS images have a 256 bytes loader function before the real image
1.1.1.13 root 698: * starts (34 bytes for TOS 4.92). Since we directly copy the image to the right
699: * location later, we simply skip this additional header here: */
700: if (SDL_SwapBE32(*(Uint32 *)(pTosFile+34)) == 0x602E0492)
701: nRamTosLoaderSize = 0x22;
702: else
703: nRamTosLoaderSize = 0x100;
704: TosSize -= nRamTosLoaderSize;
705: memmove(pTosFile, pTosFile + nRamTosLoaderSize, TosSize);
1.1.1.16 root 706: bRamTosImage = true;
1.1.1.12 root 707: }
708: else
709: {
1.1.1.16 root 710: bRamTosImage = false;
1.1.1.12 root 711: }
712:
1.1.1.13 root 713: /* Check for EmuTOS ... (0x45544F53 = 'ETOS') */
714: bIsEmuTOS = (SDL_SwapBE32(*(Uint32 *)&pTosFile[0x2c]) == 0x45544F53);
715:
1.1.1.12 root 716: /* Now, look at start of image to find Version number and address */
717: TosVersion = SDL_SwapBE16(*(Uint16 *)&pTosFile[2]);
718: TosAddress = SDL_SwapBE32(*(Uint32 *)&pTosFile[8]);
719:
720: /* Check for reasonable TOS version: */
1.1.1.18 root 721: if (TosVersion == 0x000 && TosSize == 16384)
722: {
723: /* TOS 0.00 was a very early boot loader ROM which could only
724: * execute a boot sector from floppy disk, which was used in
725: * the very early STs before a full TOS was available in ROM.
726: * It's not very useful nowadays, but we support it here, too,
727: * just for fun. */
728: TosAddress = 0xfc0000;
729: }
1.1.1.24 root 730: else if (TosVersion < 0x100 || TosVersion >= 0x500 || TosSize > 1024*1024L
731: || (TosAddress == 0xfc0000 && TosSize > 224*1024L)
732: || (bRamTosImage && TosAddress + TosSize > STRamEnd)
733: || (!bRamTosImage && TosAddress != 0xe00000 && TosAddress != 0xfc0000))
1.1.1.12 root 734: {
735: Log_AlertDlg(LOG_FATAL, "Your TOS image seems not to be a valid TOS ROM file!\n"
736: "(TOS version %x, address $%x)", TosVersion, TosAddress);
1.1.1.24 root 737: free(pTosFile);
1.1.1.12 root 738: return -2;
739: }
740:
1.1.1.13 root 741: /* Assert that machine type matches the TOS version. Note that EmuTOS can
742: * handle all machine types, so we don't do the system check there: */
743: if (!bIsEmuTOS)
744: TOS_CheckSysConfig();
745:
1.1.1.24 root 746: #if ENABLE_WINUAE_CPU
1.1.1.25! root 747: /* 32-bit addressing is supported only by CPU >= 68020, TOS v3, TOS v4 and EmuTOS */
! 748: if (ConfigureParams.System.nCpuLevel < 2 || (TosVersion < 0x0300 && !bIsEmuTOS))
! 749: {
1.1.1.24 root 750: ConfigureParams.System.bAddressSpace24 = true;
1.1.1.25! root 751: M68000_CheckCpuSettings();
! 752: }
1.1.1.24 root 753: else if (ConfigureParams.Memory.nTTRamSize)
754: {
755: switch (ConfigureParams.System.nMachineType)
756: {
757: case MACHINE_TT:
758: if (ConfigureParams.System.bAddressSpace24)
759: {
760: /* Print a message and force 32 bit addressing (keeping 24 bit with TT RAM would crash TOS) */
761: Log_AlertDlg(LOG_ERROR, "Enabling 32-bit addressing for TT-RAM access.\nThis can cause issues in some programs!\n");
762: ConfigureParams.System.bAddressSpace24 = false;
1.1.1.25! root 763: M68000_CheckCpuSettings();
1.1.1.24 root 764: }
765: break;
766: case MACHINE_FALCON:
767: if (ConfigureParams.System.bAddressSpace24)
768: {
769: /* Print a message, but don't force 32 bit addressing as 24 bit addressing is also possible under Falcon */
770: /* So, if Falcon is in 24 bit mode, we just don't add TT RAM */
771: Log_AlertDlg(LOG_ERROR, "You need to disable 24-bit addressing to use TT-RAM in Falcon mode.\n");
772: }
773: break;
774: default:
775: break;
776: }
777: }
778: #endif
1.1.1.13 root 779:
780: /* (Re-)Initialize the memory banks: */
781: memory_uninit();
1.1.1.24 root 782: memory_init(STRamEnd, ConfigureParams.Memory.nTTRamSize*1024*1024, TosAddress);
1.1.1.13 root 783:
784: /* Clear Upper memory (ROM and IO memory) */
785: memset(&RomMem[0xe00000], 0, 0x200000);
1.1.1.12 root 786:
1.1.1.24 root 787: /* Copy loaded image into memory */
788: if (bRamTosImage)
789: memcpy(&STRam[TosAddress], pTosFile, TosSize);
790: else
791: memcpy(&RomMem[TosAddress], pTosFile, TosSize);
1.1.1.12 root 792:
793: Log_Printf(LOG_DEBUG, "Loaded TOS version %i.%c%c, starting at $%x, "
794: "country code = %i, %s\n", TosVersion>>8, '0'+((TosVersion>>4)&0x0f),
795: '0'+(TosVersion&0x0f), TosAddress, STMemory_ReadWord(TosAddress+28)>>1,
796: (STMemory_ReadWord(TosAddress+28)&1)?"PAL":"NTSC");
797:
798: /* Are we allowed VDI under this TOS? */
799: if (TosVersion == 0x0100 && bUseVDIRes)
800: {
801: /* Warn user */
1.1.1.18 root 802: Log_AlertDlg(LOG_ERROR, "To use extended VDI resolutions, you must select a TOS >= 1.02.");
1.1.1.12 root 803: /* And select non VDI */
1.1.1.16 root 804: bUseVDIRes = ConfigureParams.Screen.bUseExtVdiResolutions = false;
1.1.1.12 root 805: }
806:
807: /* Fix TOS image, modify code for emulation */
1.1.1.19 root 808: if (ConfigureParams.Rom.bPatchTos && !bIsEmuTOS)
809: {
1.1.1.13 root 810: TOS_FixRom();
1.1.1.19 root 811: }
812: else
813: {
814: Log_Printf(LOG_DEBUG, "Skipped TOS patches.\n");
815: }
1.1.1.12 root 816:
817: /* Set connected devices, memory configuration, etc. */
818: STMemory_SetDefaultConfig();
1.1.1.6 root 819:
1.1.1.12 root 820: /* and free loaded image */
821: free(pTosFile);
1.1.1.6 root 822:
1.1.1.16 root 823: bTosImageLoaded = true;
1.1.1.18 root 824: TOS_CreateAutoInf();
1.1.1.6 root 825:
1.1.1.12 root 826: return 0;
1.1 root 827: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.