Subversion Repositories Kolibri OS

Rev

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

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