VGA: only part of screen

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.
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

VGA: only part of screen

Post by Awe2K »

So, I've switched to 800x600x32 mode, and tried to fill screen with white color.
Hovewer, it doesn't work for some reason, maybe I am wrong? Please help me.
Thanks, Awe2K.

Screenshot:
http://imgur.com/LNKt64f

Code:
My putpixel:

Code: Select all

static void putpixel(int x, int y, int color) {
	unsigned char * screen = vid_mem;
	unsigned where = x * 3 + y * 2400;
	screen[where] = color & 255;              // BLUE
	screen[where + 1] = (color >> 8) & 255;   // GREEN
	screen[where + 2] = (color >> 16) & 255;  // RED
}
My fill:

Code: Select all

int x,y;
	for (x=0;x<800;x++)
	for (y=0;y<600;y++)
	putpixel(x,y,bgc); // bgc==0xFFFFFF
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: VGA: only part of screen

Post by Octocontrabass »

Did you switch to a mode with a linear frame buffer? If not, you'll have to flip between pages in the frame buffer in order to fill the entire screen.

Does vid_mem point to the correct address?
Awe2K wrote:800x600x32

unsigned where = x * 3 + y * 2400;
How many bytes are 32 bits? How many bits are in 3 bytes?
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

Octocontrabass wrote:Did you switch to a mode with a linear frame buffer? If not, you'll have to flip between pages in the frame buffer in order to fill the entire screen.
I've used GRUB to switch mode (specified in multiboot header).
Does vid_mem point to the correct address?
Yes, it is 0xA0000
Awe2K wrote:800x600x32
unsigned where = x * 3 + y * 2400;
How many bytes are 32 bits? How many bits are in 3 bytes?
Yes, I know 32 bits is for 4 bytes, and 3 bytes are 24 bits. But if I change 3 to 4 and 2400 to 3200, then it just gets worse.

Screenshot (after editing code as you mentioned):
http://imgur.com/LXqhhmI
Last edited by Awe2K on Sun Oct 25, 2015 8:12 am, edited 1 time in total.
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

Also, here are the screenshots of how fonts work both ways (my crash screen):
x*3+y*2400 http://imgur.com/LIY5oEL
x*4+y*3200 http://imgur.com/y6PerOv
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: VGA: only part of screen

Post by Octocontrabass »

Awe2K wrote:
Does vid_mem point to the correct address?
Yes, it is 0xA0000
A framebuffer at 800x600x32 is about 1.8 megabytes. There is only 128 kilobytes of address space available for a framebuffer at that address. You either have the wrong address or you aren't using a LFB mode.
Awe2K wrote:Yes, I know 32 bits is 4 bytes, and 3 bytes are 24 bits. But if I change 3 to 4 and 2400 to 3200, then it just gets worse.
That's because you're actually in a 24bpp mode, not 32bpp.
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

In boot.asm

Code: Select all

   dd 0    ; # 0 = set graphics mode
   dd 800  ; # 800 = width
   dd 600  ; # 600 = height
   dd 32   ; # 32 = bpp
Second flag in multiboot header is set.
May my GRUB be trashing vga mode?
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

Also, how can I get linear frame buffer with GRUB?
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

Bump?
Octocontrabass
Member
Member
Posts: 5588
Joined: Mon Mar 25, 2013 7:01 pm

Re: VGA: only part of screen

Post by Octocontrabass »

Awe2K wrote:May my GRUB be trashing vga mode?
GRUB is not guaranteed to set the exact mode you've requested.
Awe2K wrote:Also, how can I get linear frame buffer with GRUB?
How do you know it's not already a linear frame buffer?
Awe2K wrote:Bump?
Six hours is not very long. Some of us have things to do outside of posting on internet forums.
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

I know that setting video mode manually won't give linear frame buffer.But I thought grub does so. Or I have to switch back to real mode and set this mode manually?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: VGA: only part of screen

Post by Brendan »

Hi,
Awe2K wrote:I know that setting video mode manually won't give linear frame buffer.But I thought grub does so. Or I have to switch back to real mode and set this mode manually?
If the "video mode number" that GRUB told you it used (in the multi-boot information structure) has bit 14 set (which is very likely) then the video mode is using LFB; and in that case you've probably got the address 0xA0000 from the wrong part of the VBE mode information structure (e.g. from the "window A base address" field and not from the "LFB base address" field).


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.
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

Brendan wrote:Hi,
Awe2K wrote:I know that setting video mode manually won't give linear frame buffer.But I thought grub does so. Or I have to switch back to real mode and set this mode manually?
If the "video mode number" that GRUB told you it used (in the multi-boot information structure) has bit 14 set (which is very likely) then the video mode is using LFB; and in that case you've probably got the address 0xA0000 from the wrong part of the VBE mode information structure (e.g. from the "window A base address" field and not from the "LFB base address" field).


Cheers,

Brendan
But if bit 14 is not set, how do I achieve that?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: VGA: only part of screen

Post by Brendan »

Hi,
Awe2K wrote:
Brendan wrote:If the "video mode number" that GRUB told you it used (in the multi-boot information structure) has bit 14 set (which is very likely) then the video mode is using LFB; and in that case you've probably got the address 0xA0000 from the wrong part of the VBE mode information structure (e.g. from the "window A base address" field and not from the "LFB base address" field).
But if bit 14 is not set, how do I achieve that?
If bit 14 isn't set, then GRUB is buggy and you're mostly screwed. You'd either have to refuse to boot, switch to real mode and set a video mode yourself to work around the problem, or setup segments for (one of) VBE's protected mode interfaces so that you can do bank switching (and write code that switches banks whenever it needs to access a different 64 KiB bank of display memory).

Of course it's extremely likely that bit 14 is set.


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.
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

Ok, now I've got my mboot->vbe_mode bit 14 set, how do I know linear address then, or where are framebuffer segments located?
Awe2K
Member
Member
Posts: 49
Joined: Sat Oct 24, 2015 3:14 am
Libera.chat IRC: awe2k

Re: VGA: only part of screen

Post by Awe2K »

Okay, it seems I've solved it. Grub simply gave me wrong vga memory offset. (I've forgot packed attr. within mboot struct)
Post Reply