-
Notifications
You must be signed in to change notification settings - Fork 122
/
Copy pathVEC.A
executable file
·1601 lines (1493 loc) · 27.4 KB
/
VEC.A
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
groupheader equ 2 ;bytes to add to group offset to get MEMBERS COUNT
globalshr equ 0 ;2
MAXCMD equ 10000 ;maximum num of commands done by docmd_dssi
ALIGN 4
curxpos dd ?
curypos dd ?
curzpos dd ?
curmatrix dw 9 dup(?)
tmpmatrix dw 9 dup(?)
dw 9 dup(?)
dw 9 dup(?)
ALIGN 4
objoffset dw ?
objsegment dw ?
PUBLIC _zadd
_zadd LABEL WORD
unused dw ?
getme dw ?
ALIGN 4
;rotate sins/coss
rxsin dw 0
rxcos dw 0
rysin dw 0
rycos dw 0
rzsin dw 0
rzcos dw 0
ALIGN 4
projxmul dd 256
projymul dd 256
projminz dd 256
projminzshr dw 8
projxadd dw 160
projyadd dw 80
addx dw 0
addy dw 0
addz dw 0
addshr dw 0
addy0 dw 0 ;temp shadow
;rotated point data
pointadd equ 32
pointshl equ 5
pointnum dw 0
ALIGN 4
cpoint dw 32 dup(16 dup(0))
MAXPOINT equ 512
point dw MAXPOINT dup(16 dup(0)) ;-,-,-,flags,PX,PY,-,-, ddX,ddY,ddZ,-,-
;+1 = out to right
;+2 = out to left
;+4 = out to up
;+8 = out to down
;+16 = behind the eye
;PX/PY=projected
;ddX/Y/Z are 32 bit for point vertices,
; but only 16 bits for normal vertices
pointend dw pointadd dup('!')
PX equ 0
PY equ 4
PZ equ 8
PPX equ 12
PPY equ 14 ;PPY must be just after PPX
PFL equ 16
PRX equ 18
PRY equ 20 ;PRY must be just after PRX
PRFL equ 22
PTX equ 24
PTY equ 26
totalhiddenflags dw 0
groupflags dw 0 ;of polygon group
objectflags dw 0 ;of current object
polynormal dw 0 ;tmp storage
ALIGN 2
pointlist dw 32 dup(0)
d3clipcut PROC NEAR
;save bp(invisible)/bx,si,di, return dx/ax
push si
mov cl,byte ptr ds:projminzshr
mov esi,dword ptr ds:point[bx+PZ]
mov edx,esi
sub esi,dword ptr ds:point[bp+PZ]
sub edx,ds:projminz
xor eax,eax
shr edx,1
rcr eax,1
cmp esi,edx
jle dcp23
div esi
mov esi,eax
dcp3: mov eax,dword ptr ds:point[bp+PX]
sub eax,dword ptr ds:point[bx+PX]
imul esi
shld edx,eax,1
mov eax,edx
add eax,dword ptr ds:point[bx+PX]
imul ds:projxmul
shrd eax,edx,cl
add ax,ds:projxadd
push ax
mov eax,dword ptr ds:point[bp+PY]
sub eax,dword ptr ds:point[bx+PY]
imul esi
shld edx,eax,1
mov eax,edx
add eax,dword ptr ds:point[bx+PY]
imul ds:projymul
shrd eax,edx,cl
add ax,ds:projyadd
pop dx
pop si
ret
dcp23: mov esi,16384
jmp dcp3
d3clipcut ENDP
ALIGN 2
lastindex dw 0
clipped dw 0
d3clip PROC NEAR
;ds:[si]=>points, bp=lastindex
push ds
mov ax,cs
mov ds,ax
mov ds:clipped,0
add bp,OFFSET pointlist
mov ds:lastindex,bp
mov si,OFFSET pointlist
mov di,OFFSET polyxy
;first dot
mov bp,ds:[si]
mov dl,-1 ;invisible
test ds:point[bp+PFL],16
jnz dcl5
mov dl,1 ;visible
mov eax,DWORD PTR ds:point[bp+PPX]
mov ds:[di],eax
add di,4
dcl5: add si,2
;other dots
dcl1: mov bx,ds:[si]
test ds:point[bx+PFL],16
jz dcl3
;invisible dot
cmp dl,-1
je dcl4 ;last was also invisible
mov ds:clipped,1
;last line was visible, cut
xchg bp,bx
call d3clipcut ;points bp/bx
xchg bp,bx
mov ds:[di],dx ;x
mov ds:[di+2],ax ;y
add di,4
mov dl,-1
jmp dcl4
dcl3: ;visible dot
cmp dl,1
je dcl6 ;last was also visible
;last line was invisible, cut
call d3clipcut ;points bp/bx
mov ds:[di],dx ;x
mov ds:[di+2],ax ;y
add di,4
mov dl,1
dcl6: cmp si,ds:lastindex
je dcl2
mov eax,DWORD PTR ds:point[bx+PPX]
mov ds:[di],eax
add di,4
dcl4: cmp si,ds:lastindex
je dcl2
add si,2
mov bp,bx
jmp dcl1
dcl2:
sub di,OFFSET polyxy
shr di,2
mov ds:polysides,di
mov ax,ds:clipped
pop ds
ret
d3clip ENDP
ALIGN 4
tmpesi dd ?
td3clipcut2 PROC NEAR
;save bp(invisible)/bx,si,di, return edx/eax/cx(=hiddenflags)
push si
mov cl,byte ptr ds:projminzshr
mov esi,dword ptr ds:point[bx+PZ]
mov eax,esi
sub esi,dword ptr ds:point[bp+PZ]
sub eax,ds:projminz
cdq
shl eax,14
div esi
mov esi,eax
dc1p3: mov ds:tmpesi,esi
;mov eax,16384
;sub eax,esi
;imul eax
;sar eax,14
;mov esi,16384
;sub esi,eax
;
mov ax,word ptr ds:point[bp+PTX]
sub ax,word ptr ds:point[bx+PTX]
cwde
imul esi
sar eax,14
add ax,word ptr ds:point[bx+PTX]
push ax ;X
mov ax,word ptr ds:point[bp+PTY]
sub ax,word ptr ds:point[bx+PTY]
cwde
imul esi
sar eax,14
add ax,word ptr ds:point[bx+PTY]
push ax ;Y
mov esi,ds:tmpesi
mov eax,dword ptr ds:point[bp+PX]
sub eax,dword ptr ds:point[bx+PX]
imul esi
sar eax,14
add eax,dword ptr ds:point[bx+PX]
imul ds:projxmul
shrd eax,edx,cl
add ax,ds:projxadd
push ax
mov eax,dword ptr ds:point[bp+PY]
sub eax,dword ptr ds:point[bx+PY]
imul esi
sar eax,14
add eax,dword ptr ds:point[bx+PY]
imul ds:projymul
shrd eax,edx,cl
add ax,ds:projyadd
pop dx
xor cx,cx
cmp dx,ds:WMINX
jnl dc1p41
or cl,1
dc1p41: cmp dx,ds:WMAXX
jng dc1p42
or cl,2
dc1p42: cmp ax,ds:WMINY
jnl dc1p43
or cl,4
dc1p43: cmp ax,ds:WMAXY
jnl dc1p44
or cl,8
dc1p44:
shl eax,16
mov ax,dx
pop dx
shl edx,16
pop dx
pop si
ret
td3clipcut2 ENDP
td3clip2 PROC NEAR
;ds:[si]=>points, bp=lastindex
push ds
mov ax,cs
mov ds,ax
mov ds:clipped,0
add bp,OFFSET pointlist
mov ds:lastindex,bp
mov si,OFFSET pointlist
mov di,OFFSET cpoint
;first dot
mov bp,ds:[si]
mov dl,-1 ;invisible
test ds:point[bp+PFL],16
jnz dc1l5
mov dl,1 ;visible
mov eax,DWORD PTR ds:point[bp+PPX]
mov ds:[di+PPX],eax
mov eax,DWORD PTR ds:point[bp+PTX]
mov ds:[di+PTX],eax
mov eax,DWORD PTR ds:point[bp+PZ]
mov ds:[di+PZ],eax
mov ax,ds:point[bp+PFL]
mov ds:[di+PFL],ax
add di,pointadd
dc1l5: add si,2
;other dots
dc1l1: mov bx,ds:[si]
test ds:point[bx+PFL],16
jz dc1l3
;invisible dot
cmp dl,-1
je dc1l4 ;last was also invisible
mov ds:clipped,1
;last line was visible, cut
xchg bp,bx
call td3clipcut2 ;points bp/bx
mov ds:[di+PPX],eax
mov ds:[di+PTX],edx
mov ds:[di+PFL],cx
mov eax,cs:projminz
mov ds:[di+PZ],eax
xchg bp,bx
add di,pointadd
mov dl,-1
jmp dc1l4
dc1l3: ;visible dot
cmp dl,1
je dc1l6 ;last was also visible
;last line was invisible, cut
call td3clipcut2 ;points bp/bx
mov ds:[di+PPX],eax
mov ds:[di+PTX],edx
mov ds:[di+PFL],cx
mov eax,cs:projminz
mov ds:[di+PZ],eax
add di,pointadd
mov dl,1
dc1l6: cmp si,ds:lastindex
je dc1l2
mov eax,DWORD PTR ds:point[bx+PPX]
mov ds:[di+PPX],eax
mov eax,DWORD PTR ds:point[bx+PZ]
mov ds:[di+PZ],eax
mov eax,DWORD PTR ds:point[bx+PTX]
mov ds:[di+PTX],eax
mov ax,ds:point[bx+PFL]
mov ds:[di+PFL],ax
add di,pointadd
dc1l4: cmp si,ds:lastindex
je dc1l2
add si,2
mov bp,bx
jmp dc1l1
dc1l2:
sub di,OFFSET cpoint
shr di,pointshl
mov ds:polysides,di
mov ax,ds:clipped
pop ds
ret
td3clip2 ENDP
td3loadbp PROC NEAR
mov eax,dword ptr ds:cpoint[bp+PPX]
mov ecx,dword ptr ds:cpoint[bp+PZ]
mov edx,dword ptr ds:cpoint[bp+PTX]
ret
td3loadbp ENDP
td3storebx PROC NEAR
mov ds:[di],eax
mov ds:[POLYTXY+di],edx
mov ds:[POLYZ+di],ecx
add di,4
ret
td3storebx ENDP
td3clipbx PROC NEAR
;bx=end to be clipped
;bp=other end
;return: eax=y/x
push si
push di
mov cx,16384 ;delta
mov si,ds:cpoint[bx+PFL]
td3k0: test si,1
jz td3k4
;x<minx
test ds:cpoint[bp+PFL],1
jnz td3k9
mov ax,ds:WMINX
mov di,ds:cpoint[bx+PPX]
sub ax,di
cwde
shl eax,14
neg di
add di,ds:cpoint[bp+PPX]
movsx edi,di
cdq
idiv edi
cmp ax,cx
jg td3k4
mov cx,ax
td3k4: test si,2
jz td3k2
;x>maxx
test ds:cpoint[bp+PFL],2
jnz td3k9
mov ax,ds:cpoint[bx+PPX]
mov di,ax
sub ax,ds:WMAXX
cwde
shl eax,14
sub di,ds:cpoint[bp+PPX]
movsx edi,di
cdq
idiv edi
cmp ax,cx
jg td3k2
mov cx,ax
td3k2: ;clip by cx (0..16383)
;X/Y
mov eax,dword ptr ds:cpoint[bp+PPX] ;end
mov esi,dword ptr ds:cpoint[bx+PPX] ;beg
sub ax,si
imul cx
shrd ax,dx,14
add ax,si ;x
rol eax,16
rol esi,16
sub ax,si
imul cx
shrd ax,dx,14
add ax,si ;y
rol eax,16 ;y/x
push eax
;Z
;find suitable texture function
mov eax,256
imul dword ptr ds:cpoint[bx+PZ]
idiv dword ptr ds:cpoint[bp+PZ]
mov si,-4
td3k8: add si,4
cmp fs:[si],ax
ja td3k8
mov si,fs:[si+2]
mov ax,cx
shr ax,5
shl ax,1
add si,ax
mov cx,fs:[si] ;si=0..511
mov eax,dword ptr ds:cpoint[bp+PZ] ;end
mov esi,dword ptr ds:cpoint[bx+PZ] ;beg
sub eax,esi
imul cx
shrd ax,dx,9
add eax,esi
push eax ;Z
;texture X/Y
mov eax,dword ptr ds:cpoint[bp+PTX] ;end
mov esi,dword ptr ds:cpoint[bx+PTX] ;beg
sub ax,si
imul cx
shrd ax,dx,9
add ax,si ;x
rol eax,16
rol esi,16
sub ax,si
imul cx
shrd ax,dx,9
add ax,si ;y
rol eax,16 ;y/x
pop ecx ;z
mov edx,eax ;txy
pop eax ;xy
;
pop di
pop si
clc
ret
td3k9: pop di
pop si
stc
ret
td3clipbx ENDP
td3clip PROC NEAR
push ds
mov fs,cs:depthseg
mov ax,cs
mov ds,ax
mov ds:clipped,0
mov bp,ds:polysides
shl bp,pointshl
mov ds:lastindex,bp
xor si,si
mov di,OFFSET polyxy
;BX=beg, BP=endp
;first dot
mov bp,si
td3l1: cmp si,ds:lastindex
jb td3l2
sub di,OFFSET polyxy
shr di,2
mov ds:polysides,di
pop ds
ret
td3l2: mov bx,bp
add si,pointadd
mov bp,si
cmp bp,ds:lastindex
jne td3l7
xor bp,bp
td3l7: mov ax,ds:cpoint[PFL+bx]
and ax,not (4+8)
mov dx,ds:cpoint[PFL+bp]
and dx,not (4+8)
cmp ax,0
je td3l5
cmp dx,0
je td3l4
;clip both ends
call td3clipbx
jc td3l91
call td3storebx
td3l91: xchg bx,bp
call td3clipbx
jc td3l92
call td3storebx
td3l92: xchg bx,bp
jmp td3l1
td3l4: cmp ax,0
je td3l5
;bf
call td3clipbx
jc td3l93
call td3storebx
td3l93: call td3loadbp
jc td3l94
call td3storebx
td3l94: jmp td3l1
td3l5: cmp dx,0
je td3l6
;ef
xchg bx,bp
call td3clipbx
jc td3l95
call td3storebx
td3l95: xchg bx,bp
jmp td3l1
td3l6: call td3loadbp
call td3storebx
jmp td3l1
td3clip ENDP
unify32 PROC NEAR
;returns: ax,bx,cx (vector length=256)
jmp uni1
uni2: sar eax,4
sar ebx,4
sar ecx,4
uni1: cmp eax,16000
jg uni2
cmp eax,-16000
jl uni2
cmp ebx,16000
jg uni2
cmp ebx,-16000
jl uni2
cmp ecx,16000
jg uni2
cmp ecx,-16000
jl uni2
;
push ax
push bx
push cx
imul eax
mov edi,eax
mov eax,ebx
imul eax
add edi,eax
mov eax,ecx
imul eax
add edi,eax
mov si,di
shr edi,16
call longsqrt
cmp ax,0
je uni3
mov si,ax
;
pop ax
cwd
shld dx,ax,8
shl ax,8
idiv si
mov cx,ax
;
pop ax
cwd
shld dx,ax,8
shl ax,8
idiv si
mov bx,ax
;
pop ax
cwd
shld dx,ax,8
shl ax,8
idiv si
;
ret
uni3: xor ax,ax
xor bx,bx
xor cx,cx
ret
unify32 ENDP
ALIGN 2
public _testflash,_testflasho,_testflashgo,_testflashpnt
_testflash dw 0
_testflasho dw 0
_testflashgo dw 0
_testflashpnt dw 0,0
testflashc dw 0
flashgo dw 0
flashgo0 dw 0
flasher db 0
checkdeg MACRO reg
local l0,l1,l2
l0: cmp reg,3600
jb l1
jl l2
;>3600
sub reg,3600
jmp l0
l2: ;<0
add reg,3600
jmp l0
l1: ENDM
ALIGN 4
rotatedx dd ?
rotatedy dd ?
rotatedz dd ?
rotateposition PROC NEAR
mov eax,ds:[si+0]
movsx ecx,word ptr cs:[di+0]
imul ecx
shld edx,eax,17
mov ebx,edx
mov eax,ds:[si+4]
movsx ecx,word ptr cs:[di+2]
imul ecx
shld edx,eax,17
add ebx,edx
mov eax,ds:[si+8]
movsx ecx,word ptr cs:[di+4]
imul ecx
shld edx,eax,17
add ebx,edx
mov cs:rotatedx,ebx
mov eax,ds:[si+0]
movsx ecx,word ptr cs:[di+6]
imul ecx
shld edx,eax,17
mov ebx,edx
mov eax,ds:[si+4]
movsx ecx,word ptr cs:[di+8]
imul ecx
shld edx,eax,17
add ebx,edx
mov eax,ds:[si+8]
movsx ecx,word ptr cs:[di+10]
imul ecx
shld edx,eax,17
add ebx,edx
mov cs:rotatedy,ebx
mov eax,ds:[si+0]
movsx ecx,word ptr cs:[di+12]
imul ecx
shld edx,eax,17
mov ebx,edx
mov eax,ds:[si+4]
movsx ecx,word ptr cs:[di+14]
imul ecx
shld edx,eax,17
add ebx,edx
mov eax,ds:[si+8]
movsx ecx,word ptr cs:[di+16]
imul ecx
shld edx,eax,17
add ebx,edx
mov cs:rotatedz,ebx
ret
rotateposition ENDP
objadd LABEL WORD
dw 0
dw -1000
dw 10000
objrot LABEL WORD
dw 0
dw 0
dw 0
ALIGN 4
zorder dw 64 dup(0,0)
;****NRS****
nxpos dd ?
nypos dd ?
nzpos dd ?
;shadow
nxspos dd ?
nyspos dd ?
nzspos dd ?
PUBLIC _cammatrix
_cammatrix dw 9 dup(?)
dw 9 dup(?) ;reverse cammatrix
nmatrix dw 9 dup(?)
np0 dw ? ;first point number under this node
npn0 dw ? ;first normal number under this node
noflags dw 0
tmprotx dw ?
tmproty dw ?
tmprotz dw ?
shadow db 0 ;flag for drawing
dofirstnrs PROC NEAR
mov ax,cs
mov ds,ax
;
cmp dword ptr ds:_tmpxyz[0],-200000000
je notrack
mov ax,asm_objs
mov es,ax
mov si,OFFSET _camera
mov di,OFFSET _tmpxyz
call trackcam
mov ds:_camera[18],bx
mov ds:_camera[20],ax
notrack:
;initial rotate matrix
mov ax,ds:_camera[18]
mov ds:tmprotx,ax
mov ax,ds:_camera[20]
mov ds:tmproty,ax
mov ax,ds:_camera[22]
mov ds:tmprotz,ax
;calc XYZ rot
mov si,OFFSET tmprotx
mov di,OFFSET tmpmatrix
call calcmatrixsep ;ds:si=src(rx,ry,rz), ds:di=dest[3 matrices]
mov ax,cs
mov es,ax
mov si,OFFSET tmpmatrix+1*18
mov di,OFFSET tmpmatrix+0*18
call mulmatrices ;Y*=X
mov si,OFFSET tmpmatrix+1*18
mov di,OFFSET tmpmatrix+2*18
call mulmatrices ;Y*=Z
mov si,OFFSET tmpmatrix+1*18
mov cx,9
xor bx,bx
ccam2: mov ax,cs:[si+bx]
mov cs:_cammatrix[bx+9*2],ax
add bx,2
loop ccam2
;
neg ds:tmprotx
neg ds:tmproty
neg ds:tmprotz
mov si,OFFSET tmprotx
mov di,OFFSET tmpmatrix
call calcmatrixsep ;ds:si=src(rx,ry,rz), ds:di=dest[3 matrices]
;multiply to get: Z*X*Y
mov ax,cs
mov es,ax
mov si,OFFSET tmpmatrix+2*18
mov di,OFFSET tmpmatrix+0*18
call mulmatrices ;Z*=X
mov si,OFFSET tmpmatrix+2*18
mov di,OFFSET tmpmatrix+1*18
call mulmatrices ;Z*=Y
;move the result to nmatrix
mov si,OFFSET tmpmatrix+2*18
mov cx,9
xor bx,bx
ccam1: mov ax,cs:[si+bx]
mov cs:nmatrix[bx],ax
mov cs:_cammatrix[bx],ax
add bx,2
loop ccam1
;calc initial camera rotation
mov eax,dword ptr ds:_camera[0]
neg eax
mov ds:nxpos,eax
mov eax,dword ptr ds:_camera[4]
neg eax
mov ds:nypos,eax
mov eax,dword ptr ds:_camera[8]
neg eax
mov ds:nzpos,eax
mov si,OFFSET nxpos
mov di,OFFSET nmatrix
call rotateposition ;si=>rotatedx,y,z
mov ebx,ds:rotatedx
mov ecx,ds:rotatedy
mov edx,ds:rotatedz
mov ds:nxpos,ebx
mov ds:nypos,ecx
mov ds:nzpos,edx
mov ds:nxspos,ebx
mov ds:nyspos,ecx
mov ds:nzspos,edx
; mov ds:addy0,cx ;for temp shadow
mov ds:noflags,0
;init OBJD list pointers
mov cs:oopnt,OFFSET objdoffs
mov cs:odpnt,OFFSET objdarea
;calc horizon
cmp cs:_horizonenabled,0
je nohorz
call calchorizon
call drawhorizon
nohorz: ;do world
mov ax,asm_objs
mov ds,ax
mov si,OFFSET _worldroot
call donrsnode
ret
dofirstnrs ENDP
ALIGN 2
newlight dw 9460,9460,9460
normallight PROC NEAR
;ds=cs
;bx=normal vertex number (preshifted by pointshl)
;ret: ax=relative brightness 0..255
mov ax,cs
mov ds,ax
mov ax,ds:point[bx+PX]
imul ds:newlight[0]
mov bp,ax
mov cx,dx
mov ax,ds:point[bx+PY]
imul ds:newlight[2]
add bp,ax
adc cx,dx
mov ax,ds:point[bx+PZ]
imul ds:newlight[4]
add bp,ax
adc cx,dx
shld cx,bp,2
mov ax,cx
sar ax,7
add ax,128
;ax=0..255
ret
normallight ENDP
checknormalhidden PROC NEAR
;ds=cs
;bx=normal vertex number,di=vertex number from tested polygon
;^both above should be preshifted by pointshl
;ret: carry=1=hidden
mov eax,dword ptr ds:point[di+PX]
movsx edx,word ptr ds:point[bx+PX]
imul edx
mov ebp,eax
mov ecx,edx
mov eax,dword ptr ds:point[di+PY]
movsx edx,word ptr ds:point[bx+PY]
imul edx
add ebp,eax
adc ecx,edx
mov eax,dword ptr ds:point[di+PZ]
movsx edx,word ptr ds:point[bx+PZ]
imul edx
add ebp,eax
adc ecx,edx
rcl ecx,1 ;if cx<0, carry=1=visible
cmc ;now carry=1 when invisible
ret
checknormalhidden ENDP
ALIGN 4
_texturexy LABEL DWORD
dd 00000000h,0000003fh,003f003fh,003f0000h
dd 00000000h,0000003fh,003f003fh,003f0000h
dd 00000000h,0000003fh,003f003fh,003f0000h
dd 00000000h,0000003fh,003f003fh,003f0000h
nrs_poly PROC NEAR
test cs:noflags,1
jnz nrsnewpoly
mov si,OFFSET m_oldpoly
jmp fatalexit
nrsnewpoly: ;new polys are created by OC, so some user features done by OC
;are disabled for (minimum :-) speed gains.
sub si,2 ;point si to command
push si
;single polygon
mov ax,ds:[si+4]
mov cs:color,ax
mov ax,ds:[si+0]
and ah,not 1
mov byte ptr cs:groupflags,ah ;+2=always show, +4=texture, +8=dim
mov cl,al
xor ch,ch ;cx=sides
mov byte ptr cs:polysides,cl
mov ax,ds:[si+2] ;normal
mov cs:polynormal,ax
add si,6
;normal vector selfhidden? (for dot/line, always visible flag should be on)
test byte ptr cs:groupflags,2
jnz nrp15
mov di,ds:[si]
push ds
mov ax,cs
mov ds,ax
mov bx,ds:polynormal
shl bx,pointshl
shl di,pointshl
push cx
call checknormalhidden
pop cx ;cx=polysides
jc nrp19 ;hidden by culling (pop ds also at nrp19)
pop ds
nrp15: mov di,OFFSET polyxy
xor bp,bp
mov dx,0ff00h
nrp4: mov bx,ds:[si]
shl bx,pointshl
mov cs:pointlist[bp],bx
add bp,2
mov al,byte ptr cs:point[bx+PFL]
and dh,al
or dl,al
mov eax,DWORD PTR cs:point[bx+PPX]
mov cs:[di],eax
add di,4
add si,2
loop nrp4
test cs:groupflags,4
jz nrp9
;texture
push dx
add si,2 ;pic segment
mov cx,cs:polysides
xor di,di
nrpt1: mov dx,ds:[si]
movzx ax,dh
shl eax,16
movzx ax,dl
mov bx,cs:pointlist[di]
;shl eax,5
add si,2
mov dword ptr cs:point[bx+PTX],eax
shl di,1
mov dword ptr cs:polyxy[POLYTXY+di],eax
mov eax,dword ptr cs:point[bx+PZ]
mov dword ptr cs:polyxy[POLYZ+di],eax
shr di,1
add di,2
loop nrpt1
pop dx