home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / egagraph.zip / BOX.ASM next >
Assembly Source File  |  1987-07-23  |  8KB  |  280 lines

  1. ; BOX.ASM   EGA box drawing routine
  2.  
  3. ; Box(x1,y1,x2,y2 : INTEGER; Fill : BOOLEAN; Color : INTEGER);
  4.  
  5. ;  (x1,y2) is the upper left corner
  6. ;  (x2,y2) is the lower right corner
  7.  
  8. ; This routine is designed to be called from Turbo Pascal.
  9. ; It has been tested on both EGA and 640x480 modes on the
  10. ; Video 7 graphics board. If you find a way to make it faster,
  11. ; let me know.
  12.  
  13. ; James Billmeyer
  14. ; Soft-Touch Computer Systems
  15. ; 7716 Balboa Blvd., Unit D
  16. ; Van Nuys, Ca. 91406
  17. ; (818) 781-4400
  18.  
  19.  
  20. cseg   segment  byte              ; start of code segment
  21.        assume   cs:cseg
  22.  
  23. ; AX = general use
  24. ; BL = Mask
  25. ; BH = Color
  26. ; CX = delx (or longest dela length -- main loop only)
  27. ; DX = (for port output)
  28. ; DI = Address1
  29. ; SI = Address2
  30.  
  31. box    proc     near
  32.  
  33. ; --- Initialization ---
  34.        int    1
  35.        push   bp
  36.        mov    bp,sp          ; get top of stack
  37.  
  38.        mov    ax,[bp+10]     ; delx := x2 - x1
  39.        sub    ax,[bp+14]
  40.        cmp    ax,0           ; if delx < 0 then
  41.        jge    cdely
  42.        neg    ax             ;   delx := abs(delx)
  43.        mov    bx,[bp+10]     ;   swap(x1,x2)
  44.        xchg   bx,[bp+14]
  45.        mov    [bp+10],bx     ; endif
  46.  
  47. cdely:
  48.        mov    bx,[bp+8]      ; dely := y2 - y1
  49.        sub    bx,[bp+12]
  50.        cmp    bx,0
  51.        jge    initEGA        ; else if dely < 0 then
  52.        neg    bx             ;   dely  := abs(dely)
  53.        mov    dx,[bp+8]      ;   swap(y1,y2)
  54.        xchg   bx,[bp+12]
  55.        mov    [bp+8],bx      ; endif
  56.  
  57. initEGA:
  58.        push   bx
  59.        push   ax
  60.  
  61. ; ---- Initialize EGA Card ----
  62. ; Select Write Mode 2
  63.  
  64.        mov    dx,3CEh        ; select mode register
  65.        mov    ax,5
  66.        out    dx,al
  67.        mov    dx,3CFh        ; set to write mode 2
  68.        mov    ax,2
  69.        out    dx,al
  70.  
  71. ; Set Bit Mask Register
  72.  
  73.        mov    dx,3CEh        ; select register 8
  74.        mov    ax,8
  75.        out    dx,al
  76.        mov    dx,0A000h      ;    es := EGA buffer segment address
  77.        mov    es,dx
  78.  
  79.        mov    ax,[bp+6]      ; if filled then
  80.        cmp    ax,0
  81.        jg     filled         ;   HollowBox
  82.        pop    ax
  83.        pop    bx
  84.        call   boxh
  85.        jmp    lend
  86. filled:                      ; else
  87.        pop    ax
  88.        pop    bx
  89.        call   boxf           ;    FilledBox
  90.                              ; endif
  91. lend:
  92. ; Restore defualt EGA graphics status
  93.  
  94.        mov    dx,3CEh
  95.        mov    ax,5
  96.        out    dx,al
  97.        mov    dx,3CFh
  98.        mov    ax,0
  99.        out    dx,al
  100.        mov    dx,3CEh
  101.        mov    ax,8
  102.        out    dx,al
  103.        mov    dx,3CFh
  104.        mov    ax,0FFh
  105.        out    dx,al
  106.        pop    bp
  107.        ret    12
  108. box    endp
  109.  
  110. ; --- HollowBox ---
  111.  
  112. boxh   proc   near
  113.        push    bx
  114.        push    ax
  115.        mov    ax,[bp+12]     ; address1 := (y1 * 80) + (x1 / 8)
  116.        mov    dx,80
  117.        mul    dx
  118.        mov    cx,3
  119.        mov    di,[bp+14]
  120.        shr    di,cl
  121.        add    di,ax
  122.        mov    ax,[bp+8]     ; address2 := (y2 * 80) + (x1 / 8)
  123.        mov    dx,80
  124.        mul    dx
  125.        mov    cx,3
  126.        mov    si,[bp+14]
  127.        shr    si,cl
  128.        add    si,ax
  129.        mov    cx,[bp+14]     ; mask := 1 shl (7 - x mod 8)
  130.        and    cl,7
  131.        xor    cl,7
  132.        mov    ch,1
  133.        shl    ch,cl
  134.        mov    bl,ch
  135.        mov    bh,bl
  136.  
  137.        mov    dx,3CFh
  138.  
  139.        pop    cx             ; for i := 1 to dx do
  140.        inc    cx
  141. hllp1:
  142.  
  143. ; ---- Plot Point -------------+
  144.                              ; |
  145.        mov    al,bl          ; | output bit mask to register 8
  146.        out    dx,al          ; |
  147.        mov    al,es:[di]     ; | latches all four bit planes
  148.        mov    ax,[bp+4]      ; |
  149.        mov    es:[di],al     ; | set color
  150.        mov    ah,es:[si]     ; | latches all four bit planes
  151.        mov    es:[si],al     ; | set color
  152.                              ; |
  153. ; --- end of plot point -------+
  154.  
  155.        ror    bl,1           ;   x := x + 1
  156.        adc    di,+00
  157.        ror    bh,1
  158.        adc    si,+00
  159.        loop   hllp1          ; endfor
  160.  
  161. ; --- Calculate addresses for x constant lines ---
  162.  
  163.        mov    ax,[bp+12]     ; address1 := (y1 * 80) + (x1 / 8)
  164.        mov    dx,80
  165.        mul    dx
  166.        mov    cx,3
  167.        mov    di,[bp+14]
  168.        shr    di,cl
  169.        add    di,ax
  170.        mov    ax,[bp+12]     ; address2 := (y1 * 80) + (x2 / 8)
  171.        mov    dx,80
  172.        mul    dx
  173.        mov    cx,3
  174.        mov    si,[bp+10]
  175.        shr    si,cl
  176.        add    si,ax
  177.        mov    cx,[bp+14]     ; mask := 1 shl (7 - x1 mod 8)
  178.        and    cl,7
  179.        xor    cl,7
  180.        mov    ch,1
  181.        shl    ch,cl
  182.        mov    bl,ch
  183.        mov    cx,[bp+10]     ; mask := 1 shl (7 - x2 mod 8)
  184.        and    cl,7
  185.        xor    cl,7
  186.        mov    ch,1
  187.        shl    ch,cl
  188.        mov    bh,ch
  189.  
  190.        mov    dx,3CFh
  191.  
  192.        pop    cx             ; for i := 1 to dy do
  193. hllp2:
  194. ; ---- Plot Point -------------+
  195.                              ; |
  196.        mov    al,bl          ; | output bit mask to register 8
  197.        out    dx,al          ; |
  198.        mov    al,es:[di]     ; | latches all four bit planes
  199.        mov    ax,[bp+4]      ; |
  200.        mov    es:[di],al     ; | set color
  201.        mov    al,bh          ; | output bit mask to register 8
  202.        out    dx,al          ; |
  203.        mov    al,es:[si]     ; | latches all four bit planes
  204.        mov    ax,[bp+4]      ; |
  205.        mov    es:[si],al     ; | set color
  206.                              ; |
  207. ; --- end of plot point -------+
  208.  
  209.        add    di,80          ;   y := y + 1
  210.        add    si,80
  211.        loop   hllp2          ; endfor
  212.        ret
  213. boxh   endp
  214.  
  215. ; --- Filled Box ---
  216.  
  217. boxf   proc   near
  218.        push    bx
  219.        push    ax
  220.        mov    ax,[bp+12]     ; address1 := (y1 * 80) + (x1 / 8)
  221.        mov    dx,80
  222.        mul    dx
  223.        mov    cx,3
  224.        mov    di,[bp+14]
  225.        shr    di,cl
  226.        add    di,ax
  227.        mov    cx,[bp+14]     ; mask := 1 shl (7 - x mod 8)
  228.        and    cl,7
  229.        xor    cl,7
  230.        mov    ch,1
  231.        shl    ch,cl
  232.        mov    bl,ch
  233.        mov    bh,bl          ; oldmask := mask
  234.  
  235.        mov    dx,3CFh
  236.  
  237.        pop    cx             ; for i := 1 to dx do
  238.        pop    si
  239.        inc    si
  240.        inc    cx
  241. fllp1:
  242.        ror    bl,1           ;   x := x + 1
  243.        jc     plot           ;   if NOT MaskFull then
  244.        or     bh,bl          ;     oldmask := oldmask or mask
  245.        loop   fllp1
  246.        jmp    fend
  247. plot:                        ;   else
  248.        xchg   cx,si
  249.        push   cx
  250.        mov    al,bh          ;     output bit mask to register 8
  251.        out    dx,al
  252.        mov    ax,[bp+4]      ;     set color
  253.        push   di             ;     oldaddress := address
  254. fllp3:                       ;     for i := 1 to dy do
  255.        mov    ah,es:[di]     ;       latches all four bit planes (address)
  256.        mov    es:[di],al     ;       turn pixels on (address)
  257.        add    di,80          ;       address := address + 80
  258.        loop   fllp3          ;     endfor
  259.        pop    di             ;     address := oldaddress
  260.        add    di,1           ;     address := address + 1
  261.        mov    bh,bl          ;     oldmask := mask
  262.        pop    cx
  263.        xchg   cx,si
  264.                              ;   endif
  265.        loop   fllp1          ; endfor
  266. fend:
  267.        mov    al,bh          ; output bit mask to register 8
  268.        out    dx,al          ;
  269.        mov    al,es:[di]     ; latches all four bit planes (address)
  270.        mov    ax,[bp+4]      ; set color
  271.        mov    cx,si
  272. fllp4:                       ; for i := 1 to dy do
  273.        mov    es:[di],al     ;   turn pixels on (address)
  274.        add    di,80          ;   address := address + 80
  275.        loop   fllp4          ; endfor
  276.        ret
  277. boxf   endp
  278. cseg   ends
  279.        end
  280.