home *** CD-ROM | disk | FTP | other *** search
/ 100 af Verdens Bedste Spil / 100Spil.iso / dos / wolf3d / source / wolfsrc.1 / WL_DEBUG.C < prev    next >
C/C++ Source or Header  |  1993-02-04  |  13KB  |  723 lines

  1. // WL_DEBUG.C
  2.  
  3. #include "WL_DEF.H"
  4. #pragma hdrstop
  5. #include <BIOS.H>
  6.  
  7. /*
  8. =============================================================================
  9.  
  10.                          LOCAL CONSTANTS
  11.  
  12. =============================================================================
  13. */
  14.  
  15. #define VIEWTILEX    (viewwidth/16)
  16. #define VIEWTILEY    (viewheight/16)
  17.  
  18. /*
  19. =============================================================================
  20.  
  21.                          GLOBAL VARIABLES
  22.  
  23. =============================================================================
  24. */
  25.  
  26.  
  27. int DebugKeys (void);
  28.  
  29. /*
  30. =============================================================================
  31.  
  32.                          LOCAL VARIABLES
  33.  
  34. =============================================================================
  35. */
  36.  
  37.  
  38. int    maporgx;
  39. int    maporgy;
  40. enum {mapview,tilemapview,actoratview,visview}    viewtype;
  41.  
  42. void ViewMap (void);
  43.  
  44. //===========================================================================
  45.  
  46. /*
  47. ==================
  48. =
  49. = DebugMemory
  50. =
  51. ==================
  52. */
  53.  
  54. void DebugMemory (void)
  55. {
  56.     int    i;
  57.     char    scratch[80],str[10];
  58.     long    mem;
  59.     spritetype _seg    *block;
  60.  
  61.     CenterWindow (16,7);
  62.  
  63.     US_CPrint ("Memory Usage");
  64.     US_CPrint ("------------");
  65.     US_Print ("Total     :");
  66.     US_PrintUnsigned (mminfo.mainmem/1024);
  67.     US_Print ("k\nFree      :");
  68.     US_PrintUnsigned (MM_UnusedMemory()/1024);
  69.     US_Print ("k\nWith purge:");
  70.     US_PrintUnsigned (MM_TotalFree()/1024);
  71.     US_Print ("k\n");
  72.     VW_UpdateScreen();
  73.     IN_Ack ();
  74. }
  75.  
  76. //===========================================================================
  77.  
  78. /*
  79. ==================
  80. =
  81. = CountObjects
  82. =
  83. ==================
  84. */
  85.  
  86. void CountObjects (void)
  87. {
  88.     int    i,total,count,active,inactive,doors;
  89.     objtype    *obj;
  90.  
  91.     CenterWindow (16,7);
  92.     active = inactive = count = doors = 0;
  93.  
  94.     US_Print ("Total statics :");
  95.     total = laststatobj-&statobjlist[0];
  96.     US_PrintUnsigned (total);
  97.  
  98.     US_Print ("\nIn use statics:");
  99.     for (i=0;i<total;i++)
  100.         if (statobjlist[i].shapenum != -1)
  101.             count++;
  102.         else
  103.             doors++;    //debug
  104.     US_PrintUnsigned (count);
  105.  
  106.     US_Print ("\nDoors         :");
  107.     US_PrintUnsigned (doornum);
  108.  
  109.     for (obj=player->next;obj;obj=obj->next)
  110.     {
  111.         if (obj->active)
  112.             active++;
  113.         else
  114.             inactive++;
  115.     }
  116.  
  117.     US_Print ("\nTotal actors  :");
  118.     US_PrintUnsigned (active+inactive);
  119.  
  120.     US_Print ("\nActive actors :");
  121.     US_PrintUnsigned (active);
  122.  
  123.     VW_UpdateScreen();
  124.     IN_Ack ();
  125. }
  126.  
  127. //===========================================================================
  128.  
  129. /*
  130. ================
  131. =
  132. = PicturePause
  133. =
  134. ================
  135. */
  136.  
  137. void PicturePause (void)
  138. {
  139.     int            i;
  140.     byte        p;
  141.     unsigned    x;
  142.     byte        far    *dest,far *src;
  143.     memptr        buffer;
  144.  
  145.     VW_ColorBorder (15);
  146.     FinishPaletteShifts ();
  147.  
  148.     LastScan = 0;
  149.     while (!LastScan)
  150.     ;
  151.     if (LastScan != sc_Enter)
  152.     {
  153.         VW_ColorBorder (0);
  154.         return;
  155.     }
  156.  
  157.     VW_ColorBorder (1);
  158.     VW_SetScreen (0,0);
  159. //
  160. // vga stuff...
  161. //
  162.  
  163.     ClearMemory ();
  164.     CA_SetAllPurge();
  165.     MM_GetPtr (&buffer,64000);
  166.     for (p=0;p<4;p++)
  167.     {
  168.        src = MK_FP(0xa000,displayofs);
  169.        dest = (byte far *)buffer+p;
  170.        VGAREADMAP(p);
  171.        for (x=0;x<16000;x++,dest+=4)
  172.            *dest = *src++;
  173.     }
  174.  
  175.  
  176. #if 0
  177.     for (p=0;p<4;p++)
  178.     {
  179.         src = MK_FP(0xa000,0);
  180.         dest = (byte far *)buffer+51200+p;
  181.         VGAREADMAP(p);
  182.         for (x=0;x<3200;x++,dest+=4)
  183.             *dest = *src++;
  184.     }
  185. #endif
  186.  
  187.     asm    mov    ax,0x13
  188.     asm    int    0x10
  189.  
  190.     dest = MK_FP(0xa000,0);
  191.     _fmemcpy (dest,buffer,64000);
  192.  
  193.     VL_SetPalette (&gamepal);
  194.  
  195.  
  196.     IN_Shutdown ();
  197.  
  198.     VW_WaitVBL(70);
  199.     bioskey(0);
  200.     VW_WaitVBL(70);
  201.     Quit (NULL);
  202. }
  203.  
  204.  
  205. //===========================================================================
  206.  
  207.  
  208. /*
  209. ================
  210. =
  211. = ShapeTest
  212. =
  213. ================
  214. */
  215.  
  216. #pragma warn -pia
  217. void ShapeTest (void)
  218. {
  219. extern    word    NumDigi;
  220. extern    word    _seg *DigiList;
  221. static    char    buf[10];
  222.  
  223.     boolean            done;
  224.     ScanCode        scan;
  225.     int                i,j,k,x;
  226.     longword        l;
  227.     memptr            addr;
  228.     PageListStruct    far *page;
  229.  
  230.     CenterWindow(20,16);
  231.     VW_UpdateScreen();
  232.     for (i = 0,done = false;!done;)
  233.     {
  234.         US_ClearWindow();
  235. //        sound = -1;
  236.  
  237.         page = &PMPages[i];
  238.         US_Print(" Page #");
  239.         US_PrintUnsigned(i);
  240.         if (i < PMSpriteStart)
  241.             US_Print(" (Wall)");
  242.         else if (i < PMSoundStart)
  243.             US_Print(" (Sprite)");
  244.         else if (i == ChunksInFile - 1)
  245.             US_Print(" (Sound Info)");
  246.         else
  247.             US_Print(" (Sound)");
  248.  
  249.         US_Print("\n XMS: ");
  250.         if (page->xmsPage != -1)
  251.             US_PrintUnsigned(page->xmsPage);
  252.         else
  253.             US_Print("No");
  254.  
  255.         US_Print("\n Main: ");
  256.         if (page->mainPage != -1)
  257.             US_PrintUnsigned(page->mainPage);
  258.         else if (page->emsPage != -1)
  259.         {
  260.             US_Print("EMS ");
  261.             US_PrintUnsigned(page->emsPage);
  262.         }
  263.         else
  264.             US_Print("No");
  265.  
  266.         US_Print("\n Last hit: ");
  267.         US_PrintUnsigned(page->lastHit);
  268.  
  269.         US_Print("\n Address: ");
  270.         addr = PM_GetPageAddress(i);
  271.         sprintf(buf,"0x%04x",(word)addr);
  272.         US_Print(buf);
  273.  
  274.         if (addr)
  275.         {
  276.             if (i < PMSpriteStart)
  277.             {
  278.             //
  279.             // draw the wall
  280.             //
  281.                 bufferofs += 32*SCREENWIDTH;
  282.                 postx = 128;
  283.                 postwidth = 1;
  284.                 postsource = ((long)((unsigned)addr))<<16;
  285.                 for (x=0;x<64;x++,postx++,postsource+=64)
  286.                 {
  287.                     wallheight[postx] = 256;
  288.                     FarScalePost ();
  289.                 }
  290.                 bufferofs -= 32*SCREENWIDTH;
  291.             }
  292.             else if (i < PMSoundStart)
  293.             {
  294.             //
  295.             // draw the sprite
  296.             //
  297.                 bufferofs += 32*SCREENWIDTH;
  298.                 SimpleScaleShape (160, i-PMSpriteStart, 64);
  299.                 bufferofs -= 32*SCREENWIDTH;
  300.             }
  301.             else if (i == ChunksInFile - 1)
  302.             {
  303.                 US_Print("\n\n Number of sounds: ");
  304.                 US_PrintUnsigned(NumDigi);
  305.                 for (l = j = k = 0;j < NumDigi;j++)
  306.                 {
  307.                     l += DigiList[(j * 2) + 1];
  308.                     k += (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;
  309.                 }
  310.                 US_Print("\n Total bytes: ");
  311.                 US_PrintUnsigned(l);
  312.                 US_Print("\n Total pages: ");
  313.                 US_PrintUnsigned(k);
  314.             }
  315.             else
  316.             {
  317.                 byte far *dp = (byte far *)MK_FP(addr,0);
  318.                 for (j = 0;j < NumDigi;j++)
  319.                 {
  320.                     k = (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;
  321.                     if
  322.                     (
  323.                         (i >= PMSoundStart + DigiList[j * 2])
  324.                     &&    (i < PMSoundStart + DigiList[j * 2] + k)
  325.                     )
  326.                         break;
  327.                 }
  328.                 if (j < NumDigi)
  329.                 {
  330. //                    sound = j;
  331.                     US_Print("\n Sound #");
  332.                     US_PrintUnsigned(j);
  333.                     US_Print("\n Segment #");
  334.                     US_PrintUnsigned(i - PMSoundStart - DigiList[j * 2]);
  335.                 }
  336.                 for (j = 0;j < page->length;j += 32)
  337.                 {
  338.                     byte v = dp[j];
  339.                     int v2 = (unsigned)v;
  340.                     v2 -= 128;
  341.                     v2 /= 4;
  342.                     if (v2 < 0)
  343.                         VWB_Vlin(WindowY + WindowH - 32 + v2,
  344.                                 WindowY + WindowH - 32,
  345.                                 WindowX + 8 + (j / 32),BLACK);
  346.                     else
  347.                         VWB_Vlin(WindowY + WindowH - 32,
  348.                                 WindowY + WindowH - 32 + v2,
  349.                                 WindowX + 8 + (j / 32),BLACK);
  350.                 }
  351.             }
  352.         }
  353.  
  354.         VW_UpdateScreen();
  355.  
  356.         while (!(scan = LastScan))
  357.             SD_Poll();
  358.  
  359.         IN_ClearKey(scan);
  360.         switch (scan)
  361.         {
  362.         case sc_LeftArrow:
  363.             if (i)
  364.                 i--;
  365.             break;
  366.         case sc_RightArrow:
  367.             if (++i >= ChunksInFile)
  368.                 i--;
  369.             break;
  370.         case sc_W:    // Walls
  371.             i = 0;
  372.             break;
  373.         case sc_S:    // Sprites
  374.             i = PMSpriteStart;
  375.             break;
  376.         case sc_D:    // Digitized
  377.             i = PMSoundStart;
  378.             break;
  379.         case sc_I:    // Digitized info
  380.             i = ChunksInFile - 1;
  381.             break;
  382.         case sc_L:    // Load all pages
  383.             for (j = 0;j < ChunksInFile;j++)
  384.                 PM_GetPage(j);
  385.             break;
  386.         case sc_P:
  387. //            if (sound != -1)
  388. //                SD_PlayDigitized(sound);
  389.             break;
  390.         case sc_Escape:
  391.             done = true;
  392.             break;
  393.         case sc_Enter:
  394.             PM_GetPage(i);
  395.             break;
  396.         }
  397.     }
  398.     SD_StopDigitized();
  399. }
  400. #pragma warn +pia
  401.  
  402.  
  403.  
  404. //===========================================================================
  405.  
  406.  
  407. /*
  408. ================
  409. =
  410. = DebugKeys
  411. =
  412. ================
  413. */
  414.  
  415. int DebugKeys (void)
  416. {
  417.     boolean esc;
  418.     int level,i;
  419.  
  420.     if (Keyboard[sc_B])        // B = border color
  421.     {
  422.         CenterWindow(24,3);
  423.         PrintY+=6;
  424.         US_Print(" Border color (0-15):");
  425.         VW_UpdateScreen();
  426.         esc = !US_LineInput (px,py,str,NULL,true,2,0);
  427.         if (!esc)
  428.         {
  429.             level = atoi (str);
  430.             if (level>=0 && level<=15)
  431.                 VW_ColorBorder (level);
  432.         }
  433.         return 1;
  434.     }
  435.  
  436.     if (Keyboard[sc_C])        // C = count objects
  437.     {
  438.         CountObjects();
  439.         return 1;
  440.     }
  441.  
  442.     if (Keyboard[sc_E])        // E = quit level
  443.     {
  444.         if (tedlevel)
  445.             Quit (NULL);
  446.         playstate = ex_completed;
  447. //        gamestate.mapon++;
  448.     }
  449.  
  450.     if (Keyboard[sc_F])        // F = facing spot
  451.     {
  452.         CenterWindow (14,4);
  453.         US_Print ("X:");
  454.         US_PrintUnsigned (player->x);
  455.         US_Print ("\nY:");
  456.         US_PrintUnsigned (player->y);
  457.         US_Print ("\nA:");
  458.         US_PrintUnsigned (player->angle);
  459.         VW_UpdateScreen();
  460.         IN_Ack();
  461.         return 1;
  462.     }
  463.  
  464.     if (Keyboard[sc_G])        // G = god mode
  465.     {
  466.         CenterWindow (12,2);
  467.         if (godmode)
  468.           US_PrintCentered ("God mode OFF");
  469.         else
  470.           US_PrintCentered ("God mode ON");
  471.         VW_UpdateScreen();
  472.         IN_Ack();
  473.         godmode ^= 1;
  474.         return 1;
  475.     }
  476.     if (Keyboard[sc_H])        // H = hurt self
  477.     {
  478.         IN_ClearKeysDown ();
  479.         TakeDamage (16,NULL);
  480.     }
  481.     else if (Keyboard[sc_I])            // I = item cheat
  482.     {
  483.         CenterWindow (12,3);
  484.         US_PrintCentered ("Free items!");
  485.         VW_UpdateScreen();
  486.         GivePoints (100000);
  487.         HealSelf (99);
  488.         if (gamestate.bestweapon<wp_chaingun)
  489.             GiveWeapon (gamestate.bestweapon+1);
  490.         gamestate.ammo += 50;
  491.         if (gamestate.ammo > 99)
  492.             gamestate.ammo = 99;
  493.         DrawAmmo ();
  494.         IN_Ack ();
  495.         return 1;
  496.     }
  497.     else if (Keyboard[sc_M])            // M = memory info
  498.     {
  499.         DebugMemory();
  500.         return 1;
  501.     }
  502. #ifdef SPEAR
  503.     else if (Keyboard[sc_N])            // N = no clip
  504.     {
  505.         noclip^=1;
  506.         CenterWindow (18,3);
  507.         if (noclip)
  508.             US_PrintCentered ("No clipping ON");
  509.         else
  510.             US_PrintCentered ("No clipping OFF");
  511.         VW_UpdateScreen();
  512.         IN_Ack ();
  513.         return 1;
  514.     }
  515. #endif
  516. #if 0
  517.     else if (Keyboard[sc_O])            // O = overhead
  518.     {
  519.         ViewMap();
  520.         return 1;
  521.     }
  522. #endif
  523.     else if (Keyboard[sc_P])            // P = pause with no screen disruptioon
  524.     {
  525.         PicturePause ();
  526.         return 1;
  527.     }
  528.     else if (Keyboard[sc_Q])            // Q = fast quit
  529.         Quit (NULL);
  530.     else if (Keyboard[sc_S])            // S = slow motion
  531.     {
  532.         singlestep^=1;
  533.         CenterWindow (18,3);
  534.         if (singlestep)
  535.             US_PrintCentered ("Slow motion ON");
  536.         else
  537.             US_PrintCentered ("Slow motion OFF");
  538.         VW_UpdateScreen();
  539.         IN_Ack ();
  540.         return 1;
  541.     }
  542.     else if (Keyboard[sc_T])            // T = shape test
  543.     {
  544.         ShapeTest ();
  545.         return 1;
  546.     }
  547.     else if (Keyboard[sc_V])            // V = extra VBLs
  548.     {
  549.         CenterWindow(30,3);
  550.         PrintY+=6;
  551.         US_Print("  Add how many extra VBLs(0-8):");
  552.         VW_UpdateScreen();
  553.         esc = !US_LineInput (px,py,str,NULL,true,2,0);
  554.         if (!esc)
  555.         {
  556.             level = atoi (str);
  557.             if (level>=0 && level<=8)
  558.                 extravbls = level;
  559.         }
  560.         return 1;
  561.     }
  562.     else if (Keyboard[sc_W])            // W = warp to level
  563.     {
  564.         CenterWindow(26,3);
  565.         PrintY+=6;
  566. #ifndef SPEAR
  567.         US_Print("  Warp to which level(1-10):");
  568. #else
  569.         US_Print("  Warp to which level(1-21):");
  570. #endif
  571.         VW_UpdateScreen();
  572.         esc = !US_LineInput (px,py,str,NULL,true,2,0);
  573.         if (!esc)
  574.         {
  575.             level = atoi (str);
  576. #ifndef SPEAR
  577.             if (level>0 && level<11)
  578. #else
  579.             if (level>0 && level<22)
  580. #endif
  581.             {
  582.                 gamestate.mapon = level-1;
  583.                 playstate = ex_warped;
  584.             }
  585.         }
  586.         return 1;
  587.     }
  588.     else if (Keyboard[sc_X])            // X = item cheat
  589.     {
  590.         CenterWindow (12,3);
  591.         US_PrintCentered ("Extra stuff!");
  592.         VW_UpdateScreen();
  593.         // DEBUG: put stuff here
  594.         IN_Ack ();
  595.         return 1;
  596.     }
  597.  
  598.     return 0;
  599. }
  600.  
  601.  
  602. #if 0
  603. /*
  604. ===================
  605. =
  606. = OverheadRefresh
  607. =
  608. ===================
  609. */
  610.  
  611. void OverheadRefresh (void)
  612. {
  613.     unsigned    x,y,endx,endy,sx,sy;
  614.     unsigned    tile;
  615.  
  616.  
  617.     endx = maporgx+VIEWTILEX;
  618.     endy = maporgy+VIEWTILEY;
  619.  
  620.     for (y=maporgy;y<endy;y++)
  621.         for (x=maporgx;x<endx;x++)
  622.         {
  623.             sx = (x-maporgx)*16;
  624.             sy = (y-maporgy)*16;
  625.  
  626.             switch (viewtype)
  627.             {
  628. #if 0
  629.             case mapview:
  630.                 tile = *(mapsegs[0]+farmapylookup[y]+x);
  631.                 break;
  632.  
  633.             case tilemapview:
  634.                 tile = tilemap[x][y];
  635.                 break;
  636.  
  637.             case visview:
  638.                 tile = spotvis[x][y];
  639.                 break;
  640. #endif
  641.             case actoratview:
  642.                 tile = (unsigned)actorat[x][y];
  643.                 break;
  644.             }
  645.  
  646.             if (tile<MAXWALLTILES)
  647.                 LatchDrawTile(sx,sy,tile);
  648.             else
  649.             {
  650.                 LatchDrawChar(sx,sy,NUMBERCHARS+((tile&0xf000)>>12));
  651.                 LatchDrawChar(sx+8,sy,NUMBERCHARS+((tile&0x0f00)>>8));
  652.                 LatchDrawChar(sx,sy+8,NUMBERCHARS+((tile&0x00f0)>>4));
  653.                 LatchDrawChar(sx+8,sy+8,NUMBERCHARS+(tile&0x000f));
  654.             }
  655.         }
  656.  
  657. }
  658. #endif
  659.  
  660. #if 0
  661. /*
  662. ===================
  663. =
  664. = ViewMap
  665. =
  666. ===================
  667. */
  668.  
  669. void ViewMap (void)
  670. {
  671.     boolean        button0held;
  672.  
  673.     viewtype = actoratview;
  674. //    button0held = false;
  675.  
  676.  
  677.     maporgx = player->tilex - VIEWTILEX/2;
  678.     if (maporgx<0)
  679.         maporgx = 0;
  680.     if (maporgx>MAPSIZE-VIEWTILEX)
  681.         maporgx=MAPSIZE-VIEWTILEX;
  682.     maporgy = player->tiley - VIEWTILEY/2;
  683.     if (maporgy<0)
  684.         maporgy = 0;
  685.     if (maporgy>MAPSIZE-VIEWTILEY)
  686.         maporgy=MAPSIZE-VIEWTILEY;
  687.  
  688.     do
  689.     {
  690. //
  691. // let user pan around
  692. //
  693.         PollControls ();
  694.         if (controlx < 0 && maporgx>0)
  695.             maporgx--;
  696.         if (controlx > 0 && maporgx<mapwidth-VIEWTILEX)
  697.             maporgx++;
  698.         if (controly < 0 && maporgy>0)
  699.             maporgy--;
  700.         if (controly > 0 && maporgy<mapheight-VIEWTILEY)
  701.             maporgy++;
  702.  
  703. #if 0
  704.         if (c.button0 && !button0held)
  705.         {
  706.             button0held = true;
  707.             viewtype++;
  708.             if (viewtype>visview)
  709.                 viewtype = mapview;
  710.         }
  711.         if (!c.button0)
  712.             button0held = false;
  713. #endif
  714.  
  715.         OverheadRefresh ();
  716.  
  717.     } while (!Keyboard[sc_Escape]);
  718.  
  719.     IN_ClearKeysDown ();
  720. }
  721. #endif
  722.  
  723.