-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFIRE.C
More file actions
79 lines (67 loc) · 1.79 KB
/
FIRE.C
File metadata and controls
79 lines (67 loc) · 1.79 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
/* Fire effect - Copyright (c) 2025 Henrik Löfgren
* This program is distributable under the terms of the 2-clause BSD license.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#include "gfxlib.h"
void setPalette(void);
int main(void)
{
unsigned char buffer[64640];
int x,y,cnt;
int ypos;
float runtime;
clock_t start_time, end_time;
setVideoMode(0x13);
setPalette();
start_time = clock();
for(cnt=0; cnt<60000; cnt++) {
// Seed lines
for(x=0; x<320;x++) {
if(x<160) {
buffer[64000+x] = (x>>1) + (unsigned char)(rand() % (96+x));
} else {
buffer[64000+x] = (unsigned char)(rand() % (256-(x-160)));
}
if(x<160) {
buffer[64320+x] = (unsigned char)(rand() %(96+x));
} else {
buffer[64320+x] = (unsigned char)(rand() % (256-(x-160)))+
((x-160)>>1);
}
}
// Fire effect
for(y=1; y<200; y++) {
ypos = (y<<8) + (y<<6);
for(x=0; x<320; x++) {
buffer[ypos + x] = ((buffer[ypos+x-320]<<2)+
(buffer[ypos+x+320]<<2)+
(buffer[ypos+x+319]<<1)+
(buffer[ypos+x+321]<<1)+
(buffer[ypos+x+640]<<2))>>4;
}
}
updateScreen(&buffer);
if(kbhit()) break;
}
end_time=clock();
getch();
runtime = (float)(end_time-start_time)/((float)CLOCKS_PER_SEC);
setVideoMode(0x03);
printf("Frames: %d\n", cnt);
printf("Runtime: %f\n", runtime);
printf("FPS: %f\n", (float)cnt/runtime);
return 0;
}
void setPalette(void)
{
int i;
for(i=0; i<64; i++) setPalReg(i,0,0,0);
for(i=64; i<96; i++) setPalReg(i,(i-64)<<1,0,0);
for(i=96; i<160; i++) setPalReg(i,63,(i-96),0);
for(i=160; i<224; i++) setPalReg(i,63,63,(i-160));
for(i=224; i<256; i++) setPalReg(i,63,63,63);
}