+
+static void TapeStartIndexSearch()
+{
+ tape.index_search = TRUE;
+
+ if (!tape.fast_forward || tape.pause_before_death)
+ {
+ tape.pausing = FALSE;
+
+ SetDrawDeactivationMask(REDRAW_FIELD | REDRAW_DOOR_1);
+ audio.sound_deactivated = TRUE;
+ }
+}
+
+static void TapeStopIndexSearch()
+{
+ tape.index_search = FALSE;
+
+ SetDrawDeactivationMask(REDRAW_NONE);
+ audio.sound_deactivated = FALSE;
+
+ RedrawPlayfield(TRUE, 0,0,0,0);
+ DrawGameDoorValues();
+}
+
+static void TapeSingleStep()
+{
+ if (options.network)
+ return;
+
+ if (!tape.pausing)
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+
+ tape.single_step = !tape.single_step;
+}
+
+void TapeQuickSave()
+{
+ if (game_status == PLAYING)
+ {
+ if (tape.recording)
+ TapeHaltRecording(); /* prepare tape for saving on-the-fly */
+
+ if (TAPE_IS_EMPTY(tape))
+ Request("No tape that can be saved !", REQ_CONFIRM);
+ else
+ SaveTape(tape.level_nr);
+ }
+ else if (game_status == MAINMENU)
+ Request("No game that can be saved !", REQ_CONFIRM);
+}
+
+void TapeQuickLoad()
+{
+ if (game_status == PLAYING || game_status == MAINMENU)
+ {
+ TapeStop();
+ TapeErase();
+
+ LoadTape(level_nr);
+ if (!TAPE_IS_EMPTY(tape))
+ {
+ TapeStartGamePlaying();
+ TapeStartIndexSearch();
+
+ tape.quick_resume = TRUE;
+ }
+ else
+ Request("No tape for this level !", REQ_CONFIRM);
+ }
+}
+
+
+/* ---------- new tape button stuff ---------------------------------------- */
+
+/* graphic position values for tape buttons */
+#define TAPE_BUTTON_XSIZE 18
+#define TAPE_BUTTON_YSIZE 18
+#define TAPE_BUTTON_XPOS 5
+#define TAPE_BUTTON_YPOS 77
+
+#define TAPE_BUTTON_EJECT_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_INDEX_XPOS (TAPE_BUTTON_XPOS + 0 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_STOP_XPOS (TAPE_BUTTON_XPOS + 1 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_PAUSE_XPOS (TAPE_BUTTON_XPOS + 2 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_RECORD_XPOS (TAPE_BUTTON_XPOS + 3 * TAPE_BUTTON_XSIZE)
+#define TAPE_BUTTON_PLAY_XPOS (TAPE_BUTTON_XPOS + 4 * TAPE_BUTTON_XSIZE)
+
+static struct
+{
+ int x, y;
+ int gadget_id;
+ char *infotext;
+} tapebutton_info[NUM_TAPE_BUTTONS] =
+{
+ {
+ TAPE_BUTTON_EJECT_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_EJECT,
+ "eject tape"
+ },
+ {
+ TAPE_BUTTON_INDEX_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_INDEX,
+ "index mark"
+ },
+ {
+ TAPE_BUTTON_STOP_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_STOP,
+ "stop tape"
+ },
+ {
+ TAPE_BUTTON_PAUSE_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_PAUSE,
+ "pause tape"
+ },
+ {
+ TAPE_BUTTON_RECORD_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_RECORD,
+ "record tape"
+ },
+ {
+ TAPE_BUTTON_PLAY_XPOS, TAPE_BUTTON_YPOS,
+ TAPE_CTRL_ID_PLAY,
+ "play tape"
+ }
+};
+
+void CreateTapeButtons()
+{
+ int i;
+
+ for (i=0; i<NUM_TAPE_BUTTONS; i++)
+ {
+ Bitmap *gd_bitmap = pix[PIX_DOOR];
+ struct GadgetInfo *gi;
+ int gd_xoffset, gd_yoffset;
+ int gd_x1, gd_x2, gd_y;
+ int id = i;
+
+ gd_xoffset = tapebutton_info[i].x;
+ gd_yoffset = tapebutton_info[i].y;
+ gd_x1 = DOOR_GFX_PAGEX4 + gd_xoffset;
+ gd_x2 = DOOR_GFX_PAGEX3 + gd_xoffset;
+ gd_y = DOOR_GFX_PAGEY2 + gd_yoffset;
+
+ if (i == TAPE_CTRL_ID_INDEX)
+ {
+ gd_x1 = DOOR_GFX_PAGEX6 + gd_xoffset;
+ gd_x2 = DOOR_GFX_PAGEX5 + gd_xoffset;
+ }
+
+ gi = CreateGadget(GDI_CUSTOM_ID, id,
+ GDI_INFO_TEXT, tapebutton_info[i].infotext,
+ GDI_X, VX + gd_xoffset,
+ GDI_Y, VY + gd_yoffset,
+ GDI_WIDTH, TAPE_BUTTON_XSIZE,
+ GDI_HEIGHT, TAPE_BUTTON_YSIZE,
+ GDI_TYPE, GD_TYPE_NORMAL_BUTTON,
+ GDI_STATE, GD_BUTTON_UNPRESSED,
+ GDI_DESIGN_UNPRESSED, gd_bitmap, gd_x1, gd_y,
+ GDI_DESIGN_PRESSED, gd_bitmap, gd_x2, gd_y,
+ GDI_EVENT_MASK, GD_EVENT_RELEASED,
+ GDI_CALLBACK_ACTION, HandleTapeButtons,
+ GDI_END);
+
+ if (gi == NULL)
+ Error(ERR_EXIT, "cannot create gadget");
+
+ tape_gadget[id] = gi;
+ }
+}
+
+void MapTapeEjectButton()
+{
+ UnmapGadget(tape_gadget[TAPE_CTRL_ID_INDEX]);
+ MapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
+}
+
+void MapTapeIndexButton()
+{
+ UnmapGadget(tape_gadget[TAPE_CTRL_ID_EJECT]);
+ MapGadget(tape_gadget[TAPE_CTRL_ID_INDEX]);
+}
+
+void MapTapeButtons()
+{
+ int i;
+
+ for (i=0; i<NUM_TAPE_BUTTONS; i++)
+ if (i != TAPE_CTRL_ID_INDEX)
+ MapGadget(tape_gadget[i]);
+
+ if (tape.recording || tape.playing)
+ MapTapeIndexButton();
+}
+
+void UnmapTapeButtons()
+{
+ int i;
+
+ for (i=0; i<NUM_TAPE_BUTTONS; i++)
+ UnmapGadget(tape_gadget[i]);
+}
+
+static void HandleTapeButtons(struct GadgetInfo *gi)
+{
+ int id = gi->custom_id;
+
+ if (game_status != MAINMENU && game_status != PLAYING)
+ return;
+
+ switch (id)
+ {
+ case TAPE_CTRL_ID_EJECT:
+ TapeStop();
+ if (TAPE_IS_EMPTY(tape))
+ {
+ LoadTape(level_nr);
+ if (TAPE_IS_EMPTY(tape))
+ Request("No tape for this level !", REQ_CONFIRM);
+ }
+ else
+ {
+ if (tape.changed)
+ SaveTape(tape.level_nr);
+ TapeErase();
+ }
+ DrawCompleteVideoDisplay();
+ break;
+
+ case TAPE_CTRL_ID_INDEX:
+ if (tape.playing)
+ TapeStartIndexSearch();
+ else if (tape.recording)
+ TapeSingleStep();
+ break;
+
+ case TAPE_CTRL_ID_STOP:
+ TapeStop();
+ break;
+
+ case TAPE_CTRL_ID_PAUSE:
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+ break;
+
+ case TAPE_CTRL_ID_RECORD:
+ if (TAPE_IS_STOPPED(tape))
+ TapeStartGameRecording();
+ else if (tape.pausing)
+ {
+ if (tape.playing) /* PLAYING -> PAUSING -> RECORDING */
+ TapeAppendRecording();
+ else
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+ }
+ break;
+
+ case TAPE_CTRL_ID_PLAY:
+ if (TAPE_IS_EMPTY(tape))
+ break;
+
+ if (TAPE_IS_STOPPED(tape))
+ {
+ TapeStartGamePlaying();
+ }
+ else if (tape.playing)
+ {
+ if (tape.pausing) /* PAUSE -> PLAY */
+ {
+ TapeTogglePause(TAPE_TOGGLE_MANUAL);
+ }
+ else if (!tape.fast_forward) /* PLAY -> FAST FORWARD PLAY */
+ {
+ tape.fast_forward = TRUE;
+ DrawVideoDisplay(VIDEO_STATE_FFWD_ON, 0);
+ }
+ else if (!tape.pause_before_death) /* FFWD PLAY -> AUTO PAUSE */
+ {
+ tape.pause_before_death = TRUE;
+ DrawVideoDisplay(VIDEO_STATE_PBEND_ON, VIDEO_DISPLAY_LABEL_ONLY);
+ }
+ else /* AUTO PAUSE -> NORMAL PLAY */
+ {
+ tape.fast_forward = FALSE;
+ tape.pause_before_death = FALSE;
+ DrawVideoDisplay(VIDEO_STATE_FFWD_OFF | VIDEO_STATE_PBEND_OFF, 0);
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+}