// xboard232.h, Peter McGavin
//
// This file was derived from Rémi Coulom's win_a232.h (mainly by deleting
// Windows-95 and C++ specific code) which contained the following
// conditions of use:
//
//-----------------------------------------------------------------------
//-  Module:  win_a232.h                                                -
//-  Project: Windows-95 Autoplayer.                                    -
//-  Purpose: Reference Implementation of Auto232-Driver for Windows-95 -
//-  History: See win_a232.cpp                                          -
//-  (c) 1997 by Stefan Meyer-Kahlen (Original Code).                   -
//-  (c) 1997 by Ch.Donninger (Auto232 Specification, Modifications,    -
//-                            Documentation).                          -
//-  Copyright Conditions:                                              -
//-  This code can be used freely by other chess programmers under the  -
//-  following conditions:                                              -
//-  A) The History and Copyright-comments must be left in the code.    -
//-  B) The code or any executables produced by it must not be sold     -
//-     (this is also valid for modifications of this code).            -
//-  C) Executables/Object-code can be distributed in a bundled form    -
//-     with chess-programs. There must be NO extra price tag for the   -
//-     the autoplayer-version of the chess program.                    -
//-  D) Credit should be given in the About-Box of the program to       -
//-     Stefan Meyer-Kahlen and Ch.Donninger. (This point is only a     -
//-     question of etiquette).                                         -
//-  E) The authors can not be blamed for bugs. It is the duty of each  -
//-     chess programmer to test the code and fix bugs. Serious bugs    -
//-     should be reported to the authors.                              -
//-  F) This code can be distributed freely to other chess programmers  -
//-     if the copyright conditions above are NOT changed.              -
//-  Note: Please consider this implementation as a "Standard". The     -
//-     autoplayer-specification has due to historic reasons some       -
//-     limitations, but it works. Refrain from incompatible extensions -
//-     and changes.                                                    -
//-----------------------------------------------------------------------
#ifndef _XBOARD232_H
#define _XBOARD232_H

#define A232_ATTEMPTS   3 // Number of retries to send a packet.

// Communication-Codes
#define A232_ACK  0x46
#define A232_NAK  0x55
#define A232_STX  0x42
#define A232_ETX  0x43

// Move-Commands
#define A232_NMOVE   0x01
#define A232_CAPMOVE 0x02
#define A232_EPMOVE  0x03
#define A232_OOMOVE  0x04
#define A232_OOOMOVE 0x05

// Miscellanous-Commands.
#define A232_ILLEGALMOVE           0x06
#define A232_COMMAND               0x08
#define A232_REQUESTMATCH          0x20
#define A232_CONFIRMMATCH          0x21
#define A232_CANCELGAME            0x22
#define A232_SAVEGAME              0x23
#define A232_CONTINUEGAME          0x24
#define A232_EXTENDEDMODE          0x25 // Documented as "reject match" ?
#define A232_FRITZ                 0x26 // Unknown code sent by FRITZ
#define A232_EXTENDEDCOMMANDMODE   0x66
#define A232_QUIT                  0x99

// Command codes for A232_COMMAND
#define A232_COM_COMPUTE    0x01
#define A232_COM_STOP       0x02
#define A232_COM_NEWGAME    0x03
#define A232_COM_TAKEBACK   0x04
#define A232_COM_MEMOON     0x05
#define A232_COM_MEMOOFF    0x06
#define A232_COM_FLIPBOARD  0x07
#define A232_COM_OFFERDRAW  0x08
#define A232_COM_ACCEPTDRAW 0x09
#define A232_COM_REJECTDRAW 0x0a
#define A232_COM_RESIGN     0x0b
#define A232_COM_BOOKON     0x0c
#define A232_COM_BOOKOFF    0x0d

//--
//-- Messages sent by the driver to the chess program. If the message ID's are
//-- already used in your program, simply change the value of WM_AUTO232.
//--
#define WM_AUTO232(n) (WM_USER + 800 + (n))

//-- Chess program should start the search. The message-parameters have no meaning.
#define AUTO232_STARTSEARCH_MSG  WM_AUTO232(A232_COM_COMPUTE)

//-- Chess program should stop the current search and play the calculated move.
//-- The message-parameters have no meaning.
#define AUTO232_STOPSEARCH_MSG   WM_AUTO232(A232_COM_STOP)

//-- Chess program should establish the start position. The message-parameters
//-- have no meaning.
#define AUTO232_NEWGAME_MSG      WM_AUTO232(A232_COM_NEWGAME)
#define AUTO232_TAKEBACK_MSG     WM_AUTO232(A232_COM_TAKEBACK)
#define AUTO232_MEMOON_MSG       WM_AUTO232(A232_COM_MEMOON)
#define AUTO232_MEMOOFF_MSG      WM_AUTO232(A232_COM_MEMOOFF)
#define AUTO232_FLIPBOARD_MSG    WM_AUTO232(A232_COM_FLIPBOARD)
#define AUTO232_OFFERDRAW_MSG    WM_AUTO232(A232_COM_OFFERDRAW)
#define AUTO232_ACCEPTDRAW_MSG   WM_AUTO232(A232_COM_ACCEPTDRAW)
#define AUTO232_REJECTDRAW_MSG   WM_AUTO232(A232_COM_REJECTDRAW)
#define AUTO232_RESIGN_MSG       WM_AUTO232(A232_COM_RESIGN)
#define AUTO232_BOOKON_MSG       WM_AUTO232(A232_COM_BOOKON)
#define AUTO232_BOOKOFF_MSG      WM_AUTO232(A232_COM_BOOKOFF)

//-- Chess program should stop the current game. The message-parameters have no
//-- meaning.
#define AUTO232_CANCELGAME_MSG   WM_AUTO232(0x20)

//-- Chess program should save the current game. Message-parameter 1 is the number
//-- of games in the current match, parameter 2 the number of the current game.
#define AUTO232_SAVEGAME_MSG     WM_AUTO232(0x21)

//-- Chess program has received from the opponent a move. Message parameter-1 is
//-- the from square, parameter-2 the to-square.
//-- Attention: In Extended Mode are the highest to-bits of the two square used
//--            for under-promotion information. See also comments to procedure
//--            Auto232SendMove in win_a232.cpp
//-- The chess program should start thinking just after it has received this
//-- message and not wait for an AUTO232_STARTSEARCH_MSG
#define AUTO232_MOVE_MSG         WM_AUTO232(0x22)

//-- Autoplay-session has been stopped by opponent. The message-parameters have
//-- no meaning.
#define AUTO232_QUIT_MSG         WM_AUTO232(0x23)


//-- The procedures are documented in win_a232.cpp

#define AUTO232_SERIAL 0
#define AUTO232_SERVER 1
#define AUTO232_CLIENT 2

#if 0
int Auto232InitCom(int OpenMode);

int Auto232StartMatch();
void Auto232Close();
int Auto232NextGame();

void Auto232SetTrace(int NewTrace);
void Auto232SetAlternate(int NewAlternate);
void Auto232SetInterval(int NewInterval);
void Auto232SetComPort(int NewComPort);
void Auto232SetHWnd(HWND hwnd);
void Auto232SetTimeOut(int NewTimeOut);
void Auto232SetNumGames(int NewNumGames);
void Auto232SetHostName(const char *pszHostName);

int IsAuto232Connected();
int IsAuto232ComOn();
int IsAuto232Master();
int IsAuto232ExtendedMode();
int Auto232GetTrace();
int Auto232GetAlternate();
int Auto232GetInterval();
int Auto232GetComPort();
int Auto232GetTimeOut();
int Auto232GetNumGames();
const char *Auto232GetHostName();

int Auto232SendMove(unsigned char from,unsigned char to,unsigned char mvtype);
int Auto232SendCommand(unsigned char command, int confirm);
#endif

#endif
