1
#define PRGNAME "gfxlink"
2
#define PRGVERSION "1.5"
7
- combines Magnetic Scrolls picture files (Amiga format)
8
to gfxfile (compatible with the MAG interpreter)
9
- does not currently work with Collection & Wonderland pictures
11
Author: Paul David Doherty <h0142kdd@rz.hu-berlin.de>
14
v1.1: 17 Apr 1997 Amigafied & cleverised
15
v1.2: 19 Apr 1997 itoa() replaced
16
v1.3: 22 Apr 1997 cleaned up; name changed to 'gfxlink'
17
v1.4: 8 May 1997 might even work under UNIX now
18
v1.5: 25 Nov 1997 UNIX fixes supplied by Robert Bihlmeyer
21
#if defined(AZTEC_C) || defined(LATTICE)
25
#define FILENAMELENGTH 256
26
#define MAXPICTURES 35
36
#define S_IRUSR S_IREAD
37
#define S_IWUSR S_IWRITE
47
#if defined(__TURBOC__) || defined(__GNUC__) && !defined(__unix__)
48
#define O_SCRIVERE O_WRONLY|O_BINARY
49
#define O_LEGGERE O_RDONLY|O_BINARY
51
#define O_SCRIVERE O_WRONLY
52
#define O_LEGGERE O_RDONLY
67
typedef unsigned char type8;
69
#error "Can't find an 8-bit integer type"
73
typedef unsigned short type16;
75
typedef unsigned int type16;
77
#error "Can't find a 16-bit integer type"
80
#if INT_MAX==0x7fffffff
81
typedef unsigned int type32;
82
#elif LONG_MAX==0x7fffffff
83
typedef unsigned long type32;
85
#error "Can't find a 32-bit integer type"
88
int fdi, fdo_temp, fdo_gfx;
89
char infilemask[FILENAMELENGTH];
90
char infile[FILENAMELENGTH];
91
char gfxfile[FILENAMELENGTH];
95
#define TEMPFILE "ram:pics.tmp"
97
#define TEMPFILE "pics.tmp"
100
char *magic = "MaPi";
103
type8 endfile_reached = FALSE;
104
type8 offsetcounter = 1;
107
type32 offset[MAXPICTURES + 2];
121
1, 15, 17, 21, 23, 25, 27, 30, 32, 34,
123
1, 15, 17, 21, 23, 25, 27, 30, 32, 34,
124
"The Pawn", "ThePawn/Pawn",
125
1, 15, 17, 21, 23, 25, 27, 30, 32, 34,
126
"The Guild of Thieves", "guild",
127
4, 32, 0, 0, 0, 0, 0, 0, 0, 0,
128
"The Guild of Thieves", "The Guild Of Thieves/guild",
129
4, 32, 0, 0, 0, 0, 0, 0, 0, 0,
131
3, 30, 73, 73, 0, 0, 0, 0, 0, 0,
133
16, 37, 41, 41, 38, 40, 0, 0, 0, 0,
135
14, 40, 0, 0, 0, 0, 0, 0, 0, 0,
137
16, 19, 0, 0, 0, 0, 0, 0, 0, 0
141
write_32 (type32 numb)
143
inputbuf[3] = numb & 0xff;
145
inputbuf[2] = numb & 0xff;
147
inputbuf[1] = numb & 0xff;
150
write (fdo_gfx, inputbuf, 4);
156
fprintf (stderr, PRGNAME ": %s\n", error);
165
itoa_krns (type16 n, char s[])
171
s[k++] = n % 10 + '0';
173
while ((n /= 10) > 0);
175
for (k = 0, l = strlen (s) - 1; k < l; k++, l--)
184
kick (type16 picnumber)
186
itoa_krns (picnumber, picnum);
187
strcpy (infile, infilemask);
188
strcat (infile, picnum);
190
if ((fdi = open (infile, O_LEGGERE, 0)) == -1)
192
printf ("File not found: %s\n", infile);
193
ex ("picture file(s) missing; can't create gfxfile");
197
endfile_reached = FALSE;
199
while (endfile_reached == FALSE)
201
buflength = read (fdi, inputbuf, 256);
202
if (buflength != 256)
203
endfile_reached = TRUE;
204
write (fdo_temp, inputbuf, (int) buflength);
205
partlength = partlength + buflength;
207
offset[offsetcounter] = offset[offsetcounter - 1] + partlength;
216
fprintf (stderr, PRGNAME " v" PRGVERSION ": ");
217
fprintf (stderr, "creates Magnetic Scrolls graphics file.\n");
218
fprintf (stderr, "(c) 1997 by Paul David Doherty <h0142kdd@rz.hu-berlin.de>\n\n");
219
fprintf (stderr, "Usage: " PRGNAME " [path] gfxfile\n");
220
fprintf (stderr, " e.g. " PRGNAME " df0: pawn.gfx\n");
225
main (int argc, char **argv)
229
if ((argc < 2) || (argc > 3))
232
strcpy (gfxfile, argv[(argc == 2) ? 1 : 2]);
235
strcpy (infilemask, argv[1]);
236
if ((infilemask[strlen (infilemask) - 1] != ':')
237
&& (infilemask[strlen (infilemask) - 1] != '/')
238
&& (infilemask[strlen (infilemask) - 1] != '\\'))
239
strcat (infilemask, DIRSEP);
243
for (i = 0; i < (sizeof (lookup) / sizeof (struct lookuptab)); i++)
245
itoa_krns (lookup[i].par[1], picnum);
246
strcpy (infile, infilemask);
247
strcat (infile, lookup[i].filemask);
248
strcat (infile, picnum);
249
if ((fdi = open (infile, O_LEGGERE, 0)) != -1)
253
if (detected >= (sizeof (lookup) / sizeof (struct lookuptab)))
254
ex ("no picture files detected");
256
printf ("Game detected: %s\n", lookup[detected].game);
258
/* generation of temp file & offsets */
259
if ((fdo_temp = open (TEMPFILE,
260
O_SCRIVERE | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1)
261
ex ("could not create temp file");
264
strcat (infilemask, lookup[detected].filemask);
265
for (i = 0; i <= 8; i = i + 2)
266
for (j = lookup[detected].par[i]; j <= lookup[detected].par[i + 1]; j++)
271
printf ("Number of pictures: %d\n", offsetcounter);
273
/* writing offsets into gfx file */
274
if ((fdo_gfx = open (gfxfile,
275
O_SCRIVERE | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) == -1)
276
ex ("could not create output file");
278
addoffset = (((offsetcounter + 2) * 4) + strlen (magic));
279
for (i = 0; i < offsetcounter; i++)
280
offset[i] = offset[i] + addoffset;
281
alllength = offset[offsetcounter] + addoffset;
282
offset[offsetcounter] = 0;
283
write (fdo_gfx, magic, strlen (magic));
284
write_32 (alllength);
285
for (i = 0; i <= offsetcounter; i++)
286
write_32 (offset[i]);
288
/* copying tempfile into gfx file */
289
if ((fdi = open (TEMPFILE, O_LEGGERE, 0)) == -1)
290
ex ("could not reopen temp file");
292
endfile_reached = FALSE;
293
while (endfile_reached == FALSE)
295
buflength = read (fdi, inputbuf, 256);
296
if (buflength != 256)
297
endfile_reached = TRUE;
298
write (fdo_gfx, inputbuf, (int) buflength);
302
if (remove (TEMPFILE) != 0)
303
ex ("couldn't delete temp file");