[Reduction] #478: grcg_polygon_cx

This commit is contained in:
nmlgc 2014-09-07 02:39:52 +02:00
parent 9bb41bd72b
commit 0acdb448d1
2 changed files with 306 additions and 213 deletions

View File

@ -0,0 +1,304 @@
; gc_poly library - polygon - convex - nonclip
;
; Description:
; 凸多角形の描画 高速(機能削減)版
;
; Funciton/Procedures:
; void grcg_polygon_cx( const Point PTRPAT * pts, int npoint ) ;
;
; Parameters:
; Point * pts 座標リスト
; int npoint 座標数
;
; Binding Target:
; Microsoft-C / Turbo-C / Turbo Pascal
;
; Running Target:
; NEC PC-9801 Normal mode
;
; Requiring Resources:
; CPU: V30
; GRAPHICS ACCELARATOR: GRAPHIC CHARGER
;
; Notes:
; ・色指定は、グラフィックチャージャーを使用してください。
; ・クリッピングは一切行っていません。grc_clip_polygon_n()を利用して
;  データのクリッピングを先に行ってから呼んで下さい。
; ・データが凸多角形になっていないと、正しく描画しません。
; ・npoint が 0 以下の場合、描画しません。
; ・npoint が 1〜2 の場合、grcg_lineを呼び出します。
;
; Compiler/Assembler:
; TASM 3.0
; OPTASM 1.6
;
; Author:
; 恋塚昭彦
;
; 関連関数:
; grc_clip_polygon_n()
;
; Revision History:
; 92/ 7/11 Initial
; 92/ 7/18 点が少ないときの処理
; 93/ 6/28 2点以下のとき、large modelでおかしかったかも
;
; make_linework - DDA LINE用構造体の作成
; IN:
; DS:BX : LINEWORK * w ; 書き込み先
; DX : int x1 ; 上点のx
; AX : int x2 ; 下の点のx
; CX : int y2 - y1 ; 上下のyの差
; draw_trapezoidx - 台形の描画 高速(機能削減)版
; IN:
; SI : unsigned yadr ; 描画する三角形の上のラインの左端のVRAMオフセット
; DX : unsigned ylen ; 描画する三角形の上下のライン差(y2-y1)
; ES : unsigned gseg ; 描画するVRAMのセグメント(ClipYT_seg)
; trapez_a ; 側辺a(必ず左)のxの初期値と傾き
; trapez_b ; 側辺b(必ず右)のxの初期値と傾き
IF datasize EQ 2
MOVPTS macro to, from
mov to,ES:from
endm
PUSHPTS macro from
push word ptr ES:from
endm
ESPTS macro
mov ES,[BP+@@pts+2]
endm
ESVRAM macro
mov ES,ClipYT_seg
endm
ELSE
MOVPTS macro to, from
mov to,from
endm
PUSHPTS macro from
push from
endm
ESPTS macro
endm
ESVRAM macro
endm
ENDIF
MRETURN macro
pop DI
pop SI
leave
ret (DATASIZE+1)*2
EVEN
endm
;---------------------------------
; void RETPAT pascal grcg_polygon_cx( const Point PTRPAT * pts, int npoint ) ;
func GRCG_POLYGON_CX
enter 12,0
push SI
push DI
; 引数
@@pts = (RETSIZE+2)*2
@@npoint = (RETSIZE+1)*2
; ローカル変数
@@nl = -10
@@nr = -12
@@ly = -4
@@ry = -2
@@ty = -6
@@by = -8
if datasize eq 1
mov ES,ClipYT_seg
mov DI,[BP+@@pts]
else
les DI,[BP+@@pts]
endif
; 頂点を探す〜
mov SI,[BP+@@npoint] ; SI=npoint-1
dec SI
js short @@RETURN
mov [BP+@@nr],SI
mov DX,SI ; DX:nl
mov AX,SI
shl AX,2
add DI,AX
MOVPTS BX,[DI+2] ; BX:ty
mov CX,BX ; CX:by
dec SI
jg short @@LOOP1 ; ...LOOP1E
; 1〜2点なら直線
PUSHPTS [DI] ; pts[npoint-1].x
push BX ; pts[npoint-1].y
mov DI,[BP+@@pts]
PUSHPTS [DI] ; pts[0].x
PUSHPTS [DI+2] ; pts[0].y
call GRCG_LINE
@@RETURN:
MRETURN
@@LOOP1:
sub DI,4
MOVPTS AX,[DI+2]
cmp AX,BX ; ty
je short @@L1_010
jg short @@L1_020
mov [BP+@@nr],SI
mov DX,SI ; nl
mov BX,AX ; ty
jmp short @@L1_030
@@L1_010:
mov DX,SI ; nl
jmp short @@L1_030
@@L1_020:
cmp CX,AX ; by
jge short @@L1_030
mov CX,AX ; by
@@L1_030:
dec SI
jns short @@LOOP1
@@LOOP1E:
or DX,DX ; nl
jne short @@L1_100
mov AX,[BP+@@npoint]
dec AX
cmp AX,[BP+@@nr]
jne short @@L1_100
mov DX,AX
mov WORD PTR [BP+@@nr],0
@@L1_100:
mov [BP+@@by],CX
mov DI,[BP+@@pts]
; 最初の左側辺データを作成
mov BX,DX ; BX=nl
dec BX
jge short @@L2_010
mov BX,[BP+@@npoint]
dec BX
@@L2_010:
mov [BP+@@nl],BX
shl BX,2
add BX,DI
mov SI,DX
shl SI,2
add SI,DI
MOVPTS CX,[BX+2]
mov [BP+@@ly],CX
MOVPTS AX,[SI+2]
mov [BP+@@ty],AX
MOVPTS DX,[SI]
sub CX,AX
MOVPTS AX,[BX]
mov BX,offset trapez_a
call make_linework
; 最初の右側辺データを作成
mov SI,[BP+@@nr]
mov DX,SI ; DX
inc SI
cmp SI,[BP+@@npoint]
jl short @@L3_010
xor SI,SI
@@L3_010:
mov BX,SI
mov [BP+@@nr],SI
shl BX,2
MOVPTS AX,[BX+DI+2]
mov [BP+@@ry],AX
mov CX,BX
mov BX,DX
shl BX,2
MOVPTS DX,[BX+DI]
mov BX,CX
; 実際に描画していくんだ[よーん]
@@L4_010:
sub AX,[BP+@@ty]
mov CX,AX
MOVPTS AX,[BX+DI]
mov BX,offset trapez_b
call make_linework
mov [BP+@@nr],SI
@@LOOP4:
mov SI,[BP+@@ly]
cmp SI,[BP+@@ry]
jle short @@L4_020
mov SI,[BP+@@ry]
@@L4_020:
cmp [BP+@@by],SI
jle short @@LAST_ZOID
push SI
push DI
lea DX,[SI-1]
xchg SI,[BP+@@ty]
sub DX,SI
sub SI,ClipYT
imul SI,SI,80
ESVRAM
call draw_trapezoidx ; 一番下でない台形
ESPTS
pop DI
pop SI
cmp SI,[BP+@@ly]
jne short @@L4_040
; 左側の側辺
mov CX,[BP+@@nl]
mov BX,CX
shl BX,2
MOVPTS DX,[BX+DI] ; DX!
dec CX
jns short @@L4_030
mov CX,[BP+@@npoint]
mov BX,CX
shl BX,2
dec CX
@@L4_030:
mov [BP+@@nl],CX
sub BX,4
add BX,DI
MOVPTS CX,[BX+2]
mov [BP+@@ly],CX
sub CX,[BP+@@ty]
MOVPTS AX,[BX]
mov BX,OFFSET trapez_a
call make_linework
@@L4_040:
mov AX,[BP+@@ry]
cmp [BP+@@ty],AX
jne short @@LOOP4
; 右側の側辺
mov SI,[BP+@@nr]
mov BX,SI
shl BX,2
MOVPTS DX,[BX+DI] ; DX!
inc SI
cmp SI,[BP+@@npoint]
jl short @@L4_050
xor SI,SI
@@L4_050:
mov BX,SI
shl BX,2
MOVPTS AX,[BX+DI+2]
mov [BP+@@ry],AX
jmp @@L4_010
@@LAST_ZOID:
; 一番下の台形
ESVRAM
mov SI,[BP+@@ty]
mov DX,[BP+@@by]
sub DX,SI
sub SI,ClipYT
imul SI,SI,80
call draw_trapezoidx
MRETURN
endfunc

View File

@ -66,218 +66,7 @@ include libs/master.lib/grc_setclip.asm
include libs/master.lib/grc_clip_polygon_n.asm
include libs/master.lib/grcg_hline.asm
include libs/master.lib/grcg_line.asm
; =============== S U B R O U T I N E =======================================
; Attributes: bp-based frame
sub_18B4 proc far
var_C = word ptr -0Ch
var_A = word ptr -0Ah
var_8 = word ptr -8
var_6 = word ptr -6
var_4 = word ptr -4
var_2 = word ptr -2
arg_0 = word ptr 6
arg_2 = dword ptr 8
enter 0Ch, 0
push si
push di
les di, [bp+arg_2]
mov si, [bp+arg_0]
dec si
js short loc_18EA
mov [bp+var_C], si
mov dx, si
mov ax, si
shl ax, 2
add di, ax
mov bx, es:[di+2]
mov cx, bx
dec si
jg short loc_18F0
push word ptr es:[di]
push bx
mov di, word ptr [bp+arg_2]
push word ptr es:[di]
push word ptr es:[di+2]
call grcg_line
loc_18EA:
pop di
pop si
leave
retf 6
; ---------------------------------------------------------------------------
loc_18F0:
sub di, 4
mov ax, es:[di+2]
cmp ax, bx
jz short loc_1906
jg short loc_190A
mov [bp+var_C], si
mov dx, si
mov bx, ax
jmp short loc_1910
; ---------------------------------------------------------------------------
loc_1906:
mov dx, si
jmp short loc_1910
; ---------------------------------------------------------------------------
loc_190A:
cmp cx, ax
jge short loc_1910
mov cx, ax
loc_1910:
dec si
jns short loc_18F0
or dx, dx
jnz short loc_1927
mov ax, [bp+arg_0]
dec ax
cmp ax, [bp+var_C]
jnz short loc_1927
mov dx, ax
mov [bp+var_C], 0
loc_1927:
mov [bp+var_8], cx
mov di, word ptr [bp+arg_2]
mov bx, dx
dec bx
jge short loc_1936
mov bx, [bp+arg_0]
dec bx
loc_1936:
mov [bp+var_A], bx
shl bx, 2
add bx, di
mov si, dx
shl si, 2
add si, di
mov cx, es:[bx+2]
mov [bp+var_4], cx
mov ax, es:[si+2]
mov [bp+var_6], ax
mov dx, es:[si]
sub cx, ax
mov ax, es:[bx]
mov bx, 2630h
call make_linework
mov si, [bp+var_C]
mov dx, si
inc si
cmp si, [bp+arg_0]
jl short loc_196E
xor si, si
loc_196E:
mov bx, si
mov [bp+var_C], si
shl bx, 2
mov ax, es:[bx+di+2]
mov [bp+var_2], ax
mov cx, bx
mov bx, dx
shl bx, 2
mov dx, es:[bx+di]
mov bx, cx
loc_1989:
sub ax, [bp+var_6]
mov cx, ax
mov ax, es:[bx+di]
mov bx, 2638h
call make_linework
mov [bp+var_C], si
loc_199A:
mov si, [bp+var_4]
cmp si, [bp+var_2]
jle short loc_19A5
mov si, [bp+var_2]
loc_19A5:
cmp [bp+var_8], si
jle short loc_1A28
push si
push di
lea dx, [si-1]
xchg si, [bp+var_6]
sub dx, si
sub si, ClipYT
imul si, 50h
mov es, ClipYT_seg
call draw_trapezoidx
mov es, word ptr [bp+arg_2+2]
pop di
pop si
cmp si, [bp+var_4]
jnz short loc_19FE
mov cx, [bp+var_A]
mov bx, cx
shl bx, 2
mov dx, es:[bx+di]
dec cx
jns short loc_19E3
mov cx, [bp+arg_0]
mov bx, cx
shl bx, 2
dec cx
loc_19E3:
mov [bp+var_A], cx
sub bx, 4
add bx, di
mov cx, es:[bx+2]
mov [bp+var_4], cx
sub cx, [bp+var_6]
mov ax, es:[bx]
mov bx, 2630h
call make_linework
loc_19FE:
mov ax, [bp+var_2]
cmp [bp+var_6], ax
jnz short loc_199A
mov si, [bp+var_C]
mov bx, si
shl bx, 2
mov dx, es:[bx+di]
inc si
cmp si, [bp+arg_0]
jl short loc_1A19
xor si, si
loc_1A19:
mov bx, si
shl bx, 2
mov ax, es:[bx+di+2]
mov [bp+var_2], ax
jmp loc_1989
; ---------------------------------------------------------------------------
loc_1A28:
mov es, ClipYT_seg
mov si, [bp+var_6]
mov dx, [bp+var_8]
sub dx, si
sub si, ClipYT
imul si, 50h
call draw_trapezoidx
pop di
pop si
leave
retf 6
sub_18B4 endp
include libs/master.lib/grcg_polygon_cx.asm
include libs/master.lib/grcg_pset.asm
include libs/master.lib/grcg_setcolor.asm
include libs/master.lib/grcg_vline.asm
@ -9466,7 +9255,7 @@ loc_EA61:
push ss
push di
push ax
call sub_18B4
call grcg_polygon_cx
xor ax, ax
jmp short loc_EA70
; ---------------------------------------------------------------------------