added missing recording modes to tape recorder display state function
[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 DrawVideoDisplayCurrentState()
360 {
361   int state = 0;
362
363   DrawVideoDisplay(VIDEO_STATE_OFF, 0);
364
365   if (tape.pausing)
366     state |= VIDEO_STATE_PAUSE_ON;
367
368   if (tape.recording)
369   {
370     state |= VIDEO_STATE_REC_ON;
371
372     if (tape.single_step)
373       state |= VIDEO_STATE_1STEP_ON;
374   }
375   else if (tape.playing)
376   {
377     state |= VIDEO_STATE_PLAY_ON;
378
379     if (tape.deactivate_display)
380       state |= VIDEO_STATE_WARP2_ON;
381     else if (tape.warp_forward)
382       state |= VIDEO_STATE_WARP_ON;
383     else if (tape.fast_forward)
384       state |= VIDEO_STATE_FFWD_ON;
385
386     if (tape.pause_before_end)
387       state |= VIDEO_STATE_PBEND_ON;
388   }
389
390   // draw labels and symbols separately to prevent labels overlapping symbols
391   DrawVideoDisplayLabel(state);
392   DrawVideoDisplaySymbol(state);
393 }
394
395 void DrawCompleteVideoDisplay()
396 {
397   struct GraphicInfo *g_tape = &graphic_info[IMG_BACKGROUND_TAPE];
398
399   /* draw tape background */
400   BlitBitmap(g_tape->bitmap, drawto, g_tape->src_x, g_tape->src_y,
401              gfx.vxsize, gfx.vysize, gfx.vx, gfx.vy);
402
403   /* draw tape buttons (forced) */
404   UnmapTapeButtons();
405   MapTapeButtons();
406
407   DrawVideoDisplay(VIDEO_ALL_OFF, 0);
408
409   if (tape.recording)
410   {
411     DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
412     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
413     DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
414     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
415
416     if (tape.pausing)
417       DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
418   }
419   else if (tape.playing)
420   {
421     DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
422     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
423     DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
424     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
425
426     if (tape.pausing)
427       DrawVideoDisplay(VIDEO_STATE_PAUSE_ON, 0);
428   }
429   else if (tape.date && tape.length)
430   {
431     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
432     DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
433     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
434   }
435
436   BlitBitmap(drawto, bitmap_db_door_2, gfx.vx, gfx.vy, gfx.vxsize, gfx.vysize,
437              0, 0);
438 }
439
440 void TapeDeactivateDisplayOn()
441 {
442   SetDrawDeactivationMask(REDRAW_FIELD);
443   audio.sound_deactivated = TRUE;
444 }
445
446 void TapeDeactivateDisplayOff(boolean redraw_display)
447 {
448   SetDrawDeactivationMask(REDRAW_NONE);
449   audio.sound_deactivated = FALSE;
450
451   if (redraw_display)
452   {
453     RedrawPlayfield();
454     DrawGameDoorValues();
455   }
456 }
457
458
459 /* ========================================================================= */
460 /* tape control functions                                                    */
461 /* ========================================================================= */
462
463 void TapeSetDateFromEpochSeconds(time_t epoch_seconds)
464 {
465   struct tm *lt = localtime(&epoch_seconds);
466
467   tape.date = 10000 * (lt->tm_year % 100) + 100 * lt->tm_mon + lt->tm_mday;
468 }
469
470 void TapeSetDateFromNow()
471 {
472   TapeSetDateFromEpochSeconds(time(NULL));
473 }
474
475 void TapeErase()
476 {
477   int i;
478
479   tape.counter = 0;
480   tape.length = 0;
481   tape.length_frames = 0;
482   tape.length_seconds = 0;
483
484   if (leveldir_current)
485     setString(&tape.level_identifier, leveldir_current->identifier);
486
487   tape.level_nr = level_nr;
488   tape.pos[tape.counter].delay = 0;
489   tape.changed = TRUE;
490
491   tape.random_seed = InitRND(level.random_seed);
492
493   tape.file_version = FILE_VERSION_ACTUAL;
494   tape.game_version = GAME_VERSION_ACTUAL;
495   tape.engine_version = level.game_version;
496
497   TapeSetDateFromNow();
498
499   for (i = 0; i < MAX_PLAYERS; i++)
500     tape.player_participates[i] = FALSE;
501
502   tape.centered_player_nr_next = -1;
503   tape.set_centered_player = FALSE;
504 }
505
506 static void TapeRewind()
507 {
508   tape.counter = 0;
509   tape.delay_played = 0;
510   tape.pause_before_end = FALSE;
511   tape.recording = FALSE;
512   tape.playing = FALSE;
513   tape.fast_forward = FALSE;
514   tape.warp_forward = FALSE;
515   tape.deactivate_display = FALSE;
516   tape.auto_play = (global.autoplay_leveldir != NULL);
517   tape.auto_play_level_solved = FALSE;
518   tape.quick_resume = FALSE;
519   tape.single_step = FALSE;
520
521   tape.centered_player_nr_next = -1;
522   tape.set_centered_player = FALSE;
523
524   InitRND(tape.random_seed);
525 }
526
527 static void TapeSetRandomSeed(int random_seed)
528 {
529   tape.random_seed = InitRND(random_seed);
530 }
531
532 void TapeStartRecording(int random_seed)
533 {
534   if (!TAPE_IS_STOPPED(tape))
535     TapeStop();
536
537   TapeErase();
538   TapeRewind();
539   TapeSetRandomSeed(random_seed);
540
541   tape.recording = TRUE;
542
543   DrawVideoDisplay(VIDEO_STATE_REC_ON, 0);
544   DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
545   DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
546   DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
547
548   MapTapeWarpButton();
549
550   SetDrawDeactivationMask(REDRAW_NONE);
551   audio.sound_deactivated = FALSE;
552 }
553
554 static void TapeStartGameRecording()
555 {
556   TapeStartRecording(level.random_seed);
557
558 #if defined(NETWORK_AVALIABLE)
559   if (options.network)
560   {
561     SendToServer_StartPlaying();
562
563     return;
564   }
565 #endif
566
567   InitGame();
568 }
569
570 static void TapeAppendRecording()
571 {
572   if (!tape.playing || !tape.pausing)
573     return;
574
575   // stop playing
576   tape.playing = FALSE;
577   tape.fast_forward = FALSE;
578   tape.warp_forward = FALSE;
579   tape.pause_before_end = FALSE;
580   tape.deactivate_display = FALSE;
581
582   // start recording
583   tape.recording = TRUE;
584   tape.changed = TRUE;
585
586   // set current delay (for last played move)
587   tape.pos[tape.counter].delay = tape.delay_played;
588
589   // set current date
590   TapeSetDateFromNow();
591
592   DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
593   DrawVideoDisplay(VIDEO_STATE_PLAY_OFF | VIDEO_STATE_REC_ON, 0);
594
595   UpdateAndDisplayGameControlValues();
596 }
597
598 void TapeHaltRecording()
599 {
600   if (!tape.recording)
601     return;
602
603   tape.counter++;
604   tape.pos[tape.counter].delay = 0;
605
606   tape.length = tape.counter;
607   tape.length_frames = GetTapeLengthFrames();
608   tape.length_seconds = GetTapeLengthSeconds();
609 }
610
611 void TapeStopRecording()
612 {
613   TapeHaltRecording();
614
615   tape.recording = FALSE;
616   tape.pausing = FALSE;
617
618   DrawVideoDisplay(VIDEO_STATE_REC_OFF, 0);
619   MapTapeEjectButton();
620 }
621
622 void TapeRecordAction(byte action_raw[MAX_PLAYERS])
623 {
624   byte action[MAX_PLAYERS];
625   int i;
626
627   if (!tape.recording)          /* (record action even when tape is paused) */
628     return;
629
630   if (tape.counter >= MAX_TAPE_LEN - 1)
631   {
632     TapeStopRecording();
633     return;
634   }
635
636   for (i = 0; i < MAX_PLAYERS; i++)
637     action[i] = action_raw[i];
638
639   if (tape.set_centered_player)
640   {
641     for (i = 0; i < MAX_PLAYERS; i++)
642       if (tape.centered_player_nr_next == i ||
643           tape.centered_player_nr_next == -1)
644         action[i] |= KEY_SET_FOCUS;
645
646     tape.set_centered_player = FALSE;
647   }
648
649   if (tape.pos[tape.counter].delay > 0)         /* already stored action */
650   {
651     boolean changed_events = FALSE;
652
653     for (i = 0; i < MAX_PLAYERS; i++)
654       if (tape.pos[tape.counter].action[i] != action[i])
655         changed_events = TRUE;
656
657     if (changed_events || tape.pos[tape.counter].delay >= 255)
658     {
659       tape.counter++;
660       tape.pos[tape.counter].delay = 0;
661     }
662     else
663       tape.pos[tape.counter].delay++;
664   }
665
666   if (tape.pos[tape.counter].delay == 0)        /* store new action */
667   {
668     for (i = 0; i < MAX_PLAYERS; i++)
669       tape.pos[tape.counter].action[i] = action[i];
670
671     tape.pos[tape.counter].delay++;
672   }
673 }
674
675 void TapeTogglePause(boolean toggle_manual)
676 {
677   tape.pausing = !tape.pausing;
678
679   if (tape.single_step && toggle_manual)
680     tape.single_step = FALSE;
681
682   DrawVideoDisplayCurrentState();
683
684   if (tape.deactivate_display)
685   {
686     if (tape.pausing)
687       TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
688     else
689       TapeDeactivateDisplayOn();
690   }
691
692   if (tape.quick_resume)
693   {
694     tape.quick_resume = FALSE;
695
696     TapeStopWarpForward();
697     TapeAppendRecording();
698
699     if (!CheckEngineSnapshotSingle())
700       SaveEngineSnapshotSingle();
701
702     // restart step/move snapshots after quick loading tape
703     SaveEngineSnapshotToListInitial();
704   }
705
706   if (setup.show_snapshot_buttons &&
707       game_status == GAME_MODE_PLAYING &&
708       CheckEngineSnapshotList())
709   {
710     if (tape.pausing)
711       MapUndoRedoButtons();
712     else if (!tape.single_step)
713       UnmapUndoRedoButtons();
714   }
715 }
716
717 void TapeStartPlaying()
718 {
719   if (TAPE_IS_EMPTY(tape))
720     return;
721
722   if (!TAPE_IS_STOPPED(tape))
723     TapeStop();
724
725   TapeRewind();
726
727   tape.playing = TRUE;
728
729   DrawVideoDisplay(VIDEO_STATE_PLAY_ON, 0);
730   DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
731   DrawVideoDisplay(VIDEO_STATE_TIME_ON, 0);
732   DrawVideoDisplay(VIDEO_STATE_FRAME_ON, 0);
733
734   MapTapeWarpButton();
735
736   SetDrawDeactivationMask(REDRAW_NONE);
737   audio.sound_deactivated = FALSE;
738 }
739
740 static void TapeStartGamePlaying()
741 {
742   TapeStartPlaying();
743
744   InitGame();
745 }
746
747 void TapeStopPlaying()
748 {
749   tape.playing = FALSE;
750   tape.pausing = FALSE;
751
752   if (tape.warp_forward)
753     TapeStopWarpForward();
754
755   DrawVideoDisplay(VIDEO_STATE_PLAY_OFF, 0);
756   MapTapeEjectButton();
757 }
758
759 byte *TapePlayAction()
760 {
761   int update_delay = FRAMES_PER_SECOND / 2;
762   boolean update_video_display = (FrameCounter % update_delay == 0);
763   boolean update_draw_label_on = ((FrameCounter / update_delay) % 2 == 1);
764   static byte action[MAX_PLAYERS];
765   int i;
766
767   if (!tape.playing || tape.pausing)
768     return NULL;
769
770   if (tape.pause_before_end)  // stop some seconds before end of tape
771   {
772     if (TapeTime > tape.length_seconds - TAPE_PAUSE_SECONDS_BEFORE_DEATH)
773     {
774       TapeStopWarpForward();
775       TapeTogglePause(TAPE_TOGGLE_MANUAL);
776
777       return NULL;
778     }
779   }
780
781   if (tape.counter >= tape.length)      /* end of tape reached */
782   {
783     if (tape.warp_forward && !tape.auto_play)
784     {
785       TapeStopWarpForward();
786       TapeTogglePause(TAPE_TOGGLE_MANUAL);
787     }
788     else
789     {
790       TapeStop();
791     }
792
793     return NULL;
794   }
795
796   if (update_video_display && !tape.deactivate_display)
797   {
798     int state = 0;
799
800     if (tape.warp_forward)
801       state |= VIDEO_STATE_WARP(update_draw_label_on);
802     else if (tape.fast_forward)
803       state |= VIDEO_STATE_FFWD(update_draw_label_on);
804
805     if (tape.pause_before_end)
806       state |= VIDEO_STATE_PBEND(update_draw_label_on);
807
808     // draw labels and symbols separately to prevent labels overlapping symbols
809     DrawVideoDisplayLabel(state);
810     DrawVideoDisplaySymbol(state);
811   }
812
813   for (i = 0; i < MAX_PLAYERS; i++)
814     action[i] = tape.pos[tape.counter].action[i];
815
816 #if DEBUG_TAPE_WHEN_PLAYING
817   printf("%05d", FrameCounter);
818   for (i = 0; i < MAX_PLAYERS; i++)
819     printf("   %08x", action[i]);
820   printf("\n");
821 #endif
822
823   tape.set_centered_player = FALSE;
824   tape.centered_player_nr_next = -999;
825
826   for (i = 0; i < MAX_PLAYERS; i++)
827   {
828     if (action[i] & KEY_SET_FOCUS)
829     {
830       tape.set_centered_player = TRUE;
831       tape.centered_player_nr_next =
832         (tape.centered_player_nr_next == -999 ? i : -1);
833     }
834
835     action[i] &= ~KEY_SET_FOCUS;
836   }
837
838   tape.delay_played++;
839   if (tape.delay_played >= tape.pos[tape.counter].delay)
840   {
841     tape.counter++;
842     tape.delay_played = 0;
843   }
844
845   return action;
846 }
847
848 void TapeStop()
849 {
850   TapeStopRecording();
851   TapeStopPlaying();
852
853   DrawVideoDisplay(VIDEO_STATE_OFF, 0);
854
855   if (tape.date && tape.length)
856   {
857     DrawVideoDisplay(VIDEO_STATE_DATE_ON, tape.date);
858     DrawVideoDisplay(VIDEO_STATE_TIME_ON, tape.length_seconds);
859     DrawVideoDisplay(VIDEO_STATE_FRAME_ON, tape.length_frames);
860   }
861 }
862
863 unsigned int GetTapeLengthFrames()
864 {
865   unsigned int tape_length_frames = 0;
866   int i;
867
868   if (TAPE_IS_EMPTY(tape))
869     return(0);
870
871   for (i = 0; i < tape.length; i++)
872     tape_length_frames += tape.pos[i].delay;
873
874   return tape_length_frames;
875 }
876
877 unsigned int GetTapeLengthSeconds()
878 {
879   return (GetTapeLengthFrames() * GAME_FRAME_DELAY / 1000);
880 }
881
882 static void TapeStartWarpForward()
883 {
884   tape.fast_forward = TRUE;
885   tape.warp_forward = TRUE;
886   tape.deactivate_display = TRUE;
887
888   tape.pausing = FALSE;
889
890   TapeDeactivateDisplayOn();
891
892   DrawVideoDisplayCurrentState();
893 }
894
895 static void TapeStopWarpForward()
896 {
897   tape.fast_forward = FALSE;
898   tape.warp_forward = FALSE;
899   tape.deactivate_display = FALSE;
900
901   tape.pause_before_end = FALSE;
902
903   TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
904
905   DrawVideoDisplayCurrentState();
906 }
907
908 static void TapeSingleStep()
909 {
910   if (options.network)
911     return;
912
913   if (!tape.pausing)
914     TapeTogglePause(TAPE_TOGGLE_MANUAL);
915
916   tape.single_step = !tape.single_step;
917
918   DrawVideoDisplay(VIDEO_STATE_1STEP(tape.single_step), 0);
919 }
920
921 void TapeQuickSave()
922 {
923   if (game_status == GAME_MODE_MAIN)
924   {
925     Request("No game that can be saved!", REQ_CONFIRM);
926
927     return;
928   }
929
930   if (game_status != GAME_MODE_PLAYING)
931     return;
932
933   if (tape.recording)
934     TapeHaltRecording();        /* prepare tape for saving on-the-fly */
935
936   if (TAPE_IS_EMPTY(tape))
937   {
938     Request("No tape that can be saved!", REQ_CONFIRM);
939
940     return;
941   }
942
943   if (SaveTapeChecked(tape.level_nr))
944     SaveEngineSnapshotSingle();
945 }
946
947 void TapeQuickLoad()
948 {
949   char *filename = getTapeFilename(level_nr);
950
951   if (!fileExists(filename))
952   {
953     Request("No tape for this level!", REQ_CONFIRM);
954
955     return;
956   }
957
958   if (tape.recording && !Request("Stop recording and load tape?",
959                                  REQ_ASK | REQ_STAY_CLOSED))
960   {
961     OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
962
963     return;
964   }
965
966   if (game_status != GAME_MODE_PLAYING && game_status != GAME_MODE_MAIN)
967     return;
968
969   if (CheckEngineSnapshotSingle())
970   {
971     TapeStartGamePlaying();
972
973     LoadEngineSnapshotSingle();
974
975     DrawCompleteVideoDisplay();
976
977     tape.playing = TRUE;
978     tape.pausing = TRUE;
979
980     TapeStopWarpForward();
981     TapeAppendRecording();
982
983     // restart step/move snapshots after quick loading tape
984     SaveEngineSnapshotToListInitial();
985
986     if (FrameCounter > 0)
987       return;
988   }
989
990   TapeStop();
991   TapeErase();
992
993   LoadTape(level_nr);
994
995   if (!TAPE_IS_EMPTY(tape))
996   {
997     TapeStartGamePlaying();
998     TapeStartWarpForward();
999
1000     tape.quick_resume = TRUE;
1001   }
1002   else  /* this should not happen (basically checked above) */
1003   {
1004     int reopen_door = (game_status == GAME_MODE_PLAYING ? REQ_REOPEN : 0);
1005
1006     Request("No tape for this level!", REQ_CONFIRM | reopen_door);
1007   }
1008 }
1009
1010 void InsertSolutionTape()
1011 {
1012   if (!TAPE_IS_EMPTY(tape))
1013     return;
1014
1015   LoadSolutionTape(level_nr);
1016
1017   if (TAPE_IS_EMPTY(tape))
1018     Request("No solution tape for this level!", REQ_CONFIRM);
1019
1020   DrawCompleteVideoDisplay();
1021 }
1022
1023
1024 /* ------------------------------------------------------------------------- *
1025  * tape autoplay functions
1026  * ------------------------------------------------------------------------- */
1027
1028 void AutoPlayTape()
1029 {
1030   static LevelDirTree *autoplay_leveldir = NULL;
1031   static boolean autoplay_initialized = FALSE;
1032   static int autoplay_level_nr = -1;
1033   static int num_levels_played = 0;
1034   static int num_levels_solved = 0;
1035   static int num_tape_missing = 0;
1036   static boolean level_failed[MAX_TAPES_PER_SET];
1037   int i;
1038
1039   if (autoplay_initialized)
1040   {
1041     /* just finished auto-playing tape */
1042     printf("%s.\n", tape.auto_play_level_solved ? "solved" : "NOT SOLVED");
1043
1044     num_levels_played++;
1045
1046     if (tape.auto_play_level_solved)
1047       num_levels_solved++;
1048     else if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
1049       level_failed[level_nr] = TRUE;
1050   }
1051   else
1052   {
1053     DrawCompleteVideoDisplay();
1054
1055     audio.sound_enabled = FALSE;
1056     setup.engine_snapshot_mode = getStringCopy(STR_SNAPSHOT_MODE_OFF);
1057
1058     autoplay_leveldir = getTreeInfoFromIdentifier(leveldir_first,
1059                                                   global.autoplay_leveldir);
1060
1061     if (autoplay_leveldir == NULL)
1062       Error(ERR_EXIT, "no such level identifier: '%s'",
1063             global.autoplay_leveldir);
1064
1065     leveldir_current = autoplay_leveldir;
1066
1067     if (autoplay_leveldir->first_level < 0)
1068       autoplay_leveldir->first_level = 0;
1069     if (autoplay_leveldir->last_level >= MAX_TAPES_PER_SET)
1070       autoplay_leveldir->last_level = MAX_TAPES_PER_SET - 1;
1071
1072     autoplay_level_nr = autoplay_leveldir->first_level;
1073
1074     printf_line("=", 79);
1075     printf("Automatically playing level tapes\n");
1076     printf_line("-", 79);
1077     printf("Level series identifier: '%s'\n", autoplay_leveldir->identifier);
1078     printf("Level series name:       '%s'\n", autoplay_leveldir->name);
1079     printf("Level series author:     '%s'\n", autoplay_leveldir->author);
1080     printf("Number of levels:        %d\n",   autoplay_leveldir->levels);
1081     printf_line("=", 79);
1082     printf("\n");
1083
1084     for (i = 0; i < MAX_TAPES_PER_SET; i++)
1085       level_failed[i] = FALSE;
1086
1087     autoplay_initialized = TRUE;
1088   }
1089
1090   while (autoplay_level_nr <= autoplay_leveldir->last_level)
1091   {
1092     level_nr = autoplay_level_nr++;
1093
1094     if (!global.autoplay_all && !global.autoplay_level[level_nr])
1095       continue;
1096
1097     TapeErase();
1098
1099     printf("Level %03d: ", level_nr);
1100
1101     LoadLevel(level_nr);
1102     if (level.no_valid_file)
1103     {
1104       printf("(no level)\n");
1105       continue;
1106     }
1107
1108 #if 0
1109     /* ACTIVATE THIS FOR LOADING/TESTING OF LEVELS ONLY */
1110     printf("(only testing level)\n");
1111     continue;
1112 #endif
1113
1114     LoadSolutionTape(level_nr);
1115
1116     if (tape.no_valid_file)
1117     {
1118       num_tape_missing++;
1119
1120       printf("(no tape)\n");
1121
1122       continue;
1123     }
1124
1125     printf("playing tape ... ");
1126
1127     TapeStartGamePlaying();
1128
1129     if (global.autoplay_mode == AUTOPLAY_FFWD)
1130       tape.fast_forward = TRUE;
1131
1132     if (global.autoplay_mode != AUTOPLAY_PLAY)
1133       TapeStartWarpForward();
1134
1135     return;
1136   }
1137
1138   printf("\n");
1139   printf_line("=", 79);
1140   printf("Number of levels played: %d\n", num_levels_played);
1141   printf("Number of levels solved: %d (%d%%)\n", num_levels_solved,
1142          (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1143   printf_line("-", 79);
1144   printf("Summary (for automatic parsing by scripts):\n");
1145   printf("LEVELDIR '%s', SOLVED %d/%d (%d%%)",
1146          autoplay_leveldir->identifier, num_levels_solved, num_levels_played,
1147          (num_levels_played ? num_levels_solved * 100 / num_levels_played :0));
1148
1149   if (num_levels_played != num_levels_solved)
1150   {
1151     printf(", FAILED:");
1152     for (i = 0; i < MAX_TAPES_PER_SET; i++)
1153       if (level_failed[i])
1154         printf(" %03d", i);
1155   }
1156
1157   printf("\n");
1158   printf_line("=", 79);
1159
1160   CloseAllAndExit(0);
1161 }
1162
1163
1164 /* ---------- new tape button stuff ---------------------------------------- */
1165
1166 static struct
1167 {
1168   int graphic;
1169   struct XY *pos;
1170   int gadget_id;
1171   char *infotext;
1172 } tapebutton_info[NUM_TAPE_BUTTONS] =
1173 {
1174   {
1175     IMG_GFX_TAPE_BUTTON_EJECT,          &tape.button.eject,
1176     TAPE_CTRL_ID_EJECT,                 "eject tape"
1177   },
1178   {
1179     /* (same position as "eject" button) */
1180     IMG_GFX_TAPE_BUTTON_EXTRA,          &tape.button.eject,
1181     TAPE_CTRL_ID_EXTRA,                 "extra functions"
1182   },
1183   {
1184     IMG_GFX_TAPE_BUTTON_STOP,           &tape.button.stop,
1185     TAPE_CTRL_ID_STOP,                  "stop tape"
1186   },
1187   {
1188     IMG_GFX_TAPE_BUTTON_PAUSE,          &tape.button.pause,
1189     TAPE_CTRL_ID_PAUSE,                 "pause tape"
1190   },
1191   {
1192     IMG_GFX_TAPE_BUTTON_RECORD,         &tape.button.record,
1193     TAPE_CTRL_ID_RECORD,                "record tape"
1194   },
1195   {
1196     IMG_GFX_TAPE_BUTTON_PLAY,           &tape.button.play,
1197     TAPE_CTRL_ID_PLAY,                  "play tape"
1198   }
1199 };
1200
1201 void CreateTapeButtons()
1202 {
1203   int i;
1204
1205   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1206   {
1207     struct GraphicInfo *gfx = &graphic_info[tapebutton_info[i].graphic];
1208     struct XY *pos = tapebutton_info[i].pos;
1209     struct GadgetInfo *gi;
1210     int gd_x = gfx->src_x;
1211     int gd_y = gfx->src_y;
1212     int gd_xp = gfx->src_x + gfx->pressed_xoffset;
1213     int gd_yp = gfx->src_y + gfx->pressed_yoffset;
1214     int id = i;
1215
1216     gi = CreateGadget(GDI_CUSTOM_ID, id,
1217                       GDI_INFO_TEXT, tapebutton_info[i].infotext,
1218                       GDI_X, VX + pos->x,
1219                       GDI_Y, VY + pos->y,
1220                       GDI_WIDTH, gfx->width,
1221                       GDI_HEIGHT, gfx->height,
1222                       GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
1223                       GDI_STATE, GD_BUTTON_UNPRESSED,
1224                       GDI_DESIGN_UNPRESSED, gfx->bitmap, gd_x, gd_y,
1225                       GDI_DESIGN_PRESSED, gfx->bitmap, gd_xp, gd_yp,
1226                       GDI_DIRECT_DRAW, FALSE,
1227                       GDI_EVENT_MASK, GD_EVENT_RELEASED,
1228                       GDI_CALLBACK_ACTION, HandleTapeButtons,
1229                       GDI_END);
1230
1231     if (gi == NULL)
1232       Error(ERR_EXIT, "cannot create gadget");
1233
1234     tape_gadget[id] = gi;
1235   }
1236 }
1237
1238 void FreeTapeButtons()
1239 {
1240   int i;
1241
1242   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1243     FreeGadget(tape_gadget[i]);
1244 }
1245
1246 void MapTapeEjectButton()
1247 {
1248   UnmapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1249   MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1250 }
1251
1252 void MapTapeWarpButton()
1253 {
1254   UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
1255   MapGadget(tape_gadget[TAPE_CTRL_ID_EXTRA]);
1256 }
1257
1258 void MapTapeButtons()
1259 {
1260   int i;
1261
1262   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1263     if (i != TAPE_CTRL_ID_EXTRA)
1264       MapGadget(tape_gadget[i]);
1265
1266   if (tape.recording || tape.playing)
1267     MapTapeWarpButton();
1268
1269   if (tape.show_game_buttons)
1270     MapGameButtons();
1271 }
1272
1273 void UnmapTapeButtons()
1274 {
1275   int i;
1276
1277   for (i = 0; i < NUM_TAPE_BUTTONS; i++)
1278     UnmapGadget(tape_gadget[i]);
1279
1280   if (tape.show_game_buttons)
1281     UnmapGameButtons();
1282 }
1283
1284 static void HandleTapeButtonsExt(int id)
1285 {
1286   if (game_status != GAME_MODE_MAIN && game_status != GAME_MODE_PLAYING)
1287     return;
1288
1289   switch (id)
1290   {
1291     case TAPE_CTRL_ID_EJECT:
1292       TapeStop();
1293
1294       if (TAPE_IS_EMPTY(tape))
1295       {
1296         LoadTape(level_nr);
1297
1298         if (TAPE_IS_EMPTY(tape))
1299           Request("No tape for this level!", REQ_CONFIRM);
1300       }
1301       else
1302       {
1303         if (tape.changed)
1304           SaveTapeChecked(tape.level_nr);
1305
1306         TapeErase();
1307       }
1308
1309       DrawCompleteVideoDisplay();
1310       break;
1311
1312     case TAPE_CTRL_ID_EXTRA:
1313       if (tape.playing)
1314       {
1315         tape.pause_before_end = !tape.pause_before_end;
1316
1317         DrawVideoDisplayCurrentState();
1318       }
1319       else if (tape.recording)
1320       {
1321         TapeSingleStep();
1322       }
1323
1324       break;
1325
1326     case TAPE_CTRL_ID_STOP:
1327       TapeStop();
1328
1329       break;
1330
1331     case TAPE_CTRL_ID_PAUSE:
1332       TapeTogglePause(TAPE_TOGGLE_MANUAL);
1333
1334       break;
1335
1336     case TAPE_CTRL_ID_RECORD:
1337       if (TAPE_IS_STOPPED(tape))
1338       {
1339         TapeStartGameRecording();
1340       }
1341       else if (tape.pausing)
1342       {
1343         if (tape.playing)                       /* PLAY -> PAUSE -> RECORD */
1344           TapeAppendRecording();
1345         else
1346           TapeTogglePause(TAPE_TOGGLE_MANUAL);
1347       }
1348
1349       break;
1350
1351     case TAPE_CTRL_ID_PLAY:
1352       if (tape.recording && tape.pausing)       /* PAUSE -> RECORD */
1353       {
1354         // ("TAPE_IS_EMPTY(tape)" is TRUE here -- probably fix this)
1355
1356         TapeTogglePause(TAPE_TOGGLE_MANUAL);
1357       }
1358
1359       if (TAPE_IS_EMPTY(tape))
1360         break;
1361
1362       if (TAPE_IS_STOPPED(tape))
1363       {
1364         TapeStartGamePlaying();
1365       }
1366       else if (tape.playing)
1367       {
1368         if (tape.pausing)                       /* PAUSE -> PLAY */
1369         {
1370           // continue playing in normal mode
1371           tape.fast_forward = FALSE;
1372           tape.warp_forward = FALSE;
1373           tape.deactivate_display = FALSE;
1374
1375           tape.pause_before_end = FALSE;
1376
1377           TapeTogglePause(TAPE_TOGGLE_MANUAL);
1378         }
1379         else if (!tape.fast_forward)            /* PLAY -> FFWD */
1380         {
1381           tape.fast_forward = TRUE;
1382         }
1383         else if (!tape.warp_forward)            /* FFWD -> WARP */
1384         {
1385           tape.warp_forward = TRUE;
1386         }
1387         else if (!tape.deactivate_display)      /* WARP -> WARP BLIND */
1388         {
1389           tape.deactivate_display = TRUE;
1390
1391           TapeDeactivateDisplayOn();
1392         }
1393         else                                    /* WARP BLIND -> PLAY */
1394         {
1395           tape.fast_forward = FALSE;
1396           tape.warp_forward = FALSE;
1397           tape.deactivate_display = FALSE;
1398
1399           TapeDeactivateDisplayOff(game_status == GAME_MODE_PLAYING);
1400         }
1401
1402         DrawVideoDisplayCurrentState();
1403       }
1404
1405       break;
1406
1407     default:
1408       break;
1409   }
1410 }
1411
1412 static void HandleTapeButtons(struct GadgetInfo *gi)
1413 {
1414   HandleTapeButtonsExt(gi->custom_id);
1415 }
1416
1417 void HandleTapeButtonKeys(Key key)
1418 {
1419   boolean eject_button_is_active = TAPE_IS_STOPPED(tape);
1420   boolean extra_button_is_active = !eject_button_is_active;
1421
1422   if (key == setup.shortcut.tape_eject && eject_button_is_active)
1423     HandleTapeButtonsExt(TAPE_CTRL_ID_EJECT);
1424   else if (key == setup.shortcut.tape_extra && extra_button_is_active)
1425     HandleTapeButtonsExt(TAPE_CTRL_ID_EXTRA);
1426   else if (key == setup.shortcut.tape_stop)
1427     HandleTapeButtonsExt(TAPE_CTRL_ID_STOP);
1428   else if (key == setup.shortcut.tape_pause)
1429     HandleTapeButtonsExt(TAPE_CTRL_ID_PAUSE);
1430   else if (key == setup.shortcut.tape_record)
1431     HandleTapeButtonsExt(TAPE_CTRL_ID_RECORD);
1432   else if (key == setup.shortcut.tape_play)
1433     HandleTapeButtonsExt(TAPE_CTRL_ID_PLAY);
1434 }