Page 1 of 1
Drawing in 32bit colour modes in protected & long mode
Posted: Fri Jan 27, 2017 12:30 pm
by obiwac
I am making a protected mode OS (I will probably also want to do long mode in the future) and I want to draw a pixel in 24 or 32bit colour modes. I would like to know if it is a good idea to switch to unreal mode. If so, how could I do it? Are there any other options? I am quite new to making OSes but I have a lot of experience with C. I am using the standard gcc compiler. Also, is it possible to do HDMI instead of VGA?
Re: Drawing in 32bit colour modes in protected & long mode
Posted: Fri Jan 27, 2017 12:46 pm
by SpyderTL
Switching to 16-bit mode is, I would say, a last resort. I would only do that if you had no other choice.
If you are in 32 or 64 bit mode, drawing pixels to the screen is fairly easy.
What is not easy in 32/64 bit mode is switching from text mode to graphics mode. If you can do that with GRUB or in your custom 16-bit boot loader, that would be the recommended approach.
So, switch to your desired graphics mode when booting, before you switch to 32-bit/64-bit mode, and do everything else without going back to 16-bit mode, if at all possible.
HDMI is handled automatically by the video card. You shouldn't have to do anything special to get HDMI to work.
Once you are in 32/64-bit mode, you simply find the address of the video card frame buffer, and start changing memory address values, and the pixels will appear on the screen.
Details are on the wiki page here:
Drawing In Protected Mode
Let us know if you have any questions or run into any problems.
Good luck.
Re: Drawing in 32bit colour modes in protected & long mode
Posted: Sat Jan 28, 2017 5:04 am
by obiwac
Thanks so much!!!
But I tried to change the grub .cfg file with "set gfxmode = 1024x768x32", but it didn't work though.
EDIT:
I found out that you can't have spaces between the gfxmode and the =. But now GRUB is in the right resolution but my OS does not keep it while booting. I did try gfxpayload=keep, but I can't seem to manage to get it work.
Re: Drawing in 32bit colour modes in protected & long mode
Posted: Sat Feb 04, 2017 4:46 pm
by obiwac
You can actually do this:
Code: Select all
section .text
align 4
dd 0x1BADB002
dd 0x04
dd -(0x1BADB002 + 0x04)
dd 0 ; skip some flags
dd 0
dd 0
dd 0
dd 0
dd 0 ; sets it to graphical mode
dd 800 ; sets the width
dd 600 ; sets the height
dd 32 ; sets the bits per pixel
and before calling main function just add
.
And in the grub .cfg you just need to add set
.
Plotting the pixels is easy:
- Go to the grub command line (with c)
- Type
- Under VGA controller, take the 8 last digits of the hexadecimal string, and that's your memory pointer for plotting pixels.
Hope this helped anyone!
Re: Drawing in 32bit colour modes in protected & long mode
Posted: Sat Feb 04, 2017 5:07 pm
by BrightLight
obiwac wrote:Plotting the pixels is easy:
- Go to the grub command line (with c)
- Type
- Under VGA controller, take the 8 last digits of the hexadecimal string, and that's your memory pointer for plotting pixels.
Hope this helped anyone!
This won't help anyone. You should never hard-code the pointer to the physical frame buffer, because it is different on each PC and on most emulators. For example, Bochs and VirtualBox have the frame buffer at 0xE0000000. QEMU has it at 0xFD000000. My laptop has it at 0xD0000000 and my two test PCs at 0xE4000000.
Instead, GRUB passes you a "VBE mode information structure" which is documented in the VBE specs. That structure contains a reliable pointer to the physical frame buffer that would work on all VBE-compatible PCs.
Re: Drawing in 32bit colour modes in protected & long mode
Posted: Sun Apr 30, 2017 6:52 am
by obiwac