GUI

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
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: GUI

Post by Dex »

You can set vesa mode in realmode and use LFB ( you will need to check that your vesa supports it, most vesa2 do ), then you can use the LFB as easy as you could use 0A000H in the old dos days.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: GUI

Post by Brendan »

Hi,
tantrikwizard wrote:
alberich wrote:...which is the best way to draw mouse pointer on screen? ...
the best way is always going to be a point of discussion, in the long run it will depend on your implementation.
I take a different view. The best way to draw a mouse pointer on the screen is to use the video card's hardware accelerated pointer/cursor, where (typically) you upload data that describes the mouse pointer into the video card, and then tell the video card where to display it if it moves.

What Alberich probably wants to know is the best way to implement support for a mouse pointer (given limited developer time, etc). IMHO the answer to this is to mimic the hardware in software, in the legacy video driver. That way the GUI can give the video driver the data that describes the mouse pointer, and the video driver can blit the mouse pointer to the screen manually (and eventually, someone might be able to write video drivers that do use the video card's hardware accelerated pointer/cursor without anyone needing to change any other software).

The only problem here is trying to figure out the format for the mouse pointer data. You'd want a format that can be used easily by video drivers that support hardware accelerated mouse pointers. However, unfortunately different video cards do it differently.

AFAIK a lot of video cards use a pair of 32 * 32 bitmaps (an "AND mask" and an "OR mask") where a pixel underneath the mouse pointer is effected by the corresponding bit in both of these bitmaps. For example:

Code: Select all

AND mask  OR mask  Result
 0         0        Black pixel
 0         1        White pixel
 1         0        Transparent pixel
 1         1        Inverted pixel
Also note that this format for mouse cursor data is used by the VBE AF specification, and is apparently similar to the format used by the "Windows 3.1 cursor file format".

However, for most modern video cards you could probably just use hardware accelerated 2D bit-blits (with alpha channel for transparency), so that you can have any colours you like (and any size mouse pointer you like).

Because of this I'd be tempted to use a 32-bpp format (alpha, red, green, blue), and then let the video driver convert this data into whatever format it needs (but I'd also make sure the mouse pointer data is either 32 * 32 or 64 * 64 to make it easier to convert to the "AND mask and OR mask" format, if necessary).


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
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: GUI

Post by quanganht »

I' using GRUB, so how to return to Unreal mode? Can GRUB setup Vesa for me?
"Programmers are tools for converting caffeine into code."
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: GUI

Post by eddyb »

quanganht wrote:I' using GRUB, so how to return to Unreal mode? Can GRUB setup Vesa for me?
search the wiki.. i know somewhere is a patch which does this.
quok
Member
Member
Posts: 490
Joined: Wed Oct 18, 2006 10:43 pm
Location: Kansas City, KS, USA

Re: GUI

Post by quok »

quanganht wrote:I' using GRUB, so how to return to Unreal mode? Can GRUB setup Vesa for me?
GRUB can do the VESA mode switches for you, but only if you patch it. I think this is mentioned on the wiki somewhere, and I know for certain there's links to patches in a couple of threads on here. Or you can Google something like "GRUB vesa vbe patch". Ah, found the thread I was talking about: http://forum.osdev.org/viewtopic.php?f=1&p=139446

Alternatively, you can use a v86 task to do this for you, but remember that v86 mode isn't available in long mode. For that reason, I plan to emulate all the 16-bit code with the help of x86emu.
User avatar
djsilence
Member
Member
Posts: 70
Joined: Wed Oct 01, 2008 11:18 am
Location: Ukraine, Kiev
Contact:

Re: GUI

Post by djsilence »

HI, anyone!

I tried to use VESA LFB modes, but they just work in assembly code. Trying to do the same in C or C++ environment makes me crash(e.g. it nothing happens)! Maybe it'd be normal to write in ASM(like MenuetOS) but i still want to use C++. I use BrokenThorn tutorial (written in MSVC++). But earlier I tried the same with other tutorials written in GCC. BUt anyway it doesn't work anywhere. I have made design of GUI, but I cann't improve it to my OS because of unworked LFB modes in C++. I thought that it can be caused by Paging, but even without paging nothing works (in ASM - works great!). Can anyone help?

Thanks!
Don't think a ****, but in ukrainian schools English is TOO BAD!
tantrikwizard
Member
Member
Posts: 153
Joined: Sun Jan 07, 2007 9:40 am
Contact:

Re: GUI

Post by tantrikwizard »

djsilence wrote:...I tried to use VESA LFB modes, but they just work in assembly code. Trying to do the same in C or C++ environment makes me crash...
Setting VBE LFB is a hardware setting, its language independent. The problem is not the C/C++ language, theres a bug in your code.
eddyb
Member
Member
Posts: 248
Joined: Fri Aug 01, 2008 7:52 am

Re: GUI

Post by eddyb »

tantrikwizard wrote:
djsilence wrote:...I tried to use VESA LFB modes, but they just work in assembly code. Trying to do the same in C or C++ environment makes me crash...
Setting VBE LFB is a hardware setting, its language independent. The problem is not the C/C++ language, theres a bug in your code.
Well, bugs can happen because of the language... For example, if you have C + inline assembly, it can be buggier than simple assembly.
User avatar
djsilence
Member
Member
Posts: 70
Joined: Wed Oct 01, 2008 11:18 am
Location: Ukraine, Kiev
Contact:

Re: GUI

Post by djsilence »

I've got tha same problem. I tried to do that fully in clear c++, in inline assemby (in GCC), tried writting _asm function in MSVC++ (using BrokenThorn tutorial that is written in MSVC++), and even tried to do asm function that is declared as global and is declared in C++ as external function and then just call it. Nothing helps. I use Dex demo wich is written in asm (like DexOS).
I tried do the next:

while OS still in ASM environment it fills screen in some color, then it calls _main() that is doing nothing (just return to the asm) and the I tried to fill screen in another color to determinate that it wirks. But the first time I fill screen it works and after main call it doesn't work. ? :?
Don't think a ****, but in ukrainian schools English is TOO BAD!
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: GUI

Post by Dex »

First do you return from function calls _main() OK, to test this try calling a beep function on return, here is a simple example

Code: Select all


 ;----------------------------------------------------;
 ; Beep                                               ;
 ;----------------------------------------------------; 
Beep:
	mov   [Hz],0x200			     ;Call this function, for beep
	call  Sound
	call  DeLay
	call  NoSound
	ret


 ;----------------------------------------------------;
 ; Sound                                              ;
 ;----------------------------------------------------;
Sound:
	mov   bx,[Hz]
	mov   ax,0x34dd
	mov   dx,0x0012
	cmp   dx,bx
	jnc   Done1
	div   bx
	mov   bx,ax
	in    al,0x61
	test  al,3
	jnz   A99
	or    al,3
	out   0x61,al
	mov   al,0xb6
	out   0x43,al
A99:
	mov   al,bl
	out   0x42,al
	mov   al,bh
	out   0x42,al
Done1:
	ret

 ;----------------------------------------------------;
 ; NoSound                                            ;
 ;----------------------------------------------------;
NoSound:
	in    al,0x61
	and   al,11111100b
	out   0x61,al
	ret
 ;----------------------------------------------------;
 ; DeLay                                              ;
 ;----------------------------------------------------;
DeLay:			 
	mov   cx,[ms1]
	jcxz  A2		
A1:
	call  DeLaYoneMS
	loop  A1		
A2:
	ret   
 ;----------------------------------------------------;
 ; DeLaYoneMS                                         ;
 ;----------------------------------------------------;
DeLaYoneMS:	       
	push  ecx				     
	mov   cx,[OneMS]		
B1:
	loop  B1	       
	pop   ecx		 
	ret
				   
OneMS	 dw	 40000
Hz	 dw	 0
ms1	 dw	 1000
If you get no beep than your problem is your not returning, if it beeps, then your problem could be too do with regs not save etc.
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: GUI

Post by Creature »

quanganht wrote:Is there any way to use VESA without returning to Unreal mode?
Or if you want something much easier (in my opinion) you can use the Bochs Graphics Adapter (can be found on the wiki). It might not be what you're looking for but it still allows you to change video resolutions and draw pixels like you would with most other ways of accessing graphics.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: GUI

Post by JohnnyTheDon »

Another alternative (that will work on real hardware) is the protected mode entry point for VESA. Look up the specifications, it allows you to change video modes while in pmode. Idk how well its supported though.
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: GUI

Post by Combuster »

Virtual8086 mode works too.
And custiom x86 emulators...
"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 ]
Post Reply