6

Recently, I started developing an operating system in NASM and C. I have already made a boot loader, kernel, filesystem, etc. So far I used the VGA text mode directly in order to write to the address 0x000B8000. So, I decided to switch to video mode instead of text mode. I chose maximal display resolution 320x200, but then I realised that there are three problems. Firstly, there are only 256 different colors. Secondly, the resolution is too small. Thirdly, writing to the address 0x000A0000 is too slow. I tried to do some animations, but it is very laggy and sometimes it waits more than one second before the next frame.

I have searched on the internet for some explanations on how to switch to higher resolutions such as 1920x1080 and how to use 256*256*256 colors instead of just 256. Everything I found said that it is very hard to use higher resolutions because you must develop drivers for all the different types of graphics cards and for some cards there are no documentations, so we must use reverse engineering.

I really want to introduce high-resolution graphics to my operating system. Is it really hard or is there any easy method? Any suggestions on how I can solve this?

Razor
  • 1,778
  • 4
  • 19
  • 36
  • 1
    If you are already having problems writing code to display fast animations on a lousy VGA 320x200 screen, then better try and improve that first before going to a screen with 3 times as much bits per pixel (probably even 4 times) and 30 (!) times more pixels. – Jongware Jan 17 '16 at 23:49

2 Answers2

4

Nearly every graphics adapter supports VESA framebuffer semantics, you can configure almost every video mode with that. The drawback is that you cannot use vendor specific features (accelerated graphics etc.)

The VESA-Xserver for example works with almost any graphics adapter (but the model specific ones are considerably faster)

See also: https://en.wikipedia.org/wiki/VESA_BIOS_Extensions

user253751
  • 57,427
  • 7
  • 48
  • 90
Ctx
  • 18,090
  • 24
  • 36
  • 51
  • Thank you, but I still have one problem. I switched to 0x0118 (1024x768) VESA mode, but it is extremely slow. It is so slow that it is useless. I tried to do some simple things to test it. I have an array of 2014x768 images in some region of RAM and I made a simple C program which loads it one after the other. However, it waits more than a second before loading another image. I am sure there is no optimisation problems. How I can speed it up to about 60+ fps? –  Jan 23 '16 at 23:32
1

You can do high res VESA graphics in assembly and it should be fast enough (in the beginning phase when you are learning and not doing very fancy 3d stuff, especially).

First of all, make sure you are using a good emulator/virtual machine for testing. I was using QEMU and it was way to slow to do any graphics at only 640x480x24bpp. I switched to VirtualBox and though it starts up quite slowly, I have never looked back.

As for the programming part, I encourage you to look at a project called Pure64. You can find it on GitHub. Go to src/init/isa.asm and look at the end of the file - there is some code to do VESA initializations. I am actually using Pure64 to set up a clean 64bit environment and I am doing VESA graphics so I can say that it works fine.

The VESA init consists of two parts - getting mode info and setting the video mode. Once you get the mode info, you get a Video Base Pointer to a region of memory which is continuous and where you can write your pixels without switching banks and doing complicated stuff. At least in 64-bit mode.

The only problem I had with this is that I could not make 32bpp mode working. I can do 24bpp, which is RRGGBB - 3 bytes per pixel (exactly like HTML/CSS color codes). As with everything that comprises of 3 bytes on a binary computer, this makes some things a bit more complex (at least for a beginner). Getting 4 bytes per pixel to work still eludes me. Maybe this is a limitation of VirtualBox or something.

This all means that for basic hi-res graphics there is no need to do a lot of hardware-specific things. If you are on a mildly current hardware, you should do fine.

Paweł Pela
  • 421
  • 3
  • 16
  • *"mildly current hardware"* - the VESA extensions have been the same at least since the early 90's (except for the addition of a few additional supported modes) so if the capacitors on your hardware are working, VESA will likely work as well. – David C. Rankin Jun 01 '16 at 02:17