home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / C-ASM_VI.ARJ / PROGASM.ZIP / PROG084.ASM < prev    next >
Assembly Source File  |  1988-05-15  |  6KB  |  168 lines

  1.  
  2. ;************************************************************************
  3. ;                                                                       *
  4. ;  Scanline(start, end, raster, color):draw line from (start,y) to      *
  5. ;       (end,y) with a color 'color'.                                   *
  6. ;  Entry :sp + 2 = Start                                                *
  7. ;         sp + 4 = Stop                                                 *
  8. ;         sp + 6 = y                                                    *
  9. ;         sp + 8 = color                                                *
  10. ;               ....                                                    *
  11. ;                                                                       *
  12. ;************************************************************************
  13.  
  14. XSIZE   EQU     640
  15. HBYTES  EQU     (XSIZE/8)
  16. GRFSEG  EQU     0A000H
  17.  
  18. Start   EQU     [BP+4]
  19. Stop    EQU     [BP+6]
  20. Raster  EQU     [BP+8]
  21. Color   EQU     [BP+10]
  22.  
  23.         PUBLIC  _ScanLine
  24.  
  25. _ScanLine       PROC NEAR
  26.         PUSH    BP
  27.         MOV     BP,SP
  28.  
  29.         PUSH    DI                      ;Preserve segment registers
  30.         PUSH    SI
  31.         PUSH    DS
  32.         PUSH    ES
  33.  
  34.        ;--- Load SET/RESET registers with current color
  35.  
  36.         MOV     DX,03CEh                ; move color into reset register
  37.         XOR     AL,AL
  38.         OUT     DX,AL
  39.         INC     DX
  40.         MOV     AL,Color
  41.         OUT     DX,AL
  42.         DEC     DX                      ; enable use of reset register
  43.         MOV     AL,1
  44.         OUT     DX,AL
  45.         INC     DX
  46.         MOV     AL,0Fh
  47.         OUT     DX,AL
  48.         MOV     DX,03C4h                ; enable all four planes for writing
  49.         MOV     AL,2
  50.         OUT     DX,AL
  51.         INC     DX
  52.         MOV     AL,0Fh
  53.         OUT     DX,al
  54.  
  55.         ;--- COMPUTE ADDRESS AND MASK FOR FIRST PIXEL -------------
  56. SL_Address:
  57.         ;--- Convert (x,y) to absolute address in display buffer
  58.  
  59.         MOV     AX,Raster               ;Compute offset as 80*y+x/8
  60.         MOV     BX,HBYTES
  61.         MUL     BX
  62.         MOV     DI,Start                ; + x/8
  63.         MOV     CL,3
  64.         SHR     DI,CL
  65.         ADD     DI,AX
  66.  
  67.         MOV     DX,GRFSEG               ;Point DS and ES into display buffer
  68.         MOV     DS,DX
  69.         MOV     ES,DX
  70.  
  71.         MOV     CX,Stop                 ;Compute dx
  72.         SUB     CX,Start
  73.  
  74.         ;--- Compute bit mask for the leading partial byte
  75.  
  76.         MOV     AX,Start                ;Fetch x0
  77.         AND     AX,07H                  ;Check if there is leading partial byte
  78.         JZ      SL_Complete             ;...No, bypass this step
  79.         MOV     BX,0FFH                 ;Compute mask for the first byte by
  80.         PUSH    CX                      ;shifting FF pattern to the right
  81.         MOV     CX,AX                   ;until only partial leading bits are
  82.         SHR     BX,CL                   ;on
  83.         POP     CX
  84.         ADD     CX,AX                   ;Update counter of bits completed
  85.         SUB     CX,8
  86.         JGE     SL_SetMask              ;Modify mask if only one byte
  87.         NEG     CX
  88.         SHR     BX,CL
  89.         SHL     BX,CL
  90.         XOR     CX,CX                   ; restore counter
  91. SL_SetMask:
  92.         MOV     DX,3CEH                 ;Set mask by loading BIT MASK
  93.         MOV     AL,08h                  ;register in the GRAPHICS controller
  94.         OUT     DX,AL
  95.         INC     DX
  96.         MOV     AL,BL
  97.         OUT     DX,AL
  98.  
  99.         ;--- Draw pixels from the leading partial byte
  100.  
  101.         MOV     AL,[DI]                 ;Latch data
  102.         STOSB                           ;Write new data
  103.  
  104.         ;--- Draw pixels from the middle complete bytes
  105.  
  106. SL_Complete:                            ; check if any bytes to set
  107.         MOV     BX,CX                   ;Check if there is more than 7 bits
  108.         CMP     CX,8                    ;left to draw
  109.         JL      SL_Trailing             ;... If not, skip this part
  110.  
  111.         SHR     CX,1                    ;Divide bits by 8 to get byte count
  112.         SHR     CX,1
  113.         SHR     CX,1
  114.         MOV     DX,03CEH                ; Enable all 8 bits for write
  115.         MOV     AL,08h                  ; by writing to BIT MASK register in
  116.         OUT     DX,AL                   ; the SEQUENCER
  117.         INC     DX
  118.         MOV     AL,0FFH
  119.         OUT     DX,AL
  120.  
  121.         REP     STOSB                   ;Write new data
  122.  
  123.         ;--- Compute mask for the trailing partial byte
  124.  
  125. SL_Trailing:
  126.         AND     BX,07H                  ;Check if there are any bits left to do
  127.         JZ      SL_Done                 ;...No, quit
  128.         MOV     AX,0FFFFH               ;...Yes, compute mask by shifting FFFF
  129.         MOV     CX,BX                   ;by number of bits to be drawn
  130.         SHR     AX,CL
  131.         XOR     AH,0FFH
  132.         MOV     DX,03CEH                ;Set BIT MASK register in GRAPHICS
  133.         MOV     AL,08h                  ;controller to the mask
  134.         OUT     DX,AL
  135.         INC     DX
  136.         MOV     AL,AH
  137.         OUT     DX,AL
  138.  
  139.         ;--- Draw pixels from the trailing partial byte
  140.  
  141.         MOV     AL,[DI]                 ;Latch data
  142.         STOSB                           ;Write new data
  143.  
  144.         ;--- Restore PLANE ENABLE and BIT MASK registers
  145. SL_Done:
  146.         MOV     DX,03CEh                ; Enable all 8-bits in a byte for write
  147.         MOV     AL,08h                  ; by setting BIT MASK register to Fhex
  148.         OUT     DX,AL
  149.         INC     DX
  150.         MOV     AL,0FFh
  151.         OUT     DX,AL
  152.  
  153.         DEC     DX                      ; Disable SET/RESET function
  154.         MOV     AL,1
  155.         OUT     DX,AL
  156.         INC     DX
  157.         XOR     AX,AX
  158.         OUT     DX,AL
  159.  
  160.         POP     ES                      ;Restore segment registers
  161.         POP     DS
  162.         POP     SI
  163.         POP     DI
  164.         MOV     SP,BP
  165.         POP     BP
  166.         RET
  167. _ScanLine       ENDP
  168.