mkrandtex.c
2.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
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
#include <stdio.h>
#define VRAND_WIDTH 32
#define VRAND_HEIGHT 64
#define VRAND_SIZE VRAND_WIDTH*VRAND_HEIGHT
#define CS_EW_WIDTH 43
#define CS_EW_HEIGHT 21
main()
{
int i, j;
unsigned short stmp;
unsigned long ltmp;
double v[VRAND_SIZE];
int iy;
float two16m1 = 65535.0;
FILE *fd;
fd = fopen("map_rand.h","w+");
/*
fprintf(fd,"static Gfx map_C_dummy_aligner1[] = { gsSPEndDisplayList() };\n\n");
*/
fprintf(fd,"unsigned short map_rand[] = {\n");
iy = 12345;
vrand(VRAND_SIZE, v, &iy);
for (j = 0; j < VRAND_HEIGHT; j++ ) {
fprintf(fd,"\t",stmp);
for (i = 0; i < VRAND_WIDTH; i++) {
stmp = two16m1*v[VRAND_WIDTH*j + i];
fprintf(fd," 0x%x,",stmp);
}
fprintf(fd,"\n");
}
fprintf(fd,"\n};\n");
fclose(fd);
fd = fopen("map_rand_comp.h","w+");
/*
fprintf(fd,"static Gfx map_C_dummy_aligner2[] = { gsSPEndDisplayList() };\n\n");
*/
fprintf(fd,"unsigned short map_rand_comp[] = {\n");
iy = 12345;
vrand(VRAND_SIZE, v, &iy);
for (j = 0; j < VRAND_HEIGHT; j++ ) {
fprintf(fd,"\t",stmp);
for (i = 0; i < VRAND_WIDTH; i++) {
stmp = two16m1*v[VRAND_WIDTH*j + i];
stmp = ~(stmp);
fprintf(fd," 0x%x,",stmp);
}
fprintf(fd,"\n");
}
fprintf(fd,"\n};\n");
fclose(fd);
/*
* Now generate a 32 x 32 texture.
*/
fd = fopen("map_rand32.h","w+");
fprintf(fd,"unsigned long map_rand32[] = {\n");
for (j = 0; j < 32; j++ ) {
fprintf(fd,"\t");
for (i = 0; i < 32; i++) {
ltmp = random();
fprintf(fd," 0x%x,",ltmp);
}
fprintf(fd,"\n");
}
fprintf(fd,"\n};\n");
fclose(fd);
fd = fopen("map_cs16_rand.h","w+");
fprintf(fd,"unsigned short map_cs16_rand[] = {\n");
iy = 12345;
vrand(CS_EW_WIDTH * CS_EW_HEIGHT, v, &iy);
for (j = 0; j < CS_EW_HEIGHT; j++ ) {
fprintf(fd,"\t");
for (i = 0; i < CS_EW_WIDTH; i++) {
stmp = two16m1*v[CS_EW_WIDTH*j + i];
fprintf(fd," 0x%x,",stmp);
}
fprintf(fd,"\n");
}
fprintf(fd,"\n};\n");
fclose(fd);
}
union
{
double d;
struct
{
int i1;
int i2;
} s;
} ss;
/*========================vrand=========================*/
/* Generates n uniformly distributed random numbers */
/* Uses iy as seed and changes it */
/*========================vrand=========================*/
vrand (n, v, iy)
double v[];
int n;
int *iy;
{
static int ia = 0x3243f6ad;
static int ic = 0x1b0cb175;
static int m2 = 0x40000000;
int i;
ss.s.i1 = 0x3e000000;
ss.s.i2 = 0;
for (i = 0; i < n; i++)
{
*iy = (*iy) * ia + ic;
if (*iy < 0)
*iy = (*iy + m2) + m2;
v[i] = ss.d * (*iy);
}
}