GRAPHICS.DOC -- Graphic Plotting Procedures =========================================== From `BLUEBOOK of ASSEMBLY ROUTINES for the IBM PC & XT' by Christopher L. Morgan Copyright (C) 1984 by The Waite Group, Inc. Purpose: GRAPHICS.ASM contains routines to perform fundamental plotting jobs on the IBM PC. These include point plotting, line drawing, character drawing, and filling of areas. GRAPHICS.DOC describes the routines. Contents: --------- CLS -- Clear the screen GET_COLOR -- Get the color of a point on the med res color screen GMSG_OUT -- Plot a string PAINT -- Fill an area with specified color RCHAR -- Plot a raster character SCHAR -- Plot a stroke character SET_BOX -- Fill a rectangular box with specified color SET_LIN -- Draw a line SET_PT -- Plot a point XOR_BOX -- Fill a rectangular box using XOR XOR_PT -- Plot a point using XOR _____________________________________________________________________________ Primitive Functions ------------------- CLS -- Clear the graphics screen. Function: This routine clears the color graphics screen. Input: None. Output: Just to the screen. Registers used: Unmodified; AX & CX are saved, then restored. Segments referenced: Upon entry, ES must point to screen RAM at B8000H. Routines called: None. ----------------------------------------------------------------------------- SET_PT -- Plot a point on the medium resolution color screen. Function: This routine plots a point on the medium resolution color graphics screen. The pixel at the specified location is given a specified color, over-writing the old color. Input: Upon entry: X-coordinate (0-319) of the point is in SI Y-coordinate (0-199) of the point is in DI color (0-3) is in DX. Output: Just to the screen. Registers used: Unmodified; SI,DI, & DX are used for input. Segments referenced: Upon entry, ES must point to video RAM at B8000, and DS must point to a data segment containing the following look-up table of rotated color masks: CTABLE DW 0003FH,0403FH,0803FH,0C03FH DW 000CFH,010CFH,020CFH,030CFH DW 000F3H,004F3H,008F3H,00CF3H DW 000FCH,001FCH,002FCH,003FCH Routines called: None. Note: No bounds checking is performed. Programmer must ensure the coordinates and color are in their proper ranges. ----------------------------------------------------------------------------- XOR_PT -- Plot a point using XOR onto the med res color screen. Function: This routine plots a point on the med res screen using the `exclusive or' operation. The pixel at the specified location is colored with a color obtained by `exclusive oring' its original color with a specified color. This function is useful for making cursors. Input: Upon entry: X-coordinate (0-319) of the point is in SI Y-coordinate (0-199) of the point is in DI color (0-3) is in DX. Output: Just to the screen. Registers used: Unmodified; SI,DI, & DX are used for input. Segments referenced: Upon entry, ES must point to video RAM at B8000, and DS must point to a data segment containing the following look-up table of rotated color masks: CTABLE DW 0003FH,0403FH,0803FH,0C03FH DW 000CFH,010CFH,020CFH,030CFH DW 000F3H,004F3H,008F3H,00CF3H DW 000FCH,001FCH,002FCH,003FCH Routines called: None. Note: No bounds checking is performed. Programmer must ensure the coordinates and color are in their proper ranges. ----------------------------------------------------------------------------- GET_COLOR -- Get color of a point on med res screen. Function: This routine returns the color of a specified point on the med res color screen. The color is returned in AL. Input: Upon entry: X-coordinate (0-319) of the specified point is in SI Y-coordinate (0-199) of the specified point is in DI. Output: Upon exit, AL contains the color (0-3) of the pixel at the specified location. Registers used: Only AX is modified. SI & DI are used for input and AL is used for output. Segments referenced: Upon entry, ES must point to the video RAM at B8000H. Routines called: None. Note: No bounds checking is performed. Programmer must ensure the coordinates and color are in their proper ranges. ----------------------------------------------------------------------------- SET_BOX -- Fill a rectangular box. Function: This routine fills a rectangular box on the color graphics screen with a specified color. Input: Upon entry: X-coordinate of upper left corner is in X1 Y-coordinate of upper left corner is in Y1 X-coordinate of lower right corner is in X2 Y-coordinate of lower right corner is in Y2 Color of the rectangle is in bits 0 & 1 of COLOR. Output: Just to the screen. Registers used: Unmodified; SI, DI, DX, BX, CX, & AX are save & restored. Segments referenced: Upon entry, ES must point to video RAM at B8000, and DS must point to a data segment containing the following look-up table for color masks: XTABLE DW 0FFC0H,0FFF0H,0FFFCH,0FFFFH DW 03FC0H,03FF0H,03FFCH,03FFFH DW 00FC0H,00FF0H,00FFCH,00FFFH DW 003C0H,003F0H,003FCH,003FFH Routines called: None. Note: No bounds checking is performed. Programmer must ensure the coordinates are in their proper range and order; i.e., the following must be true: 0 <= X1 <= X2 <= 319 0 <= Y1 <= Y2 <= 199. ----------------------------------------------------------------------------- XOR_BOX -- Fill a rectangular box using XOR. Function: This routine fills a rectangular box in the color graphics screen with a given color using the `exclusive or' operation. Each pixel in the rectangle is colored with a color obtained by `exclusive oring' its original color with a specified color. This function is useful for making cursors. Input: Upon entry: X-coordinate of upper left corner is in X1 Y-coordinate of upper left corner is in Y1 X-coordinate of lower right corner is in X2 Y-coordinate of lower right corner is in Y2 Color of the rectangle is in bits 0 & 1 of COLOR. Output: Just to the screen. Registers used: Unmodified; SI, DI, DX, BX, CX, & AX are saved & restored. Segments referenced: Upon entry, ES must point to video RAM at B8000, and DS must point to a data segment containing the following look-up table for color masks: XTABLE DW 0FFC0H,0FFF0H,0FFFCH,0FFFFH DW 03FC0H,03FF0H,03FFCH,03FFFH DW 00FC0H,00FF0H,00FFCH,00FFFH DW 003C0H,003F0H,003FCH,003FFH Routines called: None. Note: No bounds checking is performed. Programmer must ensure the coordinates are in their proper range and order; i.e., the following must be true: 0 <= X1 <= X2 <= 319 0 <= Y1 <= Y2 <= 199. ----------------------------------------------------------------------------- Second Level Functions (use Primitive Functions) ---------------------- SET_LIN -- Draw a line. Function: This routine draws a line from (X1,Y1) to (X2,Y2) in the specified color. It uses Bresenham's algorithm. Input: Upon entry: X-coordinate of starting point is in X1 Y-coordinate of starting point is in Y1 X-coordinate of ending point is in X2 Y-coordinate of ending point is in Y2 Color of line is in COLOR. Output: Just to the screen. Registers used: Unmodified; BX, CX, DX, SI, DI, & AX are saved & restored. Segments referenced: Upon entry, ES must point to video RAM at B8000H, and DS must point to a data segment used by the SET_PT plotting routine. Routines called: SET_PT. Note: No bounds checking is performed. Programmer must ensure the coordinates are in their proper range; i.e., the following must be true: 0 <= X1 & X2 <= 319 0 <= Y1 & Y2 <= 199 0 <= COLOR <= 3. ----------------------------------------------------------------------------- SCHAR -- Plot a stroke character. Function: This routine plots a stroke character. It uses a stroke character table in which each character is stored as a series of strokes. The programmer must create this stroke character table according to specific rules. Each stroke is stored as three bytes. The first byte contains a code as follows: 1AH = end of strokes `U' = pen Up, move to new current position, but don't draw `D' = pen Down, draw a stroke from old to new current position. The second byte contains the local X-coordinate of the new current position, and the third byte contains the local Y-coordinate of the new current position. These local coordinates are relative to the upper left corner of the character cell. At the beginning of the stroke table is an address table for the locations of the strokes for each of the characters. Input: Upon entry: ASCII code character is in AL X-coord of upper left corner of char cell is in X0 Y-coord of upper left corner of char cell is in Y0 Horizontal magnitude is in XMAGN Vertical magnitude is in YMAGN Color of character is in COLOR. Output: Just to the screen. Registers used: Unmodified; SI, CX, & AX are saved & restored. Segments referenced: Upon entry, ES must point to video RAM at B8000H, and DS must point to the data segment used by the point and line-drawing routines. This data segment must also contain the table of stroke chars. Routines called: SET_LIN. Note: No bounds checking is performed. Unpredictable results happen if the horizontal or vertical magnitude is too large. A string of raster characters can be printed using the GMSG_OUT routine. ----------------------------------------------------------------------------- RCHAR -- Plot a raster character. Function: This routine plots a raster character. It uses the raster character table in the IBM BIOS ROM. Only ASCII codes 0 through 127 are supported. Input: Upon entry: ASCII code character is in AL X-coord of upper left corner of char cell is in X0 Y-coord of upper left corner of char cell is in Y0 Horizontal magnitude is in XMAGN Vertical magnitude is in YMAGN Color of character is in COLOR. Output: Just to the screen Registers used: Unmodified; SI, DX, CX, & AX are saved & restored. Segments referenced: Upon entry, ES must point to video RAM at B8000H, and DS must point to the data segment used by the box-fill routine. Routines called: SET_BOX. Note: No bounds checking is performed. Unpredictable results happen if the horizontal or vertical magnitude is too large. A string of raster characters can be printed using the GMSG_OUT routine. ----------------------------------------------------------------------------- GMSG_OUT -- Print a string on the graphics screen. Function: This routine prints a message on the graphics screen, using the SCHAR or RCHAR routines. The message terminates in a zero. Input: Upon entry: Address of message is in SI X-coord of upper left corner of string is in XMSG Y-coord of upper left corner of string is in YMSG Horizontal magnitude of characters is in XMAGN Vertical magnitude of characters is in YMAGN Color of characters is in COLOR Choice of fonts (0=stroke,1=raster) is in FONT. Output: Just to the screen Registers used: Unmodified. Segments referenced: Upon entry, ES must point to video RAM at B8000H, and DS must point to the data segment used by the point-plotting, box-filling, line-drawing, and stroke character routines. Routines called: RCHAR & SCHAR Note: No bounds checking is performed. Unpredictable results happen if the horizontal or vertical magnitude is too large. ----------------------------------------------------------------------------- PAINT -- Fill an area on the screen with color. Function: This routine fills an area on the graphics screen with a specified color. It begins `painting' at a `seed' position, filling a region bounded by a `boundary' color. Input: Upon entry: X-coordinate of seed is in SI Y-coordinate of seed is in DI Paint color is in the low byte of COLOR Boundary color is in the high byte of COLOR. Output: Just to the screen. Registers used: Unmodified. Segments referenced: Upon entry, ES must point to video RAM at B8000H, and DS must point to the data segment used by the point-plotting & get-color routines. Routines called: SET_PT & GET_COLOR Note: The region must be completely surrounded by a boundary drawn in the boundary color. Any paint color in the region can obstruct the filling process, acting just like a boundary. This algorithm uses its own stack. If the region is too complex, this stack will overflow. There is no check for stack overflow, but one could easily be added. ----------------------------------------------------------------------------- _____________________________________________________________________________ >>>>> Physical EOF GRAPHICS.DOC <<<<<