1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\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
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
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
26 #include "src/lib/16_tail.h"
\r
27 #include "src/lib/16text.h"
\r
30 ==========================
\r
34 = Load a few things right away
\r
36 ==========================
\r
39 void Startup16 (global_game_variables_t *gvar)
\r
41 gvar->video.VL_Started=0;
\r
43 gvar->mm.mmstarted=0;
\r
44 gvar->pm.PMStarted=0;
\r
45 StartupCAMMPM(gvar);
\r
47 #ifdef __DEBUG_InputMgr__
\r
54 //===========================================================================
\r
57 ==========================
\r
61 = Shuts down all ID_?? managers
\r
63 ==========================
\r
66 void Shutdown16 (global_game_variables_t *gvar)
\r
69 #ifdef __DEBUG_InputMgr__
\r
74 ShutdownCAMMPM(gvar);
\r
76 if(gvar->video.VL_Started)
\r
77 VL_Shutdown (gvar);//VGAmodeX(0, 1, gvar);
\r
81 //===========================================================================
\r
84 ==========================
\r
88 ==========================
\r
91 void StartupCAMMPM (global_game_variables_t *gvar)
\r
94 MM_Startup (); // so the signon screen can be freed
\r
101 PM_UnlockMainMem ();
\r
109 //???? PM_CheckMainMem(gvar);
\r
110 PM_UnlockMainMem(gvar);
\r
115 //===========================================================================
\r
118 ==========================
\r
122 ==========================
\r
125 void ShutdownCAMMPM (global_game_variables_t *gvar)
\r
143 //===========================================================================
\r
146 ====================
\r
150 ====================
\r
153 void ReadConfig(void)
\r
161 if ( (file = open(CONFIGNAME,O_BINARY | O_RDONLY)) != -1)
\r
164 // valid config file
\r
166 // read(file,Scores,sizeof(HighScore) * MaxScores);
\r
168 // read(file,&sd,sizeof(sd));
\r
169 // read(file,&sm,sizeof(sm));
\r
170 // read(file,&sds,sizeof(sds));
\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
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
183 read(file,&viewsize,sizeof(viewsize));
\r
184 read(file,&mouseadjustment,sizeof(mouseadjustment));
\r
188 /*if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
\r
194 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
\r
195 (sds == sds_SoundSource && !SoundSourcePresent))
\r
199 mouseenabled = false;
\r
200 if (!JoysPresent[joystickport])
\r
201 joystickenabled = false;
\r
203 MainMenu[6].active=1;
\r
204 MainItems.curpos=0;
\r
209 // no config file, so select by hardware
\r
211 /* if (SoundBlasterPresent || AdLibPresent)
\r
222 if (SoundBlasterPresent)
\r
223 sds = sds_SoundBlaster;
\r
224 else if (SoundSourcePresent)
\r
225 sds = sds_SoundSource;
\r
230 mouseenabled = true;
\r
232 joystickenabled = false;
\r
233 joypadenabled = false;
\r
235 joystickprogressive = false;
\r
241 SD_SetMusicMode (sm);
\r
242 SD_SetSoundMode (sd);
\r
243 SD_SetDigiDevice (sds);
\r
248 ====================
\r
252 ====================
\r
255 void WriteConfig(void)
\r
259 file = open(CONFIGNAME,O_CREAT | O_BINARY | O_WRONLY,
\r
260 S_IREAD | S_IWRITE | S_IFREG);
\r
264 // write(file,Scores,sizeof(HighScore) * MaxScores);
\r
266 // write(file,&SoundMode,sizeof(SoundMode));
\r
267 // write(file,&MusicMode,sizeof(MusicMode));
\r
268 // write(file,&DigiMode,sizeof(DigiMode));
\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
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
281 // write(file,&viewsize,sizeof(viewsize));
\r
282 write(file,&mouseadjustment,sizeof(mouseadjustment));
\r
288 //===========================================================================
\r
291 ===================
\r
295 ===================
\r
298 boolean FizzleFade (unsigned source, unsigned dest, unsigned width, unsigned height, unsigned frames, boolean abortable, global_game_variables_t *gvar)
\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
307 unsigned esorig;//,q;
\r
310 pagedelta = dest-source;
\r
313 esorig = 0;// q = 16;
\r
316 pixperframe = (dword)(gvar->video.page[0].width*gvar->video.page[0].height)/frames;
\r
317 screenseg = SCREENSEG;
\r
319 IN_StartAck (gvar);
\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
333 if (abortable && IN_CheckAck (gvar) )
\r
340 for (p=0;p<pixperframe;p++)
\r
344 // seperate random value into x/y pair
\r
346 mov ax,[WORD PTR rndval]
\r
347 mov dx,[WORD PTR rndval+2]
\r
350 mov [BYTE PTR y],bl // low 8 bits - 1 = y xoordinate
\r
353 mov [BYTE PTR x],ah // next 9 bits = x xoordinate
\r
354 mov [BYTE PTR x+1],dl
\r
356 // advance to next random element
\r
363 #ifdef __BORLANDC__
\r
367 #ifdef __BORLANDC__
\r
370 mov [WORD PTR rndval],ax
\r
371 mov [WORD PTR rndval+2],dx
\r
374 if (x>width || y>height)
\r
375 // if ((x>width || y>height) && (x<width*2 && y<height*2))
\r
377 // drawofs = source+(gvar->video.ofs.ylookup[y]) + (x>>2);
\r
378 drawofs = source+(y*gvar->video.page[0].stridew) + (x>>2);
\r
385 mask = maskb[mask];
\r
395 if (rndval == 1) // entire sequence has been completed
\r
399 //-- while (TimeCount<frame){}//; // don't go too fast
\r
410 //===========================================================================
\r
420 void DebugMemory_(global_game_variables_t *gvar, boolean q)
\r
422 /*VW_FixRefreshBuffer ();
\r
423 US_CenterWindow (16,7);
\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
434 VW_UpdateScreen();*/
\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
450 // if(q) MM_ShowMemory (gvar);
\r
454 ===================
\r
458 ===================
\r
462 #define DISPWIDTH 110
\r
463 #define TEXTWIDTH 40
\r
464 void TestSprites(void)
\r
466 int hx,hy,sprite,oldsprite,bottomy,topx,shift;
\r
467 spritetabletype far *spr;
\r
468 spritetype _seg *block;
\r
472 VW_FixRefreshBuffer ();
\r
473 US_CenterWindow (30,17);
\r
475 US_CPrint ("Sprite Test");
\r
476 US_CPrint ("-----------");
\r
479 hx=(PrintX+56)&(~7);
\r
480 topx = hx+TEXTWIDTH;
\r
482 US_Print ("Chunk:\nWidth:\nHeight:\nOrgx:\nOrgy:\nXl:\nYl:\nXh:\nYh:\n"
\r
483 "Shifts:\nMem:\n");
\r
487 sprite = STARTSPRITES;
\r
492 if (sprite>=STARTTILE8)
\r
493 sprite = STARTTILE8-1;
\r
494 else if (sprite<STARTSPRITES)
\r
495 sprite = STARTSPRITES;
\r
497 spr = &spritetable[sprite-STARTSPRITES];
\r
498 block = (spritetype _seg *)grsegs[sprite];
\r
500 VWB_Bar (hx,hy,TEXTWIDTH,bottomy-hy,WHITE);
\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
516 US_Print ("-----");
\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
525 oldsprite = sprite;
\r
529 // draw the current shift, then wait for key
\r
531 VWB_Bar(topx,hy,DISPWIDTH,bottomy-hy,WHITE);
\r
536 US_Print ("Shift:");
\r
537 US_PrintUnsigned (shift);
\r
539 VWB_DrawSprite (topx+16+shift*2,PrintY,sprite);
\r
544 scan = IN_WaitForKey ();
\r
558 case sc_RightArrow:
\r
566 } while (sprite == oldsprite);
\r
576 ==========================
\r
580 ==========================
\r
583 void ClearMemory (global_game_variables_t *gvar)
\r
586 PM_UnlockMainMem(gvar);
\r
593 ==========================
\r
597 ==========================
\r
600 void Quit (global_game_variables_t *gvar, char *error)
\r
602 //unsigned finscreen;
\r
605 ClearMemory (gvar);
\r
609 // CA_CacheGrChunk (ORDERSCREEN);
\r
610 // screen = grsegs[ORDERSCREEN];
\r
616 // CA_CacheGrChunk (ERRORSCREEN);
\r
617 // screen = grsegs[ERRORSCREEN];
\r
621 if (error && *error)
\r
623 //movedata((unsigned)screen,7,0xb800,0,7*160);
\r
625 fprintf(stderr, "%s\n", error);
\r
630 if (!error || !(*error))
\r
634 movedata ((unsigned)screen,7,0xb800,0,4000);
\r
638 //asm mov dh,23 // row
\r
639 //asm mov dl,0 // collumn
\r
647 //===========================================================================
\r
652 // this is from my XT's BIOS
\r
653 // http://www.phatcode.net/downloads.php?id=101
\r
655 void turboXT(byte bakapee)
\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
665 mov bx, 0F89h //; low pitch blip
\r
666 and al, 4 //; Is turbo mode set?
\r
668 mov bx, 52Eh //; high pitch blip
\r
671 mov al, 10110110b //; Timer IC 8253 square waves
\r
672 out 43h, al //; channel 2, speaker
\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
680 out 61h, al //; Turn speaker on
\r
685 out 61h, al //; Turn speaker off
\r
693 const char *word_to_binary(word x)
\r
699 for (z = 16; z > 0; z >>= 1)
\r
701 strcat(b, ((x & z) == z) ? "1" : "0");
\r
706 const char *nibble_to_binary(nibble x)
\r
712 for (z = 8; z > 0; z >>= 1)
\r
714 strcat(b, ((x & z) == z) ? "1" : "0");
\r
719 const char *boolean_to_binary(boolean x)
\r
725 for (z = 1; z > 0; z >>= 1)
\r
727 strcat(b, ((x & z) == z) ? "1" : "0");
\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
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