[英]Using RGB colors in Assembly Language
I am Plotting a pixel on the screen from the following code using Assembly Language of x86 processor in C++. 我正在使用C ++中的x86处理器的汇编语言从以下代码在屏幕上绘制像素。 I dont want to use any function or method from C++ as I use this code for the boot loader program.
我不想使用C ++中的任何函数或方法,因为我将此代码用于引导加载程序。 here is the code:
这是代码:
/**********************************
* Mainvainsoft 2011. *
* Writen By: Farid-ur-Rahman *
* On: 24 Sep At: 1:34 AM. *
**********************************/
#include <conio.h>
void main ()
{
// Setting Video mode to 256 colours at 320 X 200
_asm {
mov ah , 0x00 // Setting Video mode or Clear Screen
mov al , 0x13 // Setting Video mode to 256 Color Mode
int 0x10 // Call the Registor
mov ah , 0x0c // Plot the Pixel
mov al , 4 // Color
mov cx , 160 // X-Axis
mov dx , 100 // Y-Axis
int 0x10 // Call the Registor
}
getch(); // Wait for the key press
}
I want to use the RGB colors to display on the pixel. 我想使用RGB颜色显示在像素上。
Mode 13h uses a palette with 256 18-bit RGB (6 bits for each) entries. 模式13h使用具有256个18位RGB(每个6位)条目的调色板。 So you can set for example entry 4 to the RGB color you want and the plot the pixel as you are doing with color 4.
因此,您可以将条目4设置为所需的RGB颜色,然后像对待颜色4一样绘制像素。
See here for an example of how to set a palette entry. 有关如何设置调色板条目的示例,请参见此处 。 After setting the video mode you can do something like:
设置视频模式后,您可以执行以下操作:
// Set entry 4
mov dx, 0x3c8
mov al, 4
out dx, al
inc dx
mov al, Red
out dx, al
mov al, Green
out dx, al
mov al, Blue
out dx, al
// draw pixel
In the video mode you're using, VGA mode 0x13 , each byte of the framebuffer points into the palette. 在您使用的视频模式下, VGA模式0x13 ,帧缓冲区的每个字节都指向调色板。 So if you have 24 bits of RGB color information, you can't write that directly into a pixel, since the pixels just contain palette indices.
因此,如果您具有24位RGB颜色信息,则不能直接将其写入像素,因为像素仅包含调色板索引。
You can of course quantize your colors into the palette, but that can be quite complicated. 您当然可以将颜色量化到调色板中,但这可能非常复杂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.