Subversion Repositories Kolibri OS

Rev

Rev 2984 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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