2 * $Source: /cvs/cvsroot/d2x/unused/vga/vga.jas,v $
5 * $Date: 2001-01-19 03:33:51 $
9 * $Log: not supported by cvs2svn $
10 * Revision 1.14 1996/01/02 18:00:51 matt
11 * New parms for gr_init_screen
13 * Revision 1.13 1995/12/19 13:46:05 matt
14 * Use symbolic constant for special 3dmax mode
16 * Revision 1.12 1995/12/13 18:03:03 matt
17 * From JOHN: added code for special 3dbios mode
19 * Revision 1.11 1995/12/13 16:28:54 matt
20 * Use more legal way of checking screen mode
22 * Revision 1.10 1995/11/28 10:30:22 matt
23 * Added support for 1280x1024
25 * Revision 1.9 1995/11/22 12:52:42 matt
26 * Changed numeric literals to symbolic constants
28 * Revision 1.8 1995/11/16 12:00:17 jed
29 * killed some prototype stuff
31 * Revision 1.7 1995/11/14 18:11:07 jed
32 * added code to support linear frame buffering
34 * Revision 1.6 1995/08/30 21:11:26 matt
35 * Added global containing current VGA mode
37 * Revision 1.5 1995/06/05 12:41:37 samir
38 * Moved gr_palette_clear from gr.c to vga.c
40 * Revision 1.4 1995/05/31 10:54:26 matt
59 // New for VGA Library.
67 // Global Variables -----------------------------------------------------------
69 ubyte *vga_screen_addr = NULL;
71 unsigned char * vga_video_memory = (unsigned char *)0xA0000;
73 char vga_pal_default[768];
75 int vga_installed = 0;
77 //extern int gr_palette_realized;
78 int vga_prevent_palette_loading = 0;
80 ubyte * pVideoMode = (volatile ubyte *)0x449;
81 uword * pNumColumns = (volatile uword *)0x44a;
82 ubyte * pNumRows = (volatile ubyte *)0x484;
83 uword * pCharHeight = (volatile uword *)0x485;
84 uword * pCursorPos = (volatile uword *)0x450;
85 uword * pCursorType = (volatile uword *)0x460;
86 uword * pTextMemory = (volatile uword *)0xb8000;
88 ubyte saved_video_mode = 0;
89 uword saved_num_columns = 0;
90 ubyte saved_num_rows = 0;
91 uword saved_char_height = 0;
92 uword saved_cursor_pos = 0;
93 uword saved_cursor_type = 0;
94 ubyte saved_is_graphics = 0;
95 uword * saved_video_memory = NULL;
97 int cga_show_screen_info = 0;
100 // VGA Functions --------------------------------------------------------------
102 ubyte vga_get_screen_mode( void )
107 int386( 0x10, ®s, ®s );
108 return regs.w.ax & 0xff;
111 void vga_set_cellheight( ubyte height )
122 void vga_set_linear()
124 outpw( 0x3c4, 0xE04 ); // enable chain4 mode
125 outpw( 0x3d4, 0x4014 ); // turn on dword mode
126 outpw( 0x3d4, 0xa317 ); // turn off byte mode
131 outpw( 0x3ce, 0x4005 ); // set Shift reg to 1
133 inp( 0x3da ); // dummy input
136 outp( 0x3c0, 0x61 ); // turns on PCS & PCC
138 inp( 0x3da ); // dummy input
144 void vga_turn_screen_off()
151 void vga_turn_screen_on()
158 void vga_set_misc_mode( uword mode )
163 int386( 0x10, ®s, ®s );
167 void gr_set_3dbios_mode( uint mode )
170 memset( ®s, 0, sizeof(regs) );
172 regs.w.bx = 0x3d00 | (mode & 0xff);
173 int386( 0x10, ®s, ®s );
177 void vga_set_text_25()
182 int386( 0x10, ®s, ®s );
186 void vga_set_text_43()
192 int386( 0x10, ®s, ®s );
195 int386( 0x10, ®s, ®s );
199 int386( 0x10, ®s, ®s );
202 void vga_set_text_50()
208 int386( 0x10, ®s, ®s );
211 int386( 0x10, ®s, ®s );
215 int386( 0x10, ®s, ®s );
218 ubyte is_graphics_mode()
221 tmp = inp( 0x3DA ); // Reset flip-flip
222 outp( 0x3C0, 0x30 ); // Select attr register 10
223 tmp = inp( 0x3C1 ); // Get graphics/text bit
231 saved_video_mode = vga_get_screen_mode();
232 saved_num_columns = *pNumColumns;
233 saved_num_rows = *pNumRows+1;
234 saved_char_height = *pCharHeight;
235 saved_cursor_pos = *pCursorPos;
236 saved_cursor_type = *pCursorType;
237 saved_is_graphics = is_graphics_mode();
239 if (saved_is_graphics==0)
241 MALLOC(saved_video_memory,uword, saved_num_columns*saved_num_rows );
243 for (i=0; i < saved_num_columns*saved_num_rows; i++ )
244 saved_video_memory[i] = pTextMemory[i];
247 if (cga_show_screen_info )
249 printf( "Current video mode 0x%x:\n", saved_video_mode );
250 if (saved_is_graphics)
251 printf( "Graphics mode\n" );
253 printf( "Text mode\n" );
255 printf( "( %d columns by %d rows)\n", saved_num_columns, saved_num_rows );
256 printf( "Char height is %d pixel rows\n", saved_char_height );
257 printf( "Cursor of type 0x%x is at (%d, %d)\n", saved_cursor_type, saved_cursor_pos & 0xFF, saved_cursor_pos >> 8 );
268 int386( 0x10, ®s, ®s );
270 if ( regs.h.al != 0x1a ) return 0;
271 if ( (regs.h.bl==7) || (regs.h.bl==8)) return 1;
275 void vga_set_cursor_type( uword ctype )
281 int386( 0x10, ®s, ®s );
284 void vga_enable_default_palette_loading()
289 int386( 0x10, ®s, ®s );
290 vga_prevent_palette_loading = 0;
293 void vga_disable_default_palette_loading()
298 int386( 0x10, ®s, ®s );
299 vga_prevent_palette_loading = 1;
302 void vga_set_cursor_position( uword position )
308 regs.w.dx = position;
309 int386( 0x10, ®s, ®s );
313 void vga_restore_mode()
317 if ( saved_video_mode == 3 )
319 switch( saved_num_rows )
321 case 43: vga_set_text_43(); break;
322 case 50: vga_set_text_50(); break;
323 default: vga_set_text_25(); break;
326 vga_set_misc_mode(saved_video_mode);
329 if (saved_is_graphics==0)
331 for (i=0; i < saved_num_columns*saved_num_rows; i++ )
332 pTextMemory[i]=saved_video_memory[i];
333 vga_set_cursor_type( saved_cursor_type );
334 vga_set_cursor_position( saved_cursor_pos );
341 if (vga_installed==1)
345 if( saved_video_memory )
346 free(saved_video_memory);
352 int LinearSVGABuffer=0;
354 int vga_vesa_setmode( short mode )
358 if (VesaInit (mode)) // if there is an error with linear support
365 retcode=gr_vesa_checkmode( mode ); // do the old banking way
366 if ( retcode ) return retcode;
367 return gr_vesa_setmodea( mode );
370 int VGA_current_mode = SM_ORIGINAL;
374 extern int Virge_enabled;
377 short vga_set_mode(short mode)
380 unsigned int w,h,t,data, r;
397 if (!isvga()) return 1;
398 vga_set_misc_mode(0x13);
399 w = 320; r = 320; h = 200; t=BM_LINEAR; data = 0xA0000;
403 retcode = vga_vesa_setmode( 0x100 );
404 //gr_enable_default_palette_loading();
405 if (retcode !=0 ) return retcode;
406 w = 640; r = 640; h = 400; t=BM_SVGA; data = 0;
410 retcode = vga_vesa_setmode( 0x101 );
411 //gr_enable_default_palette_loading();
412 if (retcode !=0 ) return retcode;
413 w = 640; r = 640; h = 480; t=BM_SVGA; data = 0;
417 retcode = vga_vesa_setmode( 0x103 );
418 //gr_enable_default_palette_loading();
419 if (retcode !=0 ) return retcode;
420 w = 800; r = 800; h = 600; t=BM_SVGA; data = 0;
424 retcode = vga_vesa_setmode( 0x105 );
425 //gr_enable_default_palette_loading();
426 if (retcode !=0 ) return retcode;
427 w = 1024; r = 1024; h = 768; t=BM_SVGA; data = 0;
431 retcode = vga_vesa_setmode( 0x107 );
432 //gr_enable_default_palette_loading();
433 if (retcode !=0 ) return retcode;
434 w = 1280; r = 1280; h = 1024; t=BM_SVGA; data = 0;
438 retcode = vga_vesa_setmode( 0x110 );
439 //gr_enable_default_palette_loading();
440 if (retcode !=0 ) return retcode;
441 w = 640; r = 640*2; h=480; t=BM_SVGA15; data = 0;
445 retcode = vga_vesa_setmode( 0x113 );
446 //gr_enable_default_palette_loading();
447 if (retcode !=0 ) return retcode;
448 w = 800; r = 800*2; h=600; t=BM_SVGA15; data = 0;
451 //super-special code for 3dmax high-res mode
452 case SM_320x400_3DMAX: // 3dmax 320x400
453 if (!isvga()) return 1;
454 gr_set_3dbios_mode(0x31);
455 //w = 320; r = 320/4; h = 400; t=BM_MODEX; data = 0;
456 w = 320; r = 320; h = 400; t=BM_SVGA; data = 0;
460 //@@ if (!isvga()) return 1;
461 //@@ vga_set_misc_mode(0x13);
462 //@@ vga_set_cellheight( 3 );
463 //@@ w = 320; r = 320; h = 200; t=BM_LINEAR; data = 0xA0000;
467 //@@ retcode = vga_vesa_setmode( 0x102 );
468 //@@ //gr_enable_default_palette_loading();
469 //@@ if (retcode !=0 ) return retcode;
470 //@@ vga_16_to_256();
471 //@@ vga_set_linear();
472 //@@ //gr_set_cellheight( 1 );
473 //@@ gr_vesa_setlogical( 400 );
474 //@@ w = 400; r = 400; h = 600; t=BM_SVGA; data = 0;
478 //@@ if (!isvga()) return 1;
479 //@@ vga_set_misc_mode(0xd);
480 //@@ vga_16_to_256();
481 //@@ vga_set_linear();
482 //@@ //gr_set_cellheight( 3 );
483 //@@ w = 160; r = 160; h = 200; t=BM_LINEAR; data = 0xA0000;
497 case SM_376x564U: //mode X modes
499 if (!isvga()) return 1;
500 w = gr_modex_setmode( mode );
501 //gr_enable_default_palette_loading();
502 h = w & 0xffff; w = w >> 16; r = w / 4;t = BM_MODEX; data = 0;
505 default: //unknown mode!!! Very bad!!
506 Error("Unknown mode %d in vga_set_mode()",mode);
509 // if (vga_palette_realized && (vga_prevent_palette_loading==0))
510 // gr_pal_setblock( 0, 256, gr_palette);
514 VGA_current_mode = mode;
515 if (LinearSVGABuffer)
517 mprintf ((0,"GREEEEAT!\n"));
519 vga_screen_addr=(ubyte *)VesaGetPtr();
522 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)
538 vga_screen_addr = (ubyte *)0xa0000; //address in memory of screen
540 // Save the current text screen mode
541 if (vga_save_mode()==1)
544 /* if (get_selector( &vga_fade_table, 256*GR_FADE_LEVELS, &vga_fade_table_selector ))
545 Error( "Error allocating fade table selector!" );
547 if (get_selector( &vga_palette, 256*3, &vga_palette_selector ))
548 Error( "Error allocating palette selector!" );
550 if (get_selector( &vga_inverse_table, 32*32*32, &vga_inverse_table_selector ))
551 Error( "Error allocating inverse table selector!" );
554 // Set flags indicating that this is installed.
562 short vga_mode13_checkmode()
571 // 1=No VGA adapter installed
572 // 2=Program doesn't support this VESA granularity
573 // 3=Monitor doesn't support that VESA mode.:
574 // 4=Video card doesn't support that VESA mode.
575 // 5=No VESA driver found.
576 // 6=Bad Status after VESA call/
577 // 7=Not enough DOS memory to call VESA functions.
578 // 8=Error using DPMI.
579 // 9=Error setting logical line width.
580 // 10=Error allocating selector for A0000h
581 // 11=Not a valid mode support by gr.lib
583 short vga_check_mode(short mode)
600 case SM_376x564U: return vga_mode13_checkmode();
601 case SM_640x400V: return gr_vesa_checkmode( 0x100 );
602 case SM_640x480V: return gr_vesa_checkmode( 0x101 );
603 case SM_800x600V: return gr_vesa_checkmode( 0x103 );
604 case SM_1024x768V: return vga_vesa_setmode( 0x105 );
605 case SM_640x480V15: return vga_vesa_setmode( 0x110 );
606 case SM_800x600V15: return vga_vesa_setmode( 0x113 );