1 /* $Id: init.c,v 1.5 2004-05-21 00:48:12 btb Exp $ */
15 #define _BORLAND_DOS_REGS 1
33 //added on 9/15/98 by Victor Rachels to add cd controls
35 //end this section addition - Victor Rachels
38 void install_int3_handler(void);
41 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned far * devhdr );
50 heap_status = _heapset( 0xFF );
54 mprintf((1, "ERROR - heap is damaged\n"));
58 mprintf((1, "ERROR - bad node in heap\n" ));
69 int is_3dbios_installed()
72 memset(&rregs,0,sizeof(dpmi_real_regs));
75 dpmi_real_int386x( 0x10, &rregs );
76 if ( (rregs.edx & 0xFFFF) != 0x3344 )
83 // Returns 1 if ok, 0 if failed...
88 memset(®s,0,sizeof(regs));
91 int386( 0x15, ®s, ®s );
92 if ( ( regs.x.eax & 0xFFFF ) == 0x4753 /*'SG'*/ )
98 void check_dos_version()
103 memset(®s,0,sizeof(regs));
104 regs.x.eax = 0x3000; // Get MS-DOS Version Number
105 int386( 0x21, ®s, ®s );
111 printf( "Using MS-DOS version %d.%d\nThis is not compatable with Descent.", major, minor);
114 //printf( "\nUsing MS-DOS %d.%d...\n", major, minor );
117 void dos_check_file_handles(int num_required)
122 if ( num_required > 16 )
126 for (i=0; i<16; i++ )
128 for (i=0; i<16; i++ ) {
129 fp[i] = fopen( "nul", "wb" );
133 for (i=0; i<16; i++ ) {
137 if ( n < num_required ) {
138 printf( "\n%s\n", TXT_NOT_ENOUGH_HANDLES );
139 printf( "------------------------\n" );
140 printf( "%d/%d %s\n", n, num_required, TXT_HANDLES_1 );
141 printf( "%s\n", TXT_HANDLES_2);
142 printf( "%s\n", TXT_HANDLES_3);
147 #define NEEDED_DOS_MEMORY ( 300*1024) // 300 K
148 #define NEEDED_LINEAR_MEMORY (7680*1024) // 7.5 MB
149 #define LOW_PHYSICAL_MEMORY_CUTOFF (5*1024*1024) // 5.0 MB
150 #define NEEDED_PHYSICAL_MEMORY (2000*1024) // 2000 KB
152 extern int piggy_low_memory;
154 void mem_int_to_string( int number, char *dest )
159 sprintf( buffer, "%d", number );
163 // Don't bother with less than 3 digits
164 sprintf( dest, "%d", number );
170 for (i=0; i<l; i++ ) {
185 printf( "\n%s\n", TXT_AVAILABLE_MEMORY);
186 printf( "----------------\n" );
187 mem_int_to_string( dpmi_dos_memory/1024, text );
188 printf( "Conventional: %7s KB\n", text );
189 mem_int_to_string( dpmi_physical_memory/1024, text );
190 printf( "Extended: %7s KB\n", text );
191 if ( dpmi_available_memory > dpmi_physical_memory ) {
192 mem_int_to_string( (dpmi_available_memory-dpmi_physical_memory)/1024, text );
194 mem_int_to_string( 0, text );
196 printf( "Virtual: %7s KB\n", text );
199 if ( dpmi_dos_memory < NEEDED_DOS_MEMORY ) {
200 printf( "%d %s\n", NEEDED_DOS_MEMORY - dpmi_dos_memory, TXT_MEMORY_CONFIG );
204 if ( dpmi_available_memory < NEEDED_LINEAR_MEMORY ) {
205 if ( dpmi_virtual_memory ) {
206 printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_RECONFIGURE_VMM );
208 printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_MORE_MEMORY );
209 printf( "%s\n", TXT_MORE_MEMORY_2);
214 if ( dpmi_physical_memory < NEEDED_PHYSICAL_MEMORY ) {
215 printf( "%d %s\n", NEEDED_PHYSICAL_MEMORY - dpmi_physical_memory, TXT_PHYSICAL_MEMORY );
216 if ( dpmi_virtual_memory ) {
217 printf( "%s\n", TXT_PHYSICAL_MEMORY_2);
222 if ( dpmi_physical_memory < LOW_PHYSICAL_MEMORY_CUTOFF ) {
223 piggy_low_memory = 1;
227 //NO_STACK_SIZE_CHECK uint * stack, *stack_ptr;
228 //NO_STACK_SIZE_CHECK int stack_size, unused_stack_space;
229 //NO_STACK_SIZE_CHECK int sil;
230 //NO_STACK_SIZE_CHECK
231 //NO_STACK_SIZE_CHECK int main(int argc,char **argv)
232 //NO_STACK_SIZE_CHECK {
233 //NO_STACK_SIZE_CHECK uint ret_value;
234 //NO_STACK_SIZE_CHECK
235 //NO_STACK_SIZE_CHECK unused_stack_space = 0;
236 //NO_STACK_SIZE_CHECK stack = &ret_value;
237 //NO_STACK_SIZE_CHECK stack_size = stackavail()/4;
238 //NO_STACK_SIZE_CHECK
239 //NO_STACK_SIZE_CHECK for ( sil=0; sil<stack_size; sil++ ) {
240 //NO_STACK_SIZE_CHECK stack--;
241 //NO_STACK_SIZE_CHECK *stack = 0xface0123;
242 //NO_STACK_SIZE_CHECK }
243 //NO_STACK_SIZE_CHECK
244 //NO_STACK_SIZE_CHECK ret_value = descent_main( argc, argv ); // Rename main to be descent_main
245 //NO_STACK_SIZE_CHECK
246 //NO_STACK_SIZE_CHECK for ( sil=0; sil<stack_size; sil++ ) {
247 //NO_STACK_SIZE_CHECK if ( *stack == 0xface0123 )
248 //NO_STACK_SIZE_CHECK unused_stack_space++;
249 //NO_STACK_SIZE_CHECK stack++;
250 //NO_STACK_SIZE_CHECK }
251 //NO_STACK_SIZE_CHECK
252 //NO_STACK_SIZE_CHECK mprintf(( 0, "Program used %d/%d stack space\n", (stack_size - unused_stack_space)*4, stack_size*4 ));
253 //NO_STACK_SIZE_CHECK key_getch();
254 //NO_STACK_SIZE_CHECK
255 //NO_STACK_SIZE_CHECK return ret_value;
256 //NO_STACK_SIZE_CHECK }
258 extern int digi_timer_rate;
261 #pragma off (check_stack)
262 int __far descent_critical_error_handler(unsigned deverror, unsigned errcode, unsigned __far * devhdr )
265 descent_critical_error++;
266 descent_critical_deverror = deverror;
267 descent_critical_errcode = errcode;
268 return _HARDERR_FAIL;
270 void chandler_end (void) // dummy functions
273 #pragma on (check_stack)
276 void arch_init_start() {
277 // Initialize DPMI before anything else!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
278 // (To check memory size and availbabitliy and allocate some low DOS memory)
279 // adb: no TXT_... loaded yet
280 //if (Inferno_verbose) printf( "%s... ", TXT_INITIALIZING_DPMI);
281 con_printf(CON_VERBOSE, "Initializing DPMI services... ");
282 dpmi_init(1); // Before anything
283 con_printf(CON_VERBOSE, "\n" );
286 con_printf(CON_VERBOSE, "\n%s...", TXT_INITIALIZING_CRIT);
287 if (!dpmi_lock_region((void near *)descent_critical_error_handler,(char *)chandler_end - (char near *)descent_critical_error_handler)) {
288 Error( "Unable to lock critial error handler" );
290 if (!dpmi_lock_region(&descent_critical_error,sizeof(int))) {
291 Error( "Unable to lock critial error handler" );
293 if (!dpmi_lock_region(&descent_critical_deverror,sizeof(unsigned))) {
294 Error( "Unable to lock critial error handler" );
296 if (!dpmi_lock_region(&descent_critical_errcode,sizeof(unsigned))) {
297 Error( "Unable to lock critial error handler" );
299 _harderr((void *) descent_critical_error_handler );
300 //Above line modified by KRB, added (void *) cast
306 if ( !FindArg( "-nodoscheck" ))
309 if ( !FindArg( "-nofilecheck" ))
310 dos_check_file_handles(5);
312 if ( !FindArg( "-nomemcheck" ))
317 mopen( 0, 9, 1, 78, 15, "Debug Spew");
318 mopen( 1, 2, 1, 78, 5, "Errors & Serious Warnings");
321 /* if (!WVIDEO_running)
322 mprintf((0,"WVIDEO_running = %d\n",WVIDEO_running));*/
324 //if (!WVIDEO_running) install_int3_handler();
327 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_2);
329 timer_set_rate( digi_timer_rate ); // Tell our timer how fast to go (120 Hz)
330 joy_set_timer_rate( digi_timer_rate ); // Tell joystick how fast timer is going
332 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_3);
334 if (!FindArg( "-nomouse" )) {
335 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_4);
336 if (FindArg( "-nocyberman" ))
337 // added/edited on 1/13/00 by Victor Rachels to display mouse init errors
340 con_printf(CON_NORMAL, "\nError initializing mouse.\n");
345 con_printf(CON_NORMAL, "\nError initializing mouse.\n");
347 // end this section addition - VR
349 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_5);
351 if (!FindArg( "-nojoystick" )) {
352 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6);
354 if ( FindArg( "-joyslow" )) {
355 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_7);
356 joy_set_slow_reading(JOY_SLOW_READINGS);
358 if ( FindArg( "-joypolled" )) {
359 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_8);
360 joy_set_slow_reading(JOY_POLLED_READINGS);
362 if ( FindArg( "-joybios" )) {
363 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_9);
364 joy_set_slow_reading(JOY_BIOS_READINGS);
366 if ( FindArg( "-joynice" )) {
367 con_printf(CON_VERBOSE, "\n%s", "Using nice joystick poller..." );
368 joy_set_slow_reading(JOY_FRIENDLY_READINGS);
370 if ( FindArg( "-gameport" )) {
371 if ( init_gameport() ) {
372 joy_set_slow_reading(JOY_BIOS_READINGS);
374 Error( "\nCouldn't initialize the Notebook Gameport.\nMake sure the NG driver is loaded.\n" );
378 con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_10);
381 if (Inferno_verbose) printf( "\n%s", TXT_VERBOSE_11);