1 /* SCCS Id: @(#)tile2bin.c 3.4 1995/01/26 */
2 /* Copyright (c) NetHack PC Development Team 1993, 1994, 1995 */
3 /* NetHack may be freely redistributed. See license for details. */
8 * Initial Creation M.Allison 93/10/21
9 * ifndef MONITOR_HEAP for heaputil.c P.Winner 94/03/12
10 * added Borland C _stklen variable Y.Sapir 94/05/01
11 * fixed to use text tiles from win/share M.Allison 95/01/31
31 #if defined(_MSC_VER) && _MSC_VER >= 700
32 #pragma warning(disable:4309) /* initializing */
33 #pragma warning(disable:4018) /* signed/unsigned mismatch */
34 #pragma warning(disable:4131) /* old style declarator */
35 #pragma warning(disable:4127) /* conditional express. is constant */
39 extern unsigned _stklen = STKSIZ;
42 extern char *FDECL(tilename, (int, int));
45 char masktable[8]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
46 char charcolors[MAXCOLORMAPSIZE];
48 struct overview_planar_cell_struct planetile;
50 struct planar_cell_struct planetile;
56 char packtile[TILE_Y][TILE_X];
61 pixel pixels[TILE_Y][TILE_X];
62 struct tibhdr_struct tibheader;
64 static void FDECL(write_tibtile, (int));
65 static void FDECL(write_tibheader, (FILE *, struct tibhdr_struct *));
66 static void FDECL(build_tibtile, (pixel (*)[TILE_X]));
69 char *tilefiles[] = { "../win/share/monsters.txt",
70 "../win/share/objects.txt",
71 "../win/share/other.txt"};
73 char *tilefiles[] = { "../win/share/monthin.txt",
74 "../win/share/objthin.txt",
75 "../win/share/oththin.txt"};
93 Fprintf(stderr, "usage: tile2bin (from the util directory)\n");
98 # ifndef OVERVIEW_FILE
99 tibfile1 = fopen(NETHACK_PLANAR_TILEFILE, WRBMODE);
101 tibfile1 = fopen(NETHACK_OVERVIEW_TILEFILE, WRBMODE);
103 if (tibfile1 == (FILE *)0) {
104 Fprintf(stderr, "Unable to open output file %s\n",
105 # ifndef OVERVIEW_FILE
106 NETHACK_PLANAR_TILEFILE);
108 NETHACK_OVERVIEW_TILEFILE);
115 tibfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
116 if (tibfile2 == (FILE *)0) {
117 Fprintf(stderr, "Unable to open output file %s\n",
118 NETHACK_PACKED_TILEFILE);
123 newtime = localtime(&aclock);
128 while (filenum < 3) {
129 if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
131 "usage: tile2bin (from the util or src directory)\n");
134 num_colors = colorsinmap;
135 if (num_colors > 62) {
136 Fprintf(stderr, "too many colors (%d)\n", num_colors);
141 paletteptr = tibheader.palette;
142 for (i = 0; i < num_colors; i++) {
143 *paletteptr++ = ColorMap[CM_RED][i],
144 *paletteptr++ = ColorMap[CM_GREEN][i],
145 *paletteptr++ = ColorMap[CM_BLUE][i];
151 while (read_text_tile(pixels)) {
152 build_tibtile(pixels);
153 write_tibtile(tilecount);
157 (void) fclose_text_file();
161 # if defined(_MSC_VER)
162 tibheader.compiler = MSC_COMP;
163 # elif defined(__BORLANDC__)
164 tibheader.compiler = BC_COMP;
165 # elif defined(__GO32__)
166 tibheader.compiler = DJGPP_COMP;
168 tibheader.compiler = OTHER_COMP;
171 strncpy(tibheader.ident,
172 "NetHack 3.4 MSDOS Port binary tile file", 80);
173 strncpy(tibheader.timestamp, asctime(newtime), 24);
174 tibheader.timestamp[25] = '\0';
175 tibheader.tilecount = tilecount;
176 tibheader.numcolors = num_colors;
178 tibheader.tilestyle = PLANAR_STYLE;
179 write_tibheader(tibfile1, &tibheader);
180 (void) fclose(tibfile1);
181 # ifndef OVERVIEW_FILE
182 Fprintf(stderr, "Total of %d planar tiles written to %s.\n",
183 tilecount, NETHACK_PLANAR_TILEFILE);
185 Fprintf(stderr, "Total of %d planar tiles written to %s.\n",
186 tilecount, NETHACK_OVERVIEW_TILEFILE);
191 tibheader.tilestyle = PACKED_STYLE;
192 write_tibheader(tibfile2, &tibheader);
193 Fprintf(stderr, "Total of %d packed tiles written to %s.\n",
194 tilecount, NETHACK_PACKED_TILEFILE);
195 (void) fclose(tibfile2);
205 write_tibheader(fileptr,tibhdr)
207 struct tibhdr_struct *tibhdr;
210 if (fseek(fileptr,0L,SEEK_SET)) {
211 Fprintf(stderr, "Error writing header to tile file\n");
213 fwrite(tibhdr, sizeof(struct tibhdr_struct), 1, fileptr);
217 build_tibtile(pixels)
218 pixel (*pixels)[TILE_X];
221 unsigned char co_mask,tmp;
223 #ifndef OVERVIEW_FILE
224 memset((void *)&planetile,0,sizeof(struct planar_cell_struct));
226 memset((void *)&planetile,0,
227 sizeof(struct overview_planar_cell_struct));
229 for (j = 0; j < TILE_Y; j++) {
230 for (i = 0; i < TILE_X; i++) {
231 for (k = 0; k < num_colors; k++) {
232 if (ColorMap[CM_RED][k] == pixels[j][i].r &&
233 ColorMap[CM_GREEN][k] == pixels[j][i].g &&
234 ColorMap[CM_BLUE][k] == pixels[j][i].b)
238 Fprintf(stderr, "color not in colormap!\n");
246 co_mask = masktable[i - 8];
249 co_mask = masktable[i];
252 tmp = planetile.plane[0].image[j][co_off];
253 planetile.plane[0].image[j][co_off] = (k & 0x0008) ?
257 tmp = planetile.plane[1].image[j][co_off];
258 planetile.plane[1].image[j][co_off] = (k & 0x0004) ?
262 tmp = planetile.plane[2].image[j][co_off];
263 planetile.plane[2].image[j][co_off] = (k & 0x0002) ?
267 tmp = planetile.plane[3].image[j][co_off];
268 planetile.plane[3].image[j][co_off] = (k & 0x0001) ?
271 #endif /* PLANAR_FILE */
277 write_tibtile(recnum)
283 # ifndef OVERVIEW_FILE
284 fpos = ((long)(recnum) * (long)sizeof(struct planar_cell_struct)) +
285 (long)TIBHEADER_SIZE;
287 fpos = ((long)(recnum) *
288 (long)sizeof(struct overview_planar_cell_struct)) +
289 (long)TIBHEADER_SIZE;
291 if (fseek(tibfile1,fpos,SEEK_SET)) {
292 Fprintf(stderr, "Error seeking before planar tile write %d\n",
295 # ifndef OVERVIEW_FILE
296 fwrite(&planetile, sizeof(struct planar_cell_struct), 1, tibfile1);
299 sizeof(struct overview_planar_cell_struct), 1, tibfile1);
304 fpos = ((long)(recnum) * (long)sizeof(packtile)) +
305 (long)TIBHEADER_SIZE;
306 if (fseek(tibfile2,fpos,SEEK_SET)) {
307 Fprintf(stderr, "Error seeking before packed tile write %d\n",
310 fwrite(&packtile, sizeof(packtile), 1, tibfile2);