-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsierpinski.c
85 lines (65 loc) · 1.46 KB
/
sierpinski.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
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include <tgi.h>
#include <cc65.h>
#define SCREEN_X (tgi_getxres())
#define SCREEN_Y (tgi_getyres())
/* Use static local variables for speed */
#pragma static-locals (1);
void sierpinski () {
register unsigned int row, column;
for (row = 0; row < SCREEN_Y; row++) {
for (column = 0; column < SCREEN_X; column++) {
if (!(row & column)) {
tgi_setpixel (column, row);
}
}
}
}
int main (void)
{
clock_t t;
unsigned long sec;
unsigned sec10;
unsigned char err;
clrscr();
/* Install the graphics driver */
tgi_install(tgi_static_stddrv);
err = tgi_geterror();
if (err != TGI_ERR_OK)
{
cprintf("Error #%d initializing graphics.\r\n%s\r\n",
err, tgi_geterrormsg(err));
if (doesclrscrafterexit())
{
cgetc();
}
exit(EXIT_FAILURE);
};
/* Initialize graphics */
tgi_init();
tgi_clear();
t = clock();
/* draw */
sierpinski();
t = clock() - t;
/* Fetch the character from the keyboard buffer and discard it */
cgetc();
/* Shut down gfx mode and return to textmode */
tgi_done();
/* Calculate stats */
sec = (t * 10) / CLK_TCK;
sec10 = sec % 10;
sec /= 10;
/* Output stats */
cprintf("time: %lu.%us\n\r", sec, sec10);
if (doesclrscrafterexit())
{
/* Wait for a key, then end */
cputs("Press any key when done...\n\r");
cgetc();
}
/* Done */
return EXIT_SUCCESS;
}