1 |
|
/* |
2 |
|
* main.cpp - Startup/shutdown code |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2002 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
33 |
|
#include "serial.h" |
34 |
|
#include "ether.h" |
35 |
|
#include "clip.h" |
36 |
+ |
#include "adb.h" |
37 |
|
#include "rom_patches.h" |
38 |
|
#include "user_strings.h" |
39 |
|
#include "prefs.h" |
42 |
|
#define DEBUG 0 |
43 |
|
#include "debug.h" |
44 |
|
|
45 |
+ |
#if ENABLE_MON |
46 |
+ |
#include "mon.h" |
47 |
+ |
|
48 |
+ |
static uint32 mon_read_byte_b2(uintptr adr) |
49 |
+ |
{ |
50 |
+ |
return ReadMacInt8(adr); |
51 |
+ |
} |
52 |
+ |
|
53 |
+ |
static void mon_write_byte_b2(uintptr adr, uint32 b) |
54 |
+ |
{ |
55 |
+ |
WriteMacInt8(adr, b); |
56 |
+ |
} |
57 |
+ |
#endif |
58 |
+ |
|
59 |
|
|
60 |
|
/* |
61 |
|
* Initialize everything, returns false on error |
65 |
|
{ |
66 |
|
// Check ROM version |
67 |
|
if (!CheckROM()) { |
68 |
< |
ErrorAlert(GetString(STR_UNSUPPORTED_ROM_TYPE_ERR)); |
68 |
> |
ErrorAlert(STR_UNSUPPORTED_ROM_TYPE_ERR); |
69 |
|
return false; |
70 |
|
} |
71 |
|
|
80 |
|
TwentyFourBitAddressing = true; |
81 |
|
break; |
82 |
|
case ROM_VERSION_II: |
83 |
< |
CPUType = 2; |
83 |
> |
CPUType = PrefsFindInt32("cpu"); |
84 |
> |
if (CPUType < 2) CPUType = 2; |
85 |
> |
if (CPUType > 4) CPUType = 4; |
86 |
|
FPUType = PrefsFindBool("fpu") ? 1 : 0; |
87 |
+ |
if (CPUType == 4) FPUType = 1; // 68040 always with FPU |
88 |
|
TwentyFourBitAddressing = true; |
89 |
|
break; |
90 |
|
case ROM_VERSION_32: |
91 |
< |
CPUType = 3; |
91 |
> |
CPUType = PrefsFindInt32("cpu"); |
92 |
> |
if (CPUType < 2) CPUType = 2; |
93 |
> |
if (CPUType > 4) CPUType = 4; |
94 |
|
FPUType = PrefsFindBool("fpu") ? 1 : 0; |
95 |
+ |
if (CPUType == 4) FPUType = 1; // 68040 always with FPU |
96 |
|
TwentyFourBitAddressing = false; |
97 |
|
break; |
98 |
|
} |
102 |
|
// Load XPRAM |
103 |
|
XPRAMInit(); |
104 |
|
|
105 |
+ |
// Load XPRAM default values if signature not found |
106 |
+ |
if (XPRAM[0x0c] != 0x4e || XPRAM[0x0d] != 0x75 |
107 |
+ |
|| XPRAM[0x0e] != 0x4d || XPRAM[0x0f] != 0x63) { |
108 |
+ |
D(bug("Loading XPRAM default values\n")); |
109 |
+ |
memset(XPRAM, 0, 0x100); |
110 |
+ |
XPRAM[0x0c] = 0x4e; // "NuMc" signature |
111 |
+ |
XPRAM[0x0d] = 0x75; |
112 |
+ |
XPRAM[0x0e] = 0x4d; |
113 |
+ |
XPRAM[0x0f] = 0x63; |
114 |
+ |
XPRAM[0x01] = 0x80; // InternalWaitFlags = DynWait (don't wait for SCSI devices upon bootup) |
115 |
+ |
XPRAM[0x10] = 0xa8; // Standard PRAM values |
116 |
+ |
XPRAM[0x11] = 0x00; |
117 |
+ |
XPRAM[0x12] = 0x00; |
118 |
+ |
XPRAM[0x13] = 0x22; |
119 |
+ |
XPRAM[0x14] = 0xcc; |
120 |
+ |
XPRAM[0x15] = 0x0a; |
121 |
+ |
XPRAM[0x16] = 0xcc; |
122 |
+ |
XPRAM[0x17] = 0x0a; |
123 |
+ |
XPRAM[0x1c] = 0x00; |
124 |
+ |
XPRAM[0x1d] = 0x02; |
125 |
+ |
XPRAM[0x1e] = 0x63; |
126 |
+ |
XPRAM[0x1f] = 0x00; |
127 |
+ |
XPRAM[0x08] = 0x13; |
128 |
+ |
XPRAM[0x09] = 0x88; |
129 |
+ |
XPRAM[0x0a] = 0x00; |
130 |
+ |
XPRAM[0x0b] = 0xcc; |
131 |
+ |
XPRAM[0x76] = 0x00; // OSDefault = MacOS |
132 |
+ |
XPRAM[0x77] = 0x01; |
133 |
+ |
} |
134 |
+ |
|
135 |
|
// Set boot volume |
136 |
< |
int16 i16 = PrefsFindInt16("bootdrive"); |
136 |
> |
int16 i16 = PrefsFindInt32("bootdrive"); |
137 |
|
XPRAM[0x78] = i16 >> 8; |
138 |
|
XPRAM[0x79] = i16 & 0xff; |
139 |
< |
i16 = PrefsFindInt16("bootdriver"); |
139 |
> |
i16 = PrefsFindInt32("bootdriver"); |
140 |
|
XPRAM[0x7a] = i16 >> 8; |
141 |
|
XPRAM[0x7b] = i16 & 0xff; |
142 |
|
|
146 |
|
CDROMInit(); |
147 |
|
SCSIInit(); |
148 |
|
|
149 |
+ |
#if SUPPORTS_EXTFS |
150 |
|
// Init external file system |
151 |
|
ExtFSInit(); |
152 |
+ |
#endif |
153 |
|
|
154 |
|
// Init serial ports |
155 |
|
SerialInit(); |
163 |
|
// Init clipboard |
164 |
|
ClipInit(); |
165 |
|
|
166 |
+ |
// Init ADB |
167 |
+ |
ADBInit(); |
168 |
+ |
|
169 |
|
// Init audio |
170 |
|
AudioInit(); |
171 |
|
|
173 |
|
if (!VideoInit(ROMVersion == ROM_VERSION_64K || ROMVersion == ROM_VERSION_PLUS || ROMVersion == ROM_VERSION_CLASSIC)) |
174 |
|
return false; |
175 |
|
|
176 |
+ |
// Set default video mode in XPRAM |
177 |
+ |
XPRAM[0x56] = 0x42; // 'B' |
178 |
+ |
XPRAM[0x57] = 0x32; // '2' |
179 |
+ |
const monitor_desc &main_monitor = *VideoMonitors[0]; |
180 |
+ |
XPRAM[0x58] = main_monitor.depth_to_apple_mode(main_monitor.get_current_mode().depth); |
181 |
+ |
XPRAM[0x59] = 0; |
182 |
+ |
|
183 |
|
#if EMULATED_68K |
184 |
|
// Init 680x0 emulation (this also activates the memory system which is needed for PatchROM()) |
185 |
|
if (!Init680x0()) |
188 |
|
|
189 |
|
// Install ROM patches |
190 |
|
if (!PatchROM()) { |
191 |
< |
ErrorAlert(GetString(STR_UNSUPPORTED_ROM_TYPE_ERR)); |
191 |
> |
ErrorAlert(STR_UNSUPPORTED_ROM_TYPE_ERR); |
192 |
|
return false; |
193 |
|
} |
194 |
+ |
|
195 |
+ |
#if ENABLE_MON |
196 |
+ |
// Initialize mon |
197 |
+ |
mon_init(); |
198 |
+ |
mon_read_byte = mon_read_byte_b2; |
199 |
+ |
mon_write_byte = mon_write_byte_b2; |
200 |
+ |
#endif |
201 |
+ |
|
202 |
|
return true; |
203 |
|
} |
204 |
|
|
209 |
|
|
210 |
|
void ExitAll(void) |
211 |
|
{ |
212 |
+ |
#if ENABLE_MON |
213 |
+ |
// Deinitialize mon |
214 |
+ |
mon_exit(); |
215 |
+ |
#endif |
216 |
+ |
|
217 |
|
// Save XPRAM |
218 |
|
XPRAMExit(); |
219 |
|
|
223 |
|
// Exit audio |
224 |
|
AudioExit(); |
225 |
|
|
226 |
+ |
// Exit ADB |
227 |
+ |
ADBExit(); |
228 |
+ |
|
229 |
|
// Exit clipboard |
230 |
|
ClipExit(); |
231 |
|
|
238 |
|
// Exit network |
239 |
|
EtherExit(); |
240 |
|
|
241 |
+ |
#if SUPPORTS_EXTFS |
242 |
|
// Exit external file system |
243 |
|
ExtFSExit(); |
244 |
+ |
#endif |
245 |
|
|
246 |
|
// Exit drivers |
247 |
|
SCSIExit(); |
249 |
|
DiskExit(); |
250 |
|
SonyExit(); |
251 |
|
} |
252 |
+ |
|
253 |
+ |
|
254 |
+ |
/* |
255 |
+ |
* Display error/warning alert given the message string ID |
256 |
+ |
*/ |
257 |
+ |
|
258 |
+ |
void ErrorAlert(int string_id) |
259 |
+ |
{ |
260 |
+ |
ErrorAlert(GetString(string_id)); |
261 |
+ |
} |
262 |
+ |
|
263 |
+ |
void WarningAlert(int string_id) |
264 |
+ |
{ |
265 |
+ |
WarningAlert(GetString(string_id)); |
266 |
+ |
} |