Subversion Repositories Kolibri OS

Rev

Rev 1245 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1245 Rev 6619
1
draw_triangle:
1
draw_triangle:
2
    ;----------in - eax - x1 shl 16 + y1
2
    ;----------in - eax - x1 shl 16 + y1
3
    ;------------- -ebx - x2 shl 16 + y2
3
    ;------------- -ebx - x2 shl 16 + y2
4
    ;---------------ecx - x3 shl 16 + y3
4
    ;---------------ecx - x3 shl 16 + y3
5
    ;---------------edx - color 0x00rrggbb
5
    ;---------------edx - color 0x00rrggbb
6
    ;---------------edi - pointer to screen buffer
6
    ;---------------edi - pointer to screen buffer
7
 
7
 
8
	.col equ ebp-4	;dd      ?
8
	.col equ ebp-4	;dd      ?
9
	.x1  equ ebp-6	;dw      ?
9
	.x1  equ ebp-6	;dw      ?
10
	.y1  equ  ebp-8  ;dw      ?;+8
10
	.y1  equ  ebp-8  ;dw      ?;+8
11
	.x2  equ  ebp-10 ;dw      ?
11
	.x2  equ  ebp-10 ;dw      ?
12
	.y2  equ  ebp-12 ;dw      ?
12
	.y2  equ  ebp-12 ;dw      ?
13
	.x3  equ  ebp-14  ;dw      ?
13
	.x3  equ  ebp-14  ;dw      ?
14
	.y3  equ  ebp-16  ;dw      ?;+16
14
	.y3  equ  ebp-16  ;dw      ?;+16
15
	.dx12 equ  ebp-20  ;  dd      ?
15
	.dx12 equ  ebp-20  ;  dd      ?
16
	.dx13 equ  ebp-24  ;  dd      ?;+24
16
	.dx13 equ  ebp-24  ;  dd      ?;+24
17
	.dx23 equ  ebp-28  ;  dd      ?
17
	.dx23 equ  ebp-28  ;  dd      ?
18
 
18
 
19
	mov	ebp,esp
19
	mov	ebp,esp
20
      ;  sub     esp,28
20
      ;  sub     esp,28
21
	push	edx
21
	push	edx
22
    .ch3:
22
    .ch3:
23
	cmp	ax,bx
23
	cmp	ax,bx
24
	jg	.ch1
24
	jg	.ch1
25
    .ch4:			; sort parameters
25
    .ch4:			; sort parameters
26
	cmp	bx,cx
26
	cmp	bx,cx
27
	jg	.ch2
27
	jg	.ch2
28
	jle	.chEnd
28
	jle	.chEnd
29
    .ch1:
29
    .ch1:
30
	xchg	eax,ebx
30
	xchg	eax,ebx
31
	jmp	.ch4
31
	jmp	.ch4
32
    .ch2:
32
    .ch2:
33
	xchg	ebx,ecx
33
	xchg	ebx,ecx
34
	jmp	.ch3
34
	jmp	.ch3
35
    .chEnd:
35
    .chEnd:
36
     ;   mov     dword[.y1],eax  ; ..and store to user friendly  variables
36
     ;   mov     dword[.y1],eax  ; ..and store to user friendly  variables
37
     ;   mov     dword[.y2],ebx
37
     ;   mov     dword[.y2],ebx
38
     ;   mov     dword[.y3],ecx
38
     ;   mov     dword[.y3],ecx
39
     ;   mov     [.col],edx
39
     ;   mov     [.col],edx
40
	push	eax
40
	push	eax
41
	push	ebx
41
	push	ebx
42
	push	ecx
42
	push	ecx
43
	sub	esp,12
43
	sub	esp,12
44
	mov	edx,eax 	; eax,ebx,ecx are ORd together into edx which means that
44
	mov	edx,eax 	; eax,ebx,ecx are ORd together into edx which means that
45
	or	edx,ebx 	; if any *one* of them is negative a sign flag is raised
45
	or	edx,ebx 	; if any *one* of them is negative a sign flag is raised
46
	or	edx,ecx
46
	or	edx,ecx
47
	test	edx,80008000h	; Check both X&Y at once
47
	test	edx,80008000h	; Check both X&Y at once
48
	jne	.end_triangle
48
	jne	.end_triangle
-
 
49
 
49
 
50
	mov	dx,[size_x_var]
50
	cmp	word[.x1],SIZE_X    ; {
51
	cmp	word[.x1],dx  ;SIZE_X    ; {
51
	jg	.end_triangle
52
	jg	.end_triangle
52
	cmp	word[.x2],SIZE_X     ; This can be optimized with effort
53
	cmp	word[.x2],dx  ;SIZE_X     ; This can be optimized with effort
53
	jg	.end_triangle
54
	jg	.end_triangle
54
	cmp	word[.x3],SIZE_X
55
	cmp	word[.x3],dx  ;SIZE_X
55
	jg	.end_triangle	; }
56
	jg	.end_triangle	; }
56
 
57
 
57
	shr	eax,16
58
	shr	eax,16
58
	shr	ebx,16
59
	shr	ebx,16
59
	shr	ecx,16
60
	shr	ecx,16
60
 
61
 
61
	neg	ax		; calculate delta 12
62
	neg	ax		; calculate delta 12
62
	add	ax,bx
63
	add	ax,bx
63
	cwde
64
	cwde
64
	shl	eax,ROUND
65
	shl	eax,ROUND
65
	cdq
66
	cdq
66
	mov	bx,[.y2]
67
	mov	bx,[.y2]
67
	mov	cx,[.y1]
68
	mov	cx,[.y1]
68
	sub	bx,cx
69
	sub	bx,cx
69
	;cmp     ebx,0
70
	;cmp     ebx,0
70
	jne	.noZero1
71
	jne	.noZero1
71
	mov	dword[.dx12],0
72
	mov	dword[.dx12],0
72
	jmp	.yesZero1
73
	jmp	.yesZero1
73
    .noZero1:
74
    .noZero1:
74
	idiv	ebx
75
	idiv	ebx
75
	mov	[.dx12],eax
76
	mov	[.dx12],eax
76
    .yesZero1:
77
    .yesZero1:
77
 
78
 
78
	mov	ax,[.x3]	; calculate delta 13
79
	mov	ax,[.x3]	; calculate delta 13
79
	sub	ax,[.x1]
80
	sub	ax,[.x1]
80
	cwde
81
	cwde
81
	shl	eax,ROUND
82
	shl	eax,ROUND
82
	cdq
83
	cdq
83
	mov	bx,[.y3]
84
	mov	bx,[.y3]
84
	mov	cx,[.y1]
85
	mov	cx,[.y1]
85
	sub	bx,cx
86
	sub	bx,cx
86
	;cmp     ebx,0
87
	;cmp     ebx,0
87
	jne	.noZero2
88
	jne	.noZero2
88
	mov	dword[.dx13],0
89
	mov	dword[.dx13],0
89
	jmp	.yesZero2
90
	jmp	.yesZero2
90
    .noZero2:
91
    .noZero2:
91
	idiv	ebx
92
	idiv	ebx
92
	mov	[.dx13],eax
93
	mov	[.dx13],eax
93
    .yesZero2:
94
    .yesZero2:
94
 
95
 
95
	mov	ax,[.x3]     ; calculate delta 23 [dx23]
96
	mov	ax,[.x3]     ; calculate delta 23 [dx23]
96
	sub	ax,[.x2]
97
	sub	ax,[.x2]
97
	cwde
98
	cwde
98
	shl	eax,ROUND
99
	shl	eax,ROUND
99
	cdq
100
	cdq
100
	mov	bx,[.y3]
101
	mov	bx,[.y3]
101
	mov	cx,[.y2]
102
	mov	cx,[.y2]
102
	sub	bx,cx
103
	sub	bx,cx
103
	;cmp     ebx,0
104
	;cmp     ebx,0
104
	jne	.noZero3
105
	jne	.noZero3
105
	mov	dword[.dx23],0
106
	mov	dword[.dx23],0
106
	jmp	.yesZero3
107
	jmp	.yesZero3
107
    .noZero3:
108
    .noZero3:
108
	idiv	ebx
109
	idiv	ebx
109
	mov	[.dx23],eax
110
	mov	[.dx23],eax
110
    .yesZero3:
111
    .yesZero3:
111
 
112
 
112
	movsx	eax,word[.x1]	; eax - xk1   ;;;
113
	movsx	eax,word[.x1]	; eax - xk1   ;;;
113
	shl	eax,ROUND
114
	shl	eax,ROUND
114
	mov	ebx,eax 	; ebx - xk2   ;;;
115
	mov	ebx,eax 	; ebx - xk2   ;;;
115
	movsx	esi,word[.y1]	; esi - y
116
	movsx	esi,word[.y1]	; esi - y
116
    .next_line1:
117
    .next_line1:
117
	mov	ecx,eax 	; ecx - x11
118
	mov	ecx,eax 	; ecx - x11
118
	sar	ecx,ROUND
119
	sar	ecx,ROUND
119
	mov	edx,ebx 	; edx - x12
120
	mov	edx,ebx 	; edx - x12
120
	sar	edx,ROUND
121
	sar	edx,ROUND
121
	cmp	ecx,edx
122
	cmp	ecx,edx
122
	jle	.nochg
123
	jle	.nochg
123
	xchg	ecx,edx
124
	xchg	ecx,edx
124
    .nochg:
125
    .nochg:
125
	pusha
126
	pusha
126
	mov	ebx,ecx
127
	mov	ebx,ecx
127
	sub	edx,ecx
128
	sub	edx,ecx
128
	mov	ecx,edx
129
	mov	ecx,edx
129
	mov	edx,esi
130
	mov	edx,esi
130
	mov	eax,[.col]
131
	mov	eax,[.col]
131
	call	.horizontal_line
132
	call	.horizontal_line
132
	popa
133
	popa
133
	add	eax,[.dx13]
134
	add	eax,[.dx13]
134
	add	ebx,[.dx12]
135
	add	ebx,[.dx12]
135
	inc	esi
136
	inc	esi
136
	cmp	si,[.y2]
137
	cmp	si,[.y2]
137
	jl	.next_line1
138
	jl	.next_line1
138
 
139
 
139
	movzx	esi,word[.y2]
140
	movzx	esi,word[.y2]
140
	movzx	ebx,word[.x2]
141
	movzx	ebx,word[.x2]
141
	shl	ebx,ROUND
142
	shl	ebx,ROUND
142
    .next_line2:
143
    .next_line2:
143
	mov	ecx,eax
144
	mov	ecx,eax
144
	sar	ecx,ROUND
145
	sar	ecx,ROUND
145
	mov	edx,ebx
146
	mov	edx,ebx
146
	sar	edx,ROUND
147
	sar	edx,ROUND
147
	cmp	ecx,edx
148
	cmp	ecx,edx
148
	jle	.nochg1
149
	jle	.nochg1
149
	xchg	ecx,edx
150
	xchg	ecx,edx
150
    .nochg1:
151
    .nochg1:
151
	pusha
152
	pusha
152
	mov	ebx,ecx
153
	mov	ebx,ecx
153
	sub	edx,ecx
154
	sub	edx,ecx
154
	mov	ecx,edx
155
	mov	ecx,edx
155
	mov	edx,esi
156
	mov	edx,esi
156
	mov	eax,[.col]
157
	mov	eax,[.col]
157
	call	.horizontal_line
158
	call	.horizontal_line
158
	popa
159
	popa
159
	add	eax,[.dx13]
160
	add	eax,[.dx13]
160
	add	ebx,[.dx23]
161
	add	ebx,[.dx23]
161
	inc	esi
162
	inc	esi
162
	cmp	si,[.y3]
163
	cmp	si,[.y3]
163
	jl	.next_line2
164
	jl	.next_line2
164
    .end_triangle:
165
    .end_triangle:
165
 
166
 
166
       mov     esp,ebp
167
       mov     esp,ebp
167
ret
168
ret
168
 
169
 
169
.horizontal_line:
170
.horizontal_line:
170
    ;---------in
171
    ;---------in
171
    ;---------eax - color of line,  0x00RRGGBB
172
    ;---------eax - color of line,  0x00RRGGBB
172
    ;---------ebx - x1 - x position of line begin
173
    ;---------ebx - x1 - x position of line begin
173
    ;---------ecx - lenght of line
174
    ;---------ecx - lenght of line
174
    ;---------edx - y position of line
175
    ;---------edx - y position of line
175
    ;---------edi - pointer to buffer
176
    ;---------edi - pointer to buffer
176
	jcxz	.end_hor_l
177
	jcxz	.end_hor_l
177
;        or      edx,edx
178
;        or      edx,edx
178
;        jl      .end_hor_l
179
;        jl      .end_hor_l
-
 
180
	movzx	esi,word[size_y_var]
179
	cmp	edx,SIZE_Y
181
	cmp	edx,esi  ;SIZE_Y
180
	jg	.end_hor_l
182
	jg	.end_hor_l
181
	push	eax
183
	push	eax
-
 
184
	movzx	eax,word[size_x_var]
182
	mov	eax,SIZE_X*3
185
	lea	eax,[eax*3]
-
 
186
   ;     mov     eax,SIZE_X*3
183
	mul	edx
187
	mul	edx
184
	add	edi,eax 	; calculate line begin adress
188
	add	edi,eax 	; calculate line begin adress
185
	;add     edi,ebx
189
	;add     edi,ebx
186
	;shl     ebx,1
190
	;shl     ebx,1
187
	lea	edi,[edi+ebx*2]
191
	lea	edi,[edi+ebx*2]
188
	add	edi,ebx
192
	add	edi,ebx
189
	pop	eax
193
	pop	eax
190
	cld
194
	cld
191
	;mov dword[edi-3],0000FF00h
195
	;mov dword[edi-3],0000FF00h
192
	dec	ecx
196
	dec	ecx
193
	jecxz	.last_pix
197
	jecxz	.last_pix
194
    .ddraw:			; Drawing horizontally:
198
    .ddraw:			; Drawing horizontally:
195
	;push    eax
199
	;push    eax
196
	stosd			; 4 bytes at a time
200
	stosd			; 4 bytes at a time
197
	dec edi 		; point to the 4th
201
	dec edi 		; point to the 4th
198
	loop	.ddraw
202
	loop	.ddraw
199
    .last_pix:
203
    .last_pix:
200
	stosw
204
	stosw
201
	shr	eax,16
205
	shr	eax,16
202
	stosb
206
	stosb
203
;        mov     byte[edi],0     ; The last 4th will be reset
207
;        mov     byte[edi],0     ; The last 4th will be reset
204
    .end_hor_l:
208
    .end_hor_l:
205
ret
209
ret