China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 23:16
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » Speed Considerations for GUI Design in VGA12h Mode View 1,903 Replies 7
Original Poster Posted 2006-08-18 14:48 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
### 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.
Attachments
Linex.rar (14.5 KiB, Credits to download 1 pts, Downloads: 34)
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 2 Posted 2006-08-18 23:55 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
VGA12h feels to me like just one word -- slow.
And there are only 16 colors, and the resolution is only 640×480.
I used to study VESA programming for 256-color 800×600, 1024×768 interfaces, and I have no interest in VGA12H.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 3 Posted 2006-08-20 00:27 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
JonePeng, if you have relatively comprehensive and practical materials on VESA, please provide some URLs!
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 4 Posted 2006-09-03 09:53 ·  中国 湖南 长沙 电信
中级用户
★★
Credits 282
Posts 126
Joined 2006-05-17 22:29
20-year member
UID 55724
Status Offline
If the color of the line is fixed, it is better to use write mode 3. In write mode 3, the CPU data will be used as a bit mask, which can avoid inefficient IO operations.

In fact, VGA has 256KB video memory. By modifying some key registers, a high-resolution 8-bit color mode can be achieved:
320*240*8 // The so-called Mode X. Many games use this resolution
320*400*8 // The Windows 9X startup screen uses this resolution
320*480*8
360*350*8 // Some video playback software uses this resolution because it is closest to the QCF resolution of 352*288
360*480*8 // So far, the highest resolution VGA 8-bit color mode
...

Horizontal resolution options: 320, 360
Vertical resolution options: 200, 240, 350, 400, 480


Theoretically, the parameters of the CRT controller can be modified to get any resolution, but I dare not try it randomly. For example, the resolution of 400*300 is very good, and I hope someone can figure it out.



Recommendation:
Title: Graphics Programmer's Guide (Michael Abrash's Graphics Programming Black Book Special Editior)
Author: Michael Abrash
Series title: Series of Computer Software Development and Programming
ISBN: 7-111-06396-1
Publication and distribution: Beijing - China Machine Press 1998-08-01
Carrier information: 1064 pages 26cm ¥128.00
Personal name - co-author: Abrash
Personal name - co-author: Qiandao Studio
Chinese Library Classification: TP391.41-62


This book introduces various knowledge and skills of high-performance graphics programming systematically and comprehensively from shallow to deep, from high level to bottom level. The author first discusses in detail the hardware of x86 series computers and their optimization characteristics, graphics programming and step-by-step optimization skills, gives the analysis process, program list and performance comparison of each optimization. Then a general animation graphics package X-Sharp based on Mode X is formed. Finally, the research and implementation technology of Quake is introduced.

This book is divided into two parts. The first part mainly introduces assembly optimization; the second part mainly introduces graphics hardware (VGA), high-performance graphics programming and optimization. The programs are written in C language and assembly language.

[ Last edited by zyl910 on 2006-9-3 at 09:55 ]
人类存在的目的就是试图理解人类为何存在
Floor 5 Posted 2006-09-03 11:12 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
RE:zyl910:

Good book! Where can I buy it?
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 6 Posted 2006-09-03 20:35 ·  中国 湖南 长沙 电信
中级用户
★★
Credits 282
Posts 126
Joined 2006-05-17 22:29
20-year member
UID 55724
Status Offline
I. Go to a second-hand bookstore and see, maybe you can find it.
II. Go to Chaoxing to view the electronic version.

English version:
http://public.planetmirror.com/pub/gpbb/

Translated (Chaoxing scanned version converted to PDF):
http://www.netyi.net/book/933a25cf-fa0e-4dab-b9d7-e58a0ea8f52e.aspx
人类存在的目的就是试图理解人类为何存在
Floor 7 Posted 2006-09-04 11:03 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 2,227
Posts 790
Joined 2005-01-27 00:00
21-year member
UID 35703
Gender Male
Status Offline
Why are there so many English version files? Does the Chinese version require points to download? But still, thank you ZYL910!!!
my major is english----my love is dos----my teacher is the buddha----my friends--how about U
Floor 8 Posted 2006-09-04 21:11 ·  中国 湖南 长沙 雨花区 电信
中级用户
★★
Credits 282
Posts 126
Joined 2006-05-17 22:29
20-year member
UID 55724
Status Offline
That book has many chapters:


Translator's Preface
Foreword
Chapter 1 The Brain Is the Best Optimizer
Chapter 2 Assembly Optimization
Chapter 3 General Timers
Chapter 4 The Essence of Clock Cycle Execution Time
Chapter 5 Optimization Using Reusable Blocks
Chapter 6 Beyond the Surface Value
Chapter 7 Local Optimization
Chapter 8 Accelerating C Programs Using Assembly Language
Chapter 9 Readers Make Me Succeed
Chapter 10 Coding Patiently to Speed Up
Chapter 11 Research on 286 and 386
Chapter 12 Research on 486 Part One
Chapter 13 Research on 486 Part Two
Chapter 14 Boyer-Moore String Search Method
Chapter 15 Linked Lists
Chapter 16 Optimization of Code Never Ends
Chapter 35 Bresenham Line Drawing Algorithm
Chapter 36 Bresenham Step Length Slice Algorithm
Chapter 37 Optimization of Step Length Slice Drawing Algorithm
Chapter 38 Polygon Primitives Operation
Chapter 39 Fast Convex Polygon Filling Algorithm
Chapter 40 Simplification of Complex Polygons
Chapter 41 Importance of Polygon Naming
Chapter 42 Wu's Antialiasing Algorithm
Chapter 43 Plane Animation
Chapter 44 Page Flipping Using Split Screen
Chapter 45 "Dirty Rectangle" Animation
Chapter 46 "Dirty Rectangle" Animation Using Masked Images
Chapter 47 Mode X: The Magical 256 - Color VGA Mode
Chapter 48 Mode X's Use of Latches
Chapter 49 256 - Color Animation in Mode X
Chapter 50 3D Animation
Chapter 51 Back - Face Culling Method
Chapter 52 Fast 3D Animation: Using X - Sharp
Chapter 53 Maximum Speed and Others
Chapter 54 3D Shading
Chapter 55 Color Representation in 256 - Color Mode
Chapter 56 Texture Mapping
Chapter 57 Optimization of Polygon Texture Mapping
Chapter 58 Optimization of Texture Mapping
Chapter 59 BSP Tree
Chapter 60 Compiling BSP Tree
Chapter 61 Reference Objects
Chapter 62 BSP Drawing Algorithm
Chapter 63 Floating - Point Operations in Real - Time 3D Processing
Chapter 64 Visible Surface Discrimination in Quake
Chapter 65 3D Clipping
Chapter 66 Culling of Faces in Quake
Chapter 67 Implementing Span Arrangement
Chapter 68 Lighting Model in Quake
Chapter 69 Surface Cache and Quake's Triangle Model
Chapter 70 Quake: Retrospect and Prospect



As for the Chinese version ——
It's uploaded by me
In order to earn some points to download other e - books, so set 5 points, please forgive me

Register as a Deyi.com user 2 points
Log in to Deyi.com every day 1 point
Upload one piece of data every time 2 points
Each time the uploaded data is downloaded by others, get the set score / 5


[ Last edited by zyl910 on 2006 - 9 - 4 at 21:13 ]
人类存在的目的就是试图理解人类为何存在
Forum Jump: