; 用当前作图颜色,方式和线型画水平线.参数: 起始坐标,宽度
; void HoriLine(int x, int y, int width)
;
PROC _HoriLine
ARG x: word, y: word, width: word
USES ds, si, di
call SetWrMode0
mov ax, [x]
mov bx, [y]
call GetDspMem
mov di, bx
mov si, bx
mov cx, [x]
and cl, 7
mov bx, 0ffffh
shr bh, cl
mov cx, [width]
add cx, [x]
dec cx
push cx
not cl
and cl, 7
shl bl, cl
mov ax, [x]
shr ax, 3
pop cx
shr cx, 3
sub cx, ax
mov al, bh
push bx
mov bx, [LnStyle]
push es
pop ds
cld
cmp bx, 0ffffh
je @@2
and al, bh
@@1:
dec cx
js @@3
out dx, al
movsb
mov al, bl
xchg bh, bl
jmp @@1
@@2:
jcxz @@3
out dx, al
movsb
mov al, 0ffh
dec cx
js @@3
out dx, al
rep movsb
@@3:
pop bx
and al, bl
out dx, al
movsb
call RestReg0
ret
ENDP
; 用当前作图颜色,方式和线型画直线.参数: 起始坐标,结束坐标
; void Line(int x1, int y1, int x2, int y2)
;
PROC _Line
ARG x1 : word, y1 : word, x2 : word, y2 : word
USES si, di
mov ax, [x1]
mov bx, [y1]
mov si, [x2]
mov di, [y2]
cmp ax, si
jne @@2
cmp bx, di
jle @@1
xchg bx, di
@@1:
sub di, bx
inc di
push di
push bx
push ax
call _VertLine
add sp, 6
jmp @@14
@@2:
cmp bx, di
jne @@4
cmp ax, si
jle @@3
xchg ax, si
@@3:
sub si, ax
inc si
push si
push bx
push ax
call _HoriLine
add sp, 6
jmp @@14
@@4:
mov [word y1], DMWIDTH
mov [word x1], 0
cmp ax, si
jle @@5
xchg ax, si
xchg bx, di
@@5:
sub si, ax
sub di, bx
jns @@6
neg [word y1]
neg di
@@6:
cmp di, si
jle @@7
mov [word x1], 1
xchg di, si
@@7:
push si
mov [y2], di
mov [x2], si
mov di, si
shr di, 1
push ax
call GetDspMem
mov ah, 2
call SetWrMode
mov si, [LnStyle]
pop cx
and cl, 7
mov al, 80h
shr al, cl
out dx, al
mov ah, [byte Color]
pop cx
inc cx
@@8:
test si, 8000h
jz @@9
push ax
xchg ah, [byte es:bx]
pop ax
@@9:
rol si, 1
add di, [y2]
cmp di, [word x2]
jle @@10
add bx, [y1]
sub di, [x2]
jmp short @@11
@@10:
cmp [word x1], 0
je @@11
add bx, [y1]
loop @@8
jmp short @@13
@@11:
ror al, 1
test al, 80h
jz @@12
inc bx
@@12:
out dx, al
loop @@8
@@13:
call RestReg
@@14:
ret
ENDP
; 用当前作图颜色,方式和线型画矩形(不填充).参数: 起始坐标,结束坐标
; void Rectangle( int x1, int y1, int x2, int y2 )
;
PROC _Rectangle
ARG x1 : word, y1 : word, x2 : word, y2 : word
USES si, di
mov ax, [x1]
mov bx, [y1]
mov si, [x2]
mov di, [y2]
cmp ax, si
jle @@1
xchg ax, si
@@1:
cmp bx, di
jle @@2
xchg bx, di
@@2:
push si
push bx
sub si, ax
inc si
push si
push bx
push ax
call _HoriLine
pop ax
pop bx
push di
push ax
call _HoriLine
pop ax
pop di
pop si
pop bx
pop si
inc bx
sub di, bx
push di
push bx
push ax
call _VertLine
pop ax
push si
call _VertLine
add sp, 6
ret
ENDP
;
; ax = x1, bx = y1, si = x2, di = y2
;
PROC Bar
push bp
sub di, bx
inc di
push di
push bx
push ax
call GetDspMem
mov di, bx
pop ax
mov cx, ax
mov bx, 0ffffh
and cl, 7
shr bh, cl
mov cx, si
not cl
and cl, 7
shl bl, cl
shr ax, 3
shr si, 3
sub si, ax
mov bp, si
pop si
pop cx
cld
@@1:
push cx
push di
push si
push ds
and si, 7
mov al, [byte Pattern+si]
mov ah, al
and al, bh
mov cx, bp
mov si, di
push es
pop ds
dec cx
js @@2
out dx, al
movsb
mov al, ah
out dx, al
rep movsb
@@2:
and al, bl
out dx, al
movsb
pop ds
pop si
pop di
pop cx
inc si
add di, DMWIDTH
loop @@1
pop bp
ret
ENDP
; 用当前作图颜色,方式和填充图案画矩形(无边框).参数: 起始坐标,结束坐标
; void Bar( int x1, int y1, int x2, int y2 )
;
PROC _Bar
ARG x1 : word, y1 : word, x2 : word, y2 : word
USES si, di
mov ax, [x1]
mov bx, [y1]
mov si, [x2]
mov di, [y2]
cmp ax, si
jle @@1
xchg ax, si
@@1:
cmp bx, di
jle @@2
xchg bx, di
@@2:
push ax
call SetWrMode0
pop ax
call Bar
call RestReg0
ret
ENDP
; 设置调色板.参数: 调色板索引[0..15], 红,绿,蓝三色值[0..63]
; void SetPalette(int index, int Red, int Green, int Blus)
;
PROC _SetPalette
ARG index : word, red : word, green : word, blus : word
mov al, [byte index]
and al, 0fh
cmp al, 6
jl @@2
jg @@1
mov al, 14h
jmp short @@2
@@1:
cmp al, 7
je @@2
add al, 30h
@@2:
mov dx, 3c8h
out dx, al
inc dx
mov al, [byte red]
out dx, al
mov al, [byte green]
out dx, al
mov al, [byte blus]
out dx, al
ret
ENDP
END