Use the BIOS and write the graphics directly to draw the image

Source: Internet
Author: User
Tags clear screen constant definition

1. Draw a pixel [cpp] view plaincopyprint? Unrecognized INT 0x10 recognizable video image mode ---------------------------------------------------------------------- mode resolution (column * Row, pixel) color count 6 640x200 2 0DH 320x200 16 0EH 640x350 16 0FH 640x350 2 10 H 640x200 16 11 H 640x480 2 12 H 640x480 16 13 H 320x200 256 6AH 800x600 16 ----------------------------------------------------------------------- when the Video Controller is in graphic mode, INT 0 The x10 function 0CH draws a pixel on the screen. (Function 0CH execution is quite slow) [cpp] ----------------------------------------------------------------------- INT 0x10 function 0CH --------------------------------------------------------- Description: Write pixel accept parameter: AH 0CH AL pixel value BH video page cx x coordinate dx y coordinate return value: no note: the video must be displayed in graphic mode. The pixel value range and coordinate range are related to the current graph mode. If AL is set to a 7-bit value, the new Pixel will perform an exclusive or operation with the content of the current pixel. --------------------------------------------------------------------------- Example: [cpp] # This program draws a straight line in graphics mode. #2012-12-24 # guzhoudiaoke@126.com. section. text. global _ start. code16 _ start: jmp main clear_screen: # clear screen function movb $0x06, % ah # function no. 0x06 movb $0, % al # Roll up all rows, movb $0, % ch # movb $0 in the upper left corner of the screen, % ch # movb $24 in the upper left corner, % dh # movb $79 in the lower right corner, % dl # movb $ in the lower right corner 0x07, % bh # blank area property int $0x10 ret main: movw % cx, % ax movw % ax, % ds movw % ax, % es call clear_screen # clear screen # Set to image mode, 0x6a to 800x600, 16 colors movb $0, % ah # function no. 0x0 movb $ 0x6a, % al # display mode int $0x10 # draw a straight line movb $0x0, % bh # video page movw $300, % dx # y coordinate movw $100, % cx # x coordinate movb $ 0x0c, % ah # function no. movb $9, % al # pixel value (color) 1: int $0x10 incw % cx # Next pixel cmpw $700, % cx # whether the end position is reached jne 1b 1: jmp 1b. org 0x1fe, 0x90. word 0xaa55 result: 2. the image mode function 0x13 is used to display the string [cpp] # This program draws text and a straight line in graphics mode. #2012-12-24 # guzhoudiaoke@126.com. section. text. global _ start. code16 _ start: jmp main clear_screen: # clear screen function movb $0x06, % ah # function no. 0x06 movb $0, % al # Roll up all rows, movb $0, % ch # movb $0 in the upper left corner, % ch # movb $24 in the upper left corner, % dh # movb $79 in the lower right corner, % dl # bottom right column movb $0x07, % bh # blank area attribute int $0x10 ret main: movw % Cx, % ax movw % ax, % ds movw % ax, % es call clear_screen # clear screen # Set to image mode, 0x6a to 800x600, 16 colors movb $0, % ah # function no. 0x0 movb $ 0x6a, % al # display mode int $0x10 # display text movw $ msgstr, % ax movw % ax, % bp movw len, % cx movb $0x13, % ah movb $0, % al movb $0x04, % bl movb $0x0, % bh movb $0x02, % dh movb $0x04, % dl int $0x10 # draw a straight line movb $0x0, % bh # video page movw $300, % dx # y coordinate movw $100, % cx # x coordinate movb $ 0x0c, % ah # function no. movb $9, % Al # pixel value (color) 1: int $0x10 incw % cx # Next pixel cmpw $700, % cx # Whether to reach the end position jne 1b 1: jmp 1b msgstr :. asciz "line: start (100,300), end (700,300) \ n" len :. int. -msgstr. org 0x1fe, 0x90. word 0xaa55 result: 3. memory ing graphics are the easiest way to use memory ing graphics video mode 0X13. At this time, screen pixels are mapped to an array of bytes, each pixel is one byte. There are 320*200 pixels in total. Because there are 256 colors, each pixel is a byte. The address 0xa0000 corresponding to the pixel in the upper left corner. In Mode 0x13, each integer color value represents the index of the color table of the color palette. Each item in the palette is composed of three independent integers (0 ~ 63), which is called an RGB value. The color palette controls the background color of the screen. There are two output ports used to control the video palette: The value sent to port 0x3c8 indicates the palette table items to be modified, and the color value to be modified is sent to port 0x3c9. Example: [cpp] # This program draws color pixels at mode 0x13 #2012-12-24 # guzhoudiaoke@126.com. section. text. global _ start. code16 _ start: jmp main # screens # clear screen function: # set the screen background color. The index 0 of the color palette indicates the background color clear_screen: # clear screen function movb $0x06, % ah # function no. 0x06 movb $0, % al # Roll up all rows, that is, clear screen movb $0, % ch # movb $0 in the upper left corner, % ch # movb $24, % dh # movb $79, % dl # Movb $0x07, % bh # blank area attribute int $0x10 ret # ---------------------------------------------------------- # set_video_mode: movb $0, % ah # function no. 0x0 movb $ MODE_0X13, % al # display mode int $0x10 ret # detail # display some text functions: # Use INT 0x10 to interrupt the 0x13 function, display the display mode in which the computer is currently working. draw_some_text: movw $ msg_str, % bp # ES: BP is the string address movw msg_len, % cx # displays the number of characters movb $0x13, % Ah # function no. movb $0, % al # display mode movb $ TEXT_COLOR, % bl # Attribute Value movb $0, % bh # video page movb $ TEXT_ROW, % dh # display the starting line movb $ TEXT_COL, % dl # display the starting column int $0x10 ret # rotate # Set the background color to dark blue set_screen_bk_color: movw $ VIDEO_PALLETE_PORT, % dx movb $ PA_INDEX_BACKGROUND, % al outb % al, % dx movw $ COLOR_SELECTION_PORT, % dx movb $0, % al # Red outb % al, % dx movb $0, % al # Green outb % al, % dx movb $18, % al # Blue (brightness 18/63) outb % al, % dx ret # ------------------------------------------------------------ # draw some pixels by writing graphics: # First set the color of palette Index 1 to white # Then write data to ES: DI (PA_INDEX_WHITE) draw_some_pixels: # change the color at Index 1 to white (, 63, 63) movw $ VIDEO_PALLETE_PORT, % dx movb $ PA_INDEX_WHITE, % al outb % al, % dx movw $ COLOR_SELECTION_PORT, % dx movb $63, % al # Red outb % al, % dx movb $63, % al # Green ou Tb % al, % dx movb $63, % al # Blue outb % al, % dx # Set the ES value movw $ VIDEO_SEG_GRAPHIC, % ax movw % ax, % es # Set the video memory address (Destination Address) for the pixel location to be displayed movw $ (PIXEL_ROW_ST * 320 + PIXEL_COL_ST), % di movb $ PA_INDEX_WHITE, % al movw $ PIXEL_COUNT, % cx draw_a_pixel: stosb addw $5, % di loop draw_a_pixel ret main: movw % cx, % ax movw % ax, % ds movw % ax, % es call clear_screen # clear screen call set_video_mode # Set the display mode call set_screen_bk_color # Set the background Color call draw_some_text # draw string call draw_some_pixels # draw pixel 1: jmp 1b # constant definition: bytes = 0xb800 bytes = 0xa000 bytes = 0x3c8 COLOR_SELECTION_PORT = 0x3c9 MODE_0X13 = 0x13 bytes = 0x0 PA_INDEX_WHITE = 0x1 TEXT_ROW = 0x01 TEXT_COL = 0x00 TEXT_COLOR = 0x04 PIXEL_ROW_ST = 100 PIXEL_COL_ST = 160-5*10 PIXEL_COUNT = 20 msg_str: msg_mode :. asciz "video mode: 0x1 3 ". org msg_mode + 40, 0 msg_scr_res :. asciz "screen resolution: 320x200 ". org msg_scr_res + 40, 0 msg_color_num :. asciz "color num: 256 ". org msg_color_num + 40*4, 0 msg_babyos :. asciz "The new Baby OS will have a GUI, but now it can only draw some pixels, haha .. and merry Christmas! "Msg_len :. int. -msg_str-1. org 0x1fe, 0x90. word 0xaa55 result: Note: the text is displayed in bios int 0x10. The text displayed in 0x13 mode of VGA is 40 columns x 25 lines, and the character box is 8x8. It looks ugly, I will study super VGA (SVGA) later ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.