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:
parent
9e52de9586
commit
500e7f5654
353 changed files with 5091 additions and 5091 deletions
54
35-03.html
54
35-03.html
|
|
@ -37,15 +37,15 @@
|
|||
</CENTER>
|
||||
<P><BR></P>
|
||||
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">An Implementation in C</FONT></H3>
|
||||
<P>It’s time to get down and look at some actual working code. Listing 35.1 is a C implementation of Bresenham’s line-drawing algorithm for modes 0EH, 0FH, 10H, and 12H of the VGA, called as function <B>EVGALine</B>. Listing 35.2 is a sample program to demonstrate the use of <B>EVGALine</B>.</P>
|
||||
<P>It’s time to get down and look at some actual working code. Listing 35.1 is a C implementation of Bresenham’s line-drawing algorithm for modes 0EH, 0FH, 10H, and 12H of the VGA, called as function <B>EVGALine</B>. Listing 35.2 is a sample program to demonstrate the use of <B>EVGALine</B>.</P>
|
||||
<P><B>LISTING 35.1 L35-1.C</B></P>
|
||||
<!-- CODE //-->
|
||||
<PRE>
|
||||
/*
|
||||
* C implementation of Bresenham’s line drawing algorithm
|
||||
* for the EGA and VGA. Works in modes 0×E, 0×F, 0×10, and 0×12.
|
||||
* C implementation of Bresenham’s line drawing algorithm
|
||||
* for the EGA and VGA. Works in modes 0xE, 0xF, 0x10, and 0x12.
|
||||
*
|
||||
* Compiled with Borland C++
|
||||
* Compiled with Borland C++
|
||||
*
|
||||
* By Michael Abrash
|
||||
*/
|
||||
|
|
@ -55,12 +55,12 @@
|
|||
#define EVGA_SCREEN_WIDTH_IN_BYTES 80
|
||||
/* memory offset from start of
|
||||
one row to start of next */
|
||||
#define EVGA_SCREEN_SEGMENT 0×A000
|
||||
#define EVGA_SCREEN_SEGMENT 0xA000
|
||||
/* display memory segment */
|
||||
#define GC_INDEX 0×3CE
|
||||
#define GC_INDEX 0x3CE
|
||||
/* Graphics Controller
|
||||
Index register port */
|
||||
#define GC_DATA 0×3CF
|
||||
#define GC_DATA 0x3CF
|
||||
/* Graphics Controller
|
||||
Data register port */
|
||||
#define SET_RESET_INDEX 0 /* indexes of needed */
|
||||
|
|
@ -82,23 +82,23 @@ unsigned int Y0; /* (0,0) at the upper left of the screen */
|
|||
/* Calculate the offset in the screen segment of the byte in
|
||||
which the pixel lies */
|
||||
PixelBytePtr = MK_FP(EVGA_SCREEN_SEGMENT,
|
||||
( Y0 * EVGA_SCREEN_WIDTH_IN_BYTES ) + ( X0 / 8 ));
|
||||
( Y0 * EVGA_SCREEN_WIDTH_IN_BYTES ) + ( X0 / 8 ));
|
||||
|
||||
/* Generate a mask with a 1 bit in the pixel’s position within the
|
||||
/* Generate a mask with a 1 bit in the pixel’s position within the
|
||||
screen byte */
|
||||
PixelMask = 0×80 >> ( X0 & 0×07 );
|
||||
PixelMask = 0x80 >> ( X0 & 0x07 );
|
||||
|
||||
/* Set up the Graphics Controller’s Bit Mask register to allow
|
||||
/* Set up the Graphics Controller’s Bit Mask register to allow
|
||||
only the bit corresponding to the pixel being drawn to
|
||||
be modified */
|
||||
outportb(GC_INDEX, BIT_MASK_INDEX);
|
||||
outportb(GC_DATA, PixelMask);
|
||||
|
||||
/* Draw the pixel. Because of the operation of the set/reset
|
||||
feature of the EGA/VGA, the value written doesn’t matter.
|
||||
feature of the EGA/VGA, the value written doesn’t matter.
|
||||
The screen byte is ORed in order to perform a read to latch the
|
||||
display memory, then perform a write in order to modify it. */
|
||||
*PixelBytePtr |= 0×FE;
|
||||
*PixelBytePtr |= 0xFE;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -121,18 +121,18 @@ int XDirection; /* 1 if line is drawn left to right,
|
|||
|
||||
/* Draw the line */
|
||||
EVGADot(X0, Y0); /* draw the first pixel */
|
||||
while ( DeltaX— ) {
|
||||
/* See if it’s time to advance the Y coordinate */
|
||||
while ( DeltaX— ) {
|
||||
/* See if it’s time to advance the Y coordinate */
|
||||
if ( ErrorTerm >= 0 ) {
|
||||
/* Advance the Y coordinate & adjust the error term
|
||||
back down */
|
||||
Y0++;
|
||||
ErrorTerm += DeltaYx2MinusDeltaXx2;
|
||||
Y0++;
|
||||
ErrorTerm += DeltaYx2MinusDeltaXx2;
|
||||
} else {
|
||||
/* Add to the error term */
|
||||
ErrorTerm += DeltaYx2;
|
||||
ErrorTerm += DeltaYx2;
|
||||
}
|
||||
X0 += XDirection; /* advance the X coordinate */
|
||||
X0 += XDirection; /* advance the X coordinate */
|
||||
EVGADot(X0, Y0); /* draw a pixel */
|
||||
}
|
||||
}
|
||||
|
|
@ -156,18 +156,18 @@ int XDirection; /* 1 if line is drawn left to right,
|
|||
ErrorTerm = DeltaXx2 - (int) DeltaY;
|
||||
|
||||
EVGADot(X0, Y0); /* draw the first pixel */
|
||||
while ( DeltaY— ) {
|
||||
/* See if it’s time to advance the X coordinate */
|
||||
while ( DeltaY— ) {
|
||||
/* See if it’s time to advance the X coordinate */
|
||||
if ( ErrorTerm >= 0 ) {
|
||||
/* Advance the X coordinate & adjust the error term
|
||||
back down */
|
||||
X0 += XDirection;
|
||||
ErrorTerm += DeltaXx2MinusDeltaYx2;
|
||||
X0 += XDirection;
|
||||
ErrorTerm += DeltaXx2MinusDeltaYx2;
|
||||
} else {
|
||||
/* Add to the error term */
|
||||
ErrorTerm += DeltaXx2;
|
||||
ErrorTerm += DeltaXx2;
|
||||
}
|
||||
Y0++; /* advance the Y coordinate */
|
||||
Y0++; /* advance the Y coordinate */
|
||||
EVGADot(X0, Y0); /* draw a pixel */
|
||||
}
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ char Color; /* color to draw line in */
|
|||
outportb(GC_DATA, Color);
|
||||
/* Cause all planes to be forced to the Set/Reset color */
|
||||
outportb(GC_INDEX, ENABLE_SET_RESET_INDEX);
|
||||
outportb(GC_DATA, 0×F);
|
||||
outportb(GC_DATA, 0xF);
|
||||
|
||||
/* Save half the line-drawing cases by swapping Y0 with Y1
|
||||
and X0 with X1 if Y0 is greater than Y1. As a result, DeltaY
|
||||
|
|
@ -229,7 +229,7 @@ char Color; /* color to draw line in */
|
|||
outportb(GC_INDEX, ENABLE_SET_RESET_INDEX);
|
||||
outportb(GC_DATA, 0);
|
||||
outportb(GC_INDEX, BIT_MASK_INDEX);
|
||||
outportb(GC_DATA, 0×FF);
|
||||
outportb(GC_DATA, 0xFF);
|
||||
}
|
||||
</PRE>
|
||||
<!-- END CODE //-->
|
||||
|
|
|
|||
Loading…
Reference in a new issue