Subversion Repositories Kolibri OS

Rev

Rev 9237 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9237 leency 1
CATMULL_SHIFT equ 16
2
 
3
 
4
flat_triangle_z:
5
;  procedure drawing triangle with Z cordinate interpolation ------
6
;  (Catmull  alghoritm)--------------------------------------------
7
;  ----------------in - eax - x1 shl 16 + y1 ----------------------
8
;  -------------------- ebx - x2 shl 16 + y2 ----------------------
9
;  -------------------- ecx - x3 shl 16 + y3 ----------------------
10
;  -------------------- edx - color 0x00RRGGBB --------------------
11
;  -------------------- esi - pointer to Z-buffer -----------------
12
;  -------------------- edi - pointer to screen buffer-------------
13
;  -------------------- stack : z coordinates
14
;  -------------------- Z-buffer : each z variable as dword
15
;  -------------------- (Z coor. as word) shl CATMULL_SHIFT
9512 IgorA 16
.z1     equ word[ebp+4]
17
.z2     equ word[ebp+6]    ; each z coordinate as word integer
18
.z3     equ word[ebp+8]
9237 leency 19
 
9512 IgorA 20
.col    equ dword[ebp-4]
21
.x1     equ word[ebp-6]
22
.y1     equ word[ebp-8]
23
.x2     equ word[ebp-10]
24
.y2     equ word[ebp-12]
25
.x3     equ word[ebp-14]
26
.y3     equ word[ebp-16]
9237 leency 27
 
9512 IgorA 28
.dx12   equ dword[ebp-20]
29
.dz12   equ dword[ebp-24]
30
.dx13   equ dword[ebp-28]
31
.dz13   equ dword[ebp-32]
32
.dx23   equ dword[ebp-36]
33
.dz23   equ dword[ebp-40]
34
.zz1    equ dword[ebp-44]
35
.zz2    equ dword[ebp-48]
9237 leency 36
 
9512 IgorA 37
        mov     ebp,esp
38
 
39
        push    edx            ; store edx in variable .col
9237 leency 40
      .sort2:
9512 IgorA 41
        cmp     ax,bx
42
        jle     .sort1
43
        xchg    eax,ebx
44
        mov     dx,.z1
45
        xchg    dx,.z2
46
        mov     .z1,dx
9237 leency 47
      .sort1:
9512 IgorA 48
        cmp     bx,cx
49
        jle     .sort3
50
        xchg    ebx,ecx
51
        mov     dx,.z2
52
        xchg    dx,.z3
53
        mov     .z2,dx
54
        jmp     .sort2
9237 leency 55
      .sort3:
9512 IgorA 56
        push    eax            ; store triangle coordinates in user friendly variables
57
        push    ebx
58
        push    ecx
59
         mov      edx,80008000h  ; eax,ebx,ecx are ANDd together into edx which means that
60
         and      edx,ebx        ; if *all* of them are negative a sign flag is raised
61
         and      edx,ecx
62
         and      edx,eax
63
         test     edx,80008000h  ; Check both X&Y at once
64
         jne      .ft_loop2_end
9237 leency 65
       ;  cmp      ax,SIZE_Y
66
       ;  jle      @f
67
       ;  cmp      bx,SIZE_Y
68
       ;  jle      @f
69
       ;  cmp      cx,SIZE_Y
70
       ;  jge      @f
71
       ;  ror      eax,16
72
       ;  ror      ebx,16
73
       ;  ror      ecx,16
74
       ;  cmp      ax,SIZE_X
75
       ;  jle      @f
76
       ;  cmp      bx,SIZE_X
77
       ;  jle      @f
78
       ;  cmp      cx,SIZE_X
79
       ;  jle      @f
80
       ;  jmp      .ft_loop2_end
81
       ;@@:
9512 IgorA 82
  ;      sub     esp,52-12
9237 leency 83
 
9512 IgorA 84
        mov     bx,.y2       ; calc delta 12
85
        sub     bx,.y1
86
        jnz     .ft_dx12_make
87
        push    dword 0
88
        push    dword 0
89
        jmp     .ft_dx12_done
9237 leency 90
   .ft_dx12_make:
9512 IgorA 91
        mov     ax,.x2
92
        sub     ax,.x1
93
        cwde
94
        movsx   ebx,bx
95
        shl     eax,ROUND
96
        cdq
97
        idiv    ebx
98
        push    eax
9237 leency 99
 
9512 IgorA 100
        mov     ax,.z2
101
        sub     ax,.z1
102
        cwde
103
        shl     eax,CATMULL_SHIFT
104
        cdq
105
        idiv    ebx
106
        push    eax
9237 leency 107
  .ft_dx12_done:
9512 IgorA 108
        mov     bx,.y3       ; calc delta 13
109
        sub     bx,.y1
110
        jnz     .ft_dx13_make
111
        push    dword 0
112
        push    dword 0
113
        jmp     .ft_dx13_done
9237 leency 114
   .ft_dx13_make:
9512 IgorA 115
        mov     ax,.x3
116
        sub     ax,.x1
117
        cwde
118
        movsx   ebx,bx
119
        shl     eax,ROUND
120
        cdq
121
        idiv    ebx
122
        push    eax
9237 leency 123
 
9512 IgorA 124
        mov     ax,.z3
125
        sub     ax,.z1
126
        cwde
127
        shl     eax,CATMULL_SHIFT
128
        cdq
129
        idiv    ebx
130
        push    eax
131
 
9237 leency 132
    .ft_dx13_done:
9512 IgorA 133
    ;    sub     esp,48
134
        mov     bx,.y3       ; calc delta 23
135
        sub     bx,.y2
136
        jnz     .gt_dx23_make
137
        push    dword 0
138
        push    dword 0
139
    ;    mov     .dx23,0
140
    ;    mov     .dz23,0
141
        jmp     .gt_dx23_done
9237 leency 142
   .gt_dx23_make:
9512 IgorA 143
        mov     ax,.x3
144
        sub     ax,.x2
145
        cwde
146
        movsx   ebx,bx
147
        shl     eax,ROUND
148
        cdq
149
        idiv    ebx
150
        push    eax
9237 leency 151
 
9512 IgorA 152
        mov     ax,.z3
153
        sub     ax,.z2
154
        cwde
155
        shl     eax,CATMULL_SHIFT
156
        cdq
157
        idiv    ebx
158
        push    eax
159
    ;    mov     .dz23,eax
9237 leency 160
    .gt_dx23_done:
161
 
9512 IgorA 162
        movsx   edx,.z1
163
        shl     edx,CATMULL_SHIFT
164
        push    edx
165
        push    edx
166
 
167
        movsx   eax,.x1
168
        shl     eax,ROUND    ; eax - x1
169
        mov     ebx,eax      ; ebx - x2
170
        mov     cx,.y1
171
        cmp     cx,.y2
172
        jge     .ft_loop1_end
9237 leency 173
     .ft_loop1:
174
 
9512 IgorA 175
        pushad
9237 leency 176
 
9512 IgorA 177
        push    .col
178
        push    cx          ; y
179
        sar     ebx,ROUND
180
        push    bx          ; x2
181
        sar     eax,ROUND
182
        push    ax          ; x1
183
        push    .zz2        ; z2 shl CATMULL_SHIFT
184
        push    .zz1        ; z1 shl CATMULL_SHIFT
9237 leency 185
 
9512 IgorA 186
        call    flat_line_z
9237 leency 187
 
9512 IgorA 188
        popad
9237 leency 189
 
9512 IgorA 190
        add     eax,.dx13
191
        add     ebx,.dx12
192
 
193
        mov     edx,.dz13
194
        add     .zz1,edx
195
        mov     edx,.dz12
196
        add     .zz2,edx
9237 leency 197
;end if
9512 IgorA 198
        inc     cx
199
        cmp     cx,.y2
200
        jl      .ft_loop1
9237 leency 201
    .ft_loop1_end:
202
 
9512 IgorA 203
        movsx   edx,.z2
204
        shl     edx,CATMULL_SHIFT
205
        mov     .zz2,edx
206
        movsx   ebx,.x2
207
        shl     ebx,ROUND
208
 
209
        mov     cx,.y2
210
        cmp     cx,.y3
211
        jge     .ft_loop2_end
9237 leency 212
     .ft_loop2:
9512 IgorA 213
        pushad
9237 leency 214
 
9512 IgorA 215
        push    .col
216
        push    cx
217
        sar     ebx,ROUND
218
        push    bx
219
        sar     eax,ROUND
220
        push    ax          ; x1
9237 leency 221
 
9512 IgorA 222
        push    .zz2        ; z2 shl CATMULL_SHIFT
223
        push    .zz1        ; z1 shl CATMULL_SHIFT
9237 leency 224
 
9512 IgorA 225
        call    flat_line_z
9237 leency 226
 
9512 IgorA 227
        popad
228
 
229
        add     eax,.dx13
230
        add     ebx,.dx23
231
 
232
        mov     edx,.dz13
233
        add     .zz1,edx
234
        mov     edx,.dz23
235
        add     .zz2,edx
236
 
237
        inc     cx
238
        cmp     cx,.y3
239
        jl      .ft_loop2
9237 leency 240
     .ft_loop2_end:
241
 
9512 IgorA 242
        mov esp,ebp
9237 leency 243
ret 6
244
 
245
flat_line_z:
246
;----------------
247
;-------------in edi - pointer to screen buffer ----------------------------------
248
;--------------- esi - pointer to z-buffer (each Z varible dword)-----------------
249
;----------stack - (each z coordinate shifted shl CATMULL_SHIFT)------------------
250
.z1 equ dword [ebp+4]
251
.z2 equ dword [ebp+8]
252
.x1 equ word  [ebp+12]
253
.x2 equ word  [ebp+14]
254
.y  equ word  [ebp+16]
255
.col equ dword [ebp+18]
256
 
257
.dz equ dword [ebp-4]
258
 
9512 IgorA 259
     mov        ebp,esp
9237 leency 260
;;     sub        esp,4
9512 IgorA 261
     mov        ax,.y
262
     or         ax,ax
263
     jl         .fl_quit
264
     mov        bx,[size_y_var]
265
     dec        bx
266
     cmp        ax,bx ;[size_y_var]
9237 leency 267
  ;   cmp        ax,SIZE_Y-1
9512 IgorA 268
     jg         .fl_quit
9237 leency 269
 
270
 ;    cmp        .x1,0
271
 ;    jge        .fl_ok1
272
 ;    cmp        .x2,0
273
 ;    jl         .fl_quit
274
 ;  .fl_ok1:
275
 ;    cmp        .x1,SIZE_X
276
 ;    jle        .fl_ok2
277
 ;    cmp        .x2,SIZE_X
278
 ;    jg         .fl_quit
279
 ;  .fl_ok2:
9512 IgorA 280
     mov        ax,.x1
281
     cmp        ax,.x2
282
     je         .fl_quit
283
     jl         .fl_ok
9237 leency 284
 
9512 IgorA 285
     xchg       ax,.x2
286
     mov        .x1,ax
287
     mov        edx,.z1
288
     xchg       edx,.z2
289
     mov        .z1,edx
9237 leency 290
   .fl_ok:
9512 IgorA 291
     mov        bx,[size_x_var]
292
     dec        bx
293
     cmp        .x1,bx ;SIZE_X-1
294
     jg         .fl_quit
295
     cmp        .x2,0
296
     jle        .fl_quit
9237 leency 297
 
9512 IgorA 298
     mov        eax,.z2
299
     sub        eax,.z1
9237 leency 300
     cdq
9512 IgorA 301
     mov        bx,.x2
302
     sub        bx,.x1
303
     movsx      ebx,bx
304
     idiv       ebx
9237 leency 305
;;     mov        .dz,eax                ; calculated delta - shifted .dz
9512 IgorA 306
     push       eax
9237 leency 307
 
9512 IgorA 308
     cmp        .x1,0
309
     jge        @f
310
     movsx      ebx,.x1
311
     neg        ebx
312
     imul       ebx
313
     add        .z1,eax
314
     mov        .x1,0
9237 leency 315
    @@:
9512 IgorA 316
     movzx      edx,word[size_x_var]
317
     cmp        .x2,dx ;[size_x_var] ;SIZE_X
318
     jl         @f
319
     mov        .x2,dx ;[size_x_var] ;SIZE_X
9237 leency 320
    @@:
321
 ;    movzx      edx,[size_x_var] ;SIZE_X
9512 IgorA 322
     movsx      eax,.y
323
     mul        edx                  ; edi = edi + (SIZE_X * y + x1)*3
324
     movsx      edx,.x1
325
     add        eax,edx
326
     push       eax
327
     lea        eax,[eax*3]
328
     add        edi,eax              ; esi = esi + (SIZE_X * y + x1)*4
329
     pop        eax
330
     shl        eax,2
331
     add        esi,eax
9237 leency 332
 
9512 IgorA 333
     mov        cx,.x2
334
     sub        cx,.x1
335
     movzx      ecx,cx
9237 leency 336
 
9512 IgorA 337
     mov        eax,.col
338
     mov        ebx,.z1  ; ebx : curr. z
339
     mov        edx,.dz
340
     dec        ecx
341
     jecxz      .draw_last
9237 leency 342
   .ddraw:
9512 IgorA 343
     cmp        ebx,dword[esi]
344
  ;   cmovl      [edi],eax
345
  ;   cmovl      [esi],ebx
346
     jge        @f
347
     mov        [edi],eax
348
     mov        [esi],ebx
349
  ;   stosd          ; less branches
350
  ;   dec        edi
351
  ;   mov        dword[esi],ebx
352
  ;   jmp        .no_skip
9237 leency 353
   @@:
9512 IgorA 354
     add        edi,3
355
  ; .no_skip:
356
     add        esi,4
357
     add        ebx,edx
358
     loop       .ddraw
9237 leency 359
 
360
   .draw_last:
9512 IgorA 361
     cmp        ebx,dword[esi]
362
     jge        .fl_quit
9237 leency 363
     stosw
9512 IgorA 364
     shr        eax,16
9237 leency 365
     stosb
9512 IgorA 366
     mov        dword[esi],ebx
9237 leency 367
 
368
   .fl_quit:
369
 
370
     mov   esp,ebp
371
ret 18