flat assembler
Message board for the users of flat assembler.

flat assembler > OS Construction > Question about INT 0x10

Author
Thread Post new topic Reply to topic
Fulgurance



Joined: 27 Nov 2017
Posts: 61
Hello, i have question about INT 0x10, about VBE.

It's about 4F 02 function to set super VGA mode.
On this VBE doc: https://pdos.csail.mit.edu/6.828/2011/readings/hardware/vbe3.pdf
it's specified to set D0-D8 on BX register to set desired mode, but what value can i put ? And what is the result of this value ?
Post 27 Nov 2018, 23:27
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4180
Location: 2018
Quote:

FUNCTION 02H - SET VBE MODE 40




Function 02h - Set VBE Mode
Input:
AX = 4F02h
Set VBE Mode
BX = Desired Mode to set
D0-D8 = Mode number
D9-D10 = Reserved (must be 0)
D11
= 0 Use current default refresh rate
= 1 Use user specified CRTC values for refresh rate
D12-13 Reserved for VBE/AF (must be 0)
D14
= 0 Use windowed frame buffer model
= 1 Use line ar/flat frame buffer model
D15
= 0 Clear display memory
= 1 Don't clear display memory
ES:DI = Pointer to CRTCInfoBlock structure
Output:
AX = VBE Return Status

then

Quote:

VBE MODE NUMBERS 18
Post 27 Nov 2018, 23:48
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 61
I don't understand... 18 mode is VBE ? (i would like to use custom resolution)
Post 27 Nov 2018, 23:53
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4180
Location: 2018
page 18 modes,
page 40 function 02
Post 27 Nov 2018, 23:58
View user's profile Send private message Visit poster's website Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 61
Oh okay, i have don't seen that. Thanks Wink
Post 28 Nov 2018, 00:09
View user's profile Send private message Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 41
Not sure why is this question in "OS Construction", but anyway, here's my answer:

Use INT 10/4F00 to query available modes (since VBE2.0 there are no more fixed resolution codes, the returned structure has a 32 bit pointer at 0Eh to the list, the list is terminated by 0FFFFh)
http://www.ctyme.com/intr/rb-0273.htm

And INT 10/4F01 to query information on a mode (like screen resolution, pitch and pixel format). This is important, because pitch may be different than width*bpp, and it's essential to know to calculate position on the screen.
http://www.ctyme.com/intr/rb-0274.htm

The structure returned by that function (table 79) has the BX value for the mode at offset 0 (which may or may not be different to the one in the 4F00 list. A few bits could be different). You may need to alter that a little too (bits 11-15, see table 78 ) before you pass it to INT 10/4F02.

Here's a working, well tested example (tested on qemu, bochs, VirtualBox, many different versions; on real machines: an Acer laptop, and two noname machines with 5 different video cards):
https://gitlab.com/bztsrc/bootboot/blob/master/x86_64-bios/bootboot.asm#L1715

lines 1720-1731: check if VBE2.0 is supported, and query available modes
lines 1732-1773: iterate on each mode, call 4F01 in a loop
lines 1774-1800: check wether the returned structure has the W x H x 32bpp resolution we're looking for
lines 1819-1825: set that resolution with the returned mode code with bits 13,14 set (LFB and HW acceleration)

Cheers,
bzt
Post 28 Nov 2018, 13:45
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 61
Thanks for your help Smile

I have just questions about CRTC Info Block arguments.

Example: I would like to set the resolution with size 1920x1080
I think Horizontal total it's just the horizontal size of my resolution = 1920
Horizontal Sync Start: what is this ?
Horizontal Sync End: ?
Vertical Total: 1080 ?
Flags: ? What is this ?
Pixel clock ???
Refresh rate ?

How i found this information ?
Post 29 Nov 2018, 12:05
View user's profile Send private message Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 41
Are you using a CRT monitor?
If not, then simply "don't care". Non-electron-cannon monitors (TFT, Plasma, OLED, etc. anything manufactured in the last twenty years or so) don't have a CRTC anyway, so it doesn't matter what's in that block.
If the answer is yes, then you should buy a new monitor ASAP (not kidding).

Quote:
Example: I would like to set the resolution with size 1920x1080
Then you should do (you haven't mention the bpp, let's assume 32bpp):
1. get the mode list with 4F00.
2. iterate on every mode, using 4F01 to get the VBE info (output) for mode (input).
3. check if the returned word es:[di+12h]==1920 and word es:[di+14h]==1080 and byte es:[di+19h]==32
if so, you got your mode code that you can use with 4F02 to set up 1920x1080x32 resolution (pitch at word es:[di+10h], frame buffer pointer at dword es:[di+28h]).
4. if you reach the mode 0FFFFh (or 0000h on some video cards), then 1920x1080x32 resolution is not supported.

BIOS should not list a mode which is not displayable. (Unless your BIOS is seriously broken, or your monitor is so ancient that it does not provide EDID information, see INT 10/4F15/01).
In that case (INT 10/4F15/01 returned AH=1) you can always do what WinXP did: display a message "Press OK if you can read this" with 10 secs timeout, and revert to the next (or previous) mode on timeout.

Cheers,
bzt
Post 29 Nov 2018, 17:18
View user's profile Send private message Reply with quote
Fulgurance



Joined: 27 Nov 2017
Posts: 61
In fact, without video card specification, is it not possible to set custom resolution ?

I suppose all BIOS support current screen resolution with int 10 VESA ? Or it's possible BIOS don't support screen resolution ?
Post 29 Nov 2018, 18:04
View user's profile Send private message Reply with quote
bzt



Joined: 09 Nov 2018
Posts: 41
Fulgurance wrote:
In fact, without video card specification, is it not possible to set custom resolution ?
Yes you can, with VBE (or with GOP these days). That is, if by custom you mean non-monitor-native resolution; you can choose any custom resolution from a predifined list (provided by the video card manufacturer). Because of the standard interface, you don't need to know the card's specification for that.

Quote:
I suppose all BIOS support current screen resolution with int 10 VESA ? Or it's possible BIOS don't support screen resolution ?
What you mean? The BIOS VBE specification only specifies the interface, but it does not support anything at all. Each video card contains a ROM, with code, which implements that interface. This means the BIOS describes how to pass the video modes, and how to query their resolution, but it is up to the video card manufacturer to implement that, and it's up to them what they put in those lists and structures. Because it's a standard, that both video card and monitor manufacturers are aware of, there will be a resolution subset that's supported by both the given card and a given monitor. For example, 640x400 is supported by all IBM PC compatible configurations for sure.

Now with UEFI, you have the same scheme. The only difference is that the video card ROM provides the GOP interface. You can use that to query the available video modes and to set one just like with BIOS VBE. Btw, UEFI mandates that 1024x768 must be supported by both the card and the monitor.

As a last note, if you know how to low level program the video card directly (with IO ports, memory regions etc.), then you are not restricted to the VBE/GOP. Then you can write a driver that does the same, or maybe even more. With that custom driver it is possible to set up resolutions not listed by the standard interfaces (but that's not recommended, not guaranteed to work, and if you are uncareful, you can blow up your monitor). There are some manufacturers that publicate such low level specifications for their cards (typically Intel), but big players usually don't (Nvidia for example). The only option you have is to disassembly their ROM, and see what the code actually does when you call a BIOS VBE interrupt. But to do so may be illegal in some countries, be warned.

Cheers,
bzt
Post 30 Nov 2018, 13:39
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.