Replace invalid characters with HTML entities

— with —
’ with ’
+ with +
× with x
ç with ç
“ with “
” with ”
‘ with ‘
• with •
– with -
µ with µ
† with †
Fix C++
θ with θ
Yen symbol instead of times
Fix broken apos
Bullet again
E-circumflex
This commit is contained in:
James Gregory 2013-12-30 12:50:32 +11:00
commit 500e7f5654
353 changed files with 5091 additions and 5091 deletions

View file

@ -38,27 +38,27 @@
<P><BR></P>
<P>The key to understanding Listing 26.1 is understanding the effect of ANDing the rotated CPU data with the contents of the Bit Mask register. The CPU data is the pattern for the character to be drawn, with bits equal to 1 indicating where character pixels are to appear. The Data Rotate register is set to rotate the CPU data to pixel-align it, since without rotation characters could only be drawn on byte boundaries.
</P>
<TABLE WIDTH="100%"><TD WIDTH="5%" VALIGN="TOP"><IMG SRC="images/i.jpg"><TD WIDTH="95%"><SMALL><I>As I pointed out in Chapter 25, the CPU is perfectly capable of rotating the data itself, and it&#146;s often the case that that&#146;s more efficient. The problem with using the Data Rotate register is that the <B>OUT</B> that sets that register is time-consuming, especially for proportional text, which requires a different rotation for each character. Also, if the code performs full-byte accesses to display memory&#151;that is, if it combines pieces of two adjacent characters into one byte&#151;whenever possible for efficiency, the CPU generally has to do extra work to prepare the data so the VGA&#146;s rotator can handle it.</I></SMALL>
<TABLE WIDTH="100%"><TD WIDTH="5%" VALIGN="TOP"><IMG SRC="images/i.jpg"><TD WIDTH="95%"><SMALL><I>As I pointed out in Chapter 25, the CPU is perfectly capable of rotating the data itself, and it&rsquo;s often the case that that&rsquo;s more efficient. The problem with using the Data Rotate register is that the <B>OUT</B> that sets that register is time-consuming, especially for proportional text, which requires a different rotation for each character. Also, if the code performs full-byte accesses to display memory&mdash;that is, if it combines pieces of two adjacent characters into one byte&mdash;whenever possible for efficiency, the CPU generally has to do extra work to prepare the data so the VGA&rsquo;s rotator can handle it.</I></SMALL>
</TABLE>
<P>At the same time that the Data Rotate register is set, the Bit Mask register is set to allow the CPU to modify only that portion of the display memory byte accessed that the pixel-aligned character falls in, so that other characters and/or graphics data won&#146;t be wiped out. The result of ANDing the rotated CPU data byte with the contents of the Bit Mask register is a bit mask that allows only the bits equal to 1 in the original character pattern (rotated and masked to provide pixel alignment) to be modified by the CPU; all other bits come straight from the latches. The latches should have previously been loaded from the target address, so the effect of the ultimate synthesized bit mask value is to allow the CPU to modify only those pixels in display memory that correspond to the 1 bits in that part of the pixel-aligned character that falls in the currently addressed byte. The color of the pixels set by the CPU is determined by the contents of the Set/Reset register.
<P>At the same time that the Data Rotate register is set, the Bit Mask register is set to allow the CPU to modify only that portion of the display memory byte accessed that the pixel-aligned character falls in, so that other characters and/or graphics data won&rsquo;t be wiped out. The result of ANDing the rotated CPU data byte with the contents of the Bit Mask register is a bit mask that allows only the bits equal to 1 in the original character pattern (rotated and masked to provide pixel alignment) to be modified by the CPU; all other bits come straight from the latches. The latches should have previously been loaded from the target address, so the effect of the ultimate synthesized bit mask value is to allow the CPU to modify only those pixels in display memory that correspond to the 1 bits in that part of the pixel-aligned character that falls in the currently addressed byte. The color of the pixels set by the CPU is determined by the contents of the Set/Reset register.
</P>
<P>Whew. It sounds complex, but given an understanding of what the data rotator, set/reset, and the bit mask do, it&#146;s not that bad. One good way to make sense of it is to refer to the original text-drawing program in Listing 25.1 back in Chapter 25, and then see how Listing 26.1 differs from that program.</P>
<P>It&#146;s worth noting that the results generated by Listing 26.1 could have been accomplished without write mode 3. Write mode 0 could have been used instead, but at a significant performance cost. Instead of letting write mode 3 rotate the CPU data and AND it with the contents of the Bit Mask register, the CPU could simply have rotated the CPU data directly and ANDed it with the value destined for the Bit Mask register and then set the Bit Mask register to the resulting value. Additionally, enable set/reset could have been forced on for all planes, emulating what write mode 3 does to provide pixel colors.</P>
<P>The write mode 3 approach used in Listing 26.1 can be efficiently extended to drawing large blocks of text. For example, suppose that we were to draw a line of 8-pixel-wide bit-mapped text 40 characters long. We could then set up the bit mask and data rotation as appropriate for the left portion of each bit-aligned character (the portion of each character to the left of the byte boundary) and then draw the left portions only of all 40 characters in write mode 3. Then the bit mask could be set up for the right portion of each character, and the right portions of all 40 characters could be drawn. The VGA&#146;s fast rotator would be used to do all rotation, and the only <B>OUT</B>s required would be those required to set the bit mask and data rotation. This technique could well outperform single-character bit-mapped text drivers such as the one in Listing 26.1 by a significant margin. Listing 26.2 illustrates one implementation of such an approach. Incidentally, note the use of the 8&#215;14 ROM font in Listing 26.2, rather than the 8&#215;8 ROM font used in Listing 26.1. There is also an 8&#215;16 font stored in ROM, along with the tables used to alter the 8&#215;14 and 8&#215;16 ROM fonts into 9&#215;14 and 9&#215;16 fonts.</P>
<P>Whew. It sounds complex, but given an understanding of what the data rotator, set/reset, and the bit mask do, it&rsquo;s not that bad. One good way to make sense of it is to refer to the original text-drawing program in Listing 25.1 back in Chapter 25, and then see how Listing 26.1 differs from that program.</P>
<P>It&rsquo;s worth noting that the results generated by Listing 26.1 could have been accomplished without write mode 3. Write mode 0 could have been used instead, but at a significant performance cost. Instead of letting write mode 3 rotate the CPU data and AND it with the contents of the Bit Mask register, the CPU could simply have rotated the CPU data directly and ANDed it with the value destined for the Bit Mask register and then set the Bit Mask register to the resulting value. Additionally, enable set/reset could have been forced on for all planes, emulating what write mode 3 does to provide pixel colors.</P>
<P>The write mode 3 approach used in Listing 26.1 can be efficiently extended to drawing large blocks of text. For example, suppose that we were to draw a line of 8-pixel-wide bit-mapped text 40 characters long. We could then set up the bit mask and data rotation as appropriate for the left portion of each bit-aligned character (the portion of each character to the left of the byte boundary) and then draw the left portions only of all 40 characters in write mode 3. Then the bit mask could be set up for the right portion of each character, and the right portions of all 40 characters could be drawn. The VGA&rsquo;s fast rotator would be used to do all rotation, and the only <B>OUT</B>s required would be those required to set the bit mask and data rotation. This technique could well outperform single-character bit-mapped text drivers such as the one in Listing 26.1 by a significant margin. Listing 26.2 illustrates one implementation of such an approach. Incidentally, note the use of the 8x14 ROM font in Listing 26.2, rather than the 8x8 ROM font used in Listing 26.1. There is also an 8x16 font stored in ROM, along with the tables used to alter the 8x14 and 8x16 ROM fonts into 9x14 and 9x16 fonts.</P>
<P><B>LISTING 26.2 L26-2.ASM</B></P>
<!-- CODE //-->
<PRE>
; Program to illustrate high-speed text-drawing operation of
; write mode 3 of the VGA.
; Draws a string of 8&#215;14 characters at arbitrary locations
; without disturbing the background, using VGA&#146;s 8&#215;14 ROM font.
; Draws a string of 8x14 characters at arbitrary locations
; without disturbing the background, using VGA&rsquo;s 8x14 ROM font.
; Designed for use with modes 0Dh, 0Eh, 0Fh, 10h, and 12h.
; Runs only on VGAs (in Models 50 & up and IBM Display Adapter
; and 100% compatibles).
; Assembled with MASM
; By Michael Abrash
;
stack segment para stack &#145;STACK&#146;
stack segment para stack &lsquo;STACK&rsquo;
db 512 dup(?)
stack ends
;
@ -78,22 +78,22 @@ GC_ROTATE equ 3 ;GC data rotate/logical function
GC_MODE equ 5 ;GC Mode register
GC_BIT_MASK equ 8 ;GC bit mask register index
;
dseg segment para common &#145;DATA&#146;
dseg segment para common &lsquo;DATA&rsquo;
TEST_TEXT_ROW equ 69 ;row to display test text at
TEST_TEXT_COL equ 17 ;column to display test text at
TEST_TEXT_COLOR equ 0fh ;high intensity white
TestString label byte
db &#145;Hello, world!&#146;,0 ;test string to print.
db &lsquo;Hello, world!&rsquo;,0 ;test string to print.
FontPointer dd ? ;font offset
dseg ends
;
cseg segment para public &#145;CODE&#146;
cseg segment para public &lsquo;CODE&rsquo;
assume cs:cseg, ds:dseg
start proc near
mov ax,dseg
mov ds,ax
;
; Select 640&#215;480 graphics mode.
; Select 640x480 graphics mode.
;
mov ax,012h
int 10h
@ -122,14 +122,14 @@ start proc near
mov di,0
mov cx,8000h ;fill all 32k words
mov ax,0ffffh ;because of set/reset, the value
; written actually doesn&#146;t matter
; written actually doesn&rsquo;t matter
rep stosw ;fill with blue
;
; Set driver to use the 8&#215;14 font.
; Set driver to use the 8x14 font.
;
mov ah,11h ;VGA BIOS character generator function,
mov al,30h ; return info subfunction
mov bh,2 ;get 8&#215;14 font pointer
mov bh,2 ;get 8x14 font pointer
int 10h
call SelectFont
;
@ -166,7 +166,7 @@ Start endp
; CX = column to start string at
; DS:SI = string to draw
;
; Forces ALU function to &#147;move&#148;.
; Forces ALU function to &ldquo;move&rdquo;.
; Forces write mode 3.
;
DrawString proc near
@ -225,7 +225,7 @@ DrawString proc near
;
; Set up the GC rotation. In write mode 3, this is the rotation
; of CPU data before it is ANDed with the Bit Mask register to
; form the bit mask. Force the ALU function to &#147;move&#148;. Uses the
; form the bit mask. Force the ALU function to &ldquo;move&rdquo;. Uses the
; readability of VGA registers to leave reserved bits unchanged.
;
mov dx,GC_INDEX
@ -360,7 +360,7 @@ CharacterUp endp
;
SelectFont proc near
mov word ptr [FontPointer],bp ;save pointer
mov word ptr [FontPointer&#43;2],es
mov word ptr [FontPointer+2],es
ret
SelectFont endp
;
@ -368,12 +368,12 @@ cseg ends
end start
</PRE>
<!-- END CODE //-->
<P>In this chapter, I&#146;ve tried to give you a feel for how write mode 3 works and what it might be used for, rather than providing polished, optimized, plug-it-in-and-go code. Like the rest of the VGA&#146;s write path, write mode 3 is a resource that can be used in a remarkable variety of ways, and I don&#146;t want to lock you into thinking of it as useful in just one context. Instead, you should take the time to thoroughly understand what write mode 3 does, and then, when you do VGA programming, think about how write mode 3 can best be applied to the task at hand. Because I focused on illustrating the operation of write mode 3, neither listing in this chapter is the fastest way to accomplish the desired result. For example, Listing 26.2 could be made nearly twice as fast by simply having the CPU rotate, mask, and join the bytes from adjacent characters, then draw the combined bytes to display memory in a single operation.
<P>In this chapter, I&rsquo;ve tried to give you a feel for how write mode 3 works and what it might be used for, rather than providing polished, optimized, plug-it-in-and-go code. Like the rest of the VGA&rsquo;s write path, write mode 3 is a resource that can be used in a remarkable variety of ways, and I don&rsquo;t want to lock you into thinking of it as useful in just one context. Instead, you should take the time to thoroughly understand what write mode 3 does, and then, when you do VGA programming, think about how write mode 3 can best be applied to the task at hand. Because I focused on illustrating the operation of write mode 3, neither listing in this chapter is the fastest way to accomplish the desired result. For example, Listing 26.2 could be made nearly twice as fast by simply having the CPU rotate, mask, and join the bytes from adjacent characters, then draw the combined bytes to display memory in a single operation.
</P>
<P>Similarly, Listing 26.1 is designed to illustrate write mode 3 and its interaction with the rest of the VGA as a contrast to Listing 25.1 in Chapter 25, rather than for maximum speed, and it could be made considerably more efficient. If we were going for performance, we&#146;d have the CPU not only rotate the bytes into position, but also do the masking by ANDing in software. Even more significantly, we would have the CPU combine adjacent characters into complete, rotated bytes whenever possible, so that only one drawing operation would be required per byte of display memory modified. By doing this, we would eliminate all per-character <B>OUT</B>s, and would minimize display memory accesses, approximately doubling text-drawing speed.</P>
<P>As a final note, consider that non-transparent text could also be accelerated with write mode 3. The latches could be filled with the background (text box) color, set/reset could be set to the foreground (text) color, and write mode 3 could then be used to turn monochrome text bytes written by the CPU into characters on the screen with just one write per byte. There are complications, such as drawing partial bytes, and rotating the bytes to align the characters, which we&#146;ll revisit later on in Chapter 55, while we&#146;re working through the details of the X-Sharp library. Nonetheless, the performance benefit of this approach can be a speedup of as much as four times&#151;all thanks to the decidedly quirky but surprisingly powerful and flexible write mode 3.</P>
<P>Similarly, Listing 26.1 is designed to illustrate write mode 3 and its interaction with the rest of the VGA as a contrast to Listing 25.1 in Chapter 25, rather than for maximum speed, and it could be made considerably more efficient. If we were going for performance, we&rsquo;d have the CPU not only rotate the bytes into position, but also do the masking by ANDing in software. Even more significantly, we would have the CPU combine adjacent characters into complete, rotated bytes whenever possible, so that only one drawing operation would be required per byte of display memory modified. By doing this, we would eliminate all per-character <B>OUT</B>s, and would minimize display memory accesses, approximately doubling text-drawing speed.</P>
<P>As a final note, consider that non-transparent text could also be accelerated with write mode 3. The latches could be filled with the background (text box) color, set/reset could be set to the foreground (text) color, and write mode 3 could then be used to turn monochrome text bytes written by the CPU into characters on the screen with just one write per byte. There are complications, such as drawing partial bytes, and rotating the bytes to align the characters, which we&rsquo;ll revisit later on in Chapter 55, while we&rsquo;re working through the details of the X-Sharp library. Nonetheless, the performance benefit of this approach can be a speedup of as much as four times&mdash;all thanks to the decidedly quirky but surprisingly powerful and flexible write mode 3.</P>
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">A Note on Preserving Register Bits</FONT></H3>
<P>If you take a quick look, you&#146;ll see that the code in Listing 26.1 uses the readable register feature of the VGA to preserve reserved bits and bits other than those being modified. Older adapters such as the CGA and EGA had few readable registers, so it was necessary to set all bits in a register whenever that register was modified. Happily, all VGA registers are readable, which makes it possible to change only those bits of immediate interest, and, in general, I highly recommend doing exactly that, since IBM (or clone manufacturers) may well someday use some of those reserved bits or change the meanings of some of the bits that are currently in use.
<P>If you take a quick look, you&rsquo;ll see that the code in Listing 26.1 uses the readable register feature of the VGA to preserve reserved bits and bits other than those being modified. Older adapters such as the CGA and EGA had few readable registers, so it was necessary to set all bits in a register whenever that register was modified. Happily, all VGA registers are readable, which makes it possible to change only those bits of immediate interest, and, in general, I highly recommend doing exactly that, since IBM (or clone manufacturers) may well someday use some of those reserved bits or change the meanings of some of the bits that are currently in use.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>