X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fjaws.c;h=d05a78fbb199e54933974dcc857900695d8b7042;hb=3a11677c0e70fe1833016cbf9070c3d5df615112;hp=4502178e535e266b2e0d05f4e526cfc40d43f5ce;hpb=07d6c1c19f1ca78bf3c60183447dee9f80a40bbd;p=xboard.git diff --git a/winboard/jaws.c b/winboard/jaws.c index 4502178..d05a78f 100644 --- a/winboard/jaws.c +++ b/winboard/jaws.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010 Free Software Foundation, Inc. * * XBoard borrows its colors and the bitmaps.xchess bitmap set from XChess, * which was written and is copyrighted by Wayne Christopher. @@ -83,16 +83,6 @@ extern long whiteTimeRemaining, blackTimeRemaining, timeControl, timeIncrement; -#if 0 -// from moves.h, but no longer needed, as the new routines are all moved to winboard.c - -extern char* PieceToName P((ChessSquare p, int i)); -extern char* SquareToChar P((int Xpos)); -extern char* SquareToNum P((int Ypos)); -extern int CoordToNum P((char c)); - -#endif - // from moves.c, added WinBoard_F piece types and ranks / files char *squareToChar[] = { "ay", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l" }; @@ -102,7 +92,7 @@ char *squareToNum[] = {"naught", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; char *ordinals[] = {"zeroth", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "nineth"}; char *pieceToName[] = { - "White Pawn", "White Knight", "White Bishop", "White Rook", "White Queen", + "White Pawn", "White Knight", "White Bishop", "White Rook", "White Queen", "White Guard", "White Elephant", "White Arch Bishop", "White Chancellor", "White General", "White Man", "White Cannon", "White Night Rider", "White Crowned Bishop", "White Crowned Rook", "White Grass Hopper", "White Veteran", @@ -117,6 +107,22 @@ char *pieceToName[] = { "Empty" }; +char *pieceTypeName[] = { + "Pawn", "Knight", "Bishop", "Rook", "Queen", + "Guard", "Elephant", "Arch Bishop", "Chancellor", + "General", "Man", "Cannon", "Night Rider", + "Crowned Bishop", "Crowned Rook", "Grass Hopper", "Veteran", + "Falcon", "Amazon", "Snake", "Unicorn", + "King", + "Pawn", "Knight", "Bishop", "Rook", "Queen", + "Guard", "Elephant", "Arch Bishop", "Chancellor", + "General", "Man", "Cannon", "Night Rider", + "Crowned Bishop", "Crowned Rook", "Grass Hopper", "Veteran", + "Falcon", "Amazon", "Snake", "Unicorn", + "King", + "Empty" + }; + int CoordToNum(c) char c; { @@ -130,7 +136,7 @@ char* PieceToName(p, i) int i; { if(i) return pieceToName[(int) p]; - return pieceToName[(int) p]+6; + return pieceTypeName[(int) p]; } char* SquareToChar(x) @@ -156,9 +162,9 @@ PSAYSTRING RealSayString; VOID SayString(char *mess, BOOL flag) { // for debug file - char buf[MSG_SIZ], *p; + char buf[8000], *p; if(appData.debugMode) fprintf(debugFP, "SAY '%s'\n", mess); - strcpy(buf, mess); + safeStrCpy(buf, mess, sizeof(buf)/sizeof(buf[0])); if(p = StrCaseStr(buf, "Xboard adjudication:")) { int i; for(i=19; i>1; i--) p[i] = p[i-1]; @@ -188,8 +194,8 @@ MenuItemDesc menuItemJAWS[] = { {"Say Board &Rank\tAlt+R", IDM_ReadRow }, {"Say Board &File\tAlt+F", IDM_ReadColumn }, {"-", 0 }, -{"Say &Upper Diagnols\tAlt+U", IDM_SayUpperDiagnols }, -{"Say &Lower Diagnols\tAlt+L", IDM_SayLowerDiagnols }, +{"Say &Upper Diagonals\tAlt+U", IDM_SayUpperDiagnols }, +{"Say &Lower Diagonals\tAlt+L", IDM_SayLowerDiagnols }, {"Say K&night Moves\tAlt+N", IDM_SayKnightMoves }, {"Say Current &Square\tAlt+S", IDM_SayCurrentPos }, {"Say &Attacks\tAlt+A", IDM_PossibleAttackMove }, @@ -219,20 +225,19 @@ AdaptMenu() { HMENU menuMain, menuJAWS; MENUBARINFO helpMenuInfo; - int e, i; + int i; helpMenuInfo.cbSize = sizeof(helpMenuInfo); menuMain = GetMenu(hwndMain); - if(appData.debugMode) fprintf(debugFP, "hwndMain: %8x %8x\n", hwndMain, menuMain); menuJAWS = CreatePopupMenu(); - + for(i=0; menuItemJAWS[i].name; i++) { - if(menuItemJAWS[i].name[0] == '-') + if(menuItemJAWS[i].name[0] == '-') AppendMenu(menuJAWS, MF_SEPARATOR, (UINT_PTR) 0, NULL); - else AppendMenu(menuJAWS, MF_ENABLED|MF_STRING, + else AppendMenu(menuJAWS, MF_ENABLED|MF_STRING, (UINT_PTR) menuItemJAWS[i].code, (LPCTSTR) menuItemJAWS[i].name); } - InsertMenu(menuMain, 5, MF_BYPOSITION|MF_POPUP|MF_ENABLED|MF_STRING, + InsertMenu(menuMain, 5, MF_BYPOSITION|MF_POPUP|MF_ENABLED|MF_STRING, (UINT_PTR) menuJAWS, "&JAWS"); oldMenuItemState[6] = oldMenuItemState[5]; DrawMenuBar(hwndMain); @@ -243,7 +248,7 @@ InitJAWS() { // to be called at beginning of WinMain, after InitApplication and InitInstance HINSTANCE hApi = LoadLibrary("jfwapi32.dll"); if(!hApi) { - DisplayInformation("Missing jfwapi32.dll"); + DisplayInformation("Missing jfwapi32.dll"); return (FALSE); } @@ -275,47 +280,58 @@ InitJAWS() return TRUE; } +int beeps[] = { 1, 0, 0, 0, 0 }; +int beepCodes[] = { 0, MB_OK, MB_ICONERROR, MB_ICONQUESTION, MB_ICONEXCLAMATION, MB_ICONASTERISK }; +static int dropX = -1, dropY = -1; + VOID KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { ChessSquare currentPiece; char *piece, *xchar, *ynum ; - int n; + int n, beepType = 1; // empty beep + if(fromX == -1 || fromY == -1) { // if we just dropped piece, stay at that square + fromX = dropX; fromY = dropY; + dropX = dropY = -1; // but only once + } if(fromX == -1 || fromY == -1) { fromX = BOARD_LEFT; fromY = 0; } switch(wParam) { case VK_LEFT: if(fromX == BOARD_RGHT+1) fromX -= 2; else - if(fromX == BOARD_LEFT) { if(fromY >= BOARD_HEIGHT - gameInfo.holdingsSize) fromX -= 2; } else - if(fromX > BOARD_LEFT) fromX--; + if(fromX == BOARD_LEFT) { if(fromY >= BOARD_HEIGHT - gameInfo.holdingsSize) fromX -= 2; else beepType = 0; } else + if(fromX > BOARD_LEFT) fromX--; else beepType = 0; // off-board beep break; case VK_RIGHT: if(fromX == BOARD_LEFT-2) fromX += 2; else - if(fromX == BOARD_RGHT-1) { if(fromY < gameInfo.holdingsSize) fromX += 2; } else - if(fromX < BOARD_RGHT-1) fromX++; + if(fromX == BOARD_RGHT-1) { if(fromY < gameInfo.holdingsSize) fromX += 2; else beepType = 0; } else + if(fromX < BOARD_RGHT-1) fromX++; else beepType = 0; break; case VK_UP: - if(fromX == BOARD_RGHT+1) { if(fromY < gameInfo.holdingsSize - 1) fromY++; } else - if(fromY < BOARD_HEIGHT-1) fromY++; + if(fromX == BOARD_RGHT+1) { if(fromY < gameInfo.holdingsSize - 1) fromY++; else beepType = 0; } else + if(fromY < BOARD_HEIGHT-1) fromY++; else beepType = 0; break; case VK_DOWN: - if(fromX == BOARD_LEFT-2) { if(fromY > BOARD_HEIGHT - gameInfo.holdingsSize) fromY--; } else - if(fromY > 0) fromY--; + if(fromX == BOARD_LEFT-2) { if(fromY > BOARD_HEIGHT - gameInfo.holdingsSize) fromY--; else beepType = 0; } else + if(fromY > 0) fromY--; else beepType = 0; break; } SetHighlights(fromX, fromY, -1, -1); DrawPosition(FALSE, NULL); currentPiece = boards[currentMove][fromY][fromX]; piece = PieceToName(currentPiece,1); - if(currentPiece != EmptySquare) MessageBeep(currentPiece < (int)BlackPawn ? MB_OK : MB_ICONEXCLAMATION); + if(beepType == 1 && currentPiece != EmptySquare) beepType = currentPiece < (int) BlackPawn ? 2 : 3; // white or black beep + if(beeps[beepType] == beeps[1] && (fromX == BOARD_RGHT+1 || fromX == BOARD_LEFT-2)) beepType = 4; // holdings beep + beepType = beeps[beepType]%6; + if(beepType) MessageBeep(beepCodes[beepType]); if(fromX == BOARD_LEFT - 2) { SayString("black holdings", FALSE); if(currentPiece != EmptySquare) { char buf[MSG_SIZ]; n = boards[currentMove][fromY][1]; - sprintf(buf, "%d %s%s", n, piece+6, n == 1 ? "" : "s"); + snprintf(buf, MSG_SIZ, "%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s"); SayString(buf, TRUE); } } else @@ -324,7 +340,7 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if(currentPiece != EmptySquare) { char buf[MSG_SIZ]; n = boards[currentMove][fromY][BOARD_WIDTH-2]; - sprintf(buf, "%d %s%s", n, piece+6, n == 1 ? "" : "s"); + snprintf(buf, MSG_SIZ,"%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s"); SayString(buf, TRUE); } } else @@ -334,14 +350,13 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) ynum = SquareToNum(fromY); if(currentPiece != EmptySquare) { // SayString(piece[0] == 'W' ? "white" : "black", TRUE); - sprintf(buf, "%s %s %s", piece, xchar, ynum); - } else sprintf(buf, "%s %s", xchar, ynum); + snprintf(buf, MSG_SIZ, "%s %s %s", xchar, ynum, piece); + } else snprintf(buf, MSG_SIZ, "%s %s", xchar, ynum); SayString(buf, TRUE); } return; } -extern char castlingRights[MAX_MOVES][BOARD_SIZE]; int PosFlags(int nr); typedef struct { @@ -420,8 +435,7 @@ PossibleAttackMove() swapColor = piece < (int)BlackPawn && !WhiteOnMove(currentMove) || piece >= (int)BlackPawn && WhiteOnMove(currentMove); cl.count = 0; cl.rf = fromY; cl.ff = fromX; cl.rt = cl.ft = -1; - GenLegal(boards[currentMove], PosFlags(currentMove + swapColor), EP_NONE, - castlingRights[currentMove], ReadCallback, (VOIDSTAR) &cl); + GenLegal(boards[currentMove], PosFlags(currentMove + swapColor), ReadCallback, (VOIDSTAR) &cl); if(cl.count == 0) SayString("None", FALSE); boards[currentMove][fromY][fromX] = victim; // repair @@ -448,16 +462,14 @@ PossibleAttacked() victim = boards[currentMove][fromY][fromX]; // put dummy piece on target square, to activate Pawn captures boards[currentMove][fromY][fromX] = WhiteOnMove(currentMove) ? WhiteQueen : BlackQueen; cl.count = 0; cl.rt = fromY; cl.ft = fromX; cl.rf = cl.ff = -1; - GenLegal(boards[currentMove], PosFlags(currentMove+1), EP_NONE, - castlingRights[currentMove], ReadCallback, (VOIDSTAR) &cl); + GenLegal(boards[currentMove], PosFlags(currentMove+1), ReadCallback, (VOIDSTAR) &cl); if(cl.count == 0) SayString("None", FALSE); SayString("You are defended by", FALSE); boards[currentMove][fromY][fromX] = WhiteOnMove(currentMove) ? BlackQueen : WhiteQueen; cl.count = 0; cl.rt = fromY; cl.ft = fromX; cl.rf = cl.ff = -1; - GenLegal(boards[currentMove], PosFlags(currentMove), EP_NONE, - castlingRights[currentMove], ReadCallback, (VOIDSTAR) &cl); + GenLegal(boards[currentMove], PosFlags(currentMove), ReadCallback, (VOIDSTAR) &cl); if(cl.count == 0) SayString("None", FALSE); boards[currentMove][fromY][fromX] = victim; // put back original occupant @@ -469,15 +481,15 @@ PossibleAttacked() VOID ReadRow() { - ChessSquare currentpiece; + ChessSquare currentpiece; char *piece, *xchar, *ynum ; int xPos, count=0; ynum = SquareToNum(fromY); - + if(fromY < 0) return; for (xPos=BOARD_LEFT; xPos=BOARD_LEFT) { - currentpiece = boards[currentMove][yPos][xPos]; + currentpiece = boards[currentMove][yPos][xPos]; piece = PieceToName(currentpiece,1); xchar = SquareToChar(xPos); ynum = SquareToNum(yPos); @@ -570,10 +582,10 @@ SayUpperDiagnols() VOID SayLowerDiagnols() { - ChessSquare currentpiece; + ChessSquare currentpiece; char *piece, *xchar, *ynum ; int yPos, xPos; - + if(fromX < 0 || fromY < 0) return; if(fromX < BOARD_RGHT-1 && fromY > 0) { @@ -581,7 +593,7 @@ SayLowerDiagnols() yPos = fromY-1; xPos = fromX+1; while(yPos>=0 && xPos=0 && xPos>=BOARD_LEFT) { - currentpiece = boards[currentMove][yPos][xPos]; + currentpiece = boards[currentMove][yPos][xPos]; piece = PieceToName(currentpiece,1); xchar = SquareToChar(xPos); ynum = SquareToNum(yPos); @@ -616,11 +628,11 @@ SayLowerDiagnols() VOID SayKnightMoves() { - ChessSquare currentpiece, oldpiece; + ChessSquare currentpiece, oldpiece; char *piece, *xchar, *ynum ; oldpiece = boards[currentMove][fromY][fromX]; - if(oldpiece == WhiteKnight || oldpiece == BlackKnight) + if(oldpiece == WhiteKnight || oldpiece == BlackKnight) SayString("The possible squares a Knight could move to are", FALSE); else SayString("The squares a Knight could possibly attack from are", FALSE); @@ -654,7 +666,7 @@ SayKnightMoves() SayString(piece, FALSE); } } - + if (fromY+1 < BOARD_HEIGHT && fromX+2 < BOARD_RGHT) { currentpiece = boards[currentMove][fromY+1][fromX+2]; if(((oldpiece == WhiteKnight) && (currentpiece > WhiteKing)) @@ -669,7 +681,7 @@ SayKnightMoves() SayString(piece, FALSE); } } - + if (fromY-1 >= 0 && fromX+2 < BOARD_RGHT) { currentpiece = boards[currentMove][fromY-1][fromX+2]; if(((oldpiece == WhiteKnight) && (currentpiece > WhiteKing)) @@ -684,7 +696,7 @@ SayKnightMoves() SayString(piece, FALSE); } } - + if (fromY-2 >= 0 && fromX+1 < BOARD_RGHT) { currentpiece = boards[currentMove][fromY-2][fromX+1]; if(((oldpiece == WhiteKnight) && (currentpiece > WhiteKing)) @@ -699,7 +711,7 @@ SayKnightMoves() SayString(piece, FALSE); } } - + if (fromY-2 >= 0 && fromX-1 >= BOARD_LEFT) { currentpiece = boards[currentMove][fromY-2][fromX-1]; if(((oldpiece == WhiteKnight) && (currentpiece > WhiteKing)) @@ -714,7 +726,7 @@ SayKnightMoves() SayString(piece, FALSE); } } - + if (fromY-1 >= 0 && fromX-2 >= BOARD_LEFT) { currentpiece = boards[currentMove][fromY-1][fromX-2]; if(((oldpiece == WhiteKnight) && (currentpiece > WhiteKing)) @@ -729,7 +741,7 @@ SayKnightMoves() SayString(piece, FALSE); } } - + if (fromY+1 < BOARD_HEIGHT && fromX-2 >= BOARD_LEFT) { currentpiece = boards[currentMove][fromY+1][fromX-2]; if(((oldpiece == WhiteKnight) && (currentpiece > WhiteKing)) @@ -749,7 +761,7 @@ SayKnightMoves() VOID SayPieces(ChessSquare p) { - ChessSquare currentpiece; + ChessSquare currentpiece; char *piece, *xchar, *ynum ; int yPos, xPos, count = 0; char buf[50]; @@ -757,13 +769,13 @@ SayPieces(ChessSquare p) if(p == WhitePlay) SayString("White pieces", FALSE); else if(p == BlackPlay) SayString("Black pieces", FALSE); else if(p == EmptySquare) SayString("Pieces", FALSE); else { - sprintf(buf, "%ss", PieceToName(p,1)); + snprintf(buf, sizeof(buf)/sizeof(buf[0]),"%ss", PieceToName(p,1)); SayString(buf, FALSE); } SayString("are located", FALSE); for(yPos=0; yPos= BlackPawn && currentpiece <= BlackKing || p == WhitePlay && currentpiece >= WhitePawn && currentpiece <= WhiteKing ) piece = PieceToName(currentpiece,0); @@ -772,7 +784,7 @@ SayPieces(ChessSquare p) else if(p == currentpiece) piece = NULL; else continue; - + if(count == 0) SayString("at", FALSE); xchar = SquareToChar(xPos); ynum = SquareToNum(yPos); @@ -792,7 +804,7 @@ SayCurrentPos() char *piece, *xchar, *ynum ; if(fromX < BOARD_LEFT) { SayString("You strayed into the white holdings", FALSE); return; } if(fromX >= BOARD_RGHT) { SayString("You strayed into the black holdings", FALSE); return; } - currentpiece = boards[currentMove][fromY][fromX]; + currentpiece = boards[currentMove][fromY][fromX]; piece = PieceToName(currentpiece,1); ynum = SquareToNum(fromY); xchar = SquareToChar(fromX); @@ -802,7 +814,7 @@ SayCurrentPos() SayString(piece, FALSE); if(((fromX-BOARD_LEFT) ^ fromY)&1) SayString("on a light square",FALSE); - else + else SayString("on a dark square",FALSE); PossibleAttacked(); @@ -814,29 +826,33 @@ SayAllBoard() { int Xpos, Ypos; ChessSquare currentpiece; - char *piece, *xchar, *ynum ; - + char *piece, *ynum ; + if(gameInfo.holdingsWidth) { int first = 0; for(Ypos=0; Ypos=BOARD_HEIGHT - gameInfo.holdingsSize; Ypos--) { int n = boards[currentMove][Ypos][1]; - if(n) { char buf[MSG_SIZ]; - if(!first++) SayString("black holds", FALSE); - currentpiece = boards[currentMove][Ypos][0]; - piece = PieceToName(currentpiece,0); - sprintf(buf, "%d %s%s", n, piece, (n==1 ? "" : "s") ); - SayString(buf, FALSE); + if(n) { + char buf[MSG_SIZ]; + if(!first++) + SayString("black holds", FALSE); + currentpiece = boards[currentMove][Ypos][0]; + piece = PieceToName(currentpiece,0); + snprintf(buf, MSG_SIZ, "%d %s%s", n, piece, (n==1 ? "" : "s") ); + SayString(buf, FALSE); } } } @@ -846,16 +862,17 @@ SayAllBoard() SayString(ynum, FALSE); SayString("rank", FALSE); for(Xpos=BOARD_LEFT; Xpos 1) { - sprintf(buf, "%d %ss", count, piece); - } else sprintf(buf, "%s", piece); + if(count > 1) + snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%d %ss", count, piece); + else + snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%s", piece); Xpos--; SayString(buf, FALSE); } else { @@ -865,9 +882,9 @@ SayAllBoard() if(Xpos == BOARD_RGHT && oldX == BOARD_LEFT) SayString("all", FALSE); else{ - if(count > 1) { + if(count > 1) { char buf[10]; - sprintf(buf, "%d", count); + snprintf(buf, sizeof(buf)/sizeof(buf[0]),"%d", count); SayString(buf, FALSE); } Xpos--; @@ -876,34 +893,35 @@ SayAllBoard() } } } - + } VOID SayWhosTurn() { - if(gameMode == MachinePlaysBlack || gameMode == IcsPlayingBlack) { + if(gameMode == MachinePlaysBlack || gameMode == IcsPlayingWhite) { if(WhiteOnMove(currentMove)) SayString("It is your turn", FALSE); else SayString("It is your opponents turn", FALSE); - } else if(gameMode == MachinePlaysWhite || gameMode == IcsPlayingWhite) { + } else if(gameMode == MachinePlaysWhite || gameMode == IcsPlayingBlack) { if(WhiteOnMove(currentMove)) SayString("It is your opponents turn", FALSE); else SayString("It is your turn", FALSE); } else { - if(WhiteOnMove(currentMove)) + if(WhiteOnMove(currentMove)) SayString("White is on move here", FALSE); else SayString("Black is on move here", FALSE); } } - + +extern char *commentList[]; VOID SayMachineMove(int evenIfDuplicate) { int len, xPos, yPos, moveNr, secondSpace = 0, castle = 0, n; ChessSquare currentpiece; - char *piece, *xchar, *ynum, *p; + char *piece, *xchar, *ynum, *p, checkMark = 0; char c, buf[MSG_SIZ], comment[MSG_SIZ]; static char disambiguation[2]; static int previousMove = 0; @@ -934,15 +952,15 @@ SayMachineMove(int evenIfDuplicate) c = 'W'; break; case IcsPlayingBlack: case MachinePlaysBlack: - c = 'B'; + c = 'B'; default: break; } } - if(c != lastMover) return; // line is thinking output of future move, ignore. + if(c != lastMover && !evenIfDuplicate) return; // line is thinking output of future move, ignore. if(2*moveNr - (dotCount < 2) == previousMove) return; // do not repeat same move; likely ponder output - sprintf(buf, "score %s %d at %d ply", + snprintf(buf, MSG_SIZ, "score %s %d at %d ply", score > 0 ? "plus" : score < 0 ? "minus" : "", (int) (fabs(score)*100+0.5), depth ); @@ -959,6 +977,7 @@ SayMachineMove(int evenIfDuplicate) if(secondSpace) len = secondSpace; // position behind move if(messageText[len-1] == '+' || messageText[len-1] == '#') { /* you are in checkmate */ len--; // strip off check or mate indicator + checkMark = messageText[len]; // make sure still seen after we stip off promo piece } if(messageText[len-2] == '=') { /* promotion */ len-=2; // strip off promotion piece @@ -967,16 +986,16 @@ SayMachineMove(int evenIfDuplicate) n = 2*moveNr - (dotCount < 2); - if(previousMove != 2*moveNr + (dotCount > 1) || evenIfDuplicate) { + if(previousMove != 2*moveNr + (dotCount > 1) || evenIfDuplicate) { char number[20]; previousMove = 2*moveNr + (dotCount > 1); // remember move nr of move last spoken - sprintf(number, "%d", moveNr); + snprintf(number, sizeof(number)/sizeof(number[0]),"%d", moveNr); yPos = CoordToNum(messageText[len-1]); /* turn char coords to ints */ xPos = CoordToNum(messageText[len-2]); if(xPos < 0 || xPos > 11) return; // prevent crashes if no coord string available to speak if(yPos < 0 || yPos > 9) return; - currentpiece = boards[n][yPos][xPos]; + currentpiece = boards[n][yPos][xPos]; piece = PieceToName(currentpiece,0); ynum = SquareToNum(yPos); xchar = SquareToChar(xPos); @@ -1015,11 +1034,11 @@ SayMachineMove(int evenIfDuplicate) SayString(piece, FALSE); } else SayString("Capturing onn passann",FALSE); } - if(messageText[len] == '+') SayString("check", FALSE); else - if(messageText[len] == '#') { + } + if(checkMark == '+') SayString("check", FALSE); else + if(checkMark == '#') { SayString("finishing off", FALSE); SayString(WhiteOnMove(n) ? "White" : "Black", FALSE); - } } } @@ -1030,8 +1049,8 @@ SayMachineMove(int evenIfDuplicate) if(StrStr(messageText, " 1/2-1/2")) p = "game ends in a draw"; if(comment[0]) { if(p) { - if(!StrCaseStr(comment, "draw") && - !StrCaseStr(comment, "white") && + if(!StrCaseStr(comment, "draw") && + !StrCaseStr(comment, "white") && !StrCaseStr(comment, "black") ) { SayString(p, FALSE); SayString("due to", FALSE); @@ -1040,6 +1059,8 @@ SayMachineMove(int evenIfDuplicate) SayString(comment, FALSE); // alphabetic comment (usually game end) } else if(p) SayString(p, FALSE); + if(commentDialog && commentList[currentMove]) SetFocus(commentDialog); + } else { /* starts not with digit */ if(StrCaseStr(messageText, "illegal")) PlayIcsUnfinishedSound(); @@ -1058,13 +1079,13 @@ SayClockTime() suppressClocks = 1; // if user is using alt+T command, no reason to display them if(abs(lastWhiteTime - whiteTimeRemaining) < 1000 && abs(lastBlackTime - blackTimeRemaining) < 1000) suppressClocks = 0; // back on after two requests in rapid succession - sprintf(buf1, "%s", TimeString(whiteTimeRemaining)); + snprintf(buf1, sizeof(buf1)/sizeof(buf1[0]),"%s", TimeString(whiteTimeRemaining)); str1 = buf1; - SayString("White's remaining time is", FALSE); + SayString("White clock", FALSE); SayString(str1, FALSE); - sprintf(buf2, "%s", TimeString(blackTimeRemaining)); + snprintf(buf2, sizeof(buf2)/sizeof(buf2[0]), "%s", TimeString(blackTimeRemaining)); str2 = buf2; - SayString("Black's remaining time is", FALSE); + SayString("Black clock", FALSE); SayString(str2, FALSE); lastWhiteTime = whiteTimeRemaining; lastBlackTime = blackTimeRemaining; @@ -1085,7 +1106,7 @@ KeyboardMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { ChessSquare currentpiece; char *piece; - + static BOOLEAN sameAgain = FALSE; switch (message) { case WM_KEYDOWN: @@ -1096,11 +1117,11 @@ KeyboardMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) break; } else if(oldFromX != -1) { - + ChessSquare pdown, pup; pdown = boards[currentMove][oldFromY][oldFromX]; pup = boards[currentMove][fromY][fromX]; - + if (gameMode == EditPosition || !((WhitePawn <= pdown && pdown <= WhiteKing && WhitePawn <= pup && pup <= WhiteKing) || @@ -1108,8 +1129,9 @@ KeyboardMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) BlackPawn <= pup && pup <= BlackKing))) { /* EditPosition, empty square, or different color piece; click-click move is possible */ - - if (IsPromotion(oldFromX, oldFromY, fromX, fromY)) { + char promoChoice = NULLCHAR; + + if (HasPromotionChoice(oldFromX, oldFromY, fromX, fromY, &promoChoice)) { if (appData.alwaysPromoteToQueen) { UserMoveEvent(oldFromX, oldFromY, fromX, fromY, 'q'); } @@ -1117,21 +1139,21 @@ KeyboardMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) toX = fromX; toY = fromY; fromX = oldFromX; fromY = oldFromY; PromotionPopup(hwnd); fromX = toX; fromY = toY; - } + } } else { - UserMoveEvent(oldFromX, oldFromY, fromX, fromY, NULLCHAR); + UserMoveEvent(oldFromX, oldFromY, fromX, fromY, promoChoice); } oldFromX = oldFromY = -1; break; } - + } /* First downclick, or restart on a square with same color piece */ if (OKToStartUserMove(fromX, fromY)) { oldFromX = fromX; oldFromY = fromY; - currentpiece = boards[currentMove][fromY][fromX]; + currentpiece = boards[currentMove][fromY][fromX]; piece = PieceToName(currentpiece,1); SayString(piece, FALSE); SayString("selected", FALSE); @@ -1147,7 +1169,7 @@ KeyboardMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) if (sameAgain) { /* Clicked same square twice: abort click-click move */ oldFromX = oldFromY = -1; - currentpiece = boards[currentMove][fromY][fromX]; + currentpiece = boards[currentMove][fromY][fromX]; piece = PieceToName(currentpiece,0); SayString(piece, FALSE); SayString("unselected", FALSE); @@ -1167,12 +1189,12 @@ NiceTime(int x) return (x%3000 == 0); } -#if 0 - if(isalpha((char)wParam)) { - /* capitals of any ind are intercepted and distinguished by left and right shift */ - int mine = GetKeyState(VK_RSHIFT) < 0; - if(mine || GetKeyState(VK_LSHIFT) < 0) { -#endif +#define JAWS_ARGS \ + { "beepOffBoard", ArgInt, (LPVOID) beeps, TRUE, (ArgIniType) 1 },\ + { "beepEmpty", ArgInt, (LPVOID) (beeps+1), TRUE, (ArgIniType) 0 },\ + { "beepWhite", ArgInt, (LPVOID) (beeps+2), TRUE, (ArgIniType) 0 },\ + { "beepBlack", ArgInt, (LPVOID) (beeps+3), TRUE, (ArgIniType) 0 },\ + { "beepHoldings", ArgInt, (LPVOID) (beeps+4), TRUE, (ArgIniType) 0 },\ #define JAWS_ALT_INTERCEPT \ if(suppressOneKey) {\ @@ -1182,6 +1204,7 @@ NiceTime(int x) if ((char)wParam == 022 && gameMode == EditPosition) { /* . Pop up piece menu */\ POINT pt; int x, y;\ SquareToPos(fromY, fromX, &x, &y);\ + dropX = fromX; dropY = fromY;\ pt.x = x; pt.y = y;\ if(gameInfo.variant != VariantShogi)\ MenuPopup(hwnd, pt, LoadMenu(hInst, "PieceMenu"), -1);\