home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
p
/
p640x480.zip
/
PIXEL.ASM
< prev
next >
Wrap
Assembly Source File
|
1993-03-02
|
10KB
|
214 lines
;╔═══════════════════════════════════════════════════════════════════════════╗
;║ PIXEL: Pixel plotting routine for VGA mode 12 / 640x480x16 color. ║
;║ This routine should be called from Microsoft QuickBASIC (4.5 or 7.x) ║
;║ ║
;║ It needs four parameters: 1. X co-ordinate (0-639) ║
;║ 2. Y co-ordinate (0-479) ║
;║ 3. Color (0-15) ║
;║ 4. Color mask (0-15) ║
;║ ║
;║ The first three parameters are self-explanatory, but the color mask is ║
;║ more interesting. The mask value determines what background color the ║
;║ pixel routine is allowed to plot on. If you are drawing a waveform, ║
;║ for example, you might not want the waveform data to overwrite any ║
;║ axes or grid you may have set up previously. By setting the mask to the ║
;║ background color, pixels will ONLY be plotted if the color currently at ║
;║ the specified point is the background. Any foreground data will be ║
;║ ignored. This also makes it convenient for clipping; pixels will only ║
;║ be drawn where there is the chosen background color, even if they ║
;║ are specified outside your plotting window. ║
;║ ║
;║ This code isn't particularly fast, but that's more an artifact of bit- ║
;║ plane operations than anything else. If anybody figures out how to ║
;║ make this routine more efficient, please drop us a line on the Grey ║
;║ Matter Electronic Mail and Shareware File Center @ (708) 208-0662/4716. ║
;║ It's not hard to see why you don't see many arcade-style games written ║
;║ in this video mode. ║
;║ ║
;║ James Karaganis Jr. Copyright (c) 1993 Certifed Communications Company ║
;║ Jerome Karaganis *** All Rights Reserved *** ║
;╚═══════════════════════════════════════════════════════════════════════════╝
DOSSEG ;Use Microsoft segment conventions
.MODEL MEDIUM ;and medium model to work with QuickBASIC.
PUBLIC PIXEL
;╔══════╤════════════════════════════════════════════════════════════════════╗
;║ NOTE │ The following registers are for standard VGA card control. ║
;╚══════╧════════════════════════════════════════════════════════════════════╝
VGA_SEGMENT EQU 0A000h ;Standard VGA screen buffer.
GC_INDEX EQU 3CEh ;Output port for graphics registers.
GC_SET_RESET EQU 0 ;Set/reset register.
GC_COL_COMP EQU 2 ;Color compare register.
GC_MODE EQU 5 ;Mode register.
GC_COL_DONT EQU 7 ;Color don't care register.
GC_BIT_MASK EQU 8 ;Bit mask register.
.CODE
;╔══════╤════════════════════════════════════════════════════════════════════╗
;║ NOTE │ Miscellaneous variables for pixel plot routine. ║
;╚══════╧════════════════════════════════════════════════════════════════════╝
XCOORD DW ? ;Xcoord pixel will be plotted at.
YCOORD DW ? ;Ycoord "
COLOR DW ? ;Desired color.
COLORMASK DW ? ;Background color mask.
;╔══════════════════╤════════════════════════════════════════════════════════╗
;║ QBAS: PIXEL │ Plot a pixel on screen with color mask. ║
;╚══════════════════╧════════════════════════════════════════════════════════╝
PIXEL PROC FAR
PUSH BP
MOV BP,SP
PUSH AX ;Save system registers.
PUSH BX
PUSH CX
PUSH DX
PUSH DS
PUSH ES
PUSH DI
PUSH SI
;-- Retrieve parameters from calling BASIC program --------------------------
MOV SI,[BP+12] ;X co-ordinate.
MOV AX,[SI]
MOV CS:XCOORD,AX
MOV SI,[BP+10] ;Y co-ordinate.
MOV AX,[SI]
MOV CS:YCOORD,AX
MOV SI,[BP+8] ;Plotting color.
MOV AX,[SI]
MOV CS:COLOR,AX
MOV SI,[BP+6] ;Background color mask.
MOV AX,[SI]
MOV CS:COLORMASK,AX
;-- Initialize VGA board for multiplane plotting mode -----------------------
; If you are going to plot many pixels (say, drawing a line) this chunk need
; only be executed once to initialize the pixel routine.
MOV DX,GC_INDEX ;set to draw mode 3
MOV AL,GC_MODE ;which allows us to draw without
OUT DX,AL ;disturbing the background,
INC DX ;and read mode 1 for use with
MOV AL,00001011b ;color compare.
OUT DX,AL
MOV DX,GC_INDEX ;Set color_don't_care register.
MOV AL,GC_COL_DONT
OUT DX,AL
INC DX
MOV AL,0Fh ;All bit planes checked.
OUT DX,AL
;-- Set up pixel color ------------------------------------------------------
MOV DX,GC_INDEX ;Tell VGA what color to plot in.
MOV AL,GC_SET_RESET
OUT DX,AL
INC DX
MOV AX,CS:COLOR
OUT DX,AL
;-- Set up for color compare (check background color against mask) ----------
MOV DX,GC_INDEX ;Now set up for color compare
MOV AL,GC_COL_COMP ;(look to see what color is at
OUT DX,AL ;the current pixel co-ords.)
INC DX
MOV AX,CS:COLORMASK
OUT DX,AL
;-- Calculate what byte in video memory contains the selected pixel ---------
MOV AX,CS:YCOORD ;Get address of screen byte ...
MOV BX,80 ;address = 80*y+x/8.
MUL BX
MOV CX,CS:XCOORD
SHR CX,1
SHR CX,1
SHR CX,1
ADD AX,CX
MOV SI,AX
;-- Calculate which bit in each bitplane needs to be modified ---------------
MOV CX,CS:XCOORD ;Generate pixel mask byte
AND CL,0111b ;(xcoord mod 8.)
MOV BL,010000000b
SHR BL,CL
;-- Initialize the base address of video memory -----------------------------
MOV AX,VGA_SEGMENT ;Setup screen buffer into DS.
MOV DS,AX
;-- Read back results of color comparison -----------------------------------
MOV AL,[SI] ;If background color is not what
CMP AL,CL ;was specified, then we don't want
AND AL,BL ;to plot the pixel.
JE DONTPLOT
;-- Actually plot the pixel in the specified color --------------------------
MOV DX,GC_INDEX ;Set up bit mask for plot.
MOV AL,GC_BIT_MASK
OUT DX,AL
INC DX
MOV AL,BL ;Bit mask is in BL.
OUT DX,AL ;Set up bit mask register.
MOV AL,255
MOV [SI],AL ;Put pixel on screen.
DONTPLOT:
;-- Return VGA card to normal mode ------------------------------------------
; This code just resets the video card so that QuickBASIC doesn't get
; messed up. This could be in a separate routine and only get called
; after multiple pixels have been plotted.
MOV DX,GC_INDEX ;Set read/write modes to zero.
MOV AL,GC_MODE
OUT DX,AL
INC DX
MOV AL,00000000b
OUT DX,AL
MOV DX,GC_INDEX ;Set bit mask all on.
MOV AL,GC_BIT_MASK
OUT DX,AL
INC DX
MOV AL,255
OUT DX,AL
;-- All done / restore registers and return to caller -----------------------
POP SI ;Restore system registers.
POP DI
POP ES
POP DS
POP DX
POP CX
POP BX
POP AX
POP BP
RET 8
PIXEL ENDP
END