1 |
cebix |
1.1 |
/* |
2 |
|
|
* main.cpp - Startup/shutdown code |
3 |
|
|
* |
4 |
cebix |
1.7 |
* Basilisk II (C) 1997-2001 Christian Bauer |
5 |
cebix |
1.1 |
* |
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 |
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
* (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "sysdeps.h" |
22 |
|
|
|
23 |
|
|
#include "cpu_emulation.h" |
24 |
|
|
#include "xpram.h" |
25 |
|
|
#include "timer.h" |
26 |
|
|
#include "sony.h" |
27 |
|
|
#include "disk.h" |
28 |
|
|
#include "cdrom.h" |
29 |
|
|
#include "scsi.h" |
30 |
|
|
#include "extfs.h" |
31 |
|
|
#include "audio.h" |
32 |
|
|
#include "video.h" |
33 |
|
|
#include "serial.h" |
34 |
|
|
#include "ether.h" |
35 |
|
|
#include "clip.h" |
36 |
|
|
#include "rom_patches.h" |
37 |
|
|
#include "user_strings.h" |
38 |
|
|
#include "prefs.h" |
39 |
|
|
#include "main.h" |
40 |
|
|
|
41 |
|
|
#define DEBUG 0 |
42 |
|
|
#include "debug.h" |
43 |
|
|
|
44 |
cebix |
1.3 |
#if ENABLE_MON |
45 |
|
|
#include "mon.h" |
46 |
|
|
|
47 |
|
|
static uint32 mon_read_byte_b2(uint32 adr) |
48 |
|
|
{ |
49 |
|
|
return ReadMacInt8(adr); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
static void mon_write_byte_b2(uint32 adr, uint32 b) |
53 |
|
|
{ |
54 |
|
|
WriteMacInt8(adr, b); |
55 |
|
|
} |
56 |
|
|
#endif |
57 |
|
|
|
58 |
cebix |
1.1 |
|
59 |
|
|
/* |
60 |
|
|
* Initialize everything, returns false on error |
61 |
|
|
*/ |
62 |
|
|
|
63 |
|
|
bool InitAll(void) |
64 |
|
|
{ |
65 |
|
|
// Check ROM version |
66 |
|
|
if (!CheckROM()) { |
67 |
|
|
ErrorAlert(GetString(STR_UNSUPPORTED_ROM_TYPE_ERR)); |
68 |
|
|
return false; |
69 |
|
|
} |
70 |
|
|
|
71 |
|
|
#if EMULATED_68K |
72 |
|
|
// Set CPU and FPU type (UAE emulation) |
73 |
|
|
switch (ROMVersion) { |
74 |
|
|
case ROM_VERSION_64K: |
75 |
|
|
case ROM_VERSION_PLUS: |
76 |
|
|
case ROM_VERSION_CLASSIC: |
77 |
|
|
CPUType = 0; |
78 |
|
|
FPUType = 0; |
79 |
|
|
TwentyFourBitAddressing = true; |
80 |
|
|
break; |
81 |
|
|
case ROM_VERSION_II: |
82 |
cebix |
1.4 |
CPUType = PrefsFindInt32("cpu"); |
83 |
|
|
if (CPUType < 2) CPUType = 2; |
84 |
|
|
if (CPUType > 4) CPUType = 4; |
85 |
cebix |
1.1 |
FPUType = PrefsFindBool("fpu") ? 1 : 0; |
86 |
cebix |
1.4 |
if (CPUType == 4) FPUType = 1; // 68040 always with FPU |
87 |
cebix |
1.1 |
TwentyFourBitAddressing = true; |
88 |
|
|
break; |
89 |
|
|
case ROM_VERSION_32: |
90 |
cebix |
1.4 |
CPUType = PrefsFindInt32("cpu"); |
91 |
|
|
if (CPUType < 2) CPUType = 2; |
92 |
|
|
if (CPUType > 4) CPUType = 4; |
93 |
cebix |
1.1 |
FPUType = PrefsFindBool("fpu") ? 1 : 0; |
94 |
cebix |
1.4 |
if (CPUType == 4) FPUType = 1; // 68040 always with FPU |
95 |
cebix |
1.1 |
TwentyFourBitAddressing = false; |
96 |
|
|
break; |
97 |
|
|
} |
98 |
|
|
CPUIs68060 = false; |
99 |
|
|
#endif |
100 |
|
|
|
101 |
|
|
// Load XPRAM |
102 |
|
|
XPRAMInit(); |
103 |
|
|
|
104 |
|
|
// Set boot volume |
105 |
cebix |
1.6 |
int16 i16 = PrefsFindInt32("bootdrive"); |
106 |
cebix |
1.1 |
XPRAM[0x78] = i16 >> 8; |
107 |
|
|
XPRAM[0x79] = i16 & 0xff; |
108 |
cebix |
1.6 |
i16 = PrefsFindInt32("bootdriver"); |
109 |
cebix |
1.1 |
XPRAM[0x7a] = i16 >> 8; |
110 |
|
|
XPRAM[0x7b] = i16 & 0xff; |
111 |
|
|
|
112 |
|
|
// Init drivers |
113 |
|
|
SonyInit(); |
114 |
|
|
DiskInit(); |
115 |
|
|
CDROMInit(); |
116 |
|
|
SCSIInit(); |
117 |
|
|
|
118 |
cebix |
1.2 |
#if SUPPORTS_EXTFS |
119 |
cebix |
1.1 |
// Init external file system |
120 |
|
|
ExtFSInit(); |
121 |
cebix |
1.2 |
#endif |
122 |
cebix |
1.1 |
|
123 |
|
|
// Init serial ports |
124 |
|
|
SerialInit(); |
125 |
|
|
|
126 |
|
|
// Init network |
127 |
|
|
EtherInit(); |
128 |
|
|
|
129 |
|
|
// Init Time Manager |
130 |
|
|
TimerInit(); |
131 |
|
|
|
132 |
|
|
// Init clipboard |
133 |
|
|
ClipInit(); |
134 |
|
|
|
135 |
|
|
// Init audio |
136 |
|
|
AudioInit(); |
137 |
|
|
|
138 |
|
|
// Init video |
139 |
|
|
if (!VideoInit(ROMVersion == ROM_VERSION_64K || ROMVersion == ROM_VERSION_PLUS || ROMVersion == ROM_VERSION_CLASSIC)) |
140 |
|
|
return false; |
141 |
|
|
|
142 |
|
|
#if EMULATED_68K |
143 |
|
|
// Init 680x0 emulation (this also activates the memory system which is needed for PatchROM()) |
144 |
|
|
if (!Init680x0()) |
145 |
|
|
return false; |
146 |
|
|
#endif |
147 |
|
|
|
148 |
|
|
// Install ROM patches |
149 |
|
|
if (!PatchROM()) { |
150 |
|
|
ErrorAlert(GetString(STR_UNSUPPORTED_ROM_TYPE_ERR)); |
151 |
|
|
return false; |
152 |
|
|
} |
153 |
cebix |
1.3 |
|
154 |
|
|
#if ENABLE_MON |
155 |
|
|
// Initialize mon |
156 |
|
|
mon_init(); |
157 |
|
|
mon_read_byte = mon_read_byte_b2; |
158 |
|
|
mon_write_byte = mon_write_byte_b2; |
159 |
|
|
#endif |
160 |
|
|
|
161 |
cebix |
1.1 |
return true; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
|
165 |
|
|
/* |
166 |
|
|
* Deinitialize everything |
167 |
|
|
*/ |
168 |
|
|
|
169 |
|
|
void ExitAll(void) |
170 |
|
|
{ |
171 |
cebix |
1.3 |
#if ENABLE_MON |
172 |
|
|
// Deinitialize mon |
173 |
|
|
mon_exit(); |
174 |
|
|
#endif |
175 |
|
|
|
176 |
cebix |
1.1 |
// Save XPRAM |
177 |
|
|
XPRAMExit(); |
178 |
|
|
|
179 |
|
|
// Exit video |
180 |
|
|
VideoExit(); |
181 |
|
|
|
182 |
|
|
// Exit audio |
183 |
|
|
AudioExit(); |
184 |
|
|
|
185 |
|
|
// Exit clipboard |
186 |
|
|
ClipExit(); |
187 |
|
|
|
188 |
|
|
// Exit Time Manager |
189 |
|
|
TimerExit(); |
190 |
|
|
|
191 |
|
|
// Exit serial ports |
192 |
|
|
SerialExit(); |
193 |
|
|
|
194 |
|
|
// Exit network |
195 |
|
|
EtherExit(); |
196 |
|
|
|
197 |
cebix |
1.2 |
#if SUPPORTS_EXTFS |
198 |
cebix |
1.1 |
// Exit external file system |
199 |
|
|
ExtFSExit(); |
200 |
cebix |
1.2 |
#endif |
201 |
cebix |
1.1 |
|
202 |
|
|
// Exit drivers |
203 |
|
|
SCSIExit(); |
204 |
|
|
CDROMExit(); |
205 |
|
|
DiskExit(); |
206 |
|
|
SonyExit(); |
207 |
|
|
} |