[docs] Replace cyrillic 'с' with latin 'c' in register names
[kolibrios.git] / contrib / games / wolf3d / wl_debug.cpp
blob2c0b061a0df002eb57cababa2212d6672bbb18c6
1 // WL_DEBUG.C
3 #ifdef _WIN32
4 #include <io.h>
5 #else
6 #include <unistd.h>
7 #endif
9 #include "wl_def.h"
10 #pragma hdrstop
12 #ifdef USE_CLOUDSKY
13 #include "wl_cloudsky.h"
14 #endif
17 =============================================================================
19 LOCAL CONSTANTS
21 =============================================================================
24 #define VIEWTILEX (viewwidth/16)
25 #define VIEWTILEY (viewheight/16)
28 =============================================================================
30 GLOBAL VARIABLES
32 =============================================================================
35 #ifdef DEBUGKEYS
37 int DebugKeys (void);
40 // from WL_DRAW.C
42 void ScalePost();
43 void SimpleScaleShape (int xcenter, int shapenum, unsigned height);
46 =============================================================================
48 LOCAL VARIABLES
50 =============================================================================
53 int maporgx;
54 int maporgy;
55 enum {mapview,tilemapview,actoratview,visview} viewtype;
57 void ViewMap (void);
59 //===========================================================================
62 ==================
64 = CountObjects
66 ==================
69 void CountObjects (void)
71 int i,total,count,active,inactive,doors;
72 objtype *obj;
74 CenterWindow (17,7);
75 active = inactive = count = doors = 0;
77 US_Print ("Total statics :");
78 total = (int)(laststatobj-&statobjlist[0]);
79 US_PrintUnsigned (total);
81 char str[60];
82 sprintf(str,"\nlaststatobj=%.8X",(int32_t)(uintptr_t)laststatobj);
83 US_Print(str);
85 US_Print ("\nIn use statics:");
86 for (i=0;i<total;i++)
88 if (statobjlist[i].shapenum != -1)
89 count++;
90 else
91 doors++; //debug
93 US_PrintUnsigned (count);
95 US_Print ("\nDoors :");
96 US_PrintUnsigned (doornum);
98 for (obj=player->next;obj;obj=obj->next)
100 if (obj->active)
101 active++;
102 else
103 inactive++;
106 US_Print ("\nTotal actors :");
107 US_PrintUnsigned (active+inactive);
109 US_Print ("\nActive actors :");
110 US_PrintUnsigned (active);
112 VW_UpdateScreen();
113 IN_Ack ();
117 //===========================================================================
120 ===================
122 = PictureGrabber
124 ===================
126 void PictureGrabber (void)
128 static char fname[] = "WSHOT000.BMP";
130 for(int i = 0; i < 1000; i++)
132 fname[7] = i % 10 + '0';
133 fname[6] = (i / 10) % 10 + '0';
134 fname[5] = i / 100 + '0';
135 int file = open(fname, O_RDONLY | O_BINARY);
136 if(file == -1) break; // file does not exist, so use that filename
137 close(file);
140 // overwrites WSHOT999.BMP if all wshot files exist
142 SDL_SaveBMP(curSurface, fname);
144 CenterWindow (18,2);
145 US_PrintCentered ("Screenshot taken");
146 VW_UpdateScreen();
147 IN_Ack();
151 //===========================================================================
154 ===================
156 = BasicOverhead
158 ===================
161 void BasicOverhead (void)
163 int x, y, z, offx, offy;
165 z = 128/MAPSIZE; // zoom scale
166 offx = 320/2;
167 offy = (160-MAPSIZE*z)/2;
169 #ifdef MAPBORDER
170 int temp = viewsize;
171 NewViewSize(16);
172 DrawPlayBorder();
173 #endif
175 // right side (raw)
177 for(x=0;x<MAPSIZE;x++)
178 for(y=0;y<MAPSIZE;y++)
179 VWB_Bar(x*z+offx, y*z+offy,z,z,(unsigned)(uintptr_t)actorat[x][y]);
181 // left side (filtered)
183 uintptr_t tile;
184 int color;
185 offx -= 128;
187 for(x=0;x<MAPSIZE;x++)
189 for(y=0;y<MAPSIZE;y++)
191 tile = (uintptr_t)actorat[x][y];
192 if (ISPOINTER(tile) && ((objtype *)tile)->flags&FL_SHOOTABLE) color = 72; // enemy
193 else if (!tile || ISPOINTER(tile))
195 if (spotvis[x][y]) color = 111; // visable
196 else color = 0; // nothing
198 else if (MAPSPOT(x,y,1) == PUSHABLETILE) color = 171; // pushwall
199 else if (tile == 64) color = 158; // solid obj
200 else if (tile < 128) color = 154; // walls
201 else if (tile < 256) color = 146; // doors
203 VWB_Bar(x*z+offx, y*z+offy,z,z,color);
207 VWB_Bar(player->tilex*z+offx,player->tiley*z+offy,z,z,15); // player
209 // resize the border to match
211 VW_UpdateScreen();
212 IN_Ack();
214 #ifdef MAPBORDER
215 NewViewSize(temp);
216 DrawPlayBorder();
217 #endif
221 //===========================================================================
224 ================
226 = ShapeTest
228 ================
231 void ShapeTest (void)
233 //TODO
234 #if NOTYET
235 extern word NumDigi;
236 extern word *DigiList;
237 extern int postx;
238 extern int postwidth;
239 extern byte *postsource;
240 static char buf[10];
242 boolean done;
243 ScanCode scan;
244 int i,j,k,x;
245 longword l;
246 byte *addr;
247 soundnames sound;
248 // PageListStruct far *page;
250 CenterWindow(20,16);
251 VW_UpdateScreen();
252 for (i = 0,done = false; !done;)
254 US_ClearWindow();
255 sound = (soundnames) -1;
257 // page = &PMPages[i];
258 US_Print(" Page #");
259 US_PrintUnsigned(i);
260 if (i < PMSpriteStart)
261 US_Print(" (Wall)");
262 else if (i < PMSoundStart)
263 US_Print(" (Sprite)");
264 else if (i == ChunksInFile - 1)
265 US_Print(" (Sound Info)");
266 else
267 US_Print(" (Sound)");
269 /* US_Print("\n XMS: ");
270 if (page->xmsPage != -1)
271 US_PrintUnsigned(page->xmsPage);
272 else
273 US_Print("No");
275 US_Print("\n Main: ");
276 if (page->mainPage != -1)
277 US_PrintUnsigned(page->mainPage);
278 else if (page->emsPage != -1)
280 US_Print("EMS ");
281 US_PrintUnsigned(page->emsPage);
283 else
284 US_Print("No");
286 US_Print("\n Last hit: ");
287 US_PrintUnsigned(page->lastHit);*/
289 US_Print("\n Address: ");
290 addr = (byte *) PM_GetPage(i);
291 sprintf(buf,"0x%08X",(int32_t) addr);
292 US_Print(buf);
294 if (addr)
296 if (i < PMSpriteStart)
299 // draw the wall
301 vbuf += 32*SCREENWIDTH;
302 postx = 128;
303 postwidth = 1;
304 postsource = addr;
305 for (x=0;x<64;x++,postx++,postsource+=64)
307 wallheight[postx] = 256;
308 ScalePost ();
310 vbuf -= 32*SCREENWIDTH;
312 else if (i < PMSoundStart)
315 // draw the sprite
317 vbuf += 32*SCREENWIDTH;
318 SimpleScaleShape (160, i-PMSpriteStart, 64);
319 vbuf -= 32*SCREENWIDTH;
321 else if (i == ChunksInFile - 1)
323 US_Print("\n\n Number of sounds: ");
324 US_PrintUnsigned(NumDigi);
325 for (l = j = k = 0;j < NumDigi;j++)
327 l += DigiList[(j * 2) + 1];
328 k += (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;
330 US_Print("\n Total bytes: ");
331 US_PrintUnsigned(l);
332 US_Print("\n Total pages: ");
333 US_PrintUnsigned(k);
335 else
337 byte *dp = addr;
338 for (j = 0;j < NumDigi;j++)
340 k = (DigiList[(j * 2) + 1] + (PMPageSize - 1)) / PMPageSize;
341 if ((i >= PMSoundStart + DigiList[j * 2])
342 && (i < PMSoundStart + DigiList[j * 2] + k))
343 break;
345 if (j < NumDigi)
347 sound = (soundnames) j;
348 US_Print("\n Sound #");
349 US_PrintUnsigned(j);
350 US_Print("\n Segment #");
351 US_PrintUnsigned(i - PMSoundStart - DigiList[j * 2]);
353 for (j = 0;j < PageLengths[i];j += 32)
355 byte v = dp[j];
356 int v2 = (unsigned)v;
357 v2 -= 128;
358 v2 /= 4;
359 if (v2 < 0)
360 VWB_Vlin(WindowY + WindowH - 32 + v2,
361 WindowY + WindowH - 32,
362 WindowX + 8 + (j / 32),BLACK);
363 else
364 VWB_Vlin(WindowY + WindowH - 32,
365 WindowY + WindowH - 32 + v2,
366 WindowX + 8 + (j / 32),BLACK);
371 VW_UpdateScreen();
373 IN_Ack();
374 scan = LastScan;
376 IN_ClearKey(scan);
377 switch (scan)
379 case sc_LeftArrow:
380 if (i)
381 i--;
382 break;
383 case sc_RightArrow:
384 if (++i >= ChunksInFile)
385 i--;
386 break;
387 case sc_W: // Walls
388 i = 0;
389 break;
390 case sc_S: // Sprites
391 i = PMSpriteStart;
392 break;
393 case sc_D: // Digitized
394 i = PMSoundStart;
395 break;
396 case sc_I: // Digitized info
397 i = ChunksInFile - 1;
398 break;
399 /* case sc_L: // Load all pages
400 for (j = 0;j < ChunksInFile;j++)
401 PM_GetPage(j);
402 break;*/
403 case sc_P:
404 if (sound != -1)
405 SD_PlayDigitized(sound,8,8);
406 break;
407 case sc_Escape:
408 done = true;
409 break;
410 /* case sc_Enter:
411 PM_GetPage(i);
412 break;*/
415 SD_StopDigitized();
416 #endif
420 //===========================================================================
424 ================
426 = DebugKeys
428 ================
431 int DebugKeys (void)
433 boolean esc;
434 int level;
436 if (Keyboard[sc_B]) // B = border color
438 CenterWindow(20,3);
439 PrintY+=6;
440 US_Print(" Border color (0-56): ");
441 VW_UpdateScreen();
442 esc = !US_LineInput (px,py,str,NULL,true,2,0);
443 if (!esc)
445 level = atoi (str);
446 if (level>=0 && level<=99)
448 if (level<30) level += 31;
449 else
451 if (level > 56) level=31;
452 else level -= 26;
455 bordercol=level*4+3;
457 if (bordercol == VIEWCOLOR)
458 DrawStatusBorder(bordercol);
460 DrawPlayBorder();
462 return 0;
465 return 1;
467 if (Keyboard[sc_C]) // C = count objects
469 CountObjects();
470 return 1;
472 if (Keyboard[sc_D]) // D = Darkone's FPS counter
474 CenterWindow (22,2);
475 if (fpscounter)
476 US_PrintCentered ("Darkone's FPS Counter OFF");
477 else
478 US_PrintCentered ("Darkone's FPS Counter ON");
479 VW_UpdateScreen();
480 IN_Ack();
481 fpscounter ^= 1;
482 return 1;
484 if (Keyboard[sc_E]) // E = quit level
485 playstate = ex_completed;
487 if (Keyboard[sc_F]) // F = facing spot
489 char str[60];
490 CenterWindow (14,6);
491 US_Print ("x:"); US_PrintUnsigned (player->x);
492 US_Print (" ("); US_PrintUnsigned (player->x%65536);
493 US_Print (")\ny:"); US_PrintUnsigned (player->y);
494 US_Print (" ("); US_PrintUnsigned (player->y%65536);
495 US_Print (")\nA:"); US_PrintUnsigned (player->angle);
496 US_Print (" X:"); US_PrintUnsigned (player->tilex);
497 US_Print (" Y:"); US_PrintUnsigned (player->tiley);
498 US_Print ("\n1:"); US_PrintUnsigned (tilemap[player->tilex][player->tiley]);
499 sprintf(str," 2:%.8X",(unsigned)(uintptr_t)actorat[player->tilex][player->tiley]); US_Print(str);
500 US_Print ("\nf 1:"); US_PrintUnsigned (player->areanumber);
501 US_Print (" 2:"); US_PrintUnsigned (MAPSPOT(player->tilex,player->tiley,1));
502 US_Print (" 3:");
503 if ((unsigned)(uintptr_t)actorat[player->tilex][player->tiley] < 256)
504 US_PrintUnsigned (spotvis[player->tilex][player->tiley]);
505 else
506 US_PrintUnsigned (actorat[player->tilex][player->tiley]->flags);
507 VW_UpdateScreen();
508 IN_Ack();
509 return 1;
512 if (Keyboard[sc_G]) // G = god mode
514 CenterWindow (12,2);
515 if (godmode == 0)
516 US_PrintCentered ("God mode ON");
517 else if (godmode == 1)
518 US_PrintCentered ("God (no flash)");
519 else if (godmode == 2)
520 US_PrintCentered ("God mode OFF");
522 VW_UpdateScreen();
523 IN_Ack();
524 if (godmode != 2)
525 godmode++;
526 else
527 godmode = 0;
528 return 1;
530 if (Keyboard[sc_H]) // H = hurt self
532 IN_ClearKeysDown ();
533 TakeDamage (16,NULL);
535 else if (Keyboard[sc_I]) // I = item cheat
537 CenterWindow (12,3);
538 US_PrintCentered ("Free items!");
539 VW_UpdateScreen();
540 GivePoints (100000);
541 HealSelf (99);
542 if (gamestate.bestweapon<wp_chaingun)
543 GiveWeapon (gamestate.bestweapon+1);
544 gamestate.ammo += 50;
545 if (gamestate.ammo > 99)
546 gamestate.ammo = 99;
547 DrawAmmo ();
548 IN_Ack ();
549 return 1;
551 else if (Keyboard[sc_K]) // K = give keys
553 CenterWindow(16,3);
554 PrintY+=6;
555 US_Print(" Give Key (1-4): ");
556 VW_UpdateScreen();
557 esc = !US_LineInput (px,py,str,NULL,true,1,0);
558 if (!esc)
560 level = atoi (str);
561 if (level>0 && level<5)
562 GiveKey(level-1);
564 return 1;
566 else if (Keyboard[sc_L]) // L = level ratios
568 byte x,start,end=LRpack;
570 if (end == 8) // wolf3d
572 CenterWindow(17,10);
573 start = 0;
575 else // sod
577 CenterWindow(17,12);
578 start = 0; end = 10;
580 again:
581 for(x=start;x<end;x++)
583 US_PrintUnsigned(x+1);
584 US_Print(" ");
585 US_PrintUnsigned(LevelRatios[x].time/60);
586 US_Print(":");
587 if (LevelRatios[x].time%60 < 10)
588 US_Print("0");
589 US_PrintUnsigned(LevelRatios[x].time%60);
590 US_Print(" ");
591 US_PrintUnsigned(LevelRatios[x].kill);
592 US_Print("% ");
593 US_PrintUnsigned(LevelRatios[x].secret);
594 US_Print("% ");
595 US_PrintUnsigned(LevelRatios[x].treasure);
596 US_Print("%\n");
598 VW_UpdateScreen();
599 IN_Ack();
600 if (end == 10 && gamestate.mapon > 9)
602 start = 10; end = 20;
603 CenterWindow(17,12);
604 goto again;
607 return 1;
609 else if (Keyboard[sc_N]) // N = no clip
611 noclip^=1;
612 CenterWindow (18,3);
613 if (noclip)
614 US_PrintCentered ("No clipping ON");
615 else
616 US_PrintCentered ("No clipping OFF");
617 VW_UpdateScreen();
618 IN_Ack ();
619 return 1;
621 else if (Keyboard[sc_O]) // O = basic overhead
623 BasicOverhead();
624 return 1;
626 else if(Keyboard[sc_P]) // P = Ripper's picture grabber
628 PictureGrabber();
629 return 1;
631 else if (Keyboard[sc_Q]) // Q = fast quit
632 Quit (NULL);
633 else if (Keyboard[sc_S]) // S = slow motion
635 CenterWindow(30,3);
636 PrintY+=6;
637 US_Print(" Slow Motion steps (default 14): ");
638 VW_UpdateScreen();
639 esc = !US_LineInput (px,py,str,NULL,true,2,0);
640 if (!esc)
642 level = atoi (str);
643 if (level>=0 && level<=50)
644 singlestep = level;
646 return 1;
648 else if (Keyboard[sc_T]) // T = shape test
650 ShapeTest ();
651 return 1;
653 else if (Keyboard[sc_V]) // V = extra VBLs
655 CenterWindow(30,3);
656 PrintY+=6;
657 US_Print(" Add how many extra VBLs(0-8): ");
658 VW_UpdateScreen();
659 esc = !US_LineInput (px,py,str,NULL,true,1,0);
660 if (!esc)
662 level = atoi (str);
663 if (level>=0 && level<=8)
664 extravbls = level;
666 return 1;
668 else if (Keyboard[sc_W]) // W = warp to level
670 CenterWindow(26,3);
671 PrintY+=6;
672 #ifndef SPEAR
673 US_Print(" Warp to which level(1-10): ");
674 #else
675 US_Print(" Warp to which level(1-21): ");
676 #endif
677 VW_UpdateScreen();
678 esc = !US_LineInput (px,py,str,NULL,true,2,0);
679 if (!esc)
681 level = atoi (str);
682 #ifndef SPEAR
683 if (level>0 && level<11)
684 #else
685 if (level>0 && level<22)
686 #endif
688 gamestate.mapon = level-1;
689 playstate = ex_warped;
692 return 1;
694 else if (Keyboard[sc_X]) // X = item cheat
696 CenterWindow (12,3);
697 US_PrintCentered ("Extra stuff!");
698 VW_UpdateScreen();
699 // DEBUG: put stuff here
700 IN_Ack ();
701 return 1;
703 #ifdef USE_CLOUDSKY
704 else if(Keyboard[sc_Z])
706 char defstr[15];
708 CenterWindow(34,4);
709 PrintY+=6;
710 US_Print(" Recalculate sky with seek: ");
711 int seekpx = px, seekpy = py;
712 US_PrintUnsigned(curSky->seed);
713 US_Print("\n Use color map (0-");
714 US_PrintUnsigned(numColorMaps - 1);
715 US_Print("): ");
716 int mappx = px, mappy = py;
717 US_PrintUnsigned(curSky->colorMapIndex);
718 VW_UpdateScreen();
720 sprintf(defstr, "%u", curSky->seed);
721 esc = !US_LineInput(seekpx, seekpy, str, defstr, true, 10, 0);
722 if(esc) return 0;
723 curSky->seed = (uint32_t) atoi(str);
725 sprintf(defstr, "%u", curSky->colorMapIndex);
726 esc = !US_LineInput(mappx, mappy, str, defstr, true, 10, 0);
727 if(esc) return 0;
728 uint32_t newInd = (uint32_t) atoi(str);
729 if(newInd < (uint32_t) numColorMaps)
731 curSky->colorMapIndex = newInd;
732 InitSky();
734 else
736 CenterWindow (18,3);
737 US_PrintCentered ("Illegal color map!");
738 VW_UpdateScreen();
739 IN_Ack ();
742 #endif
744 return 0;
748 #if 0
750 ===================
752 = OverheadRefresh
754 ===================
757 void OverheadRefresh (void)
759 unsigned x,y,endx,endy,sx,sy;
760 unsigned tile;
763 endx = maporgx+VIEWTILEX;
764 endy = maporgy+VIEWTILEY;
766 for (y=maporgy;y<endy;y++)
768 for (x=maporgx;x<endx;x++)
770 sx = (x-maporgx)*16;
771 sy = (y-maporgy)*16;
773 switch (viewtype)
775 #if 0
776 case mapview:
777 tile = *(mapsegs[0]+farmapylookup[y]+x);
778 break;
780 case tilemapview:
781 tile = tilemap[x][y];
782 break;
784 case visview:
785 tile = spotvis[x][y];
786 break;
787 #endif
788 case actoratview:
789 tile = (unsigned)actorat[x][y];
790 break;
793 if (tile<MAXWALLTILES)
794 LatchDrawTile(sx,sy,tile);
795 else
797 LatchDrawChar(sx,sy,NUMBERCHARS+((tile&0xf000)>>12));
798 LatchDrawChar(sx+8,sy,NUMBERCHARS+((tile&0x0f00)>>8));
799 LatchDrawChar(sx,sy+8,NUMBERCHARS+((tile&0x00f0)>>4));
800 LatchDrawChar(sx+8,sy+8,NUMBERCHARS+(tile&0x000f));
805 #endif
807 #if 0
809 ===================
811 = ViewMap
813 ===================
816 void ViewMap (void)
818 boolean button0held;
820 viewtype = actoratview;
821 // button0held = false;
824 maporgx = player->tilex - VIEWTILEX/2;
825 if (maporgx<0)
826 maporgx = 0;
827 if (maporgx>MAPSIZE-VIEWTILEX)
828 maporgx=MAPSIZE-VIEWTILEX;
829 maporgy = player->tiley - VIEWTILEY/2;
830 if (maporgy<0)
831 maporgy = 0;
832 if (maporgy>MAPSIZE-VIEWTILEY)
833 maporgy=MAPSIZE-VIEWTILEY;
838 // let user pan around
840 PollControls ();
841 if (controlx < 0 && maporgx>0)
842 maporgx--;
843 if (controlx > 0 && maporgx<mapwidth-VIEWTILEX)
844 maporgx++;
845 if (controly < 0 && maporgy>0)
846 maporgy--;
847 if (controly > 0 && maporgy<mapheight-VIEWTILEY)
848 maporgy++;
850 #if 0
851 if (c.button0 && !button0held)
853 button0held = true;
854 viewtype++;
855 if (viewtype>visview)
856 viewtype = mapview;
858 if (!c.button0)
859 button0held = false;
860 #endif
862 OverheadRefresh ();
864 } while (!Keyboard[sc_Escape]);
866 IN_ClearKeysDown ();
868 #endif
869 #endif