1 /*
2   This file is Copyright © 1994-1995 Olivier Montanuy,
3                Copyright © 1999-2005 André Majorel,
4                Copyright © 2006-2019 contributors to the DeuTex project.
5 
6   DeuTex incorporates code derived from DEU 5.21 that was put in the
7   public domain in 1994 by Raphaël Quinet and Brendon Wyber.
8 
9   SPDX-License-Identifier: GPL-2.0-or-later
10 */
11 #ifndef DEUTEX_H
12 #define DEUTEX_H
13 
14 #include "config.h"
15 
16 #include <stdbool.h>
17 #include <stdint.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 
22 /* fopen() modes */
23 #define FOPEN_RB        "rb"
24 #define FOPEN_RBP       "rb+"
25 #define FOPEN_WB        "wb"
26 #define FOPEN_RT        "r"
27 #define FOPEN_WT        "w"
28 #define FOPEN_AT        "a"
29 #define FOPEN_AB        "a"
30 
31 /* Number of bytes to read from or write to a file */
32 typedef unsigned long iolen_t;
33 
34 #define MEMORYCACHE  (0x8000L)
35 /* steps to increase size of WAD directory*/
36 #define MAXPWADDIR      (128)
37 /*Add 64000 bytes of pure junk, because of a bug in DEU5.21 */
38 #define MAXJUNK64       (1000)
39 /*special value, means int is not valid*/
40 #define INVALIDINT      (-6666)
41 /*indicate an extern WAD entry*/
42 #define EXTERNAL  (0x80000000L)
43 
44 /* Wad magic numbers */
45 #define IWADMAGIC       0x5749  /* little-endian 16-bit int for "IW" */
46 #define PWADMAGIC       0x5750  /* little-endian 16-bit int for "PW" */
47 #define WADMAGIC        0x4441  /* little-endian 16-bit int for "AD" */
48 
49 /*type of WAD files. correspond to 1st half of name*/
50 typedef int16_t WADTYPE;
51 #define IWAD (IWADMAGIC)
52 #define PWAD (PWADMAGIC)
53 
54 /* Number of entries in the game palette */
55 #define NCOLOURS 256
56 
57 /* Entry selection Bits*/
58 typedef int16_t NTRYB;
59 #define BLEVEL          (0x0001)
60 #define BLUMP           (0x0002)
61 #define BSOUND          (0x0004)
62 #define BTEXTUR         (0x0008)
63 #define BGRAPHIC        (0x0010)
64 #define BSPRITE         (0x0020)
65 #define BPATCH          (0x0040)
66 #define BFLAT           (0x0080)
67 #define BMUSIC          (0x0100)
68 #define BSNEAP          (0x0200)
69 #define BSNEAT          (0x0400)
70 #define BSCRIPT         (0x0800)
71 #define BSNEA           (BSNEAP|BSNEAT)
72 #define BALL            (0x7FFF)
73 
74 typedef int16_t SNDTYPE;
75 #define SNDNONE         (0)
76 #define SNDWAV          (2)
77 typedef int16_t IMGTYPE;
78 #define PICNONE         (0)
79 #define PICBMP          (1)
80 #define PICGIF          (2)
81 #define PICPPM          (3)
82 #define PICWAD          (5)
83 #define PICPNG          (6)
84 #define PICJPEG         (7)
85 
86 /*wad directory*/
87 struct WADDIR {                 /*same as in doom */
88     int32_t start;              /*start of entry */
89     int32_t size;               /*size of entry */
90     char name[8];               /*name of entry */
91 };
92 
93 struct WADINFO {
94     int32_t ntry;               /*entries in dir */
95     int32_t dirpos;             /*position of dir */
96     struct WADDIR *dir;         /*directory */
97     int32_t maxdir;             /*max nb of entry in dir */
98     int32_t wposit;             /*position for write */
99     int32_t maxpos;             /*farther referenced byte in WAD */
100     FILE *fd;                   /* File pointer */
101     char *filename;             /* Pointer on block malloc'd by WADRopen*() and
102                                    free'd by WADRclose() and containing the name
103                                    of the file. */
104     char ok;                    /*security ok&1=read ok&2=write */
105 };
106 
107 typedef int16_t PICTYPE;
108 #define PGRAPH  0x02
109 #define PWEAPN  0x04
110 #define PSPRIT  0x06
111 #define PPATCH  0x08
112 #define PFLAT   0x0a
113 #define PLUMP   0x0c
114 #define PSNEAP  0x0d
115 #define PSNEAT  0x0e
116 
117 typedef int16_t ENTRY;
118 #define EMASK           0xFF00
119 #define EVOID           0x0000
120 #define ELEVEL          0x0100
121 #define EMAP            0x0200  /*Levels (doom1) and Maps(Doom2) */
122 #define ELUMP           0x0300
123 #define ETEXTUR         0x0400
124 #define EPNAME          0x0500  /*textures */
125 #define ESOUND          0x0600
126 #define   ESNDPC        0x0601
127 #define   ESNDWAV       0x0602
128 #define EGRAPHIC        0x0700
129 #define ESPRITE         0x0800
130 #define EPATCH          0x0900
131 #define   EPATCH1       0x0901
132 #define   EPATCH2       0x0902
133 #define   EPATCH3       0x0903
134 #define EFLAT           0x0A00
135 #define   EFLAT1        0x0A01
136 #define   EFLAT2        0x0A02
137 #define   EFLAT3        0x0A03
138 #define EMUSIC          0x0B00
139 #define   EMUS          0x0B01
140 #define   EMIDI         0x0B02
141 #define ETXSTART        0x0C00
142 #define EDATA           0x1000
143 #define ESNEA           0x2000
144 #define   ESNEAP        0x2001  /* Snea using PLAYPAL */
145 #define   ESNEAT        0x2002  /* Snea using TITLEPAL */
146 #define ESSCRIPT        0x3000  /* Strife script (SCRIPTnn) */
147 #define EZZZZ           0x7F00  /*unidentified entries */
148 
149 void CMPOmakePWAD(const char *doomwad, WADTYPE type, const char *PWADname,
150                   const char *DataDir, const char *texin, NTRYB select,
151                   char trnR, char trnG, char trnB, bool George);
152 void EXE2list(FILE * out, char *doomexe, int32_t start, int16_t thres);
153 void EXEsubstit(const char *texin, const char *doomexe, int32_t start,
154                 int16_t thres);
155 
156 void XTRlistDir(const char *doomwad, const char *wadin, NTRYB select);
157 
158 void XTRvoidSpacesInWAD(const char *wadin);
159 
160 void XTRcompakWAD(const char *DataDir, const char *wadin, const char
161                   *texout, bool ShowIdx);
162 void XTRstructureTest(const char *doomwad, const char *wadin);
163 void XTRtextureUsed(const char *wadin);
164 
165 /*
166  *      Types defined elsewhere
167  */
168 struct cusage_s;
169 typedef struct cusage_s cusage_t;
170 
171 /*
172  *      Misc globals, set by command line arguments
173  */
174 typedef enum { PF_NORMAL, PF_ALPHA, PF_PR } picture_format_t;
175 typedef enum { TF_NORMAL, TF_NAMELESS, TF_NONE,
176                TF_STRIFE11
177 } texture_format_t;
178 typedef enum { TL_NORMAL, TL_TEXTURES, TL_NONE } texture_lump_t;
179 typedef enum { RP_REJECT, RP_FORCE, RP_WARN, RP_ACCEPT } rate_policy_t;
180 typedef enum { CLOBBER_YES, CLOBBER_NO, CLOBBER_ASK } clobber_t;
181 extern picture_format_t picture_format;
182 extern texture_format_t input_texture_format;
183 extern texture_format_t output_texture_format;
184 extern texture_lump_t texture_lump;
185 extern rate_policy_t rate_policy;
186 extern clobber_t clobber;
187 extern bool use_png_offsets;
188 extern const char *debug_ident;
189 extern const char *palette_lump;
190 
191 #endif //DEUTEX_H
192