1 /*
2
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 */
19 //====================================================================================
20 //
21 // System Shock - ©1994-1995 Looking Glass Technologies, Inc.
22 //
23 // InitMac.c - Initialize Mac toolbox managers and setup the application's globals.
24 //
25 //====================================================================================
26
27
28 //--------------------
29 // Includes
30 //--------------------
31 //#include <Palettes.h>
32 //#include <GestaltEqu.h>
33 //#include <Movies.h>
34
35 #include "Shock.h"
36 #include "InitMac.h"
37 #include "ShockBitmap.h"
38 //#include "MacTune.h"
39 #include <SDL.h>
40
41 #include "shockolate_version.h"
42 #include "tickcount.h"
43
44 //--------------------
45 // Globals
46 //--------------------
47 #ifndef __MWERKS__
48 //QDGlobals qd;
49 #endif
50 //ColorSpec *gOriginalColors;
51 unsigned long gRandSeed;
52 short gMainVRef;
53 //CursHandle gWatchCurs;
54 short gOriginalDepth = -1;
55 short gLastAlertDepth = -1;
56 short gStartupDepth;
57 char *gScreenAddress;
58 long gScreenRowbytes;
59 short gScreenWide, gScreenHigh;
60 short gActiveWide, gActiveHigh;
61 short gActiveLeft, gActiveTop;
62 //Rect gActiveArea, gOffActiveArea;
63 //Boolean gIsPowerPC = false;
64 long gDataDirID;
65 short gDataVref;
66 long gCDDataDirID;
67 short gCDDataVref;
68 long gAlogDirID;
69 short gAlogVref;
70 long gBarkDirID;
71 short gBarkVref;
72 //Boolean gMenusHid;
73
74 //---------------------------
75 // Externs
76 //---------------------------
77 void status_bio_update(void);
78 extern uchar gBioInited;
79 void MousePollProc(void);
80
81
82 //---------------------------
83 // Internal Prototypes
84 //---------------------------
85 void Cleanup(void);
86
87 //---------------------------
88 // Time Manager routines and globals
89 //---------------------------
90 long gShockTicks;
91 long *tmd_ticks;
92
93 //------------------------------------------------------------------------------------
94 // Initialize the Macintosh managers.
95 //------------------------------------------------------------------------------------
InitMac(void)96 void InitMac(void)
97 {
98 INFO("Starting %s", SHOCKOLATE_VERSION);
99
100 // Get a random seed
101 gRandSeed = TickCount();
102 gRandSeed += TickCount()<<8;
103
104 InstallShockTimers(); // needed for the tick pointer
105 }
106
107 //------------------------------------------------------------------------------------
108 // Get a resource and fail correctly if it can't be loaded.
109 //------------------------------------------------------------------------------------
110 /*Handle GetResourceFail(long id, short num)
111 {
112 Handle h;
113
114 h = GetResource(id, num);
115 if (h) return(h);
116
117 #if 1
118 STUB("If GetResource() and friends are relevant after all, implement this..")
119 #else
120
121 // At this point GetResource failed, figure out why.
122 SetResLoad(false);
123 h = GetResource(id, num);
124 SetResLoad(true);
125
126 if (gExtraMemory)
127 DisposHandle(gExtraMemory);
128
129 if (h)
130 ErrorDie(1); // resource is there, must be a memory problem
131 else
132 ErrorDie(3); // resource not there, somethings bad
133 #endif
134 return (nil);
135 }*/
136
137
138 //------------------------------------------------------------------------------------
139 // Startup the SystemShock timer.
140 //------------------------------------------------------------------------------------
InstallShockTimers(void)141 void InstallShockTimers(void)
142 {
143 gShockTicks = 0;
144 tmd_ticks = &gShockTicks;
145 }
146
147 //------------------------------------------------------------------------------------
148 // Remove the SystemShock timer.
149 //------------------------------------------------------------------------------------
RemoveShockTimers(void)150 void RemoveShockTimers(void)
151 {
152 #if 1
153 STUB("if the timer is still used, remove it here..")
154 #else
155 RmvTime((QElemPtr)&pShockTicksTask); // Stop the Shock ticks task
156 // DisposeRoutineDescriptor(pShockTicksPtr); // Dispose its UPP
157 #endif
158 }
159
160 //------------------------------------------------------------------------------------
161 // Timer tick callback.
162 //------------------------------------------------------------------------------------
TimerTickCallback(Uint32 interval,void * param)163 Uint32 TimerTickCallback(Uint32 interval, void *param)
164 {
165 gShockTicks++;
166 return interval;
167 }
168
169 //------------------------------------------------------------------------------------
170 // Display an alert using the str# resource with index strignum, then die.
171 //------------------------------------------------------------------------------------
ErrorDie(short stringnum)172 void ErrorDie(short stringnum)
173 {
174 /*if (gExtraMemory)
175 DisposHandle(gExtraMemory); // free our extra space
176
177 StringAlert(stringnum);
178 CleanupAndExit();*/
179 }
180
181 //------------------------------------------------------------------------------------
182 // Display an alert using the str# resource with index strignum
183 //------------------------------------------------------------------------------------
StringAlert(short stringnum)184 void StringAlert(short stringnum)
185 {
186 /*Str255 message, explain;
187
188 InitCursor();
189 GetIndString(message, 1000, stringnum);
190 GetIndString(explain, 1001, stringnum);
191 ParamText(message, explain, "", "");
192
193 if (*explain)
194 StopAlert(1001, nil);
195 else
196 StopAlert(1000, nil);*/
197 }
198
199 #pragma mark -
200 //------------------------------------------------------------------------------------
201 // Close all our resources, then quit.
202 //------------------------------------------------------------------------------------
Cleanup(void)203 void Cleanup(void)
204 {
205 /*GDHandle devhandle;
206
207 MacTuneShutdown();
208 RemoveShockTimers();
209
210 snd_kill_all_samples();
211 snd_shutdown();
212
213 if (gOriginalDepth != -1) // If color depth was changed at beginning of app,
214 { // then switch it back to the original.
215 devhandle = GetMainDevice();
216 if (devhandle)
217 if (HasDepth(devhandle, gOriginalDepth, 0, 0))
218 SetDepth(devhandle, gOriginalDepth, 0, 0);
219 }
220 else
221 CleanupPalette(); // Else switch back to original 8-bit palette.
222
223 gr_close();
224 mouse_shutdown();
225 kb_shutdown();
226 ResTerm();*/
227 }
228
229 //------------------------------------------------------------------------------------
230 // Normal cleanup when the program quits.
231 //------------------------------------------------------------------------------------
CleanupAndExit(void)232 void CleanupAndExit(void)
233 {
234 /*Cleanup();
235 ExitToShell();*/
236 }
237
238