forked from LemonHaze420/DCPopulous
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopulous_run.cpp
More file actions
472 lines (416 loc) · 16.1 KB
/
populous_run.cpp
File metadata and controls
472 lines (416 loc) · 16.1 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#include "Populous.h"
#include "Object.h"
#include "SafeProgramming.h"
#include <windows.h>
#include "GameDefines.h"
#include "GraphicsClasses.h"
#include "SoundSystem.h"
#include "Controls.h"
#include "Platform.h"
#include "Preferences.h"
#include "Localization.h"
// Original include files.
#include "God.h"
#include "Extern.h"
#define SAMPLE_NAME_0_10__15 "compwindy2.dat"
#define SAMPLE_NAME_26_51__77 "voicesaah.dat"
#define SAMPLE_NAME_52_53 "complongdr.dat"
#define SAMPLE_NAME_66 "swamped.dat"
#define SAMPLE_NAME_67_68 "sword.dat"
#define SAMPLE_NAME_69 "knighting.dat"
#define SAMPLE_NAME_70 "crackfire.dat"
#define SAMPLE_NAME_71_72 "heart4.dat"
#define SAMPLE_NAME_73 "laugh.dat"
#define SAMPLE_NAME_74__78 "compthunde.dat"
#define SAMPLE_NAME_75__79 "compvolcan.dat"
#define SAMPLE_NAME_76__80 "rumble.dat"
#define SAMPLE_NAME_104 "well_done.dat"
#define SAMPLE_NAME_105 "greater.dat"
#define SAMPLE_NAME_106 "deity.dat"
#define SAMPLE_NAME_107 "eternal.dat"
#define SAMPLE_NAME_109 "immortal.dat"
#define SAMPLE_NAME_110 "god.dat"
#define SAMPLE_NAME_111 "deva.dat"
#define SAMPLE_NAME_112 "being.dat"
#define SAMPLE_NAME_113 "mortal.dat"
// ----
// Function call as Structured Exception Handling (SEH)
// exception filter.
int FilterQuit(LPEXCEPTION_POINTERS _a)
{
if ( (_a)
&& (_a->ExceptionRecord->ExceptionCode == QUIT_EXCEPTION))
return EXCEPTION_EXECUTE_HANDLER;
else
return EXCEPTION_CONTINUE_SEARCH;
}
// ----
// This method is where the whole populous game runs.
// The method simply returns true to indicate that no
// errors occured, and false that something went wrong,
// and that we are to say sorry.
bool CPopulous::Run()
{
FILE *FH;
int i;
// Clear the screens to black, if only for effect.
GraphicsRef->StartDraw();
int tttt = GraphicsRef->GetActiveScreen();
for (i = 0; i < 4; i++)
{
GraphicsRef->SetActiveScreen(i);
GraphicsRef->ClearScreen(0,0,0);
}
GraphicsRef->SetActiveScreen(tttt);
GraphicsRef->EndDraw();
// Now, whatever needs to go here.
int a=200;
int x=3;
int y;
os_byte(a,&x,&y); // ?
// os_read_var_val("Populous$GameType",(char *)&start_of_game,4);
// start_of_game-='0';
start_of_game = selected;
// ----
// Load icons
TempString = ThePlatform->GetPath(EP_ImageData);
TempString += "icon";
FH = FOPEN(TempString.GetString(), "rb");
if (!FH)
return false;
SAFELY_DELETE(IconGraphics);
NEW(IconGraphics, CGraphicsData());
SAFELY_CONTROL(if, IconGraphics, InitAsPopulous(GraphicsRef, FH, 3840, 16, false), ==, false)
return false;
fclose(FH);
TempString = ThePlatform->GetPath(EP_ImageData);
TempString += "iconmask";
FH = FOPEN(TempString.GetString(), "rb");
if (!FH)
return false;
SAFELY_DELETE(ToggleIconGraphics);
NEW(ToggleIconGraphics, CGraphicsData());
SAFELY_CONTROL(if, ToggleIconGraphics, InitAsPopulous(GraphicsRef, FH, 320, 32), ==, false)
return false;
fclose(FH);
// ----
// SAMPLE_NAME_0_10__15
SAFELY_DELETE(SampleArray[0].SampleRef);
NEW(SampleArray[0].SampleRef, CSample());
if (!SampleArray[0].SampleRef->Init(&CString(SAMPLE_NAME_0_10__15), ThePlatform))
return false;
for (i = 0; i <= 10; i++)
SampleArray[i] = SampleArray[0];
SampleArray[15] = SampleArray[0];
// SAMPLE_NAME_26_51__77
SAFELY_DELETE(SampleArray[26].SampleRef);
NEW(SampleArray[26].SampleRef, CSample());
if (!SampleArray[26].SampleRef->Init(&CString(SAMPLE_NAME_26_51__77), ThePlatform))
return false;
for (i = 26; i <= 51; i++)
SampleArray[i].SampleRef = SampleArray[26].SampleRef;
SampleArray[77].SampleRef = SampleArray[26].SampleRef;
// SAMPLE_NAME_52_53
SAFELY_DELETE(SampleArray[52].SampleRef);
NEW(SampleArray[52].SampleRef, CSample());
if (!SampleArray[52].SampleRef->Init(&CString(SAMPLE_NAME_52_53), ThePlatform))
return false;
for (i = 52; i <= 53; i++)
SampleArray[i].SampleRef = SampleArray[52].SampleRef;
// SAMPLE_NAME_66
SAFELY_DELETE(SampleArray[66].SampleRef);
NEW(SampleArray[66].SampleRef, CSample());
if (!SampleArray[66].SampleRef->Init(&CString(SAMPLE_NAME_66), ThePlatform))
return false;
// SAMPLE_NAME_67_68
SAFELY_DELETE(SampleArray[67].SampleRef);
NEW(SampleArray[67].SampleRef, CSample());
if (!SampleArray[67].SampleRef->Init(&CString(SAMPLE_NAME_67_68), ThePlatform))
return false;
for (i = 67; i <= 68; i++)
SampleArray[i].SampleRef = SampleArray[67].SampleRef;
// SAMPLE_NAME_69
SAFELY_DELETE(SampleArray[69].SampleRef);
NEW(SampleArray[69].SampleRef, CSample());
if (!SampleArray[69].SampleRef->Init(&CString(SAMPLE_NAME_69), ThePlatform))
return false;
// SAMPLE_NAME_70
SAFELY_DELETE(SampleArray[70].SampleRef);
NEW(SampleArray[70].SampleRef, CSample());
if (!SampleArray[70].SampleRef->Init(&CString(SAMPLE_NAME_70), ThePlatform))
return false;
// SAMPLE_NAME_71_72
SAFELY_DELETE(SampleArray[71].SampleRef);
NEW(SampleArray[71].SampleRef, CSample());
if (!SampleArray[71].SampleRef->Init(&CString(SAMPLE_NAME_71_72), ThePlatform))
return false;
for (i = 71; i <= 72; i++)
SampleArray[i].SampleRef = SampleArray[71].SampleRef;
// SAMPLE_NAME_73
SAFELY_DELETE(SampleArray[73].SampleRef);
NEW(SampleArray[73].SampleRef, CSample());
if (!SampleArray[73].SampleRef->Init(&CString(SAMPLE_NAME_73), ThePlatform))
return false;
// SAMPLE_NAME_74__78
SAFELY_DELETE(SampleArray[74].SampleRef);
NEW(SampleArray[74].SampleRef, CSample());
if (!SampleArray[74].SampleRef->Init(&CString(SAMPLE_NAME_74__78), ThePlatform))
return false;
SampleArray[78].SampleRef = SampleArray[74].SampleRef;
// SAMPLE_NAME_75__79
SAFELY_DELETE(SampleArray[75].SampleRef);
NEW(SampleArray[75].SampleRef, CSample());
if (!SampleArray[75].SampleRef->Init(&CString(SAMPLE_NAME_75__79), ThePlatform))
return false;
SampleArray[79].SampleRef = SampleArray[75].SampleRef;
// SAMPLE_NAME_76__80
SAFELY_DELETE(SampleArray[76].SampleRef);
NEW(SampleArray[76].SampleRef, CSample());
if (!SampleArray[76].SampleRef->Init(&CString(SAMPLE_NAME_76__80), ThePlatform))
return false;
SampleArray[80].SampleRef = SampleArray[76].SampleRef;
// SAMPLE_NAME_104
SAFELY_DELETE(SampleArray[104].SampleRef);
NEW(SampleArray[104].SampleRef, CSample());
if (!SampleArray[104].SampleRef->Init(&CString(SAMPLE_NAME_104), ThePlatform))
return false;
// SAMPLE_NAME_105
SAFELY_DELETE(SampleArray[105].SampleRef);
NEW(SampleArray[105].SampleRef, CSample());
if (!SampleArray[105].SampleRef->Init(&CString(SAMPLE_NAME_105), ThePlatform))
return false;
// SAMPLE_NAME_106
SAFELY_DELETE(SampleArray[106].SampleRef);
NEW(SampleArray[106].SampleRef, CSample());
if (!SampleArray[106].SampleRef->Init(&CString(SAMPLE_NAME_106), ThePlatform))
return false;
// SAMPLE_NAME_107
SAFELY_DELETE(SampleArray[107].SampleRef);
NEW(SampleArray[107].SampleRef, CSample());
if (!SampleArray[107].SampleRef->Init(&CString(SAMPLE_NAME_107), ThePlatform))
return false;
// SAMPLE_NAME_109
SAFELY_DELETE(SampleArray[109].SampleRef);
NEW(SampleArray[109].SampleRef, CSample());
if (!SampleArray[109].SampleRef->Init(&CString(SAMPLE_NAME_109), ThePlatform))
return false;
// SAMPLE_NAME_110
SAFELY_DELETE(SampleArray[110].SampleRef);
NEW(SampleArray[110].SampleRef, CSample());
if (!SampleArray[110].SampleRef->Init(&CString(SAMPLE_NAME_110), ThePlatform))
return false;
// SAMPLE_NAME_111
SAFELY_DELETE(SampleArray[111].SampleRef);
NEW(SampleArray[111].SampleRef, CSample());
if (!SampleArray[111].SampleRef->Init(&CString(SAMPLE_NAME_111), ThePlatform))
return false;
// SAMPLE_NAME_112
SAFELY_DELETE(SampleArray[112].SampleRef);
NEW(SampleArray[112].SampleRef, CSample());
if (!SampleArray[112].SampleRef->Init(&CString(SAMPLE_NAME_112), ThePlatform))
return false;
// SAMPLE_NAME_113
SAFELY_DELETE(SampleArray[113].SampleRef);
NEW(SampleArray[113].SampleRef, CSample());
if (!SampleArray[113].SampleRef->Init(&CString(SAMPLE_NAME_113), ThePlatform))
return false;
SampleArray[0].Frequency = ((3546895/0x486)*256)/20833;
SampleArray[1].Frequency = ((3546895/0x460)*256)/20833;
SampleArray[2].Frequency = ((3546895/0x43B)*256)/20833;
SampleArray[3].Frequency = ((3546895/0x41A)*256)/20833;
SampleArray[4].Frequency = ((3546895/0x3FA)*256)/20833;
SampleArray[5].Frequency = ((3546895/0x3DC)*256)/20833;
SampleArray[6].Frequency = ((3546895/0x3C0)*256)/20833;
SampleArray[7].Frequency = ((3546895/0x3A6)*256)/20833;
SampleArray[8].Frequency = ((3546895/0x38C)*256)/20833;
SampleArray[9].Frequency = ((3546895/0x375)*256)/20833;
SampleArray[10].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[11].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[12].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[13].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[14].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[15].Frequency = ((3546895/0x408)*256)/20833;
SampleArray[16].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[17].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[18].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[19].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[20].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[21].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[22].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[23].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[24].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[25].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[26].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[27].Frequency = ((3546895/0x382)*256)/20833;
SampleArray[28].Frequency = ((3546895/0x350)*256)/20833;
SampleArray[29].Frequency = ((3546895/0x320)*256)/20833;
SampleArray[30].Frequency = ((3546895/0x2F3)*256)/20833;
SampleArray[31].Frequency = ((3546895/0x2C9)*256)/20833;
SampleArray[32].Frequency = ((3546895/0x2A1)*256)/20833;
SampleArray[33].Frequency = ((3546895/0x27B)*256)/20833;
SampleArray[34].Frequency = ((3546895/0x257)*256)/20833;
SampleArray[35].Frequency = ((3546895/0x236)*256)/20833;
SampleArray[36].Frequency = ((3546895/0x216)*256)/20833;
SampleArray[37].Frequency = ((3546895/0x6A0)*256)/20833;
SampleArray[38].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[39].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[40].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[41].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[42].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[43].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[44].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[45].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[46].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[47].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[48].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[49].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[50].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[51].Frequency = ((3546895/0x6A0)*256)/20833;
SampleArray[52].Frequency = ((3546895/0x3F8)*256)/20833;
SampleArray[53].Frequency = ((3546895/0x652)*256)/20833;
SampleArray[54].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[55].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[56].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[57].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[58].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[59].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[60].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[61].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[62].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[63].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[64].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[65].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[66].Frequency = ((3546895/0x28E)*256)/20833;
SampleArray[67].Frequency = ((3546895/0x2BD)*256)/20833;
SampleArray[68].Frequency = ((3546895/0x2CB)*256)/20833;
SampleArray[69].Frequency = ((3546895/0x2CA)*256)/20833;
SampleArray[70].Frequency = ((3546895/0x1E0)*256)/20833;
SampleArray[71].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[72].Frequency = ((3546895/0x145)*256)/20833;
SampleArray[73].Frequency = ((3546895/0xD27)*256)/20833;
SampleArray[74].Frequency = ((3546895/0x2F7)*256)/20833;
SampleArray[75].Frequency = ((3546895/0x6A8)*256)/20833;
SampleArray[76].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[77].Frequency = ((3546895/0x3B8)*256)/20833;
SampleArray[78].Frequency = ((3546895/0x2F7)*256)/20833;
SampleArray[79].Frequency = ((3546895/0x6A8)*256)/20833;
SampleArray[80].Frequency = ((3546895/0x18C)*256)/20833;
SampleArray[81].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[82].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[83].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[84].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[85].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[86].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[87].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[88].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[89].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[90].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[91].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[92].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[93].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[94].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[95].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[96].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[97].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[98].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[99].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[100].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[101].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[102].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[103].Frequency = ((3546895/0x165)*256)/20833;
SampleArray[104].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[105].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[106].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[107].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[108].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[109].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[110].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[111].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[112].Frequency = ((3546895/0x21E)*256)/20833;
SampleArray[113].Frequency = ((3546895/0x21E)*256)/20833;
#if 0
// Output a list of those values.
for (i = 0; i < 113; i++)
{
ODS("Sample ");
ODI(i);
ODS(" Frequency = ");
ODIN(SampleArray[i].Frequency);
Sleep(5);
}
#endif
// ----
// Timers
SAFELY_DELETE(Timer50ths);
NEW(Timer50ths, CTimer(20));
if (!Timer50ths)
return false;
Timer50ths->AssignSoundSystem(TheSoundSystem);
SAFELY_DELETE(Timer5ths);
NEW(Timer5ths, CTimer(200));
if (!Timer5ths)
return false;
SAFELY_DELETE(GameFrameLimiter);
NEW(GameFrameLimiter, CTimer(1000 / GAME_FRAME_RATE_LIMIT));
if (!GameFrameLimiter)
return false;
GameFrameLimiter->AssignSoundSystem(TheSoundSystem);
SAFELY_DELETE(IntroFrameLimiter);
NEW(IntroFrameLimiter, CTimer(1000 / INTRO_FRAME_RATE_LIMIT));
if (!IntroFrameLimiter)
return false;
IntroFrameLimiter->AssignSoundSystem(TheSoundSystem);
SAFELY_DELETE(MusicTimer);
NEW(MusicTimer, CTimer(20));
if (!MusicTimer)
return false;
//make_arc_sprites_8((char *)font_data,4400L);
//make_arc_sprites_16_nomask((char *)icon_data,3840L);
//sprite_data=(LONG)malloc(SPRITE_DATA);
//sprite_data_32=(LONG)malloc(SPRITE_DATA_32);
//blk_data=(LONG)malloc(BLK_DATA);
open_screen();
//claim_sound_system();
read_sprites(sprites_in);
start_game();
setup_serial_interrupt();
baud_rate=serial.baud_rate=9600;
set_serial();
__try
{
animate();
}
__except(FilterQuit(GetExceptionInformation()))
{
// All okay, we were expecting this exception. It means quit.
ODSN("Caught quit 'exception'");
}
//error_end:;
closeall();
{
int a=200;
int x=0;
int y;
os_byte(a,&x,&y);
}
return true;
}
void CPopulous::closeall()
{
// free((char *)blk_data);
free((char *)screen_pointer[2]);
}
void CPopulous::create_mouse()
{
int a=106;
int x=1;
int y=0;
os_byte(a,&x,&y);
mouse_limit=399;
left_button = 2;
right_button = 2;
}
SHORT CPopulous::Random()
{
return(rand());
}