-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTEST.ASM
1186 lines (1013 loc) · 23 KB
/
TEST.ASM
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
; 3dtest.c
;
; 19.2.1996 Marko Aalto, [email protected]
;
; *CR* == Can Remove
;
; Something to remove or simplify
; o Simple polygon centers, take just the first point
;
NPOINT equ 128
NPOLY equ 256
REAL_NPOLY equ 256
NSHADE equ 64
MASK_SHADE equ (NSHADE-1)
FP_SHADE equ 6
PAL_START_SHADE equ 16
SIZE_POLY equ 4
SIZE_VECTOR equ (3 * 4)
SIZE_MATRIX equ (3 * SIZE_VECTOR)
SCR_W equ 320
SCR_H equ 200
MID_X equ (SCR_W/2)
MID_Y equ (SCR_H/2)
D equ 8
SPD equ (VEC_FP1)
BG_PATTERN equ 0; 1010101h
GOURAD equ 1
NO_SIMPLE_CENTER equ 1
;DEBUG_CONTROL equ 1
; A = 15 degrees
IFDEF DEBUG_CONTROL
SIN_A equ 16962
SIN_A_NEG equ -16962
COS_A equ 63303
COS_A_NEG equ 63303
ELSE
SIN_A equ 4572
COS_A equ 65376
SIN_A2 equ 10252
COS_A2 equ 64729
SIN_A3 equ 12505
COS_A3 equ 64332
ENDIF
INTRO SEGMENT
ASSUME CS:INTRO,DS:INTRO ;Tell assembler about conditions at entry
ORG 100H ;A .COM program begins with 100H byte prefix
MAIN: ;Control must start here
.386
.387
;=====================================================================
;
; Main, execution starts here
;
;=====================================================================
mov ax, ds
add ax, 4100
mov screen_seg, ax ; Virtaul screen/buffer
mov es, ax ; ES points to virtual screen buffer
mov ax, 13h ; Videomode 320x200 256
int 10h
IFNDEF VEC_USE_FPU
call vec_sqrt_init
ENDIF
push es
push ds
pop es
mov ax, 0
cld
mov cx, NPOINT*3*4 + NPOINT*2
lea di, obj_point_n
rep stosb
pop es
lea si, mat_unit
lea di, obj_base
call mat_copy
call obj_calc_poly_orig_normals
call obj_calc_point_normals
call obj_calc_poly_centers
mov bx, NSHADE
mov edi, 0+PAL_START_SHADE ; EAX = BBGGRRCC
mov esi, 0+PAL_START_SHADE+NSHADE ; EAX = BBGGRRCC
LColor0:
mov eax, edi
call palette
mov eax, esi
call palette
add edi, 1010101h
add esi, 1000101h
dec bx
ja LColor0
FrameLoop:
;---------------------------------------------------------------------
call wait_sync
IFDEF DEBUG_CONTROL
mov cx, 0
mov eax, 0FFFFFFh
call palette
ENDIF
call clear_screen
call obj_draw
IFDEF DEBUG_CONTROL
mov cx, 0
xor eax, eax
call palette
ENDIF
call update_screen
mov ah, 1 ; Check if key pressed
int 16h
jz NoKeyPress ; No key pressed
xor ax, ax ; GetKey
int 16h
mov key, al
cmp al, 27
jz exit_to_dos
IFDEF DEBUG_CONTROL
lea di, obj_pos
cmp key, '8'
jnz KeyNot8
add dword ptr [di+8], SPD
KeyNot8:
cmp key, '2'
jnz KeyNot2
sub dword ptr [di+8], SPD
KeyNot2:
cmp key, '4'
jnz KeyNot4
sub dword ptr [di], SPD
KeyNot4:
cmp key, '6'
jnz KeyNot6
add dword ptr [di], SPD
KeyNot6:
cmp key, '7'
jnz KeyNot7
add dword ptr [di+4], SPD
KeyNot7:
cmp key, '1'
jnz KeyNot1
sub dword ptr [di+4], SPD
KeyNot1:
cmp key, '9'
jnz KeyNot9
mov ecx, COS_A
mov edx, SIN_A
call rotate_x
KeyNot9:
cmp key, '3'
jnz KeyNot3
mov ecx, COS_A_NEG
mov edx, SIN_A_NEG
call rotate_x
KeyNot3:
cmp key, 'q'
jnz KeyNotq
mov ecx, COS_A
mov edx, SIN_A
call rotate_z
KeyNotq:
cmp key, 'e'
jnz KeyNote
mov ecx, COS_A_NEG
mov edx, SIN_A_NEG
call rotate_z
KeyNote:
cmp key, 'w'
jnz KeyNotw
mov ecx, COS_A
mov edx, SIN_A
call rotate_y
KeyNotw:
cmp key, 's'
jnz KeyNots
mov ecx, COS_A_NEG
mov edx, SIN_A_NEG
call rotate_y
KeyNots:
NoKeyPress:
ELSE
NoKeyPress:
mov ecx, COS_A
mov edx, SIN_A
call rotate_z
mov ecx, COS_A2
mov edx, SIN_A2
call rotate_y
mov ecx, COS_A
mov edx, SIN_A
call rotate_x
ENDIF
jmp FrameLoop
exit_to_dos:
mov ax, 3
int 10h
ret
;---------------------
; INCLUDES
;---------------------
IFDEF DEBUG_CONTROL
include common.inc
ENDIF
include vector.inc
rotate_x PROC NEAR
;---------------------------------------------------------------------
; Rotates object around X axis.
; ECX = COS, EDX = SIN
; | 1, 0, 0 |
; | 0, COS, SIN |
; | 0, -SIN, COS |
;---------------------------------------------------------------------
; pushad
lea si, mat_unit
lea di, mat_rot
call mat_copy
mov [di+4*4], ecx
mov [di+5*4], edx
neg edx
mov [di+7*4], edx
mov [di+8*4], ecx
call rot_obj_base
; popad
ret
ENDP
rotate_y PROC NEAR
;---------------------------------------------------------------------
; Rotates object around Y axis.
; ECX = COS, EDX = SIN
; | COS, 0, -SIN |
; | 0, 1, 0 |
; | SIN, 0, COS |
;---------------------------------------------------------------------
; pushad
lea si, mat_unit
lea di, mat_rot
call mat_copy
mov [di+0*4], ecx
mov [di+6*4], edx
neg edx
mov [di+2*4], edx
mov [di+8*4], ecx
call rot_obj_base
; popad
ret
ENDP
rotate_z PROC NEAR
;---------------------------------------------------------------------
; Rotates object around Z axis.
; ECX = COS, EDX = SIN
; | COS, SIN, 0 |
; | -SIN, COS, 0 |
; | 0, 0, 1 |
;---------------------------------------------------------------------
; pushad
lea si, mat_unit
lea di, mat_rot
call mat_copy
mov [di+0*4], ecx
mov [di+1*4], edx
neg edx
mov [di+3*4], edx
mov [di+4*4], ecx
call rot_obj_base
; popad
ret
ENDP
rot_obj_base PROC NEAR
;---------------------------------------------------------------------
; Rotates matrix obj_base by matrix mat_rot
;---------------------------------------------------------------------
lea si, mat_rot
lea bp, obj_base
lea di, mat_c
call mat_matrix_mul
lea si, mat_c
lea di, obj_base
call mat_copy
ret
ENDP
obj_transform PROC NEAR
;---------------------------------------------------------------------
; Transform object's points to View Space (camera space)
;---------------------------------------------------------------------
; Traverser points backwards...
mov bx, NPOINT * SIZE_VECTOR - SIZE_VECTOR
Lot:
lea si, obj_base
lea bp, obj_points + bx
lea di, obj_viewpts + bx
call vec_matrix_mul
lea si, obj_pos
mov bp, di ; lea bp, obj_viewpts + bx
; lea di, obj_viewpts + bx
call vec_add
sub bx, SIZE_VECTOR
jge Lot
ret
ENDP
init_intensities_calc PROC NEAR
;---------------------------------------------------------------------
; Inits base vectors for and loops registers in:
; obj_calc_point_intensities
; obj_calc_intensities
; Dont use anywhere else.
;---------------------------------------------------------------------
lea si, vec_orig_eye
lea bp, obj_pos
lea di, vec_a
call vec_sub
lea si, obj_base
call mat_transpose
; lea si, obj_base
mov bp, di ; lea bp, vec_a
lea di, vec_eye
call vec_matrix_mul
; lea si, obj_base
call mat_transpose
ret
ENDP
obj_calc_intensities PROC NEAR
;---------------------------------------------------------------------
; Calculates intensities of objects's polygons
;---------------------------------------------------------------------
call init_intensities_calc
mov bx, NPOLY * SIZE_POLY - SIZE_POLY
lea si, obj_poly_c + NPOLY*SIZE_VECTOR - SIZE_VECTOR
Loci:
lea bp, vec_eye
lea di, vec_a
call vec_sub
IFDEF GOURAD
mov bp, di ; lea bp, vec_a
ELSE
push si
lea si, vec_a
call vec_normalize
mov bp, si ; lea bp, vec_a
pop si
ENDIF
push si
add si, offset obj_poly_on - offset obj_poly_c
call vec_smul
pop si
mov [bx + obj_poly_i], eax
sub si, SIZE_VECTOR
sub bx, SIZE_POLY
jge Loci
ret
ENDP
obj_calc_point_intensities PROC NEAR
;---------------------------------------------------------------------
; Calculates intensities of objects's points
;---------------------------------------------------------------------
call init_intensities_calc
mov bx, NPOINT*4 - 4
lea si, obj_points + NPOINT*SIZE_VECTOR - SIZE_VECTOR
Locpi:
lea bp, vec_eye
lea di, vec_a
call vec_sub
push si
lea si, vec_a
call vec_normalize
pop si
push si
add si, offset obj_point_n - obj_points
lea bp, vec_a
call vec_smul
pop si
cmp eax, 0
jge PositiveEax
neg eax
PositiveEax:
mov [bx + obj_point_i], eax
sub si, SIZE_VECTOR
sub bx, 4
jge Locpi
ret
ENDP
obj_calc_poly_centers PROC NEAR
;---------------------------------------------------------------------
; Calculates center vectors of polygons
;---------------------------------------------------------------------
; Traverse polys bacwards
mov bx, NPOLY*SIZE_POLY - SIZE_POLY
Locpc:
IFDEF NO_SIMPLE_CENTER
mov dx, 2*256+12 ; Multiplies, dont touch DX afterwads !
mov al, [bx + obj_polys]
mul dl ; SI = AX * 12
lea si, obj_points
add si, ax
lea di, vec_a
call vec_copy
; mov dh, 2
LoopDoCenter:
mov al, [bx + obj_polys + 1]
mul dl ; SI = AX * 12
lea si, obj_points
add si, ax
call vec_add
sar dword ptr [di], 1
sar dword ptr [di+4], 1
sar dword ptr [di+8], 1
inc bx
dec dh
jnz LoopDoCenter
sub bx, 2
mov si, di ; lea si, vec_a
lea di, bx + obj_poly_c
add di, bx
add di, bx
call vec_copy
ELSE
mov dl, 12
mov al, [bx + obj_polys]
mul dl ; SI = AX * 12
lea si, obj_points
add si, ax
lea di, bx + obj_poly_c
add di, bx
add di, bx
call vec_copy
ENDIF
sub bx, SIZE_POLY
jge Locpc
ret
ENDP
project_div PROC NEAR
;---------------------------------------------------------------------
; Helper function used by
; obj_project
; Dont use elsewhere!
;---------------------------------------------------------------------
cdq
shld edx, eax, D
sal eax, D
idiv dword ptr [si+bx+8]
ret
ENDP
obj_project PROC NEAR
;---------------------------------------------------------------------
; Project object's VS points to Screen Space
;---------------------------------------------------------------------
mov bx, NPOINT*4 - 4
Lop:
lea si, bx + obj_viewpts
add si, bx
mov eax, [si+bx] ; X
call project_div
add ax, MID_X
mov [obj_scrpts+bx], ax
mov eax, [si+bx+4] ; Y
call project_div
neg ax ; *CR*
add ax, MID_Y
mov [obj_scrpts+bx+2], ax
sub bx, 4
jge Lop
ret
ENDP
obj_draw PROC NEAR
;---------------------------------------------------------------------
; Draw object on the screen
;---------------------------------------------------------------------
call obj_transform
call obj_project
IFDEF GOURAD
call obj_calc_point_intensities
call obj_calc_intensities ; Visibility of polygons
ELSE
call obj_calc_intensities
ENDIF
call obj_calc_poly_dist
call obj_draw_polys
ret
ENDP
obj_calc_poly_orig_normals PROC NEAR
;---------------------------------------------------------------------
; Calculates orignal normals (object space) for all polygons
;---------------------------------------------------------------------
mov cx, NPOLY
mov bx, 0
Locpon:
mov dl, 12 ; Multiplier
lea di, bx + obj_polys
mov al, [di+1]
mul dl ; AX = AX * 12
add ax, offset obj_points
push ax
mov si, ax
mov al, [di]
mul dl
add ax, offset obj_points
mov bp, ax
push di
lea di, mat_c
call vec_sub
pop di
; lea di, bx + obj_polys
mov al, [di+2]
mul dl
mov si, ax
add si, offset obj_points
pop bp
lea di, mat_c + SIZE_VECTOR
call vec_sub
mov bp, di ; lea bp, mat_c + SIZE_VECTOR
lea di, bx + obj_poly_on
add di, bx
add di, bx
lea si, mat_c
call vec_dmul
mov si, di
call vec_normalize
add bx, SIZE_POLY
loop Locpon
ret
ENDP
obj_calc_point_normals PROC NEAR
;---------------------------------------------------------------------
; Calculates orignal normals (object space) for all points
;---------------------------------------------------------------------
mov cx, REAL_NPOLY
mov bx, 0
Locpn0:
lea si, bx + obj_poly_on
add si, bx
add si, bx
mov dx, 3
LoopPolyPoints:
xor ax, ax
mov al, [bx + obj_polys]
mov di, ax
add di, di
inc [di + obj_point_hits]
sal ax, 2
sal di, 2
add di, ax
add di, offset obj_point_n
mov bp, di
call vec_add
inc bx
dec dx
jnz LoopPolyPoints
inc bx
; add bx, SIZE_POLY
loop Locpn0
mov cx, NPOINT
lea di, obj_point_hits
lea si, obj_point_n
Locpn1:
mov ax, [di]
cwde
mov ebx, eax ; EBX = jakaja, # of hits
mov eax, [si]
cdq
idiv ebx
mov [si], eax
mov eax, [si+4]
cdq
idiv ebx
mov [si+4], eax
mov eax, [si+8]
cdq
idiv ebx
mov [si+8], eax
add di, 2
add si, SIZE_VECTOR
loop Locpn1
ret
ENDP
obj_draw_polygon PROC NEAR
;---------------------------------------------------------------------
; Draws a polygon pointed by DI
;---------------------------------------------------------------------
; pushad
lea si, obj_scrpts
xor bx, bx
mov bl, [di]
sal bx, 2
mov eax, [si+bx]
mov dword ptr p1, eax
IFDEF GOURAD
mov eax, [bx + obj_point_i]
mov dword ptr i1, eax
ENDIF
xor bx, bx
mov bl, [di+1]
sal bx, 2
mov eax, [si+bx]
mov dword ptr p2, eax
IFDEF GOURAD
mov eax, [bx + obj_point_i]
mov dword ptr i2, eax
ENDIF
xor bx, bx
mov bl, [di+2]
sal bx, 2
mov eax, [si+bx]
mov dword ptr p3, eax
IFDEF GOURAD
mov eax, [bx + obj_point_i]
mov dword ptr i3, eax
ENDIF
xor bx, bx
mov bl, [di+3]
sal bx, FP_SHADE
IFDEF GOURAD
add bx, PAL_START_SHADE
mov pcolor, bx
ELSE
; Get intensity value
mov eax, dword ptr [di + offset obj_poly_i - offset obj_polys]
neg eax
sar eax, VEC_FP-FP_SHADE
add ax, PAL_START_SHADE
add ax, bx
mov pcolor, ax
ENDIF
call draw_poly
; popad
ret
ENDP
obj_calc_poly_dist PROC NEAR
;---------------------------------------------------------------------
; Calculates distance (Z coord) of all polys
;---------------------------------------------------------------------
lea si, obj_polys
Lcpd:
; If poly not visible make dist negative (POLYSIZE=4=DWORD)
cmp dword ptr [si + offset obj_poly_i-offset obj_polys], 0
jl LcpdPolyVis
mov eax, -20*VEC_FP1
jmp LcpdContinue
LcpdPolyVis:
; Simple poly distance, just take the 1st point
mov dl, 12
mov al, [si]
mul dl
mov bx, ax
mov eax, [bx + 8 + offset obj_viewpts]
LcpdContinue:
mov [si + offset obj_poly_z - offset obj_polys], eax
add si, SIZE_POLY
cmp si, offset obj_polys + NPOLY*SIZE_POLY
jl Lcpd
ret
ENDP
obj_draw_polys PROC NEAR
;---------------------------------------------------------------------
; Sorts polygons into back to front order (Painter's algorithm)
; and draws them.
;---------------------------------------------------------------------
Lsp:
lea si, obj_poly_z
mov eax, [si]
mov di, si
LspSearch:
cmp eax, [si]
jg LNext
mov eax, [si]
mov di, si
LNext:
add si, 4
cmp si, offset obj_poly_z + NPOLY*4
jl LspSearch
; Now EAX has the max Z, and DI points to it
cmp eax, 0
jl LspOver ; Was this last poly positive ?
; mov [di], -1000*VEC_FP1 ; Make Z negative, so it will be skipped later
neg dword ptr [di]
LPolyVisible:
add di, offset obj_polys - offset obj_poly_z ; Convert BP to poly ID
call obj_draw_polygon
jmp Lsp
LspOver:
ret
ENDP
comp_swap PROC NEAR
;---------------------------------------------------------------------
; Helper function used by draw_poly
; Dont use elsewhwere, sorts by Y coordinate
; Compares and swap points SI and DI. Saves SI and DI
;---------------------------------------------------------------------
mov ax, [si + 2]
cmp ax, [di + 2]
jle LCompSwapOver
mov eax, [si]
xchg eax, [di]
mov [si], eax
IFDEF GOURAD
mov eax, [si + offset i1 - offset p1]
xchg eax, [di + offset i1 - offset p1]
mov [si+ offset i1 - offset p1], eax
ENDIF
LCompSwapOver:
ret
ENDP
draw_poly PROC NEAR
;---------------------------------------------------------------------
; Draws polygon/triangle (p1, p2, p3) with color pcolor to screen
; wiht point-intensities (i1, i2, i3)
;---------------------------------------------------------------------
; Sort points p1, p2 and p3 increasing order on Y coordinate
;------------------------------
lea si, p1
lea di, p2
call comp_swap
lea di, p3 ; lea si, p1 -- saved above
call comp_swap
lea si, p2 ; lea di, p3 -- saved above
call comp_swap
; Points are now in order p1, p2 and p3 (by the Y coordinate
; Now lets scan the right and left edge of poly
;------------------------------------------------------------
lea si, p1
lea bp, p2
lea di, scan_right
call scan_edge
mov si, bp ; lea si, p2
lea bp, p3
lea di, scan_right
call scan_edge
lea si, p1
; lea bp, p3 ; saved
lea di, scan_left
call scan_edge
IFDEF GOURAD
; Scan intensities
lea si, i1
lea bp, i2
lea di, intensity_right
call scan_intensity
mov si, bp ; lea si, i2
lea bp, i3
lea di, intensity_right
call scan_intensity
lea si, i1
; lea bp, i3 ; saved
lea di, intensity_left
call scan_intensity
ENDIF
; Draw horizontal scanlines
;-----------------------
mov si, [p1+2] ; SI = start_y * 320
sal si, 8
mov cx, [p1+2]
sal cx, 6
add si, cx
mov bx, [p3+2] ; BX = end_y - start_y (loop counter)
sub bx, [p1+2]
jz LdoOver
mov line_counter, bx
mov bp, [p1+2]
add bp, bp
Ldo:
IFDEF GOURAD
; Set up intensityspans
push bp
mov cx, [scan_right + bp]
sub cx, [scan_left + bp]
jge NotNegCount__
neg cx
NotNegCount__:
inc cx
mov ax, cx
cwde
mov ecx, eax
add bp, bp
mov eax, [intensity_right + bp]
sub eax, [intensity_left + bp]
cdq
idiv ecx
mov edx, eax ; EDX = i_delta ;mov i_delta, eax
mov eax, [intensity_left + bp]
mov i_start, eax
mov eax, [intensity_right + bp]
mov i_end, eax
pop bp
ENDIF
mov di, [scan_left + bp]
add di, si
mov cx, [scan_right + bp]
sub cx, [scan_left + bp]
jge NotNegCount
add di, cx
neg cx
mov eax, i_end
mov i_start, eax
neg edx ; neg i_delta
NotNegCount:
inc cx
IFDEF GOURAD
push si
xor ebx, ebx
mov bx, pcolor
sal ebx, VEC_FP - FP_SHADE
add ebx, i_start
LRenderLine:
mov eax, ebx
sar eax, VEC_FP - FP_SHADE
mov es:[di], al
inc di
add ebx, edx
dec cl
jg LRenderLine
pop si
ELSE
mov ax, pcolor
LRenderLine:
mov es:[di], al
inc di
dec cx
jg LRenderLine
ENDIF
add bp, 2
add si, SCR_W
dec line_counter
jg Ldo
LdoOver:
ret
ENDP
scan_edge PROC NEAR
;---------------------------------------------------------------------
; Scans an edge (from SI to BP) to DI
; Saves SI and BP
;---------------------------------------------------------------------
xor ecx, ecx
mov cx, [bp+2]
sub cx, [si+2]
jz LseOver ; jnz MoreThanOneLine
; add di, [bp+2] ; Can cause trouble... *CR*
; add di, [bp+2]
; mov ax, [bp]
; mov [di], ax
; ret
MoreThanOneLine:
push cx ; Delta Y into stack
; mov ax, cx ; cwde ; mov ecx, eax
mov ax, [bp]
sub ax, [si]
sal eax, 16 ; cwde not needed
cdq
idiv ecx
mov ebx, eax ; Delta X
mov ax, [si] ; X
sal eax, 16 ; cwde not needed
add di, [si + 2]
add di, [si + 2]
pop cx ; Delta Y from stack
inc cx ; It wont hurt to scan one extra line !!!
sar cx, 1
; cmp cx, 0 ; cx > 0, tested above, first thing in this proc
; je LseOver
Lse2:
mov edx, eax
sar eax, 16
mov [di], ax
add edx, ebx
mov eax, edx