home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-ASM_VI.ARJ / PROGASM.ZIP / PROG081P.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-04-18  |  7.4 KB  |  293 lines

  1.  
  2. ;************************************************************************
  3. ; Common definitions for the next five routines             *
  4. ;************************************************************************
  5.  
  6. GRAPHICS_CTL    EQU    3CEH        ;Address of Graphics controller
  7. SEQUENCE_CTL    EQU    3C4H        ;Address the Sequencer
  8.  
  9. XSIZE    EQU    640            ;Assume 640 pixels across
  10. HBYTES    EQU    (XSIZE/8)        ;Compute bytes per raster
  11. GRAPH_SEG    EQU    0A000H        ;Segment of display buffer
  12.  
  13. ;************************************************************************
  14. ; Set pixel at X,Y to color COLOR                    *
  15. ; using SET-RESET method                        *
  16. ;************************************************************************
  17.  
  18. X        EQU    [BP+10]        ;Formal parameters on stack
  19. Y        EQU    [BP+8]
  20. COLOR        EQU    [BP+6]
  21.  
  22.     PUBLIC    Pixel_Set
  23.  
  24. Pixel_Set    PROC    FAR
  25.     PUSH    BP
  26.     MOV    BP,SP
  27.     PUSH    ES
  28.  
  29.     ; Convert x,y address into OFFSET:SEGMENT and get MASK
  30.  
  31.     MOV    BX,X            ;Fetch X coordinate
  32.     MOV    AX,Y            ;Fetch Y coordinate
  33.     CALL    Get_Address        ;Compute SEGMENT:OFFSET address
  34.                     ;in ES:BX, Mask in CL
  35.  
  36.     MOV    DX,GRAPHICS_CTL
  37.  
  38.     ; Enable set/reset and load value into reset register
  39.  
  40.     MOV    AL,00H            ;Select SET/RESET register
  41.     OUT    DX,AL
  42.     INC    DX
  43.     MOV    AL,COLOR        ;Fetch color passed on the stack
  44.     OUT    DX,AL            ;Set SET register to color
  45.     DEC    DX
  46.     MOV    AL,01H            ;Select ENABLE RESET
  47.     OUT    DX,AL
  48.     INC    DX
  49.     MOV    AL,0FH            ;Enable all four planes for SET
  50.     OUT    DX,AL
  51.     DEC    DX
  52.  
  53.     ; Set mask register to preserve unused 7 bits in a byte
  54.  
  55.     MOV    AL,08H            ;Select BIT MASK register
  56.     OUT    DX,AL
  57.     MOV    AL,CL            ;Fetch mask returned earlier
  58.     INC    DX            ;and set MASK register to it
  59.     OUT    DX,AL
  60.     DEC    DX
  61.  
  62.     ; Set the pixel to new color
  63.  
  64.     MOV    AL,ES:[BX]        ;Must latch to preserve old bits
  65.     MOV    ES:[BX],AL        ;Set pixel color to new value
  66.  
  67.     ; Restore SET/RESET and MASK registers
  68.  
  69.     MOV    AL,01H            ;Select ENABLE RESET
  70.     OUT    DX,AL
  71.     INC    DX
  72.     MOV    AL,00H            ;Disable all four planes for SET
  73.     OUT    DX,AL
  74.     DEC    DX
  75.  
  76.     MOV    AL,08H            ;Select BIT MASK register
  77.     OUT    DX,AL
  78.     MOV    AL,0FFH         ;Enable all 8 bits for write
  79.     INC    DX            ;(default)
  80.     OUT    DX,AL
  81.     DEC    DX
  82.  
  83.     ; Restore segment registers and return
  84.  
  85.     POP    ES
  86.     MOV    SP,BP
  87.     POP    BP
  88.     RET    6
  89. Pixel_Set    ENDP
  90.  
  91. ;************************************************************************
  92. ; Set pixel at X,Y to color COLOR                    *
  93. ; using the PACKED PIXEL WRITE method                    *
  94. ;************************************************************************
  95.  
  96. X        EQU    [BP+10]        ;Formal parameters on stack
  97. Y        EQU    [BP+8]
  98. COLOR        EQU    [BP+6]
  99.  
  100.     PUBLIC    Pixel_Packed_Write
  101.  
  102. Pixel_Packed_Write PROC    FAR
  103.     PUSH    BP
  104.     MOV    BP,SP
  105.     PUSH    ES
  106.  
  107.     ; Convert x,y address into OFFSET:SEGMENT and get MASK
  108.  
  109.     MOV    BX,X            ;Fetch X coordinate
  110.     MOV    AX,Y            ;Fetch Y coordinate
  111.     CALL    Get_Address        ;Compute SEGMENT:OFFSET address
  112.                     ;in ES:BX, Mask in CL
  113.  
  114.     MOV    DX,GRAPHICS_CTL
  115.  
  116.     ; Select write mode to be 'PACKED PIXEL WRITE'
  117.  
  118.     MOV    AL,05H            ;Select MODE register
  119.     OUT    DX,AL
  120.     INC    DX
  121.     MOV    AL,02H            ;Select write mode to be PACKED WRITE
  122.     OUT    DX,AL
  123.     DEC    DX
  124.  
  125.     ; Set mask register to preserve unused 7 bits in a byte
  126.  
  127.     MOV    AL,08H            ;Select BIT MASK register
  128.     OUT    DX,AL
  129.     MOV    AL,CL            ;Fetch mask returned earlier
  130.     INC    DX            ;and set MASK register to it
  131.     OUT    DX,AL
  132.     DEC    DX
  133.  
  134.     ; Set the pixel to new color
  135.  
  136.     MOV    AL,COLOR        ;Fetch color passed on the stack
  137.     MOV    AH,ES:[BX]        ;Must read to preserve old bits
  138.     MOV    ES:[BX],AL        ;Set pixel color to new value
  139.  
  140.     ; Restore MODE and MASK registers
  141.  
  142.     MOV    AL,05H            ;Select MODE register
  143.     OUT    DX,AL
  144.     INC    DX
  145.     MOV    AL,00H            ;Select default write mode
  146.     OUT    DX,AL
  147.     DEC    DX
  148.  
  149.     MOV    AL,08H            ;Select BIT MASK register
  150.     OUT    DX,AL
  151.     MOV    AL,0FFH         ;Enable all 8 bits for write
  152.     INC    DX            ;(default)
  153.     OUT    DX,AL
  154.     DEC    DX
  155.  
  156.     ; Restore segment registers and return
  157.  
  158.     POP    ES
  159.     MOV    SP,BP
  160.     POP    BP
  161.     RET    6
  162. Pixel_Packed_Write ENDP
  163.  
  164.  
  165. ;************************************************************************
  166. ; Set pixel at X,Y to color COLOR                    *
  167. ; using the PLANAR PIXEL WRITE method                    *
  168. ;************************************************************************
  169.  
  170. X        EQU    [BP+10]        ;Formal parameters on stack
  171. Y        EQU    [BP+8]
  172. COLOR        EQU    [BP+6]
  173.  
  174.     PUBLIC    Pixel_Write
  175.  
  176. Pixel_Write    PROC    FAR
  177.     PUSH    BP
  178.     MOV    BP,SP
  179.     PUSH    ES
  180.  
  181.     ; Convert x,y address into OFFSET:SEGMENT and get MASK
  182.  
  183.     MOV    BX,X            ;Fetch X coordinate
  184.     MOV    AX,Y            ;Fetch Y coordinate
  185.     CALL    Get_Address        ;Compute SEGMENT:OFFSET address
  186.                     ;in ES:BX, Mask in CL
  187.  
  188.     ; Set mask register to preserve unused 7 bits in a byte
  189.  
  190.     MOV    DX,GRAPHICS_CTL
  191.     MOV    AL,08H            ;Select BIT MASK register
  192.     OUT    DX,AL
  193.     MOV    AL,CL            ;Fetch mask returned earlier
  194.     INC    DX            ;and set MASK register to it
  195.     OUT    DX,AL
  196.     DEC    DX
  197.  
  198.     ; Set MAP MASK register to enable all planes and set pixel to 0
  199.     ; then set MAP MASK to enable planes coresponding to color
  200.  
  201.     MOV    DX,SEQUENCE_CTL
  202.     MOV    AL,02            ;Select MAP MASK (PLANE SELECT) registe
  203.     OUT    DX,AL
  204.     INC    DX
  205.     MOV    AL,0FH            ;Enable all four planes for write
  206.     OUT    DX,AL
  207.  
  208.     MOV    AH,ES:[BX]        ;Latch (read) data to preserve unused b
  209.     XOR    AL,AL            ;Make sure that proper bit is CLEAR
  210.     MOV    ES:[BX],AL        ;Clear all four planes
  211.  
  212.     MOV    AL,COLOR        ;Fetch color passed on the stack
  213.     AND    AL,0FH            ;Clear unused bits (use only first four
  214.     OUT    DX,AL            ;Enable planes as specified in color
  215.     DEC    DX            ;(note that MAP MASK reg is still selec
  216.  
  217.     ; Set the pixel to new color
  218.  
  219.     MOV    AL,0FFH         ;Make sure that proper bit is ON
  220.     MOV    ES:[BX],AL        ;Set pixel color to new value
  221.  
  222.     ; Restore MASK registers
  223.  
  224.     MOV    DX,GRAPHICS_CTL
  225.     MOV    AL,08H            ;Select BIT MASK register
  226.     OUT    DX,AL
  227.     MOV    AL,0FFH         ;Enable all 8 bits for write
  228.     INC    DX            ;(default)
  229.     OUT    DX,AL
  230.  
  231.     MOV    DX,SEQUENCE_CTL
  232.     MOV    AL,02            ;Select MAP MASK (PLANE SELECT) registe
  233.     OUT    DX,AL
  234.     INC    DX
  235.     MOV    AL,0FH            ;Enable all four planes for write
  236.     OUT    DX,AL
  237.  
  238.     ; Restore segment registers and return
  239.  
  240.     POP    ES
  241.     MOV    SP,BP
  242.     POP    BP
  243.     RET    6
  244. Pixel_Write    ENDP
  245.  
  246. ;************************************************************************
  247. ; Compute SEGMENT:OFFSET pair from a given x,y address            *
  248. ; of a pixel.  We know that there is HBYTES bytes in each        *
  249. ; raster and that each pixel contains eight pixels.            *
  250. ; To find offest of pixel x,y we use the following formula        *
  251. ;                                    *
  252. ;    OFFSET = HBYTES * y + x/8                    *
  253. ;                                    *
  254. ; To compute which bit within byte is to be changed we get        *
  255. ; (x mod 8) which is remainder when x is divided by 8.            *
  256. ; Which is same as keeping last three bits of x.  We use        *
  257. ; position within a byte to rotate value 80H so that the        *
  258. ; single bit matches the position in a byte.                *
  259. ; Recall that bit7 in a byte represents left most pixel.        *
  260. ; Thus MASK is computed as follows:                    *
  261. ;                                    *
  262. ;    MASK = ROTATE 80H TO THE RIGHT BY (X AND 7)            *
  263. ;                                    *
  264. ; Entry:    BX - X coordinate (pixel)                *
  265. ;        AX - Y coordinate (raster)                *
  266. ; Exit:     CL - Mask (x mod 8)                    *
  267. ;        BX - Absolute offset in display buffer            *
  268. ;************************************************************************
  269.  
  270. Get_Address    PROC    NEAR
  271.  
  272.     ; Compute SEGMENT:OFFSET pair from x,y pair
  273.  
  274.     MOV    CX,HBYTES        ;Fetch bytes per raster
  275.     MUL    CX            ;Compute offset past y rasters
  276.     MOV    CL,BL            ;Keep copy of x for later
  277.     SHR    BX,1            ;Get offset within raster as x mod 8
  278.     SHR    BX,1
  279.     SHR    BX,1
  280.     ADD    BX,AX            ;Add offsets together and keep in BX
  281.     MOV    AX,GRAPH_SEG        ;Fetch segment and copy it into ES
  282.     MOV    ES,AX
  283.  
  284.     ; Compute MASK within byte from x coordinate
  285.  
  286.     AND    CL,07H            ;Compute which bit in a byte
  287.     MOV    AL,80H            ;and use it to rotate mask into positio
  288.     ROR    AL,CL
  289.     MOV    CL,AL            ;Keep mask in CL
  290.  
  291.     RET
  292. Get_Address    ENDP
  293.