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 ==========================
\r
33 = Load a few things right away
\r
35 ==========================
\r
38 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 void TL_VidInit(global_game_variables_t *gvar)
\r
96 // DOSLIB: check our environment
\r
99 // DOSLIB: what CPU are we using?
\r
100 // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
\r
101 // So this code by itself shouldn't care too much what CPU it's running on. Except that other
\r
102 // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
\r
103 // the CPU to carry out tasks. --J.C.
\r
106 // DOSLIB: check for VGA
\r
107 if (!probe_vga()) {
\r
108 printf("VGA probe failed\n");
\r
111 // hardware must be VGA or higher!
\r
112 if (!(vga_state.vga_flags & VGA_IS_VGA)) {
\r
113 printf("This program requires VGA or higher graphics hardware\n");
\r
117 if (_DEBUG_INIT() == 0) {
\r
119 //printf("WARNING: Failed to initialize DEBUG output\n");
\r
122 _DEBUG("Serial debug output started\n"); // NTS: All serial output must end messages with newline, or DOSBox-X will not emit text to log
\r
123 _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);
\r
127 // get old video mode
\r
129 //int86(0x10, &in, &out);
\r
130 gvar->video.old_mode = vgaGetMode();//out.h.al;
\r
132 gvar->video.old_mode = 3;
\r
137 //===========================================================================
\r
140 ====================
\r
144 ====================
\r
147 /*void ReadConfig(void)
\r
155 if ( (file = open(configname,O_BINARY | O_RDONLY)) != -1)
\r
158 // valid config file
\r
160 read(file,Scores,sizeof(HighScore) * MaxScores);
\r
162 read(file,&sd,sizeof(sd));
\r
163 read(file,&sm,sizeof(sm));
\r
164 read(file,&sds,sizeof(sds));
\r
166 read(file,&mouseenabled,sizeof(mouseenabled));
\r
167 read(file,&joystickenabled,sizeof(joystickenabled));
\r
168 read(file,&joypadenabled,sizeof(joypadenabled));
\r
169 read(file,&joystickprogressive,sizeof(joystickprogressive));
\r
170 read(file,&joystickport,sizeof(joystickport));
\r
172 read(file,&dirscan,sizeof(dirscan));
\r
173 read(file,&buttonscan,sizeof(buttonscan));
\r
174 read(file,&buttonmouse,sizeof(buttonmouse));
\r
175 read(file,&buttonjoy,sizeof(buttonjoy));
\r
177 read(file,&viewsize,sizeof(viewsize));
\r
178 read(file,&mouseadjustment,sizeof(mouseadjustment));
\r
182 if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
\r
188 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
\r
189 (sds == sds_SoundSource && !SoundSourcePresent))
\r
193 mouseenabled = false;
\r
194 if (!JoysPresent[joystickport])
\r
195 joystickenabled = false;
\r
197 MainMenu[6].active=1;
\r
198 MainItems.curpos=0;
\r
203 // no config file, so select by hardware
\r
205 if (SoundBlasterPresent || AdLibPresent)
\r
216 if (SoundBlasterPresent)
\r
217 sds = sds_SoundBlaster;
\r
218 else if (SoundSourcePresent)
\r
219 sds = sds_SoundSource;
\r
224 mouseenabled = true;
\r
226 joystickenabled = false;
\r
227 joypadenabled = false;
\r
229 joystickprogressive = false;
\r
235 SD_SetMusicMode (sm);
\r
236 SD_SetSoundMode (sd);
\r
237 SD_SetDigiDevice (sds);
\r
242 ====================
\r
246 ====================
\r
249 /*void WriteConfig(void)
\r
253 file = open(configname,O_CREAT | O_BINARY | O_WRONLY,
\r
254 S_IREAD | S_IWRITE | S_IFREG);
\r
258 write(file,Scores,sizeof(HighScore) * MaxScores);
\r
260 write(file,&SoundMode,sizeof(SoundMode));
\r
261 write(file,&MusicMode,sizeof(MusicMode));
\r
262 write(file,&DigiMode,sizeof(DigiMode));
\r
264 write(file,&mouseenabled,sizeof(mouseenabled));
\r
265 write(file,&joystickenabled,sizeof(joystickenabled));
\r
266 write(file,&joypadenabled,sizeof(joypadenabled));
\r
267 write(file,&joystickprogressive,sizeof(joystickprogressive));
\r
268 write(file,&joystickport,sizeof(joystickport));
\r
270 write(file,&dirscan,sizeof(dirscan));
\r
271 write(file,&buttonscan,sizeof(buttonscan));
\r
272 write(file,&buttonmouse,sizeof(buttonmouse));
\r
273 write(file,&buttonjoy,sizeof(buttonjoy));
\r
275 write(file,&viewsize,sizeof(viewsize));
\r
276 write(file,&mouseadjustment,sizeof(mouseadjustment));
\r
282 //===========================================================================
\r
292 void DebugMemory_(global_game_variables_t *gvar, boolean q)
\r
294 /*VW_FixRefreshBuffer ();
\r
295 US_CenterWindow (16,7);
\r
297 US_CPrint ("Memory Usage");
\r
298 US_CPrint ("------------");
\r
299 US_Print ("Total :");
\r
300 US_PrintUnsigned (mminfo.mainmem/1024);
\r
301 US_Print ("k\nFree :");
\r
302 US_PrintUnsigned (MM_UnusedMemory()/1024);
\r
303 US_Print ("k\nWith purge:");
\r
304 US_PrintUnsigned (MM_TotalFree()/1024);
\r
306 VW_UpdateScreen();*/
\r
308 printf("========================================\n");
\r
309 printf(" DebugMemory_\n");
\r
310 printf("========================================\n");}
\r
311 if(q) { printf("Memory Usage\n");
\r
312 printf("------------\n"); }else printf(" %c%c", 0xD3, 0xC4);
\r
313 printf("Total: "); if(q) printf(" "); printf("%uk", gvar->mmi.mainmem/1024);
\r
314 if(q) printf("\n"); else printf(" ");
\r
315 printf("Free: "); if(q) printf(" "); printf("%uk", MM_UnusedMemory(gvar)/1024);
\r
316 if(q) printf("\n"); else printf(" ");
\r
317 printf("With purge:"); if(q) printf(" "); printf("%uk\n", MM_TotalFree(gvar)/1024);
\r
318 if(q) printf("------------\n");
\r
322 if(q) MM_ShowMemory (gvar);
\r
326 ==========================
\r
330 ==========================
\r
333 void ClearMemory (global_game_variables_t *gvar)
\r
336 PM_UnlockMainMem(gvar);
\r
343 ==========================
\r
347 ==========================
\r
350 void Quit (global_game_variables_t *gvar, char *error)
\r
352 //unsigned finscreen;
\r
355 ClearMemory (gvar);
\r
359 // CA_CacheGrChunk (ORDERSCREEN);
\r
360 // screen = grsegs[ORDERSCREEN];
\r
366 // CA_CacheGrChunk (ERRORSCREEN);
\r
367 // screen = grsegs[ERRORSCREEN];
\r
371 if (error && *error)
\r
373 //movedata((unsigned)screen,7,0xb800,0,7*160);
\r
375 fprintf(stderr, "%s\n", error);
\r
380 if (!error || !(*error))
\r
384 movedata ((unsigned)screen,7,0xb800,0,4000);
\r
388 //asm mov dh,23 // row
\r
389 //asm mov dl,0 // collumn
\r
397 //===========================================================================
\r
399 #ifndef __WATCOMC__
\r
400 char global_temp_status_text[512];
\r
401 char global_temp_status_text2[512];
\r
405 // this is from my XT's BIOS
\r
406 // http://www.phatcode.net/downloads.php?id=101
\r
408 void turboXT(byte bakapee)
\r
414 in al, 61h //; Read equipment flags
\r
415 xor al, bakapee //; toggle speed
\r
416 out 61h, al //; Write new flags back
\r
418 mov bx, 0F89h //; low pitch blip
\r
419 and al, 4 //; Is turbo mode set?
\r
421 mov bx, 52Eh //; high pitch blip
\r
424 mov al, 10110110b //; Timer IC 8253 square waves
\r
425 out 43h, al //; channel 2, speaker
\r
427 out 42h, al //; send low order
\r
428 mov al, ah //; load high order
\r
429 out 42h, al //; send high order
\r
430 in al, 61h //; Read IC 8255 machine status
\r
433 out 61h, al //; Turn speaker on
\r
438 out 61h, al //; Turn speaker off
\r
446 const char *word_to_binary(word x)
\r
452 for (z = 16; z > 0; z >>= 1)
\r
454 strcat(b, ((x & z) == z) ? "1" : "0");
\r
459 const char *nibble_to_binary(nibble x)
\r
465 for (z = 8; z > 0; z >>= 1)
\r
467 strcat(b, ((x & z) == z) ? "1" : "0");
\r
472 const char *boolean_to_binary(boolean x)
\r
478 for (z = 1; z > 0; z >>= 1)
\r
480 strcat(b, ((x & z) == z) ? "1" : "0");
\r
488 printf("nibbletest\n");
\r
489 /* nibble to binary string */
\r
490 for(pee=0;pee<18;pee++)
\r
491 printf(" %u %s\n", pee, nibble_to_binary(pee));
\r
492 printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));
\r
493 printf("end of nibble test\n");
\r
499 printf("booleantest\n");
\r
500 /* boolean to binary string */
\r
501 for(pee=0;pee<4;pee++)
\r
502 printf(" %u %s\n", pee, boolean_to_binary(pee));
\r
503 printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));
\r
504 printf("end of boolean test\n");
\r
507 #ifdef __BORLANDC__
\r
508 word modexPalOverscan(word col)
\r
510 //modexWaitBorder();
\r
511 outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */
\r
512 outp(PAL_DATA_REG, col);
\r