-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVGA16.PAS
2179 lines (1896 loc) · 62.1 KB
/
VGA16.PAS
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
Unit vga16;
{16 colour VGA driver (C) T.Lewis 1996}
{$X+}{$a+}
INTERFACE
{stuff to be preserved for mouse inter:
GRPH_ADDR
3,logicmode
0,colour
5,WriteMode (Normaly 3)
4,ReadMask
}
uses gbasics,chardef,ttypes,tmaths;
Const
{VGA register locations}
MISC_ADDR=$3C2; MISC_READ_ADDR=$3CC;
ATTR_ADDR=$3c0; ATTR_DATA_ADDR=$3c1;
SEQU_ADDR=$3c4; SEQU_DATA_ADDR=$3c5;
CRTC_ADDR=$3D4; CRTC_DATA_ADDR=$3d5;
GRPH_ADDR=$3CE; GRPH_DATA_ADDR=$3CF;
STATUS_ADDR=$3da;
noclear=128;
allplanes=3841;
{Register masks}
data_rotate=$3;
chainfour=$8;
oddeven=$4;
exetendedmem=$2;
alphaon=$1;
function set_mode(mode:byte):boolean;
Procedure bar(x1,y,x2,y2:integer);
Procedure GTriangle(xa,ya,xb,yb,xc,yc,ia,ib,ic:integer);
Procedure Triangle(xa,ya,xb,yb,xc,yc:integer);
Procedure Line(x1,y1,x2,y2:integer);
Procedure Hline(x1,x2,y:Integer);
Procedure Vline(x,y1,y2:Integer);
Procedure putpixel(x1,y1:Integer);
Function getpixel(x1,y1:Integer):byte;
Procedure outtextxy(x1,y1:integer;txt:string);
Procedure outtextxy_length(x1,y1:integer;txt:pchar;length:byte);
Procedure Drawbytes(x1,y:Integer;pic:bytearray;nbytes:byte);
Procedure Drawbytesxy(x1,y1:Integer;pic:bytearray;xbytes,ybytes:byte);
Procedure Screencopy(x1,y1,x2,y2,xd,yd:integer;page1,page2:byte);
procedure putbitmap(x1,y1:integer;bitmap:bitmaptypeptr);
function getbitmap(x1,y1,x2,y2:integer):bitmaptypeptr;
Procedure cleardevice;
procedure savescreenregs;
procedure restorescreenregs;
{quick generic interface to screen -good for file loading}
Procedure QSetXY(x,y:integer);
Procedure Qwrite(count:word);
function Qget:byte;
IMPLEMENTATION
{swaps two variables of arbitary length, inline into the code}
{stuff to be preserved for mouse inter:
GRPH_ADDR
3,logicmode
0,colour
5,WriteMode (Normaly 3)
4,ReadMask
}
var
oldlogicmode,oldcolour,oldwritemode,oldreadmask:byte;
procedure savescreenregs;
begin
end;
procedure restorescreenregs;
begin
end;
function set_mode(mode:byte):boolean;
var installed:boolean;
begin
if mode>100 then
asm mov ax,4F02h;mov bh,01h;mov bl,mode;sub bl,100;int 10h end
else
asm mov al,mode;mov ah,0;int 10h end;
asm
{Natural state for the video mode}
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor ax,ax; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0ff08h; out dx,ax; {bitmask,255 func:8}
{correct oddering of the palette}
mov cx,15
@runloop:
mov dx,STATUS_ADDR
in al,dx
mov dx,ATTR_ADDR
mov al,cl
out dx,al
out dx,al
loop @runloop
mov dx,STATUS_ADDR
in al,dx
mov dx,ATTR_ADDR
mov al,32;
out dx,al
end;
set_mode:=TRUE;
{PatternMask:=$A0000+65535;}
{PatternAdrs:=PatternMask-8;}
end;
Procedure cleardevice;assembler;
Asm
mov dx,GRPH_ADDR
mov al,3; mov ah,t_writemode; out dx,ax; {writemode}
xor al,al; mov ah,t_fillcol; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0FF08h; out dx,ax; {bitmask,255 func:8}
les di,SC.scrptr
mov ax,$ffff {set fill mask}
mov cx,word ptr SC.pagesize {byte count}
shr cx,1 {half that...}
CLD {clear stuff}
REP STOSW {write to screen}
End;
{clip a line against 'SC.viewport'}
function clip(var xas,yas,xbs,ybs:integer):boolean;
var code0,code1:byte;
var xa,ya,xb,yb:longint;
Begin
xa:=xas;ya:=yas;xb:=xbs;yb:=ybs;
While 0=0 do begin
code0:=(byte(xb>SC.viewport.x2))+ {right =$01}
(byte(yb>SC.viewport.y2)shl 1)+{bellow =$02}
(byte(xb<SC.viewport.x1)shl 2)+{left =$04}
(byte(yb<SC.viewport.y1)shl 3) {above =$08};
code1:=(byte(xa>SC.viewport.x2))+ {right =$01}
(byte(ya>SC.viewport.y2)shl 1)+{bellow =$02}
(byte(xa<SC.viewport.x1)shl 2)+{left =$04}
(byte(ya<SC.viewport.y1)shl 3) {above =$08};
if boolean(code0 and code1) then begin
clip:=false;exit;{Trivial reject}
end else begin
if not boolean(code0 or code1)then begin
xas:=xa;yas:=ya;xbs:=xb;ybs:=yb;
clip:=true;exit;{Trivial accept}
end else If (code0=0) then begin
fswap(code1,code0,1);
fswap(xb,xa,4);
fswap(yb,ya,4);
end;
if boolean(code0 and bellow) then begin
inc(xb,(xa-xb)*(SC.viewport.y2-yb)div(ya-yb));
yb:=SC.viewport.y2;
end else if boolean(code0 and above) then begin
inc(xb,(xa-xb)*(SC.viewport.y1-yb)div(ya-yb));
yb:=SC.viewport.y1;
end else if boolean(code0 and right) then begin
inc(yb,(ya-yb)*(SC.viewport.x2-xb)div(xa-xb));
xb:=SC.viewport.x2;
end else if boolean(code0 and left) then begin
inc(yb,(ya-yb)*(SC.viewport.x1-xb)div(xa-xb));
xb:=SC.viewport.x1;
end;
end;
end;
end;
{biechmans line drawing algo- bit optimization still needed}
Procedure Line(x1,y1,x2,y2:integer);
Var dfx,dfy,incr2:integer;
Begin
if x1=x2 then vline(x1,y1,y2) else begin
if y1=y2 then hline(x1,x2,y1) else
if clip(x1,y1,x2,y2) then Begin
dfx:=abs(x2-x1);dfy:=abs(y2-y1);
asm
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor al,al; mov ah,t_col; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0ff08h; out dx,ax; {bitmask,255 func:8}
mov es,word ptr SC.scrptr+2
{choose here whether to do x or y indpendent}
mov ax,dfx; cmp ax,dfy; jle @near_vertical {if dfx>dfy then....}
mov ax,x2 ; cmp x1,ax ; jle @no_swap
Xchg x1,ax ; mov x2,ax
mov ax,y2 ; Xchg y1,ax ; mov y2,ax;
@no_swap:
{get address}
mov si,y1
shl si,1
mov bx,x1; shr bx,3
add bx,word ptr Sc.startoffsets+si
{offset now in bx}
mov ax,dfy {difference in y}
sub ax,dfx {subtract difference in x}
shl ax,1 {times by two and you've got incr2}
mov incr2,ax {save it in here- goes into bp latter}
mov dx,SC.offsw {load up scanline increment}
mov ax,y1 {is y2 less than y1?}
cmp ax,y2
jle @notneg; neg dx; @notneg: {then make it not negative}
mov cx,x1 ;and cl,7 {get mask}
mov al,128 ;shr al,cl {get mask}
mov cx,dfx ;inc cx {load in the length}
mov si,dfy ;shl si,1; {get incr1}
mov di,si ;sub di,dfx {get fractional counter}
{mov ah,al {remember last drawpos}
push bp {remember stack frame}
mov bp,incr2
{is the line stippled?}
test maskbyte,255
jnz @stiplinea
@Runloopa: {start loop}
and es:[bx],al {write to screen}
ror al,1 {move index bit along 1}
adc bx,0 {increment draw offset if overflow}
cmp di,0;jl @noinca {new scan line?}
add di,bp {update di,go to next scan line}
add bx,dx {add scanline offset}
jmp @checka
@noinca:
add di,si {update fractional part}
@checka:
dec cx;jnz @runloopa
pop bp {recall stack frame}
jmp @end_of_proc
@stiplinea:
{do stippled near horizontal line}
@Runloopb: {start loop}
test maskbyte,al
jz @nodrawa
and es:[bx],al {write to screen}
@nodrawa:
ror al,1 {move index bit along 1}
adc bx,0 {increment draw offset if overflow}
cmp di,0;jl @noincb {new scan line?}
add di,bp {update di,go to next scan line}
add bx,dx {add scanline offset}
jmp @checkb
@noincb:
add di,si {update fractional part}
@checkb:
dec cx;jnz @runloopb
pop bp {recall stack frame}
jmp @end_of_proc
@near_vertical:
mov ax,y2 ; cmp y1,ax ; jle @no_swapb
Xchg y1,ax ; mov y2,ax
mov ax,x2 ; Xchg x1,ax ; mov x2,ax;
@no_swapb:
{get address}
mov si,y1
shl si,1
mov bx,x1; shr bx,3
add bx,word ptr Sc.startoffsets+si
{offset now in bx}
mov ax,dfx {difference in x}
sub ax,dfy {subtract difference in y}
shl ax,1 {times by two and you've got incr2}
mov incr2,ax
inc dfy {add one to difference in y}
mov dx,SC.offsw {screen width}
mov cx,x1 ;and cl,7 {get mask}
mov al,$80 ;shr al,cl {get mask}
mov si,dfx; shl si,1 {integer increment}
mov di,si {copy diff in x*2}
sub di,dfy {(diff in X*2)-diff in y}
mov ah,1 {stipple mask}
mov cx,x1; cmp cx,x2; {check if line is going..}
jg @left {..left or right}
{do these loads for both directions because of the use of bp}
mov cx,dfy {difference in Y}
push bp
mov bp,incr2 {fractional increment}
{is the line stippled?}
test maskbyte,255
jnz @stiplineb
@Runloopc:
and es:[bx],al {Write to screen}
add bx,dx {next scan line}
cmp di,0 {if no change}
jl @noincc {then don't do below}
add di,bp {do frac part}
ror al,1 {rotate mask right}
adc bx,0 {go to next byte on screen}
jmp @checkc {don't add di,si}
@noincc:
add di,si {add frac part}
@checkc:
dec cx;jnz @runloopc
jmp @end
{stippled left near vertical}
@stiplineb:
@Runloope:
test maskbyte,ah
jz @nodrawb
and es:[bx],al {write to screen}
@nodrawb:
rol ah,1 {rotate stipple check mask}
add bx,dx {next scan line}
cmp di,0 {if no change}
jl @noince {then don't do below}
add di,bp {do frac part}
ror al,1 {rotate mask right}
adc bx,0 {go to next byte on screen}
jmp @checke {don't add di,si}
@noince:
add di,si {add frac part}
@checke:
dec cx;jnz @runloope
jmp @end
@left:
{do these loads for both directions because of the use of bp}
mov cx,dfy {difference in Y}
push bp
mov bp,incr2 {fractional increment}
{is the line stippled?}
test maskbyte,255
jnz @stiplinec
@Runloopd:
and es:[bx],al {Write to screen}
add bx,dx {next scan line}
cmp di,0 {if no change}
jl @noincd {then don't do below}
add di,bp {do frac part}
rol al,1 {rotate mask left}
sbb bx,0 {go to previous byte on screen}
jmp @checkd {don't add di,si}
@noincd:
add di,si {add frac part}
@checkd:
dec cx;jnz @runloopd
jmp @end
{stippled right near vertical}
@stiplinec:
@Runloopf:
test maskbyte,ah
jz @nodrawc
and es:[bx],al {write to screen}
@nodrawc:
rol ah,1 {rotate stipple check mask}
add bx,dx {next scan line}
cmp di,0 {if no change}
jl @noincf {then don't do below}
add di,bp {do frac part}
rol al,1 {rotate mask left}
sbb bx,0 {go to previous byte on screen}
jmp @checkf {don't add di,si}
@noincf:
add di,si {add frac part}
@checkf:
dec cx;jnz @runloopf
@end:
pop bp
@end_of_proc:
end;
end;
end;
end;
{write a graphical text output to the screen.
clipped to words and then to pixel bits}
(*
Procedure outtextxy_length(x1,y1:integer;txt:pchar;length:byte);
var txtend,ylop,txtstart,lmask,rmask,cmask:byte;
Adrs,decoffs:word;
x2,y2,tmp:integer;
Begin
asm
mov al,length {get length (first byte)}
mov txtend,al
xor ah,ah {clear top byte}
mov al,txtend {x2:=x1+(txtend shl 3);}
shl ax,3
add ax,x1
mov x2,ax
mov ax,y1 {y2:=y1+Fontmax;}
add ax,Fontmax
mov y2,ax
end;
if (x1<=SC.viewport.x2)and(y1<=SC.viewport.y2)and(x2>=SC.viewport.x1)
and(y2>=SC.viewport.y1)and(txtend<>0) then begin
asm
mov ax,y1 ;imul SC.offsw
mov di,x1 ;sar di,3
add di,word ptr SC.scrptr
add di,ax
mov adrs,di
end;
{**X - Clipping**}
lmask:=$ff; rmask:=$ff;
txtstart:=1;
tmp:=(SC.viewport.x1-x1);
if x1<SC.viewport.x1 then begin
lmask:=lmask shr (tmp and 7);
tmp:=tmp shr 3;
inc(txtstart,tmp);
inc(adrs,tmp);
end;
tmp:=(x2-SC.viewport.x2-1);
if x2>SC.viewport.x2 then begin
dec(txtend,tmp shr 3);
rmask:=rmask shl (tmp and 7);
end;
if txtstart=txtend+1 then exit;
{**Y-cliping**}
If y2>SC.viewport.y2 then ylop:=(SC.viewport.y2-y1) else ylop:=Fontmax;
if y1<SC.viewport.y1 then begin
y1:=SC.viewport.y1-y1;inc(Adrs,y1*SC.offsw);
end else y1:=0;
dec(ylop,y1);
decoffs:=(SC.offsw*(ylop+1)-1);
asm
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor al,al; mov ah,t_col; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0ff08h; out dx,ax; {bitmask,255 func:8}
mov di,adrs {load offset}
mov dx,x1 {value to shift by}
and dl,7
mov bx,SC.offsw {load dx with screen offset}
dec txtstart
dec txtend
mov dh,txtstart {dh is the loop counter}
@Textloop:
les si,txt {point to string}
mov al,dh;xor ah,ah {get txtloop from dh into ax}
add si,ax {Add to offsets the offset of the..}
mov al,es:[si] ;xor ah,ah {..current character..}
test al,255 {for null terminated strings- }
jz @end {exit if zero}
shl ax,fontshift {..shift to get the byte offset..}
add ax,y1 {..of the graphic and add y to clip}
mov es,word ptr SC.scrptr+2 {set up screen address segment}
push ds {save data segment}
lea si,tcharset {point to character set}
add si,ax {add character offset}
mov cl,ylop ;inc cl {set up y dec cx;jnz (from y to ylop)}
{generate mask}
mov al,255
cmp dh,txtstart;jnz @noleft
and al,lmask {mask with the left?}
@noleft:
cmp dh,txtend; jnz @noright
and al,rmask {mask with the right?}
@noright:
mov cmask,al
mov ch,ylop ;inc ch {set up y dec cx;jnz (from y to ylop)}
@drawloop:
mov al,ds:[si] {load from pic}
and al,cmask
xor ah,ah {clear top byte}
mov cl,dl; ror ax,cl {shift right by dl}
and es:[di],al {write to screen memory}
and es:[di+1],ah {write overflow}
add di,bx {shift to next line on screen}
inc si {go to next byte in pic}
dec ch
jnz @drawloop
pop ds {restore data segment}
sub di,decoffs {correct the screen position..}
inc dh {next character}
cmp dh,txtend {is it the end?}
jle @Textloop {if not, do it all again}
@end:
end;
end;
end;*)
Procedure outtextxy_length(x1,y1:integer;txt:pchar;length:byte);
var txtlop:byte;
Begin
if tcharset.attrib<>CTproportional then
for txtlop:=1 to length do begin
drawbytes(x1,y1,@tcharset.typeface[byte(txt^)],fontheight);
inc(x1,8);
inc(txt);
end else
for txtlop:=1 to length do begin
drawbytes(x1,y1,@tcharset.typeface[byte(txt^)],fontheight);
inc(x1,tcharset.widths[byte(txt^)]);
inc(txt);
end;
end;
Procedure outtextxy(x1,y1:integer;txt:string);
Begin
outtextxy_length(x1,y1,@txt[1],byte(txt[0]));
end;
{in the C version, replace this with a macro}
Procedure Drawbytes(x1,y:Integer;pic:bytearray;nbytes:byte);
var lop,mask:byte; Adrs:word;
x2:integer;
Begin
x2:=x1+8;
dec(nbytes);
if (x2>=SC.viewport.x1)and(x1<=SC.viewport.x2)and(y+nbytes>=SC.viewport.y1)and(y<=SC.viewport.y2)then begin
{**XCliping**}
mask:=$ff;
if x1<SC.viewport.x1 then
mask:=$ff shr (SC.viewport.x1-x1);
if x2>SC.viewport.x2 then
mask:=mask and ($ff shl (x2-SC.viewport.x2-1));
asm
mov si,y
shl si,1
mov bx,x1 ;sar bx,3
add bx,word ptr SC.scrptr
add bx,word ptr SC.startoffsets+si
mov adrs,bx
end;
{**YCliping**}
If y+nbytes>SC.viewport.y2 then lop:=(SC.viewport.y2-y) else lop:=nbytes;
if y<SC.viewport.y1 then begin
y:=SC.viewport.y1-y;inc(adrs,SC.offsw*y);
end else y:=0;
dec(lop,y);
asm
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor al,al; mov ah,t_col; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0ff08h; out dx,ax; {bitmask,255 func:8}
mov es,word ptr SC.scrptr+2 {set up screen address}
mov di,adrs
{values to shift left and right by}
mov cx,x1
and cl,7
mov bh,mask
mov ch,lop ;inc ch {y loop counter}
mov dx,SC.offsw {load dx with screen offset}
push ds {save data segment}
lds si,pic
add si,y
@drawloop:
mov al,ds:[si] {load from pic}
and al,bh {and with mask}
xor ah,ah
ror ax,cl {shift right by bl}
and es:[di],al {write to screen memory}
and es:[di+1],ah
add di,dx {shift to next line on screen}
inc si {go to next byte in pic}
dec ch
jnz @drawloop
pop ds
end;
{for lop:=ystart to lop do begin
hsub2(Adrs,pic^[lop] shr (dx),(pic^[lop] shl (8-dx)));
inc(Adrs,offs);
end;}
end;
end;
Procedure drawbytesxy(x1,y1:Integer;pic:bytearray;xbytes,ybytes:byte);
var ylop,xlenclipped,lmask,rmask,cmask:byte;
Adrs,incpicoffs,incscroffs,picseg,picofs:word;
x2,y2,tmp:integer;
Begin
x2:=x1+xbytes shl 3;
y2:=y1+ybytes;
picseg:=seg(pic^);
picofs:=ofs(pic^);
if (x1<=SC.viewport.x2)and(y1<=SC.viewport.y2)and(x2>=SC.viewport.x1)
and(y2>=SC.viewport.y1)and(xbytes<>0) then begin
asm
mov ax,y1 ;imul SC.offsw
mov di,x1 ;sar di,3
add di,word ptr SC.scrptr
add di,ax
mov adrs,di
end;
{**X - Clipping**}
lmask:=$ff;rmask:=$ff;
xlenclipped:=xbytes;
incpicoffs:=0;
tmp:=(SC.viewport.x1-x1);
if x1<SC.viewport.x1 then begin
lmask:=lmask shr (tmp and 7);
tmp:=tmp shr 3;
inc(picofs,tmp);
inc(incpicoffs,tmp);
dec(xlenclipped,tmp);
inc(adrs,tmp);
end;
if incpicoffs=xbytes then exit;
tmp:=(x2-SC.viewport.x2-1);
if x2>SC.viewport.x2 then begin
rmask:=rmask shl (tmp and 7);
tmp:=tmp shr 3;
dec(xlenclipped,tmp);
inc(incpicoffs,tmp);
end;
{**Y-cliping**}
If y2>SC.viewport.y2 then
ylop:=(SC.viewport.y2-y1)+1
else
ylop:=ybytes;
if y1<SC.viewport.y1 then begin
y1:=SC.viewport.y1-y1;
inc(adrs,SC.startoffsets[y1]);
inc(picofs,y1*xbytes);
end else y1:=0;
dec(ylop,y1);
incscroffs:=(SC.offsw-xlenclipped);
asm
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor al,al; mov ah,t_col; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0ff08h; out dx,ax; {bitmask,255 func:8}
mov es,word ptr SC.scrptr+2
mov di,adrs {load offset}
mov cx,x1 {value to shift by}
and cl,7
mov bl,lmask
mov bh,rmask
mov ch,ylop
mov si,picofs {load up picture adrs}
push ds
mov ds,picseg
@yloop:
mov dh,xlenclipped {dh is the loop counter}
@xloop:
mov al,ds:[si] {load from pic}
cmp dh,xlenclipped;jnz @noleft
and al,bl {mask with the left?}
@noleft:
cmp dh,1; jnz @noright
and al,bh {mask with the right?}
@noright:
xor ah,ah
ror ax,cl {shift right by cl}
and es:[di],al {write to screen memory}
and es:[di+1],ah
inc si {next pic byte}
inc di {next screen byte}
dec dh
jnz @xloop
add di,incscroffs {next line on screen}
add si,incpicoffs
dec ch
jg @yloop
pop ds
end;
end;
end;
Procedure Hline(x1,x2,y:Integer);assembler;
asm
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor al,al; mov ah,t_col; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ah,maskbyte;mov al,8; out dx,ax; {bitmask,maskbyte func:8}
mov ax,y;mov bx,x1; mov cx,x2
{swap x1,x1 if x1>x2}
cmp bx,cx ;jle @no_swap ; Xchg bx,cx; @no_swap:
{is line at all visable?}
cmp bx,SC.viewport.x2 ;jg @fin
cmp cx,SC.viewport.x1 ;jl @fin
cmp ax,SC.viewport.y2 ;jg @fin
cmp ax,SC.viewport.y1 ;jl @fin
{X axis clipping}
mov dx,SC.viewport.x1 ;cmp bx,dx ; JGE @nochange_x1
mov bx,dx
@nochange_x1:
mov dx,SC.viewport.x2 ;cmp cx,dx ; JLE @nochange_x2
mov cx,dx
@nochange_x2:
{Get starting byte to work on}
mov si,ax
shl si,1
mov di,word ptr SC.startoffsets+si
add di,word ptr SC.scrptr
mov es,word ptr SC.scrptr+2
inc cx
mov dl,cl {save cl}
mov ax,$ffff {2nd mask }
and cl,7 ; shr ah,cl ;not ah {x2 already loaded into cx}
mov cl,bl; and cl,7 ;shr al,cl {1st mask ,load x1 (in bx) into cx}
{and ax,maskword}
mov cl,dl {restore cl}
{calculate length (in bytes-1) of line}
shr cx,3 {x2 in byte range}
shr bx,3 {x1 in byte range}
sub cx,bx {get byte length}
{shr cx,3}
add di,bx {add this to screen memory offset}
mov bx,ax {get masks from ax}
{///////2 COLOUR BACKGROUND FILLED PATTERN/////////////////////////}
test maskbackground,true
jz @normalfill
cmp cl,0; jnz @more1 {if there is only one byte then do only this}
and bh,bl
@More1:
mov dx,GRPH_ADDR
mov ah,$ff;mov al,8; out dx,ax; {bitmask,$ff func:8}
{/////////////EDGES OF SOLID PATTERN FILL////////////////}
mov al,maskbyte
and es:[64427],al {copy to top of screen memory}
push bx
and bl,al
and bh,al
cmp cx,0
jz @lastbyteb {if only one byte then goto @lastbyte}
and es:[di],bl {write to screen}
add di,cx {next byte}
@lastbyteb:
and es:[di],bh {write to screen}
pop bx
sub di,cx {restore di to original value}
xor al,al; mov ah,t_fillcol; out dx,ax; {setup inverse colour}
mov al,maskbyte
not al
and es:[64427],al {copy to top of screen memory}
and bl,al
and bh,al
cmp cx,0
jz @lastbytec {if only one byte then goto @lastbyte}
and es:[di],bl {write to screen}
add di,cx {next byte}
@lastbytec:
and es:[di],bh {write to screen}
sub di,cx {restore di to original value}
cmp cl,0
jle @fin
{/////////////BODY OF SOLID PATTERN FILL////////////////}
dec cl
inc di
mov ax,00008h;out dx,ax {set bitmask to 0}
and al,es:[64427]
shr cl,1 {word length}
REP STOSw {write words}
adc cl,cl {extra byte?}
REP STOSb {write byte if there}
jmp @fin
{///////NORMAL FILL PATTERN/////////////////////////}
@normalfill:
cmp cl,0; jnz @more {if there is only one byte then do only this}
and bh,bl
jmp @lastbyte
@More:
and es:[di],bl {first byte}
inc di {inc byte offset}
dec cl {one less for count}
jcxz @lastbyte {if no '$ff' body then go to the last byte}
mov ax,$ffff {load up for body of line}
test maskbyte,255
jnz @runloop
test T_writemode,0;
{mov ax,maskword}
Jnz @runloop {if T_writmode<>0 then goto runloop}
shr cl,1 {get word count}
REP stosw {store words}
adc cl,cl {extra byte?}
REP stosb {Draw if there}
jmp @lastbyte
@runloop: {Do this for checking bytes -xor putting}
and es:[di],al
inc di
dec cx;jnz @runloop
@lastbyte:
and es:[di],bh {write to screen}
@fin:
{reset bitmask
mov dx,GRPH_ADDR
mov ax,0FF08h; out dx,ax; {bitmask,255 func:8}
end;
Procedure putpixel(x1,y1:Integer);
begin
asm
{if dot visable?}
mov cx,x1 ;mov bx,y1
cmp cx,SC.viewport.x1 ;jl @fin {clipping..}
cmp bx,SC.viewport.y1 ;jl @fin
cmp cx,SC.viewport.x2 ;jg @fin
cmp bx,SC.viewport.y2 ;jg @fin
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor al,al; mov ah,t_col; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0FF08h; out dx,ax; {bitmask,255 func:8}
shl bx,1
mov di,word ptr SC.startoffsets+bx
add di,word ptr SC.scrptr
mov es,word ptr SC.scrptr+2
{x-offset}
mov bl,cl
xor bh,bh
and bl,7
shr cx,3
add di,cx
mov al,byte ptr singlepixelbitmasks+bx
and es:[di],al
@fin:
end;
end;
Function getpixel(x1,y1:Integer):byte;assembler;
asm
mov dx,GRPH_ADDR;mov ax,5; out dx,ax
mov ah,$0d
xor bh,bh
mov dx,y1
mov cx,x1
int $10 {value should be returned to al}
mov bl,al
mov dx,GRPH_ADDR;
mov ax,0B05h; out dx,ax;
mov ax,0FF08h; out dx,ax; {bitmask}
mov al,bl
end;
Procedure Vline(x,y1,y2:Integer);assembler;
var
height:word;
asm
mov dx,GRPH_ADDR
mov al,data_rotate;mov ah,t_writemode; out dx,ax; {Logical mode}
xor al,al; mov ah,t_col; out dx,ax; {colour}
mov ax,0B05h; out dx,ax; {writemode -3}
mov ax,0007h; out dx,ax; {set colour don't care}
mov ax,0ff08h; out dx,ax; {bitmask,255 func:8}
{remember that these registers are loaded thus:}
mov ax,y1; mov bx,y2 ;mov cx,x
{swap y2,y1 if y1>y2}
cmp ax,bx ;jle @no_swap ; Xchg ax,bx; @no_swap:
cmp ax,SC.viewport.y2 ;jg @fin {is line at all visable?}
cmp bx,SC.viewport.y1 ;jl @fin
cmp cx,SC.viewport.x2 ;jg @fin
cmp cx,SC.viewport.x1 ;jl @fin
{Y axis clipping}
mov dx,SC.viewport.y1 ;cmp ax,dx ; JGE @nochange_y1
mov ax,dx
@nochange_y1:
mov dx,SC.viewport.y2 ;cmp bx,dx ; JLE @nochange_y2
mov bx,dx
@nochange_y2:
inc bx {inc y2}
sub bx,ax {calc length}
mov height,bx
{could use a lookup table for start memory addresses as well, cut out the multiply}
mov es,word ptr SC.scrptr+2 {load up screen position}
mov si,ax
shl si,1
mov di,word ptr SC.startoffsets+si
add di,word ptr SC.scrptr; {(ax*SC.offsw)+word ptr SC.scrptr (calculate)}
{get bitmask}
mov si,cx
and si,7
mov al,byte ptr [singlepixelbitmasks+si]
{add xoffset}
shr cx,3
add di,cx
mov cx,SC.offsw {load screen width}
test maskbyte,255
jz @runloop
{////MASKED LINE//////}
push di {save screen offset}