ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/main.cpp
Revision: 1.11
Committed: 2002-01-15T14:58:32Z (22 years, 10 months ago) by cebix
Branch: MAIN
CVS Tags: snapshot-15012002
Changes since 1.10: +1 -1 lines
Log Message:
- documentation updates
- 2001 -> 2002
- version 0.9 -> 1.0

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     // Set boot volume
106 cebix 1.6 int16 i16 = PrefsFindInt32("bootdrive");
107 cebix 1.1 XPRAM[0x78] = i16 >> 8;
108     XPRAM[0x79] = i16 & 0xff;
109 cebix 1.6 i16 = PrefsFindInt32("bootdriver");
110 cebix 1.1 XPRAM[0x7a] = i16 >> 8;
111     XPRAM[0x7b] = i16 & 0xff;
112    
113     // Init drivers
114     SonyInit();
115     DiskInit();
116     CDROMInit();
117     SCSIInit();
118    
119 cebix 1.2 #if SUPPORTS_EXTFS
120 cebix 1.1 // Init external file system
121     ExtFSInit();
122 cebix 1.2 #endif
123 cebix 1.1
124     // Init serial ports
125     SerialInit();
126    
127     // Init network
128     EtherInit();
129    
130     // Init Time Manager
131     TimerInit();
132    
133     // Init clipboard
134     ClipInit();
135    
136 cebix 1.10 // Init ADB
137     ADBInit();
138    
139 cebix 1.1 // Init audio
140     AudioInit();
141    
142     // Init video
143     if (!VideoInit(ROMVersion == ROM_VERSION_64K || ROMVersion == ROM_VERSION_PLUS || ROMVersion == ROM_VERSION_CLASSIC))
144     return false;
145    
146 cebix 1.8 // Set default video mode
147     XPRAM[0x56] = 0x42; // 'B'
148     XPRAM[0x57] = 0x32; // '2'
149     XPRAM[0x58] = DepthToAppleMode(VideoMonitor.mode.depth);
150     XPRAM[0x59] = 0;
151    
152 cebix 1.1 #if EMULATED_68K
153     // Init 680x0 emulation (this also activates the memory system which is needed for PatchROM())
154     if (!Init680x0())
155     return false;
156     #endif
157    
158     // Install ROM patches
159     if (!PatchROM()) {
160 cebix 1.9 ErrorAlert(STR_UNSUPPORTED_ROM_TYPE_ERR);
161 cebix 1.1 return false;
162     }
163 cebix 1.3
164     #if ENABLE_MON
165     // Initialize mon
166     mon_init();
167     mon_read_byte = mon_read_byte_b2;
168     mon_write_byte = mon_write_byte_b2;
169     #endif
170    
171 cebix 1.1 return true;
172     }
173    
174    
175     /*
176     * Deinitialize everything
177     */
178    
179     void ExitAll(void)
180     {
181 cebix 1.3 #if ENABLE_MON
182     // Deinitialize mon
183     mon_exit();
184     #endif
185    
186 cebix 1.1 // Save XPRAM
187     XPRAMExit();
188    
189     // Exit video
190     VideoExit();
191    
192     // Exit audio
193     AudioExit();
194 cebix 1.10
195     // Exit ADB
196     ADBExit();
197 cebix 1.1
198     // Exit clipboard
199     ClipExit();
200    
201     // Exit Time Manager
202     TimerExit();
203    
204     // Exit serial ports
205     SerialExit();
206    
207     // Exit network
208     EtherExit();
209    
210 cebix 1.2 #if SUPPORTS_EXTFS
211 cebix 1.1 // Exit external file system
212     ExtFSExit();
213 cebix 1.2 #endif
214 cebix 1.1
215     // Exit drivers
216     SCSIExit();
217     CDROMExit();
218     DiskExit();
219     SonyExit();
220 cebix 1.9 }
221    
222    
223     /*
224     * Display error/warning alert given the message string ID
225     */
226    
227     void ErrorAlert(int string_id)
228     {
229     ErrorAlert(GetString(string_id));
230     }
231    
232     void WarningAlert(int string_id)
233     {
234     WarningAlert(GetString(string_id));
235 cebix 1.1 }