Page 1 of 2
VGA: only part of screen
Posted: Sun Oct 25, 2015 7:50 am
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
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 8:01 am
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?
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 8:06 am
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
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 8:10 am
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
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 8:15 am
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.
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 8:17 am
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?
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 9:28 am
by Awe2K
Also, how can I get linear frame buffer with GRUB?
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 3:10 pm
by Awe2K
Bump?
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 4:16 pm
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.
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 11:06 pm
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?
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 11:36 pm
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
Re: VGA: only part of screen
Posted: Sun Oct 25, 2015 11:52 pm
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?
Re: VGA: only part of screen
Posted: Mon Oct 26, 2015 1:50 am
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
Re: VGA: only part of screen
Posted: Mon Oct 26, 2015 2:27 am
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?
Re: VGA: only part of screen
Posted: Mon Oct 26, 2015 2:40 am
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)