简体   繁体   English

切换到更高的分辨率

[英]Switching to a higher resolution

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 . 最近,我开始在NASM和C开发一个操作系统。我已经制作了一个启动加载程序,内核,文件系统等。到目前为止,我直接使用VGA文本模式来写入地址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. 我选择了最大显示分辨率320x200 ,但后来我意识到有三个问题。 Firstly, there are only 256 different colors. 首先,只有256种不同的颜色。 Secondly, the resolution is too small. 其次,分辨率太小。 Thirdly, writing to the address 0x000A0000 is too slow. 第三,写入地址0x000A0000太慢了。 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. 我在互联网上搜索了一些关于如何切换到更高分辨率的解释,如1920x1080以及如何使用256*256*256颜色而不是256.我发现的一切都说很难使用更高的分辨率,因为你必须为所有不同类型的图形卡开发驱动程序,对于某些卡没有文档,因此我们必须使用逆向工程。

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? 关于如何解决这个问题的任何建议?

Nearly every graphics adapter supports VESA framebuffer semantics, you can configure almost every video mode with that. 几乎每个图形适配器都支持VESA帧缓冲区语义,您可以使用它配置几乎所有视频模式。 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) 例如,VESA-Xserver几乎可以与任何图形适配器配合使用(但特定型号的显卡更快)

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

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). 你可以在装配中做高分辨率VESA图形,它应该足够快(在你开始学习的开始阶段,特别是不做非常花哨的3d东西)。

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. 我正在使用QEMU,它只能以640x480x24bpp的速度减速。 I switched to VirtualBox and though it starts up quite slowly, I have never looked back. 我切换到VirtualBox,虽然启动速度很慢,但我从未回头。

As for the programming part, I encourage you to look at a project called Pure64. 至于编程部分,我鼓励您查看一个名为Pure64的项目。 You can find it on GitHub. 你可以在GitHub上找到它。 Go to src/init/isa.asm and look at the end of the file - there is some code to do VESA initializations. 转到src / init / isa.asm并查看文件的结尾 - 有一些代码可以进行VESA初始化。 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. 我实际上使用Pure64设置一个干净的64位环境,我正在做VESA图形,所以我可以说它工作正常。

The VESA init consists of two parts - getting mode info and setting the video mode. VESA init由两部分组成 - 获取模式信息和设置视频模式。 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. 至少在64位模式下。

The only problem I had with this is that I could not make 32bpp mode working. 我遇到的唯一问题是我无法使32bpp模式工作。 I can do 24bpp, which is RRGGBB - 3 bytes per pixel (exactly like HTML/CSS color codes). 我可以做24bpp,这是RRGGBB - 每像素3个字节(完全像HTML / CSS颜色代码)。 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). 与在二进制计算机上包含3个字节的所有内容一样,这使得某些事情变得更复杂(至少对于初学者而言)。 Getting 4 bytes per pixel to work still eludes me. 每个像素获得4个字节的工作仍然无法实现。 Maybe this is a limitation of VirtualBox or something. 也许这是VirtualBox或其他东西的限制。

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. 如果你是一个温和的硬件,你应该做得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM