C5_DEBUG.C 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. /* Catacomb Armageddon Source Code
  2. * Copyright (C) 1993-2014 Flat Rock Software
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. // C3_DEBUG.C
  19. #include "DEF.H"
  20. #include "gelib.h"
  21. #pragma hdrstop
  22. /*
  23. =============================================================================
  24. LOCAL CONSTANTS
  25. =============================================================================
  26. */
  27. #define DEBUG_OVERHEAD 0
  28. #define VIEWTILEX 20
  29. #define VIEWTILEY (VIEWHEIGHT/16)
  30. /*
  31. =============================================================================
  32. GLOBAL VARIABLES
  33. =============================================================================
  34. */
  35. /*
  36. =============================================================================
  37. LOCAL VARIABLES
  38. =============================================================================
  39. */
  40. short colordelay=0;
  41. boolean autofire=false;
  42. int maporgx;
  43. int maporgy;
  44. enum {mapview,tilemapview,actoratview,visview,mapseg2,lastview} viewtype;
  45. void ViewMap (void);
  46. //===========================================================================
  47. #if 0
  48. /*
  49. ================
  50. =
  51. = PicturePause
  52. =
  53. ================
  54. */
  55. void PicturePause (void)
  56. {
  57. int y;
  58. unsigned source;
  59. source = displayofs+panadjust;
  60. // VW_ColorBorder (15);
  61. VW_SetLineWidth (40);
  62. VW_SetScreen (0,0);
  63. if (source<0x10000l-200*64)
  64. {
  65. //
  66. // copy top line first
  67. //
  68. for (y=0;y<200;y++)
  69. VW_ScreenToScreen (source+y*64,y*40,40,1);
  70. }
  71. else
  72. {
  73. //
  74. // copy bottom line first
  75. //
  76. for (y=199;y>=0;y--)
  77. VW_ScreenToScreen (source+y*64,y*40,40,1);
  78. }
  79. IN_Shutdown ();
  80. VW_WaitVBL(70);
  81. bioskey(0);
  82. VW_WaitVBL(70);
  83. Quit (NULL);
  84. }
  85. #endif
  86. //===========================================================================
  87. //===========================================================================
  88. #define sc_1 0x02
  89. #define sc_2 0x03
  90. #define sc_3 0x04
  91. #define sc_4 0x05
  92. #define sc_5 0x06
  93. #define sc_6 0x07
  94. #define sc_7 0x08
  95. #define sc_8 0x09
  96. #define sc_9 0x0a
  97. #define sc_0 0x0b
  98. /*
  99. ================
  100. =
  101. = DebugKeys
  102. =
  103. ================
  104. */
  105. int DebugKeys (void)
  106. {
  107. boolean esc;
  108. int level,i;
  109. #if DEBUG_KEYS_AVAILABLE
  110. if (Keyboard[sc_R])
  111. {
  112. CenterWindow (12,2);
  113. if (autofire)
  114. US_PrintCentered ("Rapid-Fire OFF");
  115. else
  116. US_PrintCentered ("Rapid-Fire ON");
  117. VW_UpdateScreen();
  118. IN_Ack();
  119. autofire ^= 1;
  120. return 1;
  121. }
  122. #endif
  123. #if DEBUG_KEYS_AVAILABLE
  124. if (Keyboard[sc_A])
  125. {
  126. char levelstr[50];
  127. unsigned org_tile,org_mapon,msgnum;
  128. boolean newmsg=true,newlevel=false;
  129. VW_FixRefreshBuffer ();
  130. CenterWindow (16,3);
  131. US_Print("\n");
  132. US_CPrint("Message Test");
  133. VW_UpdateScreen();
  134. org_mapon = mapon;
  135. msgnum = (org_tile = *(mapsegs[0]+farmapylookup[player->tiley]+player->tilex))-NAMESTART;
  136. while (1)
  137. {
  138. // Get outta' here
  139. //
  140. if (Keyboard[sc_Escape])
  141. {
  142. while (Keyboard[sc_Escape]);
  143. break;
  144. }
  145. // Move to previous message
  146. //
  147. if (Keyboard[sc_UpArrow])
  148. {
  149. if (msgnum)
  150. {
  151. msgnum--;
  152. newmsg = true;
  153. }
  154. }
  155. // Move to next message
  156. //
  157. if (Keyboard[sc_DownArrow])
  158. {
  159. if (msgnum < 24)
  160. {
  161. msgnum++;
  162. newmsg = true;
  163. }
  164. }
  165. // Move to previous level
  166. //
  167. if (Keyboard[sc_LeftArrow])
  168. {
  169. if (mapon)
  170. {
  171. MM_SetPurge(&grsegs[LEVEL1TEXT+mapon],3);
  172. mapon--;
  173. newlevel = true;
  174. }
  175. }
  176. // Move to next level
  177. //
  178. if (Keyboard[sc_RightArrow])
  179. {
  180. if (mapon < LASTMAP-1)
  181. {
  182. MM_SetPurge(&grsegs[LEVEL1TEXT+mapon],3);
  183. mapon++;
  184. newlevel = true;
  185. }
  186. }
  187. // Load new level text
  188. //
  189. if (newlevel)
  190. {
  191. CA_CacheGrChunk(LEVEL1TEXT+mapon);
  192. ScanText();
  193. newmsg = true;
  194. newlevel=false;
  195. }
  196. // Display new message text
  197. //
  198. if (newmsg)
  199. {
  200. *(mapsegs[0]+farmapylookup[player->tiley]+player->tilex) = msgnum+NAMESTART;
  201. DrawText(true);
  202. strcpy(levelstr,"Level: ");
  203. itoa(mapon,levelstr+strlen(levelstr),10);
  204. strcat(levelstr," Msg: ");
  205. itoa(msgnum,levelstr+strlen(levelstr),10);
  206. DisplaySMsg(levelstr,NULL);
  207. newmsg = false;
  208. if (Keyboard[sc_UpArrow] || Keyboard[sc_DownArrow] || Keyboard[sc_LeftArrow] || Keyboard[sc_RightArrow])
  209. VW_WaitVBL(6);
  210. }
  211. }
  212. // Restore game
  213. //
  214. MM_SetPurge(&grsegs[LEVEL1TEXT+mapon],3);
  215. mapon = org_mapon;
  216. CA_CacheGrChunk(LEVEL1TEXT+mapon);
  217. ScanText();
  218. *(mapsegs[0]+farmapylookup[player->tiley]+player->tilex) = org_tile;
  219. DrawText(true);
  220. status_flag = 0;
  221. }
  222. if (Keyboard[sc_V])
  223. {
  224. displayofs = bufferofs = screenloc[screenpage];
  225. CenterWindow (16,4);
  226. US_CPrint("\n"GAMENAME);
  227. US_CPrint(VERSION);
  228. US_CPrint(REVISION);
  229. VW_UpdateScreen();
  230. IN_Ack ();
  231. }
  232. if (Keyboard[sc_Q]) // Q = Insta-Quit!
  233. Quit("Insta-Quit!");
  234. if (Keyboard[sc_Z]) // Z = freeze Time
  235. {
  236. if (FreezeTime)
  237. FreezeTime = 1; // Allow refresh to dec to zero..
  238. else
  239. StopTime();
  240. IN_Ack();
  241. return 1;
  242. }
  243. #endif
  244. // if (Keyboard[sc_E])
  245. // FaceDoor((player->x>>16l)+1,(player->y>>16l));
  246. // FaceAngle(90);
  247. #if 0
  248. if (Keyboard[sc_B]) // B = border color
  249. {
  250. CenterWindow(24,3);
  251. PrintY+=6;
  252. US_Print(" Border color (0-15):");
  253. VW_UpdateScreen();
  254. esc = !US_LineInput (px,py,str,NULL,true,2,0);
  255. if (!esc)
  256. {
  257. level = atoi (str);
  258. if (level>=0 && level<=15)
  259. VW_ColorBorder (level);
  260. }
  261. return 1;
  262. }
  263. #endif
  264. #if 1//DEBUG_KEYS_AVAILABLE
  265. if (Keyboard[sc_O])
  266. {
  267. extern unsigned objectcount,latchmemavail;
  268. unsigned unused,total;
  269. CenterWindow (30,13);
  270. US_Print ("Objects: ");
  271. US_PrintUnsigned (objectcount);
  272. US_Print("\n\nTics: ");
  273. US_PrintUnsigned (tics);
  274. US_Print(" Real Tics: ");
  275. US_PrintUnsigned(realtics);
  276. US_Print ("\n\n Total Available: ");
  277. US_PrintUnsigned (mminfo.mainmem/1024);
  278. US_Print ("k\n Mem In Use: ");
  279. unused=MM_UnusedMemory()/1024;
  280. US_PrintUnsigned (unused);
  281. US_Print ("k\n Mem After Purge: ");
  282. total=MM_TotalFree()/1024;
  283. US_PrintUnsigned (total);
  284. US_Print ("k (");
  285. US_PrintUnsigned (total-unused);
  286. US_Print (")\n\nLatch Mem Free: ");
  287. US_PrintUnsigned (latchmemavail);
  288. US_Print ("\n");
  289. VW_UpdateScreen();
  290. IN_Ack();
  291. }
  292. if (colordelay<1)
  293. {
  294. if (Keyboard[26])
  295. {
  296. extern unsigned *groundcolor,debug_gnd;
  297. groundcolor = &debug_gnd;
  298. debug_gnd += 0x0101;
  299. if (debug_gnd == 0x1010)
  300. debug_gnd = 0;
  301. colordelay = 10;
  302. }
  303. if (Keyboard[27])
  304. {
  305. extern unsigned *skycolor,debug_sky;
  306. skycolor = &debug_sky;
  307. debug_sky += 0x0101;
  308. if (debug_sky == 0x1010)
  309. debug_sky = 0;
  310. colordelay = 10;
  311. }
  312. }
  313. else
  314. colordelay -= realtics;
  315. #endif
  316. #if 0
  317. if (Keyboard[sc_C]) // C = count objects
  318. {
  319. CountObjects();
  320. return 1;
  321. }
  322. if (Keyboard[sc_D]) // D = start / end demo record
  323. {
  324. if (DemoMode == demo_Off)
  325. StartDemoRecord ();
  326. else if (DemoMode == demo_Record)
  327. {
  328. EndDemoRecord ();
  329. playstate = ex_completed;
  330. }
  331. return 1;
  332. }
  333. #endif
  334. #if 0
  335. if (Keyboard[sc_E]) // E = quit level
  336. {
  337. if (tedlevel)
  338. TEDDeath();
  339. playstate = ex_warped;
  340. gamestate.mapon++;
  341. }
  342. #endif
  343. #if 0
  344. if (Keyboard[sc_F]) // F = facing spot
  345. {
  346. CenterWindow (12,4);
  347. US_Print ("X:");
  348. US_PrintUnsigned (player->x);
  349. US_Print ("Y:");
  350. US_PrintUnsigned (player->y);
  351. US_Print ("A:");
  352. US_PrintUnsigned (player->angle);
  353. VW_UpdateScreen();
  354. IN_Ack();
  355. return 1;
  356. }
  357. #endif
  358. if (Keyboard[sc_G]) // G = god mode
  359. {
  360. CenterWindow (12,2);
  361. if (godmode)
  362. US_PrintCentered ("God mode OFF");
  363. else
  364. US_PrintCentered ("God mode ON");
  365. VW_UpdateScreen();
  366. IN_Ack();
  367. godmode ^= 1;
  368. return 1;
  369. }
  370. #if 0
  371. if (Keyboard[sc_H]) // H = hurt self
  372. {
  373. TakeDamage (5);
  374. }
  375. #endif
  376. if (Keyboard[sc_I]) // I = item cheat
  377. {
  378. extern boolean redraw_gems;
  379. CenterWindow (12,3);
  380. US_PrintCentered ("Free items!");
  381. VW_UpdateScreen();
  382. for (i=0;i<4;i++)
  383. {
  384. GiveBolt ();
  385. GiveNuke ();
  386. GivePotion ();
  387. // if (!gamestate.keys[i])
  388. GiveKey (i);
  389. gamestate.gems[i] = GEM_DELAY_TIME;
  390. }
  391. gamestate.gems[4] = GEM_DELAY_TIME;
  392. redraw_gems = true;
  393. ///////// for (i=0;i<8;i++)
  394. ///////// GiveScroll (i,false);
  395. IN_Ack ();
  396. return 1;
  397. }
  398. #if DEBUG_OVERHEAD
  399. if (Keyboard[sc_Z]) // O is used elsewhere...
  400. {
  401. ViewMap();
  402. return 1;
  403. }
  404. #endif
  405. #if 0
  406. if (Keyboard[sc_P]) // P = pause with no screen disruptioon
  407. {
  408. PicturePause ();
  409. return 1;
  410. }
  411. #endif
  412. #if 0
  413. if (Keyboard[sc_S]) // S = slow motion
  414. {
  415. singlestep^=1;
  416. CenterWindow (18,3);
  417. if (singlestep)
  418. US_PrintCentered ("Slow motion ON");
  419. else
  420. US_PrintCentered ("Slow motion OFF");
  421. VW_UpdateScreen();
  422. IN_Ack ();
  423. return 1;
  424. }
  425. #endif
  426. #if 0
  427. if (Keyboard[sc_V]) // V = extra VBLs
  428. {
  429. CenterWindow(30,3);
  430. PrintY+=6;
  431. US_Print(" Add how many extra VBLs(0-8):");
  432. VW_UpdateScreen();
  433. esc = !US_LineInput (px,py,str,NULL,true,2,0);
  434. if (!esc)
  435. {
  436. level = atoi (str);
  437. if (level>=0 && level<=8)
  438. extravbls = level;
  439. }
  440. return 1;
  441. }
  442. #endif
  443. if (Keyboard[sc_W]) // W = warp to level
  444. {
  445. CenterWindow(26,3);
  446. PrintY+=6;
  447. US_Print(" Warp to which level(0-16):");
  448. VW_UpdateScreen();
  449. esc = !US_LineInput (px,py,str,NULL,true,2,0);
  450. if (!esc)
  451. {
  452. level = atoi (str);
  453. if (level>=0 && level<=LASTMAP-1)
  454. {
  455. gamestate.mapon = level;
  456. playstate = ex_warped;
  457. lasttext = -1;
  458. }
  459. }
  460. return 1;
  461. }
  462. #if 0
  463. if (Keyboard[sc_X]) // X = item cheat
  464. {
  465. CenterWindow (12,3);
  466. US_PrintCentered ("Extra stuff!");
  467. VW_UpdateScreen();
  468. for (i=0;i<4;i++)
  469. {
  470. GiveBolt ();
  471. GiveNuke ();
  472. GivePotion ();
  473. }
  474. IN_Ack ();
  475. return 1;
  476. }
  477. #endif
  478. //////// if (LastScan >= sc_1 && LastScan <= sc_8) // free scrolls
  479. //////// {
  480. //////// GiveScroll (LastScan-sc_1,false);
  481. //////// IN_ClearKeysDown ();
  482. //////// }
  483. return 0;
  484. }
  485. #if DEBUG_OVERHEAD
  486. /*
  487. =====================
  488. =
  489. = LatchDrawChar
  490. =
  491. =====================
  492. */
  493. void LatchDrawChar (unsigned x, unsigned y, unsigned picnum)
  494. {
  495. unsigned source, dest;
  496. dest = bufferofs + ylookup[y]+x;
  497. source = latchpics[0]+picnum*8;
  498. EGAWRITEMODE(1);
  499. EGAMAPMASK(15);
  500. asm mov bx,[linewidth]
  501. asm dec bx
  502. asm mov ax,[screenseg]
  503. asm mov es,ax
  504. asm mov ds,ax
  505. asm mov si,[source]
  506. asm mov di,[dest]
  507. asm movsb
  508. asm add di,bx
  509. asm movsb
  510. asm add di,bx
  511. asm movsb
  512. asm add di,bx
  513. asm movsb
  514. asm add di,bx
  515. asm movsb
  516. asm add di,bx
  517. asm movsb
  518. asm add di,bx
  519. asm movsb
  520. asm add di,bx
  521. asm movsb
  522. asm mov ax,ss
  523. asm mov ds,ax // restore turbo's data segment
  524. EGAWRITEMODE(0);
  525. }
  526. #endif
  527. #if DEBUG_OVERHEAD
  528. /*
  529. =====================
  530. =
  531. = LatchDrawTile
  532. =
  533. =====================
  534. */
  535. void LatchDrawTile (unsigned x, unsigned y, unsigned picnum)
  536. {
  537. unsigned source, dest;
  538. dest = bufferofs + ylookup[y]+x;
  539. source = tileoffsets[picnum];
  540. EGAWRITEMODE(1);
  541. EGAMAPMASK(15);
  542. asm mov bx,[linewidth]
  543. asm sub bx,2
  544. asm mov ax,[screenseg]
  545. asm mov es,ax
  546. asm mov ds,ax
  547. asm mov si,[source]
  548. asm mov di,[dest]
  549. asm mov dx,16
  550. lineloop:
  551. asm movsb
  552. asm movsb
  553. asm add di,bx
  554. asm dec dx
  555. asm jnz lineloop
  556. asm mov ax,ss
  557. asm mov ds,ax // restore turbo's data segment
  558. EGAWRITEMODE(0);
  559. }
  560. #endif
  561. #if DEBUG_OVERHEAD
  562. /*
  563. ===================
  564. =
  565. = OverheadRefresh
  566. =
  567. ===================
  568. */
  569. void OverheadRefresh (void)
  570. {
  571. unsigned x,y,endx,endy,sx,sy;
  572. unsigned tile;
  573. if (++screenpage == 3)
  574. screenpage = 0;
  575. bufferofs = screenloc[screenpage];
  576. endx = maporgx+VIEWTILEX;
  577. endy = maporgy+VIEWTILEY;
  578. for (y=maporgy;y<endy;y++)
  579. for (x=maporgx;x<endx;x++)
  580. {
  581. sx = (x-maporgx)*2;
  582. sy = (y-maporgy)*16;
  583. switch (viewtype)
  584. {
  585. case mapview:
  586. tile = *(mapsegs[0]+farmapylookup[y]+x);
  587. break;
  588. case tilemapview:
  589. tile = tilemap[x][y];
  590. break;
  591. case actoratview:
  592. tile = (unsigned)actorat[x][y];
  593. break;
  594. case visview:
  595. tile = spotvis[x][y];
  596. break;
  597. case mapseg2:
  598. tile = *(mapsegs[2]+farmapylookup[y]+x);
  599. if (tile < 256)
  600. tile = *(mapsegs[0]+farmapylookup[y]+x);
  601. break;
  602. }
  603. if (tile<NUMTILE16)
  604. LatchDrawTile(sx,sy,tile);
  605. else
  606. {
  607. LatchDrawChar(sx,sy,NUMBERCHARS+((tile&0xf000)>>12));
  608. LatchDrawChar(sx+1,sy,NUMBERCHARS+((tile&0x0f00)>>8));
  609. LatchDrawChar(sx,sy+8,NUMBERCHARS+((tile&0x00f0)>>4));
  610. LatchDrawChar(sx+1,sy+8,NUMBERCHARS+(tile&0x000f));
  611. }
  612. }
  613. VW_SetScreen (bufferofs,0);
  614. displayofs = bufferofs;
  615. }
  616. /*
  617. ===================
  618. =
  619. = ViewMap
  620. =
  621. ===================
  622. */
  623. void ViewMap (void)
  624. {
  625. boolean button0held;
  626. viewtype = actoratview;
  627. button0held = false;
  628. maporgx = player->tilex - VIEWTILEX/2;
  629. if (maporgx<0)
  630. maporgx = 0;
  631. maporgy = player->tiley - VIEWTILEY/2;
  632. if (maporgy<0)
  633. maporgy = 0;
  634. do
  635. {
  636. //
  637. // let user pan around
  638. //
  639. IN_ReadControl(0,&control);
  640. if (control.xaxis == -1 && maporgx>0)
  641. maporgx--;
  642. if (control.xaxis == 1 && maporgx<mapwidth-VIEWTILEX)
  643. maporgx++;
  644. if (control.yaxis == -1 && maporgy>0)
  645. maporgy--;
  646. if (control.yaxis == 1 && maporgy<mapheight-VIEWTILEY)
  647. maporgy++;
  648. if (control.button0 && !button0held)
  649. {
  650. button0held = true;
  651. viewtype++;
  652. if (viewtype==lastview)
  653. viewtype = mapview;
  654. }
  655. if (!control.button0)
  656. button0held = false;
  657. OverheadRefresh ();
  658. } while (!Keyboard[sc_Escape]);
  659. IN_ClearKeysDown ();
  660. DrawPlayScreen ();
  661. }
  662. #endif