Turbo C使用的汇编函数 -- VGA 12H模式图形函数(二)

        接上篇文章《Turbo C使用的汇编函数 -- VGA 12H模式图形函数(一)》,继续粘贴代码文件:

;    grimage.asm

    include    graph.inc

    DATASEG

bufseg        dw    
0
bufoff        dw    
0
linebytes    dw    
0
tmpbuf        db    
80  dup( 0 )

    CODESEG

    PUBLIC    _ImageSize
    PUBLIC    _GetImage
    PUBLIC    _PutImage
;
long  ImageSize(  int  x1,  int  y1,  int  x2,  int  y2 )
;
PROC    _ImageSize

    ARG    x1 : word, y1 : word, x2 : word, y2 : word
    USES    si, di

    mov    ax, [x1]
    mov    bx, [y1]
    mov    si, [x2]
    mov    di, [y2]
    mov    cx, MAXX
    mov    dx, MAXY
    call    TestPoint
    jnc    @@
1
    xor    ax, ax
    xor    dx, dx
    jmp    
short  @@ 2
@@
1 :
    xchg    ax, si
    sub    ax, si
    sub    di, bx
    inc    di
    and    ax, 0fff8h
    shr    ax, 
1
    add    ax, 
4
    mul    di
    add    ax, 
4
    adc    dx, 
0
@@
2 :
    ret
ENDP
;
PROC    PackLine

    USES    bx, ds, es

    push    es
    pop    ds
    mov    es, [bufseg]
    mov    di, [bufoff]
    mov    si, offset tmpbuf
@@
1 :
    xor    bh, bh
@@
2 :
    or    bl, bl
    jz    @@
3
    lodsb
    dec    bl
    inc    bh
    cmp    al, [si]
    je    @@
2
@@
3 :
    cmp     bh, 
1
    ja    @@
4
    test    al, 80h
    jz    @@
5
@@
4 :
    xchg    al, bh
    or    al, 80h
    stosb
    mov    al, bh
@@
5 :
    stosb
    or    bl, bl
    jnz    @@
1
    mov    [bufoff], di
    ret
ENDP
;
PROC    UnPackLine

    USES    bx, cx, di, es

    push    ds
    pop    es
    mov    di, offset tmpbuf
    push    di
    push    ds
    mov    si, [bufoff]
    mov    bx, [linebytes]
    mov    ax, [bufseg]
    mov    ds, ax
@@
1 :
    lodsb
    mov    cx, 
1
    test    al, 80h
    jz    @@
2
    and    ax, 7fh
    mov    cx, ax
    lodsb
@@
2 :
    sub    bx, cx
@@
3 :
    stosb
    loop    @@
3
    cmp    bx, 
0
    jne    @@
1
    pop    ds
    mov    [bufoff], si
    pop    si
    ret
ENDP
;
; unsigned GetImage( 
int  x1,  int  y1,  int  x2,  int  y2,  void  far  * buf )
;
PROC    _GetImage

    ARG     x1 : word, y1 : word, x2 : word, y2 : word, buf : far ptr
    USES    si, di

    mov    ax, [x1]
    mov    bx, [y1]
    mov    si, [x2]
    mov    di, [y2]
    mov    cx, MAXX
    mov    dx, MAXY
    call    TestPoint
    jnc    @@
5
    xor    ax, ax
    jmp    @@
4
@@
5 :
    push    ds
    mov    cx, ax
    and    cl, 
7
    mov    dl, cl
    mov    cx, si
    not    cl
    add    cl, dl
    and    cl, 
7
    mov    dh, 0ffh
    shl    dh, cl
    mov    [x1], dx
    sub     si, ax
    sub    di, bx
    mov    cx, di
    les    di, [dword buf]
    mov    [word es:di], si
    mov    [word es:di
+ 2 ], cx
    push    di
    add    di, 
4
    mov    [bufseg], es
    mov    [bufoff], di
    shr    si, 
3
    call    GetDspMemOff
    xchg    si, bx
    inc    bx
    inc    cx
    push    ds
    pop    es
    mov    di, offset tmpbuf
    push    DSPMEMSEG
    pop    ds
    mov    dx, 3ceh
    cld
@@
1 :
    push    cx
    push    si
    mov    cx, [x1]
    mov    ax, 304h
@@
2 :
    
out     dx, ax
    push    ax
    push    si
    push    di
    push    bx
    lodsb
@@
3 :
    mov    ah, al
    lodsb
    push    ax
    shl    ax, cl
    mov    al, ah
    stosb
    pop    ax
    dec    bx
    jnz    @@
3
    and    [
byte  es:di - 1 ], ch
    pop    bx
    call    PackLine
    pop    di
    pop    si
    pop    ax
    dec    ah
    jns    @@
2
    pop    si
    pop    cx
    add    si, DMWIDTH
    loop    @@
1
    pop    di
    pop    ds
    mov    ax, [bufoff]
    sub    ax, di
@@
4 :
    ret
ENDP
;
void  PutImage( int  x,  int  y,  void  far  * buf,  int  mod)
;
PROC    _PutImage

    ARG     x : word, y : word, buf : far ptr, mod : word
    USES    si, di

    les    bx, [dword buf]
    mov    di, [word es:bx
+ 2 ]
    mov    si, [word es:bx]
    mov    [bufseg], es
    add    bx, 
4
    mov    [bufoff], bx
    mov    ax, si
    shr    ax, 
3
    inc    ax
    mov    [linebytes], ax
    mov    ax, [x]
    mov    bx, [y]
    add    si, ax
    add    di, bx
    mov    cx, MAXX
    mov    dx, MAXY
    call    TestPoint
    jc    @@
7
    push    [word DrMode]
    mov    cx, si
    not    cl
    and    cl, 
7
    mov    ch, 0ffh
    shl    ch, cl
    mov    cl, al
    and    cl, 
7
    mov    [x], cx
    push    ax
    shr    si, 
3
    shr    ax, 
3
    sub    si, ax
    push    si
    push    [word mod]
    call    _SetDrMode
    xor    ah, ah
    call    SetWrMode
    pop    ax
    cld
    mov    cx, di
    sub    cx, bx
    inc    cx
    pop     di
    pop    ax
    call    GetDspMem
@@
2 :
    push    bx
    push    cx
    mov    ax, 802h
    mov    cx, [x]
@@
3 :
    mov    dx, 3c4h
    
out     dx, ax
    mov    dx, 3cfh
    push    ax
    push    bx
    push    di
    call    UnPackLine
    mov    ax, 0ffh
    shr    al, cl
    dec    di
    js    @@
6
    
out     dx, al
    lodsb
    ror    ax, cl
    xchg    al, [
byte  es:bx]
    inc    bx
    mov    al, 0ffh
    
out     dx, al
@@
4 :
    dec    di
    js    @@
5
    mov    ch, ah
    lodsb
    xor    ah, ah
    ror    ax, cl
    or    al, ch
    xchg    al, [
byte  es:bx]
    inc    bx
    jmp    
short  @@ 4
@@
5 :
    mov    al, 0ffh
@@
6 :
    and    al, [
byte  x + 1 ]
    
out     dx, al
    lodsb
    shr    al, cl
    or    al, ah
    xchg    al, [
byte  es:bx]
    pop    di
    pop    bx
    pop    ax
    shr    ah, 
1
    jnz     @@
3
    pop    cx
    pop    bx
    add    bx, DMWIDTH
    loop    @@
2
    pop    [word DrMode]
    call    RestReg
    mov    dx, 3c4h
    mov    ax, 0f02h
    
out     dx, ax
@@
7 :
    ret
ENDP
    END

 

;    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, [MaxX]
    shr    cx, 
3
    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 :
    cmp    cx, [MinX]
    jl    @@
18
    cmp    cx, [MaxX]
    jg    @@
18
    cmp    dx, [MinY]
    jl    @@
18
    cmp    dx, [MaxY]
    jg    @@
18
    push    es
    push    ax
    push    cx
    push    dx
    mov    ax, cx
    mov    bx, dx
    call    GetPixel
    mov    bx, ax
    pop    dx
    pop    cx
    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, [WidthX]
    ja    @@
2
    cmp    bx, [WidthY]
    ja    @@
2
    add    ax, [MinX]
    add    bx, [MinY]
    mov    [x], ax
    mov    [y], bx
    call    GetPixel
    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

 

; grroll.asm

    include    graph.inc

    CODESEG

    PUBLIC    _Roll
;
void  Roll( int  n,  int  x1,  int  y1,  int  x2,  int  y2)
;
PROC    _Roll

    ARG    n : word, x1 : word, y1 : word, x2 : word, y2 : word
    USES    si, di, ds

    cmp    [word n], 
0
    je    @@
4
    mov    ax, [x1]
    mov    bx, [y1]
    mov    si, [x2]
    mov    di, [y2]
    mov    cx, MAXX
    mov    dx, MAXY
    call    TestPoint
    jc    @@
4
    mov    dx, 0ffffh
    mov    cx, ax
    and    cl, 
7
    shr    dh, cl
    mov    cx, si
    and    cl, 
7
    not    cl
    shl    dl, cl
    push    dx
    push    ax
    shr    ax, 
3
    shr    si, 
3
    sub    si, ax
    mov    [x2], si
    mov    cx, [n]
    mov    ax, DMWIDTH
    mov    [y2], ax
    imul    cx
    mov    si, ax
    mov    cx, di
    sub    cx, bx
    inc    cx
    cmp    si, 
0
    jg    @@
1
    xchg    bx, di
    neg    [word n]
    neg    [word y2]
@@
1 :
    pop    ax
    call    GetDspMem
    mov    di, bx
    add    si, di
    pop    bx
    sub    cx, [n]
    jle    @@
4
    mov    ah, 
1
    call    SetWrMode
    push    es
    pop    ds
    cld
@@
2 :
    push    cx
    push    si
    push    di
    mov    cx, [x2]
    mov    al, bh
    jcxz    @@
3
    
out     dx, al
    movsb
    mov    al, 0ffh
    dec    cx
    jz    @@
3
    
out     dx, ax
    repz    movsb
    mov    al, 0ffh
@@
3 :
    and    al, bl
    
out     dx, ax
    movsb
    pop    di
    pop    si
    pop    cx
    add    di, [y2]
    add    si, [y2]
    loop    @@
2
    call    RestReg
@@
4 :
    ret
ENDP
    end

 

; GRARC.ASM

    P386N
    include    graph.inc

    DATASEG

Sin        dw    0000h, 00afh, 015dh, 020bh, 02bah, 0368h, 0415h, 04c3h
        dw    0570h, 061ch, 06c8h, 0774h, 081fh, 08cah, 0973h, 0a1ch
        dw    0ac4h, 0b6ch, 0c12h, 0cb8h, 0d5ch, 0e00h, 0ea2h, 0f43h
        dw    0fe3h, 1082h, 1120h, 11bch, 1257h, 12f0h, 1388h, 141eh
        dw    14b3h, 1546h, 15d8h, 1668h, 16f6h, 1782h, 180dh, 1895h
        dw    191ch, 19a1h, 1a23h, 1aa4h, 1b23h, 1b9fh, 1c19h, 1c92h
        dw    1d07h, 1d7bh, 1dech, 1e5bh, 1ec8h, 1f32h, 1f9ah, 2000h
        dw    2062h, 20c3h, 2120h, 217ch, 21d4h, 222ah, 227dh, 22ceh
        dw    231ch, 2367h, 23afh, 23f5h, 2438h, 2478h, 24b5h, 24efh
        dw    2527h, 255bh, 258dh, 25bbh, 25e7h, 2610h, 2635h, 2658h
        dw    2678h, 2695h, 26afh, 26c5h, 26d9h, 26eah, 26f8h, 2702h
        dw    270ah, 270eh, 2710h
StartQ        dw    
0
EndQ        dw    
0
StartX        dw    
0
StartY        dw    
0
EndX        dw    
0
EndY        dw    
0
;

    EXTRN    CirX0:word
    EXTRN    CirY0:word
;
    CODESEG

    PUBLIC    _Arc
    PUBLIC    _Slice
    PUBLIC    _Pie

    EXTRN    Ellipse:proc
    EXTRN    PlotCirPix:proc
;
;
PROC    SumArcXY

    ARG    x : word, y : word

    mov    ax, [CirX0]
    mov    bx, [CirY0]
    and    cx, 
3
    jnz    @@
1
    add    ax, [x]
    sub    bx, [y]
    jmp    
short  @@ 4
@@
1 :
    cmp    cx, 
1
    jne    @@
2
    sub    ax, [x]
    sub    bx, [y]
    jmp    
short  @@ 4
@@
2 :
    add    bx, [y]
    cmp    cx, 
2
    jne    @@
3
    sub    ax, [x]
    jmp    
short  @@ 4
@@
3 :
    add    ax, [x]
@@
4 :
    ret
ENDP
;
;
PROC    Arcjs

    USES    di

@@
1 :
    cmp    di, bp
    je    @@
5
    cmp    ax, [es:di]
    jne    @@
2
    cmp    bx, [es:di
+ 2 ]
    je    @@
5
    cmp    bx, [es:di
+ 6 ]
    je    @@
5
@@
2 :
    cmp    bx, [es:di
+ 2 ]
    jne    @@
3
    cmp    ax, [es:di
+ 4 ]
    je    @@
5
@@
3 :
    add    di, cx
    jmp    
short  @@ 1
@@
5 :
    mov    ax, di
    ret
ENDP
;
; ax 
=  jd, dx  =  r,  return  ax  =  sq, di  =  x, dx  =  y
;
PROC    ArcSum

    movsx    ecx, dx
    xor    dx, dx
    mov    si, 
90
    div    si
    push    ax
    mov    di, dx
    sub    si, dx
    shl    di, 
1
    shl    si, 
1
    movsx   eax, [word Sin
+ di]
    imul    ecx
    add    eax, 
5000
    mov    ebx, 
10000
    div    ebx
    mov    di, ax
    movsx   eax, [word Sin
+ si]
    imul    ecx
    add    eax, 
5000
    div    ebx
    mov    dx, ax
    pop    ax
    test    ax, 
1
    jnz    @@
1
    xchg    dx, di
@@
1 :
    ret
ENDP
;
void  Arc( int  x,  int  y,  int  start,  int  end,  int  radius)
;
PROC    _Arc

    ARG    x : word, y : word, start : word, end : word, radius : word
    USES    si, di

    mov    ax, [end]
    or    ax, ax
    js    @@
2
    mov    bx, [start]
    or    bx, bx
    js    @@
2
    cmp    ax, bx
    jge    @@
3
    xchg    ax, bx
@@
3 :
    push    bx
    mov    dx, [radius]
    call    ArcSum
    mov    [EndQ], ax
    mov    [EndX], di
    mov    [EndY], dx
    pop    ax
    mov    dx, [radius]
    call    ArcSum
    mov    [StartQ], ax
    mov    [StartX], di
    mov    [StartY], dx
    push    
0
    push    
12000
    call    _farmalloc
    add    sp, 
4
    cmp    dx, 
0
    je    @@
2
    mov    es, dx
    push    dx
    push    ax
    push    [word x]
    push    [word y]
    pop    [word CirY0]
    pop    [word CirX0]
    mov    si, [radius]
    mov    di, si
    push    bp
    mov    bp, ax
    push    ax
    call    Ellipse
    mov    ah, 
2
    call    SetWrMode
    pop    di
    mov    cx, 
4
    mov    si, [StartQ]
    test    si, 
1
    jnz     @@
4
@@
1 :
    neg    cx
    xchg    di, bp
@@
4 :
    push    si
    push    di
    cmp    si, [StartQ]
    jne    @@
5
    mov    bx, [StartY]
    mov    ax, [StartX]
    call    Arcjs
    mov    di, ax
    mov    eax, [dword es:di]
    mov    [dword StartX], eax
@@
5 :
    cmp    si, [EndQ]
    jne    @@
6
    mov    bx, [EndY]
    mov    ax, [EndX]
    call    Arcjs
    mov    bp, ax
    mov    eax, [dword es:bp]
    mov    [dword EndX], eax
    or    [word EndQ], 8000h
@@
6 :
    and    si, 
3
    call    PlotCirPix
    pop    di
    pop    si
    inc    si
    test    [word EndQ], 8000h
    jz    @@
1
    pop    bp
    call    _farfree
    add    sp, 
4
    call    RestReg
@@
2 :
    ret
ENDP
;
void  Slice( int  x,  int  y,  int  start,  int  end,  int  radius)
;
PROC    _Slice

    ARG    x : word, y : word, start : word, end : word, radius : word

    push    [word radius]
    push    [word end]
    push    [word start]
    push    [word y]
    push    [word x]
    call    _Arc
    add    sp, 
10
    push    [word StartY]
    push    [word StartX]
    mov    cx, [StartQ]
    call    SumArcXY
    add    sp, 
4
    push    bx
    push    ax
    call    _PutPixel
    push    [word CirY0]
    push    [word CirX0]
    call    _Line
    add    sp, 
8
    mov    ax, [CirX0]
    mov    bx, [CirY0]
    push    bx
    push    ax
    call    _PutPixel
    push    [word EndY]
    push    [word EndX]
    mov    cx, [EndQ]
    call    SumArcXY
    add    sp, 
4
    push    bx
    push    ax
    call    _Line
    ret
ENDP
;
void  Pie( int  x,  int  y,  int  start,  int  end,  int  radius)
;
PROC    _Pie

    ARG    x : word, y : word, start : word, end : word, radius : word

    push    [word radius]
    push    [word end]
    push    [word start]
    push    [word y]
    push    [word x]
    call    _Arc
    add    sp, 
10
    push    [word StartY]
    push    [word StartX]
    mov    cx, [StartQ]
    call    SumArcXY
    add    sp, 
4
    push    bx
    push    ax
    call    _PutPixel
    push    [word EndY]
    push    [word EndX]
    mov    cx, [EndQ]
    call    SumArcXY
    add    sp, 
4
    push    bx
    push    ax
    call    _Line
    ret
ENDP
    END

 

; GRELLIP.ASM

    P386N
    include    graph.inc

    DATASEG

    PUBLIC    CirX0, CirY0

Asp        dd    
0
Bsp        dd    
0
TowA        dd    
0
TowB        dd    
0
CirX0        dw    
0
CirY0        dw    
0
;
    CODESEG

    PUBLIC    _Circle
    PUBLIC    _Ellipse
    PUBLIC    Ellipse
    PUBLIC    PlotCirPix
;
; si 
=  a(xr), di  =  b(yr), bp  =  BufPtr
;
PROC    Ellipse

    movsx    eax, di
    imul    eax
    mov    [Bsp], eax    ;Bsp 
=  b  *  b
    shl    eax, 
1
    mov    [TowB], eax    ;TowB 
=  b  *  b  *   2
    movsx    eax, si
    imul    eax
    mov    [Asp], eax    ;Asp 
=  a  *  a
    push    eax
    shl    eax, 
1
    mov    [TowA], eax    ;TowA 
=  a  *  a  *   2
    movsx    edx, di
    imul    edx
    mov    ebx, eax    ;Cirdy 
=  TowA  *  b
    pop    eax
    mov    ecx, eax
    sar    ecx, 
2
    add    ecx, [Bsp]
    movsx    edx, di
    imul    edx
    sub    ecx, eax        ;Cird 
=  Bsp  -  Asp  *  b  +  Asp  /   4
    xor    si, si          ;x 
=   0
    xor    edx, edx    ;Cirdx 
=   0
@@
1 :
    cmp    edx, ebx    ;
while (dx  <  dy)
    jge    @@
5
    mov    [es:bp], si
    mov    [es:bp
+ 2 ], di
    add    bp, 
4
    cmp    ecx, 
0         ; if (d  >   0 )
    jle    @@
4
    sub    ebx, [TowA]    ;dy 
-=  TowA
    sub    ecx, ebx    ;d 
-=  dy
    dec    di        ;y 
--
@@
4 :
    inc    si        ;x 
++
    add    edx, [TowB]    ;dx 
+=  TowB
    add    ecx, [Bsp]      ;d 
+=  Bsp + dx
    add    ecx, edx
    jmp    
short  @@ 1
@@
5 :
    mov    eax, [Asp]    ;d 
+=  ( 3   *  (Asp  -  Bsp)  /   2   -  (dx  +  dy))  /   2
    sub    eax, [Bsp]
    push    ebx
    mov    ebx, eax
    sar    eax, 
1
    add    eax, ebx
    pop    ebx
    sub    eax, edx
    sub    eax, ebx
    sar    eax, 
1
    add    ecx, eax
@@
6 :
    or    di, di        ;
if (y  >=   0 )
    js    @@
9
    mov    [es:bp], si
    mov    [es:bp
+ 2 ], di
    add    bp, 
4
    cmp    ecx, 
0         ; if (d  <   0 )
    jge    @@
8
    add    edx, [TowB]        ;dx 
+=  TowB
    add    ecx, edx    ;d 
+=  dx
    inc    si        ;x 
++
@@
8 :
    sub    ebx, [TowA]    ;dy 
-=  TowA
    sub    ecx, ebx
    add    ecx, [Asp]    ;d 
+=  Asp  -  dy
    dec    di        ;y 
--
    jmp    
short  @@ 6
@@
9 :
    sub    bp, 
4
    ret
ENDP
;
; di 
=  startoffs, bp  =  endoffs, cx  =  incvluse, si  =  xx
;
PROC    PlotCirPix

@@
1 :
    cmp    di, bp
    je    @@
6
    mov    ax, [CirX0]
    mov    bx, [CirY0]
    cmp    si, 
1
    jg    @@
3
    je    @@
2
    add    ax, [es:di]
    sub    bx, [es:di
+ 2 ]
    jmp    
short  @@ 5
@@
2 :
    sub    ax, [es:di]
    sub    bx, [es:di
+ 2 ]
    jmp    
short  @@ 5
@@
3 :
    add    bx, [es:di
+ 2 ]
    cmp    si, 
2
    jne    @@
4
    sub    ax, [es:di]
    jmp    
short  @@ 5
@@
4 :
    add    ax, [es:di]
@@
5 :
    push    es
    push    cx
    call    PutPixel
    pop    cx
    pop    es
    add    di, cx
    jmp    
short  @@ 1
@@
6 :
    ret
ENDP
;
void  Ellipse( int  x,  int  y,  int  xr,  int  yr)
;
PROC    _Ellipse

    ARG    x0 : word, y0 : word, xr : word, yr : word
    USES    si, di

    push    
0
    push    
12000
    call    _farmalloc
    add    sp, 
4
    cmp    dx, 
0
    je    @@
2
    mov    es, dx
    push    dx
    push    ax
    push    [word x0]
    push    [word y0]
    pop    [word CirY0]
    pop    [word CirX0]
    mov    si, [xr]
    mov    di, [yr]
    push    bp
    mov    bp, ax
    push    ax
    call    Ellipse
    mov    ah, 
2
    call    SetWrMode
    pop    di
    xor    si, si
    mov    cx, 
4
@@
1 :
    neg    cx
    xchg    di, bp
    push    di
    call    PlotCirPix
    pop    di
    inc    si
    cmp    si, 
4
    jl    @@
1
    pop    bp
    call    _farfree
    add    sp, 
4
    call    RestReg
@@
2 :
    ret
ENDP
;
void  Circle( int  x,  int  y,  int  r)
;
PROC    _Circle

    ARG    x0 : word, y0 : word, r : word

    push    [word r]
    push    [word r]
    push    [word y0]
    push    [word x0]
    call    _Ellipse
    ret
ENDP
    END

 

; grroll.asm

    include    graph.inc

    CODESEG

    PUBLIC    _Roll
;
void  Roll( int  n,  int  x1,  int  y1,  int  x2,  int  y2)
;
PROC    _Roll

    ARG    n : word, x1 : word, y1 : word, x2 : word, y2 : word
    USES    si, di, ds

    cmp    [word n], 
0
    je    @@
4
    mov    ax, [x1]
    mov    bx, [y1]
    mov    si, [x2]
    mov    di, [y2]
    mov    cx, MAXX
    mov    dx, MAXY
    call    TestPoint
    jc    @@
4
    mov    dx, 0ffffh
    mov    cx, ax
    and    cl, 
7
    shr    dh, cl
    mov    cx, si
    and    cl, 
7
    not    cl
    shl    dl, cl
    push    dx
    push    ax
    shr    ax, 
3
    shr    si, 
3
    sub    si, ax
    mov    [x2], si
    mov    cx, [n]
    mov    ax, DMWIDTH
    mov    [y2], ax
    imul    cx
    mov    si, ax
    mov    cx, di
    sub    cx, bx
    inc    cx
    cmp    si, 
0
    jg    @@
1
    xchg    bx, di
    neg    [word n]
    neg    [word y2]
@@
1 :
    pop    ax
    call    GetDspMem
    mov    di, bx
    add    si, di
    pop    bx
    sub    cx, [n]
    jle    @@
4
    mov    ah, 
1
    call    SetWrMode
    push    es
    pop    ds
    cld
@@
2 :
    push    cx
    push    si
    push    di
    mov    cx, [x2]
    mov    al, bh
    jcxz    @@
3
    
out     dx, al
    movsb
    mov    al, 0ffh
    dec    cx
    jz    @@
3
    
out     dx, ax
    repz    movsb
    mov    al, 0ffh
@@
3 :
    and    al, bl
    
out     dx, ax
    movsb
    pop    di
    pop    si
    pop    cx
    add    di, [y2]
    add    si, [y2]
    loop    @@
2
    call    RestReg
@@
4 :
    ret
ENDP
    end

        下面这个文件的函数必须要安装UCDOS3.1以上版本才能工作:

; grputch.asm

    include    graph.inc

    DATASEG

ChX        dw    
0
ChY        dw    
0
HighCh        db    
0
ChFlag        db    
0
CurCount    db    
1
CurFlag        db    0ffh
OldInt1ch    dd    
0
CursorFlag    dw    
1
CursorStart    dw    
8
CursorLines    dw    
8
CursorColor    dw    
7
;
    CODESEG

    PUBLIC    _SetPos
    PUBLIC    _GetPos
    PUBLIC    _ShowCursor
    PUBLIC    _HideCursor
    PUBLIC    _Putch
    PUBLIC    _Putss
    PUBLIC    _InitUCDOS
    PUBLIC    _RestUCDOS
    PUBLIC    _InsertMode
;

PROC    PutCursor

    USES    es

    push    [word Color]
    push    [word DrMode]
    push    [word CursorColor]
    pop    [word Color]
    mov    [DrMode], 1803h
    call    SetWrMode0
    mov    ax, [ChX]
    mov    bx, [ChY]
    add    bx, [CursorStart]
    mov    cl, al
    call    GetDspMem
    and    cl, 
7
    mov    al, 0ffh
    shr    al, cl
    mov    cx, [CursorLines]
    push    cx
    push    bx
    
out     dx, al
@@
1 :
    xchg    ah, [es:bx]
    add    bx, DMWIDTH
    loop    @@
1
    pop    bx
    pop    cx
    or    al, al
    js    @@
3
    inc    bx
    not    al
    
out     dx, al
@@
2 :
    xchg    al, [es:bx]
    add    bx, DMWIDTH
    loop    @@
2
@@
3 :
    pop    [word DrMode]
    pop    [word Color]
    call    RestReg0
    ret
ENDP
;
OldDs    dw    
0
;
PROC    NewInt1ch

    pusha
    push    ds
    mov    ax, [cs : OldDs]
    mov    ds, ax
    cmp     [
byte  CursorFlag],  0
    jne    @@
1
    dec    [
byte  CurCount]
    jnz    @@
1
    mov    [
byte  CurCount],  9
    neg    [
byte  CurFlag]
    call    PutCursor
@@
1 :
    pop    ds
    popa
    iret
ENDP
;
int  InitUCDOS( int  curcolor)
;
PROC    _InitUCDOS

    ARG    curcolor : word

    mov    ax, 0db00h
    
int     2fh
    cbw
    or    ax, ax
    jz    @@
1
    xor    ax, ax
    cmp    bx, 5450h
    jne    @@
1
    mov    ax, 0ff01h
    mov    bx, 
1
    
int     10h
    mov    ax, ds
    mov    [word cs : OldDs], ax
    push    ds
    mov    ax, 351ch
    
int     21h
    mov    [word OldInt1ch], bx
    mov    ax, es
    mov    [word OldInt1ch
+ 2 ], ax
    mov    ax, [curcolor]
    mov    [CursorColor], ax
    push    cs
    pop    ds
    mov    dx, offset NewInt1ch
    mov    ax, 251ch
    
int     21h
    pop    ds
    mov    ax, 0ffh
@@
1 :
    ret
ENDP
;
void  RestUCDOS( void )
;
PROC    _RestUCDOS

    ARG    flag : word

    push    ds
    mov     dx, [word OldInt1ch]
    mov    ax, [word OldInt1ch
+ 2 ]
    mov    ds, ax
    mov    ax, 251ch
    
int     21h
    pop    ds
    cmp    [word flag], 
0
    jne    @@
1
    mov    ax, 0ff01h
    mov    bx, 101h
    
int     10h
@@
1 :
    ret
ENDP
;
void  ShowCursor( void )
;
PROC    _ShowCursor

    cmp    [
byte  CursorFlag],  0
    je    @@
1
    dec    [
byte  CursorFlag]
@@
1 :
    ret
ENDP
;
void  HideCursor( void )
;
PROC    _HideCursor

    inc    [
byte  CursorFlag]
    cmp    [
byte  CurFlag],  1
    jne    @@
1
    call    PutCursor
    neg    [
byte  CurFlag]
@@
1 :
    ret
ENDP
;
PROC    _InsertMode

    call    _HideCursor
    mov    ax, [CursorLines]
    xor    ax, 0ch
    mov    [CursorLines], ax
    mov    [word CursorStart], 
16
    sub    [CursorStart], ax
    shr    ax, 
3
    push    ax
    call    _ShowCursor
    pop    ax
    ret
ENDP
;
void  SetPos( int  x,  int  y)
;
PROC    _SetPos

    ARG    x : word, y : word

    call    _HideCursor
    mov    ax, [x]
    cmp    ax, MAXX
- 7
    ja    @@
2
    mov    [ChX], ax
@@
1 :
    mov    ax, [y]
    cmp    ax, MAXY
- 15
    ja    @@
2
    mov    [ChY], ax
@@
2 :
    call    _ShowCursor
    ret
ENDP
;
void  GetPos( int   * x,  int   * y)
;
PROC    _GetPos

    ARG    x : DPTR_, y : DPTR_

    LES_    bx, [x]
    mov    ax, [ChX]
    mov    [ES_ bx], ax
    LES_    bx, [y]
    mov    ax, [ChY]
    mov    [ES_ bx], ax
    ret
ENDP
;
; ax 
=  ch;  return  dx  =  AddrSeg
;
PROC    GetchAddr

    cmp    al, 80h
    jb    @@
2
    cmp    [
byte  HighCh],  0
    jne    @@
1
    mov     [HighCh], al
    mov    [
byte  ChFlag],  0
    jmp    
short  @@ 3
@@
1 :
    mov    ah, [HighCh]
    and    ax, 7f7fh
    or    ax, 8000h
    
int     6ah
    mov    dx, es
    mov    [
byte  ChFlag],  2
    mov    [
byte  HighCh],  0
    jmp    @@
3
@@
2 :
    and    ax, 7fh
    mov    dx, ax
    
int     7fh
    mov    [
byte  ChFlag],  1
@@
3 :
    ret
ENDP
;
; dx 
=  AddrSeg, si  =  AddrOffs, ch  =  attr, cl  =  shrs, es:bx  =  CrtAddr
;
PROC    PutchBin

    USES    ds, dx

    cld
    mov    ds, dx
    mov    dx, 3ceh
    mov    ah, ch
    shr    ah, 
4
    xor    al, al
    
out     dx, ax
    mov    ax, 0f01h
    
out     dx, ax
    mov    al, 
8
    
out     dx, al
    inc    dx
    mov    al, 0ffh
    shr    al, cl
    
out     dx, al
    push    cx
    mov    cx, 
16
    push    bx
@@
1 :
    xchg    al, [es:bx]
    add    bx, DMWIDTH
    loop    @@
1
    pop    bx
    pop    cx
    cmp    cl, 
0
    je    @@
3
    mov    al, 0ffh
    shr    al, cl
    not    al
    
out     dx, al
    push    cx
    mov    cx, 
16
    push    bx
    inc    bx
@@
2 :
    xchg    al, [es:bx]
    add    bx, DMWIDTH
    loop    @@
2
    pop    bx
    pop    cx
@@
3 :
    mov    ah, ch
    and    ax, 0f00h
    mov    dx, 3ceh
    
out     dx, ax
    mov    ax, 0f01h
    
out     dx, ax
    mov    al, 
8
    
out     dx, al
    inc    dx
    push    cx
    push    bx
    push    si
    mov    ah, 
16
@@
4 :
    lodsb
    shr    al, cl
    
out     dx, al
    xchg    al, [es:bx]
    add    bx, DMWIDTH
    dec    ah
    jnz    @@
4
    pop    si
    pop    bx
    pop    cx
    cmp    cl, 
0
    je    @@
6
    push    cx
    push    bx
    push    si
    mov    ah, 
16
    inc    bx
    mov    ch, 
8
    sub    ch, cl
    mov    cl, ch
@@
5 :
    lodsb
    shl    al, cl
    
out     dx, al
    xchg    al, [es:bx]
    add    bx, DMWIDTH
    dec    ah
    jnz    @@
5
    pop    si
    pop    bx
    pop    cx
@@
6 :
    inc    bx
    ret
ENDP
;
void  Putch( int  ch,  int  n,  int  attr)
;
PROC    _Putch

    ARG    
char  : word, n : word, attr : word
    USES    si, di

    mov    ax, [
char ]
    call    GetchAddr
    cmp    [
byte  ChFlag],  0
    je    @@
2
    push    dx
    call    _HideCursor
    mov    ax, [ChX]
    mov    cl, al
    and    cl, 
7
    mov    ch, [
byte  attr]
    mov    bx, [ChY]
    call    GetDspMem
    pop    dx
    mov    di, [n]
@@
1 :
    xor    si, si
    cmp    [
byte  ChFlag],  2
    jne    @@
3
    dec    bx
@@
3 :
    call    PutchBin
    cmp    [
byte  ChFlag],  2
    jne    @@
4
    mov    si, 
16
    call    PutchBin
    dec    di
@@
4 :
    dec    di
    jg    @@
1
    call    RestReg0
    call    _ShowCursor
@@
2 :
    ret
ENDP
;
int  Putss( int  x,  int  y,  char   * s,  int  endx,  int  attr)
;
PROC    _Putss

    ARG    x : word, y : word, s : DPTR_, endx : word, attr : word
    USES    si, di

    call    _HideCursor
    mov    di, [x]
    mov    bx, [y]
    cmp    bx, MAXY
- 15
    ja    @@
5
    mov    [ChY], bx
    mov    ax, di
    cmp    ax, MAXX
- 7
    ja    @@
5
    mov    cl, al
    and    cl, 
7
    mov    ch, [
byte  attr]
    call    GetDspMem
    mov    si, [word s]
    cld
@@
1 :
    cmp    di, [endx]
    jge    @@
4
IF LDATA
    push    ds
    push    [word s
+ 2 ]
    pop    ds
    lodsb
    pop    ds
ELSE
    lodsb
ENDIF
    cmp    al, 20h
    jb    @@
4
    push    es
    push    cx
    call    GetchAddr
    pop    cx
    pop    es
    add    di, 
8
    cmp    [
byte  ChFlag],  0
    je    @@
1
    push    si
    xor    si, si
    call    PutchBin
    cmp    [
byte  ChFlag],  2
    jne    @@
3
    mov    si, 
16
    call    PutchBin
@@
3 :
    pop    si
    jmp    
short  @@ 1
@@
4 :
    mov    [
byte  HighCh],  0
    call    RestReg0
@@
5 :
    mov    [ChX], di
    call    _ShowCursor
    mov    ax, di
    sub    ax, [x]
    shr    ax, 
3
    ret
ENDP
;
    END

图形函数文件就结束了,没想到这么长,下一篇给出一个鼠标函数文件和XSM文件。

         再次声明,这几篇文章的代码是1995年前的东西,用现在的眼光去看它们,还不知道是不是C函数,只能供初学者们借鉴参考。至于是否有错误,我就不得而知了,不过,我以前使用时,没出过什么问题。有错误或建议,请来信:maozefa@hotmail.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值