Problem using Linear Frame Buffer [SOLVED]

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.
Post Reply
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Problem using Linear Frame Buffer [SOLVED]

Post by Chandra »

I've been trying to implement the Linear Frame Buffer under Vesa mode 1024x768x24bpp. I've initialized the vesa video mode in my bootloader like this:

Code: Select all

;;Bootloader stage 2
                    VESAINFO  	db 'VBE2'		;; Space for info ret by vid BIOS
				times 508  db 0
	       MODEINFO	times 256 db 0
	       frame_buffer    dd 0

init_vesa:
		
		mov DI, VESAINFO
        	mov AX, 4F00h
        	int 10h
       
        	cmp AX, 4Fh
		jne vesa_init_failed	; Function Call not supported/ No Vesa present
		mov DX,0h		; We'll use the DX register to test the modes
		call find_mode

	find_mode:
		Inc DX
		cmp DX, 0xffff		; Have we finished testing all the modes
		JZ vesa_init_failed	; If this is the case, we couldn't find the mode we want
		mov CX,DX		; Else,let's go on testing the mode until we find the one we need

		mov AX, 4F01h		; CX contains the mode no. for the Mode Info Call
		mov DI, MODEINFO
		int 10h
		cmp AX,4Fh
		jne find_mode		; Mode Info Call not supported
		
		
		mov AX, word [MODEINFO]	;; Get the first word of the buffer
			
		bt AX, 0		;; Is the mode supported?
		jnc find_mode
		
		bt AX, 4		;; Is this mode a graphics mode?
		jnc find_mode
		
		bt AX, 7		;; Does this mode support a linear frame buffer?
		jnc find_mode
		
		mov Ax, word [MODEINFO+18]
		cmp ax,1024		;; Is the horizontal resolution = 1024?
		jnz find_mode
		
		mov Ax, word [MODEINFO+20]
		cmp ax,768		;; Is the vertical resolution = 768?
		jnz find_mode

		mov al, byte [MODEINFO+25]
		cmp al,24		;; Is the bits per pixel = 24 ?
		jnz find_mode
					;; If we reached this point,we found our mode

		mov eax,Dword [MODEINFO+40] ;; Adress of PhysBasePtr(LFB)
		mov [frame_buffer],eax
				
			
        	MOV AX, 04F02h      	; Set VESA Video Mode
        	MOV BX, DX       	; DX contains the mode we want 1024x768x24bpp
        	INT 10h             	; Video Interrupt
        	CMP AX, 04Fh       	; AX = 04Fh ? 
        	JNz vesa_init_failed    ; If No Then Video Error
		
			

	vesa_init_failed:
		cli
		hlt
The problem is that when I use the address strored in [frame_buffer] to put pixel, it works fine with QEMU but when I use the same compiled image in BOCHs nothing gets displayed.I'm sure that there's no problem with my putpixel function because if I write to the adress 0xa0000, this function works fine(upto 65536 bytes though), but when I write to the adress stored in [frame_buffer], nothing gets displayed under Bochs.
Have I missed something in the configuration of BOCHS(since it works fine with QEMU) or is my code to determine the adress of Linear frame Buffer wrong? Please Help!!

EDIT: Brendan added some code tags..
Last edited by Chandra on Mon Sep 27, 2010 12:37 am, edited 1 time in total.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
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: Problem using Linear Frame Buffer

Post by Combuster »

Read the forum rules, use code tags.

Also, tell VESA that you want a LFB mode and not a banked mode.
"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 ]
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Problem using Linear Frame Buffer

Post by Chandra »

Combuster wrote:Read the forum rules, use code tags.

Also, tell VESA that you want a LFB mode and not a banked mode.
If Banking had been the problem, why did it worked perfectly with QEMU?
Anyway, please tell me how do I tell Vesa to enable LFB.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Problem using Linear Frame Buffer

Post by Brendan »

Hi,
Chandra wrote:
Combuster wrote:Also, tell VESA that you want a LFB mode and not a banked mode.
If Banking had been the problem, why did it worked perfectly with QEMU?
Qemu might enable both bank switching and LFB, regardless of which you ask for.
Chandra wrote:Anyway, please tell me how do I tell Vesa to enable LFB.
When you set a video mode, the video mode number goes in the lower bits of DX and the higher bits of DX are used for different flags (if you want the display memory cleared, if you want to specify a "CRTCinfo" structure, and if you want LFB). You have to set the "use LFB flag" in DX when setting the mode if you want to use LFB.

You should probably also take a look at common mistakes too... ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Problem using Linear Frame Buffer

Post by Chandra »

Thanks very much Brendan. Setting the Bit 14 while calling sub function 4F02 worked.
Great to find a solution. Thanks again.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Post Reply