home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / RTGRAF.ZIP / SOURCE.ZIP / PROGXXX.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-06-30  |  2.7 KB  |  51 lines

  1. ;************************************************************************
  2. ; Compute SEGMENT:OFFSET pair from a given x,y address                  *
  3. ; of a pixel.  We know that there is HBYTES bytes in each               *
  4. ; raster and that each byte  contains eight pixels.                     *
  5. ; To find offest of pixel x,y we use the following formula              *
  6. ;                                                                       *
  7. ;       OFFSET = HBYTES * y + x/8                                       *
  8. ;                                                                       *
  9. ; To compute which bit within byte is to be changed we get              *
  10. ; (x mod 8) which is remainder when x is divided by 8.                  *
  11. ; Which is same as keeping last three bits of x.  We use                *
  12. ; position within a byte to rotate value 80H so that the                *
  13. ; single bit matches the position in a byte.                            *
  14. ; Recall that bit7 in a byte represents left most pixel.                *
  15. ; Thus MASK is computed as follows:                                     *
  16. ;                                                                       *
  17. ;       MASK = ROTATE 80H TO THE RIGHT BY (X AND 7)                     *
  18. ;                                                                       *
  19. ; Entry:        BX - X coordinate (pixel)                               *
  20. ;               AX - Y coordinate (raster)                              *
  21. ; Exit:         CL - Mask (x mod 8)                                     *
  22. ;               BX - Absolute offset in display buffer                  *
  23. ;************************************************************************
  24. GRAPH_SEG       EQU     0A000H          ;Segment of display buffer
  25.  
  26. Get_Address     PROC    NEAR
  27.  
  28.         ; Compute SEGMENT:OFFSET pair from x,y pair
  29.  
  30.     ; RPT this line limits to only 640 pixel widths
  31.         MOV     CX,HBYTES               ;Fetch bytes per raster
  32.  
  33.         MUL     CX                      ;Compute offset past y rasters
  34.         MOV     CL,BL                   ;Keep copy of x for later
  35.         SHR     BX,1                    ;Get offset within raster as x mod 8
  36.         SHR     BX,1
  37.         SHR     BX,1
  38.         ADD     BX,AX                   ;Add offsets together and keep in BX
  39.         MOV     AX,GRAPH_SEG            ;Fetch segment and copy it into ES
  40.         MOV     ES,AX
  41.  
  42.         ; Compute MASK within byte from x coordinate
  43.  
  44.         AND     CL,07H                  ;Compute which bit in a byte
  45.         MOV     AL,80H                  ;and use it to rotate mask into positio
  46.         ROR     AL,CL
  47.         MOV     CL,AL                   ;Keep mask in CL
  48.  
  49.         RET
  50. Get_Address     ENDP
  51.