Subversion Repositories Kolibri OS

Rev

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

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