home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
games
/
egagraph.zip
/
LINE.ASM
< prev
next >
Wrap
Assembly Source File
|
1987-07-23
|
5KB
|
182 lines
; LINE.ASM EGA line drawing routine
; PROCEDURE DrawLine(x1,y1,x2,y2,color : integer); External 'LINE.BIN';
; This routine is designed to be called from Turbo Pascal.
; It has been tested on both EGA and 640x480 modes on the
; Video 7 graphics board. This routine draws at about 84,000
; pixels per second on a 10 mhz, 1 wait state, 286 machine.
; If you find a way to make it faster, let me know.
; James Billmeyer
; Soft-Touch Computer Systems
; 7716 Balboa Blvd., Unit D
; Van Nuys, Ca. 91406
; (818) 781-4400
cseg segment byte ; start of code segment
assume cs:cseg
; [bp-2] = xinc
; [bp-4] = yinc1
; [bp-6] = yinc2
; [bp-8] = incr1
; [bp-10] = incr2
; AX = general use
; BL = Mask
; BH = Color
; CX = delx (or longest dela length -- main loop only)
; DX = (for port output)
; DI = Address
; SI = d
line proc near
; --- Initialization ---
int 1
push bp
mov bp,sp ; get top of stack
sub sp,10 ; allow for variable space
mov ax,80
mov [bp-6],ax ; yinc2 := 80
mov [bp-4],ax ; yinc1 := 80
mov ax,1
mov [bp-2],ax ; xinc := 1
mov ax,[bp+8] ; delx := x2 - x1
sub ax,[bp+12]
cmp ax,0 ; if delx < 0 then
jge cdely
neg ax ; delx := abs(delx)
mov bx,[bp+8] ; x1 := x2
mov [bp+12],bx
mov bx,[bp+6] ; swap(y2,y1)
xchg bx,[bp+10]
mov [bp+6],bx ; endif
cdely:
mov bx,[bp+6] ; dely := y2 - y1
sub bx,[bp+10]
cmp bx,0
jge cmpdxdy ; else if dely < 0 then
neg bx ; dely := abs(dely)
mov dx,-80 ; yinc2 := -80
mov [bp-6],dx
mov [bp-4],dx ; endif
cmpdxdy:
cmp ax,bx ; if delx < dely then
jge setyinc1
mov dx,0 ; xinc := 0
mov [bp-2],dx
xchg ax,bx ; swap(delx,dely);
jmp calcaddr ; else
setyinc1:
mov dx,0 ; yinc1 := 0
mov [bp-4],dx
; endif
calcaddr:
push ax
mov cx,bx ; incr1 := dely * 2
shl cx,1
mov [bp-8],cx
sub bx,ax ; incr2 := (dely - delx) * 2
shl bx,1
mov [bp-10],bx
mov si,bx
mov ax,[bp+10] ; address := (y * 80) + (x / 8)
mov dx,80
mul dx
mov cx,3
mov di,[bp+12]
shr di,cl
add di,ax
mov cx,[bp+12] ; mask := 1 shl (7 - x mod 8)
and cl,7
xor cl,7
mov ch,1
shl ch,cl
mov bl,ch
; ---- Initialize EGA Card ----
; Select Write Mode 2
mov dx,3CEh ; select mode register
mov ax,5
out dx,al
mov dx,3CFh ; set to write mode 2
mov ax,2
out dx,al
; Set Bit Mask Register
mov dx,3CEh ; select register 8
mov ax,8
out dx,al
mov dx,0A000h ; es := EGA buffer segment address
mov es,dx
mov bh,[bp+4] ; get color
mov dx,3CFh
pop cx ; for i := 1 to dx do
inc cx
llp1:
; ---- Plot Point -------------+
; |
mov al,bl ; | output bit mask to register 8
out dx,al ; |
; |
; Latch all four bit planes ; |
; |
mov al,es:[di] ; | latches all four bit planes
; |
; Write Pixel ; |
; |
mov es:[di],bh ; | set color
; |
; --- end of plot point -------+
cmp si,0 ; if d < 0 then
jge llp2
mov ax,cx
mov cx,[bp-2] ; x := x + xinc1
ror bl,cl
mov cx,ax
adc di,+00
add di,[bp-4] ; y := y + yinc1
add si,[bp-8] ; d := d + incr1
loop llp1
jmp lend
llp2: ; else
ror bl,1 ; x := x + xinc2
adc di,+00
add di,[bp-6] ; y := y + yinc2
add si,[bp-10] ; d := d + incr2
loop llp1 ; endif
; endfor
lend:
; Restore defualt EGA graphics status
mov dx,3CEh
mov ax,5
out dx,al
mov dx,3CFh
mov ax,0
out dx,al
mov dx,3CEh
mov ax,8
out dx,al
mov dx,3CFh
mov ax,0FFh
out dx,al
mov sp,bp
pop bp
ret 10
line endp
cseg ends
end