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
47 #ifdef __DEBUG_InputMgr__
\r
54 PM_CheckMainMem(gvar);
\r
55 PM_UnlockMainMem(gvar);
\r
60 //===========================================================================
\r
63 ==========================
\r
67 = Shuts down all ID_?? managers
\r
69 ==========================
\r
72 void Shutdown16(global_game_variables_t *gvar)
\r
78 #ifdef __DEBUG_InputMgr__
\r
86 if(gvar->video.VL_Started)
\r
87 VL_Shutdown (gvar);//VGAmodeX(0, 1, gvar);
\r
91 //===========================================================================
\r
94 ====================
\r
98 ====================
\r
101 /*void ReadConfig(void)
\r
109 if ( (file = open(configname,O_BINARY | O_RDONLY)) != -1)
\r
112 // valid config file
\r
114 read(file,Scores,sizeof(HighScore) * MaxScores);
\r
116 read(file,&sd,sizeof(sd));
\r
117 read(file,&sm,sizeof(sm));
\r
118 read(file,&sds,sizeof(sds));
\r
120 read(file,&mouseenabled,sizeof(mouseenabled));
\r
121 read(file,&joystickenabled,sizeof(joystickenabled));
\r
122 read(file,&joypadenabled,sizeof(joypadenabled));
\r
123 read(file,&joystickprogressive,sizeof(joystickprogressive));
\r
124 read(file,&joystickport,sizeof(joystickport));
\r
126 read(file,&dirscan,sizeof(dirscan));
\r
127 read(file,&buttonscan,sizeof(buttonscan));
\r
128 read(file,&buttonmouse,sizeof(buttonmouse));
\r
129 read(file,&buttonjoy,sizeof(buttonjoy));
\r
131 read(file,&viewsize,sizeof(viewsize));
\r
132 read(file,&mouseadjustment,sizeof(mouseadjustment));
\r
136 if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
\r
142 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
\r
143 (sds == sds_SoundSource && !SoundSourcePresent))
\r
147 mouseenabled = false;
\r
148 if (!JoysPresent[joystickport])
\r
149 joystickenabled = false;
\r
151 MainMenu[6].active=1;
\r
152 MainItems.curpos=0;
\r
157 // no config file, so select by hardware
\r
159 if (SoundBlasterPresent || AdLibPresent)
\r
170 if (SoundBlasterPresent)
\r
171 sds = sds_SoundBlaster;
\r
172 else if (SoundSourcePresent)
\r
173 sds = sds_SoundSource;
\r
178 mouseenabled = true;
\r
180 joystickenabled = false;
\r
181 joypadenabled = false;
\r
183 joystickprogressive = false;
\r
189 SD_SetMusicMode (sm);
\r
190 SD_SetSoundMode (sd);
\r
191 SD_SetDigiDevice (sds);
\r
196 ====================
\r
200 ====================
\r
203 /*void WriteConfig(void)
\r
207 file = open(configname,O_CREAT | O_BINARY | O_WRONLY,
\r
208 S_IREAD | S_IWRITE | S_IFREG);
\r
212 write(file,Scores,sizeof(HighScore) * MaxScores);
\r
214 write(file,&SoundMode,sizeof(SoundMode));
\r
215 write(file,&MusicMode,sizeof(MusicMode));
\r
216 write(file,&DigiMode,sizeof(DigiMode));
\r
218 write(file,&mouseenabled,sizeof(mouseenabled));
\r
219 write(file,&joystickenabled,sizeof(joystickenabled));
\r
220 write(file,&joypadenabled,sizeof(joypadenabled));
\r
221 write(file,&joystickprogressive,sizeof(joystickprogressive));
\r
222 write(file,&joystickport,sizeof(joystickport));
\r
224 write(file,&dirscan,sizeof(dirscan));
\r
225 write(file,&buttonscan,sizeof(buttonscan));
\r
226 write(file,&buttonmouse,sizeof(buttonmouse));
\r
227 write(file,&buttonjoy,sizeof(buttonjoy));
\r
229 write(file,&viewsize,sizeof(viewsize));
\r
230 write(file,&mouseadjustment,sizeof(mouseadjustment));
\r
236 //===========================================================================
\r
239 ===================
\r
243 ===================
\r
246 #define PIXPERFRAME 1600
\r
248 boolean FizzleFade (unsigned source, unsigned dest, unsigned width, unsigned height, unsigned frames, boolean abortable, global_game_variables_t *gvar)
\r
250 word p,pixperframe;
\r
251 unsigned drawofs,pagedelta;
\r
252 byte mask,maskb[8] = {1,2,4,8};
\r
253 unsigned x,y,frame ,esorig,q;
\r
255 word screenseg = SCREENSEG;
\r
257 pagedelta = dest-source;
\r
258 rndval = 1; esorig = 0; q = 16;
\r
260 pixperframe = 76800/(dword)frames;
\r
262 IN_StartAck (gvar);
\r
270 if (abortable && IN_CheckAck (gvar) )
\r
277 for (p=0;p<pixperframe;p++)
\r
281 // seperate random value into x/y pair
\r
283 mov ax,[WORD PTR rndval]
\r
284 mov dx,[WORD PTR rndval+2]
\r
287 mov [BYTE PTR y],bl // low 8 bits - 1 = y xoordinate
\r
290 mov [BYTE PTR x],ah // next 9 bits = x xoordinate
\r
291 mov [BYTE PTR x+1],dl
\r
293 // advance to next random element
\r
300 #ifdef __BORLANDC__
\r
304 #ifdef __BORLANDC__
\r
307 mov [WORD PTR rndval],ax
\r
308 mov [WORD PTR rndval+2],dx
\r
311 if ((x>width || y>height) && (x<width*2 && y<height*2))
\r
313 //drawofs = source+(gvar->video.ofs.ylookup[y]) + (x>>2);
\r
314 drawofs = source+(y*gvar->video.page[0].stridew) + (x>>2);
\r
322 mask = maskb[mask];
\r
325 // modexputPixel(&(gvar->video.page[0]), x, y, rand()%8);
\r
326 // VL_Plot (x, y, 15, &(gvar->video.ofs));
\r
335 if (rndval == 1) // entire sequence has been completed
\r
339 //-- while (TimeCount<frame){}//; // don't go too fast
\r
347 //===========================================================================
\r
357 void DebugMemory_(global_game_variables_t *gvar, boolean q)
\r
359 /*VW_FixRefreshBuffer ();
\r
360 US_CenterWindow (16,7);
\r
362 US_CPrint ("Memory Usage");
\r
363 US_CPrint ("------------");
\r
364 US_Print ("Total :");
\r
365 US_PrintUnsigned (mminfo.mainmem/1024);
\r
366 US_Print ("k\nFree :");
\r
367 US_PrintUnsigned (MM_UnusedMemory()/1024);
\r
368 US_Print ("k\nWith purge:");
\r
369 US_PrintUnsigned (MM_TotalFree()/1024);
\r
371 VW_UpdateScreen();*/
\r
373 printf("========================================\n");
\r
374 printf(" DebugMemory_\n");
\r
375 printf("========================================\n");}
\r
376 if(q) { printf("Memory Usage\n");
\r
377 printf("------------\n"); }else printf(" %c%c", 0xD3, 0xC4);
\r
378 printf("Total: "); if(q) printf(" "); printf("%uk", gvar->mmi.mainmem/1024);
\r
379 if(q) printf("\n"); else printf(" ");
\r
380 printf("Free: "); if(q) printf(" "); printf("%uk", MM_UnusedMemory(gvar)/1024);
\r
381 if(q) printf("\n"); else printf(" ");
\r
382 printf("With purge:"); if(q) printf(" "); printf("%uk\n", MM_TotalFree(gvar)/1024);
\r
383 if(q) printf("------------\n");
\r
387 // if(q) MM_ShowMemory (gvar);
\r
391 ==========================
\r
395 ==========================
\r
398 void ClearMemory (global_game_variables_t *gvar)
\r
401 PM_UnlockMainMem(gvar);
\r
408 ==========================
\r
412 ==========================
\r
415 void Quit (global_game_variables_t *gvar, char *error)
\r
417 //unsigned finscreen;
\r
420 ClearMemory (gvar);
\r
424 // CA_CacheGrChunk (ORDERSCREEN);
\r
425 // screen = grsegs[ORDERSCREEN];
\r
431 // CA_CacheGrChunk (ERRORSCREEN);
\r
432 // screen = grsegs[ERRORSCREEN];
\r
436 if (error && *error)
\r
438 //movedata((unsigned)screen,7,0xb800,0,7*160);
\r
440 fprintf(stderr, "%s\n", error);
\r
445 if (!error || !(*error))
\r
449 movedata ((unsigned)screen,7,0xb800,0,4000);
\r
453 //asm mov dh,23 // row
\r
454 //asm mov dl,0 // collumn
\r
462 //===========================================================================
\r
464 #ifndef __WATCOMC__
\r
465 char global_temp_status_text[512];
\r
466 char global_temp_status_text2[512];
\r
470 // this is from my XT's BIOS
\r
471 // http://www.phatcode.net/downloads.php?id=101
\r
473 void turboXT(byte bakapee)
\r
479 in al, 61h //; Read equipment flags
\r
480 xor al, bakapee //; toggle speed
\r
481 out 61h, al //; Write new flags back
\r
483 mov bx, 0F89h //; low pitch blip
\r
484 and al, 4 //; Is turbo mode set?
\r
486 mov bx, 52Eh //; high pitch blip
\r
489 mov al, 10110110b //; Timer IC 8253 square waves
\r
490 out 43h, al //; channel 2, speaker
\r
492 out 42h, al //; send low order
\r
493 mov al, ah //; load high order
\r
494 out 42h, al //; send high order
\r
495 in al, 61h //; Read IC 8255 machine status
\r
498 out 61h, al //; Turn speaker on
\r
503 out 61h, al //; Turn speaker off
\r
511 const char *word_to_binary(word x)
\r
517 for (z = 16; z > 0; z >>= 1)
\r
519 strcat(b, ((x & z) == z) ? "1" : "0");
\r
524 const char *nibble_to_binary(nibble x)
\r
530 for (z = 8; z > 0; z >>= 1)
\r
532 strcat(b, ((x & z) == z) ? "1" : "0");
\r
537 const char *boolean_to_binary(boolean x)
\r
543 for (z = 1; z > 0; z >>= 1)
\r
545 strcat(b, ((x & z) == z) ? "1" : "0");
\r
553 printf("nibbletest\n");
\r
554 /* nibble to binary string */
\r
555 for(pee=0;pee<18;pee++)
\r
556 printf(" %u %s\n", pee, nibble_to_binary(pee));
\r
557 printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));
\r
558 printf("end of nibble test\n");
\r
564 printf("booleantest\n");
\r
565 /* boolean to binary string */
\r
566 for(pee=0;pee<4;pee++)
\r
567 printf(" %u %s\n", pee, boolean_to_binary(pee));
\r
568 printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));
\r
569 printf("end of boolean test\n");
\r