-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreplay.c
391 lines (327 loc) · 8.45 KB
/
replay.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
/*
Copyright (C) 2005 Michael K. McCarty & Fritz Bronner
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Interplay's BUZZ ALDRIN's RACE into SPACE
//
// Formerly -=> LiftOff : Race to the Moon :: IBM version MCGA
// Copyright 1991 by Strategic Visions, Inc.
// Designed by Fritz Bronner
// Programmed by Michael K McCarty
//
#include <gamedata.h>
#include <Buzz_inc.h>
#include <externs.h>
#include <assert.h>
#include <mmfile.h>
#include <av.h>
#include <logging.h>
#ifdef DEADCODE
#define FRM_Delay 25
#define STL_OFF 26715
#define ANIM_PARTS 297
extern char STEPnum, loc[4];
extern struct MisEval Mev[60];
extern char MANNED[2], STEP, pal2[768], AI[2];
extern int tFrames, cFrame;
extern long aLoc;
extern GXHEADER dply;
extern struct AnimType AHead;
extern struct BlockHead BHead;
#endif
LOG_DEFAULT_CATEGORY(LOG_ROOT_CAT)
#if 0
void
RLEF(char *dest, char *src, unsigned int src_size)
{
asm push es; // preserve ES
asm push ds; // preserve DS
asm les di, dest; // move dest into ES:DI
asm lds si, src; // move src into DS:SI
asm mov cx, 0; // clear CX
asm mov bx, src_size; // move counter into BX
loa:
asm lodsb; // move byte into AL
asm dec bx; // decrement CX
asm cmp al, 0; // compare AL to 0
asm jl repeat; // if al < 0 jump to repeat
// copy bytes
asm mov ah, 0; // clear AH
asm inc al; // increment AL
asm mov cl, al; // put value of AL into CL
asm rep movsb; // move CX bytes from DS:SI to ES:DI
asm sub bx, ax; // increment BX by approp value
asm cmp bx, 0; // see if finished
asm jg loa; // if not then loop
asm jmp bot; // else jump to bottom
repeat:
asm neg al; // negate AL
asm inc al; // increment AL by 1
asm mov cl, al; // move counter value to CX
asm lodsb; // load value to copy
lob:
asm stosb; // copy AL into ES:DI
asm loop lob; // do while CX >0
asm dec bx; // decrement bx;
asm cmp bx, 100 h;
asm jg sk;
asm int 03 h;
sk:
asm cmp bx, 0; // see if finished
asm jg loa; // if not then loop
bot: // bottom of routine
asm pop ds; // restore ds
asm pop es; // restore es
return;
}
#endif
/** find and fill REPLAY structure and return 0, or -1 if failed.
* if grp != NULL and oGROUP at offset rep->off[0] is found, then fill grp too
*
* \return -1 on bad sequence
* \return 0 in all other cases
*/
static int
find_replay(REPLAY * rep, struct oGROUP *grp, char player, int num,
const char *type)
{
FILE *fseq = NULL;
struct oGROUP group;
size_t offset = 0;
int retval = 0;
assert(rep);
/** \note uses SEQ.DAT */
fseq = sOpen("SEQ.DAT", "rb", 0);
if (!fseq)
return -1;
if (strncmp("OOOO", type, 4) == 0)
{
FILE *f = sOpen("REPLAY.DAT", "rb", 1);
offset = (player * 100) + num;
fseek(f, offset * (sizeof *rep), SEEK_SET);
/** \todo Uses fread() here - should be fread_REPLAY(&Rep, 1, f); */
fread(rep, (sizeof *rep), 1, f);
fclose(f);
if (grp && fseek(fseq, sizeof_oGROUP * rep->Off[0], SEEK_SET) == 0)
fread_oGROUP(grp, 1, fseq);
}
else
{
int j = 0;
while (fread_oGROUP(&group, 1, fseq))
{
if (strncmp(group.ID, "XXXX", 4) == 0)
{
/* bad sequence? */
retval = -1;
goto done;
}
if (strcmp(&group.ID[3], type) == 0)
break;
j++;
}
rep->Qty = 1;
rep->Off[0] = j;
if (grp)
memcpy(grp, &group, sizeof(group));
}
done:
if (fseq)
fclose(fseq);
return retval;
}
/**
*
* \returns nothing if find_replay() fails
* \returns nothing if it can't open the [f]seq.dat file
*/
void
Replay(char plr, int num, int dx, int dy, int width, int height, char *Type)
{
int keep_going;
int i, kk, mode, max;
FILE *seqf, *fseqf;
long offset;
struct oGROUP group;
struct oFGROUP fgroup;
struct Table table;
REPLAY Rep;
mm_file vidfile;
float fps;
double last_time;
if (find_replay(&Rep, NULL, plr, num, Type) < 0)
return;
/** \note uses SEQ.DAT
* \note uses FSEQ.DAT
*/
seqf = sOpen("SEQ.DAT", "rb", 0);
fseqf = sOpen("FSEQ.DAT", "rb", 0);
if (!seqf || !fseqf)
{
if (!seqf)
fclose(seqf);
if (!fseqf)
fclose(fseqf);
return;
}
WaitForMouseUp();
DEBUG2("video sequence: %d segments", Rep.Qty);
for (kk = 0; kk < Rep.Qty; kk++)
{
DEBUG3("playing segment %d: %d", kk, Rep.Off[kk]);
if (Rep.Off[kk] < 1000) //Specs: success seq
{
fseek(seqf, Rep.Off[kk] * sizeof_oGROUP, SEEK_SET);
fread_oGROUP(&group, 1, seqf);
max = group.ID[1] - '0';
mode = 0;
}
else
{ //Specs: failure seq
int j = 0;
// MAX 50 Tables
i = Rep.Off[kk] / 1000;
j = Rep.Off[kk] % 1000;
if (i == 0 || i == 50)
goto done;
i--; //Specs: offset index klugge
fseek(fseqf, i * sizeof_Table, SEEK_SET);
fread_Table(&table, 1, fseqf);
offset = table.foffset;
fseek(fseqf, offset + j * sizeof_oFGROUP, SEEK_SET);
fread_oFGROUP(&fgroup, 1, fseqf);
mode = 1;
max = fgroup.ID[1] - '0';
};
i = 0;
keep_going = 1;
// update_map = 0;
while (keep_going && i < max)
{
int frm_idx;
char *seq_fname = NULL;
char fname[20];
if (mode == 1) /* failure */
frm_idx = fgroup.oLIST[i].aIdx;
else
frm_idx = group.oLIST[i].aIdx;
/* here we should create YUV Overlay, but we can't use it on
* pallettized surface, so we use a global Overlay initialized in
* sdl.c. */
seq_fname = seq_filename(frm_idx, mode);
if (!seq_fname)
seq_fname = "(unknown)";
/** \todo assumption on file extension */
snprintf(fname, sizeof(fname), "%s.ogg", seq_fname);
INFO2("opening video file `%s'", fname);
if (mm_open_fp(&vidfile, sOpen(fname, "rb", FT_VIDEO)) <= 0)
goto done;
/** \todo do not ignore width/height */
if (mm_video_info(&vidfile, NULL, NULL, &fps) <= 0)
goto done;
last_time = get_time();
while (keep_going)
{
video_rect.x = dx;
video_rect.y = dy;
video_rect.w = width;
video_rect.h = height;
screen_dirty = 1;
/** \todo track decoding time and adjust delays */
if (mm_decode_video(&vidfile, video_overlay) <= 0)
break;
if (bioskey(0) || grGetMouseButtons())
keep_going = 0;
/** \todo idle_loop is too inaccurate for this */
idle_loop_secs(1.0 / fps);
}
mm_close(&vidfile);
i++;
}
}
done:
mm_close(&vidfile);
video_rect.w = 0;
video_rect.h = 0;
fclose(fseqf);
fclose(seqf);
return;
}
void
DispBaby(int x, int y, int loc, char neww)
{
int i;
FILE *fin;
GXHEADER boob;
ui16 *bot, off = 0;
long locl;
off = 224;
GV(&boob, 68, 46);
bot = (ui16 *) boob.vptr;
fin = sOpen("BABYPICX.CDR", "rb", 0);
locl = (long) 1612 *loc; // First Image
fseek(fin, locl, SEEK_SET);
for (i = 0; i < 48; i++)
pal[off * 3 + i] = 0;
if (neww)
gxSetDisplayPalette(pal);
fread(&pal[off * 3], 48, 1, fin);
fread(boob.vptr, 1564, 1, fin);
fclose(fin);
for (i = 0; i < 782; i++)
{
bot[i + 782] = ((bot[i] & 0xF0F0) >> 4);
bot[i] = (bot[i] & 0x0F0F);
}
for (i = 0; i < 1564; i++)
{
boob.vptr[i] += off;
boob.vptr[1564 + i] += off;
}
gxPutImage(&boob, gxSET, x, y, 0);
if (neww)
gxSetDisplayPalette(pal);
DV(&boob);
return;
}
void
AbzFrame(char plr, int num, int dx, int dy, int width, int height,
char *Type, char mode)
{
int idx = 0;
struct oGROUP grp;
REPLAY Rep;
/* force mode to zero */
mode = 0;
char fname[100];
mm_file vidfile;
memset(&grp, 0, sizeof grp);
if (find_replay(&Rep, &grp, plr, num, Type) < 0)
return;
idx = grp.oLIST[0].aIdx;
/* XXX use a generic function */
snprintf(fname, sizeof(fname), "%s.ogg", seq_filename(idx, mode));
INFO2("opening video file `%s'", fname);
if (mm_open_fp(&vidfile, sOpen(fname, "rb", FT_VIDEO)) <= 0)
return;
if (mm_video_info(&vidfile, NULL, NULL, NULL) <= 0)
goto done;
if (mm_decode_video(&vidfile, video_overlay) <= 0)
goto done;
video_rect.x = dx;
video_rect.y = dy;
video_rect.w = width;
video_rect.h = height;
done:
mm_close(&vidfile);
}