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
46 gvar->video.VL_Started=0;
\r
48 gvar->mm.mmstarted=0;
\r
49 gvar->pm.PMStarted=0;
\r
52 #ifdef __DEBUG_InputMgr__
\r
59 PM_CheckMainMem(gvar);
\r
60 PM_UnlockMainMem(gvar);
\r
65 //===========================================================================
\r
68 ==========================
\r
72 = Shuts down all ID_?? managers
\r
74 ==========================
\r
77 void Shutdown16(global_game_variables_t *gvar)
\r
83 #ifdef __DEBUG_InputMgr__
\r
91 if(gvar->video.VL_Started)
\r
92 VGAmodeX(0, 1, gvar);
\r
96 void TL_VidInit(global_game_variables_t *gvar)
\r
99 // DOSLIB: check our environment
\r
102 // DOSLIB: what CPU are we using?
\r
103 // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.
\r
104 // So this code by itself shouldn't care too much what CPU it's running on. Except that other
\r
105 // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for
\r
106 // the CPU to carry out tasks. --J.C.
\r
109 // DOSLIB: check for VGA
\r
110 if (!probe_vga()) {
\r
111 printf("VGA probe failed\n");
\r
114 // hardware must be VGA or higher!
\r
115 if (!(vga_state.vga_flags & VGA_IS_VGA)) {
\r
116 printf("This program requires VGA or higher graphics hardware\n");
\r
120 if (_DEBUG_INIT() == 0) {
\r
122 //printf("WARNING: Failed to initialize DEBUG output\n");
\r
125 _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
126 _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);
\r
130 // get old video mode
\r
132 //int86(0x10, &in, &out);
\r
133 if(!gvar->video.old_mode) gvar->video.old_mode = vgaGetMode();//out.h.al;
\r
135 gvar->video.old_mode = 3;
\r
137 gvar->video.VL_Initiated = 1;
\r
141 //===========================================================================
\r
144 ====================
\r
148 ====================
\r
151 /*void ReadConfig(void)
\r
159 if ( (file = open(configname,O_BINARY | O_RDONLY)) != -1)
\r
162 // valid config file
\r
164 read(file,Scores,sizeof(HighScore) * MaxScores);
\r
166 read(file,&sd,sizeof(sd));
\r
167 read(file,&sm,sizeof(sm));
\r
168 read(file,&sds,sizeof(sds));
\r
170 read(file,&mouseenabled,sizeof(mouseenabled));
\r
171 read(file,&joystickenabled,sizeof(joystickenabled));
\r
172 read(file,&joypadenabled,sizeof(joypadenabled));
\r
173 read(file,&joystickprogressive,sizeof(joystickprogressive));
\r
174 read(file,&joystickport,sizeof(joystickport));
\r
176 read(file,&dirscan,sizeof(dirscan));
\r
177 read(file,&buttonscan,sizeof(buttonscan));
\r
178 read(file,&buttonmouse,sizeof(buttonmouse));
\r
179 read(file,&buttonjoy,sizeof(buttonjoy));
\r
181 read(file,&viewsize,sizeof(viewsize));
\r
182 read(file,&mouseadjustment,sizeof(mouseadjustment));
\r
186 if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent)
\r
192 if ((sds == sds_SoundBlaster && !SoundBlasterPresent) ||
\r
193 (sds == sds_SoundSource && !SoundSourcePresent))
\r
197 mouseenabled = false;
\r
198 if (!JoysPresent[joystickport])
\r
199 joystickenabled = false;
\r
201 MainMenu[6].active=1;
\r
202 MainItems.curpos=0;
\r
207 // no config file, so select by hardware
\r
209 if (SoundBlasterPresent || AdLibPresent)
\r
220 if (SoundBlasterPresent)
\r
221 sds = sds_SoundBlaster;
\r
222 else if (SoundSourcePresent)
\r
223 sds = sds_SoundSource;
\r
228 mouseenabled = true;
\r
230 joystickenabled = false;
\r
231 joypadenabled = false;
\r
233 joystickprogressive = false;
\r
239 SD_SetMusicMode (sm);
\r
240 SD_SetSoundMode (sd);
\r
241 SD_SetDigiDevice (sds);
\r
246 ====================
\r
250 ====================
\r
253 /*void WriteConfig(void)
\r
257 file = open(configname,O_CREAT | O_BINARY | O_WRONLY,
\r
258 S_IREAD | S_IWRITE | S_IFREG);
\r
262 write(file,Scores,sizeof(HighScore) * MaxScores);
\r
264 write(file,&SoundMode,sizeof(SoundMode));
\r
265 write(file,&MusicMode,sizeof(MusicMode));
\r
266 write(file,&DigiMode,sizeof(DigiMode));
\r
268 write(file,&mouseenabled,sizeof(mouseenabled));
\r
269 write(file,&joystickenabled,sizeof(joystickenabled));
\r
270 write(file,&joypadenabled,sizeof(joypadenabled));
\r
271 write(file,&joystickprogressive,sizeof(joystickprogressive));
\r
272 write(file,&joystickport,sizeof(joystickport));
\r
274 write(file,&dirscan,sizeof(dirscan));
\r
275 write(file,&buttonscan,sizeof(buttonscan));
\r
276 write(file,&buttonmouse,sizeof(buttonmouse));
\r
277 write(file,&buttonjoy,sizeof(buttonjoy));
\r
279 write(file,&viewsize,sizeof(viewsize));
\r
280 write(file,&mouseadjustment,sizeof(mouseadjustment));
\r
286 //===========================================================================
\r
289 ===================
\r
293 ===================
\r
296 #define PIXPERFRAME 1600
\r
298 void FizzleFade (unsigned source, unsigned dest,
\r
299 unsigned width,unsigned height, boolean abortable, global_game_variables_t *gv)
\r
301 unsigned drawofs,pagedelta;
\r
302 unsigned char maskb[8] = {1,2,4,8,16,32,64,128};
\r
303 unsigned x,y,p,frame;
\r
305 word TimeCount = *clockw;
\r
306 word screenseg = SCREENSEG;
\r
308 pagedelta = dest-source;
\r
309 //++++ VL_SetScreen (dest,0);
\r
325 IN_ReadControl(0,gv);
\r
326 if (gv->player[0].info.button0 || gv->player[0].info.button1 || gv->in.inst->Keyboard[sc_Space]
\r
327 || gv->in.inst->Keyboard[sc_Enter])
\r
329 //++++ VW_ScreenToScreen (source,dest,width/8,height);
\r
334 for (p=0;p<PIXPERFRAME;p++)
\r
337 // seperate random value into x/y pair
\r
340 mov ax,[WORD PTR rndval]
\r
341 mov dx,[WORD PTR rndval+2]
\r
344 mov [BYTE PTR y],bl // low 8 bits - 1 = y xoordinate
\r
356 mov [x],bx // next 9 bits = x xoordinate
\r
358 // advance to next random element
\r
365 #ifdef __BORLANDC__
\r
369 #ifdef __BORLANDC__
\r
372 mov [WORD PTR rndval],ax
\r
373 mov [WORD PTR rndval+2],dx
\r
376 if (x>width || y>height)
\r
378 drawofs = source+gv->video.ofs.ylookup[y];
\r
386 mov ah,BYTE PTR [maskb+si]
\r
398 mov al,GC_READMAP // leave GC_INDEX set to READMAP
\r
442 if (rndval == 1) // entire sequence has been completed
\r
444 //++++ VGABITMASK(255);
\r
445 //++++ VGAMAPMASK(15);
\r
450 //++++ while (TimeCount<frame){} // don't go too fast
\r
456 //===========================================================================
\r
466 void DebugMemory_(global_game_variables_t *gvar, boolean q)
\r
468 /*VW_FixRefreshBuffer ();
\r
469 US_CenterWindow (16,7);
\r
471 US_CPrint ("Memory Usage");
\r
472 US_CPrint ("------------");
\r
473 US_Print ("Total :");
\r
474 US_PrintUnsigned (mminfo.mainmem/1024);
\r
475 US_Print ("k\nFree :");
\r
476 US_PrintUnsigned (MM_UnusedMemory()/1024);
\r
477 US_Print ("k\nWith purge:");
\r
478 US_PrintUnsigned (MM_TotalFree()/1024);
\r
480 VW_UpdateScreen();*/
\r
482 printf("========================================\n");
\r
483 printf(" DebugMemory_\n");
\r
484 printf("========================================\n");}
\r
485 if(q) { printf("Memory Usage\n");
\r
486 printf("------------\n"); }else printf(" %c%c", 0xD3, 0xC4);
\r
487 printf("Total: "); if(q) printf(" "); printf("%uk", gvar->mmi.mainmem/1024);
\r
488 if(q) printf("\n"); else printf(" ");
\r
489 printf("Free: "); if(q) printf(" "); printf("%uk", MM_UnusedMemory(gvar)/1024);
\r
490 if(q) printf("\n"); else printf(" ");
\r
491 printf("With purge:"); if(q) printf(" "); printf("%uk\n", MM_TotalFree(gvar)/1024);
\r
492 if(q) printf("------------\n");
\r
496 // if(q) MM_ShowMemory (gvar);
\r
500 ==========================
\r
504 ==========================
\r
507 void ClearMemory (global_game_variables_t *gvar)
\r
510 PM_UnlockMainMem(gvar);
\r
517 ==========================
\r
521 ==========================
\r
524 void Quit (global_game_variables_t *gvar, char *error)
\r
526 //unsigned finscreen;
\r
529 ClearMemory (gvar);
\r
533 // CA_CacheGrChunk (ORDERSCREEN);
\r
534 // screen = grsegs[ORDERSCREEN];
\r
540 // CA_CacheGrChunk (ERRORSCREEN);
\r
541 // screen = grsegs[ERRORSCREEN];
\r
545 if (error && *error)
\r
547 //movedata((unsigned)screen,7,0xb800,0,7*160);
\r
549 fprintf(stderr, "%s\n", error);
\r
554 if (!error || !(*error))
\r
558 movedata ((unsigned)screen,7,0xb800,0,4000);
\r
562 //asm mov dh,23 // row
\r
563 //asm mov dl,0 // collumn
\r
571 //===========================================================================
\r
573 #ifndef __WATCOMC__
\r
574 char global_temp_status_text[512];
\r
575 char global_temp_status_text2[512];
\r
579 // this is from my XT's BIOS
\r
580 // http://www.phatcode.net/downloads.php?id=101
\r
582 void turboXT(byte bakapee)
\r
588 in al, 61h //; Read equipment flags
\r
589 xor al, bakapee //; toggle speed
\r
590 out 61h, al //; Write new flags back
\r
592 mov bx, 0F89h //; low pitch blip
\r
593 and al, 4 //; Is turbo mode set?
\r
595 mov bx, 52Eh //; high pitch blip
\r
598 mov al, 10110110b //; Timer IC 8253 square waves
\r
599 out 43h, al //; channel 2, speaker
\r
601 out 42h, al //; send low order
\r
602 mov al, ah //; load high order
\r
603 out 42h, al //; send high order
\r
604 in al, 61h //; Read IC 8255 machine status
\r
607 out 61h, al //; Turn speaker on
\r
612 out 61h, al //; Turn speaker off
\r
620 const char *word_to_binary(word x)
\r
626 for (z = 16; z > 0; z >>= 1)
\r
628 strcat(b, ((x & z) == z) ? "1" : "0");
\r
633 const char *nibble_to_binary(nibble x)
\r
639 for (z = 8; z > 0; z >>= 1)
\r
641 strcat(b, ((x & z) == z) ? "1" : "0");
\r
646 const char *boolean_to_binary(boolean x)
\r
652 for (z = 1; z > 0; z >>= 1)
\r
654 strcat(b, ((x & z) == z) ? "1" : "0");
\r
662 printf("nibbletest\n");
\r
663 /* nibble to binary string */
\r
664 for(pee=0;pee<18;pee++)
\r
665 printf(" %u %s\n", pee, nibble_to_binary(pee));
\r
666 printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));
\r
667 printf("end of nibble test\n");
\r
673 printf("booleantest\n");
\r
674 /* boolean to binary string */
\r
675 for(pee=0;pee<4;pee++)
\r
676 printf(" %u %s\n", pee, boolean_to_binary(pee));
\r
677 printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));
\r
678 printf("end of boolean test\n");
\r
681 #ifdef __BORLANDC__
\r
682 word modexPalOverscan(word col)
\r
684 //modexWaitBorder();
\r
685 outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */
\r
686 outp(PAL_DATA_REG, col);
\r