1 /* aNetHack 0.0.1 pctiles.c $ANH-Date: 1432512791 2015/05/25 00:13:11 $ $ANH-Branch: master $:$ANH-Revision: 1.11 $ */
2 /* Copyright (c) aNetHack PC Development Team 1993, 1994 */
3 /* aNetHack 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 */
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 */
49 * Read the header/palette information at the start of the
52 * There is 1024 bytes (1K) of header information
53 * at the start of the file, including a palette.
57 ReadTileFileHeader(tibhdr
, filestyle
)
58 struct tibhdr_struct
*tibhdr
;
62 x
= filestyle
? tilefile_O
: tilefile
;
63 if (fseek(x
, 0L, SEEK_SET
)) {
66 fread(tibhdr
, sizeof(struct tibhdr_struct
), 1, x
);
72 * Open the requested tile file.
74 * aNetHack1.tib file is a series of
75 * 'struct planar_tile_struct' structures, one for each
78 * aNetHack2.tib file is a series of
79 * char arrays [TILE_Y][TILE_X] in dimensions, one for each
82 * There is 1024 bytes (1K) of header information
83 * at the start of each .tib file. The first glyph tile starts at
88 OpenTileFile(tilefilename
, filestyle
)
96 tilefile_O
= fopen(tilefilename
, "rb");
97 if (tilefile_O
== (FILE *) 0)
100 tilefile
= fopen(tilefilename
, "rb");
101 if (tilefile
== (FILE *) 0)
105 if (iflags
.preload_tiles
) {
107 struct overview_planar_cell_struct
*gp
;
109 sizeof(struct overview_planar_cell_struct
) * total_tiles_used
;
110 if (fseek(tilefile_O
, (long) TIBHEADER_SIZE
,
111 SEEK_SET
)) { /*failure*/
114 (struct overview_planar_cell_struct
*) alloc(ram_needed
);
115 /* Todo: fall back to file method here if alloc failed */
117 for (k
= 0; k
< total_tiles_used
; ++k
) {
118 fread(gp
, sizeof(struct overview_planar_cell_struct
), 1,
122 #ifdef DEBUG_RAMTILES
123 pline("%d overview tiles read into ram.", k
);
126 otiles_in_ram
= TRUE
;
128 struct planar_cell_struct
*gp
;
130 sizeof(struct planar_cell_struct
) * total_tiles_used
;
131 if (fseek(tilefile
, (long) TIBHEADER_SIZE
,
132 SEEK_SET
)) { /*failure*/
134 ramtiles
= (struct planar_cell_struct
*) alloc(ram_needed
);
135 /* Todo: fall back to file method here if alloc failed */
137 for (k
= 0; k
< total_tiles_used
; ++k
) {
138 fread(gp
, sizeof(struct planar_cell_struct
), 1, tilefile
);
141 #ifdef DEBUG_RAMTILES
142 pline("%d tiles read into ram.", k
);
153 CloseTileFile(filestyle
)
156 fclose(filestyle
? tilefile_O
: tilefile
);
158 if (!filestyle
&& tiles_in_ram
) {
160 free((genericptr_t
) ramtiles
);
161 tiles_in_ram
= FALSE
;
162 } else if (filestyle
&& otiles_in_ram
) {
164 free((genericptr_t
) oramtiles
);
165 otiles_in_ram
= FALSE
;
170 struct planar_cell_struct plancell
;
171 struct overview_planar_cell_struct oplancell
;
173 /* This routine retrieves the requested aNetHack glyph tile
174 * from the planar style binary .tib file.
175 * This is currently done 'on demand', so if the player
176 * is running without a disk cache (ie. smartdrv) operating,
177 * things can really be slowed down. We don't have any
178 * base memory under MSDOS, in which to store the pictures.
180 * Todo: Investigate the possibility of loading the glyph
181 * tiles into extended or expanded memory using
182 * the MSC virtual memory routines.
184 * Under an environment like djgpp, it should be possible to
185 * read the entire set of glyph tiles into a large
186 * array of 'struct planar_cell_struct' structures at
187 * game initialization time, and recall them from the array
188 * as needed. That should speed things up (at the cost of
189 * increasing the memory requirement - can't have everything).
194 ReadPlanarTileFile(tilenum
, gp
)
196 struct planar_cell_struct
**gp
;
202 *gp
= ramtiles
+ tilenum
;
206 fpos
= ((long) (tilenum
) * (long) sizeof(struct planar_cell_struct
))
207 + (long) TIBHEADER_SIZE
;
208 if (fseek(tilefile
, fpos
, SEEK_SET
)) {
211 fread(&plancell
, sizeof(struct planar_cell_struct
), 1, tilefile
);
217 ReadPlanarTileFile_O(tilenum
, gp
)
219 struct overview_planar_cell_struct
**gp
;
225 *gp
= oramtiles
+ tilenum
;
230 ((long) (tilenum
) * (long) sizeof(struct overview_planar_cell_struct
))
231 + (long) TIBHEADER_SIZE
;
232 if (fseek(tilefile_O
, fpos
, SEEK_SET
)) {
235 fread(&oplancell
, sizeof(struct overview_planar_cell_struct
), 1,
245 ReadPackedTileFile(tilenum
, pta
)
252 ((long) (tilenum
) * (long) (TILE_Y
* TILE_X
) + (long) TIBHEADER_SIZE
);
253 if (fseek(tilefile
, fpos
, SEEK_SET
)) {
256 fread(pta
, (TILE_Y
* TILE_X
), 1, tilefile
);
261 #endif /* USE_TILES */