1 /* SCCS Id: @(#)pctiles.c 3.4 1995/07/31 */
2 /* Copyright (c) NetHack PC Development Team 1993, 1994 */
3 /* NetHack may be freely redistributed. See license for details. */
6 * pctiles.c - PC Graphical Tile Support Routines
9 * Initial Creation M. Allison 93/10/30
17 #if defined(__GO32__) || defined(__DJGPP__)
19 #define TILES_IN_RAM /* allow tiles to be read into ram */
22 # if defined(_MSC_VER)
24 #pragma warning(disable:4018) /* signed/unsigned mismatch */
25 #pragma warning(disable:4127) /* conditional expression is constant */
26 #pragma warning(disable:4131) /* old style declarator */
27 #pragma warning(disable:4309) /* initializing */
36 STATIC_VAR FILE *tilefile;
37 STATIC_VAR FILE *tilefile_O;
38 extern short glyph2tile[]; /* in tile.c (made from tilemap.c) */
41 struct planar_cell_struct *ramtiles;
42 struct overview_planar_cell_struct *oramtiles;
43 boolean tiles_in_ram = FALSE;
44 boolean otiles_in_ram = FALSE;
45 extern int total_tiles_used; /* tile.c */
51 * Read the header/palette information at the start of the
54 * There is 1024 bytes (1K) of header information
55 * at the start of the file, including a palette.
58 int ReadTileFileHeader(tibhdr, filestyle)
59 struct tibhdr_struct *tibhdr;
63 x = filestyle ? tilefile_O : tilefile;
64 if (fseek(x,0L,SEEK_SET)) {
67 fread(tibhdr, sizeof(struct tibhdr_struct), 1, x);
73 * Open the requested tile file.
75 * NetHack1.tib file is a series of
76 * 'struct planar_tile_struct' structures, one for each
79 * NetHack2.tib file is a series of
80 * char arrays [TILE_Y][TILE_X] in dimensions, one for each
83 * There is 1024 bytes (1K) of header information
84 * at the start of each .tib file. The first glyph tile starts at
89 OpenTileFile(tilefilename, filestyle)
97 tilefile_O = fopen(tilefilename,"rb");
98 if (tilefile_O == (FILE *)0) return 1;
100 tilefile = fopen(tilefilename,"rb");
101 if (tilefile == (FILE *)0) return 1;
104 if (iflags.preload_tiles) {
106 struct overview_planar_cell_struct *gp;
107 long ram_needed = sizeof(struct overview_planar_cell_struct) *
109 if (fseek(tilefile_O,(long)TIBHEADER_SIZE, SEEK_SET)) { /*failure*/
111 oramtiles = (struct overview_planar_cell_struct *)alloc(ram_needed);
112 /* Todo: fall back to file method here if alloc failed */
114 for(k=0; k < total_tiles_used; ++k) {
115 fread(gp, sizeof(struct overview_planar_cell_struct),
119 #ifdef DEBUG_RAMTILES
120 pline("%d overview tiles read into ram.", k);
123 otiles_in_ram = TRUE;
125 struct planar_cell_struct *gp;
126 long ram_needed = sizeof(struct planar_cell_struct) *
128 if (fseek(tilefile,(long)TIBHEADER_SIZE, SEEK_SET)) { /*failure*/
130 ramtiles = (struct planar_cell_struct *)alloc(ram_needed);
131 /* Todo: fall back to file method here if alloc failed */
133 for(k=0; k < total_tiles_used; ++k) {
134 fread(gp, sizeof(struct planar_cell_struct),
138 #ifdef DEBUG_RAMTILES
139 pline("%d tiles read into ram.", k);
150 CloseTileFile(filestyle)
153 fclose(filestyle ? tilefile_O : tilefile);
155 if (!filestyle && tiles_in_ram) {
156 if (ramtiles) free((genericptr_t) ramtiles);
157 tiles_in_ram = FALSE;
158 } else if (filestyle && otiles_in_ram) {
159 if (oramtiles) free((genericptr_t) oramtiles);
160 otiles_in_ram = FALSE;
168 struct planar_cell_struct plancell;
169 struct overview_planar_cell_struct oplancell;
171 /* This routine retrieves the requested NetHack glyph tile
172 * from the planar style binary .tib file.
173 * This is currently done 'on demand', so if the player
174 * is running without a disk cache (ie. smartdrv) operating,
175 * things can really be slowed down. We don't have any
176 * base memory under MSDOS, in which to store the pictures.
178 * Todo: Investigate the possibility of loading the glyph
179 * tiles into extended or expanded memory using
180 * the MSC virtual memory routines.
182 * Under an environment like djgpp, it should be possible to
183 * read the entire set of glyph tiles into a large
184 * array of 'struct planar_cell_struct' structures at
185 * game initialization time, and recall them from the array
186 * as needed. That should speed things up (at the cost of
187 * increasing the memory requirement - can't have everything).
191 int ReadPlanarTileFile(tilenum,gp)
193 struct planar_cell_struct **gp;
199 *gp = ramtiles + tilenum;
203 fpos = ((long)(tilenum) * (long)sizeof(struct planar_cell_struct)) +
204 (long)TIBHEADER_SIZE;
205 if (fseek(tilefile,fpos,SEEK_SET)) {
208 fread(&plancell, sizeof(struct planar_cell_struct), 1, tilefile);
213 int ReadPlanarTileFile_O(tilenum,gp)
215 struct overview_planar_cell_struct **gp;
221 *gp = oramtiles + tilenum;
225 fpos = ((long)(tilenum) *
226 (long)sizeof(struct overview_planar_cell_struct)) +
227 (long)TIBHEADER_SIZE;
228 if (fseek(tilefile_O,fpos,SEEK_SET)) {
231 fread(&oplancell, sizeof(struct overview_planar_cell_struct),
240 int ReadPackedTileFile(tilenum,pta)
246 fpos = ((long)(tilenum) * (long)(TILE_Y * TILE_X) +
247 (long)TIBHEADER_SIZE;
248 if (fseek(tilefile,fpos,SEEK_SET)) {
251 fread(pta, (TILE_Y * TILE_X), 1, tilefile);
257 #endif /* USE_TILES */