ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/main.cpp
Revision: 1.12
Committed: 2002-03-19T14:25:50Z (22 years, 7 months ago) by cebix
Branch: MAIN
Changes since 1.11: +31 -1 lines
Log Message:
XPRAM gets loaded with default values if "NuMc" signature isn't found. This is
done so the correct (default) video mode is used if the PRAM was wiped.

File Contents

# User Rev Content
1 cebix 1.1 /*
2     * main.cpp - Startup/shutdown code
3     *
4 cebix 1.11 * Basilisk II (C) 1997-2002 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 cebix 1.10 #include "adb.h"
37 cebix 1.1 #include "rom_patches.h"
38     #include "user_strings.h"
39     #include "prefs.h"
40     #include "main.h"
41    
42     #define DEBUG 0
43     #include "debug.h"
44    
45 cebix 1.3 #if ENABLE_MON
46     #include "mon.h"
47    
48     static uint32 mon_read_byte_b2(uint32 adr)
49     {
50     return ReadMacInt8(adr);
51     }
52    
53     static void mon_write_byte_b2(uint32 adr, uint32 b)
54     {
55     WriteMacInt8(adr, b);
56     }
57     #endif
58    
59 cebix 1.1
60     /*
61     * Initialize everything, returns false on error
62     */
63    
64     bool InitAll(void)
65     {
66     // Check ROM version
67     if (!CheckROM()) {
68 cebix 1.9 ErrorAlert(STR_UNSUPPORTED_ROM_TYPE_ERR);
69 cebix 1.1 return false;
70     }
71    
72     #if EMULATED_68K
73     // Set CPU and FPU type (UAE emulation)
74     switch (ROMVersion) {
75     case ROM_VERSION_64K:
76     case ROM_VERSION_PLUS:
77     case ROM_VERSION_CLASSIC:
78     CPUType = 0;
79     FPUType = 0;
80     TwentyFourBitAddressing = true;
81     break;
82     case ROM_VERSION_II:
83 cebix 1.4 CPUType = PrefsFindInt32("cpu");
84     if (CPUType < 2) CPUType = 2;
85     if (CPUType > 4) CPUType = 4;
86 cebix 1.1 FPUType = PrefsFindBool("fpu") ? 1 : 0;
87 cebix 1.4 if (CPUType == 4) FPUType = 1; // 68040 always with FPU
88 cebix 1.1 TwentyFourBitAddressing = true;
89     break;
90     case ROM_VERSION_32:
91 cebix 1.4 CPUType = PrefsFindInt32("cpu");
92     if (CPUType < 2) CPUType = 2;
93     if (CPUType > 4) CPUType = 4;
94 cebix 1.1 FPUType = PrefsFindBool("fpu") ? 1 : 0;
95 cebix 1.4 if (CPUType == 4) FPUType = 1; // 68040 always with FPU
96 cebix 1.1 TwentyFourBitAddressing = false;
97     break;
98     }
99     CPUIs68060 = false;
100     #endif
101    
102     // Load XPRAM
103     XPRAMInit();
104    
105 cebix 1.12 // 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 cebix 1.1 // Set boot volume
136 cebix 1.6 int16 i16 = PrefsFindInt32("bootdrive");
137 cebix 1.1 XPRAM[0x78] = i16 >> 8;
138     XPRAM[0x79] = i16 & 0xff;
139 cebix 1.6 i16 = PrefsFindInt32("bootdriver");
140 cebix 1.1 XPRAM[0x7a] = i16 >> 8;
141     XPRAM[0x7b] = i16 & 0xff;
142    
143     // Init drivers
144     SonyInit();
145     DiskInit();
146     CDROMInit();
147     SCSIInit();
148    
149 cebix 1.2 #if SUPPORTS_EXTFS
150 cebix 1.1 // Init external file system
151     ExtFSInit();
152 cebix 1.2 #endif
153 cebix 1.1
154     // Init serial ports
155     SerialInit();
156    
157     // Init network
158     EtherInit();
159    
160     // Init Time Manager
161     TimerInit();
162    
163     // Init clipboard
164     ClipInit();
165    
166 cebix 1.10 // Init ADB
167     ADBInit();
168    
169 cebix 1.1 // Init audio
170     AudioInit();
171    
172     // Init video
173     if (!VideoInit(ROMVersion == ROM_VERSION_64K || ROMVersion == ROM_VERSION_PLUS || ROMVersion == ROM_VERSION_CLASSIC))
174     return false;
175    
176 cebix 1.12 // Set default video mode in XPRAM
177 cebix 1.8 XPRAM[0x56] = 0x42; // 'B'
178     XPRAM[0x57] = 0x32; // '2'
179     XPRAM[0x58] = DepthToAppleMode(VideoMonitor.mode.depth);
180     XPRAM[0x59] = 0;
181    
182 cebix 1.1 #if EMULATED_68K
183     // Init 680x0 emulation (this also activates the memory system which is needed for PatchROM())
184     if (!Init680x0())
185     return false;
186     #endif
187    
188     // Install ROM patches
189     if (!PatchROM()) {
190 cebix 1.9 ErrorAlert(STR_UNSUPPORTED_ROM_TYPE_ERR);
191 cebix 1.1 return false;
192     }
193 cebix 1.3
194     #if ENABLE_MON
195     // Initialize mon
196     mon_init();
197     mon_read_byte = mon_read_byte_b2;
198     mon_write_byte = mon_write_byte_b2;
199     #endif
200    
201 cebix 1.1 return true;
202     }
203    
204    
205     /*
206     * Deinitialize everything
207     */
208    
209     void ExitAll(void)
210     {
211 cebix 1.3 #if ENABLE_MON
212     // Deinitialize mon
213     mon_exit();
214     #endif
215    
216 cebix 1.1 // Save XPRAM
217     XPRAMExit();
218    
219     // Exit video
220     VideoExit();
221    
222     // Exit audio
223     AudioExit();
224 cebix 1.10
225     // Exit ADB
226     ADBExit();
227 cebix 1.1
228     // Exit clipboard
229     ClipExit();
230    
231     // Exit Time Manager
232     TimerExit();
233    
234     // Exit serial ports
235     SerialExit();
236    
237     // Exit network
238     EtherExit();
239    
240 cebix 1.2 #if SUPPORTS_EXTFS
241 cebix 1.1 // Exit external file system
242     ExtFSExit();
243 cebix 1.2 #endif
244 cebix 1.1
245     // Exit drivers
246     SCSIExit();
247     CDROMExit();
248     DiskExit();
249     SonyExit();
250 cebix 1.9 }
251    
252    
253     /*
254     * Display error/warning alert given the message string ID
255     */
256    
257     void ErrorAlert(int string_id)
258     {
259     ErrorAlert(GetString(string_id));
260     }
261    
262     void WarningAlert(int string_id)
263     {
264     WarningAlert(GetString(string_id));
265 cebix 1.1 }