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