2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
14 #include "pa_enabl.h" //$$POLY_ACC
28 // New for VGA Library.
39 // Global Variables -----------------------------------------------------------
41 ubyte *vga_screen_addr = NULL;
43 unsigned char * vga_video_memory = (unsigned char *)0xA0000;
45 char vga_pal_default[768];
47 int vga_installed = 0;
49 //extern int gr_palette_realized;
50 int vga_prevent_palette_loading = 0;
52 ubyte * pVideoMode = (volatile ubyte *)0x449;
53 uword * pNumColumns = (volatile uword *)0x44a;
54 ubyte * pNumRows = (volatile ubyte *)0x484;
55 uword * pCharHeight = (volatile uword *)0x485;
56 uword * pCursorPos = (volatile uword *)0x450;
57 uword * pCursorType = (volatile uword *)0x460;
58 uword * pTextMemory = (volatile uword *)0xb8000;
60 ubyte saved_video_mode = 0;
61 uword saved_num_columns = 0;
62 ubyte saved_num_rows = 0;
63 uword saved_char_height = 0;
64 uword saved_cursor_pos = 0;
65 uword saved_cursor_type = 0;
66 ubyte saved_is_graphics = 0;
67 uword * saved_video_memory = NULL;
69 int cga_show_screen_info = 0;
72 // VGA Functions --------------------------------------------------------------
74 ubyte vga_get_screen_mode( void )
79 int386( 0x10, ®s, ®s );
80 return regs.w.ax & 0xff;
83 void vga_set_cellheight( ubyte height )
96 outpw( 0x3c4, 0xE04 ); // enable chain4 mode
97 outpw( 0x3d4, 0x4014 ); // turn on dword mode
98 outpw( 0x3d4, 0xa317 ); // turn off byte mode
103 outpw( 0x3ce, 0x4005 ); // set Shift reg to 1
105 inp( 0x3da ); // dummy input
108 outp( 0x3c0, 0x61 ); // turns on PCS & PCC
110 inp( 0x3da ); // dummy input
116 void vga_turn_screen_off()
123 void vga_turn_screen_on()
130 void vga_set_misc_mode( uword mode )
135 int386( 0x10, ®s, ®s );
139 void gr_set_3dbios_mode( uint mode )
142 memset( ®s, 0, sizeof(regs) );
144 regs.w.bx = 0x3d00 | (mode & 0xff);
145 int386( 0x10, ®s, ®s );
149 void vga_set_text_25()
154 int386( 0x10, ®s, ®s );
158 void vga_set_text_43()
164 int386( 0x10, ®s, ®s );
167 int386( 0x10, ®s, ®s );
171 int386( 0x10, ®s, ®s );
174 void vga_set_text_50()
180 int386( 0x10, ®s, ®s );
183 int386( 0x10, ®s, ®s );
187 int386( 0x10, ®s, ®s );
190 ubyte is_graphics_mode()
193 tmp = inp( 0x3DA ); // Reset flip-flip
194 outp( 0x3C0, 0x30 ); // Select attr register 10
195 tmp = inp( 0x3C1 ); // Get graphics/text bit
203 saved_video_mode = vga_get_screen_mode();
204 saved_num_columns = *pNumColumns;
205 saved_num_rows = *pNumRows+1;
206 saved_char_height = *pCharHeight;
207 saved_cursor_pos = *pCursorPos;
208 saved_cursor_type = *pCursorType;
209 saved_is_graphics = is_graphics_mode();
211 if (saved_is_graphics==0)
213 MALLOC(saved_video_memory,uword, saved_num_columns*saved_num_rows );
215 for (i=0; i < saved_num_columns*saved_num_rows; i++ )
216 saved_video_memory[i] = pTextMemory[i];
219 if (cga_show_screen_info )
221 printf( "Current video mode 0x%x:\n", saved_video_mode );
222 if (saved_is_graphics)
223 printf( "Graphics mode\n" );
225 printf( "Text mode\n" );
227 printf( "( %d columns by %d rows)\n", saved_num_columns, saved_num_rows );
228 printf( "Char height is %d pixel rows\n", saved_char_height );
229 printf( "Cursor of type 0x%x is at (%d, %d)\n", saved_cursor_type, saved_cursor_pos & 0xFF, saved_cursor_pos >> 8 );
240 int386( 0x10, ®s, ®s );
242 if ( regs.h.al != 0x1a ) return 0;
243 if ( (regs.h.bl==7) || (regs.h.bl==8)) return 1;
247 void vga_set_cursor_type( uword ctype )
253 int386( 0x10, ®s, ®s );
256 void vga_enable_default_palette_loading()
261 int386( 0x10, ®s, ®s );
262 vga_prevent_palette_loading = 0;
265 void vga_disable_default_palette_loading()
270 int386( 0x10, ®s, ®s );
271 vga_prevent_palette_loading = 1;
274 void vga_set_cursor_position( uword position )
280 regs.w.dx = position;
281 int386( 0x10, ®s, ®s );
285 void vga_restore_mode()
289 if ( saved_video_mode == 3 )
291 switch( saved_num_rows )
293 case 43: vga_set_text_43(); break;
294 case 50: vga_set_text_50(); break;
295 default: vga_set_text_25(); break;
298 vga_set_misc_mode(saved_video_mode);
301 if (saved_is_graphics==0)
303 for (i=0; i < saved_num_columns*saved_num_rows; i++ )
304 pTextMemory[i]=saved_video_memory[i];
305 vga_set_cursor_type( saved_cursor_type );
306 vga_set_cursor_position( saved_cursor_pos );
312 #if defined(POLY_ACC)
316 if (vga_installed==1)
320 if( saved_video_memory )
321 free(saved_video_memory);
327 int LinearSVGABuffer=0;
329 int vga_vesa_setmode( short mode )
333 #if defined(POLY_ACC)
335 mprintf((0, "vga_vesa_setmode %d\n"));
339 if (VesaInit (mode)) // if there is an error with linear support
346 retcode=gr_vesa_checkmode( mode ); // do the old banking way
347 if ( retcode ) return retcode;
348 return gr_vesa_setmodea( mode );
351 int VGA_current_mode = SM_ORIGINAL;
352 extern int VesaGetRowSize (int);
354 short vga_set_mode(short mode)
357 unsigned int w,h,t,data, r;
359 #if defined(POLY_ACC)
360 if(mode != SM_640x480x15xPA)
363 mprintf((0, "vga_set_mode(%d)\n", mode));
380 if (!isvga()) return 1;
381 vga_set_misc_mode(0x13);
382 w = 320; r = 320; h = 200; t=BM_LINEAR; data = 0xA0000;
386 retcode = vga_vesa_setmode( 0x100 );
387 //gr_enable_default_palette_loading();
388 if (retcode !=0 ) return retcode;
389 w = 640; r = 640; h = 400; t=BM_SVGA; data = 0;
393 retcode = vga_vesa_setmode( 0x101 );
394 //gr_enable_default_palette_loading();
395 if (retcode !=0 ) return retcode;
396 w = 640; r = 640; h = 480; t=BM_SVGA; data = 0;
400 retcode = vga_vesa_setmode( 0x103 );
401 //gr_enable_default_palette_loading();
402 if (retcode !=0 ) return retcode;
403 w = 800; h = 600; t=BM_SVGA; data = 0;
404 r=VesaGetRowSize (0x103);
408 retcode = vga_vesa_setmode( 0x105 );
409 //gr_enable_default_palette_loading();
410 if (retcode !=0 ) return retcode;
411 w = 1024; r = 1024; h = 768; t=BM_SVGA; data = 0;
412 r=VesaGetRowSize (0x105);
416 retcode = vga_vesa_setmode( 0x107 );
417 //gr_enable_default_palette_loading();
418 if (retcode !=0 ) return retcode;
419 w = 1280; r = 1280; h = 1024; t=BM_SVGA; data = 0;
420 r=VesaGetRowSize (0x107);
424 retcode = vga_vesa_setmode( 0x110 );
425 //gr_enable_default_palette_loading();
426 if (retcode !=0 ) return retcode;
427 w = 640; r = 640*2; h=480; t=BM_SVGA15; data = 0;
431 retcode = vga_vesa_setmode( 0x113 );
432 //gr_enable_default_palette_loading();
433 if (retcode !=0 ) return retcode;
434 w = 800; r = 800*2; h=600; t=BM_SVGA15; data = 0;
437 //super-special code for 3dmax high-res mode
438 case SM_320x400_3DMAX: // 3dmax 320x400
439 if (!isvga()) return 1;
440 gr_set_3dbios_mode(0x31);
441 //w = 320; r = 320/4; h = 400; t=BM_MODEX; data = 0;
442 w = 320; r = 320; h = 400; t=BM_SVGA; data = 0;
446 //@@ if (!isvga()) return 1;
447 //@@ vga_set_misc_mode(0x13);
448 //@@ vga_set_cellheight( 3 );
449 //@@ w = 320; r = 320; h = 200; t=BM_LINEAR; data = 0xA0000;
453 //@@ retcode = vga_vesa_setmode( 0x102 );
454 //@@ //gr_enable_default_palette_loading();
455 //@@ if (retcode !=0 ) return retcode;
456 //@@ vga_16_to_256();
457 //@@ vga_set_linear();
458 //@@ //gr_set_cellheight( 1 );
459 //@@ gr_vesa_setlogical( 400 );
460 //@@ w = 400; r = 400; h = 600; t=BM_SVGA; data = 0;
464 //@@ if (!isvga()) return 1;
465 //@@ vga_set_misc_mode(0xd);
466 //@@ vga_16_to_256();
467 //@@ vga_set_linear();
468 //@@ //gr_set_cellheight( 3 );
469 //@@ w = 160; r = 160; h = 200; t=BM_LINEAR; data = 0xA0000;
483 case SM_376x564U: //mode X modes
485 if (!isvga()) return 1;
486 w = gr_modex_setmode( mode );
487 //gr_enable_default_palette_loading();
488 h = w & 0xffff; w = w >> 16; r = w / 4;t = BM_MODEX; data = 0;
491 #if defined(POLY_ACC)
492 case SM_640x480x15xPA:
494 w = 640; r = 640*2; h=480; t=BM_LINEAR15; data = 0; //$$ data should be what?
495 #ifdef PA_3DFX_VOODOO
501 default: //unknown mode!!! Very bad!!
502 Error("Unknown mode %d in vga_set_mode()",mode);
505 // if (vga_palette_realized && (vga_prevent_palette_loading==0))
506 // gr_pal_setblock( 0, 256, gr_palette);
510 VGA_current_mode = mode;
511 #if defined(POLY_ACC)
512 vga_screen_addr = pa_get_buffer_address(0);
514 if (LinearSVGABuffer)
516 mprintf ((0,"GREEEEAT!\n"));
518 vga_screen_addr=(ubyte *)VesaGetPtr();
521 vga_screen_addr=(ubyte *)0xa0000;
525 return gr_init_screen( t,w,h,0,0,r,vga_screen_addr);
531 // Only do this function once!
532 if (vga_installed==1)
535 #if !defined(POLY_ACC)
540 vga_screen_addr = (ubyte *)0xa0000; //address in memory of screen
542 // Save the current text screen mode
543 if (vga_save_mode()==1)
546 /* if (get_selector( &vga_fade_table, 256*GR_FADE_LEVELS, &vga_fade_table_selector ))
547 Error( "Error allocating fade table selector!" );
549 if (get_selector( &vga_palette, 256*3, &vga_palette_selector ))
550 Error( "Error allocating palette selector!" );
552 if (get_selector( &vga_inverse_table, 32*32*32, &vga_inverse_table_selector ))
553 Error( "Error allocating inverse table selector!" );
556 // Set flags indicating that this is installed.
557 // gr_palette_clear();
561 #if defined(POLY_ACC)
567 short vga_mode13_checkmode()
576 // 1=No VGA adapter installed
577 // 2=Program doesn't support this VESA granularity
578 // 3=Monitor doesn't support that VESA mode.:
579 // 4=Video card doesn't support that VESA mode.
580 // 5=No VESA driver found.
581 // 6=Bad Status after VESA call/
582 // 7=Not enough DOS memory to call VESA functions.
583 // 8=Error using DPMI.
584 // 9=Error setting logical line width.
585 // 10=Error allocating selector for A0000h
586 // 11=Not a valid mode support by gr.lib
588 short vga_check_mode(short mode)
590 #if defined(POLY_ACC)
591 if(mode != SM_640x480x15xPA)
610 case SM_376x564U: return vga_mode13_checkmode();
611 case SM_640x400V: return gr_vesa_checkmode( 0x100 );
612 case SM_640x480V: return gr_vesa_checkmode( 0x101 );
613 case SM_800x600V: return gr_vesa_checkmode( 0x103 );
614 case SM_1024x768V: return gr_vesa_checkmode( 0x105 );
615 case SM_640x480V15: return gr_vesa_checkmode( 0x110 );
616 case SM_800x600V15: return gr_vesa_checkmode( 0x113 );
617 #if defined(POLY_ACC)
618 case SM_640x480x15xPA: return pa_detect(mode);