Subversion Repositories Kolibri OS

Rev

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

Rev 1931 Rev 1979
1
; application : View3ds ver. 0.057 - tiny .3ds files viewer.
1
; application : View3ds ver. 0.059 - tiny .3ds files viewer.
2
; compiler    : FASM
2
; compiler    : FASM
3
; system      : KolibriOS
3
; system      : KolibriOS
4
; author      : Macgub aka Maciej Guba
4
; author      : Macgub aka Maciej Guba
5
; email       : macgub3@wp.pl
5
; email       : macgub3@wp.pl
6
; web         : www.macgub.hekko.pl
6
; web         : www.macgub.hekko.pl
7
; Fell free to use this intro in your own distribution of KolibriOS/MenuetOS.
7
; Fell free to use this intro in your own distribution of KolibriOS/MenuetOS.
8
; Special greetings to all MenuetOS maniax in the world.
8
; Special greetings to all MenuetOS maniax in the world.
9
; I hope because my intros Christian Belive will be near to each of You.
9
; I hope because my intros Christian Belive will be near to each of You.
10
 
10
 
11
 
11
 
12
; Some adjustments made by Madis Kalme
12
; Some adjustments made by Madis Kalme
13
; madis.kalme@mail.ee
13
; madis.kalme@mail.ee
14
; I tried optimizing it a bit, but don't know if it was successful. The objects
14
; I tried optimizing it a bit, but don't know if it was successful. The objects
15
; can be:
15
; can be:
16
; 1) Read from a file (*.3DS standard)
16
; 1) Read from a file (*.3DS standard)
17
; 2) Written in manually (at the end of the code)
17
; 2) Written in manually (at the end of the code)
18
;include 'proc32.inc'
18
;include 'proc32.inc'
19
 
19
 
20
SIZE_X equ 512
20
SIZE_X equ 512
21
SIZE_Y equ 512				       ;      /////     I want definitely
21
SIZE_Y equ 512				       ;      /////     I want definitely
22
TIMEOUT equ 10				       ;     ------     say:
22
TIMEOUT equ 10				       ;     ------     say:
23
ROUND equ 10				       ;     \ @ @/     keep smiling every
23
ROUND equ 10				       ;     \ @ @/     keep smiling every
24
TEX_X equ 512	  ; texture width              ;      \ ./    / day.
24
TEX_X equ 512	  ; texture width              ;      \ ./    / day.
25
TEX_Y equ 512	  ;         height             ;       \/    /
25
TEX_Y equ 512	  ;         height             ;       \/    /
26
TEX_SHIFT equ 9  ; texture width shifting      ;     __||__ /
26
TEX_SHIFT equ 9  ; texture width shifting      ;     __||__ /
27
TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1	       ;   /|      |
27
TEXTURE_SIZE EQU (TEX_X * TEX_Y)-1	       ;   /|      |
28
TEX equ  SHIFTING ;  TEX={SHIFTING | FLUENTLY} ;  / \      /
28
TEX equ  SHIFTING ;  TEX={SHIFTING | FLUENTLY} ;  / \      /
29
FLUENTLY = 0				       ; /   |    |
29
FLUENTLY = 0				       ; /   |    |
30
SHIFTING = 1				       ;     ------
30
SHIFTING = 1				       ;     ------
31
CATMULL_SHIFT equ 8			       ;      |  |
31
CATMULL_SHIFT equ 8			       ;      |  |
32
LIGHT_SIZE equ 22			       ;      |  |
32
LIGHT_SIZE equ 22			       ;      |  |
33
NON   =   0				       ;     -/  \-
33
NON   =   0				       ;     -/  \-
34
MMX   =   1
34
MMX   =   1
35
SSE   =   2
35
SSE   =   2
36
Ext   =   MMX		     ;Ext={ NON | MMX | SSE}
36
SSE2  =   3
-
 
37
Ext   =   MMX		    ;Ext={ NON | MMX | SSE | SSE2 }
37
 
38
 
38
; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features)
39
; 0 for short names (Menuet-compatible), 1 for long names (Kolibri features)
39
USE_LFN = 1
40
USE_LFN = 1
40
 
41
 
41
use32
42
use32
42
	org    0x0
43
	org    0x0
43
	db     'MENUET01'	; 8 byte id
44
	db     'MENUET01'	; 8 byte id
44
	dd     0x01		; header version
45
	dd     0x01		; header version
45
	dd     START		; start of code
46
	dd     START		; start of code
46
	dd     I_END		; size of image
47
	dd     I_END		; size of image
47
	dd     MEM_END		; memory for app
48
	dd     MEM_END		; memory for app
48
	dd     MEM_END		; esp
49
	dd     MEM_END		; esp
49
	dd     I_Param		; I_Param
50
	dd     I_Param		; I_Param
50
	dd     0x0		; I_Icon
51
	dd     0x0		; I_Icon
51
 
52
 
52
START:	  ; start of execution
53
START:	  ; start of execution
53
	cld
54
	cld
54
	call   alloc_buffer_mem
55
	call   alloc_buffer_mem
55
	call   read_param
56
	call   read_param
56
	call   read_from_disk	 ; read, if all is ok eax = 0
57
	call   read_from_disk	 ; read, if all is ok eax = 0
57
	cmp    eax,0
58
	cmp    eax,0
58
	jne    .gen
59
	jne    .gen
59
	call   read_tp_variables ; init points and triangles count variables
60
	call   read_tp_variables ; init points and triangles count variables
60
	cmp    eax,0
61
	cmp    eax,0
61
	je     .gen
62
	je     .gen
62
	jmp    .malloc
63
	jmp    .malloc
63
    .gen:
64
    .gen:
64
     if USE_LFN
65
     if USE_LFN
65
	mov    [triangles_count_var],1000
66
	mov    [triangles_count_var],1000
66
	mov    [points_count_var],1000
67
	mov    [points_count_var],1000
67
	call   alloc_mem_for_tp
68
	call   alloc_mem_for_tp
68
     end if
69
     end if
69
	call   generate_object
70
	call   generate_object
70
	jmp    .opt
71
	jmp    .opt
71
    .malloc:
72
    .malloc:
72
     if USE_LFN
73
     if USE_LFN
73
	call   alloc_mem_for_tp
74
	call   alloc_mem_for_tp
74
     end if
75
     end if
75
	call   read_from_file
76
	call   read_from_file
76
    .opt:
77
    .opt:
77
	call   optimize_object1     ;  proc in file b_procs.asm
78
	call   optimize_object1     ;  proc in file b_procs.asm
78
				    ;  set point(0,0,0) in center and  calc all coords
79
				    ;  set point(0,0,0) in center and  calc all coords
79
				    ;  to be in <-1.0,1.0>
80
				    ;  to be in <-1.0,1.0>
80
	call   normalize_all_light_vectors
81
	call   normalize_all_light_vectors
81
	call   init_triangles_normals2
82
	call   init_triangles_normals2
82
	call   init_point_normals
83
	call   init_point_normals
83
	call   init_envmap2
84
	call   init_envmap2
84
	call   init_envmap_cub
85
	call   init_envmap_cub
85
	call   generate_texture2
86
	call   generate_texture2
86
	call   init_sincos_tab
87
	call   init_sincos_tab
87
 
88
 
88
	call   do_color_buffer	 ; intit color_map
89
	call   do_color_buffer	 ; intit color_map
89
	mov    edi,bumpmap
90
	mov    edi,bumpmap
90
	call   calc_bumpmap
91
	call   calc_bumpmap
91
	call   calc_bumpmap_coords   ; bump and texture mapping
92
	call   calc_bumpmap_coords   ; bump and texture mapping
92
	call   draw_window
93
	call   draw_window
93
 
94
 
94
 
95
 
95
still:
96
still:
96
 
97
 
97
	mov	eax,23		; wait here for event with timeout
98
	mov	eax,23		; wait here for event with timeout
98
	mov	ebx,TIMEOUT
99
	mov	ebx,TIMEOUT
99
	cmp	[speed_flag],1
100
	cmp	[speed_flag],1
100
	jne	.skip
101
	jne	.skip
101
	mov	eax,11
102
	mov	eax,11
102
    .skip:
103
    .skip:
103
	int	0x40
104
	int	0x40
104
 
105
 
105
	cmp	eax,1		; redraw request ?
106
	cmp	eax,1		; redraw request ?
106
	je	red
107
	je	red
107
	cmp	eax,2		; key in buffer ?
108
	cmp	eax,2		; key in buffer ?
108
	je	key
109
	je	key
109
	cmp	eax,3		; button in buffer ?
110
	cmp	eax,3		; button in buffer ?
110
	je	button
111
	je	button
111
 
112
 
112
	jmp	noclose
113
	jmp	noclose
113
 
114
 
114
    red:			; redraw
115
    red:			; redraw
115
	call	draw_window
116
	call	draw_window
116
 
117
 
117
	jmp	noclose
118
	jmp	noclose
118
 
119
 
119
    key:			; key
120
    key:			; key
120
	mov	eax,2		; just read it and ignore
121
	mov	eax,2		; just read it and ignore
121
	int	0x40
122
	int	0x40
122
	jmp	noclose
123
	jmp	noclose
123
 
124
 
124
    button:			; button
125
    button:			; button
125
	mov	eax,17		; get id
126
	mov	eax,17		; get id
126
	int	0x40
127
	int	0x40
127
 
128
 
128
	cmp	ah,1		; button id=1 ?
129
	cmp	ah,1		; button id=1 ?
129
	jne	@f
130
	jne	@f
130
 
131
 
131
	mov	eax,-1		; close this program
132
	mov	eax,-1		; close this program
132
	int	0x40
133
	int	0x40
133
    @@:
134
    @@:
134
	cmp	ah,30
135
	cmp	ah,30
135
	jge	add_vec_buttons
136
	jge	add_vec_buttons
136
	call	update_flags	      ; update flags and write labels of flags
137
	call	update_flags	      ; update flags and write labels of flags
137
 
138
 
138
				      ; do other operations according to flag
139
				      ; do other operations according to flag
139
	cmp	ah,3		      ; ah = 3 -> shading model
140
	cmp	ah,3		      ; ah = 3 -> shading model
140
	jne	.next_m6
141
	jne	.next_m6
141
	cmp	[dr_flag],2
142
	cmp	[dr_flag],2
142
	jne	@f
143
	jne	@f
143
   ;     call    init_envmap2    ;   <----! this don't works in env mode
144
   ;     call    init_envmap2    ;   <----! this don't works in env mode
144
				 ;          and more than ~18 kb objects
145
				 ;          and more than ~18 kb objects
145
 ;       call    init_envmap_cub2
146
 ;       call    init_envmap_cub2
146
     @@:
147
     @@:
147
	cmp	[dr_flag],4
148
	cmp	[dr_flag],4
148
	jne	@f
149
	jne	@f
149
	call	generate_texture2
150
	call	generate_texture2
150
 
151
 
151
     @@:
152
     @@:
152
     .next_m6:
153
     .next_m6:
153
				      ; ah = 5 -> scale-
154
				      ; ah = 5 -> scale-
154
	cmp	ah,5
155
	cmp	ah,5
155
	jne	@f
156
	jne	@f
156
	mov	[scale],0.7
157
	mov	[scale],0.7
157
	fninit
158
	fninit
158
	fld	[rsscale]
159
	fld	[rsscale]
159
	fmul	[scale]
160
	fmul	[scale]
160
	fstp	[rsscale]
161
	fstp	[rsscale]
161
 
162
 
162
      @@:
163
      @@:
163
	cmp	ah,6		     ; ah = 6 ->  scale+
164
	cmp	ah,6		     ; ah = 6 ->  scale+
164
	jne	@f
165
	jne	@f
165
	mov	[scale],1.3
166
	mov	[scale],1.3
166
	fninit
167
	fninit
167
	fld	[rsscale]
168
	fld	[rsscale]
168
	fmul	[scale]
169
	fmul	[scale]
169
	fstp	[rsscale]
170
	fstp	[rsscale]
170
 
171
 
171
      @@:
172
      @@:
172
	cmp	ah,9	; lights random                 ;    'flat'  0
173
	cmp	ah,9	; lights random                 ;    'flat'  0
173
	jne	.next_m5				;    'grd '  1
174
	jne	.next_m5				;    'grd '  1
174
	call	make_random_lights			;    'env '  2
175
	call	make_random_lights			;    'env '  2
175
	call	normalize_all_light_vectors		;    'bump'  3
176
	call	normalize_all_light_vectors		;    'bump'  3
176
	call	do_color_buffer   ; intit color_map     ;    'tex '  4
177
	call	do_color_buffer   ; intit color_map     ;    'tex '  4
177
      ;  cmp     [emboss_flag],1                         ;    'pos '  5
178
      ;  cmp     [emboss_flag],1                         ;    'pos '  5
178
      ;  je      @f                                      ;    'dots'  6
179
      ;  je      @f                                      ;    'dots'  6
179
      ;  cmp     [dr_flag],8
180
      ;  cmp     [dr_flag],8
180
      ;  jge     @f
181
      ;  jge     @f
181
      ;  cmp     [dr_flag],2                             ;    'txgr'  7
182
      ;  cmp     [dr_flag],2                             ;    'txgr'  7
182
      ;  jl      .next_m5                            ;    '2tex'  8
183
      ;  jl      .next_m5                            ;    '2tex'  8
183
      ;  cmp     [dr_flag],3                             ;    'btex'  9
184
      ;  cmp     [dr_flag],3                             ;    'btex'  9
184
      ;  jg      .next_m5
185
      ;  jg      .next_m5
185
    ; @@:
186
    ; @@:
186
	call	init_envmap2	; update env map if shading model = environment or bump
187
	call	init_envmap2	; update env map if shading model = environment or bump
187
    .next_m5:
188
    .next_m5:
188
	cmp	 ah,11
189
	cmp	 ah,11
189
	je	 @f
190
	je	 @f
190
	cmp	 ah,12
191
	cmp	 ah,12
191
	je	 @f
192
	je	 @f
192
	cmp	 ah,13
193
	cmp	 ah,13
193
	jne	 .next_m4
194
	jne	 .next_m4
194
      @@:
195
      @@:
195
	call	 mirror
196
	call	 mirror
196
     .next_m4:
197
     .next_m4:
197
	cmp	 ah,14
198
	cmp	 ah,14
198
	jne	 @f
199
	jne	 @f
199
	call	 exchange
200
	call	 exchange
200
     @@:
201
     @@:
201
	cmp	 ah,15
202
	cmp	 ah,15
202
	jne	 @f
203
	jne	 @f
203
	cmp	 [emboss_flag],1
204
	cmp	 [emboss_flag],1
204
	call	 init_envmap2
205
	call	 init_envmap2
205
     @@:
206
     @@:
206
;        cmp      ah,17
207
;        cmp      ah,17
207
;        jne      .next_m
208
;        jne      .next_m
208
;        cmp      [move_flag],2
209
;        cmp      [move_flag],2
209
;        jne      @f
210
;        jne      @f
210
;        call     draw_window             ; redraw other labels to navigation buttons
211
;        call     draw_window             ; redraw other labels to navigation buttons
211
;      @@:
212
;      @@:
212
;        cmp      [move_flag],0
213
;        cmp      [move_flag],0
213
;        jne      .next_m
214
;        jne      .next_m
214
;        call     draw_window             ; redraw other labels to navigation buttons
215
;        call     draw_window             ; redraw other labels to navigation buttons
215
     .next_m:
216
     .next_m:
216
	cmp	 ah,18
217
	cmp	 ah,18
217
	jne	 .next_m2
218
	jne	 .next_m2
218
     if USE_LFN
219
     if USE_LFN
219
	mov	 [re_alloc_flag],1	 ; reallocate memory
220
	mov	 [re_alloc_flag],1	 ; reallocate memory
220
	mov	 [triangles_count_var],1000
221
	mov	 [triangles_count_var],1000
221
	mov	 [points_count_var],1000
222
	mov	 [points_count_var],1000
222
	call	 alloc_mem_for_tp
223
	call	 alloc_mem_for_tp
223
	mov	 [re_alloc_flag],0
224
	mov	 [re_alloc_flag],0
224
     end if
225
     end if
225
	mov	 bl,[generator_flag]
226
	mov	 bl,[generator_flag]
226
	or	 bl,bl
227
	or	 bl,bl
227
	jz	 .next_m2
228
	jz	 .next_m2
228
	cmp	 bl,1
229
	cmp	 bl,1
229
	jne	 @f
230
	jne	 @f
230
	call	 generate_object
231
	call	 generate_object
231
	jmp	 .calc_norm
232
	jmp	 .calc_norm
232
      @@:
233
      @@:
233
	cmp	 bl,4
234
	cmp	 bl,4
234
	jg	 @f
235
	jg	 @f
235
	movzx	 ax,bl		      ; ax < - object number
236
	movzx	 ax,bl		      ; ax < - object number
236
	call	 generate_object2
237
	call	 generate_object2
237
	jmp	.calc_norm
238
	jmp	.calc_norm
238
      @@:
239
      @@:
239
	call	generate_object3
240
	call	generate_object3
240
      .calc_norm:
241
      .calc_norm:
241
	call	optimize_object1
242
	call	optimize_object1
242
	call	init_triangles_normals2
243
	call	init_triangles_normals2
243
	call	init_point_normals
244
	call	init_point_normals
244
	call	calc_bumpmap_coords   ; bump and texture mapping
245
	call	calc_bumpmap_coords   ; bump and texture mapping
245
 
246
 
246
     .next_m2:
247
     .next_m2:
247
	cmp	 ah,19
248
	cmp	 ah,19
248
	je	 @f
249
	je	 @f
249
	cmp	 ah,20
250
	cmp	 ah,20
250
	jne	 .next_m3
251
	jne	 .next_m3
251
     @@:
252
     @@:
252
	mov	 edi,bumpmap
253
	mov	 edi,bumpmap
253
	call	 calc_bumpmap
254
	call	 calc_bumpmap
254
     .next_m3:
255
     .next_m3:
255
	cmp	ah,21		 ; re map bumps, texture coordinates
256
	cmp	ah,21		 ; re map bumps, texture coordinates
256
	jne	@f
257
	jne	@f
257
	call	calc_bumpmap_coords
258
	call	calc_bumpmap_coords
258
      @@:
259
      @@:
259
	jmp	noclose
260
	jmp	noclose
260
 
261
 
261
 
262
 
262
			       ; there are 6 navigation buttons each
263
			       ; there are 6 navigation buttons each
263
   add_vec_buttons:	       ; can move: object, camera,.. list is open
264
   add_vec_buttons:	       ; can move: object, camera,.. list is open
264
			       ;
265
			       ;
265
	cmp	ah,30
266
	cmp	ah,30
266
	jne	.next
267
	jne	.next
267
	cmp	[move_flag],1
268
	cmp	[move_flag],1
268
	je	@f
269
	je	@f
269
;        cmp     [move_flag],2
270
;        cmp     [move_flag],2
270
;        je      .set_light1
271
;        je      .set_light1
271
	sub	[vect_y],10
272
	sub	[vect_y],10
272
	jmp	.next
273
	jmp	.next
273
      @@:
274
      @@:
274
	sub	[yobs],10   ;  observator = camera position
275
	sub	[yobs],10   ;  observator = camera position
275
	jmp	.next
276
	jmp	.next
276
 
277
 
277
;--------------------------------------------------
278
;--------------------------------------------------
278
;      .set_light1:          ;  r -
279
;      .set_light1:          ;  r -
279
;        movzx   ebx,[light_no_flag]  ; * 22
280
;        movzx   ebx,[light_no_flag]  ; * 22
280
;        mov     ecx,ebx
281
;        mov     ecx,ebx
281
;        shl     ebx,4
282
;        shl     ebx,4
282
;        shl     ecx,1
283
;        shl     ecx,1
283
;        add     ebx,ecx
284
;        add     ebx,ecx
284
;        shl     ecx,1
285
;        shl     ecx,1
285
;        add     ebx,ecx
286
;        add     ebx,ecx
286
;        add     ebx,lights+6    ; 6 -> light vector size
287
;        add     ebx,lights+6    ; 6 -> light vector size
287
;
288
;
288
;        movzx   ecx,[light_comp_flag]
289
;        movzx   ecx,[light_comp_flag]
289
;        lea     ecx,[ecx*3}
290
;        lea     ecx,[ecx*3}
290
;        add     ebx,ecx         ; ebx ->  color to set
291
;        add     ebx,ecx         ; ebx ->  color to set
291
 
292
 
292
;---------------------------------------------------
293
;---------------------------------------------------
293
      .next:
294
      .next:
294
	cmp	ah,31
295
	cmp	ah,31
295
	jne	.next1
296
	jne	.next1
296
	cmp	[move_flag],1
297
	cmp	[move_flag],1
297
	je	@f
298
	je	@f
298
 
299
 
299
	add	[vect_z],10
300
	add	[vect_z],10
300
	jmp	.next1
301
	jmp	.next1
301
      @@:
302
      @@:
302
	add	[zobs],10	  ;  observator = camera position
303
	add	[zobs],10	  ;  observator = camera position
303
     .next1:
304
     .next1:
304
	cmp	ah,33
305
	cmp	ah,33
305
	jne	.next2
306
	jne	.next2
306
	cmp	[move_flag],1
307
	cmp	[move_flag],1
307
	je	@f
308
	je	@f
308
 
309
 
309
	sub	[vect_x],10
310
	sub	[vect_x],10
310
	jmp	.next2
311
	jmp	.next2
311
      @@:
312
      @@:
312
	sub	[xobs],10	  ;  observator = camera position
313
	sub	[xobs],10	  ;  observator = camera position
313
      .next2:
314
      .next2:
314
	cmp	ah,32
315
	cmp	ah,32
315
	jne	.next3
316
	jne	.next3
316
	cmp	[move_flag],1
317
	cmp	[move_flag],1
317
	je	@f
318
	je	@f
318
 
319
 
319
	add	[vect_x],10
320
	add	[vect_x],10
320
	jmp	.next3
321
	jmp	.next3
321
      @@:
322
      @@:
322
	add	[xobs],10	  ;  observator = camera position
323
	add	[xobs],10	  ;  observator = camera position
323
      .next3:
324
      .next3:
324
	cmp	ah,34
325
	cmp	ah,34
325
	jne	.next4
326
	jne	.next4
326
	cmp	[move_flag],1
327
	cmp	[move_flag],1
327
	je	@f
328
	je	@f
328
 
329
 
329
	sub	[vect_z],10
330
	sub	[vect_z],10
330
	jmp	.next4
331
	jmp	.next4
331
      @@:
332
      @@:
332
	sub	[zobs],10	  ;  observator = camera position
333
	sub	[zobs],10	  ;  observator = camera position
333
      .next4:
334
      .next4:
334
	cmp	ah,35
335
	cmp	ah,35
335
	jne	.next5
336
	jne	.next5
336
	cmp	[move_flag],1
337
	cmp	[move_flag],1
337
	je	@f
338
	je	@f
338
 
339
 
339
      ;  call    add_vector
340
      ;  call    add_vector
340
	add	[vect_y],10
341
	add	[vect_y],10
341
	jmp	.next5
342
	jmp	.next5
342
      @@:
343
      @@:
343
	add	[yobs],10	  ;  observator = camera position
344
	add	[yobs],10	  ;  observator = camera position
344
      .next5:
345
      .next5:
345
 
346
 
346
 
347
 
347
 
348
 
348
    noclose:
349
    noclose:
349
 
350
 
350
	cmp	[r_flag],2
351
	cmp	[r_flag],2
351
	jne	.no_x
352
	jne	.no_x
352
	inc	[angle_x]
353
	inc	[angle_x]
353
	and	[angle_x],0xff
354
	and	[angle_x],0xff
354
	mov	[angle_z],0
355
	mov	[angle_z],0
355
	jmp	.end_rot
356
	jmp	.end_rot
356
 
357
 
357
      .no_x:
358
      .no_x:
358
	cmp	[r_flag],0
359
	cmp	[r_flag],0
359
	jne	.no_y
360
	jne	.no_y
360
	inc	[angle_y]
361
	inc	[angle_y]
361
	and	[angle_y],0xff
362
	and	[angle_y],0xff
362
	mov	[angle_z],0
363
	mov	[angle_z],0
363
	jmp	.end_rot
364
	jmp	.end_rot
364
 
365
 
365
      .no_y:
366
      .no_y:
366
	cmp	[r_flag],1
367
	cmp	[r_flag],1
367
	jne	.end_rot
368
	jne	.end_rot
368
	mov	cx,[angle_x]
369
	mov	cx,[angle_x]
369
	inc	cx
370
	inc	cx
370
	and	cx,0xff
371
	and	cx,0xff
371
	mov	[angle_z],0
372
	mov	[angle_z],0
372
	mov	[angle_y],cx
373
	mov	[angle_y],cx
373
	mov	[angle_x],cx
374
	mov	[angle_x],cx
374
     .end_rot:
375
     .end_rot:
375
 
376
 
376
	mov	esi,angle_x
377
	mov	esi,angle_x
377
	mov	edi,matrix
378
	mov	edi,matrix
378
	call	make_rotation_matrix
379
	call	make_rotation_matrix
379
    RDTSC
380
    RDTSC
380
    push eax
381
    push eax
381
	mov	esi,[points_normals_ptr]
382
	mov	esi,[points_normals_ptr]
382
	mov	edi,[points_normals_rot_ptr]
383
	mov	edi,[points_normals_rot_ptr]
383
	mov	ebx,matrix
384
	mov	ebx,matrix
384
	movzx	ecx,[points_count_var]
385
	movzx	ecx,[points_count_var]
385
	call	rotary
386
	call	rotary
386
 
387
 
387
	mov	esi,matrix
388
	mov	esi,matrix
388
	call	add_scale_to_matrix
389
	call	add_scale_to_matrix
389
 
390
 
390
	mov	esi,[points_ptr]
391
	mov	esi,[points_ptr]
391
	mov	edi,[points_rotated_ptr]
392
	mov	edi,[points_rotated_ptr]
392
	mov	ebx,matrix
393
	mov	ebx,matrix
393
	movzx	ecx,[points_count_var]
394
	movzx	ecx,[points_count_var]
394
	call	rotary
395
	call	rotary
395
 
396
 
396
;    RDTSC
397
;    RDTSC
397
;    pop    ebx
398
;    pop    ebx
398
;    sub    eax,ebx
399
;    sub    eax,ebx
399
;    sub    eax,41
400
;    sub    eax,41
400
;    push   eax
401
;    push   eax
401
 
402
 
402
	mov	esi,[points_rotated_ptr]
403
	mov	esi,[points_rotated_ptr]
403
	mov	edi,[points_translated_ptr]
404
	mov	edi,[points_translated_ptr]
404
	movzx	ecx,[points_count_var]
405
	movzx	ecx,[points_count_var]
405
	call	translate_points
406
	call	translate_points
406
 
407
 
407
;        cmp     [dr_flag],5
408
;        cmp     [dr_flag],5
408
;        jne     @f
409
;        jne     @f
409
;        call    calc_attenuation_light
410
;        call    calc_attenuation_light
410
;     @@:
411
;     @@:
411
	cmp	[fire_flag],0
412
	cmp	[fire_flag],0
412
	jne	@f
413
	jne	@f
413
	call	clrscr		; clear the screen
414
	call	clrscr		; clear the screen
414
     @@:
415
     @@:
415
	cmp	[catmull_flag],1  ;non sort if Catmull = on
416
	cmp	[catmull_flag],1  ;non sort if Catmull = on
416
	je	.no_sort
417
	je	.no_sort
417
	call	sort_triangles
418
	call	sort_triangles
418
      .no_sort:
419
      .no_sort:
419
	cmp	[dr_flag],7	  ; fill if 2tex and texgrd
420
	cmp	[dr_flag],7	  ; fill if 2tex and texgrd
420
	jge	@f
421
	jge	@f
421
	cmp	[catmull_flag],0  ;non fill if Catmull = off
422
	cmp	[catmull_flag],0  ;non fill if Catmull = off
422
	je	.non_f
423
	je	.non_f
423
	cmp	[dr_flag],6	  ; non fill if dots
424
	cmp	[dr_flag],6	  ; non fill if dots
424
	je	.non_f
425
	je	.non_f
425
      @@:
426
      @@:
426
	call	fill_Z_buffer	  ; make background
427
	call	fill_Z_buffer	  ; make background
427
     .non_f:
428
     .non_f:
428
;    RDTSC
429
;    RDTSC
429
;    push eax
430
;    push eax
430
	cmp	[dr_flag],6
431
	cmp	[dr_flag],6
431
	jne	@f
432
	jne	@f
432
	call	 draw_dots
433
	call	 draw_dots
433
	jmp	 .blurrr
434
	jmp	 .blurrr
434
      @@:
435
      @@:
435
	call	draw_triangles	; draw all triangles from the list
436
	call	draw_triangles	; draw all triangles from the list
436
      .blurrr:
437
      .blurrr:
437
	cmp	[fire_flag],0
438
	cmp	[fire_flag],0
438
	jne	@f
439
	jne	@f
439
	cmp	[blur_flag],0
440
	cmp	[blur_flag],0
440
	je	.no_blur  ; no blur, no fire
441
	je	.no_blur  ; no blur, no fire
441
	movzx	ecx,[blur_flag]
442
	movzx	ecx,[blur_flag]
442
	call	blur_screen    ; blur and fire
443
	call	blur_screen    ; blur and fire
443
	jmp	.no_blur
444
	jmp	.no_blur
444
    @@:
445
    @@:
445
	cmp	[emboss_flag],0
446
	cmp	[emboss_flag],0
446
	jne	.emb	       ; if emboss=true -> no fire
447
	jne	.emb	       ; if emboss=true -> no fire
447
	movzx	ecx,[fire_flag]
448
	movzx	ecx,[fire_flag]
448
	call	blur_screen    ; blur and fire
449
	call	blur_screen    ; blur and fire
449
    .no_blur:		       ; no blur, no fire
450
    .no_blur:		       ; no blur, no fire
450
	cmp	[emboss_flag],0
451
	cmp	[emboss_flag],0
451
	je	@f
452
	je	@f
452
     .emb:
453
     .emb:
453
	call	do_emboss
454
	call	do_emboss
454
 
455
 
455
      @@:
456
      @@:
456
 
457
 
457
 
458
 
458
    RDTSC
459
    RDTSC
459
    sub eax,[esp]
460
    sub eax,[esp]
460
    sub eax,41
461
    sub eax,41
461
;    pop     eax
462
;    pop     eax
462
 
463
 
463
    mov     ecx,10
464
    mov     ecx,10
464
  .dc:
465
  .dc:
465
    xor     edx,edx
466
    xor     edx,edx
466
    mov     edi,10
467
    mov     edi,10
467
    div     edi
468
    div     edi
468
    add     dl,30h
469
    add     dl,30h
469
    mov     [STRdata+ecx-1],dl
470
    mov     [STRdata+ecx-1],dl
470
    loop    .dc
471
    loop    .dc
471
    pop eax
472
    pop eax
472
 
473
 
473
    mov     eax,7	    ; put image
474
    mov     eax,7	    ; put image
474
    mov     ebx,screen
475
    mov     ebx,screen
475
    mov     ecx,SIZE_X shl 16 + SIZE_Y
476
    mov     ecx,SIZE_X shl 16 + SIZE_Y
476
    mov     edx,5 shl 16 + 20
477
    mov     edx,5 shl 16 + 20
477
    int     0x40
478
    int     0x40
478
 
479
 
479
 
480
 
480
    mov  eax,4			   ; function 4 : write text to window
481
    mov  eax,4			   ; function 4 : write text to window
481
    mov  ebx,5*65536+23 	   ; [x start] *65536 + [y start]
482
    mov  ebx,5*65536+23 	   ; [x start] *65536 + [y start]
482
    mov  ecx,-1
483
    mov  ecx,-1
483
    mov  edx,STRdata		   ; pointer to text beginning
484
    mov  edx,STRdata		   ; pointer to text beginning
484
    mov  esi,10 		   ; text length
485
    mov  esi,10 		   ; text length
485
    int  40h
486
    int  40h
486
 
487
 
487
 
488
 
488
 
489
 
489
   jmp	   still
490
   jmp	   still
490
 
491
 
491
;--------------------------------------------------------------------------------
492
;--------------------------------------------------------------------------------
492
;-------------------------PROCEDURES---------------------------------------------
493
;-------------------------PROCEDURES---------------------------------------------
493
;--------------------------------------------------------------------------------
494
;--------------------------------------------------------------------------------
494
include "TEX3.INC"
495
include "TEX3.INC"
495
include "FLAT_CAT.INC"
496
include "FLAT_CAT.INC"
496
include "TEX_CAT.INC"
497
include "TEX_CAT.INC"
497
include "BUMP_CAT.INC"
498
include "BUMP_CAT.INC"
498
include "3DMATH.INC"
499
include "3DMATH.INC"
499
include "GRD3.INC"
500
include "GRD3.INC"
500
include "FLAT3.INC"
501
include "FLAT3.INC"
501
include "BUMP3.INC"
502
include "BUMP3.INC"
502
include "B_PROCS.INC"
503
include "B_PROCS.INC"
503
include "A_PROCS.INC"
504
include "A_PROCS.INC"
504
include "GRD_CAT.INC"
505
include "GRD_CAT.INC"
505
include "BUMP_TEX.INC"
506
include "BUMP_TEX.INC"
506
include "GRD_TEX.INC"
507
include "GRD_TEX.INC"
507
include "TWO_TEX.INC"
508
include "TWO_TEX.INC"
508
 
509
 
509
alloc_buffer_mem:
510
alloc_buffer_mem:
510
    movzx    ecx,[size_x]
511
    movzx    ecx,[size_x]
511
    movzx    eax,[size_y]
512
    movzx    eax,[size_y]
512
    mul      ecx
513
    mul      ecx
513
    lea      ecx,[eax*3]
514
    lea      ecx,[eax*3]
514
    push     ecx
515
    push     ecx
515
    shl      eax,2
516
    shl      eax,2
516
    add      ecx,eax
517
    add      ecx,eax
517
    add      ecx,MEM_END
518
    add      ecx,MEM_END
518
    mov      ebx,1
519
    mov      ebx,1
519
    mov      eax,64	; allocate mem  - resize app mem
520
    mov      eax,64	; allocate mem  - resize app mem
520
    int      0x40
521
    int      0x40
521
    mov      [screen_ptr],MEM_END
522
    mov      [screen_ptr],MEM_END
522
    mov      [Zbuffer_ptr],MEM_END
523
    mov      [Zbuffer_ptr],MEM_END
523
    pop      ecx
524
    pop      ecx
524
    add      [Zbuffer_ptr],ecx
525
    add      [Zbuffer_ptr],ecx
525
ret
526
ret
526
 
527
 
527
update_flags:
528
update_flags:
528
; updates flags and writing flag description
529
; updates flags and writing flag description
529
; in    ah - button number
530
; in    ah - button number
530
	push	ax
531
	push	ax
531
	mov	edi,menu
532
	mov	edi,menu
532
      .ch_another:
533
      .ch_another:
533
	cmp	ah,byte[edi]	 ; ah = button id
534
	cmp	ah,byte[edi]	 ; ah = button id
534
	jne	@f
535
	jne	@f
535
	mov	bl,byte[edi+11]  ; max_flag + 1
536
	mov	bl,byte[edi+11]  ; max_flag + 1
536
	cmp	bl,255
537
	cmp	bl,255
537
	je	.no_write
538
	je	.no_write
538
	inc	byte[edi+12]	 ; flag
539
	inc	byte[edi+12]	 ; flag
539
	cmp	byte[edi+12],bl
540
	cmp	byte[edi+12],bl
540
	jne	.write
541
	jne	.write
541
	mov	byte[edi+12],0
542
	mov	byte[edi+12],0
542
	jmp	.write
543
	jmp	.write
543
      @@:
544
      @@:
544
	add	edi,17
545
	add	edi,17
545
	cmp	byte[edi],-1
546
	cmp	byte[edi],-1
546
	jne	.ch_another
547
	jne	.ch_another
547
     .write:
548
     .write:
548
;     clreol   {pascal never dies}
549
;     clreol   {pascal never dies}
549
;          * eax = 13 - function number
550
;          * eax = 13 - function number
550
;  * ebx = [coordinate on axis x]*65536 + [size on axis x]
551
;  * ebx = [coordinate on axis x]*65536 + [size on axis x]
551
;  * ecx = [coordinate on axis y]*65536 + [size on axis y]
552
;  * ecx = [coordinate on axis y]*65536 + [size on axis y]
552
;  * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill
553
;  * edx = color 0xRRGGBB or 0x80RRGGBB for gradient fill
553
 
554
 
554
	mov	eax,13				 ; function 13 write rectangle
555
	mov	eax,13				 ; function 13 write rectangle
555
	movzx	ecx,byte[edi]
556
	movzx	ecx,byte[edi]
556
	sub	cl,2
557
	sub	cl,2
557
	lea	ecx,[ecx*3]
558
	lea	ecx,[ecx*3]
558
	lea	ecx,[ecx*5]
559
	lea	ecx,[ecx*5]
559
	add	ecx,28
560
	add	ecx,28
560
	shl	ecx,16
561
	shl	ecx,16
561
	add	ecx,14				;  ecx = [coord y]*65536 + [size y]
562
	add	ecx,14				;  ecx = [coord y]*65536 + [size y]
562
	mov	ebx,(SIZE_X+12+70)*65536+25	; [x start] *65536 + [size x]
563
	mov	ebx,(SIZE_X+12+70)*65536+25	; [x start] *65536 + [size x]
563
	mov	edx,0x00000000			;  color  0x00RRGGBB
564
	mov	edx,0x00000000			;  color  0x00RRGGBB
564
	int	0x40
565
	int	0x40
565
 
566
 
566
	mov	eax,4				; function 4 : write text to window
567
	mov	eax,4				; function 4 : write text to window
567
	movzx	ebx,byte[edi]
568
	movzx	ebx,byte[edi]
568
	sub	bl,2
569
	sub	bl,2
569
	lea	ebx,[ebx*3]
570
	lea	ebx,[ebx*3]
570
	lea	ebx,[ebx*5]
571
	lea	ebx,[ebx*5]
571
	add	ebx,(SIZE_X+12+70)*65536+28	; [x start] *65536 + [y start]
572
	add	ebx,(SIZE_X+12+70)*65536+28	; [x start] *65536 + [y start]
572
	mov	ecx,0x20ddeeff			; font 1 & color ( 0xF0RRGGBB )
573
	mov	ecx,0x20ddeeff			; font 1 & color ( 0xF0RRGGBB )
573
	movzx	edx,byte[edi+12]		; current flag
574
	movzx	edx,byte[edi+12]		; current flag
574
	shl	edx,2				; * 4 = text length
575
	shl	edx,2				; * 4 = text length
575
	add	edx,dword[edi+13]		; pointer to text beginning
576
	add	edx,dword[edi+13]		; pointer to text beginning
576
	mov	esi,4				; text length -
577
	mov	esi,4				; text length -
577
						; flag description 4 characters
578
						; flag description 4 characters
578
	int	0x40
579
	int	0x40
579
 
580
 
580
     .no_write:
581
     .no_write:
581
	pop	ax
582
	pop	ax
582
ret
583
ret
583
normalize_all_light_vectors:
584
normalize_all_light_vectors:
584
	mov	edi,lights
585
	mov	edi,lights
585
     @@:
586
     @@:
586
	call	normalize_vector	   ;       3dmath.inc
587
	call	normalize_vector	   ;       3dmath.inc
587
	add	edi,LIGHT_SIZE
588
	add	edi,LIGHT_SIZE
588
	cmp	edi,lightsend	;ecx
589
	cmp	edi,lightsend	;ecx
589
	jl	@b
590
	jl	@b
590
ret
591
ret
591
 
592
 
592
calc_bumpmap_coords:	  ; map texture, bump
593
calc_bumpmap_coords:	  ; map texture, bump
593
;macro .comment222
594
;macro .comment222
594
;                                ; planar mapping
595
;                                ; planar mapping
595
;        mov     esi,points
596
;        mov     esi,points
596
;        mov     edi,tex_points
597
;        mov     edi,tex_points
597
;      @@:
598
;      @@:
598
;         add     esi,2
599
;         add     esi,2
599
;         movsd
600
;         movsd
600
;         cmp     dword[esi],dword -1
601
;         cmp     dword[esi],dword -1
601
;         jne     @b
602
;         jne     @b
602
 
603
 
603
;      .Pi2  equ dword[ebp-4]
604
;      .Pi2  equ dword[ebp-4]
604
 
605
 
605
;      mov   ebp,esp
606
;      mov   ebp,esp
606
;      sub   esp,4
607
;      sub   esp,4
607
 
608
 
608
      fninit
609
      fninit
609
      fldpi
610
      fldpi
610
      fadd	st,st
611
      fadd	st,st
611
      mov	esi,[points_ptr]
612
      mov	esi,[points_ptr]
612
      mov	edi,tex_points
613
      mov	edi,tex_points
613
      movzx	ecx,[points_count_var]
614
      movzx	ecx,[points_count_var]
614
      inc	ecx
615
      inc	ecx
615
;      cmp       [map_tex_flag],1
616
;      cmp       [map_tex_flag],1
616
;      jne       .cylindric
617
;      jne       .cylindric
617
      ; spherical mapping around y axle
618
      ; spherical mapping around y axle
618
 
619
 
619
   @@:
620
   @@:
620
      fld	dword[esi]     ; x coord
621
      fld	dword[esi]     ; x coord
621
      fld	dword[esi+8]   ; z coord
622
      fld	dword[esi+8]   ; z coord
622
      fpatan		       ; arctg(st1/st)
623
      fpatan		       ; arctg(st1/st)
623
;      fdiv      .Pi2
624
;      fdiv      .Pi2
624
      fdiv	st0,st1
625
      fdiv	st0,st1
625
      fimul	[tex_x_div2]
626
      fimul	[tex_x_div2]
626
      fiadd	[tex_x_div2]
627
      fiadd	[tex_x_div2]
627
      fistp	word[edi]      ; x
628
      fistp	word[edi]      ; x
628
 
629
 
629
      fld	dword[esi+4]   ; y coord
630
      fld	dword[esi+4]   ; y coord
630
      fld	dword[esi]     ; x
631
      fld	dword[esi]     ; x
631
      fmul	st,st0
632
      fmul	st,st0
632
      fld	dword[esi+4]   ; y
633
      fld	dword[esi+4]   ; y
633
      fmul	st,st0
634
      fmul	st,st0
634
      fld	dword[esi+8]   ; z
635
      fld	dword[esi+8]   ; z
635
      fmul	st,st0
636
      fmul	st,st0
636
      faddp
637
      faddp
637
      faddp
638
      faddp
638
      fsqrt
639
      fsqrt
639
      fpatan
640
      fpatan
640
      fldpi
641
      fldpi
641
      fdivp
642
      fdivp
642
      fimul    [tex_y_div2]
643
      fimul    [tex_y_div2]
643
      fiadd    [tex_y_div2]
644
      fiadd    [tex_y_div2]
644
      fistp    word[edi+2]     ; y
645
      fistp    word[edi+2]     ; y
645
 
646
 
646
      add      esi,12
647
      add      esi,12
647
      add      edi,4
648
      add      edi,4
648
      loop     @b
649
      loop     @b
649
      ffree    st0
650
      ffree    st0
650
;      jmp      .end_map
651
;      jmp      .end_map
651
;  .cylindric:
652
;  .cylindric:
652
;       fld     dword[esi]     ; around y axle
653
;       fld     dword[esi]     ; around y axle
653
;       fld     dword[esi+8]
654
;       fld     dword[esi+8]
654
;       fpatan
655
;       fpatan
655
;       fdiv    st0,st1
656
;       fdiv    st0,st1
656
;       fimul   [tex_x_div2]
657
;       fimul   [tex_x_div2]
657
;       fiadd   [tex_x_div2]
658
;       fiadd   [tex_x_div2]
658
;       fistp   word[edi]
659
;       fistp   word[edi]
659
 
660
 
660
;       fld     dword[esi+4]
661
;       fld     dword[esi+4]
661
;       fimul   [tex_y_div2]
662
;       fimul   [tex_y_div2]
662
;       fiadd   [tex_y_div2]
663
;       fiadd   [tex_y_div2]
663
;       fistp   word[edi+2]
664
;       fistp   word[edi+2]
664
 
665
 
665
;       add     esi,12
666
;       add     esi,12
666
;       add     edi,4
667
;       add     edi,4
667
;       loop    .cylindric
668
;       loop    .cylindric
668
;       ffree    st0
669
;       ffree    st0
669
;;      mov      esp,ebp
670
;;      mov      esp,ebp
670
;   .end_map:
671
;   .end_map:
671
ret
672
ret
672
 
673
 
673
 
674
 
674
init_envmap2:	      ; do env_map using many light sources
675
init_envmap2:	      ; do env_map using many light sources
675
;env_map 512 x 512 x 3 bytes
676
;env_map 512 x 512 x 3 bytes
676
.temp  equ word   [ebp-2]
677
.temp  equ word   [ebp-2]
677
.nEy   equ word  [ebp-4]
678
.nEy   equ word  [ebp-4]
678
.nEx   equ word  [ebp-6]
679
.nEx   equ word  [ebp-6]
679
.col_r equ    [ebp-8]
680
.col_r equ    [ebp-8]
680
.col_g equ    [ebp-9]
681
.col_g equ    [ebp-9]
681
.col_b equ    [ebp-10]
682
.col_b equ    [ebp-10]
682
 
683
 
683
	 push	  ebp
684
	 push	  ebp
684
	 mov	  ebp,esp
685
	 mov	  ebp,esp
685
	 sub	  esp,20
686
	 sub	  esp,20
686
	 mov	  edi,envmap
687
	 mov	  edi,envmap
687
	 fninit
688
	 fninit
688
 
689
 
689
	 mov	  dx,- TEX_Y / 2 ;256   ; dx - vertical coordinate = y
690
	 mov	  dx,- TEX_Y / 2 ;256   ; dx - vertical coordinate = y
690
    .ie_ver:
691
    .ie_ver:
691
	 mov	  cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
692
	 mov	  cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
692
    .ie_hor:
693
    .ie_hor:
693
	 xor	  ebx,ebx
694
	 xor	  ebx,ebx
694
	 mov	  dword .col_b, 0
695
	 mov	  dword .col_b, 0
695
     .light:
696
     .light:
696
	 lea	  esi,[lights+ebx]
697
	 lea	  esi,[lights+ebx]
697
	 fld	  dword[esi]	 ; light vector x cooficient
698
	 fld	  dword[esi]	 ; light vector x cooficient
698
	 fimul	  [tex_x_div2] ;[i256]
699
	 fimul	  [tex_x_div2] ;[i256]
699
	 mov	  .temp,cx
700
	 mov	  .temp,cx
700
	 fisubr   .temp
701
	 fisubr   .temp
701
	 fistp	  .nEx
702
	 fistp	  .nEx
702
	 fld	  dword[esi+4]	 ; light vector y cooficient
703
	 fld	  dword[esi+4]	 ; light vector y cooficient
703
	 fimul	  [tex_y_div2] ;[i256]
704
	 fimul	  [tex_y_div2] ;[i256]
704
	 mov	  .temp,dx
705
	 mov	  .temp,dx
705
	 fisubr   .temp
706
	 fisubr   .temp
706
	 fistp	  .nEy
707
	 fistp	  .nEy
707
 
708
 
708
	 cmp	  .nEx,- TEX_X / 2 ;256
709
	 cmp	  .nEx,- TEX_X / 2 ;256
709
	 jl	  .update_counters
710
	 jl	  .update_counters
710
	 cmp	  .nEy,- TEX_Y / 2 ;256
711
	 cmp	  .nEy,- TEX_Y / 2 ;256
711
	 jl	  .update_counters
712
	 jl	  .update_counters
712
	 cmp	  .nEx,TEX_X / 2 ;256
713
	 cmp	  .nEx,TEX_X / 2 ;256
713
	 jg	  .update_counters
714
	 jg	  .update_counters
714
	 cmp	  .nEy,TEX_Y / 2 ;256
715
	 cmp	  .nEy,TEX_Y / 2 ;256
715
	 jg	  .update_counters
716
	 jg	  .update_counters
716
 
717
 
717
	 fild	  .nEx
718
	 fild	  .nEx
718
	 fmul	  st,st0
719
	 fmul	  st,st0
719
	 fild	  .nEy
720
	 fild	  .nEy
720
	 fmul	  st,st0
721
	 fmul	  st,st0
721
	 faddp
722
	 faddp
722
	 fsqrt
723
	 fsqrt
723
	 fisubr   [i256]
724
	 fisubr   [i256]
724
	 fmul	  [env_const]
725
	 fmul	  [env_const]
725
	 fidiv	  [i256]   ; st - 'virtual' dot product
726
	 fidiv	  [i256]   ; st - 'virtual' dot product
726
 
727
 
727
	 fcom	  [dot_max]
728
	 fcom	  [dot_max]
728
	 fstsw	  ax
729
	 fstsw	  ax
729
	 sahf
730
	 sahf
730
	 jb	  @f
731
	 jb	  @f
731
	 ffree	  st
732
	 ffree	  st
732
	 fld1	  ;[dot_max]
733
	 fld1	  ;[dot_max]
733
      @@:
734
      @@:
734
	 fcom	  [dot_min]
735
	 fcom	  [dot_min]
735
	 fstsw	  ax
736
	 fstsw	  ax
736
	 sahf
737
	 sahf
737
	 ja	  @f
738
	 ja	  @f
738
	 ffree	  st
739
	 ffree	  st
739
	 fldz	  ;[dot_min]
740
	 fldz	  ;[dot_min]
740
      @@:
741
      @@:
741
	 push	  ebp
742
	 push	  ebp
742
	 movzx	  ax,byte[esi+21]
743
	 movzx	  ax,byte[esi+21]
743
	 push	  ax  ;- shines
744
	 push	  ax  ;- shines
744
	 mov	  al,byte[esi+14]   ; b    orginal color
745
	 mov	  al,byte[esi+14]   ; b    orginal color
745
	 push	  ax
746
	 push	  ax
746
	 mov	  al,byte[esi+13]   ; g
747
	 mov	  al,byte[esi+13]   ; g
747
	 push	  ax
748
	 push	  ax
748
	 mov	  al,byte[esi+12]   ; r
749
	 mov	  al,byte[esi+12]   ; r
749
	 push	  ax
750
	 push	  ax
750
	 mov	  al,byte[esi+20]   ; b     max color
751
	 mov	  al,byte[esi+20]   ; b     max color
751
	 push	  ax
752
	 push	  ax
752
	 mov	  al,byte[esi+19]   ; g
753
	 mov	  al,byte[esi+19]   ; g
753
	 push	  ax
754
	 push	  ax
754
	 mov	  al,byte[esi+18]   ; r
755
	 mov	  al,byte[esi+18]   ; r
755
	 push	  ax
756
	 push	  ax
756
	 mov	  al,byte[esi+17]   ; b    min col
757
	 mov	  al,byte[esi+17]   ; b    min col
757
	 push	  ax
758
	 push	  ax
758
	 mov	  al,byte[esi+16]   ; g
759
	 mov	  al,byte[esi+16]   ; g
759
	 push	  ax
760
	 push	  ax
760
	 mov	  al,byte[esi+15]   ; r
761
	 mov	  al,byte[esi+15]   ; r
761
	 push	  ax
762
	 push	  ax
762
	 push	  eax	      ; earlier - dot pr
763
	 push	  eax	      ; earlier - dot pr
763
      ;  fstp     .dot_product
764
      ;  fstp     .dot_product
764
      ;  push     .dot_product
765
      ;  push     .dot_product
765
	 call	  calc_one_col
766
	 call	  calc_one_col
766
	 pop	  ebp
767
	 pop	  ebp
767
	 ; eax-0x00rrggbb
768
	 ; eax-0x00rrggbb
768
	 cmp	  al,.col_b
769
	 cmp	  al,.col_b
769
	 jbe	  @f
770
	 jbe	  @f
770
	 mov	  .col_b,al
771
	 mov	  .col_b,al
771
   @@:			      ;  eax - ggbb00rr
772
   @@:			      ;  eax - ggbb00rr
772
	 shr	  ax,8
773
	 shr	  ax,8
773
	 cmp	  al,.col_g
774
	 cmp	  al,.col_g
774
	 jbe	  @f
775
	 jbe	  @f
775
	 mov	  .col_g,al
776
	 mov	  .col_g,al
776
   @@:			      ;  eax - bb0000gg
777
   @@:			      ;  eax - bb0000gg
777
	 shr	  eax,16
778
	 shr	  eax,16
778
	 cmp	  al,.col_r
779
	 cmp	  al,.col_r
779
	 jbe	  @f
780
	 jbe	  @f
780
	 mov	  .col_r,al
781
	 mov	  .col_r,al
781
   @@:
782
   @@:
782
   .update_counters:			 ; update and jump when neccesery
783
   .update_counters:			 ; update and jump when neccesery
783
	 add	  ebx,LIGHT_SIZE
784
	 add	  ebx,LIGHT_SIZE
784
	 cmp	  bx,[all_lights_size]
785
	 cmp	  bx,[all_lights_size]
785
	 jl	  .light    ; next_light
786
	 jl	  .light    ; next_light
786
	 mov	  eax,dword .col_b
787
	 mov	  eax,dword .col_b
787
	 stosd
788
	 stosd
788
	 dec	  edi
789
	 dec	  edi
789
 
790
 
790
	 inc	  cx
791
	 inc	  cx
791
	 cmp	  cx,TEX_X / 2 ;256
792
	 cmp	  cx,TEX_X / 2 ;256
792
	 jne	  .ie_hor
793
	 jne	  .ie_hor
793
 
794
 
794
	 inc	  dx
795
	 inc	  dx
795
	 cmp	  dx,TEX_Y / 2 ;256
796
	 cmp	  dx,TEX_Y / 2 ;256
796
	 jne	 .ie_ver
797
	 jne	 .ie_ver
797
 
798
 
798
	 mov	 esp,ebp
799
	 mov	 esp,ebp
799
	 pop	 ebp
800
	 pop	 ebp
800
ret
801
ret
801
 
802
 
802
 
803
 
803
 
804
 
804
do_color_buffer:	 ; do color buffer for Gouraud, flat shading
805
do_color_buffer:	 ; do color buffer for Gouraud, flat shading
805
;env_map 512 x 512 x 3 bytes    ; many lights using
806
;env_map 512 x 512 x 3 bytes    ; many lights using
806
.temp  equ word   [ebp-2]
807
.temp  equ word   [ebp-2]
807
.nz    equ dword  [ebp-6]  ; dword
808
.nz    equ dword  [ebp-6]  ; dword
808
.ny    equ dword  [ebp-10]
809
.ny    equ dword  [ebp-10]
809
.nx    equ dword  [ebp-14]
810
.nx    equ dword  [ebp-14]
810
.col_r equ    [ebp-16]
811
.col_r equ    [ebp-16]
811
.col_g equ    [ebp-17]
812
.col_g equ    [ebp-17]
812
.col_b equ    [ebp-18]
813
.col_b equ    [ebp-18]
813
 
814
 
814
	 push	  ebp
815
	 push	  ebp
815
	 mov	  ebp,esp
816
	 mov	  ebp,esp
816
	 sub	  esp,20
817
	 sub	  esp,20
817
	 mov	  edi,color_map
818
	 mov	  edi,color_map
818
	 fninit
819
	 fninit
819
 
820
 
820
	 mov	  dx,- TEX_Y / 2 ;-256   ; dx - vertical coordinate = y
821
	 mov	  dx,- TEX_Y / 2 ;-256   ; dx - vertical coordinate = y
821
    .ie_ver:
822
    .ie_ver:
822
	 mov	  cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
823
	 mov	  cx,- TEX_X / 2 ;256   ; cx - horizontal coord = x
823
    .ie_hor:
824
    .ie_hor:
824
	 mov	  .temp,cx
825
	 mov	  .temp,cx
825
	 fild	  .temp
826
	 fild	  .temp
826
	 fidiv	  [i256]   ;st = Nx - vector normal x cooficient
827
	 fidiv	  [i256]   ;st = Nx - vector normal x cooficient
827
	 fst	  .nx
828
	 fst	  .nx
828
	 fmul	  st,st0
829
	 fmul	  st,st0
829
	 mov	  .temp,dx
830
	 mov	  .temp,dx
830
	 fild	  .temp
831
	 fild	  .temp
831
	 fidiv	  [i256]   ; st = Ny - vector normal y coeficient
832
	 fidiv	  [i256]   ; st = Ny - vector normal y coeficient
832
	 fst	  .ny
833
	 fst	  .ny
833
	 fmul	  st,st0
834
	 fmul	  st,st0
834
	 faddp
835
	 faddp
835
	 fld1
836
	 fld1
836
	 fchs
837
	 fchs
837
	 faddp
838
	 faddp
838
	 fabs
839
	 fabs
839
	 fsqrt
840
	 fsqrt
840
	 fchs
841
	 fchs
841
	 fstp	  .nz		   ; st - Nz - vect normal z coeficient
842
	 fstp	  .nz		   ; st - Nz - vect normal z coeficient
842
	 xor	  ebx,ebx
843
	 xor	  ebx,ebx
843
	 mov	  dword .col_b, 0
844
	 mov	  dword .col_b, 0
844
     .light:
845
     .light:
845
	 push	  edi	;env_map
846
	 push	  edi	;env_map
846
	 lea	  esi,[lights+ebx]
847
	 lea	  esi,[lights+ebx]
847
	 lea	  edi,.nx
848
	 lea	  edi,.nx
848
	 call	  dot_product
849
	 call	  dot_product
849
	 pop	  edi
850
	 pop	  edi
850
	 fcom	  [dot_min]
851
	 fcom	  [dot_min]
851
	 fstsw	  ax
852
	 fstsw	  ax
852
	 sahf
853
	 sahf
853
	 ja	  .env_ok1  ;compare with dot_max
854
	 ja	  .env_ok1  ;compare with dot_max
854
	 ffree	  st
855
	 ffree	  st
855
 
856
 
856
	jmp	  .update_counters
857
	jmp	  .update_counters
857
      .env_ok1:
858
      .env_ok1:
858
	 fcom	 [dot_max]
859
	 fcom	 [dot_max]
859
	 fstsw	 ax
860
	 fstsw	 ax
860
	 sahf
861
	 sahf
861
	 jb	 .env_ok2     ; calc col
862
	 jb	 .env_ok2     ; calc col
862
	 ffree	 st
863
	 ffree	 st
863
	 jmp	 .update_counters
864
	 jmp	 .update_counters
864
      .env_ok2: 	   ;calc col
865
      .env_ok2: 	   ;calc col
865
	 push	  ebp
866
	 push	  ebp
866
	 movzx	  ax,byte[esi+21]
867
	 movzx	  ax,byte[esi+21]
867
	 push	  ax  ;- shines
868
	 push	  ax  ;- shines
868
	 mov	  al,byte[esi+14]   ; b    orginal color
869
	 mov	  al,byte[esi+14]   ; b    orginal color
869
	 push	  ax
870
	 push	  ax
870
	 mov	  al,byte[esi+13]   ; g
871
	 mov	  al,byte[esi+13]   ; g
871
	 push	  ax
872
	 push	  ax
872
	 mov	  al,byte[esi+12]   ; r
873
	 mov	  al,byte[esi+12]   ; r
873
	 push	  ax
874
	 push	  ax
874
	 mov	  al,byte[esi+20]   ; b     max color
875
	 mov	  al,byte[esi+20]   ; b     max color
875
	 push	  ax
876
	 push	  ax
876
	 mov	  al,byte[esi+19]   ; g
877
	 mov	  al,byte[esi+19]   ; g
877
	 push	  ax
878
	 push	  ax
878
	 mov	  al,byte[esi+18]   ; r
879
	 mov	  al,byte[esi+18]   ; r
879
	 push	  ax
880
	 push	  ax
880
	 mov	  al,byte[esi+17]   ; b    min col
881
	 mov	  al,byte[esi+17]   ; b    min col
881
	 push	  ax
882
	 push	  ax
882
	 mov	  al,byte[esi+16]   ; g
883
	 mov	  al,byte[esi+16]   ; g
883
	 push	  ax
884
	 push	  ax
884
	 mov	  al,byte[esi+15]   ; r
885
	 mov	  al,byte[esi+15]   ; r
885
	 push	  ax
886
	 push	  ax
886
	 push	  eax	      ; earlier - dot pr
887
	 push	  eax	      ; earlier - dot pr
887
      ;  fstp     .dot_product
888
      ;  fstp     .dot_product
888
      ;  push     .dot_product
889
      ;  push     .dot_product
889
	 call	  calc_one_col
890
	 call	  calc_one_col
890
	 pop	  ebp
891
	 pop	  ebp
891
	 ; eax-0x00rrggbb
892
	 ; eax-0x00rrggbb
892
	 cmp	  al,.col_b
893
	 cmp	  al,.col_b
893
	 jbe	  @f
894
	 jbe	  @f
894
	 mov	  .col_b,al
895
	 mov	  .col_b,al
895
   @@:
896
   @@:
896
	 shr	  ax,8
897
	 shr	  ax,8
897
	 cmp	  al,.col_g
898
	 cmp	  al,.col_g
898
	 jbe	  @f
899
	 jbe	  @f
899
	 mov	  .col_g,al
900
	 mov	  .col_g,al
900
   @@:
901
   @@:
901
	 shr	  eax,16
902
	 shr	  eax,16
902
	 cmp	  al,.col_r
903
	 cmp	  al,.col_r
903
	 jbe	  @f
904
	 jbe	  @f
904
	 mov	  .col_r,al
905
	 mov	  .col_r,al
905
  @@:
906
  @@:
906
 .update_counters:				    ; update and jump when neccesery
907
 .update_counters:				    ; update and jump when neccesery
907
	add	ebx,LIGHT_SIZE
908
	add	ebx,LIGHT_SIZE
908
	cmp	bx,[all_lights_size]
909
	cmp	bx,[all_lights_size]
909
	jl	.light	  ; next_light
910
	jl	.light	  ; next_light
910
	mov	eax,dword .col_b
911
	mov	eax,dword .col_b
911
	stosd
912
	stosd
912
	dec	edi
913
	dec	edi
913
 
914
 
914
	inc	cx
915
	inc	cx
915
	cmp	cx,TEX_X / 2 ;256
916
	cmp	cx,TEX_X / 2 ;256
916
	jne	.ie_hor
917
	jne	.ie_hor
917
 
918
 
918
	inc	dx
919
	inc	dx
919
	cmp	dx,TEX_X / 2 ;256
920
	cmp	dx,TEX_X / 2 ;256
920
	jne	.ie_ver
921
	jne	.ie_ver
921
 
922
 
922
    .env_done:
923
    .env_done:
923
	 mov	 esp,ebp
924
	 mov	 esp,ebp
924
	 pop	 ebp
925
	 pop	 ebp
925
ret
926
ret
926
if 0
927
if 0
927
init_triangles_normals:
928
init_triangles_normals:
928
	mov	ebx,triangles_normals
929
	mov	ebx,triangles_normals
929
	mov	ebp,triangles
930
	mov	ebp,triangles
930
     @@:
931
     @@:
931
	push	ebx
932
	push	ebx
932
	mov	ebx,vectors
933
	mov	ebx,vectors
933
	movzx	esi,word[ebp]	       ; first point index
934
	movzx	esi,word[ebp]	       ; first point index
934
	lea	esi,[esi*3]
935
	lea	esi,[esi*3]
935
	lea	esi,[points+esi*2]     ; esi - pointer to 1st 3d point
936
	lea	esi,[points+esi*2]     ; esi - pointer to 1st 3d point
936
	movzx	edi,word[ebp+2]        ; second point index
937
	movzx	edi,word[ebp+2]        ; second point index
937
	lea	edi,[edi*3]
938
	lea	edi,[edi*3]
938
	lea	edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
939
	lea	edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
939
	call	make_vector
940
	call	make_vector
940
	add	ebx,12
941
	add	ebx,12
941
	mov	esi,edi
942
	mov	esi,edi
942
	movzx	edi,word[ebp+4]        ; third point index
943
	movzx	edi,word[ebp+4]        ; third point index
943
	lea	edi,[edi*3]
944
	lea	edi,[edi*3]
944
	lea	edi,[points+edi*2]
945
	lea	edi,[points+edi*2]
945
	call	make_vector
946
	call	make_vector
946
	mov	edi,ebx 		; edi - pointer to 2nd vector
947
	mov	edi,ebx 		; edi - pointer to 2nd vector
947
	mov	esi,ebx
948
	mov	esi,ebx
948
	sub	esi,12			; esi - pointer to 1st vector
949
	sub	esi,12			; esi - pointer to 1st vector
949
	pop	ebx
950
	pop	ebx
950
	call	cross_product
951
	call	cross_product
951
	mov	edi,ebx
952
	mov	edi,ebx
952
	call	normalize_vector
953
	call	normalize_vector
953
	add	ebp,6
954
	add	ebp,6
954
	add	ebx,12
955
	add	ebx,12
955
	cmp	dword[ebp],-1
956
	cmp	dword[ebp],-1
956
	jne	@b
957
	jne	@b
957
ret
958
ret
958
end if
959
end if
959
init_point_normals:
960
init_point_normals:
960
.x equ dword [ebp-4]
961
.x equ dword [ebp-4]
961
.y equ dword [ebp-8]
962
.y equ dword [ebp-8]
962
.z equ dword [ebp-12]
963
.z equ dword [ebp-12]
963
.point_number equ word [ebp-26]
964
.point_number equ word [ebp-26]
964
.hit_faces    equ word [ebp-28]
965
.hit_faces    equ word [ebp-28]
965
 
966
 
966
	fninit
967
	fninit
967
	mov	  ebp,esp
968
	mov	  ebp,esp
968
	sub	  esp,28
969
	sub	  esp,28
969
	mov	  edi,[points_normals_ptr]
970
	mov	  edi,[points_normals_ptr]
970
	mov	  .point_number,0
971
	mov	  .point_number,0
971
    .ipn_loop:
972
    .ipn_loop:
972
	mov	  .hit_faces,0
973
	mov	  .hit_faces,0
973
	mov	  .x,0
974
	mov	  .x,0
974
	mov	  .y,0
975
	mov	  .y,0
975
	mov	  .z,0
976
	mov	  .z,0
976
	mov	  esi,[triangles_ptr]
977
	mov	  esi,[triangles_ptr]
977
	xor	  ecx,ecx	       ; ecx - triangle number
978
	xor	  ecx,ecx	       ; ecx - triangle number
978
    .ipn_check_face:
979
    .ipn_check_face:
979
	xor	  ebx,ebx	       ; ebx - 'position' in one triangle
980
	xor	  ebx,ebx	       ; ebx - 'position' in one triangle
980
    .ipn_check_vertex:
981
    .ipn_check_vertex:
981
	movzx	  eax,word[esi+ebx]    ;  eax - point_number
982
	movzx	  eax,word[esi+ebx]    ;  eax - point_number
982
	cmp	  ax,.point_number
983
	cmp	  ax,.point_number
983
	jne	  .ipn_next_vertex
984
	jne	  .ipn_next_vertex
984
	push	  esi
985
	push	  esi
985
	mov	  esi,ecx
986
	mov	  esi,ecx
986
	lea	  esi,[esi*3]
987
	lea	  esi,[esi*3]
987
       ; lea       esi,[triangles_normals+esi*4]
988
       ; lea       esi,[triangles_normals+esi*4]
988
	shl	  esi,2
989
	shl	  esi,2
989
	add	  esi,[triangles_normals_ptr]
990
	add	  esi,[triangles_normals_ptr]
990
 
991
 
991
	fld	  .x
992
	fld	  .x
992
	fadd	  dword[esi+vec_x]	 ; vec_x this defined in 3dmath.asm - x cooficient
993
	fadd	  dword[esi+vec_x]	 ; vec_x this defined in 3dmath.asm - x cooficient
993
	fstp	  .x			 ; of normal vactor
994
	fstp	  .x			 ; of normal vactor
994
	fld	  .y
995
	fld	  .y
995
	fadd	  dword[esi+vec_y]
996
	fadd	  dword[esi+vec_y]
996
	fstp	  .y
997
	fstp	  .y
997
	fld	  .z
998
	fld	  .z
998
	fadd	  dword[esi+vec_z]
999
	fadd	  dword[esi+vec_z]
999
	fstp	  .z
1000
	fstp	  .z
1000
	pop	  esi
1001
	pop	  esi
1001
	inc	  .hit_faces
1002
	inc	  .hit_faces
1002
	jmp	  .ipn_next_face
1003
	jmp	  .ipn_next_face
1003
    .ipn_next_vertex:
1004
    .ipn_next_vertex:
1004
	add	  ebx,2
1005
	add	  ebx,2
1005
	cmp	  ebx,6
1006
	cmp	  ebx,6
1006
	jne	  .ipn_check_vertex
1007
	jne	  .ipn_check_vertex
1007
    .ipn_next_face:
1008
    .ipn_next_face:
1008
	add	  esi,6
1009
	add	  esi,6
1009
	inc	  ecx
1010
	inc	  ecx
1010
	cmp	  cx,[triangles_count_var]
1011
	cmp	  cx,[triangles_count_var]
1011
	jne	  .ipn_check_face
1012
	jne	  .ipn_check_face
1012
 
1013
 
1013
	fld	  .x
1014
	fld	  .x
1014
	fidiv	  .hit_faces
1015
	fidiv	  .hit_faces
1015
	fstp	  dword[edi+vec_x]
1016
	fstp	  dword[edi+vec_x]
1016
	fld	  .y
1017
	fld	  .y
1017
	fidiv	  .hit_faces
1018
	fidiv	  .hit_faces
1018
	fstp	  dword[edi+vec_y]
1019
	fstp	  dword[edi+vec_y]
1019
	fld	  .z
1020
	fld	  .z
1020
	fidiv	  .hit_faces
1021
	fidiv	  .hit_faces
1021
	fstp	  dword[edi+vec_z]
1022
	fstp	  dword[edi+vec_z]
1022
	call	  normalize_vector
1023
	call	  normalize_vector
1023
	add	  edi,12  ;type vector 3d
1024
	add	  edi,12  ;type vector 3d
1024
	inc	  .point_number
1025
	inc	  .point_number
1025
	mov	  dx,.point_number
1026
	mov	  dx,.point_number
1026
	cmp	  dx,[points_count_var]
1027
	cmp	  dx,[points_count_var]
1027
	jne	  .ipn_loop
1028
	jne	  .ipn_loop
1028
 
1029
 
1029
	mov	  esp,ebp
1030
	mov	  esp,ebp
1030
ret
1031
ret
1031
;===============================================================
1032
;===============================================================
1032
 
1033
 
1033
init_triangles_normals2:
1034
init_triangles_normals2:
1034
	mov	ebx,[triangles_normals_ptr]
1035
	mov	ebx,[triangles_normals_ptr]
1035
	mov	ebp,[triangles_ptr]
1036
	mov	ebp,[triangles_ptr]
1036
     @@:
1037
     @@:
1037
	push	ebx
1038
	push	ebx
1038
	mov	ebx,vectors
1039
	mov	ebx,vectors
1039
	movzx	esi,word[ebp]	       ; first point index
1040
	movzx	esi,word[ebp]	       ; first point index
1040
	lea	esi,[esi*3]
1041
	lea	esi,[esi*3]
1041
;        lea     esi,[points+esi*2]     ; esi - pointer to 1st 3d point
1042
;        lea     esi,[points+esi*2]     ; esi - pointer to 1st 3d point
1042
	shl	esi,2
1043
	shl	esi,2
1043
	add	esi,[points_ptr]
1044
	add	esi,[points_ptr]
1044
	movzx	edi,word[ebp+2] 	 ; first point index
1045
	movzx	edi,word[ebp+2] 	 ; first point index
1045
	lea	edi,[edi*3]
1046
	lea	edi,[edi*3]
1046
	shl	edi,2
1047
	shl	edi,2
1047
	add	edi,[points_ptr]
1048
	add	edi,[points_ptr]
1048
;        movzx   edi,word[ebp+2]        ; second point index
1049
;        movzx   edi,word[ebp+2]        ; second point index
1049
;        lea     edi,[edi*3]
1050
;        lea     edi,[edi*3]
1050
;        lea     edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
1051
;        lea     edi,[points+edi*2]     ; edi - pointer to 2nd 3d point
1051
	call	make_vector_r
1052
	call	make_vector_r
1052
	add	ebx,12
1053
	add	ebx,12
1053
	mov	esi,edi
1054
	mov	esi,edi
1054
	movzx	edi,word[ebp+4]        ; third point index
1055
	movzx	edi,word[ebp+4]        ; third point index
1055
	lea	edi,[edi*3]
1056
	lea	edi,[edi*3]
1056
	shl	edi,2
1057
	shl	edi,2
1057
	add	edi,[points_ptr]
1058
	add	edi,[points_ptr]
1058
;        lea     edi,[points+edi*2]
1059
;        lea     edi,[points+edi*2]
1059
	call	make_vector_r
1060
	call	make_vector_r
1060
	mov	edi,ebx 		; edi - pointer to 2nd vector
1061
	mov	edi,ebx 		; edi - pointer to 2nd vector
1061
	mov	esi,ebx
1062
	mov	esi,ebx
1062
	sub	esi,12			; esi - pointer to 1st vector
1063
	sub	esi,12			; esi - pointer to 1st vector
1063
	pop	ebx
1064
	pop	ebx
1064
	call	cross_product
1065
	call	cross_product
1065
	mov	edi,ebx
1066
	mov	edi,ebx
1066
	call	normalize_vector
1067
	call	normalize_vector
1067
	add	ebp,6
1068
	add	ebp,6
1068
	add	ebx,12
1069
	add	ebx,12
1069
	cmp	dword[ebp],-1
1070
	cmp	dword[ebp],-1
1070
	jne	@b
1071
	jne	@b
1071
ret
1072
ret
1072
 
1073
 
1073
 
1074
 
1074
;=================================================================
1075
;=================================================================
1075
sort_triangles:
1076
sort_triangles:
1076
	mov	esi,[triangles_ptr]
1077
	mov	esi,[triangles_ptr]
1077
	mov	edi,triangles_with_z
1078
	mov	edi,triangles_with_z
1078
	mov	ebp,[points_translated_ptr]
1079
	mov	ebp,[points_translated_ptr]
1079
 
1080
 
1080
    make_triangle_with_z:	;makes list with triangles and z position
1081
    make_triangle_with_z:	;makes list with triangles and z position
1081
	movzx	eax,word[esi]
1082
	movzx	eax,word[esi]
1082
	lea	eax,[eax*3]
1083
	lea	eax,[eax*3]
1083
	movzx	ecx,word[ebp+eax*2+4]
1084
	movzx	ecx,word[ebp+eax*2+4]
1084
 
1085
 
1085
	movzx	eax,word[esi+2]
1086
	movzx	eax,word[esi+2]
1086
	lea	eax,[eax*3]
1087
	lea	eax,[eax*3]
1087
	add	cx,word[ebp+eax*2+4]
1088
	add	cx,word[ebp+eax*2+4]
1088
 
1089
 
1089
	movzx	eax,word[esi+4]
1090
	movzx	eax,word[esi+4]
1090
	lea	eax,[eax*3]
1091
	lea	eax,[eax*3]
1091
	add	cx,word[ebp+eax*2+4]
1092
	add	cx,word[ebp+eax*2+4]
1092
 
1093
 
1093
	mov	ax,cx
1094
	mov	ax,cx
1094
       ; cwd
1095
       ; cwd
1095
       ; idiv    word[i3]
1096
       ; idiv    word[i3]
1096
	movsd			; store vertex coordinates
1097
	movsd			; store vertex coordinates
1097
	movsw
1098
	movsw
1098
	stosw			; middle vertex coordinate  'z' in triangles_with_z list
1099
	stosw			; middle vertex coordinate  'z' in triangles_with_z list
1099
	cmp	dword[esi],-1
1100
	cmp	dword[esi],-1
1100
	jne	make_triangle_with_z
1101
	jne	make_triangle_with_z
1101
	movsd			; copy end mark
1102
	movsd			; copy end mark
1102
	mov	eax,4
1103
	mov	eax,4
1103
	lea	edx,[edi-8-trizdd]
1104
	lea	edx,[edi-8-trizdd]
1104
     ;   lea     edx, [edi-8]
1105
     ;   lea     edx, [edi-8]
1105
     ;   sub     edx,[triangles_w_z_ptr]
1106
     ;   sub     edx,[triangles_w_z_ptr]
1106
	mov	[high],edx
1107
	mov	[high],edx
1107
	call	quicksort
1108
	call	quicksort
1108
	mov	eax,4
1109
	mov	eax,4
1109
	mov	edx,[high]
1110
	mov	edx,[high]
1110
	call	insertsort
1111
	call	insertsort
1111
	jmp	end_sort
1112
	jmp	end_sort
1112
 
1113
 
1113
    quicksort:
1114
    quicksort:
1114
	mov	ecx,edx
1115
	mov	ecx,edx
1115
	sub	ecx,eax
1116
	sub	ecx,eax
1116
	cmp	ecx,32
1117
	cmp	ecx,32
1117
	jc	.exit
1118
	jc	.exit
1118
	lea	ecx,[eax+edx]
1119
	lea	ecx,[eax+edx]
1119
	shr	ecx,4
1120
	shr	ecx,4
1120
	lea	ecx,[ecx*8-4];
1121
	lea	ecx,[ecx*8-4];
1121
;        mov     edi,[triangles_w_z_ptr]
1122
;        mov     edi,[triangles_w_z_ptr]
1122
;        mov     ebx,[edi+eax]
1123
;        mov     ebx,[edi+eax]
1123
;        mov     esi,[edi+ecx]
1124
;        mov     esi,[edi+ecx]
1124
;        mov     edi,[edi+edx]
1125
;        mov     edi,[edi+edx]
1125
	mov	ebx,[trizdd+eax]; trizdd[l]
1126
	mov	ebx,[trizdd+eax]; trizdd[l]
1126
	mov	esi,[trizdd+ecx]; trizdd[i]
1127
	mov	esi,[trizdd+ecx]; trizdd[i]
1127
	mov	edi,[trizdd+edx]; trizdd[h]
1128
	mov	edi,[trizdd+edx]; trizdd[h]
1128
	cmp	ebx,esi
1129
	cmp	ebx,esi
1129
	jg	@f		; direction NB! you need to negate these to invert the order
1130
	jg	@f		; direction NB! you need to negate these to invert the order
1130
      if Ext=NON
1131
      if Ext=NON
1131
	mov	[trizdd+eax],esi
1132
	mov	[trizdd+eax],esi
1132
	mov	[trizdd+ecx],ebx
1133
	mov	[trizdd+ecx],ebx
1133
	mov	ebx,[trizdd+eax-4]
1134
	mov	ebx,[trizdd+eax-4]
1134
	mov	esi,[trizdd+ecx-4]
1135
	mov	esi,[trizdd+ecx-4]
1135
	mov	[trizdd+eax-4],esi
1136
	mov	[trizdd+eax-4],esi
1136
	mov	[trizdd+ecx-4],ebx
1137
	mov	[trizdd+ecx-4],ebx
1137
	mov	ebx,[trizdd+eax]
1138
	mov	ebx,[trizdd+eax]
1138
	mov	esi,[trizdd+ecx]
1139
	mov	esi,[trizdd+ecx]
1139
      else
1140
      else
1140
;        push    ebx
1141
;        push    ebx
1141
;        mov     ebx,[triangles_w_z_ptr]
1142
;        mov     ebx,[triangles_w_z_ptr]
1142
;        movq    mm0,[ebx+eax-4]
1143
;        movq    mm0,[ebx+eax-4]
1143
;        movq    mm1,[ebx+ecx-4]
1144
;        movq    mm1,[ebx+ecx-4]
1144
;        movq    [ebx+ecx-4],mm0
1145
;        movq    [ebx+ecx-4],mm0
1145
;        movq    [ebx+eax-4],mm1
1146
;        movq    [ebx+eax-4],mm1
1146
;        pop     ebx
1147
;        pop     ebx
1147
	movq	mm0,[trizdq+eax-4]
1148
	movq	mm0,[trizdq+eax-4]
1148
	movq	mm1,[trizdq+ecx-4]
1149
	movq	mm1,[trizdq+ecx-4]
1149
	movq	[trizdq+ecx-4],mm0
1150
	movq	[trizdq+ecx-4],mm0
1150
	movq	[trizdq+eax-4],mm1
1151
	movq	[trizdq+eax-4],mm1
1151
	xchg	ebx,esi
1152
	xchg	ebx,esi
1152
      end if
1153
      end if
1153
      @@:
1154
      @@:
1154
	cmp	ebx,edi
1155
	cmp	ebx,edi
1155
	jg	@f		; direction
1156
	jg	@f		; direction
1156
      if Ext=NON
1157
      if Ext=NON
1157
	mov	[trizdd+eax],edi
1158
	mov	[trizdd+eax],edi
1158
	mov	[trizdd+edx],ebx
1159
	mov	[trizdd+edx],ebx
1159
	mov	ebx,[trizdd+eax-4]
1160
	mov	ebx,[trizdd+eax-4]
1160
	mov	edi,[trizdd+edx-4]
1161
	mov	edi,[trizdd+edx-4]
1161
	mov	[trizdd+eax-4],edi
1162
	mov	[trizdd+eax-4],edi
1162
	mov	[trizdd+edx-4],ebx
1163
	mov	[trizdd+edx-4],ebx
1163
	mov	ebx,[trizdd+eax]
1164
	mov	ebx,[trizdd+eax]
1164
	mov	edi,[trizdd+edx]
1165
	mov	edi,[trizdd+edx]
1165
      else
1166
      else
1166
;        push    ebx
1167
;        push    ebx
1167
;        mov     ebx,[triangles_w_z_ptr]
1168
;        mov     ebx,[triangles_w_z_ptr]
1168
;        movq    mm0,[ebx+eax-4]
1169
;        movq    mm0,[ebx+eax-4]
1169
;        movq    mm1,[ebx+edx-4]
1170
;        movq    mm1,[ebx+edx-4]
1170
;        movq    [ebx+edx-4],mm0
1171
;        movq    [ebx+edx-4],mm0
1171
;        movq    [ebx+eax-4],mm1
1172
;        movq    [ebx+eax-4],mm1
1172
	movq	mm0,[trizdq+eax-4]
1173
	movq	mm0,[trizdq+eax-4]
1173
	movq	mm1,[trizdq+edx-4]
1174
	movq	mm1,[trizdq+edx-4]
1174
	movq	[trizdq+edx-4],mm0
1175
	movq	[trizdq+edx-4],mm0
1175
	movq	[trizdq+eax-4],mm1
1176
	movq	[trizdq+eax-4],mm1
1176
;        pop     ebx
1177
;        pop     ebx
1177
	xchg	ebx,edi
1178
	xchg	ebx,edi
1178
      end if
1179
      end if
1179
      @@:
1180
      @@:
1180
	cmp	esi,edi
1181
	cmp	esi,edi
1181
	jg	@f		; direction
1182
	jg	@f		; direction
1182
      if Ext=NON
1183
      if Ext=NON
1183
	mov	[trizdd+ecx],edi
1184
	mov	[trizdd+ecx],edi
1184
	mov	[trizdd+edx],esi
1185
	mov	[trizdd+edx],esi
1185
	mov	esi,[trizdd+ecx-4]
1186
	mov	esi,[trizdd+ecx-4]
1186
	mov	edi,[trizdd+edx-4]
1187
	mov	edi,[trizdd+edx-4]
1187
	mov	[trizdd+ecx-4],edi
1188
	mov	[trizdd+ecx-4],edi
1188
	mov	[trizdd+edx-4],esi
1189
	mov	[trizdd+edx-4],esi
1189
      else
1190
      else
1190
;        push    ebx
1191
;        push    ebx
1191
;        mov     ebx,[triangles_w_z_ptr]
1192
;        mov     ebx,[triangles_w_z_ptr]
1192
;        movq    mm0,[ebx+ecx-4]
1193
;        movq    mm0,[ebx+ecx-4]
1193
;        movq    mm1,[ebx+edx-4]
1194
;        movq    mm1,[ebx+edx-4]
1194
;        movq    [ebx+edx-4],mm0
1195
;        movq    [ebx+edx-4],mm0
1195
;        movq    [ebx+ecx-4],mm1
1196
;        movq    [ebx+ecx-4],mm1
1196
;        pop     ebx
1197
;        pop     ebx
1197
 
1198
 
1198
	movq	mm0,[trizdq+ecx-4]
1199
	movq	mm0,[trizdq+ecx-4]
1199
	movq	mm1,[trizdq+edx-4]
1200
	movq	mm1,[trizdq+edx-4]
1200
	movq	[trizdq+edx-4],mm0
1201
	movq	[trizdq+edx-4],mm0
1201
	movq	[trizdq+ecx-4],mm1
1202
	movq	[trizdq+ecx-4],mm1
1202
	xchg	ebx,esi
1203
	xchg	ebx,esi
1203
      end if
1204
      end if
1204
      @@:
1205
      @@:
1205
	mov	ebp,eax 	; direction
1206
	mov	ebp,eax 	; direction
1206
	add	ebp,8	   ;   j
1207
	add	ebp,8	   ;   j
1207
      if Ext=NON
1208
      if Ext=NON
1208
	mov	esi,[trizdd+ebp]
1209
	mov	esi,[trizdd+ebp]
1209
	mov	edi,[trizdd+ecx]
1210
	mov	edi,[trizdd+ecx]
1210
	mov	[trizdd+ebp],edi
1211
	mov	[trizdd+ebp],edi
1211
	mov	[trizdd+ecx],esi
1212
	mov	[trizdd+ecx],esi
1212
	mov	esi,[trizdd+ebp-4]
1213
	mov	esi,[trizdd+ebp-4]
1213
	mov	edi,[trizdd+ecx-4]
1214
	mov	edi,[trizdd+ecx-4]
1214
	mov	[trizdd+ecx-4],esi
1215
	mov	[trizdd+ecx-4],esi
1215
	mov	[trizdd+ebp-4],edi
1216
	mov	[trizdd+ebp-4],edi
1216
      else
1217
      else
1217
;        push    ebx
1218
;        push    ebx
1218
;        mov     ebx,[triangles_w_z_ptr]
1219
;        mov     ebx,[triangles_w_z_ptr]
1219
;        movq    mm0,[ebx+ebp-4]
1220
;        movq    mm0,[ebx+ebp-4]
1220
;        movq    mm1,[ebx+ecx-4]
1221
;        movq    mm1,[ebx+ecx-4]
1221
;        movq    [ebx+ecx-4],mm0
1222
;        movq    [ebx+ecx-4],mm0
1222
;        movq    [ebx+ebp-4],mm1
1223
;        movq    [ebx+ebp-4],mm1
1223
;        pop     ebx
1224
;        pop     ebx
1224
 
1225
 
1225
	movq	mm0,[trizdq+ebp-4]
1226
	movq	mm0,[trizdq+ebp-4]
1226
	movq	mm1,[trizdq+ecx-4]
1227
	movq	mm1,[trizdq+ecx-4]
1227
	movq	[trizdq+ecx-4],mm0
1228
	movq	[trizdq+ecx-4],mm0
1228
	movq	[trizdq+ebp-4],mm1
1229
	movq	[trizdq+ebp-4],mm1
1229
      end if
1230
      end if
1230
	mov	ecx,edx    ;   i; direction
1231
	mov	ecx,edx    ;   i; direction
1231
	mov	ebx,[trizdd+ebp]; trizdd[j]
1232
	mov	ebx,[trizdd+ebp]; trizdd[j]
1232
;        mov     ebx, [triangles_w_z_ptr]
1233
;        mov     ebx, [triangles_w_z_ptr]
1233
;        add     ebx, ebp
1234
;        add     ebx, ebp
1234
 
1235
 
1235
 ;       push    eax
1236
 ;       push    eax
1236
 ;       mov     eax, [triangles_w_z_ptr]
1237
 ;       mov     eax, [triangles_w_z_ptr]
1237
      .loop:
1238
      .loop:
1238
	sub	ecx,8		; direction
1239
	sub	ecx,8		; direction
1239
	cmp	[trizdd+ecx],ebx
1240
	cmp	[trizdd+ecx],ebx
1240
;        cmp     [eax+ecx],ebx
1241
;        cmp     [eax+ecx],ebx
1241
	jl	.loop		; direction
1242
	jl	.loop		; direction
1242
      @@:
1243
      @@:
1243
	add	ebp,8		; direction
1244
	add	ebp,8		; direction
1244
	cmp	[trizdd+ebp],ebx
1245
	cmp	[trizdd+ebp],ebx
1245
;        cmp     [eax+ebp],ebx
1246
;        cmp     [eax+ebp],ebx
1246
	jg	@b		; direction
1247
	jg	@b		; direction
1247
	cmp	ebp,ecx
1248
	cmp	ebp,ecx
1248
	jge	@f		; direction
1249
	jge	@f		; direction
1249
      if Ext=NON
1250
      if Ext=NON
1250
	mov	esi,[trizdd+ecx]
1251
	mov	esi,[trizdd+ecx]
1251
	mov	edi,[trizdd+ebp]
1252
	mov	edi,[trizdd+ebp]
1252
	mov	[trizdd+ebp],esi
1253
	mov	[trizdd+ebp],esi
1253
	mov	[trizdd+ecx],edi
1254
	mov	[trizdd+ecx],edi
1254
	mov	edi,[trizdd+ecx-4]
1255
	mov	edi,[trizdd+ecx-4]
1255
	mov	esi,[trizdd+ebp-4]
1256
	mov	esi,[trizdd+ebp-4]
1256
	mov	[trizdd+ebp-4],edi
1257
	mov	[trizdd+ebp-4],edi
1257
	mov	[trizdd+ecx-4],esi
1258
	mov	[trizdd+ecx-4],esi
1258
      else
1259
      else
1259
;        movq    mm0,[eax+ecx-4]
1260
;        movq    mm0,[eax+ecx-4]
1260
;        movq    mm1,[eax+ebp-4]
1261
;        movq    mm1,[eax+ebp-4]
1261
;        movq    [eax+ebp-4],mm0
1262
;        movq    [eax+ebp-4],mm0
1262
;        movq    [eax+ecx-4],mm1
1263
;        movq    [eax+ecx-4],mm1
1263
	movq	mm0,[trizdq+ecx-4]
1264
	movq	mm0,[trizdq+ecx-4]
1264
	movq	mm1,[trizdq+ebp-4]
1265
	movq	mm1,[trizdq+ebp-4]
1265
	movq	[trizdq+ebp-4],mm0
1266
	movq	[trizdq+ebp-4],mm0
1266
	movq	[trizdq+ecx-4],mm1
1267
	movq	[trizdq+ecx-4],mm1
1267
      end if
1268
      end if
1268
	jmp	.loop
1269
	jmp	.loop
1269
;        pop     eax
1270
;        pop     eax
1270
      @@:
1271
      @@:
1271
      if Ext=NON
1272
      if Ext=NON
1272
	mov	esi,[trizdd+ecx]
1273
	mov	esi,[trizdd+ecx]
1273
	mov	edi,[trizdd+eax+8]
1274
	mov	edi,[trizdd+eax+8]
1274
	mov	[trizdd+eax+8],esi
1275
	mov	[trizdd+eax+8],esi
1275
	mov	[trizdd+ecx],edi
1276
	mov	[trizdd+ecx],edi
1276
	mov	edi,[trizdd+ecx-4]
1277
	mov	edi,[trizdd+ecx-4]
1277
	mov	esi,[trizdd+eax+4]
1278
	mov	esi,[trizdd+eax+4]
1278
	mov	[trizdd+eax+4],edi
1279
	mov	[trizdd+eax+4],edi
1279
	mov	[trizdd+ecx-4],esi
1280
	mov	[trizdd+ecx-4],esi
1280
      else
1281
      else
1281
;        push    edx
1282
;        push    edx
1282
;        mov     edx,[triangles_w_z_ptr]
1283
;        mov     edx,[triangles_w_z_ptr]
1283
;        movq    mm0,[edx+ecx-4]
1284
;        movq    mm0,[edx+ecx-4]
1284
;        movq    mm1,[edx+eax+4]; dir
1285
;        movq    mm1,[edx+eax+4]; dir
1285
;        movq    [edx+eax+4],mm0; dir
1286
;        movq    [edx+eax+4],mm0; dir
1286
;        movq    [edx+ecx-4],mm1
1287
;        movq    [edx+ecx-4],mm1
1287
;        pop     edx
1288
;        pop     edx
1288
 
1289
 
1289
	movq	mm0,[trizdq+ecx-4]
1290
	movq	mm0,[trizdq+ecx-4]
1290
	movq	mm1,[trizdq+eax+4]; dir
1291
	movq	mm1,[trizdq+eax+4]; dir
1291
	movq	[trizdq+eax+4],mm0; dir
1292
	movq	[trizdq+eax+4],mm0; dir
1292
	movq	[trizdq+ecx-4],mm1
1293
	movq	[trizdq+ecx-4],mm1
1293
      end if
1294
      end if
1294
	add	ecx,8
1295
	add	ecx,8
1295
	push	ecx edx
1296
	push	ecx edx
1296
	mov	edx,ebp
1297
	mov	edx,ebp
1297
	call	quicksort
1298
	call	quicksort
1298
	pop	edx eax
1299
	pop	edx eax
1299
	call	quicksort
1300
	call	quicksort
1300
      .exit:
1301
      .exit:
1301
    ret
1302
    ret
1302
    insertsort:
1303
    insertsort:
1303
	mov	esi,eax
1304
	mov	esi,eax
1304
      .start:
1305
      .start:
1305
	add	esi,8
1306
	add	esi,8
1306
	cmp	esi,edx
1307
	cmp	esi,edx
1307
	ja	.exit
1308
	ja	.exit
1308
	mov	ebx,[trizdd+esi]
1309
	mov	ebx,[trizdd+esi]
1309
;        mov     ebx,[triangles_w_z_ptr]
1310
;        mov     ebx,[triangles_w_z_ptr]
1310
;        add     ebx,esi
1311
;        add     ebx,esi
1311
      if Ext=NON
1312
      if Ext=NON
1312
	mov	ecx,[trizdd+esi-4]
1313
	mov	ecx,[trizdd+esi-4]
1313
      else
1314
      else
1314
;        push    ebx
1315
;        push    ebx
1315
;        mov     ebx,[triangles_w_z_ptr]
1316
;        mov     ebx,[triangles_w_z_ptr]
1316
;        movq    mm1,[ebx+esi-4]
1317
;        movq    mm1,[ebx+esi-4]
1317
	movq	mm1,[trizdq+esi-4]
1318
	movq	mm1,[trizdq+esi-4]
1318
;        pop     ebx
1319
;        pop     ebx
1319
      end if
1320
      end if
1320
	mov	edi,esi
1321
	mov	edi,esi
1321
      @@:
1322
      @@:
1322
	cmp	edi,eax
1323
	cmp	edi,eax
1323
	jna	@f
1324
	jna	@f
1324
;        push    eax
1325
;        push    eax
1325
;        mov     eax,[triangles_w_z_ptr]
1326
;        mov     eax,[triangles_w_z_ptr]
1326
;        cmp     [eax+edi-8],ebx
1327
;        cmp     [eax+edi-8],ebx
1327
;        pop     eax
1328
;        pop     eax
1328
       cmp     [trizdd+edi-8],ebx
1329
       cmp     [trizdd+edi-8],ebx
1329
	jg	@f		   ; direction
1330
	jg	@f		   ; direction
1330
      if Ext=NON
1331
      if Ext=NON
1331
	mov	ebp,[trizdd+edi-8]
1332
	mov	ebp,[trizdd+edi-8]
1332
	mov	[trizdd+edi],ebp
1333
	mov	[trizdd+edi],ebp
1333
	mov	ebp,[trizdd+edi-12]
1334
	mov	ebp,[trizdd+edi-12]
1334
	mov	[trizdd+edi-4],ebp
1335
	mov	[trizdd+edi-4],ebp
1335
      else
1336
      else
1336
;        push    eax
1337
;        push    eax
1337
;        mov     eax,[triangles_w_z_ptr]
1338
;        mov     eax,[triangles_w_z_ptr]
1338
;        movq    mm0,[eax+edi-12]
1339
;        movq    mm0,[eax+edi-12]
1339
;        movq    [eax+edi-4],mm0
1340
;        movq    [eax+edi-4],mm0
1340
	movq	mm0,[trizdq+edi-12]
1341
	movq	mm0,[trizdq+edi-12]
1341
	movq	[trizdq+edi-4],mm0
1342
	movq	[trizdq+edi-4],mm0
1342
;        pop     eax
1343
;        pop     eax
1343
      end if
1344
      end if
1344
	sub	edi,8
1345
	sub	edi,8
1345
	jmp	@b
1346
	jmp	@b
1346
      @@:
1347
      @@:
1347
      if Ext=NON
1348
      if Ext=NON
1348
	mov	[trizdd+edi],ebx
1349
	mov	[trizdd+edi],ebx
1349
	mov	[trizdd+edi-4],ecx
1350
	mov	[trizdd+edi-4],ecx
1350
      else
1351
      else
1351
;        push    eax
1352
;        push    eax
1352
;        mov     eax,[triangles_w_z_ptr]
1353
;        mov     eax,[triangles_w_z_ptr]
1353
;        movq    [eax+edi-4],mm1
1354
;        movq    [eax+edi-4],mm1
1354
	movq	[trizdq+edi-4],mm1
1355
	movq	[trizdq+edi-4],mm1
1355
;        pop     eax
1356
;        pop     eax
1356
      end if
1357
      end if
1357
	jmp	.start
1358
	jmp	.start
1358
      .exit:
1359
      .exit:
1359
    ret
1360
    ret
1360
   end_sort:
1361
   end_sort:
1361
    ; translate triangles_with_z to sorted_triangles
1362
    ; translate triangles_with_z to sorted_triangles
1362
	mov	esi,triangles_with_z
1363
	mov	esi,triangles_with_z
1363
;        mov      esi,[triangles_w_z_ptr]
1364
;        mov      esi,[triangles_w_z_ptr]
1364
      ;  mov     edi,sorted_triangles
1365
      ;  mov     edi,sorted_triangles
1365
	mov	 edi,[triangles_ptr]
1366
	mov	 edi,[triangles_ptr]
1366
    again_copy:
1367
    again_copy:
1367
      if Ext=NON
1368
      if Ext=NON
1368
	movsd
1369
	movsd
1369
	movsw
1370
	movsw
1370
	add	esi,2
1371
	add	esi,2
1371
      else
1372
      else
1372
	movq	mm0,[esi]
1373
	movq	mm0,[esi]
1373
	movq	[edi],mm0
1374
	movq	[edi],mm0
1374
	add	esi,8
1375
	add	esi,8
1375
	add	edi,6
1376
	add	edi,6
1376
      end if
1377
      end if
1377
	cmp	dword[esi],-1
1378
	cmp	dword[esi],-1
1378
	jne	again_copy
1379
	jne	again_copy
1379
;      if Ext=MMX
1380
;      if Ext=MMX
1380
;        emms
1381
;        emms
1381
;      end if
1382
;      end if
1382
	movsd  ; copy end mark too
1383
	movsd  ; copy end mark too
1383
ret
1384
ret
1384
 
1385
 
1385
clrscr:
1386
clrscr:
1386
	mov	edi,screen
1387
	mov	edi,screen
1387
	mov	ecx,SIZE_X*SIZE_Y*3/4
1388
	mov	ecx,SIZE_X*SIZE_Y*3/4
1388
	xor	eax,eax
1389
	xor	eax,eax
1389
      if Ext=NON
1390
      if Ext=NON
1390
	rep	stosd
1391
	rep	stosd
1391
      else
1392
      else
1392
	pxor	mm0,mm0
1393
	pxor	mm0,mm0
1393
      @@:
1394
      @@:
1394
	movq	[edi+00],mm0
1395
	movq	[edi+00],mm0
1395
	movq	[edi+08],mm0
1396
	movq	[edi+08],mm0
1396
	movq	[edi+16],mm0
1397
	movq	[edi+16],mm0
1397
	movq	[edi+24],mm0
1398
	movq	[edi+24],mm0
1398
	add	edi,32
1399
	add	edi,32
1399
	sub	ecx,8
1400
	sub	ecx,8
1400
	jnc	@b
1401
	jnc	@b
1401
      end if
1402
      end if
1402
ret
1403
ret
1403
 
1404
 
1404
 
1405
 
1405
draw_triangles:
1406
draw_triangles:
1406
	mov esi,[triangles_ptr]
1407
	mov esi,[triangles_ptr]
1407
    .again_dts:
1408
    .again_dts:
1408
	mov ebp,[points_translated_ptr]
1409
	mov ebp,[points_translated_ptr]
1409
      if Ext=NON
1410
      if Ext=NON
1410
	movzx	eax,word[esi]
1411
	movzx	eax,word[esi]
1411
	mov	[point_index1],ax
1412
	mov	[point_index1],ax
1412
	lea	eax,[eax*3]
1413
	lea	eax,[eax*3]
1413
	add	eax,eax
1414
	add	eax,eax
1414
	push	ebp
1415
	push	ebp
1415
	add	ebp,eax
1416
	add	ebp,eax
1416
	mov	eax,[ebp]
1417
	mov	eax,[ebp]
1417
	mov	dword[xx1],eax
1418
	mov	dword[xx1],eax
1418
	mov	eax,[ebp+4]
1419
	mov	eax,[ebp+4]
1419
	mov	[zz1],ax
1420
	mov	[zz1],ax
1420
	pop	ebp
1421
	pop	ebp
1421
 
1422
 
1422
 
1423
 
1423
	movzx	eax,word[esi+2]
1424
	movzx	eax,word[esi+2]
1424
	mov	[point_index2],ax
1425
	mov	[point_index2],ax
1425
	lea	eax,[eax*3]
1426
	lea	eax,[eax*3]
1426
	add	eax,eax
1427
	add	eax,eax
1427
	push	ebp
1428
	push	ebp
1428
	add	ebp,eax
1429
	add	ebp,eax
1429
	mov	eax,[ebp]
1430
	mov	eax,[ebp]
1430
	mov	dword[xx2],eax
1431
	mov	dword[xx2],eax
1431
	mov	eax,[ebp+4]
1432
	mov	eax,[ebp+4]
1432
	mov	[zz2],ax
1433
	mov	[zz2],ax
1433
	pop	ebp
1434
	pop	ebp
1434
 
1435
 
1435
 
1436
 
1436
	movzx	eax,word[esi+4]        ; xyz3 = [ebp+[esi+4]*6]
1437
	movzx	eax,word[esi+4]        ; xyz3 = [ebp+[esi+4]*6]
1437
	mov	[point_index3],ax
1438
	mov	[point_index3],ax
1438
	lea	eax,[eax*3]
1439
	lea	eax,[eax*3]
1439
	add	eax,eax
1440
	add	eax,eax
1440
    ;    push    ebp
1441
    ;    push    ebp
1441
	add	ebp,eax
1442
	add	ebp,eax
1442
	mov	eax,[ebp]
1443
	mov	eax,[ebp]
1443
	mov	dword[xx3],eax
1444
	mov	dword[xx3],eax
1444
	mov	eax,[ebp+4]
1445
	mov	eax,[ebp+4]
1445
	mov	[zz3],ax
1446
	mov	[zz3],ax
1446
      else
1447
      else
1447
	mov	eax,dword[esi]		 ; don't know MMX
1448
	mov	eax,dword[esi]		 ; don't know MMX
1448
	mov	dword[point_index1],eax
1449
	mov	dword[point_index1],eax
1449
       ; shr     eax,16
1450
       ; shr     eax,16
1450
       ; mov     [point_index2],ax
1451
       ; mov     [point_index2],ax
1451
	mov	ax,word[esi+4]
1452
	mov	ax,word[esi+4]
1452
	mov	[point_index3],ax
1453
	mov	[point_index3],ax
1453
	movq	mm0,[esi]
1454
	movq	mm0,[esi]
1454
	pmullw	mm0,qword[const6]
1455
	pmullw	mm0,qword[const6]
1455
	movd	eax,mm0
1456
	movd	eax,mm0
1456
	psrlq	mm0,16
1457
	psrlq	mm0,16
1457
	movd	ebx,mm0
1458
	movd	ebx,mm0
1458
	psrlq	mm0,16
1459
	psrlq	mm0,16
1459
	movd	ecx,mm0
1460
	movd	ecx,mm0
1460
	and	eax,0FFFFh
1461
	and	eax,0FFFFh
1461
	and	ebx,0FFFFh
1462
	and	ebx,0FFFFh
1462
	and	ecx,0FFFFh
1463
	and	ecx,0FFFFh
1463
	movq	mm0,[ebp+eax]
1464
	movq	mm0,[ebp+eax]
1464
	movq	mm1,[ebp+ebx]
1465
	movq	mm1,[ebp+ebx]
1465
	movq	mm2,[ebp+ecx]
1466
	movq	mm2,[ebp+ecx]
1466
	movq	qword[xx1],mm0
1467
	movq	qword[xx1],mm0
1467
	movq	qword[xx2],mm1
1468
	movq	qword[xx2],mm1
1468
	movq	qword[xx3],mm2
1469
	movq	qword[xx3],mm2
1469
;        emms
1470
;        emms
1470
      end if				  ; *********************************
1471
      end if				  ; *********************************
1471
	push esi			  ;
1472
	push esi			  ;
1472
	fninit				  ; DO culling AT FIRST
1473
	fninit				  ; DO culling AT FIRST
1473
	cmp	[culling_flag],1	  ; (if culling_flag = 1)
1474
	cmp	[culling_flag],1	  ; (if culling_flag = 1)
1474
	jne	.no_culling
1475
	jne	.no_culling
1475
	mov	esi,point_index1	  ; *********************************
1476
	mov	esi,point_index1	  ; *********************************
1476
	mov	ecx,3			  ;
1477
	mov	ecx,3			  ;
1477
      @@:
1478
      @@:
1478
	movzx	eax,word[esi]
1479
	movzx	eax,word[esi]
1479
	lea	eax,[eax*3]
1480
	lea	eax,[eax*3]
1480
	shl	eax,2
1481
	shl	eax,2
1481
	add	eax,[points_normals_rot_ptr]
1482
	add	eax,[points_normals_rot_ptr]
1482
;        lea     eax,[eax+point_normals_rotated]
1483
;        lea     eax,[eax+point_normals_rotated]
1483
	fld	dword[eax+8]		 ; *****************************
1484
	fld	dword[eax+8]		 ; *****************************
1484
	ftst				 ; CHECKING OF Z COOFICIENT OF
1485
	ftst				 ; CHECKING OF Z COOFICIENT OF
1485
	fstsw	ax			 ; NORMAL VECTOR
1486
	fstsw	ax			 ; NORMAL VECTOR
1486
	sahf
1487
	sahf
1487
	jb	@f
1488
	jb	@f
1488
	ffree	st
1489
	ffree	st
1489
	loop	@b
1490
	loop	@b
1490
	jmp	.end_draw   ; non visable
1491
	jmp	.end_draw   ; non visable
1491
      @@:
1492
      @@:
1492
	ffree	st  ;is visable
1493
	ffree	st  ;is visable
1493
      .no_culling:
1494
      .no_culling:
1494
	cmp	[dr_flag],0		  ; draw type flag
1495
	cmp	[dr_flag],0		  ; draw type flag
1495
	je	.flat_draw
1496
	je	.flat_draw
1496
	cmp	[dr_flag],2
1497
	cmp	[dr_flag],2
1497
	je	.env_mapping
1498
	je	.env_mapping
1498
	cmp	[dr_flag],3
1499
	cmp	[dr_flag],3
1499
	je	.bump_mapping
1500
	je	.bump_mapping
1500
	cmp	[dr_flag],4
1501
	cmp	[dr_flag],4
1501
	je	.tex_mapping
1502
	je	.tex_mapping
1502
	cmp	[dr_flag],5
1503
	cmp	[dr_flag],5
1503
	je	.rainbow
1504
	je	.rainbow
1504
	cmp	[dr_flag],7
1505
	cmp	[dr_flag],7
1505
	je	.grd_tex
1506
	je	.grd_tex
1506
	cmp	[dr_flag],8
1507
	cmp	[dr_flag],8
1507
	je	.two_tex
1508
	je	.two_tex
1508
	cmp	[dr_flag],9
1509
	cmp	[dr_flag],9
1509
	je	.bump_tex
1510
	je	.bump_tex
1510
	cmp	[dr_flag],10
1511
	cmp	[dr_flag],10
1511
	je	.cubic_env_mapping
1512
	je	.cubic_env_mapping
1512
				      ; ****************
1513
				      ; ****************
1513
	mov	esi,point_index3      ; do Gouraud shading
1514
	mov	esi,point_index3      ; do Gouraud shading
1514
	mov	ecx,3
1515
	mov	ecx,3
1515
      .again_grd_draw:
1516
      .again_grd_draw:
1516
	movzx	eax,word[esi]
1517
	movzx	eax,word[esi]
1517
	shl	eax,2
1518
	shl	eax,2
1518
	lea	eax,[eax*3]
1519
	lea	eax,[eax*3]
1519
	add	eax,[points_normals_rot_ptr]
1520
	add	eax,[points_normals_rot_ptr]
1520
	; texture x=(rotated point normal -> x * 255)+255
1521
	; texture x=(rotated point normal -> x * 255)+255
1521
	fld	dword[eax]	 ; x cooficient of normal vector
1522
	fld	dword[eax]	 ; x cooficient of normal vector
1522
	fimul	[correct_tex]
1523
	fimul	[correct_tex]
1523
	fiadd	[correct_tex]
1524
	fiadd	[correct_tex]
1524
	fistp	word[esp-2]
1525
	fistp	word[esp-2]
1525
	; texture y=(rotated point normal -> y * 255)+255
1526
	; texture y=(rotated point normal -> y * 255)+255
1526
	fld	dword[eax+4]	  ; y cooficient
1527
	fld	dword[eax+4]	  ; y cooficient
1527
	fimul	[correct_tex]
1528
	fimul	[correct_tex]
1528
	fiadd	[correct_tex]
1529
	fiadd	[correct_tex]
1529
	fistp	word[esp-4]
1530
	fistp	word[esp-4]
1530
 
1531
 
1531
	movzx	 eax,word[esp-4]
1532
	movzx	 eax,word[esp-4]
1532
	movzx	 ebx,word[esp-2]
1533
	movzx	 ebx,word[esp-2]
1533
	shl	 eax,TEX_SHIFT
1534
	shl	 eax,TEX_SHIFT
1534
	add	 eax,ebx
1535
	add	 eax,ebx
1535
	lea	 eax,[eax*3+color_map]
1536
	lea	 eax,[eax*3+color_map]
1536
	mov	 eax,dword[eax]
1537
	mov	 eax,dword[eax]
1537
	cmp	[catmull_flag],1      ; put on stack z coordinate if necessary
1538
	cmp	[catmull_flag],1      ; put on stack z coordinate if necessary
1538
	jne	 @f
1539
	jne	 @f
1539
	lea	 edx,[ecx*3]
1540
	lea	 edx,[ecx*3]
1540
	push	 word[edx*2+xx1-2]    ; zz1 ,2 ,3
1541
	push	 word[edx*2+xx1-2]    ; zz1 ,2 ,3
1541
      @@:
1542
      @@:
1542
	ror	 eax,16 	      ; eax -0xxxrrggbb -> 0xggbbxxrr
1543
	ror	 eax,16 	      ; eax -0xxxrrggbb -> 0xggbbxxrr
1543
	xor	 ah,ah
1544
	xor	 ah,ah
1544
	push	 ax	    ;r
1545
	push	 ax	    ;r
1545
	rol	 eax,8		      ; eax-0xggbb00rr -> 0xbb00rrgg
1546
	rol	 eax,8		      ; eax-0xggbb00rr -> 0xbb00rrgg
1546
	xor	 ah,ah
1547
	xor	 ah,ah
1547
	push	 ax	    ;g
1548
	push	 ax	    ;g
1548
	shr	 eax,24
1549
	shr	 eax,24
1549
	push	 ax	    ;b
1550
	push	 ax	    ;b
1550
 
1551
 
1551
	sub	 esi,2
1552
	sub	 esi,2
1552
	dec	 cx
1553
	dec	 cx
1553
	jnz	 .again_grd_draw
1554
	jnz	 .again_grd_draw
1554
	jmp	 .both_draw
1555
	jmp	 .both_draw
1555
 
1556
 
1556
   ;     movzx   edi,[point_index3]   ;gouraud shading according to light vector
1557
   ;     movzx   edi,[point_index3]   ;gouraud shading according to light vector
1557
   ;     lea     edi,[edi*3]
1558
   ;     lea     edi,[edi*3]
1558
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1559
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1559
   ;     mov     esi,light_vector
1560
   ;     mov     esi,light_vector
1560
   ;     call    dot_product
1561
   ;     call    dot_product
1561
   ;     fabs
1562
   ;     fabs
1562
   ;     fimul   [orginal_color_r]
1563
   ;     fimul   [orginal_color_r]
1563
   ;     fistp   [temp_col]
1564
   ;     fistp   [temp_col]
1564
   ;     and     [temp_col],0x00ff
1565
   ;     and     [temp_col],0x00ff
1565
   ;     push    [temp_col]
1566
   ;     push    [temp_col]
1566
   ;     push    [temp_col]
1567
   ;     push    [temp_col]
1567
   ;     push    [temp_col]
1568
   ;     push    [temp_col]
1568
 
1569
 
1569
   ;     movzx   edi,[point_index2]
1570
   ;     movzx   edi,[point_index2]
1570
   ;     lea     edi,[edi*3]
1571
   ;     lea     edi,[edi*3]
1571
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1572
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1572
   ;     mov     esi,light_vector
1573
   ;     mov     esi,light_vector
1573
   ;     call    dot_product
1574
   ;     call    dot_product
1574
   ;     fabs
1575
   ;     fabs
1575
   ;     fimul   [orginal_color_r]
1576
   ;     fimul   [orginal_color_r]
1576
   ;     fistp    [temp_col]
1577
   ;     fistp    [temp_col]
1577
   ;     and     [temp_col],0x00ff
1578
   ;     and     [temp_col],0x00ff
1578
   ;     push    [temp_col]
1579
   ;     push    [temp_col]
1579
   ;     push    [temp_col]
1580
   ;     push    [temp_col]
1580
   ;     push    [temp_col]
1581
   ;     push    [temp_col]
1581
 
1582
 
1582
   ;     movzx   edi,[point_index1]
1583
   ;     movzx   edi,[point_index1]
1583
   ;     lea     edi,[edi*3]
1584
   ;     lea     edi,[edi*3]
1584
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1585
   ;     lea     edi,[4*edi+point_normals_rotated] ; edi - normal
1585
   ;     mov     esi,light_vector
1586
   ;     mov     esi,light_vector
1586
   ;     call    dot_product
1587
   ;     call    dot_product
1587
   ;     fabs
1588
   ;     fabs
1588
   ;     fimul   [orginal_color_r]
1589
   ;     fimul   [orginal_color_r]
1589
   ;     fistp   [temp_col]
1590
   ;     fistp   [temp_col]
1590
   ;     and     [temp_col],0x00ff
1591
   ;     and     [temp_col],0x00ff
1591
   ;     push    [temp_col]
1592
   ;     push    [temp_col]
1592
   ;     push    [temp_col]
1593
   ;     push    [temp_col]
1593
   ;     push    [temp_col]
1594
   ;     push    [temp_col]
1594
   .rainbow:
1595
   .rainbow:
1595
	cmp	[catmull_flag],1      ; put on stack z coordinate if necessary
1596
	cmp	[catmull_flag],1      ; put on stack z coordinate if necessary
1596
	jne	 @f
1597
	jne	 @f
1597
	push	 [zz3]
1598
	push	 [zz3]
1598
      @@:
1599
      @@:
1599
	mov	 eax,dword[yy3]
1600
	mov	 eax,dword[yy3]
1600
	mov	 ebx,0x00ff00ff
1601
	mov	 ebx,0x00ff00ff
1601
	and	 eax,ebx
1602
	and	 eax,ebx
1602
	push	 eax
1603
	push	 eax
1603
	neg	 al
1604
	neg	 al
1604
	push	 ax
1605
	push	 ax
1605
	cmp	[catmull_flag],1
1606
	cmp	[catmull_flag],1
1606
	jne	 @f
1607
	jne	 @f
1607
	push	 [zz2]
1608
	push	 [zz2]
1608
      @@:
1609
      @@:
1609
	mov	 eax,dword[yy2]
1610
	mov	 eax,dword[yy2]
1610
	and	 eax,ebx
1611
	and	 eax,ebx
1611
	push	 eax
1612
	push	 eax
1612
	neg	 al
1613
	neg	 al
1613
	push	 ax
1614
	push	 ax
1614
	cmp	[catmull_flag],1
1615
	cmp	[catmull_flag],1
1615
	jne	 @f
1616
	jne	 @f
1616
	push	 [zz1]
1617
	push	 [zz1]
1617
      @@:
1618
      @@:
1618
	mov	 eax,dword[yy1]
1619
	mov	 eax,dword[yy1]
1619
	and	 eax,ebx
1620
	and	 eax,ebx
1620
	push	 eax
1621
	push	 eax
1621
	neg	 al
1622
	neg	 al
1622
	push	 ax
1623
	push	 ax
1623
    .both_draw:
1624
    .both_draw:
1624
	mov	eax,dword[xx1]
1625
	mov	eax,dword[xx1]
1625
	ror	eax,16
1626
	ror	eax,16
1626
	mov	ebx,dword[xx2]
1627
	mov	ebx,dword[xx2]
1627
	ror	ebx,16
1628
	ror	ebx,16
1628
	mov	ecx,dword[xx3]
1629
	mov	ecx,dword[xx3]
1629
	ror	ecx,16
1630
	ror	ecx,16
1630
	lea	edi,[screen]
1631
	lea	edi,[screen]
1631
	cmp	[catmull_flag],0
1632
	cmp	[catmull_flag],0
1632
	je	@f
1633
	je	@f
1633
  ;      lea     esi,[Z_buffer]
1634
  ;      lea     esi,[Z_buffer]
1634
	mov	esi,[Zbuffer_ptr]
1635
	mov	esi,[Zbuffer_ptr]
1635
	call	gouraud_triangle_z
1636
	call	gouraud_triangle_z
1636
	jmp	.end_draw
1637
	jmp	.end_draw
1637
       @@:
1638
       @@:
1638
	call	gouraud_triangle
1639
	call	gouraud_triangle
1639
	jmp	.end_draw
1640
	jmp	.end_draw
1640
 
1641
 
1641
     .flat_draw:		     ;**************************
1642
     .flat_draw:		     ;**************************
1642
				     ; FLAT DRAWING
1643
				     ; FLAT DRAWING
1643
	movzx	eax,[point_index1]
1644
	movzx	eax,[point_index1]
1644
	movzx	ebx,[point_index2]
1645
	movzx	ebx,[point_index2]
1645
	movzx	ecx,[point_index3]
1646
	movzx	ecx,[point_index3]
1646
	shl	eax,2
1647
	shl	eax,2
1647
	shl	ebx,2
1648
	shl	ebx,2
1648
	shl	ecx,2
1649
	shl	ecx,2
1649
	lea	eax,[eax*3]  ;+point_normals_rotated]
1650
	lea	eax,[eax*3]  ;+point_normals_rotated]
1650
	add	eax,[points_normals_rot_ptr]
1651
	add	eax,[points_normals_rot_ptr]
1651
	lea	ebx,[ebx*3]  ;+point_normals_rotated]
1652
	lea	ebx,[ebx*3]  ;+point_normals_rotated]
1652
	add	ebx,[points_normals_rot_ptr]
1653
	add	ebx,[points_normals_rot_ptr]
1653
	lea	ecx,[ecx*3]  ;+point_normals_rotated]
1654
	lea	ecx,[ecx*3]  ;+point_normals_rotated]
1654
	add	ecx,[points_normals_rot_ptr]
1655
	add	ecx,[points_normals_rot_ptr]
1655
	fld	dword[eax]	; x cooficient of normal vector
1656
	fld	dword[eax]	; x cooficient of normal vector
1656
	fadd	dword[ebx]
1657
	fadd	dword[ebx]
1657
	fadd	dword[ecx]
1658
	fadd	dword[ecx]
1658
	fidiv	[i3]
1659
	fidiv	[i3]
1659
	fimul	[correct_tex]
1660
	fimul	[correct_tex]
1660
	fiadd	[correct_tex]
1661
	fiadd	[correct_tex]
1661
	fistp	dword[esp-4]	; x temp variables
1662
	fistp	dword[esp-4]	; x temp variables
1662
	fld	dword[eax+4]	; y cooficient of normal vector
1663
	fld	dword[eax+4]	; y cooficient of normal vector
1663
	fadd	dword[ebx+4]
1664
	fadd	dword[ebx+4]
1664
	fadd	dword[ecx+4]
1665
	fadd	dword[ecx+4]
1665
	fidiv	[i3]
1666
	fidiv	[i3]
1666
	fimul	[correct_tex]
1667
	fimul	[correct_tex]
1667
	fiadd	[correct_tex]
1668
	fiadd	[correct_tex]
1668
	fistp	dword[esp-8]   ;  y
1669
	fistp	dword[esp-8]   ;  y
1669
	mov	edx,dword[esp-8]
1670
	mov	edx,dword[esp-8]
1670
	shl	edx,TEX_SHIFT
1671
	shl	edx,TEX_SHIFT
1671
	add	edx,dword[esp-4]
1672
	add	edx,dword[esp-4]
1672
	lea	eax,[3*edx+color_map]
1673
	lea	eax,[3*edx+color_map]
1673
	mov	edx,dword[eax]
1674
	mov	edx,dword[eax]
1674
 
1675
 
1675
	and	edx,0x00ffffff	  ; edx = 0x00rrggbb
1676
	and	edx,0x00ffffff	  ; edx = 0x00rrggbb
1676
 
1677
 
1677
 
1678
 
1678
 
1679
 
1679
     ;   mov     ax,[zz1]      ; z position depend draw
1680
     ;   mov     ax,[zz1]      ; z position depend draw
1680
     ;   add     ax,[zz2]
1681
     ;   add     ax,[zz2]
1681
     ;   add     ax,[zz3]
1682
     ;   add     ax,[zz3]
1682
     ;   cwd
1683
     ;   cwd
1683
     ;   idiv    [i3] ;    = -((a+b+c)/3+130)
1684
     ;   idiv    [i3] ;    = -((a+b+c)/3+130)
1684
     ;   add     ax,130
1685
     ;   add     ax,130
1685
     ;   neg     al
1686
     ;   neg     al
1686
     ;   xor     edx,edx
1687
     ;   xor     edx,edx
1687
     ;   mov     ah,al           ;set color according to z position
1688
     ;   mov     ah,al           ;set color according to z position
1688
     ;   shl     eax,8
1689
     ;   shl     eax,8
1689
     ;   mov     edx,eax
1690
     ;   mov     edx,eax
1690
 
1691
 
1691
	mov	eax,dword[xx1]
1692
	mov	eax,dword[xx1]
1692
	ror	eax,16
1693
	ror	eax,16
1693
	mov	ebx,dword[xx2]
1694
	mov	ebx,dword[xx2]
1694
	ror	ebx,16
1695
	ror	ebx,16
1695
	mov	ecx,dword[xx3]
1696
	mov	ecx,dword[xx3]
1696
	ror	ecx,16
1697
	ror	ecx,16
1697
       ; mov     edi,screen
1698
       ; mov     edi,screen
1698
	lea	edi,[screen]
1699
	lea	edi,[screen]
1699
	cmp	[catmull_flag],0
1700
	cmp	[catmull_flag],0
1700
	je	@f
1701
	je	@f
1701
   ;     lea     esi,[Z_buffer]
1702
   ;     lea     esi,[Z_buffer]
1702
	mov	esi,[Zbuffer_ptr]
1703
	mov	esi,[Zbuffer_ptr]
1703
	push	word[zz3]
1704
	push	word[zz3]
1704
	push	word[zz2]
1705
	push	word[zz2]
1705
	push	word[zz1]
1706
	push	word[zz1]
1706
	call	flat_triangle_z
1707
	call	flat_triangle_z
1707
	jmp	.end_draw
1708
	jmp	.end_draw
1708
      @@:
1709
      @@:
1709
	call	draw_triangle
1710
	call	draw_triangle
1710
	jmp	.end_draw
1711
	jmp	.end_draw
1711
      .env_mapping:
1712
      .env_mapping:
1712
       ; fninit
1713
       ; fninit
1713
	cmp	[catmull_flag],0
1714
	cmp	[catmull_flag],0
1714
	je	@f
1715
	je	@f
1715
	push	[zz3]
1716
	push	[zz3]
1716
	push	[zz2]
1717
	push	[zz2]
1717
	push	[zz1]
1718
	push	[zz1]
1718
      @@:
1719
      @@:
1719
	mov	esi,point_index1
1720
	mov	esi,point_index1
1720
	sub	esp,12
1721
	sub	esp,12
1721
	mov	edi,esp
1722
	mov	edi,esp
1722
	mov	ecx,3
1723
	mov	ecx,3
1723
      @@:
1724
      @@:
1724
	movzx	eax,word[esi]
1725
	movzx	eax,word[esi]
1725
	lea	eax,[eax*3]
1726
	lea	eax,[eax*3]
1726
	shl	eax,2
1727
	shl	eax,2
1727
	add	eax,[points_normals_rot_ptr]	   ;point_normals_rotated
1728
	add	eax,[points_normals_rot_ptr]	   ;point_normals_rotated
1728
; #
1729
; #
1729
;        fld     dword[eax]
1730
;        fld     dword[eax]
1730
;        fmul    dword[eax+4]
1731
;        fmul    dword[eax+4]
1731
;        fld1
1732
;        fld1
1732
;        fld1
1733
;        fld1
1733
;        faddp
1734
;        faddp
1734
;        fmulp
1735
;        fmulp
1735
;        fimul   [correct_tex]
1736
;        fimul   [correct_tex]
1736
;        fiadd   [correct_tex]
1737
;        fiadd   [correct_tex]
1737
;        fistp   word[edi]
1738
;        fistp   word[edi]
1738
;        mov     word[edi+2],0
1739
;        mov     word[edi+2],0
1739
;;        fistp   word[edi+2]
1740
;;        fistp   word[edi+2]
1740
; # last change
1741
; # last change
1741
	; texture x=(rotated point normal -> x * 255)+255
1742
	; texture x=(rotated point normal -> x * 255)+255
1742
	fld	dword[eax]
1743
	fld	dword[eax]
1743
	fimul	[correct_tex]
1744
	fimul	[correct_tex]
1744
	fiadd	[correct_tex]
1745
	fiadd	[correct_tex]
1745
	fistp	word[edi]
1746
	fistp	word[edi]
1746
	; texture y=(rotated point normal -> y * 255)+255
1747
	; texture y=(rotated point normal -> y * 255)+255
1747
	fld	dword[eax+4]
1748
	fld	dword[eax+4]
1748
	fimul	[correct_tex]
1749
	fimul	[correct_tex]
1749
	fiadd	[correct_tex]
1750
	fiadd	[correct_tex]
1750
	fistp	word[edi+2]
1751
	fistp	word[edi+2]
1751
; # end of last ch.
1752
; # end of last ch.
1752
	add	edi,4
1753
	add	edi,4
1753
	add	esi,2
1754
	add	esi,2
1754
	loop	@b
1755
	loop	@b
1755
 
1756
 
1756
	mov	eax,dword[xx1]
1757
	mov	eax,dword[xx1]
1757
	ror	eax,16
1758
	ror	eax,16
1758
	mov	ebx,dword[xx2]
1759
	mov	ebx,dword[xx2]
1759
	ror	ebx,16
1760
	ror	ebx,16
1760
	mov	ecx,dword[xx3]
1761
	mov	ecx,dword[xx3]
1761
	ror	ecx,16
1762
	ror	ecx,16
1762
	mov	edi,screen
1763
	mov	edi,screen
1763
	mov	esi,envmap
1764
	mov	esi,envmap
1764
	cmp	[catmull_flag],0
1765
	cmp	[catmull_flag],0
1765
	je	@f
1766
	je	@f
1766
  ;      mov     edx,Z_buffer
1767
  ;      mov     edx,Z_buffer
1767
	mov	edx,[Zbuffer_ptr]
1768
	mov	edx,[Zbuffer_ptr]
1768
	call	tex_triangle_z
1769
	call	tex_triangle_z
1769
	jmp	.end_draw
1770
	jmp	.end_draw
1770
      @@:
1771
      @@:
1771
	call	tex_triangle
1772
	call	tex_triangle
1772
	jmp	.end_draw
1773
	jmp	.end_draw
1773
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1774
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1774
     .cubic_env_mapping:
1775
     .cubic_env_mapping:
1775
       ; fninit
1776
       ; fninit
1776
	cmp	[catmull_flag],0
1777
	cmp	[catmull_flag],0
1777
	je	@f
1778
	je	@f
1778
	push	[zz3]
1779
	push	[zz3]
1779
	push	[zz2]
1780
	push	[zz2]
1780
	push	[zz1]
1781
	push	[zz1]
1781
      @@:
1782
      @@:
1782
	mov	esi,point_index1
1783
	mov	esi,point_index1
1783
	sub	esp,12
1784
	sub	esp,12
1784
	mov	edi,esp
1785
	mov	edi,esp
1785
	mov	ecx,3
1786
	mov	ecx,3
1786
      @@:
1787
      @@:
1787
	movzx	eax,word[esi]
1788
	movzx	eax,word[esi]
1788
	lea	eax,[eax*3]
1789
	lea	eax,[eax*3]
1789
	shl	eax,2
1790
	shl	eax,2
1790
	add	eax,[points_normals_rot_ptr]  ;point_normals_rotated
1791
	add	eax,[points_normals_rot_ptr]  ;point_normals_rotated
1791
; #
1792
; #
1792
	fld	dword[eax]
1793
	fld	dword[eax]
1793
	fmul	dword[eax+4]
1794
	fmul	dword[eax+4]
1794
	fld1
1795
	fld1
1795
	fld1
1796
	fld1
1796
	faddp
1797
	faddp
1797
	fmulp
1798
	fmulp
1798
	fimul	[correct_tex]
1799
	fimul	[correct_tex]
1799
	fiadd	[correct_tex]
1800
	fiadd	[correct_tex]
1800
	fistp	word[edi]
1801
	fistp	word[edi]
1801
	mov	word[edi+2],0
1802
	mov	word[edi+2],0
1802
;        fistp   word[edi+2]
1803
;        fistp   word[edi+2]
1803
; # last change
1804
; # last change
1804
;        ; texture x=(rotated point normal -> x * 255)+255
1805
;        ; texture x=(rotated point normal -> x * 255)+255
1805
;        fld     dword[eax]
1806
;        fld     dword[eax]
1806
;        fimul   [correct_tex]
1807
;        fimul   [correct_tex]
1807
;        fiadd   [correct_tex]
1808
;        fiadd   [correct_tex]
1808
;        fistp   word[edi]
1809
;        fistp   word[edi]
1809
;        ; texture y=(rotated point normal -> y * 255)+255
1810
;        ; texture y=(rotated point normal -> y * 255)+255
1810
;        fld     dword[eax+4]
1811
;        fld     dword[eax+4]
1811
;        fimul   [correct_tex]
1812
;        fimul   [correct_tex]
1812
;        fiadd   [correct_tex]
1813
;        fiadd   [correct_tex]
1813
;        fistp   word[edi+2]
1814
;        fistp   word[edi+2]
1814
; # end of last ch.
1815
; # end of last ch.
1815
	add	edi,4
1816
	add	edi,4
1816
	add	esi,2
1817
	add	esi,2
1817
	loop	@b
1818
	loop	@b
1818
 
1819
 
1819
	mov	eax,dword[xx1]
1820
	mov	eax,dword[xx1]
1820
	ror	eax,16
1821
	ror	eax,16
1821
	mov	ebx,dword[xx2]
1822
	mov	ebx,dword[xx2]
1822
	ror	ebx,16
1823
	ror	ebx,16
1823
	mov	ecx,dword[xx3]
1824
	mov	ecx,dword[xx3]
1824
	ror	ecx,16
1825
	ror	ecx,16
1825
	mov	edi,screen
1826
	mov	edi,screen
1826
	mov	esi,envmap_cub
1827
	mov	esi,envmap_cub
1827
	cmp	[catmull_flag],0
1828
	cmp	[catmull_flag],0
1828
	je	@f
1829
	je	@f
1829
  ;      mov     edx,Z_buffer
1830
  ;      mov     edx,Z_buffer
1830
	mov	edx,[Zbuffer_ptr]
1831
	mov	edx,[Zbuffer_ptr]
1831
	call	tex_triangle_z
1832
	call	tex_triangle_z
1832
	jmp	.end_draw
1833
	jmp	.end_draw
1833
      @@:
1834
      @@:
1834
	call	tex_triangle
1835
	call	tex_triangle
1835
	jmp	.end_draw
1836
	jmp	.end_draw
1836
 
1837
 
1837
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1838
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1838
 
1839
 
1839
      .bump_mapping:
1840
      .bump_mapping:
1840
	; fninit
1841
	; fninit
1841
	cmp	[catmull_flag],0
1842
	cmp	[catmull_flag],0
1842
	je	@f
1843
	je	@f
1843
;        push    Z_buffer
1844
;        push    Z_buffer
1844
	push	[Zbuffer_ptr]
1845
	push	[Zbuffer_ptr]
1845
	push	[zz3]
1846
	push	[zz3]
1846
	push	[zz2]
1847
	push	[zz2]
1847
	push	[zz1]
1848
	push	[zz1]
1848
      @@:
1849
      @@:
1849
	mov	esi,point_index1
1850
	mov	esi,point_index1
1850
	sub	esp,12
1851
	sub	esp,12
1851
	mov	edi,esp
1852
	mov	edi,esp
1852
	mov	ecx,3
1853
	mov	ecx,3
1853
      @@:
1854
      @@:
1854
	movzx	eax,word[esi]
1855
	movzx	eax,word[esi]
1855
	lea	eax,[eax*3]
1856
	lea	eax,[eax*3]
1856
	shl	eax,2
1857
	shl	eax,2
1857
	add	eax,[points_normals_rot_ptr]  ;point_normals_rotated
1858
	add	eax,[points_normals_rot_ptr]  ;point_normals_rotated
1858
	; texture x=(rotated point normal -> x * 255)+255
1859
	; texture x=(rotated point normal -> x * 255)+255
1859
	fld	dword[eax]
1860
	fld	dword[eax]
1860
	fimul	[correct_tex]
1861
	fimul	[correct_tex]
1861
	fiadd	[correct_tex]
1862
	fiadd	[correct_tex]
1862
	fistp	word[edi]
1863
	fistp	word[edi]
1863
	; texture y=(rotated point normal -> y * 255)+255
1864
	; texture y=(rotated point normal -> y * 255)+255
1864
	fld	dword[eax+4]
1865
	fld	dword[eax+4]
1865
	fimul	[correct_tex]
1866
	fimul	[correct_tex]
1866
	fiadd	[correct_tex]
1867
	fiadd	[correct_tex]
1867
	fistp	word[edi+2]
1868
	fistp	word[edi+2]
1868
 
1869
 
1869
	add	edi,4
1870
	add	edi,4
1870
	add	esi,2
1871
	add	esi,2
1871
	loop	@b
1872
	loop	@b
1872
 
1873
 
1873
	movzx  esi,[point_index3]      ; bump map coords
1874
	movzx  esi,[point_index3]      ; bump map coords
1874
	shl    esi,2
1875
	shl    esi,2
1875
	add    esi,tex_points
1876
	add    esi,tex_points
1876
	push   dword[esi]
1877
	push   dword[esi]
1877
	movzx  esi,[point_index2]
1878
	movzx  esi,[point_index2]
1878
	shl    esi,2
1879
	shl    esi,2
1879
	add    esi,tex_points
1880
	add    esi,tex_points
1880
;       lea    esi,[esi*3]
1881
;       lea    esi,[esi*3]
1881
;       lea    esi,[points+2+esi*2]
1882
;       lea    esi,[points+2+esi*2]
1882
	push   dword[esi]
1883
	push   dword[esi]
1883
  ;     push   dword[xx2]
1884
  ;     push   dword[xx2]
1884
	movzx  esi,[point_index1]
1885
	movzx  esi,[point_index1]
1885
	shl    esi,2
1886
	shl    esi,2
1886
	add    esi,tex_points
1887
	add    esi,tex_points
1887
;       lea     esi,[esi*3]
1888
;       lea     esi,[esi*3]
1888
;       lea     esi,[points+2+esi*2]
1889
;       lea     esi,[points+2+esi*2]
1889
	push   dword[esi]
1890
	push   dword[esi]
1890
   ;    push     dword[xx1]
1891
   ;    push     dword[xx1]
1891
 
1892
 
1892
	mov	eax,dword[xx1]
1893
	mov	eax,dword[xx1]
1893
	ror	eax,16
1894
	ror	eax,16
1894
	mov	ebx,dword[xx2]
1895
	mov	ebx,dword[xx2]
1895
	ror	ebx,16
1896
	ror	ebx,16
1896
	mov	ecx,dword[xx3]
1897
	mov	ecx,dword[xx3]
1897
	ror	ecx,16
1898
	ror	ecx,16
1898
	mov	edi,screen
1899
	mov	edi,screen
1899
	mov	esi,envmap
1900
	mov	esi,envmap
1900
	mov	edx,bumpmap	       ;BUMP_MAPPING
1901
	mov	edx,bumpmap	       ;BUMP_MAPPING
1901
 
1902
 
1902
	cmp	[catmull_flag],0
1903
	cmp	[catmull_flag],0
1903
	je	@f
1904
	je	@f
1904
	call	bump_triangle_z
1905
	call	bump_triangle_z
1905
	jmp	.end_draw
1906
	jmp	.end_draw
1906
      @@:
1907
      @@:
1907
	call	bump_triangle
1908
	call	bump_triangle
1908
	jmp	.end_draw
1909
	jmp	.end_draw
1909
 
1910
 
1910
      .tex_mapping:
1911
      .tex_mapping:
1911
 
1912
 
1912
	; fninit
1913
	; fninit
1913
	cmp	[catmull_flag],0
1914
	cmp	[catmull_flag],0
1914
	je	@f
1915
	je	@f
1915
	push	[zz3]
1916
	push	[zz3]
1916
	push	[zz2]
1917
	push	[zz2]
1917
	push	[zz1]
1918
	push	[zz1]
1918
      @@:
1919
      @@:
1919
	movzx  esi,[point_index3]      ; tex map coords
1920
	movzx  esi,[point_index3]      ; tex map coords
1920
	shl    esi,2
1921
	shl    esi,2
1921
	add    esi,tex_points
1922
	add    esi,tex_points
1922
	push   dword[esi]
1923
	push   dword[esi]
1923
	movzx  esi,[point_index2]
1924
	movzx  esi,[point_index2]
1924
	shl    esi,2
1925
	shl    esi,2
1925
	add    esi,tex_points
1926
	add    esi,tex_points
1926
	push   dword[esi]
1927
	push   dword[esi]
1927
	movzx  esi,[point_index1]
1928
	movzx  esi,[point_index1]
1928
	shl    esi,2
1929
	shl    esi,2
1929
	add    esi,tex_points
1930
	add    esi,tex_points
1930
	push   dword[esi]
1931
	push   dword[esi]
1931
 
1932
 
1932
	mov	eax,dword[xx1]
1933
	mov	eax,dword[xx1]
1933
	ror	eax,16
1934
	ror	eax,16
1934
	mov	ebx,dword[xx2]
1935
	mov	ebx,dword[xx2]
1935
	ror	ebx,16
1936
	ror	ebx,16
1936
	mov	ecx,dword[xx3]
1937
	mov	ecx,dword[xx3]
1937
	ror	ecx,16
1938
	ror	ecx,16
1938
	mov	edi,screen
1939
	mov	edi,screen
1939
	mov	esi,texmap
1940
	mov	esi,texmap
1940
	cmp	[catmull_flag],0
1941
	cmp	[catmull_flag],0
1941
	je	@f
1942
	je	@f
1942
   ;     mov     edx,Z_buffer
1943
   ;     mov     edx,Z_buffer
1943
	mov	edx,[Zbuffer_ptr]
1944
	mov	edx,[Zbuffer_ptr]
1944
	call	tex_triangle_z
1945
	call	tex_triangle_z
1945
 ;       call    tex_plus_grd_trianlgle
1946
 ;       call    tex_plus_grd_trianlgle
1946
	jmp	.end_draw
1947
	jmp	.end_draw
1947
      @@:
1948
      @@:
1948
	call	tex_triangle
1949
	call	tex_triangle
1949
	jmp	.end_draw
1950
	jmp	.end_draw
1950
;      .ray:
1951
;      .ray:
1951
;        grd_triangle according to points index
1952
;        grd_triangle according to points index
1952
;        cmp     [catmull_flag],0
1953
;        cmp     [catmull_flag],0
1953
;        je      @f
1954
;        je      @f
1954
;        push    [zz3]                   ; spot light with attenuation
1955
;        push    [zz3]                   ; spot light with attenuation
1955
;     @@:
1956
;     @@:
1956
;        movzx   eax,[point_index3]      ; env_map - points color list
1957
;        movzx   eax,[point_index3]      ; env_map - points color list
1957
;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
1958
;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
1958
;        lea     eax,[3*eax+bumpmap]
1959
;        lea     eax,[3*eax+bumpmap]
1959
;        push    word[eax]
1960
;        push    word[eax]
1960
;        push    word[eax+2]
1961
;        push    word[eax+2]
1961
;        push    word[eax+4]
1962
;        push    word[eax+4]
1962
;        cmp     [catmull_flag],0
1963
;        cmp     [catmull_flag],0
1963
;        je      @f
1964
;        je      @f
1964
;        push    [zz2]
1965
;        push    [zz2]
1965
;    @@:
1966
;    @@:
1966
;        movzx   eax,[point_index2]      ; env_map - points color list
1967
;        movzx   eax,[point_index2]      ; env_map - points color list
1967
;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
1968
;        shl     eax,1                   ; each color as word, 0x00rr00gg00bb..
1968
;        lea     eax,[eax*3+bumpmap]
1969
;        lea     eax,[eax*3+bumpmap]
1969
;        push    word[eax]
1970
;        push    word[eax]
1970
;        push    word[eax+2]
1971
;        push    word[eax+2]
1971
;        push    word[eax+4]
1972
;        push    word[eax+4]
1972
;        cmp     [catmull_flag],0
1973
;        cmp     [catmull_flag],0
1973
;        je      @f
1974
;        je      @f
1974
;        push    [zz1]
1975
;        push    [zz1]
1975
;     @@:
1976
;     @@:
1976
;        movzx   eax,[point_index1]      ; env_map - points color list
1977
;        movzx   eax,[point_index1]      ; env_map - points color list
1977
;        shl     eax,1                   ; each color as word, 0xrr00gg00bb00..
1978
;        shl     eax,1                   ; each color as word, 0xrr00gg00bb00..
1978
;        lea     eax,[eax*3+bumpmap]
1979
;        lea     eax,[eax*3+bumpmap]
1979
;        push    word[eax]
1980
;        push    word[eax]
1980
;        push    word[eax+2]
1981
;        push    word[eax+2]
1981
;        push    word[eax+4]
1982
;        push    word[eax+4]
1982
;        jmp     .both_draw
1983
;        jmp     .both_draw
1983
 
1984
 
1984
     .grd_tex:		  ; smooth shading + texture
1985
     .grd_tex:		  ; smooth shading + texture
1985
	 push	ebp
1986
	 push	ebp
1986
	 mov	ebp,esp
1987
	 mov	ebp,esp
1987
	 sub	esp,4
1988
	 sub	esp,4
1988
	 push	ebp
1989
	 push	ebp
1989
 
1990
 
1990
	 movzx	esi,[point_index3]	; tex map coords
1991
	 movzx	esi,[point_index3]	; tex map coords
1991
	 shl	esi,2
1992
	 shl	esi,2
1992
	 add	esi,tex_points
1993
	 add	esi,tex_points
1993
	 push	dword[esi]		; texture coords as first
1994
	 push	dword[esi]		; texture coords as first
1994
	 movzx	esi,[point_index2]	; group of parameters
1995
	 movzx	esi,[point_index2]	; group of parameters
1995
	 shl	esi,2
1996
	 shl	esi,2
1996
	 add	esi,tex_points
1997
	 add	esi,tex_points
1997
	 push	dword[esi]
1998
	 push	dword[esi]
1998
	 movzx	esi,[point_index1]
1999
	 movzx	esi,[point_index1]
1999
	 shl	esi,2
2000
	 shl	esi,2
2000
	 add	esi,tex_points
2001
	 add	esi,tex_points
2001
	 push	dword[esi]
2002
	 push	dword[esi]
2002
 
2003
 
2003
	 mov	 esi,point_index3
2004
	 mov	 esi,point_index3
2004
	 mov	 ecx,3
2005
	 mov	 ecx,3
2005
 
2006
 
2006
      .aagain_grd_draw:
2007
      .aagain_grd_draw:
2007
 
2008
 
2008
	lea	 edx,[ecx*3]
2009
	lea	 edx,[ecx*3]
2009
	push	 word[edx*2+xx1-2]    ; zz1 ,2 ,3
2010
	push	 word[edx*2+xx1-2]    ; zz1 ,2 ,3
2010
 
2011
 
2011
	movzx	eax,word[esi]
2012
	movzx	eax,word[esi]
2012
	shl	eax,2
2013
	shl	eax,2
2013
	lea	eax,[eax*3] ;+point_normals_rotated]
2014
	lea	eax,[eax*3] ;+point_normals_rotated]
2014
	add	eax,[points_normals_rot_ptr]
2015
	add	eax,[points_normals_rot_ptr]
2015
	; texture x=(rotated point normal -> x * 255)+255
2016
	; texture x=(rotated point normal -> x * 255)+255
2016
	fld	dword[eax]	 ; x cooficient of normal vector
2017
	fld	dword[eax]	 ; x cooficient of normal vector
2017
	fimul	[correct_tex]
2018
	fimul	[correct_tex]
2018
	fiadd	[correct_tex]
2019
	fiadd	[correct_tex]
2019
	fistp	word[ebp-2]
2020
	fistp	word[ebp-2]
2020
	; texture y=(rotated point normal -> y * 255)+255
2021
	; texture y=(rotated point normal -> y * 255)+255
2021
	fld	dword[eax+4]	  ; y cooficient
2022
	fld	dword[eax+4]	  ; y cooficient
2022
	fimul	[correct_tex]
2023
	fimul	[correct_tex]
2023
	fiadd	[correct_tex]
2024
	fiadd	[correct_tex]
2024
	fistp	word[ebp-4]
2025
	fistp	word[ebp-4]
2025
 
2026
 
2026
	movzx	 eax,word[ebp-4]
2027
	movzx	 eax,word[ebp-4]
2027
	movzx	 ebx,word[ebp-2]
2028
	movzx	 ebx,word[ebp-2]
2028
	shl	 eax,TEX_SHIFT
2029
	shl	 eax,TEX_SHIFT
2029
	add	 eax,ebx
2030
	add	 eax,ebx
2030
	lea	 eax,[eax*3+color_map]
2031
	lea	 eax,[eax*3+color_map]
2031
	mov	 eax,dword[eax]
2032
	mov	 eax,dword[eax]
2032
 
2033
 
2033
	ror	 eax,16 	      ; eax -0xxxrrggbb -> 0xggbbxxrr
2034
	ror	 eax,16 	      ; eax -0xxxrrggbb -> 0xggbbxxrr
2034
	xor	 ah,ah
2035
	xor	 ah,ah
2035
	push	 ax	    ;r
2036
	push	 ax	    ;r
2036
	rol	 eax,8		      ; eax-0xggbb00rr -> 0xbb00rrgg
2037
	rol	 eax,8		      ; eax-0xggbb00rr -> 0xbb00rrgg
2037
	xor	 ah,ah
2038
	xor	 ah,ah
2038
	push	 ax	    ;g
2039
	push	 ax	    ;g
2039
	shr	 eax,24
2040
	shr	 eax,24
2040
	push	 ax	    ;b
2041
	push	 ax	    ;b
2041
 
2042
 
2042
	sub	 esi,2
2043
	sub	 esi,2
2043
	dec	 cx
2044
	dec	 cx
2044
	jnz	 .aagain_grd_draw
2045
	jnz	 .aagain_grd_draw
2045
 
2046
 
2046
	mov	eax,dword[xx1]
2047
	mov	eax,dword[xx1]
2047
	ror	eax,16
2048
	ror	eax,16
2048
	mov	ebx,dword[xx2]
2049
	mov	ebx,dword[xx2]
2049
	ror	ebx,16
2050
	ror	ebx,16
2050
	mov	ecx,dword[xx3]
2051
	mov	ecx,dword[xx3]
2051
	ror	ecx,16
2052
	ror	ecx,16
2052
	mov	edi,screen
2053
	mov	edi,screen
2053
	mov	edx,texmap
2054
	mov	edx,texmap
2054
	mov	esi,[Zbuffer_ptr]
2055
	mov	esi,[Zbuffer_ptr]
2055
 
2056
 
2056
	call	tex_plus_grd_triangle
2057
	call	tex_plus_grd_triangle
2057
 
2058
 
2058
	pop	ebp
2059
	pop	ebp
2059
	mov	esp,ebp
2060
	mov	esp,ebp
2060
	pop	ebp
2061
	pop	ebp
2061
	jmp	.end_draw
2062
	jmp	.end_draw
2062
 
2063
 
2063
      .two_tex:
2064
      .two_tex:
2064
	push	[Zbuffer_ptr]
2065
	push	[Zbuffer_ptr]
2065
 
2066
 
2066
	push	word[zz3]
2067
	push	word[zz3]
2067
	push	word[zz2]
2068
	push	word[zz2]
2068
	push	word[zz1]
2069
	push	word[zz1]
2069
 
2070
 
2070
	movzx  esi,[point_index3]      ; tex map coords
2071
	movzx  esi,[point_index3]      ; tex map coords
2071
	shl    esi,2
2072
	shl    esi,2
2072
	add    esi,tex_points
2073
	add    esi,tex_points
2073
	push   dword[esi]
2074
	push   dword[esi]
2074
	movzx  esi,[point_index2]
2075
	movzx  esi,[point_index2]
2075
	shl    esi,2
2076
	shl    esi,2
2076
	add    esi,tex_points
2077
	add    esi,tex_points
2077
	push   dword[esi]
2078
	push   dword[esi]
2078
	movzx  esi,[point_index1]
2079
	movzx  esi,[point_index1]
2079
	shl    esi,2
2080
	shl    esi,2
2080
	add    esi,tex_points
2081
	add    esi,tex_points
2081
	push   dword[esi]
2082
	push   dword[esi]
2082
 
2083
 
2083
	mov	esi,point_index1     ; env coords
2084
	mov	esi,point_index1     ; env coords
2084
	sub	esp,12
2085
	sub	esp,12
2085
	mov	edi,esp
2086
	mov	edi,esp
2086
	mov	ecx,3
2087
	mov	ecx,3
2087
      @@:
2088
      @@:
2088
	movzx	eax,word[esi]
2089
	movzx	eax,word[esi]
2089
	lea	eax,[eax*3]
2090
	lea	eax,[eax*3]
2090
	shl	eax,2
2091
	shl	eax,2
2091
	add	eax,[points_normals_rot_ptr]
2092
	add	eax,[points_normals_rot_ptr]
2092
	; texture x=(rotated point normal -> x * 255)+255
2093
	; texture x=(rotated point normal -> x * 255)+255
2093
	fld	dword[eax]
2094
	fld	dword[eax]
2094
	fimul	[correct_tex]
2095
	fimul	[correct_tex]
2095
	fiadd	[correct_tex]
2096
	fiadd	[correct_tex]
2096
	fistp	word[edi]
2097
	fistp	word[edi]
2097
	; texture y=(rotated point normal -> y * 255)+255
2098
	; texture y=(rotated point normal -> y * 255)+255
2098
	fld	dword[eax+4]
2099
	fld	dword[eax+4]
2099
	fimul	[correct_tex]
2100
	fimul	[correct_tex]
2100
	fiadd	[correct_tex]
2101
	fiadd	[correct_tex]
2101
	fistp	word[edi+2]
2102
	fistp	word[edi+2]
2102
 
2103
 
2103
	add	edi,4
2104
	add	edi,4
2104
	add	esi,2
2105
	add	esi,2
2105
	loop	@b
2106
	loop	@b
2106
 
2107
 
2107
	mov	eax,dword[xx1]
2108
	mov	eax,dword[xx1]
2108
	ror	eax,16
2109
	ror	eax,16
2109
	mov	ebx,dword[xx2]
2110
	mov	ebx,dword[xx2]
2110
	ror	ebx,16
2111
	ror	ebx,16
2111
	mov	ecx,dword[xx3]
2112
	mov	ecx,dword[xx3]
2112
	ror	ecx,16
2113
	ror	ecx,16
2113
	mov	edi,screen
2114
	mov	edi,screen
2114
	mov	esi,texmap
2115
	mov	esi,texmap
2115
	mov	edx,envmap
2116
	mov	edx,envmap
2116
 
2117
 
2117
	call	two_tex_triangle_z
2118
	call	two_tex_triangle_z
2118
	jmp	.end_draw
2119
	jmp	.end_draw
2119
 
2120
 
2120
   .bump_tex:
2121
   .bump_tex:
2121
	movzx  esi,[point_index3]      ; tex map coords
2122
	movzx  esi,[point_index3]      ; tex map coords
2122
	shl    esi,2
2123
	shl    esi,2
2123
	add    esi,tex_points
2124
	add    esi,tex_points
2124
	push   dword[esi]
2125
	push   dword[esi]
2125
	movzx  esi,[point_index2]
2126
	movzx  esi,[point_index2]
2126
	shl    esi,2
2127
	shl    esi,2
2127
	add    esi,tex_points
2128
	add    esi,tex_points
2128
	push   dword[esi]
2129
	push   dword[esi]
2129
	movzx  esi,[point_index1]
2130
	movzx  esi,[point_index1]
2130
	shl    esi,2
2131
	shl    esi,2
2131
	add    esi,tex_points
2132
	add    esi,tex_points
2132
	push   dword[esi]
2133
	push   dword[esi]
2133
 
2134
 
2134
	push  dword texmap
2135
	push  dword texmap
2135
 
2136
 
2136
	push  [Zbuffer_ptr]
2137
	push  [Zbuffer_ptr]
2137
	xor   edi,edi
2138
	xor   edi,edi
2138
 
2139
 
2139
	push	word[zz3]
2140
	push	word[zz3]
2140
	push	word[zz2]
2141
	push	word[zz2]
2141
	push	word[zz1]
2142
	push	word[zz1]
2142
 
2143
 
2143
	mov	esi,point_index1     ; env coords
2144
	mov	esi,point_index1     ; env coords
2144
	sub	esp,12
2145
	sub	esp,12
2145
	mov	edi,esp
2146
	mov	edi,esp
2146
	mov	ecx,3
2147
	mov	ecx,3
2147
      @@:
2148
      @@:
2148
	movzx	eax,word[esi]
2149
	movzx	eax,word[esi]
2149
	lea	eax,[eax*3]
2150
	lea	eax,[eax*3]
2150
	shl	eax,2
2151
	shl	eax,2
2151
	add	eax,[points_normals_rot_ptr]
2152
	add	eax,[points_normals_rot_ptr]
2152
	; texture x=(rotated point normal -> x * 255)+255
2153
	; texture x=(rotated point normal -> x * 255)+255
2153
	fld	dword[eax]
2154
	fld	dword[eax]
2154
	fimul	[correct_tex]
2155
	fimul	[correct_tex]
2155
	fiadd	[correct_tex]
2156
	fiadd	[correct_tex]
2156
	fistp	word[edi]
2157
	fistp	word[edi]
2157
	; texture y=(rotated point normal -> y * 255)+255
2158
	; texture y=(rotated point normal -> y * 255)+255
2158
	fld	dword[eax+4]
2159
	fld	dword[eax+4]
2159
	fimul	[correct_tex]
2160
	fimul	[correct_tex]
2160
	fiadd	[correct_tex]
2161
	fiadd	[correct_tex]
2161
	fistp	word[edi+2]
2162
	fistp	word[edi+2]
2162
 
2163
 
2163
	add	edi,4
2164
	add	edi,4
2164
	add	esi,2
2165
	add	esi,2
2165
	loop	@b
2166
	loop	@b
2166
 
2167
 
2167
;        push  dword 1 shl 16 + 1  ; emap coords
2168
;        push  dword 1 shl 16 + 1  ; emap coords
2168
;        push  dword 127 shl 16 + 1
2169
;        push  dword 127 shl 16 + 1
2169
;        push  dword 127 shl 16 + 127
2170
;        push  dword 127 shl 16 + 127
2170
 
2171
 
2171
	movzx  esi,[point_index3]      ; bump map coords
2172
	movzx  esi,[point_index3]      ; bump map coords
2172
	shl    esi,2
2173
	shl    esi,2
2173
	add    esi,tex_points
2174
	add    esi,tex_points
2174
	push   dword[esi]
2175
	push   dword[esi]
2175
	movzx  esi,[point_index2]
2176
	movzx  esi,[point_index2]
2176
	shl    esi,2
2177
	shl    esi,2
2177
	add    esi,tex_points
2178
	add    esi,tex_points
2178
	push   dword[esi]
2179
	push   dword[esi]
2179
 
2180
 
2180
	movzx  esi,[point_index1]
2181
	movzx  esi,[point_index1]
2181
	shl    esi,2
2182
	shl    esi,2
2182
	add    esi,tex_points
2183
	add    esi,tex_points
2183
	push   dword[esi]
2184
	push   dword[esi]
2184
 
2185
 
2185
;        push  dword 1 shl 16 + 127
2186
;        push  dword 1 shl 16 + 127
2186
;        push  dword 127 shl 16 + 127
2187
;        push  dword 127 shl 16 + 127
2187
;        push  dword 1 shl 16 + 1  ; bump coords
2188
;        push  dword 1 shl 16 + 1  ; bump coords
2188
 
2189
 
2189
	mov	eax,dword[xx1]
2190
	mov	eax,dword[xx1]
2190
	ror	eax,16
2191
	ror	eax,16
2191
	mov	ebx,dword[xx2]
2192
	mov	ebx,dword[xx2]
2192
	ror	ebx,16
2193
	ror	ebx,16
2193
	mov	ecx,dword[xx3]
2194
	mov	ecx,dword[xx3]
2194
	ror	ecx,16
2195
	ror	ecx,16
2195
	mov	edi,screen
2196
	mov	edi,screen
2196
	mov	esi,envmap
2197
	mov	esi,envmap
2197
	mov	edx,bumpmap
2198
	mov	edx,bumpmap
2198
 
2199
 
2199
	call bump_tex_triangle_z
2200
	call bump_tex_triangle_z
2200
 
2201
 
2201
      .end_draw:
2202
      .end_draw:
2202
	pop	esi
2203
	pop	esi
2203
	add	esi,6
2204
	add	esi,6
2204
	cmp	dword[esi],-1
2205
	cmp	dword[esi],-1
2205
	jne	.again_dts
2206
	jne	.again_dts
2206
ret
2207
ret
2207
 
2208
 
2208
 
2209
 
2209
fill_Z_buffer:
2210
fill_Z_buffer:
2210
	mov	eax,0x70000000
2211
	mov	eax,0x70000000
2211
      ;  mov     edi,Z_buffer
2212
      ;  mov     edi,Z_buffer
2212
	mov	edi,[Zbuffer_ptr]
2213
	mov	edi,[Zbuffer_ptr]
2213
	mov	ecx,SIZE_X*SIZE_Y
2214
	mov	ecx,SIZE_X*SIZE_Y
2214
	rep	stosd
2215
	rep	stosd
2215
ret
2216
ret
2216
 
2217
 
2217
read_from_file:
2218
read_from_file:
2218
	fninit
2219
	fninit
2219
	mov	edi,[triangles_ptr]
2220
	mov	edi,[triangles_ptr]
2220
	xor	ebx,ebx
2221
	xor	ebx,ebx
2221
	xor	ebp,ebp
2222
	xor	ebp,ebp
2222
	mov	[points_count_var],0
2223
	mov	[points_count_var],0
2223
	mov	[triangles_count_var],0
2224
	mov	[triangles_count_var],0
2224
   if USE_LFN = 0
2225
   if USE_LFN = 0
2225
	mov	esi,SourceFile
2226
	mov	esi,SourceFile
2226
   else
2227
   else
2227
	mov	esi,[fptr]
2228
	mov	esi,[fptr]
2228
   end if
2229
   end if
2229
	cmp	[esi],word 4D4Dh
2230
	cmp	[esi],word 4D4Dh
2230
	jne	.exit ;Must be legal .3DS file
2231
	jne	.exit ;Must be legal .3DS file
2231
;        cmp     dword[esi+2],EndFile-SourceFile
2232
;        cmp     dword[esi+2],EndFile-SourceFile
2232
;        jne     .exit ;This must tell the length
2233
;        jne     .exit ;This must tell the length
2233
	mov	eax,dword[esi+2]
2234
	mov	eax,dword[esi+2]
2234
  ;      cmp     eax,[fsize]
2235
  ;      cmp     eax,[fsize]
2235
  ;      jne     .exit
2236
  ;      jne     .exit
2236
 
2237
 
2237
	add	eax,esi
2238
	add	eax,esi
2238
	mov	[EndFile],eax	 ;
2239
	mov	[EndFile],eax	 ;
2239
 
2240
 
2240
	add	esi,6
2241
	add	esi,6
2241
      @@:
2242
      @@:
2242
	cmp	[esi],word 3D3Dh
2243
	cmp	[esi],word 3D3Dh
2243
	je	@f
2244
	je	@f
2244
	add	esi,[esi+2]
2245
	add	esi,[esi+2]
2245
	jmp	@b
2246
	jmp	@b
2246
      @@:
2247
      @@:
2247
	add	esi,6
2248
	add	esi,6
2248
      .find4k:
2249
      .find4k:
2249
	cmp	[esi],word 4000h
2250
	cmp	[esi],word 4000h
2250
	je	@f
2251
	je	@f
2251
	add	esi,[esi+2]
2252
	add	esi,[esi+2]
2252
	cmp	esi,[EndFile]
2253
	cmp	esi,[EndFile]
2253
	jc	.find4k
2254
	jc	.find4k
2254
	jmp	.exit
2255
	jmp	.exit
2255
      @@:
2256
      @@:
2256
	add	esi,6
2257
	add	esi,6
2257
      @@:
2258
      @@:
2258
	cmp	[esi],byte 0
2259
	cmp	[esi],byte 0
2259
	je	@f
2260
	je	@f
2260
	inc	esi
2261
	inc	esi
2261
	jmp	@b
2262
	jmp	@b
2262
      @@:
2263
      @@:
2263
	inc	esi
2264
	inc	esi
2264
      @@:
2265
      @@:
2265
	cmp	[esi],word 4100h
2266
	cmp	[esi],word 4100h
2266
	je	@f
2267
	je	@f
2267
	add	esi,[esi+2]
2268
	add	esi,[esi+2]
2268
	jmp	@b
2269
	jmp	@b
2269
      @@:
2270
      @@:
2270
	add	esi,6
2271
	add	esi,6
2271
      @@:
2272
      @@:
2272
	cmp	[esi],word 4110h
2273
	cmp	[esi],word 4110h
2273
	je	@f
2274
	je	@f
2274
	add	esi,[esi+2]
2275
	add	esi,[esi+2]
2275
	jmp	@b
2276
	jmp	@b
2276
      @@:
2277
      @@:
2277
	movzx	ecx,word[esi+6]
2278
	movzx	ecx,word[esi+6]
2278
	add	[points_count_var],cx
2279
	add	[points_count_var],cx
2279
 
2280
 
2280
	mov	edx,ecx
2281
	mov	edx,ecx
2281
	add	esi,8
2282
	add	esi,8
2282
     @@:
2283
     @@:
2283
	push	edi
2284
	push	edi
2284
	mov	edi,[points_ptr]
2285
	mov	edi,[points_ptr]
2285
	push	dword[esi+4]
2286
	push	dword[esi+4]
2286
	pop	dword[edi+ebx*2+0]
2287
	pop	dword[edi+ebx*2+0]
2287
	push	dword[esi+8]
2288
	push	dword[esi+8]
2288
	pop	dword[edi+ebx*2+4]
2289
	pop	dword[edi+ebx*2+4]
2289
	push	dword[esi+0]
2290
	push	dword[esi+0]
2290
	pop	dword[edi+ebx*2+8]
2291
	pop	dword[edi+ebx*2+8]
2291
	pop	edi
2292
	pop	edi
2292
;        fld     dword[esi+4]
2293
;        fld     dword[esi+4]
2293
;        fstp    dword[real_points+ebx*2+0]  ; x
2294
;        fstp    dword[real_points+ebx*2+0]  ; x
2294
;        fld     dword[esi+8]
2295
;        fld     dword[esi+8]
2295
;        fstp   dword[real_points+ebx*2+4]  ; y
2296
;        fstp   dword[real_points+ebx*2+4]  ; y
2296
;        fld     dword[esi+0]
2297
;        fld     dword[esi+0]
2297
;        fstp   dword[real_points+ebx*2+8]  ; z
2298
;        fstp   dword[real_points+ebx*2+8]  ; z
2298
 
2299
 
2299
	add	ebx,6
2300
	add	ebx,6
2300
	add	esi,12
2301
	add	esi,12
2301
	dec	ecx
2302
	dec	ecx
2302
	jnz	@b
2303
	jnz	@b
2303
      @@:
2304
      @@:
2304
  ;      mov     dword[points+ebx],-1
2305
  ;      mov     dword[points+ebx],-1
2305
	push	edi
2306
	push	edi
2306
	mov	edi,[points_ptr]
2307
	mov	edi,[points_ptr]
2307
	mov	dword[edi+ebx*2],-1	   ; end mark (not always in use)
2308
	mov	dword[edi+ebx*2],-1	   ; end mark (not always in use)
2308
	pop	edi
2309
	pop	edi
2309
      @@:
2310
      @@:
2310
	cmp	[esi],word 4120h
2311
	cmp	[esi],word 4120h
2311
	je	@f
2312
	je	@f
2312
	add	esi,[esi+2]
2313
	add	esi,[esi+2]
2313
	jmp	@b
2314
	jmp	@b
2314
      @@:
2315
      @@:
2315
	movzx	ecx,word[esi+6]
2316
	movzx	ecx,word[esi+6]
2316
	add	[triangles_count_var],cx
2317
	add	[triangles_count_var],cx
2317
	add	esi,8
2318
	add	esi,8
2318
	;mov     edi,triangles
2319
	;mov     edi,triangles
2319
      @@:
2320
      @@:
2320
	movsd
2321
	movsd
2321
	movsw
2322
	movsw
2322
	add	word[edi-6],bp
2323
	add	word[edi-6],bp
2323
	add	word[edi-4],bp
2324
	add	word[edi-4],bp
2324
	add	word[edi-2],bp
2325
	add	word[edi-2],bp
2325
	add	esi,2
2326
	add	esi,2
2326
	dec	ecx
2327
	dec	ecx
2327
	jnz	@b
2328
	jnz	@b
2328
	add	ebp,edx
2329
	add	ebp,edx
2329
	jmp	.find4k
2330
	jmp	.find4k
2330
	mov	eax,-1 ;<---mark if OK
2331
	mov	eax,-1 ;<---mark if OK
2331
      .exit:
2332
      .exit:
2332
	mov	dword[edi],-1
2333
	mov	dword[edi],-1
2333
ret
2334
ret
2334
 
2335
 
2335
read_tp_variables:	      ; read [triangles_count_var] and  [points_count_var]
2336
read_tp_variables:	      ; read [triangles_count_var] and  [points_count_var]
2336
			      ; and  allocate memory
2337
			      ; and  allocate memory
2337
	xor	ebx,ebx
2338
	xor	ebx,ebx
2338
	xor	ebp,ebp
2339
	xor	ebp,ebp
2339
	mov	[points_count_var],bx
2340
	mov	[points_count_var],bx
2340
	mov	[triangles_count_var],bx
2341
	mov	[triangles_count_var],bx
2341
   if USE_LFN = 0
2342
   if USE_LFN = 0
2342
	mov	esi,SourceFile
2343
	mov	esi,SourceFile
2343
   else
2344
   else
2344
	mov	esi,[fptr]
2345
	mov	esi,[fptr]
2345
   end if
2346
   end if
2346
 
2347
 
2347
	cmp	[esi],word 4D4Dh
2348
	cmp	[esi],word 4D4Dh
2348
	je	@f ;Must be legal .3DS file
2349
	je	@f ;Must be legal .3DS file
2349
	xor	eax,eax
2350
	xor	eax,eax
2350
	ret
2351
	ret
2351
    @@:
2352
    @@:
2352
	mov	eax,dword[esi+2]
2353
	mov	eax,dword[esi+2]
2353
	cmp	eax,[fsize] ;This must tell the length
2354
	cmp	eax,[fsize] ;This must tell the length
2354
	je	@f
2355
	je	@f
2355
	xor	eax,eax
2356
	xor	eax,eax
2356
	ret
2357
	ret
2357
     @@:
2358
     @@:
2358
	add	eax,esi
2359
	add	eax,esi
2359
	mov	[EndFile],eax	 ;
2360
	mov	[EndFile],eax	 ;
2360
 
2361
 
2361
	add	esi,6
2362
	add	esi,6
2362
      @@:
2363
      @@:
2363
	cmp	[esi],word 3D3Dh
2364
	cmp	[esi],word 3D3Dh
2364
	je	@f
2365
	je	@f
2365
	add	esi,[esi+2]
2366
	add	esi,[esi+2]
2366
	jmp	@b
2367
	jmp	@b
2367
      @@:
2368
      @@:
2368
	add	esi,6
2369
	add	esi,6
2369
      .find4k:
2370
      .find4k:
2370
	cmp	[esi],word 4000h
2371
	cmp	[esi],word 4000h
2371
	je	@f
2372
	je	@f
2372
	add	esi,[esi+2]
2373
	add	esi,[esi+2]
2373
	cmp	esi,[EndFile]
2374
	cmp	esi,[EndFile]
2374
	jc	.find4k
2375
	jc	.find4k
2375
	jmp	.exit
2376
	jmp	.exit
2376
      @@:
2377
      @@:
2377
	add	esi,6
2378
	add	esi,6
2378
      @@:
2379
      @@:
2379
	cmp	[esi],byte 0
2380
	cmp	[esi],byte 0
2380
	je	@f
2381
	je	@f
2381
	inc	esi
2382
	inc	esi
2382
	jmp	@b
2383
	jmp	@b
2383
      @@:
2384
      @@:
2384
	inc	esi
2385
	inc	esi
2385
      @@:
2386
      @@:
2386
	cmp	[esi],word 4100h
2387
	cmp	[esi],word 4100h
2387
	je	@f
2388
	je	@f
2388
	add	esi,[esi+2]
2389
	add	esi,[esi+2]
2389
	jmp	@b
2390
	jmp	@b
2390
      @@:
2391
      @@:
2391
	add	esi,6
2392
	add	esi,6
2392
      @@:
2393
      @@:
2393
	cmp	[esi],word 4110h
2394
	cmp	[esi],word 4110h
2394
	je	@f
2395
	je	@f
2395
	add	esi,[esi+2]
2396
	add	esi,[esi+2]
2396
	jmp	@b
2397
	jmp	@b
2397
      @@:
2398
      @@:
2398
	movzx	ecx,word[esi+6]
2399
	movzx	ecx,word[esi+6]
2399
	add	[points_count_var],cx
2400
	add	[points_count_var],cx
2400
 
2401
 
2401
	mov	edx,ecx
2402
	mov	edx,ecx
2402
	add	esi,8
2403
	add	esi,8
2403
     @@:
2404
     @@:
2404
 
2405
 
2405
	add	ebx,6
2406
	add	ebx,6
2406
	add	esi,12
2407
	add	esi,12
2407
     ;   dec     ecx
2408
     ;   dec     ecx
2408
	loop	 @b
2409
	loop	 @b
2409
      @@:
2410
      @@:
2410
 
2411
 
2411
      @@:
2412
      @@:
2412
	cmp	[esi],word 4120h
2413
	cmp	[esi],word 4120h
2413
	je	@f
2414
	je	@f
2414
	add	esi,[esi+2]
2415
	add	esi,[esi+2]
2415
	jmp	@b
2416
	jmp	@b
2416
      @@:
2417
      @@:
2417
	movzx	ecx,word[esi+6]
2418
	movzx	ecx,word[esi+6]
2418
	add	[triangles_count_var],cx
2419
	add	[triangles_count_var],cx
2419
	add	esi,8
2420
	add	esi,8
2420
 
2421
 
2421
      @@:
2422
      @@:
2422
	add	esi,8
2423
	add	esi,8
2423
	dec	ecx
2424
	dec	ecx
2424
	jnz	@b
2425
	jnz	@b
2425
;        xor     ecx,ecx
2426
;        xor     ecx,ecx
2426
	add	ebp,edx
2427
	add	ebp,edx
2427
	jmp	.find4k
2428
	jmp	.find4k
2428
	mov	eax,-1 ;<---mark if OK
2429
	mov	eax,-1 ;<---mark if OK
2429
      .exit:
2430
      .exit:
2430
ret
2431
ret
2431
 
2432
 
2432
if USE_LFN
2433
if USE_LFN
2433
alloc_mem_for_tp:
2434
alloc_mem_for_tp:
2434
	mov	eax, 68
2435
	mov	eax, 68
2435
	cmp	[re_alloc_flag],1
2436
	cmp	[re_alloc_flag],1
2436
	jz	@f
2437
	jz	@f
2437
	mov	ebx, 12
2438
	mov	ebx, 12
2438
	jmp	.alloc
2439
	jmp	.alloc
2439
    @@:
2440
    @@:
2440
	mov	ebx,20
2441
	mov	ebx,20
2441
    .alloc:
2442
    .alloc:
2442
	movzx	ecx, [triangles_count_var]
2443
	movzx	ecx, [triangles_count_var]
2443
	inc	ecx
2444
	inc	ecx
2444
	lea	ecx, [ecx*3]
2445
	lea	ecx, [ecx*3]
2445
	add	ecx, ecx
2446
	add	ecx, ecx
2446
	mov	edx,[triangles_ptr]
2447
	mov	edx,[triangles_ptr]
2447
	int	0x40		       ;  -> allocate memory to triangles
2448
	int	0x40		       ;  -> allocate memory to triangles
2448
	mov	[triangles_ptr], eax   ;  -> eax = pointer to allocated mem
2449
	mov	[triangles_ptr], eax   ;  -> eax = pointer to allocated mem
2449
 
2450
 
2450
;        mov     eax, 68
2451
;        mov     eax, 68
2451
;        mov     ebx, 12
2452
;        mov     ebx, 12
2452
;        movzx   ecx, [triangles_count_var]
2453
;        movzx   ecx, [triangles_count_var]
2453
;        shl     ecx, 4
2454
;        shl     ecx, 4
2454
;        int     0x40
2455
;        int     0x40
2455
;        mov     [triangles_w_z_ptr], eax   ; for trainagles_with_z list
2456
;        mov     [triangles_w_z_ptr], eax   ; for trainagles_with_z list
2456
					    ; ststic  memory
2457
					    ; ststic  memory
2457
 
2458
 
2458
	mov	eax, 68
2459
	mov	eax, 68
2459
	movzx	ecx, [triangles_count_var]
2460
	movzx	ecx, [triangles_count_var]
2460
	lea	ecx, [3+ecx*3]
2461
	lea	ecx, [3+ecx*3]
2461
	shl	ecx, 2
2462
	shl	ecx, 2
2462
	mov	edx,[triangles_normals_ptr]
2463
	mov	edx,[triangles_normals_ptr]
2463
	int	0x40			       ;  -> allocate memory for triangles normals
2464
	int	0x40			       ;  -> allocate memory for triangles normals
2464
	mov	[triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
2465
	mov	[triangles_normals_ptr], eax   ;  -> eax = pointer to allocated mem
2465
 
2466
 
2466
	mov	eax, 68
2467
	mov	eax, 68
2467
	movzx	ecx, [points_count_var]
2468
	movzx	ecx, [points_count_var]
2468
	lea	ecx,[3+ecx*3]
2469
	lea	ecx,[3+ecx*3]
2469
	shl	ecx, 2
2470
	shl	ecx, 2
2470
	mov	edx,[points_normals_ptr]
2471
	mov	edx,[points_normals_ptr]
2471
	int	0x40
2472
	int	0x40
2472
	mov	[points_normals_ptr], eax
2473
	mov	[points_normals_ptr], eax
2473
 
2474
 
2474
	mov	eax, 68
2475
	mov	eax, 68
2475
    ;    mov     ebx, 12
2476
    ;    mov     ebx, 12
2476
	movzx	ecx, [points_count_var]
2477
	movzx	ecx, [points_count_var]
2477
	lea	ecx,[3+ecx*3]
2478
	lea	ecx,[3+ecx*3]
2478
	shl	ecx, 2
2479
	shl	ecx, 2
2479
	mov	edx,[points_normals_rot_ptr]
2480
	mov	edx,[points_normals_rot_ptr]
2480
	int	0x40
2481
	int	0x40
2481
	mov	[points_normals_rot_ptr], eax
2482
	mov	[points_normals_rot_ptr], eax
2482
 
2483
 
2483
	mov	eax, 68
2484
	mov	eax, 68
2484
	mov	edx,[points_ptr]
2485
	mov	edx,[points_ptr]
2485
	int	0x40
2486
	int	0x40
2486
	mov	[points_ptr], eax
2487
	mov	[points_ptr], eax
2487
 
2488
 
2488
	mov	eax, 68
2489
	mov	eax, 68
2489
	mov	edx,[points_rotated_ptr]
2490
	mov	edx,[points_rotated_ptr]
2490
	int	0x40
2491
	int	0x40
2491
	mov	[points_rotated_ptr], eax
2492
	mov	[points_rotated_ptr], eax
2492
 
2493
 
2493
	mov	eax, 68
2494
	mov	eax, 68
2494
	movzx	ecx, [points_count_var]
2495
	movzx	ecx, [points_count_var]
2495
	inc	ecx
2496
	inc	ecx
2496
	shl	ecx, 3
2497
	shl	ecx, 3
2497
	mov	edx,[points_translated_ptr]
2498
	mov	edx,[points_translated_ptr]
2498
	int	0x40
2499
	int	0x40
2499
	mov	[points_translated_ptr], eax
2500
	mov	[points_translated_ptr], eax
2500
ret
2501
ret
2501
end if
2502
end if
2502
 
2503
 
2503
 
2504
 
2504
read_from_disk:
2505
read_from_disk:
2505
if USE_LFN
2506
if USE_LFN
2506
;-
2507
;-
2507
    mov     eax, 70
2508
    mov     eax, 70
2508
    mov     ebx, file_info
2509
    mov     ebx, file_info
2509
    mov     dword[ebx], 5	   ;  -> subfunction number
2510
    mov     dword[ebx], 5	   ;  -> subfunction number
2510
    int     0x40		   ;  -> read file size
2511
    int     0x40		   ;  -> read file size
2511
    mov     ebx, [fptr]
2512
    mov     ebx, [fptr]
2512
    mov     ebx, dword[ebx+32]
2513
    mov     ebx, dword[ebx+32]
2513
    inc     ebx
2514
    inc     ebx
2514
    mov     [fsize], ebx
2515
    mov     [fsize], ebx
2515
 
2516
 
2516
    mov     eax, 68
2517
    mov     eax, 68
2517
    mov     ebx, 11
2518
    mov     ebx, 11
2518
    int     0x40		   ;  -> create heap
2519
    int     0x40		   ;  -> create heap
2519
 
2520
 
2520
    mov     eax, 68
2521
    mov     eax, 68
2521
    mov     ebx, 12
2522
    mov     ebx, 12
2522
    mov     ecx, [fsize]
2523
    mov     ecx, [fsize]
2523
    int     0x40		   ;  -> allocate memory for file
2524
    int     0x40		   ;  -> allocate memory for file
2524
    mov     [fptr], eax 	   ;  -> eax = pointer to allocated mem
2525
    mov     [fptr], eax 	   ;  -> eax = pointer to allocated mem
2525
 
2526
 
2526
    mov     eax, 70
2527
    mov     eax, 70
2527
    mov     ebx, file_info
2528
    mov     ebx, file_info
2528
    mov     dword[ebx],0
2529
    mov     dword[ebx],0
2529
    int     0x40		   ; -> read file
2530
    int     0x40		   ; -> read file
2530
 
2531
 
2531
    mov     [fsize],ebx
2532
    mov     [fsize],ebx
2532
 
2533
 
2533
    cmp     eax,6
2534
    cmp     eax,6
2534
    jnz     @f
2535
    jnz     @f
2535
    xor     eax,eax	;;;;---
2536
    xor     eax,eax	;;;;---
2536
  @@:
2537
  @@:
2537
else
2538
else
2538
    mov      eax,58
2539
    mov      eax,58
2539
    mov      ebx,file_info
2540
    mov      ebx,file_info
2540
    int      0x40
2541
    int      0x40
2541
 
2542
 
2542
    mov      eax,ebx
2543
    mov      eax,ebx
2543
    shr      eax,9
2544
    shr      eax,9
2544
    inc      eax
2545
    inc      eax
2545
    mov      [fsize],eax
2546
    mov      [fsize],eax
2546
;    mov      ecx,ebx
2547
;    mov      ecx,ebx
2547
;    add      ecx,MEM_END
2548
;    add      ecx,MEM_END
2548
;    mov      ebx,1
2549
;    mov      ebx,1
2549
;    mov      eax,64     ; allocate mem  - resize app mem
2550
;    mov      eax,64     ; allocate mem  - resize app mem
2550
			; for points and  triangles
2551
			; for points and  triangles
2551
    int      0x40
2552
    int      0x40
2552
 
2553
 
2553
    mov      eax,58
2554
    mov      eax,58
2554
    mov      ebx,file_info
2555
    mov      ebx,file_info
2555
    int      0x40
2556
    int      0x40
2556
end if
2557
end if
2557
  ;  eax = 0   -> ok file loaded
2558
  ;  eax = 0   -> ok file loaded
2558
ret
2559
ret
2559
read_param:
2560
read_param:
2560
    mov        esi,I_Param
2561
    mov        esi,I_Param
2561
    cmp        dword[esi],0
2562
    cmp        dword[esi],0
2562
    je	       .end
2563
    je	       .end
2563
    cmp        byte[esi],'/'
2564
    cmp        byte[esi],'/'
2564
    je	       .copy
2565
    je	       .copy
2565
    mov        edi,esi
2566
    mov        edi,esi
2566
    mov        ecx,25	; 25 - would be enought
2567
    mov        ecx,25	; 25 - would be enought
2567
    repe       scasb
2568
    repe       scasb
2568
    jne        .end
2569
    jne        .end
2569
    dec        edi
2570
    dec        edi
2570
    mov        esi,edi
2571
    mov        esi,edi
2571
 .copy:
2572
 .copy:
2572
    mov 	edi,file_name
2573
    mov 	edi,file_name
2573
    mov 	ecx,50
2574
    mov 	ecx,50
2574
    rep 	movsd
2575
    rep 	movsd
2575
 .end:
2576
 .end:
2576
ret
2577
ret
2577
buttons:				      ; draw some buttons (all but navigation and close )
2578
buttons:				      ; draw some buttons (all but navigation and close )
2578
	mov	edi,menu
2579
	mov	edi,menu
2579
      .again:
2580
      .again:
2580
	mov	eax,8			      ; function 8 : define and draw button
2581
	mov	eax,8			      ; function 8 : define and draw button
2581
	mov	ebx,(SIZE_X+10)*65536+62      ; [x start] *65536 + [x size]
2582
	mov	ebx,(SIZE_X+10)*65536+62      ; [x start] *65536 + [x size]
2582
	movzx	ecx,byte[edi]		      ; button id = position+2
2583
	movzx	ecx,byte[edi]		      ; button id = position+2
2583
	sub	cl,2
2584
	sub	cl,2
2584
	lea	ecx,[ecx*5]
2585
	lea	ecx,[ecx*5]
2585
	lea	ecx,[ecx*3]
2586
	lea	ecx,[ecx*3]
2586
	add	ecx,25
2587
	add	ecx,25
2587
	shl	ecx,16
2588
	shl	ecx,16
2588
	add	ecx,12
2589
	add	ecx,12
2589
	movzx	edx,byte[edi]			; button id
2590
	movzx	edx,byte[edi]			; button id
2590
	mov	esi,0x6688dd			; button color RRGGBB
2591
	mov	esi,0x6688dd			; button color RRGGBB
2591
	int	0x40
2592
	int	0x40
2592
	 ; BUTTON  LABEL
2593
	 ; BUTTON  LABEL
2593
	mov	eax,4				; function 4 : write text to window
2594
	mov	eax,4				; function 4 : write text to window
2594
	movzx	ebx,byte[edi]
2595
	movzx	ebx,byte[edi]
2595
	sub	bl,2				; button id, according to position
2596
	sub	bl,2				; button id, according to position
2596
	lea	ebx,[ebx*3]
2597
	lea	ebx,[ebx*3]
2597
	lea	ebx,[ebx*5]
2598
	lea	ebx,[ebx*5]
2598
	add	ebx,(SIZE_X+12)*65536+28	; [x start] *65536 + [y start]
2599
	add	ebx,(SIZE_X+12)*65536+28	; [x start] *65536 + [y start]
2599
	mov	ecx,0x20ddeeff			; font 1 & color ( 0xF0RRGGBB )
2600
	mov	ecx,0x20ddeeff			; font 1 & color ( 0xF0RRGGBB )
2600
	lea	edx,[edi+1]			; pointer to text beginning
2601
	lea	edx,[edi+1]			; pointer to text beginning
2601
	mov	esi,10				; text length
2602
	mov	esi,10				; text length
2602
	int	0x40
2603
	int	0x40
2603
	cmp	byte[edi+11],255		; if max_flag=255
2604
	cmp	byte[edi+11],255		; if max_flag=255
2604
	je	@f				; skip
2605
	je	@f				; skip
2605
	; flag description
2606
	; flag description
2606
;       mov     eax,4                           ; function 4 : write text to window
2607
;       mov     eax,4                           ; function 4 : write text to window
2607
;       movzx   ebx,byte[edi]
2608
;       movzx   ebx,byte[edi]
2608
;       sub     bl,2
2609
;       sub     bl,2
2609
;       lea     ebx,[ebx*3]
2610
;       lea     ebx,[ebx*3]
2610
;       lea     ebx,[ebx*5]
2611
;       lea     ebx,[ebx*5]
2611
;       add     ebx,(SIZE_X+12+70)*65536+28     ; [x start] *65536 + [y start]
2612
;       add     ebx,(SIZE_X+12+70)*65536+28     ; [x start] *65536 + [y start]
2612
	add	ebx,70*65536
2613
	add	ebx,70*65536
2613
;       mov     ecx,0x20ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
2614
;       mov     ecx,0x20ddeeff                  ; font 1 & color ( 0xF0RRGGBB )
2614
	movzx	edx,byte[edi+12]		; current flag
2615
	movzx	edx,byte[edi+12]		; current flag
2615
	shl	edx,2				; * 4 = text length
2616
	shl	edx,2				; * 4 = text length
2616
	add	edx,dword[edi+13]		; pointer to text beginning
2617
	add	edx,dword[edi+13]		; pointer to text beginning
2617
	mov	esi,4				; text length
2618
	mov	esi,4				; text length
2618
	int	0x40
2619
	int	0x40
2619
 
2620
 
2620
    @@:
2621
    @@:
2621
	add	edi,17
2622
	add	edi,17
2622
	cmp	byte[edi],-1
2623
	cmp	byte[edi],-1
2623
	jnz	.again
2624
	jnz	.again
2624
ret
2625
ret
2625
;   *********************************************
2626
;   *********************************************
2626
;   *******  WINDOW DEFINITIONS AND DRAW ********
2627
;   *******  WINDOW DEFINITIONS AND DRAW ********
2627
;   *********************************************
2628
;   *********************************************
2628
    draw_window:
2629
    draw_window:
2629
	mov	eax,12		; function 12:tell os about windowdraw
2630
	mov	eax,12		; function 12:tell os about windowdraw
2630
	mov	ebx,1		; 1, start of draw
2631
	mov	ebx,1		; 1, start of draw
2631
	int	0x40
2632
	int	0x40
2632
 
2633
 
2633
	; DRAW WINDOW
2634
	; DRAW WINDOW
2634
	mov	eax,0		; function 0 : define and draw window
2635
	mov	eax,0		; function 0 : define and draw window
2635
	mov	ebx,100*65536;+SIZE_X;+80+30 ; [x start] *65536 + [x size]
2636
	mov	ebx,100*65536;+SIZE_X;+80+30 ; [x start] *65536 + [x size]
2636
	mov	ecx,100*65536;+SIZE_Y;+30    ; [y start] *65536 + [y size]
2637
	mov	ecx,100*65536;+SIZE_Y;+30    ; [y start] *65536 + [y size]
2637
	mov	bx,[size_x]
2638
	mov	bx,[size_x]
2638
	add	bx,110
2639
	add	bx,110
2639
	mov	cx,[size_y]
2640
	mov	cx,[size_y]
2640
	add	cx,30
2641
	add	cx,30
2641
	mov	edx,0x14000000	; color of work area RRGGBB,8->color gl
2642
	mov	edx,0x14000000	; color of work area RRGGBB,8->color gl
2642
	mov	esi,0x805080d0	; color of grab bar  RRGGBB,8->color gl
2643
	mov	esi,0x805080d0	; color of grab bar  RRGGBB,8->color gl
2643
	mov	edi,0x005080d0	; color of frames    RRGGBB
2644
	mov	edi,0x005080d0	; color of frames    RRGGBB
2644
	int	0x40
2645
	int	0x40
2645
 
2646
 
2646
	; WINDOW LABEL
2647
	; WINDOW LABEL
2647
	mov	eax,4		; function 4 : write text to window
2648
	mov	eax,4		; function 4 : write text to window
2648
	mov	ebx,8*65536+8	; [x start] *65536 + [y start]
2649
	mov	ebx,8*65536+8	; [x start] *65536 + [y start]
2649
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2650
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2650
	mov	edx,labelt	; pointer to text beginning
2651
	mov	edx,labelt	; pointer to text beginning
2651
	mov	esi,labellen-labelt	; text length
2652
	mov	esi,labellen-labelt	; text length
2652
	int	0x40
2653
	int	0x40
2653
 
2654
 
2654
	; CLOSE BUTTON
2655
	; CLOSE BUTTON
2655
;       mov     eax,8           ; function 8 : define and draw button
2656
;       mov     eax,8           ; function 8 : define and draw button
2656
;       movzx   ebx,[size_x]
2657
;       movzx   ebx,[size_x]
2657
;       shl     ebx,16
2658
;       shl     ebx,16
2658
;       add     ebx, 91 shl 16 + 12
2659
;       add     ebx, 91 shl 16 + 12
2659
;;        mov     ebx,(SIZE_X+80+30-19)*65536+12     ; [x start] *65536 + [x size]
2660
;;        mov     ebx,(SIZE_X+80+30-19)*65536+12     ; [x start] *65536 + [x size]
2660
;       mov     ecx,5*65536+12  ; [y start] *65536 + [y size]
2661
;       mov     ecx,5*65536+12  ; [y start] *65536 + [y size]
2661
;       mov     edx,1           ; button id
2662
;       mov     edx,1           ; button id
2662
;       mov     esi,0x6688dd    ; button color RRGGBB
2663
;       mov     esi,0x6688dd    ; button color RRGGBB
2663
;       int     0x40
2664
;       int     0x40
2664
 
2665
 
2665
	call	buttons 	; more buttons
2666
	call	buttons 	; more buttons
2666
 
2667
 
2667
	.Y_ADD equ 1   ;-> offset of 'add vector' buttons
2668
	.Y_ADD equ 1   ;-> offset of 'add vector' buttons
2668
 
2669
 
2669
	; ADD VECTOR LABEL      ; add vector buttons - 30 ++
2670
	; ADD VECTOR LABEL      ; add vector buttons - 30 ++
2670
	mov	eax,4		; function 4 : write text to window
2671
	mov	eax,4		; function 4 : write text to window
2671
	mov	ebx,(SIZE_X+12)*65536+(168+15*(13+.Y_ADD))   ; [x start] *65536 + [y start]
2672
	mov	ebx,(SIZE_X+12)*65536+(168+15*(13+.Y_ADD))   ; [x start] *65536 + [y start]
2672
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2673
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2673
	mov	edx,labelvector      ; pointer to text beginning
2674
	mov	edx,labelvector      ; pointer to text beginning
2674
	mov	esi,labelvectorend-labelvector	   ; text length
2675
	mov	esi,labelvectorend-labelvector	   ; text length
2675
    ;    cmp     [move_flag],2
2676
    ;    cmp     [move_flag],2
2676
    ;    jne     @f
2677
    ;    jne     @f
2677
    ;    add     edx,navigation_size
2678
    ;    add     edx,navigation_size
2678
    ;  @@:
2679
    ;  @@:
2679
	int	0x40
2680
	int	0x40
2680
	 ; VECTOR Y- BUTTON
2681
	 ; VECTOR Y- BUTTON
2681
	mov	eax,8		; function 8 : define and draw button
2682
	mov	eax,8		; function 8 : define and draw button
2682
	mov	ebx,(SIZE_X+30)*65536+20     ; [x start] *65536 + [x size]
2683
	mov	ebx,(SIZE_X+30)*65536+20     ; [x start] *65536 + [x size]
2683
	mov	ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2684
	mov	ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2684
	mov	edx,30		 ; button id
2685
	mov	edx,30		 ; button id
2685
	mov	esi,0x6688dd	; button color RRGGBB
2686
	mov	esi,0x6688dd	; button color RRGGBB
2686
	int	0x40
2687
	int	0x40
2687
	;VECTOR Y- LABEL
2688
	;VECTOR Y- LABEL
2688
	mov	eax,4		; function 4 : write text to window
2689
	mov	eax,4		; function 4 : write text to window
2689
	mov	ebx,(SIZE_X+32)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
2690
	mov	ebx,(SIZE_X+32)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
2690
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2691
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2691
	mov	edx,labelyminus      ; pointer to text beginning
2692
	mov	edx,labelyminus      ; pointer to text beginning
2692
	mov	esi,labelyminusend-labelyminus	   ; text length
2693
	mov	esi,labelyminusend-labelyminus	   ; text length
2693
	cmp	[move_flag],2
2694
	cmp	[move_flag],2
2694
   ;     jne     @f
2695
   ;     jne     @f
2695
   ;     add     edx,navigation_size
2696
   ;     add     edx,navigation_size
2696
   ;   @@:
2697
   ;   @@:
2697
	int	0x40
2698
	int	0x40
2698
	; VECTOR Z+ BUTTON
2699
	; VECTOR Z+ BUTTON
2699
	mov	eax,8		; function 8 : define and draw button
2700
	mov	eax,8		; function 8 : define and draw button
2700
	mov	ebx,(SIZE_X+51)*65536+21     ; [x start] *65536 + [x size]
2701
	mov	ebx,(SIZE_X+51)*65536+21     ; [x start] *65536 + [x size]
2701
	mov	ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2702
	mov	ecx,(165+15*(14+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2702
	mov	edx,31		 ; button id
2703
	mov	edx,31		 ; button id
2703
	mov	esi,0x6688dd	; button color RRGGBB
2704
	mov	esi,0x6688dd	; button color RRGGBB
2704
	int	0x40
2705
	int	0x40
2705
	;VECTOR Z+ LABEL
2706
	;VECTOR Z+ LABEL
2706
	mov	eax,4		; function 4 : write text to window
2707
	mov	eax,4		; function 4 : write text to window
2707
	mov	ebx,(SIZE_X+53)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
2708
	mov	ebx,(SIZE_X+53)*65536+(168+15*(14+.Y_ADD))   ; [x start] *65536 + [y start]
2708
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2709
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2709
	mov	edx,labelzplus	    ; pointer to text beginning
2710
	mov	edx,labelzplus	    ; pointer to text beginning
2710
	mov	esi,labelzplusend-labelzplus	 ; text length
2711
	mov	esi,labelzplusend-labelzplus	 ; text length
2711
   ;     cmp     [move_flag],2
2712
   ;     cmp     [move_flag],2
2712
   ;     jne     @f
2713
   ;     jne     @f
2713
   ;     add     edx,navigation_size
2714
   ;     add     edx,navigation_size
2714
   ;   @@:
2715
   ;   @@:
2715
 
2716
 
2716
	int	0x40
2717
	int	0x40
2717
	; VECTOR x- BUTTON
2718
	; VECTOR x- BUTTON
2718
	mov	eax,8		; function 8 : define and draw button
2719
	mov	eax,8		; function 8 : define and draw button
2719
	mov	ebx,(SIZE_X+10)*65536+21     ; [x start] *65536 + [x size]
2720
	mov	ebx,(SIZE_X+10)*65536+21     ; [x start] *65536 + [x size]
2720
	mov	ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2721
	mov	ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2721
	mov	edx,32		 ; button id
2722
	mov	edx,32		 ; button id
2722
	mov	esi,0x6688dd	; button color RRGGBB
2723
	mov	esi,0x6688dd	; button color RRGGBB
2723
	int	0x40
2724
	int	0x40
2724
	;VECTOR x- LABEL
2725
	;VECTOR x- LABEL
2725
	mov	eax,4		; function 4 : write text to window
2726
	mov	eax,4		; function 4 : write text to window
2726
	mov	ebx,(SIZE_X+12)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
2727
	mov	ebx,(SIZE_X+12)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
2727
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2728
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2728
	mov	edx,labelxminus      ; pointer to text beginning
2729
	mov	edx,labelxminus      ; pointer to text beginning
2729
	mov	esi,labelxminusend-labelxminus	   ; text length
2730
	mov	esi,labelxminusend-labelxminus	   ; text length
2730
   ;     cmp     [move_flag],2
2731
   ;     cmp     [move_flag],2
2731
   ;     jne     @f
2732
   ;     jne     @f
2732
   ;     add     edx,navigation_size
2733
   ;     add     edx,navigation_size
2733
   ;   @@:
2734
   ;   @@:
2734
	int	0x40
2735
	int	0x40
2735
	; VECTOR x+ BUTTON
2736
	; VECTOR x+ BUTTON
2736
	mov	eax,8		; function 8 : define and draw button
2737
	mov	eax,8		; function 8 : define and draw button
2737
	mov	ebx,(SIZE_X+51)*65536+21     ; [x start] *65536 + [x size]
2738
	mov	ebx,(SIZE_X+51)*65536+21     ; [x start] *65536 + [x size]
2738
	mov	ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2739
	mov	ecx,(165+15*(15+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2739
	mov	edx,33		 ; button id
2740
	mov	edx,33		 ; button id
2740
	mov	esi,0x6688dd	; button color RRGGBB
2741
	mov	esi,0x6688dd	; button color RRGGBB
2741
	int	0x40
2742
	int	0x40
2742
	;VECTOR x+ LABEL
2743
	;VECTOR x+ LABEL
2743
	mov	eax,4		; function 4 : write text to window
2744
	mov	eax,4		; function 4 : write text to window
2744
	mov	ebx,(SIZE_X+53)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
2745
	mov	ebx,(SIZE_X+53)*65536+(168+15*(15+.Y_ADD))   ; [x start] *65536 + [y start]
2745
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2746
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2746
	mov	edx,labelxplus	    ; pointer to text beginning
2747
	mov	edx,labelxplus	    ; pointer to text beginning
2747
	mov	esi,labelxplusend-labelxplus	 ; text length
2748
	mov	esi,labelxplusend-labelxplus	 ; text length
2748
   ;     cmp     [move_flag],2
2749
   ;     cmp     [move_flag],2
2749
   ;     jne     @f
2750
   ;     jne     @f
2750
   ;     add     edx,navigation_size
2751
   ;     add     edx,navigation_size
2751
   ;   @@:
2752
   ;   @@:
2752
	int	0x40
2753
	int	0x40
2753
	; VECTOR z- BUTTON
2754
	; VECTOR z- BUTTON
2754
	mov	eax,8		; function 8 : define and draw button
2755
	mov	eax,8		; function 8 : define and draw button
2755
	mov	ebx,(SIZE_X+10)*65536+62-41	; [x start] *65536 + [x size]
2756
	mov	ebx,(SIZE_X+10)*65536+62-41	; [x start] *65536 + [x size]
2756
	mov	ecx,(25+140+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2757
	mov	ecx,(25+140+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2757
	mov	edx,34		 ; button id
2758
	mov	edx,34		 ; button id
2758
	mov	esi,0x6688dd	; button color RRGGBB
2759
	mov	esi,0x6688dd	; button color RRGGBB
2759
	int	0x40
2760
	int	0x40
2760
	;VECTOR z- LABEL
2761
	;VECTOR z- LABEL
2761
	mov	eax,4		; function 4 : write text to window
2762
	mov	eax,4		; function 4 : write text to window
2762
	mov	ebx,(SIZE_X+12)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
2763
	mov	ebx,(SIZE_X+12)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
2763
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2764
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2764
	mov	edx,labelzminus      ; pointer to text beginning
2765
	mov	edx,labelzminus      ; pointer to text beginning
2765
	mov	esi,labelzminusend-labelzminus	   ; text length
2766
	mov	esi,labelzminusend-labelzminus	   ; text length
2766
   ;     cmp     [move_flag],2
2767
   ;     cmp     [move_flag],2
2767
   ;     jne     @f
2768
   ;     jne     @f
2768
   ;     add     edx,navigation_size
2769
   ;     add     edx,navigation_size
2769
   ;   @@:
2770
   ;   @@:
2770
	int	0x40
2771
	int	0x40
2771
       ;VECTOR Y+ BUTTON
2772
       ;VECTOR Y+ BUTTON
2772
	mov	eax,8		; function 8 : define and draw button
2773
	mov	eax,8		; function 8 : define and draw button
2773
	mov	ebx,(SIZE_X+10+20)*65536+20	; [x start] *65536 + [x size]
2774
	mov	ebx,(SIZE_X+10+20)*65536+20	; [x start] *65536 + [x size]
2774
	mov	ecx,(165+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2775
	mov	ecx,(165+15*(16+.Y_ADD))*65536+12  ; [y start] *65536 + [y size]
2775
	mov	edx,35		 ; button id
2776
	mov	edx,35		 ; button id
2776
	mov	esi,0x6688dd	; button color RRGGBB
2777
	mov	esi,0x6688dd	; button color RRGGBB
2777
	int	0x40
2778
	int	0x40
2778
	;VECTOR Y+ LABEL
2779
	;VECTOR Y+ LABEL
2779
	mov	eax,4		; function 4 : write text to window
2780
	mov	eax,4		; function 4 : write text to window
2780
	mov	ebx,(SIZE_X+32)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
2781
	mov	ebx,(SIZE_X+32)*65536+(168+15*(16+.Y_ADD))   ; [x start] *65536 + [y start]
2781
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2782
	mov	ecx,0x20ddeeff	; font 1 & color ( 0xF0RRGGBB )
2782
	mov	edx,labelyplus	    ; pointer to text beginning
2783
	mov	edx,labelyplus	    ; pointer to text beginning
2783
	mov	esi,labelyplusend-labelyplus	 ; text length
2784
	mov	esi,labelyplusend-labelyplus	 ; text length
2784
   ;     cmp     [move_flag],2
2785
   ;     cmp     [move_flag],2
2785
   ;     jne     @f
2786
   ;     jne     @f
2786
   ;     add     edx,navigation_size
2787
   ;     add     edx,navigation_size
2787
   ;   @@:
2788
   ;   @@:
2788
	int	0x40
2789
	int	0x40
2789
 
2790
 
2790
	mov	eax,12		; function 12:tell os about windowdraw
2791
	mov	eax,12		; function 12:tell os about windowdraw
2791
	mov	ebx,2		; 2, end of draw
2792
	mov	ebx,2		; 2, end of draw
2792
	int	0x40
2793
	int	0x40
2793
	ret
2794
	ret
2794
 
2795
 
2795
 
2796
 
2796
   ; DATA AREA  ************************************
2797
   ; DATA AREA  ************************************
2797
 
2798
 
2798
   include 'data.inc'
2799
   include 'DATA.INC'
2799
 
2800
 
2800
MEM_END:
2801
MEM_END: