/
DrawMisc.cpp
5508 lines (4547 loc) · 150 KB
/
DrawMisc.cpp
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
//
// Copyright 2020 Electronic Arts Inc.
//
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
// software: you can redistribute it and/or modify it under the terms of
// the GNU General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
// in the hope that it will be useful, but with permitted additional restrictions
// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
// distributed with this program. You should have received a copy of the
// GNU General Public License along with permitted additional restrictions
// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
/*
**
**
** Misc asm functions from ww lib
** ST - 12/19/2018 1:20PM
**
**
**
**
**
**
**
**
**
**
**
*/
#include "gbuffer.h"
#include "MISC.H"
IconCacheClass::IconCacheClass (void)
{
IsCached =FALSE;
SurfaceLost =FALSE;
DrawFrequency =0;
CacheSurface =NULL;
IconSource =NULL;
}
IconCacheClass::~IconCacheClass (void)
{
}
IconCacheClass CachedIcons[MAX_CACHED_ICONS];
extern "C"{
IconSetType IconSetList[MAX_ICON_SETS];
short IconCacheLookup[MAX_LOOKUP_ENTRIES];
}
int CachedIconsDrawn=0; //Counter of number of cache hits
int UnCachedIconsDrawn=0; //Counter of number of cache misses
BOOL CacheMemoryExhausted; //Flag set if we have run out of video RAM
void Invalidate_Cached_Icons (void) {}
void Restore_Cached_Icons (void) {}
void Register_Icon_Set (void *icon_data , BOOL pre_cache) {};
//
// Prototypes for assembly language procedures in STMPCACH.ASM
//
extern "C" void __cdecl Clear_Icon_Pointers (void) {};
extern "C" void __cdecl Cache_Copy_Icon (void const *icon_ptr ,void * , int) {};
extern "C" int __cdecl Is_Icon_Cached (void const *icon_data , int icon) {return -1;};
extern "C" int __cdecl Get_Icon_Index (void *icon_ptr) {return 0;};
extern "C" int __cdecl Get_Free_Index (void) {return 0;};
extern "C" BOOL __cdecl Cache_New_Icon (int icon_index, void *icon_ptr) {return -1;};
extern "C" int __cdecl Get_Free_Cache_Slot(void) {return -1;}
void IconCacheClass::Draw_It (LPDIRECTDRAWSURFACE dest_surface , int x_pixel, int y_pixel, int window_left , int window_top , int window_width , int window_height) {}
extern int CachedIconsDrawn;
extern int UnCachedIconsDrawn;
extern "C" void __cdecl Set_Font_Palette_Range(void const *palette, INT start_idx, INT end_idx)
{
}
/*
;***************************************************************************
;* VVC::DRAW_LINE -- Scales a virtual viewport to another virtual viewport *
;* *
;* INPUT: WORD sx_pixel - the starting x pixel position *
;* WORD sy_pixel - the starting y pixel position *
;* WORD dx_pixel - the destination x pixel position *
;* WORD dy_pixel - the destination y pixel position *
;* WORD color - the color of the line to draw *
;* *
;* Bounds Checking: Compares sx_pixel, sy_pixel, dx_pixel and dy_pixel *
;* with the graphic viewport it has been assigned to. *
;* *
;* HISTORY: *
;* 06/16/1994 PWG : Created. *
;* 08/30/1994 IML : Fixed clipping bug. *
;*=========================================================================*
PROC Buffer_Draw_Line C NEAR
USES eax,ebx,ecx,edx,esi,edi
*/
void __cdecl Buffer_Draw_Line(void *this_object, int sx, int sy, int dx, int dy, unsigned char color)
{
unsigned int clip_min_x;
unsigned int clip_max_x;
unsigned int clip_min_y;
unsigned int clip_max_y;
unsigned int clip_var;
unsigned int accum;
unsigned int bpr;
static int _one_time_init = 0;
//clip_tbl DD nada,a_up,a_dwn,nada
// DD a_lft,a_lft,a_dwn,nada
// DD a_rgt,a_up,a_rgt,nada
// DD nada,nada,nada,nada
static void *_clip_table [4*4] = {0};
unsigned int int_color = color;
unsigned int x1_pixel = (unsigned int) sx;
unsigned int y1_pixel = (unsigned int) sy;
unsigned int x2_pixel = (unsigned int) dx;
unsigned int y2_pixel = (unsigned int) dy;
__asm {
mov eax,_one_time_init
and eax,eax
jnz init_done
call do_init
init_done:
//;*==================================================================
//;* Take care of find the clip minimum and maximums
//;*==================================================================
mov ebx,[this_object]
xor eax,eax
mov [clip_min_x],eax
mov [clip_min_y],eax
mov eax,[ebx]GraphicViewPortClass.Width
mov [clip_max_x],eax
add eax,[ebx]GraphicViewPortClass.XAdd
add eax,[ebx]GraphicViewPortClass.Pitch
mov [bpr],eax
mov eax,[ebx]GraphicViewPortClass.Height
mov [clip_max_y],eax
//;*==================================================================
//;* Adjust max pixels as they are tested inclusively.
//;*==================================================================
dec [clip_max_x]
dec [clip_max_y]
//;*==================================================================
//;* Set the registers with the data for drawing the line
//;*==================================================================
mov eax,[x1_pixel] //; eax = start x pixel position
mov ebx,[y1_pixel] //; ebx = start y pixel position
mov ecx,[x2_pixel] //; ecx = dest x pixel position
mov edx,[y2_pixel] //; edx = dest y pixel position
//;*==================================================================
//;* This is the section that "pushes" the line into bounds.
//;* I have marked the section with PORTABLE start and end to signify
//;* how much of this routine is 100% portable between graphics modes.
//;* It was just as easy to have variables as it would be for constants
//;* so the global vars ClipMaxX,ClipMinY,ClipMaxX,ClipMinY are used
//;* to clip the line (default is the screen)
//;* PORTABLE start
//;*==================================================================
cmp eax,[clip_min_x]
jl short clip_it
cmp eax,[clip_max_x]
jg short clip_it
cmp ebx,[clip_min_y]
jl short clip_it
cmp ebx,[clip_max_y]
jg short clip_it
cmp ecx,[clip_min_x]
jl short clip_it
cmp ecx,[clip_max_x]
jg short clip_it
cmp edx,[clip_min_y]
jl short clip_it
cmp edx,[clip_max_y]
jle short on_screen
//;*==================================================================
//;* Takes care off clipping the line.
//;*==================================================================
clip_it:
call set_bits
xchg eax,ecx
xchg ebx,edx
mov edi,esi
call set_bits
mov [clip_var],edi
or [clip_var],esi
jz short on_screen
test edi,esi
jne short off_screen
shl esi,2
//call [clip_tbl+esi]
call [_clip_table+esi]
jc clip_it
xchg eax,ecx
xchg ebx,edx
shl edi,2
//call [clip_tbl+edi]
call [_clip_table+edi]
jmp clip_it
on_screen:
jmp draw_it
off_screen:
jmp and_out
//;*==================================================================
//;* Jump table for clipping conditions
//;*==================================================================
//clip_tbl DD nada,a_up,a_dwn,nada
// DD a_lft,a_lft,a_dwn,nada
// DD a_rgt,a_up,a_rgt,nada
// DD nada,nada,nada,nada
nada:
clc
ret
a_up:
mov esi,[clip_min_y]
call clip_vert
stc
ret
a_dwn:
mov esi,[clip_max_y]
neg esi
neg ebx
neg edx
call clip_vert
neg ebx
neg edx
stc
ret
//;*==================================================================
//;* xa'=xa+[(miny-ya)(xb-xa)/(yb-ya)]
//;*==================================================================
clip_vert:
push edx
push eax
mov [clip_var],edx //; clip_var = yb
sub [clip_var],ebx //; clip_var = (yb-ya)
neg eax //; eax=-xa
add eax,ecx //; (ebx-xa)
mov edx,esi //; edx=miny
sub edx,ebx //; edx=(miny-ya)
imul edx
idiv [clip_var]
pop edx
add eax,edx
pop edx
mov ebx,esi
ret
a_lft:
mov esi,[clip_min_x]
call clip_horiz
stc
ret
a_rgt:
mov esi,[clip_max_x]
neg eax
neg ecx
neg esi
call clip_horiz
neg eax
neg ecx
stc
ret
//;*==================================================================
//;* ya'=ya+[(minx-xa)(yb-ya)/(xb-xa)]
//;*==================================================================
clip_horiz:
push edx
mov [clip_var],ecx //; clip_var = xb
sub [clip_var],eax //; clip_var = (xb-xa)
sub edx,ebx //; edx = (yb-ya)
neg eax //; eax = -xa
add eax,esi //; eax = (minx-xa)
imul edx //; eax = (minx-xa)(yb-ya)
idiv [clip_var] //; eax = (minx-xa)(yb-ya)/(xb-xa)
add ebx,eax //; ebx = xa+[(minx-xa)(yb-ya)/(xb-xa)]
pop edx
mov eax,esi
ret
//;*==================================================================
//;* Sets the condition bits
//;*==================================================================
set_bits:
xor esi,esi
cmp ebx,[clip_min_y] //; if y >= top its not up
jge short a_not_up
or esi,1
a_not_up:
cmp ebx,[clip_max_y] //; if y <= bottom its not down
jle short a_not_down
or esi,2
a_not_down:
cmp eax,[clip_min_x] //; if x >= left its not left
jge short a_not_left
or esi,4
a_not_left:
cmp eax,[clip_max_x] //; if x <= right its not right
jle short a_not_right
or esi,8
a_not_right:
ret
//;*==================================================================
//;* Draw the line to the screen.
//;* PORTABLE end
//;*==================================================================
draw_it:
sub edx,ebx //; see if line is being draw down
jnz short not_hline //; if not then its not a hline
jmp short hline //; do special case h line
not_hline:
jg short down //; if so there is no need to rev it
neg edx //; negate for actual pixel length
xchg eax,ecx //; swap x's to rev line draw
sub ebx,edx //; get old edx
down:
push edx
push eax
mov eax,[bpr]
mul ebx
mov ebx,eax
mov eax,[this_object]
add ebx,[eax]GraphicViewPortClass.Offset
pop eax
pop edx
mov esi,1 //; assume a right mover
sub ecx,eax //; see if line is right
jnz short not_vline //; see if its a vertical line
jmp vline
not_vline:
jg short right //; if so, the difference = length
//left:
neg ecx //; else negate for actual pixel length
neg esi //; negate counter to move left
right:
cmp ecx,edx //; is it a horiz or vert line
jge short horiz //; if ecx > edx then |x|>|y| or horiz
//vert:
xchg ecx,edx //; make ecx greater and edx lesser
mov edi,ecx //; set greater
mov [accum],ecx //; set accumulator to 1/2 greater
shr [accum],1
//;*==================================================================
//;* at this point ...
//;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
//;* esi=adder; accum=accumulator
//;* in a vertical loop the adder is conditional and the inc constant
//;*==================================================================
//vert_loop:
add ebx,eax
mov eax,[int_color]
v_midloop:
mov [ebx],al
dec ecx
jl and_out
add ebx,[bpr]
sub [accum],edx //; sub the lesser
jge v_midloop //; any line could be new
add [accum],edi //; add greater for new accum
add ebx,esi //; next pixel over
jmp v_midloop
horiz:
mov edi,ecx //; set greater
mov [accum],ecx //; set accumulator to 1/2 greater
shr [accum],1
//;*==================================================================
//;* at this point ...
//;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
//;* esi=adder; accum=accumulator
//;* in a vertical loop the adder is conditional and the inc constant
//;*==================================================================
//horiz_loop:
add ebx,eax
mov eax,[int_color]
h_midloop:
mov [ebx],al
dec ecx //; dec counter
jl and_out //; end of line
add ebx,esi
sub [accum],edx //; sub the lesser
jge h_midloop
add [accum],edi //; add greater for new accum
add ebx,[bpr] //; goto next line
jmp h_midloop
//;*==================================================================
//;* Special case routine for horizontal line draws
//;*==================================================================
hline:
cmp eax,ecx //; make eax < ecx
jl short hl_ac
xchg eax,ecx
hl_ac:
sub ecx,eax //; get len
inc ecx
push edx
push eax
mov eax,[bpr]
mul ebx
mov ebx,eax
mov eax,[this_object]
add ebx,[eax]GraphicViewPortClass.Offset
pop eax
pop edx
add ebx,eax
mov edi,ebx
cmp ecx,15
jg big_line
mov al,[color]
rep stosb //; write as many words as possible
jmp short and_out //; get outt
big_line:
mov al,[color]
mov ah,al
mov ebx,eax
shl eax,16
mov ax,bx
test edi,3
jz aligned
mov [edi],al
inc edi
dec ecx
test edi,3
jz aligned
mov [edi],al
inc edi
dec ecx
test edi,3
jz aligned
mov [edi],al
inc edi
dec ecx
aligned:
mov ebx,ecx
shr ecx,2
rep stosd
mov ecx,ebx
and ecx,3
rep stosb
jmp and_out
//;*==================================================================
//;* a special case routine for vertical line draws
//;*==================================================================
vline:
mov ecx,edx //; get length of line to draw
inc ecx
add ebx,eax
mov eax,[int_color]
vl_loop:
mov [ebx],al //; store bit
add ebx,[bpr]
dec ecx
jnz vl_loop
jmp and_out
do_init:
mov edi, offset _clip_table
lea esi, nada
mov [edi], esi
mov [edi+12], esi
lea esi, a_up
mov [edi+4], esi
lea esi, a_dwn
mov [edi+8], esi
add edi, 16
lea esi, a_lft
mov [edi], esi
mov [edi+4], esi
lea esi, a_dwn
mov [edi+8], esi
lea esi, nada
mov [edi+12], esi
add edi, 16
lea esi, a_rgt
mov [edi], esi
mov [edi+8], esi
lea esi, a_up
mov [edi+4], esi
lea esi, nada
mov [edi+12], esi
add edi, 16
lea esi, nada
mov [edi], esi
mov [edi+4], esi
mov [edi+8], esi
mov [edi+12], esi
mov [_one_time_init], 1
ret
and_out:
}
}
/*
;***************************************************************************
;** C O N F I D E N T I A L --- W E S T W O O D A S S O C I A T E S **
;***************************************************************************
;* *
;* Project Name : Westwood 32 bit Library *
;* *
;* File Name : DRAWLINE.ASM *
;* *
;* Programmer : Phil W. Gorrow *
;* *
;* Start Date : June 16, 1994 *
;* *
;* Last Update : August 30, 1994 [IML] *
;* *
;*-------------------------------------------------------------------------*
;* Functions: *
;* VVC::Scale -- Scales a virtual viewport to another virtual viewport *
;* Normal_Draw -- jump loc for drawing scaled line of normal pixel *
;* __DRAW_LINE -- Assembly routine to draw a line *
;* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - *
IDEAL
P386
MODEL USE32 FLAT
INCLUDE ".\drawbuff.inc"
INCLUDE ".\gbuffer.inc"
CODESEG
*/
/*
;***************************************************************************
;* VVC::DRAW_LINE -- Scales a virtual viewport to another virtual viewport *
;* *
;* INPUT: WORD sx_pixel - the starting x pixel position *
;* WORD sy_pixel - the starting y pixel position *
;* WORD dx_pixel - the destination x pixel position *
;* WORD dy_pixel - the destination y pixel position *
;* WORD color - the color of the line to draw *
;* *
;* Bounds Checking: Compares sx_pixel, sy_pixel, dx_pixel and dy_pixel *
;* with the graphic viewport it has been assigned to. *
;* *
;* HISTORY: *
;* 06/16/1994 PWG : Created. *
;* 08/30/1994 IML : Fixed clipping bug. *
;*=========================================================================*
PROC Buffer_Draw_Line C NEAR
USES eax,ebx,ecx,edx,esi,edi
;*==================================================================
;* Define the arguements that the function takes.
;*==================================================================
ARG this_object:DWORD ; associated graphic view port
ARG x1_pixel:DWORD ; the start x pixel position
ARG y1_pixel:DWORD ; the start y pixel position
ARG x2_pixel:DWORD ; the dest x pixel position
ARG y2_pixel:DWORD ; the dest y pixel position
ARG color:DWORD ; the color we are drawing
;*==================================================================
;* Define the local variables that we will use on the stack
;*==================================================================
LOCAL clip_min_x:DWORD
LOCAL clip_max_x:DWORD
LOCAL clip_min_y:DWORD
LOCAL clip_max_y:DWORD
LOCAL clip_var:DWORD
LOCAL accum:DWORD
LOCAL bpr:DWORD
;*==================================================================
;* Take care of find the clip minimum and maximums
;*==================================================================
mov ebx,[this_object]
xor eax,eax
mov [clip_min_x],eax
mov [clip_min_y],eax
mov eax,[(GraphicViewPort ebx).GVPWidth]
mov [clip_max_x],eax
add eax,[(GraphicViewPort ebx).GVPXAdd]
add eax,[(GraphicViewPort ebx).GVPPitch]
mov [bpr],eax
mov eax,[(GraphicViewPort ebx).GVPHeight]
mov [clip_max_y],eax
;*==================================================================
;* Adjust max pixels as they are tested inclusively.
;*==================================================================
dec [clip_max_x]
dec [clip_max_y]
;*==================================================================
;* Set the registers with the data for drawing the line
;*==================================================================
mov eax,[x1_pixel] ; eax = start x pixel position
mov ebx,[y1_pixel] ; ebx = start y pixel position
mov ecx,[x2_pixel] ; ecx = dest x pixel position
mov edx,[y2_pixel] ; edx = dest y pixel position
;*==================================================================
;* This is the section that "pushes" the line into bounds.
;* I have marked the section with PORTABLE start and end to signify
;* how much of this routine is 100% portable between graphics modes.
;* It was just as easy to have variables as it would be for constants
;* so the global vars ClipMaxX,ClipMinY,ClipMaxX,ClipMinY are used
;* to clip the line (default is the screen)
;* PORTABLE start
;*==================================================================
cmp eax,[clip_min_x]
jl short ??clip_it
cmp eax,[clip_max_x]
jg short ??clip_it
cmp ebx,[clip_min_y]
jl short ??clip_it
cmp ebx,[clip_max_y]
jg short ??clip_it
cmp ecx,[clip_min_x]
jl short ??clip_it
cmp ecx,[clip_max_x]
jg short ??clip_it
cmp edx,[clip_min_y]
jl short ??clip_it
cmp edx,[clip_max_y]
jle short ??on_screen
;*==================================================================
;* Takes care off clipping the line.
;*==================================================================
??clip_it:
call NEAR PTR ??set_bits
xchg eax,ecx
xchg ebx,edx
mov edi,esi
call NEAR PTR ??set_bits
mov [clip_var],edi
or [clip_var],esi
jz short ??on_screen
test edi,esi
jne short ??off_screen
shl esi,2
call [DWORD PTR cs:??clip_tbl+esi]
jc ??clip_it
xchg eax,ecx
xchg ebx,edx
shl edi,2
call [DWORD PTR cs:??clip_tbl+edi]
jmp ??clip_it
??on_screen:
jmp ??draw_it
??off_screen:
jmp ??out
;*==================================================================
;* Jump table for clipping conditions
;*==================================================================
??clip_tbl DD ??nada,??a_up,??a_dwn,??nada
DD ??a_lft,??a_lft,??a_dwn,??nada
DD ??a_rgt,??a_up,??a_rgt,??nada
DD ??nada,??nada,??nada,??nada
??nada:
clc
retn
??a_up:
mov esi,[clip_min_y]
call NEAR PTR ??clip_vert
stc
retn
??a_dwn:
mov esi,[clip_max_y]
neg esi
neg ebx
neg edx
call NEAR PTR ??clip_vert
neg ebx
neg edx
stc
retn
;*==================================================================
;* xa'=xa+[(miny-ya)(xb-xa)/(yb-ya)]
;*==================================================================
??clip_vert:
push edx
push eax
mov [clip_var],edx ; clip_var = yb
sub [clip_var],ebx ; clip_var = (yb-ya)
neg eax ; eax=-xa
add eax,ecx ; (ebx-xa)
mov edx,esi ; edx=miny
sub edx,ebx ; edx=(miny-ya)
imul edx
idiv [clip_var]
pop edx
add eax,edx
pop edx
mov ebx,esi
retn
??a_lft:
mov esi,[clip_min_x]
call NEAR PTR ??clip_horiz
stc
retn
??a_rgt:
mov esi,[clip_max_x]
neg eax
neg ecx
neg esi
call NEAR PTR ??clip_horiz
neg eax
neg ecx
stc
retn
;*==================================================================
;* ya'=ya+[(minx-xa)(yb-ya)/(xb-xa)]
;*==================================================================
??clip_horiz:
push edx
mov [clip_var],ecx ; clip_var = xb
sub [clip_var],eax ; clip_var = (xb-xa)
sub edx,ebx ; edx = (yb-ya)
neg eax ; eax = -xa
add eax,esi ; eax = (minx-xa)
imul edx ; eax = (minx-xa)(yb-ya)
idiv [clip_var] ; eax = (minx-xa)(yb-ya)/(xb-xa)
add ebx,eax ; ebx = xa+[(minx-xa)(yb-ya)/(xb-xa)]
pop edx
mov eax,esi
retn
;*==================================================================
;* Sets the condition bits
;*==================================================================
??set_bits:
xor esi,esi
cmp ebx,[clip_min_y] ; if y >= top its not up
jge short ??a_not_up
or esi,1
??a_not_up:
cmp ebx,[clip_max_y] ; if y <= bottom its not down
jle short ??a_not_down
or esi,2
??a_not_down:
cmp eax,[clip_min_x] ; if x >= left its not left
jge short ??a_not_left
or esi,4
??a_not_left:
cmp eax,[clip_max_x] ; if x <= right its not right
jle short ??a_not_right
or esi,8
??a_not_right:
retn
;*==================================================================
;* Draw the line to the screen.
;* PORTABLE end
;*==================================================================
??draw_it:
sub edx,ebx ; see if line is being draw down
jnz short ??not_hline ; if not then its not a hline
jmp short ??hline ; do special case h line
??not_hline:
jg short ??down ; if so there is no need to rev it
neg edx ; negate for actual pixel length
xchg eax,ecx ; swap x's to rev line draw
sub ebx,edx ; get old edx
??down:
push edx
push eax
mov eax,[bpr]
mul ebx
mov ebx,eax
mov eax,[this_object]
add ebx,[(GraphicViewPort eax).GVPOffset]
pop eax
pop edx
mov esi,1 ; assume a right mover
sub ecx,eax ; see if line is right
jnz short ??not_vline ; see if its a vertical line
jmp ??vline
??not_vline:
jg short ??right ; if so, the difference = length
??left:
neg ecx ; else negate for actual pixel length
neg esi ; negate counter to move left
??right:
cmp ecx,edx ; is it a horiz or vert line
jge short ??horiz ; if ecx > edx then |x|>|y| or horiz
??vert:
xchg ecx,edx ; make ecx greater and edx lesser
mov edi,ecx ; set greater
mov [accum],ecx ; set accumulator to 1/2 greater
shr [accum],1
;*==================================================================
;* at this point ...
;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
;* esi=adder; accum=accumulator
;* in a vertical loop the adder is conditional and the inc constant
;*==================================================================
??vert_loop:
add ebx,eax
mov eax,[color]
??v_midloop:
mov [ebx],al
dec ecx
jl ??out
add ebx,[bpr]
sub [accum],edx ; sub the lesser
jge ??v_midloop ; any line could be new
add [accum],edi ; add greater for new accum
add ebx,esi ; next pixel over
jmp ??v_midloop
??horiz:
mov edi,ecx ; set greater
mov [accum],ecx ; set accumulator to 1/2 greater
shr [accum],1
;*==================================================================
;* at this point ...
;* eax=xpos ; ebx=page line offset; ecx=counter; edx=lesser; edi=greater;
;* esi=adder; accum=accumulator
;* in a vertical loop the adder is conditional and the inc constant
;*==================================================================
??horiz_loop:
add ebx,eax
mov eax,[color]
??h_midloop:
mov [ebx],al
dec ecx ; dec counter
jl ??out ; end of line
add ebx,esi
sub [accum],edx ; sub the lesser
jge ??h_midloop
add [accum],edi ; add greater for new accum
add ebx,[bpr] ; goto next line
jmp ??h_midloop
;*==================================================================
;* Special case routine for horizontal line draws
;*==================================================================
??hline:
cmp eax,ecx ; make eax < ecx
jl short ??hl_ac
xchg eax,ecx
??hl_ac:
sub ecx,eax ; get len
inc ecx
push edx
push eax
mov eax,[bpr]
mul ebx
mov ebx,eax
mov eax,[this_object]
add ebx,[(GraphicViewPort eax).GVPOffset]
pop eax
pop edx
add ebx,eax
mov edi,ebx
cmp ecx,15
jg ??big_line
mov al,[byte color]
rep stosb ; write as many words as possible
jmp short ??out ; get outt
??big_line:
mov al,[byte color]
mov ah,al
mov ebx,eax
shl eax,16
mov ax,bx
test edi,3
jz ??aligned
mov [edi],al
inc edi
dec ecx
test edi,3
jz ??aligned
mov [edi],al
inc edi
dec ecx
test edi,3
jz ??aligned
mov [edi],al
inc edi
dec ecx
??aligned:
mov ebx,ecx
shr ecx,2
rep stosd
mov ecx,ebx
and ecx,3
rep stosb
jmp ??out
;*==================================================================
;* a special case routine for vertical line draws
;*==================================================================
??vline:
mov ecx,edx ; get length of line to draw
inc ecx
add ebx,eax
mov eax,[color]