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
85 PM_UnlockMainMem(gvar);
\r
89 //===========================================================================
\r
92 ==========================
\r
96 = Shuts down all ID_?? managers
\r
98 ==========================
\r
101 void Shutdown16(global_game_variables_t *gvar)
\r
105 #ifdef __DEBUG_InputMgr__
\r
115 //===========================================================================
\r
118 ====================
\r
122 ====================
\r
125 /*void ReadConfig(void)
\r
133 if ( (file = open(configname,O_BINARY | O_RDONLY)) != -1)
\r
136 // valid config file
\r
138 read(file,Scores,sizeof(HighScore) * MaxScores);
\r
140 read(file,&sd,sizeof(sd));
\r
141 read(file,&sm,sizeof(sm));
\r
142 read(file,&sds,sizeof(sds));
\r
144 read(file,&mouseenabled,sizeof(mouseenabled));
\r
145 read(file,&joystickenabled,sizeof(joystickenabled));
\r
146 read(file,&joypadenabled,sizeof(joypadenabled));
\r
147 read(file,&joystickprogressive,sizeof(joystickprogressive));
\r
148 read(file,&joystickport,sizeof(joystickport));
\r
150 read(file,&dirscan,sizeof(dirscan));
\r
151 read(file,&buttonscan,sizeof(buttonscan));
\r
152 read(file,&buttonmouse,sizeof(buttonmouse));
\r
153 read(file,&buttonjoy,sizeof(buttonjoy));
\r
155 read(file,&viewsize,sizeof(viewsize));
\r
156 read(file,&mouseadjustment,sizeof(mouseadjustment));
\r
160 if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
\r
166 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
\r
167 (sds == sds_SoundSource && !SoundSourcePresent))
\r
171 mouseenabled = false;
\r
172 if (!JoysPresent[joystickport])
\r
173 joystickenabled = false;
\r
175 MainMenu[6].active=1;
\r
176 MainItems.curpos=0;
\r
181 // no config file, so select by hardware
\r
183 if (SoundBlasterPresent || AdLibPresent)
\r
194 if (SoundBlasterPresent)
\r
195 sds = sds_SoundBlaster;
\r
196 else if (SoundSourcePresent)
\r
197 sds = sds_SoundSource;
\r
202 mouseenabled = true;
\r
204 joystickenabled = false;
\r
205 joypadenabled = false;
\r
207 joystickprogressive = false;
\r
213 SD_SetMusicMode (sm);
\r
214 SD_SetSoundMode (sd);
\r
215 SD_SetDigiDevice (sds);
\r
220 ====================
\r
224 ====================
\r
227 /*void WriteConfig(void)
\r
231 file = open(configname,O_CREAT | O_BINARY | O_WRONLY,
\r
232 S_IREAD | S_IWRITE | S_IFREG);
\r
236 write(file,Scores,sizeof(HighScore) * MaxScores);
\r
238 write(file,&SoundMode,sizeof(SoundMode));
\r
239 write(file,&MusicMode,sizeof(MusicMode));
\r
240 write(file,&DigiMode,sizeof(DigiMode));
\r
242 write(file,&mouseenabled,sizeof(mouseenabled));
\r
243 write(file,&joystickenabled,sizeof(joystickenabled));
\r
244 write(file,&joypadenabled,sizeof(joypadenabled));
\r
245 write(file,&joystickprogressive,sizeof(joystickprogressive));
\r
246 write(file,&joystickport,sizeof(joystickport));
\r
248 write(file,&dirscan,sizeof(dirscan));
\r
249 write(file,&buttonscan,sizeof(buttonscan));
\r
250 write(file,&buttonmouse,sizeof(buttonmouse));
\r
251 write(file,&buttonjoy,sizeof(buttonjoy));
\r
253 write(file,&viewsize,sizeof(viewsize));
\r
254 write(file,&mouseadjustment,sizeof(mouseadjustment));
\r
260 //===========================================================================
\r
270 void DebugMemory_(global_game_variables_t *gvar, boolean q)
\r
272 /*VW_FixRefreshBuffer ();
\r
273 US_CenterWindow (16,7);
\r
275 US_CPrint ("Memory Usage");
\r
276 US_CPrint ("------------");
\r
277 US_Print ("Total :");
\r
278 US_PrintUnsigned (mminfo.mainmem/1024);
\r
279 US_Print ("k\nFree :");
\r
280 US_PrintUnsigned (MM_UnusedMemory()/1024);
\r
281 US_Print ("k\nWith purge:");
\r
282 US_PrintUnsigned (MM_TotalFree()/1024);
\r
284 VW_UpdateScreen();*/
\r
286 printf("========================================\n");
\r
287 printf(" DebugMemory_\n");
\r
288 printf("========================================\n");}
\r
289 if(q) { printf("Memory Usage\n");
\r
290 printf("------------\n"); }else printf(" %c%c", 0xD3, 0xC4);
\r
291 printf("Total: "); if(q) printf(" "); printf("%uk", gvar->mmi.mainmem/1024);
\r
292 if(q) printf("\n"); else printf(" ");
\r
293 printf("Free: "); if(q) printf(" "); printf("%uk", MM_UnusedMemory(gvar)/1024);
\r
294 if(q) printf("\n"); else printf(" ");
\r
295 printf("With purge:"); if(q) printf(" "); printf("%uk\n", MM_TotalFree(gvar)/1024);
\r
296 if(q) printf("------------\n");
\r
300 if(q) MM_ShowMemory (gvar);
\r
304 ==========================
\r
308 ==========================
\r
311 void ClearMemory (global_game_variables_t *gvar)
\r
313 PM_UnlockMainMem(gvar);
\r
319 ==========================
\r
323 ==========================
\r
326 void Quit (global_game_variables_t *gvar, char *error)
\r
328 //unsigned finscreen;
\r
331 ClearMemory (gvar);
\r
335 // CA_CacheGrChunk (ORDERSCREEN);
\r
336 // screen = grsegs[ORDERSCREEN];
\r
342 // CA_CacheGrChunk (ERRORSCREEN);
\r
343 // screen = grsegs[ERRORSCREEN];
\r
347 if (error && *error)
\r
349 movedata((unsigned)screen,7,0xb800,0,7*160);
\r
351 fprintf(stderr, "%s\n", error);
\r
356 if (!error || !(*error))
\r
360 movedata ((unsigned)screen,7,0xb800,0,4000);
\r
364 //asm mov dh,23 // row
\r
365 //asm mov dl,0 // collumn
\r
373 //===========================================================================
\r
374 #ifndef __WATCOMC__
\r
375 char global_temp_status_text[512];
\r
379 // this is from my XT's BIOS
\r
380 // http://www.phatcode.net/downloads.php?id=101
\r
382 void turboXT(byte bakapee)
\r
388 in al, 61h //; Read equipment flags
\r
389 xor al, bakapee //; toggle speed
\r
390 out 61h, al //; Write new flags back
\r
392 mov bx, 0F89h //; low pitch blip
\r
393 and al, 4 //; Is turbo mode set?
\r
395 mov bx, 52Eh //; high pitch blip
\r
398 mov al, 10110110b //; Timer IC 8253 square waves
\r
399 out 43h, al //; channel 2, speaker
\r
401 out 42h, al //; send low order
\r
402 mov al, ah //; load high order
\r
403 out 42h, al //; send high order
\r
404 in al, 61h //; Read IC 8255 machine status
\r
407 out 61h, al //; Turn speaker on
\r
412 out 61h, al //; Turn speaker off
\r
420 const char *nibble_to_binary(nibble x)
\r
426 for (z = 8; z > 0; z >>= 1)
\r
428 strcat(b, ((x & z) == z) ? "1" : "0");
\r
433 const char *boolean_to_binary(boolean x)
\r
439 for (z = 1; z > 0; z >>= 1)
\r
441 strcat(b, ((x & z) == z) ? "1" : "0");
\r
449 printf("nibbletest\n");
\r
450 /* nibble to binary string */
\r
451 for(pee=0;pee<18;pee++)
\r
452 printf(" %u %s\n", pee, nibble_to_binary(pee));
\r
453 printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));
\r
454 printf("end of nibble test\n");
\r
460 printf("booleantest\n");
\r
461 /* boolean to binary string */
\r
462 for(pee=0;pee<4;pee++)
\r
463 printf(" %u %s\n", pee, boolean_to_binary(pee));
\r
464 printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));
\r
465 printf("end of boolean test\n");
\r