-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.c
More file actions
471 lines (410 loc) · 10.3 KB
/
Copy pathmain.c
File metadata and controls
471 lines (410 loc) · 10.3 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
/******************************************************************************
**
** Copyright (C) 1995, an unpublished work by The 3DO Company. All rights
*reserved.
** This material contains confidential information that is the property of The
*3DO Company.
** Any unauthorized duplication, disclosure or use is prohibited.
** $Id: colorecho.c,v 1.24 1995/01/16 19:48:35 vertex Exp $
**
******************************************************************************/
/*
* colorecho - Shows interesting visual effects in tune with audio.
*
* Displays graphic patterns created by drawing a zoomed and rotated
* image of the screen back into the screen (feedback).
*
* Arguments: -g start without waiting for button press
* -m never enter Auto mode
*/
#include "colorecho.h"
#include "displayutils.h"
#include "event.h"
#include "graphics.h"
#include "hardware.h"
#include "stdio.h"
#include "types.h"
#define VERSION "1.6"
/* *************************************************************************
* *** Function Prototypes ***********************************************
* *************************************************************************
*/
int32 ce_DrawAboutScreen(ScreenContext *sc);
int32 ce_ProcessUserInput(ScreenContext *sc, ColorEcho *ce, uint32 Joy);
int32 ce_FakeUserInput(ScreenContext *sc, ColorEcho *ce);
int32 ce_InteractiveLoop(ScreenContext *sc, ColorEcho *ce);
/************************************************************************/
int32
ce_DrawAboutScreen(ScreenContext *sc)
{
int32 y;
GrafCon GCon;
#define LINEHEIGHT (10)
#define LEFTMARGIN (30)
#define NEXTLINE(msg) \
MoveTo(&GCon, LEFTMARGIN, y); \
y += LINEHEIGHT; \
DrawText8(&GCon, sc->sc_BitmapItems[0], (u8 *)(msg));
y = 28;
NEXTLINE("Color Echo ");
DrawText8(&GCon, sc->sc_BitmapItems[0], (u8 *)VERSION);
NEXTLINE("(c) 3DO, May 1993");
NEXTLINE("by Phil Burk");
NEXTLINE(" Left,Right = Rotate");
NEXTLINE(" Up,Down = Zoom");
NEXTLINE(" A = Sprinkle");
NEXTLINE(" B = Lines");
NEXTLINE(" C = Center");
NEXTLINE(" LeftShift = PixelMode");
NEXTLINE(" RightShift = X,Y");
NEXTLINE("Hit any key to continue.");
return 0;
}
/*********************************************************************/
/* Roll binary die based on Prob/1024 */
#define Maybe(Prob) ((((uint32)rand()) & 1023) < (Prob))
/**********************************************************************
** Automatic demo mode.
** Randomly change parameters to simulate user unput.
**********************************************************************/
int32
ce_FakeUserInput(ScreenContext *sc, ColorEcho *ce)
{
int32 Result = 0;
int32 iv;
ce->ce_PIXC = PPMP_BOTH_AVERAGE;
/* Rotate -----------------------------------------*/
/* Maybe set random zoom velocity. */
if(Maybe(10))
{
if(ce->ce_Zoom > ZOOMONE)
{
ce->ce_ZoomVelocity = Random(8) - 4;
}
else
{
ce->ce_ZoomVelocity = Random(8) - 3;
}
}
/* Maybe set random anglular velocity. */
if(Maybe(10))
{
iv = Random(17) - 8; /* -8 -> 8 */
ce->ce_AngleVelocity = (ANGLEDELTA * iv) >> 2;
}
/* Maybe Seed display. */
if(Maybe(30))
{
ce_Seed(sc, ce);
if(Maybe(500))
{
ce_Freeze(ce);
}
}
/* Occasionally ReCenter display. */
if(Maybe(1))
{
ce->ce_Zoom = ZOOMONE;
ce->ce_Angle = 0;
ce->ce_XOffset = 0;
ce->ce_YOffset = 0;
ce_Freeze(ce);
}
/* Modify X,Y velocity. Only use if zoomed out past 1.0 */
if(ce->ce_Zoom < ZOOMONE)
{
if((Maybe(10)) && (ce->ce_XOffset == 0) && (ce->ce_YOffset == 0))
{
ce->ce_XVelocity = Random(3) - 1;
ce->ce_YVelocity = Random(3) - 1;
}
else if(Maybe(40))
{
ce->ce_XVelocity = 0;
ce->ce_YVelocity = 0;
}
}
else
{
ce->ce_XOffset = 0;
ce->ce_YOffset = 0;
ce->ce_XVelocity = 0;
ce->ce_YVelocity = 0;
}
return Result;
}
/************************************************************************/
int32
ce_ProcessUserXY(ColorEcho *ce, uint32 Joy)
{
if(Joy & ControlRight)
{
ce->ce_XVelocity = 1;
}
else if(Joy & ControlLeft)
{
ce->ce_XVelocity = -1;
}
else
{
ce->ce_XVelocity = 0;
}
if(Joy & ControlDown)
{
ce->ce_YVelocity = 1;
}
else if(Joy & ControlUp)
{
ce->ce_YVelocity = -1;
}
else
{
ce->ce_YVelocity = 0;
}
return 0;
}
/************************************************************************/
int32
ce_ProcessUserZoom(ColorEcho *ce, uint32 Joy)
{
if(Joy & ControlUp)
{
ce->ce_ZoomVelocity = 2;
}
else if(Joy & ControlDown)
{
ce->ce_ZoomVelocity = -2;
}
else
{
ce->ce_ZoomVelocity = 0;
}
if(Joy & ControlLeft)
{
ce->ce_AngleVelocity = -ANGLEDELTA;
}
else if(Joy & ControlRight)
{
ce->ce_AngleVelocity = ANGLEDELTA;
}
else
{
ce->ce_AngleVelocity = 0;
}
return 0;
}
/************************************************************************/
int32
ce_ProcessUserInput(ScreenContext *sc, ColorEcho *ce, uint32 Joy)
{
int32 Result;
Result = 0;
ce->ce_IfSport = TRUE;
/* Turn Off Doloresizing with Left Shift */
if(Joy & ControlLeftShift) /* If ControlC held down, move in X,Y */
{
ce->ce_PIXC = PPMP_BOTH_NORMAL;
}
else
{
ce->ce_PIXC = PPMP_BOTH_AVERAGE;
}
/* Use JoyPad to spin and zoom cel. */
if(Joy & ControlRightShift) /* If RightShift held down, move in X,Y */
{
ce_ProcessUserXY(ce, Joy);
}
else
{
ce_ProcessUserZoom(ce, Joy);
}
/* Sprinkle rectangles or dots. */
if(Joy & ControlA)
{
ce_Seed(sc, ce);
}
/* Display line pattern over image. */
if(Joy & ControlB)
{
if(!(ce->ce_Flags & CE_PATTERN_ON)) /* Edge detect button press. */
{
ce->ce_Flags |= CE_PATTERN_ON;
ce->ce_PatternSeed = ReadHardwareRandomNumber();
}
ce_SeedPattern(sc, ce);
}
else
{
ce->ce_Flags &= ~CE_PATTERN_ON; /* Turn off flag. */
}
/* Recenter and freeze motion */
if(Joy & ControlC)
{
ce_Center(ce);
ce_Freeze(ce);
}
return Result;
}
/*********************************************************************/
int32
ce_InteractiveLoop(ScreenContext *sc, ColorEcho *ce)
{
int32 Result;
uint32 Joy;
int32 HandsOffCount;
ControlPadEventData cped;
HandsOffCount = 0;
/* Loop until the user presses ControlX */
while(1)
{
/* Get User input. */
Result = GetControlPad(1, FALSE, &cped);
if(Result < 0)
{
PrintError(0, "\\error in", "GetControlPad", Result);
}
Joy = cped.cped_ButtonBits;
if(Joy & ControlX)
break;
/* If no events, check to see if it is time for AutoMode */
if(Joy == 0)
{
if((HandsOffCount > MAXHANDSOFF) && (ce->ce_Flags & CE_ENABLE_AUTO))
{
ce_FakeUserInput(sc, ce);
}
else
{
HandsOffCount++;
ce_Freeze(ce);
ce->ce_PIXC = PPMP_BOTH_AVERAGE;
ce->ce_Flags &= ~CE_PATTERN_ON; /* Turn off Line Pattern flag. */
}
}
else
{
HandsOffCount = 0;
Result = ce_ProcessUserInput(sc, ce, Joy);
if(Result < 0)
{
PrintError(0, "\\error in", "ce_ProcessUserInput", Result);
goto DONE;
}
}
/* Generate the next video image. */
Result = ce_DrawNextScreen(sc, ce);
if(Result < 0)
{
PrintError(0, "\\error in", "ce_DrawNextScreen", Result);
goto DONE;
}
/* Switch double buffered screens. */
Result = DisplayScreen(sc->sc_Screens[(sc->sc_curScreen)], 0);
if(Result < 0)
{
PrintError(0, "\\error in", "DisplayScreen", Result);
return Result;
}
sc->sc_curScreen = 1 - sc->sc_curScreen;
}
DONE:
return Result;
}
/************************************************************************/
/************************************************************************/
/********* Color Echo Application ***************************************/
/************************************************************************/
/************************************************************************/
int
main(int argc, char *argv[])
{
int32 Result;
ColorEcho MyCE;
char *ptr, c;
uint8 EnableAuto, WaitToStart;
ScreenContext ScreenCon;
ControlPadEventData cped;
EnableAuto = 1;
WaitToStart = 1;
printf("Options:\n");
printf(" -g = Go, don't wait for button press to start.\n");
printf(" -m = Manual, never enter Auto mode.\n");
for(; argc > 1; argc--)
{
ptr = *argv++;
c = *ptr++;
if(c == '-')
{
switch(c = *ptr++)
{
case 'm':
case 'M':
EnableAuto = 0;
break;
case 'g':
case 'G':
WaitToStart = 0;
break;
default:
printf("ERROR: unknown command arg %c\n", c);
break;
}
}
}
/* OpenMathFolio for access to transcendental hardware math. */
Result = OpenMathFolio();
if(Result < 0)
{
PrintError(0, "open math folio", 0, Result);
printf("Did you run operamath?\n");
goto DONE;
}
/* Initialize the EventBroker. */
Result = InitEventUtility(1, 0, LC_ISFOCUSED);
if(Result < 0)
{
PrintError(0, "init event utility", 0, Result);
goto DONE;
}
/* Set up double buffered display. */
Result = CreateBasicDisplay(&ScreenCon, DI_TYPE_NTSC, 2);
if(Result < 0)
{
printf("CreateBasicDisplay failed 0x%lx\n", Result);
return (int)Result;
}
/* Initialize ColorEcho structure. */
if((Result = ce_Init(&MyCE)) != 0)
goto DONE;
if(EnableAuto)
MyCE.ce_Flags |= CE_ENABLE_AUTO;
/* Seed random number generator with hardware random . */
srand(ReadHardwareRandomNumber());
/* Make the screen we have created visible. */
ScreenCon.sc_curScreen = 1;
Result = DisplayScreen(ScreenCon.sc_Screens[0], 0);
if(Result < 0)
{
PrintError(0, "\\error in", "DisplayScreen", Result);
goto DONE;
}
/* Seed graphics */
RandomBoxes(ScreenCon.sc_BitmapItems[0], 99);
RandomBoxes(ScreenCon.sc_BitmapItems[1], 99);
/* Draw the help screen or just start. */
if(WaitToStart)
{
ce_DrawAboutScreen(&ScreenCon);
GetControlPad(1, TRUE, &cped); /* Wait for button press. */
}
ce_InteractiveLoop(&ScreenCon, &MyCE);
/* Cleanup the EventBroker. */
Result = KillEventUtility();
if(Result < 0)
{
PrintError(0, "\\error in", "KillEventUtility", Result);
}
DONE:
printf("\ncolorecho finished!\n");
return ((int)Result);
}