-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathXVGA256.PAS
1659 lines (1465 loc) · 44.3 KB
/
XVGA256.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 XVGA256;
{$X+}{$a+}
{stuff to be preserved for mouse inter:
SEQU_ADDR
2,writemask
GRPH_ADDR
4,readmask
}
INTERFACE
uses Gbasics,chardef,ttypes,tmaths;
{to set a vga mode you only need to set these 29 registers}
type
vgaregstype=record
misc:byte;
crtc00_09:array[0..$9] of byte;{mostly horizontal res stuff}
crtc10_17:array[0..$7] of byte;{mostly vertical res stuff}
sequ1,sequ3,sequ4:byte; {can define modeX with just these set to 1,0 & 6}
grph5,grph6:byte; {bit and bobs}
attr10_14:array[0..4] of byte; {as above}
end;
const
X640x400data:vgaregstype=(misc:$6b;
crtc00_09:($ad,$9f,$9f,$89,$a0,$6,$bf,$1f,$0,$60);
crtc10_17:($9c,$8e,$8f,$50,$0,$96,$b9,$e3);
sequ1:$1;sequ3:$0;sequ4:$6;
grph5:$40;grph6:$5;
attr10_14:($41,$0,$f,$0,$10));
X400x600data:vgaregstype=(misc:$e7;
crtc00_09:( $70,$63,$64,$92,$65,$82,$70,$f0,$0,$60);
crtc10_17:($5b,$8c,$57,$32,$0,$58,$70,$e3);
sequ1:$1;sequ3:$0;sequ4:$6;
grph5:$40;grph6:$5;
attr10_14:($41,$0,$f,$0,$10));
X400x300data:vgaregstype=(misc:$a7;
crtc00_09:($71,$63,$64,$92,$65,$82,$46,$1f,$0,$40);
crtc10_17:($31,$80,$2b,$32,$0,$2f,$44,$e3);
sequ1:$1;sequ3:$0;sequ4:$6;
grph5:$40;grph6:$5;
attr10_14:($41,$0,$f,$0,$10));
X320x200data:vgaregstype=(misc:$63;
crtc00_09:($5f,$4f,$50,$82,$54,$80,$bf,$1f,$0,$41);
crtc10_17:($9c,$8e,$8f,$28,$0,$96,$b9,$e3);
sequ1:$1;sequ3:$0;sequ4:$6;
grph5:$40;grph6:$5;
attr10_14:($41,$0,$f,$0,$10));
X320x240data:vgaregstype=(misc:$e3;
crtc00_09:($5f,$4f,$50,$82,$54,$80,$d,$3e,$0,$41);
crtc10_17:($ea,$ac,$df,$28,$0,$e7,$6,$e3);
sequ1:$1;sequ3:$0;sequ4:$6;
grph5:$40;grph6:$5;
attr10_14:($41,$0,$f,$0,$10));
{VGA register locations}
MISC_ADDR=$3c2; MISC_READ_ADDR=$3cc;
ATTR_ADDR=$3c0; ATTR_DATA_ADDR=$3c1;
STATUS_ADDR=$3da;
SEQU_ADDR=$3c4; SEQU_DATA_ADDR=$3c5;
CRTC_ADDR=$3D4; CRTC_DATA_ADDR=$3d5;
GRPH_ADDR=$3CE; GRPH_DATA_ADDR=$3CF;
{screen modes}
mapmask_index=2;
allplanes=3841;
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
{stuff to be preserved for mouse inter:
SEQU_ADDR
2,writemask
GRPH_ADDR
4,readmask
}
var
oldwritemask,oldreadmask:byte;
procedure savescreenregs;
begin
end;
procedure restorescreenregs;
begin
end;
{Set actual graphics mode}
function set_mode(mode:byte):boolean;
var old,lop,dummy:byte;
regs:vgaregstype;
installed:boolean;
begin
{setup mode 13h}
asm
mov al,13h; {mode}
mov ah,0; {function 0}
int 10h {call screen interrupt}
end;
SC.Colourdepth:=256;
SC.offsw:=SC.size.x shr 2;
{set up the unchained mode screen}
port[misc_addr]:=regs.misc and 253;
portw[crtc_addr]:=$11; {disable register protection}
for lop:=0 to $9 do begin
port[crtc_addr]:=lop;
port[crtc_data_addr]:=regs.crtc00_09[lop];
end;
for lop:=$10 to $17 do begin
port[crtc_addr]:=lop;
port[crtc_data_addr]:=regs.crtc10_17[lop-$10];
end;
port[SEQU_ADDR]:=1;port[SEQU_data_ADDR]:=regs.sequ1;
port[SEQU_ADDR]:=3;port[SEQU_data_ADDR]:=regs.sequ3;
port[SEQU_ADDR]:=4;port[SEQU_data_ADDR]:=regs.sequ4;
port[GRPH_ADDR]:=05;port[GRPH_data_ADDR]:=regs.grph5;
port[GRPH_ADDR]:=06;port[GRPH_data_ADDR]:=regs.grph6;
for lop:=$10 to $14 do begin
dummy:=port[status_addr];
port[attr_addr]:=lop or $20;
port[attr_addr]:=regs.attr10_14[lop-$10];
end;
dummy:=port[status_addr];
for lop:=0 to 15 do begin
port[attr_addr]:=lop;
port[attr_addr]:=lop;
end;
dummy:=port[status_addr];port[attr_addr]:=32; {allow access to pallette}
{allow access to screen}
old:=port[misc_read_addr];
port[misc_addr]:=old+2;
set_mode:=TRUE;
{flip default font}
for lop:=0 to 255 do
Flipx_font(@TCharset.typeface[lop],8,fontheight);
end;
Procedure savefontlist(filename:string;var ch:charsettype);
var lop:byte;
begin
for lop:=0 to 255 do
Flipx_font(@Ch.typeface[lop],8,fontheight);
chardef.savefontlist(filename,ch);
end;
Procedure Loadfontlist(filename:string;var ch:charsettype);
var lop:byte;
begin
chardef.Loadfontlist(filename,ch);
for lop:=0 to 255 do
Flipx_font(@Ch.typeface[lop],8,fontheight);
end;
Procedure FSwap(Var s,d; L:Integer);
Begin
Inline($1e /$c5/$b6/s /$c4/$be/d /$8b/$8e/l /$fc /$26/$8a/$05
/$86/$04 /$46 /$aa /$e2/$f7 /$1f);
End;
procedure FillWord(var Dest; Count: Word; Data: Word);
begin
inline(
$C4/$7E/<Dest/ (* LES DI,Dest[BP] *)
$8B/$4E/<Count/ (* MOV CX,Count[BP]*)
$8B/$46/<Data/ (* MOV AX,Data[BP] *)
$FC/ (* CLD *)
$F3/$AB); (* REP STOSW *)
end;
Procedure cleardevice;assembler;
Asm
mov dx,SEQU_ADDR ;mov ax,allplanes+1; out dx,ax
les di,sc.scrptr
mov al,t_fillcol
mov ah,t_fillcol
mov cx,word ptr SC.pagesize
shr cx,1
CLD
REP STOSW
End;
Function outcode(x1,y1:integer):byte;
var return:byte;
Begin
return:=0;
if y1>sc.viewport.y2 then Return:=bellow else
if y1<sc.viewport.y1 then Return:=above;
if x1>sc.viewport.x2 then inc(Return,right) else
if x1<sc.viewport.x1 then inc(Return,left);
outcode:=return;
end;
function clip(var x0,y0,x1,y1:integer):boolean;
var code0,code1:byte;swapvar:integer;
Begin
While 0=0 do begin
code0:=outcode(x0,y0);code1:=outcode(x1,y1);
if (code0 and code1)<>0 then begin
clip:=false;exit;{Trivial reject}
end else begin
if not(code0 or code1<>0)then begin
clip:=true;exit;{Trivial accept}
end else If (code0=0) then begin
swapvar:=code1;code1:=code0;code0:=swapvar;
swapvar:=x0;x0:=x1;x1:=swapvar;
swapvar:=y0;y0:=y1;y1:=swapvar;
end;
if (code0 and bellow)<>0 then begin
inc(x0,(x1-x0)*(sc.viewport.y2-y0)div(y1-y0));
y0:=sc.viewport.y2;
end else if (code0 and above)<>0 then begin
inc(x0,(x1-x0)*(sc.viewport.y1-y0)div(y1-y0));
y0:=sc.viewport.y1;
end else if (code0 and right)<>0 then begin
inc(y0,(y1-y0)*(sc.viewport.x2-x0)div(x1-x0));
x0:=sc.viewport.x2;
end else if (code0 and left)<>0 then begin
inc(y0,(y1-y0)*(sc.viewport.x1-x0)div(x1-x0));
x0:=sc.viewport.x1;
end;
end;
end;
end;
Procedure Line(x1,y1,x2,y2:integer);
Var dfx,dfy,d,d2,incr1,incr2,xinc:integer;
adrs:word;mask:byte;
const
startval=1;
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 es,word ptr sc.scrptr +2 end;
if dfx>dfy then begin
asm
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:
end;
incr2:=(dfy-dfx)shl 1;
if(y2>y1) then xinc:=SC.offsw else xinc:=-SC.offsw;
adrs:=(y1*SC.offsw)+(x1 shr 2);
asm
mov dx,sequ_addr ;mov al,mapmask_index; out dx,al {get X-shift}
inc dx
mov bx,adrs {get offset}
add bx,word ptr sc.scrptr {add screen offset}
mov ah,t_col {load in colour}
mov cx,x1 ;and cl,3 {get mask}
mov al,startval ;shl al,cl
mov cx,dfx ;inc cx {load in the length}
mov si,dfy ;shl si,1 {get increment value 1}
mov di,si ;sub di,dfx {get 'd'}
@Runloop:
out dx,al
mov es:[bx],ah
shl al,1
test al,16
jz @same
mov al,startval
inc bx
@same:
cmp di,0
jl @noinc
add di,incr2
add bx,xinc
jmp @check
@noinc:
add di,si
@check:
loop @runloop
end;
end else begin
d2:=dfx shl 1;
d:=d2-dfy;
incr2:=(dfx-dfy) shl 1;
inc(dfy);
{if y2>y1 then swap both X and Y}
asm
mov ax,y2 ; cmp y1,ax ; jle @no_swap
Xchg y1,ax ; mov y2,ax
mov ax,x2 ; xchg x1,ax ; mov x2,ax;
@no_swap:
end;
mask:=startval shl (x1 and 3);
adrs:=(y1*SC.offsw)+(x1 shr 2);
asm
mov dx,sequ_addr;mov al,mapmask_index;out dx,al;inc dx
mov ah,t_col
mov bx,adrs
add bx,word ptr sc.scrptr; {add screen offset}
mov al,mask;out dx,al {load up starter mask}
mov si,d2 {inrement value 2}
mov di,d {inrement value 2 - diff in Y}
mov cx,x1; cmp cx,x2;
jg @left {check if line is doing left or right}
mov cx,dfy
@Runloop:
mov es:[bx],ah {write to screen}
add bx,SC.offsw {increment screen address}
cmp di,0
jl @noinc
add di,incr2
shl al,1 {shift bit mask along}
test al,16 {do check:}
jz @noreset {if al=16 then...}
mov al,1 {reload al with 1}
inc bx {increment address byte}
@noreset:
out dx,al {load mapmask register with bitmap}
jmp @check {don't do below code}
@noinc:
add di,si
@check:
loop @runloop
jmp @end {leave without doing below}
@left:
mov cx,dfy
@Runloopb:
mov es:[bx],ah {write to screen}
add bx,SC.offsw {increment screen address}
cmp di,0
jl @noincb
add di,incr2
shr al,1 {shift bit mask along}
jnc @noresetb {do check: if carried then...}
mov al,8 {reload al with 8}
dec bx {increment address byte}
@noresetb:
out dx,al {load mapmask register with bitmap}
jmp @checkb {don't do below code}
@noincb:
add di,si
@checkb:
loop @runloopb
@end:
end;
end;
end;
end;
end;
Procedure outtextxy_length(x1,y1:integer;txt:pchar;length:byte);
begin
end;
Procedure outtextxy(x1,y1:integer;txt:string);
var txtend,ylop,txtstart,lmask,rmask,cmask,txtlop,savelop:byte;
Adrs,decoffs,Loffsw:word;
x2,y2,tmp:integer;
Begin
asm
les si,[bp+6] {point to string}
mov al,es:[si] {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,2
add di,word ptr sc.scrptr
add di,ax
mov adrs,di
end;
{**X - Clipping**}
lmask:=$ff; rmask:=$ff;
Loffsw:=SC.offsw;
txtstart:=1;
tmp:=(sc.viewport.x1-x1);
if x1<sc.viewport.x1 then begin
lmask:=lmask shl (tmp and 7);
{HACK!!!!! -to correct an error in start position. SORT IT OUT!}
if (tmp and 7)>3 then dec(Adrs);
inc(adrs,tmp shr 2);
inc(txtstart,tmp shr 3);
end;
tmp:=(x2-sc.viewport.x2-1);
if x2>sc.viewport.x2 then begin
dec(txtend,tmp shr 3);
rmask:=rmask shr (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-1);
decoffs:=(SC.offsw*(ylop)-2);
asm
mov di,adrs
mov dx,SEQU_ADDR;
mov al,mapmask_index;out dx,al {set up mapmask}
inc dx
mov bx,x1 {value to shift right by}
and bl,3
mov bh,t_col
mov cl,txtstart ;xor ch,ch; {load text loop}
@Textloop:
les si,[bp+6] {point to string}
mov al,cl;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}
lea si,tcharset {point to character set}
add si,ax {add character offset}
mov ch,ylop {set up y loop (from y to ylop)}
mov txtlop,cl {save current char}
{generate mask}
mov al,255
cmp cl,txtstart;jnz @noleft
and al,lmask {mask with the left?}
@noleft:
cmp cl,txtend; jnz @noright
and al,rmask {mask with the right?}
@noright:
mov cmask,al
@drawloop:
mov al,ds:[si] {load from pic}
and al,cmask
xor ah,ah {clear top byte}
mov cl,bl; rol ax,cl {shift right by bl, into ah}
out dx,al {write to mapmask}
mov es:[di],bh {write to screen memory}
shr al,4;out dx,al {isolate top 4 bits, write to mapmask}
mov es:[di+1],bh {write to screen memory}
mov al,ah;out dx,al {load end mask into al, write to mapmask}
mov es:[di+2],bh {write to screen memory}
mov cl,txtlop {restore curr character}
add di,Loffsw {shift to next line on screen}
inc si {go to next byte in pic}
dec ch
jnz @drawloop
Sub di,decoffs {correct the screen position..}
inc cl {next character}
cmp cl,txtend {is it the end?}
jle @Textloop {if not, do it all again}
@end:
end;
{for txtlop:=1 to txtlop do begin
currmask:=pointer(@tcharset^[ord(txt[txtlop])][y]);
for lop:=0 to lop do begin
hsub2(adrs,currmask^ shr dxr,currmask^ shl (8-dxr));
inc(Adrs,offs);
inc(currmask);
end;
dec(Adrs,decoffs);
end;}
end;
end;
Procedure Drawbytesxy(x1,y1:Integer;pic:bytearray;xbytes,ybytes:byte);
begin
end;
Procedure Drawbytes(x1,y:Integer;pic:bytearray;nbytes:byte);
var lop,mask:byte; Adrs,Loffsw:word;
x2:integer;
Begin
loffsw:=SC.offsw;
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
asm
mov ax,y ;imul SC.offsw
mov bx,x1 ;sar bx,2
add bx,word ptr sc.scrptr
add ax,bx
mov adrs,ax
end;
{**XCliping**}
mask:=$ff;
if x1<sc.viewport.x1 then
mask:=$ff shl (sc.viewport.x1-x1);
if x2>sc.viewport.x2 then
mask:=mask and ($ff shr (x2-sc.viewport.x2-1));
{**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,y*SC.offsw);
end else y:=0;
dec(lop,y);
asm
mov es,word ptr sc.scrptr+2 {set up screen address}
mov di,adrs
mov dx,SEQU_ADDR;mov al,mapmask_index;out dx,al
inc dx
{values to shift left and right by}
mov cx,x1
and cl,3
mov bh,t_col
mov ch,lop ;inc ch
push ds {save data segment}
lds si,pic
add si,y
@drawloop:
mov ah,ds:[si] {load from pic}
and ah,mask
xor al,al {clear top mask}
rol ax,cl {shift right by cl, into ah}
out dx,al {write to mapmask}
mov es:[di+2],bh {write to screen memory}
mov al,ah;out dx,al {load end mask into al, write to mapmask}
mov es:[di],bh {write to screen memory}
shr al,4;out dx,al {isolate top 4 bits, write to mapmask}
mov es:[di+1],bh {write to screen memory}
add di,loffsw {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 Hline(x1,x2,y:Integer);assembler;
asm
{es -screen seg
di -byte offset
ax -bit masks
cx -X length of line in bytes-1}
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:
{start of mode dependant stuff}
{load up screen position}
mov es,word ptr sc.scrptr+2
inc cx ; imul SC.offsw ;add ax,word ptr sc.scrptr; mov di,ax
{select mapmask -the two least dig bits of X are mapmask}
mov al,mapmask_index
mov dx,SEQU_ADDR
out dx,al
mov si,cx {save cx}
mov ax,$ffff {2nd mask }
and cl,3 ;shl ah,cl ;not ah {1st mask }
mov cx,bx; and cl,3 ;shl al,cl {save cx}
mov cx,si
{calculate length (in bytes-1) of line}
shr cx,2
shr bx,2
sub cx,bx
add di,bx {add this to screen memory offset}
mov bh,t_col
{get register data address ready.... -sequ_data_addr}
inc dx
{if there are only 4 pixels then do this only}
cmp cl,0
jnz @more
and ah,al
jmp @lastbyte
@More:
out dx,al
mov es:[di],bh {first}
inc di {inc byte offset}
cmp cl,1;jz @lastbyte {if no body then go to the last byte}
mov al,15 {else load up for body of line}
out dx,al
mov si,ax {save ax}
mov al,bh {load up with colour}
mov ah,al {fill up all of ax}
dec cl
shr cl,1 {get word count}
REP STOSW {draw words}
adc cl,cl {extra byte?}
REP STOSB {do fill}
mov ax,si {retore ax}
@lastbyte:
mov al,ah
out dx,al
mov es:[di],bh
@fin:
end;
procedure putpixel(x1,y1:integer);assembler;
asm
{clipping}
mov ax,y1 ;mov bx,x1
cmp bx,sc.viewport.x1 ;jl @fin; cmp ax,sc.viewport.y1 ;jl @fin
cmp bx,sc.viewport.x2 ;jg @fin; cmp ax,sc.viewport.y2 ;jg @fin
{load up screen position}
mov es,word ptr sc.scrptr+2
mov cx,bx
imul SC.offsw; add ax,word ptr sc.scrptr; mov di,ax
shr bx,2; add di,bx
{select mapmask -the two least dig bits of X are mapmask}
mov al,mapmask_index {function select}
mov ah,1 ;and cl,3; shl ah,cl {1 shl (X and 3)}
mov dx,SEQU_ADDR
out dx,ax
mov al,t_col
mov es:[di],al
@fin:
{ mem[word ptr sc.scrptr+2:(offs*y)+(x shr 2)]:=t_col;}
end;
Function getpixel(x1,y1:Integer):byte;
assembler;
asm
mov ax,y1 ;mov bx,x1
mov es,word ptr sc.scrptr+2
mov cx,bx
imul SC.offsw; add ax,word ptr sc.scrptr; mov di,ax
shr bx,2; add di,bx
mov al,4 {set up read mask}
and cl,3; mov ah,cl
mov dx,GRPH_ADDR
out dx,ax
mov al,es:[di]
end;
Procedure Vline(x,y1,y2:Integer);assembler;
asm
{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:
{is line at all visable?}
cmp ax,sc.viewport.y2 ;jg @fin
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 es,word ptr sc.scrptr+2 {load up screen position}
imul SC.offsw; add ax,word ptr sc.scrptr; {(ax*SC.offsw)+word ptr sc.scrptr (calculate)}
mov dx,cx {make copy of x into dx}
shr dx,2; add ax,dx; mov di,ax {(+dx shr 2(address}
and cl,3; mov ah,$1; shl ah,cl {get mask}
mov cx,bx {load length into cx}
mov bx,SC.offsw {load screen width}
mov al,mapmask_index {function select}
mov dx,SEQU_ADDR {load up register address}
out dx,ax {write mask,
al=mapmask mode,ah=mask}
mov al,t_col {load current colour into al}
@runloop:
mov es:[di],al
add di,bx
loop @runloop
@fin:
end;
Procedure bar(x1,y,x2,y2:integer);assembler;
asm
mov ax,x2 ;cmp x1,ax ;jle @no_swapx ; Xchg x1,ax; mov x2,ax ; @no_swapx:
mov ax,y2 ;cmp y,ax ;jle @no_swapy ; Xchg y,ax; mov y2,ax ; @no_swapy:
{is bar at all visable?}
mov ax,x1 ;cmp ax,sc.viewport.x2 ;jg @end
mov ax,x2 ;cmp ax,sc.viewport.x1 ;jl @end
mov ax,y ;cmp ax,sc.viewport.y2 ;jg @end
mov ax,y2 ;cmp ax,sc.viewport.y1 ;jl @end
{x axis clipping}
mov ax,sc.viewport.x1 ;cmp x1,ax ; JGE @nochange_x1
mov x1,ax
@nochange_x1:
mov ax,sc.viewport.x2 ;cmp x2,ax ; JLE @nochange_x2
mov x2,ax
@nochange_x2:
{Y axis clipping}
mov ax,sc.viewport.y1 ;cmp y,ax ; JGE @nochange_y1
mov y,ax
@nochange_y1:
mov ax,sc.viewport.y2 ;cmp y2,ax ; JLE @nochange_y2
mov y2,ax
@nochange_y2:
inc y2;inc x2
{start of mode dependant stuff}
{load up screen position}
mov es,word ptr sc.scrptr+2
mov ax,y ;imul SC.offsw ;add ax,word ptr sc.scrptr;mov di,ax
mov al,mapmask_index {select mapmask -the two}
mov dx,SEQU_ADDR {least sig bits of X are }
out dx,al {the mapmask}
mov ax,$ffff {1st mask}
mov cx,x1;
and cl,3 ;shl al,cl
mov cx,x2 ;and cl,3 {2nd mask}
shl ah,cl ;not ah
mov cx,x2 ;shr cx,2 {calculate length (in bytes-1) of line}
mov bx,x1 ;shr bx,2
sub cx,bx
add di,bx {add this to screen memory offset}
mov si,SC.offsw
sub si,cx
mov bh,t_fillcol
mov bl,cl
cmp bl,0; jnz @noand
and ah,al
@noand:
dec bl
{get register data address ready.... -sequ_data_addr}
inc dx
mov cx,y2
sub cx,y
{if there are only 4 pixels then do this only}
push bp {save stack frame}
push ds
@runloop:
mov ds,cx
mov cl,bl ;xor ch,ch {load up loop counter with bl}
cmp cl,255;jz @lastbyte {if only one byte then goto @lastbyte}
out dx,al {first byte}
mov es:[di],bh
inc di {inc byte offset}
mov bp,ax {save ax}
shr cl,1
mov al,15; {else load up for body of line}
out dx,al
mov al,bh ;mov ah,al {load up with colour}
REP STOSW {do fill}
adc cl,cl {extra byte?}
REP STOSB {fill it if there}
mov ax,bp {restore ax}
@lastbyte:
mov bp,ax {save ax}
mov al,ah
out dx,al {write bitmask to mapmask reg}
mov es:[di],bh {write to screen}
mov ax,bp {restore ax}
mov cx,ds
ADD di,si
loop @runloop
pop ds
pop bp {restore stack frame}
@end:
end;
Procedure Triangle(xa,ya,xb,yb,xc,yc:integer);assembler;
const shiftby=6;
Var
lop,Lx,Rx,
Lxadd,Rxadd,yrdiff,yldiff,xoff,Lxa,Rxa,xdiff,endp:integer;
right:boolean;
scrwidthet:word;
{sort by Y}
asm
{if ya>yc then swap xc,xa swap yc,ya fswap ic,ia}
mov ax,yc
cmp ya,ax
jl @NoSwapY1
xchg ya,ax; mov yc,ax
mov ax,xc; xchg xa,ax; mov xc,ax
@NoSwapY1:
{if ya>yb then swap xb,xa swap yb,ya fswap ib,ia}
mov ax,yb
cmp ya,ax
jl @NoSwapY2
xchg ya,ax; mov yb,ax
mov ax,xb; xchg xa,ax; mov xb,ax
@NoSwapY2:
{if yb>yc then swap xc,xb swap yc,yb fswap ic,ib}
mov ax,yc
cmp yb,ax
jl @NoSwapY3
xchg yb,ax; mov yc,ax
mov ax,xc; xchg xb,ax; mov xc,ax
@NoSwapY3:
{is the cross point to the left or right?}
mov di,yc;sub di,ya
mov ax,yb;sub ax,yc
mov cx,xc;sub cx,xa
imul cx
cmp di,0
jz @nodiv
idiv di
@nodiv:
add ax,xc
cmp xb,ax
mov right,true
jle @isright
mov right,false
@isright:
{get largest x}
mov bx,xa;
mov ax,xb
cmp bx,ax; jg @nodo1 ;mov bx,ax ;@nodo1:
mov ax,xc
cmp bx,ax; jg @nodo2 ;mov bx,ax ;@nodo2:
{if largest off screen then exit}
cmp bx,sc.viewport.x1;jl @triend
{get smallest x}
mov bx,xa;
mov ax,xb
cmp bx,ax; jl @nodo3 ;mov bx,ax ;@nodo3:
mov ax,xc
cmp bx,ax; jl @nodo4 ;mov bx,ax ;@nodo4:
{if smallest off screen then exit}
cmp bx,sc.viewport.x2;jg @triend
mov xoff,bx
{sub by bx and shift left}
sub xa,bx
sub xb,bx
sub xc,bx
shl xa,shiftby
shl xb,shiftby
shl xc,shiftby
{get y length}
mov si,yc
cmp si,sc.viewport.y2
jle @noyclip
mov si,sc.viewport.y2
inc si
@noyclip:
mov endp,si {exit routine if ends of tri are outside VP}
mov si,ya
cmp si,sc.viewport.y2 {if ya>sc.viewport then exit}
jg @triend
cmp si,endp {if ya=clipped yc then exit}
jz @triend
{yldiff:=yb-ya;if yldiff=0 then yldiff:=1;
Lxadd:=(xb-xa) div yldiff;}
mov ax,xb ;sub ax,xa
mov bx,yb ;sub bx,ya
jz @nodiv1
cwd
idiv bx
jmp @nocorrect1
@nodiv1:
mov bx,1
@nocorrect1:
mov yldiff,bx
mov lxadd,ax
{yrdiff:=yc-ya;if yrdiff=0 then yrdiff:=1;
Rxadd:=(xc-xa) div yrdiff;}
mov ax,xc ;sub ax,xa
mov bx,yc ;sub bx,ya
jz @nodiv2
cwd
idiv bx
jmp @nocorrect2
@nodiv2:
mov bx,1
@nocorrect2:
mov yrdiff,bx
mov rxadd,ax
mov ax,xa
mov Lxa,ax