]> 4ch.mooo.com Git - 16.git/blob - 16/scrasm/GENMAP.C
more
[16.git] / 16 / scrasm / GENMAP.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   255\r
7 \r
8 #define MAPNAME "Diagonal"\r
9 #define FILENAME "%s.MAP"\r
10 char    fn[100] = FILENAME;\r
11 typedef unsigned char BYTE;\r
12 typedef unsigned short int WORD;\r
13 typedef BYTE    ROW[WIDTH];\r
14 \r
15 ROW     r;\r
16 \r
17 #define MAGIC_NUM       100\r
18 #define SQUARE_WIDTH    16\r
19 #define SQUARE_HEIGHT   16\r
20 #define SCREEN_WIDTH    320\r
21 #define SCREEN_HEIGHT   200\r
22 #define VIRTUAL_WIDTH   352\r
23 #define VIRTUAL_HEIGHT  240\r
24 typedef struct MAPHEADER {\r
25         BYTE    name[12];       /* 12    Includes [n]=0 and [n+1]=26 */\r
26         WORD    width;          /*  2                                */\r
27         WORD    height;         /*  2                                */\r
28         WORD    extent;         /*  2                                */\r
29         WORD    off_x1;         /*  2                                */\r
30         WORD    off_y1;         /*  2                                */\r
31         WORD    off_x2;         /*  2                                */\r
32         WORD    off_y2;         /*  2                                */\r
33         WORD    x_wrap;         /*  2                                */\r
34         WORD    y_wrap;         /*  2                                */\r
35         WORD    magic;          /*  2                                */\r
36         } MAPHEADER, far *LPMAPHEADER;\r
37 MAPHEADER mh;\r
38 \r
39 void main(int argc, char *argv[])\r
40         {\r
41         FILE    *fp;\r
42         int     i,j;\r
43         BYTE    b;\r
44         int     width = WIDTH;\r
45         int     height = WIDTH;\r
46 \r
47         if (argc > 1) {\r
48                 width = atoi(argv[1]);\r
49                 if (width > WIDTH)\r
50                         width = WIDTH;\r
51                 printf("Width = %d\n",width);\r
52                 height=width;\r
53                 if (argc > 2) {\r
54                         height = atoi(argv[2]);\r
55                         if (height > WIDTH)\r
56                                 height = WIDTH;\r
57                         printf("Height = %d\n",height);\r
58                         }\r
59                 }\r
60 \r
61         sprintf(fn,FILENAME,MAPNAME);\r
62         fp = fopen(fn,"wb");\r
63         if (!fp) {\r
64                 printf("Couldn't open %s for write.\n",fn);\r
65                 exit(1);\r
66                 }\r
67 \r
68         memset(&mh, 0xFF, sizeof(MAPHEADER));   /* Will reveal missing initializing */\r
69         strcpy((char *)mh.name,MAPNAME);\r
70         mh.name[8]=0;\r
71         mh.name[9]=26;  /* Ctrl-Z */\r
72         mh.width = (WORD)width;\r
73         mh.height = (WORD)height;\r
74         mh.extent = (WORD)((WORD)width * (WORD)height);\r
75         mh.off_x1 = (WORD)0;\r
76         mh.off_y1 = (WORD)0;\r
77         mh.off_x2 = (WORD)(((VIRTUAL_WIDTH / SQUARE_WIDTH) - 1) % width);\r
78         mh.off_y2 = (WORD)((((VIRTUAL_HEIGHT / SQUARE_HEIGHT) - 1) % height) * width);\r
79         mh.x_wrap = (WORD)width;\r
80         mh.y_wrap = (WORD)height;\r
81         mh.magic = MAGIC_NUM;\r
82         fwrite(&mh, 1, sizeof(MAPHEADER), fp);\r
83 \r
84         for (i = 0; i<width; i++) {\r
85                 b = (BYTE)(i%width);\r
86                 for (j = 0; j<width; j++) {\r
87                         r[j] = b;\r
88                         b = (BYTE)(((int)b+1) % width);\r
89                         }\r
90                 r[0]=1;\r
91                 if (i == 0) r[0]=0;\r
92                 fwrite(r, width,1, fp);\r
93                 printf("Map row %d\r",i);\r
94                 }\r
95         fclose(fp);\r
96         printf("All done!    \n");\r
97         exit(0);\r
98         }\r
99 \1a