VGA display card graphics mode access (prompted version) (2)
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.
Read operations for VGA
First, we still have to calculate the location in memory. Since we have already introduced it in the previous chapter. So, here we don't explain it. Write the code directly.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; file name: VGA_READ.ASM (partially resolved) ;; author: Huang Xiang Kui main function ;; : PIX_READ ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Returns: 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 = DX PUSH AX; save live AX register push bx; save live BX register push dx; save live DX registers; start calculating X / 8 MOV AX, CX MOV BX, 8 DIV BL; Al = AX / 8 AH = AX% 8 MOV WORD [X], AX; deposit the result into x; start calculation Y * 80 POP AX; read DX content read Enter the AX Push AX; in the stack to restore the DX content MOV BX, 80 MUL BX; (DX) = AX * 80 after the program ends. 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, Al Mov BH, 00H; Here we have to extend 8 digits into 16-bit add dx, bx; dx BX MOV WORD [X], DX MOV AL, AH MOV AH, 00H; Expanded into 16-bit MOV Word [Y], AX; Recovery Data Pop DX Pop BX Pop AX X: DW 0 Y: DW 0; Program Run Completion The content in X is the access address, y is offset ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;; (c) Huang Zikui ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; The above code is actually plagiarging (1) code, here again, there is no Readers read (1) consider.
Then, we still have to find the specified pixels we want in eight binarys. Different is this time we have to choose a more effective way. Moreover, we have to protect the offset in Y, which makes us use it again later. I think we will happen again about the working principle of 16 colors. So, we will cut into the topic.
Now, suppose you already know the relationship between the latch and the plane. So, we must consider how to combine some of the broken colors. Let's first determine the location of the pixel. So, we give (1) the same code. Different, we have different ways of use behind.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; file name: VGA_READ.ASM (partially resolved) ;; author: Huang Xiang Kui main function ;; : PIX_READ ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Returns: 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 ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;; The above code, stored in B; Protection Scene AX into the stack PUSH CX; Protection Scene BX into the stack MOV CX, Word [y]; into the offset into CX MOV AL, 10000000B; because of the word eight bits, only Al Ror Al, Cl; this is only one 1, so ROR and SHR are the same MOV BYTE [B ], Al; deposit the returned data into B; restore the field POP CX POP AX B: DB 0; the program runs complete, the contents of the B are written. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;; ;; CopyRight: (c) Huang Yuxi ;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;, remember, content in Y and B above. I have to use them to do a relative efficiency. If you have a better and more stable way, remember to tell me! remember!
Finally, I will read the color information in the memory. Everyone knows that the four digits of the color are in four latches. So, we have to read four times to the same address before you can get it. Every time I read there is a word, that is, the quarter of eight pixels. We will use TEST is also the AND (logic multiplication, also called). Then, read the temporary register with OR (logic plus, also call or). Let's talk less nonsense, let's do it. We will use read mode 0 to complete the read operation.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; file name: VGA_READ.ASM (partially resolved) ;; author: Huang Xiang Kui main function ;; : PIX_READ ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Returns: 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 ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;; Concealed the above code, x is address, y is a displacement number, B is data Push Bx Push CX Push DX Push ES Push AX; save live data, Although Al is modified, AH should be restored ^ _ ^ MOV AX, 0A000H; set the address of the ES 0A000h MOV ES, AX; we want to set the mode register for read mode 0 MOV DX, 3CEH MOV Al, 5H Out DX , Al; Set the current payroll as mode register MOV DX, 3CFH MOV Al, 00000000B OUT DX, AL; set the bit of the current read mode 0, note, read mode, and write mode settings, see (1); we want Set the initialization operation MOV BX, Word [x] before reading the data; this is where the memory is set. MOV AH, 00000000B; Here, the AH 00000000B This is not used by some of the operations, so it can be used for temporary registers MOV DX, 3CEH MOV Al, 4H OUT DX, AL; set the current use read space selection register Let's start reading data; first reading MOV DX, 3CFH MOV Al, 03H OUT DX, AL; Current Readout Face 3 MOV Al, Byte [ES: BX]; Read Data And Al, Byte [ b]; Remove the binary data or AH, Al; Al; read the data into the temporary register AH ROL AH, 1; the loop is left to move a AH; second reading MOV DX, 3CFH MOV Al, 02H OUT DX, Al Current Reading Face 2 MOV Al, Byte [ES: BX]; Read Data And Al, Byte [B]; Remove the binary data or AH, Al; Al; read the data into the temporary register AH ROL AH , 1; cycle left shift a AH; third reading MOV DX, 3CFH MOV Al, 01H OUT DX, Al; Current Readout Face 1 MOV Al, Byte [ES: BX]; Read Data And Al, Byte [ b]; Remove the binary data or AH, Al; Al; read the data into the temporary register AH ROL AH, 1; loop to move a AH; Fourth Read MOV DX, 3CFH MOV Al, 00h Out DX, Al Current Reading Face 0 MOV Al, Byte [ES: BX]; Read Data And Al, Byte [B]; Remove the binary data or AH, Al; Al; read the data into the temporary register AH ROL AH 1; loop left to shift a AH; Finally, we have to organize the data, so that it outputs the data MOV CX, Word [Y] Rol Ah, Cl; Word [Y] Rol Ah, Cl; I just moved right, now we move Back MOV Al, AH; saving the data into Al, which is convenient for data returns. POP BX; Restore AX data.
MOV AH, BH; restores the data within AH Pop ES POP DX POP CX POP BX; recovered data; here, the program is completed ;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;; ;; copyright: (c) Huang Yuxi ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; below, me Post 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_READ.ASM ;; author: Huang Xiang Kui ;; main functions: Pix_read ;; Parameter Description: CX: X Coordinate Value DX: Y Cartes Value Returns: Al: Color Value (16 Color); Brief Note: This program requires users to work in VGA 640 * 380 16 color mode, use BIOS before use Interrupt ;; Set the VGA display mode 12h. ; Create time: January 2005; Copyright: (c) Huang Zikui; mailbox: huangxiangkui@msn.com ;; All copy of property rights should be used to contact me ;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;; push:; s1 start push ax push bx push dx mov AX, CX MOV BX, 8 Div Bl Mov Word [x], AX POP AX PUSH AX MOV BX, 80 MUL BX MOV WORD [Y], AX MOV AX, Word [x] MOV DX, WORD [Y] MOV BL, Al Mov Bh, 00h Add DX, BX MOV WORD [X], DX MOV Al, AH MOV AH, 00H MOV WORD [Y], AX POP DX POP BX POP AX; S1 End; S2 START PUSH AX PUSH CX MOV CX, WORD [Y] MOV Al, 10000000B Ror Al, Cl Mov Byte [B], Al Pop CX POP AX; S2 End; S3 Start Push BX Push CX Push DX Push ES Push Ax Mov AX, 0A000H MOV ES, AX MOV DX, 3CEH MOV AL, 5H OUT DX, Al Mov DX, 3CFH MOV Al, 00000000B OUT DX, Al MOV BX, Word [x] MOV AH, 00000000B MOV DX, 3CEH MOV Al, 4H OUT DX, Al Mov DX, 3CFH MOV Al, 03H OUT DX, Al Mov Al, Byte [ES: BX] And Al, Byte [B ] or AH, Al Rol AH, 1 MOV DX, 3CFH MOV Al, 02H OUT DX, Al Mov Al, Byte [ES: BX] And Al, Byte [B] or AH, Al Rol AH, 1 MOV DX, 3CFH MOV Al, 01h Out DX, Al Mov Al, Byte [ES: BX] And Al, Byte [B] or AH, Al Rol AH, 1 MOV DX, 3CFH MOV Al, 00h OUT DX, Al Mov Al, Byte [ES: BX] And Al, Byte [B] or AH, Al Rol AH, 1 MOV CX, Word [Y] ROL AH, CL MOV AL, AH POP BX MOV AH, BH POP ES POP DX POP CX POP BX; S3 End Ret ;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;; ,;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I use the tools that I want to share with you. I am using Emacs compilation, NASM compile. Nice. Can be used under Win32 and Linux. It feels very good. If you are interested, you can use it. Although Emacs is more difficult, I know some basic operations, you will find how fascio software development group (SDT) Studio Development Team Beidou Star (Huang Yuxi) January 2005