Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

445 lines
11 KiB

  1. #include "sol.h"
  2. #include <io.h>
  3. #include <string.h>
  4. #include "assert.h"
  5. VSZASSERT
  6. #ifdef DEBUG
  7. MDBG rgmdbg[imdbgMax];
  8. WORD lvl = 0;
  9. INT imdbgCur = 0;
  10. VOID InitDebug()
  11. {
  12. INT imdbg;
  13. MDBG *pmdbg;
  14. for(imdbg = 0; imdbg < imdbgMax; imdbg++)
  15. {
  16. pmdbg = &rgmdbg[imdbg];
  17. pmdbg->pgmcol = NULL;
  18. pmdbg->lvl = 0;
  19. pmdbg->msg = 0xcccc;
  20. pmdbg->wp1 = 0xcccc;
  21. pmdbg->wp2 = 0xcccc;
  22. pmdbg->wResult = 0xcccc;
  23. }
  24. imdbgCur = 0;
  25. lvl = 0;
  26. }
  27. WORD ILogMsg(VOID *pgmcol, INT msg, WPARAM wp1, LPARAM wp2, BOOL fGm)
  28. {
  29. MDBG *pmdbg;
  30. WORD imdbgRet;
  31. Assert(FInRange(imdbgCur, 0, imdbgMax-1));
  32. pmdbg = &rgmdbg[imdbgCur];
  33. Assert(fGm == 0 || fGm == 1);
  34. pmdbg->pgmcol = pgmcol;
  35. pmdbg->msg = msg + (fGm << 15);
  36. pmdbg->wp1 = wp1;
  37. pmdbg->wp2 = wp2;
  38. pmdbg->wResult = 0xcccc;
  39. pmdbg->lvl = lvl;
  40. lvl++;
  41. imdbgRet = imdbgCur++;
  42. imdbgCur %= imdbgMax;
  43. Assert(FInRange(imdbgCur, 0, imdbgMax-1));
  44. return imdbgRet;
  45. }
  46. VOID LogMsgResult(INT imdbg, LRESULT wResult)
  47. {
  48. lvl--;
  49. Assert(FInRange(imdbg, 0, imdbgMax-1));
  50. rgmdbg[imdbg].wResult = wResult;
  51. }
  52. VOID WriteCrlf(INT fh)
  53. {
  54. _write(fh, TEXT("\x0d\n"), sizeof(TCHAR) * 2);
  55. }
  56. VOID WriteSz(INT fh, TCHAR *sz)
  57. {
  58. _write(fh, sz, lstrlen(sz));
  59. WriteCrlf(fh);
  60. }
  61. VOID WriteIField(INT fh, TCHAR *szField, INT_PTR ifld)
  62. {
  63. TCHAR szBuf[128];
  64. INT cch;
  65. _write(fh, szField, lstrlen(szField));
  66. _write(fh, TEXT(" = "), sizeof(TCHAR) *3);
  67. cch = CchDecodeInt(szBuf, ifld);
  68. _write(fh, szBuf, cch);
  69. WriteCrlf(fh);
  70. }
  71. VOID DumpCol(INT fh, COL *pcol)
  72. {
  73. INT icrd;
  74. MOVE *pmove;
  75. WriteCrlf(fh);
  76. WriteIField(fh, TEXT(">>> *pcol"), (INT_PTR) pcol);
  77. WriteIField(fh, TEXT("pcolcls->tcls"), pcol->pcolcls->tcls);
  78. WriteIField(fh, TEXT("icrdMac"), pcol->icrdMac);
  79. WriteIField(fh, TEXT("pmove"), (INT_PTR) pcol->pmove);
  80. if(pcol->pmove != NULL)
  81. {
  82. pmove = pcol->pmove;
  83. WriteIField(fh, TEXT("pmove->icrdSel"), pmove->icrdSel);
  84. WriteIField(fh, TEXT("pmove->ccrdSel"), pmove->ccrdSel);
  85. WriteIField(fh, TEXT("pmove->delHit.x"), pmove->delHit.dx);
  86. WriteIField(fh, TEXT("pmove->delHit.y"), pmove->delHit.dy);
  87. WriteIField(fh, TEXT("pmove->fHdc"), pmove->fHdc);
  88. WriteIField(fh, TEXT("pmove->dyCol"), pmove->dyCol);
  89. WriteIField(fh, TEXT("pmove->hdcScreen"), (INT_PTR)pmove->hdcScreen);
  90. WriteIField(fh, TEXT("pmove->hdcCol"), (INT_PTR)pmove->hdcCol);
  91. WriteIField(fh, TEXT("pmove->hbmColOld"), (INT_PTR)pmove->hbmColOld);
  92. WriteIField(fh, TEXT("pmove->hdcScreenSave"), (INT_PTR)pmove->hdcScreenSave);
  93. WriteIField(fh, TEXT("pmove->hbmScreenSaveOld"), (INT_PTR)pmove->hbmScreenSaveOld);
  94. WriteIField(fh, TEXT("pmove->hdcT"), (INT_PTR)pmove->hdcT);
  95. WriteIField(fh, TEXT("pmove->hbmT"), (INT_PTR)pmove->hbmT);
  96. }
  97. for(icrd = 0; icrd < pcol->icrdMac; icrd++)
  98. {
  99. WriteIField(fh, TEXT("\t-card "), icrd);
  100. WriteIField(fh, TEXT("\t cd"), pcol->rgcrd[icrd].cd);
  101. WriteIField(fh, TEXT("\t fUp"), pcol->rgcrd[icrd].fUp);
  102. WriteIField(fh, TEXT("\t pt.x"), pcol->rgcrd[icrd].pt.x);
  103. WriteIField(fh, TEXT("\t pt.y"), pcol->rgcrd[icrd].pt.y);
  104. }
  105. }
  106. VOID DumpGm(INT fh, GM *pgm)
  107. {
  108. INT icol;
  109. WriteIField(fh, TEXT("pgm"), (INT_PTR) pgm);
  110. WriteIField(fh, TEXT("udr.fAvail"), pgm->udr.fAvail);
  111. WriteIField(fh, TEXT("udr.sco"), pgm->udr.sco);
  112. WriteIField(fh, TEXT("udr.icol1"), pgm->udr.icol1);
  113. WriteIField(fh, TEXT("udr.icol2"), pgm->udr.icol2);
  114. WriteIField(fh, TEXT("udr.rgpcol[1]"), (INT_PTR) pgm->udr.rgpcol[1]);
  115. WriteIField(fh, TEXT("udr.rgpcol[2]"), (INT_PTR) pgm->udr.rgpcol[2]);
  116. WriteIField(fh, TEXT("fDealt"), pgm->fDealt);
  117. WriteIField(fh, TEXT("fWon"), pgm->fWon);
  118. WriteIField(fh, TEXT("fInput"), pgm->fInput);
  119. WriteIField(fh, TEXT("sco"), pgm->sco);
  120. WriteIField(fh, TEXT("iqsecScore"), pgm->iqsecScore);
  121. WriteIField(fh, TEXT("dqsecScore"), pgm->dqsecScore);
  122. WriteIField(fh, TEXT("ccrdDeal"), pgm->ccrdDeal);
  123. WriteIField(fh, TEXT("irep"), pgm->irep);
  124. WriteIField(fh, TEXT("ptMousePrev->x"), pgm->ptMousePrev.x);
  125. WriteIField(fh, TEXT("ptMousePrev->y"), pgm->ptMousePrev.y);
  126. WriteIField(fh, TEXT("fButtonDown"), pgm->fButtonDown);
  127. WriteIField(fh, TEXT("icolKbd"), pgm->icolKbd);
  128. WriteIField(fh, TEXT("icrdKbd"), pgm->icrdKbd);
  129. WriteIField(fh, TEXT("icolSel"), pgm->icolSel);
  130. WriteIField(fh, TEXT("icolHilight"), pgm->icolHilight);
  131. WriteIField(fh, TEXT("icolMac"), pgm->icolMac);
  132. WriteIField(fh, TEXT("icolMax"), pgm->icolMax);
  133. for(icol = 0; icol < pgm->icolMac; icol++)
  134. DumpCol(fh, pgm->rgpcol[icol]);
  135. }
  136. TCHAR *PchDecodeWp(TCHAR *pch, INT_PTR wp)
  137. {
  138. INT icol;
  139. if(pgmCur == NULL)
  140. return pch;
  141. if((GM *) wp == pgmCur)
  142. return PszCopy(TEXT("(pgmCur)"), pch);
  143. for(icol = 0; icol < pgmCur->icolMac; icol++)
  144. {
  145. if((struct _col *) wp == pgmCur->rgpcol[icol])
  146. {
  147. pch = PszCopy(TEXT("(col "), pch);
  148. pch += CchDecodeInt(pch, icol);
  149. *pch++ = TEXT(')');
  150. break;
  151. }
  152. }
  153. return pch;
  154. }
  155. VOID DumpRgmdbg(TCHAR *szFile, INT li)
  156. {
  157. OFSTRUCT of;
  158. INT fh;
  159. INT imdbg;
  160. USHORT lvl;
  161. MDBG *pmdbg;
  162. TCHAR szBuf[128];
  163. TCHAR *pch;
  164. if((fh = (OpenFile("sol.dbg", &of, OF_CREATE|OF_WRITE))) == -1)
  165. return;
  166. WriteSz(fh, TEXT("Assertion Failure"));
  167. WriteIField(fh, szFile, li);
  168. WriteSz(fh, szVer);
  169. WriteIField(fh, TEXT("Game #"), igmCur);
  170. WriteCrlf(fh);
  171. /* write game and col structs */
  172. if(pgmCur != NULL)
  173. DumpGm(fh, pgmCur);
  174. imdbg = imdbgCur;
  175. do
  176. {
  177. Assert(FInRange(imdbgCur, 0, imdbgMax-1));
  178. pmdbg = &rgmdbg[imdbg];
  179. Assert(pmdbg->lvl < 60);
  180. for(lvl = 0; lvl < pmdbg->lvl; lvl++)
  181. _write(fh, TEXT("\t"), 1);
  182. pch = PchDecodeWp(szBuf, (INT_PTR) pmdbg->pgmcol);
  183. pmdbg->msg &= 0x7fff;
  184. *pch++ = TEXT(' ');
  185. pch += CchDecodeInt(pch, pmdbg->msg);
  186. *pch++ = TEXT(',');
  187. *pch++ = TEXT(' ');
  188. pch += CchDecodeInt(pch, pmdbg->wp1);
  189. pch = PchDecodeWp(pch, pmdbg->wp1);
  190. *pch++ = TEXT(',');
  191. *pch++ = TEXT(' ');
  192. pch += CchDecodeInt(pch, pmdbg->wp2);
  193. pch = PchDecodeWp(pch, pmdbg->wp2);
  194. *pch++ = TEXT(' ');
  195. *pch++ = TEXT('-');
  196. *pch++ = TEXT('>');
  197. *pch++ = TEXT(' ');
  198. pch += CchDecodeInt(pch, pmdbg->wResult);
  199. _write(fh, szBuf, (int)(pch-szBuf));
  200. WriteCrlf(fh);
  201. imdbg--;
  202. if(imdbg < 0)
  203. imdbg = imdbgMax-1;
  204. Assert(FInRange(imdbg, 0, imdbgMax-1));
  205. } while(imdbg != imdbgCur);
  206. _close(fh);
  207. }
  208. /* Puts msg on bottom of screen. Useful because I don't have a debug console now */
  209. VOID DisplayMsg(TCHAR *sz, INT msgc, INT wp1, INT wp2)
  210. {
  211. INT y;
  212. INT x;
  213. HDC hdc;
  214. INT cch;
  215. TCHAR szInt[20];
  216. TEXTMETRIC tm;
  217. if(fScreenShots)
  218. return;
  219. x = 0;
  220. hdc = GetDC(hwndApp);
  221. GetTextMetrics(hdc, (LPTEXTMETRIC)&tm);
  222. y = 0;/* dyScreen - tm.tmHeight; */
  223. TextOut(hdc, x, y, TEXT(" "), 24);
  224. TextOut(hdc, x, y, sz, cch = lstrlen(sz));
  225. x += (cch+1) * tm.tmMaxCharWidth;
  226. cch = CchDecodeInt(szInt, msgc);
  227. TextOut(hdc, x, y, szInt, cch);
  228. x += (cch+1) * tm.tmAveCharWidth;
  229. cch = CchDecodeInt(szInt, wp1);
  230. TextOut(hdc, x, y, szInt, cch);
  231. x += (cch+1) * tm.tmAveCharWidth;
  232. cch = CchDecodeInt(szInt, wp2);
  233. TextOut(hdc, x, y, szInt, cch);
  234. x += (cch+1) * tm.tmAveCharWidth;
  235. ReleaseDC(hwndApp, hdc);
  236. }
  237. VOID PrintCardMacs(GM *pgm)
  238. {
  239. INT icol;
  240. TCHAR sz[20];
  241. INT cch;
  242. HDC hdc;
  243. hdc = GetDC(hwndApp);
  244. for(icol = 0; icol < pgm->icolMac; icol++)
  245. {
  246. cch = CchDecodeInt(sz, pgm->rgpcol[icol]->icrdMac);
  247. TextOut(hdc, 30 * icol, 10, sz, cch);
  248. }
  249. ReleaseDC(hwndApp, hdc);
  250. }
  251. INT_PTR APIENTRY GameNo(HWND hdlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
  252. {
  253. BOOL fTranslated;
  254. INT igmNext;
  255. if (iMessage == WM_COMMAND)
  256. {
  257. if( GET_WM_COMMAND_ID( wParam, lParam ) == IDOK )
  258. {
  259. igmNext = GetDlgItemInt(hdlg, ideGameNoEdit, &fTranslated, fFalse);
  260. if(fTranslated && igmNext >= 0)
  261. igmCur = igmNext;
  262. else
  263. {
  264. Error(TEXT("Invalid game number"));
  265. return fFalse;
  266. }
  267. }
  268. if(wParam == IDOK || wParam == IDCANCEL)
  269. EndDialog(hdlg, wParam == IDOK);
  270. return fTrue;
  271. }
  272. else if (iMessage == WM_INITDIALOG)
  273. {
  274. SetDlgItemInt(hdlg, ideGameNoEdit, igmCur, fFalse);
  275. return fTrue;
  276. }
  277. else
  278. return fFalse;
  279. }
  280. BOOL FSetGameNo()
  281. {
  282. BOOL fResult;
  283. if(fResult = (BOOL)DialogBox(hinstApp,
  284. MAKEINTRESOURCE(iddGameNo),
  285. hwndApp,
  286. GameNo))
  287. srand(igmCur);
  288. return fResult;
  289. }
  290. BOOL FValidCol(COL *pcol)
  291. {
  292. INT icol;
  293. if(pcol == NULL)
  294. return fFalse;
  295. for(icol = 0; icol < pgmCur->icolMax; icol++)
  296. {
  297. if(pcol == pgmCur->rgpcol[icol])
  298. {
  299. if(pcol->pcolcls == NULL)
  300. return fFalse;
  301. if(pcol->icrdMac > pcol->icrdMax)
  302. return fFalse;
  303. return fTrue;
  304. }
  305. }
  306. return fFalse;
  307. }
  308. TCHAR *vszFile;
  309. INT vli;
  310. TCHAR vszLi[32];
  311. INT_PTR APIENTRY AssertDlgProc(HANDLE hdlg, UINT wm, WPARAM wParam, LPARAM lParam)
  312. {
  313. switch(wm)
  314. {
  315. case WM_INITDIALOG:
  316. SetWindowText(GetDlgItem(hdlg, FILE), vszFile);
  317. CchDecodeInt(vszLi, vli);
  318. SetWindowText(GetDlgItem(hdlg, LINE), vszLi);
  319. CchDecodeInt(vszLi, igmCur);
  320. SetWindowText(GetDlgItem(hdlg, GAMENO), vszLi);
  321. /* SetWindowText(GetDlgItem(hdlg, SOLVERSION), szVer); */
  322. break;
  323. case WM_COMMAND:
  324. switch( GET_WM_COMMAND_ID( wParam, lParam ))
  325. {
  326. default:
  327. return fFalse;
  328. case IDOK:
  329. EndDialog(hdlg, 0);
  330. break;
  331. case EXIT:
  332. EndDialog(hdlg, 1);
  333. break;
  334. }
  335. break;
  336. default:
  337. return fFalse;
  338. }
  339. return fTrue;
  340. }
  341. VOID AssertFailed(TCHAR *szFile, INT li)
  342. {
  343. INT f;
  344. vszFile = szFile;
  345. vli = li;
  346. f = (INT)DialogBox(hinstApp,
  347. MAKEINTRESOURCE(ASSERTFAILED),
  348. hwndApp,
  349. AssertDlgProc);
  350. DumpRgmdbg(szFile, li);
  351. }
  352. #endif