-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnow.c
507 lines (435 loc) · 12.9 KB
/
snow.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
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
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
/* $Id: snow.c,v 1.16 2004/01/05 22:08:08 eric Exp $
**********************************************************************
* (C) 2003/2004 Copyright Aurora - M. Bilderbeek & E. Boon
*
* DESCRIPTION :
* Main program of the incredible snowTV demo
*
**********************************************************************/
/**********************************************************************
* INCLUDES *
**********************************************************************/
#include "stdlib.h"
#include "msxbios.h"
#include "glib.h"
#include "conio.h"
#include "string.h"
/**********************************************************************
* EXTERNAL REFERENCES (Eventually, these should go into .h files!) *
**********************************************************************/
int gs2loadgrp(uchar scrnmode, uchar page, char *filename);
int kbhit();
//void DBG_mode(uchar);
//void DBG_out(uchar);
/**********************************************************************
* DEFINITIONS *
**********************************************************************/
//#define DEBUG 1
#define FALSE 0
#define TRUE (!(FALSE))
#define SYSVAR(type,x) (*((type *)(x)))
#define CLICKSW SYSVAR(uchar,0xF3DB)
#define JIFFY SYSVAR(uint, 0xFC9E)
#define NOISE_FILE "snowbg2.sr5"
#define GRAFX_FILE "tvs5.sr5"
#define NOISE_PG 2
#define GRAFX_PG 3
#define FONT_Y 0
#define FONT_CPL 16 // Nof characters on a line
#define FONT_W 16
#define FONT_H 12
#define MAXNOFTVS 8
#define TV_H 32
#define TV_W 32
#define TV_Y 80
#define SCROLL_SPD 4
#define GRAVITY 4
#define ST_DEAD 0
#define ST_DYING 1
#define ST_ALIVE 2
/**********************************************************************/
typedef struct
{
unsigned char oldx[2];
unsigned char oldy[2];
unsigned char x;
unsigned char y; // in VRAM
unsigned char imx;
unsigned char imy; // on the source image page
char vx;
char vy;
char dvy;
unsigned char animrev; // 1=reverse
char state;
} tvobj;
/**********************************************************************
* STATIC VARS *
**********************************************************************/
static char* scrolltext[] = {
"Woahh! I guess you expected something like [\\ with | or not? ",
"Well, here it is: [[[[[[\\ and | | |; snow fall all over the place. { ",
"Hah, instead you got a load of falling }s! How about that ",
"for a change... The joke works better in Dutch though, where ",
"}-noise is called \"snow\"! Well, we certainly hope you like ",
"this super lame demo with a screen full of snow and some falling ",
"snow, too... Anyway, we made this demo using Hi-Tech C (via ",
"our own \"htc\" compiler script which can be downloaded from ",
"http://uzix.sf.net/), in ",
"combination with Linux, VIM, openMSX, the GNU C preprocessor, GNU make, cpmemu, Pierre ",
"Gielen's libraries, our own additions to them, GraphSaurus 2 and MSX-Basic ",
"for prototyping.",
" ",
"| { Almost forgot: we wish all of you a great 2004 with lots of MSX fun! { | ",
" ",
"Greetings to ... eh... everyone! { | { ",
" ",
"Did you know this is Manuel's ",
"first real scroll text in his first real (!?) demo? Eric made tons ",
"(at least 2!) of them in the past, being a member of 4Trax... ",
" ",
"Small non-commercial break: check out http://openmsx.sf.net/ for ",
"the most complete open source MSX emulator available... {{{",
" ",
"We don't guarantee that this little demo will work under DOS2 ",
"or other stuff... We didn't really have the time to test that all. ",
"So, if you have problems, use use a plain MSX2, will ya? { ",
" ",
"Heh heh, Eric thinks the colours in this scroll are really ugly... ",
"but I like'em! Guess I have bad taste... The really nice font ",
"was designed by Eric himself, for screen 0 actually! We'll be ",
"using it again in the future! ",
" ",
"OK, now we're really out of scroll text... Let's loop it! ",
" ",
"(This is } man!)",
" ",
"(Don't forget to find the quasi-hidden options..!)",
" ",
"{ | { | { | { | { | { | { | { "
" ",
NULL
};
static char* scrolltext2[] = {
" . . . . KRKGKRKG.... BEEP... <!%+#(@)>~*^#@$|\\)}][{]... kggrr.. ",
"This is the quasi-hidden scroll text, which you get when you press ",
"the 's'-key during this fabulous demo... Well, not much to see here, ",
"is there? Move along people...",
" ",
"Time for the Dutch part... ",
"Zeg, je wilde toch sneeuw zien vallen? Nou, hier heb je 't. ",
"Daaaaag!"
" ",
"Geintje... De kredieten: \"Sneeuw\" is aan 't eind van 2003 ",
"en aan 't begin van 2004 ",
"gemaakt door Eric Boon & Manuel Bilderbeek, zijnde (deel van) ",
"Aurora. Je mag deze software schaamteloos dupliceren zonder ",
"enige beperkingen.",
" ",
NULL
};
static uint palette[] =
{ /*-GRB */
#include <palette.h>
0x0557,
0x0556,
0x0655,
0x0664,
0x0663,
0x0672,
0x0771,
0x0770
};
static tvobj tvarray [MAXNOFTVS];
static uchar vdp23;
static uint textidx;
static char **textptr;
static uchar dpage;
static uchar colormorph;
/**********************************************************************
* AUXILIARY ROUTINES *
**********************************************************************/
/**********************************************************************
* cpyv2v_wrap() - better cpy, to cpy 'around' page borders
*/
void cpyv2v_wrap(uint sx1, uint sy1, uint sx2, uint sy2, uchar sp,
uint dx, uint dy, uchar dp, uchar logop)
{
uint h = sy2 - sy1;
uint h1 = 255 - sy1;
uint h2;
dy &= 255; // afromen die handel!
h2 = 255 - dy;
if(h1 > h ) h1=h;
if(h2 > h ) h2=h;
if(h2 < h1) { h2^=h1; h1^=h2; h2^=h1; } // swap h1, h2
cpyv2v(sx1, sy1, sx2, sy1+h1, sp, dx, dy, dp, logop);
if((h1!=h) && (h1!=h2))
cpyv2v(sx1, (sy1+h1+1) & 255, sx2, (sy1+h2) & 255, sp,
dx, (dy +h1+1) & 255, dp, logop);
if(h2!=h)
cpyv2v(sx1, (sy1+h2+1) & 255, sx2, sy2 & 255, sp,
dx, (dy +h2+1) & 255, dp, logop);
}
/**********************************************************************
* init () - initalisation routine
*/
static void init(void)
{
uchar i;
char filename[13];
//DBG_mode((uchar)0x1F); /* single byte, decimal) */
/* Initialize graphics */
ginit();
color(15, 0, 0);
screen(5);
wrtvdp(8, 10); // disable sprites
disscr();
for(i = 0; i < MAXNOFTVS; i++) {
tvarray[i].state = ST_DEAD;
tvarray[i].x = FONT_W;
tvarray[i].vx = 0;
tvarray[i].vy = 0;
tvarray[i].dvy = 0;
}
for(i = 0; i < 16; i++)
setpal(i, palette[i]);
/* Load the real stuff... */
strcpy(filename, NOISE_FILE);
gs2loadgrp(5, NOISE_PG, filename);
strcpy(filename, GRAFX_FILE);
gs2loadgrp(5, GRAFX_PG, filename);
/* hack to 'grey' the normally invisible area of the screen */
cpyv2v(0, 100, 255, 255-212+100, NOISE_PG, 0, 212, NOISE_PG, PSET);
/* debug*/
#if DEBUG
setpg(0,NOISE_PG);
boxfill(0,212,255,255,8,PSET);
setpg(0,0);
#endif
/* end debug/hack */
/* Fill display pages with noise */
cpyv2v(0, 0, 255, 255, NOISE_PG, 0, 0, 0, PSET);
cpyv2v(0, 0, 255, 255, NOISE_PG, 0, 0, 1, PSET);
/* Initialize 'sound' system */
gicini();
/* Snow sound ;-) */
sound(6, 13); /* noise frequency */
sound(7, 0xB7); /* 10.110.111 channel select */
sound(8, 10); /* volume on channel 1 */
/* hit it! */
vdp23 = 0;
textidx = 0;
textptr = scrolltext;
dpage = 0;
colormorph = TRUE;
srand(JIFFY);
setpg(dpage, 1-dpage);
enascr();
}
/**********************************************************************
* loop_colors() - Color animations for noise in background and on TVs
*/
static void loop_colors(void)
{
static int i = 0;
static int j = 0;
int k=0;
/* Cycle colors 1..3 through palette entries 1..3 */
setpal(1, palette[ (i ) + 1]);
setpal(2, palette[((i + 1) %3) + 1]);
setpal(3, palette[((i + 2) %3) + 1]);
/* Cycle colors 4..6 through palette entries 4..6 */
setpal(4, palette[ (i % 3) + 4]);
setpal(5, palette[((i + 1) % 3) + 4]);
setpal(6, palette[((i + 2) % 3) + 4]);
i++;
i %= 3;
if (colormorph)
{
j++;
j %=14;
k=j;
if (j>7) k=14-j;
setpal(13, palette[16+k]);
setpal(14, palette[16+7-k]);
}
}
/**********************************************************************
* next_char() - puts next character of scroll text on screen
*/
static void next_char()
{
uchar y = (vdp23 - FONT_H),
ch = ((*textptr)[textidx] - ' ');
uint sx = ((ch % FONT_CPL) * FONT_W),
sy = (FONT_Y + ((ch / FONT_CPL) * FONT_H));
/* copy background noise and character on both pages */
cpyv2v_wrap(0, y, FONT_W-1, y + FONT_H-1, NOISE_PG, 0, y, 0, PSET);
cpyv2v_wrap(sx, sy, sx+FONT_W-1, sy + FONT_H-1, GRAFX_PG, 0, y, 0, TPSET);
cpyv2v_wrap(0, y, FONT_W-1, y + FONT_H-1, NOISE_PG, 0, y, 1, PSET);
cpyv2v_wrap(sx, sy, sx+FONT_W-1, sy + FONT_H-1, GRAFX_PG, 0, y, 1, TPSET);
textidx++;
if((*textptr)[textidx]=='\0')
{
++textptr;
if (*textptr==NULL) textptr=scrolltext;
textidx=0;
}
}
/**********************************************************************
* new_tv() - create a new tv
*/
static void new_tv(void)
{
tvobj *tvp = tvarray;
uchar tvx = 0;
uchar tvy = (rand() % 4) * TV_H + TV_Y;
uchar i;
for(i = 0; i < MAXNOFTVS; i++, tvp++) {
if(tvp->state == ST_DEAD) {
tvp->x = rand() % (256 - TV_W - FONT_W);
tvp->x += FONT_W;
tvp->y = vdp23 - TV_H;
tvp->oldx[0] = tvp->x;
tvp->oldx[1] = tvp->x;
tvp->oldy[0] = tvp->y;
tvp->oldy[1] = tvp->y;
tvp->imx=tvx;
tvp->imy=tvy;
tvp->vx = ((rand()%((SCROLL_SPD<<1)-1)) - SCROLL_SPD + 1)/2;
tvp->vy = (rand()%((SCROLL_SPD<<1)-1)) - SCROLL_SPD + 1;
tvp->dvy = GRAVITY;
tvp->state = ST_ALIVE;
tvp->animrev = rand() & 1; // normal or reverse animation
break;
}
}
}
/**********************************************************************
* move_tvs() - Calc. new coordinates
*/
static void move_tvs(void)
{
uchar i;
tvobj *tvp = tvarray;
for(i = 0; i < MAXNOFTVS; i++, tvp++) {
if(tvp->state == ST_ALIVE) {
char animstep=(((tvp->y-vdp23+TV_H)&255)/28); // tv animation (28 == 212/#steps)
if (tvp->animrev) animstep=7-animstep;
tvp->imx=animstep*TV_W;
tvp->oldx[dpage]=tvp->x;
tvp->x+=tvp->vx; // autowrap: uchars
if(tvp->x<FONT_W) {
tvp->x=FONT_W;
tvp->vx=-tvp->vx;
} else if(tvp->x > (255-TV_W)) {
tvp->x=255-TV_W;
tvp->vx=-tvp->vx;
}
tvp->oldy[dpage]=tvp->y;
tvp->y+=tvp->vy; // autowrap: uchars
if((tvp->y >= (uchar)(vdp23 + 212)) && /* in the invisible area */
(tvp->y < (uchar)(vdp23 - TV_H - SCROLL_SPD))) {
tvp->state=ST_DYING; }
if(!(--tvp->dvy)) {
tvp->vy++;
tvp->dvy = GRAVITY;
}
}
}
}
/**********************************************************************
* draw_tvs() - Move them on the screen
*/
static void draw_tvs(void)
{
uchar i;
tvobj *tvp = tvarray;
/* Remove old TVs */
for(i = 0; i < MAXNOFTVS; i++, tvp++) {
if(tvp->state != ST_DEAD) {
uint oldy = tvp->oldy[1-dpage];
uint oldx = tvp->oldx[1-dpage];
cpyv2v_wrap(oldx, oldy, oldx+TV_W-1, oldy+TV_H-1, NOISE_PG,
oldx, oldy, 1-dpage, PSET);
if(tvp->state == ST_DYING)
{
oldy = tvp->oldy[dpage];
oldx = tvp->oldx[dpage];
cpyv2v_wrap(oldx, oldy, oldx+TV_W-1, oldy+TV_H-1, NOISE_PG,
oldx, oldy, dpage, PSET);
tvp->state = ST_DEAD; // object is dead
}
}
}
/* Put new ones */
tvp = tvarray;
for(i = 0; i < MAXNOFTVS; i++, tvp++) {
if(tvp->state == ST_ALIVE) {
cpyv2v_wrap(tvp->imx, tvp->imy, tvp->imx+TV_W-1, tvp->imy+TV_H-1, GRAFX_PG,
tvp->x, tvp->y, 1-dpage, TPSET);
}
}
}
/**********************************************************************
* MAIN ROUTINE
*/
int main ()
{
uchar charcnt = 0;
uchar clicksw = CLICKSW;
uchar goon = 1, loops=0, start=0;
int key;
/* switch off key click */
clicksw = CLICKSW;
CLICKSW = 0;
init();
// now the real stuff begins...
do {
do {
/* Flip pages */
dpage=1-dpage;
while(JIFFY<4)
; /* just wait */
setpg(dpage, 1-dpage);
JIFFY=0;
loop_colors();
vdp23 -= SCROLL_SPD;
charcnt += SCROLL_SPD;
wrtvdp(23, vdp23);
if (start)
{
if(charcnt >= FONT_H) // this doesn't work if FONT_H % SCROLL_SPD != 0
{
next_char();
charcnt = 0;
}
new_tv();
}
move_tvs();
draw_tvs();
if (loops==50) start=TRUE;
else loops++;
}
while(!kbhit());
key=(getch()|32);
if (strchr("ms",key)) {
switch (key)
{
case 'm': colormorph=!colormorph;
break;
case 's': textptr=scrolltext2;
textidx=0;
break;
default: break;
}
}
else { goon=0; }
} while (goon);
kilbuf();
wrtvdp(23, 0);
sound(8,0);
screen(0);
CLICKSW=clicksw;
return 0;
}