flat assembler
Message board for the users of flat assembler.

Index > OS Construction > VESA don't work.

Author
Thread Post new topic Reply to topic
superos



Joined: 24 Apr 2013
Posts: 10
superos 29 Jan 2014, 20:45
hey,
I have a problem with the following code:
Code:
;************************************
; By Dex
; Assemble with fasm 
; c:\fasm Vesa.asm Vesa.bin
;
;************************************
org 0x7C00 

use16
start:
jmp dal
dq  0
dq  0
dq  0
dq  0
dq  0
dq  0
dq  0
dq  0
dq  0
dq  0
dal:
;****************************
; Realmode startup code.
;****************************


cli
        xor   ax,ax
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   sp,0x7C00
        sti

;****************************
; Vesa start code.
;****************************

        mov  bx,4112h
        mov  ax,4f01h
        mov  di,Mode_Info       
        mov  cx,bx
        int  10h 
        
        mov  ax,4f02h
        int  10h

;*****************************
; Setting up, to enter pmode.
;*****************************

        cli 
        lgdt  [gdtr]
        
        mov   eax, cr0
        or    al,0x1 
        mov   cr0,eax
 
        jmp   0x10: protected

;*****************************
; Pmode. Wink
;*****************************

use32
protected:
        mov   ax,0x8 
        mov   ds,ax
        mov   es,ax
        mov   ss,ax
        mov   esp,0x7C00


;*****************************
; Do we have 32 BitsPerPixel.
;*****************************

        cmp   byte[ModeInfo_BitsPerPixel],32
        jne   Letsloop 

;*****************************
; fade background screen.
;*****************************

fade_screen:
        mov   edx,[ModeInfo_PhysBasePtr]
        mov   edi,edx
        xor   eax,eax
        mov   al,0xc5          
        xor   ebx,ebx
        mov   bl,195 
DoLoop:    
        mov   cx,640*2 
        dec   eax    

        rep   stosd
       
        dec   ebx
        jnz   DoLoop
Letsloop:
        hlt
        jmp   Letsloop

;*************************************
; GDT. 
;*************************************

gdt:        dw    0x0000, 0x0000, 0x0000, 0x0000
sys_data:   dw    0xFFFF, 0x0000, 0x9200, 0x00CF
sys_code:   dw    0xFFFF, 0x0000, 0x9800, 0x00CF
gdt_end:

gdtr:       dw gdt_end - gdt - 1                                          
            dd gdt 


;*************************************
; Make program 510 byte's + 0xaa55
;*************************************
            
times 510- ($-start)  db 0  
dw 0xaa55

;*************************************
; Put uninitialized data here.
;*************************************

;=========================================================;
; Vesa Information Block                         11/12/03 ;
;---------------------------------------------------------;
; DOS EXTREME OS V0.01                                    ;
; by Craig Bamford(Dex).                                  ;
;                                                         ;
;=========================================================;

;============================== VESA MODE INFORMATION ===========================================
Mode_Info:              
ModeInfo_ModeAttributes         rw      1
ModeInfo_WinAAttributes         rb      1
ModeInfo_WinBAttributes         rb      1
ModeInfo_WinGranularity         rw      1
ModeInfo_WinSize                rw      1
ModeInfo_WinASegment            rw      1
ModeInfo_WinBSegment            rw      1
ModeInfo_WinFuncPtr             rd      1
ModeInfo_BytesPerScanLine       rw      1
ModeInfo_XResolution            rw      1
ModeInfo_YResolution            rw      1
ModeInfo_XCharSize              rb      1
ModeInfo_YCharSize              rb      1
ModeInfo_NumberOfPlanes         rb      1
ModeInfo_BitsPerPixel           rb      1
ModeInfo_NumberOfBanks          rb      1
ModeInfo_MemoryModel            rb      1
ModeInfo_BankSize               rb      1
ModeInfo_NumberOfImagePages     rb      1
ModeInfo_Reserved_page          rb      1
ModeInfo_RedMaskSize            rb      1
ModeInfo_RedMaskPos             rb      1
ModeInfo_GreenMaskSize          rb      1
ModeInfo_GreenMaskPos           rb      1
ModeInfo_BlueMaskSize           rb      1
ModeInfo_BlueMaskPos            rb      1
ModeInfo_ReservedMaskSize       rb      1
ModeInfo_ReservedMaskPos        rb      1
ModeInfo_DirectColorModeInfo    rb      1
; VBE 2.0 extensions
ModeInfo_PhysBasePtr            rd      1
ModeInfo_OffScreenMemOffset     rd      1
ModeInfo_OffScreenMemSize       rw      1

;======================================= START OF PROGRAM  ======================================
    

it does not work in VirtualPC and Bochs. PM starts, set VESA mode, but there is no point on the screen.

thanks for the reply
Post 29 Jan 2014, 20:45
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 29 Jan 2014, 23:43
Dex is still active in OS development. you should talk to him. it sounds like a bug report he should be informed of rather than a public request for help.
Post 29 Jan 2014, 23:43
View user's profile Send private message Visit poster's website Reply with quote
sid123



Joined: 30 Jul 2013
Posts: 339
Location: Asia, Singapore
sid123 30 Jan 2014, 06:46
Um, the BIOS loads !ONLY! the first 512 bytes into memory, means that the VESA information block which is after padding is !NOT! loaded in memory and the place you're storing the VESA Information Block is rubbish. You may need to load sectors using int 0x13.
Post 30 Jan 2014, 06:46
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
edfed 30 Jan 2014, 09:59
vesa block will not appear at all in the binary cause it is memory reservation at the end of the source code.

vesa mode info block will be generated at run time by int 10h at the position stated in the source code.

it misses another structure about vesa, the VESA_Info
Code:
;-------------------------------- FASM VESA INFORMATION BLOCK -----------------------------------
VESA_Info:
.Signature              rb      4      ; VBE Signature
.Version                rw      1      ; VBE Version
.OEMStringPtr           rd      1      ; VbeFarPtr to OEM String
.capabilities           rb      4      ; Capabilities of graphics controller
.VideoModePtr           rd      1      ; VbeFarPtr to VideoModeList
.TotalMemory            rw      1      ; Number of 64kb memory blocks
.OEMSoftwareRev         rw      1      ; VBE implementation Software revision
.OEMVendorNamePtr       rd      1      ; VbeFarPtr to Vendor Name String
.OEMProductNamePtr      rd      1      ; VbeFarPtr to Product Name String
.OEMProductRevPtr       rd      1      ; VbeFarPtr to Product Revision String
.Reserved               rb      222    ; Reserved for VBE implementation scratch area
.OEMData                rb      256    ; Data Area for OEM Strings
;============================== VESA MODE INFORMATION ===========================================
Mode_Info:
.ModeAttributes         rw      1      ; mode attributes
.WinAAttributes         rb      1      ; window A attributes
.WinBAttributes         rb      1      ; window B attributes
.WinGranularity         rw      1      ; window granularity
.WinSize                rw      1      ; window size
.WinASegment            rw      1      ; window A start segment
.WinBSegment            rw      1      ; window B start segment
.WinFuncPtr             rd      1      ; real mode pointer to window function
.BytesPerScanLine       rw      1      ; bytes per scan line
.XResolution            rw      1      ; horizontal resolution in pixels or characters
.YResolution            rw      1      ; vertical resolution in pixels or characters
.XCharSize              rb      1      ; character cell width in pixels
.YCharSize              rb      1      ; character cell height in pixels
.NumberOfPlanes         rb      1      ; number of memory planes
.BitsPerPixel           rb      1      ; bits per pixel
.NumberOfBanks          rb      1      ; number of banks
.MemoryModel            rb      1      ; memory model type
.BankSize               rb      1      ; bank size in KB
.NumberOfImagePages     rb      1      ; number of images
.Reserved_page          rb      1      ; reserved for page function
.RedMaskSize            rb      1      ; size of direct color red mask in bits
.RedMaskPos             rb      1      ; bit position of lsb of red mask
.GreenMaskSize          rb      1      ; size of direct color green mask in bits
.GreenMaskPos           rb      1      ; bit position of lsb of green mask
.BlueMaskSize           rb      1      ; size of direct color blue mask in bits
.BlueMaskPos            rb      1      ; bit position of lsb of blue mask
.ReservedMaskSize       rb      1      ; size of direct color reserved mask in bits
.ReservedMaskPos        rb      1      ; bit position of lsb of reserved mask
.DirectColorModeInfo    rb      1      ; direct color mode attributes
; VBE 2.0 extensions
.PhysBasePtr            rd      1      ; *physical address for flat memory frame buffer*
.OffScreenMemOffset     rd      1      ; Reserved - always set to 0
.OffScreenMemSize       rw      1      ; Reserved - always set to 0
; VBE 3.0 extensions
.LinBytesPerScanLine    rw      1      ; bytes per scan line for linear modes
.BnkNumberOfPages       rb      1      ; number of images for banked modes
.LinNumberOfPages       rb      1      ; number of images for linear modes
.LinRedMaskSize         rb      1      ; size of direct color red mask (linear modes)
.LinRedFieldPos         rb      1      ; bit position of lsb of red mask (linear modes)
.LinGreenMaskSize       rb      1      ; size of direct color green mask (linear modes)
.LinGreenFieldPos       rb      1      ; bit position of lsb of green mask (linear modes)
.LinBlueMaskSize        rb      1      ; size of direct color blue mask (linear modes)
.LinBlueFieldPos        rb      1      ; bit position of lsb of blue mask (linear modes)
.LinRsvdMaskSize        rb      1      ; size of direct color reserved mask (linear modes)
.LinRsvdFieldPos        rb      1      ; bit position of lsb of reserved mask (linear modes)
.MaxPixelClock          rd      1      ; maximum pixel clock (in Hz) for graphics mode
;Reserved
.Reserved               rb      190    ; remainder of ModeInfoBlock
;======================================= START OF PROGRAM  ======================================



    


the init should go like this
Code:
Vesa:
        ;------------------------------------------------------------
        ; Purpose: Checks to see if VESA is available and if the desired mode is
        ; available.
        ; Inputs:  None
        ; Outputs: VESAInfo and VESA_Info structures filled (if successful)
        ;------------------------------------------------------------
        mov   dword [VESAInfo_Signature],'VBE2'
        mov   ax,4f00h                         ; Is Vesa installed ?                       
        mov   di,VESA_Info                     ; This is the address of how info block.
        int   10h
 
        cmp   ax,004Fh                         ; Is vesa installed ?,
        jne   near NoVesa2                     ; If not print a mesage & quit.

        mov   ax,4f01h                         ; Get Vesa Mode information. 
        mov   di,Mode_Info                     ; This is the address of how info block.
        mov   cx,0x4000+vesamode                        ; 4112h = 32/24bit ; 0x4101 = 256bit ;4111h = 65535bit (640*480)
        and   cx,0xfff
        int   10h 

        cmp   dword [VESAInfo_Signature], 'VESA'
        jne   near NoVesa2
        
        cmp   byte [VESAInfo_Version+1], 2
        jb    NoVesa2                          ; VESA version below 2.0  
        ret

;'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''';
; Error No Vesa2                                                                               ;
;..............................................................................................;
NoVesa2:
        mov   si,NoVesa2Msg
        call  Print
NoVesa2End:
        hlt
        jmp   NoVesa2End   

NoVesa2Msg:   db " You need vesa2 for this demo! ",0    

and only in REAL MODE as you made Smile

http://board.flatassembler.net/topic.php?p=82651#82651
Post 30 Jan 2014, 09:59
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 30 Jan 2014, 10:19
superos,

You're set VESA mode 0x112 (640×480, 24bpp) and surprisingly expected [ModeInfo_BitsPerPixel]==32?!
Post 30 Jan 2014, 10:19
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 30 Jan 2014, 15:54
sid123 wrote:
Um, the BIOS loads !ONLY! the first 512 bytes into memory, means that the VESA information block which is after padding is !NOT! loaded in memory and the place you're storing the VESA Information Block is rubbish. You may need to load sectors using int 0x13.

that section is equivalent to "virtual" memory. the meory is written by the VGA BIOS function.

_________________
byte me.
Post 30 Jan 2014, 15:54
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 618
cod3b453 30 Jan 2014, 21:44
The last time I tried VESA on VirtualPC it didn't work (the mode switch occured but I think LFB didn't work) but I believe both only support 24bit colour.
Post 30 Jan 2014, 21:44
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac 06 Mar 2014, 12:10
baldr wrote:
superos,

You're set VESA mode 0x112 (640×480, 24bpp) and surprisingly expected [ModeInfo_BitsPerPixel]==32?!

Some VBE-Bios provide only 32 bpp and some VBE-Bios provide only 24 bpp and some other provide both bpp with different numbers like my Powercolor ATI 9800 PRO: 24 bpp with number 0x112 and 32 pbb with number 0x121.

My Sapphire 7950 does not support the VBE-modenumber 0x112, but it support the resolution of 640x480x32 together with the modenumber 0x121.

Dirk
Post 06 Mar 2014, 12:10
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 06 Mar 2014, 12:59
freecrac,

You shouldn't assume when there're methods to get it right. Query VBE about that mode (IIRC you may get unusual pitch too).
Post 06 Mar 2014, 12:59
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac 08 Mar 2014, 09:22
baldr wrote:
freecrac,

You shouldn't assume when there're methods to get it right. Query VBE about that mode (IIRC you may get unusual pitch too).

I do not really understand what you said, but i have no problems for to use the VBE, most of the VBE3-bios-functions i properly used on real hardware without an emulation. Only a stereoscopic mode i never used, because i have no shutterglasses.

With a CRTC-monitor i like to get the EDID and using a refreshrate controlled mode together with the hardware triple buffering for a screenwide movement of large objects across the screen without a flickering and a tearing. But for a simplest access to the LFB and for to continue using the bios i like to use the big real mode.

..

I think it is a good practice for to compare the "ModeInfo_PhysBasePtr" if it is not zero.

But i never compare if the "VESAInfo_Signature" is 'VESA' and i never write 'VBE2' to the "VESAInfo_Signature". Inside of the "vbe3.pdf" i can not find the part that we have to write 'VBE2' to the "VESAInfo_Signature" inside of our reserved buffer before we can use function 0x4F00. So i do not believe that we have to write to it. I think it is enough if we check the returncode of function 0x4F00 if it is 0x4F and to compare the VBE major number if it is 2 or 3 for to make it clear that we have a VBE 2 or VBE 3 bios. But it make more sense in the beginning before we get a mode specific information and not after.

For the address calculation of a screen position (and also for to calculate the start address of the second and third buffer for double and triple buffering) we have to use the scanline (LinBytesPerScanLine for LFB) and not the horizontal resolution, because the scanline is maybe longer with a part outside of the visible view. Example the scanline for a resolution of 640x480x8 is maybe 1024 bytes with a part from 640 to 1024 pixels of each line outside of the visible view.

...

For a startup-code we can check the memory map and using a free memory for the VBE-information buffer and for the mode information buffer.
http://wiki.osdev.org/Detecting_Memory_%28x86%29

Dirk
Post 08 Mar 2014, 09:22
View user's profile Send private message Send e-mail 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.