Normal quotes
This commit is contained in:
parent
5e10794a24
commit
18011c595a
352 changed files with 6040 additions and 6040 deletions
64
37-01.md
64
37-01.md
|
|
@ -12,24 +12,24 @@ As I write this, the wife, the kid, and I are in the throes of yet
|
|||
another lightning-quick transcontinental move, this time to Redmond,
|
||||
Washington, to work for You Know Who. Moving is never fun, but what
|
||||
makes it worse for us is the pets. Getting them into kennels and to the
|
||||
airport is hard; there’s always the possibility that they might not be
|
||||
airport is hard; there's always the possibility that they might not be
|
||||
allowed to fly because of the weather; and, worst of all, they might not
|
||||
make it. Animals don’t usually end up injured or dead, but it does
|
||||
make it. Animals don't usually end up injured or dead, but it does
|
||||
happen.
|
||||
|
||||
In a (not notably successful) effort to cheer me up about the prospect
|
||||
of shipping my animals, a friend told me the following story, which he
|
||||
swears actually happened to a friend of his. I don’t know—to me, it has
|
||||
swears actually happened to a friend of his. I don't know—to me, it has
|
||||
the ring of an urban legend, which is to say it makes a good story, but
|
||||
you can never track down the person it really happened to; it’s always a
|
||||
friend of a friend. But maybe it is true, and anyway, it’s a good story.
|
||||
you can never track down the person it really happened to; it's always a
|
||||
friend of a friend. But maybe it is true, and anyway, it's a good story.
|
||||
|
||||
This friend of a friend (henceforth referred to as FOF), worked in an
|
||||
air-freight terminal. Consequently, he handled a lot of animals, which
|
||||
was fine by him, because he liked animals; in fact, he had quite a few
|
||||
cats at home. You can imagine his dismay when, one day, he took a kennel
|
||||
off the plane to find that the cat it carried was quite thoroughly dead.
|
||||
(No, it wasn’t resting, nor pining for the fjords; this cat was bloody
|
||||
(No, it wasn't resting, nor pining for the fjords; this cat was bloody
|
||||
*deceased*.)
|
||||
|
||||
FOF knew how upset the owner would be, and came up with a plan to make
|
||||
|
|
@ -38,29 +38,29 @@ markings. He would substitute that cat, and since all cats treat all
|
|||
humans with equal disdain, the owner would never know the difference,
|
||||
and would never suffer the trauma of the loss of her cat. So FOF drove
|
||||
home, got his cat, put it in the kennel, and waited for the owner to
|
||||
show up—at which point, she took one look at the kennel and said, “This
|
||||
isn’t my cat. My cat is dead.”
|
||||
show up—at which point, she took one look at the kennel and said, "This
|
||||
isn't my cat. My cat is dead."
|
||||
|
||||
As it turned out, she had shipped her recently deceased feline home to
|
||||
be buried. History does not record how our FOF dug himself out of this
|
||||
one.
|
||||
|
||||
Okay, but what’s the point? The point is, if it isn’t broken, don’t fix
|
||||
it. And if it is broken, maybe that’s all right, too. Which brings us,
|
||||
Okay, but what's the point? The point is, if it isn't broken, don't fix
|
||||
it. And if it is broken, maybe that's all right, too. Which brings us,
|
||||
neat as a pin, to the topic of drawing lines in a serious hurry.
|
||||
|
||||
### Fast Run-Length Slice Line Drawing {#Heading3}
|
||||
|
||||
In the last chapter, we examined the principles of run-length slice line
|
||||
drawing, which draws lines a run at a time rather than a pixel at a
|
||||
time, a run being a series of pixels along the major (longer) axis. It’s
|
||||
time, a run being a series of pixels along the major (longer) axis. It's
|
||||
time to turn theory into useful practice by developing a fast assembly
|
||||
version. Listing 37.1 is the assembly version, in a form that’s
|
||||
version. Listing 37.1 is the assembly version, in a form that's
|
||||
plug-compatible with the C code from the previous chapter.
|
||||
|
||||
**LISTING 37.1 L37-1.ASM**
|
||||
|
||||
; Fast run-length slice line drawing implementation for mode 0x13, the VGA’s
|
||||
; Fast run-length slice line drawing implementation for mode 0x13, the VGA's
|
||||
; 320x200 256-color mode.
|
||||
; Draws a line between the specified endpoints in color Color.
|
||||
; C near-callable as:
|
||||
|
|
@ -93,13 +93,13 @@ plug-compatible with the C code from the previous chapter.
|
|||
public _LineDraw
|
||||
_LineDraw proc near
|
||||
cld
|
||||
push bp ;preserve caller’s stack frame
|
||||
push bp ;preserve caller's stack frame
|
||||
mov bp,sp ;point to our stack frame
|
||||
sub sp, LOCAL_SIZE ;allocate space for local variables
|
||||
push si ;preserve C register variables
|
||||
push di
|
||||
push ds ;preserve caller’s DS
|
||||
; We’ll draw top to bottom, to reduce the number of cases we have to handle,
|
||||
push ds ;preserve caller's DS
|
||||
; We'll draw top to bottom, to reduce the number of cases we have to handle,
|
||||
; and to make lines between the same endpoints always draw the same pixels.
|
||||
mov ax,[bp].YStart
|
||||
cmp ax,[bp].YEnd
|
||||
|
|
@ -117,10 +117,10 @@ plug-compatible with the C code from the previous chapter.
|
|||
mov di,si
|
||||
add di,ax ;DI = YStart * SCREEN_WIDTH + XStart
|
||||
; = offset of initial pixel
|
||||
; Figure out how far we’re going vertically (guaranteed to be positive).
|
||||
; Figure out how far we're going vertically (guaranteed to be positive).
|
||||
mov cx,[bp].YEnd
|
||||
sub cx,[bp].YStart ;CX = YDelta
|
||||
; Figure out whether we’re going left or right, and how far we’re going
|
||||
; Figure out whether we're going left or right, and how far we're going
|
||||
; horizontally. In the process, special-case vertical lines, for speed and
|
||||
; to avoid nasty boundary conditions and division by 0.
|
||||
mov dx,[bp].XEnd
|
||||
|
|
@ -229,11 +229,11 @@ plug-compatible with the C code from the previous chapter.
|
|||
; (may be adjusted later). This is also the
|
||||
; final run pixel count
|
||||
push cx ;remember final run pixel count for later
|
||||
; If the basic run length is even and there’s no fractional advance, we have
|
||||
; If the basic run length is even and there's no fractional advance, we have
|
||||
; one pixel that could go to either the initial or last partial run, which
|
||||
; we’ll arbitrarily allocate to the last run.
|
||||
; If there is an odd number of pixels per run, we have one pixel that can’t
|
||||
; be allocated to either the initial or last partial run, so we’ll add 0.5 to
|
||||
; we'll arbitrarily allocate to the last run.
|
||||
; If there is an odd number of pixels per run, we have one pixel that can't
|
||||
; be allocated to either the initial or last partial run, so we'll add 0.5 to
|
||||
; the error term so this pixel will be handled by the normal full-run loop.
|
||||
add dx,si ;assume odd length, add YDelta to error term
|
||||
; (add 0.5 of a pixel to the error term)
|
||||
|
|
@ -241,7 +241,7 @@ plug-compatible with the C code from the previous chapter.
|
|||
jnz XMajorAdjustDone ;no, already did work for odd case, all set
|
||||
sub dx,si ;length is even, undo odd stuff we just did
|
||||
and bx,bx ;is the adjust up equal to 0?
|
||||
jnz XMajorAdjustDone ;no (don’t need to check for odd length,
|
||||
jnz XMajorAdjustDone ;no (don't need to check for odd length,
|
||||
; because of the above test)
|
||||
dec cx ;both conditions met; make initial run 1
|
||||
; shorter
|
||||
|
|
@ -267,7 +267,7 @@ plug-compatible with the C code from the previous chapter.
|
|||
inc cx ;one extra pixel in run
|
||||
sub dx,[bp].AdjDown ;reset the error term
|
||||
XMajorNoExtra:
|
||||
rep stosb ;draw this scan line’s run
|
||||
rep stosb ;draw this scan line's run
|
||||
add di,SCREEN_WIDTH ;advance along the minor axis (Y)
|
||||
XMajorFullRunsOddEntry: ;enter loop here if there is an odd number
|
||||
; of full runs
|
||||
|
|
@ -277,7 +277,7 @@ plug-compatible with the C code from the previous chapter.
|
|||
inc cx ;one extra pixel in run
|
||||
sub dx,[bp].AdjDown ;reset the error term
|
||||
XMajorNoExtra2:
|
||||
rep stosb ;draw this scan line’s run
|
||||
rep stosb ;draw this scan line's run
|
||||
add di,SCREEN_WIDTH ;advance along the minor axis (Y)
|
||||
|
||||
dec si
|
||||
|
|
@ -323,18 +323,18 @@ plug-compatible with the C code from the previous chapter.
|
|||
; (may be adjusted later)
|
||||
push cx ;remember final run pixel count for later
|
||||
|
||||
; If the basic run length is even and there’s no fractional advance, we have
|
||||
; If the basic run length is even and there's no fractional advance, we have
|
||||
; one pixel that could go to either the initial or last partial run, which
|
||||
; we’ll arbitrarily allocate to the last run.
|
||||
; If there is an odd number of pixels per run, we have one pixel that can’t
|
||||
; be allocated to either the initial or last partial run, so we’ll add 0.5 to
|
||||
; we'll arbitrarily allocate to the last run.
|
||||
; If there is an odd number of pixels per run, we have one pixel that can't
|
||||
; be allocated to either the initial or last partial run, so we'll add 0.5 to
|
||||
; the error term so this pixel will be handled by the normal full-run loop.
|
||||
add dx,si ;assume odd length, add XDelta to error term
|
||||
test al,1 ;is run length even?
|
||||
jnz YMajorAdjustDone ;no, already did work for odd case, all set
|
||||
sub dx,si ;length is even, undo odd stuff we just did
|
||||
and bx,bx ;is the adjust up equal to 0?
|
||||
jnz YMajorAdjustDone ;no (don’t need to check for odd length,
|
||||
jnz YMajorAdjustDone ;no (don't need to check for odd length,
|
||||
; because of the above test)
|
||||
dec cx ;both conditions met; make initial run 1
|
||||
; shorter
|
||||
|
|
@ -400,11 +400,11 @@ plug-compatible with the C code from the previous chapter.
|
|||
dec cx
|
||||
jnz YMajorLastLoop
|
||||
Done:
|
||||
pop ds ;restore caller’s DS
|
||||
pop ds ;restore caller's DS
|
||||
pop di
|
||||
pop si ;restore C register variables
|
||||
mov sp,bp ;deallocate local variables
|
||||
pop bp ;restore caller’s stack frame
|
||||
pop bp ;restore caller's stack frame
|
||||
ret
|
||||
_LineDraw endp
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue