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