added missing definitions
[rocksndiamonds.git] / src / tape.c
1 // ============================================================================
2 // Rocks'n'Diamonds - McDuffin Strikes Back!
3 // ----------------------------------------------------------------------------
4 // (c) 1995-2014 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  http://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // tape.c
10 // ============================================================================
11
12 #include "libgame/libgame.h"
13
14 #include "tape.h"
15 #include "init.h"
16 #include "game.h"
17 #include "tools.h"
18 #include "files.h"
19 #include "network.h"
20 #include "anim.h"
21
22 #define DEBUG_TAPE_WHEN_PLAYING                 FALSE
23
24 /* tape button identifiers */
25 #define TAPE_CTRL_ID_EJECT                      0
26 #define TAPE_CTRL_ID_EXTRA                      1
27 #define TAPE_CTRL_ID_STOP                       2
28 #define TAPE_CTRL_ID_PAUSE                      3
29 #define TAPE_CTRL_ID_RECORD                     4
30 #define TAPE_CTRL_ID_PLAY                       5
31
32 #define NUM_TAPE_BUTTONS                        6
33
34 /* values for tape handling */
35 #define TAPE_PAUSE_SECONDS_BEFORE_DEATH         5
36
37 /* forward declaration for internal use */
38 static void HandleTapeButtons(struct GadgetInfo *);
39 static void TapeStopWarpForward();
40
41 static struct GadgetInfo *tape_gadget[NUM_TAPE_BUTTONS];
42
43
44 /* ========================================================================= */
45 /* video tape definitions                                                    */
46 /* ========================================================================= */
47
48 #define VIDEO_INFO_OFF                  (VIDEO_STATE_DATE_OFF   |       \
49                                          VIDEO_STATE_TIME_OFF   |       \
50                                          VIDEO_STATE_FRAME_OFF)
51 #define VIDEO_STATE_OFF                 (VIDEO_STATE_PLAY_OFF   |       \
52                                          VIDEO_STATE_REC_OFF    |       \
53                                          VIDEO_STATE_PAUSE_OFF  |       \
54                                          VIDEO_STATE_FFWD_OFF   |       \
55                                          VIDEO_STATE_WARP_OFF   |       \
56                                          VIDEO_STATE_WARP2_OFF  |       \
57                                          VIDEO_STATE_PBEND_OFF  |       \
58                                          VIDEO_STATE_1STEP_OFF)
59 #define VIDEO_PRESS_OFF                 (VIDEO_PRESS_PLAY_OFF   |       \
60                                          VIDEO_PRESS_REC_OFF    |       \
61                                          VIDEO_PRESS_PAUSE_OFF  |       \
62                                          VIDEO_PRESS_STOP_OFF   |       \
63                                          VIDEO_PRESS_EJECT_OFF)
64 #define VIDEO_ALL_OFF                   (VIDEO_INFO_OFF         |       \
65                                          VIDEO_STATE_OFF        |       \
66                                          VIDEO_PRESS_OFF)
67
68 #define VIDEO_INFO_ON                   (VIDEO_STATE_DATE_ON    |       \
69                                          VIDEO_STATE_TIME_ON    |       \
70                                          VIDEO_STATE_FRAME_ON)
71 #define VIDEO_STATE_ON                  (VIDEO_STATE_PLAY_ON    |       \
72                                          VIDEO_STATE_REC_ON     |       \
73                                          VIDEO_STATE_PAUSE_ON   |       \
74                                          VIDEO_STATE_FFWD_ON    |       \
75                                          VIDEO_STATE_WARP_ON    |       \
76                                          VIDEO_STATE_WARP2_ON   |       \
77                                          VIDEO_STATE_PBEND_ON   |       \
78                                          VIDEO_STATE_1STEP_ON)
79 #define VIDEO_PRESS_ON                  (VIDEO_PRESS_PLAY_ON    |       \
80                                          VIDEO_PRESS_REC_ON     |       \
81                                          VIDEO_PRESS_PAUSE_ON   |       \
82                                          VIDEO_PRESS_STOP_ON    |       \
83                                          VIDEO_PRESS_EJECT_ON)
84 #define VIDEO_ALL_ON                    (VIDEO_INFO_ON          |       \
85                                          VIDEO_STATE_ON         |       \
86                                          VIDEO_PRESS_ON)
87
88 #define VIDEO_INFO                      (VIDEO_INFO_ON | VIDEO_INFO_OFF)
89 #define VIDEO_STATE                     (VIDEO_STATE_ON | VIDEO_STATE_OFF)
90 #define VIDEO_PRESS                     (VIDEO_PRESS_ON | VIDEO_PRESS_OFF)
91 #define VIDEO_ALL                       (VIDEO_ALL_ON | VIDEO_ALL_OFF)
92
93 #define NUM_TAPE_FUNCTIONS              11
94 #define NUM_TAPE_FUNCTION_PARTS         2
95 #define NUM_TAPE_FUNCTION_STATES        2
96
97
98 /* ========================================================================= */
99 /* video display functions                                                   */
100 /* ========================================================================= */
101
102 static void DrawVideoDisplay_Graphics(unsigned int state, unsigned int value)
103 {
104   int i, j, k;
105
106   static struct
107   {
108     int graphic;
109     struct XY *pos;
110   }
111   video_pos[NUM_TAPE_FUNCTIONS][NUM_TAPE_FUNCTION_PARTS] =
112   {
113     {
114       { IMG_GFX_TAPE_LABEL_PLAY,                &tape.label.play        },
115       { IMG_GFX_TAPE_SYMBOL_PLAY,               &tape.symbol.play       },
116     },
117     {
118       { IMG_GFX_TAPE_LABEL_RECORD,              &tape.label.record      },
119       { IMG_GFX_TAPE_SYMBOL_RECORD,             &tape.symbol.record     },
120     },
121     {
122       { IMG_GFX_TAPE_LABEL_PAUSE,               &tape.label.pause       },
123       { IMG_GFX_TAPE_SYMBOL_PAUSE,              &tape.symbol.pause      },
124     },
125     {
126       { IMG_GFX_TAPE_LABEL_DATE,                &tape.label.date        },
127       { -1,                                     NULL                    },
128     },
129     {
130       { IMG_GFX_TAPE_LABEL_TIME,                &tape.label.time        },
131       { -1,                                     NULL                    },
132     },
133     {
134       /* (no label for displaying optional frame) */
135       { -1,                                     NULL                    },
136       { -1,                                     NULL                    },
137     },
138     {
139       { IMG_GFX_TAPE_LABEL_FAST_FORWARD,        &tape.label.fast_forward  },
140       { IMG_GFX_TAPE_SYMBOL_FAST_FORWARD,       &tape.symbol.fast_forward },
141     },
142     {
143       { IMG_GFX_TAPE_LABEL_WARP_FORWARD,        &tape.label.warp_forward  },
144       { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD,       &tape.symbol.warp_forward },
145     },
146     {
147       { IMG_GFX_TAPE_LABEL_WARP_FORWARD_BLIND,  &tape.label.warp_forward_blind},
148       { IMG_GFX_TAPE_SYMBOL_WARP_FORWARD_BLIND, &tape.symbol.warp_forward_blind},
149     },
150     {
151       { IMG_GFX_TAPE_LABEL_PAUSE_BEFORE_END,    &tape.label.pause_before_end  },
152       { IMG_GFX_TAPE_SYMBOL_PAUSE_BEFORE_END,   &tape.symbol.pause_before_end },
153     },
154     {
155       { IMG_GFX_TAPE_LABEL_SINGLE_STEP,         &tape.label.single_step  },
156       { IMG_GFX_TAPE_SYMBOL_SINGLE_STEP,        &tape.symbol.single_step },
157     },
158   };
159
160   for (k = 0; k < NUM_TAPE_FUNCTION_STATES; k++)        /* on or off states */
161   {
162     for (i = 0; i < NUM_TAPE_FUNCTIONS; i++)            /* record, play, ... */
163     {
164       for (j = 0; j < NUM_TAPE_FUNCTION_PARTS; j++)     /* label or symbol */
165       {
166         int graphic = video_pos[i][j].graphic;
167         struct XY *pos = video_pos[i][j].pos;
168
169         if (graphic == -1 ||
170             pos->x == -1 ||
171             pos->y == -1)
172           continue;
173
174         if (state & (1 << (i * 2 + k)))
175         {
176           struct GraphicInfo *gfx_bg = &graphic_info[IMG_BACKGROUND_TAPE];
177           struct GraphicInfo *gfx = &graphic_info[graphic];
178           Bitmap *gd_bitmap;
179           int gd_x, gd_y;
180           int skip_value =
181             (j == 0 ? VIDEO_DISPLAY_SYMBOL_ONLY : VIDEO_DISPLAY_LABEL_ONLY);
182
183           if (value == skip_value)
184             continue;
185
186           if (k == 1)           /* on */
187           {
188             gd_bitmap = gfx->bitmap;
189             gd_x = gfx->src_x;
190             gd_y = gfx->src_y;
191           }
192           else                  /* off */
193           {
194             gd_bitmap = gfx_bg->bitmap;
195             gd_x = gfx_bg->src_x + pos->x;
196             gd_y = gfx_bg->src_y + pos->y;
197           }
198
199           /* some tape graphics may be undefined -- only draw if defined */
200           if (gd_bitmap != NULL)
201             BlitBitmap(gd_bitmap, drawto, gd_x, gd_y, gfx->width, gfx->height,
202                        VX + pos->x, VY + pos->y);
203
204           redraw_mask |= REDRAW_DOOR_2;
205         }
206       }
207     }
208   }
209 }
210
211
212 #define DATETIME_NONE                   (0)
213
214 #define DATETIME_DATE_YYYY              (1 << 0)
215 #define DATETIME_DATE_YY                (1 << 1)
216 #define DATETIME_DATE_MON               (1 << 2)
217 #define DATETIME_DATE_MM                (1 << 3)
218 #define DATETIME_DATE_DD                (1 << 4)
219
220 #define DATETIME_TIME_HH                (1 << 5)
221 #define DATETIME_TIME_MIN               (1 << 6)
222 #define DATETIME_TIME_MM                (1 << 7)
223 #define DATETIME_TIME_SS                (1 << 8)
224
225 #define DATETIME_FRAME                  (1 << 9)
226
227 #define DATETIME_XOFFSET_1              (1 << 10)
228 #define DATETIME_XOFFSET_2              (1 << 11)
229
230 #define DATETIME_DATE                   (DATETIME_DATE_YYYY     |       \
231                                          DATETIME_DATE_YY       |       \
232                                          DATETIME_DATE_MON      |       \
233                                          DATETIME_DATE_MM       |       \
234                                          DATETIME_DATE_DD)
235
236 #define DATETIME_TIME                   (DATETIME_TIME_HH       |       \
237                                          DATETIME_TIME_MIN      |       \
238                                          DATETIME_TIME_MM       |       \
239                                          DATETIME_TIME_SS)
240
241 #define MAX_DATETIME_STRING_SIZE        32
242
243 static void DrawVideoDisplay_DateTime(unsigned int state, unsigned int value)
244 {
245   int i;
246
247   static char *month_shortnames[] =
248   {
249     "JAN",
250     "FEB",
251     "MAR",
252     "APR",
253     "MAY",
254     "JUN",
255     "JUL",
256     "AUG",
257     "SEP",
258     "OCT",
259     "NOV",
260     "DEC"
261   };
262
263   static struct
264   {
265     struct TextPosInfo *pos;
266     int type;
267   }
268   datetime_info[] =
269   {
270     { &tape.text.date,          DATETIME_DATE_DD                        },
271     { &tape.text.date,          DATETIME_DATE_MON | DATETIME_XOFFSET_1  },
272     { &tape.text.date,          DATETIME_DATE_YY  | DATETIME_XOFFSET_2  },
273     { &tape.text.date_yyyy,     DATETIME_DATE_YYYY                      },
274     { &tape.text.date_yy,       DATETIME_DATE_YY                        },
275     { &tape.text.date_mon,      DATETIME_DATE_MON                       },
276     { &tape.text.date_mm,       DATETIME_DATE_MM                        },
277     { &tape.text.date_dd,       DATETIME_DATE_DD                        },
278
279     { &tape.text.time,          DATETIME_TIME_MIN                       },
280     { &tape.text.time,          DATETIME_TIME_SS  | DATETIME_XOFFSET_1  },
281     { &tape.text.time_hh,       DATETIME_TIME_HH                        },
282     { &tape.text.time_mm,       DATETIME_TIME_MM                        },
283     { &tape.text.time_ss,       DATETIME_TIME_SS                        },
284
285     { &tape.text.frame,         DATETIME_FRAME                          },
286
287     { NULL,                     DATETIME_NONE                           },
288   };
289
290   for (i = 0; datetime_info[i].pos != NULL; i++)
291   {
292     struct TextPosInfo *pos = datetime_info[i].pos;
293     int type = datetime_info[i].type;
294     int xpos, ypos;
295
296     if (pos->x == -1 &&
297         pos->y == -1)
298       continue;
299
300     xpos = VX + pos->x + (type & DATETIME_XOFFSET_1 ? pos->xoffset  :
301                           type & DATETIME_XOFFSET_2 ? pos->xoffset2 : 0);
302     ypos = VY + pos->y;
303
304     if ((type & DATETIME_DATE) && (state & VIDEO_STATE_DATE_ON))
305     {
306       char s[MAX_DATETIME_STRING_SIZE];
307       int year2 = value / 10000;
308       int year4 = (year2 < 70 ? 2000 + year2 : 1900 + year2);
309       int month_index = (value / 100) % 100;
310       int month = month_index + 1;
311       int day = value % 100;
312
313       strcpy(s, (type & DATETIME_DATE_YYYY ? int2str(year4, 4) :
314                  type & DATETIME_DATE_YY   ? int2str(year2, 2) :
315                  type & DATETIME_DATE_MON  ? month_shortnames[month_index] :
316                  type & DATETIME_DATE_MM   ? int2str(month, 2) :
317                  type & DATETIME_DATE_DD   ? int2str(day, 2) : ""));
318
319       DrawText(xpos, ypos, s, pos->font);
320     }
321     else if ((type & DATETIME_TIME) && (state & VIDEO_STATE_TIME_ON))
322     {
323       char s[MAX_DATETIME_STRING_SIZE];
324       int hh = (value / 3600) % 100;
325       int min = value / 60;
326       int mm = (value / 60) % 60;
327       int ss = value % 60;
328
329       strcpy(s, (type & DATETIME_TIME_HH  ? int2str(hh, 2) :
330                  type & DATETIME_TIME_MIN ? int2str(min, 2) :
331                  type & DATETIME_TIME_MM  ? int2str(mm, 2) :
332                  type & DATETIME_TIME_SS  ? int2str(ss, 2) : ""));
333
334       DrawText(xpos, ypos, s, pos->font);
335     }
336     else if ((type & DATETIME_FRAME) && (state & VIDEO_STATE_FRAME_ON))
337     {
338       DrawText(xpos, ypos, int2str(value, pos->size), pos->font);
339     }
340   }
341 }
342
343 void DrawVideoDisplay(unsigned int state, unsigned int value)
344 {
345   DrawVideoDisplay_Graphics(state, value);
346   DrawVideoDisplay_DateTime(state, value);
347 }
348
349 void DrawVideoDisplayLabel(unsigned int state)
350 {
351   DrawVideoDisplay(state, VIDEO_DISPLAY_LABEL_ONLY);
352 }
353
354 void DrawVideoDisplaySymbol(unsigned int state)
355 {
356   DrawVideoDisplay(state, VIDEO_DISPLAY_SYMBOL_ONLY);
357 }
358
359 void DrawCompleteVideoDisplay()
360 {
361   struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE];
362
363   /* draw tape background */
364   BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y,
365              gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
366
367   /* draw tape buttons (forced) */
368   UnmapTapeButtons();
369   MapTapeButtons();
370
371   DrawVideoDisplay(VIDEO_ALL_OFF, 0);
372
373   if (tape.recording)
374   {
375     DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
376     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
377     DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
378     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
379
380     if (tape.pausing)
381       DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
382   }
383   else if (tape.playing)
384   {
385     DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
386     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
387     DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
388     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
389
390     if (tape.pausing)
391       DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
392   }
393   else if (tape.date && tape.length)
394   {
395     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
396     DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
397     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
398   }
399
400   BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
401              0, 0);
402 }
403
404 void TapeDeactivateDisplayOn()
405 {
406   SetDrawDeactivationMask(REDRAW_FIELD);
407   audio.sound_deactivated = TRUE;
408 }
409
410 void TapeDeactivateDisplayOff(boolean redraw_display)
411 {
412   SetDrawDeactivationMask(REDRAW_NONE);
413   audio.sound_deactivated = FALSE;
414
415   if (redraw_display)
416   {
417     RedrawPlayfield();
418     DrawGameDoorValues();
419   }
420 }
421
422
423 /* ========================================================================= */
424 /* tape control functions                                                    */
425 /* ========================================================================= */
426
427 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
428 {
429   struct tm *lt = localtime(&epoch_seconds);
430
431   tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
432 }
433
434 void TapeSetDateFromNow()
435 {
436   TapeSetDateFromEpochSeconds(time(NULL));
437 }
438
439 void TapeErase()
440 {
441   int i;
442
443   tape.counter = 0;
444   tape.length = 0;
445   tape.length_frames = 0;
446   tape.length_seconds = 0;
447
448   if (leveldir_current)
449     setString(&tape.level_identifier, leveldir_current->identifier);
450
451   tape.level_nr = level_nr;
452   tape.pos[tape.counter].delay = 0;
453   tape.changed = TRUE;
454
455   tape.random_seed = InitRND(level.random_seed);
456
457   tape.file_version = FILE_VERSION_ACTUAL;
458   tape.game_version = GAME_VERSION_ACTUAL;
459   tape.engine_version = level.game_version;
460
461   TapeSetDateFromNow();
462
463   for (i = 0; i < MAX_PLAYERS; i++)
464     tape.player_participates[i] = FALSE;
465
466   tape.centered_player_nr_next = -1;
467   tape.set_centered_player = FALSE;
468 }
469
470 static void TapeRewind()
471 {
472   tape.counter = 0;
473   tape.delay_played = 0;
474   tape.pause_before_end = FALSE;
475   tape.recording = FALSE;
476   tape.playing = FALSE;
477   tape.fast_forward = FALSE;
478   tape.warp_forward = FALSE;
479   tape.deactivate_display = FALSE;
480   tape.auto_play = (global.autoplay_leveldir != NULL);
481   tape.auto_play_level_solved = FALSE;
482   tape.quick_resume = FALSE;
483   tape.single_step = FALSE;
484
485   tape.centered_player_nr_next = -1;
486   tape.set_centered_player = FALSE;
487
488   InitRND(tape.random_seed);
489 }
490
491 static void TapeSetRandomSeed(int random_seed)
492 {
493   tape.random_seed = InitRND(random_seed);
494 }
495
496 void TapeStartRecording(int random_seed)
497 {
498   if (!TAPE_IS_STOPPED(tape))
499     TapeStop();
500
501   TapeErase();
502   TapeRewind();
503   TapeSetRandomSeed(random_seed);
504
505   tape.recording = TRUE;
506
507   DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
508   DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
509   DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
510   DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
511
512   MapTapeWarpButton();
513
514   SetDrawDeactivationMask(REDRAW_NONE);
515   audio.sound_deactivated = FALSE;
516 }
517
518 static void TapeStartGameRecording()
519 {
520   TapeStartRecording(level.random_seed);
521
522 #if defined(NETWORK_AVALIABLE)
523   if (options.network)
524   {
525     SendToServer_StartPlaying();
526
527     return;
528   }
529 #endif
530
531   InitGame();
532 }
533
534 static void TapeAppendRecording()
535 {
536   if (!tape.playing || !tape.pausing)
537     return;
538
539   // stop playing
540   tape.playing = FALSE;
541   tape.fast_forward = FALSE;
542   tape.warp_forward = FALSE;
543   tape.pause_before_end = FALSE;
544   tape.deactivate_display = FALSE;
545
546   // start recording
547   tape.recording = TRUE;
548   tape.changed = TRUE;
549
550   // set current delay (for last played move)
551   tape.pos[tape.counter].delay = tape.delay_played;
552
553   // set current date
554   TapeSetDateFromNow();
555
556   DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
557   DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
558
559   UpdateAndDisplayGameControlValues();
560 }
561
562 void TapeHaltRecording()
563 {
564   if (!tape.recording)
565     return;
566
567   tape.counter++;
568   tape.pos[tape.counter].delay = 0;
569
570   tape.length = tape.counter;
571   tape.length_frames = GetTapeLengthFrames();
572   tape.length_seconds = GetTapeLengthSeconds();
573 }
574
575 void TapeStopRecording()
576 {
577   TapeHaltRecording();
578
579   tape.recording = FALSE;
580   tape.pausing = FALSE;
581
582   DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
583   MapTapeEjectButton();
584 }
585
586 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
587 {
588   byte action[MAX_PLAYERS];
589   int i;
590
591   if (!tape.recording)          /* (record action even when tape is paused) */
592     return;
593
594   if (tape.counter >= MAX_TAPE_LEN - 1)
595   {
596     TapeStopRecording();
597     return;
598   }
599
600   for (i = 0; i < MAX_PLAYERS; i++)
601     action[i] = action_raw[i];
602
603   if (tape.set_centered_player)
604   {
605     for (i = 0; i < MAX_PLAYERS; i++)
606       if (tape.centered_player_nr_next == i ||
607           tape.centered_player_nr_next == -1)
608         action[i] |= KEY_SET_FOCUS;
609
610     tape.set_centered_player = FALSE;
611   }
612
613   if (tape.pos[tape.counter].delay > 0)         /* already stored action */
614   {
615     boolean changed_events = FALSE;
616
617     for (i = 0; i < MAX_PLAYERS; i++)
618       if (tape.pos[tape.counter].action[i] != action[i])
619         changed_events = TRUE;
620
621     if (changed_events || tape.pos[tape.counter].delay >= 255)
622     {
623       tape.counter++;
624       tape.pos[tape.counter].delay = 0;
625     }
626     else
627       tape.pos[tape.counter].delay++;
628   }
629
630   if (tape.pos[tape.counter].delay == 0)        /* store new action */
631   {
632     for (i = 0; i < MAX_PLAYERS; i++)
633       tape.pos[tape.counter].action[i] = action[i];
634
635     tape.pos[tape.counter].delay++;
636   }
637 }
638
639 void TapeTogglePause(boolean toggle_manual)
640 {
641   int state = 0;
642
643   tape.pausing = !tape.pausing;
644
645   if (tape.single_step && toggle_manual)
646     tape.single_step = FALSE;
647
648   state |= VIDEO_STATE_PAUSE(tape.pausing);
649
650   if (tape.pause_before_end)
651     state |= VIDEO_STATE_PBEND(!tape.pausing);
652   else if (tape.fast_forward)
653     state |= VIDEO_STATE_FFWD(!tape.pausing);
654
655   if (tape.playing)
656     state |= VIDEO_STATE_PLAY_ON;
657   else
658     state |= VIDEO_STATE_1STEP(tape.single_step);
659
660   DrawVideoDisplay(state, 0);
661
662   if (tape.warp_forward)
663   {
664     if (tape.pausing)
665     {
666       TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
667     }
668     else if (tape.deactivate_display)
669     {
670       TapeDeactivateDisplayOn();
671
672       DrawVideoDisplaySymbol(VIDEO_STATE_WARP_ON);
673     }
674     else
675     {
676       DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
677     }
678
679     if (tape.quick_resume)
680     {
681       tape.quick_resume = FALSE;
682
683       TapeStopWarpForward();
684       TapeAppendRecording();
685
686       if (!CheckEngineSnapshotSingle())
687         SaveEngineSnapshotSingle();
688
689       // restart step/move snapshots after quick loading tape
690       SaveEngineSnapshotToListInitial();
691     }
692   }
693
694   if (setup.show_snapshot_buttons &&
695       game_status == GAME_MODE_PLAYING &&
696       CheckEngineSnapshotList())
697   {
698     if (tape.pausing)
699       MapUndoRedoButtons();
700     else if (!tape.single_step)
701       UnmapUndoRedoButtons();
702   }
703 }
704
705 void TapeStartPlaying()
706 {
707   if (TAPE_IS_EMPTY(tape))
708     return;
709
710   if (!TAPE_IS_STOPPED(tape))
711     TapeStop();
712
713   TapeRewind();
714
715   tape.playing = TRUE;
716
717   DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
718   DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
719   DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
720   DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
721
722   MapTapeWarpButton();
723
724   SetDrawDeactivationMask(REDRAW_NONE);
725   audio.sound_deactivated = FALSE;
726 }
727
728 static void TapeStartGamePlaying()
729 {
730   TapeStartPlaying();
731
732   InitGame();
733 }
734
735 void TapeStopPlaying()
736 {
737   tape.playing = FALSE;
738   tape.pausing = FALSE;
739
740   if (tape.warp_forward)
741     TapeStopWarpForward();
742
743   DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
744   MapTapeEjectButton();
745 }
746
747 byte *TapePlayAction()
748 {
749   int update_delay = FRAMES_PER_SECOND / 2;
750   boolean update_video_display = (FrameCounter % update_delay == 0);
751   boolean update_draw_label_on = ((FrameCounter / update_delay) % 2 == 1);
752   static byte action[MAX_PLAYERS];
753   int i;
754
755   if (!tape.playing || tape.pausing)
756     return NULL;
757
758   if (tape.pause_before_end)  // stop some seconds before end of tape
759   {
760     if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
761     {
762       tape.fast_forward = FALSE;
763       tape.pause_before_end = FALSE;
764
765       TapeStopWarpForward();
766       TapeTogglePause(TAPE_TOGGLE_MANUAL);
767
768       return NULL;
769     }
770   }
771
772   if (update_video_display && !tape.deactivate_display)
773   {
774     if (tape.pause_before_end)
775       DrawVideoDisplayLabel(VIDEO_STATE_PBEND(update_draw_label_on));
776     else if (tape.fast_forward)
777       DrawVideoDisplayLabel(VIDEO_STATE_FFWD(update_draw_label_on));
778
779     if (tape.warp_forward)
780       DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
781   }
782
783   if (tape.counter >= tape.length)      /* end of tape reached */
784   {
785     if (tape.warp_forward && !tape.auto_play)
786       TapeTogglePause(TAPE_TOGGLE_MANUAL);
787     else
788       TapeStop();
789
790     return NULL;
791   }
792
793   for (i = 0; i < MAX_PLAYERS; i++)
794     action[i] = tape.pos[tape.counter].action[i];
795
796 #if DEBUG_TAPE_WHEN_PLAYING
797   printf("%05d", FrameCounter);
798   for (i = 0; i < MAX_PLAYERS; i++)
799     printf("   %08x", action[i]);
800   printf("\n");
801 #endif
802
803   tape.set_centered_player = FALSE;
804   tape.centered_player_nr_next = -999;
805
806   for (i = 0; i < MAX_PLAYERS; i++)
807   {
808     if (action[i] & KEY_SET_FOCUS)
809     {
810       tape.set_centered_player = TRUE;
811       tape.centered_player_nr_next =
812         (tape.centered_player_nr_next == -999 ? i : -1);
813     }
814
815     action[i] &= ~KEY_SET_FOCUS;
816   }
817
818   tape.delay_played++;
819   if (tape.delay_played >= tape.pos[tape.counter].delay)
820   {
821     tape.counter++;
822     tape.delay_played = 0;
823   }
824
825   return action;
826 }
827
828 void TapeStop()
829 {
830   TapeStopRecording();
831   TapeStopPlaying();
832
833   DrawVideoDisplay(VIDEO_STATE_OFF, 0);
834
835   if (tape.date && tape.length)
836   {
837     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
838     DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
839     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
840   }
841 }
842
843 unsigned int GetTapeLengthFrames()
844 {
845   unsigned int tape_length_frames = 0;
846   int i;
847
848   if (TAPE_IS_EMPTY(tape))
849     return(0);
850
851   for (i = 0; i < tape.length; i++)
852     tape_length_frames += tape.pos[i].delay;
853
854   return tape_length_frames;
855 }
856
857 unsigned int GetTapeLengthSeconds()
858 {
859   return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
860 }
861
862 static void TapeStartWarpForward()
863 {
864   tape.warp_forward = TRUE;
865
866   if (!tape.fast_forward && !tape.pause_before_end)
867   {
868     tape.pausing = FALSE;
869     tape.pause_before_end = TRUE;
870     tape.deactivate_display = TRUE;
871
872     TapeDeactivateDisplayOn();
873
874     DrawVideoDisplay(VIDEO_STATE_PBEND_ON, 0);
875     DrawVideoDisplaySymbol(VIDEO_STATE_WARP_ON);
876   }
877   else
878   {
879     DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
880   }
881 }
882
883 static void TapeStopWarpForward()
884 {
885   int state = VIDEO_STATE_PAUSE(tape.pausing);
886
887   if (tape.deactivate_display)
888     tape.pause_before_end = FALSE;
889
890   tape.warp_forward = FALSE;
891   tape.deactivate_display = FALSE;
892
893   TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
894
895   state |= VIDEO_STATE_WARP_OFF;
896   state |= (tape.pause_before_end ? VIDEO_STATE_PBEND_ON :
897             tape.fast_forward     ? VIDEO_STATE_FFWD_ON :
898             VIDEO_STATE_PLAY_ON);
899
900   DrawVideoDisplay(state, 0);
901 }
902
903 static void TapeSingleStep()
904 {
905   if (options.network)
906     return;
907
908   if (!tape.pausing)
909     TapeTogglePause(TAPE_TOGGLE_MANUAL);
910
911   tape.single_step = !tape.single_step;
912
913   DrawVideoDisplay(VIDEO_STATE_1STEP(tape.single_step), 0);
914 }
915
916 void TapeQuickSave()
917 {
918   if (game_status == GAME_MODE_MAIN)
919   {
920     Request("No game that can be saved!", REQ_CONFIRM);
921
922     return;
923   }
924
925   if (game_status != GAME_MODE_PLAYING)
926     return;
927
928   if (tape.recording)
929     TapeHaltRecording();        /* prepare tape for saving on-the-fly */
930
931   if (TAPE_IS_EMPTY(tape))
932   {
933     Request("No tape that can be saved!", REQ_CONFIRM);
934
935     return;
936   }
937
938   if (SaveTapeChecked(tape.level_nr))
939     SaveEngineSnapshotSingle();
940 }
941
942 void TapeQuickLoad()
943 {
944   char *filename = getTapeFilename(level_nr);
945
946   if (!fileExists(filename))
947   {
948     Request("No tape for this level!", REQ_CONFIRM);
949
950     return;
951   }
952
953   if (tape.recording && !Request("Stop recording and load tape?",
954                                  REQ_ASK | REQ_STAY_CLOSED))
955   {
956     OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
957
958     return;
959   }
960
961   if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
962     return;
963
964   if (CheckEngineSnapshotSingle())
965   {
966     TapeStartGamePlaying();
967
968     LoadEngineSnapshotSingle();
969
970     DrawCompleteVideoDisplay();
971
972     tape.playing = TRUE;
973     tape.pausing = TRUE;
974
975     TapeStopWarpForward();
976     TapeAppendRecording();
977
978     // restart step/move snapshots after quick loading tape
979     SaveEngineSnapshotToListInitial();
980
981     if (FrameCounter > 0)
982       return;
983   }
984
985   TapeStop();
986   TapeErase();
987
988   LoadTape(level_nr);
989
990   if (!TAPE_IS_EMPTY(tape))
991   {
992     TapeStartGamePlaying();
993     TapeStartWarpForward();
994
995     tape.quick_resume = TRUE;
996   }
997   else  /* this should not happen (basically checked above) */
998   {
999     int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
1000
1001     Request("No tape for this level!", REQ_CONFIRM | reopen_door);
1002   }
1003 }
1004
1005 void InsertSolutionTape()
1006 {
1007   if (!TAPE_IS_EMPTY(tape))
1008     return;
1009
1010   LoadSolutionTape(level_nr);
1011
1012   if (TAPE_IS_EMPTY(tape))
1013     Request("No solution tape for this level!", REQ_CONFIRM);
1014
1015   DrawCompleteVideoDisplay();
1016 }
1017
1018
1019 /* ------------------------------------------------------------------------- *
1020  * tape autoplay functions
1021  * ------------------------------------------------------------------------- */
1022
1023 void AutoPlayTape()
1024 {
1025   static LevelDirTree *autoplay_leveldir = NULL;
1026   static boolean autoplay_initialized = FALSE;
1027   static int autoplay_level_nr = -1;
1028   static int num_levels_played = 0;
1029   static int num_levels_solved = 0;
1030   static int num_tape_missing = 0;
1031   static boolean level_failed[MAX_TAPES_PER_SET];
1032   int i;
1033
1034   if (autoplay_initialized)
1035   {
1036     /* just finished auto-playing tape */
1037     printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
1038
1039     num_levels_played++;
1040
1041     if (tape.auto_play_level_solved)
1042       num_levels_solved++;
1043     else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1044       level_failed[level_nr] = TRUE;
1045   }
1046   else
1047   {
1048     DrawCompleteVideoDisplay();
1049
1050     audio.sound_enabled = FALSE;
1051     setup.engine_snapshot_mode = getStringCopy(STR_SNAPSHOT_MODE_OFF);
1052
1053     autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1054                                                   global.autoplay_leveldir);
1055
1056     if (autoplay_leveldir == NULL)
1057       Error(ERR_EXIT, "no such level identifier: '%s'",
1058             global.autoplay_leveldir);
1059
1060     leveldir_current = autoplay_leveldir;
1061
1062     if (autoplay_leveldir->first_level < 0)
1063       autoplay_leveldir->first_level = 0;
1064     if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1065       autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1066
1067     autoplay_level_nr = autoplay_leveldir->first_level;
1068
1069     printf_line("=", 79);
1070     printf("Automatically playing level tapes\n");
1071     printf_line("-", 79);
1072     printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1073     printf("Level series name:       '%s'\n", autoplay_leveldir->name);
1074     printf("Level series author:     '%s'\n", autoplay_leveldir->author);
1075     printf("Number of levels:        %d\n",   autoplay_leveldir->levels);
1076     printf_line("=", 79);
1077     printf("\n");
1078
1079     for (i = 0; i < MAX_TAPES_PER_SET; i++)
1080       level_failed[i] = FALSE;
1081
1082     autoplay_initialized = TRUE;
1083   }
1084
1085   while (autoplay_level_nr <= autoplay_leveldir->last_level)
1086   {
1087     level_nr = autoplay_level_nr++;
1088
1089     if (!global.autoplay_all && !global.autoplay_level[level_nr])
1090       continue;
1091
1092     TapeErase();
1093
1094     printf("Level %03d: ", level_nr);
1095
1096     LoadLevel(level_nr);
1097     if (level.no_valid_file)
1098     {
1099       printf("(no level)\n");
1100       continue;
1101     }
1102
1103 #if 0
1104     /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1105     printf("(only testing level)\n");
1106     continue;
1107 #endif
1108
1109     LoadSolutionTape(level_nr);
1110
1111     if (tape.no_valid_file)
1112     {
1113       num_tape_missing++;
1114
1115       printf("(no tape)\n");
1116
1117       continue;
1118     }
1119
1120     printf("playing tape ... ");
1121
1122     TapeStartGamePlaying();
1123
1124     if (global.autoplay_mode == AUTOPLAY_FFWD)
1125       tape.fast_forward = TRUE;
1126
1127     if (global.autoplay_mode != AUTOPLAY_PLAY)
1128       TapeStartWarpForward();
1129
1130     return;
1131   }
1132
1133   printf("\n");
1134   printf_line("=", 79);
1135   printf("Number of levels played: %d\n", num_levels_played);
1136   printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1137          (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1138   printf_line("-", 79);
1139   printf("Summary (for automatic parsing by scripts):\n");
1140   printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1141          autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1142          (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1143
1144   if (num_levels_played != num_levels_solved)
1145   {
1146     printf(", FAILED:");
1147     for (i = 0; i < MAX_TAPES_PER_SET; i++)
1148       if (level_failed[i])
1149         printf(" %03d", i);
1150   }
1151
1152   printf("\n");
1153   printf_line("=", 79);
1154
1155   CloseAllAndExit(0);
1156 }
1157
1158
1159 /* ---------- new tape button stuff ---------------------------------------- */
1160
1161 static struct
1162 {
1163   int graphic;
1164   struct XY *pos;
1165   int gadget_id;
1166   char *infotext;
1167 } tapebutton_info[NUM_TAPE_BUTTONS] =
1168 {
1169   {
1170     IMG_GFX_TAPE_BUTTON_EJECT,          &tape.button.eject,
1171     TAPE_CTRL_ID_EJECT,                 "eject tape"
1172   },
1173   {
1174     /* (same position as "eject" button) */
1175     IMG_GFX_TAPE_BUTTON_EXTRA,          &tape.button.eject,
1176     TAPE_CTRL_ID_EXTRA,                 "extra functions"
1177   },
1178   {
1179     IMG_GFX_TAPE_BUTTON_STOP,           &tape.button.stop,
1180     TAPE_CTRL_ID_STOP,                  "stop tape"
1181   },
1182   {
1183     IMG_GFX_TAPE_BUTTON_PAUSE,          &tape.button.pause,
1184     TAPE_CTRL_ID_PAUSE,                 "pause tape"
1185   },
1186   {
1187     IMG_GFX_TAPE_BUTTON_RECORD,         &tape.button.record,
1188     TAPE_CTRL_ID_RECORD,                "record tape"
1189   },
1190   {
1191     IMG_GFX_TAPE_BUTTON_PLAY,           &tape.button.play,
1192     TAPE_CTRL_ID_PLAY,                  "play tape"
1193   }
1194 };
1195
1196 void CreateTapeButtons()
1197 {
1198   int i;
1199
1200   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1201   {
1202     struct GraphicInfo *gfx = &graphic_info[tapebutton_info[i].graphic];
1203     struct XY *pos = tapebutton_info[i].pos;
1204     struct GadgetInfo *gi;
1205     int gd_x = gfx->src_x;
1206     int gd_y = gfx->src_y;
1207     int gd_xp = gfx->src_x + gfx->pressed_xoffset;
1208     int gd_yp = gfx->src_y + gfx->pressed_yoffset;
1209     int id = i;
1210
1211     gi = CreateGadget(GDI_CUSTOM_ID, id,
1212                       GDI_INFO_TEXT, tapebutton_info[i].infotext,
1213                       GDI_X, VX + pos->x,
1214                       GDI_Y, VY + pos->y,
1215                       GDI_WIDTH, gfx->width,
1216                       GDI_HEIGHT, gfx->height,
1217                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1218                       GDI_STATE, GD_BUTTON_UNPRESSED,
1219                       GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
1220                       GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
1221                       GDI_DIRECT_DRAW, FALSE,
1222                       GDI_EVENT_MASK, GD_EVENT_RELEASED,
1223                       GDI_CALLBACK_ACTION, HandleTapeButtons,
1224                       GDI_END);
1225
1226     if (gi == NULL)
1227       Error(ERR_EXIT, "cannot create gadget");
1228
1229     tape_gadget[id] = gi;
1230   }
1231 }
1232
1233 void FreeTapeButtons()
1234 {
1235   int i;
1236
1237   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1238     FreeGadget(tape_gadget[i]);
1239 }
1240
1241 void MapTapeEjectButton()
1242 {
1243   UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1244   MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1245 }
1246
1247 void MapTapeWarpButton()
1248 {
1249   UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1250   MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1251 }
1252
1253 void MapTapeButtons()
1254 {
1255   int i;
1256
1257   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1258     if (i != TAPE_CTRL_ID_EXTRA)
1259       MapGadget(tape_gadget[i]);
1260
1261   if (tape.recording || tape.playing)
1262     MapTapeWarpButton();
1263
1264   if (tape.show_game_buttons)
1265     MapGameButtons();
1266 }
1267
1268 void UnmapTapeButtons()
1269 {
1270   int i;
1271
1272   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1273     UnmapGadget(tape_gadget[i]);
1274
1275   if (tape.show_game_buttons)
1276     UnmapGameButtons();
1277 }
1278
1279 static void HandleTapeButtonsExt(int id)
1280 {
1281   if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1282     return;
1283
1284   switch (id)
1285   {
1286     case TAPE_CTRL_ID_EJECT:
1287       TapeStop();
1288
1289       if (TAPE_IS_EMPTY(tape))
1290       {
1291         LoadTape(level_nr);
1292
1293         if (TAPE_IS_EMPTY(tape))
1294           Request("No tape for this level!", REQ_CONFIRM);
1295       }
1296       else
1297       {
1298         if (tape.changed)
1299           SaveTapeChecked(tape.level_nr);
1300
1301         TapeErase();
1302       }
1303
1304       DrawCompleteVideoDisplay();
1305       break;
1306
1307     case TAPE_CTRL_ID_EXTRA:
1308       if (tape.playing)
1309       {
1310         if (!tape.warp_forward)                 /* PLAY -> WARP FORWARD PLAY */
1311         {
1312           TapeStartWarpForward();
1313         }
1314         else if (tape.pausing)                  /* PAUSE -> WARP FORWARD PLAY */
1315         {
1316           TapeTogglePause(TAPE_TOGGLE_MANUAL);
1317         }
1318         else                                    /* WARP FORWARD PLAY -> PLAY */
1319         {
1320           TapeStopWarpForward();
1321         }
1322       }
1323       else if (tape.recording)
1324         TapeSingleStep();
1325
1326       break;
1327
1328     case TAPE_CTRL_ID_STOP:
1329       TapeStop();
1330       break;
1331
1332     case TAPE_CTRL_ID_PAUSE:
1333       TapeTogglePause(TAPE_TOGGLE_MANUAL);
1334       break;
1335
1336     case TAPE_CTRL_ID_RECORD:
1337       if (TAPE_IS_STOPPED(tape))
1338         TapeStartGameRecording();
1339       else if (tape.pausing)
1340       {
1341         if (tape.playing)                       /* PLAY -> PAUSE -> RECORD */
1342           TapeAppendRecording();
1343         else
1344           TapeTogglePause(TAPE_TOGGLE_MANUAL);
1345       }
1346       break;
1347
1348     case TAPE_CTRL_ID_PLAY:
1349       if (tape.recording && tape.pausing)       /* PAUSE -> RECORD */
1350       {
1351         // ("TAPE_IS_EMPTY(tape)" is TRUE here -- probably fix this)
1352
1353         TapeTogglePause(TAPE_TOGGLE_MANUAL);
1354       }
1355
1356       if (TAPE_IS_EMPTY(tape))
1357         break;
1358
1359       if (TAPE_IS_STOPPED(tape))
1360       {
1361         TapeStartGamePlaying();
1362       }
1363       else if (tape.playing)
1364       {
1365         if (tape.pausing)                       /* PAUSE -> PLAY */
1366         {
1367           // continue playing in normal mode
1368           tape.fast_forward = FALSE;
1369           tape.warp_forward = FALSE;
1370           tape.pause_before_end = FALSE;
1371           tape.deactivate_display = FALSE;
1372
1373           TapeTogglePause(TAPE_TOGGLE_MANUAL);
1374         }
1375         else if (tape.warp_forward &&
1376                  !tape.fast_forward)            /* WARP FORWARD PLAY -> PLAY */
1377         {
1378           TapeStopWarpForward();
1379         }
1380         else if (!tape.fast_forward)            /* PLAY -> FAST FORWARD PLAY */
1381         {
1382           tape.fast_forward = TRUE;
1383
1384           DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
1385         }
1386         else if (!tape.pause_before_end)        /* FFWD PLAY -> AUTO PAUSE */
1387         {
1388           tape.pause_before_end = TRUE;
1389
1390           DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_ON, 0);
1391
1392           if (tape.warp_forward)
1393             DrawVideoDisplaySymbol(VIDEO_STATE_WARP2_ON);
1394         }
1395         else                                    /* AUTO PAUSE -> NORMAL PLAY */
1396         {
1397           if (tape.warp_forward)
1398             TapeStopWarpForward();
1399
1400           tape.fast_forward = FALSE;
1401           tape.pause_before_end = FALSE;
1402
1403           DrawVideoDisplay(VIDEO_STATE_PBEND_OFF | VIDEO_STATE_PLAY_ON, 0);
1404         }
1405       }
1406       break;
1407
1408     default:
1409       break;
1410   }
1411 }
1412
1413 static void HandleTapeButtons(struct GadgetInfo *gi)
1414 {
1415   HandleTapeButtonsExt(gi->custom_id);
1416 }
1417
1418 void HandleTapeButtonKeys(Key key)
1419 {
1420   boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
1421   boolean extra_button_is_active = !eject_button_is_active;
1422
1423   if (key == setup.shortcut.tape_eject && eject_button_is_active)
1424     HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
1425   else if (key == setup.shortcut.tape_extra && extra_button_is_active)
1426     HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
1427   else if (key == setup.shortcut.tape_stop)
1428     HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
1429   else if (key == setup.shortcut.tape_pause)
1430     HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
1431   else if (key == setup.shortcut.tape_record)
1432     HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
1433   else if (key == setup.shortcut.tape_play)
1434     HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);
1435 }