1 /*
2  * sf_frotz.h
3  *
4  * Declarations and definitions for the SDL interface
5  *
6  */
7 
8 #ifndef _SF_FROTZ_H
9 #define _SF_FROTZ_H
10 
11 #include "../common/frotz.h"
12 #include "../blorb/blorb.h"
13 
14 #include <stdint.h>
15 typedef uint8_t byte;
16 typedef uint16_t word;
17 #define ulong uint32_t
18 
19 typedef struct {
20 	bb_result_t bbres;
21 	ulong type;
22 	FILE *file;
23 } myresource;
24 
25 int sf_getresource(int num, int ispic, int method, myresource * res);
26 void sf_freeresource(myresource * res);
27 bool sf_IsAdaptive(int picture);
28 
29 #ifndef true
30 #define true 1
31 #endif
32 #ifndef false
33 #define false 0
34 #endif
35 
36 #define NON_STD_COLS 238
37 
38 /* Paths where z-files may be found */
39 #define PATH1		"ZCODE_PATH"
40 #define PATH2		"INFOCOM_PATH"
41 
42 #define MAX(x,y) ((x)>(y)) ? (x) : (y)
43 #define MIN(x,y) ((x)<(y)) ? (x) : (y
44 
45 #ifdef WIN32
46 #define HOMEDIR "USERPROFILE"
47 #else
48 #define HOMEDIR "HOME"
49 #endif
50 
51 /* this assumes RGBA with lsb = R */
RGB5ToTrue(word w)52 static inline ulong RGB5ToTrue(word w)
53 {
54 	int _r = w & 0x001F;
55 	int _g = (w & 0x03E0) >> 5;
56 	int _b = (w & 0x7C00) >> 10;
57 	_r = (_r << 3) | (_r >> 2);
58 	_g = (_g << 3) | (_g >> 2);
59 	_b = (_b << 3) | (_b >> 2);
60 	return (ulong) (_r | (_g << 8) | (_b << 16));
61 }
62 
TrueToRGB5(ulong u)63 static inline word TrueToRGB5(ulong u)
64 {
65 	return (word) (((u >> 3) & 0x001f) | ((u >> 6) & 0x03e0) |
66 		       ((u >> 9) & 0x7c00));
67 }
68 
69 void reset_memory(void);
70 void replay_close(void);
71 void set_header_extension(int entry, zword val);
72 int colour_in_use(zword colour);
73 
74 /*  various data */
75 extern bool m_tandy;
76 extern int m_v6scale;
77 extern double m_gfxScale_w;
78 extern double m_gfxScale_h;
79 extern ulong m_defaultFore;
80 extern ulong m_defaultBack;
81 extern ulong m_colours[11];
82 extern ulong m_nonStdColours[NON_STD_COLS];
83 extern int m_nonStdIndex;
84 extern bool m_exitPause;
85 extern bool m_lineInput;
86 extern bool m_morePrompts;
87 extern int AcWidth;
88 extern int AcHeight;
89 extern int m_random_seed;
90 extern int m_fullscreen;
91 extern char *m_fontfiles[9];
92 extern bool m_localfiles;
93 extern int m_no_sound;
94 extern int m_vga_fonts;
95 extern int SFdticks;
96 extern volatile bool SFticked;
97 extern char *m_fontdir;
98 extern bool m_aafonts;
99 extern char *m_setupfile;
100 extern int m_frequency;
101 
102 extern double m_gamma;
103 
104 extern bool sdl_active;
105 
106 /* sf_resource.c */
107 
108 /* must be called as soon as possible (i.e. by os_process_arguments()) */
109 int sf_load_resources(void);
110 
111 typedef struct {
112 	int number;	/* 0 means unallocated */
113 	int width, height;
114 	byte *pixels;
115 	ulong palette[16];
116 	int palette_entries;
117 	int transparentcolor;
118 	bool adaptive;
119 	bool usespalette;
120 } sf_picture;
121 
122 #define DEFAULT_GAMMA 2.2
123 
124 void sf_setgamma(double gamma);
125 
126 
127 /* get pointer from cache */
128 sf_picture *sf_getpic(int num);
129 
130 void sf_flushtext();
131 
132 /* glyph */
133 typedef struct {
134 	byte dx;
135 	byte w, h;
136 	char xof, yof;
137 	byte bitmap[0];
138 } SF_glyph;
139 
140 typedef struct sfontstruct SFONT;
141 
142 extern SFONT *(*ttfontloader)(char *fspec, SFONT * like, int *err);
143 extern void (*ttfontsdone)();
144 
145 struct sfontstruct {
146 	int refcount;
147 	void (*destroy)(SFONT *);
148 	int (*height)(SFONT *);
149 	int (*ascent)(SFONT *);
150 	int (*descent)(SFONT *);
151 	int (*minchar)(SFONT *);
152 	int (*maxchar)(SFONT *);
153 	int (*hasglyph)(SFONT *, word, int);
154 	SF_glyph *(*getglyph)(SFONT *, word, int);
155 	int antialiased;
156 	void *data;
157 };
158 
159 typedef struct {
160 	SFONT *font;
161 	int proportional;
162 	int style, zfontnum;
163 	int cx, cy;		/* cursor position - 0 based */
164 	int oh;			/* overhang */
165 	unsigned long fore, back;
166 	bool foreDefault, backDefault, backTransparent;
167 } SF_textsetting;
168 
169 SF_textsetting *sf_curtextsetting(void);
170 
171 /**
172  * Return the advance width of character c.
173  * Store glyph width minus advance width to oh ("overhang").
174  */
175 int sf_charwidth(zword c, int *oh);
176 
177 void sf_writeglyph(SF_glyph * g);
178 
179 void sf_fillrect(unsigned long color, int x, int y, int w, int h);
180 
181 int sf_GetProfileInt(const char *sect, const char *id, int def);
182 double sf_GetProfileDouble(const char *sect, const char *id, double def);
183 char *sf_GetProfileString(const char *sect, const char *id, char *def);
184 
185 void sf_readsettings();
186 
187 ulong sf_GetColour(int colour);
188 ulong sf_GetDefaultColour(bool fore);
189 int sf_GetColourIndex(ulong colour);
190 
191 void sf_initvideo(int w, int h, int full);
192 
193 int sf_initsound(void);
194 
195 void sf_initfonts(void);
196 
197 void sf_setdialog(void);
198 void sf_initloader(void);
199 
200 void sf_cleanup_all(void);
201 void sf_regcleanfunc(void *f, const char *nam);
202 #define CLEANREG( f) sf_regcleanfunc( (void *)f, #f)
203 
204 const char *sf_msgstring(int id);
205 
206 /* consts for msg ids */
207 enum { IDS_BLORB_GLULX, IDS_BLORB_NOEXEC, IDS_MORE, IDS_HIT_KEY_EXIT, IDS_TITLE,
208 	IDS_FATAL, IDS_FROTZ, IDS_FAIL_DIRECTSOUND, IDS_FAIL_MODPLUG,
209 	    IDS_ABOUT_INFO,
210 	IDS_SAVE_FILTER, IDS_SAVE_TITLE, IDS_RESTORE_TITLE,
211 	IDS_SCRIPT_FILTER, IDS_SCRIPT_TITLE,
212 	IDS_RECORD_FILTER, IDS_RECORD_TITLE, IDS_PLAYBACK_TITLE,
213 	IDS_AUX_FILTER, IDS_SAVE_AUX_TITLE, IDS_LOAD_AUX_TITLE
214 };
215 
216 bool sf_IsInfocomV6(void);
217 
218 ulong sf_blend(int a, ulong s, ulong d);
219 
220 void sf_sleep(int millisecs);
221 
222 unsigned long sf_ticks(void);
223 
224 void sf_DrawInput(zchar * buffer, int pos, int ptx, int pty, int width,
225 		  bool cursor);
226 
227 int sf_aiffwav(FILE * f, int foffs, void **wav, int *size);
228 
229 int sf_pkread(FILE * f, int foffs, void **out, int *size);
230 
231 ulong *sf_savearea(int x, int y, int w, int h);
232 void sf_restoreareaandfree(ulong * s);
233 #define SF_NOTIMP (-9999)
234 
235 zword sf_read_key(int timeout, bool cursor, bool allowed, bool text);
236 
237 int sf_user_fdialog(bool exist, const char *def, const char *filt,
238 		    const char *title, char **res);
239 extern int (*sf_osdialog)(bool ex, const char *def, const char *filt,
240 			  const char *tit, char **res, ulong * sbuf, int sbp,
241 			  int ew, int eh, int isfull);
242 
243 void sf_checksound(void);
244 
245 void sf_installhandlers(void);
246 
247 void sf_pushtextsettings(void);
248 void sf_poptextsettings(void);
249 
250 char *sf_searchfile(char *, int, char *, char *);
251 
252 void sf_chline(int x, int y, ulong c, int n);
253 void sf_cvline(int x, int y, ulong c, int n);
254 bool sf_flushdisplay(void);
255 void sf_getclip(int *x, int *y, int *w, int *h);
256 void sf_rect(unsigned long color, int x, int y, int w, int h);
257 void sf_setclip(int x, int y, int w, int h);
258 void sf_wpixel(int x, int y, ulong c);
259 
260 void sf_InitProfile(const char *fn);
261 void sf_FinishProfile(void);
262 
263 #ifdef WIN32
264 #define OS_PATHSEP ';'
265 #define OS_DIRSEP '\\'
266 #else
267 #define OS_PATHSEP ':'
268 #define OS_DIRSEP '/'
269 #endif
270 
271 #define DEFSIZE 14
272 
273 /* virtual keys */
274 #define VK_TAB	0x16
275 #define VK_INS	0x17
276 #define VK_PAGE_UP 0x18
277 #define VK_PAGE_DOWN 0x19
278 #define VK_DEL 0x100
279 
280 /* for AIFF resampling */
281 typedef struct CONVstruct CONV;
282 struct CONVstruct {
283 	double ratio;
284 	// input
285 	int channels;
286 	int bytespersam;
287 	// returns num of output samples
288 	int (*doCONV)(CONV *, FILE *, void *, int, int);
289 	void (*finishCONV)(CONV *);
290 	int maxin, maxout;
291 	float *inbuf, *outbuf;
292 	void *aux;
293 };
294 
295 #endif
296