### Speed Considerations in VGA12h Mode GUI Design
1. Time Consumption Comparison of Drawing Lines in Various Ways in VGA12h Mode:
==============================================
Line Drawing Method Time Consumption (seconds) Running Program* Number of Writes Linear Address Calculation REG Settings
-----------------------------------------------------------------------------------------------------
Scan Block Drawing (REG) 0.046343422 lineff.com L*P/8 Non-repetitive between lines Non-repetitive
Scan Line Drawing (REG) 0.061104584 linehh.com L*P/8 Repetitive between lines Repetitive between lines
Vertical Line Drawing (REG) 0.326120375 linev.com L*P Non-repetitive between points Repetitive between lines
Normal Line Drawing (REG) 0.823882125 linen.com L*P Repetitive between points Repetitive between lines
-----------------------------------------------------------------------------------------------------
Normal Point Drawing (BIOS) 3.899710625 lineb.com L*P Repetitive between points Repetitive between points
==============================================
Note: REG -- VGA registers BIOS -- BIOS interrupts L -- Number of lines P -- Number of pixels
* -- lineff.com, linehh.com draw 100*16 screen, others.com draw 16 screen
It can be seen that BIOS point drawing and line drawing are too slow (time consumption is about 64 times that of the scan line method), and are not considered in GUI programming. Even when using VGA register programming, the time consumption of normal line drawing is about 13.5 times that of the scan line method, and the time consumption of normal line drawing is about 2.53 times that of the vertical line method.
Note: The methods of lineff.com and linehh.com are both drawing scan lines, and because the start and end of the lines fall on pixels that are multiples of 8, each time 8 pixels are written, block drawing and line drawing are the fastest. lineff.com is faster because it does not repeat address calculation between lines, so it is faster, and the time consumption is 2/3 of linehh.com! linev.com is the fastest way to draw vertical lines, for the same reason as scan line block drawing -- no repeated address calculation! For other lines that are not horizontal or vertical, only the normal line drawing method can be used.
Therefore, in GUI design requiring speed, block drawing should use the lineff.com method, frame line drawing should use the linehh.com and linev.com methods, not the linen.com normal line drawing method!
2. Considerations for Absolute Speed Optimization:
When using the VGA register method to draw lines, it is necessary to go through several stages: first ① calculate the linear address of the video buffer, ② calculate the bit mask value, set the bit mask and other registers, then ③ draw points and lines, and finally ④ restore the default values of the modified registers.
In the first link ①, multiplication and division may be used, but multiplication and division are generally considered to be operations with high overhead. When encountering multiplication and division that need to be executed repeatedly, they should be replaced with shifts and additions. Shifting left by 1 bit is equivalent to multiplying by 2, and shifting right by 2 bits is equivalent to dividing by 4. In many drawing algorithms, calculating the address often requires multiplying by 80, which can be calculated as follows:
80*y=(64+16)*y=(y shl 6)+(y shl 4)
Assembly code:
mov ax,y
mov cx,4
shl ax,cl ;y*16
mov bx,ax
shl bx,1
shl bx,1 ;y*64
add ax,bx ;(y*64)+(y*16)
In the register operations that are necessarily used in stages ②③④, the efficiency is also different between using out dx,al or out dx,ax. The following code segment:
mov dx,3CEh
xor al,al
out dx,al
inc dx
mov ax,Color
out dx,al
dec dx
mov al,1
out dx,al
mov al,0Fh
out dx,al
Can be considered to be changed to:
mov dx,3CEh
xor al,al
mov ah,Color
out dx,ax
mov ax,0F01h
out dx,ax
In each stage of line drawing, you can pay attention to whether this operation is necessary to be repeated. If there is a fixed incremental relationship, etc., it can be simplified. If it is not necessary, it can be omitted. You can refer to the program code in line?.com.
1. Time Consumption Comparison of Drawing Lines in Various Ways in VGA12h Mode:
==============================================
Line Drawing Method Time Consumption (seconds) Running Program* Number of Writes Linear Address Calculation REG Settings
-----------------------------------------------------------------------------------------------------
Scan Block Drawing (REG) 0.046343422 lineff.com L*P/8 Non-repetitive between lines Non-repetitive
Scan Line Drawing (REG) 0.061104584 linehh.com L*P/8 Repetitive between lines Repetitive between lines
Vertical Line Drawing (REG) 0.326120375 linev.com L*P Non-repetitive between points Repetitive between lines
Normal Line Drawing (REG) 0.823882125 linen.com L*P Repetitive between points Repetitive between lines
-----------------------------------------------------------------------------------------------------
Normal Point Drawing (BIOS) 3.899710625 lineb.com L*P Repetitive between points Repetitive between points
==============================================
Note: REG -- VGA registers BIOS -- BIOS interrupts L -- Number of lines P -- Number of pixels
* -- lineff.com, linehh.com draw 100*16 screen, others.com draw 16 screen
It can be seen that BIOS point drawing and line drawing are too slow (time consumption is about 64 times that of the scan line method), and are not considered in GUI programming. Even when using VGA register programming, the time consumption of normal line drawing is about 13.5 times that of the scan line method, and the time consumption of normal line drawing is about 2.53 times that of the vertical line method.
Note: The methods of lineff.com and linehh.com are both drawing scan lines, and because the start and end of the lines fall on pixels that are multiples of 8, each time 8 pixels are written, block drawing and line drawing are the fastest. lineff.com is faster because it does not repeat address calculation between lines, so it is faster, and the time consumption is 2/3 of linehh.com! linev.com is the fastest way to draw vertical lines, for the same reason as scan line block drawing -- no repeated address calculation! For other lines that are not horizontal or vertical, only the normal line drawing method can be used.
Therefore, in GUI design requiring speed, block drawing should use the lineff.com method, frame line drawing should use the linehh.com and linev.com methods, not the linen.com normal line drawing method!
2. Considerations for Absolute Speed Optimization:
When using the VGA register method to draw lines, it is necessary to go through several stages: first ① calculate the linear address of the video buffer, ② calculate the bit mask value, set the bit mask and other registers, then ③ draw points and lines, and finally ④ restore the default values of the modified registers.
In the first link ①, multiplication and division may be used, but multiplication and division are generally considered to be operations with high overhead. When encountering multiplication and division that need to be executed repeatedly, they should be replaced with shifts and additions. Shifting left by 1 bit is equivalent to multiplying by 2, and shifting right by 2 bits is equivalent to dividing by 4. In many drawing algorithms, calculating the address often requires multiplying by 80, which can be calculated as follows:
80*y=(64+16)*y=(y shl 6)+(y shl 4)
Assembly code:
mov ax,y
mov cx,4
shl ax,cl ;y*16
mov bx,ax
shl bx,1
shl bx,1 ;y*64
add ax,bx ;(y*64)+(y*16)
In the register operations that are necessarily used in stages ②③④, the efficiency is also different between using out dx,al or out dx,ax. The following code segment:
mov dx,3CEh
xor al,al
out dx,al
inc dx
mov ax,Color
out dx,al
dec dx
mov al,1
out dx,al
mov al,0Fh
out dx,al
Can be considered to be changed to:
mov dx,3CEh
xor al,al
mov ah,Color
out dx,ax
mov ax,0F01h
out dx,ax
In each stage of line drawing, you can pay attention to whether this operation is necessary to be repeated. If there is a fixed incremental relationship, etc., it can be simplified. If it is not necessary, it can be omitted. You can refer to the program code in line?.com.
Attachments
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
