Normal quotes
This commit is contained in:
parent
5e10794a24
commit
18011c595a
352 changed files with 6040 additions and 6040 deletions
32
35-07.md
32
35-07.md
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
**LISTING 35.3 L35-3.ASM**
|
||||
|
||||
; Fast assembler implementation of Bresenham’s line-drawing algorithm
|
||||
; Fast assembler implementation of Bresenham's line-drawing algorithm
|
||||
; for the EGA and VGA. Works in modes 0Eh, 0Fh, 10h, and 12h.
|
||||
; Borland C++ near-callable.
|
||||
; Bit mask accumulation technique when |DeltaX| >= |DeltaY|
|
||||
|
|
@ -74,7 +74,7 @@
|
|||
local MoveToNextByte, ResetBitMaskAccumulator
|
||||
mov cx,bx ;# of pixels in line
|
||||
jcxz Line1End ;done if there are no more pixels
|
||||
; (there’s always at least the one pixel
|
||||
; (there's always at least the one pixel
|
||||
; at the start location)
|
||||
shl si,1 ;DeltaY * 2
|
||||
mov bp,si ;error term
|
||||
|
|
@ -87,7 +87,7 @@
|
|||
; for the initial pixel
|
||||
LineLoop:
|
||||
;
|
||||
; See if it’s time to advance the Y coordinate yet.
|
||||
; See if it's time to advance the Y coordinate yet.
|
||||
;
|
||||
and bp,bp ;see if error term is negative
|
||||
js MoveXCoord ;yes, stay at the same Y coordinate
|
||||
|
|
@ -101,7 +101,7 @@
|
|||
;load latches and write pixels, with bit mask
|
||||
; preserving other latched bits. Because
|
||||
; set/reset is enabled for all planes, the
|
||||
; value written actually doesn’t matter
|
||||
; value written actually doesn't matter
|
||||
add di,EVGA_SCREEN_WIDTH_IN_BYTES ;increment Y coordinate
|
||||
add bp,si ;adjust error term back down
|
||||
;
|
||||
|
|
@ -113,7 +113,7 @@
|
|||
else
|
||||
ror ah,1 ;move pixel mask 1 pixel to the right
|
||||
endif
|
||||
jnc ResetBitMaskAccumulator ;didn’t wrap to next byte
|
||||
jnc ResetBitMaskAccumulator ;didn't wrap to next byte
|
||||
jmp short MoveToNextByte ;did wrap to next byte
|
||||
;
|
||||
; Move pixel mask one pixel (either right or left, depending
|
||||
|
|
@ -134,7 +134,7 @@
|
|||
;load latches and write pixels, with bit mask
|
||||
; preserving other latched bits. Because
|
||||
; set/reset is enabled for all planes, the
|
||||
; value written actually doesn’t matter
|
||||
; value written actually doesn't matter
|
||||
MoveToNextByte:
|
||||
if MOVE_LEFT
|
||||
dec di ;next pixel is in byte to left
|
||||
|
|
@ -156,7 +156,7 @@
|
|||
;load latches and write pixels, with bit mask
|
||||
; preserving other latched bits. Because
|
||||
; set/reset is enabled for all planes, the
|
||||
; value written actually doesn’t matter
|
||||
; value written actually doesn't matter
|
||||
endm
|
||||
|
||||
;
|
||||
|
|
@ -190,10 +190,10 @@
|
|||
;load latches and write pixel, with bit mask
|
||||
; preserving other latched bits. Because
|
||||
; set/reset is enabled for all planes, the
|
||||
; value written actually doesn’t matter
|
||||
; value written actually doesn't matter
|
||||
LineLoop:
|
||||
;
|
||||
; See if it’s time to advance the X coordinate yet.
|
||||
; See if it's time to advance the X coordinate yet.
|
||||
;
|
||||
and bp,bp ;see if error term is negative
|
||||
jns ETermAction ;no, advance X coordinate
|
||||
|
|
@ -225,7 +225,7 @@
|
|||
;load latches and write pixel, with bit mask
|
||||
; preserving other latched bits. Because
|
||||
; set/reset is enabled for all planes, the
|
||||
; value written actually doesn’t matter
|
||||
; value written actually doesn't matter
|
||||
;
|
||||
loop LineLoop
|
||||
Line2End:
|
||||
|
|
@ -270,9 +270,9 @@
|
|||
mov ax,[bp+Y0] ;line Y end, used later in
|
||||
;calculating the start address
|
||||
sub si,ax ;calculate DeltaY
|
||||
jns CalcStartAddress ;if positive, we’re set
|
||||
jns CalcStartAddress ;if positive, we're set
|
||||
;
|
||||
; DeltaY is negative — swap coordinates so we’re always working
|
||||
; DeltaY is negative — swap coordinates so we're always working
|
||||
; with a positive DeltaY.
|
||||
;
|
||||
mov ax,[bp+Y1] ;set line start to Y1, for use
|
||||
|
|
@ -385,7 +385,7 @@ which is well-commented, should speak for itself.
|
|||
One point I do want to make is that Listing 35.3 incorporates a clever
|
||||
notion for which credit is due Jim Mackraz, who described the notion in
|
||||
a letter written in response to an article I wrote long ago in the late
|
||||
and lamented *Programmer’s Journal*. Jim’s suggestion was that when
|
||||
and lamented *Programmer's Journal*. Jim's suggestion was that when
|
||||
drawing lines for which |**DeltaX**| is greater than |**DeltaY**|, bits
|
||||
set to 1 for each of the pixels controlled by a given byte can be
|
||||
accumulated in a register, rather than drawing each pixel individually.
|
||||
|
|
@ -393,16 +393,16 @@ All the pixels controlled by that byte can then be drawn at once, with a
|
|||
single access to display memory, when all pixel processing associated
|
||||
with that byte has been completed. This approach can save many **OUT**s
|
||||
and many display memory reads and writes when drawing nearly-horizontal
|
||||
lines, and that’s important because EGAs and VGAs hold the CPU up for a
|
||||
lines, and that's important because EGAs and VGAs hold the CPU up for a
|
||||
considerable period of time on each I/O operation and display memory
|
||||
access.
|
||||
|
||||
All too many PC programmers fall into the high-level-language trap of
|
||||
thinking that a good algorithm guarantees good performance. Not so: As
|
||||
our two implementations of Bresenham’s algorithm graphically illustrate
|
||||
our two implementations of Bresenham's algorithm graphically illustrate
|
||||
(pun not originally intended, but allowed to stand once recognized),
|
||||
truly great PC code requires both a good algorithm *and* a good assembly
|
||||
implementation. In Listing 35.3, we’ve got y-oh-my, isn’t it fun?
|
||||
implementation. In Listing 35.3, we've got y-oh-my, isn't it fun?
|
||||
|
||||
------------------------ --------------------------------- --------------------
|
||||
[Previous](35-06.html) [Table of Contents](index.html) [Next](36-01.html)
|
||||
|
|
|
|||
Loading…
Reference in a new issue