Subversion Repositories Kolibri OS

Rev

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

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