Talk:Mode X

From Wikipedia, the free encyclopedia

[edit] 640x400

Removed reference to 640x400 in 256 colours being possible, and reverted to correct 360x480. The contributor may have mistaken the fact that the VGA has enough VRAM to provide a 256 colour 640x400 mode with the fact that the VGA doesn't have enough memory bandwidth to display such a mode.

Nominally, the VGA can display 720 pixels and 480 lines in 16 colours. 256 colour modes require 2 dot clocks as there is twice the bits per pixel as in the 16-colour mode. This reduces the highest supported horizontal width to 360 pixels. While it is true that these specs can be exceeded by taking the video timing outside of specification I doubt any monitor could sync to to the very low refresh rate that would be needed to make a 640x400 mode possible, and besides it would be eye-wateringly, headache inducingly bad.

Funkymonkey Thu 10 Nov, 2005

[edit] Source Code

Wikipedia is not sourceforge so it shouldn't contain any source code (maybe a snipet or two in very specific cases where it's warranted). For now I am pasting the code here, but it probably doesn't even belong in the talk page. Is this code even in the public domain? I don't know what the copyright issues are in this specific case. Dori 17:48, Oct 25, 2003 (UTC)

//Video.h 
unsigned char *v_mem; 
int v_draw; 
int v_show; 

void v_init() 
{ 
  cli(); //<<Upgrade by Epp 
  v_mem = (unsigned char*) 0xa0000; 
  int crtc11; 

  outport(0x3d4, 0x11); // unlock crtc 
  crtc11 = inport(0x3d5) & 0x7f; 
  outport(0x3d4, 0x11); 
  outport(0x3d5, crtc11); 

  /*width   = 320; 
  height  = 240; 
  maxx    = 319; 
  maxy    = 239; 
  pages   = 3; 
  lineSize = 80; 
  pageSize = 76800; 
  modeName = "320x240";*/ 

  outport(0x3c2, 0xe3);   // mor 
  
  outport(0x3d4, 0x00); // crtc 
  outport(0x3d5, 0x5f); 

  outport(0x3d4, 0x01); // crtc 
  outport(0x3d5, 0x4f); 

  outport(0x3d4, 0x02); // crtc 
  outport(0x3d5, 0x50); 

  outport(0x3d4, 0x03); // crtc 
  outport(0x3d5, 0x82); 

  outport(0x3d4, 0x04); // crtc 
  outport(0x3d5, 0x54); 

  outport(0x3d4, 0x05); // crtc 
  outport(0x3d5, 0x80); 

  outport(0x3d4, 0x06); // crtc 
  outport(0x3d5, 0x0d); 

  outport(0x3d4, 0x07); // crtc 
  outport(0x3d5, 0x3e); 

  outport(0x3d4, 0x08); // crtc 
  outport(0x3d5, 0x00); 

  outport(0x3d4, 0x09); // crtc 
  outport(0x3d5, 0x41); 

  outport(0x3d4, 0x10); // crtc 
  outport(0x3d5, 0xea); 

  outport(0x3d4, 0x11); // crtc 
  outport(0x3d5, 0xac); 

  outport(0x3d4, 0x12); // crtc 
  outport(0x3d5, 0xdf); 

  outport(0x3d4, 0x13); // crtc 
  outport(0x3d5, 0x28); 

  outport(0x3d4, 0x14); // crtc 
  outport(0x3d5, 0x00); 

  outport(0x3d4, 0x15); // crtc 
  outport(0x3d5, 0xe7); 

  outport(0x3d4, 0x16); // crtc 
  outport(0x3d5, 0x06); 

  outport(0x3d4, 0x17); // crtc 
  outport(0x3d5, 0xe3); 

  outport(0x3c4, 0x01); // seq 
  outport(0x3c5, 0x01); 

  outport(0x3c4, 0x04); // seq 
  outport(0x3c5, 0x06); 

  outport(0x3ce, 0x05); // gcr 
  outport(0x3cf, 0x40); 

  outport(0x3ce, 0x06); // gcr 
  outport(0x3cf, 0x05); 

  inport(0x3da);          // acr 
  outport(0x3c0, 0x10 | 0x20); 
  outport(0x3c0, 0x41); 

  inport(0x3da);          // acr 
  outport(0x3c0, 0x13 | 0x20); 
  outport(0x3c0, 0x00); 

  outport(0x3d4, 0x11); // lock crtc 
  crtc11 = inport(0x3d5) | 0x80; 
  outport(0x3d4, 0x11); 
  outport(0x3d5, crtc11); 
  sti(); //<<Upgrade by Epp 
} 
        
        
//Clears ALL THE PAGES 
void v_clear(unsigned char color) 
{ 
  cli(); //<<Upgrade by Epp 
  unsigned long color4 = ((color) | (color << 8)); 
  color4 = ((color4) | (color4 <<  16)); 
  outport(0x3c4, 2); // map mask reg 
  outport(0x3c5, 0xF); // select all planes to wirte to so we can clear them all at once 
  unsigned long *videomem_long = (unsigned long*) 0xa0000; 
  int count; 
  for(count=0;count<((76800)/4);count++) 
  { 
    videomem_long[count]=color4;      
  } 
  sti(); //<<Upgrade by Epp 
} 
        
//Sets the current page where everything is drawn to 
void v_setdrawpage(int sdp) 
{ 
  v_draw=sdp; 
} 
        
//Sets the current page which is shown to the screen 
void v_setshowpage(int ssp) 
{ 
  cli(); //<<Upgrade by Epp 
  v_show=ssp; 
  int long offset; 
  offset = ssp * (76800) / 4; 
  while(inport(0x3da) & 0x01)       // wait for display disable 
  { 
  } 
  outport(0x3d4, 0x0c); 
  outport(0x3d5, (offset & 0xff00) >> 8); 
  outport(0x3d4, 0x0d); 
  outport(0x3d5, offset & 0x00ff); 
  // you can spend a lot of CPU time in this little loop 
  while(!(inport(0x3da) & 0x08));    // wait for vertical retrace 
  { 
  } 
  sti(); //<<Upgrade by Epp 
} 
        
//Puts a pixel in the draw page 
void v_putpixel(signed short px,signed short py,unsigned char pc) 
{ 
  cli(); //<<Upgrade by Epp 
  // set the mask so that only one pixel gets written 
  outport(0x3c4, 0x02); 
  outport(0x3c5, 1 << (px & 0x3)); 
  unsigned char *mem_char = (unsigned char*) 0xa0000 + (v_draw * (76800) / 4); 
  mem_char[(80 * py) + (px >> 2)] = pc; 
  sti(); //<<Upgrade by Epp 
} 
              
//Gets a pixel on the draw page 
unsigned char v_getpixel(signed short gx,signed short gy) 
{ 
  cli(); //<<Upgrade by Epp 
  outport(0x3ce, 0x04); 
  outport(0x3cf, gx & 0x3); 
  unsigned char *mem_char = (unsigned char*) 0xa0000 + (v_draw * (76800) / 4); 
  sti(); //<<Upgrade by Epp 
  return mem_char[(80 * gy) + (gx >> 2)]; 
} 

void v_flip() 
{ 
  int temp; 
  temp=v_show; 
  v_show=v_draw; 
  v_draw=temp; 
  v_setshowpage(v_show); 
}

[edit] DOCUMENTATION

I am not sure 'MODE X' was mentioned in the VGA specs. Michael Abrash claimed MODE X 'was omitted entirely from IBM's documentation of the VGA'. He claimed that many people discovered it independently.

I also don't understand why this article is flagged for no citations, Michael Abrash's 'Black Book of Graphics Programming' and the Dr. Dobb's article are citations.

Stephen

I just rearranged what was there, I don't think I added or took anything away. I'll see if I can find any direct quotes on the matter (anyone know how to find the VGA specs?). It's probably okay to delete the "sources" tags as long as we list the black book under "references", which we don't currently do. - Rainwarrior 17:18, 24 November 2006 (UTC)
Okay, putting the VGA into 320x240 isn't documented, no, but the behaviour and purpose of the VGA registers is documented. So... the unchained mode were documented, more or less, though none of its advantages are. I replaced the line with an alternative. - Rainwarrior 18:06, 24 November 2006 (UTC)