Add XBoard key bindings for Revert and Truncate
[xboard.git] / xboard.c
index d9f382a..14dac2c 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -141,12 +141,6 @@ extern char *getenv();
 # endif
 #endif
 
-
-# if HAVE_LIBREADLINE /* add gnu-readline support */
-#include <readline/readline.h>
-#include <readline/history.h>
-# endif
-
 #include <X11/Intrinsic.h>
 #include <X11/StringDefs.h>
 #include <X11/Shell.h>
@@ -231,11 +225,13 @@ void EvalGraphProc P((Widget w, XEvent *event,
 
 typedef struct {
     String string;
+    String ref;
     XtActionProc proc;
 } MenuItem;
 
 typedef struct {
     String name;
+    String ref;
     MenuItem *mi;
 } Menu;
 
@@ -248,6 +244,7 @@ RETSIGTYPE TermSizeSigHandler P((int sig));
 void CreateGCs P((void));
 void CreateXIMPieces P((void));
 void CreateXPMPieces P((void));
+void CreateXPMBoard P((char *s, int n));
 void CreatePieces P((void));
 void CreatePieceMenus P((void));
 Widget CreateMenuBar P((Menu *mb));
@@ -474,11 +471,6 @@ void SettingsPopDown P(());
 void update_ics_width P(());
 int get_term_width P(());
 int CopyMemoProc P(());
-
-# if HAVE_LIBREADLINE /* add gnu-readline support */
-static void ReadlineCompleteHandler P((char *)); 
-# endif
-
 /*
 * XBoard depends on Xt R4 or higher
 */
@@ -514,13 +506,6 @@ FileProc fileProc;
 char *fileOpenMode;
 char installDir[] = "."; // [HGM] UCI: needed for UCI; probably needs run-time initializtion
 
-# if HAVE_LIBREADLINE /* gnu readline support */
-static char* readline_buffer;
-static int readline_complete=0;
-extern int sending_ICS_login;
-extern int sending_ICS_password;
-#endif
-
 Position commentX = -1, commentY = -1;
 Dimension commentW, commentH;
 typedef unsigned int BoardSize;
@@ -562,7 +547,8 @@ Pixmap pieceBitmap2[2][(int)BlackPawn+4];       /* [HGM] pieces */
 Pixmap xpmPieceBitmap[4][(int)BlackPawn];      /* LL, LD, DL, DD actually used*/
 Pixmap xpmPieceBitmap2[4][(int)BlackPawn+4];   /* LL, LD, DL, DD set to select from */
 Pixmap xpmLightSquare, xpmDarkSquare, xpmJailSquare;
-int useImages, useImageSqs;
+Pixmap xpmBoardBitmap[2];
+int useImages, useImageSqs, useTexture, textureW[2], textureH[2];
 XImage *ximPieceBitmap[4][(int)BlackPawn+4];   /* LL, LD, DL, DD */
 Pixmap ximMaskPm[(int)BlackPawn];               /* clipmasks, used for XIM pieces */
 Pixmap ximMaskPm2[(int)BlackPawn+4];            /* clipmasks, used for XIM pieces */
@@ -606,166 +592,183 @@ static Pixmap xpmMask[BlackKing + 1];
 SizeDefaults sizeDefaults[] = SIZE_DEFAULTS;
 
 MenuItem fileMenu[] = {
-    {N_("New Game"), ResetProc},
-    {N_("New Shuffle Game ..."), ShuffleMenuProc},
-    {N_("New Variant ..."), NewVariantProc},      // [HGM] variant: not functional yet
-    {"----", NothingProc},
-    {N_("Load Game"), LoadGameProc},
-    {N_("Load Next Game"), LoadNextGameProc},
-    {N_("Load Previous Game"), LoadPrevGameProc},
-    {N_("Reload Same Game"), ReloadGameProc},
-    {N_("Save Game"), SaveGameProc},
-    {"----", NothingProc},
-    {N_("Copy Game"), CopyGameProc},
-    {N_("Paste Game"), PasteGameProc},
-    {"----", NothingProc},
-    {N_("Load Position"), LoadPositionProc},
-    {N_("Load Next Position"), LoadNextPositionProc},
-    {N_("Load Previous Position"), LoadPrevPositionProc},
-    {N_("Reload Same Position"), ReloadPositionProc},
-    {N_("Save Position"), SavePositionProc},
-    {"----", NothingProc},
-    {N_("Copy Position"), CopyPositionProc},
-    {N_("Paste Position"), PastePositionProc},
-    {"----", NothingProc},
-    {N_("Mail Move"), MailMoveProc},
-    {N_("Reload CMail Message"), ReloadCmailMsgProc},
-    {"----", NothingProc},
-    {N_("Exit"), QuitProc},
-    {NULL, NULL}
+    {N_("New Game"),             "New Game", ResetProc},
+    {N_("New Shuffle Game ..."), "New Shuffle Game", ShuffleMenuProc},
+    {N_("New Variant ..."),      "New Variant", NewVariantProc},      // [HGM] variant: not functional yet
+    {"----", NULL, NothingProc},
+    {N_("Load Game"),     "Load Game", LoadGameProc},
+    {N_("Load Position"), "Load Position", LoadPositionProc},
+//    {N_("Load Next Game"), "Load Next Game", LoadNextGameProc},
+//    {N_("Load Previous Game"), "Load Previous Game", LoadPrevGameProc},
+//    {N_("Reload Same Game"), "Reload Same Game", ReloadGameProc},
+    {"----", NULL, NothingProc},
+//    {N_("Load Next Position"), "Load Next Position", LoadNextPositionProc},
+//    {N_("Load Previous Position"), "Load Previous Position", LoadPrevPositionProc},
+//    {N_("Reload Same Position"), "Reload Same Position", ReloadPositionProc},
+    {N_("Save Game"),     "Save Game", SaveGameProc},
+    {N_("Save Position"), "Save Position", SavePositionProc},
+    {"----", NULL, NothingProc},
+    {N_("Mail Move"),            "Mail Move", MailMoveProc},
+    {N_("Reload CMail Message"), "Reload CMail Message", ReloadCmailMsgProc},
+    {"----", NULL, NothingProc},
+    {N_("Exit"), "Exit", QuitProc},
+    {NULL, NULL, NULL}
+};
+
+MenuItem editMenu[] = {
+    {N_("Copy Game"),      "Copy Game", CopyGameProc},
+    {N_("Copy Position"),  "Copy Position", CopyPositionProc},
+    {"----", NULL, NothingProc},
+    {N_("Paste Game"),     "Paste Game", PasteGameProc},
+    {N_("Paste Position"), "Paste Position", PastePositionProc},
+    {"----", NULL, NothingProc},
+    {N_("Edit Game"),      "Edit Game", EditGameProc},
+    {N_("Edit Position"),  "Edit Position", EditPositionProc},
+    {"----", NULL, NothingProc},
+    {N_("Edit Tags"),      "Edit Tags", EditTagsProc},
+    {N_("Edit Comment"),   "Edit Comment", EditCommentProc},
+    {"----", NULL, NothingProc},
+    {N_("Revert"),         "Revert", RevertProc},
+    {N_("Annotate"),       "Annotate", AnnotateProc},
+    {N_("Truncate Game"),  "Truncate Game", TruncateGameProc},
+    {"----", NULL, NothingProc},
+    {N_("Backward"),       "Backward", BackwardProc},
+    {N_("Forward"),        "Forward", ForwardProc},
+    {N_("Back to Start"),  "Back to Start", ToStartProc},
+    {N_("Forward to End"), "Forward to End", ToEndProc},
+    {NULL, NULL, NULL}
+};
+
+MenuItem viewMenu[] = {
+    {N_("Flip View"),        "Flip View", FlipViewProc},
+    {"----", NULL, NothingProc},
+    {N_("Engine Output"),    "Show Engine Output", EngineOutputProc},
+    {N_("Evaluation Graph"), "Show Evaluation Graph", EvalGraphProc},
+    {N_("Game List"),        "Show Game List", ShowGameListProc},
+    {N_("Move History"),     "Show Move History", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code
+    {"----", NULL, NothingProc},
+    {N_("Tags"),             "Show Tags", EditTagsProc},
+    {N_("Comments"),         "Show Comments", EditCommentProc},
+    {N_("ICS Input Box"),    "ICS Input Box", IcsInputBoxProc},
+    {NULL, NULL, NULL}
 };
 
 MenuItem modeMenu[] = {
-    {N_("Machine White"), MachineWhiteProc},
-    {N_("Machine Black"), MachineBlackProc},
-    {N_("Two Machines"), TwoMachinesProc},
-    {N_("Analysis Mode"), AnalyzeModeProc},
-    {N_("Analyze File"), AnalyzeFileProc },
-    {N_("ICS Client"), IcsClientProc},
-    {N_("Edit Game"), EditGameProc},
-    {N_("Edit Position"), EditPositionProc},
-    {N_("Training"), TrainingProc},
-    {"----", NothingProc},
-    {N_("Show Engine Output"), EngineOutputProc},
-    {N_("Show Evaluation Graph"), EvalGraphProc},
-    {N_("Show Game List"), ShowGameListProc},
-    {N_("Show Move History"), HistoryShowProc}, // [HGM] hist: activate 4.2.7 code
-    {"----", NothingProc},
-    {N_("Edit Tags"), EditTagsProc},
-    {N_("Edit Comment"), EditCommentProc},
-    {N_("ICS Input Box"), IcsInputBoxProc},
-    {N_("Pause"), PauseProc},
-    {NULL, NULL}
+    {N_("Machine White"), "Machine White", MachineWhiteProc},
+    {N_("Machine Black"), "Machine Black", MachineBlackProc},
+    {N_("Two Machines"),  "Two Machines", TwoMachinesProc},
+    {N_("Analysis Mode"), "Analysis Mode", AnalyzeModeProc},
+    {N_("Analyze File"),  "Analyze File", AnalyzeFileProc },
+    {N_("Edit Game"),     "Edit Game", EditGameProc},
+    {N_("Edit Position"), "Edit Position", EditPositionProc},
+    {N_("Training"),      "Training", TrainingProc},
+    {N_("ICS Client"),    "ICS Client", IcsClientProc},
+    {"----", NULL, NothingProc},
+    {N_("Pause"),         "Pause", PauseProc},
+    {NULL, NULL, NULL}
 };
 
 MenuItem actionMenu[] = {
-    {N_("Accept"), AcceptProc},
-    {N_("Decline"), DeclineProc},
-    {N_("Rematch"), RematchProc},
-    {"----", NothingProc},
-    {N_("Call Flag"), CallFlagProc},
-    {N_("Draw"), DrawProc},
-    {N_("Adjourn"), AdjournProc},
-    {N_("Abort"), AbortProc},
-    {N_("Resign"), ResignProc},
-    {"----", NothingProc},
-    {N_("Stop Observing"), StopObservingProc},
-    {N_("Stop Examining"), StopExaminingProc},
-    {N_("Upload to Examine"), UploadProc},
-    {"----", NothingProc},
-    {N_("Adjudicate to White"), AdjuWhiteProc},
-    {N_("Adjudicate to Black"), AdjuBlackProc},
-    {N_("Adjudicate Draw"), AdjuDrawProc},
-    {NULL, NULL}
+    {N_("Accept"),    "Accept", AcceptProc},
+    {N_("Decline"),   "Decline", DeclineProc},
+    {N_("Rematch"),   "Rematch", RematchProc},
+    {"----", NULL, NothingProc},
+    {N_("Call Flag"), "Call Flag", CallFlagProc},
+    {N_("Draw"),      "Draw", DrawProc},
+    {N_("Adjourn"),   "Adjourn", AdjournProc},
+    {N_("Abort"),     "Abort", AbortProc},
+    {N_("Resign"),    "Resign", ResignProc},
+    {"----", NULL, NothingProc},
+    {N_("Stop Observing"),      "Stop Observing", StopObservingProc},
+    {N_("Stop Examining"),      "Stop Examining", StopExaminingProc},
+    {N_("Upload to Examine"),   "Upload to Examine", UploadProc},
+    {"----", NULL, NothingProc},
+    {N_("Adjudicate to White"), "Adjudicate to White", AdjuWhiteProc},
+    {N_("Adjudicate to Black"), "Adjudicate to Black", AdjuBlackProc},
+    {N_("Adjudicate Draw"),     "Adjudicate Draw", AdjuDrawProc},
+    {NULL, NULL, NULL}
 };
 
-MenuItem stepMenu[] = {
-    {N_("Backward"), BackwardProc},
-    {N_("Forward"), ForwardProc},
-    {N_("Back to Start"), ToStartProc},
-    {N_("Forward to End"), ToEndProc},
-    {N_("Revert"), RevertProc},
-    {N_("Annotate"), AnnotateProc},
-    {N_("Truncate Game"), TruncateGameProc},
-    {"----", NothingProc},
-    {N_("Move Now"), MoveNowProc},
-    {N_("Retract Move"), RetractMoveProc},
-    {NULL, NULL}
+MenuItem engineMenu[] = {
+    {N_("Engine #1 Settings ..."), "Engine #1 Settings", FirstSettingsProc},
+    {N_("Engine #2 Settings ..."), "Engine #2 Settings", SecondSettingsProc},
+    {"----", NULL, NothingProc},
+    {N_("Move Now"),     "Move Now", MoveNowProc},
+    {N_("Retract Move"), "Retract Move", RetractMoveProc},
+    {NULL, NULL, NULL}
 };
 
 MenuItem optionsMenu[] = {
-    {N_("Flip View"), FlipViewProc},
-    {"----", NothingProc},
-    {N_("Adjudications ..."), EngineMenuProc},
-    {N_("General Settings ..."), UciMenuProc},
-    {N_("Engine #1 Settings ..."), FirstSettingsProc},
-    {N_("Engine #2 Settings ..."), SecondSettingsProc},
-    {N_("Time Control ..."), TimeControlProc},
-    {N_("Game List ..."), GameListOptionsPopUp},
-    {"----", NothingProc},
-    {N_("Always Queen"), AlwaysQueenProc},
-    {N_("Animate Dragging"), AnimateDraggingProc},
-    {N_("Animate Moving"), AnimateMovingProc},
-    {N_("Auto Comment"), AutocommProc},
-    {N_("Auto Flag"), AutoflagProc},
-    {N_("Auto Flip View"), AutoflipProc},
-    {N_("Auto Observe"), AutobsProc},
-    {N_("Auto Raise Board"), AutoraiseProc},
-    {N_("Auto Save"), AutosaveProc},
-    {N_("Blindfold"), BlindfoldProc},
-    {N_("Flash Moves"), FlashMovesProc},
-    {N_("Get Move List"), GetMoveListProc},
+    {N_("Time Control ..."),  "Time Control", TimeControlProc},
+    {N_("Common Engine ..."), "Common Engine", UciMenuProc},
+    {N_("Adjudications ..."), "Adjudications", EngineMenuProc},
+    {N_("Game List ..."),     "Game List", GameListOptionsPopUp},
+    {"----", NULL, NothingProc},
+    {N_("Always Queen"),     "Always Queen", AlwaysQueenProc},
+    {N_("Animate Dragging"), "Animate Dragging", AnimateDraggingProc},
+    {N_("Animate Moving"),   "Animate Moving", AnimateMovingProc},
+    {N_("Auto Comment"),     "Auto Comment", AutocommProc},
+    {N_("Auto Flag"),        "Auto Flag", AutoflagProc},
+    {N_("Auto Flip View"),   "Auto Flip View", AutoflipProc},
+    {N_("Auto Observe"),     "Auto Observe", AutobsProc},
+    {N_("Auto Raise Board"), "Auto Raise Board", AutoraiseProc},
+    {N_("Auto Save"),        "Auto Save", AutosaveProc},
+    {N_("Blindfold"),        "Blindfold", BlindfoldProc},
+    {N_("Flash Moves"),      "Flash Moves", FlashMovesProc},
+    {N_("Get Move List"),    "Get Move List", GetMoveListProc},
 #if HIGHDRAG
-    {N_("Highlight Dragging"), HighlightDraggingProc},
+    {N_("Highlight Dragging"),    "Highlight Dragging", HighlightDraggingProc},
 #endif
-    {N_("Highlight Last Move"), HighlightLastMoveProc},
-    {N_("Move Sound"), MoveSoundProc},
-    {N_("ICS Alarm"), IcsAlarmProc},
-    {N_("Old Save Style"), OldSaveStyleProc},
-    {N_("Periodic Updates"), PeriodicUpdatesProc},
-    {N_("Ponder Next Move"), PonderNextMoveProc},
-    {N_("Popup Exit Message"), PopupExitMessageProc},
-    {N_("Popup Move Errors"), PopupMoveErrorsProc},
-    {N_("Premove"), PremoveProc},
-    {N_("Quiet Play"), QuietPlayProc},
-    {N_("Show Coords"), ShowCoordsProc},
-    {N_("Hide Thinking"), HideThinkingProc},
-    {N_("Test Legality"), TestLegalityProc},
-    {"----", NothingProc},
-    {N_("Save Settings Now"), SaveSettingsProc},
-    {N_("Save Settings on Exit"), SaveOnExitProc},
-    {NULL, NULL}
+    {N_("Highlight Last Move"),   "Highlight Last Move", HighlightLastMoveProc},
+    {N_("Move Sound"),            "Move Sound", MoveSoundProc},
+    {N_("ICS Alarm"),             "ICS Alarm", IcsAlarmProc},
+    {N_("Old Save Style"),        "Old Save Style", OldSaveStyleProc},
+    {N_("Periodic Updates"),      "Periodic Updates", PeriodicUpdatesProc},
+    {N_("Ponder Next Move"),      "Ponder Next Move", PonderNextMoveProc},
+    {N_("Popup Exit Message"),    "Popup Exit Message", PopupExitMessageProc},
+    {N_("Popup Move Errors"),     "Popup Move Errors", PopupMoveErrorsProc},
+    {N_("Premove"),               "Premove", PremoveProc},
+    {N_("Quiet Play"),            "Quiet Play", QuietPlayProc},
+    {N_("Show Coords"),           "Show Coords", ShowCoordsProc},
+    {N_("Hide Thinking"),         "Hide Thinking", HideThinkingProc},
+    {N_("Test Legality"),         "Test Legality", TestLegalityProc},
+    {"----", NULL, NothingProc},
+    {N_("Save Settings Now"),     "Save Settings Now", SaveSettingsProc},
+    {N_("Save Settings on Exit"), "Save Settings on Exit", SaveOnExitProc},
+    {NULL, NULL, NULL}
 };
 
 MenuItem helpMenu[] = {
-    {N_("Info XBoard"), InfoProc},
-    {N_("Man XBoard"), ManProc},
-    {"----", NothingProc},
-    {N_("Hint"), HintProc},
-    {N_("Book"), BookProc},
-    {"----", NothingProc},
-    {N_("About XBoard"), AboutProc},
-    {NULL, NULL}
+    {N_("Info XBoard"), "Info XBoard", InfoProc},
+    {N_("Man XBoard"),  "Man XBoard", ManProc},
+    {"----", NULL, NothingProc},
+    {N_("Hint"), "Hint", HintProc},
+    {N_("Book"), "Book", BookProc},
+    {"----", NULL, NothingProc},
+    {N_("About XBoard"), "About XBoard", AboutProc},
+    {NULL, NULL, NULL}
 };
 
 Menu menuBar[] = {
-    {N_("File"), fileMenu},
-    {N_("Mode"), modeMenu},
-    {N_("Action"), actionMenu},
-    {N_("Step"), stepMenu},
-    {N_("Options"), optionsMenu},
-    {N_("Help"), helpMenu},
-    {NULL, NULL}
+    {N_("File"),    "File", fileMenu},
+    {N_("Edit"),    "Edit", editMenu},
+    {N_("View"),    "View", viewMenu},
+    {N_("Mode"),    "Mode", modeMenu},
+    {N_("Action"),  "Action", actionMenu},
+    {N_("Engine"),  "Engine", engineMenu},
+    {N_("Options"), "Options", optionsMenu},
+    {N_("Help"),    "Help", helpMenu},
+    {NULL, NULL, NULL}
 };
 
-#define PAUSE_BUTTON N_("P")
+#define PAUSE_BUTTON "P"
 MenuItem buttonBar[] = {
-    {"<<", ToStartProc},
-    {"<", BackwardProc},
-    {PAUSE_BUTTON, PauseProc},
-    {">", ForwardProc},
-    {">>", ToEndProc},
-    {NULL, NULL}
+    {"<<", "<<", ToStartProc},
+    {"<", "<", BackwardProc},
+    {PAUSE_BUTTON, PAUSE_BUTTON, PauseProc},
+    {">", ">", ForwardProc},
+    {">>", ">>", ToEndProc},
+    {NULL, NULL, NULL}
 };
 
 #define PIECE_MENU_SIZE 18
@@ -1057,6 +1060,8 @@ char globalTranslations[] =
    :Meta<Key>Right: ForwardProc() \n \
    :Meta<Key>Home: ToStartProc() \n \
    :Meta<Key>Left: BackwardProc() \n \
+   :<Key>Home: RevertProc() \n \
+   :<Key>End: TruncateGameProc() \n \
    :Ctrl<Key>m: MoveNowProc() \n \
    :Ctrl<Key>x: RetractMoveProc() \n \
    :Meta<Key>J: EngineMenuProc() \n \
@@ -1079,8 +1084,9 @@ char globalTranslations[] =
                                 \"Send to second chess program:\",,2) \n";
 
 char boardTranslations[] =
-   "<Btn1Down>: HandleUserMove() \n \
-   <Btn1Up>: HandleUserMove() \n \
+   "<Btn1Down>: HandleUserMove(0) \n \
+   Shift<Btn1Up>: HandleUserMove(1) \n \
+   <Btn1Up>: HandleUserMove(0) \n \
    <Btn1Motion>: AnimateUserMove() \n \
    <Btn3Motion>: HandlePV() \n \
    <Btn3Up>: PieceMenuPopup(menuB) \n \
@@ -1728,6 +1734,10 @@ void InitDrawingSizes(BoardSize boardSize, int flags)
           xpmPieceBitmap[i][(int)WhiteMarshall] = xpmPieceBitmap2[i][(int)WhiteSilver];
        }
 #endif
+       if(gameInfo.variant == VariantSChess && (squareSize == 49 || squareSize == 72)) {
+          xpmPieceBitmap[i][(int)WhiteAngel]    = xpmPieceBitmap2[i][(int)WhiteFalcon];
+          xpmPieceBitmap[i][(int)WhiteMarshall] = xpmPieceBitmap2[i][(int)WhiteAlfil];
+       }
 #if !HAVE_LIBXPM
        // [HGM] why are thee ximMasks used at all? the ximPieceBitmaps seem to be never used!
        for(p=0; p<=(int)WhiteKing; p++)
@@ -1744,6 +1754,10 @@ void InitDrawingSizes(BoardSize boardSize, int flags)
            ximMaskPm[(int)WhiteMarshall] = ximMaskPm2[(int)WhiteSilver];
        }
 #endif
+       if(gameInfo.variant == VariantSChess && (squareSize == 49 || squareSize == 72)) {
+           ximMaskPm[(int)WhiteAngel]    = ximMaskPm2[(int)WhiteFalcon];
+           ximMaskPm[(int)WhiteMarshall] = ximMaskPm2[(int)WhiteAlfil];
+       }
 #endif
       }
     } else {
@@ -1763,6 +1777,10 @@ void InitDrawingSizes(BoardSize boardSize, int flags)
           pieceBitmap[i][(int)WhiteMarshall] = pieceBitmap2[i][(int)WhiteSilver];
        }
 #endif
+       if(gameInfo.variant == VariantSChess && (squareSize == 49 || squareSize == 72)) {
+          pieceBitmap[i][(int)WhiteAngel]    = pieceBitmap2[i][(int)WhiteFalcon];
+          pieceBitmap[i][(int)WhiteMarshall] = pieceBitmap2[i][(int)WhiteAlfil];
+       }
       }
     }
 #if HAVE_LIBXPM
@@ -1791,12 +1809,6 @@ main(argc, argv)
     setbuf(stdout, NULL);
     setbuf(stderr, NULL);
     debugFP = stderr;
-    
-# if HAVE_LIBREADLINE
-    /* install gnu-readline handler */
-    rl_callback_handler_install("> ", ReadlineCompleteHandler);
-    rl_readline_name="XBoard";
-# endif
 
     if(argc > 1 && (!strcmp(argv[1], "-v" ) || !strcmp(argv[1], "--version" ))) {
        printf("%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
@@ -1966,6 +1978,7 @@ XBoard square size (hint): %d\n\
            fprintf(stderr, _("Closest %s size: %d\n"), IMAGE_EXT, squareSize);
        }
     }
+    if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap;
 
     /* [HR] height treated separately (hacked) */
     boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap);
@@ -2542,6 +2555,8 @@ XBoard square size (hint): %d\n\
       CreatePieces();
     } else {
       CreateXPMPieces();
+      CreateXPMBoard(appData.liteBackTextureFile, 1);
+      CreateXPMBoard(appData.darkBackTextureFile, 0);
     }
 #else
     CreateXIMPieces();
@@ -2620,13 +2635,6 @@ ShutDownFrontEnd()
     if (saveSettingsOnExit) SaveSettings(settingsFileName);
     unlink(gameCopyFilename);
     unlink(gamePasteFilename);
-
-# if HAVE_LIBREADLINE
-    /* remove gnu-readline handler.  */
-    rl_callback_handler_remove();
-#endif
-
-    return;
 }
 
 RETSIGTYPE TermSizeSigHandler(int sig)
@@ -2722,15 +2730,15 @@ GreyRevert(grey)
 {
     Widget w;
     if (!menuBarWidget) return;
-    w = XtNameToWidget(menuBarWidget, "menuStep.Revert");
+    w = XtNameToWidget(menuBarWidget, "menuEdit.Revert");
     if (w == NULL) {
-      DisplayError("menuStep.Revert", 0);
+      DisplayError("menuEdit.Revert", 0);
     } else {
       XtSetSensitive(w, !grey);
     }
-    w = XtNameToWidget(menuBarWidget, "menuStep.Annotate");
+    w = XtNameToWidget(menuBarWidget, "menuEdit.Annotate");
     if (w == NULL) {
-      DisplayError("menuStep.Annotate", 0);
+      DisplayError("menuEdit.Annotate", 0);
     } else {
       XtSetSensitive(w, !grey);
     }
@@ -2764,12 +2772,14 @@ Enables icsEnables[] = {
 #ifndef ZIPPY
     { "menuHelp.Hint", False },
     { "menuHelp.Book", False },
-    { "menuStep.Move Now", False },
+    { "menuEngine.Move Now", False },
     { "menuOptions.Periodic Updates", False },
     { "menuOptions.Hide Thinking", False },
     { "menuOptions.Ponder Next Move", False },
+    { "menuEngine.Engine #1 Settings", False },
 #endif
-    { "menuStep.Annotate", False },
+    { "menuEngine.Engine #2 Settings", False },
+    { "menuEdit.Annotate", False },
     { NULL, False }
 };
 
@@ -2782,12 +2792,14 @@ Enables ncpEnables[] = {
     { "menuMode.Analyze File", False },
     { "menuMode.Two Machines", False },
     { "menuMode.ICS Client", False },
-    { "menuMode.ICS Input Box", False },
+    { "menuView.ICS Input Box", False },
     { "Action", False },
-    { "menuStep.Revert", False },
-    { "menuStep.Annotate", False },
-    { "menuStep.Move Now", False },
-    { "menuStep.Retract Move", False },
+    { "menuEdit.Revert", False },
+    { "menuEdit.Annotate", False },
+    { "menuEngine.Engine #1 Settings", False },
+    { "menuEngine.Engine #2 Settings", False },
+    { "menuEngine.Move Now", False },
+    { "menuEngine.Retract Move", False },
     { "menuOptions.Auto Comment", False },
     { "menuOptions.Auto Flag", False },
     { "menuOptions.Auto Flip View", False },
@@ -2807,7 +2819,7 @@ Enables ncpEnables[] = {
 
 Enables gnuEnables[] = {
     { "menuMode.ICS Client", False },
-    { "menuMode.ICS Input Box", False },
+    { "menuView.ICS Input Box", False },
     { "menuAction.Accept", False },
     { "menuAction.Decline", False },
     { "menuAction.Rematch", False },
@@ -2815,8 +2827,8 @@ Enables gnuEnables[] = {
     { "menuAction.Stop Examining", False },
     { "menuAction.Stop Observing", False },
     { "menuAction.Upload to Examine", False },
-    { "menuStep.Revert", False },
-    { "menuStep.Annotate", False },
+    { "menuEdit.Revert", False },
+    { "menuEdit.Annotate", False },
     { "menuOptions.Auto Comment", False },
     { "menuOptions.Auto Observe", False },
     { "menuOptions.Auto Raise Board", False },
@@ -2849,60 +2861,60 @@ Enables cmailEnables[] = {
 Enables trainingOnEnables[] = {
   { "menuMode.Edit Comment", False },
   { "menuMode.Pause", False },
-  { "menuStep.Forward", False },
-  { "menuStep.Backward", False },
-  { "menuStep.Forward to End", False },
-  { "menuStep.Back to Start", False },
-  { "menuStep.Move Now", False },
-  { "menuStep.Truncate Game", False },
+  { "menuEdit.Forward", False },
+  { "menuEdit.Backward", False },
+  { "menuEdit.Forward to End", False },
+  { "menuEdit.Back to Start", False },
+  { "menuEngine.Move Now", False },
+  { "menuEdit.Truncate Game", False },
   { NULL, False }
 };
 
 Enables trainingOffEnables[] = {
   { "menuMode.Edit Comment", True },
   { "menuMode.Pause", True },
-  { "menuStep.Forward", True },
-  { "menuStep.Backward", True },
-  { "menuStep.Forward to End", True },
-  { "menuStep.Back to Start", True },
-  { "menuStep.Move Now", True },
-  { "menuStep.Truncate Game", True },
+  { "menuEdit.Forward", True },
+  { "menuEdit.Backward", True },
+  { "menuEdit.Forward to End", True },
+  { "menuEdit.Back to Start", True },
+  { "menuEngine.Move Now", True },
+  { "menuEdit.Truncate Game", True },
   { NULL, False }
 };
 
 Enables machineThinkingEnables[] = {
   { "menuFile.Load Game", False },
-  { "menuFile.Load Next Game", False },
-  { "menuFile.Load Previous Game", False },
-  { "menuFile.Reload Same Game", False },
-  { "menuFile.Paste Game", False },
+//  { "menuFile.Load Next Game", False },
+//  { "menuFile.Load Previous Game", False },
+//  { "menuFile.Reload Same Game", False },
+  { "menuEdit.Paste Game", False },
   { "menuFile.Load Position", False },
-  { "menuFile.Load Next Position", False },
-  { "menuFile.Load Previous Position", False },
-  { "menuFile.Reload Same Position", False },
-  { "menuFile.Paste Position", False },
+//  { "menuFile.Load Next Position", False },
+//  { "menuFile.Load Previous Position", False },
+//  { "menuFile.Reload Same Position", False },
+  { "menuEdit.Paste Position", False },
   { "menuMode.Machine White", False },
   { "menuMode.Machine Black", False },
   { "menuMode.Two Machines", False },
-  { "menuStep.Retract Move", False },
+  { "menuEngine.Retract Move", False },
   { NULL, False }
 };
 
 Enables userThinkingEnables[] = {
   { "menuFile.Load Game", True },
-  { "menuFile.Load Next Game", True },
-  { "menuFile.Load Previous Game", True },
-  { "menuFile.Reload Same Game", True },
-  { "menuFile.Paste Game", True },
+//  { "menuFile.Load Next Game", True },
+//  { "menuFile.Load Previous Game", True },
+//  { "menuFile.Reload Same Game", True },
+  { "menuEdit.Paste Game", True },
   { "menuFile.Load Position", True },
-  { "menuFile.Load Next Position", True },
-  { "menuFile.Load Previous Position", True },
-  { "menuFile.Reload Same Position", True },
-  { "menuFile.Paste Position", True },
+//  { "menuFile.Load Next Position", True },
+//  { "menuFile.Load Previous Position", True },
+//  { "menuFile.Reload Same Position", True },
+  { "menuEdit.Paste Position", True },
   { "menuMode.Machine White", True },
   { "menuMode.Machine Black", True },
   { "menuMode.Two Machines", True },
-  { "menuStep.Retract Move", True },
+  { "menuEngine.Retract Move", True },
   { NULL, False }
 };
 
@@ -3399,6 +3411,16 @@ void CreateXIMPieces()
 }
 
 #if HAVE_LIBXPM
+void CreateXPMBoard(char *s, int kind)
+{
+    XpmAttributes attr;
+    attr.valuemask = 0;
+    if(s == NULL || *s == 0 || *s == '*') return;
+    if (XpmReadFileToPixmap(xDisplay, xBoardWindow, s, &(xpmBoardBitmap[kind]), NULL, &attr) == 0) {
+       useTexture |= kind + 1; textureW[kind] = attr.width; textureH[kind] = attr.height;
+    }
+}
+
 void CreateXPMPieces()
 {
     int piece, kind, r;
@@ -3699,8 +3721,8 @@ void CreateMenuBarPopup(parent, name, mb)
            entry = XtCreateManagedWidget(mi->string, smeLineObjectClass,
                                          menu, args, j);
        } else {
-          XtSetArg(args[j], XtNlabel, XtNewString(_(mi->string)));
-           entry = XtCreateManagedWidget(mi->string, smeBSBObjectClass,
+          XtSetArg(args[j], XtNlabel, XtNewString(mi->string));
+           entry = XtCreateManagedWidget(mi->ref, smeBSBObjectClass,
                                          menu, args, j+1);
            XtAddCallback(entry, XtNcallback,
                          (XtCallbackProc) MenuBarSelect,
@@ -3727,17 +3749,17 @@ Widget CreateMenuBar(mb)
 
     while (mb->name != NULL) {
         safeStrCpy(menuName, "menu", sizeof(menuName)/sizeof(menuName[0]) );
-       strncat(menuName, mb->name, MSG_SIZ - strlen(menuName) - 1);
+       strncat(menuName, mb->ref, MSG_SIZ - strlen(menuName) - 1);
        j = 0;
        XtSetArg(args[j], XtNmenuName, XtNewString(menuName));  j++;
        if (tinyLayout) {
            char shortName[2];
-            shortName[0] = _(mb->name)[0];
+            shortName[0] = mb->name[0];
            shortName[1] = NULLCHAR;
            XtSetArg(args[j], XtNlabel, XtNewString(shortName)); j++;
        }
       else {
-          XtSetArg(args[j], XtNlabel, XtNewString(_(mb->name))); j++;
+          XtSetArg(args[j], XtNlabel, XtNewString(mb->name)); j++;
       }
 
        XtSetArg(args[j], XtNborderWidth, 0);                   j++;
@@ -4065,11 +4087,34 @@ ClearPremoveHighlights()
   SetPremoveHighlights(-1, -1, -1, -1);
 }
 
-static void BlankSquare(x, y, color, piece, dest)
-     int x, y, color;
+static int CutOutSquare(x, y, x0, y0, kind)
+     int x, y, *x0, *y0, kind;
+{
+    int W = BOARD_WIDTH, H = BOARD_HEIGHT;
+    int nx = x/(squareSize + lineGap), ny = y/(squareSize + lineGap);
+    *x0 = 0; *y0 = 0;
+    if(textureW[kind] < squareSize || textureH[kind] < squareSize) return 0;
+    if(textureW[kind] < W*squareSize)
+       *x0 = (textureW[kind] - squareSize) * nx/(W-1);
+    else
+       *x0 = textureW[kind]*nx / W + (textureW[kind] - W*squareSize) / (2*W);
+    if(textureH[kind] < H*squareSize)
+       *y0 = (textureH[kind] - squareSize) * ny/(H-1);
+    else
+       *y0 = textureH[kind]*ny / H + (textureH[kind] - H*squareSize) / (2*H);
+    return 1;
+}
+
+static void BlankSquare(x, y, color, piece, dest, fac)
+     int x, y, color, fac;
      ChessSquare piece;
      Drawable dest;
-{
+{   // [HGM] extra param 'fac' for forcing destination to (0,0) for copying to animation buffer
+    int x0, y0;
+    if (useImages && color != 2 && (useTexture & color+1) && CutOutSquare(x, y, &x0, &y0, color)) {
+       XCopyArea(xDisplay, xpmBoardBitmap[color], dest, wlPieceGC, x0, y0,
+                 squareSize, squareSize, x*fac, y*fac);
+    } else
     if (useImages && useImageSqs) {
        Pixmap pm;
        switch (color) {
@@ -4085,7 +4130,7 @@ static void BlankSquare(x, y, color, piece, dest)
            break;
        }
        XCopyArea(xDisplay, pm, dest, wlPieceGC, 0, 0,
-                 squareSize, squareSize, x, y);
+                 squareSize, squareSize, x*fac, y*fac);
     } else {
        GC gc;
        switch (color) {
@@ -4100,7 +4145,7 @@ static void BlankSquare(x, y, color, piece, dest)
            gc = jailSquareGC;
            break;
        }
-       XFillRectangle(xDisplay, dest, gc, x, y, squareSize, squareSize);
+       XFillRectangle(xDisplay, dest, gc, x*fac, y*fac, squareSize, squareSize);
     }
 }
 
@@ -4193,7 +4238,7 @@ static void colorDrawPieceImage(piece, square_color, x, y, dest)
      int square_color, x, y;
      Drawable dest;
 {
-    int kind;
+    int kind, p = piece;
 
     switch (square_color) {
       case 1: /* light */
@@ -4216,6 +4261,14 @@ static void colorDrawPieceImage(piece, square_color, x, y, dest)
        break;
     }
     if(appData.upsideDown && flipView) kind ^= 2; // swap white and black pieces
+    if(useTexture & square_color+1) {
+        BlankSquare(x, y, square_color, piece, dest, 1); // erase previous contents with background
+       XSetClipMask(xDisplay, wlPieceGC, xpmMask[p]);
+       XSetClipOrigin(xDisplay, wlPieceGC, x, y);
+       XCopyArea(xDisplay, xpmPieceBitmap[kind][piece], dest, wlPieceGC, 0, 0, squareSize, squareSize, x, y);
+       XSetClipMask(xDisplay, wlPieceGC, None);
+       XSetClipOrigin(xDisplay, wlPieceGC, 0, 0);
+    } else
     XCopyArea(xDisplay, xpmPieceBitmap[kind][piece],
              dest, wlPieceGC, 0, 0,
              squareSize, squareSize, x, y);
@@ -4297,7 +4350,7 @@ void DrawSquare(row, column, piece, do_flash)
                  column == BOARD_LEFT-1 ||  column == BOARD_RGHT
               || (column == BOARD_LEFT-2 && row < BOARD_HEIGHT-gameInfo.holdingsSize)
                  || (column == BOARD_RGHT+1 && row >= gameInfo.holdingsSize) ) {
-                       BlankSquare(x, y, 2, EmptySquare, xBoardWindow);
+                       BlankSquare(x, y, 2, EmptySquare, xBoardWindow, 1);
 
                        // [HGM] print piece counts next to holdings
                        string[1] = NULLCHAR;
@@ -4329,7 +4382,7 @@ void DrawSquare(row, column, piece, do_flash)
                        }
     } else {
            if (piece == EmptySquare || appData.blindfold) {
-                       BlankSquare(x, y, square_color, piece, xBoardWindow);
+                       BlankSquare(x, y, square_color, piece, xBoardWindow, 1);
            } else {
                        drawfunc = ChooseDrawFunc();
                        if (do_flash && appData.flashCount > 0) {
@@ -4339,7 +4392,7 @@ void DrawSquare(row, column, piece, do_flash)
                                        XSync(xDisplay, False);
                                        do_flash_delay(flash_delay);
 
-                                       BlankSquare(x, y, square_color, piece, xBoardWindow);
+                                       BlankSquare(x, y, square_color, piece, xBoardWindow, 1);
                                        XSync(xDisplay, False);
                                        do_flash_delay(flash_delay);
                            }
@@ -4540,7 +4593,7 @@ void XDrawPosition(w, repaint, board)
     }
     if (!lastBoardValid[nr] || (nr == 0 && lastFlipView != flipView)) {
        XtSetArg(args[0], XtNleftBitmap, (flipView ? xMarkPixmap : None));
-       XtSetValues(XtNameToWidget(menuBarWidget, "menuOptions.Flip View"),
+       XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Flip View"),
                    args, 1);
     }
 
@@ -4651,6 +4704,7 @@ void HandleUserMove(w, event, prms, nprms)
      Cardinal *nprms;
 {
     if (w != boardWidget || errorExitStatus != -1) return;
+    if(nprms) shiftKey = !strcmp(prms[0], "1");
 
     if (promotionUp) {
        if (event->type == ButtonPress) {
@@ -4987,7 +5041,9 @@ void EditCommentPopUp(index, title, text)
     editUp = True;
     j = 0;
     XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Comment"),
+    XtSetValues(XtNameToWidget(menuBarWidget, "menuEdit.Edit Comment"),
+               args, j);
+    XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Comments"),
                args, j);
 }
 
@@ -5036,7 +5092,9 @@ void EditCommentPopDown()
     editUp = False;
     j = 0;
     XtSetArg(args[j], XtNleftBitmap, None); j++;
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Comment"),
+    XtSetValues(XtNameToWidget(menuBarWidget, "menuEdit.Edit Comment"),
+               args, j);
+    XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Comments"),
                args, j);
 }
 
@@ -5073,7 +5131,7 @@ void ICSInputBoxPopUp()
     ICSInputBoxUp = True;
     j = 0;
     XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.ICS Input Box"),
+    XtSetValues(XtNameToWidget(menuBarWidget, "menuView.ICS Input Box"),
                args, j);
 }
 
@@ -5105,7 +5163,7 @@ void ICSInputBoxPopDown()
     ICSInputBoxUp = False;
     j = 0;
     XtSetArg(args[j], XtNleftBitmap, None); j++;
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.ICS Input Box"),
+    XtSetValues(XtNameToWidget(menuBarWidget, "menuView.ICS Input Box"),
                args, j);
 }
 
@@ -5767,7 +5825,7 @@ SendPositionSelection(Widget w, Atom *selection, Atom *target,
      * automatically call XtFree on the value returned.  So have to
      * make a copy of it allocated with XtMalloc */
     selection_tmp= XtMalloc(strlen(selected_fen_position)+16);
-    safeStrCpy(selection_tmp, selected_fen_position, sizeof(selection_tmp)/sizeof(selection_tmp[0]) );
+    safeStrCpy(selection_tmp, selected_fen_position, strlen(selected_fen_position)+16 );
 
     *value_return=selection_tmp;
     *length_return=strlen(selection_tmp);
@@ -7561,7 +7619,7 @@ ExpandPathName(path)
        }
        else {
          safeStrCpy(buf, s+1, sizeof(buf)/sizeof(buf[0]) );
-         *strchr(buf, '/') = 0;
+         { char *p; if(p = strchr(buf, '/')) *p = 0; }
          pwd = getpwnam(buf);
          if (!pwd)
            {
@@ -8107,98 +8165,16 @@ DoInputCallback(closure, source, xid)
        }
        q = is->buf;
        while (p < is->unused) {
-         *q++ = *p++;
+           *q++ = *p++;
        }
        is->unused = q;
     } else {
-# if HAVE_LIBREADLINE
-      /* check if input is from stdin, if yes, use gnu-readline */
-      if( is->fd==fileno(stdin) )
-       {
-         /* to clear the line */
-         printf("\r                                                 \r");
-         
-         /* read from stdin */
-         rl_callback_read_char(); 
-
-         /* redisplay the current line, check special case for login and password */
-         if(sending_ICS_password)
-           {
-             int i; char buf[MSG_SIZ];
-
-             bzero(buf,MSG_SIZ);
-
-             /* blank the password */
-             count = strlen(rl_line_buffer);
-             if(count>MSG_SIZ-1)
-               {
-                 printf("PROBLEM with readline\n");
-                 count=MSG_SIZ;
-               }
-             for(i=0;i<count;i++)
-               buf[i]='*';
-             i++;
-             buf[i]='\0';
-             printf("\rpassword: %s",buf);
-           }
-         else if (sending_ICS_login)
-           {
-             /* show login prompt */
-             count = strlen(rl_line_buffer);
-             printf("\rlogin: %s",rl_line_buffer);
-           }
-         else
-           rl_reset_line_state();
-         
-         if(readline_complete)
-           {
-             /* copy into XBoards buffer */
-             count = strlen(readline_buffer);
-             if (count>INPUT_SOURCE_BUF_SIZE-1)
-               {
-                 printf("PROBLEM with readline\n");
-                 count = INPUT_SOURCE_BUF_SIZE;
-               };
-             strncpy(is->buf,readline_buffer,count);
-             is->buf[count]='\n';count++; 
-
-             /* reset gnu-readline state */
-             free(readline_buffer);
-             readline_buffer=NULL;
-             readline_complete=0;
-
-             if (count == -1)
-               error = errno;
-             else
-               error = 0;
-             (is->func)(is, is->closure, is->buf, count, error);
-
-             /* are we done with the password? */
-             if(sending_ICS_password)
-               sending_ICS_password=0;
-             if(sending_ICS_login)
-               sending_ICS_login=0;
-           }
-       }
-      else
-       {
-         /* input not from stdin, use default method */
-         count = read(is->fd, is->buf, INPUT_SOURCE_BUF_SIZE);
-         if (count == -1)
-           error = errno;
-         else
-           error = 0;
-         (is->func)(is, is->closure, is->buf, count, error);
-       };
-#else /* no readline support */
-      count = read(is->fd, is->buf, INPUT_SOURCE_BUF_SIZE);
-      if (count == -1)
-       error = errno;
-      else
-       error = 0;
-      (is->func)(is, is->closure, is->buf, count, error);
-#endif
-
+       count = read(is->fd, is->buf, INPUT_SOURCE_BUF_SIZE);
+       if (count == -1)
+         error = errno;
+       else
+         error = 0;
+       (is->func)(is, is->closure, is->buf, count, error);
     }
 }
 
@@ -8254,36 +8230,28 @@ int OutputToProcess(pr, message, count, outError)
     ChildProc *cp = (ChildProc *) pr;
     int outCount;
 
-
     if (pr == NoProc)
     {
-      if (appData.noJoin || !appData.useInternalWrap)
-       outCount = fwrite(message, 1, count, stdout);
-      else
+        if (appData.noJoin || !appData.useInternalWrap)
+            outCount = fwrite(message, 1, count, stdout);
+        else
         {
-         int width = get_term_width();
-         int len = wrap(NULL, message, count, width, &line);
-         char *msg = malloc(len);
-         int dbgchk;
-         
-         if (!msg)
-           outCount = fwrite(message, 1, count, stdout);
-         else
+            int width = get_term_width();
+            int len = wrap(NULL, message, count, width, &line);
+            char *msg = malloc(len);
+            int dbgchk;
+
+            if (!msg)
+                outCount = fwrite(message, 1, count, stdout);
+            else
             {
-             dbgchk = wrap(msg, message, count, width, &line);
-             if (dbgchk != len && appData.debugMode)
-               fprintf(debugFP, "wrap(): dbgchk(%d) != len(%d)\n", dbgchk, len);
-             outCount = fwrite(msg, 1, dbgchk, stdout);
-             free(msg);
+                dbgchk = wrap(msg, message, count, width, &line);
+                if (dbgchk != len && appData.debugMode)
+                    fprintf(debugFP, "wrap(): dbgchk(%d) != len(%d)\n", dbgchk, len);
+                outCount = fwrite(msg, 1, dbgchk, stdout);
+                free(msg);
             }
         }
-      
-# if HAVE_LIBREADLINE
-      /* readline support */
-      if(strlen(rl_line_buffer))
-        printf("\n>  %s",rl_line_buffer);
-#endif
-
     }
     else
       outCount = write(cp->fdTo, message, count);
@@ -8763,7 +8731,7 @@ BeginAnimation(anim, piece, startColor, start)
   Pixmap mask;
 
   /* The old buffer is initialised with the start square (empty) */
-  BlankSquare(0, 0, startColor, EmptySquare, anim->saveBuf);
+  BlankSquare(start->x, start->y, startColor, EmptySquare, anim->saveBuf, 0);
   anim->prevFrame = *start;
 
   /* The piece will be drawn using its own bitmap as a matte   */
@@ -8868,6 +8836,29 @@ FrameSequence(anim, piece, startColor, start, finish, frames, nFrames)
   EndAnimation(anim, finish);
 }
 
+void
+AnimateAtomicCapture(Board board, int fromX, int fromY, int toX, int toY)
+{
+    int i, x, y;
+    ChessSquare piece = board[fromY][toY];
+    board[fromY][toY] = EmptySquare;
+    DrawPosition(FALSE, board);
+    if (flipView) {
+       x = lineGap + ((BOARD_WIDTH-1)-toX) * (squareSize + lineGap);
+       y = lineGap + toY * (squareSize + lineGap);
+    } else {
+       x = lineGap + toX * (squareSize + lineGap);
+       y = lineGap + ((BOARD_HEIGHT-1)-toY) * (squareSize + lineGap);
+    }
+    for(i=1; i<4*kFactor; i++) {
+       int r = squareSize * 9 * i/(20*kFactor - 5);
+       XFillArc(xDisplay, xBoardWindow, highlineGC,
+               x + squareSize/2 - r, y+squareSize/2 - r, 2*r, 2*r, 0, 64*360);
+       FrameDelay(appData.animSpeed);
+    }
+    board[fromY][toY] = piece;
+}
+
 /* Main control logic for deciding what to animate and how */
 
 void
@@ -8899,7 +8890,7 @@ AnimateMove(board, fromX, fromY, toX, toY)
 #if DONT_HOP
   hop = FALSE;
 #else
-  hop = (piece == WhiteKnight || piece == BlackKnight);
+  hop = abs(fromX-toX) == 1 && abs(fromY-toY) == 2 || abs(fromX-toX) == 2 && abs(fromY-toY) == 1;
 #endif
 
   if (appData.debugMode) {
@@ -8911,12 +8902,12 @@ AnimateMove(board, fromX, fromY, toX, toY)
   ScreenSquare(toX, toY, &finish, &endColor);
 
   if (hop) {
-    /* Knight: make diagonal movement then straight */
+    /* Knight: make straight movement then diagonal */
     if (abs(toY - fromY) < abs(toX - fromX)) {
        mid.x = start.x + (finish.x - start.x) / 2;
-       mid.y = finish.y;
+       mid.y = start.y;
      } else {
-       mid.x = finish.x;
+       mid.x = start.x;
        mid.y = start.y + (finish.y - start.y) / 2;
      }
   } else {
@@ -8930,6 +8921,11 @@ AnimateMove(board, fromX, fromY, toX, toY)
   else
     Tween(&start, &mid, &finish, kFactor, frames, &nFrames);
   FrameSequence(&game, piece, startColor, &start, &finish, frames, nFrames);
+  if(Explode(board, fromX, fromY, toX, toY)) { // mark as damaged
+    int i,j;
+    for(i=0; i<BOARD_WIDTH; i++) for(j=0; j<BOARD_HEIGHT; j++)
+      if((i-toX)*(i-toX) + (j-toY)*(j-toY) < 6) damage[0][j][i] = True;
+  }
 
   /* Be sure end square is redrawn */
   damage[0][toY][toX] = True;
@@ -8972,6 +8968,17 @@ DragPieceBegin(x, y)
            XCopyArea(xDisplay, xBoardWindow, player.saveBuf, player.blitGC,
                     corner.x, corner.y, squareSize, squareSize,
                     0, 0); // [HGM] zh: unstack in stead of grab
+           if(gatingPiece != EmptySquare) {
+               /* Kludge alert: When gating we want the introduced
+                  piece to appear on the from square. To generate an
+                  image of it, we draw it on the board, copy the image,
+                  and draw the original piece again. */
+               ChessSquare piece = boards[currentMove][boardY][boardX];
+               DrawSquare(boardY, boardX, gatingPiece, 0);
+               XCopyArea(xDisplay, xBoardWindow, player.saveBuf, player.blitGC,
+                    corner.x, corner.y, squareSize, squareSize, 0, 0);
+               DrawSquare(boardY, boardX, piece, 0);
+           }
        damage[0][boardY][boardX] = True;
     } else {
        player.dragActive = False;
@@ -9047,7 +9054,7 @@ DrawDragPiece ()
      it's being dragged around the board. So we erase the square
      that the piece is on and draw it at the last known drag point. */
   BlankSquare(player.startSquare.x, player.startSquare.y,
-               player.startColor, EmptySquare, xBoardWindow);
+               player.startColor, EmptySquare, xBoardWindow, 1);
   AnimationFrame(&player, &player.prevFrame, player.dragPiece);
   damage[0][player.startBoardY][player.startBoardX] = TRUE;
 }
@@ -9087,18 +9094,3 @@ void NotifyFrontendLogin()
 {
     update_ics_width();
 }
-
-# if HAVE_LIBREADLINE
-static void 
-ReadlineCompleteHandler(char* ptr)
-{
-  /* make gnu-readline keep the history */
-  readline_buffer = ptr;
-  readline_complete = 1;
-  
-  if (ptr && *ptr && !sending_ICS_password && !sending_ICS_login)
-    add_history(ptr);
-
-  return;
-}
-#endif