求C语言快速写点的方法(直接写屏技术)

P__51 2007-09-15 10:26:20
如果用putpixel()写点函数来写点,慢得实在不行,写一个满屏要好几秒,在读BMP图片的时候就非常慢了,不实用。

谁知道直接写屏技术,分享分享吧(最好附上例子),谢谢了!
...全文
337 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanhan530 2007-09-16
  • 打赏
  • 举报
回复
见一刷屏的
P__51 2007-09-16
  • 打赏
  • 举报
回复
谢谢各位,谢谢阿发伯!

CSYNYK,你说的电子书给我邮一份,谢谢了。
E-mail:askhua168@163.com
_石头_ 2007-09-15
  • 打赏
  • 举报
回复
楼主:你在网上搜一下<<用C语言设计屏幕技术界面技术>>,是一本pdf格式的数,那里面专门介绍怎么控制显存的,我浏览过一次,感觉对你应该有帮助-----如果找不到的话说一声,我这有!
星羽 2007-09-15
  • 打赏
  • 举报
回复
tc 就这样了,显示图片也还是 putpixel
huang_yu1314 2007-09-15
  • 打赏
  • 举报
回复
学习一下
yjukh 2007-09-15
  • 打赏
  • 举报
回复
双缓冲
P__51 2007-09-15
  • 打赏
  • 举报
回复
补充说明一下,是在EGAVGA 640*480 16色模式下……
阿发伯 2007-09-15
  • 打赏
  • 举报
回复
楼上的应该是个Pascal调用函数吧
laiwusheng 2007-09-15
  • 打赏
  • 举报
回复
;******************************************
;640*480*16模式下的画点函数
;******************************************
PIXEL PROC
PUSH BP
PUSH BX
PUSH CX
PUSH DS
MOV BP,SP
MOV AX,80
MOV BX,WORD PTR[BP+12] ;BX<=Y
MUL BX ;(DX:AX)<=80*Y
MOV BX,AX ;
MOV AX,WORD PTR[BP+14] ;AX<--X
MOV CL,8 ; | |
DIV CL ;AL<=商(X/8),AH<=余数(X%8) SP-> | |
MOV CL,AH ;CL<=AH | DS |<-BP
MOV AH,0 ; | CX |<-BP+2
ADD BX,AX ;BX(OFFSET)<=80*Y+X/8 | BX |<-BP+4
MOV AL,80H ; | BP |<-BP+6
SHR AL,CL ;AL(MASK)<=(80H>>CL) |返回地址|<-BP+8
PUSH AX ; | COLOR |<-BP+10
MOV DX,3CEH ; | Y |<-BP+12
MOV AL,8 ; | X |<-BP+14
OUT DX,AL ; | |
MOV DX,3CFH ; PIXEL堆栈结构
POP AX
OUT DX,AL
MOV AL,ES:[BX]
MOV AX,WORD PTR[BP+10] ;AX<=COLOR
MOV BYTE PTR ES:[BX],AL
POP DS
POP CX
POP BX
POP BP
RET 6
PIXEL ENDP

阿发伯 2007-09-15
  • 打赏
  • 举报
回复
这是十多年前写的,前面带“_”的函数TC都可调用,自己再写个h文件吧!这是个基本的图形函数文件,可以外部添加的,还有一个屏幕卷动的文件,就是在基本函数上扩充的,其它的图形操作代码,如画圆、弧、屏幕拷贝、恢复等文件找不到了:

GRAPH.INC

P386N
include tasm_c.inc

MAXCOLOR equ 15 ; 最大颜色值
MAXX equ 639 ; 最大 X 象素
MAXY equ 479 ; 最大 Y 象素
DSPMEMSEG equ 0A000h ; 屏显起始地址
DMWIDTH equ 80 ; 屏幕每线字节数
GRMODE equ 12h ; 屏显方式

EXTRN Color:word
EXTRN DrMode:word
;
EXTRN _OpenGraph:proc
EXTRN _CloseGraph:proc
EXTRN _VertLine:proc
EXTRN _HoriLine:proc
EXTRN _Line:proc
EXTRN _PutPixel:proc
EXTRN _GetPixel:proc
EXTRN _SetColor:proc
EXTRN _GetColor:proc
EXTRN _SetDrMode:proc
EXTRN _SetLnStyle:proc
EXTRN _SetPattern:proc
EXTRN _GetPattern:proc
EXTRN _Rectangle:proc
EXTRN _Bar:proc
EXTRN _SetPalette:proc
EXTRN GetDspMem:proc
EXTRN GetDspMemOff:proc
EXTRN SetWrMode:proc
EXTRN SetWrMode0:proc
EXTRN RestReg:proc
EXTRN RestReg0:proc
EXTRN Bar:proc
EXTRN PutPixel:proc
EXTRN _farmalloc:proc
EXTRN _farfree:proc

; GRFILL.ASM

include graph.inc

BLOCKED equ 1
UNBLOCKED equ 2

DATASEG

BorderValue dw 0
FillColor dw 0
FillBufPtr dw 0
BufStartOfs dw 0
BufEndOfs dw 0
D dw 0
PrevD dw 0
PrevV dw 0
TmpX dw 0
TmpY dw 0
TmpFlag db 0
CODESEG

PUBLIC _Fill
;
; ax = x, bx = y return ax = xr, bx = y
;
PROC ScanRight

USES es, di, si, bx

mov si, ax
call GetDspMem
mov di, bx
mov cx, si
shr si, 3
and cl, 7
mov ch, 0ffh
shr ch, cl
mov dx, 3ceh
mov ah, [byte BorderValue]
mov al, 2
out dx, ax
mov ax, 805h
out dx, ax
mov ax, 0f07h
out dx, ax
mov al, [es:di]
inc di
not al
and al, ch
jnz @@1
mov cx, DMWIDTH-1
sub cx, si
mov al, 0ffh
cld
repe scasb
mov al, [es:di-1]
not al
cmp cx, 0
jne @@1
mov cx, MAXX
and cl, 7
mov ch, 40h
shr ch, cl
or al, ch
@@1:
sub di, bx
add di, si
shl di, 3
mov cx, 8
@@2:
shl al, 1
jc @@3
loop @@2
@@3:
sub di, cx
mov ax, 2
out dx, ax
mov ax, 5
out dx, ax
mov ax, di
ret
ENDP
;
; return ax = x, bx = y
;
PROC ScanRegion

USES di
mov di, [BufStartOfs] ;i = bufstart
@@1:
cmp di, si ;while(i < bufend)
jae @@5 ;{
cmp [byte es:di+4], BLOCKED ; if(buf[i].flag == BLOCKED
je @@2
mov bx, [es:di+2] ; || buf[i].y != buf[i+1].y)
cmp bx, [es:di+7]
je @@3
@@2:
add di, 5 ; i ++
jmp short @@1 ; }
@@3: ; else{
mov ax, [es:di] ; if(buf[i].x+1 < buf[i+1].x)
inc ax ; {
cmp ax, [es:di+5]
jge @@4
call ScanRight ; xr = ScanRight(buf[i].x+1,buf[i].y)
cmp ax, [es:di+5] ; if(xr < buf[i+1].x){
jl @@5 ; ax=xr; bx=buf[i].y
@@4: ; }
add di, 10 ; i += 2
jmp short @@1 ; }
@@5: ;}
mov [BufStartOfs], di ;bufstart = i
ret
ENDP
;
;
PROC FillRegion

USES di

push [word Color]
mov ax, [FillColor]
mov [Color], ax
mov di, [FillBufPtr]
call SetWrMode0
@@1:
cmp di, [BufEndOfs]
jae @@5
cmp [byte es:di+4], BLOCKED
je @@2
mov bx, [es:di+2]
cmp bx, [es:di+7]
je @@3
@@2:
add di, 5
jmp short @@1
@@3:
mov si, [es:di+5]
dec si
cmp si, [es:di]
jle @@4
push es
push di
mov ax, [es:di]
inc ax
mov di, bx
call Bar
pop di
pop es
@@4:
add di, 10
jmp short @@1
@@5:
call RestReg0
pop [word Color]
ret
ENDP
;
;
PROC AppendBPList

mov [byte es:si+4], bl
mov ebx, [dword TmpX]
mov [dword es:si], ebx
add si, 5
ret
ENDP
;
;
PROC FindBP

USES bx

mov cx, [TmpX]
mov dx, [TmpY]
cmp ax, 1 ; 1, 2, 3, y --
jl @@5
cmp ax, 3
jg @@1
dec dx
jmp short @@2
@@1:
cmp ax, 5 ; 5, 6, 7, y ++
jl @@3
inc dx
@@2:
cmp ax, 3 ; 3, 4, 5, x --
jl @@4
cmp ax, 5
jg @@4
@@3:
dec cx
jmp short @@6
@@4:
cmp ax, 7 ; 0, 1, 7, x ++
je @@5
cmp ax, 1
jg @@6
@@5:
inc cx
@@6:
or cx, cx
js @@18
cmp cx, MAXX
jg @@18
or dx, dx
js @@18
cmp dx, MAXY
jg @@18
push es
push ax
push dx
push cx
call _GetPixel
mov bx, ax
pop cx
pop dx
pop ax
pop es
cmp bx, [BorderValue]
je @@16
@@18:
cmp ax, [PrevD]
jne @@8
cmp [word PrevD], 4
je @@15
cmp [word PrevD], 0
jne @@7
mov [byte es:si-1], BLOCKED
jmp @@15
@@7:
mov bl, UNBLOCKED
call AppendBPList
jmp @@15
@@8:
mov bl, BLOCKED
cmp [word PrevD], 4
jne @@10
cmp [word PrevV], 5
jne @@13
mov [byte es:si-1], BLOCKED
jmp short @@13
@@10:
cmp [word PrevD], 0
jne @@11
mov [byte es:si-1], BLOCKED
cmp ax, 7
je @@13
mov bl, UNBLOCKED
jmp short @@13
@@11:
mov bl, UNBLOCKED
call AppendBPList
cmp ax, 1
jl @@14
mov bl, UNBLOCKED
cmp ax, 3
jg @@12
cmp [word PrevD], 5
jl @@14
cmp [word PrevD], 7
jg @@14
jmp short @@13
@@12:
cmp ax, 5
jl @@14
cmp [word PrevD], 1
jl @@14
cmp [word PrevD], 3
jg @@14
@@13:
call AppendBPList
@@14:
push [word PrevD]
pop [word PrevV]
@@15:
mov [PrevD], ax
mov [TmpX], cx
mov [TmpY], dx
mov ax, 1
jmp short @@17
@@16:
xor ax, ax
@@17:
ret
ENDP
;
;
PROC FindNextPixel

mov bx, -2
@@1:
inc bx
cmp bx, 5
jg @@2
mov ax, bx
add ax, [D]
and ax, 7
call FindBP
cmp ax, 0
je @@1
add [word D], bx
and [word D], 6
@@2:
ret
ENDP
;
; TraceBorder(int startx, int starty)
;
PROC TraceBorder

ARG startx : word, starty : word

mov [word D], 6
mov [word PrevD], 8
mov [word PrevV], 2
push [word startx]
pop [word TmpX]
push [word starty]
pop [word TmpY]
@@1:
call FindNextPixel
cmp ax, 0
je @@2
mov bx, [startx]
cmp bx, [TmpX]
jne @@1
mov bx, [starty]
cmp bx, [TmpY]
jne @@1
@@2:
mov cx, [startx]
mov dx, [starty]
cmp ax, 0
jne @@3
mov [es:si], cx
mov [es:si+2], dx
mov [byte es:si+4], UNBLOCKED
add si, 5
jmp short @@4
@@3:
cmp [word PrevD], 3
jg @@5
cmp [word PrevD], 1
jl @@5
@@4:
mov [es:si], cx
mov [es:si+2], dx
mov [byte es:si+4], UNBLOCKED
add si, 5
@@5:
ret
ENDP
;
PROC _CompBP

mov ax, [es:di+2]
sub ax, [TmpY]
jne @@1
mov ax, [es:di]
sub ax, [TmpX]
jne @@1
mov al, [es:di+4]
sub al, [TmpFlag]
cbw
@@1:
ret
ENDP
;
PROC BorSort

mov ax, cx
sub ax, bx
cmp ax, 10
jl @@8
xor dx, dx
mov di, 5
div di
shr ax, 1
mul di
add ax, bx
mov di, ax
mov eax, [dword es:di]
mov [dword TmpX], eax
mov al, [es:di+4]
mov [TmpFlag], al
mov si, bx
mov dx, cx
sub si, 5
push di
@@0:
mov di, si
@@1:
add di, 5
call _CompBP
jl @@1
@@2:
mov si, di
mov di, dx
@@3:
sub di, 5
call _CompBP
jg @@3
@@4:
mov dx, di
cmp si, di
jae @@7
@@6:
mov eax, [dword es:si]
xchg eax, [dword es:di]
mov [dword es:si], eax
mov al, [es:si+4]
xchg al, [es:di+4]
mov [es:si+4], al
jmp short @@0
@@7:
pop di
cmp si, di
jae @@5
push cx
push si
mov cx, si
call BorSort
pop bx
pop cx
call BorSort
jmp short @@8
@@5:
push bx
push si
mov bx, si
call BorSort
pop cx
pop bx
call BorSort
@@8:
ret
ENDP
;
; void Fill(int x, int y, int fillcolor)
;
PROC _Fill

ARG x : word, y : word, fillcolor : word
USES si

mov ax, [x]
mov bx, [y]
cmp ax, MAXX
ja @@2
cmp bx, MAXY
ja @@2
push bx
push ax
call _GetPixel
add sp, 4
cmp ax, [fillcolor]
je @@2
mov [BorderValue], ax
mov ax, [fillcolor]
mov [FillColor], ax
push 0
push 15000
call _farmalloc
add sp, 4
cmp dx, 0
je @@2
mov es, dx
mov [FillBufPtr], ax
mov [BufStartOfs], ax
mov si, ax
mov ax, [x]
mov bx, [y]
call ScanRight
@@1:
push bx
push ax
call TraceBorder
add sp, 4
push si
mov cx, si
mov bx, [BufStartOfs]
call BorSort
pop si
call ScanRegion
cmp si, [BufStartOfs]
ja @@1
mov [BufEndOfs], si
call FillRegion
push es
push [word FillBufPtr]
call _farfree
add sp, 4
@@2:
ret
ENDP
;
END
阿发伯 2007-09-15
  • 打赏
  • 举报
回复
; 用当前作图颜色,方式和线型画水平线.参数: 起始坐标,宽度
; 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
阿发伯 2007-09-15
  • 打赏
  • 举报
回复
; TASM_C.INC

IFNDEF __TINY__
IFNDEF __SMALL__
IFNDEF __MEDIUM__
IFNDEF __COMPACT__
IFNDEF __LARGE__
DISPLAY "**Warning** You must supply a model symbol."
__SMALL__ equ 1
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF

IDEAL

IFDEF __TINY__
LPROG equ 0
LDATA equ 0
MODEL TINY, PROLOG
ENDIF

IFDEF __SMALL__
LPROG equ 0
LDATA equ 0
MODEL SMALL, PROLOG
ENDIF

IFDEF __MEDIUM__
LPROG equ 1
LDATA equ 0
MODEL MEDIUM, PROLOG
ENDIF

IFDEF __COMPACT__
LPROG equ 0
LDATA equ 1
MODEL COMPACT, PROLOG
ENDIF

IFDEF __LARGE__
LPROG equ 1
LDATA equ 1
MODEL LARGE, PROLOG
ENDIF

IF LDATA
DPTR_ EQU dword
DS_ EQU ds:
ES_ EQU es:

MACRO LDS_ Register, Memory
lds Register, Memory
ENDM LDS_

MACRO LES_ Register, Memory
les Register, Memory
ENDM LES_

MACRO PUSHDS_
push ds
ENDM PUSHDS_

MACRO POPDS_
pop ds
ENDM POPDS_

MACRO PUSHES_
push es
ENDM PUSHES_

MACRO POPES_
pop es
ENDM POPES_
ELSE
DPTR_ EQU word
DS_ EQU
ES_ EQU

MACRO LDS_ Register, Memory
mov Register, Memory
ENDM LDS_

MACRO LES_ Register, Memory
mov Register, Memory
ENDM LES_

MACRO PUSHDS_
ENDM PUSHDS_

MACRO POPDS_
ENDM POPDS_

MACRO PUSHES_
ENDM PUSHES_

MACRO POPES_
ENDM POPES_
ENDIF

; TASM_C.INC END

; graphbas.asm (VGA 16 色 640 * 480 方式)

P386N
include tasm_c.inc

MAXCOLOR equ 15 ; 最大颜色值
MAXX equ 639 ; 最大 X 象素
MAXY equ 479 ; 最大 Y 象素
DSPMEMSEG equ 0A000h ; 屏显起始地址
DMWIDTH equ 80 ; 屏幕每线字节数
GRMODE equ 12h ; 屏显方式

DATASEG

PUBLIC Color
PUBLIC DrMode
;
; 当前作图参数
;
Color dw 7 ; 作图颜色
DrMode dw 3 ; 作图模式(0 拷贝,1 与,2 或,3 异或)
LnStyle dw 0ffffh ; 线型
Pattern db 8 dup (0ffh) ; 填充图案

CODESEG

PUBLIC _OpenGraph
PUBLIC _CloseGraph
PUBLIC _VertLine
PUBLIC _HoriLine
PUBLIC _Line
PUBLIC _PutPixel
PUBLIC _GetPixel
PUBLIC _SetColor
PUBLIC _GetColor
PUBLIC _GetPattern
PUBLIC _SetDrMode
PUBLIC _SetLnStyle
PUBLIC _SetPattern
PUBLIC _Rectangle
PUBLIC _Bar
PUBLIC _SetPalette
PUBLIC GetDspMem
PUBLIC GetDspMemOff
PUBLIC SetWrMode
PUBLIC SetWrMode0
PUBLIC RestReg
PUBLIC RestReg0
PUBLIC Bar
PUBLIC PutPixel
;
; 取屏显地址: 参数: ax = X, bx = Y. 返回: es:bx = 段:偏移
;
PROC GetDspMem
push DSPMEMSEG
pop es
ENDP
;
; 取屏显偏移地址: 参数: ax = X, bx = Y, 返回: bx = 偏移地址
;
PROC GetDspMemOff
push ax
shl bx, 4
mov ax, bx ; bx = Y * 16
shl ax, 2
add bx, ax ; ( bx += ( Y * 64 )) or ( bx = Y * 80 )
pop ax
shr ax, 3 ; ax = X / 8
add bx, ax ; return BX = ( Y * 80 + X / 8 )
ret
ENDP
;
; 设置 VGA 写模式 0. 返回: dx = 3cfh
;
PROC SetWrMode0
xor al, al
mov ah, [byte Color]
mov dx, 3ceh
out dx, ax
mov ax, 0f01h
out dx, ax
xor ah, ah
ENDP
;
; 设置 VGA 写模式. 参数: ah = 模式[0..3].返回: dx = 3cfh
;
PROC SetWrMode
mov al, 5
mov dx, 3ceh
out dx, ax
mov ax, [DrMode]
out dx, ax
mov al, 8
out dx, al
inc dx
ret
ENDP
;
; 恢复设置写模式 0 的寄存器初值
;
PROC RestReg0
mov dx, 3ceh
xor ax, ax
out dx, ax
inc ax
out dx, ax
ENDP
;
; 恢复设置写模式的寄存器初值
;
PROC RestReg
mov dx, 3ceh
mov ax, 0ff08h
out dx, ax
mov ax, 5
out dx, ax
mov ax, 3
out dx, ax
ret
ENDP
; 打开图形方式
; void OpenGraph()
;
PROC _OpenGraph

mov ax, GRMODE
int 10h
mov dx, 3c4h
mov ax, 0f02h
out dx, ax
call RestReg0
ret
ENDP
; 关闭图形方式
; void CloseGraph()
;
PROC _CloseGraph

mov ax, 3
int 10h
ret
ENDP
; 设置当前作图颜色.参数: 颜色值[0..15]. 返回以前作图颜色
; int SetColor( int Color )
;
PROC _SetColor

ARG color : word

mov ax, [color]
and ax, MAXCOLOR
xchg ax, [Color]
ret
ENDP
; 设置作图方式.参数: 方式[0..3]. 返回以前作图方式
; int SetDrMode( int Mode )
;
PROC _SetDrMode

ARG mode : word

mov ax, [mode]
and ax, 3
shl ax, 11
or ax, 3
xchg ax, [DrMode]
shr ax, 11
ret
ENDP
; 设置作图线型.参数: 线型. 返回以前线型
; int SetLnStyle( int linestyle )
;
PROC _SetLnStyle

ARG linestyle : word
mov ax, [linestyle]
xchg ax, [LnStyle]
ret
ENDP
; 设置填充图案.参数: 图案指针(8*8点阵), 颜色
; void SetPattern( void far *Pat, int color )
;
PROC _SetPattern

ARG pat : far ptr, color : word
USES di, si, ds

push [word color]
call _SetColor
pop ax
push ds
pop es
lea di, [Pattern]
lds si, [dword pat]
mov cx, 8
cld
rep movsb
ret
ENDP
; 返回当前作图颜色
; int GetColor( void )
;
PROC _GetColor

mov ax, [Color]
ret
ENDP
; 返回当前填充图案地址
; void far *GetPattern()
;
PROC _GetPattern

lea ax, [Pattern]
mov dx, ds
ret
ENDP
;
; 用当前颜色和作图方式画点.参数: ax = x, bx = y, dx = 03cfh
;
PROC PutPixel

push ax
call GetDspMem
pop cx
and cx, 7
mov al, 80h
shr al, cl
out dx, al
mov ax, [Color]
xchg al, [byte es:bx]
ret
ENDP
; 用当前颜色和作图方式画点.参数: 点坐标
; void PutPixel( int x, int y )
;
PROC _PutPixel

ARG x : word, y : word

mov ah, 2
call SetWrMode
mov ax, [x]
mov bx, [y]
call PutPixel
call RestReg
ret
ENDP
; 返回坐标点的颜色值.参数: 点坐标
; int GetPixel( int x, int y )
;
PROC _GetPixel

ARG x : word, y : word

mov ax, [x]
mov bx, [y]
push ax
call GetDspMem
pop cx
not cl
and cl, 7
xor ch, ch
mov dx, 3ceh
mov al, 4
out dx, al
inc dx
mov al, 3
@@1:
out dx, al
mov ah, [byte es:bx]
shr ah, cl
and ah, 1
shl ch, 1
or ch, ah
dec al
jns @@1
mov al, ch
cbw
ret
ENDP
; 用当前作图颜色,方式和线型画垂直线.参数: 起始坐标,高度
; void VertLine(int x, int y, int height)
;
PROC _VertLine

ARG x: word, y: word, height: word
USES si

mov ah, 2
call SetWrMode
mov ax, [x]
mov bx, [y]
push ax
call GetDspMem
pop cx
and cx, 7
mov al, 80h
shr al, cl
out dx, al
mov ah, [byte Color]
mov si, [LnStyle]
mov cx, [height]
@@1:
test si, 8000h
jz @@2
mov al, ah
xchg al, [byte es:bx]
@@2:
rol si, 1
add bx, DMWIDTH
loop @@1
call RestReg
ret
ENDP
mLee79 2007-09-15
  • 打赏
  • 举报
回复
唉, 啥年代了哦, 咋还在用这东西哦 ...
16色模式的高分屏下直接写屏很麻烦地, 要不停的切换不同颜色位面, 一个位面要切换好几次窗口, 远不如用256色,16位色等VESA模式方便...
还是换编译器吧,即使要在dos下跑,也要用djgpp三,保护模式是王道... 或者用 dx 吧, 一样直接写屏, 感觉好多了 ...

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧