how to use vga in protected mode?
how to use vga in protected mode?
Is possible to write a driver for vga screen mode, without swich my os to real mode or write a virtual mode?
Re: how to use vga in protected mode?
No - unless you have access to the specification of your card (possible for ATI and Intel cards at least) you'll need the BIOS to do it for you, so you'll need to drop into real mode, use VM86 mode or write a 16-bit x86 interpreter.Karlosoft wrote:Is possible to write a driver for vga screen mode, without swich my os to real mode or write a virtual mode?
- Combuster
- 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:
@JamesM: I assume that you were half asleep when you posted that...
VGA from protectected mode is easy, its SVGA (or Vesa) that requires you to have knowledge of the card (the card provides bits of this information in the BIOS, but requires the 16-bit environment to work)
The VGA Hardware page holds a lot of hardware tidbits you can start with. If you want to just grab someone else's code and pray it works, try VGA Resources
VGA from protectected mode is easy, its SVGA (or Vesa) that requires you to have knowledge of the card (the card provides bits of this information in the BIOS, but requires the 16-bit environment to work)
The VGA Hardware page holds a lot of hardware tidbits you can start with. If you want to just grab someone else's code and pray it works, try VGA Resources
You can do a switch to standard graphics modes like 320x200x256 or 640x480x16 using standard vga i/o-ports. With google you can find examples. They work on every vga card.
Using the BIOS for this is easier: put the mode number in AX (8-bit number, so AH=0) and call int 10h. Number 13h is 320x200x256 and 12h is 640x480x16. Just two lines of assembly code. It can't be easier. There are some tricks to increase the resolution from such videomode using standard svga i/o, like 320x400x256, but they are not very suitable for user interfaces. A reallife example is the Windows 9x bootscreen.
The nicer modes, 640x480 or higher and 256 or more colors, can be used with a svga card, every modern videocard. But there is not a standard routine to set them. You can use the BIOS, but even that is not standard. Mode numbers differ from vendor.
Maybe the easiest way is using VESA. VESA are some standard video bios-routines to provide a collection of standard functions. Depending on the version of VESA, you can use some of the functions from protectedmode. See: http://en.wikipedia.org/wiki/VESA_BIOS_Extensions
Specs are available: http://www.vesa.org/public/VBE/vbe3.pdf
Read the carefully to provide compatibility across differend video hardware.
Using the BIOS for this is easier: put the mode number in AX (8-bit number, so AH=0) and call int 10h. Number 13h is 320x200x256 and 12h is 640x480x16. Just two lines of assembly code. It can't be easier. There are some tricks to increase the resolution from such videomode using standard svga i/o, like 320x400x256, but they are not very suitable for user interfaces. A reallife example is the Windows 9x bootscreen.
The nicer modes, 640x480 or higher and 256 or more colors, can be used with a svga card, every modern videocard. But there is not a standard routine to set them. You can use the BIOS, but even that is not standard. Mode numbers differ from vendor.
Maybe the easiest way is using VESA. VESA are some standard video bios-routines to provide a collection of standard functions. Depending on the version of VESA, you can use some of the functions from protectedmode. See: http://en.wikipedia.org/wiki/VESA_BIOS_Extensions
Specs are available: http://www.vesa.org/public/VBE/vbe3.pdf
Read the carefully to provide compatibility across differend video hardware.
Yeah, you're quite right, I hadn't had my coffee when I checked osdev.org Got it now though!Combuster wrote:@JamesM: I assume that you were half asleep when you posted that...
VGA from protectected mode is easy, its SVGA (or Vesa) that requires you to have knowledge of the card (the card provides bits of this information in the BIOS, but requires the 16-bit environment to work)
The VGA Hardware page holds a lot of hardware tidbits you can start with. If you want to just grab someone else's code and pray it works, try VGA Resources
So you can change into 90x30 text mode (or by changing the font, 90x60), 320x200 or 640x480 graphics mode just by writing to the VGA registers.
There's also a protected mode interface defined in VESA 2.0 and VESA 3.0 (they're incompatible, iirc), but many devices still don't support this fully.
As most people's test computers are pretty old, it's not really viable to rely on a protected mode interface being available, so to access higher resolutions you'll have to use the BIOS interface (real mode).
Combuster: better?
James
True, but I support both.
As most people's test computers are pretty old, it's not really viable to rely on a protected mode interface being available, so to access higher resolutions you'll have to use the BIOS interface (real mode).
When someone is compiling from source using the binaries only on new machines, some support for vbe < 3.0 can be left out.
Here you will find some good info about vga without bios
http://bos.asmhackers.net/docs/vga_without_bios/
http://bos.asmhackers.net/docs/vga_without_bios/
Hi,robos wrote:You can do VESA in pmode, you're just restricted to setting the graphics mode and getting the address of the linear frame buffer before jumping to pmode and you'll have to select from whatever list of resolutions the VESA bios supports (no widescreen resolutions for example).
In this case, you're not really "doing" VESA in protected mode at all - you're setting everything up in real mode and using it in protected mode - i.e. you have to drop back to real mode (or use vm86 or use a 16-bit 8086 interpreter) to change setup.
Cheers,
James
In my OS, I drop out of PMode, use BIOS and go right back, after having it do the function to get a linear framebuffer and the video mode info. Its really pretty easy, the whole code fits into 128 bytes of assembled code. I've attached the source file here. A few pointers though:JamesM wrote:Hi,robos wrote:You can do VESA in pmode, you're just restricted to setting the graphics mode and getting the address of the linear frame buffer before jumping to pmode and you'll have to select from whatever list of resolutions the VESA bios supports (no widescreen resolutions for example).
In this case, you're not really "doing" VESA in protected mode at all - you're setting everything up in real mode and using it in protected mode - i.e. you have to drop back to real mode (or use vm86 or use a 16-bit 8086 interpreter) to change setup.
Cheers,
James
On boot up save the real mode IDT at a known place (mine was at 0x9000) using the sidt instruction, and dont overwrite address 0-0x500 in memory. It also assumes that you are using 8 and 16 as segment registers for code and data in PMode. It stores the result of function 4f01 at 0x5000, and automatically sets bit 13 (use framebuffer). Obviously this could be extended to implement bank switching, probe for a list of available modes, etc... but for just setting the resolution on a video card made after about 1998 it seems to work.
In other words, youll have to tweak it to fit your OS design, but it does what you want.
- Attachments
-
- videodrv.asm
- Video Driver
- (1.74 KiB) Downloaded 931 times
You are correct, I should've written my post a little bit different. The question was in regards to vga screen mode, not VESA in particular (you'll just want to use it to setup a graphics mode of interest). My response was meant to say that you can access the frame buffer from pmode and draw graphics etc. without needing to be in real mode after you've set this graphics mode up in real mode.JamesM wrote:In this case, you're not really "doing" VESA in protected mode at all - you're setting everything up in real mode and using it in protected mode - i.e. you have to drop back to real mode (or use vm86 or use a 16-bit 8086 interpreter) to change setup.robos wrote:You can do VESA in pmode, you're just restricted to setting the graphics mode and getting the address of the linear frame buffer before jumping to pmode and you'll have to select from whatever list of resolutions the VESA bios supports (no widescreen resolutions for example).
The original poster didn't specify what features his/her driver needs to have. If there's no requirement to switch graphics mode after it's been setup once there's no reel need to drop into real mode / VM86 or write a custom driver.JamesM wrote:No - unless you have access to the specification of your card (possible for ATI and Intel cards at least) you'll need the BIOS to do it for you, so you'll need to drop into real mode, use VM86 mode or write a 16-bit x86 interpreter.Karlosoft wrote:Is possible to write a driver for vga screen mode, without swich my os to real mode or write a virtual mode?
However, if you want to:
1) change graphics resolutions to a predefined list then you need real mode or VM86 etc.
2) change graphics resolutions to whatever the card / monitor supports you'll need a graphics card specific driver
Does that make my response more clear?
- Rob
- Combuster
- 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:
As a side note, the standard VGA resolutions (640x480x4, 320x200x8) are just that - standard. You can get far higher resolutions out of that card (at the cost of a lower refresh rate which your monitor may or may not support)
All video cards I've seen can do 800x600 in 16 colors with just VGA code. For 256 colors, you can at least do 400x300, but theoretically a resolution like 512x384 should work as well.
All video cards I've seen can do 800x600 in 16 colors with just VGA code. For 256 colors, you can at least do 400x300, but theoretically a resolution like 512x384 should work as well.
Yep! I'll agree with that!robos wrote:You are correct, I should've written my post a little bit different. The question was in regards to vga screen mode, not VESA in particular (you'll just want to use it to setup a graphics mode of interest). My response was meant to say that you can access the frame buffer from pmode and draw graphics etc. without needing to be in real mode after you've set this graphics mode up in real mode.JamesM wrote:In this case, you're not really "doing" VESA in protected mode at all - you're setting everything up in real mode and using it in protected mode - i.e. you have to drop back to real mode (or use vm86 or use a 16-bit 8086 interpreter) to change setup.robos wrote:You can do VESA in pmode, you're just restricted to setting the graphics mode and getting the address of the linear frame buffer before jumping to pmode and you'll have to select from whatever list of resolutions the VESA bios supports (no widescreen resolutions for example).
The original poster didn't specify what features his/her driver needs to have. If there's no requirement to switch graphics mode after it's been setup once there's no reel need to drop into real mode / VM86 or write a custom driver.JamesM wrote:No - unless you have access to the specification of your card (possible for ATI and Intel cards at least) you'll need the BIOS to do it for you, so you'll need to drop into real mode, use VM86 mode or write a 16-bit x86 interpreter.Karlosoft wrote:Is possible to write a driver for vga screen mode, without swich my os to real mode or write a virtual mode?
However, if you want to:
1) change graphics resolutions to a predefined list then you need real mode or VM86 etc.
2) change graphics resolutions to whatever the card / monitor supports you'll need a graphics card specific driver
Does that make my response more clear?