home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / egagraph.zip / LINE.ASM < prev    next >
Assembly Source File  |  1987-07-23  |  5KB  |  182 lines

  1. ; LINE.ASM   EGA line drawing routine
  2.  
  3. ; PROCEDURE DrawLine(x1,y1,x2,y2,color : integer); External 'LINE.BIN';
  4.  
  5. ; This routine is designed to be called from Turbo Pascal.
  6. ; It has been tested on both EGA and 640x480 modes on the
  7. ; Video 7 graphics board. This routine draws at about 84,000
  8. ; pixels per second on a 10 mhz, 1 wait state, 286 machine.
  9. ; If you find a way to make it faster, let me know.
  10.  
  11. ; James Billmeyer
  12. ; Soft-Touch Computer Systems
  13. ; 7716 Balboa Blvd., Unit D
  14. ; Van Nuys, Ca. 91406
  15. ; (818) 781-4400
  16.  
  17. cseg   segment  byte              ; start of code segment
  18.        assume   cs:cseg
  19.  
  20. ; [bp-2]  = xinc
  21. ; [bp-4]  = yinc1
  22. ; [bp-6]  = yinc2
  23. ; [bp-8]  = incr1
  24. ; [bp-10] = incr2
  25.  
  26. ; AX = general use
  27. ; BL = Mask
  28. ; BH = Color
  29. ; CX = delx (or longest dela length -- main loop only)
  30. ; DX = (for port output)
  31. ; DI = Address
  32. ; SI = d
  33.  
  34. line   proc     near
  35.  
  36. ; --- Initialization ---
  37.  
  38.        int    1
  39.        push   bp
  40.        mov    bp,sp          ; get top of stack
  41.        sub    sp,10          ; allow for variable space
  42.  
  43.        mov    ax,80
  44.        mov    [bp-6],ax      ; yinc2 := 80
  45.        mov    [bp-4],ax      ; yinc1 := 80
  46.        mov    ax,1
  47.        mov    [bp-2],ax      ; xinc  := 1
  48.        mov    ax,[bp+8]      ; delx := x2 - x1
  49.        sub    ax,[bp+12]
  50.        cmp    ax,0           ; if delx < 0 then
  51.        jge    cdely
  52.        neg    ax             ;   delx := abs(delx)
  53.        mov    bx,[bp+8]      ;   x1   := x2
  54.        mov    [bp+12],bx
  55.        mov    bx,[bp+6]      ;   swap(y2,y1)
  56.        xchg   bx,[bp+10]
  57.        mov    [bp+6],bx      ; endif
  58.  
  59. cdely:
  60.        mov    bx,[bp+6]      ; dely := y2 - y1
  61.        sub    bx,[bp+10]
  62.        cmp    bx,0
  63.        jge    cmpdxdy        ; else if dely < 0 then
  64.        neg    bx             ;   dely  := abs(dely)
  65.        mov    dx,-80         ;   yinc2 := -80
  66.        mov    [bp-6],dx
  67.        mov    [bp-4],dx      ; endif
  68.  
  69. cmpdxdy:
  70.        cmp    ax,bx          ; if delx < dely then
  71.        jge    setyinc1
  72.        mov    dx,0           ;   xinc := 0
  73.        mov    [bp-2],dx
  74.        xchg   ax,bx          ;   swap(delx,dely);
  75.        jmp    calcaddr       ; else
  76. setyinc1:
  77.        mov    dx,0           ;   yinc1 := 0
  78.        mov    [bp-4],dx
  79.                              ; endif
  80. calcaddr:
  81.        push   ax
  82.        mov    cx,bx          ; incr1 := dely * 2
  83.        shl    cx,1
  84.        mov    [bp-8],cx
  85.        sub    bx,ax          ; incr2 := (dely - delx) * 2
  86.        shl    bx,1
  87.        mov    [bp-10],bx
  88.        mov    si,bx
  89.        mov    ax,[bp+10]     ; address := (y * 80) + (x / 8)
  90.        mov    dx,80
  91.        mul    dx
  92.        mov    cx,3
  93.        mov    di,[bp+12]
  94.        shr    di,cl
  95.        add    di,ax
  96.        mov    cx,[bp+12]     ; mask := 1 shl (7 - x mod 8)
  97.        and    cl,7
  98.        xor    cl,7
  99.        mov    ch,1
  100.        shl    ch,cl
  101.        mov    bl,ch
  102.  
  103. ; ---- Initialize EGA Card ----
  104. ; Select Write Mode 2
  105.  
  106.        mov    dx,3CEh        ; select mode register
  107.        mov    ax,5
  108.        out    dx,al
  109.        mov    dx,3CFh        ; set to write mode 2
  110.        mov    ax,2
  111.        out    dx,al
  112.  
  113. ; Set Bit Mask Register
  114.  
  115.        mov    dx,3CEh        ; select register 8
  116.        mov    ax,8
  117.        out    dx,al
  118.        mov    dx,0A000h      ;    es := EGA buffer segment address
  119.        mov    es,dx
  120.        mov    bh,[bp+4]      ;    get color
  121.        mov    dx,3CFh
  122.  
  123.        pop    cx             ; for i := 1 to dx do
  124.        inc    cx
  125. llp1:
  126.  
  127. ; ---- Plot Point -------------+
  128.                              ; |
  129.        mov    al,bl          ; | output bit mask to register 8
  130.        out    dx,al          ; |
  131.                              ; |
  132. ; Latch all four bit planes  ; |
  133.                              ; |
  134.        mov    al,es:[di]     ; | latches all four bit planes
  135.                              ; |
  136. ; Write Pixel                ; |
  137.                              ; |
  138.        mov    es:[di],bh     ; | set color
  139.                              ; |
  140. ; --- end of plot point -------+
  141.  
  142.        cmp    si,0           ;   if d < 0 then
  143.        jge    llp2
  144.        mov    ax,cx
  145.        mov    cx,[bp-2]      ;     x := x + xinc1
  146.        ror    bl,cl
  147.        mov    cx,ax
  148.        adc    di,+00
  149.        add    di,[bp-4]      ;     y := y + yinc1
  150.        add    si,[bp-8]      ;     d := d + incr1
  151.        loop   llp1
  152.        jmp    lend
  153. llp2:                        ;   else
  154.        ror    bl,1           ;     x := x + xinc2
  155.        adc    di,+00
  156.        add    di,[bp-6]      ;     y := y + yinc2
  157.        add    si,[bp-10]     ;     d := d + incr2
  158.        loop   llp1           ;   endif
  159.                              ; endfor
  160. lend:
  161.  
  162. ; Restore defualt EGA graphics status
  163.  
  164.        mov    dx,3CEh
  165.        mov    ax,5
  166.        out    dx,al
  167.        mov    dx,3CFh
  168.        mov    ax,0
  169.        out    dx,al
  170.        mov    dx,3CEh
  171.        mov    ax,8
  172.        out    dx,al
  173.        mov    dx,3CFh
  174.        mov    ax,0FFh
  175.        out    dx,al
  176.        mov    sp,bp
  177.        pop    bp
  178.        ret    10
  179. line   endp
  180. cseg   ends
  181.        end
  182.