VGA display card graphics mode access (Tip) (1)

xiaoxiao2021-03-06  40

VGA display card graphics mode access (Tip) (1)

I have been bored recently, and I borrowed this "IBM-PC assembly language program design" in the Shanghai Library. Didn't think, when you look at the display of the monitor. It feels that the author is very vague and cannot be understood. Later, I borrowed this "80x86 assembly language program design" found that these two books are almost the same in that chapter, the example image is the same. After I repeatedly exploited and reviewed a few days in the Shanghai Science and Technology Intelligence Research Institute. Finally molded the way. Of course, I also watched online. There is no relevant content, maybe I have not found it. So, here I have given my results, I hope that there will be people with me.

This paper mainly introduces the single pixel to read and write the screen without the use of the BIOS interrupt in VGA 640 * 480 16-color mode. I will use two codes to explain how to operate, used to some tips for people who are confused.

Before reading this article, I hope the reader can have a certain assembly basis, and the basics of the vga graphics card principle (in fact, just know some). If you have time, you can read the two books in front of me before reading this article, about the operation content of the VGA display card.

Examples used herein are used for NASM assembler, and readers can download from online. The software I use can download from www.sf.net.

Write an operation on VGA

The first is to determine the coordinate position, because the access to memory is one byte, that is, 8-bit binary, and the word of the four interfaces, constitutes a four-bit color value. Therefore, we need to determine which address in 0A000H is operated.

B = x / 8 y * 80

Since we know how to calculate the location, we will write a compilet code.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; file name: VGA_WRITE.ASM (partially resolved) ;; author: Huang Xiang Kui main function ;; : PIX_WRITE ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Al: Color Value (16 Color); Brief Note: This program requires users to work in VGA 640 * 380 16 color mode, before use, please Use the BIOS interrupt ;; Set the VGA display mode for 12h. ; Create time: January 2005; Copyright: (c) Huang Zikui; mailbox: huangxiangkui@msn.com ;; All copy of property rights should be used to contact me ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; x = cx, y = DXPUSH AX; save live AX register push bx; save live BX register push dx; save live DX registers; start calculation X / 8MOV AX, CXMOV BX, 8DIV BL; Al = AX / 8 AH = AX% 8MOV WORD [X], AX; deposit the result into x; start calculation Y * 80POP AX; read DX content into Axpush ax; The content is incorporated to restore the DX content MOV BX, 80mul bx; (dx, ax) = ax * 80 after the end of the program. Since DX does not value in this calculation, DX does not record. MOV Word [Y], AX; Start Summary Calculation Mov AX, Word [x] MOV DX, Word [Y] MOV BL, Almov BH, 00H; Here we have to extend 8 digits into 16-bit add dx, bx; dx BX MOV WORD [X], DXMOV Al, AHMOV AH, 00H; Extension into 16-bit MOV Word [Y], AX; Recovery Data Pop DXPOP BXPOP AX X: DW 0Y: DW 0; The program is running, the content in X is Access address, y is offset ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;; After the program is running, we can modify the pixels of the screen by writing 0A000: X values.

Then, let's see how to write. For graphics control register groups, I don't have introduced here. Everyone can see from the book, everywhere.

Due to the value of eight pixels in 0A000: X, in order to determine one of the pixels, we must use the y that just calculate to shift the data.

Then, if the offset is 0, it is the beginning of the address, that is, 10000000B. If not, then if it is 2, the data is 00100000B. So, we can know how to determine one of the pixels in 8 pixels.

As usual, we write a code

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; file name: VGA_WRITE.ASM (partially resolved) ;; author: Huang Xiang Kui main function ;; : PIX_WRITE ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Al: Color Value (16 Color); Brief Note: This program requires users to work in VGA 640 * 380 16 color mode, before use, please Use the BIOS interrupt ;; Set the VGA display mode for 12h. ; Create time: January 2005; Copyright: (c) Huang Zikui; mailbox: huangxiangkui@msn.com ;; All copy of property rights should be used to contact me ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; Next, the code is stored in B; protecting the site AX into the stack PUSH CX; protects the site BX into the stack MOV CX, Word [Y]; into the offset into CXMOV AL, 10000000B; because of the word eight, it is only using the Alror Al, CL; here only one 1, so ROR and SHR are the same MOV BYTE [B], Al; deposit the returned data into B; restore the site POP CXPOP AX B: DB 0; the program is running completed, the contents of the B is written. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;; CopyRight: (c) Huang Yuxi ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; Finally, we have to complete write work.

For writing, I personally feel that the book is very unclear, because the bit shield register is to read latch. However, there is no detailed introduction to the working principle of VGA. Music understanding of back to bit shielding. Since the latch is read, it is necessary to read once before each write operation. Write data to latch so that it is used later.

For color settings, we can do it by setting the reset register and setup reset allow registers.

Set the reset register index 0H bit: 0 Data bits of the write place 0: 1 Data bits of the write position 1: 2 Data bits of the write place 2: 3 The data bits of the write place 3 4 to 7 Reserve

Setting Reset Allow Register Index 1H Bits: 0 Part 4 Set Reset Allow Bits: 1 Place 1 Set Reset Allow Bits: 2 Place 2 Set Reset Allow Bits: 3-Part Dessment 3 Set Reset Allow Bits: 4 ~ 7 reserved

Below, let's take a look at the example of writing.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; file name: VGA_WRITE.ASM (partially resolved) ;; author: Huang Xiang Kui main function ;; : PIX_WRITE ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Al: Color Value (16 Color); Brief Note: This program requires users to work in VGA 640 * 380 16 color mode, before use, please Use the BIOS interrupt ;; Set the VGA display mode for 12h. ; Create time: January 2005; Copyright: (c) Huang Zikui; mailbox: huangxiangkui@msn.com ;; All copy of property rights should be used to contact me ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; or an example above. The al is the color Push Dx displayed; saves the field DX data Push Ax; saves the color information entered by the user; the graphics controller register; set the write mode MOV DX, 3CEHMOV AL, 5HOUT DX, Al; Set the mode register MOV DX 3cfhmov Al, 00000000Bout DX, Al; Settings 0 bits: 0 ~ 1 write mode (0, 1, 2, 3) Using the read mode 0 bits: 3 read mode (0, 1); set the reset allowable register MOV DX, 3CEHMOV AL, 1HOUT DX, AL; Settings Use Reset Allow Register MOV DX, 3CFHMOV Al, 0FHOUT DX, AL; Since we want to use the contents of the register, and is 16 colors, set to 0FH; set the reset register MOV DX, 3CEHMOV AL, 0HOUT DX, AL; Settings Use Reset Register MOV DX, 3CFHPOP AX Read User Color Information Push AX Save User Information, easy to restore Out DX, Al; here our color is set, so, You can write it casually in memory operations. Setting the data cycle displacement register MOV DX, 3CEHMOV Al, 3Hout DX, Al; Settings Using Data Cycle Displacement Register MOV DX, 3CFHMOV Al, 00000000Bout DX, Al; Since we have been looped when we start, it is fully set 0. And this loop is only used for CPUs, we use registers. Set bit shield register MOV DX, 3CEHMOV AL, 8Hout DX, Al; Settings Using Bit Shield Register MOV DX, 3CFHMOV Al, Byte [B] Out Dx, Al; We use mask here, will not need to set it. Set data segment and initial parameters MOV AX, 0A000HMOV ES, AXMOV BX, Word [x]; because we just let VGA read at once. So, we will listen to the time to read the memory, anyway, we don't have to use this parameter. MOV DX, 3CEHMOV AL, 4HOUT DX, AL; Sets the currently available register for readout selection register MOV DX, 3CFHMOV AL, 00HOUT DX, Almov Al, Byte [ES: BX]; let the latched readout surface 0 data MOV DX, 3CFHMOV Al, 01Hout DX, Almov Al, Byte [ES: BX]; MOV DX, 3CFHMOV Al, 02Hout DX, Almov Al, Byte [ES: BX]; let lock The data MOV DX, 3CFHMOV AL, 03Hout DX, Almov Al, Byte [ES: BX]; let the data of the readout surface 3; then we will write. MOV Al, 00hmov Byte [ES: BX], Al; Because our CPU data does not have any effect on color, because the front has been set to use the reset register. So I will write a 00h here. Restore on-site data POP AXPOP DX; here, all write operations are completed.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;; CopyRight: (c) Huang Yuxi ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;; below, I put the completed subroutine code. In fact, it is the integration of the above three sets of code. (It sounds "integration" like IBM). However, the comments here will not be added because they have it. The code below is compiled under NASM and is working well.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; file name: VGA_WRITE.ASM ;; author: Huang Xiang Kui ;; main functions: Pix_write ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Al: Color Value (16 Color); Brief Note: This program requires users to work in VGA 640 * 380 16-color mode, before use, please use the BIOS interrupt; Set the VGA display mode for 12h. ; Create time: January 2005; Copyright: (c) Huang Zikui; mailbox: huangxiangkui@msn.com ;; All copy of property rights should be used to contact me ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AX MOV AX, WORD [X] MOV DX, WORD [Y] MOV BL, Almov BH, 00HADD DX, BX MOV WORD [X], DX MOV AL, AHMOV AH, 00HMOV WORD [Y], AXPOP DXPOP BXPOP AX; S1 end; S2 STARTPUSH AXPUSH CX MOV CX, WORD [Y] MOV Al, 10000000Bror Al, Clmov Byte [B], Al Pop CXPOP AX; S2 End; S3 Start Push DXPUSH AX MOV DX, 3CEHMOV AL, 5HOUT DX, Al MOV DX, 3CFHMOV AL, 00000000Bout DX, Al Mov DX, 3CEHMOV AL, 1HOUT DX, Al Mov DX, 3CFHMOV Al, 0FHOUT DX, Al Mov DX, 3CEHMOV AL, 0HOUT DX, Al Mov DX, 3CFHPOP AXPUSH AXOUT DX, Al Mov DX , 3Cehmov Al, 3Hout DX, Al Mov DX, 3CFHMOV Al, 00000000Bout DX, Al Mov DX, 3CEHMOV Al, 8Hout DX, Al Mov DX, 3CFHMOV Al, Byte [B] Out DX, Al Mov AX, 0A000HMOV ES, AX MOV BX, Word [x] MOV DX, 3CEHMOV AL, 4HOUT DX, Al Mov DX, 3CFHMOV Al, 00Hout DX, Almov Al, Byte [ES: BX] MOV DX, 3CFHMOV Al, 01H Out DX, Almov Al, Byte [ES: BX] MOV DX, 3CFHMOV Al, 02Hout DX, Almov Al, Byte [ES: BX] MOV DX, 3CFHMOV Al, 03Hout DX, Almov Al, Byte [ES: BX] MOV Al , 00hmov Byte [ES: BX], Al POP AXPOP DX; S3 End Retx: DW 0Y: DW 0B: DB 0 ;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;; Copyright: (c) Huang Yuxi ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Studio software development group (SDT) studio software development group (SDT) studio software Development Team Beidou (Huang Yikui) January 2005

转载请注明原文地址:https://www.9cbs.com/read-67370.html

New Post(0)