X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fjaws.c;h=f488039c7aad2b640a1ddf8024fae9ac753252b4;hb=a009a27e8c1e0bfa818f12fdcae675d0babc510a;hp=2810e2ea2987fd2803e81458f920b8212d98e5d4;hpb=0db7cb3a6d76078255f3d19cb8364ce3dc536458;p=xboard.git diff --git a/winboard/jaws.c b/winboard/jaws.c index 2810e2e..f488039 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, 2011, 2012, 2013 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. @@ -60,19 +60,28 @@ // BOARD_LEFT as 0, BOARD_RGHT and BOARD_HEIGHT as 8, and set holdingssizes to 0. // You will need to build with jaws.rc in stead of winboard.rc. -// from common.h, but 'extern' added to it, so the actual declaraton can remain in backend.c - -extern long whiteTimeRemaining, blackTimeRemaining, timeControl, timeIncrement; +// from resource.h + +#define IDM_PossibleAttackMove 1800 +#define IDM_PossibleAttacked 1801 +#define IDM_SayMachineMove 1802 +#define IDM_ReadRow 1803 +#define IDM_ReadColumn 1804 +#define IDM_SayCurrentPos 1805 +#define IDM_SayAllBoard 1806 +#define IDM_SayUpperDiagnols 1807 +#define IDM_SayLowerDiagnols 1808 +#define IDM_SayClockTime 1810 +#define IDM_SayWhosTurn 1811 +#define IDM_SayKnightMoves 1812 +#define ID_SHITTY_HI 1813 +#define IDM_SayWhitePieces 1816 +#define IDM_SayBlackPieces 1817 -#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)); +// from common.h, but 'extern' added to it, so the actual declaraton can remain in backend.c -#endif +extern long whiteTimeRemaining, blackTimeRemaining, timeControl, timeIncrement; // from moves.c, added WinBoard_F piece types and ranks / files @@ -83,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", @@ -98,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; { @@ -111,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) @@ -128,9 +153,8 @@ char* SquareToNum(y) // from winboard.c: all new routines - -#include "jfwapi.h" -#include "jaws.h" +#define JFWAPI __declspec(dllimport) +JFWAPI BOOL WINAPI JFWSayString (LPCTSTR lpszStrinToSpeak, BOOL bInterrupt); typedef JFWAPI BOOL (WINAPI *PSAYSTRING)(LPCTSTR lpszStrinToSpeak, BOOL bInterrupt); @@ -138,15 +162,20 @@ PSAYSTRING RealSayString; VOID SayString(char *mess, BOOL flag) { // for debug file - char buf[MSG_SIZ], *p; + static char buf[8000], *p; + int l = strlen(buf); if(appData.debugMode) fprintf(debugFP, "SAY '%s'\n", mess); - strcpy(buf, mess); + if(l) buf[l++] = ' '; // separate by space from previous + safeStrCpy(buf+l, _(mess), 8000-1-l); // buffer + if(!flag) return; // wait for flush if(p = StrCaseStr(buf, "Xboard adjudication:")) { int i; for(i=19; i>1; i--) p[i] = p[i-1]; p[1] = ' '; } - RealSayString(buf, flag); + RealSayString(buf, !strcmp(mess, " ")); // kludge to indicate flushing of interruptable speach + if(appData.debugMode) fprintf(debugFP, "SPEAK '%s'\n", buf); + buf[0] = NULLCHAR; } //static int fromX = 0, fromY = 0; @@ -154,13 +183,77 @@ static int oldFromX, oldFromY; static int timeflag; static int suppressClocks = 0; static int suppressOneKey = 0; +static HANDLE hAccelJAWS; + +typedef struct { char *name; int code; } MenuItemDesc; + +MenuItemDesc menuItemJAWS[] = { +{"Say Clock &Time\tAlt+T", IDM_SayClockTime }, +{"-", 0 }, +{"Say Last &Move\tAlt+M", IDM_SayMachineMove }, +{"Say W&ho's Turn\tAlt+X", IDM_SayWhosTurn }, +{"-", 0 }, +{"Say Complete &Position\tAlt+P",IDM_SayAllBoard }, +{"Say &White Pieces\tAlt+W", IDM_SayWhitePieces }, +{"Say &Black Pieces\tAlt+B", IDM_SayBlackPieces }, +{"Say Board &Rank\tAlt+R", IDM_ReadRow }, +{"Say Board &File\tAlt+F", IDM_ReadColumn }, +{"-", 0 }, +{"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 }, +{"Say Attacke&d\tAlt+D", IDM_PossibleAttacked }, +{NULL, 0} +}; + +ACCEL acceleratorsJAWS[] = { +{FVIRTKEY|FALT, 'T', IDM_SayClockTime }, +{FVIRTKEY|FALT, 'M', IDM_SayMachineMove }, +{FVIRTKEY|FALT, 'X', IDM_SayWhosTurn }, +{FVIRTKEY|FALT, 'P', IDM_SayAllBoard }, +{FVIRTKEY|FALT, 'W', IDM_SayWhitePieces }, +{FVIRTKEY|FALT, 'B', IDM_SayBlackPieces }, +{FVIRTKEY|FALT, 'R', IDM_ReadRow }, +{FVIRTKEY|FALT, 'F', IDM_ReadColumn }, +{FVIRTKEY|FALT, 'U', IDM_SayUpperDiagnols }, +{FVIRTKEY|FALT, 'L', IDM_SayLowerDiagnols }, +{FVIRTKEY|FALT, 'N', IDM_SayKnightMoves }, +{FVIRTKEY|FALT, 'S', IDM_SayCurrentPos }, +{FVIRTKEY|FALT, 'A', IDM_PossibleAttackMove }, +{FVIRTKEY|FALT, 'D', IDM_PossibleAttacked } +}; + +void +AdaptMenu() +{ + HMENU menuMain, menuJAWS; + MENUBARINFO helpMenuInfo; + int i; + + helpMenuInfo.cbSize = sizeof(helpMenuInfo); + menuMain = GetMenu(hwndMain); + menuJAWS = CreatePopupMenu(); + + for(i=0; menuItemJAWS[i].name; i++) { + if(menuItemJAWS[i].name[0] == '-') + AppendMenu(menuJAWS, MF_SEPARATOR, (UINT_PTR) 0, NULL); + else AppendMenu(menuJAWS, MF_ENABLED|MF_STRING, + (UINT_PTR) menuItemJAWS[i].code, (LPCTSTR) _(menuItemJAWS[i].name)); + } + InsertMenu(menuMain, 7, MF_BYPOSITION|MF_POPUP|MF_ENABLED|MF_STRING, + (UINT_PTR) menuJAWS, "&JAWS"); + oldMenuItemState[8] = oldMenuItemState[7]; + DrawMenuBar(hwndMain); +} BOOL 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); } @@ -171,20 +264,17 @@ InitJAWS() } { - // [HGM] kludge to reduce need for modification of winboard.c: mak tinyLayout menu identical + // [HGM] kludge to reduce need for modification of winboard.c: make tinyLayout menu identical // to standard layout, so that code for switching between them does not have to be deleted - HMENU hmenu = GetMenu(hwndMain); int i; - menuBarText[0][5] = "&JAWS"; - for(i=0; i<7; i++) menuBarText[1][i] = menuBarText[0][i]; - for (i=0; menuBarText[tinyLayout][i]; i++) { - ModifyMenu(hmenu, i, MF_STRING|MF_BYPOSITION|MF_POPUP, - (UINT)GetSubMenu(hmenu, i), menuBarText[tinyLayout][i]); - } - DrawMenuBar(hwndMain); + AdaptMenu(); + menuBarText[0][8] = menuBarText[0][7]; menuBarText[0][7] = "&JAWS"; + for(i=0; i<9; i++) menuBarText[1][i] = menuBarText[0][i]; } + hAccelJAWS = CreateAcceleratorTable(acceleratorsJAWS, 14); + /* initialize cursor position */ fromX = fromY = 0; SetHighlights(fromX, fromY, -1, -1); @@ -195,73 +285,85 @@ 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"); - SayString(buf, TRUE); + snprintf(buf, MSG_SIZ, "%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s"); + SayString(buf, FALSE); } + SayString(" ", TRUE); } else if(fromX == BOARD_RGHT + 1) { SayString("white holdings", FALSE); 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"); - SayString(buf, TRUE); + snprintf(buf, MSG_SIZ,"%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s"); + SayString(buf, FALSE); } + SayString(" ", TRUE); } else if(fromX >= BOARD_LEFT && fromX < BOARD_RGHT) { char buf[MSG_SIZ]; xchar = SquareToChar(fromX); 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); - SayString(buf, TRUE); + snprintf(buf, MSG_SIZ, "%s %s %s", xchar, ynum, piece); + } else snprintf(buf, MSG_SIZ, "%s %s", xchar, ynum); + SayString(buf, FALSE); + SayString(" ", TRUE); } return; } -extern char castlingRights[MAX_MOVES][BOARD_SIZE]; int PosFlags(int nr); typedef struct { @@ -319,7 +421,7 @@ PossibleAttackMove() //if(appData.debugMode) fprintf(debugFP, "PossibleAttackMove %d %d %d %d\n", fromX, fromY, oldFromX, oldFromY); if(fromY < 0 || fromY >= BOARD_HEIGHT) return; - if(fromX < BOARD_LEFT || fromX >= BOARD_RGHT) { SayString("holdings",FALSE); return; } + if(fromX < BOARD_LEFT || fromX >= BOARD_RGHT) { SayString("holdings",TRUE); return; } piece = boards[currentMove][fromY][fromX]; if(piece == EmptySquare) { // if square is empty, try to substitute selected piece @@ -330,7 +432,7 @@ PossibleAttackMove() SayString("Your", FALSE); SayString(PieceToName(piece, 0), FALSE); SayString("would have", FALSE); - } else { SayString("You must select a piece first", FALSE); return; } + } else { SayString("You must select a piece first", TRUE); return; } } victim = boards[currentMove][fromY][fromX]; @@ -340,9 +442,9 @@ 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); + SayString("", TRUE); // flush boards[currentMove][fromY][fromX] = victim; // repair if( removedSelectedPiece ) boards[currentMove][oldFromY][oldFromX] = piece; @@ -356,7 +458,7 @@ PossibleAttacked() ChessSquare piece = EmptySquare, victim; if(fromY < 0 || fromY >= BOARD_HEIGHT) return; - if(fromX < BOARD_LEFT || fromX >= BOARD_RGHT) { SayString("holdings",FALSE); return; } + if(fromX < BOARD_LEFT || fromX >= BOARD_RGHT) { SayString("holdings",TRUE); return; } if(oldFromX >= 0 && oldFromY >= 0) { // if piece is selected, remove it piece = boards[currentMove][oldFromY][oldFromX]; @@ -368,17 +470,16 @@ 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); + SayString("", TRUE); // flush boards[currentMove][fromY][fromX] = victim; // put back original occupant if(oldFromX >= 0 && oldFromY >= 0) { // put back possibl selected piece @@ -389,15 +490,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); @@ -485,15 +588,16 @@ SayUpperDiagnols() } } else SayString("There is no squares to your upper left", FALSE); + SayString("", TRUE); // flush } 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) { @@ -501,7 +605,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); @@ -531,16 +635,17 @@ SayLowerDiagnols() } } else SayString("There is no squares to your lower left", FALSE); + SayString("", TRUE); // flush } 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); @@ -574,7 +679,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)) @@ -589,7 +694,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)) @@ -604,7 +709,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)) @@ -619,7 +724,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)) @@ -634,7 +739,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)) @@ -649,7 +754,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)) @@ -664,12 +769,13 @@ SayKnightMoves() SayString(piece, FALSE); } } + SayString("", TRUE); // flush } VOID SayPieces(ChessSquare p) { - ChessSquare currentpiece; + ChessSquare currentpiece; char *piece, *xchar, *ynum ; int yPos, xPos, count = 0; char buf[50]; @@ -677,13 +783,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); @@ -692,7 +798,7 @@ SayPieces(ChessSquare p) else if(p == currentpiece) piece = NULL; else continue; - + if(count == 0) SayString("at", FALSE); xchar = SquareToChar(xPos); ynum = SquareToNum(yPos); @@ -703,6 +809,7 @@ SayPieces(ChessSquare p) } } if(count == 0) SayString("nowhere", FALSE); + SayString("", TRUE); // flush } VOID @@ -712,7 +819,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); @@ -720,13 +827,13 @@ SayCurrentPos() SayString(xchar, FALSE); SayString(ynum, FALSE); SayString(piece, FALSE); - if((fromX-BOARD_LEFT) ^ fromY) - SayString("on a dark square",FALSE); - else + if(((fromX-BOARD_LEFT) ^ fromY)&1) SayString("on a light square",FALSE); + else + SayString("on a dark square",FALSE); PossibleAttacked(); - return; + SayString("", TRUE); // flush } VOID @@ -734,29 +841,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); } } } @@ -766,16 +877,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 { @@ -785,9 +897,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--; @@ -796,34 +908,36 @@ SayAllBoard() } } } - + SayString("", TRUE); // flush } 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); } + SayString("", TRUE); // flush } - + +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; @@ -854,15 +968,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 ); @@ -879,6 +993,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 @@ -887,16 +1002,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); @@ -935,11 +1050,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); - } } } @@ -950,8 +1065,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); @@ -960,12 +1075,15 @@ 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(); SayString(messageText, FALSE); } + SayString("", TRUE); // flush } VOID @@ -978,16 +1096,17 @@ 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; + SayString("", TRUE); // flush } VOID @@ -997,6 +1116,7 @@ Toggle(Boolean *b, char *mess) SayString(mess, FALSE); SayString("is now", FALSE); SayString(*b ? "on" : "off", FALSE); + SayString("", TRUE); // flush } /* handles keyboard moves in a click-click fashion */ @@ -1005,7 +1125,7 @@ KeyboardMove(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { ChessSquare currentpiece; char *piece; - + static BOOLEAN sameAgain = FALSE; switch (message) { case WM_KEYDOWN: @@ -1016,11 +1136,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) || @@ -1028,8 +1148,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'); } @@ -1037,24 +1158,24 @@ 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); + SayString("selected", TRUE); } else { oldFromX = oldFromY = -1; @@ -1067,10 +1188,10 @@ 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); + SayString("unselected", TRUE); } } } @@ -1087,12 +1208,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) {\ @@ -1102,6 +1223,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);\ @@ -1114,13 +1236,12 @@ NiceTime(int x) case '\020': /* ctrl P */\ { char buf[MSG_SIZ];\ if(GetWindowText(hwnd, buf, MSG_SIZ-1))\ - SayString(buf, FALSE);\ + SayString(buf, TRUE);\ }\ return 0;\ -#define JAWS_KB_NAVIGATION \ +#define JAWS_KBDOWN_NAVIGATION \ \ - case WM_KEYDOWN:\ \ if(GetKeyState(VK_MENU) < 0 && GetKeyState(VK_CONTROL) < 0) {\ /* Control + Alt + letter used for speaking piece positions */\ @@ -1153,17 +1274,17 @@ NiceTime(int x) KeyboardEvent(hwnd, message, wParam, lParam);\ break;\ case VK_SPACE:\ + shiftKey = GetKeyState(VK_SHIFT) < 0;\ KeyboardMove(hwnd, message, wParam, lParam);\ break;\ }\ - break;\ - case WM_KEYUP:\ + +#define JAWS_KBUP_NAVIGATION \ switch (wParam) {\ case VK_SPACE:\ KeyboardMove(hwnd, message, wParam, lParam);\ break;\ }\ - break;\ #define JAWS_MENU_ITEMS \ case IDM_PossibleAttackMove: /*What can I possible attack from here */\ @@ -1258,23 +1379,21 @@ NiceTime(int x) \ +#define JAWS_ACCEL \ + !(!frozen && TranslateAccelerator(hwndMain, hAccelJAWS, &msg)) && + #define JAWS_INIT if (!InitJAWS()) return (FALSE); #define JAWS_DELETE(X) #define JAWS_SILENCE if(suppressClocks) return; -#define SAY(S) SayString((S), FALSE) +#define JAWS_COPYRIGHT \ + SetDlgItemText(hDlg, OPT_MESS, "Auditory/Keyboard Enhancements By: Ed Rodriguez (sort of)"); + +#define SAY(S) SayString((S), TRUE) #define SAYMACHINEMOVE() SayMachineMove(0) // After inclusion of this file somewhere early in winboard.c, the remaining part of the patch // is scattered over winboard.c for actually calling the routines. -// -// * move fromX, fromY declaration to front, before incusion of this file. (Can be permanent change in winboard.c.) -// * call InitJAWS(), after calling InitIntance(). (Using JAWS_INIT macro) -// * add keyboard cases in main switch of WndProc, though JAWS_KB_NAVIGATION above, e.g. before WM_CHAR case. -// * change the WM_CHAR case of same switch from "if(appData.icsActive)" to "if(appData.icsActive JAWS_IF_TAB)" -// * add new menu cases in WM_COMMAND case of WndProc, e.g. before IDM_Forward. (throug macro defined above) -// * add SAYMACHINEMOVE(); at the end of DisplayMessage(); -// * add SAY("board"); in WM_CHAR case of ConsoleTextSubclass, just before "SetFocus(buttondesc..."