Implementing a Function to Switch Standard VGA Video Modes

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Implementing a Function to Switch Standard VGA Video Mod

Post by iansjack »

Why not pause just a second to see if you promote any useful discussion with your diatribe?
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Implementing a Function to Switch Standard VGA Video Mod

Post by ~ »

iansjack wrote:
I intend to do it with the rest of elements that involve OS development. Absolutely everything about hardware and software. They are so many, but it's necessary to cover them once and for all from all of the very most basics.
That's a very worrying statement. This guy intends to swamp the forums with noise rather than putting onformation in the proper place - the Wiki. That will ruin the forum as a place for discussion.
I really want to see difficult and hard to find things become trivial, define the basics and then do the same with the most advanced topics. I really prefer to keep talking in implementation terms of full code that drive a specific software or hardware device. This is what I'd like to see in other posts to discuss in this way and to ask in function of code.

The Wiki can get back-links to these threads.

I think to write tutorials with working code like this in the tutorial and link them instead of altering the main articles too much.

It's just a single topic, and the same for the rest of tutorials that I'll write.

We can discuss what to improve from the code.

So, you could consider it as an automatic reply that doesn't wait for people to pop up looking for partial solutions and instead dump the correct answers of the whole lot that they will anyway need to learn but that they don't know, as if it was a minibook or tutorial.

You could see it as an effort in the background that optimizes and solves poorly or barely available stuff while the rest of the users solve their problems in other threads.

Here they will find out what they really need to learn.

You'll see how it will improve the forum quality as happened in MegaTokyo.

I'm mostly writing about VGA instead of something else to help the person that wrongly wants to exit Protected Mode just to switch standard VGA modes, which I'm developing here.

You can see that topic again: http://f.osdev.org/viewtopic.php?f=1&t=30387


And by the way, the code to actually enter a video mode is almost complete here, without taking into account the function to write the palette and the function to write the text font.
Last edited by ~ on Wed May 25, 2016 12:29 am, edited 1 time in total.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Implementing a Function to Switch Standard VGA Video Mod

Post by ~ »

Image

Enabling the 16-Color VGA Palette

This is part of the functions of the Attribute Controller Register.

We need to enable bit 5 of the Index Register for the Attribute Controller Index Register, keeping the Flip/Flop reset at the start and the end to perform proper reads and writes to this controller in the future.

Every time we drive the index register for the Attribute Controller, we need to disable bit 5 or it would be considered a different index. By disabling it to get the correct index count, it also has the hardware effect to disable the 16-color palette, and that causes that 4-color and 16-color modes get a black screen.

So we need to set bit 5 of this index register again to 1 after we finish the actual reprogramming of the Attribute Controller for things to go back to normal.

Code: Select all

VGA_Attribute_Controller__EnablePalette:
push eax
push edx

  ;Reset flip/flop
  ;;
   mov dx,0x3DA
   in al,dx


  ;Set bit 5 to enable palette
  ;(this bit is contained in the
  ;index register):
  ;;
   mov dx,0x03C0
   mov al,00100000b
   out dx,al


  ;Reset flip/flop again to realign
  ;access to the Attribute Controller port:
  ;;
   mov dx,0x3DA
   in al,dx


pop edx
pop eax
ret


Image
Last edited by ~ on Wed May 25, 2016 12:26 am, edited 1 time in total.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Writing the VGA Registers of its CRTC Controller

Post by ~ »

Image

Unprotecting the first 8 Registers of the CRTC Registers (Make Them Writable)

Registers 0-7 of the CRTC register are write-protected. We need to make them writable to reprogram the CRTC Controller.

We can leave them unprotected, which doesn't seem to have any ill effect at all.

Code: Select all

;//Input parameters:
;//---------
;//$DX: Input Port (0x3D4 color; 0x3B4 monochrome)
;//
;//AH: Bit 7 protects (1) or unprotects (0) CRTC registers 0-7.
;//    The other bits are ignored.  -
;//                                 10000000b -- protect registers
;//                                 00000000b -- unprotect registers
;//                                 -
;//
;//Outputs:
;//---------
;//
;//Effect:
;//---------
;//      This function unprotects the write of CRTC registers 0-7
;//      which normally cannot be written.
;///
VGA_protect_unprotect_CRTC_regs:
 push eax;
 push edx;


 ;//Correctly force to 0 bits 0-6 of this bit set
 ;//for a future OR operation:
 ;///
  and ah,10000000b;



 ;//We want to access CRTC register at offset 0x11:
 ;///
  mov al,0x11;


 ;//Set the index register of the CRTC:
 ;///
  out dx,al


 ;//Point to the data register 0x3D5 (color) or 0x3B5 (mono) to truly
 ;//reconfigure the bits with protection enabled/disabled:
 ;///
  inc dx;


 ;//Save the register and set bit 7, protection bit,
 ;//to the specified value to protect/unprotect registers 0-7:
 ;///
  in al,dx
  and al,01111111b
  or al,ah;


 ;///
 ;//We don't need to set the CRTC index register again.
 ;//We assume that no other code running will modify it
 ;//while we are doing this:
 ;///

  out dx,al


 pop edx;
 pop eax;
ret


Image
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Implementing a Function to Switch Standard VGA Video Mod

Post by iansjack »

You would promote more useful discussion (assuming anyone wants to discuss this) if you put your code on private Wiki pages, then linked to it from a forum post. The way you are doing it any discussion would be lost in a mass of detail. Unfortunately, this has a knock-on effect on more popular discussions which will be lost in your scatter-gun approach.

One of the most important skills in OS development is learning to use tools correctly. You are not doing this with the available documentation tools. For the sake of other posters please learn to use the tools properly.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Implementing a Function to Switch Standard VGA Video Mod

Post by Combuster »

The wiki also exist for Tutorials. Please put the things where people expect to find it.

Even if you wish to misattribute Mega-Tokyo for these kind of threads, remember that it was exactly the place where they decided to go run a wiki because it was better.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Locked