]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_tail.c
==== REPO AND DEBUG WORK==== I did many things to the repo and adding ability to...
[16.git] / src / lib / 16_tail.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 /*\r
23  * 16 tail library\r
24  */\r
25 \r
26 #include "src/lib/16_tail.h"\r
27 #include "src/lib/16text.h"\r
28 \r
29 /*\r
30 ==========================\r
31 =\r
32 = Startup16\r
33 =\r
34 = Load a few things right away\r
35 =\r
36 ==========================\r
37 */\r
38 \r
39 void Startup16 (global_game_variables_t *gvar)\r
40 {\r
41         gvar->video.VL_Started=0;\r
42         TL_VidInit(gvar);\r
43         gvar->mm.mmstarted=0;\r
44         gvar->pm.PMStarted=0;\r
45         StartupCAMMPM(gvar);\r
46 #ifdef __WATCOMC__\r
47 #ifdef __DEBUG_InputMgr__\r
48         if(!dbg_nointest)\r
49 #endif\r
50         IN_Startup(gvar);\r
51 #endif\r
52 }\r
53 \r
54 //===========================================================================\r
55 \r
56 /*\r
57 ==========================\r
58 =\r
59 = Shutdown16\r
60 =\r
61 = Shuts down all ID_?? managers\r
62 =\r
63 ==========================\r
64 */\r
65 \r
66 void Shutdown16 (global_game_variables_t *gvar)\r
67 {\r
68 #ifdef __WATCOMC__\r
69 #ifdef __DEBUG_InputMgr__\r
70         if(!dbg_nointest)\r
71 #endif\r
72         IN_Shutdown(gvar);\r
73 #endif\r
74         ShutdownCAMMPM(gvar);\r
75 #ifdef __WATCOMC__\r
76         if(gvar->video.VL_Started)\r
77                 VL_Shutdown (gvar);//VGAmodeX(0, 1, gvar);\r
78 #endif\r
79 }\r
80 \r
81 //===========================================================================\r
82 \r
83 /*\r
84 ==========================\r
85 =\r
86 = StartupCAMMPM\r
87 =\r
88 ==========================\r
89 */\r
90 \r
91 void StartupCAMMPM (global_game_variables_t *gvar)\r
92 {\r
93 /*\r
94         MM_Startup ();                  // so the signon screen can be freed\r
95 \r
96         SignonScreen ();\r
97 \r
98         VW_Startup ();\r
99         IN_Startup ();\r
100         PM_Startup ();\r
101         PM_UnlockMainMem ();\r
102         SD_Startup ();\r
103         CA_Startup ();\r
104         US_Startup ();\r
105 */\r
106         MM_Startup(gvar);\r
107 #ifdef __16_PM__\r
108         PM_Startup(gvar);\r
109 //????  PM_CheckMainMem(gvar);\r
110         PM_UnlockMainMem(gvar);\r
111 #endif\r
112         CA_Startup(gvar);\r
113 }\r
114 \r
115 //===========================================================================\r
116 \r
117 /*\r
118 ==========================\r
119 =\r
120 = ShutdownCAMMPM\r
121 =\r
122 ==========================\r
123 */\r
124 \r
125 void ShutdownCAMMPM (global_game_variables_t *gvar)\r
126 {\r
127 /*\r
128         US_Shutdown ();\r
129         SD_Shutdown ();\r
130         PM_Shutdown ();\r
131         IN_Shutdown ();\r
132         VW_Shutdown ();\r
133         CA_Shutdown ();\r
134         MM_Shutdown ()\r
135 */\r
136 #ifdef __16_PM__\r
137         PM_Shutdown(gvar);\r
138 #endif\r
139         CA_Shutdown(gvar);\r
140         MM_Shutdown(gvar);\r
141 }\r
142 \r
143 //===========================================================================\r
144 \r
145 /*\r
146 ====================\r
147 =\r
148 = ReadConfig\r
149 =\r
150 ====================\r
151 */\r
152 #if 0\r
153 void ReadConfig(void)\r
154 {\r
155         int                                      file;\r
156 //      SDMode            sd;\r
157 //      SMMode            sm;\r
158 //      SDSMode          sds;\r
159 \r
160 \r
161         if ( (file = open(CONFIGNAME,O_BINARY | O_RDONLY)) != -1)\r
162         {\r
163         //\r
164         // valid config file\r
165         //\r
166 //              read(file,Scores,sizeof(HighScore) * MaxScores);\r
167 \r
168 //              read(file,&sd,sizeof(sd));\r
169 //              read(file,&sm,sizeof(sm));\r
170 //              read(file,&sds,sizeof(sds));\r
171 \r
172                 read(file,&mouseenabled,sizeof(mouseenabled));\r
173                 read(file,&joystickenabled,sizeof(joystickenabled));\r
174                 read(file,&joypadenabled,sizeof(joypadenabled));\r
175                 read(file,&joystickprogressive,sizeof(joystickprogressive));\r
176                 read(file,&joystickport,sizeof(joystickport));\r
177 \r
178                 read(file,&dirscan,sizeof(dirscan));\r
179                 read(file,&buttonscan,sizeof(buttonscan));\r
180                 read(file,&buttonmouse,sizeof(buttonmouse));\r
181                 read(file,&buttonjoy,sizeof(buttonjoy));\r
182 \r
183                 read(file,&viewsize,sizeof(viewsize));\r
184                 read(file,&mouseadjustment,sizeof(mouseadjustment));\r
185 \r
186                 close(file);\r
187 \r
188                 /*if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)\r
189                 {\r
190                         sd = sdm_PC;\r
191                         sd = smm_Off;\r
192                 }\r
193 \r
194                 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||\r
195                         (sds == sds_SoundSource && !SoundSourcePresent))\r
196                         sds = sds_Off;*/\r
197 \r
198                 if (!MousePresent)\r
199                         mouseenabled = false;\r
200                 if (!JoysPresent[joystickport])\r
201                         joystickenabled = false;\r
202 \r
203                 MainMenu[6].active=1;\r
204                 MainItems.curpos=0;\r
205         }\r
206         else\r
207         {\r
208         //\r
209         // no config file, so select by hardware\r
210         //\r
211 /*              if (SoundBlasterPresent || AdLibPresent)\r
212                 {\r
213                         sd = sdm_AdLib;\r
214                         sm = smm_AdLib;\r
215                 }\r
216                 else\r
217                 {\r
218                         sd = sdm_PC;\r
219                         sm = smm_Off;\r
220                 }\r
221 \r
222                 if (SoundBlasterPresent)\r
223                         sds = sds_SoundBlaster;\r
224                 else if (SoundSourcePresent)\r
225                         sds = sds_SoundSource;\r
226                 else\r
227                         sds = sds_Off;*/\r
228 \r
229                 if (MousePresent)\r
230                         mouseenabled = true;\r
231 \r
232                 joystickenabled = false;\r
233                 joypadenabled = false;\r
234                 joystickport = 0;\r
235                 joystickprogressive = false;\r
236 \r
237                 viewsize = 15;\r
238                 mouseadjustment=5;\r
239         }\r
240 \r
241         SD_SetMusicMode (sm);\r
242         SD_SetSoundMode (sd);\r
243         SD_SetDigiDevice (sds);\r
244 }\r
245 \r
246 \r
247 /*\r
248 ====================\r
249 =\r
250 = WriteConfig\r
251 =\r
252 ====================\r
253 */\r
254 \r
255 void WriteConfig(void)\r
256 {\r
257         int                                      file;\r
258 \r
259         file = open(CONFIGNAME,O_CREAT | O_BINARY | O_WRONLY,\r
260                                 S_IREAD | S_IWRITE | S_IFREG);\r
261 \r
262         if (file != -1)\r
263         {\r
264 //              write(file,Scores,sizeof(HighScore) * MaxScores);\r
265 \r
266 //              write(file,&SoundMode,sizeof(SoundMode));\r
267 //              write(file,&MusicMode,sizeof(MusicMode));\r
268 //              write(file,&DigiMode,sizeof(DigiMode));\r
269 \r
270                 write(file,&mouseenabled,sizeof(mouseenabled));\r
271                 write(file,&joystickenabled,sizeof(joystickenabled));\r
272                 write(file,&joypadenabled,sizeof(joypadenabled));\r
273                 write(file,&joystickprogressive,sizeof(joystickprogressive));\r
274                 write(file,&joystickport,sizeof(joystickport));\r
275 \r
276                 write(file,&dirscan,sizeof(dirscan));\r
277                 write(file,&buttonscan,sizeof(buttonscan));\r
278                 write(file,&buttonmouse,sizeof(buttonmouse));\r
279                 write(file,&buttonjoy,sizeof(buttonjoy));\r
280 \r
281 //              write(file,&viewsize,sizeof(viewsize));\r
282                 write(file,&mouseadjustment,sizeof(mouseadjustment));\r
283 \r
284                 close(file);\r
285         }\r
286 }\r
287 #endif\r
288 //===========================================================================\r
289 \r
290 /*\r
291 ===================\r
292 =\r
293 = FizzleFade\r
294 =\r
295 ===================\r
296 */\r
297 \r
298 boolean FizzleFade (unsigned source, unsigned dest, unsigned width, unsigned height, unsigned frames, boolean abortable, global_game_variables_t *gvar)\r
299 {\r
300         word            p,pixperframe;\r
301         unsigned        drawofs,pagedelta;\r
302         byte            mask,maskb[8] = {1,2,4,8};\r
303         unsigned        x,y,frame;\r
304         long            rndval;\r
305         word            screenseg;\r
306 #ifdef __WATCOMC__\r
307         unsigned        esorig;//,q;\r
308 #endif\r
309 \r
310         pagedelta = dest-source;\r
311         rndval = 1;\r
312 #ifdef __WATCOMC__\r
313         esorig = 0;// q = 16;\r
314 #endif\r
315         x = y = 0;\r
316         pixperframe = (dword)(gvar->video.page[0].width*gvar->video.page[0].height)/frames;\r
317         screenseg = SCREENSEG;\r
318 \r
319         IN_StartAck (gvar);\r
320 \r
321 //      modexClearRegion(&(gvar->video.page[0]), 0, 0, gvar->video.page[0].width, gvar->video.page[0].height, 0);\r
322 //      modexClearRegion(&(gvar->video.page[1]), 0, 0, gvar->video.page[0].width, gvar->video.page[0].height, 15);\r
323 \r
324 #ifdef __WATCOMC__\r
325         __asm {\r
326                 mov     [esorig],es\r
327         }\r
328 #endif\r
329 //      TimeCount=\r
330         frame=0;\r
331         do      // while (1)\r
332         {\r
333                 if (abortable && IN_CheckAck (gvar) )\r
334                         return true;\r
335 \r
336                 __asm {\r
337                         mov     es,[screenseg]\r
338                 }\r
339 \r
340                 for (p=0;p<pixperframe;p++)\r
341                 {\r
342                         __asm {\r
343                                 //\r
344                                 // seperate random value into x/y pair\r
345                                 //\r
346                                 mov     ax,[WORD PTR rndval]\r
347                                 mov     dx,[WORD PTR rndval+2]\r
348                                 mov     bx,ax\r
349                                 dec     bl\r
350                                 mov     [BYTE PTR y],bl                 // low 8 bits - 1 = y xoordinate\r
351                                 mov     bx,ax\r
352                                 mov     cx,dx\r
353                                 mov     [BYTE PTR x],ah                 // next 9 bits = x xoordinate\r
354                                 mov     [BYTE PTR x+1],dl\r
355                                 //\r
356                                 // advance to next random element\r
357                                 //\r
358                                 shr     dx,1\r
359                                 rcr     ax,1\r
360                                 jnc     noxor\r
361                                 xor     dx,0x0001\r
362                                 xor     ax,0x2000\r
363 #ifdef __BORLANDC__\r
364                         }\r
365 #endif\r
366 noxor:\r
367 #ifdef __BORLANDC__\r
368                         __asm {\r
369 #endif\r
370                                 mov     [WORD PTR rndval],ax\r
371                                 mov     [WORD PTR rndval+2],dx\r
372                         }\r
373 \r
374                         if (x>width || y>height)\r
375 //                      if ((x>width || y>height) && (x<width*2 && y<height*2))\r
376                                 continue;\r
377 //                      drawofs = source+(gvar->video.ofs.ylookup[y]) + (x>>2);\r
378                         drawofs = source+(y*gvar->video.page[0].stridew) + (x>>2);\r
379 \r
380                         //\r
381                         // copy one pixel\r
382                         //\r
383                         mask = x&3;\r
384                         VGAREADMAP(mask);\r
385                         mask = maskb[mask];\r
386                         VGAMAPMASK(mask);\r
387 \r
388                         __asm {\r
389                                 mov     di,[drawofs]\r
390                                 mov     al,[es:di]\r
391                                 add     di,[pagedelta]\r
392                                 mov     [es:di],al\r
393                         }\r
394 \r
395                         if (rndval == 1)                // entire sequence has been completed\r
396                                 return false;\r
397                 }\r
398                 frame++;\r
399 //--            while (TimeCount<frame){}//;            // don't go too fast\r
400                 delay(1);\r
401         } while (1);\r
402 #ifdef __WATCOMC__\r
403         __asm {\r
404                 mov     es,[esorig]\r
405         }\r
406         return false;\r
407 #endif\r
408 }\r
409 \r
410 //===========================================================================\r
411 \r
412 /*\r
413 ==================\r
414 =\r
415 = DebugMemory\r
416 =\r
417 ==================\r
418 */\r
419 \r
420 void DebugMemory_(global_game_variables_t *gvar, boolean q)\r
421 {\r
422         /*VW_FixRefreshBuffer ();\r
423         US_CenterWindow (16,7);\r
424 \r
425         US_CPrint ("Memory Usage");\r
426         US_CPrint ("------------");\r
427         US_Print ("Total         :");\r
428         US_PrintUnsigned (mminfo.mainmem/1024);\r
429         US_Print ("k\nFree        :");\r
430         US_PrintUnsigned (MM_UnusedMemory()/1024);\r
431         US_Print ("k\nWith purge:");\r
432         US_PrintUnsigned (MM_TotalFree()/1024);\r
433         US_Print ("k\n");\r
434         VW_UpdateScreen();*/\r
435         if(q){\r
436         printf("========================================\n");\r
437         printf("                DebugMemory_\n");\r
438         printf("========================================\n");}\r
439         if(q) { printf("Memory Usage\n");\r
440         printf("------------\n"); }else printf("        %c%c", 0xD3, 0xC4);\r
441         printf("Total:  "); if(q) printf("      "); printf("%uk", gvar->mmi.mainmem/1024);\r
442         if(q) printf("\n"); else printf("       ");\r
443         printf("Free:   "); if(q) printf("      "); printf("%uk", MM_UnusedMemory(gvar)/1024);\r
444         if(q) printf("\n"); else printf("       ");\r
445         printf("With purge:"); if(q) printf("   "); printf("%uk\n", MM_TotalFree(gvar)/1024);\r
446         if(q) printf("------------\n");\r
447 #ifdef __WATCOMC__\r
448         //IN_Ack ();\r
449 #endif\r
450 //      if(q) MM_ShowMemory (gvar);\r
451 }\r
452 \r
453 /*\r
454 ===================\r
455 =\r
456 = TestSprites\r
457 =\r
458 ===================\r
459 */\r
460 \r
461 #if 0\r
462 #define DISPWIDTH       110\r
463 #define TEXTWIDTH   40\r
464 void TestSprites(void)\r
465 {\r
466         int hx,hy,sprite,oldsprite,bottomy,topx,shift;\r
467         spritetabletype far *spr;\r
468         spritetype _seg *block;\r
469         unsigned        mem,scan;\r
470 \r
471 \r
472         VW_FixRefreshBuffer ();\r
473         US_CenterWindow (30,17);\r
474 \r
475         US_CPrint ("Sprite Test");\r
476         US_CPrint ("-----------");\r
477 \r
478         hy=PrintY;\r
479         hx=(PrintX+56)&(~7);\r
480         topx = hx+TEXTWIDTH;\r
481 \r
482         US_Print ("Chunk:\nWidth:\nHeight:\nOrgx:\nOrgy:\nXl:\nYl:\nXh:\nYh:\n"\r
483                           "Shifts:\nMem:\n");\r
484 \r
485         bottomy = PrintY;\r
486 \r
487         sprite = STARTSPRITES;\r
488         shift = 0;\r
489 \r
490         do\r
491         {\r
492                 if (sprite>=STARTTILE8)\r
493                         sprite = STARTTILE8-1;\r
494                 else if (sprite<STARTSPRITES)\r
495                         sprite = STARTSPRITES;\r
496 \r
497                 spr = &spritetable[sprite-STARTSPRITES];\r
498                 block = (spritetype _seg *)grsegs[sprite];\r
499 \r
500                 VWB_Bar (hx,hy,TEXTWIDTH,bottomy-hy,WHITE);\r
501 \r
502                 PrintX=hx;\r
503                 PrintY=hy;\r
504                 US_PrintUnsigned (sprite);US_Print ("\n");PrintX=hx;\r
505                 US_PrintUnsigned (spr->width);US_Print ("\n");PrintX=hx;\r
506                 US_PrintUnsigned (spr->height);US_Print ("\n");PrintX=hx;\r
507                 US_PrintSigned (spr->orgx);US_Print ("\n");PrintX=hx;\r
508                 US_PrintSigned (spr->orgy);US_Print ("\n");PrintX=hx;\r
509                 US_PrintSigned (spr->xl);US_Print ("\n");PrintX=hx;\r
510                 US_PrintSigned (spr->yl);US_Print ("\n");PrintX=hx;\r
511                 US_PrintSigned (spr->xh);US_Print ("\n");PrintX=hx;\r
512                 US_PrintSigned (spr->yh);US_Print ("\n");PrintX=hx;\r
513                 US_PrintSigned (spr->shifts);US_Print ("\n");PrintX=hx;\r
514                 if (!block)\r
515                 {\r
516                         US_Print ("-----");\r
517                 }\r
518                 else\r
519                 {\r
520                         mem = block->sourceoffset[3]+5*block->planesize[3];\r
521                         mem = (mem+15)&(~15);           // round to paragraphs\r
522                         US_PrintUnsigned (mem);\r
523                 }\r
524 \r
525                 oldsprite = sprite;\r
526                 do\r
527                 {\r
528                 //\r
529                 // draw the current shift, then wait for key\r
530                 //\r
531                         VWB_Bar(topx,hy,DISPWIDTH,bottomy-hy,WHITE);\r
532                         if (block)\r
533                         {\r
534                                 PrintX = topx;\r
535                                 PrintY = hy;\r
536                                 US_Print ("Shift:");\r
537                                 US_PrintUnsigned (shift);\r
538                                 US_Print ("\n");\r
539                                 VWB_DrawSprite (topx+16+shift*2,PrintY,sprite);\r
540                         }\r
541 \r
542                         VW_UpdateScreen();\r
543 \r
544                         scan = IN_WaitForKey ();\r
545 \r
546                         switch (scan)\r
547                         {\r
548                         case sc_UpArrow:\r
549                                 sprite++;\r
550                                 break;\r
551                         case sc_DownArrow:\r
552                                 sprite--;\r
553                                 break;\r
554                         case sc_LeftArrow:\r
555                                 if (--shift == -1)\r
556                                         shift = 3;\r
557                                 break;\r
558                         case sc_RightArrow:\r
559                                 if (++shift == 4)\r
560                                         shift = 0;\r
561                                 break;\r
562                         case sc_Escape:\r
563                                 return;\r
564                         }\r
565 \r
566                 } while (sprite == oldsprite);\r
567 \r
568   } while (1);\r
569 \r
570 \r
571 }\r
572 \r
573 #endif\r
574 \r
575 /*\r
576 ==========================\r
577 =\r
578 = ClearMemory\r
579 =\r
580 ==========================\r
581 */\r
582 \r
583 void ClearMemory (global_game_variables_t *gvar)\r
584 {\r
585 #ifdef __16_PM__\r
586         PM_UnlockMainMem(gvar);\r
587 #endif\r
588         //sd\r
589         MM_SortMem (gvar);\r
590 }\r
591 \r
592 /*\r
593 ==========================\r
594 =\r
595 = Quit\r
596 =\r
597 ==========================\r
598 */\r
599 \r
600 void Quit (global_game_variables_t *gvar, char *error)\r
601 {\r
602         //unsigned              finscreen;\r
603         memptr  screen=0;\r
604 \r
605         ClearMemory (gvar);\r
606         if (!*error)\r
607         {\r
608 // #ifndef JAPAN\r
609 //              CA_CacheGrChunk (ORDERSCREEN);\r
610 //              screen = grsegs[ORDERSCREEN];\r
611 // #endif\r
612 //              WriteConfig ();\r
613         }\r
614         else\r
615         {\r
616 //              CA_CacheGrChunk (ERRORSCREEN);\r
617 //              screen = grsegs[ERRORSCREEN];\r
618         }\r
619         Shutdown16(gvar);\r
620 \r
621         if (error && *error)\r
622         {\r
623                 //movedata((unsigned)screen,7,0xb800,0,7*160);\r
624                 gotoxy (10,4);\r
625                 fprintf(stderr, "%s\n", error);\r
626                 gotoxy (1,8);\r
627                 exit(1);\r
628         }\r
629         else\r
630         if (!error || !(*error))\r
631         {\r
632                 clrscr();\r
633 #ifndef JAPAN\r
634                 movedata ((unsigned)screen,7,0xb800,0,4000);\r
635                 gotoxy(1,24);\r
636 #endif\r
637 //asm   mov     bh,0\r
638 //asm   mov     dh,23   // row\r
639 //asm   mov     dl,0    // collumn\r
640 //asm   mov ah,2\r
641 //asm   int     0x10\r
642         }\r
643 \r
644         exit(0);\r
645 }\r
646 \r
647 //===========================================================================\r
648 \r
649 #ifdef __WATCOMC__\r
650 //\r
651 // for mary4 (XT)\r
652 // this is from my XT's BIOS\r
653 // http://www.phatcode.net/downloads.php?id=101\r
654 //\r
655 void turboXT(byte bakapee)\r
656 {\r
657         __asm {\r
658                 push    ax\r
659                 push    bx\r
660                 push    cx\r
661                 in      al, 61h                         //; Read equipment flags\r
662                 xor     al, bakapee                     //;   toggle speed\r
663                 out     61h, al                         //; Write new flags back\r
664 \r
665                 mov     bx, 0F89h                       //; low pitch blip\r
666                 and     al, 4                           //; Is turbo mode set?\r
667                 jz      @@do_beep\r
668                 mov     bx, 52Eh                        //; high pitch blip\r
669 \r
670         @@do_beep:\r
671                 mov     al, 10110110b           //; Timer IC 8253 square waves\r
672                 out     43h, al                         //;   channel 2, speaker\r
673                 mov     ax, bx\r
674                 out     42h, al                         //;   send low order\r
675                 mov     al, ah                          //;   load high order\r
676                 out     42h, al                         //;   send high order\r
677                 in      al, 61h                         //; Read IC 8255 machine status\r
678                 push    ax\r
679                 or      al, 00000011b\r
680                 out     61h, al                         //; Turn speaker on\r
681                 mov     cx, 2000h\r
682         @@delay:\r
683                 loop    @@delay\r
684                 pop     ax\r
685                 out     61h, al                         //; Turn speaker off\r
686                 pop     cx\r
687                 pop     bx\r
688                 pop     ax\r
689         }\r
690 }\r
691 #endif\r
692 \r
693 const char *word_to_binary(word x)\r
694 {\r
695         static char b[17];\r
696         int z;\r
697 \r
698         b[0] = '\0';\r
699         for (z = 16; z > 0; z >>= 1)\r
700         {\r
701                 strcat(b, ((x & z) == z) ? "1" : "0");\r
702         }\r
703         return b;\r
704 }\r
705 \r
706 const char *nibble_to_binary(nibble x)\r
707 {\r
708         static char b[9];\r
709         int z;\r
710 \r
711         b[0] = '\0';\r
712         for (z = 8; z > 0; z >>= 1)\r
713         {\r
714                 strcat(b, ((x & z) == z) ? "1" : "0");\r
715         }\r
716         return b;\r
717 }\r
718 \r
719 const char *boolean_to_binary(boolean x)\r
720 {\r
721         static char b[9];\r
722         int z;\r
723 \r
724         b[0] = '\0';\r
725         for (z = 1; z > 0; z >>= 1)\r
726         {\r
727                 strcat(b, ((x & z) == z) ? "1" : "0");\r
728         }\r
729         return b;\r
730 }\r
731 \r
732 void nibbletest()\r
733 {\r
734         nibble pee;\r
735         printf("nibbletest\n");\r
736         /* nibble to binary string */\r
737         for(pee=0;pee<18;pee++)\r
738                 printf("        %u %s\n", pee, nibble_to_binary(pee));\r
739         printf("        sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));\r
740         printf("end of nibble test\n");\r
741 }\r
742 \r
743 void booleantest()\r
744 {\r
745         boolean pee;\r
746         printf("booleantest\n");\r
747         /* boolean to binary string */\r
748         for(pee=0;pee<4;pee++)\r
749                 printf("        %u %s\n", pee, boolean_to_binary(pee));\r
750         printf("        sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));\r
751         printf("end of boolean test\n");\r
752 }\r