0

I am Plotting a pixel on the screen from the following code using Assembly Language of x86 processor in C++. I dont want to use any function or method from C++ as I use this code for the boot loader program. 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.

2
  • use RGB color insteade of 15 assembly language colors Sep 24, 2011 at 13:40
  • 1
    as mentioned mode 0x13 doesn't support more then 256 colors at the same time and there are no standard BIOS modes that support more. However the vesa bios extensions provide support for higher color modes. gameprogrammer.com/1-vbe.html
    – Eelke
    Sep 24, 2011 at 13:50

2 Answers 2

4

Mode 13h uses a palette with 256 18-bit RGB (6 bits for each) entries. 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.

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
1

In the video mode you're using, VGA mode 0x13, each byte of the framebuffer points into the palette. 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.

You can of course quantize your colors into the palette, but that can be quite complicated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.