book.o \
commondsp.o \
@CURSESDSP@ \
- dspwrappers.o \
eval.o \
genmove.o \
init.o \
cursesdsp.o: cursesdsp.c
$(CC) $(CFLAGS) -c $<
-dspwrappers.o: dspwrappers.c
- $(CC) $(CFLAGS) -c $<
-
genmove.o: genmove.c
$(CC) $(CFLAGS) -c $<
book.o: book.c gnushogi.h
commondsp.o: commondsp.c gnushogi.h
cursesdsp.o: cursesdsp.c gnushogi.h
-dspwrappers.o: dspwrappers.c gnushogi.h
genmove.o: genmove.c gnushogi.h
globals.o: globals.c gnushogi.h
eval.o: eval.c eval.h gnushogi.h $(SRCDIR)/pattern.h
init.o: init.c gnushogi.h $(SRCDIR)/pattern.h
+init-common.o: init-common.c gnushogi.h
main.o: main.c gnushogi.h
makepattern.o: pattern.c gnushogi.h $(SRCDIR)/pattern.h
pattern.o: pattern.c gnushogi.h $(SRCDIR)/pattern.h pattern.inc
}
sprintf(msg, "Book used %d(%d).", B.bookcount, B.booksize);
- ShowMessage(msg);
+ dsp->ShowMessage(msg);
}
/* Set everything back to start the game. */
/* Now get ready to play .*/
if (!B.bookcount)
{
- ShowMessage("Can't find book.");
+ dsp->ShowMessage("Can't find book.");
Book = 0;
}
}
char mvstr[4][6];
char *InPtr;
int InBackground = false;
+struct display *dsp = &raw_display;
#if defined(BOOKTEST)
if ((f == t) && ((f != 0) || (t != 0)))
{
if (!barebones) {
- Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
+ dsp->Printf("error in algbr: FROM=TO=%d, flag=0x%4x\n", t, flag);
}
mvstr[0][0] = mvstr[1][0] = mvstr[2][0] = mvstr[3][0] = '\0';
if (SqAttacked(PieceList[opponent][0], computer, &blocked))
{
UnmakeMove(opponent, &xnode, &tempb, &tempc, &tempsf, &tempst);
- AlwaysShowMessage("Illegal move (in check) %s", s);
+ dsp->AlwaysShowMessage("Illegal move (in check) %s", s);
return false;
}
else
if (iop == VERIFY_AND_TRY_MODE)
return true;
- UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
+ dsp->UpdateDisplay(xnode.f, xnode.t, 0, (short) xnode.flags);
GameList[GameCnt].depth = GameList[GameCnt].score = 0;
GameList[GameCnt].nodes = 0;
ElapsedTime(COMPUTE_AND_INIT_MODE);
char buf[20];
sprintf(buf, "%s mates!\n", ColorStr[opponent]);
- ShowMessage(buf);
+ dsp->ShowMessage(buf);
flag.mate = true;
}
}
}
}
- AlwaysShowMessage("Illegal move (no match) %s", s);
+ dsp->AlwaysShowMessage("Illegal move (no match) %s", s);
if (!barebones && (cnt > 1))
{
sprintf(buffer, "Ambiguous Move %s!", s);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
}
return false;
}
+void RequestInputString(char* buffer, unsigned bufsize)
+{
+ static char fmt[10];
+ int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
+ if (ret < 0 ) {
+ perror("RequestInputString snprintf");
+ exit(1);
+ }
+ if (ret >= sizeof(fmt)) {
+ fprintf(stderr,
+ "Insufficient format-buffer size in %s for bufsize=%u\n",
+ __FUNCTION__, bufsize);
+ exit(1);
+ }
+ dsp->doRequestInputString(fmt, buffer);
+}
+
void
GetGame(void)
if (savefile[0]) {
strcpy(fname, savefile);
} else {
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
}
ZeroRPT();
InitializeStats();
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
Sdepth = 0;
hint = 0;
}
if (savefile[0]) {
strcpy(fname, savefile);
} else {
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
}
fclose(fd);
- ShowMessage("Game saved");
+ dsp->ShowMessage("Game saved");
}
else
{
- ShowMessage("Could not open file");
+ dsp->ShowMessage("Could not open file");
}
}
short sq;
short side, isp;
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
if (fname[0] == '\0')
Game50 = 1;
ZeroRPT();
InitializeStats();
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
Sdepth = 0;
hint = 0;
}
short sq, piece;
short side, isp;
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
if (fname[0] == '\0')
strcpy(fname, savefile);
} else {
/* Enter file name */
- ShowMessage("Enter file name: ");
+ dsp->ShowMessage("Enter file name: ");
RequestInputString(fname, sizeof(fname)-1);
}
fclose(fd);
- ShowMessage("Game saved");
+ dsp->ShowMessage("Game saved");
}
else
{
- ShowMessage("Could not open file");
+ dsp->ShowMessage("Could not open file");
}
}
flag.mate = false;
Sdepth = 0;
player = player ^ 1;
- ShowSidetoMove();
- UpdateDisplay(0, 0, 1, 0);
+ dsp->ShowSidetoMove();
+ dsp->UpdateDisplay(0, 0, 1, 0);
if (flag.regularstart)
Book = false;
else
et = 1;
- ShowNodeCnt(cnt);
+ dsp->ShowNodeCnt(cnt);
}
else
et = 1;
- ShowNodeCnt(cnt);
+ dsp->ShowNodeCnt(cnt);
}
#if !defined NOPOST
if (flag.post)
- GiveHint();
+ dsp->GiveHint();
#endif
/* do the hint move */
Sdepth = 0;
#ifdef QUIETBACKGROUND
- ShowPrompt();
+ dsp->ShowPrompt();
have_shown_prompt = true;
#endif /* QUIETBACKGROUND */
{
#endif /* QUIETBACKGROUND */
- ShowPrompt();
+ dsp->ShowPrompt();
#ifdef QUIETBACKGROUND
}
if (NOT_CURSES)
s[0] = '\0';
- eof = GetString(sx);
+ eof = dsp->GetString(sx);
} else {
strcpy(sx, command);
done = true;
sscanf(sx, "%s", s);
if (eof)
- ExitShogi();
+ dsp->ExitShogi();
if (s[0] == '\0')
continue;
if (old_xshogi)
display_type = DISPLAY_RAW;
- ClearScreen();
- UpdateDisplay(0, 0, 1, 0);
+ dsp->ClearScreen();
+ dsp->UpdateDisplay(0, 0, 1, 0);
if (old_xshogi)
display_type = DISPLAY_X;
else if ((strcmp(s, "set") == 0)
|| (strcmp(s, "edit") == 0))
{
- EditBoard();
+ dsp->EditBoard();
}
else if ((strcmp(s, "setup") == 0))
{
- SetupBoard();
+ dsp->SetupBoard();
}
else if (strcmp(s, "first") == 0)
{
}
else if (strcmp(s, "help") == 0)
{
- help();
+ dsp->help();
}
else if (strcmp(s, "material") == 0)
{
else if (strcmp(s, "new") == 0)
{
NewGame();
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
}
else if (strcmp(s, "list") == 0)
{
else if ((strcmp(s, "level") == 0)
|| (strcmp(s, "clock") == 0))
{
- SelectLevel(sx);
+ dsp->SelectLevel(sx);
}
else if (strcmp(s, "hash") == 0)
{
}
else if (strcmp(s, "Awindow") == 0)
{
- ChangeAlphaWindow();
+ dsp->ChangeAlphaWindow();
}
else if (strcmp(s, "Bwindow") == 0)
{
- ChangeBetaWindow();
+ dsp->ChangeBetaWindow();
}
else if (strcmp(s, "rcptr") == 0)
{
}
else if (strcmp(s, "hint") == 0)
{
- GiveHint();
+ dsp->GiveHint();
}
else if (strcmp(s, "both") == 0)
{
else if (strcmp(s, "reverse") == 0)
{
flag.reverse = !flag.reverse;
- ClearScreen();
- UpdateDisplay(0, 0, 1, 0);
+ dsp->ClearScreen();
+ dsp->UpdateDisplay(0, 0, 1, 0);
}
else if (strcmp(s, "switch") == 0)
{
}
else if (strcmp(s, "depth") == 0)
{
- ChangeSearchDepth();
+ dsp->ChangeSearchDepth();
}
else if (strcmp(s, "hashdepth") == 0)
{
- ChangeHashDepth();
+ dsp->ChangeHashDepth();
}
else if (strcmp(s, "random") == 0)
{
}
else if (strcmp(s, "contempt") == 0)
{
- SetContempt();
+ dsp->SetContempt();
}
else if (strcmp(s, "xwndw") == 0)
{
- ChangeXwindow();
+ dsp->ChangeXwindow();
}
else if (strcmp(s, "rv") == 0)
{
flag.rv = !flag.rv;
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
}
else if (strcmp(s, "coords") == 0)
{
flag.coords = !flag.coords;
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
}
else if (strcmp(s, "stars") == 0)
{
flag.stars = !flag.stars;
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
}
else if (!XSHOGI && strcmp(s, "moves") == 0)
{
#endif
SwagHt = 0;
- ShowMessage("Testing MoveList Speed");
+ dsp->ShowMessage("Testing MoveList Speed");
temp = generate_move_flags;
generate_move_flags = true;
TestSpeed(MoveList, 1);
generate_move_flags = temp;
- ShowMessage("Testing CaptureList Speed");
+ dsp->ShowMessage("Testing CaptureList Speed");
TestSpeed(CaptureList, 1);
- ShowMessage("Testing Eval Speed");
+ dsp->ShowMessage("Testing Eval Speed");
ExaminePosition(opponent);
TestPSpeed(ScorePosition, 1);
}
else if (!XSHOGI && strcmp(s, "test") == 0)
{
#ifdef SLOW_CPU
- ShowMessage("Testing MoveList Speed");
+ dsp->ShowMessage("Testing MoveList Speed");
TestSpeed(MoveList, 2000);
- ShowMessage("Testing CaptureList Speed");
+ dsp->ShowMessage("Testing CaptureList Speed");
TestSpeed(CaptureList, 3000);
- ShowMessage("Testing Eval Speed");
+ dsp->ShowMessage("Testing Eval Speed");
ExaminePosition(opponent);
TestPSpeed(ScorePosition, 1500);
#else
- ShowMessage("Testing MoveList Speed");
+ dsp->ShowMessage("Testing MoveList Speed");
TestSpeed(MoveList, 20000);
- ShowMessage("Testing CaptureList Speed");
+ dsp->ShowMessage("Testing CaptureList Speed");
TestSpeed(CaptureList, 30000);
- ShowMessage("Testing Eval Speed");
+ dsp->ShowMessage("Testing Eval Speed");
ExaminePosition(opponent);
TestPSpeed(ScorePosition, 15000);
#endif
}
else if (!XSHOGI && strcmp(s, "p") == 0)
{
- ShowPostnValues();
+ dsp->ShowPostnValues();
}
else if (!XSHOGI && strcmp(s, "debug") == 0)
{
- DoDebug();
+ dsp->DoDebug();
}
else
{
if (rpt >= 3)
{
DRAW = DRAW_REPETITION;
- ShowMessage(DRAW);
+ dsp->ShowMessage(DRAW);
GameList[GameCnt].flags |= draw;
flag.mate = true;
et = 0;
ElapsedTime(COMPUTE_AND_INIT_MODE);
}
-
#include <curses.h>
#include "gnushogi.h"
-#include "cursesdsp.h"
#if HAVE_UNISTD_H
#include <unistd.h>
int MSCORE;
char *DRAW;
-/* Forward declarations. */
-/* FIXME: change this name, puh-leeze! */
+/****************************************
+ * forward declarations
+ ****************************************/
+/* FIXME: change this name, puh-leeze! */
static void UpdateCatched(void);
static void DrawPiece(short sq);
static void ShowScore(short score);
+void Curses_UpdateDisplay(short f, short t, short redraw, short isspec);
+void Curses_Die(int sig);
/****************************************
* Trivial output functions.
void
-Curses_AlwaysShowMessage(const char *format, va_list ap)
+Curses_AlwaysShowMessage(const char *format, ...)
{
static char buffer[60];
+ va_list ap;
+ va_start(ap, format);
vsnprintf(buffer, sizeof(buffer), format, ap);
Curses_ShowMessage(buffer);
+ va_end(ap);
}
void
-Curses_Printf(const char *format, va_list ap)
+Curses_Printf(const char *format, ...)
{
static char buffer[60];
+ va_list ap;
+ va_start(ap, format);
vsnprintf(buffer, sizeof(buffer), format, ap);
printw("%s", buffer);
+ va_end(ap);
}
t = (l + h) >> 1;
}
- ShowNodeCnt(NodeCnt);
+ Curses_ShowNodeCnt(NodeCnt);
gotoXY(TAB, 23);
printw("Max Tree = %5d", t);
ClearEoln();
printw("%d:%02d ", m, s);
if (flag.post)
- ShowNodeCnt(NodeCnt);
+ Curses_ShowNodeCnt(NodeCnt);
refresh();
}
{
Curses_ShowMessage("'setup' command is not supported in Cursesmode");
}
+
+
+struct display curses_display =
+{
+ .ChangeAlphaWindow = Curses_ChangeAlphaWindow,
+ .ChangeBetaWindow = Curses_ChangeBetaWindow,
+ .ChangeHashDepth = Curses_ChangeHashDepth,
+ .ChangeSearchDepth = Curses_ChangeSearchDepth,
+ .ChangeXwindow = Curses_ChangeXwindow,
+ .ClearScreen = Curses_ClearScreen,
+ .DoDebug = Curses_DoDebug,
+ .DoTable = Curses_DoTable,
+ .EditBoard = Curses_EditBoard,
+ .ExitShogi = Curses_ExitShogi,
+ .GiveHint = Curses_GiveHint,
+ .Initialize = Curses_Initialize,
+ .ShowNodeCnt = Curses_ShowNodeCnt,
+ .OutputMove = Curses_OutputMove,
+ .PollForInput = Curses_PollForInput,
+ .SetContempt = Curses_SetContempt,
+ .SearchStartStuff = Curses_SearchStartStuff,
+ .SelectLevel = Curses_SelectLevel,
+ .ShowCurrentMove = Curses_ShowCurrentMove,
+ .ShowDepth = Curses_ShowDepth,
+ .ShowGameType = Curses_ShowGameType,
+ .ShowLine = Curses_ShowLine,
+ .ShowMessage = Curses_ShowMessage,
+ .AlwaysShowMessage = Curses_AlwaysShowMessage,
+ .Printf = Curses_Printf,
+ .doRequestInputString = Curses_doRequestInputString,
+ .GetString = Curses_GetString,
+ .SetupBoard = Curses_SetupBoard,
+ .ShowPatternCount = Curses_ShowPatternCount,
+ .ShowPostnValue = Curses_ShowPostnValue,
+ .ShowPostnValues = Curses_ShowPostnValues,
+ .ShowPrompt = Curses_ShowPrompt,
+ .ShowResponseTime = Curses_ShowResponseTime,
+ .ShowResults = Curses_ShowResults,
+ .ShowSidetoMove = Curses_ShowSidetoMove,
+ .ShowStage = Curses_ShowStage,
+ .TerminateSearch = Curses_TerminateSearch,
+ .UpdateClocks = Curses_UpdateClocks,
+ .UpdateDisplay = Curses_UpdateDisplay,
+ .help = Curses_help,
+};
+++ /dev/null
-/*
- * FILE: cursesdsp.h
- *
- * Curses interface for GNU Shogi.
- *
- * ----------------------------------------------------------------------
- * Copyright (c) 1993, 1994, 1995 Matthias Mutz
- * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
- *
- * GNU SHOGI is based on GNU CHESS
- *
- * Copyright (c) 1988, 1989, 1990 John Stanback
- * Copyright (c) 1992 Free Software Foundation
- *
- * This file is part of GNU SHOGI.
- *
- * GNU Shogi is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 3 of the License,
- * or (at your option) any later version.
- *
- * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with GNU Shogi; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-#ifndef _CURSESDSP_H_
-#define _CURSESDSP_H_
-
-#include "gnushogi.h"
-
-/* The following are common to rawdsp.h and cursesdsp.h */
-
-void Curses_ChangeAlphaWindow(void);
-void Curses_ChangeBetaWindow(void);
-void Curses_ChangeHashDepth(void);
-void Curses_ChangeSearchDepth(void);
-void Curses_ChangeXwindow(void);
-void Curses_ClearScreen(void);
-void Curses_Die(int sig);
-void Curses_DoDebug(void);
-void Curses_DoTable(short table[NO_SQUARES]);
-void Curses_EditBoard(void);
-void Curses_ExitShogi(void);
-void Curses_GiveHint(void);
-void Curses_Initialize(void);
-void Curses_ShowNodeCnt(long NodeCnt);
-void Curses_OutputMove(void);
-void Curses_PollForInput(void);
-void Curses_SearchStartStuff(short side);
-void Curses_SelectLevel(char *sx);
-void Curses_SetContempt(void);
-void Curses_ShowCurrentMove(short pnt, short f, short t);
-void Curses_ShowDepth(char ch);
-void Curses_ShowGameType(void);
-void Curses_ShowLine(unsigned short *bstline);
-void Curses_ShowMessage(char *s);
-void Curses_AlwaysShowMessage(const char *format, va_list ap);
-void Curses_Printf(const char *format, va_list ap);
-void Curses_doRequestInputString(const char* fmt, char* buffer);
-int Curses_GetString(char* sx);
-void Curses_SetupBoard(void);
-void Curses_ShowPatternCount(short side, short n);
-void Curses_ShowPostnValue(short sq);
-void Curses_ShowPostnValues(void);
-void Curses_ShowPrompt(void);
-void Curses_ShowResponseTime(void);
-void Curses_ShowResults(short score, unsigned short *bstline, char ch);
-void Curses_ShowSidetoMove(void);
-void Curses_ShowStage(void);
-void Curses_TerminateSearch(int sig);
-void Curses_UpdateClocks(void);
-void Curses_UpdateDisplay(short f, short t, short redraw, short isspec);
-void Curses_help(void);
-
-#endif /* _CURSESDSP_H_ */
+++ /dev/null
-/*
- * FILE: dspwrappers.c
- *
- * Wrapper functions which call analogous functions in rawdsp.c
- * or cursesdsp.c depending on the interface.
- *
- * ----------------------------------------------------------------------
- * Copyright (c) 1993, 1994, 1995 Matthias Mutz
- * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
- *
- * GNU SHOGI is based on GNU CHESS
- *
- * Copyright (c) 1988, 1989, 1990 John Stanback
- * Copyright (c) 1992 Free Software Foundation
- *
- * This file is part of GNU SHOGI.
- *
- * GNU Shogi is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 3 of the License,
- * or (at your option) any later version.
- *
- * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with GNU Shogi; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-#include "gnushogi.h"
-#include "dspwrappers.h"
-#include "rawdsp.h"
-#include "cursesdsp.h"
-
-#include <stdio.h>
-
-#define CASE_DSP_RAW(func,args) \
- case DISPLAY_RAW: \
- case DISPLAY_X: \
- func args; \
- break
-
-#ifdef HAVE_LIBCURSES
-#define CASE_DSP_CURSES(func,args) \
- case DISPLAY_CURSES: \
- func args; \
- break;
-#else
-#define CASE_DSP_CURSES(func,args)
-#endif
-
-#define DISPLAY_FUNC(func,argsdecl,args) \
- void func argsdecl \
- { \
- switch (display_type) { \
- CASE_DSP_RAW(Raw_ ## func, args); \
- CASE_DSP_CURSES(Curses_ ## func, args); \
- } \
- }
-#define DISPLAY_VOIDFUNC(func) \
- DISPLAY_FUNC(func,(void),())
-
-#define DISPLAY_STDARGFUNC(func,argsdecl,last,args) \
- void func argsdecl \
- { \
- va_list ap; \
- va_start(ap, last); \
- switch (display_type) { \
- CASE_DSP_RAW(Raw_ ## func, args); \
- CASE_DSP_CURSES(Curses_ ## func, args); \
- } \
- va_end(ap); \
- }
-
-DISPLAY_VOIDFUNC(ChangeAlphaWindow)
-DISPLAY_VOIDFUNC(ChangeBetaWindow)
-DISPLAY_VOIDFUNC(ChangeHashDepth)
-DISPLAY_VOIDFUNC(ChangeSearchDepth)
-DISPLAY_VOIDFUNC(ChangeXwindow)
-DISPLAY_VOIDFUNC(ClearScreen)
-DISPLAY_VOIDFUNC(DoDebug)
-DISPLAY_FUNC(DoTable, (short table[NO_SQUARES]), (table))
-DISPLAY_VOIDFUNC(EditBoard)
-DISPLAY_VOIDFUNC(ExitShogi)
-DISPLAY_VOIDFUNC(GiveHint)
-DISPLAY_VOIDFUNC(Initialize)
-DISPLAY_FUNC(ShowNodeCnt, (long NodeCnt), (NodeCnt))
-DISPLAY_VOIDFUNC(OutputMove)
-DISPLAY_VOIDFUNC(PollForInput)
-DISPLAY_VOIDFUNC(SetContempt)
-DISPLAY_FUNC(SearchStartStuff, (short side), (side))
-DISPLAY_FUNC(SelectLevel, (char *sx), (sx))
-DISPLAY_VOIDFUNC(SetupBoard)
-DISPLAY_FUNC(ShowCurrentMove, (short pnt, short f, short t), (pnt, f, t))
-DISPLAY_FUNC(ShowDepth, (char ch), (ch))
-DISPLAY_VOIDFUNC(ShowGameType)
-DISPLAY_FUNC(ShowLine, (unsigned short *bstline), (bstline))
-DISPLAY_FUNC(ShowMessage, (char *s), (s))
-DISPLAY_STDARGFUNC(AlwaysShowMessage, (const char *format, ...), format, (format, ap))
-DISPLAY_STDARGFUNC(Printf, (const char *format, ...), format, (format, ap))
-DISPLAY_FUNC(ShowPatternCount, (short side, short n), (side, n))
-DISPLAY_FUNC(ShowPostnValue, (short sq), (sq))
-DISPLAY_VOIDFUNC(ShowPostnValues)
-DISPLAY_VOIDFUNC(ShowPrompt)
-DISPLAY_VOIDFUNC(ShowResponseTime)
-DISPLAY_FUNC(ShowResults, (short score, unsigned short *bstline, char ch), (score, bstline, ch))
-DISPLAY_VOIDFUNC(ShowSidetoMove)
-DISPLAY_VOIDFUNC(ShowStage)
-DISPLAY_FUNC(TerminateSearch, (int sig), (sig))
-DISPLAY_VOIDFUNC(UpdateClocks)
-DISPLAY_FUNC(UpdateDisplay, (short f, short t, short redraw, short isspec), (f, t, redraw, isspec))
-DISPLAY_VOIDFUNC(help)
-
-DISPLAY_FUNC(doRequestInputString, (const char* fmt, char* buffer), (fmt, buffer))
-void RequestInputString(char* buffer, unsigned bufsize)
-{
- static char fmt[10];
- int ret = snprintf(fmt, sizeof(fmt), "%%%us", bufsize);
- if (ret >= sizeof(fmt)) {
- fprintf(stderr,
- "Insufficient format-buffer size in %s for bufsize=%u\n",
- __FUNCTION__, bufsize);
- exit(1);
- }
- doRequestInputString(fmt, buffer);
-}
-
-/*********/
-
-#define CASE_DSPFUNC_RAW(func,args) \
- case DISPLAY_RAW: \
- case DISPLAY_X: \
- return (func args); \
- break
-
-#ifdef HAVE_LIBCURSES
-#define CASE_DSPFUNC_CURSES(func,args) \
- case DISPLAY_CURSES: \
- return (func args); \
- break;
-#else
-#define CASE_DSPFUNC_CURSES(func,args)
-#endif
-
-#define DISPLAY_INTFUNC(func,argsdecl,args) \
- int func argsdecl \
- { \
- switch (display_type) { \
- CASE_DSPFUNC_RAW(Raw_ ## func, args); \
- CASE_DSPFUNC_CURSES(Curses_ ## func, args); \
- } \
- assert(0); \
- }
-
-DISPLAY_INTFUNC(GetString, (char* sx), (sx))
+++ /dev/null
-/*
- * FILE: dspwrappers.h
- *
- * Wrapper functions which call analogous functions in rawdsp.c
- * or cursesdsp.c depending on the interface.
- *
- * ----------------------------------------------------------------------
- * Copyright (c) 1993, 1994, 1995 Matthias Mutz
- * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
- *
- * GNU SHOGI is based on GNU CHESS
- *
- * Copyright (c) 1988, 1989, 1990 John Stanback
- * Copyright (c) 1992 Free Software Foundation
- *
- * This file is part of GNU SHOGI.
- *
- * GNU Shogi is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 3 of the License,
- * or (at your option) any later version.
- *
- * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with GNU Shogi; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-#ifndef _DSPWRAPPERS_H_
-#define _DSPWRAPPERS_H_
-
-#include <stdarg.h>
-
-extern void ChangeAlphaWindow(void);
-extern void ChangeBetaWindow(void);
-extern void ChangeHashDepth(void);
-extern void ChangeSearchDepth(void);
-extern void ChangeXwindow(void);
-extern void ClearScreen(void);
-extern void DoDebug(void);
-extern void DoTable(short table[NO_SQUARES]);
-extern void EditBoard(void);
-extern void ExitShogi(void);
-extern void GiveHint(void);
-extern void Initialize(void);
-extern void ShowNodeCnt(long NodeCnt);
-extern void OutputMove(void);
-extern void PollForInput(void);
-extern void SetContempt(void);
-extern void SearchStartStuff(short side);
-extern void SelectLevel(char *sx);
-extern void ShowCurrentMove(short pnt, short f, short t);
-extern void ShowDepth(char ch);
-extern void ShowGameType(void);
-extern void ShowLine(unsigned short *bstline);
-extern void ShowMessage(char *s);
-extern void AlwaysShowMessage(const char *format, ...);
-extern void Printf(const char *format, ...);
-extern void RequestInputString(char* buffer, unsigned bufsize);
-extern int GetString(char* sx);
-extern void SetupBoard(void);
-extern void ShowPatternCount(short side, short n);
-extern void ShowPostnValue(short sq);
-extern void ShowPostnValues(void);
-extern void ShowPrompt(void);
-extern void ShowResponseTime(void);
-extern void ShowResults(short score, unsigned short *bstline, char ch);
-extern void ShowSidetoMove(void);
-extern void ShowStage(void);
-extern void TerminateSearch(int sig);
-extern void UpdateClocks(void);
-extern void UpdateDisplay(short f, short t, short redraw, short isspec);
-extern void help(void);
-
-#endif /* _DSPWRAPPERS_H_ */
#include "gnushogi.h"
#include "pattern.h"
-extern void
-ShowStage(void);
-
/* Hash table for preventing multiple scoring of the same position */
int EADD = 0; /* number of writes to the cache table */
}
if (flag.post)
- ShowPatternCount(side, n);
+ dsp->ShowPatternCount(side, n);
if (os != END_OF_SEQUENCES)
update_advance_bonus(side, os);
}
else
{
- ShowPatternCount(black, -1);
- ShowPatternCount(white, -1);
+ dsp->ShowPatternCount(black, -1);
+ dsp->ShowPatternCount(white, -1);
}
}
stage = 0;
if (flag.post)
- ShowStage();
+ dsp->ShowStage();
/* Determine stage dependant weights */
{
if (*TrP == TREE)
{
- ShowMessage("TREE overflow\n");
+ dsp->ShowMessage("TREE overflow\n");
}
else
{
#include "debug.h"
#include "opts.h" /* Various option-setting #defines. */
+#include <stdarg.h>
+
/*
* Display options.
*/
extern int VerifyMove(char *s, VerifyMove_mode iop, unsigned short *mv);
extern unsigned short TTage;
-#include "dspwrappers.h" /* Display functions. */
+/* display driver framework */
+
+struct display
+{
+ void (*ChangeAlphaWindow)(void);
+ void (*ChangeBetaWindow)(void);
+ void (*ChangeHashDepth)(void);
+ void (*ChangeSearchDepth)(void);
+ void (*ChangeXwindow)(void);
+ void (*ClearScreen)(void);
+ void (*DoDebug)(void);
+ void (*DoTable)(short table[NO_SQUARES]);
+ void (*EditBoard)(void);
+ void (*ExitShogi)(void);
+ void (*GiveHint)(void);
+ void (*Initialize)(void);
+ void (*ShowNodeCnt)(long NodeCnt);
+ void (*OutputMove)(void);
+ void (*PollForInput)(void);
+ void (*SetContempt)(void);
+ void (*SearchStartStuff)(short side);
+ void (*SelectLevel)(char *sx);
+ void (*ShowCurrentMove)(short pnt, short f, short t);
+ void (*ShowDepth)(char ch);
+ void (*ShowGameType)(void);
+ void (*ShowLine)(unsigned short *bstline);
+ void (*ShowMessage)(char *s);
+ void (*AlwaysShowMessage)(const char *format, ...);
+ void (*Printf)(const char *format, ...);
+ void (*doRequestInputString)(const char* fmt, char* buffer);
+ int (*GetString)(char* sx);
+ void (*SetupBoard)(void);
+ void (*ShowPatternCount)(short side, short n);
+ void (*ShowPostnValue)(short sq);
+ void (*ShowPostnValues)(void);
+ void (*ShowPrompt)(void);
+ void (*ShowResponseTime)(void);
+ void (*ShowResults)(short score, unsigned short *bstline, char ch);
+ void (*ShowSidetoMove)(void);
+ void (*ShowStage)(void);
+ void (*TerminateSearch)(int sig);
+ void (*UpdateClocks)(void);
+ void (*UpdateDisplay)(short f, short t, short redraw, short isspec);
+ void (*help)(void);
+};
+
+extern struct display *dsp;
+
+extern struct display raw_display;
+extern struct display curses_display;
#endif /* _GNUSHOGI_H_ */
if (x >= 0)
{
- ShowMessage("datatype 'small_short' is unsigned; "
+ dsp->ShowMessage("datatype 'small_short' is unsigned; "
"check gnushogi.h\n");
return 1;
}
{
sprintf(buffer, "Cannot allocate %ld bytes for search tree",
(long)n);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
return 1;
}
if (!hashcode)
{
sprintf(buffer, "Cannot allocate %ld bytes for hashcode", (long)n);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
return 1;
}
sprintf(buffer,
"Cannot allocate %ld bytes for drop_hashcode",
(long)n);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
return 1;
}
sprintf(buffer,
"Cannot allocate %ld bytes for game record",
(long)n);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
return 1;
}
{
sprintf(buffer, "cannot allocate %ld space for nextdir %d",
(long)(n), i);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
}
nextdir[i] = NULL;
{
sprintf(buffer, "cannot allocate %ld space for nextpos %d",
(long)(n), i);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
}
use_nextpos = false;
if (!value)
{
- ShowMessage("cannot allocate value space");
+ dsp->ShowMessage("cannot allocate value space");
return 1;
}
if (!fscore)
{
- ShowMessage("cannot allocate fscore space");
+ dsp->ShowMessage("cannot allocate fscore space");
return 1;
}
{
sprintf(buffer, "Cannot allocate %ld bytes for history table",
(long)sizeof_history);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
use_history = false;
}
#endif
{
sprintf(buffer, "Cannot allocate %ld bytes for cache table %ld",
(long)n, (long)i);
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
use_etable = false;
}
}
{
sprintf(buffer, "Cannot allocate %ld bytes for transposition table",
(long)(2 * n));
- ShowMessage(buffer);
+ dsp->ShowMessage(buffer);
ttable[0] = ttable[1] = NULL;
}
#endif /* ttblsz */
if (!distdata)
{
- ShowMessage("cannot allocate distdata space...");
+ dsp->ShowMessage("cannot allocate distdata space...");
use_distdata = false;
}
#endif
}
ClearCaptured();
- ClearScreen();
+ dsp->ClearScreen();
InitializeStats();
#ifdef HAVE_GETTIMEOFDAY
if (TCflag)
SetTimeControl();
else if (MaxResponseTime == 0)
- SelectLevel(sx);
+ dsp->SelectLevel(sx);
- UpdateDisplay(0, 0, 1, 0);
+ dsp->UpdateDisplay(0, 0, 1, 0);
GetOpenings();
GetOpeningPatterns(&max_opening_sequence);
barebones = 0;
}
- Initialize();
+ dsp->Initialize();
Initialize_dist();
Initialize_eval();
#if !defined SAVE_NEXTPOS
#endif /* HASHFILE */
#endif /* ttblsz */
- ExitShogi();
+ dsp->ExitShogi();
}
case 'C':
/* Curses interface. */
display_type = DISPLAY_CURSES;
-
+ dsp = &curses_display;
break;
#endif
case 'R':
/* Raw text interface. */
display_type = DISPLAY_RAW;
-
+ dsp = &raw_display;
break;
case 'X':
/* X interface. */
display_type = DISPLAY_X;
-
+ dsp = &raw_display;
break;
small_short pattern_data[MAX_PATTERN_DATA];
/* minimal ShowMessage to avoid dependency on extraneous display code */
-void
-ShowMessage(char *s)
+static void
+Dummy_ShowMessage(char *s)
{
printf("%s\n", s);
}
+static struct display dummydsp = {
+ .ShowMessage = Dummy_ShowMessage,
+};
+struct display *dsp = &dummydsp;
#define is_digit(c) (((c) >= '0') && ((c) <= '9'))
#define is_alpha(c) ((((c) >= 'a') && ((c) <= 'z')) \
{
if (ScanPattern(s, pindex))
{
- ShowMessage("error in pattern sequence...");
+ dsp->ShowMessage("error in pattern sequence...");
exit(1);
}
else
sprintf(s,
"Pattern: %d bytes for %d sequences with %d patterns.\n",
*pindex, max_opening_sequence, max_pattern);
- ShowMessage(s);
+ dsp->ShowMessage(s);
fclose(fd);
} else {
sprintf(s, "no pattern file '%s'", patternfile);
- ShowMessage(s);
+ dsp->ShowMessage(s);
}
}
#endif
#include "gnushogi.h"
-#include "rawdsp.h"
unsigned short MV[MAXDEPTH];
int MSCORE;
extern char *InPtr;
extern short pscore[];
+/****************************************
+ * forward declarations
+ ****************************************/
+
+void Raw_UpdateDisplay(short f, short t, short redraw, short isspec);
/****************************************
* Trivial output functions.
void
-Raw_AlwaysShowMessage(const char *format, va_list ap)
+Raw_AlwaysShowMessage(const char *format, ...)
{
+ va_list ap;
+ va_start(ap, format);
vprintf(format, ap);
printf("\n");
+ va_end(ap);
}
void
-Raw_Printf(const char *format, va_list ap)
+Raw_Printf(const char *format, ...)
{
+ va_list ap;
+ va_start(ap, format);
vprintf(format, ap);
+ va_end(ap);
}
int cnt = poll(pollfds, sizeof(pollfds)/sizeof(pollfds[0]), 0);
if (cnt < 0) {
perror("polling standard input");
- ExitShogi();
+ Raw_ExitShogi();
}
#endif
if (cnt) { /* if anything to read, or error occured */
flag.bothsides = false;
}
}
+
+struct display raw_display =
+{
+ .ChangeAlphaWindow = Raw_ChangeAlphaWindow,
+ .ChangeBetaWindow = Raw_ChangeBetaWindow,
+ .ChangeHashDepth = Raw_ChangeHashDepth,
+ .ChangeSearchDepth = Raw_ChangeSearchDepth,
+ .ChangeXwindow = Raw_ChangeXwindow,
+ .ClearScreen = Raw_ClearScreen,
+ .DoDebug = Raw_DoDebug,
+ .DoTable = Raw_DoTable,
+ .EditBoard = Raw_EditBoard,
+ .ExitShogi = Raw_ExitShogi,
+ .GiveHint = Raw_GiveHint,
+ .Initialize = Raw_Initialize,
+ .ShowNodeCnt = Raw_ShowNodeCnt,
+ .OutputMove = Raw_OutputMove,
+ .PollForInput = Raw_PollForInput,
+ .SetContempt = Raw_SetContempt,
+ .SearchStartStuff = Raw_SearchStartStuff,
+ .SelectLevel = Raw_SelectLevel,
+ .ShowCurrentMove = Raw_ShowCurrentMove,
+ .ShowDepth = Raw_ShowDepth,
+ .ShowGameType = Raw_ShowGameType,
+ .ShowLine = Raw_ShowLine,
+ .ShowMessage = Raw_ShowMessage,
+ .AlwaysShowMessage = Raw_AlwaysShowMessage,
+ .Printf = Raw_Printf,
+ .doRequestInputString = Raw_doRequestInputString,
+ .GetString = Raw_GetString,
+ .SetupBoard = Raw_SetupBoard,
+ .ShowPatternCount = Raw_ShowPatternCount,
+ .ShowPostnValue = Raw_ShowPostnValue,
+ .ShowPostnValues = Raw_ShowPostnValues,
+ .ShowPrompt = Raw_ShowPrompt,
+ .ShowResponseTime = Raw_ShowResponseTime,
+ .ShowResults = Raw_ShowResults,
+ .ShowSidetoMove = Raw_ShowSidetoMove,
+ .ShowStage = Raw_ShowStage,
+ .TerminateSearch = Raw_TerminateSearch,
+ .UpdateClocks = Raw_UpdateClocks,
+ .UpdateDisplay = Raw_UpdateDisplay,
+ .help = Raw_help,
+};
+++ /dev/null
-/*
- * FILE: rawdsp.h
- *
- * Raw text interface for GNU Shogi.
- *
- * ----------------------------------------------------------------------
- * Copyright (c) 1993, 1994, 1995 Matthias Mutz
- * Copyright (c) 1999 Michael Vanier and the Free Software Foundation
- *
- * GNU SHOGI is based on GNU CHESS
- *
- * Copyright (c) 1988, 1989, 1990 John Stanback
- * Copyright (c) 1992 Free Software Foundation
- *
- * This file is part of GNU SHOGI.
- *
- * GNU Shogi is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 3 of the License,
- * or (at your option) any later version.
- *
- * GNU Shogi is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with GNU Shogi; see the file COPYING. If not, see
- * <http://www.gnu.org/licenses/>.
- * ----------------------------------------------------------------------
- *
- */
-
-#ifndef _RAWDSP_H_
-#define _RAWDSP_H_
-
-#include "gnushogi.h"
-
-/* The following are common to rawdsp.h and cursesdsp.h */
-
-void Raw_ChangeAlphaWindow(void);
-void Raw_ChangeBetaWindow(void);
-void Raw_ChangeHashDepth(void);
-void Raw_ChangeSearchDepth(void);
-void Raw_ChangeXwindow(void);
-void Raw_ClearScreen(void);
-void Raw_Die(int sig);
-void Raw_DoDebug(void);
-void Raw_DoTable(short table[NO_SQUARES]);
-void Raw_EditBoard(void);
-void Raw_ExitShogi(void);
-void Raw_GiveHint(void);
-void Raw_Initialize(void);
-void Raw_ShowNodeCnt(long NodeCnt);
-void Raw_OutputMove(void);
-void Raw_PollForInput(void);
-void Raw_SearchStartStuff(short side);
-void Raw_SelectLevel(char *sx);
-void Raw_SetContempt(void);
-void Raw_ShowCurrentMove(short pnt, short f, short t);
-void Raw_ShowDepth(char ch);
-void Raw_ShowGameType(void);
-void Raw_ShowLine(unsigned short *bstline);
-void Raw_ShowMessage(char *s);
-void Raw_AlwaysShowMessage(const char *format, va_list ap);
-void Raw_Printf(const char *format, va_list ap);
-void Raw_doRequestInputString(const char* fmt, char* buffer);
-int Raw_GetString(char* sx);
-void Raw_SetupBoard(void);
-void Raw_ShowPatternCount(short side, short n);
-void Raw_ShowPostnValue(short sq);
-void Raw_ShowPostnValues(void);
-void Raw_ShowPrompt(void);
-void Raw_ShowResponseTime(void);
-void Raw_ShowResults(short score, unsigned short *bstline, char ch);
-void Raw_ShowSidetoMove(void);
-void Raw_ShowStage(void);
-void Raw_TerminateSearch(int sig);
-void Raw_UpdateClocks(void);
-void Raw_UpdateDisplay(short f, short t, short redraw, short isspec);
-void Raw_help(void);
-
-#endif /* _RAWDSP_H_ */
-
#ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- ShowResponseTime();
+ dsp->ShowResponseTime();
ExtraTime = 0;
#ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- ShowSidetoMove();
+ dsp->ShowSidetoMove();
#ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- SearchStartStuff(side);
+ dsp->SearchStartStuff(side);
#ifdef HISTORY
array_zero(history, sizeof_history);
# ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- ShowDepth(' ');
+ dsp->ShowDepth(' ');
/* search at this level returns score of PV */
score = search(side, 1, Sdepth, alpha, beta, PrVar, &rpt);
#ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- ShowDepth('-');
+ dsp->ShowDepth('-');
if (TCflag && TCcount < MAXTCCOUNTR)
{
#ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- ShowDepth('+');
+ dsp->ShowDepth('+');
score = search(side, 1, Sdepth, -(SCORE_LIMIT + 999),
(SCORE_LIMIT + 999), PrVar, &rpt);
#ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- ShowResults(score, PrVar, '.');
+ dsp->ShowResults(score, PrVar, '.');
}
/********************** end of main loop ***************************/
ElapsedTime(COMPUTE_AND_INIT_MODE);
/* update time control info */
- OutputMove();
+ dsp->OutputMove();
/* if mate set flag */
if ((score == -(SCORE_LIMIT + 999) || score == (SCORE_LIMIT + 998)))
#ifdef QUIETBACKGROUND
if (!background)
#endif
- ShowResponseTime();
+ dsp->ShowResponseTime();
}
else if (!TCflag && flag.musttimeout && Sdepth > MINDEPTH)
{
#ifdef QUIETBACKGROUND
if (!background)
#endif /* QUIETBACKGROUND */
- ShowCurrentMove(pnt, node->f, node->t);
+ dsp->ShowCurrentMove(pnt, node->f, node->t);
}
}
#endif
{
if (best > beta)
{
- ShowResults(best, bstline, '+');
+ dsp->ShowResults(best, bstline, '+');
}
else if (best < alpha)
{
- ShowResults(best, bstline, '-');
+ dsp->ShowResults(best, bstline, '-');
}
else
{
- ShowResults (best, bstline, '&');
+ dsp->ShowResults(best, bstline, '&');
}
}
#ifdef QUIETBACKGROUND
#endif
if (flag.timeout)
- ShowMessage("timeout");
+ dsp->ShowMessage("timeout");
}
struct timeval tv;
#endif
- PollForInput();
+ dsp->PollForInput();
#ifdef HAVE_GETTIMEOFDAY
gettimeofday(&tv, NULL);
#ifdef QUIETBACKGROUND
if (!background)
#endif
- UpdateClocks();
+ dsp->UpdateClocks();
}
}