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 >
Assembly Source File  |  1993-03-02  |  10KB  |  214 lines

  1. ;╔═══════════════════════════════════════════════════════════════════════════╗
  2. ;║ PIXEL: Pixel plotting routine for VGA mode 12 / 640x480x16 color.         ║
  3. ;║ This routine should be called from Microsoft QuickBASIC (4.5 or 7.x)      ║
  4. ;║                                                                           ║
  5. ;║ It needs four parameters: 1. X co-ordinate (0-639)                        ║
  6. ;║                           2. Y co-ordinate (0-479)                        ║
  7. ;║                           3. Color         (0-15)                         ║
  8. ;║                           4. Color mask    (0-15)                         ║
  9. ;║                                                                           ║
  10. ;║ The first three parameters are self-explanatory, but the color mask is    ║
  11. ;║ more interesting.  The mask value determines what background color the    ║
  12. ;║ pixel routine is allowed to plot on.  If you are drawing a waveform,      ║
  13. ;║ for example, you might not want the waveform data to overwrite any        ║
  14. ;║ axes or grid you may have set up previously.  By setting the mask to the  ║
  15. ;║ background color, pixels will ONLY be plotted if the color currently at   ║
  16. ;║ the specified point is the background.  Any foreground data will be       ║
  17. ;║ ignored.  This also makes it convenient for clipping; pixels will only    ║
  18. ;║ be drawn where there is the chosen background color, even if they         ║
  19. ;║ are specified outside your plotting window.                               ║
  20. ;║                                                                           ║
  21. ;║ This code isn't particularly fast, but that's more an artifact of bit-    ║
  22. ;║ plane operations than anything else.  If anybody figures out how to       ║
  23. ;║ make this routine more efficient, please drop us a line on the Grey       ║
  24. ;║ Matter Electronic Mail and Shareware File Center @ (708) 208-0662/4716.   ║
  25. ;║ It's not hard to see why you don't see many arcade-style games written    ║
  26. ;║ in this video mode.                                                       ║
  27. ;║                                                                           ║
  28. ;║ James Karaganis Jr.    Copyright (c) 1993 Certifed Communications Company ║
  29. ;║ Jerome Karaganis                              *** All Rights Reserved *** ║
  30. ;╚═══════════════════════════════════════════════════════════════════════════╝
  31.  
  32.                 DOSSEG          ;Use Microsoft segment conventions
  33.                 .MODEL  MEDIUM  ;and medium model to work with QuickBASIC.
  34.  
  35.                 PUBLIC  PIXEL
  36.  
  37. ;╔══════╤════════════════════════════════════════════════════════════════════╗
  38. ;║ NOTE │ The following registers are for standard VGA card control.         ║
  39. ;╚══════╧════════════════════════════════════════════════════════════════════╝
  40.  
  41. VGA_SEGMENT     EQU     0A000h  ;Standard VGA screen buffer.
  42.  
  43. GC_INDEX        EQU     3CEh    ;Output port for graphics registers.
  44. GC_SET_RESET    EQU     0       ;Set/reset register.
  45. GC_COL_COMP     EQU     2       ;Color compare register.
  46. GC_MODE         EQU     5       ;Mode register.
  47. GC_COL_DONT     EQU     7       ;Color don't care register.
  48. GC_BIT_MASK     EQU     8       ;Bit mask register.
  49.  
  50.                 .CODE
  51.  
  52. ;╔══════╤════════════════════════════════════════════════════════════════════╗
  53. ;║ NOTE │ Miscellaneous variables for pixel plot routine.                    ║
  54. ;╚══════╧════════════════════════════════════════════════════════════════════╝
  55.  
  56. XCOORD          DW      ?       ;Xcoord pixel will be plotted at.
  57. YCOORD          DW      ?       ;Ycoord  "
  58. COLOR           DW      ?       ;Desired color.
  59. COLORMASK       DW      ?       ;Background color mask.
  60.  
  61. ;╔══════════════════╤════════════════════════════════════════════════════════╗
  62. ;║ QBAS: PIXEL      │ Plot a pixel on screen with color mask.                ║
  63. ;╚══════════════════╧════════════════════════════════════════════════════════╝
  64.  
  65. PIXEL           PROC      FAR
  66.  
  67.                 PUSH      BP
  68.                 MOV       BP,SP
  69.                 PUSH      AX             ;Save system registers.
  70.                 PUSH      BX
  71.                 PUSH      CX
  72.                 PUSH      DX
  73.                 PUSH      DS
  74.                 PUSH      ES
  75.                 PUSH      DI
  76.                 PUSH      SI
  77.  
  78. ;-- Retrieve parameters from calling BASIC program --------------------------
  79.  
  80.                 MOV     SI,[BP+12]      ;X co-ordinate.
  81.                 MOV     AX,[SI]
  82.                 MOV     CS:XCOORD,AX
  83.  
  84.                 MOV     SI,[BP+10]      ;Y co-ordinate.
  85.                 MOV     AX,[SI]
  86.                 MOV     CS:YCOORD,AX
  87.  
  88.                 MOV     SI,[BP+8]       ;Plotting color.
  89.                 MOV     AX,[SI]
  90.                 MOV     CS:COLOR,AX
  91.  
  92.                 MOV     SI,[BP+6]       ;Background color mask.
  93.                 MOV     AX,[SI]
  94.                 MOV     CS:COLORMASK,AX
  95.  
  96. ;-- Initialize VGA board for multiplane plotting mode -----------------------
  97.  
  98. ; If you are going to plot many pixels (say, drawing a line) this chunk need
  99. ; only be executed once to initialize the pixel routine.
  100.  
  101.                 MOV     DX,GC_INDEX     ;set to draw mode 3
  102.                 MOV     AL,GC_MODE      ;which allows us to draw without
  103.                 OUT     DX,AL           ;disturbing the background,
  104.                 INC     DX              ;and read mode 1 for use with
  105.                 MOV     AL,00001011b    ;color compare.
  106.                 OUT     DX,AL
  107.  
  108.                 MOV     DX,GC_INDEX     ;Set color_don't_care register.
  109.                 MOV     AL,GC_COL_DONT
  110.                 OUT     DX,AL
  111.                 INC     DX
  112.                 MOV     AL,0Fh          ;All bit planes checked.
  113.                 OUT     DX,AL
  114.  
  115. ;-- Set up pixel color ------------------------------------------------------
  116.                       
  117.                 MOV     DX,GC_INDEX     ;Tell VGA what color to plot in.
  118.                 MOV     AL,GC_SET_RESET
  119.                 OUT     DX,AL
  120.                 INC     DX
  121.                 MOV     AX,CS:COLOR
  122.                 OUT     DX,AL
  123.  
  124. ;-- Set up for color compare (check background color against mask) ----------
  125.                                                                    
  126.                 MOV     DX,GC_INDEX     ;Now set up for color compare
  127.                 MOV     AL,GC_COL_COMP  ;(look to see what color is at
  128.                 OUT     DX,AL           ;the current pixel co-ords.)
  129.                 INC     DX
  130.                 MOV     AX,CS:COLORMASK
  131.                 OUT     DX,AL
  132.   
  133. ;-- Calculate what byte in video memory contains the selected pixel ---------
  134.  
  135.                 MOV     AX,CS:YCOORD    ;Get address of screen byte ...
  136.                 MOV     BX,80           ;address = 80*y+x/8.
  137.                 MUL     BX
  138.                 MOV     CX,CS:XCOORD
  139.                 SHR     CX,1
  140.                 SHR     CX,1
  141.                 SHR     CX,1
  142.                 ADD     AX,CX
  143.                 MOV     SI,AX
  144.  
  145. ;-- Calculate which bit in each bitplane needs to be modified ---------------
  146.  
  147.                 MOV     CX,CS:XCOORD    ;Generate pixel mask byte
  148.                 AND     CL,0111b        ;(xcoord mod 8.)
  149.                 MOV     BL,010000000b
  150.                 SHR     BL,CL
  151.  
  152. ;-- Initialize the base address of video memory -----------------------------
  153.  
  154.                 MOV     AX,VGA_SEGMENT  ;Setup screen buffer into DS.
  155.                 MOV     DS,AX
  156.  
  157. ;-- Read back results of color comparison -----------------------------------
  158.  
  159.                 MOV     AL,[SI]         ;If background color is not what
  160.                 CMP     AL,CL           ;was specified, then we don't want
  161.                 AND     AL,BL           ;to plot the pixel.                
  162.                 JE      DONTPLOT      
  163.  
  164. ;-- Actually plot the pixel in the specified color --------------------------
  165.  
  166.                 MOV     DX,GC_INDEX     ;Set up bit mask for plot.
  167.                 MOV     AL,GC_BIT_MASK
  168.                 OUT     DX,AL
  169.                 INC     DX
  170.                 MOV     AL,BL           ;Bit mask is in BL.
  171.                 OUT     DX,AL           ;Set up bit mask register.
  172.                 MOV     AL,255
  173.                 MOV     [SI],AL         ;Put pixel on screen.
  174. DONTPLOT:
  175.  
  176. ;-- Return VGA card to normal mode ------------------------------------------
  177.  
  178. ; This code just resets the video card so that QuickBASIC doesn't get
  179. ; messed up.  This could be in a separate routine and only get called
  180. ; after multiple pixels have been plotted.
  181.  
  182.                 MOV     DX,GC_INDEX     ;Set read/write modes to zero.
  183.                 MOV     AL,GC_MODE
  184.                 OUT     DX,AL
  185.                 INC     DX
  186.                 MOV     AL,00000000b
  187.                 OUT     DX,AL
  188.  
  189.                 MOV     DX,GC_INDEX     ;Set bit mask all on.
  190.                 MOV     AL,GC_BIT_MASK
  191.                 OUT     DX,AL
  192.                 INC     DX
  193.                 MOV     AL,255          
  194.                 OUT     DX,AL           
  195.  
  196. ;-- All done / restore registers and return to caller -----------------------
  197.  
  198.                 POP  SI                  ;Restore system registers.
  199.                 POP  DI
  200.                 POP  ES
  201.                 POP  DS
  202.                 POP  DX
  203.                 POP  CX
  204.                 POP  BX
  205.                 POP  AX
  206.                 POP  BP
  207.  
  208.                 RET  8
  209.  
  210. PIXEL           ENDP
  211.  
  212.                 END
  213.  
  214.