Subversion Repositories Kolibri OS

Rev

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

Rev 485 Rev 551
1
;
1
;
2
; 3D POLYGONAL CUBE - ASCL
2
; 3D POLYGONAL CUBE - ASCL
3
;
3
;
4
; Pavlushin Evgeni
4
; Pavlushin Evgeni
5
; mail: waptap@mail.ru       site: www.deck4.narod.ru
5
; mail: waptap@mail.ru       site: www.deck4.narod.ru
6
;
6
;
7
; Create on base 3D test sample
7
; Create on base 3D test sample
8
; Mikolaj Felix mfelix@polbox.com
8
; Mikolaj Felix mfelix@polbox.com
9
;
9
;
10
 
10
 
11
use32
11
use32
12
               org     0x0
12
               org     0x0
13
               db     'MENUET01'              ; 8 byte id
13
               db     'MENUET01'              ; 8 byte id
14
               dd     0x01                    ; header version
14
               dd     0x01                    ; header version
15
               dd     START                   ; start of code
15
               dd     START                   ; start of code
16
               dd     I_END                   ; size of image
16
               dd     I_END                   ; size of image
17
               dd     0x30000                  ; memory for app
17
               dd     0x30000                  ; memory for app
18
               dd     0x30000                  ; esp
18
               dd     0x30000                  ; esp
19
               dd     0x0 , 0x0               ; I_Param , I_Icon
19
               dd     0x0 , 0x0               ; I_Param , I_Icon
20
 
20
 
21
MAX_POINTS equ 8
21
MAX_POINTS equ 8
22
MAX_TRIANGLES equ 12
22
MAX_TRIANGLES equ 12
23
SCREEN_X equ 320
23
SCREEN_X equ 320
24
SCREEN_Y equ 200
24
SCREEN_Y equ 200
25
 
25
 
26
include 'lang.inc'
26
include 'lang.inc'
27
include '..\..\..\macros.inc'
27
include '..\..\..\macros.inc'
28
include 'ascl.inc'
28
include 'ascl.inc'
29
include 'ascgl.inc'
29
include 'ascgl.inc'
30
 
30
 
31
START:
31
START:
32
    call draw_window
32
    call draw_window
33
   	call init_sin_cos
33
   	call init_sin_cos
34
 
34
 
35
still:
35
still:
36
    mov eax,11
36
    mov eax,11
37
    mcall
37
    mcall
38
 
38
 
39
    dec eax
39
    dec eax
40
;    cmp  eax,1                  ; window redraw request ?
40
;    cmp  eax,1                  ; window redraw request ?
41
    jz   red
41
    jz   red
42
    dec eax
42
    dec eax
43
;    cmp  eax,2                  ; key in buffer ?
43
;    cmp  eax,2                  ; key in buffer ?
44
    jz   key
44
    jz   key
45
    dec eax
45
    dec eax
46
;    cmp  eax,3                  ; button in buffer ?
46
;    cmp  eax,3                  ; button in buffer ?
47
    jz   button
47
    jz   button
48
 
48
 
49
    fps  230,8,cl_White,cl_Black
49
    fps  230,8,cl_White,cl_Black
50
 
50
 
51
main_loop:
51
main_loop:
52
 
52
 
53
	mov esi,object
53
	mov esi,object
54
	mov edi,object_rotated
54
	mov edi,object_rotated
55
	mov ecx,MAX_POINTS*3
55
	mov ecx,MAX_POINTS*3
56
	cld
56
	cld
57
	rep movsw
57
	rep movsw
58
 
58
 
59
	mov esi,angle_x
59
	mov esi,angle_x
60
	mov edi,object_rotated
60
	mov edi,object_rotated
61
	mov ecx,MAX_POINTS
61
	mov ecx,MAX_POINTS
62
	call rotate_points
62
	call rotate_points
63
 
63
 
64
	mov esi,object_rotated
64
	mov esi,object_rotated
65
	mov edi,object_translated
65
	mov edi,object_translated
66
	mov ecx,MAX_POINTS
66
	mov ecx,MAX_POINTS
67
	call translate_points
67
	call translate_points
68
 
68
 
69
	call draw_faces
69
	call draw_faces
70
 
70
 
71
	call clear_screen_buffer
71
	call clear_screen_buffer
72
 
72
 
73
	add [angle_x],2
73
	add [angle_x],2
74
	add [angle_y],3
74
	add [angle_y],3
75
	add [angle_z],1
75
	add [angle_z],1
76
 
76
 
77
     jmp still
77
     jmp still
78
 
78
 
79
red:
79
red:
80
     call draw_window
80
     call draw_window
81
     jmp still
81
     jmp still
82
key:
82
key:
83
     mov eax,2
83
     mov eax,2
84
     mcall
84
     mcall
85
     jmp still
85
     jmp still
86
button:
86
button:
87
     mov eax,17
87
     mov eax,17
88
     mcall
88
     mcall
89
     cmp ah,1
89
     cmp ah,1
90
     jne still
90
     jne still
91
exit:
91
exit:
92
     mov eax,-1
92
     mov eax,-1
93
     mcall
93
     mcall
94
 
94
 
95
;Draw window
95
;Draw window
96
draw_window:
96
draw_window:
97
    mov eax,12  ;Start
97
    mov eax,12  ;Start
98
    mov ebx,1
98
    mov ebx,1
99
    mcall
99
    mcall
100
 
100
 
101
    mov eax,0   ;Draw window
101
    mov eax,0   ;Draw window
102
    mov ebx,100*65536+(SCREEN_X+9) ;x start*65536+x size
102
    mov ebx,100*65536+(SCREEN_X+9) ;x start*65536+x size
103
    mov ecx,100*65536+(SCREEN_Y+26) ;y start*65536+y size
103
    mov ecx,100*65536+(SCREEN_Y+26) ;y start*65536+y size
104
    mov edx,0x13000000         ;0x03 use skinned window
104
    mov edx,0x14000000         ;0x03 use skinned window
105
    mov edi,title
105
    mov edi,title
106
    mcall
106
    mcall
107
 
107
 
108
    mov eax,12  ;End
108
    mov eax,12  ;End
109
    mov ebx,2
109
    mov ebx,2
110
    mcall
110
    mcall
111
    ret
111
    ret
112
 
112
 
113
title db '3D TEST SAMPLE FOR MENUETOS',0
113
title db '3D TEST SAMPLE FOR MENUETOS',0
114
 
114
 
115
 
115
 
116
; Draw faces procedure
116
; Draw faces procedure
117
 
117
 
118
draw_faces:
118
draw_faces:
119
 
119
 
120
	mov esi,link
120
	mov esi,link
121
	mov ecx,MAX_TRIANGLES
121
	mov ecx,MAX_TRIANGLES
122
df_draw:
122
df_draw:
123
	push ecx
123
	push ecx
124
	mov ecx,3
124
	mov ecx,3
125
	mov edi,@@tx1 ;bp
125
	mov edi,@@tx1 ;bp
126
df_get_point:
126
df_get_point:
127
	xor bh,bh
127
	xor bh,bh
128
	mov bl,byte [esi]
128
	mov bl,byte [esi]
129
	shl bx,2
129
	shl bx,2
130
	mov ax,word [object_translated+bx]
130
	mov ax,word [object_translated+bx]
131
	mov word [edi],ax
131
	mov word [edi],ax
132
	mov ax,word [object_translated+bx+2]
132
	mov ax,word [object_translated+bx+2]
133
	mov word [edi+2],ax
133
	mov word [edi+2],ax
134
	inc esi
134
	inc esi
135
	add edi,4
135
	add edi,4
136
	dec ecx
136
	dec ecx
137
	jnz df_get_point
137
	jnz df_get_point
138
 
138
 
139
	mov ax,[@@ty1]
139
	mov ax,[@@ty1]
140
	sub ax,[@@ty3]
140
	sub ax,[@@ty3]
141
	mov bx,[@@tx2]
141
	mov bx,[@@tx2]
142
	sub bx,[@@tx1]
142
	sub bx,[@@tx1]
143
	imul bx
143
	imul bx
144
	shl edx,16
144
	shl edx,16
145
	mov dx,ax
145
	mov dx,ax
146
	push edx
146
	push edx
147
	mov ax,[@@tx1]
147
	mov ax,[@@tx1]
148
	sub ax,[@@tx3]
148
	sub ax,[@@tx3]
149
	mov bx,[@@ty2]
149
	mov bx,[@@ty2]
150
	sub bx,[@@ty1]
150
	sub bx,[@@ty1]
151
	imul bx
151
	imul bx
152
	shl edx,16
152
	shl edx,16
153
	mov dx,ax
153
	mov dx,ax
154
	pop ebx
154
	pop ebx
155
	sub ebx,edx
155
	sub ebx,edx
156
	or ebx,ebx
156
	or ebx,ebx
157
	jge df_next
157
	jge df_next
158
 
158
 
159
	xor ah,ah
159
	xor ah,ah
160
	mov al,byte [si]
160
	mov al,byte [si]
161
	
161
	
162
 mov  [@@xcol],ax
162
 mov  [@@xcol],ax
163
 
163
 
164
	call filled_triangle
164
	call filled_triangle
165
df_next:
165
df_next:
166
	inc si
166
	inc si
167
	pop ecx
167
	pop ecx
168
	dec ecx
168
	dec ecx
169
	jnz df_draw
169
	jnz df_draw
170
	ret
170
	ret
171
 
171
 
172
;modify
172
;modify
173
;include graphlib.asm
173
;include graphlib.asm
174
 
174
 
175
clear_screen_buffer:
175
clear_screen_buffer:
176
 
176
 
177
;outscrbuf
177
;outscrbuf
178
 mov ebx,scrbuf
178
 mov ebx,scrbuf
179
 mov ecx,SCREEN_X*65536+SCREEN_Y
179
 mov ecx,SCREEN_X*65536+SCREEN_Y
180
 mov edx,5*65536+22
180
 mov edx,5*65536+22
181
 mov ax,7
181
 mov ax,7
182
 mcall
182
 mcall
183
 
183
 
184
;White background
184
;White background
185
 mov edi,scrbuf
185
 mov edi,scrbuf
186
 mov ecx,(SCREEN_X*SCREEN_Y*3)/4
186
 mov ecx,(SCREEN_X*SCREEN_Y*3)/4
187
 mov eax,0xffffffff
187
 mov eax,0xffffffff
188
 cld
188
 cld
189
 rep stosd
189
 rep stosd
190
 
190
 
191
	ret
191
	ret
192
 
192
 
193
;include triangle.asm
193
;include triangle.asm
194
; Mikolaj Felix 14/5/2001
194
; Mikolaj Felix 14/5/2001
195
; mfelix@polbox.com
195
; mfelix@polbox.com
196
 
196
 
197
;filled trangle procedure
197
;filled trangle procedure
198
 
198
 
199
@@tx1  dw 0
199
@@tx1  dw 0
200
@@ty1  dw 0
200
@@ty1  dw 0
201
@@tx2  dw 0
201
@@tx2  dw 0
202
@@ty2  dw 0
202
@@ty2  dw 0
203
@@tx3  dw 0
203
@@tx3  dw 0
204
@@ty3  dw 0
204
@@ty3  dw 0
205
@@xcol dw 0
205
@@xcol dw 0
206
 
206
 
207
@@dx12 dw 0
207
@@dx12 dw 0
208
@@dx13 dw 0
208
@@dx13 dw 0
209
@@dx23 dw 0
209
@@dx23 dw 0
210
 
210
 
211
filled_triangle:
211
filled_triangle:
212
 
212
 
213
 mov ax,[@@xcol]  ;trnsforming color
213
 mov ax,[@@xcol]  ;trnsforming color
214
 mov bl,al        ;byte bbbggrrx
214
 mov bl,al        ;byte bbbggrrx
215
 mov dl,al        ;to 3 byte
215
 mov dl,al        ;to 3 byte
216
 mov dh,al        ;bbbxxxxx ggxxxxxx rrxxxxxx
216
 mov dh,al        ;bbbxxxxx ggxxxxxx rrxxxxxx
217
 and dh,00000001b
217
 and dh,00000001b
218
 
218
 
219
 and al,11100000b
219
 and al,11100000b
220
 and bl,00011000b
220
 and bl,00011000b
221
 and dl,00000110b
221
 and dl,00000110b
222
 shl bl,3
222
 shl bl,3
223
 shl dl,5
223
 shl dl,5
224
 
224
 
225
 cmp dh,1
225
 cmp dh,1
226
 jne no_bitup
226
 jne no_bitup
227
 or  al,00011111b
227
 or  al,00011111b
228
 or  bl,00111111b
228
 or  bl,00111111b
229
 or  dl,00111111b
229
 or  dl,00111111b
230
no_bitup:
230
no_bitup:
231
 
231
 
232
 shl eax,8 ;puck colors
232
 shl eax,8 ;puck colors
233
 mov al,bl
233
 mov al,bl
234
 shl eax,8
234
 shl eax,8
235
 mov al,dl
235
 mov al,dl
236
 mov dword [@@rgb],eax
236
 mov dword [@@rgb],eax
237
 mov eax,0 ; for 16 bit instructions
237
 mov eax,0 ; for 16 bit instructions
238
 
238
 
239
	mov ax,[@@ty1]
239
	mov ax,[@@ty1]
240
	cmp ax,[@@ty3]
240
	cmp ax,[@@ty3]
241
	jb ft_check1
241
	jb ft_check1
242
 
242
 
243
	xchg ax,[@@ty3]
243
	xchg ax,[@@ty3]
244
	mov [@@ty1],ax
244
	mov [@@ty1],ax
245
 
245
 
246
	mov ax,[@@tx1]
246
	mov ax,[@@tx1]
247
	xchg ax,[@@tx3]
247
	xchg ax,[@@tx3]
248
	mov [@@tx1],ax
248
	mov [@@tx1],ax
249
ft_check1:
249
ft_check1:
250
	mov ax,[@@ty2]
250
	mov ax,[@@ty2]
251
	cmp ax,[@@ty3]
251
	cmp ax,[@@ty3]
252
	jb ft_check2
252
	jb ft_check2
253
 
253
 
254
	xchg ax,[@@ty3]
254
	xchg ax,[@@ty3]
255
	mov [@@ty2],ax
255
	mov [@@ty2],ax
256
 
256
 
257
	mov ax,[@@tx2]
257
	mov ax,[@@tx2]
258
	xchg ax,[@@tx3]
258
	xchg ax,[@@tx3]
259
	mov [@@tx2],ax
259
	mov [@@tx2],ax
260
ft_check2:
260
ft_check2:
261
	mov ax,[@@ty1]
261
	mov ax,[@@ty1]
262
	cmp ax,[@@ty2]
262
	cmp ax,[@@ty2]
263
	jb ft_check3
263
	jb ft_check3
264
 
264
 
265
	xchg ax,[@@ty2]
265
	xchg ax,[@@ty2]
266
	mov [@@ty1],ax
266
	mov [@@ty1],ax
267
 
267
 
268
	mov ax,[@@tx1]
268
	mov ax,[@@tx1]
269
	xchg ax,[@@tx2]
269
	xchg ax,[@@tx2]
270
	mov [@@tx1],ax
270
	mov [@@tx1],ax
271
ft_check3:
271
ft_check3:
272
 
272
 
273
	mov bx,[@@ty2]
273
	mov bx,[@@ty2]
274
	sub bx,[@@ty1]
274
	sub bx,[@@ty1]
275
	jnz ft_dx12_make
275
	jnz ft_dx12_make
276
 
276
 
277
	mov [@@dx12],word 0
277
	mov [@@dx12],word 0
278
	jmp ft_dx12_done
278
	jmp ft_dx12_done
279
ft_dx12_make:
279
ft_dx12_make:
280
	mov ax,[@@tx2]
280
	mov ax,[@@tx2]
281
	sub ax,[@@tx1]
281
	sub ax,[@@tx1]
282
	shl ax,7
282
	shl ax,7
283
	cwd
283
	cwd
284
	idiv bx
284
	idiv bx
285
	mov [@@dx12],ax			; dx12 = (x2-x1)/(y2-y1)
285
	mov [@@dx12],ax			; dx12 = (x2-x1)/(y2-y1)
286
ft_dx12_done:
286
ft_dx12_done:
287
 
287
 
288
	mov bx,[@@ty3]
288
	mov bx,[@@ty3]
289
	sub bx,[@@ty1]
289
	sub bx,[@@ty1]
290
	jnz ft_dx13_make
290
	jnz ft_dx13_make
291
 
291
 
292
	mov [@@dx13],word 0
292
	mov [@@dx13],word 0
293
	jmp ft_dx13_done
293
	jmp ft_dx13_done
294
ft_dx13_make:
294
ft_dx13_make:
295
	mov ax,[@@tx3]
295
	mov ax,[@@tx3]
296
	sub ax,[@@tx1]
296
	sub ax,[@@tx1]
297
	shl ax,7
297
	shl ax,7
298
	cwd
298
	cwd
299
	idiv bx
299
	idiv bx
300
	mov [@@dx13],ax			; dx13 = (x3-x1)/(y3-y1)
300
	mov [@@dx13],ax			; dx13 = (x3-x1)/(y3-y1)
301
ft_dx13_done:
301
ft_dx13_done:
302
 
302
 
303
	mov bx,[@@ty3]
303
	mov bx,[@@ty3]
304
	sub bx,[@@ty2]
304
	sub bx,[@@ty2]
305
	jnz ft_dx23_make
305
	jnz ft_dx23_make
306
 
306
 
307
	mov [@@dx23],word 0
307
	mov [@@dx23],word 0
308
	jmp ft_dx23_done
308
	jmp ft_dx23_done
309
ft_dx23_make:
309
ft_dx23_make:
310
	mov ax,[@@tx3]
310
	mov ax,[@@tx3]
311
	sub ax,[@@tx2]
311
	sub ax,[@@tx2]
312
	shl ax,7
312
	shl ax,7
313
	cwd
313
	cwd
314
	idiv bx
314
	idiv bx
315
	mov [@@dx23],ax			; dx23 = (x3-x2)/(y3-y2)
315
	mov [@@dx23],ax			; dx23 = (x3-x2)/(y3-y2)
316
ft_dx23_done:
316
ft_dx23_done:
317
 
317
 
318
	mov ax,[@@tx1]
318
	mov ax,[@@tx1]
319
	shl ax,7
319
	shl ax,7
320
	mov bx,ax
320
	mov bx,ax
321
 
321
 
322
	mov cx,[@@ty1]
322
	mov cx,[@@ty1]
323
ft_loop1:
323
ft_loop1:
324
 
324
 
325
 pushad
325
 pushad
326
 
326
 
327
	mov [@@ly],cx
327
	mov [@@ly],cx
328
	mov dx,bx
328
	mov dx,bx
329
	shr dx,7
329
	shr dx,7
330
	mov [@@lx2],dx
330
	mov [@@lx2],dx
331
	mov dx,ax
331
	mov dx,ax
332
	shr dx,7
332
	shr dx,7
333
	mov [@@lx1],dx
333
	mov [@@lx1],dx
334
	mov ax,[@@xcol]
334
	mov ax,[@@xcol]
335
 mov [@@lcol],ax
335
 mov [@@lcol],ax
336
 call horizontal_line
336
 call horizontal_line
337
 
337
 
338
 popad
338
 popad
339
 
339
 
340
	add ax,[@@dx13]
340
	add ax,[@@dx13]
341
	add bx,[@@dx12]
341
	add bx,[@@dx12]
342
	inc cx
342
	inc cx
343
	cmp cx,[@@ty2]
343
	cmp cx,[@@ty2]
344
	jb ft_loop1
344
	jb ft_loop1
345
 
345
 
346
	
346
	
347
	mov bx,[@@tx2]
347
	mov bx,[@@tx2]
348
	shl bx,7
348
	shl bx,7
349
	mov cx,[@@ty2]
349
	mov cx,[@@ty2]
350
ft_loop2:
350
ft_loop2:
351
 
351
 
352
 pushad
352
 pushad
353
 
353
 
354
	mov [@@ly],cx
354
	mov [@@ly],cx
355
	mov dx,bx
355
	mov dx,bx
356
	shr dx,7
356
	shr dx,7
357
	mov [@@lx2],dx
357
	mov [@@lx2],dx
358
	mov dx,ax
358
	mov dx,ax
359
	shr dx,7
359
	shr dx,7
360
	mov [@@lx1],dx
360
	mov [@@lx1],dx
361
 mov ax,[@@xcol]
361
 mov ax,[@@xcol]
362
 mov [@@lcol],ax
362
 mov [@@lcol],ax
363
	call horizontal_line
363
	call horizontal_line
364
 
364
 
365
 popad
365
 popad
366
 
366
 
367
	add ax,[@@dx13]
367
	add ax,[@@dx13]
368
	add bx,[@@dx23]
368
	add bx,[@@dx23]
369
	inc ecx
369
	inc ecx
370
	cmp cx,[@@ty3]
370
	cmp cx,[@@ty3]
371
	jb ft_loop2
371
	jb ft_loop2
372
 
372
 
373
	ret
373
	ret
374
 
374
 
375
;horizontal line subproc
375
;horizontal line subproc
376
 
376
 
377
@@lx1  dw 0
377
@@lx1  dw 0
378
@@lx2  dw 0
378
@@lx2  dw 0
379
@@ly   dw 0
379
@@ly   dw 0
380
@@lcol dw 0
380
@@lcol dw 0
381
 
381
 
382
@@rgb  dd 0
382
@@rgb  dd 0
383
 
383
 
384
horizontal_line:
384
horizontal_line:
385
 
385
 
386
 mov ecx,0
386
 mov ecx,0
387
 mov cx,[@@lx1]
387
 mov cx,[@@lx1]
388
 cmp cx,[@@lx2]
388
 cmp cx,[@@lx2]
389
 ja  x12
389
 ja  x12
390
 je  ext
390
 je  ext
391
; ret
391
; ret
392
 mov cx,[@@lx2]
392
 mov cx,[@@lx2]
393
 sub cx,[@@lx1]
393
 sub cx,[@@lx1]
394
 mov edi,3
394
 mov edi,3
395
 jmp xx
395
 jmp xx
396
x12:
396
x12:
397
 mov cx,[@@lx1]
397
 mov cx,[@@lx1]
398
 sub cx,[@@lx2]
398
 sub cx,[@@lx2]
399
 mov edi,-3
399
 mov edi,-3
400
 jmp xx
400
 jmp xx
401
ext:
401
ext:
402
 mov ecx,-1 ;1
402
 mov ecx,-1 ;1
403
; sub ebp,3
403
; sub ebp,3
404
xx:
404
xx:
405
 mov eax,0
405
 mov eax,0
406
 mov ax,[@@ly]
406
 mov ax,[@@ly]
407
 mov ebx,SCREEN_X ;320
407
 mov ebx,SCREEN_X ;320
408
 mul ebx
408
 mul ebx
409
 mov ebp,0
409
 mov ebp,0
410
 mov bp,[@@lx1] ;for correct 16 bit size
410
 mov bp,[@@lx1] ;for correct 16 bit size
411
 add eax,ebp
411
 add eax,ebp
412
 mov ebx,3
412
 mov ebx,3
413
 mul ebx
413
 mul ebx
414
 mov ebp,eax
414
 mov ebp,eax
415
 sub ebp,3   ;for delete  white dots
415
 sub ebp,3   ;for delete  white dots
416
 add ecx,2
416
 add ecx,2
417
loo:
417
loo:
418
 
418
 
419
 mov eax,dword [@@rgb]
419
 mov eax,dword [@@rgb]
420
 mov bl,al
420
 mov bl,al
421
 shr eax,8 ;puck colors
421
 shr eax,8 ;puck colors
422
 
422
 
423
 mov byte [scrbuf+ebp],ah
423
 mov byte [scrbuf+ebp],ah
424
 mov byte [scrbuf+ebp+1],al
424
 mov byte [scrbuf+ebp+1],al
425
 mov byte [scrbuf+ebp+2],bl
425
 mov byte [scrbuf+ebp+2],bl
426
 add ebp,edi
426
 add ebp,edi
427
 dec ecx
427
 dec ecx
428
 jnz loo
428
 jnz loo
429
 
429
 
430
	ret
430
	ret
431
 
431
 
432
;include fixed3d.asm
432
;include fixed3d.asm
433
; Mikolaj Felix 25/5/2001
433
; Mikolaj Felix 25/5/2001
434
; mfelix@polbox.com
434
; mfelix@polbox.com
435
 
435
 
436
;------------------------------------------------------------
436
;------------------------------------------------------------
437
;	ds:si	- offset to angles
437
;	ds:si	- offset to angles
438
;	ds:di	- offset to 3d points
438
;	ds:di	- offset to 3d points
439
;	cx	- number of points
439
;	cx	- number of points
440
;------------------------------------------------------------
440
;------------------------------------------------------------
441
 
441
 
442
@@sin_x dw 0
442
@@sin_x dw 0
443
@@cos_x dw 0
443
@@cos_x dw 0
444
@@sin_y dw 0
444
@@sin_y dw 0
445
@@cos_y dw 0
445
@@cos_y dw 0
446
@@sin_z dw 0
446
@@sin_z dw 0
447
@@cos_z dw 0
447
@@cos_z dw 0
448
 
448
 
449
@@px equ word [edi]
449
@@px equ word [edi]
450
@@py equ word [edi+2]
450
@@py equ word [edi+2]
451
@@pz equ word [edi+4]
451
@@pz equ word [edi+4]
452
 
452
 
453
rotate_points:
453
rotate_points:
454
 
454
 
455
 push edi
455
 push edi
456
	mov edi,@@sin_x
456
	mov edi,@@sin_x
457
	mov edx,3
457
	mov edx,3
458
rp_sin_cos:
458
rp_sin_cos:
459
	mov bx,word [esi]
459
	mov bx,word [esi]
460
	and bx,511
460
	and bx,511
461
	shl bx,1
461
	shl bx,1
462
	mov ax,word [sin_table+bx]
462
	mov ax,word [sin_table+bx]
463
	mov word [edi],ax
463
	mov word [edi],ax
464
	mov ax,word [cos_table+bx]
464
	mov ax,word [cos_table+bx]
465
	mov word [edi+2],ax
465
	mov word [edi+2],ax
466
 
466
 
467
	add esi,2
467
	add esi,2
468
	add edi,4
468
	add edi,4
469
	dec edx
469
	dec edx
470
	jnz rp_sin_cos
470
	jnz rp_sin_cos
471
	pop edi
471
	pop edi
472
 
472
 
473
rp_rotate:
473
rp_rotate:
474
 
474
 
475
	; rotate around x-axis
475
	; rotate around x-axis
476
 
476
 
477
	mov ax,@@py
477
	mov ax,@@py
478
	imul [@@cos_x]
478
	imul [@@cos_x]
479
	mov bx,ax
479
	mov bx,ax
480
	mov si,dx
480
	mov si,dx
481
 
481
 
482
	mov ax,@@pz
482
	mov ax,@@pz
483
	imul [@@sin_x]
483
	imul [@@sin_x]
484
	sub bx,ax
484
	sub bx,ax
485
	sbb si,dx
485
	sbb si,dx
486
	shrd bx,si,14
486
	shrd bx,si,14
487
	push bx
487
	push bx
488
 
488
 
489
	mov ax,@@py
489
	mov ax,@@py
490
	imul [@@sin_x]
490
	imul [@@sin_x]
491
	mov bx,ax
491
	mov bx,ax
492
	mov si,dx
492
	mov si,dx
493
 
493
 
494
	mov ax,@@pz
494
	mov ax,@@pz
495
	imul [@@cos_x]
495
	imul [@@cos_x]
496
	add bx,ax
496
	add bx,ax
497
	adc si,dx
497
	adc si,dx
498
	shrd bx,si,14
498
	shrd bx,si,14
499
 
499
 
500
	pop @@py
500
	pop @@py
501
	mov @@pz,bx
501
	mov @@pz,bx
502
 
502
 
503
	; rotate around y-axis
503
	; rotate around y-axis
504
 
504
 
505
	mov ax,@@px
505
	mov ax,@@px
506
	imul [@@cos_y]
506
	imul [@@cos_y]
507
	mov bx,ax
507
	mov bx,ax
508
	mov si,dx
508
	mov si,dx
509
 
509
 
510
	mov ax,@@pz
510
	mov ax,@@pz
511
	imul [@@sin_y]
511
	imul [@@sin_y]
512
	sub bx,ax
512
	sub bx,ax
513
	sbb si,dx
513
	sbb si,dx
514
	shrd bx,si,14
514
	shrd bx,si,14
515
	push bx
515
	push bx
516
 
516
 
517
	mov ax,@@px
517
	mov ax,@@px
518
	imul [@@sin_y]
518
	imul [@@sin_y]
519
	mov bx,ax
519
	mov bx,ax
520
	mov si,dx
520
	mov si,dx
521
 
521
 
522
	mov ax,@@pz
522
	mov ax,@@pz
523
	imul [@@cos_y]
523
	imul [@@cos_y]
524
	add bx,ax
524
	add bx,ax
525
	adc si,dx
525
	adc si,dx
526
	shrd bx,si,14
526
	shrd bx,si,14
527
 
527
 
528
	pop @@px
528
	pop @@px
529
	mov @@pz,bx
529
	mov @@pz,bx
530
 
530
 
531
	; rotate around z-axis
531
	; rotate around z-axis
532
 
532
 
533
	mov ax,@@px
533
	mov ax,@@px
534
	imul [@@cos_z]
534
	imul [@@cos_z]
535
	mov bx,ax
535
	mov bx,ax
536
	mov si,dx
536
	mov si,dx
537
 
537
 
538
	mov ax,@@py
538
	mov ax,@@py
539
	imul [@@sin_z]
539
	imul [@@sin_z]
540
	sub bx,ax
540
	sub bx,ax
541
	sbb si,dx
541
	sbb si,dx
542
	shrd bx,si,14
542
	shrd bx,si,14
543
	push bx
543
	push bx
544
 
544
 
545
	mov ax,@@px
545
	mov ax,@@px
546
	imul [@@sin_z]
546
	imul [@@sin_z]
547
	mov bx,ax
547
	mov bx,ax
548
	mov si,dx
548
	mov si,dx
549
 
549
 
550
	mov ax,@@py
550
	mov ax,@@py
551
	imul [@@cos_z]
551
	imul [@@cos_z]
552
	add bx,ax
552
	add bx,ax
553
	adc si,dx
553
	adc si,dx
554
	shrd bx,si,14
554
	shrd bx,si,14
555
 
555
 
556
	pop @@px
556
	pop @@px
557
	mov @@py,bx
557
	mov @@py,bx
558
 
558
 
559
	add edi,6
559
	add edi,6
560
	dec ecx
560
	dec ecx
561
	jnz rp_rotate
561
	jnz rp_rotate
562
 
562
 
563
	ret
563
	ret
564
 
564
 
565
;------------------------------------------------------------
565
;------------------------------------------------------------
566
;	ds:si	- offset to 3d points
566
;	ds:si	- offset to 3d points
567
;	es:di	- offset to 2d points
567
;	es:di	- offset to 2d points
568
;	cx	- number of points
568
;	cx	- number of points
569
;------------------------------------------------------------
569
;------------------------------------------------------------
570
 
570
 
571
 mx dw 0
571
 mx dw 0
572
 my dw 0
572
 my dw 0
573
 
573
 
574
translate_points:
574
translate_points:
575
 pushad
575
 pushad
576
 mov eax,37
576
 mov eax,37
577
 mov ebx,1
577
 mov ebx,1
578
 mcall
578
 mcall
579
 mov ebx,eax
579
 mov ebx,eax
580
 shr eax,16
580
 shr eax,16
581
 and ebx,0xffff
581
 and ebx,0xffff
582
 cmp ax,SCREEN_X
582
 cmp ax,SCREEN_X
583
 jna x_n
583
 jna x_n
584
 mov ax,0 ;SCREEN_X
584
 mov ax,0 ;SCREEN_X
585
x_n:
585
x_n:
586
 cmp bx,SCREEN_Y
586
 cmp bx,SCREEN_Y
587
 jna y_n
587
 jna y_n
588
 mov bx,0 ;SCREEN_Y
588
 mov bx,0 ;SCREEN_Y
589
y_n:
589
y_n:
590
 mov [mx],ax
590
 mov [mx],ax
591
 mov [my],bx
591
 mov [my],bx
592
 popad
592
 popad
593
 
593
 
594
 mov ebx,0  ;?
594
 mov ebx,0  ;?
595
	mov bx,word [esi+4]
595
	mov bx,word [esi+4]
596
 mov ax,[my]
596
 mov ax,[my]
597
 cmp ax,0
597
 cmp ax,0
598
 jng no_m
598
 jng no_m
599
 shl ax,3
599
 shl ax,3
600
 add bx,ax
600
 add bx,ax
601
no_m:
601
no_m:
602
 add bx,256  ; Z factor (zoom)
602
 add bx,256  ; Z factor (zoom)
603
 
603
 
604
 mov eax,0  ;?
604
 mov eax,0  ;?
605
	mov ax,word [esi]
605
	mov ax,word [esi]
606
	shl ax,8
606
	shl ax,8
607
	cwd
607
	cwd
608
	idiv bx; bx
608
	idiv bx; bx
609
	add ax,(SCREEN_X/2) ;160         ;X factor (center X)
609
	add ax,(SCREEN_X/2) ;160         ;X factor (center X)
610
	stosw
610
	stosw
611
 
611
 
612
 mov eax,0  ;?
612
 mov eax,0  ;?
613
	mov ax,word [esi+2]
613
	mov ax,word [esi+2]
614
	shl ax,8
614
	shl ax,8
615
	cwd
615
	cwd
616
	idiv bx
616
	idiv bx
617
	add ax,(SCREEN_Y/2) ;100         ;Y factor (center Y)
617
	add ax,(SCREEN_Y/2) ;100         ;Y factor (center Y)
618
	stosw
618
	stosw
619
 
619
 
620
	add esi,6
620
	add esi,6
621
	dec ecx
621
	dec ecx
622
	jnz translate_points
622
	jnz translate_points
623
	ret
623
	ret
624
 
624
 
625
init_sin_cos:
625
init_sin_cos:
626
	finit
626
	finit
627
	fldz
627
	fldz
628
	fstp [temp]
628
	fstp [temp]
629
	xor edi,edi
629
	xor edi,edi
630
	mov ecx,512
630
	mov ecx,512
631
isc_make:
631
isc_make:
632
	fld [temp]
632
	fld [temp]
633
	fld st0
633
	fld st0
634
	fld st0
634
	fld st0
635
	fsin
635
	fsin
636
	fmul [fixed_point_const]
636
	fmul [fixed_point_const]
637
	fistp word [sin_table+edi]
637
	fistp word [sin_table+edi]
638
	fcos
638
	fcos
639
	fmul [fixed_point_const]
639
	fmul [fixed_point_const]
640
	fistp word [cos_table+edi]
640
	fistp word [cos_table+edi]
641
 
641
 
642
	fadd [inc_angle]
642
	fadd [inc_angle]
643
	fstp [temp]
643
	fstp [temp]
644
 
644
 
645
	add edi,2
645
	add edi,2
646
	loop isc_make
646
	loop isc_make
647
	ret
647
	ret
648
 
648
 
649
temp dd 0
649
temp dd 0
650
 
650
 
651
fixed_point_const dd 16384.0
651
fixed_point_const dd 16384.0
652
inc_angle dd 0.01227184630309			; pi/256
652
inc_angle dd 0.01227184630309			; pi/256
653
 
653
 
654
angle_x dw 0
654
angle_x dw 0
655
angle_y dw 0
655
angle_y dw 0
656
angle_z dw 0
656
angle_z dw 0
657
 
657
 
658
object	dw -50,-50,-50, 50,-50,-50, 50,50,-50, -50,50,-50
658
object	dw -50,-50,-50, 50,-50,-50, 50,50,-50, -50,50,-50
659
      	dw -50,-50, 50, 50,-50, 50, 50,50, 50, -50,50, 50
659
      	dw -50,-50, 50, 50,-50, 50, 50,50, 50, -50,50, 50
660
 
660
 
661
link:
661
link:
662
 db  0,1,2,10000011b, 0,2,3,10000011b ;purpure   side
662
 db  0,1,2,10000011b, 0,2,3,10000011b ;purpure   side
663
 db  5,4,7,00000111b, 5,7,6,00000111b ;soft-red  side
663
 db  5,4,7,00000111b, 5,7,6,00000111b ;soft-red  side
664
 db  1,5,6,00011000b, 1,6,2,00011000b ;soft-lime side
664
 db  1,5,6,00011000b, 1,6,2,00011000b ;soft-lime side
665
 db  4,0,3,11100001b, 4,3,7,11100001b ;soft-blue side
665
 db  4,0,3,11100001b, 4,3,7,11100001b ;soft-blue side
666
 db  4,5,1,00011111b, 1,0,4,00011111b ;yellow    side
666
 db  4,5,1,00011111b, 1,0,4,00011111b ;yellow    side
667
 db  3,2,6,00000000b, 3,6,7,00000000b ;black     side
667
 db  3,2,6,00000000b, 3,6,7,00000000b ;black     side
668
 
668
 
669
sin_table:
669
sin_table:
670
rw 512
670
rw 512
671
cos_table:
671
cos_table:
672
rw 512
672
rw 512
673
 
673
 
674
object_rotated:
674
object_rotated:
675
rw MAX_POINTS*3
675
rw MAX_POINTS*3
676
object_translated:
676
object_translated:
677
rw MAX_POINTS*2
677
rw MAX_POINTS*2
678
 
678
 
679
scrbuf:
679
scrbuf:
680
I_END:
680
I_END: