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
44 // DOSLIB: check our environment
\r
47 // DOSLIB: what CPU are we using?
\r
48 // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
\r
49 // So this code by itself shouldn't care too much what CPU it's running on. Except that other
\r
50 // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
\r
51 // the CPU to carry out tasks. --J.C.
\r
54 // DOSLIB: check for VGA
\r
56 printf("VGA probe failed\n");
\r
59 // hardware must be VGA or higher!
\r
60 if (!(vga_state.vga_flags & VGA_IS_VGA)) {
\r
61 printf("This program requires VGA or higher graphics hardware\n");
\r
65 if (_DEBUG_INIT() == 0) {
\r
67 //printf("WARNING: Failed to initialize DEBUG output\n");
\r
70 _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
71 _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);
\r
75 gvar->mm.mmstarted=0;
\r
76 gvar->pm.PMStarted=0;
\r
79 #ifdef __DEBUG_InputMgr__
\r
86 PM_CheckMainMem(gvar);
\r
87 PM_UnlockMainMem(gvar);
\r
92 //===========================================================================
\r
95 ==========================
\r
99 = Shuts down all ID_?? managers
\r
101 ==========================
\r
104 void Shutdown16(global_game_variables_t *gvar)
\r
110 #ifdef __DEBUG_InputMgr__
\r
118 VGAmodeX(0, 1, gvar);
\r
123 //===========================================================================
\r
126 ====================
\r
130 ====================
\r
133 /*void ReadConfig(void)
\r
141 if ( (file = open(configname,O_BINARY | O_RDONLY)) != -1)
\r
144 // valid config file
\r
146 read(file,Scores,sizeof(HighScore) * MaxScores);
\r
148 read(file,&sd,sizeof(sd));
\r
149 read(file,&sm,sizeof(sm));
\r
150 read(file,&sds,sizeof(sds));
\r
152 read(file,&mouseenabled,sizeof(mouseenabled));
\r
153 read(file,&joystickenabled,sizeof(joystickenabled));
\r
154 read(file,&joypadenabled,sizeof(joypadenabled));
\r
155 read(file,&joystickprogressive,sizeof(joystickprogressive));
\r
156 read(file,&joystickport,sizeof(joystickport));
\r
158 read(file,&dirscan,sizeof(dirscan));
\r
159 read(file,&buttonscan,sizeof(buttonscan));
\r
160 read(file,&buttonmouse,sizeof(buttonmouse));
\r
161 read(file,&buttonjoy,sizeof(buttonjoy));
\r
163 read(file,&viewsize,sizeof(viewsize));
\r
164 read(file,&mouseadjustment,sizeof(mouseadjustment));
\r
168 if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
\r
174 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
\r
175 (sds == sds_SoundSource && !SoundSourcePresent))
\r
179 mouseenabled = false;
\r
180 if (!JoysPresent[joystickport])
\r
181 joystickenabled = false;
\r
183 MainMenu[6].active=1;
\r
184 MainItems.curpos=0;
\r
189 // no config file, so select by hardware
\r
191 if (SoundBlasterPresent || AdLibPresent)
\r
202 if (SoundBlasterPresent)
\r
203 sds = sds_SoundBlaster;
\r
204 else if (SoundSourcePresent)
\r
205 sds = sds_SoundSource;
\r
210 mouseenabled = true;
\r
212 joystickenabled = false;
\r
213 joypadenabled = false;
\r
215 joystickprogressive = false;
\r
221 SD_SetMusicMode (sm);
\r
222 SD_SetSoundMode (sd);
\r
223 SD_SetDigiDevice (sds);
\r
228 ====================
\r
232 ====================
\r
235 /*void WriteConfig(void)
\r
239 file = open(configname,O_CREAT | O_BINARY | O_WRONLY,
\r
240 S_IREAD | S_IWRITE | S_IFREG);
\r
244 write(file,Scores,sizeof(HighScore) * MaxScores);
\r
246 write(file,&SoundMode,sizeof(SoundMode));
\r
247 write(file,&MusicMode,sizeof(MusicMode));
\r
248 write(file,&DigiMode,sizeof(DigiMode));
\r
250 write(file,&mouseenabled,sizeof(mouseenabled));
\r
251 write(file,&joystickenabled,sizeof(joystickenabled));
\r
252 write(file,&joypadenabled,sizeof(joypadenabled));
\r
253 write(file,&joystickprogressive,sizeof(joystickprogressive));
\r
254 write(file,&joystickport,sizeof(joystickport));
\r
256 write(file,&dirscan,sizeof(dirscan));
\r
257 write(file,&buttonscan,sizeof(buttonscan));
\r
258 write(file,&buttonmouse,sizeof(buttonmouse));
\r
259 write(file,&buttonjoy,sizeof(buttonjoy));
\r
261 write(file,&viewsize,sizeof(viewsize));
\r
262 write(file,&mouseadjustment,sizeof(mouseadjustment));
\r
268 //===========================================================================
\r
278 void DebugMemory_(global_game_variables_t *gvar, boolean q)
\r
280 /*VW_FixRefreshBuffer ();
\r
281 US_CenterWindow (16,7);
\r
283 US_CPrint ("Memory Usage");
\r
284 US_CPrint ("------------");
\r
285 US_Print ("Total :");
\r
286 US_PrintUnsigned (mminfo.mainmem/1024);
\r
287 US_Print ("k\nFree :");
\r
288 US_PrintUnsigned (MM_UnusedMemory()/1024);
\r
289 US_Print ("k\nWith purge:");
\r
290 US_PrintUnsigned (MM_TotalFree()/1024);
\r
292 VW_UpdateScreen();*/
\r
294 printf("========================================\n");
\r
295 printf(" DebugMemory_\n");
\r
296 printf("========================================\n");}
\r
297 if(q) { printf("Memory Usage\n");
\r
298 printf("------------\n"); }else printf(" %c%c", 0xD3, 0xC4);
\r
299 printf("Total: "); if(q) printf(" "); printf("%uk", gvar->mmi.mainmem/1024);
\r
300 if(q) printf("\n"); else printf(" ");
\r
301 printf("Free: "); if(q) printf(" "); printf("%uk", MM_UnusedMemory(gvar)/1024);
\r
302 if(q) printf("\n"); else printf(" ");
\r
303 printf("With purge:"); if(q) printf(" "); printf("%uk\n", MM_TotalFree(gvar)/1024);
\r
304 if(q) printf("------------\n");
\r
308 if(q) MM_ShowMemory (gvar);
\r
312 ==========================
\r
316 ==========================
\r
319 void ClearMemory (global_game_variables_t *gvar)
\r
322 PM_UnlockMainMem(gvar);
\r
329 ==========================
\r
333 ==========================
\r
336 void Quit (global_game_variables_t *gvar, char *error)
\r
338 //unsigned finscreen;
\r
341 ClearMemory (gvar);
\r
345 // CA_CacheGrChunk (ORDERSCREEN);
\r
346 // screen = grsegs[ORDERSCREEN];
\r
352 // CA_CacheGrChunk (ERRORSCREEN);
\r
353 // screen = grsegs[ERRORSCREEN];
\r
357 if (error && *error)
\r
359 //movedata((unsigned)screen,7,0xb800,0,7*160);
\r
361 fprintf(stderr, "%s\n", error);
\r
366 if (!error || !(*error))
\r
370 movedata ((unsigned)screen,7,0xb800,0,4000);
\r
374 //asm mov dh,23 // row
\r
375 //asm mov dl,0 // collumn
\r
383 //===========================================================================
\r
385 #ifndef __WATCOMC__
\r
386 char global_temp_status_text[512];
\r
387 char global_temp_status_text2[512];
\r
391 // this is from my XT's BIOS
\r
392 // http://www.phatcode.net/downloads.php?id=101
\r
394 void turboXT(byte bakapee)
\r
400 in al, 61h //; Read equipment flags
\r
401 xor al, bakapee //; toggle speed
\r
402 out 61h, al //; Write new flags back
\r
404 mov bx, 0F89h //; low pitch blip
\r
405 and al, 4 //; Is turbo mode set?
\r
407 mov bx, 52Eh //; high pitch blip
\r
410 mov al, 10110110b //; Timer IC 8253 square waves
\r
411 out 43h, al //; channel 2, speaker
\r
413 out 42h, al //; send low order
\r
414 mov al, ah //; load high order
\r
415 out 42h, al //; send high order
\r
416 in al, 61h //; Read IC 8255 machine status
\r
419 out 61h, al //; Turn speaker on
\r
424 out 61h, al //; Turn speaker off
\r
432 const char *word_to_binary(word x)
\r
438 for (z = 16; z > 0; z >>= 1)
\r
440 strcat(b, ((x & z) == z) ? "1" : "0");
\r
445 const char *nibble_to_binary(nibble x)
\r
451 for (z = 8; z > 0; z >>= 1)
\r
453 strcat(b, ((x & z) == z) ? "1" : "0");
\r
458 const char *boolean_to_binary(boolean x)
\r
464 for (z = 1; z > 0; z >>= 1)
\r
466 strcat(b, ((x & z) == z) ? "1" : "0");
\r
474 printf("nibbletest\n");
\r
475 /* nibble to binary string */
\r
476 for(pee=0;pee<18;pee++)
\r
477 printf(" %u %s\n", pee, nibble_to_binary(pee));
\r
478 printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));
\r
479 printf("end of nibble test\n");
\r
485 printf("booleantest\n");
\r
486 /* boolean to binary string */
\r
487 for(pee=0;pee<4;pee++)
\r
488 printf(" %u %s\n", pee, boolean_to_binary(pee));
\r
489 printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));
\r
490 printf("end of boolean test\n");
\r