]> 4ch.mooo.com Git - 16.git/blob - 16/scrasm/GENSQ.C
i hate being tired wwww i will work on the project some more sometime wwww
[16.git] / 16 / scrasm / GENSQ.C
1 #include <stdio.h>\r
2 #include <string.h>\r
3 #include <memory.h>\r
4 #include <stdlib.h>\r
5 \r
6 #define WIDTH   256\r
7 \r
8 #define FILENAME "DIAGONAL.TIL"\r
9 char    fn[100] = FILENAME;\r
10 typedef unsigned char BYTE;\r
11 typedef BYTE    ROW[16];\r
12 typedef ROW     BITMAP[16];\r
13 \r
14 BITMAP  b;\r
15 BITMAP  c;\r
16 \r
17 BITMAP  pattern={{1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},\r
18                  {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0},\r
19                  {1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0},\r
20                  {1,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0},\r
21                  {1,0,0,1,0,0,0,0,0,0,0,2,0,0,0,0},\r
22                  {0,0,1,0,0,1,1,0,1,1,0,0,2,0,0,0},\r
23                  {0,0,1,0,0,1,2,0,1,2,0,0,2,0,0,0},\r
24                  {0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0},\r
25                  {0,1,0,0,0,0,0,0,0,0,0,0,0,2,0,0},\r
26                  {0,1,0,0,1,2,0,0,0,1,2,0,0,2,0,0},\r
27                  {0,0,1,0,1,2,1,1,1,1,2,0,2,0,0,0},\r
28                  {0,0,1,0,0,2,2,2,2,2,0,0,2,0,0,2},\r
29                  {0,0,0,1,0,0,0,0,0,0,0,2,0,0,0,2},\r
30                  {0,0,0,0,2,2,0,0,0,2,2,0,0,0,0,2},\r
31                  {0,0,0,0,0,0,2,2,2,0,0,0,0,0,2,2},\r
32                  {0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2}};\r
33 \r
34 void copy_pattern(BITMAP b,BITMAP patt, BYTE l, BYTE m, BYTE h)\r
35         {\r
36         int     x,y;\r
37 \r
38         for (y=0; y<16; y++) {\r
39                 for (x=0; x<16; x++) {\r
40                         switch (patt[y][x]) {\r
41                                 case 0:\r
42                                         b[y][x] = m;\r
43                                         break;\r
44                                 case 1:\r
45                                         b[y][x] = l;\r
46                                         break;\r
47                                 case 2:\r
48                                         b[y][x] = h;\r
49                                         break;\r
50                                 }\r
51                         }\r
52                 }\r
53         }\r
54 \r
55 /* Transforms linear to planar */\r
56 void transform(BITMAP b,BITMAP c)\r
57         {\r
58         int     x,y,p;\r
59         BYTE    *pb = (BYTE *)c;\r
60 \r
61         for (p=0; p<4; p++) {\r
62                 for (y=0; y<16; y++) {\r
63                         for (x=0; x<16; x+=4) {\r
64                                 *(pb++) = b[y][x+p];\r
65                                 }\r
66                         }\r
67                 }\r
68         }\r
69 \r
70 void main(int argc,char *argv[])\r
71         {\r
72         FILE    *fp;\r
73         int     i;\r
74         int     width = WIDTH;\r
75 \r
76         fp = fopen(fn,"wb");\r
77         if (!fp) {\r
78                 printf("Couldn't open %s for write.\n",fn);\r
79                 exit(1);\r
80                 }\r
81         if (argc > 1) {\r
82                 width = atoi(argv[1]);\r
83                 if (width > WIDTH)\r
84                         width = WIDTH;\r
85                 printf("Width = %d\n",width);\r
86                 }\r
87 \r
88         for (i = 0; i< width; i++) {\r
89                 BYTE    less,more;\r
90 \r
91                 less = (BYTE)((i + width - 1) % width);\r
92                 more = (BYTE)((i + 1) % width);\r
93                 copy_pattern(b, pattern, less, (BYTE)i, more);\r
94                 transform(b,c);\r
95                 fwrite(c, 16,16, fp);\r
96                 printf("Square %d\r",i);\r
97                 }\r
98         fclose(fp);\r
99         printf("All done!     \n");\r
100         exit(0);\r
101         }\r
102 \1a