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