home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / OS2 / SPEL / UCHESS / UCHESSRC / MAIN.C < prev    next >
C/C++ Source or Header  |  1994-11-07  |  244KB  |  9,009 lines

  1. // InputThread is the guy who runs the UI
  2. // while main thread does chesswork
  3.  
  4. // need to load the strings "new" "get" and "save"
  5. // for load/save/new games when in menu, then set
  6. // done to 1!!!
  7.  
  8. // NOTE THAT THE INPUT THREAD HAS TO BE THE ONE TO
  9. // GETGAME AND SAVE GAME THOUGH!! so it must all change
  10.  
  11. /*#define EIGHT_BIT_SCREEN 1 */
  12.  
  13. #define BLANKDATA 0xffff
  14.  
  15.  
  16. /* main.c - C source for GNU CHESS
  17.  *
  18.  * Copyright (c) 1988,1989,1990 John Stanback
  19.  * Copyright (c) 1992 Free Software Foundation
  20.  *
  21.  * This file is part of GNU CHESS.
  22.  *
  23.  * GNU Chess is free software; you can redistribute it and/or modify
  24.  * it under the terms of the GNU General Public License as published by
  25.  * the Free Software Foundation; either version 2, or (at your option)
  26.  * any later version.
  27.  *
  28.  * GNU Chess is distributed in the hope that it will be useful,
  29.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  31.  * GNU General Public License for more details.
  32.  *
  33.  * You should have received a copy of the GNU General Public License
  34.  * along with GNU Chess; see the file COPYING.  If not, write to
  35.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  36.  */
  37.  
  38. #define INCL_HELP
  39. #define INCL_DOS
  40. #define INCL_WIN
  41. #define INCL_GPI
  42.  
  43. int MaxX,MaxY;
  44. int ForceMini=0;
  45. int ForceMax=0;
  46. int ForceMicro=0;
  47. char globaltitle[32];
  48. extern int backsrchaborted;
  49. int myGameCnt=0;
  50. int OrigComputer,OrigOpponent;
  51. char MsgBuf[8][48];
  52.  
  53. int CheckIllegal = 0;
  54. extern int IllegalMove;
  55. #include "version.h"
  56. #include "gnuchess.h"
  57. #include <signal.h>
  58. #include <ctype.h>
  59.  
  60. #include <dos.h>
  61. #include <conio.h>
  62. #include "bobs.h"
  63. #include "UChess.h"
  64.  
  65. CHAR szLibName[HELPLIBRARYNAMELEN];
  66. CHAR szWindowTitle[HELPLIBRARYNAMELEN];
  67. HWND hwndHelpInstance;
  68. int   fHelpEnabled=0;              /* flag to determine if help is enabled */
  69. extern char mvstr[8][8];
  70. int ETABLE=ETABLE_CONST;
  71. int etblsize=ETABLE_CONST;
  72. extern struct etable *etab[2];
  73. int GlobalFilType = FDS_OPEN_DIALOG;
  74. HEV replyhandle;
  75. //UCHAR semname[16]="\\SEM32\\UCSEM";
  76. UCHAR replyname[16]="\\SEM32\\RPLYSEM";
  77. PFNWP OldFrameProc;
  78.  
  79. #ifdef AMIGA
  80. #define EXCLUDE_PATT 0xffffff00L
  81. #define __USE_SYSBASE
  82. #include <exec/types.h>
  83. #include <exec/exec.h>
  84. #include <exec/semaphores.h>
  85. #include <proto/exec.h>
  86. #include <proto/dos.h>
  87. #include <dos/dostags.h>
  88. #include <proto/graphics.h>
  89. #include <graphics/gfxbase.h>
  90. #include <proto/intuition.h>
  91. #include <utility/tagitem.h>
  92. #include <graphics/modeid.h>
  93. #include <lhlib.h>
  94. #include <libraries/asl.h>
  95. #include <proto/icon.h>
  96. #include <proto/asl.h>
  97. #include <workbench/startup.h>
  98. #include <workbench/workbench.h>
  99.  
  100. struct TmpRas  temp_rast;
  101. unsigned char *tempras_bitplane=(unsigned char *)0L;
  102.  
  103. #define mySetABPenDrMd(a,b,c,d) if (gfxversion > 38) {SetABPenDrMd(a,b,c,d);} else {SetAPen(a,b);SetDrMd(a,d);}
  104.  
  105.  
  106.  
  107. struct __iobuf __iob[1];
  108. struct SignalSemaphore  mySemaphore; // should be all zeroed
  109.  
  110. #endif //AMIGA
  111.  
  112.  
  113. ULONG flCreateFlags = FCF_TITLEBAR | FCF_SYSMENU | FCF_MINMAX | FCF_ACCELTABLE
  114. | FCF_SIZEBORDER | FCF_SHELLPOSITION | FCF_TASKLIST | FCF_ICON | FCF_MENU;
  115.  
  116. int MainThreadStarted=0;
  117. QMSG qmsg;
  118. HMQ hmq;
  119.  
  120. // These variables are for the BOB routines
  121. int cyClient,cxClient;
  122. HAB hab;
  123. HWND hwndClient;
  124. HWND hwndFrame;
  125. unsigned char UC_Title[32]="UChess P5:";
  126. int global_promote_char=0;
  127.  
  128.  
  129. char DisplayPromoteRequestor(void);
  130.  
  131. VOID InitHelp(VOID);
  132. VOID HelpHelpForHelp(/*MPARAM*/);
  133. VOID HelpExtended(/*MPARAM*/);
  134. //VOID HelpKeys(/*MPARAM*/);
  135. VOID HelpIndex(/*MPARAM*/);
  136. VOID DisplayHelpPanel(LONG);
  137. VOID DestroyHelpInstance(VOID);
  138.  
  139.  
  140.  
  141. MRESULT EXPENTRY myFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  142. MRESULT EXPENTRY SkillFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  143. MRESULT EXPENTRY PromoteFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  144. MRESULT EXPENTRY AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  145. MRESULT EXPENTRY TimeControlFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  146. MRESULT EXPENTRY SetPlayersFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
  147. void AnimCastle(char *);
  148. void AnimEnPassant(char *);
  149. void WaitRealThink(void);
  150. void WaitThinkAhead(void);
  151. void PutPieceBack(void);
  152. VOID HelpAbout(void);
  153. LONG MainCommand(HWND hwnd, MPARAM mp1/*, MPARAM mp2*/);
  154. void DrawChessPieces(HPS);
  155. void TransBlit(BOB *,HPS,HPS,LONG,PPOINTL);
  156. void TransBlit2(BOB *,HPS,HPS,LONG,PPOINTL);
  157. VOID FixSysMenu(HWND hwndDlg);
  158.  
  159.  
  160. #define PAWNBOB 0
  161. #define KNIGHTBOB 1
  162. #define BISHOPBOB 2
  163. #define ROOKBOB 3
  164. #define QUEENBOB 4
  165. #define KINGBOB 5
  166.  
  167. int MouseX=0,MouseY=0;
  168. int ButtonDown=0;
  169. int ReturnHit=0;
  170. extern HDC winhdc;
  171. HBITMAP WhiteBitMap,BlackBitMap,textBitMap;
  172. CHAR szClientClass[16] = "UChess Window";
  173.  
  174. long ScreenWidth=0;
  175. long ScreenHeight=0;
  176. long ScreenColors=0;
  177.  
  178. int EditMode=0;
  179. extern HPS hpsMemory;
  180. unsigned char PieceFileNames[2][6][24]={
  181. "CPAWN2.BMP","CKNIGHT2.BMP","CBISHOP2.BMP",
  182. "CROOK2.BMP","CQUEEN2.BMP","CKING2.BMP",
  183. "CPAWN1.BMP","CKNIGHT1.BMP","CBISHOP1.BMP",
  184. "CROOK1.BMP","CQUEEN1.BMP","CKING1.BMP"};
  185.  
  186. extern int SafeBlit;
  187.  
  188. int WinNotInited=1;
  189. int GotSize=0;
  190. MRESULT EXPENTRY ClientWndProc(HWND,ULONG,MPARAM,MPARAM);
  191. #define PEL_DEPTH 8
  192. #define NUMCOLORS (1<<PEL_DEPTH)
  193.  
  194.  
  195. int oldflageasy=0;
  196. unsigned int CurrBobColor=0;
  197. unsigned int CurrBobIndex=0;
  198. BOB *TheBob[2][6]; // all pieces are a BOB
  199.  
  200. //HMTX mySemaphore; // taken care of by DrawSemaphore
  201. extern int backsrcshaborted;
  202. extern int bookflag;
  203.  
  204.  
  205.  
  206. #define LN2 693147 /* .693147 */
  207. #define LOGE_34 3526361 /* log2(34) = ln(34)/ln(2) = 5.087463 */
  208. #define LOGE_16 2772589 /* ln(16) = */
  209.  
  210. void SetTimeControl2 (int);
  211. void calc_pgm_rating(void);
  212. void DoEasy(void);
  213. void DoIntermediate(void);
  214. void DoAdvanced(void);
  215. int GetScreenMode(void);
  216. void QueryTimeValues(HWND);
  217. void QueryPlayerValues(HWND);
  218. void QueryPromoteValues(HWND);
  219. void QuerySkillValues(HWND);
  220.  
  221.  
  222. /* this table index ln(2)*1e6 - ln(1202)*1e6 by 6's */
  223. /* so take (#secs - 2)/6 for index into this table */
  224.  
  225.  
  226. //char    UCProcName[16]="UCTurbo Engine";
  227. //char    InputPortName[16]="UC Port";
  228. //struct TagItem    ProcTagList[8] = {
  229. //{NP_Entry,(ULONG)InputThread},
  230. //{NP_StackSize,4096L},
  231. //{NP_Name,(ULONG)UCProcName},
  232. //{0,0}
  233. //};
  234. //struct MsgPort  *InputReply=(struct MsgPort *)0L;
  235. //struct MsgPort *InThreadPort;
  236. ULONG Global_Message;
  237.  
  238. extern INTSIZE amigaboard[64],amigacolor[64];
  239. extern int RealThink;
  240. int opindex=0;
  241. int OpEntryRecvd=0;
  242. int InputThreadState=0;
  243. char OpEntryStr[64]={0,0,0,0};
  244. char lOpEntryStr[64]={0,0,0,0};
  245.  
  246. long OrigResponse;
  247. int log_e[]={
  248. 693147, 2079442, 2639057, 2995732, 3258097, 3465736, 3637586, 3784190, 
  249. 3912023, 4025352, 4127134, 4219508, 4304065, 4382027, 4454347, 4521789, 
  250. 4584967, 4644391, 4700480, 4753590, 4804021, 4852030, 4897840, 4941642, 
  251. 4983607, 5023881, 5062595, 5099866, 5135798, 5170484, 5204007, 5236442, 
  252. 5267858, 5298317, 5327876, 5356586, 5384495, 5411646, 5438079, 5463832, 
  253. 5488938, 5513429, 5537334, 5560682, 5583496, 5605802, 5627621, 5648974, 
  254. 5669881, 5690359, 5710427, 5730100, 5749393, 5768321, 5786897, 5805135, 
  255. 5823046, 5840642, 5857933, 5874931, 5891644, 5908083, 5924256, 5940171, 
  256. 5955837, 5971262, 5986452, 6001415, 6016157, 6030685, 6045005, 6059123, 
  257. 6073045, 6086775, 6100319, 6113682, 6126869, 6139885, 6152733, 6165418, 
  258. 6177944, 6190315, 6202536, 6214608, 6226537, 6238325, 6249975, 6261492, 
  259. 6272877, 6284134, 6295266, 6306275, 6317165, 6327937, 6338594, 6349139, 
  260. 6359574, 6369901, 6380123, 6390241, 6400257, 6410175, 6419995, 6429719, 
  261. 6439350, 6448889, 6458338, 6467699, 6476972, 6486161, 6495266, 6504288, 
  262. 6513230, 6522093, 6530878, 6539586, 6548219, 6556778, 6565265, 6573680, 
  263. 6582025, 6590301, 6598509, 6606650, 6614726, 6622736, 6630683, 6638568, 
  264. 6646391, 6654153, 6661855, 6669498, 6677083, 6684612, 6692084, 6699500, 
  265. 6706862, 6714171, 6721426, 6728629, 6735780, 6742881, 6749931, 6756932, 
  266. 6763885, 6770789, 6777647, 6784457, 6791221, 6797940, 6804615, 6811244, 
  267. 6817831, 6824374, 6830874, 6837333, 6843750, 6850126, 6856462, 6862758, 
  268. 6869014, 6875232, 6881411, 6887553, 6893656, 6899723, 6905753, 6911747, 
  269. 6917706, 6923629, 6929517, 6935370, 6941190, 6946976, 6952729, 6958448, 
  270. 6964136, 6969791, 6975414, 6981006, 6986566, 6992096, 6997596, 7003065, 
  271. 7008505, 7013915, 7019297, 7024649, 7029973, 7035269, 7040536, 7045777, 
  272. 7050989, 7056175, 7061334, 7066467, 7071573, 7076654, 7081709, 7086738, 
  273. 7091742};
  274.  
  275.  
  276. /* Structure for transparent images */
  277.  
  278. void Undo(void);
  279. char    vstring[64]={AVSTR};
  280. extern int SecsPerMove;
  281. int  lastpiece=BLANKDATA;
  282.  
  283.  
  284. #ifdef AMIGA
  285.  
  286. #define PTRHEIGHT 55
  287.  
  288. #endif //AMIGA 
  289.  
  290.  
  291.  
  292. long    piecechar[12]={'p','n','b','r','q','k',
  293.               'P','N','B','R','Q','K'};
  294. char    oldboard[8][8];
  295.  
  296. int    BACKPEN=1;
  297.  
  298. int  BLACK=1;
  299.  
  300. //int  Picasso=0L;
  301. ULONG    bpen;
  302. int  PlayMode = 2;
  303. int  global_tmp_score=0;
  304. int  previous_score=0;
  305. extern short int ISZERO;
  306. extern int thinkahead;
  307. unsigned long int next = 1;
  308. int doswap=0;
  309. int doundo=0;
  310. int doauto=0;
  311. int gfxversion=0L;
  312. int v15Khz=0L;
  313. int teston=0;
  314. int cmptr_sec,cmptr_min,hum_sec,hum_min;
  315.  
  316. #ifdef AMIGA
  317. struct TagItem myTagList[8] = {
  318. {SA_DisplayID,VGAPRODUCT_KEY},
  319. {SA_Overscan,OSCAN_STANDARD},
  320. {0,0},
  321. {0,0},
  322. {0,0}
  323. };
  324. #define WINDOWSIGNAL (1L<<(wG->UserPort->mp_SigBit))
  325. ULONG  globalsignalset=0L;
  326. #define WINDOWSIGNAL (1L<<(wG->UserPort->mp_SigBit))
  327. ULONG  globalsignalset=0L;
  328. #endif
  329.  
  330. int  MoveNowOK=0;
  331.  
  332.  
  333. ULONG  RTG_ModeID=0x0L;
  334. int  Super72=0;
  335. int  RTG=0;
  336. int  SYSTEM_BOBS=1;
  337.  
  338. int  ResignOffered=0;
  339. //ULONG    tmppal[4];
  340.  
  341. void TimeCalc (void);
  342.  
  343.  
  344. int    FasterDisplay=0;
  345. int  trying_again=0;
  346. int  SupervisorMode=0;
  347. int  MenuStripSet = 0;
  348. int  GlobalTgtDepth=4; // was 3
  349. long  OrigCol,OrigRow,DestCol,DestRow;
  350.  
  351. #ifdef AMIGA
  352. UWORD chip myPointer[]={
  353. 0,0,
  354. 31744,0,
  355. 4096,0,
  356. 4096,0,
  357. 4096,0,
  358. 4096,0,
  359. 5120,0,
  360. 5120,0,
  361. 1024,0,
  362. 1920,0,
  363. 1152,0,
  364. 1152,0,
  365. 1152,0,
  366. 256,0,
  367. 0,0,
  368. 768,0,
  369. 256,0,
  370. 256,0,
  371. 256,0,
  372. 896,0,
  373. 0,0,
  374. 896,0,
  375. 576,0,
  376. 576,0,
  377. 576,0,
  378. 576,0,
  379. 0,0,
  380. 512,0,
  381. 512,0,
  382. 576,0,
  383. 640,0,
  384. 896,0,
  385. 640,0,
  386. 576,0,
  387. 0,0,
  388. 256,0,
  389. 0,0,
  390. 768,0,
  391. 256,0,
  392. 256,0,
  393. 256,0,
  394. 896,0,
  395. 0,0,
  396. 0,0,
  397. 896,0,
  398. 576,0,
  399. 576,0,
  400. 576,0,
  401. 576,0,
  402. 0,0,
  403. 960,0,
  404. 576,0,
  405. 576,0,
  406. 960,0,
  407. 64,0,
  408. 960,0,
  409. 0,0
  410. };
  411.  
  412.  
  413. struct TransImage
  414. {
  415.     struct Image *ti_IM;        /* The plain image */
  416.     struct BitMap *ti_sBM;      /* Shadow bitmap */
  417.     struct RastPort *ti_sRP;    /* Shadow rastport */
  418.     struct BitMap ti_BM;        /* Image bitmap */
  419.     struct RastPort ti_RP;      /* Image rastport */
  420. };
  421.  
  422. struct Image  BobImage;
  423.  
  424. struct TransImage  *BobTransImage;
  425.  
  426. struct TransImage *AllocTransImage (struct Image * im);
  427. VOID FreeTransImage (struct TransImage * ti);
  428. VOID ClipBlitTrans (struct RastPort *, WORD, WORD, struct RastPort *, WORD, WORD, WORD, WORD, struct RastPort *);
  429. struct BitMap *AllocShadowBM (UWORD, UWORD, UWORD);
  430. VOID FreeShadowBM (struct BitMap *);
  431. struct RastPort *AllocShadowRP (struct BitMap *);
  432. VOID FreeShadowRP (struct RastPort *);
  433.  
  434.  
  435.  
  436. #define TDEPTH 4
  437. #define THEIGHT 400 /* tmp ht */
  438. #define TBLOCKPEN 4 /* was 9 */
  439. #define MENUPEN 11
  440.  
  441. #ifdef EIGHT_BIT_SCREEN
  442. int  DEPTH=8;
  443. #ifdef MANYP
  444. int  HEIGHT=480;
  445. int  USERBOX=480-168;
  446. int  COMPUTERBOX=480-60;
  447. int  BACKGNDTEXTCOLOR=0xe0; /* for 256 use 0xe0 */
  448. int  BOBHEIGHT=55; /* 55 for 480 screens */
  449. int  ROW8B=24; /* 24 for 480 screens */
  450. int  MBLOCKPEN=251;
  451. #endif
  452. #else
  453. int  DEPTH=4;
  454. #endif
  455.  
  456. #endif // AMIGA
  457.  
  458. #include "Chess256.c"
  459.  
  460. TID myTID;
  461. int  TCadd = 0;
  462. int  thinking2=0; /* look for move now menu selection in elasped time when set */
  463. int  TIMEYCOORD1=480-120;
  464. int  TIMEYCOORD2=480-230;
  465. int  SYSBOXLEN=102;
  466. int  HEIGHT=480;
  467. int  USERBOX=480-168;
  468. int  SYSTEMBOX=480-233;
  469. int  COMPUTERBOX=480-60;
  470. int  BACKGNDTEXTCOLOR=0xe0; /* for 256 use 0xe0 */
  471. int  BOBHEIGHT=55; /* 55 for 480 screens 46 for 400 lines */
  472. int  ROW8B=480-24; /* 24 for 480 screens 20 for 400 line screens*/
  473. int  MBLOCKPEN=9;
  474.  
  475. #define MENUBARHT 11
  476. #define WIDTH 640
  477. #define VIEWMODES (HIRES|LACE)
  478.  
  479. int  BOBDEPTH=8;
  480.  
  481. #define BOARDWIDTH 640
  482. #define BOARDWIDINW 40
  483. #define BOARDSIZE (480*DEPTH*BOARDWIDINW*sizeof(WORD))
  484. #define BOARDBLOCKSIZE ((BOARDSIZE+(BOARDWIDINW*sizeof(WORD))*(480+2))+(BOARDWIDINW*sizeof(WORD)))
  485.  
  486. #define BOBWIDTH 64 /* only 59 pixels are really used, rest are tranparent */
  487. #define BOBWIDINW 4
  488. #define BOBSIZE (BOBHEIGHT*BOBDEPTH*BOBWIDINW*sizeof(WORD))
  489. #define BOBBLOCKSIZE ((BOBSIZE)+(BOBWIDINW*sizeof(WORD)*(BOBHEIGHT+2))+(BOBWIDINW*sizeof(WORD)))
  490.  
  491. #define BOBLW ((BOBBLOCKSIZE)/4)
  492. #define BOBMEMASK 0
  493. #define BOBHITMASK 0
  494. int  BOBPLANEPICK=0xf; /* if 16 colors should be 0xf if 256 should be 0xff */
  495. #define BOBPLANEONOFF 0x0
  496.  
  497. #define SQUAREWIDTH 59
  498. #define ROUNDEDSQUAREWIDTH 64
  499. #define SQUAREHEIGHT BOBHEIGHT
  500. #define COLA (16)
  501. #define COLB (16+SQUAREWIDTH)
  502. #define COLC (16+SQUAREWIDTH*2)
  503. #define COLD (16+SQUAREWIDTH*3)
  504. #define COLE (16+SQUAREWIDTH*4)
  505. #define COLF (16+SQUAREWIDTH*5)
  506. #define COLG (16+SQUAREWIDTH*6)
  507. #define COLH (16+SQUAREWIDTH*7)
  508. //#define ROW7 (ROW8-SQUAREHEIGHT)
  509. #define ROW8 (ROW8B-SQUAREHEIGHT)
  510. #define ROW7 (ROW8B-SQUAREHEIGHT*2)
  511. #define ROW6 (ROW8B-SQUAREHEIGHT*3)
  512. #define ROW5 (ROW8B-SQUAREHEIGHT*4)
  513. #define ROW4 (ROW8B-SQUAREHEIGHT*5)
  514. #define ROW3 (ROW8B-SQUAREHEIGHT*6)
  515. #define ROW2 (ROW8B-SQUAREHEIGHT*7)
  516. #define ROW1 (ROW8B-SQUAREHEIGHT*8)
  517.  
  518.  
  519. UWORD  *BlankImageData;
  520.  
  521. UWORD    *WhiteImageData[6];
  522. UWORD    *BlackImageData[6];
  523.  
  524. void LoadBobImage(long);
  525.  
  526. long    ColArray[8]={COLA,COLB,COLC,COLD,COLE,COLF,COLG,COLH};
  527. long    RowArray[8];
  528.  
  529. #ifdef AMIGA
  530. struct VSprite  *SpriteHead;
  531. struct VSprite  *SpriteTail;
  532.  
  533. struct GelsInfo  *myGelsInfo;
  534. struct VSprite  *BobVSprite;
  535. struct Bob  *TheBob;
  536.  
  537. struct BitMap  *WhiteBitMap,*BlackBitMap;
  538. struct BitMap *textBitMap=(struct BitMap *)0L;
  539.  
  540. struct TextFont  *myTextFont;
  541.  
  542. extern struct GfxBase  *Gfxbase;
  543. long  __stack=50000L;
  544. ULONG tt;
  545. struct RastPort  *rpG;
  546. struct ViewPort  *vP;
  547. struct Screen  *sC=0L;
  548. struct Window  *wG=0L;
  549. struct Window  *wGEdit;
  550. unsigned char    cookedchar[128]={'~',
  551.                   '1',
  552.                   '2',
  553.                   '3',
  554.                   '4',
  555.                   '5',
  556.                   '6',
  557.                   '7',
  558.                   '8',
  559.                   '9',
  560.                   '0', /* 10 */
  561.                   '-',
  562.                   '=',
  563.                   ' ',
  564.                   ' ',
  565.                   '0',
  566.                   'Q', /* 16 */
  567.                   'W',
  568.                   'E',
  569.                   'R',
  570.                   'T', /* 20 */
  571.                   'Y',
  572.                   'U',
  573.                   'I',
  574.                   'O',
  575.                   'P', /* 25 */
  576.                   '[',
  577.                   ']',
  578.                   ' ',
  579.                   '1',
  580.                   '2',
  581.                   '3',
  582.                   'A',
  583.                   'S',
  584.                   'D',
  585.                   'F',
  586.                   'G',
  587.                   'H',
  588.                   'J',
  589.                   'K',
  590.                   'L', /* 40 */
  591.                   ':',
  592.                   '"',
  593.                   13,
  594.                   ' ',
  595.                   '4',
  596.                   '5',
  597.                   '6',
  598.                   ' ',
  599.                   'Z',
  600.                   'X', /* 50 */
  601.                   'C',
  602.                   'V',
  603.                   'B',
  604.                   'N',
  605.                   'M', /* 55 */
  606.                   ',',
  607.                   '.',
  608.                   '/',
  609.                   ' ',
  610.                   '.',
  611.                   '7',
  612.                   '8',
  613.                   '9',
  614.                   ' ',
  615.                   7,
  616.                   8,
  617.                   13,
  618.                   13,
  619.                   27,
  620.                   7
  621. };
  622.  
  623.  
  624.  
  625.  
  626. char  *Orig_PlanePtr;
  627. struct BitMap  *myBitMap;
  628. struct BitMap  *OrigmyBitMap=0L;
  629.  
  630.  
  631.  
  632. UWORD    myPalette[16]=
  633. {
  634. 0xfbc, 0x632, 0x455, 0x842, 0x549, 0xa53, 0x787, 0xa56, 
  635. 0x967, 0xa85, 0x3ab, 0xaaa, 0xe88, 0xdb8, 0x333, 0xeee
  636. };
  637.  
  638. #ifdef OLDPAL
  639. {
  640. 0x0, 0x222, 0x410, 0x333, 
  641. 0x621, 0x624, 0x952, 0x665, 
  642. 0x974, 0x887, 0xb85, 0xaa9, 
  643. 0xbb7, 0xcc8, 0xcc9, 0xddc};
  644. #endif 
  645.  
  646. struct TextAttr    TOPAZ80 = {
  647.     (STRPTR)"topaz.font",
  648.     TOPAZ_EIGHTY,0,0
  649. };
  650.  
  651. SHORT    BorderVectors6[] = {
  652.     0,0,
  653.     44,0,
  654.     44,19,
  655.     0,19,
  656.     0,0
  657. };
  658. struct Border    Border6 = {
  659.     -1,-1,  /* XY origin relative to container TopLeft */
  660.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  661.     5,      /* number of XY vectors */
  662.     BorderVectors6, /* pointer to XY vectors */
  663.     NULL    /* next border in list */
  664. };
  665.  
  666. struct IntuiText    IText93 = {
  667.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  668.     12,6,   /* XY origin relative to container TopLeft */
  669.     NULL,   /* font pointer or NULL for default */
  670.     "OK",   /* pointer to text */
  671.     NULL    /* next IntuiText structure */
  672. };
  673.  
  674. struct Gadget    Gadget9 = {
  675.     NULL,   /* next gadget */
  676.     109,64, /* origin XY of hit box relative to window TopLeft */
  677.     43,18,  /* hit box width and height */
  678.     NULL,   /* gadget flags */
  679.     RELVERIFY,      /* activation flags */
  680.     BOOLGADGET,     /* gadget type flags */
  681.     (APTR)&Border6, /* gadget border or image to be rendered */
  682.     NULL,   /* alternate imagery for selection */
  683.     &IText93,       /* first IntuiText structure */
  684.     NULL,   /* gadget mutual-exclude long word */
  685.     NULL,   /* SpecialInfo structure */
  686.     NULL,   /* user-definable data */
  687.     NULL    /* pointer to user-definable data */
  688. };
  689.  
  690. UBYTE  Gadget8SIBuff[8];
  691. struct StringInfo  Gadget8SInfo = {
  692.     Gadget8SIBuff,  /* buffer where text will be edited */
  693.     NULL,   /* optional undo buffer */
  694.     0,      /* character position in buffer */
  695.     5,      /* maximum number of characters to allow */
  696.     0,      /* first displayed character buffer position */
  697.     0,0,0,0,0,      /* Intuition initialized and maintained variables */
  698.     0,      /* Rastport of gadget */
  699.     0,      /* initial value for integer gadgets */
  700.     NULL    /* alternate keymap (fill in if you set the flag) */
  701. };
  702.  
  703. SHORT    BorderVectors7[] = {
  704.     0,0,
  705.     45,0 /* was 45 */,
  706.     45,14, /* was 17 */
  707.     0,14,
  708.     0,0
  709. };
  710. struct Border    Border7 = {
  711.     -1,-1,  /* XY origin relative to container TopLeft */
  712.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  713.     5,      /* number of XY vectors */
  714.     BorderVectors7, /* pointer to XY vectors */
  715.     NULL    /* next border in list */
  716. };
  717.  
  718. struct Gadget    Gadget8 = {
  719.     &Gadget9,       /* next gadget */
  720.     136,32, /* origin XY of hit box relative to window TopLeft */
  721.     44,16,  /* hit box width and height */
  722.     NULL,   /* gadget flags */
  723.     RELVERIFY,      /* activation flags */
  724.     STRGADGET,      /* gadget type flags */
  725.     (APTR)&Border7, /* gadget border or image to be rendered */
  726.     NULL,   /* alternate imagery for selection */
  727.     NULL,   /* first IntuiText structure */
  728.     NULL,   /* gadget mutual-exclude long word */
  729.     (APTR)&Gadget8SInfo,    /* SpecialInfo structure */
  730.     NULL,   /* user-definable data */
  731.     NULL    /* pointer to user-definable data */
  732. };
  733.  
  734.  
  735. UBYTE  Gadget6SIBuff[8];
  736. struct StringInfo  Gadget6SInfo = {
  737.     Gadget6SIBuff,  /* buffer where text will be edited */
  738.     NULL,   /* optional undo buffer */
  739.     0,      /* character position in buffer */
  740.     4,      /* maximum number of characters to allow */
  741.     0,      /* first displayed character buffer position */
  742.     0,0,0,0,0,      /* Intuition initialized and maintained variables */
  743.     0,      /* Rastport of gadget */
  744.     0,      /* initial value for integer gadgets */
  745.     NULL    /* alternate keymap (fill in if you set the flag) */
  746. };
  747.  
  748. struct Border    Border9 = {
  749.     -1,-1,  /* XY origin relative to container TopLeft */
  750.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  751.     5,      /* number of XY vectors */
  752.     BorderVectors7, /* pointer to XY vectors */
  753.     NULL    /* next border in list */
  754. };
  755.  
  756. struct Gadget    Gadget6 = {
  757.     &Gadget8,       /* next gadget */
  758.     14,32,  /* origin XY of hit box relative to window TopLeft */
  759.     44,16,  /* hit box width and height */
  760.     NULL,   /* gadget flags */
  761.     RELVERIFY,      /* activation flags */
  762.     STRGADGET,      /* gadget type flags */
  763.     (APTR)&Border9, /* gadget border or image to be rendered */
  764.     NULL,   /* alternate imagery for selection */
  765.     NULL,   /* first IntuiText structure */
  766.     NULL,   /* gadget mutual-exclude long word */
  767.     (APTR)&Gadget6SInfo,    /* SpecialInfo structure */
  768.     NULL,   /* user-definable data */
  769.     NULL    /* pointer to user-definable data */
  770. };
  771.  
  772. struct Gadget    Gadget6b = {
  773.     &Gadget9,       /* next gadget */
  774.     14,32,  /* origin XY of hit box relative to window TopLeft */
  775.     44,16,  /* hit box width and height */
  776.     NULL,   /* gadget flags */
  777.     RELVERIFY,      /* activation flags */
  778.     STRGADGET,      /* gadget type flags */
  779.     (APTR)&Border9, /* gadget border or image to be rendered */
  780.     NULL,   /* alternate imagery for selection */
  781.     NULL,   /* first IntuiText structure */
  782.     NULL,   /* gadget mutual-exclude long word */
  783.     (APTR)&Gadget6SInfo,    /* SpecialInfo structure */
  784.     NULL,   /* user-definable data */
  785.     NULL    /* pointer to user-definable data */
  786. };
  787.  
  788.  
  789.  
  790.  
  791. struct IntuiText  IText47 = {
  792.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  793.     195,36, /* XY origin relative to container TopLeft */
  794.     NULL,   /* font pointer or NULL for default */
  795.     "Minutes.",     /* pointer to text */
  796.     NULL    /* next IntuiText structure */
  797. };
  798.  
  799. struct IntuiText    IText46 = {
  800.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  801.     64,35,  /* XY origin relative to container TopLeft */
  802.     NULL,   /* font pointer or NULL for default */
  803.     "Moves in",     /* pointer to text */
  804.     &IText47        /* next IntuiText structure */
  805. };
  806.  
  807. #define IntuiTextList5 IText46
  808.  
  809. struct NewWindow    NewWindowStructure5 = {
  810.     161,23, /* window XY origin relative to TopLeft of screen */
  811.     270,90, /* window width and height */
  812.     0,TBLOCKPEN,    /* detail and block pens */
  813.     GADGETUP,       /* IDCMP flags */
  814.     SIMPLE_REFRESH+ACTIVATE+NOCAREREFRESH,  /* other window flags */
  815.     &Gadget6,       /* first gadget in gadget list */
  816.     NULL,   /* custom CHECKMARK imagery */
  817.     "Computer Time Ctrl",   /* window title */
  818.     NULL,   /* custom screen pointer */
  819.     NULL,   /* custom bitmap */
  820.     5,5,    /* minimum width and height */
  821.     0xffff,0xffff,  /* maximum width and height */
  822.     CUSTOMSCREEN    /* destination screen type */
  823. };
  824.  
  825.  
  826. struct ExtNewScreen    NewScreenStructure = {
  827.     0,0,    /* screen XY origin relative to View */
  828.     WIDTH,THEIGHT,  /* screen width and height */
  829.     4,      /* screen depth (number of bitplanes) */
  830.     0,TBLOCKPEN,    /* detail and block pens */
  831.     VIEWMODES,      /* display modes for this screen */
  832.     CUSTOMBITMAP|CUSTOMSCREEN,      /* screen type */
  833.     &TOPAZ80,       /* pointer to default screen font */
  834.     VERSTRING,      /* screen title */
  835.     NULL,   /* first in list of custom screen gadgets */
  836.     NULL    /* pointer to custom BitMap structure */
  837. };
  838.  
  839. struct ExtNewScreen    NewScreenStructure2 = {
  840.     0,0,    /* screen XY origin relative to View */
  841.     WIDTH,480,      /* screen width and height */
  842.     8,      /* screen depth (number of bitplanes) */
  843.     0,251,  /* detail and block pens */
  844.     VIEWMODES,      /* display modes for this screen */
  845.     CUSTOMSCREEN|SCREENBEHIND,      /* screen type */
  846.     &TOPAZ80,       /* pointer to default screen font */
  847.     " ",    /* screen title */
  848.     NULL,   /* first in list of custom screen gadgets */
  849.     NULL    /* pointer to custom BitMap structure */
  850. };
  851.  
  852.  
  853. struct IntuiText    IText37 = {
  854.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  855.     0,0,    /* XY origin relative to container TopLeft */
  856.     &TOPAZ80,       /* font pointer or NULL for default */
  857.     "New Game",     /* pointer to text */
  858.     NULL    /* next IntuiText structure */
  859. };
  860.  
  861. struct IntuiText    IText1r = {
  862.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  863.     0,0,    /* XY origin relative to container TopLeft */
  864.     &TOPAZ80,       /* font pointer or NULL for default */
  865.     "Set Depth",    /* pointer to text */
  866.     NULL    /* next IntuiText structure */
  867. };
  868.  
  869. struct MenuItem  MenuItem3r = {
  870.     NULL,   /* next MenuItem structure */
  871.     0,32,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  872.     72,8,   /* hit box width and height */
  873.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  874.     0,      /* each bit mutually-excludes a same-level Item */
  875.     (APTR)&IText1r, /* Item render  (IntuiText or Image or NULL) */
  876.     NULL,   /* Select render */
  877.     NULL,   /* alternate command-key */
  878.     NULL,   /* SubItem list */
  879.     MENUNULL        /* filled in by Intuition for drag selections */
  880. };
  881.  
  882. struct IntuiText    IText1 = {
  883.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  884.     0,0,    /* XY origin relative to container TopLeft */
  885.     &TOPAZ80,       /* font pointer or NULL for default */
  886.     "Set Time",     /* pointer to text */
  887.     NULL    /* next IntuiText structure */
  888. };
  889.  
  890. struct MenuItem  MenuItem3 = {
  891.     &MenuItem3r,    /* next MenuItem structure */
  892.     0,24,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  893.     72,8,   /* hit box width and height */
  894.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  895.     0,      /* each bit mutually-excludes a same-level Item */
  896.     (APTR)&IText1,  /* Item render  (IntuiText or Image or NULL) */
  897.     NULL,   /* Select render */
  898.     NULL,   /* alternate command-key */
  899.     NULL,   /* SubItem list */
  900.     MENUNULL        /* filled in by Intuition for drag selections */
  901. };
  902.  
  903. struct IntuiText    IText2x = {
  904.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  905.     0,0,    /* XY origin relative to container TopLeft */
  906.     &TOPAZ80,       /* font pointer or NULL for default */
  907.     "Rate Pgm",     /* pointer to text */
  908.     NULL    /* next IntuiText structure */
  909. };
  910.  
  911. struct MenuItem  MenuItem3x = {
  912.     &MenuItem3,     /* next MenuItem structure */
  913.     0,16,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  914.     72,8,   /* hit box width and height */
  915.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  916.     0,      /* each bit mutually-excludes a same-level Item */
  917.     (APTR)&IText2x, /* Item render  (IntuiText or Image or NULL) */
  918.     NULL,   /* Select render */
  919.     NULL,   /* alternate command-key */
  920.     NULL,   /* SubItem list */
  921.     MENUNULL        /* filled in by Intuition for drag selections */
  922. };
  923.  
  924. struct IntuiText    IText2 = {
  925.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  926.     0,0,    /* XY origin relative to container TopLeft */
  927.     &TOPAZ80,       /* font pointer or NULL for default */
  928.     "Test", /* pointer to text */
  929.     NULL    /* next IntuiText structure */
  930. };
  931.  
  932. struct MenuItem  MenuItem2 = {
  933.     &MenuItem3x,    /* next MenuItem structure */
  934.     0,8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  935.     72,8,   /* hit box width and height */
  936.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  937.     0,      /* each bit mutually-excludes a same-level Item */
  938.     (APTR)&IText2,  /* Item render  (IntuiText or Image or NULL) */
  939.     NULL,   /* Select render */
  940.     NULL,   /* alternate command-key */
  941.     NULL,   /* SubItem list */
  942.     MENUNULL        /* filled in by Intuition for drag selections */
  943. };
  944.  
  945. struct IntuiText    IText3 = {
  946.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  947.     0,0,    /* XY origin relative to container TopLeft */
  948.     &TOPAZ80,       /* font pointer or NULL for default */
  949.     "Hint", /* pointer to text */
  950.     NULL    /* next IntuiText structure */
  951. };
  952.  
  953. struct MenuItem  MenuItem1 = {
  954.     &MenuItem2,     /* next MenuItem structure */
  955.     0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  956.     72,8,   /* hit box width and height */
  957.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  958.     0,      /* each bit mutually-excludes a same-level Item */
  959.     (APTR)&IText3,  /* Item render  (IntuiText or Image or NULL) */
  960.     NULL,   /* Select render */
  961.     'H',    /* alternate command-key */
  962.     NULL,   /* SubItem list */
  963.     MENUNULL        /* filled in by Intuition for drag selections */
  964. };
  965.  
  966. struct Menu  Menu4 = {
  967.     NULL,   /* next Menu structure */
  968.     162,0,  /* XY origin of Menu hit box relative to screen TopLeft */
  969.     63,0,   /* Menu hit box width and height */
  970.     MENUENABLED,    /* Menu flags */
  971.     "Special",      /* text of Menu name */
  972.     &MenuItem1      /* MenuItem linked list pointer */
  973. };
  974.  
  975. struct IntuiText    IText4cc = {
  976.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  977.     19,0,   /* XY origin relative to container TopLeft */
  978.     &TOPAZ80,       /* font pointer or NULL for default */
  979.     "Easy", /* pointer to text */
  980.     NULL    /* next IntuiText structure */
  981. };
  982.  
  983. struct MenuItem  MenuItem8cc = {
  984.     NULL,   /* next MenuItem structure */
  985.     0,80,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  986.     123,8,  /* hit box width and height */
  987.     CHECKIT+MENUTOGGLE+ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,       /* Item flags */
  988.     EXCLUDE_PATT^(0x400),   /* each bit mutually-excludes a same-level Item */
  989.     (APTR)&IText4cc,        /* Item render  (IntuiText or Image or NULL) */
  990.     NULL,   /* Select render */
  991.     'E',    /* alternate command-key */
  992.     NULL,   /* SubItem list */
  993.     MENUNULL        /* filled in by Intuition for drag selections */
  994. };
  995.  
  996. struct IntuiText    IText4dd = {
  997.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  998.     19,0,   /* XY origin relative to container TopLeft */
  999.     &TOPAZ80,       /* font pointer or NULL for default */
  1000.     "Intrmdt",      /* pointer to text */
  1001.     NULL    /* next IntuiText structure */
  1002. };
  1003.  
  1004. struct MenuItem  MenuItem8dd = {
  1005.     &MenuItem8cc,   /* next MenuItem structure */
  1006.     0,72,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1007.     123,8,  /* hit box width and height */
  1008.     CHECKIT+MENUTOGGLE+ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,       /* Item flags */
  1009.     EXCLUDE_PATT^(0x200),   /* each bit mutually-excludes a same-level Item */
  1010.     (APTR)&IText4dd,        /* Item render  (IntuiText or Image or NULL) */
  1011.     NULL,   /* Select render */
  1012.     'I',    /* alternate command-key */
  1013.     NULL,   /* SubItem list */
  1014.     MENUNULL        /* filled in by Intuition for drag selections */
  1015. };
  1016.  
  1017. struct IntuiText    IText4ee = {
  1018.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1019.     19,0,   /* XY origin relative to container TopLeft */
  1020.     &TOPAZ80,       /* font pointer or NULL for default */
  1021.     "Advancd",      /* pointer to text */
  1022.     NULL    /* next IntuiText structure */
  1023. };
  1024.  
  1025. struct MenuItem  MenuItem8ee = {
  1026.     &MenuItem8dd,   /* next MenuItem structure */
  1027.     0,64,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1028.     123,8,  /* hit box width and height */
  1029.     CHECKED+CHECKIT+MENUTOGGLE+ITEMTEXT+COMMSEQ+HIGHCOMP,   /* Item flags */
  1030.     EXCLUDE_PATT^(0x100),   /* each bit mutually-excludes a same-level Item */
  1031.     (APTR)&IText4ee,        /* Item render  (IntuiText or Image or NULL) */
  1032.     NULL,   /* Select render */
  1033.     'A',    /* alternate command-key */
  1034.     NULL,   /* SubItem list */
  1035.     MENUNULL        /* filled in by Intuition for drag selections */
  1036. };
  1037.  
  1038. struct IntuiText    IText4aa = {
  1039.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1040.     19,0,   /* XY origin relative to container TopLeft */
  1041.     &TOPAZ80,       /* font pointer or NULL for default */
  1042.     "Supvsr",       /* pointer to text */
  1043.     NULL    /* next IntuiText structure */
  1044. };
  1045.  
  1046. struct MenuItem  MenuItem8aa = {
  1047.     &MenuItem8ee,   /* next MenuItem structure */
  1048.     0,56,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1049.     123,8,  /* hit box width and height */
  1050.     CHECKIT+MENUTOGGLE+ITEMTEXT+COMMSEQ+/*ITEMENABLED+*/HIGHCOMP,   /* Item flags */
  1051.     0,      /* each bit mutually-excludes a same-level Item */
  1052.     (APTR)&IText4aa,        /* Item render  (IntuiText or Image or NULL) */
  1053.     NULL,   /* Select render */
  1054.     'Y',    /* alternate command-key */
  1055.     NULL,   /* SubItem list */
  1056.     MENUNULL        /* filled in by Intuition for drag selections */
  1057. };
  1058.  
  1059. struct IntuiText    IText4ab = {
  1060.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1061.     19,0,   /* XY origin relative to container TopLeft */
  1062.     &TOPAZ80,       /* font pointer or NULL for default */
  1063.     "Book", /* pointer to text */
  1064.     NULL    /* next IntuiText structure */
  1065. };
  1066.  
  1067. struct MenuItem  MenuItem8ab = {
  1068.     &MenuItem8aa,   /* next MenuItem structure */
  1069.     0,48,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1070.     123,8,  /* hit box width and height */
  1071.     CHECKIT+CHECKED+MENUTOGGLE+ITEMTEXT+COMMSEQ+/*ITEMENABLED+*/HIGHCOMP,   /* Item flags */
  1072.     0,      /* each bit mutually-excludes a same-level Item */
  1073.     (APTR)&IText4ab,        /* Item render  (IntuiText or Image or NULL) */
  1074.     NULL,   /* Select render */
  1075.     'B',    /* alternate command-key */
  1076.     NULL,   /* SubItem list */
  1077.     MENUNULL        /* filled in by Intuition for drag selections */
  1078. };
  1079.  
  1080. struct IntuiText    IText4a = {
  1081.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1082.     19,0,   /* XY origin relative to container TopLeft */
  1083.     &TOPAZ80,       /* font pointer or NULL for default */
  1084.     "ShwThnk",      /* pointer to text */
  1085.     NULL    /* next IntuiText structure */
  1086. };
  1087.  
  1088. struct MenuItem  MenuItem8a = {
  1089.     &MenuItem8ab,   /* next MenuItem structure */
  1090.     0,40,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1091.     123,8,  /* hit box width and height */
  1092.     CHECKIT+MENUTOGGLE+ITEMTEXT+COMMSEQ+/*ITEMENABLED+*/HIGHCOMP,   /* Item flags */
  1093.     0,      /* each bit mutually-excludes a same-level Item */
  1094.     (APTR)&IText4a, /* Item render  (IntuiText or Image or NULL) */
  1095.     NULL,   /* Select render */
  1096.     'V',    /* alternate command-key */
  1097.     NULL,   /* SubItem list */
  1098.     MENUNULL        /* filled in by Intuition for drag selections */
  1099. };
  1100.  
  1101. struct IntuiText    IText4 = {
  1102.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1103.     19,0,   /* XY origin relative to container TopLeft */
  1104.     &TOPAZ80,       /* font pointer or NULL for default */
  1105.     "Thinking",     /* pointer to text */
  1106.     NULL    /* next IntuiText structure */
  1107. };
  1108.  
  1109. struct MenuItem  MenuItem8 = {
  1110.     &MenuItem8a,    /* next MenuItem structure */
  1111.     0,32,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1112.     123,8,  /* hit box width and height */
  1113.     CHECKIT+MENUTOGGLE+ITEMTEXT+COMMSEQ/*+ITEMENABLED*/+HIGHCOMP,   /* Item flags */
  1114.     0,      /* each bit mutually-excludes a same-level Item */
  1115.     (APTR)&IText4,  /* Item render  (IntuiText or Image or NULL) */
  1116.     NULL,   /* Select render */
  1117.     'T',    /* alternate command-key */
  1118.     NULL,   /* SubItem list */
  1119.     MENUNULL        /* filled in by Intuition for drag selections */
  1120. };
  1121.  
  1122. struct IntuiText    IText5 = {
  1123.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1124.     0,0,    /* XY origin relative to container TopLeft */
  1125.     &TOPAZ80,       /* font pointer or NULL for default */
  1126.     "Undo", /* pointer to text */
  1127.     NULL    /* next IntuiText structure */
  1128. };
  1129.  
  1130. struct MenuItem  MenuItem7 = {
  1131.     &MenuItem8,     /* next MenuItem structure */
  1132.     0,24,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1133.     123,8,  /* hit box width and height */
  1134.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1135.     0,      /* each bit mutually-excludes a same-level Item */
  1136.     (APTR)&IText5,  /* Item render  (IntuiText or Image or NULL) */
  1137.     NULL,   /* Select render */
  1138.     'U',    /* alternate command-key */
  1139.     NULL,   /* SubItem list */
  1140.     MENUNULL        /* filled in by Intuition for drag selections */
  1141. };
  1142.  
  1143. struct IntuiText    IText6 = {
  1144.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1145.     0,0,    /* XY origin relative to container TopLeft */
  1146.     &TOPAZ80,       /* font pointer or NULL for default */
  1147.     "Move Now",     /* pointer to text */
  1148.     NULL    /* next IntuiText structure */
  1149. };
  1150.  
  1151. struct MenuItem  MenuItem6 = {
  1152.     &MenuItem7,     /* next MenuItem structure */
  1153.     0,16,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1154.     123,8,  /* hit box width and height */
  1155.     ITEMTEXT+COMMSEQ+/*ITEMENABLED+*/HIGHCOMP,      /* Item flags */
  1156.     0,      /* each bit mutually-excludes a same-level Item */
  1157.     (APTR)&IText6,  /* Item render  (IntuiText or Image or NULL) */
  1158.     NULL,   /* Select render */
  1159.     'M',    /* alternate command-key */
  1160.     NULL,   /* SubItem list */
  1161.     MENUNULL        /* filled in by Intuition for drag selections */
  1162. };
  1163.  
  1164. struct IntuiText    IText7 = {
  1165.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1166.     0,0,    /* XY origin relative to container TopLeft */
  1167.     &TOPAZ80,       /* font pointer or NULL for default */
  1168.     "AutoPlay",     /* pointer to text */
  1169.     NULL    /* next IntuiText structure */
  1170. };
  1171.  
  1172. struct MenuItem  MenuItem5 = {
  1173.     &MenuItem6,     /* next MenuItem structure */
  1174.     0,8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1175.     123,8,  /* hit box width and height */
  1176.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1177.     0,      /* each bit mutually-excludes a same-level Item */
  1178.     (APTR)&IText7,  /* Item render  (IntuiText or Image or NULL) */
  1179.     NULL,   /* Select render */
  1180.     NULL,   /* alternate command-key */
  1181.     NULL,   /* SubItem list */
  1182.     MENUNULL        /* filled in by Intuition for drag selections */
  1183. };
  1184.  
  1185. struct IntuiText    IText8 = {
  1186.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1187.     0,0,    /* XY origin relative to container TopLeft */
  1188.     &TOPAZ80,       /* font pointer or NULL for default */
  1189.     "Swap Sides",   /* pointer to text */
  1190.     NULL    /* next IntuiText structure */
  1191. };
  1192.  
  1193. struct MenuItem  MenuItem4 = {
  1194.     &MenuItem5,     /* next MenuItem structure */
  1195.     0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1196.     123,8,  /* hit box width and height */
  1197.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1198.     0,      /* each bit mutually-excludes a same-level Item */
  1199.     (APTR)&IText8,  /* Item render  (IntuiText or Image or NULL) */
  1200.     NULL,   /* Select render */
  1201.     'S',    /* alternate command-key */
  1202.     NULL,   /* SubItem list */
  1203.     MENUNULL        /* filled in by Intuition for drag selections */
  1204. };
  1205.  
  1206. struct Menu  Menu3 = {
  1207.     &Menu4, /* next Menu structure */
  1208.     92,0,   /* XY origin of Menu hit box relative to screen TopLeft */
  1209.     63,0,   /* Menu hit box width and height */
  1210.     MENUENABLED,    /* Menu flags */
  1211.     "Control",      /* text of Menu name */
  1212.     &MenuItem4      /* MenuItem linked list pointer */
  1213. };
  1214.  
  1215. struct IntuiText    IText9 = {
  1216.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1217.     0,0,    /* XY origin relative to container TopLeft */
  1218.     &TOPAZ80,       /* font pointer or NULL for default */
  1219.     "ReverseBoard", /* pointer to text */
  1220.     NULL    /* next IntuiText structure */
  1221. };
  1222.  
  1223. struct MenuItem  MenuItem11 = {
  1224.     NULL,   /* next MenuItem structure */
  1225.     0,16,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1226.     96,8,   /* hit box width and height */
  1227.     ITEMTEXT+/*ITEMENABLED+*/HIGHCOMP,      /* Item flags */
  1228.     0,      /* each bit mutually-excludes a same-level Item */
  1229.     (APTR)&IText9,  /* Item render  (IntuiText or Image or NULL) */
  1230.     NULL,   /* Select render */
  1231.     NULL,   /* alternate command-key */
  1232.     NULL,   /* SubItem list */
  1233.     MENUNULL        /* filled in by Intuition for drag selections */
  1234. };
  1235.  
  1236. struct IntuiText    IText10 = {
  1237.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1238.     19,0,   /* XY origin relative to container TopLeft */
  1239.     &TOPAZ80,       /* font pointer or NULL for default */
  1240.     "Edit Board",   /* pointer to text */
  1241.     NULL    /* next IntuiText structure */
  1242. };
  1243.  
  1244. struct MenuItem  MenuItem10 = {
  1245.     &MenuItem11,    /* next MenuItem structure */
  1246.     0,8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1247.     96,8,   /* hit box width and height */
  1248.     ITEMTEXT+HIGHCOMP+ITEMENABLED,  /* Item flags */
  1249.     0,      /* each bit mutually-excludes a same-level Item */
  1250.     (APTR)&IText10, /* Item render  (IntuiText or Image or NULL) */
  1251.     NULL,   /* Select render */
  1252.     NULL,   /* alternate command-key */
  1253.     NULL,   /* SubItem list */
  1254.     MENUNULL        /* filled in by Intuition for drag selections */
  1255. };
  1256.  
  1257. struct IntuiText    IText11 = {
  1258.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1259.     19,0,   /* XY origin relative to container TopLeft */
  1260.     &TOPAZ80,       /* font pointer or NULL for default */
  1261.     "2-D",  /* pointer to text */
  1262.     NULL    /* next IntuiText structure */
  1263. };
  1264.  
  1265. struct MenuItem  MenuItem9 = {
  1266.     &MenuItem10,    /* next MenuItem structure */
  1267.     0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1268.     96,8,   /* hit box width and height */
  1269.     CHECKED+CHECKIT+ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1270.     0,      /* each bit mutually-excludes a same-level Item */
  1271.     (APTR)&IText11, /* Item render  (IntuiText or Image or NULL) */
  1272.     NULL,   /* Select render */
  1273.     NULL,   /* alternate command-key */
  1274.     NULL,   /* SubItem list */
  1275.     MENUNULL        /* filled in by Intuition for drag selections */
  1276. };
  1277.  
  1278. struct Menu  Menu2 = {
  1279.     &Menu3, /* next Menu structure */
  1280.     46,0,   /* XY origin of Menu hit box relative to screen TopLeft */
  1281.     39,0,   /* Menu hit box width and height */
  1282.     MENUENABLED,    /* Menu flags */
  1283.     "View", /* text of Menu name */
  1284.     &MenuItem9      /* MenuItem linked list pointer */
  1285. };
  1286.  
  1287. struct IntuiText    IText12 = {
  1288.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1289.     0,0,    /* XY origin relative to container TopLeft */
  1290.     &TOPAZ80,       /* font pointer or NULL for default */
  1291.     "Quit", /* pointer to text */
  1292.     NULL    /* next IntuiText structure */
  1293. };
  1294.  
  1295. struct MenuItem  MenuItem15 = {
  1296.     NULL,   /* next MenuItem structure */
  1297.     0,40,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1298.     72,8,   /* hit box width and height */
  1299.     ITEMTEXT+COMMSEQ+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1300.     0,      /* each bit mutually-excludes a same-level Item */
  1301.     (APTR)&IText12, /* Item render  (IntuiText or Image or NULL) */
  1302.     NULL,   /* Select render */
  1303.     'Q',    /* alternate command-key */
  1304.     NULL,   /* SubItem list */
  1305.     MENUNULL        /* filled in by Intuition for drag selections */
  1306. };
  1307.  
  1308. struct IntuiText    IText13a = {
  1309.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1310.     0,0,    /* XY origin relative to container TopLeft */
  1311.     &TOPAZ80,       /* font pointer or NULL for default */
  1312.     "List Game",    /* pointer to text */
  1313.     NULL    /* next IntuiText structure */
  1314. };
  1315.  
  1316. struct MenuItem  MenuItem14a = {
  1317.     &MenuItem15,    /* next MenuItem structure */
  1318.     0,32,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1319.     72,8,   /* hit box width and height */
  1320.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1321.     0,      /* each bit mutually-excludes a same-level Item */
  1322.     (APTR)&IText13a,/* Item render  (IntuiText or Image or NULL) */
  1323.     NULL,   /* Select render */
  1324.     NULL,   /* alternate command-key */
  1325.     NULL,   /* SubItem list */
  1326.     MENUNULL        /* filled in by Intuition for drag selections */
  1327. };
  1328.  
  1329. struct IntuiText    IText13 = {
  1330.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1331.     0,0,    /* XY origin relative to container TopLeft */
  1332.     &TOPAZ80,       /* font pointer or NULL for default */
  1333.     "Save Game",    /* pointer to text */
  1334.     NULL    /* next IntuiText structure */
  1335. };
  1336.  
  1337. struct MenuItem  MenuItem14 = {
  1338.     &MenuItem14a,   /* next MenuItem structure */
  1339.     0,24,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1340.     72,8,   /* hit box width and height */
  1341.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1342.     0,      /* each bit mutually-excludes a same-level Item */
  1343.     (APTR)&IText13, /* Item render  (IntuiText or Image or NULL) */
  1344.     NULL,   /* Select render */
  1345.     NULL,   /* alternate command-key */
  1346.     NULL,   /* SubItem list */
  1347.     MENUNULL        /* filled in by Intuition for drag selections */
  1348. };
  1349.  
  1350. struct IntuiText    IText14 = {
  1351.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1352.     0,0,    /* XY origin relative to container TopLeft */
  1353.     &TOPAZ80,       /* font pointer or NULL for default */
  1354.     "Load Game",    /* pointer to text */
  1355.     NULL    /* next IntuiText structure */
  1356. };
  1357.  
  1358. struct MenuItem  MenuItem13 = {
  1359.     &MenuItem14,    /* next MenuItem structure */
  1360.     0,16,   /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1361.     72,8,   /* hit box width and height */
  1362.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1363.     0,      /* each bit mutually-excludes a same-level Item */
  1364.     (APTR)&IText14, /* Item render  (IntuiText or Image or NULL) */
  1365.     NULL,   /* Select render */
  1366.     NULL,   /* alternate command-key */
  1367.     NULL,   /* SubItem list */
  1368.     MENUNULL        /* filled in by Intuition for drag selections */
  1369. };
  1370.  
  1371. struct MenuItem  MenuItem28 = {
  1372.     &MenuItem13,    /* next MenuItem structure */
  1373.     0,8,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1374.     72,8,   /* hit box width and height */
  1375.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1376.     0,      /* each bit mutually-excludes a same-level Item */
  1377.     (APTR)&IText37, /* Item render  (IntuiText or Image or NULL) */
  1378.     NULL,   /* Select render */
  1379.     NULL,   /* alternate command-key */
  1380.     NULL,   /* SubItem list */
  1381.     MENUNULL        /* filled in by Intuition for drag selections */
  1382. };
  1383.  
  1384. struct IntuiText    IText15 = {
  1385.     MENUPEN,1,JAM1,//TBLOCKPEN,1,COMPLEMENT,        /* front and back text pens, drawmode and fill byte */
  1386.     0,0,    /* XY origin relative to container TopLeft */
  1387.     &TOPAZ80,       /* font pointer or NULL for default */
  1388.     "About..",      /* pointer to text */
  1389.     NULL    /* next IntuiText structure */
  1390. };
  1391.  
  1392. struct MenuItem  MenuItem12 = {
  1393.     &MenuItem28,    /* next MenuItem structure */
  1394.     0,0,    /* XY of Item hitbox relative to TopLeft of parent hitbox */
  1395.     72,8,   /* hit box width and height */
  1396.     ITEMTEXT+ITEMENABLED+HIGHCOMP,  /* Item flags */
  1397.     0,      /* each bit mutually-excludes a same-level Item */
  1398.     (APTR)&IText15, /* Item render  (IntuiText or Image or NULL) */
  1399.     NULL,   /* Select render */
  1400.     NULL,   /* alternate command-key */
  1401.     NULL,   /* SubItem list */
  1402.     MENUNULL        /* filled in by Intuition for drag selections */
  1403. };
  1404.  
  1405. struct Menu  Menu1 = {
  1406.     &Menu2, /* next Menu structure */
  1407.     0,0,    /* XY origin of Menu hit box relative to screen TopLeft */
  1408.     39,0,   /* Menu hit box width and height */
  1409.     MENUENABLED,    /* Menu flags */
  1410.     "File", /* text of Menu name */
  1411.     &MenuItem12     /* MenuItem linked list pointer */
  1412. };
  1413.  
  1414. #define MenuList1 Menu1
  1415.  
  1416. struct NewWindow  NewWindowStructure1 = {
  1417.     0,0,    /* window XY origin relative to TopLeft of screen */
  1418.     WIDTH,THEIGHT,  /* window width and height */
  1419.     0,TBLOCKPEN,    /* detail and block pens */
  1420.     MOUSEBUTTONS|MENUPICK|RAWKEY,   /* IDCMP flags */
  1421.     BACKDROP+BORDERLESS+ACTIVATE+NOCAREREFRESH,     /* other window flags */
  1422.     NULL,   /* first gadget in gadget list */
  1423.     NULL,   /* custom CHECKMARK imagery */
  1424.     " ",    /* window title */
  1425.     NULL,   /* custom screen pointer */
  1426.     NULL,   /* custom bitmap */
  1427.     WIDTH,THEIGHT,  /* minimum width and height */
  1428.     0xffff,0xffff,  /* maximum width and height */
  1429.     CUSTOMSCREEN    /* destination screen type */
  1430. };
  1431.  
  1432. SHORT    BorderVectors1[] = {
  1433.     0,0,
  1434.     81,0,
  1435.     81,38,
  1436.     0,38,
  1437.     0,0
  1438. };
  1439. struct Border    Border1 = {
  1440.     -1,-1,  /* XY origin relative to container TopLeft */
  1441.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1442.     5,      /* number of XY vectors */
  1443.     BorderVectors1, /* pointer to XY vectors */
  1444.     NULL    /* next border in list */
  1445. };
  1446.  
  1447. struct IntuiText    IText16 = {
  1448.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1449.     31,15,  /* XY origin relative to container TopLeft */
  1450.     NULL,   /* font pointer or NULL for default */
  1451.     "OK",   /* pointer to text */
  1452.     NULL    /* next IntuiText structure */
  1453. };
  1454.  
  1455. struct Gadget    Gadget1 = {
  1456.     NULL,   /* next gadget */
  1457.     155,233,        /* origin XY of hit box relative to window TopLeft */
  1458.     80,37,  /* hit box width and height */
  1459.     NULL,   /* gadget flags */
  1460.     RELVERIFY,      /* activation flags */
  1461.     BOOLGADGET,     /* gadget type flags */
  1462.     (APTR)&Border1, /* gadget border or image to be rendered */
  1463.     NULL,   /* alternate imagery for selection */
  1464.     &IText16,       /* first IntuiText structure */
  1465.     NULL,   /* gadget mutual-exclude long word */
  1466.     NULL,   /* SpecialInfo structure */
  1467.     NULL,   /* user-definable data */
  1468.     NULL    /* pointer to user-definable data */
  1469. };
  1470.  
  1471. #define GadgetList2 Gadget1
  1472.  
  1473. struct IntuiText    IText22 = {
  1474.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1475.     143,130,        /* XY origin relative to container TopLeft */
  1476.     NULL,   /* font pointer or NULL for default */
  1477.     "of Computers.",        /* pointer to text */
  1478.     NULL    /* next IntuiText structure */
  1479. };
  1480.  
  1481. struct IntuiText    IText21 = {
  1482.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1483.     115,117,        /* XY origin relative to container TopLeft */
  1484.     NULL,   /* font pointer or NULL for default */
  1485.     "For the Amiga Family", /* pointer to text */
  1486.     &IText22        /* next IntuiText structure */
  1487. };
  1488.  
  1489. struct IntuiText    IText20 = {
  1490.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1491.     104,102,        /* XY origin relative to container TopLeft */
  1492.     NULL,   /* font pointer or NULL for default */
  1493.     "Chess Program Available",      /* pointer to text */
  1494.     &IText21        /* next IntuiText structure */
  1495. };
  1496.  
  1497. struct IntuiText    IText19 = {
  1498.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1499.     108,87, /* XY origin relative to container TopLeft */
  1500.     NULL,   /* font pointer or NULL for default */
  1501.     "The strongest Playing",        /* pointer to text */
  1502.     &IText20        /* next IntuiText structure */
  1503. };
  1504.  
  1505. struct IntuiText    IText18 = {
  1506.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1507.     126,31, /* XY origin relative to container TopLeft */
  1508.     NULL,   /* font pointer or NULL for default */
  1509.     "by Roger Uzun",        /* pointer to text */
  1510.     &IText19        /* next IntuiText structure */
  1511. };
  1512.  
  1513. struct IntuiText    IText17 = {
  1514.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1515.     131,18, /* XY origin relative to container TopLeft */
  1516.     NULL,   /* font pointer or NULL for default */
  1517.     VERSTRING,      /* pointer to text */
  1518.     &IText18        /* next IntuiText structure */
  1519. };
  1520.  
  1521. struct NewWindow    NewWindowStructure2 = {
  1522.     125,30, /* window XY origin relative to TopLeft of screen */
  1523.     390,290,        /* window width and height */
  1524.     0,TBLOCKPEN,    /* detail and block pens */
  1525.     VANILLAKEY|GADGETUP,    /* IDCMP flags */
  1526.     SIMPLE_REFRESH+NOCAREREFRESH+ACTIVATE,  /* other window flags */
  1527.     &Gadget1,       /* first gadget in gadget list */
  1528.     NULL,   /* custom CHECKMARK imagery */
  1529. #ifdef _M68040
  1530.     "UChess Pro",   /* window title */
  1531. #else
  1532. #ifndef TINYCHESS
  1533.     "UChess Jr.",   /* window title */
  1534. #else
  1535.     "UChess Tiny",  /* window title */
  1536. #endif
  1537. #endif
  1538.     NULL,   /* custom screen pointer */
  1539.     NULL,   /* custom bitmap */
  1540.     5,5,    /* minimum width and height */
  1541.     0xffff,0xffff,  /* maximum width and height */
  1542.     CUSTOMSCREEN    /* destination screen type */
  1543. };
  1544.  
  1545.  
  1546. SHORT    aBorderVectors1[] = {
  1547.     0,0,
  1548.     77,0,
  1549.     77,25,
  1550.     0,25,
  1551.     0,0
  1552. };
  1553. struct Border    aBorder1 = {
  1554.     -1,-1,  /* XY origin relative to container TopLeft */
  1555.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1556.     5,      /* number of XY vectors */
  1557.     aBorderVectors1,        /* pointer to XY vectors */
  1558.     NULL    /* next border in list */
  1559. };
  1560.  
  1561. struct IntuiText    aIText1 = {
  1562.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1563.     16,8,   /* XY origin relative to container TopLeft */
  1564.     NULL,   /* font pointer or NULL for default */
  1565.     "KNIGHT",       /* pointer to text */
  1566.     NULL    /* next IntuiText structure */
  1567. };
  1568.  
  1569. struct Gadget    aGadget4 = {
  1570.     NULL,   /* next gadget */
  1571.     55,124, /* origin XY of hit box relative to window TopLeft */
  1572.     76,24,  /* hit box width and height */
  1573.     NULL,   /* gadget flags */
  1574.     RELVERIFY,      /* activation flags */
  1575.     BOOLGADGET,     /* gadget type flags */
  1576.     (APTR)&aBorder1,        /* gadget border or image to be rendered */
  1577.     NULL,   /* alternate imagery for selection */
  1578.     &aIText1,       /* first IntuiText structure */
  1579.     NULL,   /* gadget mutual-exclude long word */
  1580.     NULL,   /* SpecialInfo structure */
  1581.     NULL,   /* user-definable data */
  1582.     NULL    /* pointer to user-definable data */
  1583. };
  1584.  
  1585. SHORT    aBorderVectors2[] = {
  1586.     0,0,
  1587.     77,0,
  1588.     77,25,
  1589.     0,25,
  1590.     0,0
  1591. };
  1592. struct Border    aBorder2 = {
  1593.     -1,-1,  /* XY origin relative to container TopLeft */
  1594.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1595.     5,      /* number of XY vectors */
  1596.     aBorderVectors2,        /* pointer to XY vectors */
  1597.     NULL    /* next border in list */
  1598. };
  1599.  
  1600. struct IntuiText    aIText2 = {
  1601.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1602.     15,8,   /* XY origin relative to container TopLeft */
  1603.     NULL,   /* font pointer or NULL for default */
  1604.     "BISHOP",       /* pointer to text */
  1605.     NULL    /* next IntuiText structure */
  1606. };
  1607.  
  1608. struct Gadget    aGadget3 = {
  1609.     &aGadget4,      /* next gadget */
  1610.     55,92,  /* origin XY of hit box relative to window TopLeft */
  1611.     76,24,  /* hit box width and height */
  1612.     NULL,   /* gadget flags */
  1613.     RELVERIFY,      /* activation flags */
  1614.     BOOLGADGET,     /* gadget type flags */
  1615.     (APTR)&aBorder2,        /* gadget border or image to be rendered */
  1616.     NULL,   /* alternate imagery for selection */
  1617.     &aIText2,       /* first IntuiText structure */
  1618.     NULL,   /* gadget mutual-exclude long word */
  1619.     NULL,   /* SpecialInfo structure */
  1620.     NULL,   /* user-definable data */
  1621.     NULL    /* pointer to user-definable data */
  1622. };
  1623.  
  1624. SHORT    aBorderVectors3[] = {
  1625.     0,0,
  1626.     77,0,
  1627.     77,25,
  1628.     0,25,
  1629.     0,0
  1630. };
  1631. struct Border    aBorder3 = {
  1632.     -1,-1,  /* XY origin relative to container TopLeft */
  1633.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1634.     5,      /* number of XY vectors */
  1635.     aBorderVectors3,        /* pointer to XY vectors */
  1636.     NULL    /* next border in list */
  1637. };
  1638.  
  1639. struct IntuiText    aIText3 = {
  1640.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1641.     19,8,   /* XY origin relative to container TopLeft */
  1642.     NULL,   /* font pointer or NULL for default */
  1643.     "ROOK", /* pointer to text */
  1644.     NULL    /* next IntuiText structure */
  1645. };
  1646.  
  1647. struct Gadget    aGadget2 = {
  1648.     &aGadget3,      /* next gadget */
  1649.     55,60,  /* origin XY of hit box relative to window TopLeft */
  1650.     76,24,  /* hit box width and height */
  1651.     NULL,   /* gadget flags */
  1652.     RELVERIFY,      /* activation flags */
  1653.     BOOLGADGET,     /* gadget type flags */
  1654.     (APTR)&aBorder3,        /* gadget border or image to be rendered */
  1655.     NULL,   /* alternate imagery for selection */
  1656.     &aIText3,       /* first IntuiText structure */
  1657.     NULL,   /* gadget mutual-exclude long word */
  1658.     NULL,   /* SpecialInfo structure */
  1659.     NULL,   /* user-definable data */
  1660.     NULL    /* pointer to user-definable data */
  1661. };
  1662.  
  1663. SHORT    aBorderVectors4[] = {
  1664.     0,0,
  1665.     77,0,
  1666.     77,25,
  1667.     0,25,
  1668.     0,0
  1669. };
  1670. struct Border    aBorder4 = {
  1671.     -1,-1,  /* XY origin relative to container TopLeft */
  1672.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1673.     5,      /* number of XY vectors */
  1674.     aBorderVectors4,        /* pointer to XY vectors */
  1675.     NULL    /* next border in list */
  1676. };
  1677.  
  1678. struct IntuiText    aIText4 = {
  1679.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1680.     16,8,   /* XY origin relative to container TopLeft */
  1681.     NULL,   /* font pointer or NULL for default */
  1682.     "QUEEN",        /* pointer to text */
  1683.     NULL    /* next IntuiText structure */
  1684. };
  1685.  
  1686. struct Gadget    aGadget1 = {
  1687.     &aGadget2,      /* next gadget */
  1688.     55,28,  /* origin XY of hit box relative to window TopLeft */
  1689.     76,24,  /* hit box width and height */
  1690.     NULL,   /* gadget flags */
  1691.     RELVERIFY,      /* activation flags */
  1692.     BOOLGADGET,     /* gadget type flags */
  1693.     (APTR)&aBorder4,        /* gadget border or image to be rendered */
  1694.     NULL,   /* alternate imagery for selection */
  1695.     &aIText4,       /* first IntuiText structure */
  1696.     NULL,   /* gadget mutual-exclude long word */
  1697.     NULL,   /* SpecialInfo structure */
  1698.     NULL,   /* user-definable data */
  1699.     NULL    /* pointer to user-definable data */
  1700. };
  1701.  
  1702.  
  1703. struct IntuiText    aIText5 = {
  1704.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1705.     33,14,  /* XY origin relative to container TopLeft */
  1706.     &TOPAZ80,       /* font pointer or NULL for default */
  1707.     "Promote Pawn to",      /* pointer to text */
  1708.     NULL    /* next IntuiText structure */
  1709. };
  1710.  
  1711.  
  1712. struct NewWindow  NewWindowStructure6 = {
  1713.     220,35, /* window XY origin relative to TopLeft of screen */
  1714.     200,170,        /* window width and height */
  1715.     0,TBLOCKPEN,    /* detail and block pens */
  1716.     GADGETUP,       /* IDCMP flags */
  1717.     SIMPLE_REFRESH+ACTIVATE+NOCAREREFRESH,  /* other window flags */
  1718.     &aGadget1,      /* first gadget in gadget list */
  1719.     NULL,   /* custom CHECKMARK imagery */
  1720.     "Promote Piece",        /* window title */
  1721.     NULL,   /* custom screen pointer */
  1722.     NULL,   /* custom bitmap */
  1723.     5,5,    /* minimum width and height */
  1724.     0xffff,0xffff,  /* maximum width and height */
  1725.     CUSTOMSCREEN    /* destination screen type */
  1726. };
  1727.  
  1728. #define MOVENOWMENUNUM 0x42
  1729. #define THINKMENUNUM 0x82
  1730. #define SHOWMENUNUM 0xa2
  1731. #define BOOKMENUNUM 0xc2
  1732. #define SUPERMENUNUM 0xe2
  1733. #define ADVANCEDMENUNUM 0x102
  1734. #define INTERMEDIATEMENUNUM 0x122
  1735. #define EASYMENUNUM 0x142
  1736.  
  1737.  
  1738. SHORT    pBorderVectors1[] = {
  1739.     0,0,
  1740.     68,0,
  1741.     68,31,
  1742.     0,31,
  1743.     0,0
  1744. };
  1745. struct Border    pBorder1 = {
  1746.     -1,-1,  /* XY origin relative to container TopLeft */
  1747.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1748.     5,      /* number of XY vectors */
  1749.     pBorderVectors1,        /* pointer to XY vectors */
  1750.     NULL    /* next border in list */
  1751. };
  1752.  
  1753. struct IntuiText    pIText1 = {
  1754.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1755.     13,11,  /* XY origin relative to container TopLeft */
  1756.     &TOPAZ80,       /* font pointer or NULL for default */
  1757.     "DONE", /* pointer to text */
  1758.     NULL    /* next IntuiText structure */
  1759. };
  1760.  
  1761. struct Gadget    pGadget4 = {
  1762.     NULL,   /* next gadget */
  1763.     104,172,        /* origin XY of hit box relative to window TopLeft */
  1764.     67,30,  /* hit box width and height */
  1765.     NULL,   /* gadget flags */
  1766.     RELVERIFY,      /* activation flags */
  1767.     BOOLGADGET,     /* gadget type flags */
  1768.     (APTR)&pBorder1,        /* gadget border or image to be rendered */
  1769.     NULL,   /* alternate imagery for selection */
  1770.     &pIText1,       /* first IntuiText structure */
  1771.     NULL,   /* gadget mutual-exclude long word */
  1772.     NULL,   /* SpecialInfo structure */
  1773.     NULL,   /* user-definable data */
  1774.     NULL    /* pointer to user-definable data */
  1775. };
  1776.  
  1777. SHORT    pBorderVectors2[] = {
  1778.     0,0,
  1779.     68,0,
  1780.     68,31,
  1781.     0,31,
  1782.     0,0
  1783. };
  1784. struct Border    pBorder2 = {
  1785.     -1,-1,  /* XY origin relative to container TopLeft */
  1786.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1787.     5,      /* number of XY vectors */
  1788.     pBorderVectors2,        /* pointer to XY vectors */
  1789.     NULL    /* next border in list */
  1790. };
  1791.  
  1792. struct IntuiText    pIText2 = {
  1793.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1794.     117,132,        /* was 13,11 XY origin relative to container TopLeft */
  1795.     &TOPAZ80,       /* font pointer or NULL for default */
  1796.     "WHITE",        /* pointer to text */
  1797.     NULL    /* next IntuiText structure */
  1798. };
  1799.  
  1800. struct IntuiText    pIText2a = {
  1801.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1802.     117,132,        /* was 13,11 XY origin relative to container TopLeft */
  1803.     &TOPAZ80,       /* font pointer or NULL for default */
  1804.     "BLACK",        /* pointer to text */
  1805.     NULL    /* next IntuiText structure */
  1806. };
  1807.  
  1808. struct Gadget    pGadget3 = {
  1809.     &pGadget4,      /* next gadget */
  1810.     104,121,        /* origin XY of hit box relative to window TopLeft */
  1811.     67,30,  /* hit box width and height */
  1812.     NULL,   /* gadget flags */
  1813.     RELVERIFY,      /* activation flags */
  1814.     BOOLGADGET,     /* gadget type flags */
  1815.     (APTR)&pBorder2,        /* gadget border or image to be rendered */
  1816.     NULL,   /* alternate imagery for selection */
  1817.     NULL,   /* first IntuiText structure */
  1818.     NULL,   /* gadget mutual-exclude long word */
  1819.     NULL,   /* SpecialInfo structure */
  1820.     NULL,   /* user-definable data */
  1821.     NULL    /* pointer to user-definable data */
  1822. };
  1823.  
  1824. SHORT    pBorderVectors3[] = {
  1825.     0,0,
  1826.     68,0,
  1827.     68,31,
  1828.     0,31,
  1829.     0,0
  1830. };
  1831. struct Border    pBorder3 = {
  1832.     -1,-1,  /* XY origin relative to container TopLeft */
  1833.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1834.     5,      /* number of XY vectors */
  1835.     pBorderVectors3,        /* pointer to XY vectors */
  1836.     NULL    /* next border in list */
  1837. };
  1838.  
  1839. struct IntuiText    pIText3 = {
  1840.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1841.     0,12,   /* XY origin relative to container TopLeft */
  1842.     &TOPAZ80,       /* font pointer or NULL for default */
  1843.     "Clear BD",     /* pointer to text */
  1844.     NULL    /* next IntuiText structure */
  1845. };
  1846.  
  1847. struct Gadget    pGadget2 = {
  1848.     &pGadget3,      /* next gadget */
  1849.     105,82, /* origin XY of hit box relative to window TopLeft */
  1850.     67,30,  /* hit box width and height */
  1851.     NULL,   /* gadget flags */
  1852.     RELVERIFY,      /* activation flags */
  1853.     BOOLGADGET,     /* gadget type flags */
  1854.     (APTR)&pBorder3,        /* gadget border or image to be rendered */
  1855.     NULL,   /* alternate imagery for selection */
  1856.     &pIText3,       /* first IntuiText structure */
  1857.     NULL,   /* gadget mutual-exclude long word */
  1858.     NULL,   /* SpecialInfo structure */
  1859.     NULL,   /* user-definable data */
  1860.     NULL    /* pointer to user-definable data */
  1861. };
  1862.  
  1863. UBYTE  pppSIBuff[4];
  1864. struct StringInfo  pppSInfo = {
  1865.     pppSIBuff,      /* buffer where text will be edited */
  1866.     NULL,   /* optional undo buffer */
  1867.     0,      /* character position in buffer */
  1868.     4,      /* maximum number of characters to allow */
  1869.     0,      /* first displayed character buffer position */
  1870.     0,0,0,0,0,      /* Intuition initialized and maintained variables */
  1871.     0,      /* Rastport of gadget */
  1872.     0,      /* initial value for integer gadgets */
  1873.     NULL    /* alternate keymap (fill in if you set the flag) */
  1874. };
  1875.  
  1876. SHORT    pBorderVectors4[] = {
  1877.     0,0,
  1878.     55,0,
  1879.     55,16, /* was 55,24 and 0, 24 */
  1880.     0,16,
  1881.     0,0
  1882. };
  1883. struct Border    pBorder4 = {
  1884.     -1,-1,  /* XY origin relative to container TopLeft */
  1885.     TBLOCKPEN,0,JAM1,       /* front pen, back pen and drawmode */
  1886.     5,      /* number of XY vectors */
  1887.     pBorderVectors4,        /* pointer to XY vectors */
  1888.     NULL    /* next border in list */
  1889. };
  1890.  
  1891. struct Gadget    pGadget1 = {
  1892.     &pGadget2,      /* next gadget */
  1893.     180,57, /* origin XY of hit box relative to window TopLeft */
  1894.     54,15,  /* was 54, 23 hit box width and height */
  1895.     NULL,   /* gadget flags */
  1896.     RELVERIFY,      /* activation flags */
  1897.     STRGADGET,      /* gadget type flags */
  1898.     (APTR)&pBorder4,        /* gadget border or image to be rendered */
  1899.     NULL,   /* alternate imagery for selection */
  1900.     NULL,   /* first IntuiText structure */
  1901.     NULL,   /* gadget mutual-exclude long word */
  1902.     (APTR)&pppSInfo,        /* SpecialInfo structure */
  1903.     NULL,   /* user-definable data */
  1904.     NULL    /* pointer to user-definable data */
  1905. };
  1906.  
  1907. struct IntuiText    pIText8a = {
  1908.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1909.     32,44,  /* XY origin relative to container TopLeft */
  1910.     NULL,   /* font pointer or NULL for default */
  1911.     "use space to clr a square",    /* pointer to text */
  1912.     NULL    /* next IntuiText structure */
  1913. };
  1914.  
  1915. struct IntuiText    pIText7 = {
  1916.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1917.     26,34,  /* XY origin relative to container TopLeft */
  1918.     NULL,   /* font pointer or NULL for default */
  1919.     "Bd is updated after edit session",     /* pointer to text */
  1920.     &pIText8a       /* next IntuiText structure */
  1921. };
  1922.  
  1923. struct IntuiText    pIText6 = {
  1924.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1925.     68,62,  /* XY origin relative to container TopLeft */
  1926.     NULL,   /* font pointer or NULL for default */
  1927.     "Piece to add", /* pointer to text */
  1928.     &pIText7        /* next IntuiText structure */
  1929. };
  1930.  
  1931. struct IntuiText    pIText5 = {
  1932.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1933.     59,24,  /* XY origin relative to container TopLeft */
  1934.     NULL,   /* font pointer or NULL for default */
  1935.     "pa1 for pawn at a1, etc.",     /* pointer to text */
  1936.     &pIText6        /* next IntuiText structure */
  1937. };
  1938.  
  1939. struct IntuiText    pIText4 = {
  1940.     TBLOCKPEN,0,JAM2,       /* front and back text pens, drawmode and fill byte */
  1941.     63,14,  /* XY origin relative to container TopLeft */
  1942.     NULL,   /* font pointer or NULL for default */
  1943.     "Enter Pieces in format",       /* pointer to text */
  1944.     &pIText5        /* next IntuiText structure */
  1945. };
  1946.  
  1947. struct NewWindow    pNewWindowStructure1 = {
  1948.     170,30, /* window XY origin relative to TopLeft of screen */
  1949.     300,220,        /* window width and height */
  1950.     0,TBLOCKPEN,    /* detail and block pens */
  1951.     GADGETUP+CLOSEWINDOW,   /* IDCMP flags */
  1952.     WINDOWCLOSE+SIMPLE_REFRESH+ACTIVATE+NOCAREREFRESH,      /* other window flags */
  1953.     &pGadget1,      /* first gadget in gadget list */
  1954.     NULL,   /* custom CHECKMARK imagery */
  1955.     "Edit Board",   /* window title */
  1956.     NULL,   /* custom screen pointer */
  1957.     NULL,   /* custom bitmap */
  1958.     5,5,    /* minimum width and height */
  1959.     0xffff,0xffff,  /* maximum width and height */
  1960.     CUSTOMSCREEN    /* destination screen type */
  1961. };
  1962.  
  1963. #endif // AMIGA
  1964.  
  1965. void WaitRealThink()
  1966. {
  1967.  int i=5*7;
  1968.  
  1969.        while (RealThink)
  1970.      {
  1971.       MoveNow();
  1972.       DosSleep(250L);
  1973.       i--;
  1974.       if (!i)
  1975.        {
  1976.          WinMessageBox(HWND_DESKTOP,hwndClient,"Chess Engine still busy","THREAD SYNCH ERROR",0,MB_OK);
  1977.          return;
  1978.        }
  1979.      }
  1980. }
  1981.  
  1982. void WaitThinkAhead()
  1983. {
  1984.  int i=5*7;
  1985.  
  1986.     if ((thinkahead)&&(!flag.bothsides))
  1987.       {
  1988.        if (!TCflag)
  1989.         backsrchaborted = 1;
  1990.        while (thinkahead)
  1991.         {
  1992.          flag.back = true;
  1993.          DosSleep(250L);
  1994.          i--;
  1995.          if (!i)
  1996.           {
  1997.            WinMessageBox(HWND_DESKTOP,hwndClient,"Chess Engine still busy","THREAD SYNCH ERROR",0,MB_OK);
  1998.            return;
  1999.           }
  2000.         }
  2001.       }
  2002. }
  2003.  
  2004.  
  2005. LONG MainCommand(HWND hwnd, MPARAM mp1/*, MPARAM mp2*/)
  2006. {
  2007. //  int i;
  2008.  
  2009.    if ((EditMode)&&(SHORT1FROMMP(mp1) != IDM_EXIT))
  2010.     {
  2011.       DosBeep(1280,500);
  2012.       ShowMessage("Not during edit!");
  2013.       return 0;
  2014.     }
  2015.    switch(SHORT1FROMMP(mp1))
  2016.    {
  2017.       case IDM_NEWGAME:
  2018.     WaitRealThink();
  2019.     WaitThinkAhead();
  2020.     NewGame();
  2021.     break;
  2022.       case IDM_VERBOSE:
  2023.         flag.post = !flag.post;
  2024.         if (!flag.post)
  2025.          ShowMessage("Verbse off");
  2026.         else
  2027.          ShowMessage("Verbse on");
  2028.         break;
  2029.       case IDM_LOOK:
  2030.         flag.beep = !flag.beep;
  2031.         if (!flag.beep)
  2032.          ShowMessage("Beep off");
  2033.         else
  2034.          ShowMessage("Beep on");
  2035.         break;
  2036.       case IDM_EDIT:
  2037.         if (!ButtonDown)
  2038.          {
  2039.           if (RealThink)
  2040.          {
  2041.         ShowMessage("Turn");
  2042.         ShowMessage("Not Your");
  2043.         DosBeep(1280,170);
  2044.         break;
  2045.          }
  2046.       WaitThinkAhead();
  2047.           CurrBobColor = white;
  2048.           CurrBobIndex = PAWNBOB;
  2049.           EditMode = 2;
  2050.           WinDlgBox(HWND_DESKTOP,
  2051.           hwndClient,
  2052.           (PFNWP)AboutDlgProc,
  2053.           0,
  2054.           IDD_EDIT,
  2055.           (PVOID)NULL);
  2056.           ShowMessage("to exit");
  2057.           ShowMessage("press 'x'");
  2058.           ShowMessage("Edit on");
  2059.          }
  2060.         break;
  2061.       case IDM_SKILL:
  2062.     WaitRealThink();
  2063.     WaitThinkAhead();
  2064.         WinDlgBox(HWND_DESKTOP,hwnd,SkillFunc,0,IDD_SKILL,0);
  2065.         break;
  2066.       case IDM_CALC:
  2067.        WaitRealThink();
  2068.        WaitThinkAhead();
  2069.        strcpy(lOpEntryStr,"calc");
  2070.        strcpy(OpEntryStr,"calc");
  2071.        opindex = 0;
  2072.        ReturnHit = 1;
  2073.      break;
  2074.       case IDM_TEST:
  2075.         if (RealThink)
  2076.          {
  2077.         ShowMessage("Turn");
  2078.         ShowMessage("Not Your");
  2079.         DosBeep(1280,170);
  2080.         break;
  2081.          }
  2082.         WaitThinkAhead();
  2083.        strcpy(lOpEntryStr,"test");
  2084.        strcpy(OpEntryStr,"test");
  2085.        opindex = 0;
  2086.        ReturnHit = 1;
  2087.      break;
  2088.  
  2089.       case IDM_TAKEBACK:
  2090.        if (RealThink)
  2091.      {
  2092.       ShowMessage("your Turn!");
  2093.       ShowMessage("It's not");
  2094.       DosBeep(1280,175);
  2095.       break;
  2096.      }
  2097.        if (Mate)
  2098.         {
  2099.       ShowMessage("checkmate!");
  2100.       ShowMessage("Not after");
  2101.       DosBeep(1280,175);
  2102.       break;
  2103.         }
  2104.        WaitThinkAhead();
  2105.        TakeBack();
  2106.        break;
  2107.  
  2108.       case IDM_LOADGAME:
  2109.        if (RealThink)
  2110.      {
  2111.       ShowMessage("your Turn!");
  2112.       ShowMessage("It's not");
  2113.       DosBeep(1280,175);
  2114.       break;
  2115.      }
  2116.        WaitThinkAhead();
  2117.        GetGame();
  2118.        break;
  2119.  
  2120.       case IDM_LISTGAME:
  2121.        if (RealThink)
  2122.      {
  2123.       ShowMessage("your Turn!");
  2124.       ShowMessage("It's not");
  2125.       DosBeep(1280,175);
  2126.       break;
  2127.      }
  2128.     WaitThinkAhead();
  2129.     ListGame(0xff);
  2130.      break;
  2131.  
  2132.       case IDM_SAVEGAME:
  2133.        if (RealThink)
  2134.      {
  2135.       ShowMessage("your Turn!");
  2136.       ShowMessage("It's not");
  2137.       DosBeep(1280,175);
  2138.       break;
  2139.      }
  2140.        WaitThinkAhead();
  2141.        SaveGame();
  2142.      break;
  2143.  
  2144.       case IDM_TIMECONTROL:
  2145.      if (!SupervisorMode)
  2146.       WinDlgBox(HWND_DESKTOP,hwnd,TimeControlFunc,0,IDD_TIMEDLG,0);
  2147.      else
  2148.       WinMessageBox(HWND_DESKTOP,hwnd,"Computer not playing!","Invalid Selection",0,MB_OK);
  2149.      break;
  2150.  
  2151.       case IDM_PLAYERS:
  2152.         if (RealThink)
  2153.          {
  2154.         ShowMessage("Turn");
  2155.         ShowMessage("Not Your");
  2156.         DosBeep(1280,170);
  2157.         break;
  2158.          }
  2159.        WaitThinkAhead();
  2160.      WinDlgBox(HWND_DESKTOP,hwnd,SetPlayersFunc,0,IDD_PLAYERS,0);
  2161.      break;
  2162.  
  2163.       case IDM_HINT:
  2164.      if (RealThink)
  2165.       {
  2166.         DosBeep(1280,75);
  2167.         ShowMessage("turn!");
  2168.         ShowMessage("not your");
  2169.       }
  2170.      else
  2171.       GiveHint();
  2172.      break;
  2173.  
  2174.       case IDM_MOVENOW:
  2175.     WaitRealThink();
  2176. #ifdef OLDWAYWT
  2177.     i = 14;
  2178.     while ((RealThink)&&(i))
  2179.       {
  2180.        i--;
  2181.        MoveNow();
  2182.        DosSleep(400);
  2183.       }
  2184.     if (RealThink)
  2185.      {
  2186.       ShowMessage("Plse wait");
  2187.       ShowMessage("thinking..");
  2188.       ShowMessage("Pgm still");
  2189.      }
  2190. #endif
  2191.     break;
  2192.       case IDM_EXIT:
  2193.         DestroyHelpInstance();
  2194.     DosExit(1,0);
  2195.     break;
  2196.       case IDM_HELPHELPFORHELP:
  2197.      HelpHelpForHelp(/*mp2*/);
  2198.      break;
  2199.  
  2200.       case IDM_HELPEXTENDED:
  2201.      HelpExtended(/*mp2*/);
  2202.      break;
  2203.  
  2204. #ifdef WORKS
  2205.       case IDM_HELPKEYS:
  2206.      HelpKeys(/*mp2*/);
  2207.      break;
  2208. #endif
  2209.  
  2210.       case HM_QUERY_KEYS_HELP:
  2211.      return (PANEL_KEYSHELP);
  2212.  
  2213.       case IDM_HELPINDEX:
  2214.      HelpIndex(/*mp2*/);
  2215.      break;
  2216.  
  2217.       case IDM_HELPPRODUCTINFO:
  2218.      HelpAbout();
  2219.      break;
  2220.    }
  2221.    return 0;
  2222. }
  2223.  
  2224. VOID InitHelp(VOID)
  2225. {
  2226.     HELPINIT hini;
  2227.  
  2228.      /* If we return because of an error, Help will be disabled */
  2229.     fHelpEnabled = FALSE;
  2230.                   /* Initialize help init structure */
  2231.     hini.cb = sizeof(HELPINIT);
  2232.     hini.ulReturnCode = 0;
  2233.                 /* If tutorial added, add name here */
  2234.     hini.pszTutorialName = (PSZ)NULL;
  2235.  
  2236.     hini.phtHelpTable = (PHELPTABLE)MAKELONG(UCHESS_HELP_TABLE, 0xFFFF);
  2237.     hini.hmodHelpTableModule = 0;
  2238.     hini.hmodAccelActionBarModule = 0;
  2239.     hini.idAccelTable = 0;
  2240.     hini.idActionBar = 0;
  2241.  
  2242.     if(!WinLoadString(hab,
  2243.               0,
  2244.               IDS_HELPWINDOWTITLE,
  2245.               HELPLIBRARYNAMELEN,
  2246.               (PSZ)szWindowTitle))
  2247.     {
  2248.         DisplayError("Cannot load help str1");
  2249.         return;
  2250.     }
  2251.     hini.pszHelpWindowTitle = (PSZ)szWindowTitle;
  2252.  
  2253.             /* If debugging, show panel ids, else don't */
  2254.     hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  2255.  
  2256.     if(!WinLoadString(hab,
  2257.               0,
  2258.               IDS_HELPLIBRARYNAME,
  2259.               HELPLIBRARYNAMELEN,
  2260.               (PSZ)szLibName))
  2261.     {
  2262.         DisplayError("Cannot load str2!");
  2263.     return;
  2264.     }
  2265.     hini.pszHelpLibraryName = (PSZ)szLibName;
  2266.                       /* Creating help instance */
  2267.     hwndHelpInstance = WinCreateHelpInstance(hab, &hini);
  2268.  
  2269.     if(hwndHelpInstance == 0L || hini.ulReturnCode)
  2270.     {
  2271.         DisplayError("Cannot Create Help!");
  2272.     return;
  2273.     }
  2274.              /* Associate help instance with main frame */
  2275.     if(!WinAssociateHelpInstance(hwndHelpInstance, hwndFrame))
  2276.     {
  2277.         DisplayError("Cannot assoc Help");
  2278.     return;
  2279.     }
  2280. /* Help manager is successfully initialized so set flag to TRUE */
  2281.     fHelpEnabled = TRUE;
  2282.    return;
  2283. }                          /* InitHelp() */
  2284.  
  2285. VOID DestroyHelpInstance(VOID)
  2286. {
  2287.     if(hwndHelpInstance != 0L)
  2288.     {
  2289.     WinDestroyHelpInstance(hwndHelpInstance);
  2290.     }
  2291.     return;
  2292. }                       /* DestroyHelpInstance() */
  2293.  
  2294.  
  2295. VOID HelpHelpForHelp(/*MPARAM mp2*/)
  2296. {
  2297.        /* This just displays the system help for help panel */
  2298.    if(fHelpEnabled)
  2299.      if((LONG)WinSendMsg(hwndHelpInstance, HM_DISPLAY_HELP,
  2300.                     (MPARAM)0L, (MPARAM)0L))
  2301.         {
  2302.           ShowMessage("Help Err");
  2303.         }
  2304.    /* This routine currently doesn't use the mp2 parameter but     *\
  2305.     *  it is referenced here to prevent an 'Unreferenced Parameter'
  2306.    \*  warning at compile time.                       */
  2307.    return;
  2308. }                       /* HelpHelpForHelp() */
  2309.  
  2310. VOID HelpExtended(/*MPARAM mp2*/)
  2311. {
  2312.        /* This just displays the system extended help panel */
  2313.    if(fHelpEnabled)
  2314.     if((LONG)WinSendMsg(hwndHelpInstance, HM_EXT_HELP,
  2315.                            (MPARAM)0L,(MPARAM)0L))
  2316.           ShowMessage("Help Err");
  2317.     /* This routine currently doesn't use the mp2 parameter but     *\
  2318.      *    it is referenced here to prevent an 'Unreferenced Parameter'
  2319.     \*    warning at compile time.                    */
  2320.    return;
  2321. }                          /* HelpExtended() */
  2322.  
  2323. #ifdef WORKS
  2324. VOID HelpKeys(/*MPARAM mp2*/)
  2325. {
  2326.            /* This just displays the system keys help panel */
  2327.     if(fHelpEnabled)
  2328.     if((LONG)WinSendMsg(hwndHelpInstance, HM_KEYS_HELP,
  2329.                          (MPARAM)0L,(MPARAM)0L))
  2330.           {
  2331.                 ShowMessage("Help err");
  2332.           }
  2333.     /* This routine currently doesn't use the mp2 parameter but     *\
  2334.      *    it is referenced here to prevent an 'Unreferenced Parameter'
  2335.     \*    warning at compile time.                    */
  2336.     return;
  2337. }                          /* HelpKeys() */
  2338.  
  2339. #endif
  2340.  
  2341. VOID HelpIndex(/*MPARAM mp2*/)
  2342. {
  2343.           /* This just displays the system help index panel */
  2344.     if(fHelpEnabled)
  2345.     if((LONG)WinSendMsg(hwndHelpInstance, HM_HELP_INDEX,
  2346.                          (MPARAM)0L,(MPARAM)0L))
  2347.                 ShowMessage("Help err");
  2348.     /* This routine currently doesn't use the mp2 parameter but     *\
  2349.      *    it is referenced here to prevent an 'Unreferenced Parameter'
  2350.     \*    warning at compile time.                    */
  2351.     return;
  2352. }                         /* HelpIndex() */
  2353.  
  2354.  
  2355.  
  2356. VOID FixSysMenu(HWND hwndDlg)
  2357. {
  2358.    HWND hwndMenu;                      /* Handle to system menu */
  2359.  
  2360.    hwndMenu = WinWindowFromID(hwndDlg, FID_SYSMENU);
  2361.  
  2362.    WinSendMsg(hwndMenu,  /* Delete Restore from the system menu */
  2363.           MM_DELETEITEM,
  2364.           MPFROM2SHORT(SC_RESTORE, TRUE),
  2365.           MPFROMP(NULL));
  2366.  
  2367.    WinSendMsg(hwndMenu,     /* Delete Size from the system menu */
  2368.           MM_DELETEITEM,
  2369.           MPFROM2SHORT(SC_SIZE, TRUE),
  2370.           MPFROMP(NULL));
  2371.  
  2372.    WinSendMsg(hwndMenu, /* Delete Minimize from the system menu */
  2373.           MM_DELETEITEM,
  2374.           MPFROM2SHORT(SC_MINIMIZE, TRUE),
  2375.           MPFROMP(NULL));
  2376.  
  2377.    WinSendMsg(hwndMenu, /* Delete Maximize from the system menu */
  2378.           MM_DELETEITEM,
  2379.           MPFROM2SHORT(SC_MAXIMIZE, TRUE),
  2380.           MPFROMP(NULL));
  2381.    return;
  2382. }
  2383.  
  2384. void QueryTimeValues(hwnd)
  2385. HWND hwnd;
  2386. {
  2387.  char str[48];
  2388.  
  2389.  sprintf(str,"%d",TCmoves);
  2390.  WinSetDlgItemText(hwnd,IDC_NUMMOVES,str);
  2391.  sprintf(str,"%d",TCminutes);
  2392.  WinSetDlgItemText(hwnd,IDC_NUMMINS,str);
  2393.  sprintf(str,"%d",MaxSearchDepth);
  2394.  WinSetDlgItemText(hwnd,IDC_DEPTH,str);
  2395.  if (!TCflag)
  2396.   {
  2397.     WinSendDlgItemMsg(hwnd,IDC_FIXEDDEPTH,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2398.   }
  2399.  if (!flag.easy)
  2400.   {
  2401.     WinSendDlgItemMsg(hwnd,IDC_EASY,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2402.   }
  2403.  if (Book)
  2404.   {
  2405.     WinSendDlgItemMsg(hwnd,IDC_BOOK,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2406.   }
  2407. }
  2408.  
  2409. void QueryPromoteValues(hwnd)
  2410. HWND hwnd;
  2411. {
  2412.  
  2413.   WinSendDlgItemMsg(hwnd,IDC_QUEEN,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2414. }
  2415.  
  2416. void QueryPlayerValues(hwnd)
  2417. HWND hwnd;
  2418. {
  2419.  
  2420.  if (SupervisorMode)
  2421.   {
  2422.     WinSendDlgItemMsg(hwnd,IDC_NEITHER,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2423.   }
  2424.  else if (flag.bothsides)
  2425.   {
  2426.     WinSendDlgItemMsg(hwnd,IDC_BOTH,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2427.   }
  2428.  else if (opponent == white)
  2429.   {
  2430.     WinSendDlgItemMsg(hwnd,IDC_BLACK,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2431.   }
  2432.  else if (opponent == black)
  2433.   {
  2434.     WinSendDlgItemMsg(hwnd,IDC_WHITE,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2435.   }
  2436. }
  2437.  
  2438. void QuerySkillValues(hwnd)
  2439. HWND hwnd;
  2440. {
  2441.  
  2442.  if (PlayMode == 0)
  2443.   {
  2444.     WinSendDlgItemMsg(hwnd,IDC_BEGIN,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2445.   }
  2446.  else if (PlayMode == 1)
  2447.   {
  2448.     WinSendDlgItemMsg(hwnd,IDC_INTER,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2449.   }
  2450.  else if (PlayMode == 2)
  2451.   {
  2452.     WinSendDlgItemMsg(hwnd,IDC_ADVAN,BM_SETCHECK,MPFROM2SHORT(TRUE,0),NULL);
  2453.   }
  2454. }
  2455.  
  2456.  
  2457.  
  2458. MRESULT EXPENTRY TimeControlFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2459. {
  2460.    MRESULT checked,hard,tmpbk;
  2461.    char str[64],str2[64],str3[64];
  2462.    int dun;
  2463.    MRESULT sRC;
  2464.  
  2465.    switch(msg)
  2466.    {
  2467.       case WM_INITDLG:
  2468.      FixSysMenu(hwnd);
  2469.      QueryTimeValues(hwnd);
  2470.      return (MRESULT)0L;
  2471.  
  2472.       case WM_COMMAND:
  2473.      WinQueryDlgItemText(hwnd,IDC_NUMMOVES,64,str);
  2474.      WinQueryDlgItemText(hwnd,IDC_NUMMINS,64,str2);
  2475.      WinQueryDlgItemText(hwnd,IDC_DEPTH,64,str3);
  2476.      checked = WinSendDlgItemMsg(hwnd,IDC_FIXEDDEPTH,BM_QUERYCHECK,NULL,NULL);
  2477.      hard = WinSendDlgItemMsg(hwnd,IDC_EASY,BM_QUERYCHECK,NULL,NULL);
  2478.      tmpbk = WinSendDlgItemMsg(hwnd,IDC_BOOK,BM_QUERYCHECK,NULL,NULL);
  2479.      WinDismissDlg(hwnd, TRUE);
  2480.       if (((tmpbk)&&(!Book))||((!tmpbk)&&(Book)))
  2481.        {
  2482.         Book = Book ? 0 : BOOKFAIL;
  2483.         bookflag = Book;
  2484.        }
  2485.      if (hard)
  2486.       {
  2487.        flag.easy = 0;
  2488.       }
  2489.      else
  2490.       {
  2491.        flag.easy = 1;
  2492.       }
  2493.      if (checked)
  2494.       TCflag = false;
  2495.      else
  2496.       TCflag = true;
  2497.      if (TCflag)
  2498.       {
  2499.        MaxSearchDepth = MAXDEPTH;
  2500.        strcat(str," ");
  2501.        strcat(str,str2);
  2502.        TCflag = true;
  2503.        SelectLevel(str);
  2504.        et = 0;
  2505.        dun = player;
  2506.        player = white;
  2507.        UpdateClocks();
  2508.        player = black;
  2509.        UpdateClocks();
  2510.        player = dun;
  2511.       }
  2512.      else
  2513.       {
  2514.        TCminutes = 10;
  2515.        TCmoves = 60;
  2516.        MaxSearchDepth = atoi(str3);
  2517.        if (MaxSearchDepth < 2)
  2518.         MaxSearchDepth = 2;
  2519.        if (MaxSearchDepth > MAXDEPTH)
  2520.         MaxSearchDepth = MAXDEPTH;
  2521.       }
  2522.      return (MRESULT)0L;
  2523.  
  2524.       default:
  2525.      sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  2526.      return sRC;
  2527.    }
  2528. }
  2529.  
  2530. MRESULT EXPENTRY SetPlayersFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2531. {
  2532.    MRESULT checked[4];
  2533.    MRESULT sRC;
  2534.  
  2535.    switch(msg)
  2536.    {
  2537.       case WM_INITDLG:
  2538.      FixSysMenu(hwnd);
  2539.      QueryPlayerValues(hwnd);
  2540.      return (MRESULT)0L;
  2541.  
  2542.       case WM_COMMAND:
  2543.      checked[0] = WinSendDlgItemMsg(hwnd,IDC_BLACK,BM_QUERYCHECK,NULL,NULL);
  2544.      checked[1] = WinSendDlgItemMsg(hwnd,IDC_WHITE,BM_QUERYCHECK,NULL,NULL);
  2545.      checked[2] = WinSendDlgItemMsg(hwnd,IDC_BOTH,BM_QUERYCHECK,NULL,NULL);
  2546.      checked[3] = WinSendDlgItemMsg(hwnd,IDC_NEITHER,BM_QUERYCHECK,NULL,NULL);
  2547.      WinDismissDlg(hwnd, TRUE);
  2548.      if (checked[3]) // supervisor
  2549.       {
  2550.        if (!SupervisorMode)
  2551.         {
  2552.          flag.force = false;
  2553.          flag.bothsides = 0;
  2554.          ShowMessage("mode set");
  2555.          ShowMessage("Supervsr");
  2556.          DoSuper();
  2557.         }
  2558.       }
  2559.      else if (checked[0])
  2560.       {
  2561.       flag.force = false;
  2562.       if (SupervisorMode)
  2563.         flag.easy = oldflageasy;
  2564.        SupervisorMode = 0;
  2565.        flag.bothsides = 0;
  2566.        if (opponent != white)
  2567.         { // switch
  2568.          strcpy(lOpEntryStr,"switch");
  2569.          strcpy(OpEntryStr,"switch");
  2570.          opindex = 0;
  2571.          ReturnHit = 1;
  2572.         }
  2573.       }
  2574.      else if (checked[1])
  2575.       {
  2576.        flag.force = false;
  2577.        if (SupervisorMode)
  2578.         flag.easy = oldflageasy;
  2579.        SupervisorMode = 0;
  2580.        flag.bothsides = 0;
  2581.        if (opponent != black)
  2582.         { // switch
  2583.          strcpy(lOpEntryStr,"switch");
  2584.          strcpy(OpEntryStr,"switch");
  2585.          opindex = 0;
  2586.          ReturnHit = 1;
  2587.         }
  2588.       }
  2589.      else if (checked[2])
  2590.       {
  2591.        if (SupervisorMode)
  2592.         flag.easy = oldflageasy;
  2593.        SupervisorMode = 0;
  2594.        strcpy(lOpEntryStr,"both");
  2595.        strcpy(OpEntryStr,"both");
  2596.        opindex = 0;
  2597.        ReturnHit = 1;
  2598.            ShowMessage("on");
  2599.            ShowMessage("Autoplay");
  2600. #ifdef XXX
  2601.       WinMessageBox(HWND_DESKTOP,hwnd,"Not yet Implemented","Under Construction",0,MB_OK);
  2602. #endif
  2603.       }
  2604.      return (MRESULT)0L;
  2605.  
  2606.       default:
  2607.      sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  2608.      return sRC;
  2609.    }
  2610. }
  2611.  
  2612. MRESULT EXPENTRY myFrameProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2613. {
  2614.   PTRACKINFO     pti  = (PTRACKINFO)mp2;
  2615.   MRESULT        mr;
  2616.  
  2617.  switch(msg)
  2618.   {
  2619.    case WM_QUERYTRACKINFO:
  2620.  
  2621.     /* first call the original frame window procedure */
  2622.     mr = (*OldFrameProc)(hwnd,msg,mp1,mp2);
  2623.  
  2624.     /* restrict maximum SIZE of this window */
  2625.     pti->ptlMaxTrackSize.x = MaxX;
  2626.     pti->ptlMaxTrackSize.y = MaxY;
  2627.     return ((MRESULT)TRUE);
  2628.  
  2629.    default :
  2630.      return((MRESULT)(*OldFrameProc)(hwnd,msg,mp1,mp2));
  2631.   }
  2632. // return((MRESULT)FALSE);
  2633. }
  2634.  
  2635. MRESULT EXPENTRY SkillFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2636. {
  2637.    MRESULT checked[4];
  2638.    MRESULT sRC;
  2639.  
  2640.    switch(msg)
  2641.    {
  2642.       case WM_INITDLG:
  2643.      FixSysMenu(hwnd);
  2644.      QuerySkillValues(hwnd);
  2645.      return (MRESULT)0L;
  2646.  
  2647.       case WM_COMMAND:
  2648.      checked[0] = WinSendDlgItemMsg(hwnd,IDC_BEGIN,BM_QUERYCHECK,NULL,NULL);
  2649.      checked[1] = WinSendDlgItemMsg(hwnd,IDC_INTER,BM_QUERYCHECK,NULL,NULL);
  2650.      checked[2] = WinSendDlgItemMsg(hwnd,IDC_ADVAN,BM_QUERYCHECK,NULL,NULL);
  2651.      if (checked[0]) // beginner
  2652.       {
  2653.            if (PlayMode != 0)
  2654.             {
  2655.               PlayMode = 0;
  2656.               NewGame();
  2657.             }
  2658.       }
  2659.      else if (checked[1]) // intermed
  2660.       {
  2661.            if (PlayMode != 1)
  2662.             {
  2663.               PlayMode = 1;
  2664.               NewGame();
  2665.             }
  2666.       }
  2667.      else if (checked[2]) // advanced
  2668.       {
  2669.            if (PlayMode != 2)
  2670.             {
  2671.               PlayMode = 2;
  2672.               NewGame();
  2673.             }
  2674.       }
  2675.      WinDismissDlg(hwnd, TRUE);
  2676.      return (MRESULT)0L;
  2677.  
  2678.       default:
  2679.      sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  2680.      return sRC;
  2681.    }
  2682. }
  2683.  
  2684.  
  2685.  
  2686. MRESULT EXPENTRY PromoteFunc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2687. {
  2688.    MRESULT checked[4];
  2689.    MRESULT sRC;
  2690.  
  2691.    switch(msg)
  2692.    {
  2693.       case WM_INITDLG:
  2694.      FixSysMenu(hwnd);
  2695.      QueryPromoteValues(hwnd);
  2696.      return (MRESULT)0L;
  2697.  
  2698.       case WM_COMMAND:
  2699.      checked[0] = WinSendDlgItemMsg(hwnd,IDC_QUEEN,BM_QUERYCHECK,NULL,NULL);
  2700.      checked[1] = WinSendDlgItemMsg(hwnd,IDC_ROOK,BM_QUERYCHECK,NULL,NULL);
  2701.      checked[2] = WinSendDlgItemMsg(hwnd,IDC_KNIGHT,BM_QUERYCHECK,NULL,NULL);
  2702.      checked[3] = WinSendDlgItemMsg(hwnd,IDC_BISHOP,BM_QUERYCHECK,NULL,NULL);
  2703.      if (checked[0]) // queen
  2704.       {
  2705.        global_promote_char = 'q';
  2706.       }
  2707.      else if (checked[1]) // rook
  2708.       {
  2709.        global_promote_char = 'r';
  2710.       }
  2711.      else if (checked[2]) // knight
  2712.       {
  2713.        global_promote_char = 'n';
  2714.       }
  2715.      else if (checked[3]) // bishop
  2716.       {
  2717.        global_promote_char = 'b';
  2718.       }
  2719.      WinDismissDlg(hwnd, TRUE);
  2720.      return (MRESULT)0L;
  2721.  
  2722.       default:
  2723.      sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  2724.      return sRC;
  2725.    }
  2726. }
  2727.  
  2728.  
  2729.  
  2730. MRESULT EXPENTRY AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  2731. {
  2732.    MRESULT sRC;
  2733.  
  2734.    switch(msg)
  2735.    {
  2736.       case WM_INITDLG:
  2737.      FixSysMenu(hwnd);
  2738.      return (MRESULT)0L;
  2739.  
  2740.       case WM_COMMAND:
  2741.      WinDismissDlg(hwnd, TRUE);
  2742.      return (MRESULT)0L;
  2743.  
  2744.       default:
  2745.      sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  2746.      return sRC;
  2747.    }
  2748. }
  2749.  
  2750.  
  2751.  
  2752. VOID HelpAbout()
  2753. {
  2754.                  /* Display the AboutBox dialog */
  2755.     WinDlgBox(HWND_DESKTOP,
  2756.           hwndClient,
  2757.           (PFNWP)AboutDlgProc,
  2758.           0,
  2759.           IDD_PRODUCTINFO,
  2760.           (PVOID)NULL);
  2761.  
  2762.     return;
  2763. }                                                /* HelpAbout() */
  2764.  
  2765.  
  2766.  
  2767. MRESULT EXPENTRY ClientWndProc(hwnd,msg,mp1,mp2)
  2768. HWND hwnd;
  2769. ULONG msg;
  2770. MPARAM mp1;
  2771. MPARAM mp2;
  2772. {
  2773.  int PromoteChar;
  2774.  POINTL myPoint;
  2775.  RECTL  rc;
  2776.  HPS hps;
  2777.  int ch;
  2778.  POINTL apts[4];
  2779.  char fname[48];
  2780.  char mvnstr[64];
  2781.  int i;
  2782.  int ycoord;
  2783.  static int first=1;
  2784.  APIRET rcd;
  2785.  int keytype,keycode;
  2786.  int tmovenum;
  2787.  int r,c,l,piece,sq;
  2788.  int tmp1,tmp2;
  2789.  PSWP     pSwp;
  2790.  
  2791.  switch (msg)
  2792.   {
  2793.        case WM_CREATE :
  2794.      WinNotInited  = 0;
  2795.      break;
  2796. case WM_MINMAXFRAME:
  2797.         pSwp = (PSWP)mp1;
  2798.         if ( (pSwp) && (pSwp->fl & SWP_MAXIMIZE) )
  2799.          {
  2800.            pSwp->cx = MaxX;
  2801.            pSwp->cy = MaxY;
  2802.            return (MRESULT)TRUE;
  2803.          }
  2804.        else
  2805.          {
  2806.           return( WinDefWindowProc(hwnd,msg,mp1,mp2) );
  2807.          }
  2808.       case WM_COMMAND:
  2809.          if (flag.bothsides)
  2810.           {
  2811.               ShowMessage("off");
  2812.               ShowMessage("Autoplay");
  2813.               flag.back = true;
  2814.               flag.bothsides = false;
  2815.               DosSleep(600);
  2816.               DrawAmigaBoard();
  2817.               break;
  2818.           }
  2819.      MainCommand(hwnd, mp1/*, mp2*/);
  2820.      break;
  2821.       case WM_BUTTON1DOWN:
  2822.          if (WinQueryActiveWindow(HWND_DESKTOP) != hwndFrame)
  2823.           {
  2824.              return(WinDefWindowProc(hwnd,msg,mp1,mp2));
  2825.           }
  2826.          if (flag.bothsides)
  2827.           {
  2828.               ShowMessage("off");
  2829.               ShowMessage("Autoplay");
  2830.               flag.back = true;
  2831.               flag.bothsides = false;
  2832.               DosSleep(600);
  2833.               DrawAmigaBoard();
  2834.               break;
  2835.           }
  2836.          if (EditMode)
  2837.           { // put piece down
  2838.            MouseX = MOUSEMSG(&msg)->x;
  2839.            MouseY = MOUSEMSG(&msg)->y;
  2840.            if (EditMode == 2)
  2841.              {
  2842.                TheBob[CurrBobColor][CurrBobIndex]->XPos = MouseX - 16;
  2843.                TheBob[CurrBobColor][CurrBobIndex]->YPos = MouseY - 12;
  2844.                AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  2845.                EditMode = 1;
  2846.              }
  2847.        if (((MouseY >= (ROW1)) && (MouseY <= ROW8B) &&
  2848.         (MouseX <= (COLH+BOBWIDTH)) && (MouseX >= COLA)))
  2849.           { // mouse down in bounds
  2850.          if (MouseX < COLB)
  2851.            DestCol = 0;
  2852.          else if (MouseX < COLC)
  2853.           DestCol = 1;
  2854.          else if (MouseX < COLD)
  2855.           DestCol = 2;
  2856.          else if (MouseX < COLE)
  2857.           DestCol = 3;
  2858.          else if (MouseX < COLF)
  2859.           DestCol = 4;
  2860.          else if (MouseX < COLG)
  2861.           DestCol = 5;
  2862.          else if (MouseX < COLH)
  2863.           DestCol = 6;
  2864.          else
  2865.           DestCol = 7;
  2866.          if (MouseY < ROW2)
  2867.           DestRow = 0;
  2868.          else if (MouseY < ROW3)
  2869.           DestRow = 1;
  2870.          else if (MouseY < ROW4)
  2871.           DestRow = 2;
  2872.          else if (MouseY < ROW5)
  2873.           DestRow = 3;
  2874.          else if (MouseY < ROW6)
  2875.           DestRow = 4;
  2876.          else if (MouseY < ROW7)
  2877.            DestRow = 5;
  2878.          else if (MouseY < ROW8)
  2879.           DestRow = 6;
  2880.          else
  2881.            DestRow = 7;
  2882.       sq = locn (DestRow, DestCol);
  2883.           if ((CurrBobColor == -1)||(CurrBobIndex == -1))
  2884.            {
  2885.                 color[sq] = amigacolor[sq] = neutral;
  2886.                 amigaboard[sq] = board[sq] = no_piece;
  2887.            }
  2888.           else
  2889.            { // bob index good
  2890.             color[sq] = amigacolor[sq] = CurrBobColor;
  2891.             switch (CurrBobIndex)
  2892.              {
  2893.                 case KINGBOB : amigaboard[sq] = board[sq] = king;break;
  2894.                 case QUEENBOB : amigaboard[sq] = board[sq] = queen;break;
  2895.                 case ROOKBOB : amigaboard[sq] = board[sq] = rook;break;
  2896.                 case BISHOPBOB : amigaboard[sq] = board[sq] = bishop;break;
  2897.                 case KNIGHTBOB : amigaboard[sq] = board[sq] = knight;break;
  2898.                 case PAWNBOB : amigaboard[sq] = board[sq] = pawn;break;
  2899.                 default : color[sq] = amigacolor[sq] = neutral;board[sq] = amigaboard[sq] = no_piece;break;
  2900.              }
  2901.             RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  2902.             DosSleep(100);
  2903.            } // bobindex good
  2904.           } // mouse down in bounds
  2905.           DrawAmigaBoard();
  2906.           DosSleep(100);
  2907.           if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  2908.            {
  2909.             AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  2910.             DrawGList();
  2911.            }
  2912.            break;
  2913.           }
  2914.      if ((!ButtonDown) &&(!(flag.quit || flag.mate || flag.force))
  2915.            &&(!RealThink))
  2916.       {
  2917.           MouseX = MOUSEMSG(&msg)->x;
  2918.           MouseY = MOUSEMSG(&msg)->y;
  2919.           if (((MouseY >= (ROW1)) && (MouseY <= ROW8B) &&
  2920.           (MouseX <= (COLH+BOBWIDTH)) && (MouseX >= COLA)))
  2921.         {
  2922.          if (MouseX < COLB)
  2923.            OrigCol = 0;
  2924.          else if (MouseX < COLC)
  2925.           OrigCol = 1;
  2926.          else if (MouseX < COLD)
  2927.           OrigCol = 2;
  2928.          else if (MouseX < COLE)
  2929.           OrigCol = 3;
  2930.          else if (MouseX < COLF)
  2931.           OrigCol = 4;
  2932.          else if (MouseX < COLG)
  2933.           OrigCol = 5;
  2934.          else if (MouseX < COLH)
  2935.          OrigCol = 6;
  2936.          else
  2937.           OrigCol = 7;
  2938.          if (MouseY < ROW2)
  2939.           OrigRow = 0;
  2940.          else if (MouseY < ROW3)
  2941.           OrigRow = 1;
  2942.          else if (MouseY < ROW4)
  2943.           OrigRow = 2;
  2944.          else if (MouseY < ROW5)
  2945.           OrigRow = 3;
  2946.          else if (MouseY < ROW6)
  2947.           OrigRow = 4;
  2948.          else if (MouseY < ROW7)
  2949.            OrigRow = 5;
  2950.          else if (MouseY < ROW8)
  2951.           OrigRow = 6;
  2952.          else
  2953.            OrigRow = 7;
  2954.          r = OrigRow;
  2955.          c = OrigCol;
  2956.          l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  2957.          if ((amigacolor[l] == neutral)||(opponent != amigacolor[l]))
  2958.           {
  2959.                       return(WinDefWindowProc(hwnd,msg,mp1,mp2));
  2960.                       //break;
  2961.           }
  2962.          else if (amigacolor[l] == white)
  2963.           piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  2964.          else
  2965.           piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  2966.         apts[2].x = 0; // src left bottom
  2967.         apts[2].y = 0; // src left bottom
  2968.         apts[3].x = SQUAREWIDTH - 1; // src rt top
  2969.         apts[3].y = SQUAREHEIGHT - 1; // src rt top
  2970.         apts[0].x = ColArray[OrigCol]; // tgt left bottom
  2971.         apts[0].y = RowArray[OrigRow]; // tgt left bottom
  2972.         apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  2973.         apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  2974.         tmp1 = OrigRow & 1;
  2975.         tmp2 = OrigCol & 1;
  2976.         rcd = DosRequestMutexSem(DrawSemaphore,3000);
  2977.         if (rcd)
  2978.          return(FALSE);
  2979.         if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  2980.           {
  2981.             GpiSetBitmap(hpsMemory,WhiteBitMap);
  2982.           }
  2983.          else
  2984.           {
  2985.             GpiSetBitmap(hpsMemory,BlackBitMap);
  2986.           }
  2987.          GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  2988.          DosReleaseMutexSem(DrawSemaphore);
  2989.          LoadBobImage(piece);
  2990.          TheBob[CurrBobColor][CurrBobIndex]->XPos = MouseX - 16;
  2991.          TheBob[CurrBobColor][CurrBobIndex]->YPos = MouseY - 12;
  2992. //#ifdef OKTODRAW
  2993.          AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  2994.          DrawGList();
  2995. //#endif // OK to draw
  2996.          CheckIllegal = IllegalMove = 0;
  2997.          ButtonDown = 1;
  2998.            } // mouse in bounds
  2999.       } // no special conditions
  3000.      break;
  3001.       case WM_BUTTON1UP:
  3002.      if ((ButtonDown) &&(!(flag.quit || flag.mate || flag.force))
  3003.            &&(!RealThink))
  3004.       {
  3005.        ButtonDown = 0;
  3006.        MouseX = MOUSEMSG(&msg)->x;
  3007.        MouseY = MOUSEMSG(&msg)->y;
  3008.        if (((MouseY >= (ROW1)) && (MouseY <= ROW8B) &&
  3009.         (MouseX <= (COLH+BOBWIDTH)) && (MouseX >= COLA)))
  3010.           { // mouse down in bounds
  3011.          if (MouseX < COLB)
  3012.            DestCol = 0;
  3013.          else if (MouseX < COLC)
  3014.           DestCol = 1;
  3015.          else if (MouseX < COLD)
  3016.           DestCol = 2;
  3017.          else if (MouseX < COLE)
  3018.           DestCol = 3;
  3019.          else if (MouseX < COLF)
  3020.           DestCol = 4;
  3021.          else if (MouseX < COLG)
  3022.           DestCol = 5;
  3023.          else if (MouseX < COLH)
  3024.           DestCol = 6;
  3025.          else
  3026.           DestCol = 7;
  3027.          if (MouseY < ROW2)
  3028.           DestRow = 0;
  3029.          else if (MouseY < ROW3)
  3030.           DestRow = 1;
  3031.          else if (MouseY < ROW4)
  3032.           DestRow = 2;
  3033.          else if (MouseY < ROW5)
  3034.           DestRow = 3;
  3035.          else if (MouseY < ROW6)
  3036.           DestRow = 4;
  3037.          else if (MouseY < ROW7)
  3038.            DestRow = 5;
  3039.          else if (MouseY < ROW8)
  3040.           DestRow = 6;
  3041.          else
  3042.            DestRow = 7;
  3043.          if ((DestRow == OrigRow)&&(DestCol == OrigCol))
  3044.           {
  3045. //#ifdef OKTODRAW
  3046.            RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3047. //#endif
  3048.            CheckIllegal = 1;
  3049.            PutPieceBack();
  3050.           }
  3051.         else
  3052.          { // try to do the move
  3053.            CheckIllegal = 1; 
  3054. //#ifdef OKTODRAW
  3055.            RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3056. //#endif
  3057.            apts[2].x = 0; // src left bottom
  3058.            apts[2].y = 0; // src left bottom
  3059.            apts[3].x = SQUAREWIDTH - 1; // src rt top
  3060.            apts[3].y = SQUAREHEIGHT - 1; // src rt top
  3061.            apts[0].x = ColArray[DestCol]; // tgt left bottom
  3062.            apts[0].y = RowArray[DestRow]; // tgt left bottom
  3063.            apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  3064.            apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  3065.            tmp1 = DestRow & 1;
  3066.            tmp2 = DestCol & 1;
  3067.            rcd = DosRequestMutexSem(DrawSemaphore,3000);
  3068.            if (rcd)
  3069.             return(FALSE);
  3070.            if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  3071.             {
  3072.              GpiSetBitmap(hpsMemory,WhiteBitMap);
  3073.             }
  3074.                else
  3075.             {
  3076.              GpiSetBitmap(hpsMemory,BlackBitMap);
  3077.             }
  3078.            GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  3079.            DosReleaseMutexSem(DrawSemaphore);
  3080.            apts[2].x = 0; // src left bottom
  3081.            apts[2].y = 0; // src left bottom
  3082.            apts[3].x = BOBWIDTH - 1; // src rt top
  3083.            apts[3].y = BOBHEIGHT - 1; // src rt top
  3084.            apts[0].x = ColArray[DestCol]; // tgt left bottom
  3085.            apts[0].y = RowArray[DestRow]; // tgt left bottom
  3086.            apts[1].x = apts[0].x + BOBWIDTH - 1; // tgt rt top
  3087.            apts[1].y = apts[0].y + BOBHEIGHT - 1; // tgt rt top
  3088.            r = OrigRow;
  3089.            c = OrigCol;
  3090.            l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  3091.            if (amigacolor[l] == white)
  3092.             piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  3093.            else if (amigacolor[l] == black)
  3094.             piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  3095.            else
  3096.             piece = BLANKDATA;
  3097.            if (piece != BLANKDATA)
  3098.             {
  3099.              LoadBobImage(piece);
  3100.              TransBlit2(TheBob[CurrBobColor][CurrBobIndex],hwClientPS,hpsMemory,4L,(PPOINTL)apts);
  3101.             }
  3102.            MouseDropped = 1;
  3103.            if (((piece == 'p')&&(DestRow == 7))||/* possible prom wht */
  3104.                ((piece == 'P')&&(!DestRow))) /* possible blk promotion */
  3105.              {
  3106.               PromoteChar = DisplayPromoteRequestor();
  3107.              }
  3108.            else
  3109.              {
  3110.               PromoteChar = 0;
  3111.              }
  3112.            if (computer == white)
  3113.             {
  3114.              tmovenum = (myGameCnt)>>1;
  3115.             }
  3116.            else
  3117.             {
  3118.               tmovenum = (myGameCnt+1)>>1; // was +2
  3119.             }
  3120.            tmovenum++;
  3121.            lOpEntryStr[0] = OrigCol + 'a';
  3122.            lOpEntryStr[1] = OrigRow + '1';
  3123.            lOpEntryStr[2] = DestCol + 'a';
  3124.            lOpEntryStr[3] = DestRow + '1';
  3125.            lOpEntryStr[4] = PromoteChar;
  3126.            lOpEntryStr[5] = 0;
  3127.            mysprintf(mvnstr,"%d: ",tmovenum);
  3128.            strcat(mvnstr,lOpEntryStr);
  3129.            strcpy(OpEntryStr,lOpEntryStr);
  3130.            opindex = 0;
  3131.            myPoint.x = 520;
  3132.            myPoint.y = USERBOX-10;
  3133.            rc.xLeft = 520;
  3134.            rc.yBottom = myPoint.y-4;
  3135.            rc.xRight = 621;
  3136.            rc.yTop = rc.yBottom + 14 + 4;
  3137.            rcd = DosRequestMutexSem(DrawSemaphore,2000);
  3138.            if (!rcd)
  3139.             {
  3140.              WinFillRect(hwClientPS,&rc,BACKGNDTEXTCOLOR);
  3141.              GpiCharStringAt(hwClientPS, &myPoint, strlen(mvnstr),
  3142.                          (PSZ)mvnstr);
  3143.              DosReleaseMutexSem(DrawSemaphore);
  3144.             }
  3145.            if ((thinkahead)&&(!flag.bothsides))
  3146.             { // code to abort quickly and drop piece!
  3147.              if (!TCflag)
  3148.               backsrchaborted = 1;
  3149.              if (!flag.timeout)
  3150.               {
  3151.                flag.back = true;
  3152.               }
  3153.             } // code to abort
  3154.            ReturnHit = 1;
  3155.          } // try to do the move
  3156.           } // mouse down in bounds
  3157.        else // mouse out of bounds
  3158.           {
  3159. //#ifdef OKTODRAW
  3160.         RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3161. //#endif
  3162.         CheckIllegal = 1;
  3163.         DestRow = -1;
  3164.         DestCol = -1;
  3165.         PutPieceBack();
  3166.           } // mouse out of bounds
  3167.       }
  3168.      break;
  3169.       case WM_MOUSEMOVE:
  3170.      if (((ButtonDown) &&(!(flag.quit || flag.mate || flag.force))
  3171.            &&(!RealThink))||(EditMode))
  3172.       {
  3173.            if ((CurrBobColor == -1)||(CurrBobIndex == -1))
  3174.             break;
  3175.        MouseX = MOUSEMSG(&msg)->x;
  3176.        MouseY = MOUSEMSG(&msg)->y;
  3177.        tmp1 = TheBob[CurrBobColor][CurrBobIndex]->XPos - 16;
  3178.        tmp1 = TheBob[CurrBobColor][CurrBobIndex]->YPos - 12;
  3179.        tmp1 = abs(tmp1 - MouseX);
  3180.        tmp2 = abs(tmp2 - MouseY);
  3181.        if (((tmp2 > 3)||(tmp2 > 3))||(EditMode == 2))
  3182.         {
  3183.          TheBob[CurrBobColor][CurrBobIndex]->XPos = MouseX - 16;
  3184.          TheBob[CurrBobColor][CurrBobIndex]->YPos = MouseY - 12;
  3185.               if (EditMode == 2)
  3186.                 {
  3187.                   AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3188.                   EditMode = 1;
  3189.                 }
  3190.          DrawGList();
  3191.         }
  3192.       }
  3193.      break;
  3194.       case WM_CHAR:
  3195.          if (flag.bothsides)
  3196.           {
  3197.               ShowMessage("off");
  3198.               ShowMessage("Autoplay");
  3199.               flag.back = true;
  3200.               flag.bothsides = false;
  3201.               DosSleep(600);
  3202.               DrawAmigaBoard();
  3203.               break;
  3204.           }
  3205.      keytype = SHORT1FROMMP(mp1);
  3206.      if (keytype & KC_CHAR)
  3207.       {
  3208.        keycode =SHORT1FROMMP(mp2);
  3209.        ch = tolower(keycode);
  3210.            if (EditMode)
  3211.             { // change bob or just exit edit mode
  3212.               if (ch == 'x')
  3213.                {
  3214.                 if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3215.                  RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3216.                 EditMode = 0;
  3217.                 ShowMessage("Edit off");
  3218.                 DestRow = DestCol = 0;
  3219.                 for (sq = 0; sq < 64; sq++)
  3220.                    {
  3221.                      if ((board[sq] == king)&&(color[sq] == white))
  3222.                       {
  3223.                         if (DestRow)
  3224.                          {
  3225.                            color[sq] = neutral;
  3226.                            board[sq] = no_piece;
  3227.                          }
  3228.                         DestRow = 1;
  3229.                       }
  3230.                      if ((board[sq] == king)&&(color[sq] == black))
  3231.                       {
  3232.                         if (DestCol)
  3233.                          {
  3234.                            color[sq] = neutral;
  3235.                            board[sq] = no_piece;
  3236.                          }
  3237.                         DestCol = 1;
  3238.                       }
  3239.                    }
  3240.                 if ((!DestCol)||(!DestRow))
  3241.                  {
  3242.                   for(i=0;i<64;i++)
  3243.                    {
  3244.                        color[i] = neutral;
  3245.                        board[i] = no_piece;
  3246.                    }
  3247.                   color[8] = white;
  3248.                   board[8] = pawn;
  3249.                   color[62-8] = black;
  3250.                   board[62-8] = pawn;
  3251.                   color[0] = white;
  3252.                   board[0] = king;
  3253.                   color[62] = black;
  3254.                   board[62] = king;
  3255.                  }
  3256.                 for (sq = 0; sq < 64; sq++)
  3257.                  Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
  3258.                 flag.regularstart = false;
  3259.                 Book = 0;
  3260.                 GameCnt = 0;
  3261.                 Game50 = 1;
  3262.                 ISZERO = 1;
  3263.                 ZeroRPT ();
  3264.                 Sdepth = 0;
  3265.                 InitializeStats ();
  3266.                 MoveMem128(board,amigaboard);
  3267.                 MoveMem128(color,amigacolor);
  3268.                 DrawAmigaBoard();
  3269.                 break;
  3270.                } // ch == 'x'
  3271.               switch (keycode)
  3272.                {
  3273.                  case 'p':
  3274.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3275.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3276.                              TheBob[white][PAWNBOB]->XPos = MouseX;
  3277.                              TheBob[white][PAWNBOB]->YPos = MouseY;
  3278.                              CurrBobColor = white;
  3279.                              CurrBobIndex = PAWNBOB;
  3280.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3281.                              DrawGList();
  3282.                              break;
  3283.                  case 'P':
  3284.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3285.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3286.                              TheBob[black][PAWNBOB]->XPos = MouseX;
  3287.                              TheBob[black][PAWNBOB]->YPos = MouseY;
  3288.                              CurrBobColor = black;
  3289.                              CurrBobIndex = PAWNBOB;
  3290.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3291.                              DrawGList();
  3292.                              break;
  3293.                  case 'n':
  3294.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3295.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3296.                              TheBob[white][KNIGHTBOB]->XPos = MouseX;
  3297.                              TheBob[white][KNIGHTBOB]->YPos = MouseY;
  3298.                              CurrBobColor = white;
  3299.                              CurrBobIndex = KNIGHTBOB;
  3300.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3301.                              DrawGList();
  3302.                              break;
  3303.                  case 'N':
  3304.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3305.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3306.                              TheBob[black][KNIGHTBOB]->XPos = MouseX;
  3307.                              TheBob[black][KNIGHTBOB]->YPos = MouseY;
  3308.                              CurrBobColor = black;
  3309.                              CurrBobIndex = KNIGHTBOB;
  3310.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3311.                              DrawGList();
  3312.                              break;
  3313.                  case 'b':
  3314.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3315.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3316.                              TheBob[white][BISHOPBOB]->XPos = MouseX;
  3317.                              TheBob[white][BISHOPBOB]->YPos = MouseY;
  3318.                              CurrBobColor = white;
  3319.                              CurrBobIndex = BISHOPBOB;
  3320.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3321.                              DrawGList();
  3322.                              break;
  3323.                  case 'B':
  3324.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3325.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3326.                              TheBob[black][BISHOPBOB]->XPos = MouseX;
  3327.                              TheBob[black][BISHOPBOB]->YPos = MouseY;
  3328.                              CurrBobColor = black;
  3329.                              CurrBobIndex = BISHOPBOB;
  3330.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3331.                              DrawGList();
  3332.                              break;
  3333.                  case 'r':
  3334.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3335.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3336.                              TheBob[white][ROOKBOB]->XPos = MouseX;
  3337.                              TheBob[white][ROOKBOB]->YPos = MouseY;
  3338.                              CurrBobColor = white;
  3339.                              CurrBobIndex = ROOKBOB;
  3340.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3341.                              DrawGList();
  3342.                              break;
  3343.                  case 'R':
  3344.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3345.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3346.                              TheBob[black][ROOKBOB]->XPos = MouseX;
  3347.                              TheBob[black][ROOKBOB]->YPos = MouseY;
  3348.                              CurrBobColor = black;
  3349.                              CurrBobIndex = ROOKBOB;
  3350.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3351.                              DrawGList();
  3352.                              break;
  3353.                  case 'q':
  3354.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3355.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3356.                              TheBob[white][QUEENBOB]->XPos = MouseX;
  3357.                              TheBob[white][QUEENBOB]->YPos = MouseY;
  3358.                              CurrBobColor = white;
  3359.                              CurrBobIndex = QUEENBOB;
  3360.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3361.                              DrawGList();
  3362.                              break;
  3363.                  case 'Q':
  3364.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3365.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3366.                              TheBob[black][QUEENBOB]->XPos = MouseX;
  3367.                              TheBob[black][QUEENBOB]->YPos = MouseY;
  3368.                              CurrBobColor = black;
  3369.                              CurrBobIndex = QUEENBOB;
  3370.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3371.                              DrawGList();
  3372.                              break;
  3373.                  case 'k':
  3374.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3375.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3376.                              TheBob[white][KINGBOB]->XPos = MouseX;
  3377.                              TheBob[white][KINGBOB]->YPos = MouseY;
  3378.                              CurrBobColor = white;
  3379.                              CurrBobIndex = KINGBOB;
  3380.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3381.                              DrawGList();
  3382.                              break;
  3383.                  case 'K':
  3384.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3385.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3386.                              TheBob[black][KINGBOB]->XPos = MouseX;
  3387.                              TheBob[black][KINGBOB]->YPos = MouseY;
  3388.                              CurrBobColor = black;
  3389.                              CurrBobIndex = KINGBOB;
  3390.                              AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  3391.                              DrawGList();
  3392.                              break;
  3393.                  case ' ':
  3394.                              if ((CurrBobColor != -1)&&(CurrBobIndex != -1))
  3395.                               RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3396.                              CurrBobColor = -1;
  3397.                              CurrBobIndex = -1;
  3398.                              break;
  3399.                 case 9: // tab clear the board
  3400.                         for (sq = 0; sq < 64; sq++)
  3401.                           {
  3402.                             board[sq] = no_piece;
  3403.                             color[sq] = neutral;
  3404.                           }
  3405.                         MoveMem128(board,amigaboard);
  3406.                         MoveMem128(color,amigacolor);
  3407.                         DrawAmigaBoard();
  3408.                         DrawGList();
  3409.                              break;
  3410.                } // switch
  3411.              break;
  3412.             } // edit mode
  3413.        if (((ch >= 'a')&&(ch <= 'z'))||((ch >= '0')&&(ch <= '9'))||(ch == '-'))
  3414.           {
  3415.            if (opindex < 12)
  3416.         {
  3417.          lOpEntryStr[opindex++] = ch;
  3418.          lOpEntryStr[opindex] = 0;
  3419.         }
  3420.           }
  3421.        else if (( ch == 8)&&(opindex))
  3422.           {
  3423.         opindex--;
  3424.         lOpEntryStr[opindex] = 0;
  3425.           }
  3426.         else if (((ch == 10)||(ch == 13))&&(opindex)&&(!RealThink))
  3427.           {
  3428.         MouseDropped = 0;
  3429.         strcpy(OpEntryStr,lOpEntryStr);
  3430.         opindex = 0;
  3431.         ReturnHit = 1;
  3432.         break;
  3433.           }
  3434.        if (computer == white)
  3435.         {
  3436.            tmovenum = (myGameCnt)>>1;
  3437.         }
  3438.       else
  3439.         {
  3440.            tmovenum = (myGameCnt+1)>>1; // was +2
  3441.         }
  3442.       tmovenum++;
  3443.       mysprintf(mvnstr,"%d: ",tmovenum);
  3444.       strcat(mvnstr,lOpEntryStr);
  3445.       myPoint.x = 520;
  3446.       myPoint.y = USERBOX-10;
  3447.       rc.xLeft = 520;
  3448.       rc.yBottom = myPoint.y-4;
  3449.       rc.xRight = 621;
  3450.       rc.yTop = rc.yBottom + 14 + 4;
  3451.       rcd = DosRequestMutexSem(DrawSemaphore,2000);
  3452.       if (!rcd)
  3453.        {
  3454.         WinFillRect(hwClientPS,&rc,BACKGNDTEXTCOLOR);
  3455.         GpiCharStringAt(hwClientPS, &myPoint, strlen(mvnstr),
  3456.                  (PSZ)mvnstr);
  3457.         DosReleaseMutexSem(DrawSemaphore);
  3458.        }
  3459.       } // normal key pressed
  3460.         break;
  3461.     case WM_PAINT:
  3462.             rcd = DosRequestMutexSem(DrawSemaphore,1000L);
  3463.             if (rcd)
  3464.              return(FALSE);
  3465.             if (first)
  3466.              {
  3467.               first = 0;
  3468.               hps = WinBeginPaint( hwnd, (HPS)NULL, &rc );
  3469.               WinEndPaint( hps );
  3470.               DosReleaseMutexSem(DrawSemaphore);
  3471.               return((MRESULT)FALSE);
  3472.              }
  3473.             hps = WinBeginPaint( hwnd, (HPS)NULL, &rc );
  3474.             if (!LoadFullBitmap(hps,NULL,FALSE,BigColorPalette))
  3475.              {
  3476.               return(FALSE);
  3477.              }
  3478.                         DosSleep(34);
  3479.             DrawChessPieces(hps);
  3480.                         if ((EditMode == 1)&&(CurrBobIndex != -1)&&(CurrBobColor != -1))
  3481.                          {
  3482.                           TheBob[CurrBobColor][CurrBobIndex]->OldX = 
  3483.                           TheBob[CurrBobColor][CurrBobIndex]->OldY = -1;
  3484.                           EditMode = 2;
  3485.               SystemBobList = NULL;
  3486.                          }
  3487.             strcpy(fname,UC_Title);
  3488.             myPoint.x = 511;
  3489.             myPoint.y = COMPUTERBOX+10;
  3490.             GpiCharStringAt(hps, &myPoint, strlen(fname),
  3491.                 (PSZ)fname);
  3492.             myPoint.x = 511;
  3493.             myPoint.y = USERBOX+10;
  3494.             strcpy(fname,"Puny Human:");
  3495.             GpiCharStringAt(hps, &myPoint, strlen(fname),
  3496.                 (PSZ)fname);
  3497.                         if (hum_min != -1)
  3498.                          {
  3499.               mysprintf2(fname,"%d:%02d     ",hum_min,hum_sec);
  3500.               myPoint.x = 540;
  3501.               myPoint.y = TIMEYCOORD2+6;
  3502.               GpiCharStringAt(hps,&myPoint,strlen(fname),(PSZ)fname);
  3503.               mysprintf2(fname,"%d:%02d     ",cmptr_min,cmptr_sec);
  3504.               myPoint.x = 540;
  3505.               myPoint.y = TIMEYCOORD1+6;
  3506.               GpiCharStringAt(hps,&myPoint,strlen(fname),(PSZ)fname);
  3507.                          }
  3508.             ycoord = SYSTEMBOX-2; // was - 6
  3509.             myPoint.x = 510;
  3510.             for(i=0;i<8;i++)
  3511.              {
  3512.                if (MsgBuf[i][0])
  3513.                 {
  3514.                  myPoint.y = ycoord;
  3515.                  GpiCharStringAt(hps,&myPoint,strlen(MsgBuf[i]),(PSZ)MsgBuf[i]);
  3516.                  ycoord -= 15;
  3517.                 }
  3518.               }
  3519.             WinEndPaint( hps );
  3520.             DosReleaseMutexSem(DrawSemaphore);
  3521.                         if (EditMode)
  3522.                          DosSleep(300);
  3523.             break;
  3524.     case WM_ERASEBACKGROUND:
  3525.             // Return TRUE to cause PM to paint the window background
  3526.             // in SYSCLR_WINDOW.
  3527.             return (MRESULT)( TRUE );
  3528.     case WM_SIZE:
  3529.             cxClient = SHORT1FROMMP( mp2 );
  3530.             GotSize = 1;
  3531.             cyClient = SHORT2FROMMP( mp2 );
  3532.             break;
  3533.     default:
  3534.             return(WinDefWindowProc(hwnd,msg,mp1,mp2));
  3535.   } // switch msg
  3536.  return((MRESULT)FALSE);
  3537. }
  3538.  
  3539.  
  3540.  
  3541. void mysprintf(char *,char *,int);
  3542. void mysprintf2(char *,char *,int,int);
  3543.  
  3544.  
  3545. // >>should be OK for PM<<
  3546. void SetTimeControl2 (color)
  3547. int color;
  3548. {
  3549.  int tmp;
  3550.  int other;
  3551.  
  3552.   other = color ^ 1;
  3553.   if (TCflag)
  3554.     {
  3555.       TimeControl.moves[color] = TCmoves;
  3556.       TimeControl.clock[color] += (6000L * TCminutes + TCseconds * 100);
  3557.       tmp = (TCminutes*60+TCseconds)/TCmoves;
  3558.       if (color == computer)
  3559.        {
  3560.       SecsPerMove = tmp;
  3561.       if (tmp < 10)
  3562.        {
  3563.     GlobalTgtDepth = 3; // was 2
  3564.        }
  3565.       else if (tmp < 180)
  3566.        {
  3567.     GlobalTgtDepth = 4; // was 3
  3568.        }
  3569.       else
  3570.        GlobalTgtDepth = 5; // was 4
  3571.       }
  3572.       TimeControl.moves[other] = TCmoves;
  3573.       TimeControl.clock[other] += (6000L * TCminutes + TCseconds * 100);
  3574.       tmp = (TCminutes*60+TCseconds)/TCmoves;
  3575.       if (other == computer)
  3576.        {
  3577.       SecsPerMove = tmp;
  3578.       if (tmp < 10)
  3579.        {
  3580.     GlobalTgtDepth = 3; // was 2
  3581.        }
  3582.       else if (tmp < 180)
  3583.        {
  3584.     GlobalTgtDepth = 4; // was 3
  3585.        }
  3586.       else
  3587.        GlobalTgtDepth = 5; // was 4
  3588.       }
  3589.     }
  3590.   else
  3591.     {
  3592.       TimeControl.moves[color] = 0;
  3593.       TimeControl.clock[color] = 0;
  3594.       TimeControl.moves[other] = 0;
  3595.       TimeControl.clock[other] = 0;
  3596.     }
  3597.   flag.onemove = (TCmoves == 1);
  3598.   et = 0;
  3599.   ElapsedTime (1);
  3600. }
  3601.  
  3602. #ifdef AMIGA
  3603. void DoEasy()
  3604. {
  3605.  
  3606.     PlayMode = 0;
  3607.     //Bob->XPos = WIDTH-1-BOBWIDTH;
  3608.     //Bob->YPos = HEIGHT-1-BOBHEIGHT;
  3609.     //RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3610.     NewGame();
  3611. }
  3612.  
  3613. void DoAdvanced()
  3614. {
  3615.  
  3616.     PlayMode = 2;
  3617. //    RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3618. //    BobVSprite->X = WIDTH-1-BOBWIDTH;
  3619. //    BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  3620. //    LoadBobImage(BLANKDATA);
  3621. //    if (SYSTEM_BOBS)
  3622. //     {
  3623. //      SortGList(rpG);
  3624. //      DrawGList(rpG,vP);
  3625. //     }
  3626. //    MakeVPort(GfxBase->ActiView,vP);
  3627. //    MrgCop(GfxBase->ActiView);
  3628. //    WaitTOF();
  3629. //    RethinkDisplay();
  3630.     NewGame();
  3631. }
  3632.  
  3633. void DoIntermediate()
  3634. {
  3635.  
  3636.     PlayMode = 1;
  3637. //    RemBob(TheBob[CurrBobColor][CurrBobIndex]);
  3638. //    BobVSprite->X = WIDTH-1-BOBWIDTH;
  3639. //    BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  3640. //    LoadBobImage(BLANKDATA);
  3641. //    if (SYSTEM_BOBS)
  3642. //     {
  3643. //      SortGList(rpG);
  3644. //      DrawGList(rpG,vP);
  3645. //     }
  3646. //    MakeVPort(GfxBase->ActiView,vP);
  3647. //    MrgCop(GfxBase->ActiView);
  3648. //    WaitTOF();
  3649. //    RethinkDisplay();
  3650.     NewGame();
  3651. f}
  3652.  
  3653. #endif // amiga
  3654.  
  3655. void mysprintf(ostr,fstr,num)
  3656. char *ostr,*fstr;
  3657. int num;
  3658. { // formats string "%d: xxx"
  3659.  
  3660.  int index;
  3661.  int thou,hun,ten,one,rem;
  3662.  
  3663.  
  3664.  if (num < 0) 
  3665.   {
  3666.    num = -num;
  3667.    index = 1;
  3668.    strcpy(ostr,"-");
  3669.   }
  3670.  else
  3671.   {
  3672.    index = 0;
  3673.    ostr[0] = 0;
  3674.   }
  3675.  thou = num / 1000;
  3676.  rem = num-(num / 1000)*1000;
  3677.  hun = (rem / 100);
  3678.  rem = rem-(hun * 100);
  3679.  ten = rem / 10;
  3680.  rem = rem-(ten * 10);
  3681.  one = rem;
  3682.  if (thou)
  3683.   {
  3684.    ostr[index++] = thou+'0';
  3685.   }
  3686.  if ((hun)||(thou))
  3687.   {
  3688.    ostr[index++] = hun+'0';
  3689.   }
  3690.  if ((ten)||(hun)||(thou))
  3691.   {
  3692.    ostr[index++] = ten+'0';
  3693.   }
  3694.  ostr[index++] = one+'0';
  3695.  ostr[index] = 0;
  3696.  strcat(ostr,&fstr[2]);
  3697. }
  3698.  
  3699. void mysprintf2(ostr,fstr,num,num2)
  3700. char *ostr,*fstr;
  3701. int num,num2;
  3702. { // formats string "%d: xxx"
  3703.  
  3704.  int index;
  3705.  int thou,hun,ten,one,rem;
  3706.  
  3707.  
  3708.  if (num < 0) 
  3709.   {
  3710.    num = -num;
  3711.    index = 1;
  3712.    strcpy(ostr,"-");
  3713.   }
  3714.  else
  3715.   {
  3716.    index = 0;
  3717.    ostr[0] = 0;
  3718.   }
  3719.  thou = num / 1000;
  3720.  rem = num-(num / 1000)*1000;
  3721.  hun = (rem / 100);
  3722.  rem = rem-(hun * 100);
  3723.  ten = rem / 10;
  3724.  rem = rem-(ten * 10);
  3725.  one = rem;
  3726.  if (thou)
  3727.   {
  3728.    ostr[index++] = thou+'0';
  3729.   }
  3730.  if ((hun)||(thou))
  3731.   {
  3732.    ostr[index++] = hun+'0';
  3733.   }
  3734.  if ((ten)||(hun)||(thou))
  3735.   {
  3736.    ostr[index++] = ten+'0';
  3737.   }
  3738.  ostr[index++] = one+'0';
  3739.  ostr[index++] = ':';
  3740.  
  3741.  ten = num2 / 10;
  3742.  one = num2 % 10;
  3743.  ostr[index++] = ten+'0';
  3744.  ostr[index++] = one+'0';
  3745.  ostr[index] = 0;
  3746.  strcat(ostr,&fstr[7]);
  3747. }
  3748.  
  3749. void
  3750. gsrand (unsigned int seed);
  3751.  
  3752.  
  3753. void calc_pgm_rating()
  3754. {
  3755.  /* 34 secs on an RS/6000 which is about 2338, so to rate itself
  3756.     rating = 2338 - 75*(log2(time) - log2(34)) */
  3757.  
  3758.  unsigned long st;
  3759.  unsigned long endst;
  3760.  double secs;
  3761.  int rating;
  3762.  int tmpbk,Old,oldtc;
  3763.  int OldPM;
  3764.  char tstr[32],tstr2[32];
  3765.  
  3766.  OldPM = PlayMode;
  3767.  PlayMode = 2;
  3768.  tmpbk = Book;
  3769.  oldtc = TCflag;
  3770.  Old = MaxSearchDepth;
  3771.  NewGame ();
  3772.  UpdateDisplay (0, 0, 1, 0);
  3773.  MaxSearchDepth = 6;
  3774.  Book = 0;
  3775.  TCflag = 0;
  3776.  computer = computer ^ 1;
  3777.  opponent = opponent ^ 1;
  3778.  xwndw = (computer == white) ? WXWNDW : BXWNDW;
  3779.  flag.force = false;
  3780.  Sdepth = 0;
  3781.  ShowMessage("Calculating.");
  3782.  ShowMessage("Please wait.");
  3783. // SetPointer(wG,myPointer,PTRHEIGHT,0x10L,0L,0L);
  3784.  flag.beep = 0;
  3785.  st = clock();
  3786.  SelectMove (computer, 1);
  3787.  endst = clock();
  3788.  secs = (endst - st);
  3789.  secs = secs / CLOCKS_PER_SEC;
  3790.  st = secs;
  3791. // ClearPointer(wG);
  3792.  if (st<4)
  3793.   st = 4;
  3794.  st = (st - 2)/6;
  3795.  if (st > 200)
  3796.   {
  3797.    strcpy(tstr,"too slow Cannot rate");
  3798.   }
  3799.  else
  3800.   {
  3801.    if (st < 4)
  3802.     st = 4;
  3803. #ifdef PL_60
  3804.    rating = 2350 - (((75*log_e[st]) - (75*LOGE_34))/LN2);
  3805. #else /* patch level 61 */
  3806.    rating = 2350 - (((75*log_e[st]) - (75*LOGE_16))/LN2);
  3807. #endif
  3808.    rating -= 40;
  3809.    sprintf(tstr,"USCF %04d",rating);
  3810.   }
  3811.  Book = tmpbk;
  3812.  MaxSearchDepth = Old;
  3813.  TCflag = oldtc;
  3814.  PlayMode = OldPM;
  3815.  NewGame ();
  3816.  UpdateDisplay (0, 0, 1, 0);
  3817.  sprintf(tstr2,"%1.2lf secs",secs);
  3818.  ShowMessage(tstr2);
  3819.  ShowMessage(tstr);
  3820. }
  3821.  
  3822. int DoResign()
  3823. {
  3824.  ULONG response;
  3825. // struct EasyStruct  resignES = {
  3826. //    sizeof (struct EasyStruct),
  3827. //    0,
  3828. //    "Resignation Alert",
  3829. //    "Accept UChess's Resignation",
  3830. //    "Yes|No",
  3831. //  };
  3832.  
  3833.  //ULONG  iflags=0L;
  3834.  //UCHAR   volname[4]={0,0,0,0};
  3835.  
  3836.  ResignOffered = -1;
  3837.  response = WinMessageBox(HWND_DESKTOP,hwndClient,"Accept resignation","UChess Resigns",0,MB_YESNO);
  3838.  if (response == MBID_YES)
  3839.   return(0xff);
  3840.  else
  3841.   return(0);
  3842. // Delay(30L);
  3843. // DisplayBeep(0L);
  3844. /* return 0 if no resign accepted, yes if accepted */
  3845. // return(EasyRequest( wG, &resignES, &iflags, volname ));
  3846. }
  3847.  
  3848.  
  3849. void GetEditText(s,color)
  3850. char *s;
  3851. int *color;
  3852. { /* gets the edit string from the user */
  3853.   /* returns # for clr bd, c for change colors and pa1 to put a pawn at a1*/
  3854.   /* YOU MUST RETURN THE STRING IN ALL LOWER CASE! */
  3855.  
  3856. if (*color == white)
  3857.  s[0] = 0; // to shut up compiler for now
  3858. #ifdef NEEDTODO
  3859.   int dun;
  3860.   long code,class;
  3861.   int i;
  3862.   APTR object;
  3863.   struct IntuiMessage *message;
  3864.  
  3865.   dun = 0;
  3866.   s[0] = 0;
  3867.   pppSIBuff[0] = '\0';
  3868.   ActivateGadget(&pGadget1,wGEdit,NULL);
  3869.   do {
  3870.   WaitPort(wGEdit->UserPort);
  3871.   while(message = (struct IntuiMessage *)GetMsg(wGEdit->UserPort))
  3872.   {
  3873.    code = message->Code;
  3874.    object = message->IAddress;
  3875.    class = message->Class;
  3876.    ReplyMsg((struct Message *)message);
  3877.    if (class == CLOSEWINDOW)
  3878.     {
  3879.      strcpy(s,".");
  3880.      dun = 1;
  3881.     }
  3882.    else if (class == GADGETUP)
  3883.     { /* text */
  3884.      if (object == (APTR)&pGadget1)
  3885.       {
  3886.        if (pppSIBuff[0])
  3887.     {
  3888.      dun = 1;
  3889.      strcpy(s,pppSIBuff);
  3890.      for(i=0;i<4;i++)
  3891.       s[i] = tolower(s[i]);
  3892.     }
  3893.       }
  3894.      else if (object == (APTR)&pGadget2)
  3895.       {
  3896.        dun = 1;
  3897.        strcpy(s,"#");
  3898.       }
  3899.      else if (object == (APTR)&pGadget3)
  3900.       { /* white/black */
  3901.        if (*color == white)
  3902.     *color = black;
  3903.        else
  3904.     *color = white;
  3905.        SetDrMd(wGEdit->RPort,JAM1);
  3906.        SetAPen(wGEdit->RPort,0L);
  3907.        RectFill(wGEdit->RPort,107,124,167,145);
  3908.        if (*color == white)
  3909.     PrintIText(wGEdit->RPort,&pIText2,0L,0L); /* white label */
  3910.        else
  3911.     PrintIText(wGEdit->RPort,&pIText2a,0L,0L); /* white label */
  3912.       }
  3913.      else if (object == (APTR)&pGadget4)
  3914.       { /* done */
  3915.        strcpy(s,".");
  3916.        dun = 1;
  3917.       }
  3918.     }
  3919.   }
  3920.  } while (!dun);
  3921.  DisplayBeep(0L);
  3922. #endif // NEEDTODO
  3923. }
  3924.  
  3925. void CloseAmigaEditWindow()
  3926. {
  3927.  
  3928. #ifdef NEEDTODO
  3929.  struct IntuiMessage *message;
  3930.  
  3931.   while(message = (struct IntuiMessage *)GetMsg(wGEdit->UserPort))
  3932.   {
  3933.    ReplyMsg((struct Message *)message);
  3934.   }
  3935.  CloseWindow(wGEdit);
  3936. // if (DEPTH >= 6)
  3937. //  {
  3938. //   SetRGB32(vP,1,tmppal[0],tmppal[1],tmppal[2]);
  3939. //  }
  3940. // else
  3941. //  {
  3942. //   SetRGB4(vP,1,((tmppal[0]>>8)&0xf),((tmppal[0]>>4)&0xf),((tmppal[0])&0xf));
  3943. //  }
  3944. #endif //need to do
  3945. }
  3946.  
  3947.  
  3948. int OpenAmigaEditWindow() /* opens a window for edit board */
  3949.  {
  3950. #ifdef NEEDTODO
  3951.   if (!(wGEdit = OpenWindow(&pNewWindowStructure1)))
  3952.    {
  3953.     DisplayBeep(0L);
  3954.     return(0);
  3955.    }
  3956. // if (DEPTH >= 6)
  3957. //  {
  3958. //   tmppal[0] = BigColorPalette[4];
  3959. //   tmppal[1] = BigColorPalette[5];
  3960. //   tmppal[2] = BigColorPalette[6];
  3961. //   SetRGB32(vP,1,0xaaaaaaaa,0xaaaaaaaa,0xaaaaaaaa);
  3962. //  }
  3963. // else
  3964.  // {
  3965.  //  tmppal[0] = myPalette[1];
  3966. //   SetRGB4(vP,1,0xa,0xa,0xa);
  3967. //  }
  3968.   pppSIBuff[0] = 0;
  3969.   pppSIBuff[3] = 0;
  3970.   PrintIText(wGEdit->RPort,&pIText4,0L,0L);
  3971.   PrintIText(wGEdit->RPort,&pIText2,0L,0L); /* white label */
  3972. #endif // NEEDTODO
  3973.   return(1);
  3974.  }
  3975.  
  3976.  
  3977. #ifdef AMIGA
  3978. void EnableMoveNow()
  3979. {
  3980.  if (MenuStripSet)
  3981.   {
  3982.    MoveNowOK = 1;
  3983.    OnMenu(wG,MOVENOWMENUNUM); 
  3984.   }
  3985. }
  3986.  
  3987. void DisableMoveNow()
  3988. {
  3989.  if (MenuStripSet)
  3990.   {
  3991.    MoveNowOK = 0;
  3992.    OffMenu(wG,MOVENOWMENUNUM); 
  3993.   }
  3994. }
  3995.  
  3996. #endif
  3997.  
  3998. int GetFileName(char *s)
  3999. {
  4000.   HWND hwnd;
  4001.   FILEDLG myFilD;
  4002.   HWND hwndDlg;
  4003.  
  4004.      hwnd = hwndClient;
  4005.      memset(&myFilD,0,sizeof(FILEDLG));
  4006.      myFilD.pszTitle = globaltitle;
  4007.      myFilD.cbSize = sizeof(FILEDLG);
  4008.      myFilD.fl = FDS_HELPBUTTON | FDS_CENTER; // also FDS_SAVEAS_DIALOG
  4009.      myFilD.fl |= GlobalFilType;
  4010.      myFilD.szFullFile[0] = 0;
  4011.      hwndDlg = WinFileDlg(HWND_DESKTOP,hwnd,&myFilD);
  4012.      if ((hwndDlg && (myFilD.lReturn == DID_OK)))
  4013.       {// myFilD.szFullFile has the filename
  4014.        strcpy(s,myFilD.szFullFile);
  4015.        return(0xff);
  4016.       }
  4017.      return(0);
  4018. #ifdef NEEDTODO
  4019.  int tmp;
  4020.  struct FileRequester *myFileReq;
  4021.  struct  TagItem  Tags[2] = {
  4022.  {ASLFR_Window,0L},
  4023.  {0,0}
  4024.  };
  4025.  
  4026.  Tags[0].ti_Data = (ULONG)wG;
  4027.  myFileReq = AllocAslRequest(ASL_FileRequest,Tags);
  4028.  if (myFileReq)
  4029.   {
  4030.    tmp = AslRequest(myFileReq,Tags);
  4031.    if (!tmp)
  4032.     {
  4033.      FreeAslRequest(myFileReq);
  4034.      return(0);
  4035.     }
  4036.    strcpy(s,myFileReq->fr_Drawer);
  4037.    if (s[0])
  4038.     {
  4039.      if ((s[strlen(s)-1] != ':')&&(s[strlen(s)-1] != '/'))
  4040.       {
  4041.        strcat(s,"/");
  4042.       }
  4043.     }
  4044.    strcat(s,myFileReq->fr_File);
  4045.    FreeAslRequest(myFileReq);
  4046.    return(0xff);
  4047.   }
  4048.  else
  4049.   return(0);
  4050. #endif
  4051. }
  4052.  
  4053. #ifdef AMIGA
  4054. int GetScreenMode()
  4055. {
  4056.  int tmp;
  4057.  struct ScreenModeRequester *myScreenReq;
  4058.  struct TagItem  Tags[4] = {
  4059.  {ASLSM_InitialDisplayID,HIRES|LACE|DEFAULT_MONITOR_ID},
  4060.  {ASLSM_InitialAutoScroll,FALSE},
  4061.  {0,0}
  4062.  };
  4063.  
  4064.  myScreenReq = AllocAslRequest(ASL_ScreenModeRequest,0L);
  4065.  if (myScreenReq)
  4066.   {
  4067.    tmp = AslRequest(myScreenReq,Tags);
  4068.    if (!tmp)
  4069.     {
  4070.      FreeAslRequest(myScreenReq);
  4071.      return(0);
  4072.     }
  4073.    RTG_ModeID = myScreenReq->sm_DisplayID;
  4074.    FreeAslRequest(myScreenReq);
  4075.    return(0xff);
  4076.   }
  4077.  else
  4078.   return(0);
  4079. }
  4080.  
  4081. #endif // AMIGA
  4082.  
  4083. void
  4084. UpdateClocks (void)
  4085. {
  4086.   POINTL myPoint;
  4087.   char tempstr[16];
  4088.   APIRET rc;
  4089.   long ycoord;
  4090.   INTSIZE ref_min,ref_sec;
  4091.   ULONG max_time;
  4092.   INTSIZE m, s;
  4093.   RECTL myRect;
  4094.   int score_diff;
  4095.  
  4096.   m = (INTSIZE) (et / 6000);
  4097.   s = (INTSIZE) (et - 6000 * (long) m) / 100;
  4098.   if (TCflag)
  4099.     {
  4100.       m = (INTSIZE) ((TimeControl.clock[player] - et) / 6000);
  4101.       s = (INTSIZE) ((TimeControl.clock[player] - et - 6000 * (long) m) / 100);
  4102.     }
  4103.   if (m < 0)
  4104.     m = 0;
  4105.   if (s < 0)
  4106.     s = 0;
  4107.   if (player == computer)
  4108.    {
  4109.     ref_min = cmptr_min;
  4110.     ref_sec = cmptr_sec;
  4111.     ycoord = TIMEYCOORD1;
  4112.    }
  4113.   else
  4114.    {
  4115.     ref_min = hum_min;
  4116.     ref_sec = hum_sec;
  4117.     ycoord = TIMEYCOORD2;
  4118.    }
  4119.   if ((ref_min != m)||(ref_sec != s))
  4120.    {
  4121.     mysprintf2(tempstr,"%d:%02d     ",m,s);
  4122.     rc = DosRequestMutexSem(DrawSemaphore,5000);
  4123.     if (rc)
  4124.      {
  4125.       return;
  4126.      }
  4127.     //Move(rpG,540,ycoord);
  4128.     //mySetABPenDrMd(rpG,BACKGNDTEXTCOLOR,bpen,JAM1);
  4129.     //RectFill(rpG,540,ycoord-6,621,ycoord+5);
  4130.     //mySetABPenDrMd(rpG,BLACK,bpen,JAM1);
  4131.  
  4132. #ifdef AMIGA   
  4133.     Move(rpG,540,ycoord);
  4134.     Text(rpG,tempstr,strlen(tempstr));
  4135. #else
  4136.     myRect.xLeft = 540;
  4137.     myRect.yBottom = ycoord+6;
  4138.     myRect.xRight = 621;
  4139.     myRect.yTop = ycoord + 6 + 14;
  4140.     WinFillRect(hwClientPS,&myRect,BACKGNDTEXTCOLOR);
  4141.     myPoint.x = 540;
  4142.     myPoint.y = ycoord+6;
  4143.     GpiCharStringAt(hwClientPS,&myPoint,strlen(tempstr),(PSZ)tempstr);
  4144. #endif
  4145.  
  4146.     DosReleaseMutexSem(DrawSemaphore);
  4147.     if (player == computer)
  4148.      {
  4149.       score_diff = global_tmp_score - previous_score;
  4150.       cmptr_min = m;
  4151.       cmptr_sec = s;
  4152.       if (TCflag)
  4153.        {
  4154.     max_time = s + m*60;
  4155.     if ((TimeControl.moves[computer] < ((TCmoves/2)-2))&&(Sdepth > GlobalTgtDepth)&&
  4156.         (score_diff >= -55)&&(ResponseTime < 9999998)&&
  4157.         (max_time<(((TimeControl.moves[computer]-1)*SecsPerMove)>>1)))
  4158.      {//have little time available on 2nd half of game
  4159.       flag.back = true;
  4160.      }
  4161.     if ((!m)&&(s <= 1)&&(Sdepth > MINDEPTH))
  4162.      {
  4163.       flag.back = true;
  4164.      }
  4165.     if ((Sdepth > MINDEPTH)&&(!m)&&
  4166.         (s<((TimeControl.moves[player]-1)*5)))
  4167.      { // less than 1 min left on clock, less than 5 secs/move!
  4168.       flag.back = true;
  4169.      }
  4170.       }
  4171. //printf("prev score = %d  global_tmp_score = %d\n",previous_score,global_tmp_score);
  4172. //printf("score_diff = %d  Sdepth = %d GlobalTgtDepth = %d\n",score_diff,Sdepth,GlobalTgtDepth);
  4173.       if (((score_diff > -16))&&(Sdepth > GlobalTgtDepth)
  4174.       &&(OrigResponse > 2500)&&(global_tmp_score > -55))
  4175.        { // more than 25 secs/move and am not losing by too much
  4176.     ycoord = OrigResponse >> 1;
  4177.     if (ycoord > 3101)
  4178.      ycoord = 3101;
  4179.     max_time = OrigResponse + ycoord; // 1.5Xorig OR orig + 31 whichver is smaller
  4180. //printf("max time = %lu et = %lu\n",max_time,et);
  4181.        }
  4182.       else if (Sdepth > (GlobalTgtDepth))
  4183.        max_time = (OrigResponse<<1) + ExtraTime + 101;
  4184.       else
  4185.        max_time = ((OrigResponse<<1) + ExtraTime + OrigResponse);
  4186.       if ((TCflag) && (!trying_again) && (ResponseTime < 9999998) && (Sdepth > MINDEPTH)
  4187.       && ((et) >= max_time))
  4188.        {
  4189. //printf("Considering the move!\n");
  4190.     if (score_diff >= -75)
  4191.       {
  4192.        flag.back = true;
  4193.       }
  4194.        } 
  4195.      }
  4196.     else // human player
  4197.      {
  4198.       hum_min = m;
  4199.       hum_sec = s;
  4200.      }
  4201.    } // 1 sec or more has elapsed
  4202. }
  4203.  
  4204.  
  4205. char DisplayPromoteRequestor()
  4206. {
  4207.  global_promote_char = 'q';
  4208.  WinDlgBox(HWND_DESKTOP,hwndClient,PromoteFunc,0,IDD_PROMOTE,0);
  4209.  return(global_promote_char);
  4210. #ifdef NEEDTODO
  4211. // ULONG tmp[4];
  4212.  int dun;
  4213.  struct IntuiMessage  *message;
  4214.  struct Window  *wG3;
  4215.  UWORD  code;
  4216.  ULONG  class;
  4217.  APTR object;
  4218.  
  4219. // if (DEPTH >= 6)
  4220. //  {
  4221. //   tmp[0] = BigColorPalette[4];
  4222. //   tmp[1] = BigColorPalette[5];
  4223. //   tmp[2] = BigColorPalette[6];
  4224. //   SetRGB32(vP,1,0xaaaaaaaa,0xaaaaaaaa,0xaaaaaaaa);
  4225. // }
  4226. // else
  4227. //  {
  4228. //   tmp[0] = myPalette[1];
  4229. //   SetRGB4(vP,1,0xa,0xa,0xa);
  4230. //  }
  4231.  if (!(wG3 = OpenWindow(&NewWindowStructure6)))
  4232.  {
  4233.   DisplayBeep(0L);
  4234.   return('q');
  4235.  }
  4236.  PrintIText(wG3->RPort,&aIText5,0L,0L);
  4237.  dun = 0;
  4238.  do {
  4239.  WaitPort(wG3->UserPort);
  4240.  while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  4241.   {
  4242.    code = message->Code;
  4243.    object = message->IAddress;
  4244.    class = message->Class;
  4245.    ReplyMsg((struct Message *)message);
  4246.    dun = 1;
  4247.    if (object == (APTR)&aGadget1)
  4248.       {
  4249.        retchar = 'q';
  4250.       }
  4251.     else if (object == (APTR)&aGadget2)
  4252.       {
  4253.        retchar = 'r';
  4254.       }
  4255.     else if (object == (APTR)&aGadget3)
  4256.       {
  4257.        retchar = 'b';
  4258.       }
  4259.     else if (object == (APTR)&aGadget4)
  4260.       {
  4261.        retchar = 'n';
  4262.       }
  4263.   }
  4264.  } while (!dun);
  4265.  CloseWindow(wG3);
  4266. // if (DEPTH >= 6)
  4267. //  {
  4268. //   SetRGB32(vP,1,tmp[0],tmp[1],tmp[2]);
  4269. //  }
  4270. // else
  4271.  // {
  4272.  //  SetRGB4(vP,1,((tmp[0]>>8)&0xf),((tmp[0]>>4)&0xf),((tmp[0])&0xf));
  4273. //  }
  4274. #endif // NEEDTODO
  4275. }
  4276.  
  4277. #ifdef AMIGA
  4278.  
  4279. void tFreeBitMap(struct BitMap *);
  4280. void sFreeBitMap(struct BitMap *);
  4281. struct BitMap *tAllocBitMap(int,int,int,int,struct BitMap *);
  4282. struct BitMap *sAllocBitMap(int,int,int,int,struct BitMap *);
  4283.  
  4284. struct BitMap *tAllocBitMap(wid,ht,depth,flags,friend)
  4285. int wid,ht,depth,flags;
  4286. struct BitMap *friend;
  4287. {
  4288.  int i;
  4289.  unsigned long tt;
  4290.  LONG image_data;
  4291.  ULONG planes;
  4292.  struct BitMap *tmp;
  4293.  
  4294.  if (gfxversion < 39)
  4295.   {
  4296.    planes = RASSIZE(wid,ht);
  4297.    if (!(tmp = AllocMem(sizeof (struct BitMap),MEMF_CLEAR)))
  4298.     {
  4299.      return(0);
  4300.     }
  4301.    InitBitMap(tmp,depth,wid,ht);
  4302.    tt = planes*depth;
  4303.    if (!(tmp->Planes[0] = AllocMem(tt,MEMF_CHIP|MEMF_CLEAR)))
  4304.     {
  4305.      FreeMem(tmp,sizeof(struct BitMap));
  4306.      return(0);
  4307.     }
  4308.    image_data = (LONG)tmp->Planes[0];
  4309.    for(i=1;i<depth;i++)
  4310.     {
  4311.      tmp->Planes[i] = (PLANEPTR) (image_data + i * planes);
  4312.     }
  4313.   }
  4314.  else
  4315.   {
  4316.    tmp = AllocBitMap(wid,ht,depth,flags,friend);
  4317.   }
  4318.  return(tmp);
  4319. }
  4320.  
  4321. struct BitMap *sAllocBitMap(wid,ht,depth,flags,friend)
  4322. int wid,ht,depth,flags;
  4323. struct BitMap *friend;
  4324. {
  4325.  int i;
  4326.  unsigned long tt;
  4327.  ULONG image_data;
  4328.  ULONG planes;
  4329.  struct BitMap *tmp;
  4330.  
  4331.  
  4332.  if (!(tmp = AllocMem(sizeof (struct BitMap),MEMF_CLEAR)))
  4333.   {
  4334.    return(0);
  4335.   }
  4336.  InitBitMap(tmp,8,640,480);
  4337.  planes = RASSIZE(640,480);
  4338.  tmp->BytesPerRow = 640;
  4339.  tmp->Flags = 0x0;
  4340.  tmp->Rows = 480;
  4341.  tmp->Depth = 8;
  4342.  tmp->pad = 32860;
  4343.  tt = planes*8;
  4344.  if (!(tmp->Planes[0] = AllocMem(tt,MEMF_CHIP|MEMF_CLEAR)))
  4345.   {
  4346.    FreeMem(tmp,sizeof(struct BitMap));
  4347.    return(0);
  4348.   }
  4349.  image_data = (ULONG)tmp->Planes[0];
  4350.  planes = 0x50;
  4351.  for(i=1;i<depth;i++)
  4352.   {
  4353.    tmp->Planes[i] = (PLANEPTR) (image_data + i * planes);
  4354.   }
  4355.  return(tmp);
  4356. }
  4357.  
  4358. void tFreeBitMap(bmap)
  4359. struct BitMap *bmap;
  4360. {
  4361.  ULONG numbytes;
  4362.  
  4363.  if (gfxversion < 39)
  4364.   {
  4365.    numbytes = bmap->Rows*bmap->BytesPerRow*bmap->Depth;
  4366.    FreeMem(bmap->Planes[0],numbytes);
  4367.    FreeMem(bmap,sizeof(struct BitMap));
  4368.   }
  4369.  else
  4370.   {
  4371.    FreeBitMap(bmap);
  4372.   }
  4373. }
  4374.  
  4375. void sFreeBitMap(bmap)
  4376. struct BitMap *bmap;
  4377. {
  4378.  ULONG numbytes,planes;
  4379.  
  4380.   planes = RASSIZE(640,480);
  4381.   numbytes = planes*8;
  4382.   FreeMem(bmap->Planes[0],numbytes);
  4383.   FreeMem(bmap,sizeof(struct BitMap));
  4384. }
  4385.  
  4386.  
  4387.  
  4388. int HandleEvent(object)
  4389. APTR object;
  4390. {
  4391.  int tmpdone=0;
  4392.  UWORD nextcode;
  4393.  struct MenuItem *myMenuItem;
  4394.  
  4395.  do {
  4396.   if (!RealThink)
  4397.    {
  4398.     if (object == (APTR)&MenuItem15) { DoQuit();return(1); }
  4399.     if (object == (APTR)&MenuItem1) { DoHint(); }
  4400.     if (object == (APTR)&MenuItem12) { DoAbout(); }
  4401.     //if (object == (APTR)&MenuItem6) { }
  4402.     if (object == (APTR)&MenuItem13) { LoadAGame(); }
  4403.     if (object == (APTR)&MenuItem14) { SaveAGame(); }
  4404.     if (object == (APTR)&MenuItem14a) { ListAGame();  }
  4405.     if (object == (APTR)&MenuItem9) { Go2D(); }
  4406.     if (object == (APTR)&MenuItem10) { EditBoard(); }
  4407.     if (object == (APTR)&MenuItem11) { DoReverse(); }
  4408.     if (object == (APTR)&MenuItem4) { DoSwap();  }
  4409.     if (object == (APTR)&MenuItem5) { DoAutoPlay(); }
  4410.     if (object == (APTR)&MenuItem7) { TakeBack();  }
  4411.     if (object == (APTR)&MenuItem8) { DoThinking();  }
  4412.     if (object == (APTR)&MenuItem8a) { DoShwThnk();  }
  4413.     if (object == (APTR)&MenuItem8aa) { DoSuper(); }
  4414.     if (object == (APTR)&MenuItem8ab) { DoBookToggle(); }
  4415.     if (object == (APTR)&MenuItem8ee) {strcpy(OpEntryStr,"advan");tmpdone = 1;}
  4416.     if (object == (APTR)&MenuItem8dd) {strcpy(OpEntryStr,"interm");tmpdone = 1;}
  4417.     if (object == (APTR)&MenuItem8cc) {strcpy(OpEntryStr,"easy");tmpdone = 1;}
  4418.     if (object == (APTR)&MenuItem2) { DoTest();  }
  4419.     if (object == (APTR)&MenuItem3) { SetTime(); }
  4420.     if (object == (APTR)&MenuItem3x) { strcpy(OpEntryStr,"calc");tmpdone = 1;}
  4421.     if (object == (APTR)&MenuItem3r) { ChangeSearchDepth();}
  4422.     if (object == (APTR)&MenuItem28) 
  4423.      {
  4424. #ifndef OLDNEW
  4425.       tmpdone = 1;
  4426.       strcpy(OpEntryStr,"new");
  4427. #else
  4428.       BobVSprite->X = WIDTH-1-BOBWIDTH;
  4429.       BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  4430.       LoadBobImage(BLANKDATA);
  4431.       if (SYSTEM_BOBS)
  4432.        {
  4433.     SortGList(rpG);
  4434.     DrawGList(rpG,vP);
  4435.        }
  4436.       MakeVPort(GfxBase->ActiView,vP);
  4437.       MrgCop(GfxBase->ActiView);
  4438.       WaitTOF();
  4439.       RethinkDisplay();
  4440.       NewGame();
  4441. #endif
  4442.      }
  4443.    } // !RealThink
  4444.   else
  4445.    { // realthink
  4446.     if (object == (APTR)&MenuItem15) {MoveNow();while (RealThink) Delay(20L);DoQuit();return(1);}
  4447.     if (object == (APTR)&MenuItem6) { MoveNow();  }
  4448.     if (object == (APTR)&MenuItem8ab) { DoBookToggle(); }
  4449.     if (object == (APTR)&MenuItem8) { DoThinking();  }
  4450.     if (object == (APTR)&MenuItem8aa) { MoveNow();while (RealThink) Delay(20L);DoSuper(); }
  4451.     if (object == (APTR)&MenuItem8a) { DoShwThnk();  }
  4452.     if (object == (APTR)&MenuItem8ee) {MoveNow();while (RealThink) Delay(20L);strcpy(OpEntryStr,"advan");tmpdone = 1;}
  4453.     if (object == (APTR)&MenuItem8dd) {MoveNow();while (RealThink) Delay(20L);strcpy(OpEntryStr,"interm");tmpdone = 1;}
  4454.     if (object == (APTR)&MenuItem8cc) {MoveNow();Delay(50L);strcpy(OpEntryStr,"easy");tmpdone = 1;}
  4455.    }
  4456.   myMenuItem = (struct MenuItem *)object;
  4457.   nextcode = myMenuItem->NextSelect;
  4458.   if (nextcode != MENUNULL)
  4459.    {
  4460.     object = (APTR)ItemAddress(&MenuList1,nextcode);
  4461.    }
  4462.   } while (nextcode != MENUNULL);
  4463.  return(tmpdone);
  4464. }
  4465.  
  4466. #endif // AMIGA
  4467.  
  4468. #ifdef NEEDTODO
  4469. void DoAbout()
  4470. {
  4471.  int done=0;
  4472.  struct IntuiMessage  *message;
  4473.  struct Window  *wG3;
  4474.  ULONG class,code;
  4475.  
  4476.  if (!(wG3 = OpenWindow(&NewWindowStructure2)))
  4477.  {
  4478.   DisplayBeep(0L);
  4479.   return;
  4480.  }
  4481.  PrintIText(wG3->RPort,&IText17,0L,0L);
  4482.  do {
  4483.   WaitPort(wG3->UserPort);
  4484.   while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  4485.    {
  4486.     class = message->Class;
  4487.     code = message->Code;
  4488.     ReplyMsg((struct Message *)message);
  4489.     if (class == GADGETUP)
  4490.      done = 1;
  4491.     else if (class == VANILLAKEY)
  4492.      {
  4493.       if ((code == 13)||(code == 10))
  4494.        done = 1;
  4495.      }
  4496.    }
  4497.  } while (!done);
  4498.  CloseWindow(wG3);
  4499. }
  4500.  
  4501. #endif // nEEDTODO
  4502.  
  4503. void LoadAGame(void)
  4504. {
  4505. // strcpy(OpEntryStr,"get");
  4506.  if (thinkahead)
  4507.    {
  4508.     flag.back = true;
  4509.     while (thinkahead)
  4510.      {
  4511.       DosSleep(500L);
  4512.      }
  4513.    }
  4514.  GetGame();
  4515. }
  4516.  
  4517. void SaveAGame(void)
  4518. {
  4519. // strcpy(OpEntryStr,"save");
  4520.  if (thinkahead)
  4521.    {
  4522.     flag.back = true;
  4523.     while (thinkahead)
  4524.      {
  4525.       DosSleep(500L);
  4526.      }
  4527.    }
  4528.  SaveGame();
  4529. }
  4530.  
  4531. void ListAGame(void)
  4532. {
  4533.  if (thinkahead)
  4534.    {
  4535.     flag.back = true;
  4536.     while (thinkahead)
  4537.      {
  4538.       DosSleep(500L);
  4539.      }
  4540.    }
  4541.  ListGame(0xff);
  4542. }
  4543.  
  4544. void DoQuit(void)
  4545. {
  4546.  flag.quit = true;
  4547. }
  4548.  
  4549. void Go2D(void)
  4550. {
  4551. }
  4552.  
  4553. void DoReverse(void)
  4554. {
  4555. }
  4556.  
  4557. void DoSwap(void)
  4558. {
  4559.  doswap = 1;
  4560. }
  4561.  
  4562. void DoAutoPlay(void)
  4563. {
  4564.  hint = 0;
  4565.  //SetPointer(wG,myPointer,PTRHEIGHT,0x10L,0L,0L);
  4566.  doauto = 1;
  4567. }
  4568.  
  4569. void MoveNow(void)
  4570. {
  4571.  if ((RealThink))
  4572.   {
  4573. //   if (!flag.timeout)
  4574. //    {
  4575.      flag.back = true;
  4576.      flag.musttimeout = true;
  4577. //    }
  4578.    flag.bothsides = false;
  4579.   }
  4580. }
  4581.  
  4582. void TakeBack(void)
  4583. {
  4584. // char mvnstr[16];
  4585. // int currpiece;
  4586. // long tmp1,tmp2;
  4587.  int r,c,l;
  4588.  
  4589.  MoveMem128(amigaboard,board);
  4590.  MoveMem128(amigacolor,color);
  4591.  doundo = 1;
  4592.  hint = 0;
  4593.  if (GameCnt <= 0)
  4594.   return;
  4595.  for (r = 7; r >= 0; r--)
  4596.   {
  4597.    for (c = 0; c <= 7; c++)
  4598.     {
  4599.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  4600.       if (amigacolor[l] == neutral)
  4601.     oldboard[r][c] = ' ';
  4602.       else if (amigacolor[l] == white)
  4603.     oldboard[r][c] = qxx[amigaboard[l]];
  4604.       else
  4605.     oldboard[r][c] = pxx[amigaboard[l]];
  4606.     }
  4607.   }
  4608.  
  4609.  Undo();
  4610.  DrawAmigaBoard();
  4611. // THIS ALL NEEDS TO BE DONE FOR PM OS2!!!!
  4612. #ifdef NEEDTODO
  4613.  for (r = 7; r >= 0; r--)
  4614.     {
  4615.      for (c = 0; c <= 7; c++)
  4616.       {
  4617.     l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  4618.     if ((color[l] == neutral)&&(oldboard[r][c] != ' '))
  4619.      {
  4620.       tmp1 = r & 1L;
  4621.       tmp2 = c & 1L;
  4622.       if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  4623.        {
  4624.         BltBitMap(BlackBitMap,0,0,myBitMap,ColArray[c],
  4625.             RowArray[r],SQUAREWIDTH,SQUAREHEIGHT,
  4626.             0xc0L,0xffL,0L);
  4627.        }
  4628.       else
  4629.        {
  4630.         BltBitMap(WhiteBitMap,0,0,myBitMap,ColArray[c],
  4631.             RowArray[r],SQUAREWIDTH,SQUAREHEIGHT,
  4632.             0xc0L,0xffL,0L);
  4633.        }
  4634.      }
  4635.     else
  4636.      {
  4637.       if (color[l] == white)
  4638.        currpiece = qxx[board[l]];
  4639.       else
  4640.        currpiece = pxx[board[l]];
  4641.       if (currpiece != oldboard[r][c])
  4642.        {
  4643.         tmp1 = r & 1L;
  4644.         tmp2 = c & 1L;
  4645.         if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  4646.          {
  4647.           BltBitMap(BlackBitMap,0,0,myBitMap,ColArray[c],
  4648.                 RowArray[r],SQUAREWIDTH,SQUAREHEIGHT,
  4649.                 0xc0L,0xffL,0L);
  4650.          }
  4651.         else
  4652.          {
  4653.           BltBitMap(WhiteBitMap,0,0,myBitMap,ColArray[c],
  4654.                 RowArray[r],SQUAREWIDTH,SQUAREHEIGHT,
  4655.                 0xc0L,0xffL,0L);
  4656.          }
  4657.         LoadBobImage(currpiece);
  4658.         ClipBlitTrans (
  4659.         &(BobTransImage->ti_RP),        /* Source RastPort */
  4660.         0, 0,           /* Source LeftEdge, TopEdge */
  4661.         rpG,            /* Destination RastPort */
  4662.         ColArray[c],RowArray[r],/* Destination LeftEdge, TopEdge */
  4663.         BobTransImage->ti_IM->Width,    /* Width of Image */
  4664.         BobTransImage->ti_IM->Height,/* Height of Image */
  4665.         BobTransImage->ti_sRP); /* Shadow RastPort */
  4666.         BobVSprite->X = WIDTH-1-BOBWIDTH;
  4667.         BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  4668.         LoadBobImage(BLANKDATA);
  4669.         if (SYSTEM_BOBS)
  4670.          {
  4671.           SortGList(rpG);
  4672.           DrawGList(rpG,vP);
  4673.          }
  4674.        }
  4675.      }
  4676.       }
  4677.     }
  4678.  BobVSprite->X = WIDTH-1-BOBWIDTH;
  4679.  BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  4680.  LoadBobImage(BLANKDATA);
  4681.  if (SYSTEM_BOBS)
  4682.   {
  4683.    SortGList(rpG);
  4684.    DrawGList(rpG,vP);
  4685.   }
  4686.  if (computer != black)
  4687.   mysprintf(mvnstr,"%d: ",(GameCnt+1)>>1);
  4688.  else
  4689.   mysprintf(mvnstr,"%d: ",(GameCnt+2)>>1);
  4690.  ObtainSemaphore(&mySemaphore);
  4691.  mySetABPenDrMd(rpG,BACKGNDTEXTCOLOR,bpen,JAM1);
  4692.  RectFill(rpG,520,USERBOX,621,USERBOX+30);
  4693.  Move(rpG,520,USERBOX+6);
  4694.  mySetABPenDrMd(rpG,BLACK,bpen,JAM1);
  4695.  Text(rpG,mvnstr,strlen(mvnstr));
  4696.  ReleaseSemaphore(&mySemaphore);
  4697. #endif // NEEDTODO
  4698. }
  4699.  
  4700. void DoThinking(void)
  4701. {
  4702.  flag.easy = !flag.easy;
  4703. }
  4704.  
  4705. void DoShwThnk(void)
  4706. {
  4707.  flag.post = !flag.post;
  4708. }
  4709.  
  4710. void DoSuper(void)
  4711. {
  4712.  
  4713.  SupervisorMode = !SupervisorMode;
  4714.  if (SupervisorMode)
  4715.   { // going into supervisor mode
  4716.    oldflageasy = flag.easy;
  4717.    flag.easy = 1;
  4718.   }
  4719.  else
  4720.   { // leaving supervisor mode, restore easy flag
  4721.    flag.easy = oldflageasy;
  4722.   }
  4723. }
  4724.  
  4725. void DoBookToggle(void)
  4726. {
  4727.     Book = Book ? 0 : BOOKFAIL;
  4728.     bookflag = Book;
  4729. }
  4730.  
  4731. void DoHint(void)
  4732. {
  4733.  GiveHint();
  4734. }
  4735.  
  4736. void DoTest(void)
  4737. {
  4738.  teston = 1;
  4739. }
  4740.  
  4741. int SetAmigaDepth()
  4742. {
  4743.  int dun=6;
  4744.  //struct IntuiMessage  *message;
  4745.  //struct Window  *wG3;
  4746.  //UWORD  code;
  4747.  //ULONG  class;
  4748.  //APTR object;
  4749. // ULONG tmp[3];
  4750.  
  4751. // if (DEPTH >= 6)
  4752. //  {
  4753. //   tmp[0] = BigColorPalette[4];
  4754. //   tmp[1] = BigColorPalette[5];
  4755. //   tmp[2] = BigColorPalette[6];
  4756. //   SetRGB32(vP,1,0xaaaaaaaa,0xaaaaaaaa,0xaaaaaaaa);
  4757. //  }
  4758. // else
  4759. //  {
  4760. //   tmp[0] = myPalette[1];
  4761. //   SetRGB4(vP,1,0xa,0xa,0xa);
  4762. //  }
  4763. #ifdef NEEDTODO
  4764.  mysprintf(Gadget6SIBuff,"%d",MaxSearchDepth);
  4765.  NewWindowStructure5.FirstGadget = &Gadget6b;
  4766.  if (!(wG3 = OpenWindow(&NewWindowStructure5)))
  4767.  {
  4768.   DisplayBeep(0L);
  4769.   return(0);
  4770.  }
  4771.  Move(wG3->RPort,66,39);
  4772.  Text(wG3->RPort,"Depth",5);
  4773.  ActivateGadget(&Gadget6,wG3,NULL);
  4774.  dun = 0;
  4775.  do {
  4776.  WaitPort(wG3->UserPort);
  4777.  while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  4778.   {
  4779.    code = message->Code;
  4780.    object = message->IAddress;
  4781.    class = message->Class;
  4782.    ReplyMsg((struct Message *)message);
  4783. #ifdef SELECTIVEBB
  4784.    if (object != (APTR)&Gadget6b)
  4785.       {
  4786.        dun = 1;
  4787.       }
  4788. #else
  4789.    dun = 1;
  4790. #endif
  4791.   }
  4792.  } while (!dun);
  4793.  CloseWindow(wG3);
  4794. // if (DEPTH >= 6)
  4795. //  {
  4796. //   SetRGB32(vP,1,tmp[0],tmp[1],tmp[2]);
  4797. //  }
  4798. // else
  4799. //  {
  4800. //   SetRGB4(vP,1,((tmp[0]>>8)&0xf),((tmp[0]>>4)&0xf),((tmp[0])&0xf));
  4801. //  }
  4802.  dun = atoi(Gadget6SIBuff);
  4803.  if (dun > (MAXDEPTH-1))
  4804.   dun = MAXDEPTH -1;
  4805.  if (dun < MINDEPTH)
  4806.   dun = MINDEPTH;
  4807.  NewWindowStructure5.FirstGadget = &Gadget6;
  4808. #endif //NEEDTODO
  4809.  return(dun);
  4810. }
  4811.  
  4812. #ifdef NEEDED
  4813. void SetTime(void)
  4814. {
  4815.  int dun;
  4816.  char str[128];
  4817.  //struct IntuiMessage  *message;
  4818.  //struct Window  *wG3;
  4819.  //UWORD  code;
  4820.  //ULONG  class;
  4821.  //APTR object;
  4822. // ULONG tmp[3];
  4823.  //struct Gadget *tg;
  4824.  
  4825. // if (DEPTH >= 6)
  4826. //  {
  4827. //   tmp[0] = BigColorPalette[4];
  4828. //   tmp[1] = BigColorPalette[5];
  4829. //   tmp[2] = BigColorPalette[6];
  4830. //   SetRGB32(vP,1,0xaaaaaaaa,0xaaaaaaaa,0xaaaaaaaa);
  4831. //  }
  4832.  //else
  4833. //  {
  4834. //   tmp[0] = myPalette[1];
  4835. //   SetRGB4(vP,1,0xa,0xa,0xa);
  4836. //  }
  4837. #ifdef AMIGA
  4838.  mysprintf(Gadget6SIBuff,"%d",TCmoves);
  4839.  mysprintf(Gadget8SIBuff,"%d",(TCminutes));
  4840.  if (!(wG3 = OpenWindow(&NewWindowStructure5)))
  4841.  {
  4842.   DisplayBeep(0L);
  4843.   return;
  4844.  }
  4845.  PrintIText(wG3->RPort,&IText46,0L,0L);
  4846.  ActivateGadget(&Gadget6,wG3,NULL);
  4847.  dun = 0;
  4848.  do {
  4849.  WaitPort(wG3->UserPort);
  4850.  while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  4851.   {
  4852.    code = message->Code;
  4853.    object = message->IAddress;
  4854.    class = message->Class;
  4855.    ReplyMsg((struct Message *)message);
  4856.    if (object != (APTR)&Gadget9)
  4857.       {
  4858.        if (object == (APTR)&Gadget6)
  4859.     {
  4860.      tg = &Gadget8;
  4861.      ActivateGadget(tg,wG3,NULL);
  4862.     }
  4863.        else if (object == (APTR)&Gadget8)
  4864.     dun = 1;
  4865.       }
  4866.      else
  4867.       {
  4868.        dun = 1;
  4869.       }
  4870.   }
  4871.  } while (!dun);
  4872.  CloseWindow(wG3);
  4873. // if (DEPTH >= 6)
  4874. //  {
  4875. //   SetRGB32(vP,1,tmp[0],tmp[1],tmp[2]);
  4876. //  }
  4877. // else
  4878. //  {
  4879. //   SetRGB4(vP,1,((tmp[0]>>8)&0xf),((tmp[0]>>4)&0xf),((tmp[0])&0xf));
  4880. //  }
  4881.  strcpy(str,Gadget6SIBuff);
  4882.  strcat (str," ");
  4883.  strcat(str,Gadget8SIBuff);
  4884. #endif // AMIGA
  4885.  
  4886.  strcpy(str,"60 10"); // hard code for now
  4887.  SelectLevel(str);
  4888.  et = 0;
  4889.  dun = player;
  4890.  player = white;
  4891.  UpdateClocks();
  4892.  player = black;
  4893.  UpdateClocks();
  4894.  player = dun;
  4895. }
  4896.  
  4897. #endif
  4898.  
  4899.  
  4900. void DisplayError(str)
  4901. char *str;
  4902. {
  4903.  //RECTL myRect={0,0,639,479};
  4904.  //POINTL myPoint;
  4905.  FILE *fh;
  4906.  
  4907.   if (WinNotInited)
  4908.    {
  4909.     fh = fopen("uc_error.log","w");
  4910.     if (!fh)
  4911.      DosExit(1,0);
  4912.     fprintf(fh,"%s\n",str);
  4913.     fclose(fh);
  4914.     return;
  4915.    }
  4916.  WinMessageBox(HWND_DESKTOP,hwndClient,str,"UChess Pgm Err",0,MB_OK);
  4917. #ifdef AMIGA
  4918.  struct IntuiMessage  *message;
  4919.  struct Window  *wG3;
  4920.  char  c2;
  4921.  char  helpstr[64];
  4922.  BPTR  mywindow;
  4923.  long  temp;
  4924.  
  4925.  DisplayBeep(0L);
  4926.  if (wG)
  4927.   {
  4928.    if (!(wG3 = OpenWindow(&NewWindowStructure2)))
  4929.    {
  4930.     DisplayBeep(0L);
  4931.     return;
  4932.    }
  4933.    Move(wG3->RPort,2,25);
  4934.    Text(wG3->RPort,str,strlen(str));
  4935.    WaitPort(wG3->UserPort);
  4936.    while(message = (struct IntuiMessage *)GetMsg(wG3->UserPort))
  4937.     ReplyMsg((struct Message *)message);
  4938.    CloseWindow(wG3);
  4939.   }
  4940.  else
  4941.   { // open on wb screen
  4942.    (void)WBenchToFront();
  4943.    strcpy(helpstr,"RAW:120/10/400/100/Program Error");
  4944.    if (!(mywindow = Open(helpstr,MODE_NEWFILE)))
  4945.     {
  4946.      DisplayBeep(0L);
  4947.      return;
  4948.     }
  4949.    strcat(str,"\n\n\n");
  4950.    temp = strlen(str);
  4951.    if (Write(mywindow,str,temp) != temp)
  4952.     {
  4953.       DisplayBeep(0L);
  4954.       Close(mywindow);
  4955.       return;
  4956.     }
  4957.    strcpy(helpstr,"      Press any key to continue...");
  4958.    temp = strlen(helpstr);
  4959.    if (Write(mywindow,helpstr,temp) != temp)
  4960.     {
  4961.       DisplayBeep(0L);
  4962.       Close(mywindow);
  4963.       return;
  4964.     }
  4965.    Read(mywindow,&c2,1L);
  4966.    Close(mywindow);
  4967.   }
  4968. #endif // AMIGA
  4969. }
  4970.  
  4971. //struct Library *LhBase;
  4972. //struct LhBuffer *myLHBuffer;
  4973.  
  4974. int LoadBobData(void);
  4975. void FreeBobData(void);
  4976. int InitmyGels(void);
  4977. void ClosemyGels(void);
  4978.  
  4979.  
  4980. void LoadBobImage(piece)
  4981. long piece; /* loads bob with pieces image */
  4982. {
  4983.  // For OS2_PM this routine needs to just set the correct
  4984.  // indices so that the current bob becomes the one we want
  4985.  if (piece == BLANKDATA)
  4986.   {
  4987.    lastpiece = piece;
  4988.    return; // for OS2 this should not matter
  4989.   }
  4990.  if (piece >= 'a') // white piece
  4991.   {
  4992.    CurrBobColor = white;
  4993.   }
  4994.  else
  4995.   {
  4996.    CurrBobColor = black;
  4997.   }
  4998.  switch (tolower(piece))
  4999.   {
  5000.    case 'p' :
  5001.         CurrBobIndex = PAWNBOB;
  5002.         break;
  5003.    case 'n' :
  5004.         CurrBobIndex = KNIGHTBOB;
  5005.         break;
  5006.    case 'b' :
  5007.         CurrBobIndex = BISHOPBOB;
  5008.         break;
  5009.    case 'r' :
  5010.         CurrBobIndex = ROOKBOB;
  5011.         break;
  5012.    case 'q' :
  5013.         CurrBobIndex = QUEENBOB;
  5014.         break;
  5015.    case 'k' :
  5016.         CurrBobIndex = KINGBOB;
  5017.         break;
  5018.    default :
  5019.     ShowMessage("Piece Err");
  5020.     DosBeep(1380,1000);
  5021.     DosSleep(1500);
  5022.     DosExit(1,0);
  5023.   }
  5024.  lastpiece = piece;
  5025. #ifdef AMIGA
  5026.  int i;
  5027.  UWORD *temp;
  5028.  LONG image_data;
  5029.  WORD planes = RASSIZE (BOBWIDTH, BOBHEIGHT);
  5030.  
  5031.  if (piece == BLANKDATA)
  5032.   {
  5033.    temp = BlankImageData;
  5034.   }
  5035.  else if (piece >= 'a') /* white pieces */
  5036.   {
  5037.    if (piece == 'p')
  5038.     temp = WhiteImageData[0];
  5039.    else if (piece == 'n')
  5040.     temp = WhiteImageData[1];
  5041.    else if (piece == 'b')
  5042.     temp = WhiteImageData[2];
  5043.    else if (piece == 'r')
  5044.     temp = WhiteImageData[3];
  5045.    else if (piece == 'q')
  5046.     temp = WhiteImageData[4];
  5047.    else if (piece == 'k')
  5048.     temp = WhiteImageData[5];
  5049.   }
  5050.  else /* black pieces */
  5051.   {
  5052.    if (piece == 'P')
  5053.     temp = BlackImageData[0];
  5054.    else if (piece == 'N')
  5055.     temp = BlackImageData[1];
  5056.    else if (piece == 'B')
  5057.     temp = BlackImageData[2];
  5058.    else if (piece == 'R')
  5059.     temp = BlackImageData[3];
  5060.    else if (piece == 'Q')
  5061.     temp = BlackImageData[4];
  5062.    else if (piece == 'K')
  5063.     temp = BlackImageData[5];
  5064.   }
  5065.  BobImage.ImageData = BobVSprite->ImageData = temp;
  5066.  image_data = (LONG) BobImage.ImageData;
  5067.  /* Map the image data to planes */
  5068.  for (i = 0L; i < BOBDEPTH; ++i)
  5069.   BobTransImage->ti_BM.Planes[i] = (PLANEPTR) (image_data + i * planes);
  5070.  temp += (BOBHEIGHT*BOBDEPTH*BOBWIDINW);
  5071.  TheBob->ImageShadow = BobVSprite->CollMask = temp;
  5072.  temp += ((BOBHEIGHT+2)*BOBWIDINW);
  5073.  BobVSprite->BorderLine = temp;
  5074.  BobImage.ImageData = BobVSprite->ImageData;
  5075.  BobTransImage->ti_sBM->Planes[0] = (char *)TheBob->ImageShadow;
  5076.  for (i = 1; i < BOBDEPTH; i++)
  5077.    BobTransImage->ti_sBM->Planes[i] = BobTransImage->ti_sBM->Planes[0];
  5078.  lastpiece = piece;
  5079. #endif // NEEDTODO
  5080. }
  5081.  
  5082. int LoadBobData()
  5083. {
  5084.  int i,j;
  5085.  unsigned char *imagebuffer;
  5086.  APIRET rc;
  5087.  
  5088.  rc = DosAllocMem((PPVOID)&imagebuffer,BOBWIDTH*BOBHEIGHT,
  5089.  PAG_READ|PAG_WRITE|PAG_COMMIT);
  5090.  if (rc)
  5091.   exit(0);
  5092.  for(i=0;i<2;i++)
  5093.   {
  5094.    for(j=0;j<6;j++)
  5095.     {
  5096.      if (!LoadBMPImage(&PieceFileNames[i][j][0],imagebuffer,BOBWIDTH,BOBHEIGHT))
  5097.       {
  5098.        DisplayError("Cannot get Piece Images");
  5099.        DosExit(1,0);
  5100.       }
  5101.      TheBob[i][j] = CreateBob(BOBWIDTH,BOBHEIGHT,8,imagebuffer,BigColorPalette);
  5102.       if (TheBob[i][j] == NULL)
  5103.        {
  5104.     DisplayError("Cannot Create BOB");
  5105.     DosExit(1,0);
  5106.        }
  5107.      TheBob[i][j]->XPos = 0;
  5108.      TheBob[i][j]->YPos = 0;
  5109.     }
  5110.   }
  5111.  DosFreeMem(imagebuffer);
  5112.  return(1);
  5113. #ifdef NEEDTODO
  5114.  USHORT  len;
  5115.  long  templong;
  5116.  BPTR fh;
  5117.  UBYTE *srcbuf;
  5118.  int i;
  5119.  
  5120.  if (!(srcbuf = AllocMem(BOBBLOCKSIZE,0L)))
  5121.   {
  5122.    return(0);
  5123.   }
  5124.  if (DEPTH < 6)
  5125.   {
  5126.    if (!(fh = Open("uchess:Pieces.lzw",MODE_OLDFILE)))
  5127.     {
  5128.     return(0);
  5129.    }
  5130.   }
  5131.  else if (FasterDisplay)
  5132.   {
  5133.    if (!(fh = Open("uchess:Pieces64.lzw",MODE_OLDFILE)))
  5134.     {
  5135.     return(0);
  5136.    }
  5137.   }
  5138.  else
  5139.   {
  5140.    if (!(fh = Open("uchess:Pieces256.lzw",MODE_OLDFILE)))
  5141.     {
  5142.     return(0);
  5143.    }
  5144.   }
  5145.  if (!(LhBase = OpenLibrary(LH_NAME,LH_VERSION)))
  5146.   {
  5147.    DisplayError("Cannot open lh.lib\n");
  5148.    return(0);
  5149.   }
  5150.  if (!(myLHBuffer = CreateBuffer(TRUE))) /* small buffer for only decomp*/
  5151.   {
  5152.    DisplayError("Cannot Create Buffer\n");
  5153.    CloseLibrary(LhBase);
  5154.    return(0);
  5155.   }
  5156.  for(i=0;i<6;i++)
  5157.   {
  5158.    if (Read(fh,(char *)&len,2L) != 2L)
  5159.     {
  5160.      Close(fh);
  5161.      return(0);
  5162.     }
  5163.    templong = len;
  5164.    if (Read(fh,srcbuf,templong) != templong)
  5165.     {
  5166.      Close(fh);
  5167.      return(0);
  5168.     }
  5169.    if (!(WhiteImageData[i] = 
  5170.     (UWORD *)AllocMem(BOBBLOCKSIZE,MEMF_CHIP|MEMF_CLEAR)))
  5171.     {
  5172.      return(0);
  5173.     }
  5174.    LoadBobImage(piecechar[i]);
  5175.    myLHBuffer->lh_Src = (APTR)srcbuf;
  5176.    myLHBuffer->lh_Dst = (APTR)BobVSprite->ImageData;
  5177.    myLHBuffer->lh_SrcSize = templong;
  5178.    myLHBuffer->lh_DstSize = BOBBLOCKSIZE;
  5179.    LhDecode(myLHBuffer);
  5180.    InitMasks(BobVSprite);
  5181.    if (Read(fh,(char *)&len,2L) != 2L)
  5182.     {
  5183.      Close(fh);
  5184.      return(0);
  5185.     }
  5186.    templong = len;
  5187.    if (Read(fh,srcbuf,templong) != templong)
  5188.     {
  5189.      Close(fh);
  5190.      return(0);
  5191.     }
  5192.    if (!(BlackImageData[i] = 
  5193.     (UWORD *)AllocMem(BOBBLOCKSIZE,MEMF_CHIP|MEMF_CLEAR)))
  5194.     {
  5195.      return(0);
  5196.     }
  5197.    LoadBobImage(piecechar[i+6]);
  5198.    myLHBuffer->lh_Src = (APTR)srcbuf;
  5199.    myLHBuffer->lh_Dst = (APTR)BobVSprite->ImageData;
  5200.    myLHBuffer->lh_SrcSize = templong;
  5201.    myLHBuffer->lh_DstSize = BOBBLOCKSIZE;
  5202.    LhDecode(myLHBuffer);
  5203.    InitMasks(BobVSprite);
  5204.   }
  5205.  Close(fh);
  5206.  FreeMem(srcbuf,BOBBLOCKSIZE);
  5207.  DeleteBuffer(myLHBuffer);
  5208.  CloseLibrary(LhBase);
  5209.  LoadBobImage(BLANKDATA);
  5210. #endif // NEEDTODO
  5211. }
  5212.  
  5213. void FreeBobData()
  5214. {
  5215. #ifdef NEEDTODO
  5216.  int i;
  5217.  
  5218.  for(i=0;i<6;i++)
  5219.   {
  5220.    FreeMem((char *)WhiteImageData[i],BOBBLOCKSIZE);
  5221.    FreeMem((char *)BlackImageData[i],BOBBLOCKSIZE);
  5222.   }
  5223.  FreeMem((char *)BlankImageData,BOBBLOCKSIZE);
  5224. #endif // NEEDTODO
  5225. }
  5226.  
  5227. int InitmyGels()
  5228. {
  5229.  if (!InitGels())
  5230.   {
  5231.     DisplayError("Cannot Init Gels!");
  5232.     return(0);
  5233.   }
  5234.  if (!LoadBobData())
  5235.   {
  5236.    DisplayError("Cannot Load/Create Bobs");
  5237.    return(0);
  5238.   }
  5239.  return(1);
  5240. #ifdef NEEDTODO
  5241.  
  5242. #ifdef EXTRAINIT
  5243.  struct BitMap  tmpBitMap;
  5244. #endif
  5245.  int i;
  5246.  UWORD *temp;
  5247.  
  5248.  if (!(SpriteHead = (struct VSprite *)
  5249.        AllocMem(sizeof(struct VSprite),MEMF_PUBLIC|MEMF_CLEAR)))
  5250.   {
  5251.    return(0);
  5252.   }
  5253.  if (!(SpriteTail = (struct VSprite *)
  5254.        AllocMem(sizeof(struct VSprite),MEMF_PUBLIC|MEMF_CLEAR)))
  5255.   {
  5256.    return(0);
  5257.   }
  5258.  if (!(BobVSprite = (struct VSprite *)
  5259.        AllocMem(sizeof(struct VSprite),MEMF_PUBLIC|MEMF_CLEAR)))
  5260.   {
  5261.    return(0);
  5262.   }
  5263.  if (!(TheBob = (struct Bob *)
  5264.        AllocMem(sizeof(struct Bob),MEMF_PUBLIC|MEMF_CLEAR)))
  5265.   {
  5266.    return(0);
  5267.   }
  5268.  if (!(myGelsInfo = (struct GelsInfo *)
  5269.        AllocMem(sizeof(struct GelsInfo),MEMF_PUBLIC|MEMF_CLEAR)))
  5270.   {
  5271.    return(0);
  5272.   }
  5273.  if (!(myGelsInfo->nextLine = (WORD *)AllocMem(sizeof(WORD)*32,
  5274.     MEMF_PUBLIC|MEMF_CLEAR)))
  5275.   {
  5276.    return(0);
  5277.   }
  5278.  if (!(myGelsInfo->lastColor = (WORD **)AllocMem(sizeof(WORD)*32,
  5279.     MEMF_PUBLIC|MEMF_CLEAR)))
  5280.   {
  5281.    return(0);
  5282.   }
  5283.  if (!(myGelsInfo->collHandler = (struct collTable *)
  5284.     AllocMem(sizeof(struct collTable),MEMF_PUBLIC|MEMF_CLEAR)))
  5285.   {
  5286.    return(0);
  5287.   }
  5288.  if (!(TheBob->SaveBuffer = (WORD *)
  5289.     AllocMem(sizeof(SHORT)*BOBWIDINW*BOBHEIGHT*BOBDEPTH,MEMF_CHIP|MEMF_CLEAR)))
  5290.   {
  5291.    return(0);
  5292.   }
  5293.  if (!(temp = BobVSprite->ImageData = 
  5294.     (UWORD *)AllocMem(BOBBLOCKSIZE,MEMF_CHIP|MEMF_CLEAR)))
  5295.     {
  5296.      return(0);
  5297.     }
  5298.  BlankImageData = temp;
  5299.  temp += (BOBHEIGHT*BOBDEPTH*BOBWIDINW);
  5300.  TheBob->ImageShadow = BobVSprite->CollMask = temp;
  5301.  temp += ((BOBHEIGHT+2)*BOBWIDINW);
  5302.  BobVSprite->BorderLine = temp;
  5303. #ifdef DBL_BUFF
  5304.  if (!(TheBob->DBuffer = (struct DBufPacket *)AllocMem
  5305.     (sizeof(struct DBufPacket),MEMF_CHIP|MEMF_CLEAR)))
  5306.     {
  5307.      return(0);
  5308.     }
  5309.  if (!(TheBob->DBuffer->BufBuffer = 
  5310.        (WORD *)AllocRaster(BOBWIDTH,BOBHEIGHT*BOBDEPTH)))
  5311.   {
  5312.      return(0);
  5313.   }
  5314. #endif
  5315.  
  5316.  BOBPLANEPICK = 1;
  5317.  for(i=0;i<DEPTH;i++)
  5318.   {
  5319.    BOBPLANEPICK *= 2;
  5320.   }
  5321.  BOBPLANEPICK--;
  5322.  BobImage.LeftEdge = 0;
  5323.  BobImage.TopEdge = 0;
  5324.  BobImage.Width = BOBWIDTH;
  5325.  BobImage.Height = BOBHEIGHT;
  5326.  BobImage.Depth = BOBDEPTH; 
  5327.  BobImage.ImageData = BobVSprite->ImageData;
  5328.  BobImage.PlanePick = BOBPLANEPICK;
  5329.  BobImage.PlaneOnOff = BOBPLANEONOFF;
  5330.  BobImage.NextImage = NULL;
  5331.  if (!(BobTransImage = AllocTransImage(&BobImage)))
  5332.   {
  5333.    return(0);
  5334.   }
  5335.  
  5336.  if (SYSTEM_BOBS)
  5337.   {
  5338.    myGelsInfo->leftmost = COLA;
  5339.    myGelsInfo->rightmost = COLH+BOBWIDTH+1;
  5340.    myGelsInfo->topmost = ROW8;
  5341.    myGelsInfo->bottommost = ROW1+BOBHEIGHT+1; 
  5342.    rpG->GelsInfo = myGelsInfo;
  5343.    InitGels((struct VSprite *)SpriteHead,SpriteTail,myGelsInfo);
  5344.    WaitTOF();
  5345.   }
  5346.  BobVSprite->Flags = SAVEBACK | OVERLAY;
  5347.  BobVSprite->X = WIDTH-1-BOBWIDTH;
  5348.  BobVSprite->Y = HEIGHT-1-BOBHEIGHT;  
  5349.  BobVSprite->Height = BOBHEIGHT;
  5350.  BobVSprite->Width = BOBWIDINW;
  5351.  BobVSprite->Depth = BOBDEPTH;
  5352.  BobVSprite->MeMask = BOBMEMASK;
  5353.  BobVSprite->HitMask = BOBHITMASK;
  5354.  BobVSprite->VSBob = TheBob;
  5355.  BobVSprite->PlanePick = BOBPLANEPICK;
  5356.  BobVSprite->PlaneOnOff = BOBPLANEONOFF;  
  5357.  BobVSprite->VUserExt = 0;
  5358.  TheBob->BobVSprite = BobVSprite;
  5359.  
  5360.  if (!LoadBobData())
  5361.   {
  5362.    DisplayError("Cannot Load BOB data\n");
  5363.    //CloseWindow(wG);
  5364.    CloseScreen(sC);
  5365.   }
  5366.  
  5367.  
  5368.  InitMasks(BobVSprite);
  5369. #endif // NEEDTODO
  5370. }
  5371.  
  5372. void ClosemyGels()
  5373. {
  5374.  int i,j;
  5375.  
  5376.   CloseGels();
  5377.   for(i=0;i<2;i++)
  5378.    for(j=0;j<6;j++)
  5379.      FreeBob(TheBob[i][j]);
  5380.  
  5381. #ifdef NEEDTODO
  5382.      FreeBobData();
  5383.    
  5384. #ifdef DBL_BUFF
  5385.    FreeRaster((PLANEPTR)TheBob->DBuffer->BufBuffer,BOBWIDTH,BOBHEIGHT*BOBDEPTH);
  5386.    FreeMem((char *)TheBob->DBuffer,sizeof(struct DBufPacket));
  5387. #endif
  5388.    FreeTransImage(BobTransImage);
  5389.    FreeMem((char *)TheBob->SaveBuffer,
  5390.      sizeof(SHORT)*BOBWIDINW*BOBHEIGHT*BOBDEPTH);
  5391.    FreeMem((char *)myGelsInfo->collHandler,sizeof(struct collTable));
  5392.    FreeMem((char *)myGelsInfo->lastColor,sizeof(WORD)*32);
  5393.    FreeMem((char *)myGelsInfo->nextLine,sizeof(WORD)*32);
  5394.    FreeMem((char *)myGelsInfo,sizeof(struct GelsInfo));
  5395.    FreeMem((char *)TheBob,sizeof(struct Bob));
  5396.    FreeMem((char *)BobVSprite,sizeof(struct VSprite));
  5397.    FreeMem((char *)SpriteTail,sizeof(struct VSprite));
  5398.    FreeMem((char *)SpriteHead,sizeof(struct VSprite));
  5399. #endif // NEEDTODO
  5400. }
  5401.  
  5402. #ifdef AMIGA
  5403. struct TransImage *
  5404. AllocTransImage (struct Image * im)
  5405. {
  5406.     if (im)
  5407.     {
  5408.     LONG msize = sizeof (struct TransImage);
  5409.     struct TransImage *ti;
  5410.  
  5411.     if (ti = (struct TransImage *) AllocMem (msize, MEMF_CLEAR))
  5412.     {
  5413.         LONG image_data = (LONG) im->ImageData;
  5414.         UWORD depth = im->Depth;
  5415.         UWORD width = im->Width;
  5416.         UWORD height = im->Height;
  5417.         WORD planes = RASSIZE (width, height);
  5418.         WORD i;
  5419.  
  5420.         /* Remember the image */
  5421.         ti->ti_IM = im;
  5422.  
  5423.         /* Initialize the Image bitmap */
  5424.         InitBitMap (&ti->ti_BM, depth, width, height);
  5425.  
  5426.         /* Map the image data to planes */
  5427.         for (i = 0L; i < depth; ++i)
  5428.         ti->ti_BM.Planes[i] = (PLANEPTR) (image_data + i * planes);
  5429.  
  5430.         /* Initialize the Image rastport */
  5431.         InitRastPort (&ti->ti_RP);
  5432.         ti->ti_RP.BitMap = &ti->ti_BM;
  5433.  
  5434.         if (ti->ti_sBM = AllocShadowBM (depth, width, height))
  5435.         {
  5436.         if (ti->ti_sRP = AllocShadowRP (ti->ti_sBM))
  5437.         {
  5438.             return (ti);
  5439.         }
  5440.         FreeShadowBM (ti->ti_sBM);
  5441.         }
  5442.         FreeMem ((APTR) ti, msize);
  5443.     }
  5444.     }
  5445.  
  5446.     return (NULL);
  5447. }
  5448.  
  5449. VOID
  5450. FreeTransImage (struct TransImage * ti)
  5451. {
  5452.  
  5453.     if (ti)
  5454.     {
  5455.     LONG msize = sizeof (struct TransImage);
  5456.  
  5457.     /* Free the shadow RastPort */
  5458.     FreeShadowRP (ti->ti_sRP);
  5459.  
  5460.     /* Free the shadow BitMap */
  5461.     FreeShadowBM (ti->ti_sBM);
  5462.  
  5463.     /* Free the temporary buffer */
  5464.     FreeMem ((APTR) ti, msize);
  5465.     }
  5466. }
  5467.  
  5468. VOID
  5469. FreeShadowBM (struct BitMap *sbm)
  5470. {
  5471.  
  5472.     if (sbm)
  5473.     {
  5474.  
  5475. #ifdef ALLOCFORREAL
  5476.     LONG msize;
  5477.  
  5478.     msize = RASSIZE (8 * (sbm->BytesPerRow), sbm->Rows);
  5479.  
  5480.  
  5481.  
  5482.     if (sbm->Planes[0])
  5483.     {
  5484.         FreeMem ((APTR)sbm->Planes[0], msize);
  5485.     }
  5486. #else
  5487.  
  5488.     FreeMem ((APTR)sbm, sizeof (struct BitMap));
  5489. #endif
  5490.     }
  5491. }
  5492.  
  5493. VOID
  5494. FreeShadowRP (struct RastPort *srp)
  5495. {
  5496.  
  5497.     if (srp)
  5498.     {
  5499.     FreeMem (srp, sizeof (struct RastPort));
  5500.     }
  5501. }
  5502.  
  5503. struct BitMap *
  5504. AllocShadowBM (UWORD depth, UWORD width, UWORD height)
  5505. {
  5506.     LONG msize = sizeof (struct BitMap);
  5507.     struct BitMap *bm;
  5508.     WORD i;
  5509.  
  5510.     /* Allocate a bitmap */
  5511.     if (bm = (struct BitMap *) AllocMem (msize, MEMF_CLEAR))
  5512.     {
  5513. #ifdef ALLOCFORREAL
  5514.     LONG rsize = RASSIZE (width, height);
  5515. #endif
  5516.  
  5517.     /* Initialize the bitmap */
  5518.     InitBitMap (bm, depth, width, height);
  5519.  
  5520. #ifdef ALLOCFORREAL
  5521.     /* Allocate one plane */
  5522.     if (bm->Planes[0] = (PLANEPTR) AllocMem (rsize, MEMF_CHIP | MEMF_CLEAR))
  5523.     {
  5524.         /* All planes point to the first plane */
  5525.         for (i = 1; i < depth; i++)
  5526.         bm->Planes[i] = bm->Planes[0];
  5527.  
  5528.         return (bm);
  5529.     }
  5530.  
  5531.     FreeMem ((APTR) bm, msize);
  5532. #else
  5533.      bm->Planes[0] = (char *)TheBob->ImageShadow;
  5534.      for (i = 1; i < depth; i++)
  5535.     bm->Planes[i] = bm->Planes[0];
  5536.      return (bm);
  5537. #endif
  5538.     }
  5539.     return (NULL);
  5540. }
  5541.  
  5542. struct RastPort *
  5543. AllocShadowRP (struct BitMap *bm)
  5544. {
  5545.     LONG msize = sizeof (struct RastPort);
  5546.     struct RastPort *rp;
  5547.  
  5548.     /* Allocate a RastPort */
  5549.     if (rp = (struct RastPort *) AllocMem (msize, MEMF_CHIP))
  5550.     {
  5551.     /* Initialize the new RastPort */
  5552.     InitRastPort (rp);
  5553.  
  5554.     /* Point the RastPort's BitMap... */
  5555.     rp->BitMap = bm;
  5556.     }
  5557.  
  5558.     return (rp);
  5559. }
  5560.  
  5561.  
  5562. VOID
  5563. ClipBlitTrans (
  5564.     struct RastPort *rp,        /* source RastPort */
  5565.     WORD sx, WORD sy,           /* source top-left edge */
  5566.     struct RastPort *drp,       /* destination RastPort */
  5567.     WORD dx, WORD dy,           /* destination top-left edge */
  5568.     WORD width, WORD height,    /* width & height of image to blit */
  5569.     struct RastPort *Srp)       /* shadow RastPort */
  5570. {
  5571.  
  5572.     /* make the shadow */
  5573.     ClipBlit (rp, sx, sy, Srp, 0, 0, width, height, 0xe0);
  5574.     ClipBlit (Srp, 0, 0, drp, dx, dy, width, height, 0x20); /* blit cookie cutter outline */
  5575.     ClipBlit (rp, sx, sy, drp, dx, dy, width, height, 0xe0); /* now fill in image */
  5576. }
  5577.  
  5578. #endif // AMIGA
  5579.  
  5580. int myLoadFullBitMap(int);
  5581.  
  5582. int myLoadFullBitMap(first)
  5583. int first;
  5584. {
  5585. // InitGels MUST be called FIRST!!!
  5586.  APIRET rc;
  5587.  BITMAPINFO2 *bmi2;
  5588.  POINTL myPoint;
  5589.  int i;
  5590.  POINTL apts[4];
  5591.  char fname[64];
  5592.  
  5593.   if (!LoadFullBitmap(hwClientPS,"CHESS.BMP",TRUE,BigColorPalette))
  5594.      {
  5595.       DisplayError("Cannot load full bitmap from disk");
  5596.       DosExit(1,0);
  5597.      }
  5598.  strcpy(fname,UC_Title);
  5599.  rc = DosRequestMutexSem(DrawSemaphore,5000);
  5600.  if (rc)
  5601.   return(0);
  5602.  myPoint.x = 511;
  5603.  myPoint.y = COMPUTERBOX+10;
  5604.  GpiCharStringAt(hwClientPS, &myPoint, strlen(fname),
  5605.          (PSZ)fname);
  5606.  myPoint.x = 511;
  5607.  myPoint.y = USERBOX+10;
  5608.  strcpy(fname,"Puny Human:");
  5609.  GpiCharStringAt(hwClientPS, &myPoint, strlen(fname),
  5610.          (PSZ)fname);
  5611.  DosReleaseMutexSem(DrawSemaphore);
  5612.  if (!first)
  5613.   return(1);
  5614. // Now I need to create the Black and WhiteBitMaps and blit the image into them
  5615. // use SQUAREWIDTH and SQUAREHEIGHT
  5616.    bmi2 = calloc(sizeof(BITMAPINFOHEADER2)+(sizeof(RGB2)*256),1);
  5617.    if (bmi2 == NULL)
  5618.     {
  5619.      return(0);
  5620.     }
  5621.    for(i=0;i<256;i++)
  5622.     {  // each rgb2 entry in the palette is 4 bytes long
  5623.       bmi2->argbColor[i].bRed = BigColorPalette[i*4];
  5624.       bmi2->argbColor[i].bGreen = BigColorPalette[i*4+1];
  5625.       bmi2->argbColor[i].bBlue = BigColorPalette[i*4+2];
  5626.     }
  5627.    bmi2->cbFix = sizeof(BITMAPINFOHEADER2);
  5628.    bmi2->cx = SQUAREWIDTH;
  5629.    bmi2->cy = SQUAREHEIGHT;
  5630.    bmi2->cPlanes = 1;
  5631.    bmi2->cBitCount = 8;
  5632.    bmi2->cbImage = (ROUNDEDSQUAREWIDTH*SQUAREHEIGHT);
  5633.    bmi2->cxResolution = cxClient;
  5634.    bmi2->cyResolution = cyClient;
  5635.    bmi2->cclrUsed = 256;
  5636.    bmi2->cclrImportant = 256;
  5637.    bmi2->ulColorEncoding = BCE_RGB;
  5638.    WhiteBitMap = GpiCreateBitmap(hwClientPS,(PBITMAPINFOHEADER2)bmi2,
  5639.             0L,NULL,bmi2);
  5640.    if (WhiteBitMap == NULL)
  5641.     return(0);
  5642.    BlackBitMap = GpiCreateBitmap(hwClientPS,(PBITMAPINFOHEADER2)bmi2,
  5643.             0L,NULL,bmi2);
  5644.    if (BlackBitMap == NULL)
  5645.     return(0);
  5646.    bmi2->cx = 160;
  5647.    bmi2->cy = 160;
  5648.    bmi2->cbImage = (160*160);
  5649.    textBitMap = GpiCreateBitmap(hwClientPS,(PBITMAPINFOHEADER2)bmi2,
  5650.             0L,NULL,bmi2);
  5651.    if (textBitMap == NULL)
  5652.     return(0);
  5653.    apts[2].x = COLB; // src left bottom
  5654.    apts[2].y = (ROW5) - SQUAREHEIGHT; // src left bottom
  5655.    apts[3].x = apts[2].x + SQUAREWIDTH - 1; // src rt top
  5656.    apts[3].y = apts[2].y + SQUAREHEIGHT - 1; // src rt top
  5657.    apts[0].x = 0; // tgt left bottom
  5658.    apts[0].y = 0; // tgt left bottom
  5659.    apts[1].x = SQUAREWIDTH - 1; // tgt rt top
  5660.    apts[1].y = SQUAREHEIGHT - 1; // tgt rt top
  5661.    GpiSetBitmap(hpsMemory,WhiteBitMap);
  5662.    GpiBitBlt(hpsMemory,hwClientPS,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  5663.  
  5664.    apts[2].x = COLA; // src left bottom
  5665.    apts[2].y = (ROW5) - SQUAREHEIGHT; // src left bottom
  5666.    apts[3].x = apts[2].x + SQUAREWIDTH - 1; // src rt top
  5667.    apts[3].y = apts[2].y + SQUAREHEIGHT - 1; // src rt top
  5668.    apts[0].x = 0; // tgt left bottom
  5669.    apts[0].y = 0; // tgt left bottom
  5670.    apts[1].x = SQUAREWIDTH - 1; // tgt rt top
  5671.    apts[1].y = SQUAREHEIGHT - 1; // tgt rt top
  5672.    GpiSetBitmap(hpsMemory,BlackBitMap);
  5673.    GpiBitBlt(hpsMemory,hwClientPS,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  5674.  
  5675.    DosFreeMem(bmi2);
  5676. // now copy in image data from the full board
  5677. // use COLB ROW5 for white, COLA, ROW5 for BLACK
  5678.  
  5679.  return(1);
  5680.  
  5681. #ifdef NEEDTODO
  5682.  
  5683.  unsigned long i;
  5684.  char errstr[40];
  5685.  char fname[80];
  5686.  long count;
  5687.  USHORT len;
  5688.  char *srcbuf;
  5689.  ULONG tt;
  5690.  BPTR fh;
  5691.  BPTR  fp;
  5692.  struct BitMap *tmpBitMap;
  5693.  struct BitMap *PlanarBitMap;
  5694.  struct FileInfoBlock  *myFileInfoBlock;
  5695. //LONG tmp1,tmp2;
  5696. //char tstr[40];
  5697.  
  5698.  if (DEPTH < 6)
  5699.   strcpy(fname,"uchess:Chess.lzw");
  5700.  else if (FasterDisplay)
  5701.   strcpy(fname,"uchess:Chess64.lzw");
  5702.  else
  5703.   strcpy(fname,"uchess:Chess256.lzw");
  5704.  
  5705.  
  5706.   if (!(myFileInfoBlock = 
  5707.      (struct FileInfoBlock *)AllocMem(sizeof(struct FileInfoBlock),MEMF_PUBLIC)))
  5708.    {
  5709.      DisplayError("No Mem now for finfo block");
  5710.      return(0);
  5711.    }
  5712.   if (!(fp = Lock(fname,ACCESS_READ)))
  5713.    {
  5714.      FreeMem((char *)myFileInfoBlock,sizeof(struct FileInfoBlock));
  5715.      return(0);
  5716.    }
  5717.   if (!(Examine(fp,myFileInfoBlock)))
  5718.    {
  5719.      DisplayError("Cannot get finfo");
  5720.      UnLock(fp);
  5721.      FreeMem((char *)myFileInfoBlock,sizeof(struct FileInfoBlock));
  5722.      return(0);
  5723.    }
  5724.   UnLock(fp);
  5725.   count = myFileInfoBlock->fib_Size - 2L;
  5726.   FreeMem((char *)myFileInfoBlock,sizeof(struct FileInfoBlock));
  5727.  
  5728.  
  5729. /* before unpacking the bitmap, save the titlebar area in a tmp bitmap */
  5730.  if (!RTG)
  5731.   {
  5732.    if (!(tmpBitMap = tAllocBitMap(WIDTH,MENUBARHT,DEPTH,BMF_CLEAR,myBitMap)))
  5733.     {
  5734.      return(0);
  5735.     }
  5736.    BltBitMap(myBitMap,0,0,tmpBitMap,0L,0L,WIDTH,MENUBARHT,0xc0L,0xffL,0L);
  5737.   }
  5738.  else
  5739.   {
  5740.    if (!(tmpBitMap = tAllocBitMap(WIDTH,MENUBARHT,DEPTH,BMF_CLEAR,0L)))
  5741.     {
  5742.      return(0);
  5743.     }
  5744.    BltBitMap(sC->RastPort.BitMap,0,0,tmpBitMap,0L,0L,WIDTH,MENUBARHT,0xc0L,0xffL,0L);
  5745.   }
  5746.  if (!(srcbuf = AllocMem(count,0L)))
  5747.   {
  5748.    sprintf(errstr,"Cannot allocate lharc %d byte buffer",count);
  5749.    DisplayError(errstr);
  5750.    return(0);
  5751.   }
  5752.  if (!(LhBase = OpenLibrary(LH_NAME,LH_VERSION)))
  5753.   {
  5754.    DisplayError("Cannot open lh.lib");
  5755.    return(0);
  5756.   }
  5757.  if (!(myLHBuffer = CreateBuffer(TRUE))) /* small buffer for only decomp*/
  5758.   {
  5759.    DisplayError("Cannot Create Buffer");
  5760.    CloseLibrary(LhBase);
  5761.    return(0);
  5762.   }
  5763.  
  5764.    if (!(fh = Open(fname,MODE_OLDFILE)))
  5765.     {
  5766.      DisplayError("Cannot open chess file");
  5767.      return(0);
  5768.     }
  5769.    if (Read(fh,(char *)&len,2L) != 2L)
  5770.     {
  5771.      DisplayError("Cannot read chess file");
  5772.      Close(fh);
  5773.      return(0);
  5774.     }
  5775.    if (Read(fh,srcbuf,count) != count)
  5776.     {
  5777.      DisplayError("Cannot read chess file2");
  5778.      Close(fh);
  5779.      return(0);
  5780.     }
  5781.    Close(fh);
  5782.    if ((RTG)&&(!OrigmyBitMap))
  5783.     { // allocate the BitMap to unpack to
  5784.      if (!(OrigmyBitMap = myBitMap = sAllocBitMap(WIDTH,HEIGHT,DEPTH,BMF_INTERLEAVED|BMF_CLEAR|BMF_DISPLAYABLE,
  5785.                0L)))
  5786.       {
  5787.        return(0);
  5788.       }
  5789.     }
  5790.  
  5791.    myLHBuffer->lh_Src = (APTR)srcbuf;
  5792.    myLHBuffer->lh_Dst = (APTR)myBitMap->Planes[0];
  5793.    myLHBuffer->lh_SrcSize = count;
  5794.    tt = WIDTH/8L;
  5795.    tt = tt*HEIGHT;
  5796.    tt = tt*DEPTH;
  5797.    myLHBuffer->lh_DstSize = tt;
  5798.    LhDecode(myLHBuffer);
  5799.  
  5800.  FreeMem(srcbuf,count); 
  5801.  DeleteBuffer(myLHBuffer);
  5802.  CloseLibrary(LhBase);
  5803.  BltBitMap(tmpBitMap,0,0,myBitMap,0L,0L,WIDTH,MENUBARHT,0xc0L,0xffL,0L);
  5804.  tFreeBitMap(tmpBitMap);
  5805.  if (RTG)
  5806.   {
  5807.      if (!(PlanarBitMap = tAllocBitMap(WIDTH,HEIGHT/10,DEPTH,BMF_CLEAR,0L)))
  5808.       {
  5809.        return(0);
  5810.       }
  5811.      for(i=0;i<10;i++)
  5812.       {
  5813.        BltBitMap(myBitMap,0,(i*(HEIGHT/10)),PlanarBitMap,0,0,WIDTH,(HEIGHT/10),0xc0L,0xffL,0L);
  5814.        BltBitMap(PlanarBitMap,0,0,sC->RastPort.BitMap,0,(i*(HEIGHT/10)),WIDTH,(HEIGHT/10),0xc0L,0xffL,0L);
  5815.       }
  5816.      // then free the non-interleaved bitmap...
  5817.      tFreeBitMap(PlanarBitMap);
  5818.   }
  5819.  
  5820. #ifdef _M68040
  5821.  strcpy(fname,"UChess Pro:");
  5822. #else
  5823. #ifndef TINYCHESS
  5824.  strcpy(fname,"UChess Jr.:");
  5825. #else
  5826.  strcpy(fname,"UChess Tiny:");
  5827. #endif
  5828. #endif
  5829.  ObtainSemaphore(&mySemaphore);
  5830.  mySetABPenDrMd(rpG,BLACK,bpen,JAM1);
  5831.  Move(rpG,511,COMPUTERBOX-10);
  5832.  Text(rpG,fname,strlen(fname));
  5833.  Move(rpG,511,USERBOX-10);
  5834.  strcpy(fname,"Puny Human:");
  5835.  Text(rpG,fname,strlen(fname));
  5836.  ReleaseSemaphore(&mySemaphore);
  5837.  if (!RTG)
  5838.   {
  5839.    BltBitMap(myBitMap,COLB,ROW5,WhiteBitMap,0L,0L,SQUAREWIDTH,SQUAREHEIGHT,0xc0L,0xffL,0L);
  5840.    BltBitMap(myBitMap,COLA,ROW5,BlackBitMap,0L,0L,SQUAREWIDTH,SQUAREHEIGHT,0xc0L,0xffL,0L);
  5841.   }
  5842.  else
  5843.   {
  5844.    BltBitMap(sC->RastPort.BitMap,COLB,ROW5,WhiteBitMap,0L,0L,SQUAREWIDTH,SQUAREHEIGHT,0xc0L,0xffL,0L);
  5845.    BltBitMap(sC->RastPort.BitMap,COLA,ROW5,BlackBitMap,0L,0L,SQUAREWIDTH,SQUAREHEIGHT,0xc0L,0xffL,0L);
  5846.   }
  5847.  RethinkDisplay();
  5848.  if (RTG)
  5849.   {
  5850.    myBitMap = sC->RastPort.BitMap;
  5851.    sFreeBitMap(OrigmyBitMap);
  5852.    OrigmyBitMap = 0L;
  5853.   }
  5854.  if (!textBitMap)
  5855.   {
  5856.    if (!(textBitMap = tAllocBitMap(160,160,DEPTH,BMF_CLEAR,myBitMap)))
  5857.     {
  5858.      DisplayBeep(0L);
  5859.      Delay(10L);
  5860.      DisplayBeep(0L);
  5861.      Delay(15L);
  5862.      DisplayBeep(0L);
  5863.      Delay(25L);
  5864.      DisplayBeep(0L);
  5865.      return(0);
  5866.     }
  5867.   }
  5868. #endif
  5869. }
  5870.  
  5871.  
  5872. #ifdef AMIGA
  5873. int mAllocBitMap(void);
  5874.  
  5875. int mAllocBitMap()
  5876. {
  5877.  
  5878.  if (!RTG)
  5879.   {
  5880.    if (!(OrigmyBitMap = myBitMap = tAllocBitMap(WIDTH,HEIGHT,DEPTH,BMF_INTERLEAVED|BMF_CLEAR|BMF_DISPLAYABLE,
  5881.             0L)))
  5882.     {
  5883.      return(0);
  5884.     }
  5885.    tempras_bitplane = AllocMem(WIDTH*HEIGHT/8,MEMF_CLEAR|MEMF_CHIP);
  5886.    if (!tempras_bitplane)
  5887.     {
  5888.      return(0);
  5889.     }
  5890.   }
  5891.  else
  5892.   {
  5893.    if (!(OrigmyBitMap = myBitMap = sAllocBitMap(WIDTH,HEIGHT,DEPTH,BMF_INTERLEAVED|BMF_CLEAR|BMF_DISPLAYABLE,
  5894.             0L)))
  5895.     {
  5896.      return(0);
  5897.     }
  5898.   }
  5899.  if (RTG)
  5900.   {
  5901.    if ((RTG_ModeID == VGAPRODUCT_KEY)||
  5902.        (RTG_ModeID == (HIRES|LACE|DEFAULT_MONITOR_ID))||
  5903.        (RTG_ModeID == (HIRES|LACE|PAL_MONITOR_ID))|| 
  5904.        (RTG_ModeID == (HIRES|LACE|NTSC_MONITOR_ID)) || 
  5905.        (RTG_ModeID == (HIRES|LACE|DBLPAL_MONITOR_ID))|| 
  5906.        (RTG_ModeID == (HIRES|LACE|DBLNTSC_MONITOR_ID)) || 
  5907.        (RTG_ModeID == (LORES_KEY|LACE|DEFAULT_MONITOR_ID))|| 
  5908.        (RTG_ModeID == (LORES_KEY|LACE|PAL_MONITOR_ID))|| 
  5909.        (RTG_ModeID == (LORES_KEY|LACE|NTSC_MONITOR_ID)) || 
  5910.        (RTG_ModeID == (LORES_KEY|LACE|DBLPAL_MONITOR_ID))|| 
  5911.        (RTG_ModeID == (LORES_KEY|LACE|DBLNTSC_MONITOR_ID)) || 
  5912.        (RTG_ModeID == (HIRES|DEFAULT_MONITOR_ID))||
  5913.        (RTG_ModeID == (HIRES|PAL_MONITOR_ID))|| 
  5914.        (RTG_ModeID == (HIRES|NTSC_MONITOR_ID)) || 
  5915.        (RTG_ModeID == (HIRES|DBLNTSC_MONITOR_ID)) || 
  5916.        (RTG_ModeID == (HIRES|DBLPAL_MONITOR_ID)) || 
  5917.        (RTG_ModeID == (LORES_KEY|DEFAULT_MONITOR_ID))|| 
  5918.        (RTG_ModeID == (LORES_KEY|PAL_MONITOR_ID))|| 
  5919.        (RTG_ModeID == (LORES_KEY|NTSC_MONITOR_ID)) || 
  5920.        (RTG_ModeID == (LORES_KEY|DBLPAL_MONITOR_ID)) || 
  5921.        (RTG_ModeID == (LORES_KEY|DBLNTSC_MONITOR_ID)) || 
  5922.        (RTG_ModeID == (SUPER72_MONITOR_ID | SUPERLACE_KEY)))
  5923.      {
  5924.       myTagList[3].ti_Tag = SA_Interleaved;
  5925.       myTagList[3].ti_Data = TRUE;
  5926.      }
  5927.    NewScreenStructure.Type = CUSTOMSCREEN | NS_EXTENDED; // no custom bitmap
  5928.    NewScreenStructure.CustomBitMap = 0L;
  5929.    if (!(WhiteBitMap = tAllocBitMap(ROUNDEDSQUAREWIDTH,SQUAREHEIGHT,DEPTH,
  5930.             BMF_CLEAR,0L)))
  5931.     {
  5932.      return(0);
  5933.     }
  5934.    if (!(BlackBitMap = tAllocBitMap(ROUNDEDSQUAREWIDTH,SQUAREHEIGHT,DEPTH,
  5935.               BMF_CLEAR,0L)))
  5936.     {
  5937.      return(0);
  5938.     }
  5939.   }
  5940.  else
  5941.   {
  5942.    NewScreenStructure.CustomBitMap = myBitMap;
  5943.    if (!(WhiteBitMap = tAllocBitMap(ROUNDEDSQUAREWIDTH,SQUAREHEIGHT,DEPTH,
  5944.             BMF_CLEAR,myBitMap)))
  5945.     {
  5946.      return(0);
  5947.     }
  5948.    if (!(BlackBitMap = tAllocBitMap(ROUNDEDSQUAREWIDTH,SQUAREHEIGHT,DEPTH,
  5949.               BMF_CLEAR,myBitMap)))
  5950.     {
  5951.      return(0);
  5952.     }
  5953.   }
  5954.  return(1);
  5955. }
  5956.  
  5957. void FreeTheBitMap(void);
  5958.  
  5959. void FreeTheBitMap()
  5960. {
  5961.  tFreeBitMap(BlackBitMap);
  5962.  tFreeBitMap(WhiteBitMap);
  5963.  if (OrigmyBitMap)
  5964.   if (!RTG)
  5965.    tFreeBitMap(OrigmyBitMap);
  5966.   else
  5967.    sFreeBitMap(OrigmyBitMap);
  5968.  if (textBitMap)
  5969.   tFreeBitMap(textBitMap);
  5970. }
  5971.  
  5972. #endif // AMIGA
  5973.  
  5974. void PM_ShutDown(void);
  5975. int PM_Startup(void);
  5976.  
  5977.  
  5978. int AmigaStarted = 0;
  5979.  
  5980. int PM_Startup()
  5981. {
  5982.  APIRET rc;
  5983.  
  5984. // Semaphore for screen is DrawSemaphore, I do not need another one
  5985. //        rc = DosCreateMutexSem("\\SEM32\\UChessMut",&mySemaphore,0L,0L);
  5986. //        if (rc)
  5987. //         {
  5988. //          DisplayError("Cannot open mutex sem\n");
  5989. //          return(0);
  5990. //         }
  5991.     rc = DosCreateThread(&myTID,(PFNTHREAD)InputThread,0L,0L,16384L);
  5992.     if (rc)
  5993.      {
  5994.       DisplayError("Cannot start thread\n");
  5995.       return(0);
  5996.      }
  5997.     DosSleep(250L);
  5998.     while (InputThreadState < 1)
  5999.      DosSleep(200L);
  6000.     if (InputThreadState != 1)
  6001.      {
  6002.       DisplayError("Trbl with child process");
  6003.       return(0);
  6004.      }
  6005.     Global_Message = 0L;
  6006.     flag.post = true;
  6007.     RowArray[0] = ROW1;
  6008.     RowArray[1] = ROW2;
  6009.     RowArray[2] = ROW3;
  6010.     RowArray[3] = ROW4;
  6011.     RowArray[4] = ROW5;
  6012.     RowArray[5] = ROW6;
  6013.     RowArray[6] = ROW7;
  6014.     RowArray[7] = ROW8;
  6015.     USERBOX=480-168;
  6016.     SYSTEMBOX = USERBOX - 112;
  6017.     SYSBOXLEN = 102;
  6018.     AmigaStarted = 1;
  6019.  
  6020. #ifdef AMIGA
  6021.     if (!(myTextFont = OpenFont(&TOPAZ80)))
  6022.      {
  6023.       return(0);
  6024.      }
  6025.     if (gfxversion < 39)
  6026.      DEPTH = 4;
  6027.     else if (RTG)
  6028.      { // use screen requestor to ask guy what he wants
  6029.       if (!GetScreenMode())
  6030.        {
  6031.          return(0);
  6032.        }
  6033.       DEPTH = 8; // only support 8 bit RTG screens
  6034.       myTagList[0].ti_Data = RTG_ModeID;
  6035.       myTagList[2].ti_Tag = SA_AutoScroll;
  6036.       myTagList[2].ti_Data = TRUE;
  6037.      }
  6038.     else
  6039.      {
  6040.       if (v15Khz)
  6041.        {
  6042.         myTagList[0].ti_Data = HIRES|LACE|DEFAULT_MONITOR_ID;
  6043.         myTagList[2].ti_Data = TRUE;
  6044.         myTagList[2].ti_Tag = SA_AutoScroll;
  6045.        }
  6046.       if (Super72)
  6047.        myTagList[0].ti_Data = (SUPER72_MONITOR_ID | SUPERLACE_KEY);
  6048.       NewScreenStructure2.Type |= NS_EXTENDED;
  6049.       NewScreenStructure2.Extension = myTagList;
  6050.       NewScreenStructure2.Height = 480;
  6051.       NewScreenStructure2.Depth = 8; 
  6052.       NewScreenStructure2.BlockPen = 251;
  6053.       if ((sC = OpenScreen((struct NewScreen *)&NewScreenStructure2)))
  6054.        {
  6055.         CloseScreen(sC);
  6056.         DEPTH = 8;
  6057.        }
  6058.       else
  6059.        {
  6060.         myTagList[0].ti_Data = HIRES|LACE|DEFAULT_MONITOR_ID;
  6061.         myTagList[2].ti_Tag = SA_AutoScroll;
  6062.         myTagList[2].ti_Data = TRUE;
  6063.         if ((sC = OpenScreen((struct NewScreen *)&NewScreenStructure2)))
  6064.          {
  6065.           CloseScreen(sC);
  6066.           DEPTH = 8;
  6067.          }
  6068.         else
  6069.          {
  6070.           myTagList[2].ti_Tag = 0;
  6071.           myTagList[2].ti_Data = 0;
  6072.           myTagList[0].ti_Data = HIRES|LACE;
  6073.           DEPTH = 4;
  6074.          }
  6075.        }
  6076.      }
  6077.     if (DEPTH == 8)
  6078.      {
  6079.       BLACK = 2;
  6080.       if (FasterDisplay)
  6081.        {
  6082.         DEPTH = 6;
  6083.         MBLOCKPEN = 0;//61;
  6084.         BACKGNDTEXTCOLOR = 57;
  6085.         BACKPEN =61;
  6086.        }
  6087.       else
  6088.        {
  6089.         MBLOCKPEN = 0;//251;
  6090.         BACKGNDTEXTCOLOR = 0xe0;
  6091.         BACKPEN = 251;
  6092.        }
  6093.       TIMEYCOORD1 = 120;
  6094.       TIMEYCOORD2 = 230;
  6095.       USERBOX=168;
  6096.       SYSTEMBOX = USERBOX + 112;
  6097.       SYSBOXLEN = 102;
  6098.       COMPUTERBOX=60;
  6099.       BOBDEPTH = DEPTH;
  6100.       ROW8 = 24;
  6101.       BOBHEIGHT = 55;
  6102.       HEIGHT = 480;
  6103.       NewScreenStructure.Type |= NS_EXTENDED;
  6104.       NewScreenStructure.Extension = myTagList;
  6105.       NewScreenStructure.Height = HEIGHT;
  6106.       NewScreenStructure.Depth = DEPTH;
  6107.       NewScreenStructure.BlockPen = BACKPEN;
  6108.       NewWindowStructure1.Height = HEIGHT;
  6109.       NewWindowStructure1.MaxHeight = HEIGHT;
  6110.       NewWindowStructure1.BlockPen = BACKPEN;
  6111.       NewWindowStructure2.BlockPen = BACKPEN;
  6112.       NewWindowStructure5.BlockPen = BACKPEN;
  6113.       NewWindowStructure6.BlockPen = BACKPEN;
  6114.       pNewWindowStructure1.BlockPen = BACKPEN;
  6115.       Border6.FrontPen = Border7.FrontPen = 
  6116.       Border9.FrontPen = Border1.FrontPen = BACKPEN;
  6117.       aBorder1.FrontPen = aBorder2.FrontPen = 
  6118.       aBorder3.FrontPen = aBorder4.FrontPen = 
  6119.       pBorder1.FrontPen = pBorder2.FrontPen = 
  6120.       pBorder3.FrontPen = pBorder4.FrontPen = BACKPEN;
  6121.       pIText1.FrontPen = 
  6122.       pIText2.FrontPen = 
  6123.       pIText2a.FrontPen = 
  6124.       pIText3.FrontPen = 
  6125.       pIText4.FrontPen = 
  6126.       pIText5.FrontPen = 
  6127.       pIText6.FrontPen = 
  6128.       pIText7.FrontPen = 
  6129.       pIText8a.FrontPen = 
  6130.       IText93.FrontPen = 
  6131.       IText47.FrontPen = 
  6132.       IText46.FrontPen = 
  6133.       IText37.FrontPen = 
  6134.       IText1.FrontPen = 
  6135.       IText1r.FrontPen = 
  6136.       IText2.FrontPen = 
  6137.       IText2x.FrontPen = 
  6138.       IText3.FrontPen = 
  6139.       IText4.FrontPen = 
  6140.       IText4aa.FrontPen = 
  6141.       IText4ab.FrontPen = 
  6142.       IText4cc.FrontPen = 
  6143.       IText4dd.FrontPen = 
  6144.       IText4ee.FrontPen = 
  6145.       IText4a.FrontPen = 
  6146.       IText5.FrontPen = 
  6147.       IText6.FrontPen = 
  6148.       IText7.FrontPen = 
  6149.       IText8.FrontPen = 
  6150.       IText9.FrontPen = 
  6151.       IText10.FrontPen = 
  6152.       IText11.FrontPen = 
  6153.       IText12.FrontPen = 
  6154.       IText13.FrontPen = 
  6155.       IText13a.FrontPen = 
  6156.       IText14.FrontPen = 
  6157.       IText15.FrontPen = 
  6158.       IText16.FrontPen = 
  6159.       IText22.FrontPen = 
  6160.       IText21.FrontPen = 
  6161.       IText20.FrontPen = 
  6162.       IText19.FrontPen = 
  6163.       IText18.FrontPen = 
  6164.       aIText1.FrontPen = 
  6165.       aIText2.FrontPen = 
  6166.       aIText3.FrontPen = 
  6167.       aIText4.FrontPen = 
  6168.       aIText5.FrontPen = 
  6169.       IText17.FrontPen = BACKPEN;
  6170.  
  6171.       IText37.BackPen = 
  6172.       IText1.BackPen = 
  6173.       IText1r.BackPen = 
  6174.       IText2.BackPen = 
  6175.       IText2x.BackPen = 
  6176.       IText3.BackPen = 
  6177.       IText4.BackPen = 
  6178.       IText4aa.BackPen = 
  6179.       IText4ab.BackPen = 
  6180.       IText4cc.BackPen = 
  6181.       IText4dd.BackPen = 
  6182.       IText4ee.BackPen = 
  6183.       IText4a.BackPen = 
  6184.       IText5.BackPen = 
  6185.       IText6.BackPen = 
  6186.       IText7.BackPen = 
  6187.       IText8.BackPen = 
  6188.       IText9.BackPen = 
  6189.       IText10.BackPen = 
  6190.       IText11.BackPen = 
  6191.       IText12.BackPen = 
  6192.       IText13.BackPen = 
  6193.       IText13a.BackPen = 
  6194.       IText14.BackPen = 
  6195.       IText15.BackPen = BACKPEN;
  6196.  
  6197.       IText37.FrontPen = 
  6198.       IText1.FrontPen = 
  6199.       IText1r.FrontPen = 
  6200.       IText2.FrontPen = 
  6201.       IText2x.FrontPen = 
  6202.       IText3.FrontPen = 
  6203.       IText4.FrontPen = 
  6204.       IText4aa.FrontPen = 
  6205.       IText4ab.FrontPen = 
  6206.       IText4cc.FrontPen = 
  6207.       IText4dd.FrontPen = 
  6208.       IText4ee.FrontPen = 
  6209.       IText4a.FrontPen = 
  6210.       IText5.FrontPen = 
  6211.       IText6.FrontPen = 
  6212.       IText7.FrontPen = 
  6213.       IText8.FrontPen = 
  6214.       IText9.FrontPen = 
  6215.       IText10.FrontPen = 
  6216.       IText11.FrontPen = 
  6217.       IText12.FrontPen = 
  6218.       IText13.FrontPen = 
  6219.       IText13a.FrontPen = 
  6220.       IText14.FrontPen = 
  6221.       IText15.FrontPen = MBLOCKPEN;
  6222.      }
  6223.     if (!(mAllocBitMap()))
  6224.      {
  6225.       CloseFont(myTextFont);
  6226.       return(0);
  6227.      }
  6228.     if (!(sC = OpenScreen((struct NewScreen *)&NewScreenStructure)))
  6229.      {
  6230.       if (RTG)
  6231.        {
  6232.         myTagList[2].ti_Tag = 0; // kill autoscroll and try again
  6233.         myTagList[2].ti_Data = 0;
  6234.         if (!(sC = OpenScreen((struct NewScreen *)&NewScreenStructure)))
  6235.          {
  6236.           //FreeTheBitMap();
  6237.           CloseFont(myTextFont);
  6238.           DisplayError("256 color screen in this mode not avail");
  6239.           return(0);
  6240.          }
  6241.        }
  6242.       else // not rtg
  6243.        {
  6244.         FreeTheBitMap();
  6245.         CloseFont(myTextFont);
  6246.         DisplayError("FATAL:Screen mode not avail");
  6247.         return(0);
  6248.        }
  6249.      }
  6250.     vP = &sC->ViewPort;
  6251.     if (DEPTH >= 6)
  6252.      {
  6253.       if (!FasterDisplay)
  6254.        LoadRGB32(&(sC->ViewPort),BigColorPalette);
  6255.       else
  6256.        LoadRGB32(&(sC->ViewPort),Big64Palette);
  6257.      }
  6258.     else
  6259.      LoadRGB4(&(sC->ViewPort),myPalette,16);
  6260.     if (gfxversion > 38)
  6261.      {
  6262.       NewWindowStructure1.Flags |= WFLG_NEWLOOKMENUS;
  6263.      }
  6264.     NewWindowStructure1.Screen = sC;
  6265.     pNewWindowStructure1.Screen = sC;
  6266.     NewWindowStructure2.Screen = sC;
  6267.     NewWindowStructure5.Screen = sC;
  6268.     NewWindowStructure6.Screen = sC;
  6269.     InitSemaphore(&mySemaphore);
  6270.     if (!(InputReply = CreatePort(0L,0L)))
  6271.      {
  6272.       DisplayError("Cannot create reply");
  6273.       return(0);
  6274.      }
  6275.     if (!CreateNewProc(ProcTagList))
  6276.      {
  6277.       DisplayError("Cannot create new proc");
  6278.       return(0);
  6279.      }
  6280.     Delay(15L);
  6281.     while (InputThreadState < 1)
  6282.      Delay(10L);
  6283.     if (InputThreadState != 1)
  6284.      {
  6285.       DisplayError("Trbl with child process");
  6286.       return(0);
  6287.      }
  6288.     Forbid();
  6289.     if (!(InThreadPort = FindPort(InputPortName)))
  6290.       {
  6291.        Permit();
  6292.        DisplayError("Cannot find input port");
  6293.        return(0);
  6294.       }
  6295.     Permit();
  6296.     Global_Message.myData = 0L;
  6297.     Global_Message.MainMsg.mn_Length = sizeof(Global_Message);
  6298.     Global_Message.MainMsg.mn_Node.ln_Type = NT_MESSAGE;
  6299.     Global_Message.MainMsg.mn_ReplyPort = InputReply;
  6300.     rpG = wG->RPort;        /* get a rastport pointer for the window */
  6301.     if (!RTG)
  6302.      {
  6303.       InitTmpRas(&temp_rast,tempras_bitplane,WIDTH*HEIGHT/8);
  6304.       rpG->TmpRas = &temp_rast;
  6305.      }
  6306.     SetFont(rpG,myTextFont);
  6307.     Delay(25L); /* crashes from wb if I do not do this! */
  6308.     SetDrMd(rpG,JAM1);
  6309.     if (!InitmyGels())
  6310.      {
  6311.       CloseScreen(sC);
  6312.       CloseFont(myTextFont);
  6313. //          FreeTheBitMap();
  6314.       return(0);
  6315.      }
  6316.     else
  6317.      {
  6318.       if (!myLoadFullBitMap(1)) // first time
  6319.        {
  6320.         //CloseWindow(wG);
  6321.         CloseScreen(sC);
  6322.         return(0);
  6323.        }
  6324. // finish GEL init and add the bob
  6325.       if (SYSTEM_BOBS)
  6326.        AddBob(TheBob,rpG);
  6327.       WaitTOF();
  6328.       MakeScreen(sC);
  6329.       RethinkDisplay();
  6330.       if (SYSTEM_BOBS)
  6331.         {
  6332.          SortGList(rpG);
  6333.          DrawGList(rpG,vP);
  6334.          MakeVPort(GfxBase->ActiView,vP);
  6335.          MrgCop(GfxBase->ActiView);
  6336.          WaitTOF();
  6337.          SortGList(rpG);
  6338.          DrawGList(rpG,vP);
  6339.          MakeVPort(GfxBase->ActiView,vP);
  6340.          MrgCop(GfxBase->ActiView);
  6341.          WaitTOF();
  6342.          SortGList(rpG);
  6343.          DrawGList(rpG,vP);
  6344.         }
  6345.       MakeVPort(GfxBase->ActiView,vP);
  6346.       MrgCop(GfxBase->ActiView);
  6347.       WaitTOF();
  6348.       MakeScreen(sC);
  6349.       RethinkDisplay();
  6350.       WaitTOF();
  6351.       AmigaStarted = 1;
  6352.       if (gfxversion > 38)
  6353.        bpen = GetBPen(rpG);
  6354.       return(1);
  6355.      }
  6356. #else // FOR NOW THIS IS MY TEMP INIT PROC
  6357.     return(1);
  6358. #endif // NEEDTODO
  6359. }
  6360.  
  6361.  
  6362.  
  6363. void PM_ShutDown()
  6364. {
  6365. #ifdef NEEDTODO
  6366.  int tmpargcnt;
  6367.  
  6368. // need to wake up the input thread so it can exit 1st
  6369.     Global_Message.myData = 0xff;
  6370.     Forbid();
  6371.     PutMsg(InThreadPort,(struct Message *)&Global_Message);
  6372.     Permit();
  6373.     tmpargcnt = 0;
  6374.     Delay(25L);
  6375.     while ((InputThreadState < 2)&&(tmpargcnt < 10))
  6376.      {
  6377.       tmpargcnt++;
  6378.       Delay(25L);
  6379.      }
  6380.     ClosemyGels();
  6381.     CloseScreen(sC);
  6382.     if (!RTG)
  6383.      {
  6384.       if (tempras_bitplane)
  6385.        FreeMem(tempras_bitplane,WIDTH*HEIGHT/8);
  6386.      }
  6387.     FreeTheBitMap();
  6388.     CloseFont(myTextFont);
  6389.     if (InputReply)
  6390.      DeletePort(InputReply);
  6391. #endif // NEEDTODO
  6392. }
  6393.  
  6394. void ShowMessage(str)
  6395. char *str;
  6396. {
  6397.  char tstr[2][16];
  6398.  POINTL myPoint;
  6399.  int i,j;
  6400.  RECTL myRect;
  6401.  int ycoord,nums;
  6402.  APIRET rc;
  6403.  
  6404.  i = strlen(str);
  6405.  if (str[i-1] == '\n')
  6406.   {
  6407.    str[i-1] = 0;
  6408.   }
  6409. // just keep 4 lines of text around I guess, in a buffer 12 chars max
  6410.  if (i > 24)
  6411.   str[24] = 0;
  6412.  if (i > 12)
  6413.   {
  6414.    nums = 2;
  6415.    strcpy(tstr[0],&str[12]);
  6416.    str[12] = 0;
  6417.    strcpy(tstr[1],str);
  6418.   }
  6419.  else
  6420.   {
  6421.    strcpy(tstr[0],str);
  6422.    nums = 1;
  6423.   }
  6424.  for(j=0;j<nums;j++)
  6425.   {
  6426.    for(i=7;i>0;i--)
  6427.     strcpy(MsgBuf[i],MsgBuf[i-1]);
  6428.    strcpy(MsgBuf[0],tstr[j]);
  6429.    MsgBuf[0][12] = 0;
  6430.   }
  6431.  if (WinNotInited)
  6432.   return;
  6433.  ycoord = SYSTEMBOX-2; // was - 6
  6434. /* scroll down 3 lines (36 pixels) */
  6435.  myRect.xLeft = 510;
  6436.  myRect.yBottom = SYSTEMBOX-SYSBOXLEN - 9;
  6437.  myRect.xRight = 621;
  6438.  myRect.yTop = SYSTEMBOX+14;
  6439.  myPoint.x = 510;
  6440.  rc = DosRequestMutexSem(DrawSemaphore,2000);
  6441.  if (rc)
  6442.   return;
  6443.  
  6444. // STILL NEED TO DO THESE BLTBITMAPS FOR OS/2!!! TMP!!!
  6445.  
  6446. // now fill the area at top of system box with backgnd color
  6447.  WinFillRect(hwClientPS,&myRect,BACKGNDTEXTCOLOR);
  6448.  for(i=0;i<8;i++)
  6449.   {
  6450.    if (MsgBuf[i][0])
  6451.     {
  6452.      myPoint.y = ycoord;
  6453.      GpiCharStringAt(hwClientPS,&myPoint,strlen(MsgBuf[i]),(PSZ)MsgBuf[i]);
  6454.      ycoord -= 15;
  6455.     }
  6456.   }
  6457.  DosReleaseMutexSem(DrawSemaphore);
  6458. }
  6459.  
  6460.  
  6461. void DisplayComputerMove(str)
  6462. char *str;
  6463. {
  6464.  char tstr[16];
  6465.  int done = 0;
  6466.  int i=0;
  6467.  int j,k,lim;
  6468.  RECTL rc;
  6469.  POINTL myPoint;
  6470.  APIRET rcd;
  6471.  int ycoord;
  6472.  
  6473.  if (WinNotInited)
  6474.   return;
  6475.  if (str[strlen(str)-1] == '\n')
  6476.   {
  6477.    str[strlen(str)-1] = 0;
  6478.   }
  6479.  rc.xLeft = 520;
  6480.  rc.yBottom = COMPUTERBOX-36;
  6481.  rc.xRight = 621;
  6482.  rc.yTop = COMPUTERBOX+4;
  6483.  rcd = DosRequestMutexSem(DrawSemaphore,2000);
  6484.  if (rcd)
  6485.   return;
  6486.  WinFillRect(hwClientPS,&rc,BACKGNDTEXTCOLOR);
  6487.  //RectFill(rpG,520,COMPUTERBOX,621,COMPUTERBOX+30);
  6488.  
  6489.  myPoint.x = 520;
  6490.  ycoord = COMPUTERBOX-10;
  6491.  do {
  6492.  j = i;
  6493.  if (strlen(str) <= 12)
  6494.   {
  6495.    done = 1;
  6496.    strcpy(tstr,str);
  6497.   }
  6498.  else
  6499.   {
  6500.    lim = j + 12;
  6501.    if (lim >= strlen(str))
  6502.     {
  6503.      done = 1;
  6504.      lim = strlen(str);
  6505.     }
  6506.    for(k=0;i<lim;i++,k++)
  6507.     tstr[k] = str[i];
  6508.    tstr[k] = 0;
  6509.   }
  6510.  myPoint.y = ycoord;
  6511.  GpiCharStringAt(hwClientPS, &myPoint, strlen(tstr),
  6512.                (PSZ)tstr);
  6513.  //Move(rpG,520,ycoord);
  6514.  //Text(rpG,tstr,strlen(tstr));
  6515.  ycoord -= 12;
  6516.  } while (!done);
  6517.  DosReleaseMutexSem(DrawSemaphore);
  6518. }
  6519.  
  6520. #ifdef NEEDTODO
  6521. void DoLegalMove(str)
  6522. char *str;
  6523. {
  6524.  long mpiece;
  6525.  char piece;
  6526.  int r,c,l;
  6527.  int ecol,erow,scol,srow,side,tmp1,tmp2,incrx,incry,i;
  6528.  
  6529.    if (SYSTEM_BOBS)
  6530.     {
  6531.      SortGList(rpG);
  6532.      DrawGList(rpG,vP);
  6533.     }
  6534.    MakeVPort(GfxBase->ActiView,vP);
  6535.    MrgCop(GfxBase->ActiView);
  6536.    if (SYSTEM_BOBS)
  6537.     {
  6538.      RemIBob(TheBob,rpG,vP);
  6539.      SortGList(rpG);
  6540.      DrawGList(rpG,vP);
  6541.     }
  6542.    MakeVPort(GfxBase->ActiView,vP);
  6543.    MrgCop(GfxBase->ActiView);
  6544.    r = str[3] - '1';
  6545.    c = str[2] - 'a';
  6546.    tmp1 = r & 1;
  6547.    tmp2 = c & 1;
  6548.    if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  6549.     {
  6550.      BltBitMap(BlackBitMap,0,0,myBitMap,ColArray[c],
  6551.             RowArray[r],SQUAREWIDTH,SQUAREHEIGHT,
  6552.             0xc0L,0xffL,0L);
  6553.     }
  6554.    else
  6555.     {
  6556.      BltBitMap(WhiteBitMap,0,0,myBitMap,ColArray[c],
  6557.             RowArray[r],SQUAREWIDTH,SQUAREHEIGHT,
  6558.             0xc0L,0xffL,0L);
  6559.     }
  6560.    MakeVPort(GfxBase->ActiView,vP);
  6561.    MrgCop(GfxBase->ActiView);
  6562.    RethinkDisplay();
  6563.    WaitTOF();
  6564.    l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  6565.    if ((color[l] == neutral))
  6566.     {
  6567.      ExitChess();
  6568.      return;
  6569.     }
  6570.    else if (color[l] == white)
  6571.     piece = qxx[board[l]]; /* white are lower case pieces */
  6572.    else
  6573.     piece = pxx[board[l]]; /* black are upper case pieces */
  6574.    if ((DestRow == 7)||(!DestRow))
  6575.     { /* possible promotion */
  6576.       mpiece = piece;
  6577.       LoadBobImage(mpiece);
  6578.     }
  6579.    ClipBlitTrans (
  6580.         &(BobTransImage->ti_RP),        /* Source RastPort */
  6581.         0, 0,           /* Source LeftEdge, TopEdge */
  6582.         rpG,            /* Destination RastPort */
  6583.         ColArray[DestCol],RowArray[DestRow],/* Destination LeftEdge, TopEdge */
  6584.         BobTransImage->ti_IM->Width,    /* Width of Image */
  6585.         BobTransImage->ti_IM->Height,/* Height of Image */
  6586.         BobTransImage->ti_sRP); /* Shadow RastPort */
  6587.    BobVSprite->X = WIDTH-1-BOBWIDTH;
  6588.    BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  6589.    LoadBobImage(BLANKDATA);
  6590.    if (SYSTEM_BOBS)
  6591.     {
  6592.      AddBob(TheBob,rpG);
  6593.      SortGList(rpG);
  6594.      DrawGList(rpG,vP);
  6595.     }
  6596.    MakeVPort(GfxBase->ActiView,vP);
  6597.    MrgCop(GfxBase->ActiView);
  6598.    if (piece >= 'a')
  6599.     {
  6600.      mpiece = 'r';
  6601.      srow = 0;
  6602.      erow = 0;
  6603.      side = white;
  6604.      if (str[2] == 'g') /* king side white */
  6605.       {
  6606.        scol = 7;
  6607.        ecol = 5;
  6608.       }
  6609.      else
  6610.       {
  6611.        ecol = 3;
  6612.        scol = 0;
  6613.       }
  6614.     }
  6615.    else
  6616.     {
  6617.      mpiece = 'R';
  6618.      srow = 7;
  6619.      erow = 7;
  6620.      side = black;
  6621.      if (str[2] == 'g') /* king side black */
  6622.       {
  6623.        scol = 7;
  6624.        ecol = 5;
  6625.       }
  6626.      else
  6627.       {
  6628.        ecol = 3;
  6629.        scol = 0;
  6630.       }
  6631.     }
  6632.    if (Castled[side])
  6633.     {
  6634.      Castled[side] = 0;
  6635.      tmp1 = srow & 1;
  6636.      tmp2 = scol & 1;
  6637.      if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  6638.       {
  6639.        BltBitMap(BlackBitMap,0,0,myBitMap,ColArray[scol],
  6640.             RowArray[srow],SQUAREWIDTH,SQUAREHEIGHT,
  6641.             0xc0L,0xffL,0L);
  6642.       }
  6643.      else
  6644.       {
  6645.        BltBitMap(WhiteBitMap,0,0,myBitMap,ColArray[scol],
  6646.             RowArray[srow],SQUAREWIDTH,SQUAREHEIGHT,
  6647.             0xc0L,0xffL,0L);
  6648.       }
  6649.      BobVSprite->X = ColArray[scol];
  6650.      BobVSprite->Y = RowArray[srow];
  6651.      if (SYSTEM_BOBS)
  6652.       {
  6653.        SortGList(rpG);
  6654.        DrawGList(rpG,vP);
  6655.       }
  6656.      MakeVPort(GfxBase->ActiView,vP);
  6657.      MrgCop(GfxBase->ActiView);
  6658.      LoadBobImage(mpiece);
  6659.      if (SYSTEM_BOBS)
  6660.       {
  6661.        SortGList(rpG);
  6662.        DrawGList(rpG,vP);
  6663.       }
  6664.      MakeVPort(GfxBase->ActiView,vP);
  6665.      MrgCop(GfxBase->ActiView);
  6666.      incry = (RowArray[erow] - RowArray[srow])/8;
  6667.      incrx = (ColArray[ecol] - ColArray[scol])/8;
  6668.      for(i=0;i<8;i++)
  6669.       {
  6670.        BobVSprite->X += incrx;
  6671.        BobVSprite->Y += incry;
  6672.        if (SYSTEM_BOBS)
  6673.     {
  6674.      SortGList(rpG);
  6675.      DrawGList(rpG,vP);
  6676.     }
  6677.        MakeVPort(GfxBase->ActiView,vP);
  6678.        MrgCop(GfxBase->ActiView);
  6679.       }
  6680.      if (SYSTEM_BOBS)
  6681.       {
  6682.        RemIBob(TheBob,rpG,vP);
  6683.        SortGList(rpG);
  6684.        DrawGList(rpG,vP);
  6685.       }
  6686.      MakeVPort(GfxBase->ActiView,vP);
  6687.      MrgCop(GfxBase->ActiView);
  6688.      ClipBlitTrans (
  6689.             &(BobTransImage->ti_RP),        /* Source RastPort */
  6690.             0, 0,           /* Source LeftEdge, TopEdge */
  6691.             rpG,            /* Destination RastPort */
  6692.             ColArray[ecol],RowArray[erow],/* Destination LeftEdge, TopEdge */
  6693.             BobTransImage->ti_IM->Width,    /* Width of Image */
  6694.             BobTransImage->ti_IM->Height,/* Height of Image */
  6695.             BobTransImage->ti_sRP); /* Shadow RastPort */
  6696.      LoadBobImage(BLANKDATA);
  6697.      if (SYSTEM_BOBS)
  6698.       {
  6699.        AddBob(TheBob,rpG);
  6700.       }
  6701.      MakeVPort(GfxBase->ActiView,vP);
  6702.      MrgCop(GfxBase->ActiView);
  6703.     }
  6704.    else /* check EnPassant */
  6705.     {
  6706.      side ^= 1;
  6707.      if (myEnPassant[side])
  6708.       {
  6709.        myEnPassant[side] = 0;
  6710.        scol = str[2] - 'a';
  6711.        if (str[3] == '3') /* white is removed from bd at 4*/
  6712.     {
  6713.      srow = 3;
  6714.     }
  6715.        else /* black is removed at pos 5 */
  6716.     {
  6717.      srow = 4;
  6718.     }
  6719.        tmp1 = srow & 1;
  6720.        tmp2 = scol & 1;
  6721.        if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  6722.     {
  6723.      BltBitMap(BlackBitMap,0,0,myBitMap,ColArray[scol],
  6724.             RowArray[srow],SQUAREWIDTH,SQUAREHEIGHT,
  6725.             0xc0L,0xffL,0L);
  6726.     }
  6727.        else
  6728.     {
  6729.      BltBitMap(WhiteBitMap,0,0,myBitMap,ColArray[scol],
  6730.             RowArray[srow],SQUAREWIDTH,SQUAREHEIGHT,
  6731.             0xc0L,0xffL,0L);
  6732.     }
  6733.       }
  6734.     }
  6735. }
  6736. #endif // NEEDTODO
  6737.  
  6738. void DrawChessPieces(tgthps)
  6739. HPS tgthps;
  6740. {
  6741.  int bcolor,bpiece;
  6742.  POINTL apts[4];
  6743.  int r,c,l;
  6744.  int piece;
  6745.  
  6746.  for(r=0;r<8;r++)
  6747.   for(c=0;c<8;c++)
  6748.    {
  6749.     l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  6750.     if (amigacolor[l] == white)
  6751.      piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  6752.     else
  6753.      piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  6754.     if (amigacolor[l] != neutral)
  6755.      {
  6756.       if (piece >= 'a') // white piece
  6757.        {
  6758.     bcolor = white;
  6759.        }
  6760.      else
  6761.       {
  6762.        bcolor = black;
  6763.       }
  6764.      switch (tolower(piece))
  6765.       {
  6766.        case 'p' :
  6767.         bpiece = PAWNBOB;
  6768.         break;
  6769.        case 'n' :
  6770.         bpiece = KNIGHTBOB;
  6771.         break;
  6772.        case 'b' :
  6773.         bpiece = BISHOPBOB;
  6774.         break;
  6775.        case 'r' :
  6776.         bpiece = ROOKBOB;
  6777.         break;
  6778.        case 'q' :
  6779.         bpiece = QUEENBOB;
  6780.         break;
  6781.        case 'k' :
  6782.         bpiece = KINGBOB;
  6783.         break;
  6784.       }
  6785.       apts[2].x = 0; // src left bottom
  6786.       apts[2].y = 0; // src left bottom
  6787.       apts[3].x = BOBWIDTH - 1; // src rt top
  6788.       apts[3].y = BOBHEIGHT - 1; // src rt top
  6789.       apts[0].x = ColArray[c]; // tgt left bottom
  6790.       apts[0].y = RowArray[r]; // tgt left bottom
  6791.       apts[1].x = apts[0].x + BOBWIDTH - 1; // tgt rt top
  6792.       apts[1].y = apts[0].y + BOBHEIGHT - 1; // tgt rt top
  6793.       TransBlit(TheBob[bcolor][bpiece],tgthps,hpsMemory,4L,(PPOINTL)apts);
  6794.      } // color not neut
  6795.    } // for c
  6796. }// drawpieces
  6797.  
  6798. void PutPieceBack()
  6799. {
  6800.  POINTL apts[4];
  6801.  APIRET rc;
  6802.  int tmp1,tmp2;
  6803.  int r,c,l,piece;
  6804.  
  6805.  if (CheckIllegal)
  6806.   {
  6807.    apts[2].x = 0; // src left bottom
  6808.    apts[2].y = 0; // src left bottom
  6809.    apts[3].x = SQUAREWIDTH - 1; // src rt top
  6810.    apts[3].y = SQUAREHEIGHT - 1; // src rt top
  6811.    apts[0].x = ColArray[OrigCol]; // tgt left bottom
  6812.    apts[0].y = RowArray[OrigRow]; // tgt left bottom
  6813.    apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  6814.    apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  6815.    tmp1 = OrigRow & 1;
  6816.    tmp2 = OrigCol & 1;
  6817.    rc = DosRequestMutexSem(DrawSemaphore,3000);
  6818.    if (rc)
  6819.     return;
  6820.    if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  6821.     {
  6822.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  6823.     }
  6824.        else
  6825.     {
  6826.      GpiSetBitmap(hpsMemory,BlackBitMap);
  6827.     }
  6828.    GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  6829.    DosReleaseMutexSem(DrawSemaphore);
  6830.    apts[2].x = 0; // src left bottom
  6831.    apts[2].y = 0; // src left bottom
  6832.    apts[3].x = BOBWIDTH - 1; // src rt top
  6833.    apts[3].y = BOBHEIGHT - 1; // src rt top
  6834.    apts[0].x = ColArray[OrigCol]; // tgt left bottom
  6835.    apts[0].y = RowArray[OrigRow]; // tgt left bottom
  6836.    apts[1].x = apts[0].x + BOBWIDTH - 1; // tgt rt top
  6837.    apts[1].y = apts[0].y + BOBHEIGHT - 1; // tgt rt top
  6838.    TransBlit2(TheBob[CurrBobColor][CurrBobIndex],hwClientPS,hpsMemory,4L,(PPOINTL)apts);
  6839. // Now I need to put the target square back the way it was
  6840.    if (((OrigRow != DestRow)||(OrigCol != DestCol))&&((DestRow != -1)&&(DestCol != -1)))
  6841.     {
  6842.    apts[2].x = 0; // src left bottom
  6843.    apts[2].y = 0; // src left bottom
  6844.    apts[3].x = SQUAREWIDTH - 1; // src rt top
  6845.    apts[3].y = SQUAREHEIGHT - 1; // src rt top
  6846.    apts[0].x = ColArray[DestCol]; // tgt left bottom
  6847.    apts[0].y = RowArray[DestRow]; // tgt left bottom
  6848.    apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  6849.    apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  6850.    tmp1 = DestRow & 1;
  6851.    tmp2 = DestCol & 1;
  6852.    rc = DosRequestMutexSem(DrawSemaphore,3000);
  6853.    if (rc)
  6854.     return;
  6855.    if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  6856.     {
  6857.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  6858.     }
  6859.        else
  6860.     {
  6861.      GpiSetBitmap(hpsMemory,BlackBitMap);
  6862.     }
  6863.    GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  6864.    DosReleaseMutexSem(DrawSemaphore);
  6865.    apts[2].x = 0; // src left bottom
  6866.    apts[2].y = 0; // src left bottom
  6867.    apts[3].x = BOBWIDTH - 1; // src rt top
  6868.    apts[3].y = BOBHEIGHT - 1; // src rt top
  6869.    apts[0].x = ColArray[OrigCol]; // tgt left bottom
  6870.    apts[0].y = RowArray[OrigRow]; // tgt left bottom
  6871.    apts[1].x = apts[0].x + BOBWIDTH - 1; // tgt rt top
  6872.    apts[1].y = apts[0].y + BOBHEIGHT - 1; // tgt rt top
  6873.    r = OrigRow;
  6874.    c = OrigCol;
  6875.    l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  6876.    if (amigacolor[l] == white)
  6877.     piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  6878.    else if (amigacolor[l] == black)
  6879.     piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  6880.    else
  6881.     piece = BLANKDATA;
  6882.    if (piece != BLANKDATA)
  6883.     {
  6884.      LoadBobImage(piece);
  6885.      TransBlit2(TheBob[CurrBobColor][CurrBobIndex],hwClientPS,hpsMemory,4L,(PPOINTL)apts);
  6886.     }
  6887.    apts[2].x = 0; // src left bottom
  6888.    apts[2].y = 0; // src left bottom
  6889.    apts[3].x = BOBWIDTH - 1; // src rt top
  6890.    apts[3].y = BOBHEIGHT - 1; // src rt top
  6891.    apts[0].x = ColArray[DestCol]; // tgt left bottom
  6892.    apts[0].y = RowArray[DestRow]; // tgt left bottom
  6893.    apts[1].x = apts[0].x + BOBWIDTH - 1; // tgt rt top
  6894.    apts[1].y = apts[0].y + BOBHEIGHT - 1; // tgt rt top
  6895.    r = DestRow;
  6896.    c = DestCol;
  6897.    l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  6898.    if (amigacolor[l] == white)
  6899.     piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  6900.    else if (amigacolor[l] == black)
  6901.     piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  6902.    else
  6903.     piece = BLANKDATA;
  6904.    if (piece != BLANKDATA)
  6905.     {
  6906.      LoadBobImage(piece);
  6907.      TransBlit2(TheBob[CurrBobColor][CurrBobIndex],hwClientPS,hpsMemory,4L,(PPOINTL)apts);
  6908.     }
  6909.     } // fix up the dest square
  6910.    CheckIllegal = 0;
  6911.   }
  6912. }
  6913.  
  6914. void DrawAmigaBoard()
  6915. {
  6916.  HPS tgthps;
  6917.  int bcolor,bpiece;
  6918.  POINTL apts[4];
  6919.  int r,c,l,tmp1,tmp2;
  6920.  int piece;
  6921.  APIRET rcd;
  6922.  
  6923.  tgthps = hwClientPS;
  6924.  rcd = DosRequestMutexSem(DrawSemaphore,2000);
  6925.  if (rcd)
  6926.   return;
  6927.  for(r=0;r<8;r++)
  6928.   for(c=0;c<8;c++)
  6929.    {
  6930.        tmp1 = r & 1;
  6931.        tmp2 = c & 1;
  6932.        apts[2].x = 0; // src left bottom
  6933.        apts[2].y = 0; // src left bottom
  6934.        apts[3].x = SQUAREWIDTH - 1; // src rt top
  6935.        apts[3].y = SQUAREHEIGHT - 1; // src rt top
  6936.        apts[0].x = ColArray[c]; // tgt left bottom
  6937.        apts[0].y = RowArray[r]; // tgt left bottom
  6938.        apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  6939.        apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  6940.        if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  6941.     {
  6942.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  6943.     }
  6944.        else
  6945.     {
  6946.      GpiSetBitmap(hpsMemory,BlackBitMap);
  6947.     }
  6948.     GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  6949.     l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  6950.     if (amigacolor[l] == white)
  6951.      piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  6952.     else
  6953.      piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  6954.     if (amigacolor[l] != neutral)
  6955.      {
  6956.       if (piece >= 'a') // white piece
  6957.        {
  6958.     bcolor = white;
  6959.        }
  6960.      else
  6961.       {
  6962.        bcolor = black;
  6963.       }
  6964.      switch (tolower(piece))
  6965.       {
  6966.        case 'p' :
  6967.         bpiece = PAWNBOB;
  6968.         break;
  6969.        case 'n' :
  6970.         bpiece = KNIGHTBOB;
  6971.         break;
  6972.        case 'b' :
  6973.         bpiece = BISHOPBOB;
  6974.         break;
  6975.        case 'r' :
  6976.         bpiece = ROOKBOB;
  6977.         break;
  6978.        case 'q' :
  6979.         bpiece = QUEENBOB;
  6980.         break;
  6981.        case 'k' :
  6982.         bpiece = KINGBOB;
  6983.         break;
  6984.       }
  6985.       apts[2].x = 0; // src left bottom
  6986.       apts[2].y = 0; // src left bottom
  6987.       apts[3].x = BOBWIDTH - 1; // src rt top
  6988.       apts[3].y = BOBHEIGHT - 1; // src rt top
  6989.       apts[0].x = ColArray[c]; // tgt left bottom
  6990.       apts[0].y = RowArray[r]; // tgt left bottom
  6991.       apts[1].x = apts[0].x + BOBWIDTH - 1; // tgt rt top
  6992.       apts[1].y = apts[0].y + BOBHEIGHT - 1; // tgt rt top
  6993.       TransBlit(TheBob[bcolor][bpiece],tgthps,hpsMemory,4L,(PPOINTL)apts);
  6994.      } // color not neut
  6995.    } // for c
  6996.  DosReleaseMutexSem(DrawSemaphore);
  6997. }
  6998.  
  6999.  
  7000. //#define INPUTSIGNAL (1<<InputPort->mp_SigBit)
  7001.  
  7002.  
  7003. void InputThread()
  7004. {
  7005.  ULONG SysInfo[16];
  7006.  int BorderX,BorderY,MenuHt,TitleHt;
  7007.  APIRET rc;
  7008.  int i;
  7009.  //ULONG postcnt;
  7010.  int xleft,ybottom;
  7011.  
  7012. // Init The Port We will use to communicate
  7013.  InputThreadState = 0; // tell world not ready yet...
  7014.  
  7015. // this thread needs to open the PM window 
  7016. // and prepare the event semaphore to talk
  7017. // to main chess engine with
  7018.  
  7019. // open the PM window...
  7020.  
  7021. //     rc = DosCreateEventSem(semname,&semhandle,0,0);
  7022. //     if (rc)
  7023. //      {
  7024. //       DisplayError("InputThread cannot create event sem\n");
  7025. //       InputThreadState = 2;
  7026. //       DosExit(1,0);
  7027. //      }
  7028.      rc = DosQuerySysInfo(QSV_VERSION_MAJOR,QSV_TOTPHYSMEM,SysInfo,16L*4L);
  7029.      if (rc)
  7030.       {
  7031.        DosExit(1,0);
  7032.       }
  7033.      if (ForceMax)
  7034.       {
  7035.        ttblsize = 120001;
  7036.        etblsize = 14001;
  7037.        strcpy(UC_Title,"UChess Max: ");
  7038.       }
  7039.      else
  7040.       { // normal sizes
  7041.        ttblsize = 74000;
  7042.        etblsize = 8100;
  7043.       }
  7044.      if ((SysInfo[6] < 16000000L)||(ForceMini))
  7045.       {
  7046.        ttblsize = 32768;
  7047.        etblsize = 3072;
  7048.        strcpy(UC_Title,"UChess mini: ");
  7049.       }
  7050.     if ((SysInfo[6] < 7900000L)||(ForceMicro))
  7051.      {
  7052.        ttblsize = 16000;
  7053.        etblsize = 900;
  7054.        strcpy(UC_Title,"UChess baby: ");
  7055.      }
  7056.     ETABLE = etblsize;
  7057.     rc = DosAllocMem((PPVOID)&etab[0],sizeof(struct etable)*etblsize,
  7058.      (ULONG)(PAG_READ|PAG_WRITE|PAG_COMMIT));
  7059.     if (rc)
  7060.      {
  7061.       DosExit(1,0);
  7062.      }
  7063.     rc = DosAllocMem((PPVOID)&etab[1],sizeof(struct etable)*etblsize,
  7064.      (ULONG)(PAG_READ|PAG_WRITE|PAG_COMMIT));
  7065.     if (rc)
  7066.      {
  7067.       DosExit(1,0);
  7068.      }
  7069.      rc = DosCreateEventSem(replyname,&replyhandle,0,0);
  7070.      if (rc)
  7071.       {
  7072.        DisplayError("InputThread cannot create reply sem\n");
  7073.        InputThreadState = 2;
  7074.        DosExit(1,0);
  7075.       }
  7076.      InputThreadState = 1;
  7077. // NOW the main thread can just boogie and I will wait for it
  7078. // now create the event semaphone
  7079.      while (!MainThreadStarted)
  7080.        {
  7081.     DosSleep(250);
  7082.        }
  7083.     hab= WinInitialize(0);
  7084.     hmq = WinCreateMsgQueue(hab,0);
  7085.     WinRegisterClass(hab,
  7086.             szClientClass,
  7087.             ClientWndProc,
  7088.             CS_SIZEREDRAW,
  7089.             0 );
  7090.     TitleHt = WinQuerySysValue(HWND_DESKTOP,SV_CYTITLEBAR);
  7091.     if (!TitleHt)
  7092.      {
  7093.       DosBeep(1280,1000);
  7094.       TitleHt  = 16;
  7095.      }
  7096.     BorderX = WinQuerySysValue(HWND_DESKTOP,SV_CXBORDER);
  7097.     if (!BorderX)
  7098.      {
  7099.       DosBeep(1280,1000);
  7100.       BorderX  = 4;
  7101.      }
  7102.     BorderY = WinQuerySysValue(HWND_DESKTOP,SV_CYBORDER);
  7103.     if (!BorderY)
  7104.      {
  7105.       DosBeep(1280,1000);
  7106.       BorderY  = 4;
  7107.      }
  7108.     MenuHt = WinQuerySysValue(HWND_DESKTOP,SV_CYMENU);
  7109.     if (!MenuHt)
  7110.      {
  7111.       DosBeep(1280,1000);
  7112.       MenuHt  = 16;
  7113.      }
  7114.     hwndFrame = WinCreateStdWindow(
  7115.             HWND_DESKTOP,
  7116.             WS_VISIBLE,
  7117.             &flCreateFlags,
  7118.             szClientClass,
  7119.             VERSTRING,
  7120.             0,
  7121.             NULLHANDLE,
  7122.             MENU_ID,
  7123.             &hwndClient);
  7124.     if (!hwndFrame)
  7125.      {
  7126.        DosExit(1,0);
  7127.      }
  7128.         OldFrameProc = WinSubclassWindow(hwndFrame, myFrameProc);
  7129.     winhdc = WinOpenWindowDC(hwndClient);
  7130.     if (!DevQueryCaps(winhdc,CAPS_WIDTH,1,(PLONG)&ScreenWidth))
  7131.      DosExit(1,0);
  7132.     if (!DevQueryCaps(winhdc,CAPS_HEIGHT,1,(PLONG)&ScreenHeight))
  7133.      DosExit(1,0);
  7134.     if (!DevQueryCaps(winhdc,CAPS_COLORS,1,(PLONG)&ScreenColors))
  7135.      DosExit(1,0);
  7136.     if (ScreenColors < 256)
  7137.      {
  7138.        DisplayError("UChess requires 256 colors (or more)");
  7139.        DosExit(1,0);
  7140.      }
  7141.     xleft = (ScreenWidth - WIDTH - 8)/2;
  7142.     ybottom = (ScreenHeight - HEIGHT - 28 - 22)/2;
  7143.         MaxX = WIDTH + BorderX*4+2;
  7144.         MaxY = HEIGHT + BorderY*4 + MenuHt + TitleHt+4;
  7145.     WinSetWindowPos(hwndFrame,HWND_TOP,xleft,ybottom,WIDTH+BorderX*4+1,
  7146.               HEIGHT+BorderY*4 + MenuHt + TitleHt+1,SWP_SIZE|SWP_MOVE|SWP_SHOW);
  7147.     do {
  7148.         DosSleep(34);
  7149.     } while (WinNotInited);
  7150.     if (!GotSize)
  7151.      DosExit(1,0);
  7152.         InitHelp();
  7153.     if (!InitmyGels())
  7154.      {
  7155.       DisplayError("Cannot initmy gel system");
  7156.       DosExit(1,0);
  7157.      }
  7158.     else
  7159.      {
  7160.       if (!myLoadFullBitMap(1))
  7161.        {
  7162.         DisplayError("Cannot load the disk bitmap");
  7163.         DosExit(1,0);
  7164.        }
  7165.      }
  7166.  
  7167.  
  7168.   ShowMessage("UChess ready");
  7169.   DosBeep(800,100);
  7170.   while (WinGetMsg(hab,&qmsg,NULLHANDLE,0,0))
  7171.    {
  7172. // in here I have to route input via msgs to other process
  7173.     WinDispatchMsg(hab,&qmsg);
  7174.     if (((qmsg.msg == WM_CLOSE)||(qmsg.msg == WM_QUIT))&&(qmsg.hwnd == hwndClient))
  7175.      {
  7176.       DestroyHelpInstance();
  7177.       DosExit(1,0);
  7178.      }
  7179.     else
  7180.      { // here we must process the event, and send something to reply handle
  7181.        // if needed
  7182.     if (ReturnHit)
  7183.      {
  7184.       ReturnHit = 0;
  7185.       if (strlen(OpEntryStr))
  7186.        { // strlen not 0
  7187.         if (!(stricmp(OpEntryStr,"hint")))
  7188.          {
  7189.           GiveHint();
  7190.          }
  7191.         else if (!(stricmp(OpEntryStr,"quit")))
  7192.          {
  7193.           DosExit(1,0);
  7194.          }
  7195.         else if (RealThink)
  7196.          {
  7197.           OpEntryStr[0] = 0;
  7198.          }
  7199.         else // not hint
  7200.          {
  7201.           if ((!ResignOffered)&&(!flag.mate)&&(PlayMode == 2)&&(!flag.quit))
  7202.            {
  7203.         if (global_tmp_score < -975)
  7204.           {
  7205.            if (DoResign())
  7206.             {
  7207.              flag.mate = true;
  7208.              flag.back = true;
  7209.              Mate = 1;
  7210.              ShowMessage("You Win!");
  7211.              ShowMessage("UChess Resigns");
  7212.             }
  7213.           }
  7214.            } // check on resigning
  7215.           if (!flag.bothsides)
  7216.            {
  7217.         flag.back = true;
  7218.         flag.musttimeout = true;
  7219.            }
  7220.           if ((!OpEntryRecvd)&&(!RealThink)) // do not set if already set by movenow
  7221.          OpEntryRecvd = 1;
  7222.           i = 5;
  7223.           do {
  7224.         rc = DosPostEventSem(replyhandle); // let caller know you are done
  7225.         if (rc)
  7226.          {
  7227.           ShowMessage("Sem retry");
  7228.           DosSleep(250);
  7229.          }
  7230.         i--;
  7231.            } while ((rc)&&(i>0));
  7232.           if (rc)
  7233.            {
  7234.         ShowMessage("Event Err");
  7235.         DosBeep(1380,500);
  7236.         DosSleep(1000);
  7237.         DosExit(1,0);
  7238.            }
  7239.          } // not hint and not computers turn
  7240.        } // strlen not 0
  7241.      }
  7242.      }
  7243.    }
  7244. #ifdef AMIGAWAY
  7245.      do {
  7246.        rc = DosWaitEventSem(semhandle,SEM_INDEFINITE_WAIT);
  7247.        if (rc)
  7248.     {
  7249.      DosExit(1,1);
  7250.     }
  7251.        DosResetEventSem(semhandle,&postcnt);
  7252.        if (!flag.quit)
  7253.       { // !flag.quit
  7254.        if (Global_Message == 1L) // do get op entry
  7255.         {
  7256.          OpEntryRecvd = 0;
  7257.          do {
  7258.          GetOperatorEntry(); // TMP DEBUG COMMENTED OUT!
  7259.          if ((!OpEntryRecvd)&&(!RealThink)) // do not set if already set by movenow
  7260.           OpEntryRecvd = 1;
  7261.          if (OpEntryRecvd)
  7262.           DosPostEventSem(replyhandle); // let caller know you are done
  7263.          } while (!OpEntryRecvd);
  7264.         }
  7265.       } //flag.quit
  7266.      } while ((Global_Message != 0xff));
  7267. #endif
  7268.    // NOW CLOSE THE PM WINDOW
  7269.  InputThreadState = 2;
  7270.  DosExit(0,0);
  7271. }
  7272.  
  7273. #ifdef NEEDTODO
  7274. void GetOperatorEntry(void)
  7275. {
  7276.  char *str;
  7277.  char  PromoteChar;
  7278.  char mvnstr[32];
  7279.  ULONG signals;
  7280.  char  tempstr[40];
  7281.  struct IntuiMessage  *message;
  7282.  long done=0;
  7283.  long done2;
  7284.  int ilen=0;
  7285.  int r,c,l,piece;
  7286.  long  class,code;
  7287.  int MouseX,MouseY;
  7288.  long tmp1,tmp2;
  7289.  int tmovenum;
  7290.  static int movenum;
  7291.  
  7292.  
  7293.  
  7294.  str = OpEntryStr;
  7295.  if (CheckIllegal)
  7296.   {
  7297.    CheckIllegal = 0;
  7298.    if (IllegalMove)
  7299.     { /* put guy back! */
  7300.       IllegalMove = 0;
  7301.       if (SYSTEM_BOBS)
  7302.        {
  7303.     RemIBob(TheBob,rpG,vP);
  7304.     SortGList(rpG); 
  7305.     DrawGList(rpG,vP);
  7306.        }
  7307.       MakeVPort(GfxBase->ActiView,vP);
  7308.       MrgCop(GfxBase->ActiView);
  7309.       ClipBlitTrans (
  7310.         &(BobTransImage->ti_RP),        /* Source RastPort */
  7311.         0, 0,           /* Source LeftEdge, TopEdge */
  7312.         rpG,            /* Destination RastPort */
  7313.         ColArray[OrigCol],RowArray[OrigRow],/* Destination LeftEdge, TopEdge */
  7314.         BobTransImage->ti_IM->Width,    /* Width of Image */
  7315.         BobTransImage->ti_IM->Height,/* Height of Image */
  7316.         BobTransImage->ti_sRP); /* Shadow RastPort */
  7317.       BobVSprite->X = WIDTH-1-BOBWIDTH;
  7318.       BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  7319.       LoadBobImage(BLANKDATA);
  7320.       if (SYSTEM_BOBS)
  7321.        AddBob(TheBob,rpG);
  7322.       MakeVPort(GfxBase->ActiView,vP);
  7323.       MrgCop(GfxBase->ActiView);
  7324.     }
  7325.   }
  7326.  while (message = (struct IntuiMessage *)GetMsg(wG->UserPort))
  7327.    {
  7328.      ReplyMsg((struct Message *)message);
  7329.    }
  7330. // when an illegal move is made
  7331. // the tmovenum used to be 1 too many for computer == black
  7332.  if (!thinkahead)
  7333.   {
  7334.    if (computer == white)
  7335.     {
  7336.       movenum = (GameCnt)>>1;
  7337.     }
  7338.    else
  7339.     {
  7340.      movenum = (GameCnt+1)>>1; // was +2
  7341.     }
  7342.   }
  7343.  else
  7344.   {
  7345.     movenum++;
  7346.   }
  7347.  if (!GameCnt)
  7348.   tmovenum = 1;
  7349.  else
  7350.   {
  7351.    if (thinkahead)
  7352.     {
  7353.     if (computer == white)
  7354.      {
  7355.       tmovenum = movenum - 1;
  7356.      }
  7357.     else
  7358.      tmovenum = movenum;
  7359.     }
  7360.    else
  7361.     {
  7362.      tmovenum = movenum + 1;
  7363.     }
  7364.   }
  7365.  if (tmovenum < 1)
  7366.   tmovenum = 1;
  7367.  mysprintf(mvnstr,"%d: ",tmovenum);
  7368.  ObtainSemaphore(&mySemaphore);
  7369.  mySetABPenDrMd(rpG,BACKGNDTEXTCOLOR,bpen,JAM1);
  7370.  RectFill(rpG,520,USERBOX,621,USERBOX+30);
  7371.  Move(rpG,520,USERBOX+6);
  7372.  mySetABPenDrMd(rpG,BLACK,bpen,JAM1);
  7373.  Text(rpG,mvnstr,strlen(mvnstr));
  7374.  ReleaseSemaphore(&mySemaphore);
  7375.  tempstr[0] = 0;
  7376.  PromoteChar = 0;
  7377.  OnMenu(wG,SHOWMENUNUM); 
  7378.  OnMenu(wG,SUPERMENUNUM); 
  7379.  OnMenu(wG,THINKMENUNUM); 
  7380.  OnMenu(wG,BOOKMENUNUM); 
  7381.  do {
  7382. // if (!globalmessage_valid)
  7383. //  signals = Wait(globalsignalset);
  7384.  WaitPort(wG->UserPort);
  7385. // if ((signals & WINDOWSIGNAL)||(globalmessage_valid))
  7386. //  {
  7387. //  message = (struct IntuiMessage *)1;
  7388.   while ((message = (struct IntuiMessage *)GetMsg(wG->UserPort)))
  7389.   {
  7390.   //if (!globalmessage_valid)
  7391.    //message = (struct IntuiMessage *)GetMsg(wG->UserPort);
  7392.   //if ((message)) //||(globalmessage_valid))
  7393.    //{
  7394.    //     if (!globalmessage_valid)
  7395.    //      {
  7396.       class = message->Class;
  7397.       code = message->Code;
  7398.       MouseX = message->MouseX;
  7399.       MouseY = message->MouseY;
  7400.       ReplyMsg((struct Message *)message);
  7401. //         }
  7402. //        else
  7403. //         {
  7404. //        class = globalmessage.Class;
  7405. //        code = globalmessage.Code;
  7406. //          MouseX = globalmessage.MouseX;
  7407. //          MouseY = globalmessage.MouseY;
  7408. //          globalmessage_valid = 0L;
  7409. //         }
  7410.     if (RealThink)
  7411.      { // we are in the middle of Selectmove iop == 1!!
  7412.       if (class == MENUPICK)
  7413.        {
  7414.         if (code != MENUNULL)
  7415.          {
  7416.           done = HandleEvent((APTR)ItemAddress(&MenuList1,code));
  7417.           if (done)
  7418.            strcpy(tempstr,OpEntryStr);
  7419.          }
  7420.        }
  7421.       else if ((class == MOUSEBUTTONS)&&(code == SELECTDOWN))
  7422.        {
  7423.         if (flag.bothsides)
  7424.          {
  7425.           if (!flag.timeout)
  7426.            {
  7427.         flag.back = true;
  7428.            }
  7429.           flag.bothsides = false;
  7430.          }
  7431.        }
  7432.      }
  7433.     else if ( class == MENUPICK )   /* MenuItems */
  7434.      { // ! realthink
  7435.       if (code != MENUNULL)
  7436.        {
  7437.         done = HandleEvent((APTR)ItemAddress(&MenuList1,code));
  7438.         if (done)
  7439.          strcpy(tempstr,OpEntryStr);
  7440.         if (flag.quit) 
  7441.          done = 1;
  7442.         else if (!done)
  7443.          {
  7444.           if (teston)
  7445.            {
  7446.         done = 1;
  7447.         teston = 0;
  7448.         strcpy(tempstr,"test");
  7449.            }
  7450.           else if (doswap)
  7451.            {
  7452.         done = 1;
  7453.         doswap = 0;
  7454.         strcpy(tempstr,"switch");
  7455.            }
  7456.           else if (doauto)
  7457.            {
  7458.         done = 1;
  7459.         doauto = 0;
  7460.         strcpy(tempstr,"both");
  7461.            }
  7462.           else if (doundo)
  7463.            {
  7464.         done = 1;
  7465.         doundo = 0;
  7466.         strcpy(tempstr,"help");
  7467.            }
  7468.          }
  7469.        }
  7470.      }
  7471.     else if ((class == RAWKEY) && (!RealThink))
  7472.      {
  7473.       if (code < 80)
  7474.        {
  7475.       code = cookedchar[code];
  7476.       if ((code == 13)||(code == 10))
  7477.        {
  7478.         if (tempstr[0])
  7479.          done = 1;
  7480.        }
  7481.       else if ((code == 7)&&(ilen)) /* backspace */
  7482.        {
  7483.         tempstr[strlen(tempstr)-1] = '\0';
  7484.         mysprintf(mvnstr,"%d: ",tmovenum);
  7485.         ObtainSemaphore(&mySemaphore);
  7486.         mySetABPenDrMd(rpG,BACKGNDTEXTCOLOR,bpen,JAM1);
  7487.         RectFill(rpG,520,USERBOX,621,USERBOX+30);
  7488.         mySetABPenDrMd(rpG,BLACK,bpen,JAM1);
  7489.         Move(rpG,520,USERBOX+6);
  7490.         Text(rpG,mvnstr,strlen(mvnstr));
  7491.         Text(rpG,tempstr,strlen(tempstr));
  7492.         ReleaseSemaphore(&mySemaphore);
  7493.         ilen--;
  7494.        }
  7495.       else if ((isalnum(code)||(code == '-')||(code == '/')) && (strlen(tempstr) < 12))
  7496.        {
  7497.         tempstr[ilen] = tolower(code);
  7498.         ilen++;
  7499.         tempstr[ilen] = 0;
  7500.         mysprintf(mvnstr,"%d: ",tmovenum);
  7501.         ObtainSemaphore(&mySemaphore);
  7502.         mySetABPenDrMd(rpG,BLACK,bpen,JAM1);
  7503.         Move(rpG,520,USERBOX+6);
  7504.         Text(rpG,mvnstr,strlen(mvnstr));
  7505.         Text(rpG,tempstr,strlen(tempstr));
  7506.         ReleaseSemaphore(&mySemaphore);
  7507.        }
  7508.       } /* code < 80 */
  7509.      }
  7510.     else if ((class == MOUSEBUTTONS)&&(!(flag.quit || flag.mate || flag.force))
  7511.            &&(!RealThink))
  7512.      {
  7513.       if ((code == SELECTDOWN) && 
  7514.           ((MouseY <= (ROW1+SQUAREHEIGHT)) && (MouseY >= ROW8) && (MouseX <= (COLH+BOBWIDTH)) &&
  7515.            (MouseX >= COLA)))
  7516.        {
  7517.         if (MouseX < COLB)
  7518.          OrigCol = 0;
  7519.         else if (MouseX < COLC)
  7520.          OrigCol = 1;
  7521.         else if (MouseX < COLD)
  7522.          OrigCol = 2;
  7523.         else if (MouseX < COLE)
  7524.          OrigCol = 3;
  7525.         else if (MouseX < COLF)
  7526.          OrigCol = 4;
  7527.         else if (MouseX < COLG)
  7528.          OrigCol = 5;
  7529.         else if (MouseX < COLH)
  7530.          OrigCol = 6;
  7531.         else 
  7532.          OrigCol = 7;
  7533.         if (MouseY < ROW7)
  7534.          OrigRow = 7;
  7535.         else if (MouseY < ROW6)
  7536.          OrigRow = 6;
  7537.         else if (MouseY < ROW5)
  7538.          OrigRow = 5;
  7539.         else if (MouseY < ROW4)
  7540.          OrigRow = 4;
  7541.         else if (MouseY < ROW3)
  7542.          OrigRow = 3;
  7543.         else if (MouseY < ROW2)
  7544.          OrigRow = 2;
  7545.         else if (MouseY < ROW1)
  7546.          OrigRow = 1;
  7547.         else 
  7548.          OrigRow = 0;
  7549.         tmp1 = OrigRow & 1L;
  7550.         tmp2 = OrigCol & 1L;
  7551.         done2 = 0;
  7552.         r = OrigRow;
  7553.         c = OrigCol;
  7554.         l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  7555.         if ((amigacolor[l] == neutral)||(opponent != amigacolor[l]))
  7556.          {
  7557.           done2 = 1;
  7558.          }
  7559.         else if (amigacolor[l] == white)
  7560.          piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  7561.         else
  7562.          piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  7563.         if (!done2)
  7564.          {
  7565.           if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  7566.            {
  7567.         BltBitMap(BlackBitMap,0,0,myBitMap,ColArray[OrigCol],
  7568.             RowArray[OrigRow],SQUAREWIDTH,SQUAREHEIGHT,
  7569.             0xc0L,0xffL,0L);
  7570.            }
  7571.           else
  7572.            {
  7573.         BltBitMap(WhiteBitMap,0,0,myBitMap,ColArray[OrigCol],
  7574.             RowArray[OrigRow],SQUAREWIDTH,SQUAREHEIGHT,
  7575.             0xc0L,0xffL,0L);
  7576.            }
  7577.           BobVSprite->X = WIDTH-1-BOBWIDTH;
  7578.           BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  7579.           LoadBobImage(BLANKDATA);
  7580.           if (SYSTEM_BOBS)
  7581.            {
  7582.         SortGList(rpG);
  7583.         DrawGList(rpG,vP);
  7584.            }
  7585.           MakeVPort(GfxBase->ActiView,vP);
  7586.           MrgCop(GfxBase->ActiView);
  7587.           CheckIllegal = 1;
  7588.           IllegalMove = 0;
  7589.  /* NOW POSITION BOB AND LOAD IN ITS CORRECT PIECE IMAGE */
  7590.           LoadBobImage(piece);
  7591.           BobVSprite->X = MouseX - 24;
  7592.           BobVSprite->Y = MouseY - 16;
  7593.           if (SYSTEM_BOBS)
  7594.            {
  7595.         SortGList(rpG);
  7596.         DrawGList(rpG,vP);
  7597.            }
  7598.           MakeVPort(GfxBase->ActiView,vP);
  7599.           MrgCop(GfxBase->ActiView);
  7600.          }
  7601.         ModifyIDCMP(wG,NewWindowStructure1.IDCMPFlags | INTUITICKS);
  7602.         do {
  7603.         signals = Wait(globalsignalset);
  7604.         if (signals & WINDOWSIGNAL)
  7605.          {
  7606.           while ( (message = (struct IntuiMessage *)
  7607.           GetMsg(wG->UserPort) ))
  7608.           {
  7609.           class = message->Class;
  7610.           code = message->Code;
  7611.           MouseX = message->MouseX;
  7612.           MouseY = message->MouseY;
  7613.           ReplyMsg((struct Message *)message);
  7614.           if (!done2)
  7615.            {
  7616.           if ((class == MOUSEBUTTONS)&&(code == SELECTUP))
  7617.            { /* now try and make the move */
  7618.         done2 = 1;
  7619.         if ((MouseX > (COLH+SQUAREWIDTH)) || (MouseX < COLA) ||
  7620.             (MouseY < ROW8) || (MouseY > (ROW1+BOBHEIGHT)))
  7621.          { /* Put the Piece Back */
  7622.            BobVSprite->X = WIDTH-1-BOBWIDTH;
  7623.            BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  7624.            tmp1 = lastpiece;
  7625.            LoadBobImage(BLANKDATA);
  7626.            if (SYSTEM_BOBS)
  7627.             {
  7628.              SortGList(rpG);
  7629.              DrawGList(rpG,vP);
  7630.              RemIBob(TheBob,rpG,vP);
  7631.              SortGList(rpG);
  7632.              DrawGList(rpG,vP);
  7633.             }
  7634.            MakeVPort(GfxBase->ActiView,vP);
  7635.            MrgCop(GfxBase->ActiView);
  7636.            LoadBobImage(tmp1);
  7637.            ClipBlitTrans (
  7638.               &(BobTransImage->ti_RP),  /* Source RastPort */
  7639.               0, 0,             /* Source LeftEdge, TopEdge */
  7640.               rpG,              /* Destination RastPort */
  7641.               ColArray[OrigCol],RowArray[OrigRow],/* Destination LeftEdge, TopEdge */
  7642.               BobTransImage->ti_IM->Width,      /* Width of Image */
  7643.               BobTransImage->ti_IM->Height,/* Height of Image */
  7644.               BobTransImage->ti_sRP);   /* Shadow RastPort */
  7645.            BobVSprite->X = WIDTH-1-BOBWIDTH;
  7646.            BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  7647.            LoadBobImage(BLANKDATA);
  7648.            if (SYSTEM_BOBS)
  7649.             {
  7650.              AddBob(TheBob,rpG);
  7651.              SortGList(rpG);
  7652.              DrawGList(rpG,vP);
  7653.             }
  7654.            MakeVPort(GfxBase->ActiView,vP);
  7655.            MrgCop(GfxBase->ActiView);
  7656.          }
  7657.         else
  7658.          {
  7659.           done = 1; /* try the move */
  7660.           if (MouseX < COLB)
  7661.            DestCol = 0;
  7662.           else if (MouseX < COLC)
  7663.            DestCol = 1;
  7664.           else if (MouseX < COLD)
  7665.            DestCol = 2;
  7666.           else if (MouseX < COLE)
  7667.            DestCol = 3;
  7668.           else if (MouseX < COLF)
  7669.            DestCol = 4;
  7670.           else if (MouseX < COLG)
  7671.            DestCol = 5;
  7672.           else if (MouseX < COLH)
  7673.            DestCol = 6;
  7674.           else 
  7675.            DestCol = 7;
  7676.           if (MouseY < ROW7)
  7677.            DestRow = 7;
  7678.           else if (MouseY < ROW6)
  7679.            DestRow = 6;
  7680.           else if (MouseY < ROW5)
  7681.            DestRow = 5;
  7682.           else if (MouseY < ROW4)
  7683.            DestRow = 4;
  7684.           else if (MouseY < ROW3)
  7685.            DestRow = 3;
  7686.           else if (MouseY < ROW2)
  7687.            DestRow = 2;
  7688.           else if (MouseY < ROW1)
  7689.            DestRow = 1;
  7690.           else 
  7691.            DestRow = 0;
  7692.           if ((DestRow == OrigRow) && (DestCol == OrigCol))
  7693.            {
  7694.             done = 0;
  7695.             tmp1 = lastpiece;
  7696.             LoadBobImage(BLANKDATA);
  7697.             BobVSprite->X = WIDTH-1-BOBWIDTH;
  7698.             BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  7699.             if (SYSTEM_BOBS)
  7700.              {
  7701.               SortGList(rpG);
  7702.               DrawGList(rpG,vP);
  7703.               RemIBob(TheBob,rpG,vP);
  7704.               SortGList(rpG);
  7705.               DrawGList(rpG,vP);
  7706.              }
  7707.             MakeVPort(GfxBase->ActiView,vP);
  7708.             MrgCop(GfxBase->ActiView);
  7709.             LoadBobImage(tmp1);
  7710.             ClipBlitTrans (
  7711.             &(BobTransImage->ti_RP),        /* Source RastPort */
  7712.             0, 0,           /* Source LeftEdge, TopEdge */
  7713.             rpG,            /* Destination RastPort */
  7714.             ColArray[OrigCol],RowArray[OrigRow],/* Destination LeftEdge, TopEdge */
  7715.             BobTransImage->ti_IM->Width,    /* Width of Image */
  7716.             BobTransImage->ti_IM->Height,/* Height of Image */
  7717.             BobTransImage->ti_sRP); /* Shadow RastPort */
  7718.             BobVSprite->X = WIDTH-1-BOBWIDTH;
  7719.             BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  7720.             LoadBobImage(BLANKDATA);
  7721.             if (SYSTEM_BOBS)
  7722.              {
  7723.               AddBob(TheBob,rpG);
  7724.               SortGList(rpG);
  7725.               DrawGList(rpG,vP);
  7726.              }
  7727.             MakeVPort(GfxBase->ActiView,vP);
  7728.             MrgCop(GfxBase->ActiView);
  7729.            }
  7730.           else
  7731.           {
  7732.            MouseDropped = 1;
  7733.            if (((piece == 'p')&&(DestRow == 7))||/* possible prom wht */
  7734.                ((piece == 'P')&&(!DestRow))) /* possible blk promotion */
  7735.              {
  7736.               PromoteChar = DisplayPromoteRequestor();
  7737.              }
  7738.            tempstr[4] = 0;
  7739.            tempstr[0] = OrigCol + 'a';
  7740.            tempstr[1] = OrigRow + '1';
  7741.            tempstr[2] = DestCol + 'a';
  7742.            tempstr[3] = DestRow + '1';
  7743.            mysprintf(mvnstr,"%d: ",tmovenum);
  7744.            ObtainSemaphore(&mySemaphore);
  7745.            mySetABPenDrMd(rpG,BLACK,bpen,JAM1);
  7746.            Move(rpG,520,USERBOX+6);
  7747.            Text(rpG,mvnstr,strlen(mvnstr));
  7748.            Text(rpG,tempstr,strlen(tempstr));
  7749.            ReleaseSemaphore(&mySemaphore);
  7750.            if ((thinkahead)&&(!flag.bothsides))
  7751.             { // code to abort quickly and drop piece!
  7752.              (void)SetTaskPri((struct Task *)myproc,procpri);
  7753.              if (!TCflag)
  7754.               backsrchaborted = 1;
  7755.              if (!flag.timeout)
  7756.               {
  7757.                flag.back = true;
  7758.               }
  7759.             }
  7760.           }
  7761.          }
  7762.            }
  7763.           else if (class == INTUITICKS)
  7764.            {
  7765.         BobVSprite->X = MouseX - 24;
  7766.         BobVSprite->Y = MouseY - 16;
  7767.         if (SYSTEM_BOBS)
  7768.          {
  7769.           SortGList(rpG);
  7770.           DrawGList(rpG,vP);
  7771.          }
  7772.         MakeVPort(GfxBase->ActiView,vP);
  7773.         MrgCop(GfxBase->ActiView);
  7774.            }
  7775.            } /* ! done2 */
  7776.           }
  7777.          } /* signals & WINDOWSIGNAL */
  7778.         } while (!done2);
  7779.         ModifyIDCMP(wG,NewWindowStructure1.IDCMPFlags);
  7780.         while ( (message = (struct IntuiMessage *)
  7781.          GetMsg(wG->UserPort) ))
  7782.          {
  7783.           ReplyMsg((struct Message *)message);
  7784.          }
  7785.        }
  7786.      }
  7787.    //} // if message
  7788. //    if (done)
  7789. //     {
  7790. //       while ((message = (struct IntuiMessage *)GetMsg(wG->UserPort)))
  7791. //        ReplyMsg((struct Message *)message);
  7792. //     }
  7793.   } /* while message */
  7794.   //} /* signals & windowsignal */
  7795.   } while (!done);
  7796. OffMenu(wG,SHOWMENUNUM); 
  7797. OffMenu(wG,BOOKMENUNUM); 
  7798. OffMenu(wG,SUPERMENUNUM); 
  7799. OffMenu(wG,THINKMENUNUM); 
  7800. if (tempstr[0])
  7801.  {
  7802.   if (tempstr[2] == '-')
  7803.    {
  7804.     for(ilen=2;ilen<strlen(tempstr);ilen++)
  7805.      tempstr[ilen] = tempstr[ilen+1];
  7806.    }
  7807.   if (tempstr[4] == '/')
  7808.    {
  7809.     for(ilen=4;ilen<strlen(tempstr);ilen++)
  7810.      tempstr[ilen] = tempstr[ilen+1];
  7811.    }
  7812.  }
  7813. if ((!PromoteChar)&&((strlen(tempstr) == 2) || (strlen(tempstr) == 4)))
  7814.  {
  7815.   r = tempstr[1] - '1';
  7816.   if ((strlen(tempstr) == 2)&&(opponent == white))
  7817.    {
  7818.     r--;
  7819.    }
  7820.   else if ((strlen(tempstr) == 2)&&(opponent == black))
  7821.    {
  7822.     r++;
  7823.    }
  7824.   c = tempstr[0] - 'a';
  7825.   l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  7826.   if ((amigacolor[l] == neutral)||(opponent != amigacolor[l]))
  7827.    {
  7828.     done2 = 1;
  7829.    }
  7830.   else if (amigacolor[l] == white)
  7831.    piece = qxx[amigaboard[l]]; /* white are lower case pieces */
  7832.   else
  7833.    piece = pxx[amigaboard[l]]; /* black are upper case pieces */
  7834.   if (strlen(tempstr) == 4)
  7835.    {
  7836.      r = tempstr[3] - '1';
  7837.    }
  7838.   else
  7839.    {
  7840.     if (opponent == white)
  7841.      {
  7842.       r++;
  7843.      }
  7844.      else
  7845.      {
  7846.       r--;
  7847.      }
  7848.    }
  7849.   if (((piece == 'p')&&(r == 7))||/* possible prom wht */
  7850.       ((piece == 'P')&&(!r))) /* possible blk promotion */
  7851.     {
  7852.      PromoteChar = DisplayPromoteRequestor();
  7853.      if (strlen(tempstr) == 2)
  7854.       {
  7855.        if (!r)
  7856.     {
  7857.      tempstr[4] = 0;
  7858.      tempstr[3] = tempstr[1];
  7859.      tempstr[2] = tempstr[0];
  7860.      tempstr[1]++;
  7861.     }
  7862.        else
  7863.     {
  7864.      tempstr[4] = 0;
  7865.      tempstr[3] = tempstr[1];
  7866.      tempstr[2] = tempstr[0];
  7867.      tempstr[1]--;  
  7868.     }
  7869.       }
  7870.     }
  7871.  }
  7872. if (PromoteChar)
  7873.  {
  7874.   ilen = strlen(tempstr);
  7875.   tempstr[ilen] = PromoteChar;
  7876.   tempstr[ilen+1] = 0;
  7877.  }
  7878. strcpy(str,tempstr);
  7879. if (!(stricmp(str,"new")))
  7880.  {
  7881.     BobVSprite->X = WIDTH-1-BOBWIDTH;
  7882.     BobVSprite->Y = HEIGHT-1-BOBHEIGHT;
  7883.     LoadBobImage(BLANKDATA);
  7884.     if (SYSTEM_BOBS)
  7885.      {
  7886.       SortGList(rpG);
  7887.       DrawGList(rpG,vP);
  7888.      }
  7889.     MakeVPort(GfxBase->ActiView,vP);
  7890.     MrgCop(GfxBase->ActiView);
  7891.     WaitTOF();
  7892.     RethinkDisplay();
  7893.  }
  7894. }
  7895. #endif // NEEDTODO
  7896.  
  7897. void AnimCastle(str)
  7898. char *str;
  7899. {
  7900.  POINTL apts[4],apts2[4];
  7901.  APIRET rc;
  7902.  int r,c;
  7903.  int bobcolor;
  7904.  
  7905. // king is moved must now erase old castle, and draw new one
  7906.  Castled[opponent] = 0;
  7907.  rc = DosRequestMutexSem(DrawSemaphore,3000);
  7908.  if (rc)
  7909.   return;
  7910.  if (str[1] == '1') // white
  7911.   {
  7912.    bobcolor = white;
  7913.    if (tolower(str[2]) == 'c')
  7914.     { // queen side
  7915.      c = 3; // col d
  7916.      r = 0; // row 1
  7917.      apts[2].x = 0; // src left bottom
  7918.      apts[2].y = 0; // src left bottom
  7919.      apts[3].x = SQUAREWIDTH - 1; // src rt top
  7920.      apts[3].y = SQUAREHEIGHT - 1; // src rt top
  7921.      apts[0].x = ColArray[0]; // tgt left bottom
  7922.      apts[0].y = RowArray[0]; // tgt left bottom
  7923.      apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  7924.      apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  7925.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  7926.     }
  7927.   else
  7928.    { // king side
  7929.      c = 5; // col f
  7930.      r = 0; // row 1
  7931.      apts[2].x = 0; // src left bottom
  7932.      apts[2].y = 0; // src left bottom
  7933.      apts[3].x = SQUAREWIDTH - 1; // src rt top
  7934.      apts[3].y = SQUAREHEIGHT - 1; // src rt top
  7935.      apts[0].x = ColArray[7]; // tgt left bottom
  7936.      apts[0].y = RowArray[0]; // tgt left bottom
  7937.      apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  7938.      apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  7939.      GpiSetBitmap(hpsMemory,BlackBitMap);
  7940.    }
  7941.   }
  7942.  else if (str[1] == '8') // black
  7943.   {
  7944.    bobcolor = black;
  7945.    if (tolower(str[2]) == 'c')
  7946.     { // queen side
  7947.      c = 3; // col d
  7948.      r = 7; // row 8
  7949.      apts[2].x = 0; // src left bottom
  7950.      apts[2].y = 0; // src left bottom
  7951.      apts[3].x = SQUAREWIDTH - 1; // src rt top
  7952.      apts[3].y = SQUAREHEIGHT - 1; // src rt top
  7953.      apts[0].x = ColArray[0]; // tgt left bottom
  7954.      apts[0].y = RowArray[7]; // tgt left bottom
  7955.      apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  7956.      apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  7957.      GpiSetBitmap(hpsMemory,BlackBitMap);
  7958.     }
  7959.   else
  7960.    { // king side
  7961.      c = 5; // col f
  7962.      r = 7; // row 8
  7963.      apts[2].x = 0; // src left bottom
  7964.      apts[2].y = 0; // src left bottom
  7965.      apts[3].x = SQUAREWIDTH - 1; // src rt top
  7966.      apts[3].y = SQUAREHEIGHT - 1; // src rt top
  7967.      apts[0].x = ColArray[7]; // tgt left bottom
  7968.      apts[0].y = RowArray[7]; // tgt left bottom
  7969.      apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  7970.      apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  7971.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  7972.    }
  7973.   }
  7974.  else // mistake
  7975.   {
  7976.    DosReleaseMutexSem(DrawSemaphore);
  7977.    return;
  7978.   }
  7979.  GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  7980.  apts2[2].x = 0; // src left bottom
  7981.  apts2[2].y = 0; // src left bottom
  7982.  apts2[3].x = BOBWIDTH - 1; // src rt top
  7983.  apts2[3].y = BOBHEIGHT - 1; // src rt top
  7984.  apts2[0].x = ColArray[c]; // tgt left bottom
  7985.  apts2[0].y = RowArray[r]; // tgt left bottom
  7986.  apts2[1].x = apts2[0].x + BOBWIDTH - 1; // tgt rt top
  7987.  apts2[1].y = apts2[0].y + BOBHEIGHT - 1; // tgt rt top
  7988.  TransBlit(TheBob[bobcolor][ROOKBOB],hwClientPS,hpsMemory,4L,(PPOINTL)apts2);
  7989.  DosReleaseMutexSem(DrawSemaphore);
  7990. }
  7991.  
  7992. void AnimEnPassant(str)
  7993. char *str;
  7994. {
  7995.  APIRET rcd;
  7996.  POINTL apts[4];
  7997.  int r,c,tmp1,tmp2;
  7998.  
  7999.  myEnPassant[opponent^1] = 0;
  8000. // in this case I have to remove the pawn directly behind or in front of me
  8001. // I made the EnPassant move, so I took his pawn
  8002. // if I am white it is in the row one prior to mine me
  8003. // if I am black it is in the row one in front of mine
  8004.  if (opponent == white) // I am white
  8005.   {
  8006.    if (str[3] != '6')
  8007.     {
  8008.      return;
  8009.     }
  8010.    r = 4; // row 5
  8011.    c = tolower(str[2]) - 'a';
  8012.   }
  8013.  else
  8014.   {
  8015.    if (str[3] != '3')
  8016.     {
  8017.       return;
  8018.     }
  8019.    r = 3; // row 4
  8020.    c = tolower(str[2]) - 'a';
  8021.   }
  8022.  if ((c < 0)||(c > 7))
  8023.   return;
  8024.  tmp1 = r & 1;
  8025.  tmp2 = c & 1;
  8026.  apts[2].x = 0; // src left bottom
  8027.  apts[2].y = 0; // src left bottom
  8028.  apts[3].x = SQUAREWIDTH - 1; // src rt top
  8029.  apts[3].y = SQUAREHEIGHT - 1; // src rt top
  8030.  apts[0].x = ColArray[c]; // tgt left bottom
  8031.  apts[0].y = RowArray[r]; // tgt left bottom
  8032.  apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  8033.  apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  8034.  rcd = DosRequestMutexSem(DrawSemaphore,2000);
  8035.  if (rcd)
  8036.   return;
  8037.  if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  8038.   {
  8039.     GpiSetBitmap(hpsMemory,WhiteBitMap);
  8040.   }
  8041.  else
  8042.   {
  8043.    GpiSetBitmap(hpsMemory,BlackBitMap);
  8044.   }
  8045.  GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  8046.  DosReleaseMutexSem(DrawSemaphore);
  8047. }
  8048.  
  8049.  
  8050. void AnimateAmigaMove(str,piece)
  8051. char *str;
  8052. char piece; /* black are upper case pieces, white lower case */
  8053. {
  8054.  int side;
  8055.  int tmp1,tmp2;
  8056.  int srow,scol,erow,ecol,incrx,incry,i;
  8057.  POINTL apts[4];
  8058.  APIRET rc;
  8059.  long mpiece;
  8060.  
  8061.  
  8062.  if ((piece == ' ')||(flag.quit))
  8063.   return;
  8064.  mpiece = piece;
  8065.  if (!MouseDropped)
  8066.   {
  8067.    scol = str[0] - 'a';
  8068.    srow = str[1] - '1';
  8069.    ecol = str[2] - 'a';
  8070.    erow = str[3] - '1';
  8071.    tmp1 = srow & 1;
  8072.    tmp2 = scol & 1;
  8073.  
  8074.    rc = DosRequestMutexSem(DrawSemaphore,3000);
  8075.    if (rc)
  8076.     return;
  8077.    apts[2].x = 0; // src left bottom    
  8078.    apts[2].y = 0; // src left bottom
  8079.    apts[3].x = SQUAREWIDTH - 1; // src rt top
  8080.    apts[3].y = SQUAREHEIGHT - 1; // src rt top
  8081.    apts[0].x = ColArray[scol]; // tgt left bottom
  8082.    apts[0].y = RowArray[srow]; // tgt left bottom
  8083.    apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  8084.    apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  8085.    if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  8086.     {
  8087.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  8088.     }
  8089.        else
  8090.     {
  8091.      GpiSetBitmap(hpsMemory,BlackBitMap);
  8092.     }
  8093.    GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  8094.  
  8095.    tmp1 = erow & 1;
  8096.    tmp2 = ecol & 1;
  8097.    apts[2].x = 0; // src left bottom
  8098.    apts[2].y = 0; // src left bottom
  8099.    apts[3].x = SQUAREWIDTH - 1; // src rt top
  8100.    apts[3].y = SQUAREHEIGHT - 1; // src rt top
  8101.    apts[0].x = ColArray[ecol]; // tgt left bottom
  8102.    apts[0].y = RowArray[erow]; // tgt left bottom
  8103.    apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  8104.    apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  8105.    if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  8106.     {
  8107.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  8108.     }
  8109.        else
  8110.     {
  8111.      GpiSetBitmap(hpsMemory,BlackBitMap);
  8112.     }
  8113.    GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  8114.    DosReleaseMutexSem(DrawSemaphore);
  8115.    LoadBobImage(mpiece);
  8116.    TheBob[CurrBobColor][CurrBobIndex]->XPos = ColArray[scol];
  8117.    TheBob[CurrBobColor][CurrBobIndex]->YPos = RowArray[srow];
  8118.    AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  8119.    DrawGList();
  8120.    incry = (RowArray[erow] - RowArray[srow])/8;
  8121.    incrx = (ColArray[ecol] - ColArray[scol])/8;
  8122.    for(i=0;i<8;i++)
  8123.     {
  8124.      if (i == 7)
  8125.       {
  8126.        TheBob[CurrBobColor][CurrBobIndex]->XPos = ColArray[ecol];
  8127.        TheBob[CurrBobColor][CurrBobIndex]->YPos = RowArray[erow];
  8128.       }
  8129.      else
  8130.       {
  8131.        TheBob[CurrBobColor][CurrBobIndex]->XPos += incrx;
  8132.        TheBob[CurrBobColor][CurrBobIndex]->YPos += incry;
  8133.       }
  8134.      DrawGList();
  8135.     }
  8136.    RemBobNR(TheBob[CurrBobColor][CurrBobIndex]); // do not erase when removing it!
  8137.    if (piece >= 'a')
  8138.     {
  8139.      mpiece = 'r';
  8140.      srow = 0;
  8141.      erow = 0;
  8142.      side = white;
  8143.      if (str[2] == 'g') /* king side white */
  8144.       {
  8145.        scol = 7;
  8146.        ecol = 5;
  8147.       }
  8148.      else
  8149.       {
  8150.        ecol = 3;
  8151.        scol = 0;
  8152.       }
  8153.     }
  8154.    else
  8155.     {
  8156.      mpiece = 'R';
  8157.      srow = 7;
  8158.      erow = 7;
  8159.      side = black;
  8160.      if (str[2] == 'g') /* king side black */
  8161.       {
  8162.        scol = 7;
  8163.        ecol = 5;
  8164.       }
  8165.      else
  8166.       {
  8167.        ecol = 3;
  8168.        scol = 0;
  8169.       }
  8170.     }
  8171.    if (Castled[side])
  8172.     {
  8173.      Castled[side] = 0;
  8174.      tmp1 = srow & 1;
  8175.      tmp2 = scol & 1;
  8176.  
  8177.      rc = DosRequestMutexSem(DrawSemaphore,3000);
  8178.      if (rc)
  8179.       return;
  8180.      apts[2].x = 0; // src left bottom
  8181.      apts[2].y = 0; // src left bottom
  8182.      apts[3].x = SQUAREWIDTH - 1; // src rt top
  8183.      apts[3].y = SQUAREHEIGHT - 1; // src rt top
  8184.      apts[0].x = ColArray[scol]; // tgt left bottom
  8185.      apts[0].y = RowArray[srow]; // tgt left bottom
  8186.      apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  8187.      apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  8188.      if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  8189.     {
  8190.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  8191.     }
  8192.        else
  8193.     {
  8194.      GpiSetBitmap(hpsMemory,BlackBitMap);
  8195.     }
  8196.      GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  8197.      DosReleaseMutexSem(DrawSemaphore);
  8198.      LoadBobImage(mpiece);
  8199.      TheBob[CurrBobColor][CurrBobIndex]->XPos = ColArray[scol];
  8200.      TheBob[CurrBobColor][CurrBobIndex]->YPos = RowArray[srow];
  8201.      AddBob(TheBob[CurrBobColor][CurrBobIndex]);
  8202.      DrawGList();
  8203.      incry = (RowArray[erow] - RowArray[srow])/8;
  8204.      incrx = (ColArray[ecol] - ColArray[scol])/8;
  8205.      for(i=0;i<8;i++)
  8206.       {
  8207.        if (i == 7)
  8208.     {
  8209.      TheBob[CurrBobColor][CurrBobIndex]->XPos = ColArray[ecol];
  8210.      TheBob[CurrBobColor][CurrBobIndex]->YPos = RowArray[erow];
  8211.     }
  8212.        else
  8213.     {
  8214.      TheBob[CurrBobColor][CurrBobIndex]->XPos += incrx;
  8215.      TheBob[CurrBobColor][CurrBobIndex]->YPos += incry;
  8216.     }
  8217.        DrawGList();
  8218.       }
  8219.      RemBobNR(TheBob[CurrBobColor][CurrBobIndex]);
  8220.     }
  8221.    else /* check EnPassant */
  8222.     {
  8223.      side ^= 1;
  8224.      if (myEnPassant[side])
  8225.       {
  8226.        myEnPassant[side] = 0;
  8227.        scol = str[2] - 'a';
  8228.        if (str[3] == '3') /* white is removed from bd at 4*/
  8229.     {
  8230.      srow = 3;
  8231.     }
  8232.        else /* black is removed at pos 5 */
  8233.     {
  8234.      srow = 4;
  8235.     }
  8236.        tmp1 = srow & 1;
  8237.        tmp2 = scol & 1;
  8238.        rc = DosRequestMutexSem(DrawSemaphore,3000);
  8239.        if (rc)
  8240.     return;
  8241.        apts[2].x = 0; // src left bottom
  8242.        apts[2].y = 0; // src left bottom
  8243.        apts[3].x = SQUAREWIDTH - 1; // src rt top
  8244.        apts[3].y = SQUAREHEIGHT - 1; // src rt top
  8245.        apts[0].x = ColArray[scol]; // tgt left bottom
  8246.        apts[0].y = RowArray[srow]; // tgt left bottom
  8247.        apts[1].x = apts[0].x + SQUAREWIDTH - 1; // tgt rt top
  8248.        apts[1].y = apts[0].y + SQUAREHEIGHT - 1; // tgt rt top
  8249.        if (((!tmp1) && (!tmp2)) || ((tmp1)&&(tmp2)))
  8250.     {
  8251.      GpiSetBitmap(hpsMemory,WhiteBitMap);
  8252.     }
  8253.        else
  8254.     {
  8255.      GpiSetBitmap(hpsMemory,BlackBitMap);
  8256.     }
  8257.        GpiBitBlt(hwClientPS,hpsMemory,4,(PPOINTL)apts,ROP_SRCCOPY,BBO_IGNORE);
  8258.        DosReleaseMutexSem(DrawSemaphore);
  8259.       }
  8260.     }
  8261.   } // !MOUSE DROPPED
  8262. }
  8263.  
  8264.  
  8265. #ifdef AMIGA
  8266. void GetTimeString(str)
  8267. char *str;
  8268. {
  8269. }
  8270. #endif
  8271.  
  8272.  
  8273.  
  8274. char  *ColorStr[2];
  8275. char    *CP[CPSIZE];
  8276. /*
  8277.  * In a networked enviroment gnuchess might be compiled on different hosts
  8278.  * with different random number generators, that is not acceptable if they
  8279.  * are going to share the same transposition table.
  8280.  */
  8281.  
  8282. unsigned int urand (void);
  8283.  
  8284.  
  8285. unsigned long  hashkey, hashbd;
  8286. #ifdef LONGINTS2
  8287. struct hashval   hashcode[2][7][64];
  8288. #else
  8289. struct hashval  hashcode[2][7][64];
  8290. #endif
  8291.  
  8292. #ifdef CACHE
  8293. #ifdef ttblsz
  8294. struct hashentry *ttable[2];
  8295. unsigned int  ttblsize=ttblsz;
  8296. #endif
  8297.  
  8298. #else
  8299.  
  8300. #ifdef ttblsz
  8301. struct hashentry    ttable[2][vttblsz + MAXrehash];
  8302. unsigned int  ttblsize=ttblsz;
  8303. #endif
  8304.  
  8305. #endif
  8306.  
  8307. char    savefile[128] = "";
  8308. char    listfile[128] = "";
  8309. #ifdef HISTORY
  8310. unsigned char    history[32768];
  8311. #endif
  8312. INTSIZE  rpthash[2][256];
  8313. struct leaf    Tree[TREE];
  8314. struct leaf   *root;
  8315. INTSIZE  TrPnt[MAXDEPTH];
  8316. INTSIZE  PieceList[2][64], PawnCnt[2][8];
  8317. INTSIZE  castld[2], Mvboard[64];
  8318. INTSIZE  svalue[64];
  8319. struct flags  flag;
  8320. INTSIZE  opponent, computer, WAwindow, WBwindow, BAwindow, BBwindow, dither, INCscore;
  8321. long  ResponseTime, ExtraTime, MaxResponseTime, et, et0, time0, ft;
  8322. long  GenCnt, NodeCnt, ETnodes, EvalNodes, HashCnt, HashAdd, FHashCnt, FHashAdd, HashCol,
  8323.  THashCol, filesz;
  8324. long  replus, reminus;
  8325. INTSIZE  HashDepth = HASHDEPTH, HashMoveLimit = HASHMOVELIMIT;
  8326. INTSIZE  player, xwndw, rehash;
  8327. struct GameRec  GameList[MAXMOVES + MAXDEPTH];
  8328. INTSIZE  Sdepth, GameCnt, Game50, MaxSearchDepth;
  8329. INTSIZE  epsquare, contempt;
  8330. int  Book;
  8331. struct TimeControlRec  TimeControl;
  8332. INTSIZE  TCflag, TCmoves, TCminutes, TCseconds, OperatorTime;
  8333. INTSIZE  XCmoves[3], XCminutes[3], XCseconds[3], XC, XCmore;
  8334. const INTSIZE  otherside[3] =
  8335. {black, white, neutral};
  8336. unsigned INTSIZE  hint;
  8337. INTSIZE int  TOflag;           /* force search re-init if we backup search */
  8338.  
  8339. INTSIZE  mtl[2], pmtl[2], hung[2];
  8340. INTSIZE  Pindex[64];
  8341. INTSIZE  PieceCnt[2];
  8342. INTSIZE  FROMsquare, TOsquare;
  8343. INTSIZE  HasKnight[2], HasBishop[2], HasRook[2], HasQueen[2];
  8344. INTSIZE  ChkFlag[MAXDEPTH], CptrFlag[MAXDEPTH], PawnThreat[MAXDEPTH];
  8345. INTSIZE  Pscore[MAXDEPTH], Tscore[MAXDEPTH];
  8346. const INTSIZE  qrook[3] =
  8347. {0, 56, 0};
  8348. const INTSIZE  krook[3] =
  8349. {7, 63, 0};
  8350. const INTSIZE  kingP[3] =
  8351. {4, 60, 0};
  8352. const INTSIZE  rank7[3] =
  8353. {6, 1, 0};
  8354. const INTSIZE  sweep[8] =
  8355. {false, false, false, true, true, true, false, false};
  8356. unsigned INTSIZE  killr0[MAXDEPTH], killr1[MAXDEPTH];
  8357. unsigned INTSIZE  killr2[MAXDEPTH], killr3[MAXDEPTH];
  8358. unsigned INTSIZE  PV, SwagHt, Swag0, Swag1, Swag2, Swag3, Swag4;
  8359.  
  8360. #ifdef USE_SIDEBIT
  8361. unsigned INTSIZE  sidebit;
  8362. #endif
  8363.  
  8364. #ifdef KILLT
  8365. INTSIZE    killt[0x4000];
  8366. #endif
  8367. const INTSIZE  value[7] =
  8368. {0, valueP, valueN, valueB, valueR, valueQ, valueK};
  8369. const INTSIZE  control[7] =
  8370. {0, ctlP, ctlN, ctlB, ctlR, ctlQ, ctlK};
  8371. INTSIZE  stage, stage2, Developed[2];
  8372. FILE  *hashfile;
  8373. unsigned int  starttime;
  8374. INTSIZE int  ahead = true, hash = true;
  8375.  
  8376. #if defined CHESSTOOL || defined XBOARD
  8377. void
  8378. TerminateChess (int sig)
  8379. {
  8380.   ExitChess();
  8381. }
  8382. #endif
  8383.  
  8384. int  timeopp[MINGAMEIN], timecomp[MINGAMEIN];
  8385. int  compptr, oppptr;
  8386.  
  8387. inline void
  8388. TimeCalc ()
  8389. {
  8390. /* adjust number of moves remaining in gamein games */
  8391.   int increment = 0;
  8392.   int topsum = 0;
  8393.   int tcompsum = 0;
  8394.   int me,him;
  8395.   int i;
  8396. /* dont do anything til you have enough numbers */
  8397.   if (GameCnt < (MINGAMEIN * 2)) return;
  8398. /* calculate average time in sec for last MINGAMEIN moves */
  8399.   for (i = 0; i < MINGAMEIN; i++)
  8400.     {
  8401.       tcompsum += timecomp[i];
  8402.       topsum += timeopp[i];
  8403.     }
  8404.   topsum /= (100 * MINGAMEIN);
  8405.   tcompsum /= (100 * MINGAMEIN);
  8406. /* if I have less time than opponent add another move */
  8407.     me = TimeControl.clock[computer]/100; 
  8408.     him = TimeControl.clock[opponent]/100;
  8409.     if(me < him) increment += 2;
  8410. /* if I am losing more time with each move add another */
  8411.   /*if ( !((me - him) > 60) && tcompsum > topsum) increment++;*/
  8412.   if ( tcompsum > topsum) increment +=2;
  8413. /* but dont let moves go below MINMOVES */
  8414.   else if (TimeControl.moves[computer] < MINMOVES && !increment) increment++;
  8415. /* if I am doing really well use more time per move */
  8416.   else if (me > him && tcompsum < topsum) increment = -1;
  8417.   TimeControl.moves[computer] += increment;
  8418. }
  8419.  
  8420.  
  8421. /* hmm.... shouldn`t main be moved to the interface routines */
  8422. void main (argc,argv)
  8423. int argc;
  8424. char *argv[];
  8425. {
  8426.  // char cstring[40];
  8427.   char *xwin = 0;
  8428.   char *Lang = NULL;
  8429.   int l,src_row,src_col,dest_row,dest_col,piece;
  8430.  
  8431.  if (argc > 1)
  8432.   {
  8433.    if ((!stricmp(argv[1],"max"))||(!stricmp(argv[1],"maxi")))
  8434.     {
  8435.       ForceMax = 1;
  8436.     }
  8437.   else
  8438.     {
  8439.      ForceMax = 0;
  8440.     }
  8441.    if (!stricmp(argv[1],"mini"))
  8442.     {
  8443.       ForceMini = 1;
  8444.     }
  8445.   else
  8446.     {
  8447.      ForceMini = 0;
  8448.     }
  8449.    if ((!stricmp(argv[1],"micro"))||(!stricmp(argv[1],"baby")))
  8450.     {
  8451.       ForceMicro = 1;
  8452.     }
  8453.   else
  8454.     {
  8455.      ForceMicro = 0;
  8456.     }
  8457.   }
  8458. #ifdef AMIGA
  8459.  int tmpargcnt;
  8460.  struct WBStartup *startmsg;
  8461.  struct ExecBase **execbaseptr=(struct ExecBase **)4L;
  8462.  UWORD cpuid;
  8463.  struct ExecBase *execbase;
  8464.  BPTR fp;
  8465.  APTR tempxx;
  8466.  struct WBArg *mywbptr;
  8467.  struct DiskObject *dob;
  8468.  
  8469.  execbase = *execbaseptr;
  8470.  cpuid = execbase->AttnFlags;
  8471.  
  8472.  if (!(cpuid & AFF_68020))
  8473.   {
  8474.    exit(0);
  8475.   }
  8476.  gfxversion = GfxBase->LibNode.lib_Version;
  8477.  if (gfxversion < 37)
  8478.   exit(-1);
  8479.  if (!aargc)
  8480.   {
  8481.    startmsg = (struct WBStartup *)aargv;
  8482.    mywbptr = startmsg->sm_ArgList; 
  8483.    if (dob = GetDiskObject (mywbptr->wa_Name))
  8484.     {
  8485.      xwin = FindToolType(dob->do_ToolTypes,"PRI");
  8486.      if (xwin)
  8487.       {
  8488.        procpri = xwin[0] - '0';
  8489.        if (procpri < 0)
  8490.     procpri = 0;
  8491.        if (procpri > 4)
  8492.     procpri = 4;
  8493.       }
  8494.      xwin = FindToolType(dob->do_ToolTypes,"COLORS");
  8495.      if (xwin)
  8496.       {
  8497.        if ((xwin[0] == '1')&&(xwin[1] == '6'))
  8498.     gfxversion = 37;
  8499.        else if ((xwin[0] == '6')&&(xwin[1] == '4'))
  8500.     FasterDisplay = 1;
  8501.       }
  8502.      xwin = FindToolType(dob->do_ToolTypes,"MONITOR");
  8503.      if (xwin)
  8504.       {
  8505.        if ((xwin[0] == '1')&&(xwin[1] == '5'))
  8506.     v15Khz = 1;
  8507.       }
  8508.      xwin = FindToolType(dob->do_ToolTypes,"FASTAGA");
  8509.      if (xwin)
  8510.       {
  8511.        if ((xwin[0] == '1')||(xwin[0] == 'O')||(xwin[0] == 'o'))
  8512.     FasterDisplay = 1;
  8513.       }
  8514.      xwin = FindToolType(dob->do_ToolTypes,"SUPER72");
  8515.      if (xwin)
  8516.       {
  8517.        if ((xwin[0] == '1')||(xwin[0] == 'O')||(xwin[0] == 'o'))
  8518.     Super72 = 1;
  8519.       }
  8520.      xwin = FindToolType(dob->do_ToolTypes,"RTG");
  8521.      if (xwin)
  8522.       {
  8523.        if ((xwin[0] == '1')||(xwin[0] == 'O')||(xwin[0] == 'o'))
  8524.     RTG = 1;
  8525.       }
  8526. //     xwin = FindToolType(dob->do_ToolTypes,"PICASSO");
  8527. //     if (xwin)
  8528. //      {
  8529. //       if ((xwin[0] == '1')||(xwin[0] == 'O')||(xwin[0] == 'o'))
  8530. //        Picasso = 1;
  8531. //      }
  8532.      xwin = FindToolType(dob->do_ToolTypes,"NO_BOBS");
  8533.      if (xwin)
  8534.       {
  8535.        if ((xwin[0] == '1')||(xwin[0] == 'O')||(xwin[0] == 'o'))
  8536.     SYSTEM_BOBS = 0;
  8537.       }
  8538.      FreeDiskObject (dob);
  8539.     }
  8540.    xwin = 0L;
  8541.   }
  8542.  else if (aargc > 1)
  8543.   {
  8544.    for(tmpargcnt=1;tmpargcnt<aargc;tmpargcnt++)
  8545.     {
  8546.      if (!(strcmp(aargv[tmpargcnt],"16")))
  8547.       {
  8548.        gfxversion = 37;
  8549.       }
  8550.      else if (!(stricmp(aargv[tmpargcnt],"Super72")))
  8551.       {
  8552.        Super72 = 1;
  8553.       }
  8554.      else if (!(stricmp(aargv[tmpargcnt],"RTG")))
  8555.       {
  8556.        RTG = 1;
  8557.       }
  8558.      else if (!(stricmp(aargv[tmpargcnt],"NOBOBS")))
  8559.       {
  8560.        SYSTEM_BOBS = 0;
  8561.       }
  8562.      else if (!(stricmp(aargv[tmpargcnt],"15KHZ")))
  8563.       {
  8564.        v15Khz = 1;
  8565.       }
  8566. //     else if (!(stricmp(aargv[tmpargcnt],"PICASSO")))
  8567. //      {
  8568. //       Picasso = 1;
  8569. //      }
  8570.      else if ((!(stricmp(aargv[tmpargcnt],"FASTAGA")))||((!(strcmp(aargv[tmpargcnt],"64")))))
  8571.       {
  8572.        FasterDisplay = 1;
  8573.       }
  8574.      else if (strcmp(aargv[tmpargcnt],"256"))
  8575.       {
  8576.        procpri=atoi(aargv[tmpargcnt]);
  8577.        if (procpri < 0)
  8578.      procpri = 0;
  8579.        if (procpri > 4)
  8580.     procpri = 4;
  8581.       }
  8582.     }
  8583.   }
  8584.  if (gfxversion < 39)
  8585.   RTG = Super72 = 0;
  8586.  if (RTG)
  8587.   {
  8588.    FasterDisplay = 0;
  8589.    v15Khz = 0;
  8590.   }
  8591. // if (!RTG)
  8592. //  Picasso = 0;
  8593.  Delay(3L);
  8594.  myproc = (struct Process *)FindTask(0L);
  8595.  tempxx = myproc->pr_WindowPtr;
  8596.  Delay(3L);
  8597.  myproc->pr_WindowPtr = (APTR)-1L;
  8598.  if (!(fp = Open("uchess:uchess.lang",MODE_OLDFILE)))
  8599.   {
  8600.    system("Assign >nil: uchess: \"\"");
  8601.   }
  8602.  else
  8603.   Close(fp);
  8604.  myproc->pr_WindowPtr = tempxx;
  8605. #endif // AMIGA
  8606.  
  8607.   
  8608. #ifdef ttblsz
  8609.   ttblsize = ttblsz;
  8610.   rehash = -1;
  8611. #endif /* ttblsz */
  8612.   gsrand (starttime = ((unsigned int) time (0L)));      /* init urand */
  8613.   flag.easy = 0; // was 0
  8614. #ifndef AMIGA
  8615. //  if (argc > 2)
  8616. //    {
  8617. //      if (argv[1][0] == '-' && argv[1][1] == 'L')
  8618. //        {
  8619. //          Lang = argv[2];
  8620. //          argv += 2;
  8621. //          argc -= 2;
  8622. //        }
  8623. //    }
  8624. #endif
  8625.   InitConst (Lang);
  8626.   ColorStr[0] = CP[118];
  8627.   ColorStr[1] = CP[119];
  8628.  
  8629. #ifndef AMIGA
  8630. #ifdef IWANTTHIS
  8631.   while (argc > 1 && ((argv[1][0] == '-') || (argv[1][0] == '+')))
  8632.     {
  8633.       switch (argv[1][1])
  8634.     {
  8635.     case 'a':
  8636.       ahead = ((argv[1][0] == '-') ? false : true);
  8637.       break;
  8638.     case 'h':
  8639.       hash = ((argv[1][0] == '-') ? false : true);
  8640.       break;
  8641.     case 's':
  8642.       argc--;
  8643.       argv++;
  8644.       if (argc > 1)
  8645.         strcpy (savefile, argv[1]);
  8646.       break;
  8647.     case 'l':
  8648.       argc--;
  8649.       argv++;
  8650.       if (argc > 1)
  8651.         strcpy (listfile, argv[1]);
  8652.       break;
  8653.  
  8654. #if ttblsz
  8655.     case 'r':
  8656.       if (argc > 2)
  8657.         rehash = atoi (argv[2]);
  8658.       argc--;
  8659.       argv++;
  8660.       if (rehash > MAXrehash)
  8661.         rehash = MAXrehash;
  8662.       break;
  8663.     case 'T':
  8664.       if (argc > 2)
  8665.         ttblsize = atoi (argv[2]);
  8666.       argc--;
  8667.       argv++;
  8668.       if (ttblsize > 0 && ttblsize < 24)
  8669.         ttblsize = (1 << ttblsize);
  8670.       else
  8671.         ttblsize = ttblsz;
  8672.       break;
  8673. #ifdef HASHFILE
  8674.     case 't':               /* create or test persistent transposition
  8675.                  * table */
  8676.       hashfile = fopen (HASHFILE, RWA_ACC);
  8677.       if (hashfile)
  8678.         {
  8679.           fseek (hashfile, 0L, SEEK_END);
  8680.           filesz = (ftell (hashfile) / sizeof (struct fileentry)) - 1;
  8681.         }
  8682.       if (hashfile != NULL)
  8683.         {
  8684.           long i, j;
  8685.           int nr[MAXDEPTH];
  8686.           struct fileentry n;
  8687.  
  8688.           /*ShowMessage (CP[49]);*/
  8689.           for (i = 0; i < MAXDEPTH; i++)
  8690.         nr[i] = 0;
  8691.           fseek (hashfile, 0L, SEEK_END);
  8692.           i = ftell (hashfile) / sizeof (struct fileentry);
  8693.           fseek (hashfile, 0L, SEEK_SET);
  8694.           for (j = 0; j < i + 1; j++)
  8695.         {
  8696.           fread (&n, sizeof (struct fileentry), 1, hashfile);
  8697.           if (n.depth)
  8698.             {
  8699.               nr[n.depth]++;
  8700.               nr[0]++;
  8701.             }
  8702.         }
  8703.           sprintf (astr,CP[109],
  8704.               nr[0], i);
  8705.           /*ShowMessage(astr);*/
  8706.           for (j = 1; j < MAXDEPTH; j++)
  8707.            /*
  8708.         printf ("%d ", nr[j]);
  8709.           printf ("\n")*/;
  8710.         }
  8711.       return 0;
  8712.     case 'c':               /* create or test persistent transposition
  8713.                  * table */
  8714.       if (argc > 2)
  8715.         filesz = atoi (argv[2]);
  8716.       if (filesz > 0 && filesz < 24)
  8717.         filesz = (1 << filesz) - 1 + MAXrehash;
  8718.       else
  8719.         filesz = Deffilesz + MAXrehash;
  8720.       if ((hashfile = fopen (HASHFILE, RWA_ACC)) == NULL)
  8721.         hashfile = fopen (HASHFILE, WA_ACC);
  8722.       if (hashfile != NULL)
  8723.         {
  8724.           long j;
  8725.           struct fileentry n;
  8726.  
  8727.           /*printf (CP[66]);*/
  8728.           for (j = 0; j < 32; j++)
  8729.         n.bd[j] = 0;
  8730.           n.f = n.t = 0;
  8731.           n.flags = 0;
  8732.           n.depth = 0;
  8733.           n.sh = n.sl = 0;
  8734.           for (j = 0; j < filesz + 1; j++)
  8735.         fwrite (&n, sizeof (struct fileentry), 1, hashfile);
  8736.           fclose (hashfile);
  8737.         }
  8738.      /* else
  8739.         printf (CP[50], HASHFILE);*/
  8740.       return (0);
  8741. #endif /* HASHFILE */
  8742. #endif /* ttblsz */
  8743.     case 'x':
  8744.       xwin = &argv[1][2];
  8745.       break;
  8746.     case 'v':
  8747. /*        fprintf (stderr, CP[102], version, patchlevel);*/
  8748.       exit (1);
  8749.     default:
  8750.       /*fprintf (stderr, CP[113]);*/
  8751.       exit (1);
  8752.     }
  8753.       argv++;
  8754.       argc--;
  8755.     }
  8756. #endif // I want this all startup
  8757. #endif // ndef amiga
  8758.   XC = 0;
  8759.   MaxResponseTime = 0;
  8760. #if defined CHESSTOOL || defined XBOARD
  8761.   signal (SIGTERM, TerminateChess);
  8762.   TCflag = true;
  8763.   TCmoves = 40;
  8764.   TCminutes = 120;
  8765.   TCseconds = 0;
  8766.   TCadd = 0;
  8767.   OperatorTime = 0;
  8768. #else
  8769. /*  TCflag = false;*/
  8770. /*  OperatorTime = 0;*/
  8771.   TCflag = true;
  8772.   TCmoves = 60;
  8773.   TCminutes = 10;
  8774.   TCseconds = 0;
  8775.   OperatorTime = 0;
  8776. #endif
  8777. #ifdef IWANTHIS
  8778.   if (argc == 2)
  8779.     {
  8780.       char *p;
  8781.  
  8782.       MaxResponseTime = 100L*strtol(argv[1], &p, 10);
  8783.       if (*p == ':')
  8784.     MaxResponseTime = 60L*MaxResponseTime + 
  8785.         100L*strtol(++p, (char **) NULL, 10);
  8786.       TCflag = false;
  8787.       TCmoves = 0;
  8788.       TCminutes = 0;
  8789.       TCseconds = 0;
  8790.     }
  8791.   if (argc >= 3)
  8792.     {
  8793.       char *p;
  8794.       if (argc > 9)
  8795.     {
  8796.      /* printf ("%s\n", CP[220]);*/
  8797.       exit (1);
  8798.     }
  8799.       TCmoves = atoi (argv[1]);
  8800.       TCminutes = strtol (argv[2], &p, 10);
  8801.       if (*p == ':')
  8802.     TCseconds = strtol (p + 1, (char **) NULL, 10);
  8803.       else
  8804.     TCseconds = 0;
  8805.       TCflag = true;
  8806.       argc -= 3;
  8807.       argv += 3;
  8808.       while (argc > 1)
  8809.     {
  8810.       XCmoves[XC] = atoi (argv[0]);
  8811.       XCminutes[XC] = strtol (argv[1], &p, 10);
  8812.       if (*p == ':')
  8813.         XCseconds[XC] = strtol (p + 1, (char **) NULL, 10);
  8814.       else
  8815.         XCseconds[XC] = 0;
  8816.       if (XCmoves[XC] && (XCminutes[XC] || XCseconds[XC]))
  8817.         XC++;
  8818.       else
  8819.         {
  8820.           /*printf (CP[220]);*/
  8821.           exit (1);
  8822.         }
  8823.       argc -= 2;
  8824.       argv += 2;
  8825.     }
  8826.       if (argc)
  8827.     {
  8828.       /*printf ("%s\n", CP[220]);*/
  8829.       exit (1);
  8830.     }
  8831.     }
  8832. #endif /* IWANTHIS */
  8833. #ifdef AMIGA
  8834.  (void)SetTaskPri((struct Task *)myproc,procpri);
  8835.  Delay(3L);
  8836.  if (!AmigaStartup())
  8837.   {
  8838.    exit(2);
  8839.   }
  8840. #else
  8841.  if (!(PM_Startup()))
  8842.   {
  8843.    exit(2);
  8844.   }
  8845. #endif
  8846.   Initialize ();
  8847. #ifndef CACHE
  8848. #ifdef ttblsz
  8849.   Initialize_ttable ();
  8850. #endif /* ttblsz */
  8851. #endif
  8852.   Initialize_dist ();
  8853.   Initialize_moves ();
  8854.   FirstTime = 1;
  8855.   NewGame ();
  8856.   flag.easy = 0; // I want to start with thinking on so should be 0
  8857.   flag.hash = hash;
  8858.   if (xwin)
  8859.     xwndw = atoi (xwin);
  8860.  
  8861.   hashfile = NULL;
  8862. #if ttblsz
  8863. #ifdef HASHFILE
  8864.   hashfile = fopen (HASHFILE, RWA_ACC);
  8865.   if (hashfile)
  8866.     {
  8867.       fseek (hashfile, 0L, SEEK_END);
  8868.       filesz = ftell (hashfile) / sizeof (struct fileentry) - 1;
  8869.     }
  8870. #if !defined CHESSTOOL && !defined XBOARD
  8871.   else
  8872.     ShowMessage (CP[98]);
  8873. #endif
  8874. #endif /* HASHFILE */
  8875. #endif /* ttblsz */
  8876. #ifdef AMIGA
  8877.  SetMenuStrip(wG,&MenuList1);   /* attach any Menu */
  8878.  MenuStripSet = 1;
  8879.  EnableMoveNow();
  8880. #endif
  8881.  
  8882.   while (!(flag.quit))
  8883.     {
  8884.       oppptr = (oppptr + 1) % MINGAMEIN;
  8885.       if (flag.bothsides && !flag.mate)
  8886.        {
  8887.     //SetPointer(wG,myPointer,PTRHEIGHT,0x10L,0L,0L);
  8888.     SelectMove (opponent, 1);
  8889.         MoveMem128(color,amigacolor);
  8890.         MoveMem128(board,amigaboard);
  8891.         DosSleep(350);
  8892.        }
  8893.       else
  8894.     {
  8895.      InputCommand ();
  8896.     }
  8897.  
  8898.       if (opponent == black)
  8899.     if (flag.gamein || TCadd)
  8900.       {
  8901.         TimeCalc ();
  8902.       }
  8903.     else if (TimeControl.moves[opponent] == 0)
  8904.       {
  8905.         if (XC)
  8906.           if (XCmore < XC)
  8907.         {
  8908.           TCmoves = XCmoves[XCmore];
  8909.           TCminutes = XCminutes[XCmore];
  8910.           TCseconds = XCseconds[XCmore];
  8911.           XCmore++;
  8912.         }
  8913.         SetTimeControl2 (opponent);
  8914.       }
  8915.  
  8916.       compptr = (compptr + 1) % MINGAMEIN;
  8917.  
  8918.  
  8919.       if (SupervisorMode)
  8920.        {
  8921.       computer = computer ^ 1;
  8922.       opponent = opponent ^ 1;
  8923.       xwndw = (computer == white) ? WXWNDW : BXWNDW;
  8924.       flag.force = false;
  8925.       Sdepth = 0;
  8926.        }
  8927.       else if (!(flag.quit || flag.mate || flag.force))
  8928.     {
  8929.       //SetPointer(wG,myPointer,PTRHEIGHT,0x10L,0L,0L);
  8930.       SelectMove (computer, 1);
  8931.           if (Mate)
  8932.           {
  8933.            src_col = tolower(mvstr[0][0]) - 'a';
  8934.            src_row = mvstr[0][1] - '1';
  8935.            dest_col = tolower(mvstr[0][2]) - 'a';
  8936.            dest_row = mvstr[0][3] - '1';
  8937.            if ((src_col >= 0) && (src_col <= 7) && (src_row >= 0) && (src_row <= 7) &&
  8938.               (dest_col >= 0) && (dest_col <= 7) && (dest_row >= 0) && (dest_row <= 7))
  8939.             { // in bounds
  8940.              l = ((flag.reverse) ? locn (7 - src_row, 7 - src_col) : locn (src_row, src_col));
  8941.              piece = board[l]; /* white are lower case pieces */
  8942.              board[l] = 0;
  8943.              color[l] = neutral;
  8944.              l = ((flag.reverse) ? locn (7 - dest_row, 7 - dest_col) : locn (dest_row, dest_col));
  8945.              if ((piece == pawn)&&((dest_row == 7)||(!dest_row)))
  8946.               piece = queen;
  8947.              board[l] = piece;
  8948.              color[l] = computer;
  8949.              MoveMem128(board,amigaboard);
  8950.              MoveMem128(color,amigacolor);
  8951.              DrawAmigaBoard();
  8952.            } // in bounds
  8953.          } // mate
  8954.       if (computer == black)
  8955.         if (flag.gamein)
  8956.           {
  8957.         TimeCalc ();
  8958.           }
  8959.         else if (TimeControl.moves[computer] == 0)
  8960.           {
  8961.         if (XC)
  8962.           if (XCmore < XC)
  8963.             {
  8964.               TCmoves = XCmoves[XCmore];
  8965.               TCminutes = XCminutes[XCmore];
  8966.               TCseconds = XCseconds[XCmore];
  8967.               XCmore++;
  8968.             }
  8969.         SetTimeControl2 (computer);
  8970.           }
  8971.     }
  8972.       if ((flag.mate)&&(!Mate)&&(!DrawnGame))
  8973.        ShowMessage("CheckMate");
  8974.       if (Mate)
  8975.        {
  8976.     ShowMessage(MateString);
  8977.        }
  8978.       else if (DrawnGame)
  8979.        {
  8980.     ShowMessage("Draw..");
  8981.        }
  8982. #ifdef AMIGAWAY
  8983.       else if ((!flag.mate)&&(PlayMode == 2)&&(!ResignOffered)&&(!flag.quit))
  8984.        {
  8985.     if (1)//(global_tmp_score < -950)
  8986.      {
  8987.       if (DoResign())
  8988.        {
  8989.         //ClearPointer(wG);
  8990.         flag.mate = true;
  8991.         flag.back = true;
  8992.         Mate = 1;
  8993.         ShowMessage("You Win!");
  8994.         ShowMessage("UChess Resigns");
  8995.        }
  8996.      }
  8997.        }
  8998. #endif // AMIGAWAY
  8999.     }
  9000. #if ttblsz
  9001. #ifdef HASHFILE
  9002.   if (hashfile)
  9003.     fclose (hashfile);
  9004. #endif /* HASHFILE */
  9005. #endif /* ttblsz */
  9006.  
  9007.   ExitChess ();
  9008. }
  9009.