X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=84937ae62209a5ea7a0b9445ce1c489182680af3;hb=912ff451e7a648f6aa3ba7d2a10df2a1dc2cace5;hp=8ea75c85ca1c25dd2bd69f2f9a22453698a7679d;hpb=cda9681381317b37da384bc8450795c29e8dccc8;p=xboard.git diff --git a/backend.c b/backend.c index 8ea75c8..84937ae 100644 --- a/backend.c +++ b/backend.c @@ -212,10 +212,12 @@ void ParseFeatures P((char* args, ChessProgramState *cps)); void InitBackEnd3 P((void)); void FeatureDone P((ChessProgramState* cps, int val)); void InitChessProgram P((ChessProgramState *cps)); - -#ifdef WIN32 - extern void ConsoleCreate(); -#endif +double u64ToDouble P((u64 value)); + +#ifdef WIN32 + extern void ConsoleCreate(); +#endif + extern int tinyLayout, smallLayout; static ChessProgramStats programStats; @@ -258,6 +260,26 @@ static ChessProgramStats programStats; #define TN_SGA 0003 #define TN_PORT 23 +/* Some compiler can't cast u64 to double + * This function do the job for us: + + * We use the highest bit for cast, this only + * works if the highest bit is not + * in use (This should not happen) + * + * We used this for all compiler + */ +double +u64ToDouble(u64 value) +{ + double r; + u64 tmp = value & u64Const(0x7fffffffffffffff); + r = (double)(s64)tmp; + if (value & u64Const(0x8000000000000000)) + r += 9.2233720368547758080e18; /* 2^63 */ + return r; +} + /* Fake up flags for now, as we aren't keeping track of castling availability yet */ int @@ -305,7 +327,7 @@ Boolean alarmSounded; /* end premove variables */ char *ics_prefix = "$"; -ics_type = ICS_GENERIC; +int ics_type = ICS_GENERIC; int currentMove = 0, forwardMostMove = 0, backwardMostMove = 0; int pauseExamForwardMostMove = 0; @@ -692,12 +714,12 @@ InitBackEnd3 P((void)) char buf[MSG_SIZ]; int err; - InitChessProgram(&first); - - #ifdef WIN32 - /* Make a console window if needed */ - if (appData.icsActive) ConsoleCreate(); - #endif + InitChessProgram(&first); + + #ifdef WIN32 + /* Make a console window if needed */ + if (appData.icsActive) ConsoleCreate(); + #endif if (appData.icsActive) { err = establish(); @@ -1466,15 +1488,10 @@ read_from_ics(isr, closure, data, count, error) int i, oldi; int buf_len; int next_out; - int tkind; -#ifdef WIN32 - /* For zippy color lines of winboard - * cleanup for gcc compiler */ - int backup; -#endif + int tkind; + int backup; char *p; -#ifdef WIN32 if (appData.debugMode) { if (!error) { fprintf(debugFP, " 0) { /* If last read ended with a partial line that we couldn't parse, @@ -1728,20 +1744,20 @@ read_from_ics(isr, closure, data, count, error) oldi = i; if (appData.zippyTalk || appData.zippyPlay) { -#if ZIPPY - #ifdef WIN32 - /* Backup address for color zippy lines */ - backup = i; - if (loggedOn == TRUE) - if (ZippyControl(buf, &backup) || ZippyConverse(buf, &backup) || - (appData.zippyPlay && ZippyMatch(buf, &backup))); + /* Backup address for color zippy lines */ + backup = i; +#if ZIPPY + #ifdef WIN32 + if (loggedOn == TRUE) + if (ZippyControl(buf, &backup) || ZippyConverse(buf, &backup) || + (appData.zippyPlay && ZippyMatch(buf, &backup))); #else if (ZippyControl(buf, &i) || ZippyConverse(buf, &i) || (appData.zippyPlay && ZippyMatch(buf, &i))) { loggedOn = TRUE; - continue; - } + if (!appData.colorize) continue; + } #endif #endif } @@ -2423,6 +2439,11 @@ read_from_ics(isr, closure, data, count, error) if (gameMode == IcsObserving && atoi(star_match[0]) == ics_gamenum) { + /* icsEngineAnalyze */ + if (appData.icsEngineAnalyze) { + ExitAnalyzeMode(); + ModeHighlight(); + } StopClocks(); gameMode = IcsIdle; ics_gamenum = -1; @@ -2598,8 +2619,8 @@ ParseBoard12(string) char *string; { GameMode newGameMode; - int gamenum, newGame, newMove, relation, basetime, increment, ics_flip = 0; - int j, k, n, moveNum, white_stren, black_stren, white_time, black_time; + int gamenum, newGame, newMove, relation, basetime, increment, ics_flip = 0, i; + int j, k, n, moveNum, white_stren, black_stren, white_time, black_time, takeback; int double_push, castle_ws, castle_wl, castle_bs, castle_bl, irrev_count; char to_play, board_chars[72]; char move_str[500], str[500], elapsed_time[500]; @@ -2711,7 +2732,7 @@ ParseBoard12(string) /* Forget the old game and get the history (if any) of the new one */ if (gameMode != BeginningOfGame) { - Reset(FALSE, TRUE); + Reset(FALSE, TRUE); } newGame = TRUE; if (appData.autoRaiseBoard) BoardToTop(); @@ -2833,6 +2854,16 @@ ParseBoard12(string) /* Update currentMove and known move number limits */ newMove = newGame || moveNum > forwardMostMove; + + /* If we found takebacks during icsEngineAnalyze + try send to engine */ + if (!newGame && appData.icsEngineAnalyze && moveNum < forwardMostMove) { + takeback = forwardMostMove - moveNum; + for (i = 0; i < takeback; i++) { + if (appData.debugMode) fprintf(debugFP, "take back move\n"); + SendToProgram("undo\n", &first); + } + } if (newGame) { forwardMostMove = backwardMostMove = currentMove = moveNum; if (gameMode == IcsExamining && moveNum == 0) { @@ -4361,6 +4392,10 @@ HandleMachineMove(message, cps) break; case AnalyzeMode: case AnalyzeFile: + break; + /* icsEngineAnalyze */ + case IcsObserving: + if (!appData.icsEngineAnalyze) ignore = TRUE; break; case TwoMachinesPlay: if ((cps->twoMachinesColor[0] == 'w') != @@ -4421,10 +4456,10 @@ HandleMachineMove(message, cps) ToUpper(cps->twoMachinesColor[0]) : ' '), ((double) curscore) / 100.0, prefixHint ? lastHint : "", - prefixHint ? " " : "", buf1); + prefixHint ? " " : "", programStats.movelist); - if (currentMove == forwardMostMove || - gameMode == AnalyzeMode || gameMode == AnalyzeFile) { + if (currentMove == forwardMostMove || gameMode == AnalyzeMode + || gameMode == AnalyzeFile || appData.icsEngineAnalyze) { DisplayMove(currentMove - 1); DisplayAnalysis(); } @@ -4450,7 +4485,7 @@ HandleMachineMove(message, cps) programStats.line_is_book = 1; if (currentMove == forwardMostMove || gameMode==AnalyzeMode || - gameMode == AnalyzeFile) { + gameMode == AnalyzeFile || appData.icsEngineAnalyze) { DisplayMove(currentMove - 1); DisplayAnalysis(); } @@ -4495,7 +4530,7 @@ HandleMachineMove(message, cps) strcat(programStats.movelist, " "); strcat(programStats.movelist, p); if (currentMove == forwardMostMove || gameMode==AnalyzeMode || - gameMode == AnalyzeFile) { + gameMode == AnalyzeFile || appData.icsEngineAnalyze) { DisplayMove(currentMove - 1); DisplayAnalysis(); } @@ -5309,8 +5344,8 @@ ResurrectChessProgram() timeRemaining[1][currentMove] = blackTimeRemaining; } - if ((gameMode == AnalyzeMode || gameMode == AnalyzeFile) && - first.analysisSupport) { + if ((gameMode == AnalyzeMode || gameMode == AnalyzeFile || + appData.icsEngineAnalyze) && first.analysisSupport) { SendToProgram("analyze\n", &first); first.analyzing = TRUE; } @@ -6975,7 +7010,7 @@ MailMoveEvent() || (nCmailMovesRegistered + nCmailResults == nCmailGames)) { sprintf(string, partCommandString, appData.debugMode ? " -v" : "", appData.cmailGameName); - commandOutput = popen(string, "rb"); + commandOutput = popen(string, "r"); if (commandOutput == NULL) { DisplayError(_("Failed to invoke cmail"), 0); @@ -7273,8 +7308,10 @@ AnalyzeModeEvent() return; if (gameMode != AnalyzeFile) { - EditGameEvent(); - if (gameMode != EditGame) return; + if (!appData.icsEngineAnalyze) { + EditGameEvent(); + if (gameMode != EditGame) return; + } ResurrectChessProgram(); SendToProgram("analyze\n", &first); first.analyzing = TRUE; @@ -7283,7 +7320,7 @@ AnalyzeModeEvent() AnalysisPopUp(_("Analysis"), _("Starting analysis mode...\nIf this message stays up, your chess program does not support analysis.")); } - gameMode = AnalyzeMode; + if (!appData.icsEngineAnalyze) gameMode = AnalyzeMode; pausing = FALSE; ModeHighlight(); SetGameInfo(); @@ -7749,6 +7786,11 @@ EditPositionEvent() void ExitAnalyzeMode() { + /* icsEngineAnalyze - possible call from other functions */ + if (appData.icsEngineAnalyze) { + appData.icsEngineAnalyze = FALSE; + DisplayMessage("","Close ICS engine analyze..."); + } if (first.analysisSupport && first.analyzing) { SendToProgram("exit\n", &first); first.analyzing = FALSE; @@ -8878,7 +8920,18 @@ ReceiveFromProgram(isr, closure, message, count, error) SubtractTimeMarks(&now, &programStartTime), cps->which, message); } - HandleMachineMove(message, cps); + /* if icsEngineAnalyze is active we block all + whisper and kibitz output, because nobody want + see this + */ + if (appData.icsEngineAnalyze) { + if (strstr(message, "whisper") != NULL || + strstr(message, "kibitz") != NULL || + strstr(message, "tellics") != NULL) return; + HandleMachineMove(message, cps); + } else { + HandleMachineMove(message, cps); + } } @@ -9218,7 +9271,8 @@ DisplayAnalysisText(text) { char buf[MSG_SIZ]; - if (gameMode == AnalyzeMode || gameMode == AnalyzeFile) { + if (gameMode == AnalyzeMode || gameMode == AnalyzeFile + || appData.icsEngineAnalyze) { sprintf(buf, "Analysis (%s)", first.tidy); AnalysisPopUp(buf, text); } @@ -9251,8 +9305,8 @@ DisplayAnalysis() if (programStats.got_only_move) { strcpy(buf, programStats.movelist); } else { - nps = (((u64)programStats.nodes) / - (((double)programStats.time)/100.0)); + nps = (u64ToDouble(programStats.nodes) / + ((double)programStats.time /100.0)); cs = programStats.time % 100; s = programStats.time / 100;