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
29 static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */
\r
32 ==========================
\r
36 = Load a few things right away
\r
38 ==========================
\r
41 void Startup16(global_game_variables_t *gvar)
\r
43 gvar->video.VL_Started=0;
\r
45 gvar->mm.mmstarted=0;
\r
46 gvar->pm.PMStarted=0;
\r
49 #ifdef __DEBUG_InputMgr__
\r
56 PM_CheckMainMem(gvar);
\r
57 PM_UnlockMainMem(gvar);
\r
62 //===========================================================================
\r
65 ==========================
\r
69 = Shuts down all ID_?? managers
\r
71 ==========================
\r
74 void Shutdown16(global_game_variables_t *gvar)
\r
80 #ifdef __DEBUG_InputMgr__
\r
88 if(gvar->video.VL_Started)
\r
89 VGAmodeX(0, 1, gvar);
\r
93 //===========================================================================
\r
96 ====================
\r
100 ====================
\r
103 /*void ReadConfig(void)
\r
111 if ( (file = open(configname,O_BINARY | O_RDONLY)) != -1)
\r
114 // valid config file
\r
116 read(file,Scores,sizeof(HighScore) * MaxScores);
\r
118 read(file,&sd,sizeof(sd));
\r
119 read(file,&sm,sizeof(sm));
\r
120 read(file,&sds,sizeof(sds));
\r
122 read(file,&mouseenabled,sizeof(mouseenabled));
\r
123 read(file,&joystickenabled,sizeof(joystickenabled));
\r
124 read(file,&joypadenabled,sizeof(joypadenabled));
\r
125 read(file,&joystickprogressive,sizeof(joystickprogressive));
\r
126 read(file,&joystickport,sizeof(joystickport));
\r
128 read(file,&dirscan,sizeof(dirscan));
\r
129 read(file,&buttonscan,sizeof(buttonscan));
\r
130 read(file,&buttonmouse,sizeof(buttonmouse));
\r
131 read(file,&buttonjoy,sizeof(buttonjoy));
\r
133 read(file,&viewsize,sizeof(viewsize));
\r
134 read(file,&mouseadjustment,sizeof(mouseadjustment));
\r
138 if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
\r
144 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
\r
145 (sds == sds_SoundSource && !SoundSourcePresent))
\r
149 mouseenabled = false;
\r
150 if (!JoysPresent[joystickport])
\r
151 joystickenabled = false;
\r
153 MainMenu[6].active=1;
\r
154 MainItems.curpos=0;
\r
159 // no config file, so select by hardware
\r
161 if (SoundBlasterPresent || AdLibPresent)
\r
172 if (SoundBlasterPresent)
\r
173 sds = sds_SoundBlaster;
\r
174 else if (SoundSourcePresent)
\r
175 sds = sds_SoundSource;
\r
180 mouseenabled = true;
\r
182 joystickenabled = false;
\r
183 joypadenabled = false;
\r
185 joystickprogressive = false;
\r
191 SD_SetMusicMode (sm);
\r
192 SD_SetSoundMode (sd);
\r
193 SD_SetDigiDevice (sds);
\r
198 ====================
\r
202 ====================
\r
205 /*void WriteConfig(void)
\r
209 file = open(configname,O_CREAT | O_BINARY | O_WRONLY,
\r
210 S_IREAD | S_IWRITE | S_IFREG);
\r
214 write(file,Scores,sizeof(HighScore) * MaxScores);
\r
216 write(file,&SoundMode,sizeof(SoundMode));
\r
217 write(file,&MusicMode,sizeof(MusicMode));
\r
218 write(file,&DigiMode,sizeof(DigiMode));
\r
220 write(file,&mouseenabled,sizeof(mouseenabled));
\r
221 write(file,&joystickenabled,sizeof(joystickenabled));
\r
222 write(file,&joypadenabled,sizeof(joypadenabled));
\r
223 write(file,&joystickprogressive,sizeof(joystickprogressive));
\r
224 write(file,&joystickport,sizeof(joystickport));
\r
226 write(file,&dirscan,sizeof(dirscan));
\r
227 write(file,&buttonscan,sizeof(buttonscan));
\r
228 write(file,&buttonmouse,sizeof(buttonmouse));
\r
229 write(file,&buttonjoy,sizeof(buttonjoy));
\r
231 write(file,&viewsize,sizeof(viewsize));
\r
232 write(file,&mouseadjustment,sizeof(mouseadjustment));
\r
238 //===========================================================================
\r
241 ===================
\r
245 ===================
\r
248 #define PIXPERFRAME 1600
\r
250 void FizzleFade (unsigned source, unsigned dest,
\r
251 unsigned width,unsigned height, boolean abortable, global_game_variables_t *gv)
\r
253 unsigned drawofs,pagedelta;
\r
254 unsigned char maskb[8] = {1,2,4,8,16,32,64,128};
\r
255 unsigned x,y,p,frame;
\r
257 word TimeCount = *clockw;
\r
258 word screenseg = SCREENSEG;
\r
260 pagedelta = dest-source;
\r
261 //++++ VL_SetScreen (dest,0);
\r
277 IN_ReadControl(0,gv);
\r
278 if (gv->player[0].info.button0 || gv->player[0].info.button1 || gv->in.inst->Keyboard[sc_Space]
\r
279 || gv->in.inst->Keyboard[sc_Enter])
\r
281 //++++ VW_ScreenToScreen (source,dest,width/8,height);
\r
286 for (p=0;p<PIXPERFRAME;p++)
\r
289 // seperate random value into x/y pair
\r
292 mov ax,[WORD PTR rndval]
\r
293 mov dx,[WORD PTR rndval+2]
\r
296 mov [BYTE PTR y],bl // low 8 bits - 1 = y xoordinate
\r
308 mov [x],bx // next 9 bits = x xoordinate
\r
310 // advance to next random element
\r
317 #ifdef __BORLANDC__
\r
321 #ifdef __BORLANDC__
\r
324 mov [WORD PTR rndval],ax
\r
325 mov [WORD PTR rndval+2],dx
\r
328 if (x>width || y>height)
\r
330 drawofs = source+gv->video.ofs.ylookup[y];
\r
338 mov ah,BYTE PTR [maskb+si]
\r
350 mov al,GC_READMAP // leave GC_INDEX set to READMAP
\r
394 if (rndval == 1) // entire sequence has been completed
\r
396 //++++ VGABITMASK(255);
\r
397 //++++ VGAMAPMASK(15);
\r
402 //++++ while (TimeCount<frame){} // don't go too fast
\r
408 //===========================================================================
\r
418 void DebugMemory_(global_game_variables_t *gvar, boolean q)
\r
420 /*VW_FixRefreshBuffer ();
\r
421 US_CenterWindow (16,7);
\r
423 US_CPrint ("Memory Usage");
\r
424 US_CPrint ("------------");
\r
425 US_Print ("Total :");
\r
426 US_PrintUnsigned (mminfo.mainmem/1024);
\r
427 US_Print ("k\nFree :");
\r
428 US_PrintUnsigned (MM_UnusedMemory()/1024);
\r
429 US_Print ("k\nWith purge:");
\r
430 US_PrintUnsigned (MM_TotalFree()/1024);
\r
432 VW_UpdateScreen();*/
\r
434 printf("========================================\n");
\r
435 printf(" DebugMemory_\n");
\r
436 printf("========================================\n");}
\r
437 if(q) { printf("Memory Usage\n");
\r
438 printf("------------\n"); }else printf(" %c%c", 0xD3, 0xC4);
\r
439 printf("Total: "); if(q) printf(" "); printf("%uk", gvar->mmi.mainmem/1024);
\r
440 if(q) printf("\n"); else printf(" ");
\r
441 printf("Free: "); if(q) printf(" "); printf("%uk", MM_UnusedMemory(gvar)/1024);
\r
442 if(q) printf("\n"); else printf(" ");
\r
443 printf("With purge:"); if(q) printf(" "); printf("%uk\n", MM_TotalFree(gvar)/1024);
\r
444 if(q) printf("------------\n");
\r
448 // if(q) MM_ShowMemory (gvar);
\r
452 ==========================
\r
456 ==========================
\r
459 void ClearMemory (global_game_variables_t *gvar)
\r
462 PM_UnlockMainMem(gvar);
\r
469 ==========================
\r
473 ==========================
\r
476 void Quit (global_game_variables_t *gvar, char *error)
\r
478 //unsigned finscreen;
\r
481 ClearMemory (gvar);
\r
485 // CA_CacheGrChunk (ORDERSCREEN);
\r
486 // screen = grsegs[ORDERSCREEN];
\r
492 // CA_CacheGrChunk (ERRORSCREEN);
\r
493 // screen = grsegs[ERRORSCREEN];
\r
497 if (error && *error)
\r
499 //movedata((unsigned)screen,7,0xb800,0,7*160);
\r
501 fprintf(stderr, "%s\n", error);
\r
506 if (!error || !(*error))
\r
510 movedata ((unsigned)screen,7,0xb800,0,4000);
\r
514 //asm mov dh,23 // row
\r
515 //asm mov dl,0 // collumn
\r
523 //===========================================================================
\r
525 #ifndef __WATCOMC__
\r
526 char global_temp_status_text[512];
\r
527 char global_temp_status_text2[512];
\r
531 // this is from my XT's BIOS
\r
532 // http://www.phatcode.net/downloads.php?id=101
\r
534 void turboXT(byte bakapee)
\r
540 in al, 61h //; Read equipment flags
\r
541 xor al, bakapee //; toggle speed
\r
542 out 61h, al //; Write new flags back
\r
544 mov bx, 0F89h //; low pitch blip
\r
545 and al, 4 //; Is turbo mode set?
\r
547 mov bx, 52Eh //; high pitch blip
\r
550 mov al, 10110110b //; Timer IC 8253 square waves
\r
551 out 43h, al //; channel 2, speaker
\r
553 out 42h, al //; send low order
\r
554 mov al, ah //; load high order
\r
555 out 42h, al //; send high order
\r
556 in al, 61h //; Read IC 8255 machine status
\r
559 out 61h, al //; Turn speaker on
\r
564 out 61h, al //; Turn speaker off
\r
572 const char *word_to_binary(word x)
\r
578 for (z = 16; z > 0; z >>= 1)
\r
580 strcat(b, ((x & z) == z) ? "1" : "0");
\r
585 const char *nibble_to_binary(nibble x)
\r
591 for (z = 8; z > 0; z >>= 1)
\r
593 strcat(b, ((x & z) == z) ? "1" : "0");
\r
598 const char *boolean_to_binary(boolean x)
\r
604 for (z = 1; z > 0; z >>= 1)
\r
606 strcat(b, ((x & z) == z) ? "1" : "0");
\r
614 printf("nibbletest\n");
\r
615 /* nibble to binary string */
\r
616 for(pee=0;pee<18;pee++)
\r
617 printf(" %u %s\n", pee, nibble_to_binary(pee));
\r
618 printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));
\r
619 printf("end of nibble test\n");
\r
625 printf("booleantest\n");
\r
626 /* boolean to binary string */
\r
627 for(pee=0;pee<4;pee++)
\r
628 printf(" %u %s\n", pee, boolean_to_binary(pee));
\r
629 printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));
\r
630 printf("end of boolean test\n");
\r